From 71c13fe53cb79a9b535d9cd3e32802245357eaf3 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Wed, 4 Dec 2024 04:20:44 +0300 Subject: [PATCH] fix display all models, suppress current problems, enable color! and enable world changes! --- prismarine-viewer/examples/Cube.frag.wgsl | 2 +- .../examples/scenes/floorStoneWorld.ts | 2 +- prismarine-viewer/examples/webgpuRenderer.ts | 4 +- .../examples/webgpuRendererMain.ts | 2 +- .../examples/webgpuRendererWorker.ts | 8 --- prismarine-viewer/viewer/lib/mesher/mesher.ts | 1 - .../viewer/lib/worldrendererWebgpu.ts | 61 +++++-------------- 7 files changed, 20 insertions(+), 60 deletions(-) diff --git a/prismarine-viewer/examples/Cube.frag.wgsl b/prismarine-viewer/examples/Cube.frag.wgsl index 1cccfcc9e..1b7bbad2a 100644 --- a/prismarine-viewer/examples/Cube.frag.wgsl +++ b/prismarine-viewer/examples/Cube.frag.wgsl @@ -11,5 +11,5 @@ fn main( let tileSize: vec2 = vec2(16.0, 16.0); let tilesPerTexture: vec2 = textureSize / tileSize; let pixelColor = textureSample(myTexture, mySampler, fragUV / tilesPerTexture + vec2f(trunc(TextureIndex % tilesPerTexture.y), trunc(TextureIndex / tilesPerTexture.x)) / tilesPerTexture); - return vec4f(pixelColor.rgb, 1.0); // Set alpha to 1.0 for full opacity + return vec4f(pixelColor.rgb * ColorBlend / 255, 1.0); // Set alpha to 1.0 for full opacity } diff --git a/prismarine-viewer/examples/scenes/floorStoneWorld.ts b/prismarine-viewer/examples/scenes/floorStoneWorld.ts index aeaf3176e..61bb6f68e 100644 --- a/prismarine-viewer/examples/scenes/floorStoneWorld.ts +++ b/prismarine-viewer/examples/scenes/floorStoneWorld.ts @@ -29,7 +29,7 @@ export default class Scene extends BasePlaygroundScene { if (squareSize > maxSquareSize) throw new Error(`Square size too big, max is ${maxSquareSize}`) // const fullBlocks = loadedData.blocksArray.map(x => x.name) const fullBlocks = loadedData.blocksArray.filter(block => { - const b = this.Block.fromStateId(block.defaultState!, 0) + const b = this.Block.fromStateId(block.defaultState, 0) if (b.shapes?.length !== 1) return false const shape = b.shapes[0] return shape[0] === 0 && shape[1] === 0 && shape[2] === 0 && shape[3] === 1 && shape[4] === 1 && shape[5] === 1 diff --git a/prismarine-viewer/examples/webgpuRenderer.ts b/prismarine-viewer/examples/webgpuRenderer.ts index 8b099927d..cc11a0cac 100644 --- a/prismarine-viewer/examples/webgpuRenderer.ts +++ b/prismarine-viewer/examples/webgpuRenderer.ts @@ -596,7 +596,7 @@ export class WebgpuRenderer { const unique = new Set() const debugCheckDuplicate = (first, second, third) => { - const key = `${first},${second},${third}` + const key = `${first},${third}` if (unique.has(key)) { throw new Error(`Duplicate: ${key}`) } @@ -644,7 +644,7 @@ export class WebgpuRenderer { cubeFlatData[i * 3] = first cubeFlatData[i * 3 + 1] = second cubeFlatData[i * 3 + 2] = third - debugCheckDuplicate(first, second, third) + // debugCheckDuplicate(first, second, third) } const chunksCount = chunks.length diff --git a/prismarine-viewer/examples/webgpuRendererMain.ts b/prismarine-viewer/examples/webgpuRendererMain.ts index ac28d1fec..5276be7a3 100644 --- a/prismarine-viewer/examples/webgpuRendererMain.ts +++ b/prismarine-viewer/examples/webgpuRendererMain.ts @@ -282,7 +282,7 @@ const getBlocksModelData = () => { let i = 0 const allBlocksStateIdToModelIdMap = {} as AllBlocksStateIdToModelIdMap for (const b of loadedData.blocksArray) { - for (let state = b.defaultState; state <= b.defaultState; state++) { + for (let state = b.minStateId; state <= b.maxStateId; state++) { const mapping = blocksMap[b.name] const block = PBlockOriginal.fromStateId(mapping && loadedData.blocksByName[mapping] ? loadedData.blocksByName[mapping].defaultState : state, 0) if (isPreflat) { diff --git a/prismarine-viewer/examples/webgpuRendererWorker.ts b/prismarine-viewer/examples/webgpuRendererWorker.ts index 21514debd..deb6074e9 100644 --- a/prismarine-viewer/examples/webgpuRendererWorker.ts +++ b/prismarine-viewer/examples/webgpuRendererWorker.ts @@ -165,16 +165,8 @@ export const workerProxyType = createWorkerProxy({ }, addBlocksSection (tiles: Record, key: string, updateData = true) { chunksStorage.addChunk(tiles, key) - // if (updateData || true) { - // updateCubesWhenAvailable() - // chunksStorage.awaitingUpdateStart = undefined - // chunksStorage.awaitingUpdateEnd = undefined - // } }, addBlocksSectionDone () { - // updateCubesWhenAvailable() - // chunksStorage.awaitingUpdateStart = undefined - // chunksStorage.awaitingUpdateEnd = undefined }, removeBlocksSection (key) { chunksStorage.removeChunk(key) diff --git a/prismarine-viewer/viewer/lib/mesher/mesher.ts b/prismarine-viewer/viewer/lib/mesher/mesher.ts index c23c69f02..e44aef580 100644 --- a/prismarine-viewer/viewer/lib/mesher/mesher.ts +++ b/prismarine-viewer/viewer/lib/mesher/mesher.ts @@ -112,7 +112,6 @@ const handleMessage = data => { } case 'unloadChunk': { world.removeColumn(data.x, data.z) - if (Object.keys(world.columns).length === 0) softCleanup() break } diff --git a/prismarine-viewer/viewer/lib/worldrendererWebgpu.ts b/prismarine-viewer/viewer/lib/worldrendererWebgpu.ts index 47d4e751f..e46586e49 100644 --- a/prismarine-viewer/viewer/lib/worldrendererWebgpu.ts +++ b/prismarine-viewer/viewer/lib/worldrendererWebgpu.ts @@ -56,14 +56,10 @@ class RendererProblemReporter { export class WorldRendererWebgpu extends WorldRendererCommon { outputFormat = 'webgpu' as const - newChunks = {} as Record // webglData: WebglData stopBlockUpdate = false - lastChunkDistance = 0 - loaded = new Set() - allowUpdates = false + allowUpdates = true issueReporter = new RendererProblemReporter() - allChunksHasLoaded = false constructor (config) { super(config) @@ -79,12 +75,12 @@ export class WorldRendererWebgpu extends WorldRendererCommon { } playgroundGetWebglData () { - const playgroundChunk = Object.values(this.newChunks).find((x: any) => Object.keys(x?.blocks ?? {}).length > 0) - if (!playgroundChunk) return - const block = Object.values(playgroundChunk.blocks)?.[0] as any - if (!block) return - const { textureName } = block - if (!textureName) return + // const playgroundChunk = Object.values(this.newChunks).find((x: any) => Object.keys(x?.blocks ?? {}).length > 0) + // if (!playgroundChunk) return + // const block = Object.values(playgroundChunk.blocks)?.[0] as any + // if (!block) return + // const { textureName } = block + // if (!textureName) return // return this.webglData[textureName] } @@ -96,11 +92,6 @@ export class WorldRendererWebgpu extends WorldRendererCommon { isWaitingForChunksToRender = false allChunksLoaded (): void { - if (this.allChunksHasLoaded) { - console.log('allChunksLoaded (ignored)') - return - } - this.allChunksHasLoaded = true console.log('allChunksLoaded') webgpuChannel.addBlocksSectionDone() } @@ -112,16 +103,11 @@ export class WorldRendererWebgpu extends WorldRendererCommon { } addChunksToScene (key: string, geometry: MesherGeometryOutput) { - if (this.loaded.has(key) && !this.allowUpdates) return - this.loaded.add(key) - const chunkCoords = key.split(',').map(Number) as [number, number, number] + if (this.finishedChunks[key] && !this.allowUpdates) return + // const chunkCoords = key.split(',').map(Number) as [number, number, number] if (/* !this.loadedChunks[chunkCoords[0] + ',' + chunkCoords[2]] || */ !this.active) return addBlocksSection(key, geometry) - this.lastChunkDistance = Math.max(...this.getDistance(new Vec3(chunkCoords[0], 0, chunkCoords[2]))) - - // todo - // this.newChunks[data.key] = data.geometry } updateCamera (pos: Vec3 | null, yaw: number, pitch: number): void { } @@ -148,28 +134,11 @@ export class WorldRendererWebgpu extends WorldRendererCommon { removeColumn (x, z) { - // TODO! disabled for now! - // console.log('removeColumn', x, z) - // super.removeColumn(x, z) - // for (const key of Object.keys(this.newChunks)) { - // const [xSec, _ySec, zSec] = key.split(',').map(Number) - // // if (Math.floor(x / 16) === x && Math.floor(z / 16) === z) { - // if (x === xSec && z === zSec) { - // // foundSections.push(key) - // removeBlocksSection(key) - // } - // } - - // for (let y = this.worldConfig.minY; y < this.worldConfig.worldHeight; y += 16) { - // this.setSectionDirty(new Vec3(x, y, z), false) - // const key = `${x},${y},${z}` - // const mesh = this.sectionObjects[key] - // if (mesh) { - // this.scene.remove(mesh) - // dispose3(mesh) - // } - // delete this.sectionObjects[key] - // } - } + // console.log('removeColumn', x, z) + // super.removeColumn(x, z) + // for (let y = this.worldConfig.minY; y < this.worldConfig.worldHeight; y += 16) { + // webgpuChannel.removeBlocksSection(`${x},${y},${z}`) + // } + } }