import { Sprite2DMaterial } from "../materials/Sprite2DMaterial.js"; import { TileLayerData } from "./types.js"; import { Tileset } from "./Tileset.js"; import { Group } from "three"; //#region src/tilemap/TileLayer.d.ts /** * A layer of tiles in a tilemap. * * Splits tiles into regional chunks for frustum culling, each rendered as a * single InstancedMesh with Sprite2DMaterial. Maps up to chunkSize×chunkSize * tiles naturally collapse into one chunk (one draw call). * * @example * ```typescript * const layer = new TileLayer( * layerData, * tileset, * 16, // tileWidth * 16, // tileHeight * ) * * scene.add(layer) * * // In update loop * layer.update(deltaMs) * * // Access material for effects * layer.material.colorNode = myCustomEffect * ``` */ declare class TileLayer extends Group { /** Layer data */ readonly data: TileLayerData; /** Tile dimensions */ readonly tileWidth: number; readonly tileHeight: number; /** Chunk size in tiles (e.g., 256 means 256×256 tiles per chunk) */ readonly chunkSize: number; /** The Sprite2DMaterial used for rendering (apply effects here) */ readonly material: Sprite2DMaterial; /** Tileset reference */ private tileset; /** Chunks keyed by "cx,cy" */ private chunks; /** * Bound mesh-source callback registered with the devtools sink so * each chunk's `InstancedMesh` shows up in the batch inspector. * Retained on the instance so `dispose()` can pass the same * reference to `_unregisterMeshBatchSource`. */ private _batchMeshSource; /** Total instance count across all chunks */ private _totalInstanceCount; /** * Maps data array index -> { chunkKey, instanceIndex }. * Only non-empty tiles have entries. */ private tileIndexMap; /** * Animated tile tracking. * Maps tile data array index to animation data. */ private animatedTilePositions; /** Animation state (keyed by base GID) */ private animationTimers; /** System flags bitmask (lit/receiveShadows/castsShadow) — same semantics as Sprite2D._systemFlags */ private _systemFlags; /** Whether the tileset texture uses flipY (loaded images vs DataTextures) */ private readonly texFlipY; /** Reusable matrix for transforms */ private static tempMatrix; private static tempScale; get lit(): boolean; set lit(value: boolean); get receiveShadows(): boolean; set receiveShadows(value: boolean); /** * Set castsShadow on a specific tile by its data-array index. * Use with IntGrid data to mark wall tiles as shadow casters. */ setCastsShadowAt(tileX: number, tileY: number, value: boolean): void; private _syncEffectFlagsToChunks; /** * Write UV data for a tile into the instanceUV buffer. * Handles the flipY difference between loaded images (flipY=true) and DataTextures (flipY=false). * * With flipY=true: UV y=0 is image bottom, y=1 is image top. Tileset row 0 is at the visual top, * so we remap y to (1 - y - height) and use positive height (PlaneGeometry UV direction matches). * * With flipY=false: UV y=0 is first pixel row (image top). We offset y by +height and negate * height so the shader traverses UV space in the correct direction. */ private writeUV; constructor(data: TileLayerData, tileset: Tileset, tileWidth: number, tileHeight: number, chunkSize?: number); /** * Lazy iterator over the current chunk meshes, tagged as * `kind: 'tilechunk'` with `label: 'chunk(x,y)'` so the batch * inspector can group tile chunks distinctly from sprite batches * and identify which chunk in the grid each draw corresponds to. * * Per-frame allocation cost: one small `{ mesh, kind, label }` * object per chunk. Chunk counts are tiny (1 per frustum-sized * region), so this is well below measurement noise — but the scratch * object is reused across frames via `_chunkEntryScratch` below. */ private _iterChunkMeshes; /** Reused `{ mesh, kind, label }` scratch — one slot per active chunk. */ private _chunkEntryScratch; /** * Build chunked instanced meshes from tile data. */ private buildInstances; /** * Update animated tiles. */ update(deltaMs: number): void; /** * Get tile GID at position (in tiles, using original Tiled coordinates). */ getTileAt(tileX: number, tileY: number): number; /** * Set tile GID at position (in tiles). * For changes between non-zero values, updates in-place. * For add/remove (0 <-> non-zero), rebuilds the entire layer. */ setTileAt(tileX: number, tileY: number, gid: number): void; /** * Get the number of chunks in this layer. */ get chunkCount(): number; /** * Get total tile count across all chunks. */ get tileCount(): number; /** * Clone for devtools/serialization compatibility. * TileLayer requires data/tileset in its constructor, so the default * Object3D.clone() (`new this.constructor()`) would crash. * Returns a Group containing cloned child meshes. */ clone(recursive?: boolean): this; /** * Dispose of all resources. */ dispose(): void; } //#endregion export { TileLayer }; //# sourceMappingURL=TileLayer.d.ts.map