import { MaterialEffect } from "../materials/MaterialEffect.js";
import { Sprite2DMaterial } from "../materials/Sprite2DMaterial.js";
import { CollisionShape, ObjectLayerData, TileMap2DOptions, TileMapData, TileMapObject } from "./types.js";
import { Tileset } from "./Tileset.js";
import { TileLayer } from "./TileLayer.js";
import { Box3, Group, Intersection, Raycaster } from "three";
//#region src/tilemap/TileMap2D.d.ts
/**
* Main tilemap class for rendering 2D tile-based maps.
*
* Supports:
* - Multiple tile layers
* - Animated tiles
* - Chunked rendering for large maps
* - Collision data extraction
* - Object layer access (spawn points, triggers, etc.)
*
* Follows R3F-compatible constructor pattern with optional parameters.
*
* @example
* ```typescript
* // Three.js
* const mapData = await TiledLoader.load('/maps/level1.json')
* const tilemap = new TileMap2D({ data: mapData })
* scene.add(tilemap)
*
* // In update loop
* tilemap.update(deltaMs)
* ```
*
* @example
* ```tsx
* // React Three Fiber (after extending)
* extend({ TileMap2D })
*
* function Level() {
* const mapData = use(TiledLoader.load('/maps/level1.json'))
* return
* }
* ```
*/
declare class TileMap2D extends Group {
/** Map data */
private _data;
/** Map dimensions in tiles */
private _widthInTiles;
private _heightInTiles;
/** Tile dimensions */
private _tileWidth;
private _tileHeight;
/** Map dimensions in world units */
private _widthInPixels;
private _heightInPixels;
/** Chunk size in tiles (default: 512) */
private _chunkSize;
/** Enable collision extraction */
private _enableCollision;
/** Tilesets */
private tilesets;
/** Tile layers */
private tileLayers;
/** Object layers (for reference) */
private objectLayers;
/** Collision shapes (extracted) */
private collisionShapes;
/** Bounds */
private _bounds;
/**
* Create a new TileMap2D.
*
* @param options - Optional configuration. If not provided (R3F path),
* the tilemap will be initialized when `data` is set.
*/
constructor(options?: TileMap2DOptions);
/**
* Get the tilemap data.
*/
get data(): TileMapData | null;
/**
* Set the tilemap data and rebuild the map.
*/
set data(value: TileMapData | null);
/**
* Get/set chunk size in tiles (default: 512).
* Each layer is split into chunks of chunkSize×chunkSize tiles for frustum culling.
* Maps smaller than chunkSize naturally use a single chunk per layer.
*/
get chunkSize(): number;
set chunkSize(value: number);
/**
* Get/set collision extraction flag.
*/
get enableCollision(): boolean;
set enableCollision(value: boolean);
get widthInTiles(): number;
get heightInTiles(): number;
get tileWidth(): number;
get tileHeight(): number;
get widthInPixels(): number;
get heightInPixels(): number;
/**
* Build the tilemap from data.
*/
private buildMap;
/**
* Get tileset for a layer (based on first non-empty tile).
*/
private getTilesetForLayer;
/**
* Get tileset containing a GID.
*/
private getTilesetForGid;
/**
* Extract collision data from tiles and object layers.
*/
private extractCollisionData;
/**
* Transform a collision shape to world space.
*/
private transformShape;
/**
* Convert a map object to a collision shape.
*/
private objectToCollisionShape;
get lit(): boolean;
set lit(value: boolean);
get receiveShadows(): boolean;
set receiveShadows(value: boolean);
/**
* Register a MaterialEffect on all tile layer materials.
* Use this to add channel providers (e.g. NormalMapProvider) so
* tilemaps participate in the lighting pipeline's channel system.
*
* @example
* ```tsx
*
*
*
* ```
*/
addEffect(effect: MaterialEffect): this;
removeEffect(_effect: MaterialEffect): this;
/**
* Mark tiles as shadow casters based on object layer data.
* Typically called with IntGrid-derived collision objects.
*
* @param types - Object types to treat as occluders (e.g. ['collision', 'torch_switch'])
* @param layerIndex - Which tile layer to mark (default: 0)
*/
markOccluders(types: string[], layerIndex?: number): void;
/**
* Update animated tiles.
* Call this in your animation loop with delta time in milliseconds.
*/
update(deltaMs: number): void;
/**
* Get tile layer by name.
*/
getLayer(name: string): TileLayer | undefined;
/**
* Get tile layer by index.
*/
getLayerAt(index: number): TileLayer | undefined;
/**
* Get all tile layers.
*/
getLayers(): readonly TileLayer[];
/**
* Get layer count.
*/
get layerCount(): number;
/**
* Get object layer by name.
*/
getObjectLayer(name: string): ObjectLayerData | undefined;
/**
* Get all objects of a specific type.
*/
getObjectsByType(type: string): TileMapObject[];
/**
* Get tile GID at world position.
*/
getTileAtWorld(worldX: number, worldY: number, layerIndex?: number): number;
/**
* Convert world position to tile coordinates (in Tiled's Y-down system).
*/
worldToTile(worldX: number, worldY: number): {
x: number;
y: number;
};
/**
* Canonical three.js raycast: O(1) arithmetic tile lookup on the
* local Z=0 plane. Top-most layer with a non-zero GID wins;
* `faceIndex` carries the layer index. Returns `false` to stop
* three's traversal from recursing into TileLayer children
* (spec §7.2 / §11.1).
*/
raycast(raycaster: Raycaster, intersects: Intersection[]): false;
/**
* Resolve a raycast intersection produced by this tilemap into
* layer + tile coordinates (Tiled Y-down) + GID. Returns null for
* foreign intersections. Spec §7.2.
*/
tileFromIntersection(hit: Intersection): {
layer: number;
tileX: number;
tileY: number;
gid: number;
} | null;
/**
* Convert tile coordinates to world position (center of tile).
*/
tileToWorld(tileX: number, tileY: number): {
x: number;
y: number;
};
/**
* Get collision shapes.
*/
getCollisionShapes(): readonly CollisionShape[];
/**
* Get map bounds.
*/
get bounds(): Box3;
/**
* Get tileset by name.
*/
getTileset(name: string): Tileset | undefined;
/**
* Get custom property from map data.
*/
getProperty(name: string): T | undefined;
/**
* Get total chunk count across all layers (equals total draw calls for tiles).
*/
get totalChunkCount(): number;
/**
* Get total tile count across all layers.
*/
get totalTileCount(): number;
/**
* Get the Sprite2DMaterial for a tile layer by name.
* Use this to apply TSL effects or lighting to specific layers.
*/
getLayerMaterial(name: string): Sprite2DMaterial | undefined;
/**
* Get the Sprite2DMaterial for a tile layer by index.
* Use this to apply TSL effects or lighting to specific layers.
*/
getLayerMaterialAt(index: number): Sprite2DMaterial | undefined;
/**
* Clone for devtools/serialization compatibility.
* Returns a Group containing cloned child layers for visual inspection.
*/
clone(recursive?: boolean): this;
/**
* Dispose internal resources (without clearing external references).
*/
private disposeInternal;
/**
* Dispose of all resources.
*/
dispose(): void;
}
//#endregion
export { TileMap2D };
//# sourceMappingURL=TileMap2D.d.ts.map