minerender 2.1.0-alpha.143 → 2.1.0-alpha.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/browser/esm/env/browser/BrowserEnv.mjs +11 -4
- package/dist/browser/esm/env/browser/BrowserEnv.mjs.map +1 -1
- package/dist/browser/esm/index.browser.d.mts +19 -4
- package/dist/browser/esm/index.browser.mjs.map +1 -1
- package/dist/browser/esm/world/Chunk.mjs +62 -33
- package/dist/browser/esm/world/Chunk.mjs.map +1 -1
- package/dist/browser/esm/world/MineRenderWorld.mjs +16 -1
- package/dist/browser/esm/world/MineRenderWorld.mjs.map +1 -1
- package/dist/browser/esm/world/SectionModels.mjs +21 -15
- package/dist/browser/esm/world/SectionModels.mjs.map +1 -1
- package/dist/browser/esm/world/SectionWorker.mjs +8 -2
- package/dist/browser/esm/world/SectionWorker.mjs.map +1 -1
- package/dist/browser/index.d.ts +19 -4
- package/dist/browser/index.js +217 -155
- package/dist/browser/index.js.map +1 -1
- package/dist/bundle.js +227 -165
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +5 -2
- package/dist/node/index.d.ts +5 -2
- package/dist/node/index.js +106 -51
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +106 -51
- package/dist/node/index.mjs.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/world/MineRenderWorld.ts"],"sourcesContent":["import { MineRenderScene } from \"../renderer/MineRenderScene\";\nimport { Block } from \"../model/block/Block\";\nimport { Raycaster, Vector3 } from \"three\";\nimport { isTripleArray, TripleArray } from \"../model/Model\";\nimport { Maybe, yieldToEventLoop } from \"../util/util\";\nimport { Chunk } from \"./Chunk\";\nimport { BlockInfo } from \"./BlockInfo\";\nimport { MultiBlockBlock, MultiBlockStructure } from \"../model/multiblock/MultiBlockStructure\";\nimport { BatchedExecutor } from \"../util/BatchedExecutor\";\nimport { AssetKey } from \"../assets/AssetKey\";\nimport { BlockStates } from \"../assets/BlockStates\";\nimport { CUBE_FACE_OFFSETS } from \"../CubeFace\";\nimport type { AnvilChunk } from \"./AnvilParser\";\nimport { SectionModels } from \"./SectionModels\";\nimport { WorldEntities } from \"./_entities/WorldEntities\";\nimport { fluidKindOf } from \"../model/fluid/FluidQuads\";\nimport type { WorldBlockIntersection } from \"./WorldBlockIntersection\";\nimport type { WorldEntityIntersection } from \"./WorldEntityIntersection\";\nimport { BiomeBlend, validateBiomeBlendRadius } from \"./_biomes/BiomeBlend\";\nimport { copySectionLight, sampleSectionLight, SavedLightSample, SectionLightData } from \"./WorldLight\";\nimport { loadBlockCulling } from \"./_culling/BlockCulling\";\nimport { logger } from \"../util/log\";\n\nconst log = logger(\"MineRenderWorld\");\nconst YIELD_INTERVAL_MS = 8;\n\n//TODO: maybe make this an Object3D to add children\n/**\n * Stores and renders blocks in sparse 16×16×16 chunks.\n * Positions use integer block coordinates, including negatives. One block is 16 scene units.\n * Set `options.sectionMeshing` in `new MineRenderWorld(scene, options)` to merge compatible terrain.\n */\nexport class MineRenderWorld<SectionMeshing extends boolean = false> {\n\n public readonly scene: MineRenderScene;\n\n private readonly _chunks: Map<string, Chunk<SectionMeshing>> = new Map();\n private readonly biomes = new Map<string, Map<number, readonly string[]>>();\n private readonly light = new Map<string, Map<number, SectionLightData>>();\n private readonly lightValidity = new Map<string, boolean>();\n private readonly highestSkySection = new Map<string, number>();\n private readonly savedLighting: boolean;\n private readonly ambientLight: number;\n private _ambientOcclusion: boolean;\n private ambientOcclusionPending = false;\n private _biomeBlendRadius: number;\n private biomeBlend?: BiomeBlend;\n private readonly pendingBiomes = new Map<Chunk<SectionMeshing>, { x: number; z: number }[] | undefined>();\n private biomeRefreshing?: Promise<Map<Chunk<SectionMeshing>, unknown>>;\n private readonly sectionModels?: SectionModels;\n private readonly entities?: WorldEntities;\n private readonly pendingCulling = new Map<Chunk<SectionMeshing>, Set<number> | \"all\">();\n private culling?: Promise<void>;\n\n constructor(scene: MineRenderScene, options: MineRenderWorldOptions<SectionMeshing> = {}) {\n if (options.savedLighting && !options.sectionMeshing) throw new TypeError(\"savedLighting requires sectionMeshing\");\n if (options.ambientOcclusion && !options.sectionMeshing) throw new TypeError(\"ambientOcclusion requires sectionMeshing\");\n if (options.ambientLight !== undefined && (!Number.isFinite(options.ambientLight) || options.ambientLight < 0 || options.ambientLight > 1)) {\n throw new RangeError(\"ambientLight must be a number from 0 to 1\");\n }\n this._biomeBlendRadius = options.biomeBlendRadius ?? 0;\n validateBiomeBlendRadius(this._biomeBlendRadius);\n if (this._biomeBlendRadius > 0 && !options.sectionMeshing) throw new TypeError(\"biomeBlendRadius requires sectionMeshing\");\n if (this._biomeBlendRadius) this.biomeBlend = new BiomeBlend((x, y, z) => this.getBiomeAt(x, y, z), this._biomeBlendRadius);\n this.scene = scene;\n this.savedLighting = options.savedLighting ?? false;\n this.ambientLight = options.ambientLight ?? 0;\n this._ambientOcclusion = options.ambientOcclusion ?? false;\n if (options.sectionMeshing) this.sectionModels = new SectionModels(options.maxAtlasSize);\n if (options.renderEntities) this.entities = new WorldEntities(scene);\n }\n\n /**\n * Returns the nearest visible block geometry hit, respecting the raycaster's layers and near/far range.\n * Includes fluids and block entities; texture alpha does not change triangle intersections.\n */\n public raycast(raycaster: Raycaster): WorldBlockIntersection | undefined {\n return Chunk.raycast(this._chunks.values(), raycaster);\n }\n\n /**\n * Returns the nearest visible mob geometry hit when renderEntities is enabled.\n * Respects layers and near/far; compare its distance with raycast() to account for blocks.\n * Texture alpha does not change triangle intersections.\n */\n public raycastEntities(raycaster: Raycaster): WorldEntityIntersection | undefined {\n return this.entities?.raycast(raycaster);\n }\n\n /** Whether neighboring opaque cubes shade block-face corners. Defaults to false. */\n public get ambientOcclusion(): boolean {\n return this._ambientOcclusion;\n }\n\n /** Rebuilds loaded blocks with or without corner shading. Block data and saved lighting are preserved. */\n public async setAmbientOcclusion(enabled: boolean): Promise<void> {\n if (typeof enabled !== \"boolean\") throw new TypeError(\"Ambient occlusion must be a boolean\");\n if (enabled && !this.sectionModels) throw new TypeError(\"ambientOcclusion requires sectionMeshing\");\n if (enabled === this._ambientOcclusion && !this.ambientOcclusionPending) {\n await this.culling;\n return;\n }\n this._ambientOcclusion = enabled;\n this.ambientOcclusionPending = true;\n for (const chunk of this._chunks.values()) this.pendingCulling.set(chunk, \"all\");\n await this.updateCulling([]);\n this.ambientOcclusionPending = false;\n }\n\n /** Horizontal biome-color sampling radius, from 0 to 7 blocks. Zero disables blending. */\n public get biomeBlendRadius(): number {\n return this._biomeBlendRadius;\n }\n\n /** Refreshes loaded grass, foliage, and water colors without reloading their source chunks. */\n public async setBiomeBlendRadius(radius: number): Promise<void> {\n validateBiomeBlendRadius(radius);\n if (radius > 0 && !this.sectionModels) throw new TypeError(\"biomeBlendRadius requires sectionMeshing\");\n if (radius !== this._biomeBlendRadius) {\n this._biomeBlendRadius = radius;\n this.biomeBlend?.clear();\n this.biomeBlend = radius ? new BiomeBlend((x, y, z) => this.getBiomeAt(x, y, z), radius) : undefined;\n for (const chunk of this._chunks.values()) this.pendingBiomes.set(chunk, undefined);\n }\n const failures = await this.refreshBiomes();\n if (failures.size) throw failures.values().next().value;\n }\n\n private markBiomesChanged(x: number, z: number, y?: number, includeColumn = true): Chunk<SectionMeshing>[] {\n const queued: Chunk<SectionMeshing>[] = [];\n if (!this.biomeBlend) return queued;\n this.biomeBlend.invalidateColumn(x, z);\n for (const chunk of this._chunks.values()) {\n if (Math.abs(chunk.x - x) > 1 || Math.abs(chunk.z - z) > 1\n || !includeColumn && chunk.x === x && chunk.z === z\n || y !== undefined && chunk.y !== y && chunk.y !== y + 1) continue;\n queued.push(chunk);\n if (!this.pendingBiomes.has(chunk)) this.pendingBiomes.set(chunk, []);\n const columns = this.pendingBiomes.get(chunk);\n if (columns && !columns.some(column => column.x === x && column.z === z)) columns.push({ x, z });\n }\n return queued;\n }\n\n private async refreshBiomes(deferCulling = false): Promise<Map<Chunk<SectionMeshing>, unknown>> {\n if (this.biomeRefreshing) {\n await this.biomeRefreshing;\n if (!deferCulling) {\n if (this.pendingCulling.size) await this.updateCulling([]);\n else await this.culling;\n }\n }\n if (!this.pendingBiomes.size) return new Map();\n return this.biomeRefreshing ??= Promise.resolve().then(async () => {\n const failures = new Map<Chunk<SectionMeshing>, unknown>();\n const batch = [...this.pendingBiomes.keys()];\n let sliceStart = performance.now();\n try {\n for (const chunk of batch) {\n const columns = this.pendingBiomes.get(chunk);\n this.pendingBiomes.delete(chunk);\n if (this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`) !== chunk) continue;\n try {\n await chunk.refreshBiomes(columns, deferCulling);\n } catch (error) {\n failures.set(chunk, error);\n if (this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`) === chunk) this.pendingBiomes.set(chunk, undefined);\n }\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n return failures;\n } finally {\n this.biomeRefreshing = undefined;\n }\n });\n }\n\n /** Returns a placed block at world block coordinates, or `undefined` for an empty position. */\n public getBlockAt(x: number, y: number, z: number): Maybe<BlockInfo<SectionMeshing>>;\n public getBlockAt(pos: Vector3): Maybe<BlockInfo<SectionMeshing>>;\n public getBlockAt(pos: TripleArray): Maybe<BlockInfo<SectionMeshing>>;\n public getBlockAt(posOrX: number | Vector3 | TripleArray, y?: number, z?: number): Maybe<BlockInfo<SectionMeshing>> {\n if (typeof posOrX == \"number\") {\n return this.getBlockAt(new Vector3(posOrX, y, z));\n }\n if (isTripleArray(posOrX)) {\n return this.getBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]))\n }\n this.validatePosBounds(posOrX);\n return this.getChunkAt(posOrX)?.getBlockAt(posOrX);\n }\n\n /** Returns the saved 4-block biome sample at integer world block coordinates, or `undefined` if absent. */\n public getBiomeAt(x: number, y: number, z: number): Maybe<string>;\n public getBiomeAt(pos: Vector3): Maybe<string>;\n public getBiomeAt(pos: TripleArray): Maybe<string>;\n public getBiomeAt(posOrX: number | Vector3 | TripleArray, y?: number, z?: number): Maybe<string> {\n if (typeof posOrX === \"number\") return this.getBiomeAt(new Vector3(posOrX, y, z));\n if (isTripleArray(posOrX)) return this.getBiomeAt(new Vector3(...posOrX));\n this.validatePosBounds(posOrX);\n const cx = Math.floor(posOrX.x / 16), cy = Math.floor(posOrX.y / 16), cz = Math.floor(posOrX.z / 16);\n const lx = posOrX.x - cx * 16, ly = posOrX.y - cy * 16, lz = posOrX.z - cz * 16;\n return this.biomes.get(`${cx}_${cz}`)?.get(cy)?.[\n Math.floor(lx / 4) + Math.floor(lz / 4) * 4 + Math.floor(ly / 4) * 16];\n }\n\n /**\n * Returns saved light at integer world block coordinates, including data marked invalid by the save.\n * Sky light is 15 above a column's highest saved sky-light array.\n */\n public getLightAt(x: number, y: number, z: number): Maybe<SavedLightSample>;\n public getLightAt(pos: Vector3): Maybe<SavedLightSample>;\n public getLightAt(pos: TripleArray): Maybe<SavedLightSample>;\n public getLightAt(posOrX: number | Vector3 | TripleArray, y?: number, z?: number): Maybe<SavedLightSample> {\n if (typeof posOrX === \"number\") return this.getLightAt(new Vector3(posOrX, y, z));\n if (isTripleArray(posOrX)) return this.getLightAt(new Vector3(...posOrX));\n this.validatePosBounds(posOrX);\n const { x, y: py, z: pz } = posOrX;\n const cx = Math.floor(x / 16), cy = Math.floor(py / 16), cz = Math.floor(pz / 16);\n const key = `${cx}_${cz}`, top = this.highestSkySection.get(key);\n const sample = sampleSectionLight(this.light.get(key)?.get(cy), (x & 15) + (pz & 15) * 16 + (py & 15) * 256);\n return top !== undefined && cy > top ? { block: sample?.block ?? 0, sky: 15 } : sample;\n }\n\n private lightLevelAt(x: number, y: number, z: number): number {\n const cx = Math.floor(x / 16), cy = Math.floor(y / 16), cz = Math.floor(z / 16), key = `${cx}_${cz}`;\n if (this.lightValidity.get(key) === false) return 255;\n const top = this.highestSkySection.get(key);\n if (top !== undefined && cy > top) return 15;\n const sample = sampleSectionLight(this.light.get(key)?.get(cy), (x & 15) + (z & 15) * 16 + (y & 15) * 256);\n return sample ? Math.max(sample.block, sample.sky) : 255;\n }\n\n /**\n * Places or replaces a block and refreshes neighboring faces.\n * Pass `undefined` or an air block to remove the block at these world block coordinates.\n */\n public async setBlockAt(x: number, y: number, z: number, block: Maybe<Block>): Promise<Maybe<BlockInfo<SectionMeshing>>>;\n public async setBlockAt(pos: Vector3, block: Maybe<Block>): Promise<Maybe<BlockInfo<SectionMeshing>>>;\n public async setBlockAt(pos: TripleArray, block: Maybe<Block>): Promise<Maybe<BlockInfo<SectionMeshing>>>;\n public async setBlockAt(posOrX: number | Vector3 | TripleArray, yOrBlock?: number | Block, z?: number, block?: Block): Promise<Maybe<BlockInfo<SectionMeshing>>> {\n if (typeof posOrX == \"number\") {\n return this.setBlockAt(new Vector3(posOrX, yOrBlock as number, z), block as Block);\n }\n if (isTripleArray(posOrX)) {\n return this.setBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock as Block);\n }\n return this.placeBlock(posOrX, yOrBlock as Maybe<Block>);\n }\n\n private async placeBlock(pos: Vector3, value: Maybe<Block>, onBlocksChanged?: (positions: Vector3[]) => Promise<void>): Promise<Maybe<BlockInfo<SectionMeshing>>> {\n this.validatePosBounds(pos);\n const chunk = Chunk.isAir(value) ? this.getChunkAt(pos) : this.getOrCreateChunkAt(pos);\n return chunk?.setBlockInChunkAt(chunk.worldPosToChunkPos(pos), value, pos, onBlocksChanged);\n }\n\n /**\n * Shows or hides a placed block without changing its data. Hidden blocks do not occlude neighbors.\n * Missing blocks are ignored; replacing or removing a block resets its visibility.\n */\n public async setBlockVisibleAt(x: number, y: number, z: number, visible: boolean): Promise<void>;\n public async setBlockVisibleAt(pos: Vector3, visible: boolean): Promise<void>;\n public async setBlockVisibleAt(pos: TripleArray, visible: boolean): Promise<void>;\n public async setBlockVisibleAt(posOrX: number | Vector3 | TripleArray, yOrVisible: number | boolean,\n z?: number, visible?: boolean): Promise<void> {\n if (typeof posOrX === \"number\") {\n return this.setBlockVisibleAt(new Vector3(posOrX, yOrVisible as number, z), visible!);\n }\n if (isTripleArray(posOrX)) {\n return this.setBlockVisibleAt(new Vector3(...posOrX), yOrVisible as boolean);\n }\n this.validatePosBounds(posOrX);\n await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible as boolean);\n }\n\n\n /**\n * Places a structure's blocks at their stored positions, then refreshes neighboring faces.\n * With `renderEntities`, also places supported saved mobs and applies supported appearance fields.\n *\n * @param useBatches - Yields between chunks by default. Set to `false` for sequential placement.\n * @param executor - Optional queue for batched placement. The caller remains responsible for stopping it.\n */\n public async placeMultiBlock(multiblock: MultiBlockStructure, useBatches: boolean = true, executor?: BatchedExecutor): Promise<void> {\n const placeEntities = this.entities?.prepare(multiblock.entities);\n const changes = new Map<string, Vector3>();\n try {\n await this.placeBlocks(multiblock, useBatches, executor, changes);\n await placeEntities?.();\n } finally {\n await this.updateCulling([...changes.values()]);\n }\n }\n\n private async placeBlocks(multiblock: MultiBlockStructure, useBatches: boolean, executor: BatchedExecutor | undefined,\n changes: Map<string, Vector3>): Promise<void> {\n const collect = async (positions: Vector3[]) => {\n for (const pos of positions) changes.set(pos.toArray().join(\",\"), pos);\n };\n const place = (block: MultiBlockBlock) => this.placeBlock(new Vector3(...block.position), block, collect);\n const keys = new Map<string, AssetKey>();\n const types = new Set<string>();\n for (const block of multiblock.blocks) {\n if (Chunk.isAir(block) || types.has(block.type)) continue;\n types.add(block.type);\n const key = AssetKey.parse(\"blockstates\", block.type);\n keys.set(key.serialize(), key);\n }\n await BlockStates.getAll(keys.values());\n\n if (!useBatches) {\n for (const block of multiblock.blocks) await place(block);\n return;\n }\n\n if (!executor) {\n const groups = new Map<Chunk<SectionMeshing>, { index: number; block: Maybe<Block> }[]>();\n const position = new Vector3();\n for (const block of multiblock.blocks) {\n const [x, y, z] = block.position;\n this.validatePosBounds(position.set(x, y, z));\n const cx = Math.floor(x / 16), cy = Math.floor(y / 16), cz = Math.floor(z / 16);\n const key = `${cx}_${cy}_${cz}`;\n const chunk = this._chunks.get(key) ?? (Chunk.isAir(block) ? undefined : this.getOrCreateChunkAt(position));\n if (!chunk) continue;\n let group = groups.get(chunk);\n if (!group) groups.set(chunk, group = []);\n group.push({ index: (y - cy * 16) * 256 + (z - cz * 16) * 16 + x - cx * 16, block });\n }\n await this.placeChunkGroups(groups, changes);\n return;\n }\n\n // Writes to the same position retain their input order.\n const positions = new Map<string, MultiBlockBlock[]>();\n for (const block of multiblock.blocks) {\n const key = block.position.join(\",\");\n const group = positions.get(key);\n if (group) group.push(block);\n else positions.set(key, [block]);\n }\n const groups = [...positions.values()];\n for (let i = 0; i < groups.length; i += executor.batch) {\n const results = await Promise.allSettled(groups.slice(i, i + executor.batch).map(blocks =>\n executor.submit(async () => {\n for (const block of blocks) await place(block);\n })\n ));\n const failure = results.find(result => result.status === \"rejected\");\n if (failure?.status === \"rejected\") throw failure.reason;\n }\n }\n\n private async placeChunkGroups(groups: Map<Chunk<SectionMeshing>, { index: number; block: Maybe<Block> }[]>,\n changes: Map<string, Vector3>): Promise<void> {\n let sliceStart = performance.now();\n for (const [chunk, blocks] of groups) {\n let positions: Vector3[] | undefined;\n try {\n positions = await chunk.placeBlocks(blocks);\n } finally {\n // Failed groups still clear cells and place their remaining blocks.\n positions ??= blocks.map(({ index }) => new Vector3(chunk.x * 16 + index % 16,\n chunk.y * 16 + Math.floor(index / 256), chunk.z * 16 + Math.floor(index / 16) % 16));\n for (const pos of positions) changes.set(`${pos.x},${pos.y},${pos.z}`, pos);\n }\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n }\n\n\n /** Replaces a chunk column's blocks, biomes, and saved light and, with `renderEntities`, its supported saved mobs. */\n public async placeChunk(chunk: AnvilChunk, executor?: BatchedExecutor): Promise<void> {\n return this.placeColumn(chunk, executor);\n }\n\n /**\n * Replaces parsed columns in input order, then refreshes neighboring geometry once.\n * Duplicate coordinates retain their order. A failed column stops placement; queued refreshes finish before rejection.\n */\n public async placeChunks(chunks: readonly AnvilChunk[]): Promise<void> {\n const columns: AnvilChunk[] = [];\n for (const chunk of chunks) {\n const { x, z } = chunk ?? {};\n if (![x, z].every(Number.isSafeInteger)) {\n throw new RangeError(\"Chunk column coordinates must be safe integers\");\n }\n const sections = Array.from(chunk.sections, section => {\n const { y } = section ?? {};\n if (!Number.isSafeInteger(y)) throw new RangeError(\"Chunk section coordinates must be safe integers\");\n return { ...section, y };\n });\n columns.push({ ...chunk, x, z, sections });\n }\n if (!columns.length) return;\n await this.culling;\n let failed = false, failure: unknown, sliceStart = performance.now();\n try {\n for (const column of columns) {\n await this.placeColumn(column, undefined, true);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n } catch (error) {\n failed = true;\n failure = error;\n } finally {\n try {\n const failures = await this.refreshBiomes(true);\n if (failures.size) log.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n } catch (error) {\n if (!failed) { failed = true; failure = error; }\n }\n try {\n await this.updateCulling([]);\n } catch (error) {\n if (!failed) { failed = true; failure = error; }\n }\n }\n if (failed) throw failure;\n }\n\n private async placeColumn(chunk: AnvilChunk, executor?: BatchedExecutor, deferCulling = false): Promise<void> {\n if (![chunk.x, chunk.z].every(Number.isSafeInteger)) {\n throw new RangeError(\"Chunk column coordinates must be safe integers\");\n }\n if (!chunk.sections.every(section => Number.isSafeInteger(section.y))) {\n throw new RangeError(\"Chunk section coordinates must be safe integers\");\n }\n const lights = new Map<number, SectionLightData>();\n for (const section of chunk.sections) {\n const light = section.light ?? (chunk.lightValid === true ? {} : undefined);\n if (light) lights.set(section.y, copySectionLight(light));\n }\n this.entities?.clearColumn(chunk.x, chunk.z);\n const placeEntities = this.entities?.prepare(chunk.entities, [chunk.x, chunk.z]);\n const changes = new Map<string, Vector3>();\n const occupiedSections = new Set<number>();\n if (!executor) {\n for (const section of chunk.sections) {\n for (let index = 0; index < 4096; index++) {\n if (!section.data.idAt(index)) continue;\n occupiedSections.add(section.y);\n break;\n }\n }\n }\n try {\n await this.clearChunkColumn(chunk.x, chunk.z);\n const columnKey = `${chunk.x}_${chunk.z}`;\n if (lights.size) this.light.set(columnKey, lights);\n for (const [y, light] of lights) {\n if (light.sky) this.highestSkySection.set(columnKey, Math.max(y, this.highestSkySection.get(columnKey) ?? -Infinity));\n }\n if (chunk.lightValid !== undefined) this.lightValidity.set(columnKey, chunk.lightValid);\n if (this.savedLighting) {\n for (const y of lights.keys()) this.markSectionChanged({ x: chunk.x, y, z: chunk.z });\n }\n // Tall plants can sample the section below, so install all biomes before rendering.\n for (const section of chunk.sections) {\n if (section.biomes) {\n const position = new Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);\n this.validatePosBounds(position);\n const copy = [...section.biomes];\n if (copy.length !== 64 || !copy.every(id => typeof id === \"string\" && id.length > 0)) {\n throw new RangeError(\"Section biomes must contain 64 nonempty biome IDs\");\n }\n const key = `${chunk.x}_${chunk.z}`;\n let column = this.biomes.get(key);\n if (!column) this.biomes.set(key, column = new Map());\n column.set(section.y, copy);\n }\n }\n let sliceStart = performance.now();\n for (const section of chunk.sections) {\n if (!executor) {\n if (!occupiedSections.has(section.y)) continue;\n const position = new Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);\n this.validatePosBounds(position);\n const target = this.getOrCreateChunkAt(position);\n try {\n await target.placeSection(section.data);\n } finally {\n this.markSectionChanged(target);\n }\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n continue;\n }\n const blocks: MultiBlockBlock[] = [];\n for (let index = 0; index < 4096; index++) {\n const block = section.data.get(index);\n if (block) blocks.push({\n ...block,\n position: [chunk.x * 16 + index % 16,\n section.y * 16 + Math.floor(index / 256),\n chunk.z * 16 + Math.floor(index / 16) % 16]\n });\n }\n await this.placeBlocks({ size: [16, 16, 16], blocks }, true, executor, changes);\n }\n await placeEntities?.();\n } finally {\n this.markBiomesChanged(chunk.x, chunk.z, undefined, false);\n if (deferCulling) await this.updateCulling([...changes.values()], true);\n else {\n const failures = await this.refreshBiomes();\n if (failures.size) log.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n await this.updateCulling([...changes.values()]);\n }\n }\n }\n\n /**\n * Removes blocks and owned entities at chunk-column coordinates, then refreshes neighboring faces and fluids.\n * Coordinates match AnvilChunk.x/z, not block positions. Missing columns are ignored.\n */\n public async unloadChunkColumn(x: number, z: number): Promise<void> {\n return this.unloadChunkColumns([{ x, z }]);\n }\n\n /**\n * Removes chunk columns together and refreshes surviving neighbors once.\n * Coordinates are absolute chunk columns. Duplicate and missing columns are ignored.\n */\n public async unloadChunkColumns(positions: readonly { x: number; z: number }[]): Promise<void> {\n const columns = new Map<string, { x: number; z: number }>();\n for (const position of positions) {\n const { x, z } = position ?? {};\n if (!Number.isInteger(x) || !Number.isInteger(z)) {\n throw new RangeError(\"Chunk column coordinates must be integers\");\n }\n columns.set(`${x}_${z}`, { x, z });\n }\n if (!columns.size) return;\n await this.culling;\n let sliceStart = performance.now();\n try {\n for (const { x, z } of columns.values()) {\n this.entities?.clearColumn(x, z);\n await this.clearChunkColumn(x, z);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n } finally {\n const failures = await this.refreshBiomes(true);\n if (failures.size) log.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n await this.updateCulling([]);\n }\n }\n\n private async clearChunkColumn(x: number, z: number): Promise<void> {\n this.biomes.delete(`${x}_${z}`);\n this.markBiomesChanged(x, z, undefined, false);\n if (this.savedLighting) {\n for (const y of this.light.get(`${x}_${z}`)?.keys() ?? []) this.markSectionChanged({ x, y, z });\n }\n this.light.delete(`${x}_${z}`);\n this.lightValidity.delete(`${x}_${z}`);\n this.highestSkySection.delete(`${x}_${z}`);\n const previous = [...this._chunks.entries()].filter(([, section]) => section.x === x && section.z === z);\n for (const [key, section] of previous) {\n this._chunks.delete(key);\n this.pendingCulling.delete(section);\n this.pendingBiomes.delete(section);\n await section.clear(false);\n this.markSectionChanged(section);\n }\n }\n\n private markSectionChanged(chunk: { x: number; y: number; z: number }): void {\n const current = this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`);\n if (current && current === chunk) this.pendingCulling.set(current, \"all\");\n for (let dy = -1; dy <= 1; dy++) {\n for (let dz = -1; dz <= 1; dz++) {\n for (let dx = -1; dx <= 1; dx++) {\n if (dx === 0 && dy === 0 && dz === 0) continue;\n const neighbor = this._chunks.get(`${chunk.x + dx}_${chunk.y + dy}_${chunk.z + dz}`);\n if (!neighbor) continue;\n let pending = this.pendingCulling.get(neighbor);\n if (pending === \"all\") continue;\n if (!pending) this.pendingCulling.set(neighbor, pending = new Set());\n for (let y = dy < 0 ? 15 : 0; y <= (dy > 0 ? 0 : 15); y++) {\n for (let z = dz < 0 ? 15 : 0; z <= (dz > 0 ? 0 : 15); z++) {\n for (let x = dx < 0 ? 15 : 0; x <= (dx > 0 ? 0 : 15); x++) {\n pending.add(y * 256 + z * 16 + x);\n }\n }\n }\n }\n }\n }\n }\n\n /** Removes all chunks and releases their blocks, section meshes, and owned entities. */\n public async clear(): Promise<void> {\n this.entities?.clear();\n await this.culling;\n const chunks = [...this._chunks.values()];\n this._chunks.clear();\n this.biomes.clear();\n this.biomeBlend?.clear();\n this.pendingBiomes.clear();\n this.light.clear();\n this.lightValidity.clear();\n this.highestSkySection.clear();\n for (const chunk of chunks) {\n await chunk.dispose();\n }\n this.sectionModels?.clear();\n }\n\n private updateCulling(positions: Vector3[], defer = false): Promise<void> {\n const neighbor = new Vector3();\n for (const pos of positions) {\n const cx = Math.floor(pos.x / 16), cy = Math.floor(pos.y / 16), cz = Math.floor(pos.z / 16);\n const chunk = this._chunks.get(`${cx}_${cy}_${cz}`);\n const lx = pos.x - cx * 16, ly = pos.y - cy * 16, lz = pos.z - cz * 16;\n // Fluid surfaces and ambient occlusion also depend on edge and corner neighbors.\n for (let y = -1; y <= 1; y++) {\n for (let z = -1; z <= 1; z++) {\n for (let x = -1; x <= 1; x++) {\n const nx = lx + x, ny = ly + y, nz = lz + z;\n const section = nx >= 0 && nx < 16 && ny >= 0 && ny < 16 && nz >= 0 && nz < 16 ? chunk\n : this._chunks.get(`${cx + Math.floor(nx / 16)}_${cy + Math.floor(ny / 16)}_${cz + Math.floor(nz / 16)}`);\n if (!section) continue;\n const index = (ny & 15) * 256 + (nz & 15) * 16 + (nx & 15);\n let pending = this.pendingCulling.get(section);\n if (pending === \"all\" || pending?.has(index)) continue;\n if (Math.abs(x) + Math.abs(y) + Math.abs(z) > 1\n && !this._ambientOcclusion && !section.isFluidIndex(index)) continue;\n if (!pending) this.pendingCulling.set(section, pending = new Set());\n pending.add(index);\n }\n }\n }\n }\n if (defer) return Promise.resolve();\n // Adjacent batched placements share one drain so they cannot replace the same model concurrently.\n return this.culling ??= Promise.resolve().then(async () => {\n let sliceStart = performance.now();\n try {\n const culling = await loadBlockCulling();\n while (this.pendingCulling.size) {\n const batch = new Map(this.pendingCulling);\n this.pendingCulling.clear();\n try {\n for (const [chunk, indices] of batch) {\n const neighbors = CUBE_FACE_OFFSETS.map(([x, y, z]) =>\n this._chunks.get(`${chunk.x + x}_${chunk.y + y}_${chunk.z + z}`));\n const neighborAt = (x: number, y: number, z: number): [Maybe<Chunk<SectionMeshing>>, number] => {\n const lx = x - chunk.x * 16, ly = y - chunk.y * 16, lz = z - chunk.z * 16;\n const section = neighbors[lx >= 16 ? 0 : lx < 0 ? 1 : ly >= 16 ? 2 : ly < 0 ? 3 : lz >= 16 ? 4 : 5];\n return [section, (ly & 15) * 256 + (lz & 15) * 16 + (lx & 15)];\n };\n const masks = chunk.updateCullMasks(indices === \"all\" ? undefined : indices, (x, y, z) => {\n const [section, i] = neighborAt(x, y, z);\n return section?.isOccludingIndex(i) ?? false;\n }, culling, (x, y, z) => {\n const [section, i] = neighborAt(x, y, z);\n return section?.visibleBlockIndex(i);\n });\n const fluidIndices = indices === \"all\" ? (function* () {\n for (let index = 0; index < 4096; index++) yield index;\n })() : indices;\n for (const index of fluidIndices) {\n if (!chunk.fluidByteIndex(index) || !chunk.isBlockVisibleIndex(index)) continue;\n const lx = index % 16, ly = Math.floor(index / 256), lz = Math.floor(index / 16) % 16;\n const wx = chunk.x * 16 + lx, wy = chunk.y * 16 + ly, wz = chunk.z * 16 + lz;\n const block = chunk.getBlockAt(neighbor.set(wx, wy, wz))!;\n if (block.object?.fluidKind) {\n await block.object.updateFluid((x, y, z) => {\n const nx = lx + x, ny = ly + y, nz = lz + z;\n const section = nx >= 0 && nx < 16 && ny >= 0 && ny < 16 && nz >= 0 && nz < 16 ? chunk\n : this._chunks.get(`${chunk.x + Math.floor(nx / 16)}_${chunk.y + Math.floor(ny / 16)}_${chunk.z + Math.floor(nz / 16)}`);\n const neighborIndex = (ny & 15) * 256 + (nz & 15) * 16 + (nx & 15);\n const byte = section?.fluidByteIndex(neighborIndex) ?? 0;\n return { fluid: fluidKindOf(byte), level: byte & 15,\n solid: section?.isOccludingIndex(neighborIndex) ?? false };\n });\n }\n }\n for (const [index, mask] of masks) await chunk.setCullMaskIndex(index, mask);\n await chunk.refreshLight(indices === \"all\" ? undefined : indices);\n chunk.refreshAmbientOcclusion(this._ambientOcclusion);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n const pending: Promise<void>[] = [];\n for (const chunk of [...batch.keys()]) {\n const build = (async () => {\n await chunk.rebuildSectionMesh();\n batch.delete(chunk);\n })();\n // Handle rejections while dispatch yields; all started builds settle before their results are checked.\n void build.catch(() => undefined);\n pending.push(build);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n const builds = await Promise.allSettled(pending);\n const failure = builds.find(result => result.status === \"rejected\");\n if (failure?.status === \"rejected\") throw failure.reason;\n } catch (error) {\n for (const [chunk, indices] of batch) {\n const pending = this.pendingCulling.get(chunk);\n this.pendingCulling.set(chunk, indices === \"all\" || pending === \"all\" ? \"all\"\n : new Set([...indices, ...pending ?? []]));\n }\n throw error;\n }\n }\n } finally {\n this.culling = undefined;\n }\n });\n }\n\n private getOrCreateChunkAt(pos: Vector3): Chunk<SectionMeshing> {\n const key = this.worldPosToChunkKey(pos);\n let chunk = this._chunks.get(key);\n if (typeof chunk === \"undefined\") {\n const x = Math.floor(pos.x / 16), y = Math.floor(pos.y / 16), z = Math.floor(pos.z / 16);\n chunk = new Chunk<SectionMeshing>(this.scene, x, y, z,\n (positions, defer) => this.updateCulling(positions, defer), this.sectionModels, (x, y, z) => {\n const cx = Math.floor(x / 16), cy = Math.floor(y / 16), cz = Math.floor(z / 16);\n const section = this._chunks.get(`${cx}_${cy}_${cz}`);\n const index = (y - cy * 16) * 256 + (z - cz * 16) * 16 + x - cx * 16;\n return (section?.fluidByteIndex(index) ?? 0) | (section?.isOccludingIndex(index) ? 64 : 0);\n }, (x, y, z) => this.getBiomeAt(x, y, z), async biomes => {\n if (this._chunks.get(key) !== chunk) return;\n const columnKey = `${x}_${z}`;\n let column = this.biomes.get(columnKey);\n if (biomes) {\n if (!column) this.biomes.set(columnKey, column = new Map());\n column.set(y, biomes);\n } else {\n column?.delete(y);\n if (!column?.size) this.biomes.delete(columnKey);\n }\n if (this.biomeBlend) {\n const queued = this.markBiomesChanged(x, z, y);\n const failures = await this.refreshBiomes();\n for (const chunk of queued) if (failures.has(chunk)) throw failures.get(chunk);\n } else {\n await chunk!.refreshBiomes();\n // Upper tall-plant halves at the boundary sample the section below.\n await this._chunks.get(`${x}_${y + 1}_${z}`)?.refreshBiomes();\n }\n }, this.savedLighting ? (x, y, z) => this.lightLevelAt(x, y, z) : undefined, async () => {\n if (this._chunks.get(key) !== chunk) return;\n const columnKey = `${x}_${z}`, column = this.light.get(columnKey);\n if (!column?.delete(y)) return;\n if (!column.size) this.light.delete(columnKey);\n this.highestSkySection.delete(columnKey);\n for (const [y, light] of column) {\n if (light.sky) this.highestSkySection.set(columnKey, Math.max(y, this.highestSkySection.get(columnKey) ?? -Infinity));\n }\n if (this.savedLighting) {\n this.markSectionChanged(chunk!);\n await this.updateCulling([]);\n }\n }, this.ambientLight, () => this.biomeBlend);\n this._chunks.set(key, chunk);\n }\n return chunk;\n }\n\n /** Returns the loaded chunk containing a world block position, without creating a chunk. */\n public getChunkAt(pos: Vector3): Maybe<Chunk<SectionMeshing>> {\n return this._chunks.get(this.worldPosToChunkKey(pos));\n }\n\n\n /** Converts block coordinates to scene units by multiplying each component by 16. */\n static worldToScenePosition(pos: Vector3): Vector3 {\n return new Vector3(\n pos.x * 16.0,\n pos.y * 16.0,\n pos.z * 16.0\n );\n }\n\n /** Converts scene units to block coordinates without rounding to an integer block. */\n static sceneToWorldPosition(pos: Vector3): Vector3 {\n return new Vector3(\n pos.x / 16.0,\n pos.y / 16.0,\n pos.z / 16.0\n );\n }\n\n worldPosToChunkKey(pos: Vector3): string {\n const chunkX = Math.floor(pos.x / 16);\n const chunkY = Math.floor(pos.y / 16);\n const chunkZ = Math.floor(pos.z / 16);\n return `${chunkX}_${chunkY}_${chunkZ}`;\n }\n\n validatePosBounds(pos: Vector3): void {\n if (![pos.x, pos.y, pos.z].every(Number.isInteger)) {\n throw new RangeError(\"Block coordinates must be integers\");\n }\n }\n\n}\n\n\n/** Settings passed as the second argument to `new MineRenderWorld(scene, options)`. */\nexport interface MineRenderWorldOptions<SectionMeshing extends boolean = boolean> {\n /** Render supported saved mobs at their position and yaw, including supported appearance fields. Defaults to false. */\n renderEntities?: boolean;\n /** Merge static opaque cubes into section meshes. Merged blocks have no individual object. */\n sectionMeshing?: SectionMeshing;\n /** Shade blocks and fluids with saved sky/block light. Missing or invalid data keeps preview brightness. Defaults to false. Requires `sectionMeshing`. */\n savedLighting?: boolean;\n /** Minimum brightness for saved lighting, from 0 to 1, like a dimension type's `ambient_light`. Defaults to 0. */\n ambientLight?: number;\n /** Bake corner shading from neighboring opaque full cubes. Defaults to false; no per-frame shading pass is added. Requires `sectionMeshing`. */\n ambientOcclusion?: boolean;\n /** Average neighboring biome colors within this horizontal radius, from 0 to 7 blocks. Defaults to 0 (off). Requires `sectionMeshing`. */\n biomeBlendRadius?: number;\n /** Maximum width and height of each section atlas page, in pixels. */\n maxAtlasSize?: number;\n}\n"],"mappings":";AAEA,SAAoB,eAAe;AACnC,SAAS,qBAAkC;AAC3C,SAAgB,wBAAwB;AACxC,SAAS,aAAa;AAItB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAElC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAG5B,SAAS,YAAY,gCAAgC;AACrD,SAAS,kBAAkB,0BAA8D;AACzF,SAAS,wBAAwB;AACjC,SAAS,cAAc;AAEvB,IAAM,MAAM,OAAO,iBAAiB;AACpC,IAAM,oBAAoB;AAQnB,IAAM,kBAAN,MAA8D;AAAA,EAsBjE,YAAY,OAAwB,UAAkD,CAAC,GAAG;AAlB1F,SAAiB,UAA8C,oBAAI,IAAI;AACvE,SAAiB,SAAS,oBAAI,IAA4C;AAC1E,SAAiB,QAAQ,oBAAI,IAA2C;AACxE,SAAiB,gBAAgB,oBAAI,IAAqB;AAC1D,SAAiB,oBAAoB,oBAAI,IAAoB;AAI7D,SAAQ,0BAA0B;AAGlC,SAAiB,gBAAgB,oBAAI,IAAmE;AAIxG,SAAiB,iBAAiB,oBAAI,IAAgD;AAIlF,QAAI,QAAQ,iBAAiB,CAAC,QAAQ,eAAgB,OAAM,IAAI,UAAU,uCAAuC;AACjH,QAAI,QAAQ,oBAAoB,CAAC,QAAQ,eAAgB,OAAM,IAAI,UAAU,0CAA0C;AACvH,QAAI,QAAQ,iBAAiB,WAAc,CAAC,OAAO,SAAS,QAAQ,YAAY,KAAK,QAAQ,eAAe,KAAK,QAAQ,eAAe,IAA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AAO,IAAI;AAAA,MACP,IAAI,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,IACZ;AAAA,EACJ;AAAA;AAAA,EAGA,OAAO,qBAAqB,KAAuB;AAC/C,WAAO,IAAI;AAAA,MACP,IAAI,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,IACZ;AAAA,EACJ;AAAA,EAEA,mBAAmB,KAAsB;AACrC,UAAM,SAAS,KAAK,MAAM,IAAI,IAAI,EAAE;AACpC,UAAM,SAAS,KAAK,MAAM,IAAI,IAAI,EAAE;AACpC,UAAM,SAAS,KAAK,MAAM,IAAI,IAAI,EAAE;AACpC,WAAO,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM;AAAA,EACxC;AAAA,EAEA,kBAAkB,KAAoB;AAClC,QAAI,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,EAAE,MAAM,OAAO,SAAS,GAAG;AAChD,YAAM,IAAI,WAAW,oCAAoC;AAAA,IAC7D;AAAA,EACJ;AAEJ;","names":["positions","groups","x","y","z","chunk"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/world/MineRenderWorld.ts"],"sourcesContent":["import { MineRenderScene } from \"../renderer/MineRenderScene\";\nimport { Block } from \"../model/block/Block\";\nimport { Raycaster, Vector3 } from \"three\";\nimport { isTripleArray, TripleArray } from \"../model/Model\";\nimport { Maybe, yieldToEventLoop } from \"../util/util\";\nimport { Chunk } from \"./Chunk\";\nimport { ChunkData } from \"./ChunkData\";\nimport { BlockInfo } from \"./BlockInfo\";\nimport { MultiBlockBlock, MultiBlockStructure } from \"../model/multiblock/MultiBlockStructure\";\nimport { BatchedExecutor } from \"../util/BatchedExecutor\";\nimport { AssetKey } from \"../assets/AssetKey\";\nimport { BlockStates } from \"../assets/BlockStates\";\nimport { BlockEntities } from \"../assets/BlockEntities\";\nimport { CUBE_FACE_OFFSETS } from \"../CubeFace\";\nimport type { AnvilChunk } from \"./AnvilParser\";\nimport { SectionModels } from \"./SectionModels\";\nimport { WorldEntities } from \"./_entities/WorldEntities\";\nimport { fluidKindOf } from \"../model/fluid/FluidQuads\";\nimport type { WorldBlockIntersection } from \"./WorldBlockIntersection\";\nimport type { WorldEntityIntersection } from \"./WorldEntityIntersection\";\nimport { BiomeBlend, validateBiomeBlendRadius } from \"./_biomes/BiomeBlend\";\nimport { copySectionLight, sampleSectionLight, SavedLightSample, SectionLightData } from \"./WorldLight\";\nimport { loadBlockCulling } from \"./_culling/BlockCulling\";\nimport { logger } from \"../util/log\";\n\nconst log = logger(\"MineRenderWorld\");\nconst YIELD_INTERVAL_MS = 8;\n\n//TODO: maybe make this an Object3D to add children\n/**\n * Stores and renders blocks in sparse 16×16×16 chunks.\n * Positions use integer block coordinates, including negatives. One block is 16 scene units.\n * Set `options.sectionMeshing` in `new MineRenderWorld(scene, options)` to merge compatible terrain.\n */\nexport class MineRenderWorld<SectionMeshing extends boolean = false> {\n\n public readonly scene: MineRenderScene;\n\n private readonly _chunks: Map<string, Chunk<SectionMeshing>> = new Map();\n private readonly biomes = new Map<string, Map<number, readonly string[]>>();\n private readonly light = new Map<string, Map<number, SectionLightData>>();\n private readonly lightValidity = new Map<string, boolean>();\n private readonly highestSkySection = new Map<string, number>();\n private readonly savedLighting: boolean;\n private readonly ambientLight: number;\n private _ambientOcclusion: boolean;\n private ambientOcclusionPending = false;\n private _biomeBlendRadius: number;\n private biomeBlend?: BiomeBlend;\n private readonly pendingBiomes = new Map<Chunk<SectionMeshing>, { x: number; z: number }[] | undefined>();\n private biomeRefreshing?: Promise<Map<Chunk<SectionMeshing>, unknown>>;\n private readonly sectionModels?: SectionModels;\n private readonly entities?: WorldEntities;\n private readonly pendingCulling = new Map<Chunk<SectionMeshing>, Set<number> | \"all\">();\n private culling?: Promise<void>;\n\n constructor(scene: MineRenderScene, options: MineRenderWorldOptions<SectionMeshing> = {}) {\n if (options.savedLighting && !options.sectionMeshing) throw new TypeError(\"savedLighting requires sectionMeshing\");\n if (options.ambientOcclusion && !options.sectionMeshing) throw new TypeError(\"ambientOcclusion requires sectionMeshing\");\n if (options.ambientLight !== undefined && (!Number.isFinite(options.ambientLight) || options.ambientLight < 0 || options.ambientLight > 1)) {\n throw new RangeError(\"ambientLight must be a number from 0 to 1\");\n }\n this._biomeBlendRadius = options.biomeBlendRadius ?? 0;\n validateBiomeBlendRadius(this._biomeBlendRadius);\n if (this._biomeBlendRadius > 0 && !options.sectionMeshing) throw new TypeError(\"biomeBlendRadius requires sectionMeshing\");\n if (this._biomeBlendRadius) this.biomeBlend = new BiomeBlend((x, y, z) => this.getBiomeAt(x, y, z), this._biomeBlendRadius);\n this.scene = scene;\n this.savedLighting = options.savedLighting ?? false;\n this.ambientLight = options.ambientLight ?? 0;\n this._ambientOcclusion = options.ambientOcclusion ?? false;\n if (options.sectionMeshing) this.sectionModels = new SectionModels(options.maxAtlasSize);\n if (options.renderEntities) this.entities = new WorldEntities(scene);\n }\n\n /**\n * Returns the nearest visible block geometry hit, respecting the raycaster's layers and near/far range.\n * Includes fluids and block entities; texture alpha does not change triangle intersections.\n */\n public raycast(raycaster: Raycaster): WorldBlockIntersection | undefined {\n return Chunk.raycast(this._chunks.values(), raycaster);\n }\n\n /**\n * Returns the nearest visible mob geometry hit when renderEntities is enabled.\n * Respects layers and near/far; compare its distance with raycast() to account for blocks.\n * Texture alpha does not change triangle intersections.\n */\n public raycastEntities(raycaster: Raycaster): WorldEntityIntersection | undefined {\n return this.entities?.raycast(raycaster);\n }\n\n /** Whether neighboring opaque cubes shade block-face corners. Defaults to false. */\n public get ambientOcclusion(): boolean {\n return this._ambientOcclusion;\n }\n\n /** Rebuilds loaded blocks with or without corner shading. Block data and saved lighting are preserved. */\n public async setAmbientOcclusion(enabled: boolean): Promise<void> {\n if (typeof enabled !== \"boolean\") throw new TypeError(\"Ambient occlusion must be a boolean\");\n if (enabled && !this.sectionModels) throw new TypeError(\"ambientOcclusion requires sectionMeshing\");\n if (enabled === this._ambientOcclusion && !this.ambientOcclusionPending) {\n await this.culling;\n return;\n }\n this._ambientOcclusion = enabled;\n this.ambientOcclusionPending = true;\n for (const chunk of this._chunks.values()) this.pendingCulling.set(chunk, \"all\");\n await this.updateCulling([]);\n this.ambientOcclusionPending = false;\n }\n\n /** Horizontal biome-color sampling radius, from 0 to 7 blocks. Zero disables blending. */\n public get biomeBlendRadius(): number {\n return this._biomeBlendRadius;\n }\n\n /** Refreshes loaded grass, foliage, and water colors without reloading their source chunks. */\n public async setBiomeBlendRadius(radius: number): Promise<void> {\n validateBiomeBlendRadius(radius);\n if (radius > 0 && !this.sectionModels) throw new TypeError(\"biomeBlendRadius requires sectionMeshing\");\n if (radius !== this._biomeBlendRadius) {\n this._biomeBlendRadius = radius;\n this.biomeBlend?.clear();\n this.biomeBlend = radius ? new BiomeBlend((x, y, z) => this.getBiomeAt(x, y, z), radius) : undefined;\n for (const chunk of this._chunks.values()) this.pendingBiomes.set(chunk, undefined);\n }\n const failures = await this.refreshBiomes();\n if (failures.size) throw failures.values().next().value;\n }\n\n private markBiomesChanged(x: number, z: number, y?: number, includeColumn = true): Chunk<SectionMeshing>[] {\n const queued: Chunk<SectionMeshing>[] = [];\n if (!this.biomeBlend) return queued;\n this.biomeBlend.invalidateColumn(x, z);\n for (const chunk of this._chunks.values()) {\n if (Math.abs(chunk.x - x) > 1 || Math.abs(chunk.z - z) > 1\n || !includeColumn && chunk.x === x && chunk.z === z\n || y !== undefined && chunk.y !== y && chunk.y !== y + 1) continue;\n queued.push(chunk);\n if (!this.pendingBiomes.has(chunk)) this.pendingBiomes.set(chunk, []);\n const columns = this.pendingBiomes.get(chunk);\n if (columns && !columns.some(column => column.x === x && column.z === z)) columns.push({ x, z });\n }\n return queued;\n }\n\n private async refreshBiomes(deferCulling = false): Promise<Map<Chunk<SectionMeshing>, unknown>> {\n if (this.biomeRefreshing) {\n await this.biomeRefreshing;\n if (!deferCulling) {\n if (this.pendingCulling.size) await this.updateCulling([]);\n else await this.culling;\n }\n }\n if (!this.pendingBiomes.size) return new Map();\n return this.biomeRefreshing ??= Promise.resolve().then(async () => {\n const failures = new Map<Chunk<SectionMeshing>, unknown>();\n const batch = [...this.pendingBiomes.keys()];\n let sliceStart = performance.now();\n try {\n for (const chunk of batch) {\n const columns = this.pendingBiomes.get(chunk);\n this.pendingBiomes.delete(chunk);\n if (this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`) !== chunk) continue;\n try {\n await chunk.refreshBiomes(columns, deferCulling);\n } catch (error) {\n failures.set(chunk, error);\n if (this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`) === chunk) this.pendingBiomes.set(chunk, undefined);\n }\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n return failures;\n } finally {\n this.biomeRefreshing = undefined;\n }\n });\n }\n\n /** Returns a placed block at world block coordinates, or `undefined` for an empty position. */\n public getBlockAt(x: number, y: number, z: number): Maybe<BlockInfo<SectionMeshing>>;\n public getBlockAt(pos: Vector3): Maybe<BlockInfo<SectionMeshing>>;\n public getBlockAt(pos: TripleArray): Maybe<BlockInfo<SectionMeshing>>;\n public getBlockAt(posOrX: number | Vector3 | TripleArray, y?: number, z?: number): Maybe<BlockInfo<SectionMeshing>> {\n if (typeof posOrX == \"number\") {\n return this.getBlockAt(new Vector3(posOrX, y, z));\n }\n if (isTripleArray(posOrX)) {\n return this.getBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]))\n }\n this.validatePosBounds(posOrX);\n return this.getChunkAt(posOrX)?.getBlockAt(posOrX);\n }\n\n /** Returns the saved 4-block biome sample at integer world block coordinates, or `undefined` if absent. */\n public getBiomeAt(x: number, y: number, z: number): Maybe<string>;\n public getBiomeAt(pos: Vector3): Maybe<string>;\n public getBiomeAt(pos: TripleArray): Maybe<string>;\n public getBiomeAt(posOrX: number | Vector3 | TripleArray, y?: number, z?: number): Maybe<string> {\n if (typeof posOrX === \"number\") return this.getBiomeAt(new Vector3(posOrX, y, z));\n if (isTripleArray(posOrX)) return this.getBiomeAt(new Vector3(...posOrX));\n this.validatePosBounds(posOrX);\n const cx = Math.floor(posOrX.x / 16), cy = Math.floor(posOrX.y / 16), cz = Math.floor(posOrX.z / 16);\n const lx = posOrX.x - cx * 16, ly = posOrX.y - cy * 16, lz = posOrX.z - cz * 16;\n return this.biomes.get(`${cx}_${cz}`)?.get(cy)?.[\n Math.floor(lx / 4) + Math.floor(lz / 4) * 4 + Math.floor(ly / 4) * 16];\n }\n\n /**\n * Returns saved light at integer world block coordinates, including data marked invalid by the save.\n * Sky light is 15 above a column's highest saved sky-light array.\n */\n public getLightAt(x: number, y: number, z: number): Maybe<SavedLightSample>;\n public getLightAt(pos: Vector3): Maybe<SavedLightSample>;\n public getLightAt(pos: TripleArray): Maybe<SavedLightSample>;\n public getLightAt(posOrX: number | Vector3 | TripleArray, y?: number, z?: number): Maybe<SavedLightSample> {\n if (typeof posOrX === \"number\") return this.getLightAt(new Vector3(posOrX, y, z));\n if (isTripleArray(posOrX)) return this.getLightAt(new Vector3(...posOrX));\n this.validatePosBounds(posOrX);\n const { x, y: py, z: pz } = posOrX;\n const cx = Math.floor(x / 16), cy = Math.floor(py / 16), cz = Math.floor(pz / 16);\n const key = `${cx}_${cz}`, top = this.highestSkySection.get(key);\n const sample = sampleSectionLight(this.light.get(key)?.get(cy), (x & 15) + (pz & 15) * 16 + (py & 15) * 256);\n return top !== undefined && cy > top ? { block: sample?.block ?? 0, sky: 15 } : sample;\n }\n\n private lightLevelAt(x: number, y: number, z: number): number {\n const cx = Math.floor(x / 16), cy = Math.floor(y / 16), cz = Math.floor(z / 16), key = `${cx}_${cz}`;\n if (this.lightValidity.get(key) === false) return 255;\n const top = this.highestSkySection.get(key);\n if (top !== undefined && cy > top) return 15;\n const sample = sampleSectionLight(this.light.get(key)?.get(cy), (x & 15) + (z & 15) * 16 + (y & 15) * 256);\n return sample ? Math.max(sample.block, sample.sky) : 255;\n }\n\n /**\n * Places or replaces a block and refreshes neighboring faces.\n * Pass `undefined` or an air block to remove the block at these world block coordinates.\n */\n public async setBlockAt(x: number, y: number, z: number, block: Maybe<Block>): Promise<Maybe<BlockInfo<SectionMeshing>>>;\n public async setBlockAt(pos: Vector3, block: Maybe<Block>): Promise<Maybe<BlockInfo<SectionMeshing>>>;\n public async setBlockAt(pos: TripleArray, block: Maybe<Block>): Promise<Maybe<BlockInfo<SectionMeshing>>>;\n public async setBlockAt(posOrX: number | Vector3 | TripleArray, yOrBlock?: number | Block, z?: number, block?: Block): Promise<Maybe<BlockInfo<SectionMeshing>>> {\n if (typeof posOrX == \"number\") {\n return this.setBlockAt(new Vector3(posOrX, yOrBlock as number, z), block as Block);\n }\n if (isTripleArray(posOrX)) {\n return this.setBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock as Block);\n }\n return this.placeBlock(posOrX, yOrBlock as Maybe<Block>);\n }\n\n private async placeBlock(pos: Vector3, value: Maybe<Block>, onBlocksChanged?: (positions: Vector3[]) => Promise<void>): Promise<Maybe<BlockInfo<SectionMeshing>>> {\n this.validatePosBounds(pos);\n const chunk = Chunk.isAir(value) ? this.getChunkAt(pos) : this.getOrCreateChunkAt(pos);\n return chunk?.setBlockInChunkAt(chunk.worldPosToChunkPos(pos), value, pos, onBlocksChanged);\n }\n\n /**\n * Shows or hides a placed block without changing its data. Hidden blocks do not occlude neighbors.\n * Missing blocks are ignored; replacing or removing a block resets its visibility.\n */\n public async setBlockVisibleAt(x: number, y: number, z: number, visible: boolean): Promise<void>;\n public async setBlockVisibleAt(pos: Vector3, visible: boolean): Promise<void>;\n public async setBlockVisibleAt(pos: TripleArray, visible: boolean): Promise<void>;\n public async setBlockVisibleAt(posOrX: number | Vector3 | TripleArray, yOrVisible: number | boolean,\n z?: number, visible?: boolean): Promise<void> {\n if (typeof posOrX === \"number\") {\n return this.setBlockVisibleAt(new Vector3(posOrX, yOrVisible as number, z), visible!);\n }\n if (isTripleArray(posOrX)) {\n return this.setBlockVisibleAt(new Vector3(...posOrX), yOrVisible as boolean);\n }\n this.validatePosBounds(posOrX);\n await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible as boolean);\n }\n\n\n /**\n * Places a structure's blocks at their stored positions, then refreshes neighboring faces.\n * With `renderEntities`, also places supported saved mobs and applies supported appearance fields.\n *\n * @param useBatches - Yields between chunks by default. Set to `false` for sequential placement.\n * @param executor - Optional queue for batched placement. The caller remains responsible for stopping it.\n */\n public async placeMultiBlock(multiblock: MultiBlockStructure, useBatches: boolean = true, executor?: BatchedExecutor): Promise<void> {\n const placeEntities = this.entities?.prepare(multiblock.entities);\n const changes = new Map<string, Vector3>();\n try {\n await this.placeBlocks(multiblock, useBatches, executor, changes);\n await placeEntities?.();\n } finally {\n await this.updateCulling([...changes.values()]);\n }\n }\n\n private async placeBlocks(multiblock: MultiBlockStructure, useBatches: boolean, executor: BatchedExecutor | undefined,\n changes: Map<string, Vector3>): Promise<void> {\n const collect = async (positions: Vector3[]) => {\n for (const pos of positions) changes.set(pos.toArray().join(\",\"), pos);\n };\n const place = (block: MultiBlockBlock) => this.placeBlock(new Vector3(...block.position), block, collect);\n const keys = new Map<string, AssetKey>();\n const types = new Set<string>();\n for (const block of multiblock.blocks) {\n if (Chunk.isAir(block) || types.has(block.type)) continue;\n types.add(block.type);\n const key = AssetKey.parse(\"blockstates\", block.type);\n keys.set(key.serialize(), key);\n }\n const loaded = await BlockStates.getAll(keys.values());\n const states = new Map([...keys.keys()].map((key, i) => [key, loaded[i]]));\n\n if (!useBatches) {\n for (const block of multiblock.blocks) await place(block);\n return;\n }\n\n if (!executor) {\n const groups = new Map<Chunk<SectionMeshing>, { index: number; block: Maybe<Block> }[]>();\n const distinct = new Map<string, MultiBlockBlock>();\n const position = new Vector3();\n for (const block of multiblock.blocks) {\n if (this.sectionModels && !Chunk.isAir(block)) distinct.set(ChunkData.paletteKey(block), block);\n const [x, y, z] = block.position;\n this.validatePosBounds(position.set(x, y, z));\n const cx = Math.floor(x / 16), cy = Math.floor(y / 16), cz = Math.floor(z / 16);\n const key = `${cx}_${cy}_${cz}`;\n const chunk = this._chunks.get(key) ?? (Chunk.isAir(block) ? undefined : this.getOrCreateChunkAt(position));\n if (!chunk) continue;\n let group = groups.get(chunk);\n if (!group) groups.set(chunk, group = []);\n group.push({ index: (y - cy * 16) * 256 + (z - cz * 16) * 16 + x - cx * 16, block });\n }\n if (this.sectionModels) {\n // States that first appear in later chunks load while earlier chunks are placed.\n for (const block of distinct.values()) {\n const state = states.get(AssetKey.parse(\"blockstates\", block.type).serialize());\n if (!state) continue;\n void (async () => {\n if (state.key && BlockEntities.entry(await BlockEntities.getIndex(state.key.root), state.key.toNamespacedString())) return;\n await this.sectionModels!.preload(state, block.properties);\n })().catch(() => undefined);\n }\n }\n await this.placeChunkGroups(groups, changes);\n return;\n }\n\n // Writes to the same position retain their input order.\n const positions = new Map<string, MultiBlockBlock[]>();\n for (const block of multiblock.blocks) {\n const key = block.position.join(\",\");\n const group = positions.get(key);\n if (group) group.push(block);\n else positions.set(key, [block]);\n }\n const groups = [...positions.values()];\n for (let i = 0; i < groups.length; i += executor.batch) {\n const results = await Promise.allSettled(groups.slice(i, i + executor.batch).map(blocks =>\n executor.submit(async () => {\n for (const block of blocks) await place(block);\n })\n ));\n const failure = results.find(result => result.status === \"rejected\");\n if (failure?.status === \"rejected\") throw failure.reason;\n }\n }\n\n private async placeChunkGroups(groups: Map<Chunk<SectionMeshing>, { index: number; block: Maybe<Block> }[]>,\n changes: Map<string, Vector3>): Promise<void> {\n let sliceStart = performance.now();\n for (const [chunk, blocks] of groups) {\n let positions: Vector3[] | undefined;\n try {\n positions = await chunk.placeBlocks(blocks);\n } finally {\n // Failed groups still clear cells and place their remaining blocks.\n positions ??= blocks.map(({ index }) => new Vector3(chunk.x * 16 + index % 16,\n chunk.y * 16 + Math.floor(index / 256), chunk.z * 16 + Math.floor(index / 16) % 16));\n for (const pos of positions) changes.set(`${pos.x},${pos.y},${pos.z}`, pos);\n }\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n }\n\n\n /** Replaces a chunk column's blocks, biomes, and saved light and, with `renderEntities`, its supported saved mobs. */\n public async placeChunk(chunk: AnvilChunk, executor?: BatchedExecutor): Promise<void> {\n return this.placeColumn(chunk, executor);\n }\n\n /**\n * Replaces parsed columns in input order, then refreshes neighboring geometry once.\n * Duplicate coordinates retain their order. A failed column stops placement; queued refreshes finish before rejection.\n */\n public async placeChunks(chunks: readonly AnvilChunk[]): Promise<void> {\n const columns: AnvilChunk[] = [];\n for (const chunk of chunks) {\n const { x, z } = chunk ?? {};\n if (![x, z].every(Number.isSafeInteger)) {\n throw new RangeError(\"Chunk column coordinates must be safe integers\");\n }\n const sections = Array.from(chunk.sections, section => {\n const { y } = section ?? {};\n if (!Number.isSafeInteger(y)) throw new RangeError(\"Chunk section coordinates must be safe integers\");\n return { ...section, y };\n });\n columns.push({ ...chunk, x, z, sections });\n }\n if (!columns.length) return;\n await this.culling;\n let failed = false, failure: unknown, sliceStart = performance.now();\n try {\n for (const column of columns) {\n await this.placeColumn(column, undefined, true);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n } catch (error) {\n failed = true;\n failure = error;\n } finally {\n try {\n const failures = await this.refreshBiomes(true);\n if (failures.size) log.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n } catch (error) {\n if (!failed) { failed = true; failure = error; }\n }\n try {\n await this.updateCulling([]);\n } catch (error) {\n if (!failed) { failed = true; failure = error; }\n }\n }\n if (failed) throw failure;\n }\n\n private async placeColumn(chunk: AnvilChunk, executor?: BatchedExecutor, deferCulling = false): Promise<void> {\n if (![chunk.x, chunk.z].every(Number.isSafeInteger)) {\n throw new RangeError(\"Chunk column coordinates must be safe integers\");\n }\n if (!chunk.sections.every(section => Number.isSafeInteger(section.y))) {\n throw new RangeError(\"Chunk section coordinates must be safe integers\");\n }\n const lights = new Map<number, SectionLightData>();\n for (const section of chunk.sections) {\n const light = section.light ?? (chunk.lightValid === true ? {} : undefined);\n if (light) lights.set(section.y, copySectionLight(light));\n }\n this.entities?.clearColumn(chunk.x, chunk.z);\n const placeEntities = this.entities?.prepare(chunk.entities, [chunk.x, chunk.z]);\n const changes = new Map<string, Vector3>();\n const occupiedSections = new Set<number>();\n if (!executor) {\n for (const section of chunk.sections) {\n for (let index = 0; index < 4096; index++) {\n if (!section.data.idAt(index)) continue;\n occupiedSections.add(section.y);\n break;\n }\n }\n }\n try {\n await this.clearChunkColumn(chunk.x, chunk.z);\n const columnKey = `${chunk.x}_${chunk.z}`;\n if (lights.size) this.light.set(columnKey, lights);\n for (const [y, light] of lights) {\n if (light.sky) this.highestSkySection.set(columnKey, Math.max(y, this.highestSkySection.get(columnKey) ?? -Infinity));\n }\n if (chunk.lightValid !== undefined) this.lightValidity.set(columnKey, chunk.lightValid);\n if (this.savedLighting) {\n for (const y of lights.keys()) this.markSectionChanged({ x: chunk.x, y, z: chunk.z });\n }\n // Tall plants can sample the section below, so install all biomes before rendering.\n for (const section of chunk.sections) {\n if (section.biomes) {\n const position = new Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);\n this.validatePosBounds(position);\n const copy = [...section.biomes];\n if (copy.length !== 64 || !copy.every(id => typeof id === \"string\" && id.length > 0)) {\n throw new RangeError(\"Section biomes must contain 64 nonempty biome IDs\");\n }\n const key = `${chunk.x}_${chunk.z}`;\n let column = this.biomes.get(key);\n if (!column) this.biomes.set(key, column = new Map());\n column.set(section.y, copy);\n }\n }\n let sliceStart = performance.now();\n for (const section of chunk.sections) {\n if (!executor) {\n if (!occupiedSections.has(section.y)) continue;\n const position = new Vector3(chunk.x * 16, section.y * 16, chunk.z * 16);\n this.validatePosBounds(position);\n const target = this.getOrCreateChunkAt(position);\n try {\n await target.placeSection(section.data);\n } finally {\n this.markSectionChanged(target);\n }\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n continue;\n }\n const blocks: MultiBlockBlock[] = [];\n for (let index = 0; index < 4096; index++) {\n const block = section.data.get(index);\n if (block) blocks.push({\n ...block,\n position: [chunk.x * 16 + index % 16,\n section.y * 16 + Math.floor(index / 256),\n chunk.z * 16 + Math.floor(index / 16) % 16]\n });\n }\n await this.placeBlocks({ size: [16, 16, 16], blocks }, true, executor, changes);\n }\n await placeEntities?.();\n } finally {\n this.markBiomesChanged(chunk.x, chunk.z, undefined, false);\n if (deferCulling) await this.updateCulling([...changes.values()], true);\n else {\n const failures = await this.refreshBiomes();\n if (failures.size) log.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n await this.updateCulling([...changes.values()]);\n }\n }\n }\n\n /**\n * Removes blocks and owned entities at chunk-column coordinates, then refreshes neighboring faces and fluids.\n * Coordinates match AnvilChunk.x/z, not block positions. Missing columns are ignored.\n */\n public async unloadChunkColumn(x: number, z: number): Promise<void> {\n return this.unloadChunkColumns([{ x, z }]);\n }\n\n /**\n * Removes chunk columns together and refreshes surviving neighbors once.\n * Coordinates are absolute chunk columns. Duplicate and missing columns are ignored.\n */\n public async unloadChunkColumns(positions: readonly { x: number; z: number }[]): Promise<void> {\n const columns = new Map<string, { x: number; z: number }>();\n for (const position of positions) {\n const { x, z } = position ?? {};\n if (!Number.isInteger(x) || !Number.isInteger(z)) {\n throw new RangeError(\"Chunk column coordinates must be integers\");\n }\n columns.set(`${x}_${z}`, { x, z });\n }\n if (!columns.size) return;\n await this.culling;\n let sliceStart = performance.now();\n try {\n for (const { x, z } of columns.values()) {\n this.entities?.clearColumn(x, z);\n await this.clearChunkColumn(x, z);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n } finally {\n const failures = await this.refreshBiomes(true);\n if (failures.size) log.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n await this.updateCulling([]);\n }\n }\n\n private async clearChunkColumn(x: number, z: number): Promise<void> {\n this.biomes.delete(`${x}_${z}`);\n this.markBiomesChanged(x, z, undefined, false);\n if (this.savedLighting) {\n for (const y of this.light.get(`${x}_${z}`)?.keys() ?? []) this.markSectionChanged({ x, y, z });\n }\n this.light.delete(`${x}_${z}`);\n this.lightValidity.delete(`${x}_${z}`);\n this.highestSkySection.delete(`${x}_${z}`);\n const previous = [...this._chunks.entries()].filter(([, section]) => section.x === x && section.z === z);\n for (const [key, section] of previous) {\n this._chunks.delete(key);\n this.pendingCulling.delete(section);\n this.pendingBiomes.delete(section);\n await section.clear(false);\n this.markSectionChanged(section);\n }\n }\n\n private markSectionChanged(chunk: { x: number; y: number; z: number }): void {\n const current = this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`);\n if (current && current === chunk) this.pendingCulling.set(current, \"all\");\n for (let dy = -1; dy <= 1; dy++) {\n for (let dz = -1; dz <= 1; dz++) {\n for (let dx = -1; dx <= 1; dx++) {\n if (dx === 0 && dy === 0 && dz === 0) continue;\n const neighbor = this._chunks.get(`${chunk.x + dx}_${chunk.y + dy}_${chunk.z + dz}`);\n if (!neighbor) continue;\n let pending = this.pendingCulling.get(neighbor);\n if (pending === \"all\") continue;\n if (!pending) this.pendingCulling.set(neighbor, pending = new Set());\n for (let y = dy < 0 ? 15 : 0; y <= (dy > 0 ? 0 : 15); y++) {\n for (let z = dz < 0 ? 15 : 0; z <= (dz > 0 ? 0 : 15); z++) {\n for (let x = dx < 0 ? 15 : 0; x <= (dx > 0 ? 0 : 15); x++) {\n pending.add(y * 256 + z * 16 + x);\n }\n }\n }\n }\n }\n }\n }\n\n /** Removes all chunks and releases their blocks, section meshes, and owned entities. */\n public async clear(): Promise<void> {\n this.entities?.clear();\n await this.culling;\n const chunks = [...this._chunks.values()];\n this._chunks.clear();\n this.biomes.clear();\n this.biomeBlend?.clear();\n this.pendingBiomes.clear();\n this.light.clear();\n this.lightValidity.clear();\n this.highestSkySection.clear();\n for (const chunk of chunks) {\n await chunk.dispose();\n }\n this.sectionModels?.clear();\n }\n\n private updateCulling(positions: Vector3[], defer = false): Promise<void> {\n const neighbor = new Vector3();\n for (const pos of positions) {\n const cx = Math.floor(pos.x / 16), cy = Math.floor(pos.y / 16), cz = Math.floor(pos.z / 16);\n const chunk = this._chunks.get(`${cx}_${cy}_${cz}`);\n const lx = pos.x - cx * 16, ly = pos.y - cy * 16, lz = pos.z - cz * 16;\n // Fluid surfaces and ambient occlusion also depend on edge and corner neighbors.\n for (let y = -1; y <= 1; y++) {\n for (let z = -1; z <= 1; z++) {\n for (let x = -1; x <= 1; x++) {\n const nx = lx + x, ny = ly + y, nz = lz + z;\n const section = nx >= 0 && nx < 16 && ny >= 0 && ny < 16 && nz >= 0 && nz < 16 ? chunk\n : this._chunks.get(`${cx + Math.floor(nx / 16)}_${cy + Math.floor(ny / 16)}_${cz + Math.floor(nz / 16)}`);\n if (!section) continue;\n const index = (ny & 15) * 256 + (nz & 15) * 16 + (nx & 15);\n let pending = this.pendingCulling.get(section);\n if (pending === \"all\" || pending?.has(index)) continue;\n if (Math.abs(x) + Math.abs(y) + Math.abs(z) > 1\n && !this._ambientOcclusion && !section.isFluidIndex(index)) continue;\n if (!pending) this.pendingCulling.set(section, pending = new Set());\n pending.add(index);\n }\n }\n }\n }\n if (defer) return Promise.resolve();\n // Adjacent batched placements share one drain so they cannot replace the same model concurrently.\n return this.culling ??= Promise.resolve().then(async () => {\n let sliceStart = performance.now();\n try {\n const culling = await loadBlockCulling();\n while (this.pendingCulling.size) {\n const batch = new Map(this.pendingCulling);\n this.pendingCulling.clear();\n try {\n for (const [chunk, indices] of batch) {\n const neighbors = CUBE_FACE_OFFSETS.map(([x, y, z]) =>\n this._chunks.get(`${chunk.x + x}_${chunk.y + y}_${chunk.z + z}`));\n const neighborAt = (x: number, y: number, z: number): [Maybe<Chunk<SectionMeshing>>, number] => {\n const lx = x - chunk.x * 16, ly = y - chunk.y * 16, lz = z - chunk.z * 16;\n const section = neighbors[lx >= 16 ? 0 : lx < 0 ? 1 : ly >= 16 ? 2 : ly < 0 ? 3 : lz >= 16 ? 4 : 5];\n return [section, (ly & 15) * 256 + (lz & 15) * 16 + (lx & 15)];\n };\n const masks = chunk.updateCullMasks(indices === \"all\" ? undefined : indices, (x, y, z) => {\n const [section, i] = neighborAt(x, y, z);\n return section?.isOccludingIndex(i) ?? false;\n }, culling, (x, y, z) => {\n const [section, i] = neighborAt(x, y, z);\n return section?.visibleBlockIndex(i);\n });\n const fluidIndices = indices === \"all\" ? (function* () {\n for (let index = 0; index < 4096; index++) yield index;\n })() : indices;\n for (const index of fluidIndices) {\n if (!chunk.fluidByteIndex(index) || !chunk.isBlockVisibleIndex(index)) continue;\n const lx = index % 16, ly = Math.floor(index / 256), lz = Math.floor(index / 16) % 16;\n const wx = chunk.x * 16 + lx, wy = chunk.y * 16 + ly, wz = chunk.z * 16 + lz;\n const block = chunk.getBlockAt(neighbor.set(wx, wy, wz))!;\n if (block.object?.fluidKind) {\n await block.object.updateFluid((x, y, z) => {\n const nx = lx + x, ny = ly + y, nz = lz + z;\n const section = nx >= 0 && nx < 16 && ny >= 0 && ny < 16 && nz >= 0 && nz < 16 ? chunk\n : this._chunks.get(`${chunk.x + Math.floor(nx / 16)}_${chunk.y + Math.floor(ny / 16)}_${chunk.z + Math.floor(nz / 16)}`);\n const neighborIndex = (ny & 15) * 256 + (nz & 15) * 16 + (nx & 15);\n const byte = section?.fluidByteIndex(neighborIndex) ?? 0;\n return { fluid: fluidKindOf(byte), level: byte & 15,\n solid: section?.isOccludingIndex(neighborIndex) ?? false };\n });\n }\n }\n for (const [index, mask] of masks) await chunk.setCullMaskIndex(index, mask);\n await chunk.refreshLight(indices === \"all\" ? undefined : indices);\n chunk.refreshAmbientOcclusion(this._ambientOcclusion);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n const pending: Promise<void>[] = [];\n for (const chunk of [...batch.keys()]) {\n const build = (async () => {\n await chunk.rebuildSectionMesh();\n batch.delete(chunk);\n })();\n // Handle rejections while dispatch yields; all started builds settle before their results are checked.\n void build.catch(() => undefined);\n pending.push(build);\n if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n const builds = await Promise.allSettled(pending);\n const failure = builds.find(result => result.status === \"rejected\");\n if (failure?.status === \"rejected\") throw failure.reason;\n } catch (error) {\n for (const [chunk, indices] of batch) {\n const pending = this.pendingCulling.get(chunk);\n this.pendingCulling.set(chunk, indices === \"all\" || pending === \"all\" ? \"all\"\n : new Set([...indices, ...pending ?? []]));\n }\n throw error;\n }\n }\n } finally {\n this.culling = undefined;\n }\n });\n }\n\n private getOrCreateChunkAt(pos: Vector3): Chunk<SectionMeshing> {\n const key = this.worldPosToChunkKey(pos);\n let chunk = this._chunks.get(key);\n if (typeof chunk === \"undefined\") {\n const x = Math.floor(pos.x / 16), y = Math.floor(pos.y / 16), z = Math.floor(pos.z / 16);\n chunk = new Chunk<SectionMeshing>(this.scene, x, y, z,\n (positions, defer) => this.updateCulling(positions, defer), this.sectionModels, (x, y, z) => {\n const cx = Math.floor(x / 16), cy = Math.floor(y / 16), cz = Math.floor(z / 16);\n const section = this._chunks.get(`${cx}_${cy}_${cz}`);\n const index = (y - cy * 16) * 256 + (z - cz * 16) * 16 + x - cx * 16;\n return (section?.fluidByteIndex(index) ?? 0) | (section?.isOccludingIndex(index) ? 64 : 0);\n }, (x, y, z) => this.getBiomeAt(x, y, z), async biomes => {\n if (this._chunks.get(key) !== chunk) return;\n const columnKey = `${x}_${z}`;\n let column = this.biomes.get(columnKey);\n if (biomes) {\n if (!column) this.biomes.set(columnKey, column = new Map());\n column.set(y, biomes);\n } else {\n column?.delete(y);\n if (!column?.size) this.biomes.delete(columnKey);\n }\n if (this.biomeBlend) {\n const queued = this.markBiomesChanged(x, z, y);\n const failures = await this.refreshBiomes();\n for (const chunk of queued) if (failures.has(chunk)) throw failures.get(chunk);\n } else {\n await chunk!.refreshBiomes();\n // Upper tall-plant halves at the boundary sample the section below.\n await this._chunks.get(`${x}_${y + 1}_${z}`)?.refreshBiomes();\n }\n }, this.savedLighting ? (x, y, z) => this.lightLevelAt(x, y, z) : undefined, async () => {\n if (this._chunks.get(key) !== chunk) return;\n const columnKey = `${x}_${z}`, column = this.light.get(columnKey);\n if (!column?.delete(y)) return;\n if (!column.size) this.light.delete(columnKey);\n this.highestSkySection.delete(columnKey);\n for (const [y, light] of column) {\n if (light.sky) this.highestSkySection.set(columnKey, Math.max(y, this.highestSkySection.get(columnKey) ?? -Infinity));\n }\n if (this.savedLighting) {\n this.markSectionChanged(chunk!);\n await this.updateCulling([]);\n }\n }, this.ambientLight, () => this.biomeBlend);\n this._chunks.set(key, chunk);\n }\n return chunk;\n }\n\n /** Returns the loaded chunk containing a world block position, without creating a chunk. */\n public getChunkAt(pos: Vector3): Maybe<Chunk<SectionMeshing>> {\n return this._chunks.get(this.worldPosToChunkKey(pos));\n }\n\n\n /** Converts block coordinates to scene units by multiplying each component by 16. */\n static worldToScenePosition(pos: Vector3): Vector3 {\n return new Vector3(\n pos.x * 16.0,\n pos.y * 16.0,\n pos.z * 16.0\n );\n }\n\n /** Converts scene units to block coordinates without rounding to an integer block. */\n static sceneToWorldPosition(pos: Vector3): Vector3 {\n return new Vector3(\n pos.x / 16.0,\n pos.y / 16.0,\n pos.z / 16.0\n );\n }\n\n worldPosToChunkKey(pos: Vector3): string {\n const chunkX = Math.floor(pos.x / 16);\n const chunkY = Math.floor(pos.y / 16);\n const chunkZ = Math.floor(pos.z / 16);\n return `${chunkX}_${chunkY}_${chunkZ}`;\n }\n\n validatePosBounds(pos: Vector3): void {\n if (![pos.x, pos.y, pos.z].every(Number.isInteger)) {\n throw new RangeError(\"Block coordinates must be integers\");\n }\n }\n\n}\n\n\n/** Settings passed as the second argument to `new MineRenderWorld(scene, options)`. */\nexport interface MineRenderWorldOptions<SectionMeshing extends boolean = boolean> {\n /** Render supported saved mobs at their position and yaw, including supported appearance fields. Defaults to false. */\n renderEntities?: boolean;\n /** Merge block models of any shape and fluid surfaces into per-section meshes; block entities keep individual objects. Merged blocks have no individual object. */\n sectionMeshing?: SectionMeshing;\n /** Shade blocks and fluids with saved sky/block light. Missing or invalid data keeps preview brightness. Defaults to false. Requires `sectionMeshing`. */\n savedLighting?: boolean;\n /** Minimum brightness for saved lighting, from 0 to 1, like a dimension type's `ambient_light`. Defaults to 0. */\n ambientLight?: number;\n /** Bake corner shading from neighboring opaque full cubes. Defaults to false; no per-frame shading pass is added. Requires `sectionMeshing`. */\n ambientOcclusion?: boolean;\n /** Average neighboring biome colors within this horizontal radius, from 0 to 7 blocks. Defaults to 0 (off). Requires `sectionMeshing`. */\n biomeBlendRadius?: number;\n /** Maximum width and height of each section atlas page, in pixels. Defaults to 2048. */\n maxAtlasSize?: number;\n}\n"],"mappings":";AAEA,SAAoB,eAAe;AACnC,SAAS,qBAAkC;AAC3C,SAAgB,wBAAwB;AACxC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAI1B,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAElC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAG5B,SAAS,YAAY,gCAAgC;AACrD,SAAS,kBAAkB,0BAA8D;AACzF,SAAS,wBAAwB;AACjC,SAAS,cAAc;AAEvB,IAAM,MAAM,OAAO,iBAAiB;AACpC,IAAM,oBAAoB;AAQnB,IAAM,kBAAN,MAA8D;AAAA,EAsBjE,YAAY,OAAwB,UAAkD,CAAC,GAAG;AAlB1F,SAAiB,UAA8C,oBAAI,IAAI;AACvE,SAAiB,SAAS,oBAAI,IAA4C;AAC1E,SAAiB,QAAQ,oBAAI,IAA2C;AACxE,SAAiB,gBAAgB,oBAAI,IAAqB;AAC1D,SAAiB,oBAAoB,oBAAI,IAAoB;AAI7D,SAAQ,0B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,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,IACZ;AAAA,EACJ;AAAA,EAEA,mBAAmB,KAAsB;AACrC,UAAM,SAAS,KAAK,MAAM,IAAI,IAAI,EAAE;AACpC,UAAM,SAAS,KAAK,MAAM,IAAI,IAAI,EAAE;AACpC,UAAM,SAAS,KAAK,MAAM,IAAI,IAAI,EAAE;AACpC,WAAO,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM;AAAA,EACxC;AAAA,EAEA,kBAAkB,KAAoB;AAClC,QAAI,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,EAAE,MAAM,OAAO,SAAS,GAAG;AAChD,YAAM,IAAI,WAAW,oCAAoC;AAAA,IAC7D;AAAA,EACJ;AAEJ;","names":["positions","groups","x","y","z","chunk"]}
|
|
@@ -93,6 +93,10 @@ var SectionModels = class {
|
|
|
93
93
|
biomeTint: source ? [...templates.values()].some((template) => template.biomeTint?.some((value) => value === 1)) || void 0 : void 0
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
/** Starts loading the state's models and atlases so a later `prepareState` with the same properties finds them loaded. */
|
|
97
|
+
async preload(blockState, properties = {}) {
|
|
98
|
+
await this.state(blockState, properties);
|
|
99
|
+
}
|
|
96
100
|
async state(blockState, properties) {
|
|
97
101
|
let states = this.states.get(blockState);
|
|
98
102
|
if (!states) this.states.set(blockState, states = /* @__PURE__ */ new Map());
|
|
@@ -115,22 +119,24 @@ var SectionModels = class {
|
|
|
115
119
|
async prepare(blockState, properties) {
|
|
116
120
|
const state = { ...await BlockStateResolver.defaults(blockState), ...properties };
|
|
117
121
|
const groups = BlockStateResolver.matching(blockState, state);
|
|
118
|
-
if (!groups.length) return void 0;
|
|
122
|
+
if (!groups.length || groups.some((group) => Array.isArray(group) && !group.length)) return void 0;
|
|
123
|
+
const variants = groups.flatMap((group) => Array.isArray(group) ? group : [group]);
|
|
124
|
+
if (variants.some((variant) => !variant.model)) return void 0;
|
|
125
|
+
const settled = await Promise.allSettled(variants.map(async (variant) => {
|
|
126
|
+
const modelKey = AssetKey.parse("models", variant.model);
|
|
127
|
+
modelKey.root = blockState.key?.root;
|
|
128
|
+
const model = await Models.getMerged(modelKey);
|
|
129
|
+
if (!model?.elements?.length) return void 0;
|
|
130
|
+
const atlas = await UVMapper.getAtlas(model);
|
|
131
|
+
const rotation = BlockStateResolver.rotation(variant);
|
|
132
|
+
if (!atlas || atlas.image.width > this.maxAtlasSize || atlas.image.height > this.maxAtlasSize) return void 0;
|
|
133
|
+
return { model, atlas, rotation };
|
|
134
|
+
}));
|
|
119
135
|
const prepared = /* @__PURE__ */ new Map();
|
|
120
|
-
for (const
|
|
121
|
-
|
|
122
|
-
if (!
|
|
123
|
-
|
|
124
|
-
if (!variant.model) return void 0;
|
|
125
|
-
const modelKey = AssetKey.parse("models", variant.model);
|
|
126
|
-
modelKey.root = blockState.key?.root;
|
|
127
|
-
const model = await Models.getMerged(modelKey);
|
|
128
|
-
if (!model?.elements?.length) return void 0;
|
|
129
|
-
const atlas = await UVMapper.getAtlas(model);
|
|
130
|
-
const rotation = BlockStateResolver.rotation(variant);
|
|
131
|
-
if (!atlas || atlas.image.width > this.maxAtlasSize || atlas.image.height > this.maxAtlasSize) return void 0;
|
|
132
|
-
prepared.set(variant, { model, atlas, rotation });
|
|
133
|
-
}
|
|
136
|
+
for (const [i, result] of settled.entries()) {
|
|
137
|
+
if (result.status === "rejected") throw result.reason;
|
|
138
|
+
if (!result.value) return void 0;
|
|
139
|
+
prepared.set(variants[i], result.value);
|
|
134
140
|
}
|
|
135
141
|
return { state, groups, choices: prepared };
|
|
136
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/world/SectionModels.ts"],"sourcesContent":["import { BufferAttribute, BufferGeometry, Euler, Matrix4, Mesh, Vector3 } from \"three\";\nimport { AssetKey } from \"../assets/AssetKey\";\nimport { Models } from \"../assets/Models\";\nimport { CUBE_FACES, CUBE_FACE_OFFSETS } from \"../CubeFace\";\nimport { BlockState, BlockStateVariant } from \"../model/block/BlockState\";\nimport { BlockStateProperties } from \"../model/block/BlockStateProperties\";\nimport { BlockStateResolver } from \"../model/block/BlockStateResolver\";\nimport { BlockTints } from \"../model/block/BlockTints\";\nimport { FluidKind } from \"../model/fluid/FluidGeometry\";\nimport { BlockModel, Model, TripleArray } from \"../model/Model\";\nimport { ModelCulling } from \"../model/ModelCulling\";\nimport { ModelObject } from \"../model/scene/ModelObject\";\nimport { TextureAtlas } from \"../texture/TextureAtlas\";\nimport { UVMapper } from \"../UVMapper\";\nimport { SectionMeshTemplate } from \"./SectionMesh\";\n\ninterface PreparedVariant {\n model: Model;\n atlas: TextureAtlas;\n rotation: Euler;\n}\n\ninterface PreparedState {\n state: BlockStateProperties;\n groups: (BlockStateVariant | BlockStateVariant[])[];\n choices: Map<BlockStateVariant, PreparedVariant>;\n}\n\n// Section meshes supply the material; templates only need the existing model geometry pipeline.\nclass SectionModel extends ModelObject {\n protected applyTextures() {}\n}\n\nfunction cached<T>(map: Map<string, Promise<T>>, key: string, load: () => Promise<T>): Promise<T> {\n let value = map.get(key);\n if (!value) {\n value = load().catch(error => { map.delete(key); throw error; });\n map.set(key, value);\n }\n return value;\n}\n\nfunction compactQuads(geometry: BufferGeometry, keep: boolean[]): BufferGeometry {\n const quads = keep.flatMap((kept, index) => kept ? [index] : []);\n const compact = new BufferGeometry();\n for (const [name, size] of Object.entries({ position: 3, normal: 3, uv: 2, uvBounds: 4, color: 3, shade: 1 })) {\n const source = geometry.getAttribute(name);\n const defaults = name === \"uvBounds\" ? [0, 0, 1, 1] : name === \"color\" ? [1, 1, 1] : name === \"shade\" ? [1] : undefined;\n const values = new Float32Array(quads.length * 4 * size);\n for (let q = 0; q < quads.length; q++) {\n for (let vertex = 0; vertex < 4; vertex++) {\n for (let component = 0; component < size; component++) {\n values[(q * 4 + vertex) * size + component] = source\n ? source.getComponent(quads[q] * 4 + vertex, component) : defaults![component];\n }\n }\n }\n compact.setAttribute(name, new BufferAttribute(values, size));\n }\n const source = geometry.getIndex()!;\n const indices: number[] = [];\n for (let q = 0; q < quads.length; q++) {\n for (let k = 0; k < 6; k++) indices.push(source.getX(quads[q] * 6 + k) - quads[q] * 4 + q * 4);\n }\n compact.setIndex(indices);\n geometry.dispose();\n return compact;\n}\n\n/** Prepares and caches model geometry and fluid atlases for merged world sections. */\nexport class SectionModels {\n private states = new WeakMap<BlockState, Map<string, Promise<PreparedState | undefined>>>();\n private models = new WeakMap<Model, Map<string, Promise<SectionMeshTemplate>>>();\n private readonly templates = new Set<SectionMeshTemplate>();\n private readonly fluidAtlases = new Map<string, Promise<TextureAtlas>>();\n\n constructor(readonly maxAtlasSize = 2048) {\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError(\"maxAtlasSize must be a positive integer\");\n }\n\n /** Returns templates for the matched parts, or `undefined` when the block needs an individual render object. */\n public async get(blockState: BlockState, properties: BlockStateProperties = {},\n position?: Readonly<TripleArray>, biome?: string): Promise<SectionMeshTemplate[] | undefined> {\n const biomePosition: TripleArray | undefined = position ? [...position] : undefined;\n const prepared = await this.state(blockState, properties);\n if (!prepared) return undefined;\n return Promise.all(prepared.groups.map(async group => {\n const variant = BlockStateResolver.choose(group, biomePosition);\n const choice = prepared.choices.get(variant)!;\n const tints = await BlockTints.get(blockState.key, prepared.state, choice.model, undefined,\n () => BlockTints.getBiomeColor(blockState.key, biome, biomePosition));\n return this.template(variant, choice, tints);\n }));\n }\n\n /** Resolves shared templates; dynamic biome tints are supplied on section placements instead of cached geometry. */\n public async prepareState(blockState: BlockState, properties: BlockStateProperties = {},\n biomeColor?: number | (() => Promise<number | undefined>), dynamicBiomeTint = false):\n Promise<{ pick(position?: Readonly<TripleArray>): SectionMeshTemplate[]; biomeTint?: boolean } | undefined> {\n const prepared = await this.state(blockState, properties);\n if (!prepared) return undefined;\n let color: Promise<number | undefined> | undefined;\n const resolveColor = typeof biomeColor === \"function\" ? () => color ??= biomeColor() : biomeColor;\n const templates = new Map<BlockStateVariant, SectionMeshTemplate>();\n const source = dynamicBiomeTint && await BlockTints.biomeSource(blockState.key);\n await Promise.all([...prepared.choices].map(async ([variant, choice]) => {\n const tints = await BlockTints.get(blockState.key, prepared.state, choice.model, undefined, resolveColor);\n const biomeTints = source ? await BlockTints.get(blockState.key, prepared.state, choice.model, undefined, 0xffffff) : undefined;\n templates.set(variant, await this.template(variant, choice, tints, biomeTints));\n }));\n return {\n pick: (position?: Readonly<TripleArray>) => prepared.groups.map(group => templates.get(BlockStateResolver.choose(group, position))!),\n biomeTint: source ? [...templates.values()].some(template => template.biomeTint?.some(value => value === 1)) || undefined : undefined\n };\n }\n\n private async state(blockState: BlockState, properties: BlockStateProperties): Promise<PreparedState | undefined> {\n let states = this.states.get(blockState);\n if (!states) this.states.set(blockState, states = new Map());\n const key = JSON.stringify(Object.entries(properties).sort(([a], [b]) => a.localeCompare(b)));\n return cached(states, key, () => this.prepare(blockState, properties));\n }\n\n /** Returns the shared still/flow atlas used by per-block fluid objects. */\n public fluidAtlas(kind: FluidKind, root?: string): Promise<TextureAtlas> {\n const key = new AssetKey(\"minecraft\", kind, \"models\", \"fluid\", \"assets\", \".json\", root);\n return cached(this.fluidAtlases, key.serialize(), async () => {\n const atlas = await UVMapper.getAtlas({\n key,\n textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },\n elements: []\n });\n if (!atlas) throw new Error(`Missing ${kind} fluid atlas`);\n return atlas;\n });\n }\n\n private async prepare(blockState: BlockState, properties: BlockStateProperties): Promise<PreparedState | undefined> {\n const state = { ...await BlockStateResolver.defaults(blockState), ...properties };\n const groups = BlockStateResolver.matching(blockState, state);\n if (!groups.length) return undefined;\n const prepared = new Map<BlockStateVariant, PreparedVariant>();\n for (const group of groups) {\n const choices = Array.isArray(group) ? group : [group];\n if (!choices.length) return undefined;\n for (const variant of choices) {\n if (!variant.model) return undefined;\n const modelKey = AssetKey.parse(\"models\", variant.model);\n modelKey.root = blockState.key?.root;\n const model = await Models.getMerged(modelKey);\n if (!model?.elements?.length) return undefined;\n const atlas = await UVMapper.getAtlas(model);\n const rotation = BlockStateResolver.rotation(variant);\n if (!atlas\n || atlas.image.width > this.maxAtlasSize || atlas.image.height > this.maxAtlasSize) return undefined;\n prepared.set(variant, { model, atlas, rotation });\n }\n }\n return { state, groups, choices: prepared };\n }\n\n private async template(variant: BlockStateVariant, { model, atlas, rotation }: PreparedVariant,\n tints?: Record<number, number>, biomeTints?: Record<number, number>): Promise<SectionMeshTemplate> {\n let models = this.models.get(model);\n if (!models) this.models.set(model, models = new Map());\n const key = JSON.stringify([rotation.x, rotation.y, rotation.z, variant.uvlock, tints, biomeTints]);\n return cached(models, key, async () => {\n const object = new SectionModel(model, {\n instanceMeshes: false, mergeMeshes: true, tints,\n uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0)\n ? [rotation.x, rotation.y, rotation.z] : undefined\n });\n await object.init();\n let geometry = (object.children[0] as Mesh).geometry;\n geometry.applyMatrix4(new Matrix4().makeRotationFromEuler(rotation));\n object.clear();\n const keep: boolean[] = [];\n const cullFaces: number[] = [];\n const biomeTint: number[] | undefined = biomeTints ? [] : undefined;\n for (const element of atlas.model.elements!) {\n for (const face of CUBE_FACES) {\n const data = element.faces[face];\n keep.push(data !== undefined);\n if (!data) continue;\n biomeTint?.push(Number(data.tintindex !== undefined && biomeTints?.[data.tintindex] !== undefined));\n const local = CUBE_FACES.findIndex(name => name === data.cullface);\n if (local < 0) {\n cullFaces.push(0);\n continue;\n }\n const normal = new Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);\n const world = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) =>\n Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);\n cullFaces.push(world < 0 ? 0 : 1 << world);\n }\n }\n geometry = compactQuads(geometry, keep);\n const template: SectionMeshTemplate = {\n geometry, atlas, cullFaces: new Uint8Array(cullFaces),\n biomeTint: biomeTint?.some(Boolean) ? new Uint8Array(biomeTint) : undefined,\n occludes: ModelCulling.isOpaqueFullCube(atlas) && ModelCulling.toLocalMask(63, rotation) === 63,\n layer: atlas.hasTranslucency ? 1 : 0, ambientOcclusion: (model as BlockModel).ambientocclusion !== false\n };\n this.templates.add(template);\n return template;\n });\n }\n\n /** Disposes prepared geometry and clears this world's template caches. */\n public clear(): void {\n for (const template of this.templates) template.geometry.dispose();\n this.templates.clear();\n this.states = new WeakMap();\n this.models = new WeakMap();\n this.fluidAtlases.clear();\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAuB,SAAe,eAAe;AAC/E,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,YAAY,yBAAyB;AAG9C,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAG3B,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB;AAgBzB,IAAM,eAAN,cAA2B,YAAY;AAAA,EACzB,gBAAgB;AAAA,EAAC;AAC/B;AAEA,SAAS,OAAU,KAA8B,KAAa,MAAoC;AAC9F,MAAI,QAAQ,IAAI,IAAI,GAAG;AACvB,MAAI,CAAC,OAAO;AACR,YAAQ,KAAK,EAAE,MAAM,WAAS;AAAE,UAAI,OAAO,GAAG;AAAG,YAAM;AAAA,IAAO,CAAC;AAC/D,QAAI,IAAI,KAAK,KAAK;AAAA,EACtB;AACA,SAAO;AACX;AAEA,SAAS,aAAa,UAA0B,MAAiC;AAC7E,QAAM,QAAQ,KAAK,QAAQ,CAAC,MAAM,UAAU,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;AAC/D,QAAM,UAAU,IAAI,eAAe;AACnC,aAAW,CAAC,MAAM,IAAI,KAAK,OAAO,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,EAAE,CAAC,GAAG;AAC3G,UAAMA,UAAS,SAAS,a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AAa,iBAAiB,KAAK,KAAK,aAAa,YAAY,IAAI,QAAQ,MAAM;AAAA,QAC7F,OAAO,MAAM,kBAAkB,IAAI;AAAA,QAAG,kBAAmB,MAAqB,qBAAqB;AAAA,MACvG;AACA,WAAK,UAAU,IAAI,QAAQ;AAC3B,aAAO;AAAA,IACX,CAAC;AAAA,EACL;AAAA;AAAA,EAGO,QAAc;AACjB,eAAW,YAAY,KAAK,UAAW,UAAS,SAAS,QAAQ;AACjE,SAAK,UAAU,MAAM;AACrB,SAAK,SAAS,oBAAI,QAAQ;AAC1B,SAAK,SAAS,oBAAI,QAAQ;AAC1B,SAAK,aAAa,MAAM;AAAA,EAC5B;AACJ;","names":["source"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/world/SectionModels.ts"],"sourcesContent":["import { BufferAttribute, BufferGeometry, Euler, Matrix4, Mesh, Vector3 } from \"three\";\nimport { AssetKey } from \"../assets/AssetKey\";\nimport { Models } from \"../assets/Models\";\nimport { CUBE_FACES, CUBE_FACE_OFFSETS } from \"../CubeFace\";\nimport { BlockState, BlockStateVariant } from \"../model/block/BlockState\";\nimport { BlockStateProperties } from \"../model/block/BlockStateProperties\";\nimport { BlockStateResolver } from \"../model/block/BlockStateResolver\";\nimport { BlockTints } from \"../model/block/BlockTints\";\nimport { FluidKind } from \"../model/fluid/FluidGeometry\";\nimport { BlockModel, Model, TripleArray } from \"../model/Model\";\nimport { ModelCulling } from \"../model/ModelCulling\";\nimport { ModelObject } from \"../model/scene/ModelObject\";\nimport { TextureAtlas } from \"../texture/TextureAtlas\";\nimport { UVMapper } from \"../UVMapper\";\nimport { SectionMeshTemplate } from \"./SectionMesh\";\n\ninterface PreparedVariant {\n model: Model;\n atlas: TextureAtlas;\n rotation: Euler;\n}\n\ninterface PreparedState {\n state: BlockStateProperties;\n groups: (BlockStateVariant | BlockStateVariant[])[];\n choices: Map<BlockStateVariant, PreparedVariant>;\n}\n\n// Section meshes supply the material; templates only need the existing model geometry pipeline.\nclass SectionModel extends ModelObject {\n protected applyTextures() {}\n}\n\nfunction cached<T>(map: Map<string, Promise<T>>, key: string, load: () => Promise<T>): Promise<T> {\n let value = map.get(key);\n if (!value) {\n value = load().catch(error => { map.delete(key); throw error; });\n map.set(key, value);\n }\n return value;\n}\n\nfunction compactQuads(geometry: BufferGeometry, keep: boolean[]): BufferGeometry {\n const quads = keep.flatMap((kept, index) => kept ? [index] : []);\n const compact = new BufferGeometry();\n for (const [name, size] of Object.entries({ position: 3, normal: 3, uv: 2, uvBounds: 4, color: 3, shade: 1 })) {\n const source = geometry.getAttribute(name);\n const defaults = name === \"uvBounds\" ? [0, 0, 1, 1] : name === \"color\" ? [1, 1, 1] : name === \"shade\" ? [1] : undefined;\n const values = new Float32Array(quads.length * 4 * size);\n for (let q = 0; q < quads.length; q++) {\n for (let vertex = 0; vertex < 4; vertex++) {\n for (let component = 0; component < size; component++) {\n values[(q * 4 + vertex) * size + component] = source\n ? source.getComponent(quads[q] * 4 + vertex, component) : defaults![component];\n }\n }\n }\n compact.setAttribute(name, new BufferAttribute(values, size));\n }\n const source = geometry.getIndex()!;\n const indices: number[] = [];\n for (let q = 0; q < quads.length; q++) {\n for (let k = 0; k < 6; k++) indices.push(source.getX(quads[q] * 6 + k) - quads[q] * 4 + q * 4);\n }\n compact.setIndex(indices);\n geometry.dispose();\n return compact;\n}\n\n/** Prepares and caches model geometry and fluid atlases for merged world sections. */\nexport class SectionModels {\n private states = new WeakMap<BlockState, Map<string, Promise<PreparedState | undefined>>>();\n private models = new WeakMap<Model, Map<string, Promise<SectionMeshTemplate>>>();\n private readonly templates = new Set<SectionMeshTemplate>();\n private readonly fluidAtlases = new Map<string, Promise<TextureAtlas>>();\n\n constructor(readonly maxAtlasSize = 2048) {\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError(\"maxAtlasSize must be a positive integer\");\n }\n\n /** Returns templates for the matched parts, or `undefined` when the block needs an individual render object. */\n public async get(blockState: BlockState, properties: BlockStateProperties = {},\n position?: Readonly<TripleArray>, biome?: string): Promise<SectionMeshTemplate[] | undefined> {\n const biomePosition: TripleArray | undefined = position ? [...position] : undefined;\n const prepared = await this.state(blockState, properties);\n if (!prepared) return undefined;\n return Promise.all(prepared.groups.map(async group => {\n const variant = BlockStateResolver.choose(group, biomePosition);\n const choice = prepared.choices.get(variant)!;\n const tints = await BlockTints.get(blockState.key, prepared.state, choice.model, undefined,\n () => BlockTints.getBiomeColor(blockState.key, biome, biomePosition));\n return this.template(variant, choice, tints);\n }));\n }\n\n /** Resolves shared templates; dynamic biome tints are supplied on section placements instead of cached geometry. */\n public async prepareState(blockState: BlockState, properties: BlockStateProperties = {},\n biomeColor?: number | (() => Promise<number | undefined>), dynamicBiomeTint = false):\n Promise<{ pick(position?: Readonly<TripleArray>): SectionMeshTemplate[]; biomeTint?: boolean } | undefined> {\n const prepared = await this.state(blockState, properties);\n if (!prepared) return undefined;\n let color: Promise<number | undefined> | undefined;\n const resolveColor = typeof biomeColor === \"function\" ? () => color ??= biomeColor() : biomeColor;\n const templates = new Map<BlockStateVariant, SectionMeshTemplate>();\n const source = dynamicBiomeTint && await BlockTints.biomeSource(blockState.key);\n await Promise.all([...prepared.choices].map(async ([variant, choice]) => {\n const tints = await BlockTints.get(blockState.key, prepared.state, choice.model, undefined, resolveColor);\n const biomeTints = source ? await BlockTints.get(blockState.key, prepared.state, choice.model, undefined, 0xffffff) : undefined;\n templates.set(variant, await this.template(variant, choice, tints, biomeTints));\n }));\n return {\n pick: (position?: Readonly<TripleArray>) => prepared.groups.map(group => templates.get(BlockStateResolver.choose(group, position))!),\n biomeTint: source ? [...templates.values()].some(template => template.biomeTint?.some(value => value === 1)) || undefined : undefined\n };\n }\n\n /** Starts loading the state's models and atlases so a later `prepareState` with the same properties finds them loaded. */\n public async preload(blockState: BlockState, properties: BlockStateProperties = {}): Promise<void> {\n await this.state(blockState, properties);\n }\n\n private async state(blockState: BlockState, properties: BlockStateProperties): Promise<PreparedState | undefined> {\n let states = this.states.get(blockState);\n if (!states) this.states.set(blockState, states = new Map());\n const key = JSON.stringify(Object.entries(properties).sort(([a], [b]) => a.localeCompare(b)));\n return cached(states, key, () => this.prepare(blockState, properties));\n }\n\n /** Returns the shared still/flow atlas used by per-block fluid objects. */\n public fluidAtlas(kind: FluidKind, root?: string): Promise<TextureAtlas> {\n const key = new AssetKey(\"minecraft\", kind, \"models\", \"fluid\", \"assets\", \".json\", root);\n return cached(this.fluidAtlases, key.serialize(), async () => {\n const atlas = await UVMapper.getAtlas({\n key,\n textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },\n elements: []\n });\n if (!atlas) throw new Error(`Missing ${kind} fluid atlas`);\n return atlas;\n });\n }\n\n private async prepare(blockState: BlockState, properties: BlockStateProperties): Promise<PreparedState | undefined> {\n const state = { ...await BlockStateResolver.defaults(blockState), ...properties };\n const groups = BlockStateResolver.matching(blockState, state);\n if (!groups.length || groups.some(group => Array.isArray(group) && !group.length)) return undefined;\n const variants = groups.flatMap(group => Array.isArray(group) ? group : [group]);\n if (variants.some(variant => !variant.model)) return undefined;\n const settled = await Promise.allSettled(variants.map(async variant => {\n const modelKey = AssetKey.parse(\"models\", variant.model!);\n modelKey.root = blockState.key?.root;\n const model = await Models.getMerged(modelKey);\n if (!model?.elements?.length) return undefined;\n const atlas = await UVMapper.getAtlas(model);\n const rotation = BlockStateResolver.rotation(variant);\n if (!atlas\n || atlas.image.width > this.maxAtlasSize || atlas.image.height > this.maxAtlasSize) return undefined;\n return { model, atlas, rotation };\n }));\n const prepared = new Map<BlockStateVariant, PreparedVariant>();\n for (const [i, result] of settled.entries()) {\n if (result.status === \"rejected\") throw result.reason;\n if (!result.value) return undefined;\n prepared.set(variants[i], result.value);\n }\n return { state, groups, choices: prepared };\n }\n\n private async template(variant: BlockStateVariant, { model, atlas, rotation }: PreparedVariant,\n tints?: Record<number, number>, biomeTints?: Record<number, number>): Promise<SectionMeshTemplate> {\n let models = this.models.get(model);\n if (!models) this.models.set(model, models = new Map());\n const key = JSON.stringify([rotation.x, rotation.y, rotation.z, variant.uvlock, tints, biomeTints]);\n return cached(models, key, async () => {\n const object = new SectionModel(model, {\n instanceMeshes: false, mergeMeshes: true, tints,\n uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0)\n ? [rotation.x, rotation.y, rotation.z] : undefined\n });\n await object.init();\n let geometry = (object.children[0] as Mesh).geometry;\n geometry.applyMatrix4(new Matrix4().makeRotationFromEuler(rotation));\n object.clear();\n const keep: boolean[] = [];\n const cullFaces: number[] = [];\n const biomeTint: number[] | undefined = biomeTints ? [] : undefined;\n for (const element of atlas.model.elements!) {\n for (const face of CUBE_FACES) {\n const data = element.faces[face];\n keep.push(data !== undefined);\n if (!data) continue;\n biomeTint?.push(Number(data.tintindex !== undefined && biomeTints?.[data.tintindex] !== undefined));\n const local = CUBE_FACES.findIndex(name => name === data.cullface);\n if (local < 0) {\n cullFaces.push(0);\n continue;\n }\n const normal = new Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);\n const world = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) =>\n Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);\n cullFaces.push(world < 0 ? 0 : 1 << world);\n }\n }\n geometry = compactQuads(geometry, keep);\n const template: SectionMeshTemplate = {\n geometry, atlas, cullFaces: new Uint8Array(cullFaces),\n biomeTint: biomeTint?.some(Boolean) ? new Uint8Array(biomeTint) : undefined,\n occludes: ModelCulling.isOpaqueFullCube(atlas) && ModelCulling.toLocalMask(63, rotation) === 63,\n layer: atlas.hasTranslucency ? 1 : 0, ambientOcclusion: (model as BlockModel).ambientocclusion !== false\n };\n this.templates.add(template);\n return template;\n });\n }\n\n /** Disposes prepared geometry and clears this world's template caches. */\n public clear(): void {\n for (const template of this.templates) template.geometry.dispose();\n this.templates.clear();\n this.states = new WeakMap();\n this.models = new WeakMap();\n this.fluidAtlases.clear();\n }\n}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E,UAAU,aAAa,iBAAiB,KAAK,KAAK,aAAa,YAAY,IAAI,QAAQ,MAAM;AAAA,QAC7F,OAAO,MAAM,kBAAkB,IAAI;AAAA,QAAG,kBAAmB,MAAqB,qBAAqB;AAAA,MACvG;AACA,WAAK,UAAU,IAAI,QAAQ;AAC3B,aAAO;AAAA,IACX,CAAC;AAAA,EACL;AAAA;AAAA,EAGO,QAAc;AACjB,eAAW,YAAY,KAAK,UAAW,UAAS,SAAS,QAAQ;AACjE,SAAK,UAAU,MAAM;AACrB,SAAK,SAAS,oBAAI,QAAQ;AAC1B,SAAK,SAAS,oBAAI,QAAQ;AAC1B,SAAK,aAAa,MAAM;AAAA,EAC5B;AACJ;","names":["source"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/world/SectionWorker.ts
|
|
2
2
|
import { Env } from "../Env.mjs";
|
|
3
|
+
import { logger } from "../util/log.mjs";
|
|
4
|
+
var log = logger("SectionWorker");
|
|
3
5
|
var _SectionWorker = class _SectionWorker {
|
|
4
6
|
constructor(worker) {
|
|
5
7
|
this.worker = worker;
|
|
@@ -13,8 +15,12 @@ var _SectionWorker = class _SectionWorker {
|
|
|
13
15
|
if (reply.type === "pages") pending.resolve(reply.pages);
|
|
14
16
|
else pending.reject(new Error(reply.message));
|
|
15
17
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
const fallBack = (message) => {
|
|
19
|
+
log.warn(`${message}, so sections build on the main thread`);
|
|
20
|
+
this.fail(message);
|
|
21
|
+
};
|
|
22
|
+
worker.addEventListener("error", (event) => fallBack(event.message || "Section worker failed"));
|
|
23
|
+
worker.addEventListener("messageerror", () => fallBack("Section worker message could not be deserialized"));
|
|
18
24
|
}
|
|
19
25
|
/** The shared worker, or undefined when the environment has none or a previous worker failed. */
|
|
20
26
|
static shared() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/world/SectionWorker.ts"],"sourcesContent":["import { Env } from \"../Env\";\nimport type { SectionGeometryInput, SectionGeometryPage } from \"./SectionGeometry\";\n\n/** Runs section geometry builds in the environment's shared worker. */\nexport class SectionWorker {\n private static initialized = false;\n private static instance: SectionWorker | undefined;\n private nextId = 0;\n private readonly pending = new Map<number, {\n resolve: (pages: SectionGeometryPage[]) => void;\n reject: (error: Error) => void;\n }>();\n\n private constructor(private worker: Worker | undefined) {\n worker!.addEventListener(\"message\", (event: MessageEvent<\n { id: number; type: \"pages\"; pages: SectionGeometryPage[] } |\n { id: number; type: \"error\"; message: string }\n >) => {\n const reply = event.data;\n const pending = this.pending.get(reply.id);\n if (!pending) return;\n this.pending.delete(reply.id);\n if (reply.type === \"pages\") pending.resolve(reply.pages);\n else pending.reject(new Error(reply.message));\n });\n // A failed worker or an undeliverable message leaves the pending builds unanswerable, so stop using it.\n worker!.addEventListener(\"error\", event =>
|
|
1
|
+
{"version":3,"sources":["../../../../src/world/SectionWorker.ts"],"sourcesContent":["import { Env } from \"../Env\";\nimport { logger } from \"../util/log\";\nimport type { SectionGeometryInput, SectionGeometryPage } from \"./SectionGeometry\";\n\nconst log = logger(\"SectionWorker\");\n\n/** Runs section geometry builds in the environment's shared worker. */\nexport class SectionWorker {\n private static initialized = false;\n private static instance: SectionWorker | undefined;\n private nextId = 0;\n private readonly pending = new Map<number, {\n resolve: (pages: SectionGeometryPage[]) => void;\n reject: (error: Error) => void;\n }>();\n\n private constructor(private worker: Worker | undefined) {\n worker!.addEventListener(\"message\", (event: MessageEvent<\n { id: number; type: \"pages\"; pages: SectionGeometryPage[] } |\n { id: number; type: \"error\"; message: string }\n >) => {\n const reply = event.data;\n const pending = this.pending.get(reply.id);\n if (!pending) return;\n this.pending.delete(reply.id);\n if (reply.type === \"pages\") pending.resolve(reply.pages);\n else pending.reject(new Error(reply.message));\n });\n // A failed worker or an undeliverable message leaves the pending builds unanswerable, so stop using it.\n const fallBack = (message: string) => {\n log.warn(`${message}, so sections build on the main thread`);\n this.fail(message);\n };\n worker!.addEventListener(\"error\", event => fallBack(event.message || \"Section worker failed\"));\n worker!.addEventListener(\"messageerror\", () => fallBack(\"Section worker message could not be deserialized\"));\n }\n\n /** The shared worker, or undefined when the environment has none or a previous worker failed. */\n public static shared(): SectionWorker | undefined {\n if (!this.initialized) {\n this.initialized = true;\n const worker = Env.provider.createWorker?.(\"section\");\n if (worker) this.instance = new SectionWorker(worker);\n }\n return this.instance;\n }\n\n /** Builds geometry without transferring the input buffers away from the caller. */\n public build(input: SectionGeometryInput): Promise<SectionGeometryPage[]> {\n if (!this.worker) return Promise.reject(new Error(\"Section worker terminated\"));\n return new Promise((resolve, reject) => {\n const id = this.nextId++;\n this.pending.set(id, { resolve, reject });\n this.worker!.postMessage({ id, type: \"build\", input });\n });\n }\n\n /** Rejects pending builds, terminates the worker, and makes shared() return undefined. */\n public terminate(): void {\n this.fail(\"Section worker terminated\");\n }\n\n private fail(message: string): void {\n const error = new Error(message);\n for (const pending of this.pending.values()) pending.reject(error);\n this.pending.clear();\n this.worker?.terminate();\n this.worker = undefined;\n SectionWorker.instance = undefined;\n }\n}\n"],"mappings":";AAAA,SAAS,WAAW;AACpB,SAAS,cAAc;AAGvB,IAAM,MAAM,OAAO,eAAe;AAG3B,IAAM,iBAAN,MAAM,eAAc;AAAA,EASf,YAAoB,QAA4B;AAA5B;AAN5B,SAAQ,SAAS;AACjB,SAAiB,UAAU,oBAAI,IAG5B;AAGC,WAAQ,iBAAiB,WAAW,CAAC,UAG/B;AACF,YAAM,QAAQ,MAAM;AACpB,YAAM,UAAU,KAAK,QAAQ,IAAI,MAAM,EAAE;AACzC,UAAI,CAAC,QAAS;AACd,WAAK,QAAQ,OAAO,MAAM,EAAE;AAC5B,UAAI,MAAM,SAAS,QAAS,SAAQ,QAAQ,MAAM,KAAK;AAAA,UAClD,SAAQ,OAAO,IAAI,MAAM,MAAM,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,WAAW,CAAC,YAAoB;AAClC,UAAI,KAAK,GAAG,OAAO,wCAAwC;AAC3D,W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