From fa1daf6c49786dc619dbda84491ae8bb2f35ad92 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Wed, 4 Dec 2024 05:34:49 +0300 Subject: [PATCH] use robust chunk value --- prismarine-viewer/examples/chunksStorage.ts | 7 ++++--- prismarine-viewer/examples/webgpuRenderer.ts | 16 +++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/prismarine-viewer/examples/chunksStorage.ts b/prismarine-viewer/examples/chunksStorage.ts index 370175da9..0adb8370f 100644 --- a/prismarine-viewer/examples/chunksStorage.ts +++ b/prismarine-viewer/examples/chunksStorage.ts @@ -165,9 +165,10 @@ export class ChunksStorage { const chunkIndex = this.chunks.indexOf(chunk) this.chunksMap.set(rawPosKey, chunkIndex) - // newData.forEach(newDatum => { - // newDatum[3].chunk = chunkIndex - // }) + for (const newDatum of newData) { + //@ts-expect-error + newDatum[3].chunk = chunkIndex + } this.addBlocksData(start, newData) this.awaitingUpdateStart = Math.min(this.awaitingUpdateStart ?? Infinity, start) diff --git a/prismarine-viewer/examples/webgpuRenderer.ts b/prismarine-viewer/examples/webgpuRenderer.ts index ab9ed8672..c23a5063a 100644 --- a/prismarine-viewer/examples/webgpuRenderer.ts +++ b/prismarine-viewer/examples/webgpuRenderer.ts @@ -614,18 +614,18 @@ export class WebgpuRenderer { const blocksToUpdate = allBlocks.slice(updateOffset, updateOffset + updateSize) const actualCount = updateOffset + blocksToUpdate.length - let chunk = chunksStorage.findBelongingChunk(updateOffset)! - let remaining = chunk.chunk.length + // let chunk = chunksStorage.findBelongingChunk(updateOffset)! + // let remaining = chunk.chunk.length // eslint-disable-next-line unicorn/no-for-loop for (let i = 0; i < blocksToUpdate.length; i++) { - if (remaining-- === 0) { - chunk = chunksStorage.findBelongingChunk(updateOffset + i)! - remaining = chunk.chunk.length - 1 - } + // if (remaining-- === 0) { + // chunk = chunksStorage.findBelongingChunk(updateOffset + i)! + // remaining = chunk.chunk.length - 1 + // } let first = 0 let second = 0 - const third = chunk.index + let third = 0 const chunkBlock = blocksToUpdate[i] if (chunkBlock) { const [x, y, z, block] = chunkBlock @@ -646,6 +646,8 @@ export class WebgpuRenderer { (visibility[4] << 4) | (visibility[5] << 5) second = ((visibilityCombined << 8 | colors[2]) << 8 | colors[1]) << 8 | colors[0] + //@ts-expect-error + third = block.chunk } cubeFlatData[i * 3] = first