minerender 2.1.0-beta.5 → 2.1.0-beta.7
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/dist/browser/esm/Materials.mjs +6 -3
- package/dist/browser/esm/Materials.mjs.map +1 -1
- package/dist/browser/esm/Ticker.mjs +3 -1
- package/dist/browser/esm/Ticker.mjs.map +1 -1
- package/dist/browser/esm/UVMapper.mjs +9 -9
- package/dist/browser/esm/UVMapper.mjs.map +1 -1
- package/dist/browser/esm/assets/AssetDefaults.mjs +8 -0
- package/dist/browser/esm/assets/AssetDefaults.mjs.map +1 -0
- package/dist/browser/esm/assets/AssetKey.mjs +1 -1
- package/dist/browser/esm/assets/AssetKey.mjs.map +1 -1
- package/dist/browser/esm/assets/AssetLoader.mjs +5 -5
- package/dist/browser/esm/assets/AssetLoader.mjs.map +1 -1
- package/dist/browser/esm/assets/Assets.mjs +1 -5
- package/dist/browser/esm/assets/Assets.mjs.map +1 -1
- package/dist/browser/esm/assets/BlockEntities.mjs +3 -1
- package/dist/browser/esm/assets/BlockEntities.mjs.map +1 -1
- package/dist/browser/esm/assets/BlockStates.mjs +1 -1
- package/dist/browser/esm/assets/BlockStates.mjs.map +1 -1
- package/dist/browser/esm/assets/Entities.mjs +1 -1
- package/dist/browser/esm/assets/Entities.mjs.map +1 -1
- package/dist/browser/esm/assets/Fonts.mjs +31 -4
- package/dist/browser/esm/assets/Fonts.mjs.map +1 -1
- package/dist/browser/esm/assets/Models.mjs +1 -1
- package/dist/browser/esm/assets/Models.mjs.map +1 -1
- package/dist/browser/esm/assets/_fonts/Unihex.mjs +168 -0
- package/dist/browser/esm/assets/_fonts/Unihex.mjs.map +1 -0
- package/dist/browser/esm/assets/index.mjs +1 -0
- package/dist/browser/esm/assets/index.mjs.map +1 -1
- package/dist/browser/esm/assets/source/HostedAssetSource.mjs +19 -9
- package/dist/browser/esm/assets/source/HostedAssetSource.mjs.map +1 -1
- package/dist/browser/esm/assets/source/parser/AssetParsers.mjs +1 -0
- package/dist/browser/esm/assets/source/parser/AssetParsers.mjs.map +1 -1
- package/dist/browser/esm/cache/Caching.mjs +2 -0
- package/dist/browser/esm/cache/Caching.mjs.map +1 -1
- package/dist/browser/esm/entity/scene/EntityAnimationPlayer.mjs +62 -11
- package/dist/browser/esm/entity/scene/EntityAnimationPlayer.mjs.map +1 -1
- package/dist/browser/esm/entity/scene/EntityObject.mjs +53 -20
- package/dist/browser/esm/entity/scene/EntityObject.mjs.map +1 -1
- package/dist/browser/esm/env/browser/BrowserCache.mjs +3 -3
- package/dist/browser/esm/env/browser/BrowserCache.mjs.map +1 -1
- package/dist/browser/esm/env/browser/section.worker.mjs +5 -3
- package/dist/browser/esm/env/browser/section.worker.mjs.map +1 -1
- package/dist/browser/esm/gui/GuiText.mjs +4 -3
- package/dist/browser/esm/gui/GuiText.mjs.map +1 -1
- package/dist/browser/esm/image/ImageLoader.mjs +3 -3
- package/dist/browser/esm/image/ImageLoader.mjs.map +1 -1
- package/dist/browser/esm/index.browser.d.mts +115 -20
- package/dist/browser/esm/inspector/SceneInspector.mjs +3 -3
- package/dist/browser/esm/inspector/SceneInspector.mjs.map +1 -1
- package/dist/browser/esm/instance/InstanceManager.mjs +4 -4
- package/dist/browser/esm/instance/InstanceManager.mjs.map +1 -1
- package/dist/browser/esm/model/block/scene/BlockObject.mjs +3 -1
- package/dist/browser/esm/model/block/scene/BlockObject.mjs.map +1 -1
- package/dist/browser/esm/model/multiblock/StructureParser.mjs +7 -4
- package/dist/browser/esm/model/multiblock/StructureParser.mjs.map +1 -1
- package/dist/browser/esm/model/scene/ModelObject.mjs +8 -4
- package/dist/browser/esm/model/scene/ModelObject.mjs.map +1 -1
- package/dist/browser/esm/nbt/NBTHelper.mjs +5 -2
- package/dist/browser/esm/nbt/NBTHelper.mjs.map +1 -1
- package/dist/browser/esm/renderer/Renderer.mjs +4 -2
- package/dist/browser/esm/renderer/Renderer.mjs.map +1 -1
- package/dist/browser/esm/renderer/SceneObject.mjs +0 -6
- package/dist/browser/esm/renderer/SceneObject.mjs.map +1 -1
- package/dist/browser/esm/request/Requests.mjs +3 -3
- package/dist/browser/esm/request/Requests.mjs.map +1 -1
- package/dist/browser/esm/skin/Skins.mjs +6 -4
- package/dist/browser/esm/skin/Skins.mjs.map +1 -1
- package/dist/browser/esm/texture/TextureLoader.mjs +4 -2
- package/dist/browser/esm/texture/TextureLoader.mjs.map +1 -1
- package/dist/browser/esm/util/log.mjs +75 -0
- package/dist/browser/esm/util/log.mjs.map +1 -1
- package/dist/browser/esm/util/model.mjs +7 -7
- package/dist/browser/esm/util/model.mjs.map +1 -1
- package/dist/browser/esm/util/performance.mjs.map +1 -1
- package/dist/browser/esm/world/Chunk.mjs +8 -5
- package/dist/browser/esm/world/Chunk.mjs.map +1 -1
- package/dist/browser/esm/world/MineRenderWorld.mjs +96 -54
- package/dist/browser/esm/world/MineRenderWorld.mjs.map +1 -1
- package/dist/browser/esm/world/SectionGeometry.mjs +5 -3
- package/dist/browser/esm/world/SectionGeometry.mjs.map +1 -1
- package/dist/browser/esm/world/SectionMesh.mjs +4 -0
- package/dist/browser/esm/world/SectionMesh.mjs.map +1 -1
- package/dist/browser/esm/world/SectionModels.mjs +2 -2
- package/dist/browser/esm/world/SectionModels.mjs.map +1 -1
- package/dist/browser/esm/world/WorldStreamer.mjs +21 -20
- package/dist/browser/esm/world/WorldStreamer.mjs.map +1 -1
- package/dist/browser/esm/world/_culling/BlockCulling.mjs +1 -1
- package/dist/browser/esm/world/_culling/BlockCulling.mjs.map +1 -1
- package/dist/browser/esm/world/_entities/WorldEntities.mjs +3 -1
- package/dist/browser/esm/world/_entities/WorldEntities.mjs.map +1 -1
- package/dist/browser/index.d.ts +115 -20
- package/dist/browser/index.js +3449 -3025
- package/dist/browser/index.js.map +1 -1
- package/dist/bundle.js +13217 -12745
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +115 -20
- package/dist/node/index.d.ts +115 -20
- package/dist/node/index.js +3477 -3046
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +3456 -3027
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -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\";\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(): Promise<Map<Chunk<SectionMeshing>, unknown>> {\n if (this.biomeRefreshing) await this.biomeRefreshing;\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);\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 > 8) {\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 > 8) {\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 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 > 8) {\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 const failures = await this.refreshBiomes();\n if (failures.size) console.warn(\"Failed to refresh biome colors\", failures.values().next().value);\n await this.updateCulling([...changes.values()]);\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 if (!Number.isInteger(x) || !Number.isInteger(z)) {\n throw new RangeError(\"Chunk column coordinates must be integers\");\n }\n this.entities?.clearColumn(x, z);\n await this.culling;\n try {\n await this.clearChunkColumn(x, z);\n } finally {\n const failures = await this.refreshBiomes();\n if (failures.size) console.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[]): 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 // 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 = [...this.pendingCulling];\n this.pendingCulling.clear();\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 ((this._ambientOcclusion || this.ambientOcclusionPending) && performance.now() - sliceStart > 8) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n await Promise.all(batch.map(([chunk]) => chunk.rebuildSectionMesh()));\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 => this.updateCulling(positions), 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;\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B,KAAM;AAC9B,kBAAM,KAAK,cAAc,CAAC,CAAC;AAAA,UAC/B;AAAA,QACJ;AAAA,QAAG,KAAK;AAAA,QAAc,MAAM,KAAK;AAAA,MAAU;AAC/C,WAAK,QAAQ,IAAI,KAAK,KAAK;AAAA,IAC/B;AACA,WAAO;AAAA,EACX;AAAA;AAAA,EAGO,WAAW,KAA4C;AAC1D,WAAO,KAAK,QAAQ,IAAI,KAAK,mBAAmB,GAAG,CAAC;AAAA,EACxD;AAAA;AAAA,EAIA,OAAO,qBAAqB,KAAuB;AAC/C,WAAO,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 { 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\");\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 > 8) {\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 > 8) {\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 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 > 8) {\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 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 * 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 > 8) {\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 ((this._ambientOcclusion || this.ambientOcclusionPending) && performance.now() - sliceStart > 8) {\n await yieldToEventLoop();\n sliceStart = performance.now();\n }\n }\n const builds = await Promise.allSettled([...batch.keys()].map(async chunk => {\n await chunk.rebuildSectionMesh();\n batch.delete(chunk);\n }));\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;AAQ7B,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,eAA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I,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"]}
|
|
@@ -21,7 +21,7 @@ function buildSectionGeometry(input) {
|
|
|
21
21
|
const cornerBrightness = ambientOcclusion ? new Float32Array(4) : void 0;
|
|
22
22
|
for (const template of templateData) {
|
|
23
23
|
const { quads } = template;
|
|
24
|
-
if (template.positions.length !== quads * 12 || template.normals.length !== quads * 12 || template.uvs.length !== quads * 8 || template.uvBounds.length !== quads * 16 || template.colors.length !== quads * 12 || template.indices.length !== quads * 6 || template.cullFaces.length !== quads || template.biomeTint && template.biomeTint.length !== quads) {
|
|
24
|
+
if (template.positions.length !== quads * 12 || template.normals.length !== quads * 12 || template.uvs.length !== quads * 8 || template.uvBounds.length !== quads * 16 || template.colors.length !== quads * 12 || template.indices.length !== quads * 6 || template.cullFaces.length !== quads || template.shade && template.shade.length !== quads * 4 || template.biomeTint && template.biomeTint.length !== quads) {
|
|
25
25
|
throw new RangeError("Section template arrays do not match its quad count");
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -112,6 +112,7 @@ function buildSectionGeometry(input) {
|
|
|
112
112
|
}
|
|
113
113
|
const positions = new Float32Array(faces * 12), normals = new Float32Array(faces * 12);
|
|
114
114
|
const uvs = new Float32Array(faces * 8), uvBounds = new Float32Array(faces * 16), colors = new Float32Array(faces * 12);
|
|
115
|
+
const shade = new Float32Array(faces * 4).fill(1);
|
|
115
116
|
const outputIndices = new Uint32Array(faces * 6);
|
|
116
117
|
const blockIndices = new Uint16Array(faces);
|
|
117
118
|
let vertex = 0, indexOffset = 0;
|
|
@@ -141,6 +142,7 @@ function buildSectionGeometry(input) {
|
|
|
141
142
|
normals[vertex * 3] = template.normals[source * 3];
|
|
142
143
|
normals[vertex * 3 + 1] = template.normals[source * 3 + 1];
|
|
143
144
|
normals[vertex * 3 + 2] = template.normals[source * 3 + 2];
|
|
145
|
+
shade[vertex] = template.shade?.[source] ?? 1;
|
|
144
146
|
uvs[vertex * 2] = mapU(template.uvs[source * 2]);
|
|
145
147
|
uvs[vertex * 2 + 1] = mapV(template.uvs[source * 2 + 1]);
|
|
146
148
|
uvBounds[vertex * 4] = mapU(template.uvBounds[source * 4]);
|
|
@@ -193,11 +195,11 @@ function buildSectionGeometry(input) {
|
|
|
193
195
|
indexOffset += 6;
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
|
-
return { layer: page.layer, width: page.width, height: page.height, placements: page.placements, positions, normals, uvs, uvBounds, colors, indices: outputIndices, blockIndices };
|
|
198
|
+
return { layer: page.layer, width: page.width, height: page.height, placements: page.placements, positions, normals, uvs, uvBounds, colors, shade, indices: outputIndices, blockIndices };
|
|
197
199
|
});
|
|
198
200
|
}
|
|
199
201
|
function sectionGeometryTransferables(pages) {
|
|
200
|
-
return pages.flatMap((page) => [page.positions.buffer, page.normals.buffer, page.uvs.buffer, page.uvBounds.buffer, page.colors.buffer, page.indices.buffer, page.blockIndices.buffer]);
|
|
202
|
+
return pages.flatMap((page) => [page.positions.buffer, page.normals.buffer, page.uvs.buffer, page.uvBounds.buffer, page.colors.buffer, page.shade.buffer, page.indices.buffer, page.blockIndices.buffer]);
|
|
201
203
|
}
|
|
202
204
|
export {
|
|
203
205
|
buildSectionGeometry,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/world/SectionGeometry.ts"],"sourcesContent":["import { buildFluidQuads, fluidKindOf } from \"../model/fluid/FluidQuads\";\nimport type { FluidKind, FluidQuads } from \"../model/fluid/FluidQuads\";\nimport { quadAmbientOcclusion, sectionAmbientOcclusionMask } from \"./_light/AmbientOcclusion\";\nimport { fluidLightLevel, LIGHT_SAMPLE_OFFSETS, lightBrightness, quadLightIndex } from \"./_light/FaceLight\";\n\n/** Static model geometry as quads: four vertices per quad, in quad order. */\nexport interface SectionTemplateData {\n quads: number;\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n uvBounds: Float32Array;\n colors: Float32Array;\n indices: Uint16Array;\n cullFaces: Uint8Array;\n biomeTint?: Uint8Array;\n atlas: number;\n layer: number;\n ambientOcclusion?: boolean;\n}\n\n/** The pixel dimensions and animation state of a source atlas. */\nexport interface SectionAtlasSize {\n width: number;\n height: number;\n animated: boolean;\n}\n\n/** One fluid kind's sprite rectangles in atlas pixels and its linear-light vertex tint. */\nexport interface SectionFluidKind {\n atlas: number;\n still: [x: number, y: number, width: number, height: number];\n flow: [x: number, y: number, width: number, height: number];\n tint: [r: number, g: number, b: number];\n}\n\n/** Fluid cells of the section plus a one-cell shell, 18×18×18, x fastest, then z, then y. */\nexport interface SectionFluidInput {\n /** Bit 128 marks a surface rendered elsewhere; the cell still supplies neighbor fluid samples. */\n cells: Uint8Array;\n /** Linear RGB per section cell, indexed by (x + 16z + 256y) * 3. Omission uses the water kind's tint. */\n waterTints?: Float32Array;\n water?: SectionFluidKind;\n lava?: SectionFluidKind;\n}\n\n/** Section placements and their shared templates, ready for geometry building. */\nexport interface SectionGeometryInput {\n count: number;\n indices: Uint16Array;\n templates: Uint16Array;\n cullMasks: Uint8Array;\n /** Linear RGB per placement; three NaN values preserve the template's colors. */\n biomeTints?: Float32Array;\n templateData: SectionTemplateData[];\n atlases: SectionAtlasSize[];\n maxAtlasSize: number;\n fluids?: SectionFluidInput;\n /** Saved brightness levels for an 18×18×18 neighborhood; 255 means unknown/full brightness. */\n light?: Uint8Array;\n /** Minimum brightness for known light levels, from 0 to 1. */\n ambientLight?: number;\n /** Opaque full cubes in an 18×18×18 neighborhood, stored as zero or one. */\n ambientOcclusion?: Uint8Array;\n}\n\n/** Merged quads and source-atlas placements for one atlas page. */\nexport interface SectionGeometryPage {\n layer: number;\n width: number;\n height: number;\n placements: { atlas: number; x: number; y: number }[];\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n uvBounds: Float32Array;\n colors: Float32Array;\n indices: Uint32Array;\n /** Owning section cell for each quad; each quad contributes two consecutive triangles. */\n blockIndices: Uint16Array;\n}\n\n/** Builds section-local geometry from visible quads, with bounded atlas pages per layer. */\nexport function buildSectionGeometry(input: SectionGeometryInput): SectionGeometryPage[] {\n const { count, indices, templates, cullMasks, templateData, atlases, maxAtlasSize, fluids, light, ambientLight, ambientOcclusion, biomeTints } = input;\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError(\"Section atlas size must be a positive integer\");\n if (count > indices.length || count > templates.length || count > cullMasks.length) throw new RangeError(\"Section entry count exceeds its arrays\");\n if (biomeTints && biomeTints.length !== count * 3) throw new RangeError(\"Section biome tints must contain RGB for each placement\");\n if (fluids && fluids.cells.length !== 5832) throw new RangeError(\"Section fluid cells must cover an 18×18×18 neighborhood\");\n if (fluids?.waterTints && fluids.waterTints.length !== 4096 * 3) throw new RangeError(\"Section water tints must contain RGB for 4096 cells\");\n if (light && (light.length !== 5832 || light.some(level => level > 15 && level !== 255))) {\n throw new RangeError(\"Section light must cover an 18×18×18 neighborhood with levels from 0 to 15 or 255\");\n }\n if (ambientLight !== undefined && (!Number.isFinite(ambientLight) || ambientLight < 0 || ambientLight > 1)) {\n throw new RangeError(\"Section ambient light must be a number from 0 to 1\");\n }\n if (ambientOcclusion && (ambientOcclusion.length !== 5832 || ambientOcclusion.some(value => value > 1))) {\n throw new RangeError(\"Section ambient occlusion must cover an 18×18×18 neighborhood with zero or one per cell\");\n }\n const cornerBrightness = ambientOcclusion ? new Float32Array(4) : undefined;\n for (const template of templateData) {\n const { quads } = template;\n if (template.positions.length !== quads * 12 || template.normals.length !== quads * 12 ||\n template.uvs.length !== quads * 8 || template.uvBounds.length !== quads * 16 ||\n template.colors.length !== quads * 12 || template.indices.length !== quads * 6 || template.cullFaces.length !== quads ||\n (template.biomeTint && template.biomeTint.length !== quads)) {\n throw new RangeError(\"Section template arrays do not match its quad count\");\n }\n }\n const visible: number[] = [];\n const visibleAtlases = new Map<number, Set<number>>();\n for (let entry = 0; entry < count; entry++) {\n const template = templateData[templates[entry]];\n if (!template.cullFaces.some(direction => !(cullMasks[entry] & direction))) continue;\n visible.push(entry);\n if (!visibleAtlases.has(template.layer)) visibleAtlases.set(template.layer, new Set());\n visibleAtlases.get(template.layer)!.add(template.atlas);\n }\n const pages: {\n layer: number; placements: SectionGeometryPage[\"placements\"]; entries: number[];\n fluids: { quads: FluidQuads; x: number; y: number; z: number; data: SectionFluidKind; tint: ArrayLike<number> }[];\n x: number; y: number; rowHeight: number; width: number; height: number;\n }[] = [];\n const locations = new Map<number, { page: number; x: number; y: number }>();\n for (const [layer, layerAtlases] of [...visibleAtlases].sort(([a], [b]) => a - b)) {\n const firstPage = pages.length;\n for (const atlas of [...layerAtlases].sort((a, b) => Number(atlases[a].animated) - Number(atlases[b].animated) ||\n (atlases[a].animated ? a - b : atlases[b].height - atlases[a].height))) {\n const { width, height, animated } = atlases[atlas];\n if (width > maxAtlasSize || height > maxAtlasSize) throw new RangeError(\"Model atlas exceeds the section atlas size limit\");\n let selected = -1;\n for (let i = firstPage; !animated && i < pages.length; i++) {\n const page = pages[i];\n const nextRow = page.x + width > maxAtlasSize;\n if ((nextRow ? page.y + page.rowHeight : page.y) + height > maxAtlasSize) continue;\n if (nextRow) {\n page.y += page.rowHeight;\n page.x = 0;\n page.rowHeight = 0;\n }\n selected = i;\n break;\n }\n if (selected < 0) {\n selected = pages.length;\n pages.push({ layer, placements: [], entries: [], fluids: [], x: 0, y: 0, rowHeight: 0, width: 0, height: 0 });\n }\n const page = pages[selected];\n page.placements.push({ atlas, x: page.x, y: page.y });\n locations.set(atlas, { page: selected, x: page.x, y: page.y });\n page.x += width;\n page.rowHeight = Math.max(page.rowHeight, height);\n page.width = Math.max(page.width, page.x);\n page.height = Math.max(page.height, page.y + height);\n }\n }\n for (const entry of visible) pages[locations.get(templateData[templates[entry]].atlas)!.page].entries.push(entry);\n\n if (fluids) {\n const fluidPages = new Map<FluidKind, (typeof pages)[number]>();\n for (let y = 0; y < 16; y++) for (let z = 0; z < 16; z++) for (let x = 0; x < 16; x++) {\n const byte = fluids.cells[(y + 1) * 324 + (z + 1) * 18 + x + 1];\n const fluid = fluidKindOf(byte);\n if (!fluid || (byte & 128)) continue;\n const data = fluids[fluid];\n if (!data) throw new RangeError(\"Section fluid input lacks the atlas for a present fluid\");\n const quads = buildFluidQuads(fluid, (dx, dy, dz) => {\n const cell = fluids.cells[(y + 1 + dy) * 324 + (z + 1 + dz) * 18 + x + 1 + dx];\n return { fluid: fluidKindOf(cell), level: cell & 15, solid: !!(cell & 64) };\n });\n if (!quads.sprites.length) continue;\n if (!fluidPages.has(fluid)) {\n const { width, height } = atlases[data.atlas];\n if (width > maxAtlasSize || height > maxAtlasSize) throw new RangeError(\"Model atlas exceeds the section atlas size limit\");\n fluidPages.set(fluid, { layer: 2, placements: [{ atlas: data.atlas, x: 0, y: 0 }], entries: [], fluids: [],\n x: 0, y: 0, rowHeight: 0, width, height });\n }\n const tintIndex = (x + z * 16 + y * 256) * 3;\n const tint = fluid === \"water\" && fluids.waterTints ? fluids.waterTints.subarray(tintIndex, tintIndex + 3) : data.tint;\n fluidPages.get(fluid)!.fluids.push({ quads, x, y, z, data, tint });\n }\n pages.push(...[...fluidPages.values()].sort((a, b) => Number(atlases[a.placements[0].atlas].animated) -\n Number(atlases[b.placements[0].atlas].animated) || a.placements[0].atlas - b.placements[0].atlas));\n }\n\n return pages.map(page => {\n let faces = page.fluids.reduce((sum, fluid) => sum + fluid.quads.sprites.length, 0);\n for (const entry of page.entries) {\n const template = templateData[templates[entry]];\n for (let quad = 0; quad < template.quads; quad++) {\n if (!(cullMasks[entry] & template.cullFaces[quad])) faces++;\n }\n }\n const positions = new Float32Array(faces * 12), normals = new Float32Array(faces * 12);\n const uvs = new Float32Array(faces * 8), uvBounds = new Float32Array(faces * 16), colors = new Float32Array(faces * 12);\n const outputIndices = new Uint32Array(faces * 6);\n const blockIndices = new Uint16Array(faces);\n let vertex = 0, indexOffset = 0;\n for (const entry of page.entries) {\n const template = templateData[templates[entry]];\n const atlas = atlases[template.atlas];\n const placement = locations.get(template.atlas)!;\n const mapU = (u: number) => (placement.x + u * atlas.width) / page.width;\n const mapV = (v: number) => 1 - (placement.y + (1 - v) * atlas.height) / page.height;\n const offsetX = (indices[entry] % 16) * 16;\n const offsetY = Math.floor(indices[entry] / 256) * 16;\n const offsetZ = (Math.floor(indices[entry] / 16) % 16) * 16;\n const lightIndex = (offsetY / 16 + 1) * 324 + (offsetZ / 16 + 1) * 18 + offsetX / 16 + 1;\n const ambientMask = ambientOcclusion && template.ambientOcclusion !== false\n ? sectionAmbientOcclusionMask(ambientOcclusion, lightIndex) : 0;\n for (let quad = 0; quad < template.quads; quad++) {\n if (cullMasks[entry] & template.cullFaces[quad]) continue;\n blockIndices[indexOffset / 6] = indices[entry];\n if (ambientMask) quadAmbientOcclusion(template.positions, template.normals, quad, ambientMask, cornerBrightness!);\n const brightness = light ? lightBrightness(light[lightIndex + LIGHT_SAMPLE_OFFSETS[\n quadLightIndex(template.positions, template.normals, quad)]], ambientLight) : 1;\n const tint = biomeTints && template.biomeTint?.[quad] && !Number.isNaN(biomeTints[entry * 3]) ? entry * 3 : undefined;\n const start = vertex;\n for (let corner = 0; corner < 4; corner++, vertex++) {\n const source = quad * 4 + corner;\n positions[vertex * 3] = template.positions[source * 3] + offsetX;\n positions[vertex * 3 + 1] = template.positions[source * 3 + 1] + offsetY;\n positions[vertex * 3 + 2] = template.positions[source * 3 + 2] + offsetZ;\n normals[vertex * 3] = template.normals[source * 3];\n normals[vertex * 3 + 1] = template.normals[source * 3 + 1];\n normals[vertex * 3 + 2] = template.normals[source * 3 + 2];\n uvs[vertex * 2] = mapU(template.uvs[source * 2]);\n uvs[vertex * 2 + 1] = mapV(template.uvs[source * 2 + 1]);\n uvBounds[vertex * 4] = mapU(template.uvBounds[source * 4]);\n uvBounds[vertex * 4 + 1] = mapV(template.uvBounds[source * 4 + 1]);\n uvBounds[vertex * 4 + 2] = mapU(template.uvBounds[source * 4 + 2]);\n uvBounds[vertex * 4 + 3] = mapV(template.uvBounds[source * 4 + 3]);\n const factor = brightness * (ambientMask ? cornerBrightness![corner] : 1);\n colors[vertex * 3] = (tint === undefined ? template.colors[source * 3] : biomeTints![tint]) * factor;\n colors[vertex * 3 + 1] = (tint === undefined ? template.colors[source * 3 + 1] : biomeTints![tint + 1]) * factor;\n colors[vertex * 3 + 2] = (tint === undefined ? template.colors[source * 3 + 2] : biomeTints![tint + 2]) * factor;\n }\n for (let corner = 0; corner < 6; corner++) outputIndices[indexOffset++] = start + template.indices[quad * 6 + corner];\n }\n }\n for (const { quads, x, y, z, data, tint } of page.fluids) {\n const atlas = atlases[data.atlas];\n const placement = page.placements[0];\n const mapU = (u: number) => (placement.x + u * atlas.width) / page.width;\n const mapV = (v: number) => 1 - (placement.y + (1 - v) * atlas.height) / page.height;\n const lightIndex = (y + 1) * 324 + (z + 1) * 18 + x + 1;\n for (let quad = 0; quad < quads.sprites.length; quad++) {\n blockIndices[indexOffset / 6] = x + z * 16 + y * 256;\n const rect = quads.sprites[quad] === 0 ? data.still : data.flow;\n const brightness = light ? lightBrightness(fluidLightLevel(light[lightIndex],\n light[lightIndex + (quads.normals[quad * 12 + 1] < 0 ? -324 : 324)]), ambientLight) : 1;\n const start = vertex;\n for (let corner = 0; corner < 4; corner++, vertex++) {\n const source = quad * 4 + corner;\n positions[vertex * 3] = quads.positions[source * 3] + x * 16;\n positions[vertex * 3 + 1] = quads.positions[source * 3 + 1] + y * 16;\n positions[vertex * 3 + 2] = quads.positions[source * 3 + 2] + z * 16;\n normals[vertex * 3] = quads.normals[source * 3];\n normals[vertex * 3 + 1] = quads.normals[source * 3 + 1];\n normals[vertex * 3 + 2] = quads.normals[source * 3 + 2];\n uvs[vertex * 2] = mapU((rect[0] + quads.uvs[source * 2] * rect[2]) / atlas.width);\n uvs[vertex * 2 + 1] = mapV(1 - (rect[1] + (1 - quads.uvs[source * 2 + 1]) * rect[3]) / atlas.height);\n uvBounds.set([mapU(rect[0] / atlas.width), mapV(1 - (rect[1] + rect[3]) / atlas.height),\n mapU((rect[0] + rect[2]) / atlas.width), mapV(1 - rect[1] / atlas.height)], vertex * 4);\n colors[vertex * 3] = tint[0] * brightness;\n colors[vertex * 3 + 1] = tint[1] * brightness;\n colors[vertex * 3 + 2] = tint[2] * brightness;\n }\n outputIndices.set([start, start + 1, start + 2, start, start + 2, start + 3], indexOffset);\n indexOffset += 6;\n }\n }\n return { layer: page.layer, width: page.width, height: page.height, placements: page.placements, positions, normals, uvs, uvBounds, colors, indices: outputIndices, blockIndices };\n });\n}\n\n/** Returns the buffers behind each page's typed arrays for transfer to another thread. */\nexport function sectionGeometryTransferables(pages: readonly SectionGeometryPage[]): ArrayBuffer[] {\n return pages.flatMap(page => [page.positions.buffer, page.normals.buffer, page.uvs.buffer, page.uvBounds.buffer, page.colors.buffer, page.indices.buffer, page.blockIndices.buffer]);\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,mBAAmB;AAE7C,SAAS,sBAAsB,mCAAmC;AAClE,SAAS,iBAAiB,sBAAsB,iBAAiB,sBAAsB;AAgFhF,SAAS,qBAAqB,OAAoD;AACrF,QAAM,EAAE,OAAO,SAAS,WAAW,WAAW,cAAc,SAAS,cAAc,QAAQ,OAAO,cAAc,kBAAkB,WAAW,IAAI;AACjJ,MAAI,CAAC,OAAO,UAAU,YAAY,KAAK,eAAe,EAAG,OAAM,IAAI,WAAW,+CAA+C;AAC7H,MAAI,QAAQ,QAAQ,UAAU,QAAQ,UAAU,UAAU,QAAQ,UAAU,OAAQ,OAAM,IAAI,WAAW,wCAAwC;AAC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IAAI,CAAC,IAAI,KAAK,CAAC,IAAI;AAAA,QACvC;AACA,sBAAc,IAAI,CAAC,OAAO,QAAQ,GAAG,QAAQ,GAAG,OAAO,QAAQ,GAAG,QAAQ,CAAC,GAAG,WAAW;AACzF,uBAAe;AAAA,MACnB;AAAA,IACJ;AACA,WAAO,EAAE,OAAO,KAAK,OAAO,OAAO,KAAK,OAAO,QAAQ,KAAK,QAAQ,YAAY,KAAK,YAAY,WAAW,SAAS,KAAK,UAAU,QAAQ,SAAS,eAAe,aAAa;AAAA,EACrL,CAAC;AACL;AAGO,SAAS,6BAA6B,OAAsD;AAC/F,SAAO,MAAM,QAAQ,UAAQ,CAAC,KAAK,UAAU,QAAQ,KAAK,QAAQ,QAAQ,KAAK,IAAI,QAAQ,KAAK,SAAS,QAAQ,KAAK,OAAO,QAAQ,KAAK,QAAQ,QAAQ,KAAK,aAAa,MAAM,CAAC;AACvL;","names":["page"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/world/SectionGeometry.ts"],"sourcesContent":["import { buildFluidQuads, fluidKindOf } from \"../model/fluid/FluidQuads\";\nimport type { FluidKind, FluidQuads } from \"../model/fluid/FluidQuads\";\nimport { quadAmbientOcclusion, sectionAmbientOcclusionMask } from \"./_light/AmbientOcclusion\";\nimport { fluidLightLevel, LIGHT_SAMPLE_OFFSETS, lightBrightness, quadLightIndex } from \"./_light/FaceLight\";\n\n/** Static model geometry as quads: four vertices per quad, in quad order. */\nexport interface SectionTemplateData {\n quads: number;\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n uvBounds: Float32Array;\n colors: Float32Array;\n shade?: Float32Array;\n indices: Uint16Array;\n cullFaces: Uint8Array;\n biomeTint?: Uint8Array;\n atlas: number;\n layer: number;\n ambientOcclusion?: boolean;\n}\n\n/** The pixel dimensions and animation state of a source atlas. */\nexport interface SectionAtlasSize {\n width: number;\n height: number;\n animated: boolean;\n}\n\n/** One fluid kind's sprite rectangles in atlas pixels and its linear-light vertex tint. */\nexport interface SectionFluidKind {\n atlas: number;\n still: [x: number, y: number, width: number, height: number];\n flow: [x: number, y: number, width: number, height: number];\n tint: [r: number, g: number, b: number];\n}\n\n/** Fluid cells of the section plus a one-cell shell, 18×18×18, x fastest, then z, then y. */\nexport interface SectionFluidInput {\n /** Bit 128 marks a surface rendered elsewhere; the cell still supplies neighbor fluid samples. */\n cells: Uint8Array;\n /** Linear RGB per section cell, indexed by (x + 16z + 256y) * 3. Omission uses the water kind's tint. */\n waterTints?: Float32Array;\n water?: SectionFluidKind;\n lava?: SectionFluidKind;\n}\n\n/** Section placements and their shared templates, ready for geometry building. */\nexport interface SectionGeometryInput {\n count: number;\n indices: Uint16Array;\n templates: Uint16Array;\n cullMasks: Uint8Array;\n /** Linear RGB per placement; three NaN values preserve the template's colors. */\n biomeTints?: Float32Array;\n templateData: SectionTemplateData[];\n atlases: SectionAtlasSize[];\n maxAtlasSize: number;\n fluids?: SectionFluidInput;\n /** Saved brightness levels for an 18×18×18 neighborhood; 255 means unknown/full brightness. */\n light?: Uint8Array;\n /** Minimum brightness for known light levels, from 0 to 1. */\n ambientLight?: number;\n /** Opaque full cubes in an 18×18×18 neighborhood, stored as zero or one. */\n ambientOcclusion?: Uint8Array;\n}\n\n/** Merged quads and source-atlas placements for one atlas page. */\nexport interface SectionGeometryPage {\n layer: number;\n width: number;\n height: number;\n placements: { atlas: number; x: number; y: number }[];\n positions: Float32Array;\n normals: Float32Array;\n uvs: Float32Array;\n uvBounds: Float32Array;\n colors: Float32Array;\n shade: Float32Array;\n indices: Uint32Array;\n /** Owning section cell for each quad; each quad contributes two consecutive triangles. */\n blockIndices: Uint16Array;\n}\n\n/** Builds section-local geometry from visible quads, with bounded atlas pages per layer. */\nexport function buildSectionGeometry(input: SectionGeometryInput): SectionGeometryPage[] {\n const { count, indices, templates, cullMasks, templateData, atlases, maxAtlasSize, fluids, light, ambientLight, ambientOcclusion, biomeTints } = input;\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError(\"Section atlas size must be a positive integer\");\n if (count > indices.length || count > templates.length || count > cullMasks.length) throw new RangeError(\"Section entry count exceeds its arrays\");\n if (biomeTints && biomeTints.length !== count * 3) throw new RangeError(\"Section biome tints must contain RGB for each placement\");\n if (fluids && fluids.cells.length !== 5832) throw new RangeError(\"Section fluid cells must cover an 18×18×18 neighborhood\");\n if (fluids?.waterTints && fluids.waterTints.length !== 4096 * 3) throw new RangeError(\"Section water tints must contain RGB for 4096 cells\");\n if (light && (light.length !== 5832 || light.some(level => level > 15 && level !== 255))) {\n throw new RangeError(\"Section light must cover an 18×18×18 neighborhood with levels from 0 to 15 or 255\");\n }\n if (ambientLight !== undefined && (!Number.isFinite(ambientLight) || ambientLight < 0 || ambientLight > 1)) {\n throw new RangeError(\"Section ambient light must be a number from 0 to 1\");\n }\n if (ambientOcclusion && (ambientOcclusion.length !== 5832 || ambientOcclusion.some(value => value > 1))) {\n throw new RangeError(\"Section ambient occlusion must cover an 18×18×18 neighborhood with zero or one per cell\");\n }\n const cornerBrightness = ambientOcclusion ? new Float32Array(4) : undefined;\n for (const template of templateData) {\n const { quads } = template;\n if (template.positions.length !== quads * 12 || template.normals.length !== quads * 12 ||\n template.uvs.length !== quads * 8 || template.uvBounds.length !== quads * 16 ||\n template.colors.length !== quads * 12 || template.indices.length !== quads * 6 || template.cullFaces.length !== quads ||\n (template.shade && template.shade.length !== quads * 4) ||\n (template.biomeTint && template.biomeTint.length !== quads)) {\n throw new RangeError(\"Section template arrays do not match its quad count\");\n }\n }\n const visible: number[] = [];\n const visibleAtlases = new Map<number, Set<number>>();\n for (let entry = 0; entry < count; entry++) {\n const template = templateData[templates[entry]];\n if (!template.cullFaces.some(direction => !(cullMasks[entry] & direction))) continue;\n visible.push(entry);\n if (!visibleAtlases.has(template.layer)) visibleAtlases.set(template.layer, new Set());\n visibleAtlases.get(template.layer)!.add(template.atlas);\n }\n const pages: {\n layer: number; placements: SectionGeometryPage[\"placements\"]; entries: number[];\n fluids: { quads: FluidQuads; x: number; y: number; z: number; data: SectionFluidKind; tint: ArrayLike<number> }[];\n x: number; y: number; rowHeight: number; width: number; height: number;\n }[] = [];\n const locations = new Map<number, { page: number; x: number; y: number }>();\n for (const [layer, layerAtlases] of [...visibleAtlases].sort(([a], [b]) => a - b)) {\n const firstPage = pages.length;\n for (const atlas of [...layerAtlases].sort((a, b) => Number(atlases[a].animated) - Number(atlases[b].animated) ||\n (atlases[a].animated ? a - b : atlases[b].height - atlases[a].height))) {\n const { width, height, animated } = atlases[atlas];\n if (width > maxAtlasSize || height > maxAtlasSize) throw new RangeError(\"Model atlas exceeds the section atlas size limit\");\n let selected = -1;\n for (let i = firstPage; !animated && i < pages.length; i++) {\n const page = pages[i];\n const nextRow = page.x + width > maxAtlasSize;\n if ((nextRow ? page.y + page.rowHeight : page.y) + height > maxAtlasSize) continue;\n if (nextRow) {\n page.y += page.rowHeight;\n page.x = 0;\n page.rowHeight = 0;\n }\n selected = i;\n break;\n }\n if (selected < 0) {\n selected = pages.length;\n pages.push({ layer, placements: [], entries: [], fluids: [], x: 0, y: 0, rowHeight: 0, width: 0, height: 0 });\n }\n const page = pages[selected];\n page.placements.push({ atlas, x: page.x, y: page.y });\n locations.set(atlas, { page: selected, x: page.x, y: page.y });\n page.x += width;\n page.rowHeight = Math.max(page.rowHeight, height);\n page.width = Math.max(page.width, page.x);\n page.height = Math.max(page.height, page.y + height);\n }\n }\n for (const entry of visible) pages[locations.get(templateData[templates[entry]].atlas)!.page].entries.push(entry);\n\n if (fluids) {\n const fluidPages = new Map<FluidKind, (typeof pages)[number]>();\n for (let y = 0; y < 16; y++) for (let z = 0; z < 16; z++) for (let x = 0; x < 16; x++) {\n const byte = fluids.cells[(y + 1) * 324 + (z + 1) * 18 + x + 1];\n const fluid = fluidKindOf(byte);\n if (!fluid || (byte & 128)) continue;\n const data = fluids[fluid];\n if (!data) throw new RangeError(\"Section fluid input lacks the atlas for a present fluid\");\n const quads = buildFluidQuads(fluid, (dx, dy, dz) => {\n const cell = fluids.cells[(y + 1 + dy) * 324 + (z + 1 + dz) * 18 + x + 1 + dx];\n return { fluid: fluidKindOf(cell), level: cell & 15, solid: !!(cell & 64) };\n });\n if (!quads.sprites.length) continue;\n if (!fluidPages.has(fluid)) {\n const { width, height } = atlases[data.atlas];\n if (width > maxAtlasSize || height > maxAtlasSize) throw new RangeError(\"Model atlas exceeds the section atlas size limit\");\n fluidPages.set(fluid, { layer: 2, placements: [{ atlas: data.atlas, x: 0, y: 0 }], entries: [], fluids: [],\n x: 0, y: 0, rowHeight: 0, width, height });\n }\n const tintIndex = (x + z * 16 + y * 256) * 3;\n const tint = fluid === \"water\" && fluids.waterTints ? fluids.waterTints.subarray(tintIndex, tintIndex + 3) : data.tint;\n fluidPages.get(fluid)!.fluids.push({ quads, x, y, z, data, tint });\n }\n pages.push(...[...fluidPages.values()].sort((a, b) => Number(atlases[a.placements[0].atlas].animated) -\n Number(atlases[b.placements[0].atlas].animated) || a.placements[0].atlas - b.placements[0].atlas));\n }\n\n return pages.map(page => {\n let faces = page.fluids.reduce((sum, fluid) => sum + fluid.quads.sprites.length, 0);\n for (const entry of page.entries) {\n const template = templateData[templates[entry]];\n for (let quad = 0; quad < template.quads; quad++) {\n if (!(cullMasks[entry] & template.cullFaces[quad])) faces++;\n }\n }\n const positions = new Float32Array(faces * 12), normals = new Float32Array(faces * 12);\n const uvs = new Float32Array(faces * 8), uvBounds = new Float32Array(faces * 16), colors = new Float32Array(faces * 12);\n const shade = new Float32Array(faces * 4).fill(1);\n const outputIndices = new Uint32Array(faces * 6);\n const blockIndices = new Uint16Array(faces);\n let vertex = 0, indexOffset = 0;\n for (const entry of page.entries) {\n const template = templateData[templates[entry]];\n const atlas = atlases[template.atlas];\n const placement = locations.get(template.atlas)!;\n const mapU = (u: number) => (placement.x + u * atlas.width) / page.width;\n const mapV = (v: number) => 1 - (placement.y + (1 - v) * atlas.height) / page.height;\n const offsetX = (indices[entry] % 16) * 16;\n const offsetY = Math.floor(indices[entry] / 256) * 16;\n const offsetZ = (Math.floor(indices[entry] / 16) % 16) * 16;\n const lightIndex = (offsetY / 16 + 1) * 324 + (offsetZ / 16 + 1) * 18 + offsetX / 16 + 1;\n const ambientMask = ambientOcclusion && template.ambientOcclusion !== false\n ? sectionAmbientOcclusionMask(ambientOcclusion, lightIndex) : 0;\n for (let quad = 0; quad < template.quads; quad++) {\n if (cullMasks[entry] & template.cullFaces[quad]) continue;\n blockIndices[indexOffset / 6] = indices[entry];\n if (ambientMask) quadAmbientOcclusion(template.positions, template.normals, quad, ambientMask, cornerBrightness!);\n const brightness = light ? lightBrightness(light[lightIndex + LIGHT_SAMPLE_OFFSETS[\n quadLightIndex(template.positions, template.normals, quad)]], ambientLight) : 1;\n const tint = biomeTints && template.biomeTint?.[quad] && !Number.isNaN(biomeTints[entry * 3]) ? entry * 3 : undefined;\n const start = vertex;\n for (let corner = 0; corner < 4; corner++, vertex++) {\n const source = quad * 4 + corner;\n positions[vertex * 3] = template.positions[source * 3] + offsetX;\n positions[vertex * 3 + 1] = template.positions[source * 3 + 1] + offsetY;\n positions[vertex * 3 + 2] = template.positions[source * 3 + 2] + offsetZ;\n normals[vertex * 3] = template.normals[source * 3];\n normals[vertex * 3 + 1] = template.normals[source * 3 + 1];\n normals[vertex * 3 + 2] = template.normals[source * 3 + 2];\n shade[vertex] = template.shade?.[source] ?? 1;\n uvs[vertex * 2] = mapU(template.uvs[source * 2]);\n uvs[vertex * 2 + 1] = mapV(template.uvs[source * 2 + 1]);\n uvBounds[vertex * 4] = mapU(template.uvBounds[source * 4]);\n uvBounds[vertex * 4 + 1] = mapV(template.uvBounds[source * 4 + 1]);\n uvBounds[vertex * 4 + 2] = mapU(template.uvBounds[source * 4 + 2]);\n uvBounds[vertex * 4 + 3] = mapV(template.uvBounds[source * 4 + 3]);\n const factor = brightness * (ambientMask ? cornerBrightness![corner] : 1);\n colors[vertex * 3] = (tint === undefined ? template.colors[source * 3] : biomeTints![tint]) * factor;\n colors[vertex * 3 + 1] = (tint === undefined ? template.colors[source * 3 + 1] : biomeTints![tint + 1]) * factor;\n colors[vertex * 3 + 2] = (tint === undefined ? template.colors[source * 3 + 2] : biomeTints![tint + 2]) * factor;\n }\n for (let corner = 0; corner < 6; corner++) outputIndices[indexOffset++] = start + template.indices[quad * 6 + corner];\n }\n }\n for (const { quads, x, y, z, data, tint } of page.fluids) {\n const atlas = atlases[data.atlas];\n const placement = page.placements[0];\n const mapU = (u: number) => (placement.x + u * atlas.width) / page.width;\n const mapV = (v: number) => 1 - (placement.y + (1 - v) * atlas.height) / page.height;\n const lightIndex = (y + 1) * 324 + (z + 1) * 18 + x + 1;\n for (let quad = 0; quad < quads.sprites.length; quad++) {\n blockIndices[indexOffset / 6] = x + z * 16 + y * 256;\n const rect = quads.sprites[quad] === 0 ? data.still : data.flow;\n const brightness = light ? lightBrightness(fluidLightLevel(light[lightIndex],\n light[lightIndex + (quads.normals[quad * 12 + 1] < 0 ? -324 : 324)]), ambientLight) : 1;\n const start = vertex;\n for (let corner = 0; corner < 4; corner++, vertex++) {\n const source = quad * 4 + corner;\n positions[vertex * 3] = quads.positions[source * 3] + x * 16;\n positions[vertex * 3 + 1] = quads.positions[source * 3 + 1] + y * 16;\n positions[vertex * 3 + 2] = quads.positions[source * 3 + 2] + z * 16;\n normals[vertex * 3] = quads.normals[source * 3];\n normals[vertex * 3 + 1] = quads.normals[source * 3 + 1];\n normals[vertex * 3 + 2] = quads.normals[source * 3 + 2];\n uvs[vertex * 2] = mapU((rect[0] + quads.uvs[source * 2] * rect[2]) / atlas.width);\n uvs[vertex * 2 + 1] = mapV(1 - (rect[1] + (1 - quads.uvs[source * 2 + 1]) * rect[3]) / atlas.height);\n uvBounds.set([mapU(rect[0] / atlas.width), mapV(1 - (rect[1] + rect[3]) / atlas.height),\n mapU((rect[0] + rect[2]) / atlas.width), mapV(1 - rect[1] / atlas.height)], vertex * 4);\n colors[vertex * 3] = tint[0] * brightness;\n colors[vertex * 3 + 1] = tint[1] * brightness;\n colors[vertex * 3 + 2] = tint[2] * brightness;\n }\n outputIndices.set([start, start + 1, start + 2, start, start + 2, start + 3], indexOffset);\n indexOffset += 6;\n }\n }\n return { layer: page.layer, width: page.width, height: page.height, placements: page.placements, positions, normals, uvs, uvBounds, colors, shade, indices: outputIndices, blockIndices };\n });\n}\n\n/** Returns the buffers behind each page's typed arrays for transfer to another thread. */\nexport function sectionGeometryTransferables(pages: readonly SectionGeometryPage[]): ArrayBuffer[] {\n return pages.flatMap(page => [page.positions.buffer, page.normals.buffer, page.uvs.buffer, page.uvBounds.buffer, page.colors.buffer, page.shade.buffer, page.indices.buffer, page.blockIndices.buffer]);\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,mBAAmB;AAE7C,SAAS,sBAAsB,mCAAmC;AAClE,SAAS,iBAAiB,sBAAsB,iBAAiB,sBAAsB;AAkFhF,SAAS,qBAAqB,OAAoD;AACrF,QAAM,EAAE,OAAO,SAAS,WAAW,WAAW,cAAc,SAAS,cAAc,QAAQ,OAAO,cAAc,kBAAkB,WAAW,IAAI;AACjJ,MAAI,CAAC,OAAO,UAAU,YAAY,KAAK,eAAe,EAAG,OAAM,IAAI,WAAW,+CAA+C;AAC7H,MAAI,QAAQ,QAAQ,UAAU,QAAQ,UAAU,UAAU,QAAQ,UAAU,OAAQ,OAAM,IAAI,WAAW,wCAAwC;AACjJ,MAAI,cAAc,WAAW,WAAW,QAAQ,EAAG,OAAM,IAAI,WAAW,yDAAyD;AACjI,MAAI,UAAU,OAAO,MAAM,WAAW,KAAM,OAAM,IAAI,WAAW,+DAAyD;AAC1H,MAAI,QAAQ,cAAc,OAAO,WAAW,WAAW,OAAO,EAAG,OAAM,IAAI,WAAW,qDAAqD;AAC3I,MAAI,UAAU,MAAM,WAAW,QAAQ,MAAM,KAAK,WAAS,QAAQ,MAAM,UAAU,GAAG,IAAI;AACtF,UAAM,IAAI,WAAW,yFAAmF;AAAA,EAC5G;AACA,MAAI,iBAAiB,WAAc,CAAC,OAAO,SA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AO,QAAQ,KAAK,QAAQ,YAAY,KAAK,YAAY,WAAW,SAAS,KAAK,UAAU,QAAQ,OAAO,SAAS,eAAe,aAAa;AAAA,EAC5L,CAAC;AACL;AAGO,SAAS,6BAA6B,OAAsD;AAC/F,SAAO,MAAM,QAAQ,UAAQ,CAAC,KAAK,UAAU,QAAQ,KAAK,QAAQ,QAAQ,KAAK,IAAI,QAAQ,KAAK,SAAS,QAAQ,KAAK,OAAO,QAAQ,KAAK,MAAM,QAAQ,KAAK,QAAQ,QAAQ,KAAK,aAAa,MAAM,CAAC;AAC1M;","names":["page"]}
|
|
@@ -51,6 +51,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
51
51
|
uvs: new Float32Array(quads * 8),
|
|
52
52
|
uvBounds: new Float32Array(quads * 16),
|
|
53
53
|
colors: new Float32Array(quads * 12),
|
|
54
|
+
shade: new Float32Array(quads * 4),
|
|
54
55
|
indices: new Uint16Array(quads * 6),
|
|
55
56
|
cullFaces: new Uint8Array(template.cullFaces),
|
|
56
57
|
biomeTint: template.biomeTint ? new Uint8Array(template.biomeTint) : void 0,
|
|
@@ -62,6 +63,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
62
63
|
const uv = template.geometry.getAttribute("uv");
|
|
63
64
|
const bounds = template.geometry.getAttribute("uvBounds");
|
|
64
65
|
const color = template.geometry.getAttribute("color");
|
|
66
|
+
const shade = template.geometry.getAttribute("shade");
|
|
65
67
|
for (let vertex = 0; vertex < quads * 4; vertex++) {
|
|
66
68
|
data.positions.set([position.getX(vertex), position.getY(vertex), position.getZ(vertex)], vertex * 3);
|
|
67
69
|
data.normals.set([normal.getX(vertex), normal.getY(vertex), normal.getZ(vertex)], vertex * 3);
|
|
@@ -73,6 +75,7 @@ function toInput(entries, maxAtlasSize, fluids, lighting) {
|
|
|
73
75
|
bounds?.getW(vertex) ?? 1
|
|
74
76
|
], vertex * 4);
|
|
75
77
|
data.colors.set([color?.getX(vertex) ?? 1, color?.getY(vertex) ?? 1, color?.getZ(vertex) ?? 1], vertex * 3);
|
|
78
|
+
data.shade[vertex] = shade?.getX(vertex) ?? 1;
|
|
76
79
|
}
|
|
77
80
|
for (let i2 = 0; i2 < data.indices.length; i2++) data.indices[i2] = indices.getX(i2) - 4 * Math.floor(i2 / 6);
|
|
78
81
|
templateCache.set(template, data);
|
|
@@ -144,6 +147,7 @@ var SectionMesh = class _SectionMesh extends Group {
|
|
|
144
147
|
geometry.setAttribute("uv", new Float32BufferAttribute(page.uvs.buffer, 2));
|
|
145
148
|
geometry.setAttribute("uvBounds", new Float32BufferAttribute(page.uvBounds.buffer, 4));
|
|
146
149
|
geometry.setAttribute("color", new Float32BufferAttribute(page.colors.buffer, 3));
|
|
150
|
+
geometry.setAttribute("shade", new Float32BufferAttribute(page.shade.buffer, 1));
|
|
147
151
|
geometry.setIndex(new Uint32BufferAttribute(page.indices.buffer, 1));
|
|
148
152
|
geometry.computeBoundingBox();
|
|
149
153
|
geometry.computeBoundingSphere();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/world/SectionMesh.ts"],"sourcesContent":["import { BufferGeometry, Color, DoubleSide, Float32BufferAttribute, FrontSide, Group, Material, Mesh, MeshBasicMaterial, ShaderMaterial, Texture, Uint32BufferAttribute } from \"three\";\nimport { createCanvas } from \"../canvas/CanvasCompat\";\nimport { Materials } from \"../Materials\";\nimport type { MineRenderScene } from \"../renderer/MineRenderScene\";\nimport { TextureAtlas } from \"../texture/TextureAtlas\";\nimport { buildSectionGeometry, SectionGeometryInput, SectionGeometryPage, SectionTemplateData } from \"./SectionGeometry\";\nimport { SectionWorker } from \"./SectionWorker\";\nimport type { Intersection } from \"three\";\n\n/** Shared quad geometry and atlas data prepared for section merging. */\nexport interface SectionMeshTemplate {\n geometry: BufferGeometry;\n atlas: TextureAtlas;\n cullFaces: Uint8Array;\n /** Quads that accept a placement's biome tint, stored as zero or one. */\n biomeTint?: Uint8Array;\n occludes: boolean;\n /** Whether the model permits corner shading from neighboring full cubes. */\n ambientOcclusion?: boolean;\n layer: 0 | 1;\n}\n\n/** One block placement in a section, with its storage index and hidden-face mask. */\nexport interface SectionMeshEntry {\n index: number;\n template: SectionMeshTemplate;\n cullMask: number;\n /** Linear RGB replacing automatic biome colors on eligible quads. */\n biomeTint?: readonly [number, number, number];\n}\n\n/** Fluid cells for one section and the shared atlases of the kinds present. */\nexport interface SectionFluids {\n cells: Uint8Array;\n /** Linear RGB per section cell, indexed by (x + 16z + 256y) * 3. */\n waterTints?: Float32Array;\n water?: TextureAtlas;\n lava?: TextureAtlas;\n}\n\nconst templateCache = new WeakMap<SectionMeshTemplate, SectionTemplateData>();\nconst WATER_TINT = new Color(0x3f76e4).toArray() as [number, number, number];\n\nfunction toInput(entries: readonly SectionMeshEntry[], maxAtlasSize: number, fluids?: SectionFluids,\n lighting?: Pick<SectionGeometryInput, \"light\" | \"ambientLight\" | \"ambientOcclusion\">): { input: SectionGeometryInput; atlases: TextureAtlas[] } {\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError(\"Section atlas size must be a positive integer\");\n const atlases: TextureAtlas[] = [];\n const atlasIds = new Map<TextureAtlas, number>();\n const templateIds = new Map<SectionMeshTemplate, number>();\n const input: SectionGeometryInput = {\n count: entries.length, indices: new Uint16Array(entries.length), templates: new Uint16Array(entries.length),\n cullMasks: new Uint8Array(entries.length), templateData: [], atlases: [], maxAtlasSize, ...lighting\n };\n for (let i = 0; i < entries.length; i++) {\n const { index, template, cullMask, biomeTint } = entries[i];\n if (biomeTint) {\n input.biomeTints ??= new Float32Array(entries.length * 3).fill(NaN);\n input.biomeTints.set(biomeTint, i * 3);\n }\n let id = templateIds.get(template);\n if (id === undefined) {\n let atlas = atlasIds.get(template.atlas);\n if (atlas === undefined) {\n atlas = atlases.length;\n atlasIds.set(template.atlas, atlas);\n atlases.push(template.atlas);\n input.atlases.push({ width: template.atlas.image.width, height: template.atlas.image.height, animated: template.atlas.hasAnimation });\n }\n let data = templateCache.get(template);\n if (!data) {\n const indices = template.geometry.getIndex()!;\n const position = template.geometry.getAttribute(\"position\");\n const quads = indices.count / 6;\n if (indices.count % 6 !== 0 || position.count !== quads * 4) {\n throw new RangeError(\"Section template geometry must hold four vertices and six indices per quad\");\n }\n data = {\n quads, positions: new Float32Array(quads * 12), normals: new Float32Array(quads * 12), uvs: new Float32Array(quads * 8),\n uvBounds: new Float32Array(quads * 16), colors: new Float32Array(quads * 12), indices: new Uint16Array(quads * 6),\n cullFaces: new Uint8Array(template.cullFaces), biomeTint: template.biomeTint ? new Uint8Array(template.biomeTint) : undefined, atlas: 0, layer: template.layer, ambientOcclusion: template.ambientOcclusion\n };\n const normal = template.geometry.getAttribute(\"normal\");\n const uv = template.geometry.getAttribute(\"uv\");\n const bounds = template.geometry.getAttribute(\"uvBounds\");\n const color = template.geometry.getAttribute(\"color\");\n for (let vertex = 0; vertex < quads * 4; vertex++) {\n data.positions.set([position.getX(vertex), position.getY(vertex), position.getZ(vertex)], vertex * 3);\n data.normals.set([normal.getX(vertex), normal.getY(vertex), normal.getZ(vertex)], vertex * 3);\n data.uvs.set([uv.getX(vertex), uv.getY(vertex)], vertex * 2);\n data.uvBounds.set([bounds?.getX(vertex) ?? 0, bounds?.getY(vertex) ?? 0,\n bounds?.getZ(vertex) ?? 1, bounds?.getW(vertex) ?? 1], vertex * 4);\n data.colors.set([color?.getX(vertex) ?? 1, color?.getY(vertex) ?? 1, color?.getZ(vertex) ?? 1], vertex * 3);\n }\n for (let i = 0; i < data.indices.length; i++) data.indices[i] = indices.getX(i) - 4 * Math.floor(i / 6);\n templateCache.set(template, data);\n }\n id = input.templateData.length;\n templateIds.set(template, id);\n // Atlas IDs belong to each build; cached buffers can be shared across concurrent builds.\n input.templateData.push({ ...data, atlas });\n }\n input.indices[i] = index;\n input.templates[i] = id;\n input.cullMasks[i] = cullMask;\n }\n if (fluids) {\n input.fluids = { cells: fluids.cells, waterTints: fluids.waterTints };\n for (const kind of [\"water\", \"lava\"] as const) {\n const atlas = fluids[kind];\n if (!atlas) continue;\n let id = atlasIds.get(atlas);\n if (id === undefined) {\n id = atlases.length;\n atlasIds.set(atlas, id);\n atlases.push(atlas);\n input.atlases.push({ width: atlas.image.width, height: atlas.image.height, animated: atlas.hasAnimation });\n }\n input.fluids[kind] = {\n atlas: id, still: [...atlas.positions.still, ...atlas.sizes.still],\n flow: [...atlas.positions.flow, ...atlas.sizes.flow], tint: kind === \"water\" ? WATER_TINT : [1, 1, 1]\n };\n }\n }\n return { input, atlases };\n}\n\n/** Merged terrain geometry and atlas pages for one 16×16×16 section. Owns its generated render resources. */\nexport class SectionMesh extends Group {\n\n private readonly ownedMeshes: { mesh: Mesh<BufferGeometry, Material>; texture?: Texture; unsubscribe: (() => void)[] }[] = [];\n private readonly blockIndices = new Map<Mesh, Uint16Array>();\n\n /** Returns the owning section cell for a triangle hit on this mesh's merged geometry. */\n public getBlockIndex(hit: Intersection): number | undefined {\n if (hit.faceIndex === undefined || hit.faceIndex === null) return undefined;\n return this.blockIndices.get(hit.object as Mesh)?.[Math.floor(hit.faceIndex / 2)];\n }\n\n /** Builds section-local meshes from visible quads. `maxAtlasSize` limits each atlas dimension in pixels. */\n public static build(entries: readonly SectionMeshEntry[], maxAtlasSize = 2048, fluids?: SectionFluids,\n lighting?: Pick<SectionGeometryInput, \"light\" | \"ambientLight\" | \"ambientOcclusion\">): SectionMesh {\n const { input, atlases } = toInput(entries, maxAtlasSize, fluids, lighting);\n return this.fromPages(buildSectionGeometry(input), atlases);\n }\n\n /** Builds section-local meshes in a browser worker when available, with synchronous fallback. */\n public static async buildAsync(entries: readonly SectionMeshEntry[], maxAtlasSize = 2048, fluids?: SectionFluids,\n lighting?: Pick<SectionGeometryInput, \"light\" | \"ambientLight\" | \"ambientOcclusion\">): Promise<SectionMesh> {\n const { input, atlases } = toInput(entries, maxAtlasSize, fluids, lighting);\n const worker = SectionWorker.shared();\n const pages = worker ? await worker.build(input).catch(() => buildSectionGeometry(input)) : buildSectionGeometry(input);\n return this.fromPages(pages, atlases);\n }\n\n private static fromPages(pages: SectionGeometryPage[], atlases: TextureAtlas[]): SectionMesh {\n const section = new SectionMesh();\n for (const page of pages) {\n const canvas = createCanvas(page.width, page.height);\n const context = canvas.getContext(\"2d\") as CanvasRenderingContext2D;\n for (const { atlas, x, y } of page.placements) {\n context.drawImage(atlases[atlas].image.canvas as CanvasImageSource, x, y);\n }\n const geometry = new BufferGeometry();\n // Passing buffers keeps Three's typed attributes from copying the builder's arrays.\n geometry.setAttribute(\"position\", new Float32BufferAttribute(page.positions.buffer, 3));\n geometry.setAttribute(\"normal\", new Float32BufferAttribute(page.normals.buffer, 3));\n geometry.setAttribute(\"uv\", new Float32BufferAttribute(page.uvs.buffer, 2));\n geometry.setAttribute(\"uvBounds\", new Float32BufferAttribute(page.uvBounds.buffer, 4));\n geometry.setAttribute(\"color\", new Float32BufferAttribute(page.colors.buffer, 3));\n geometry.setIndex(new Uint32BufferAttribute(page.indices.buffer, 1));\n geometry.computeBoundingBox();\n geometry.computeBoundingSphere();\n const transparent = page.layer === 2 ? atlases[page.placements[0].atlas].hasTranslucency : page.layer === 1;\n const material = Materials.createShadedCanvasMaterial(canvas as HTMLCanvasElement, transparent, false, true);\n material.side = FrontSide;\n if (page.layer === 2) {\n material.side = DoubleSide;\n material.forceSinglePass = true;\n material.depthWrite = !material.transparent;\n }\n material.vertexColors = true;\n const texture = (material as ShaderMaterial).uniforms?.map?.value ?? (material as MeshBasicMaterial).map;\n const mesh = new Mesh(geometry, material);\n section.add(mesh);\n section.blockIndices.set(mesh, page.blockIndices);\n const unsubscribe: (() => void)[] = [];\n for (const { atlas: id, x, y } of page.placements) {\n const atlas = atlases[id];\n if (!atlas.hasAnimation) continue;\n unsubscribe.push(atlas.subscribe(() => {\n context.clearRect(x, y, atlas.image.width, atlas.image.height);\n context.drawImage(atlas.image.canvas as CanvasImageSource, x, y);\n texture.needsUpdate = true;\n section.traverseAncestors(parent => {\n if ((parent as MineRenderScene).isMineRenderScene) (parent as MineRenderScene).dirty = true;\n });\n }));\n }\n section.ownedMeshes.push({ mesh, texture, unsubscribe });\n }\n return section;\n }\n\n public dispose(): void {\n for (const { mesh, texture, unsubscribe } of this.ownedMeshes.splice(0)) {\n for (const stop of unsubscribe) stop();\n mesh.removeFromParent();\n mesh.geometry.dispose();\n mesh.material.dispose();\n texture?.dispose();\n }\n this.blockIndices.clear();\n this.removeFromParent();\n super.dispose();\n }\n\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,OAAO,YAAY,wBAAwB,WAAW,OAAiB,MAAkD,6BAA6B;AAC/K,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAG1B,SAAS,4BAA4F;AACrG,SAAS,qBAAqB;AAkC9B,IAAM,gBAAgB,oBAAI,QAAkD;AAC5E,IAAM,aAAa,IAAI,MAAM,OAAQ,EAAE,QAAQ;AAE/C,SAAS,QAAQ,SAAsC,cAAsB,QAC5D,UAAgJ;AAC7J,MAAI,CAAC,OAAO,UAAU,YAAY,KAAK,eAAe,EAAG,OAAM,IAAI,WAAW,+CAA+C;AAC7H,QAAM,UAA0B,CAAC;AACjC,QAAM,WAAW,oBAAI,IAA0B;AAC/C,QAAM,cAAc,oBAAI,IAAiC;AACzD,QAAM,QAA8B;AAAA,IAChC,OAAO,QAAQ;AAAA,IAAQ,SAAS,IAAI,YAAY,QAAQ,MAAM;AAAA,IAAG,WAAW,IAAI,YAAY,QAAQ,MAAM;AAAA,IAC1G,WAAW,IAAI,WAAW,QAAQ,MAAM;AAAA,IAAG,cAAc,CAAC;AAAA,IAAG,SAAS,CAAC;AAAA,IAAG;AAAA,IAAc,GAAG;AAAA,EAC/F;AACA,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACrC,UAAM,EAAE,OAAO,UAAU,UAAU,UAAU,IAAI,QAAQ,CAAC;AAC1D,QAAI,WAAW;AACX,YAAM,eAAN,MAAM,aAAe,IAAI,aAAa,QAAQ,SAAS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SAAK,aAAa,MAAM;AACxB,SAAK,iBAAiB;AACtB,UAAM,QAAQ;AAAA,EAClB;AAEJ;","names":["i"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/world/SectionMesh.ts"],"sourcesContent":["import { BufferGeometry, Color, DoubleSide, Float32BufferAttribute, FrontSide, Group, Material, Mesh, MeshBasicMaterial, ShaderMaterial, Texture, Uint32BufferAttribute } from \"three\";\nimport { createCanvas } from \"../canvas/CanvasCompat\";\nimport { Materials } from \"../Materials\";\nimport type { MineRenderScene } from \"../renderer/MineRenderScene\";\nimport { TextureAtlas } from \"../texture/TextureAtlas\";\nimport { buildSectionGeometry, SectionGeometryInput, SectionGeometryPage, SectionTemplateData } from \"./SectionGeometry\";\nimport { SectionWorker } from \"./SectionWorker\";\nimport type { Intersection } from \"three\";\n\n/** Shared quad geometry and atlas data prepared for section merging. */\nexport interface SectionMeshTemplate {\n geometry: BufferGeometry;\n atlas: TextureAtlas;\n cullFaces: Uint8Array;\n /** Quads that accept a placement's biome tint, stored as zero or one. */\n biomeTint?: Uint8Array;\n occludes: boolean;\n /** Whether the model permits corner shading from neighboring full cubes. */\n ambientOcclusion?: boolean;\n layer: 0 | 1;\n}\n\n/** One block placement in a section, with its storage index and hidden-face mask. */\nexport interface SectionMeshEntry {\n index: number;\n template: SectionMeshTemplate;\n cullMask: number;\n /** Linear RGB replacing automatic biome colors on eligible quads. */\n biomeTint?: readonly [number, number, number];\n}\n\n/** Fluid cells for one section and the shared atlases of the kinds present. */\nexport interface SectionFluids {\n cells: Uint8Array;\n /** Linear RGB per section cell, indexed by (x + 16z + 256y) * 3. */\n waterTints?: Float32Array;\n water?: TextureAtlas;\n lava?: TextureAtlas;\n}\n\nconst templateCache = new WeakMap<SectionMeshTemplate, SectionTemplateData>();\nconst WATER_TINT = new Color(0x3f76e4).toArray() as [number, number, number];\n\nfunction toInput(entries: readonly SectionMeshEntry[], maxAtlasSize: number, fluids?: SectionFluids,\n lighting?: Pick<SectionGeometryInput, \"light\" | \"ambientLight\" | \"ambientOcclusion\">): { input: SectionGeometryInput; atlases: TextureAtlas[] } {\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 1) throw new RangeError(\"Section atlas size must be a positive integer\");\n const atlases: TextureAtlas[] = [];\n const atlasIds = new Map<TextureAtlas, number>();\n const templateIds = new Map<SectionMeshTemplate, number>();\n const input: SectionGeometryInput = {\n count: entries.length, indices: new Uint16Array(entries.length), templates: new Uint16Array(entries.length),\n cullMasks: new Uint8Array(entries.length), templateData: [], atlases: [], maxAtlasSize, ...lighting\n };\n for (let i = 0; i < entries.length; i++) {\n const { index, template, cullMask, biomeTint } = entries[i];\n if (biomeTint) {\n input.biomeTints ??= new Float32Array(entries.length * 3).fill(NaN);\n input.biomeTints.set(biomeTint, i * 3);\n }\n let id = templateIds.get(template);\n if (id === undefined) {\n let atlas = atlasIds.get(template.atlas);\n if (atlas === undefined) {\n atlas = atlases.length;\n atlasIds.set(template.atlas, atlas);\n atlases.push(template.atlas);\n input.atlases.push({ width: template.atlas.image.width, height: template.atlas.image.height, animated: template.atlas.hasAnimation });\n }\n let data = templateCache.get(template);\n if (!data) {\n const indices = template.geometry.getIndex()!;\n const position = template.geometry.getAttribute(\"position\");\n const quads = indices.count / 6;\n if (indices.count % 6 !== 0 || position.count !== quads * 4) {\n throw new RangeError(\"Section template geometry must hold four vertices and six indices per quad\");\n }\n data = {\n quads, positions: new Float32Array(quads * 12), normals: new Float32Array(quads * 12), uvs: new Float32Array(quads * 8),\n uvBounds: new Float32Array(quads * 16), colors: new Float32Array(quads * 12), shade: new Float32Array(quads * 4), indices: new Uint16Array(quads * 6),\n cullFaces: new Uint8Array(template.cullFaces), biomeTint: template.biomeTint ? new Uint8Array(template.biomeTint) : undefined, atlas: 0, layer: template.layer, ambientOcclusion: template.ambientOcclusion\n };\n const normal = template.geometry.getAttribute(\"normal\");\n const uv = template.geometry.getAttribute(\"uv\");\n const bounds = template.geometry.getAttribute(\"uvBounds\");\n const color = template.geometry.getAttribute(\"color\");\n const shade = template.geometry.getAttribute(\"shade\");\n for (let vertex = 0; vertex < quads * 4; vertex++) {\n data.positions.set([position.getX(vertex), position.getY(vertex), position.getZ(vertex)], vertex * 3);\n data.normals.set([normal.getX(vertex), normal.getY(vertex), normal.getZ(vertex)], vertex * 3);\n data.uvs.set([uv.getX(vertex), uv.getY(vertex)], vertex * 2);\n data.uvBounds.set([bounds?.getX(vertex) ?? 0, bounds?.getY(vertex) ?? 0,\n bounds?.getZ(vertex) ?? 1, bounds?.getW(vertex) ?? 1], vertex * 4);\n data.colors.set([color?.getX(vertex) ?? 1, color?.getY(vertex) ?? 1, color?.getZ(vertex) ?? 1], vertex * 3);\n data.shade![vertex] = shade?.getX(vertex) ?? 1;\n }\n for (let i = 0; i < data.indices.length; i++) data.indices[i] = indices.getX(i) - 4 * Math.floor(i / 6);\n templateCache.set(template, data);\n }\n id = input.templateData.length;\n templateIds.set(template, id);\n // Atlas IDs belong to each build; cached buffers can be shared across concurrent builds.\n input.templateData.push({ ...data, atlas });\n }\n input.indices[i] = index;\n input.templates[i] = id;\n input.cullMasks[i] = cullMask;\n }\n if (fluids) {\n input.fluids = { cells: fluids.cells, waterTints: fluids.waterTints };\n for (const kind of [\"water\", \"lava\"] as const) {\n const atlas = fluids[kind];\n if (!atlas) continue;\n let id = atlasIds.get(atlas);\n if (id === undefined) {\n id = atlases.length;\n atlasIds.set(atlas, id);\n atlases.push(atlas);\n input.atlases.push({ width: atlas.image.width, height: atlas.image.height, animated: atlas.hasAnimation });\n }\n input.fluids[kind] = {\n atlas: id, still: [...atlas.positions.still, ...atlas.sizes.still],\n flow: [...atlas.positions.flow, ...atlas.sizes.flow], tint: kind === \"water\" ? WATER_TINT : [1, 1, 1]\n };\n }\n }\n return { input, atlases };\n}\n\n/** Merged terrain geometry and atlas pages for one 16×16×16 section. Owns its generated render resources. */\nexport class SectionMesh extends Group {\n\n private readonly ownedMeshes: { mesh: Mesh<BufferGeometry, Material>; texture?: Texture; unsubscribe: (() => void)[] }[] = [];\n private readonly blockIndices = new Map<Mesh, Uint16Array>();\n\n /** Returns the owning section cell for a triangle hit on this mesh's merged geometry. */\n public getBlockIndex(hit: Intersection): number | undefined {\n if (hit.faceIndex === undefined || hit.faceIndex === null) return undefined;\n return this.blockIndices.get(hit.object as Mesh)?.[Math.floor(hit.faceIndex / 2)];\n }\n\n /** Builds section-local meshes from visible quads. `maxAtlasSize` limits each atlas dimension in pixels. */\n public static build(entries: readonly SectionMeshEntry[], maxAtlasSize = 2048, fluids?: SectionFluids,\n lighting?: Pick<SectionGeometryInput, \"light\" | \"ambientLight\" | \"ambientOcclusion\">): SectionMesh {\n const { input, atlases } = toInput(entries, maxAtlasSize, fluids, lighting);\n return this.fromPages(buildSectionGeometry(input), atlases);\n }\n\n /** Builds section-local meshes in a browser worker when available, with synchronous fallback. */\n public static async buildAsync(entries: readonly SectionMeshEntry[], maxAtlasSize = 2048, fluids?: SectionFluids,\n lighting?: Pick<SectionGeometryInput, \"light\" | \"ambientLight\" | \"ambientOcclusion\">): Promise<SectionMesh> {\n const { input, atlases } = toInput(entries, maxAtlasSize, fluids, lighting);\n const worker = SectionWorker.shared();\n const pages = worker ? await worker.build(input).catch(() => buildSectionGeometry(input)) : buildSectionGeometry(input);\n return this.fromPages(pages, atlases);\n }\n\n private static fromPages(pages: SectionGeometryPage[], atlases: TextureAtlas[]): SectionMesh {\n const section = new SectionMesh();\n for (const page of pages) {\n const canvas = createCanvas(page.width, page.height);\n const context = canvas.getContext(\"2d\") as CanvasRenderingContext2D;\n for (const { atlas, x, y } of page.placements) {\n context.drawImage(atlases[atlas].image.canvas as CanvasImageSource, x, y);\n }\n const geometry = new BufferGeometry();\n // Passing buffers keeps Three's typed attributes from copying the builder's arrays.\n geometry.setAttribute(\"position\", new Float32BufferAttribute(page.positions.buffer, 3));\n geometry.setAttribute(\"normal\", new Float32BufferAttribute(page.normals.buffer, 3));\n geometry.setAttribute(\"uv\", new Float32BufferAttribute(page.uvs.buffer, 2));\n geometry.setAttribute(\"uvBounds\", new Float32BufferAttribute(page.uvBounds.buffer, 4));\n geometry.setAttribute(\"color\", new Float32BufferAttribute(page.colors.buffer, 3));\n geometry.setAttribute(\"shade\", new Float32BufferAttribute(page.shade.buffer, 1));\n geometry.setIndex(new Uint32BufferAttribute(page.indices.buffer, 1));\n geometry.computeBoundingBox();\n geometry.computeBoundingSphere();\n const transparent = page.layer === 2 ? atlases[page.placements[0].atlas].hasTranslucency : page.layer === 1;\n const material = Materials.createShadedCanvasMaterial(canvas as HTMLCanvasElement, transparent, false, true);\n material.side = FrontSide;\n if (page.layer === 2) {\n material.side = DoubleSide;\n material.forceSinglePass = true;\n material.depthWrite = !material.transparent;\n }\n material.vertexColors = true;\n const texture = (material as ShaderMaterial).uniforms?.map?.value ?? (material as MeshBasicMaterial).map;\n const mesh = new Mesh(geometry, material);\n section.add(mesh);\n section.blockIndices.set(mesh, page.blockIndices);\n const unsubscribe: (() => void)[] = [];\n for (const { atlas: id, x, y } of page.placements) {\n const atlas = atlases[id];\n if (!atlas.hasAnimation) continue;\n unsubscribe.push(atlas.subscribe(() => {\n context.clearRect(x, y, atlas.image.width, atlas.image.height);\n context.drawImage(atlas.image.canvas as CanvasImageSource, x, y);\n texture.needsUpdate = true;\n section.traverseAncestors(parent => {\n if ((parent as MineRenderScene).isMineRenderScene) (parent as MineRenderScene).dirty = true;\n });\n }));\n }\n section.ownedMeshes.push({ mesh, texture, unsubscribe });\n }\n return section;\n }\n\n public dispose(): void {\n for (const { mesh, texture, unsubscribe } of this.ownedMeshes.splice(0)) {\n for (const stop of unsubscribe) stop();\n mesh.removeFromParent();\n mesh.geometry.dispose();\n mesh.material.dispose();\n texture?.dispose();\n }\n this.blockIndices.clear();\n this.removeFromParent();\n super.dispose();\n }\n\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,OAAO,YAAY,wBAAwB,WAAW,OAAiB,MAAkD,6BAA6B;AAC/K,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;A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