Skip to content

Commit

Permalink
fix display all models, suppress current problems, enable color! and …
Browse files Browse the repository at this point in the history
…enable world changes!
  • Loading branch information
zardoy committed Dec 4, 2024
1 parent 2c7e38a commit 71c13fe
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 60 deletions.
2 changes: 1 addition & 1 deletion prismarine-viewer/examples/Cube.frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ fn main(
let tileSize: vec2<f32> = vec2<f32>(16.0, 16.0);
let tilesPerTexture: vec2<f32> = 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
}
2 changes: 1 addition & 1 deletion prismarine-viewer/examples/scenes/floorStoneWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions prismarine-viewer/examples/webgpuRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion prismarine-viewer/examples/webgpuRendererMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions prismarine-viewer/examples/webgpuRendererWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,8 @@ export const workerProxyType = createWorkerProxy({
},
addBlocksSection (tiles: Record<string, BlockType>, 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)
Expand Down
1 change: 0 additions & 1 deletion prismarine-viewer/viewer/lib/mesher/mesher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ const handleMessage = data => {
}
case 'unloadChunk': {
world.removeColumn(data.x, data.z)
if (Object.keys(world.columns).length === 0) softCleanup()

break
}
Expand Down
61 changes: 15 additions & 46 deletions prismarine-viewer/viewer/lib/worldrendererWebgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ class RendererProblemReporter {

export class WorldRendererWebgpu extends WorldRendererCommon {
outputFormat = 'webgpu' as const
newChunks = {} as Record<string, any>
// webglData: WebglData
stopBlockUpdate = false
lastChunkDistance = 0
loaded = new Set()
allowUpdates = false
allowUpdates = true
issueReporter = new RendererProblemReporter()
allChunksHasLoaded = false

constructor (config) {
super(config)
Expand All @@ -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]
}

Expand All @@ -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()
}
Expand All @@ -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 { }
Expand All @@ -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}`)
// }
}
}

0 comments on commit 71c13fe

Please sign in to comment.