feat: implement experimental clipWorldBelowY setting for testing
This commit is contained in:
parent
574cdfc531
commit
32931efef0
4 changed files with 17 additions and 5 deletions
|
|
@ -7,7 +7,8 @@ export const defaultMesherConfig = {
|
|||
smoothLighting: true,
|
||||
outputFormat: 'threeJs' as 'threeJs' | 'webgpu',
|
||||
textureSize: 1024, // for testing
|
||||
debugModelVariant: undefined as undefined | number[]
|
||||
debugModelVariant: undefined as undefined | number[],
|
||||
clipWorldBelowY: undefined as undefined | number
|
||||
}
|
||||
|
||||
export type MesherConfig = typeof defaultMesherConfig
|
||||
|
|
|
|||
|
|
@ -321,6 +321,10 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|||
console.log('texture loaded')
|
||||
}
|
||||
|
||||
get worldMinYRender () {
|
||||
return Math.floor(Math.max(this.worldConfig.minY, this.mesherConfig.clipWorldBelowY ?? -Infinity) / 16) * 16
|
||||
}
|
||||
|
||||
addColumn (x: number, z: number, chunk: any, isLightUpdate: boolean) {
|
||||
if (!this.active) return
|
||||
if (this.workers.length === 0) throw new Error('workers not initialized yet')
|
||||
|
|
@ -330,7 +334,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|||
// todo optimize
|
||||
worker.postMessage({ type: 'chunk', x, z, chunk })
|
||||
}
|
||||
for (let y = this.worldConfig.minY; y < this.worldConfig.worldHeight; y += 16) {
|
||||
for (let y = this.worldMinYRender; y < this.worldConfig.worldHeight; y += 16) {
|
||||
const loc = new Vec3(x, y, z)
|
||||
this.setSectionDirty(loc)
|
||||
if (this.neighborChunkUpdates && (!isLightUpdate || this.mesherConfig.smoothLighting)) {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ const defaultOptions = {
|
|||
|
||||
// antiAliasing: false,
|
||||
|
||||
clipWorldBelowY: undefined as undefined | number, // will be removed
|
||||
showChunkBorders: false, // todo rename option
|
||||
frameLimit: false as number | false,
|
||||
alwaysBackupWorldBeforeLoading: undefined as boolean | undefined | null,
|
||||
|
|
@ -157,7 +158,7 @@ subscribe(options, () => {
|
|||
localStorage.options = JSON.stringify(saveOptions)
|
||||
})
|
||||
|
||||
type WatchValue = <T extends Record<string, any>>(proxy: T, callback: (p: T) => void) => void
|
||||
type WatchValue = <T extends Record<string, any>>(proxy: T, callback: (p: T, isChanged: boolean) => void) => void
|
||||
|
||||
export const watchValue: WatchValue = (proxy, callback) => {
|
||||
const watchedProps = new Set<string>()
|
||||
|
|
@ -166,10 +167,10 @@ export const watchValue: WatchValue = (proxy, callback) => {
|
|||
watchedProps.add(p.toString())
|
||||
return Reflect.get(target, p, receiver)
|
||||
},
|
||||
}))
|
||||
}), false)
|
||||
for (const prop of watchedProps) {
|
||||
subscribeKey(proxy, prop, () => {
|
||||
callback(proxy)
|
||||
callback(proxy, true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,12 @@ export const watchOptionsAfterViewerInit = () => {
|
|||
watchValue(options, o => {
|
||||
viewer.world.displayStats = o.renderDebug === 'advanced'
|
||||
})
|
||||
watchValue(options, (o, isChanged) => {
|
||||
viewer.world.mesherConfig.clipWorldBelowY = o.clipWorldBelowY
|
||||
if (isChanged) {
|
||||
(viewer.world as WorldRendererThree).rerenderAllChunks()
|
||||
}
|
||||
})
|
||||
|
||||
viewer.world.mesherConfig.smoothLighting = options.smoothLighting
|
||||
subscribeKey(options, 'smoothLighting', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue