/** * StaticMeshBatcher.ts * * Scene-wide static mesh batching system. * Merges geometries that share the same material into a single draw call, * dramatically reducing draw calls for static scene geometry. * * Key differences from InstancedMeshManager: * - InstancedMeshManager: many copies of the SAME geometry (GPU instancing). * - StaticMeshBatcher: many DIFFERENT geometries merged by material (geometry * merging). This is ideal for architectural elements, terrain chunks, and * any static scene geometry where instances are not identical. * * Performance Impact: * - Without batching: 1,000 unique static meshes = 1,000 draw calls. * - With batching: 1,000 unique static meshes sharing 5 materials = 5 draw calls. * * Usage: * const batcher = new StaticMeshBatcher(scene); * batcher.addMesh({ id: 'wall-01', geometry: wallGeo, material: brickMat, * position: [0, 0, 0] }); * batcher.addMesh({ id: 'wall-02', geometry: wallGeo, material: brickMat, * position: [2, 0, 0] }); * batcher.rebuild(); // produces one merged mesh for brickMat */ import * as THREE from 'three'; export interface StaticMeshEntry { /** Unique identifier for this mesh instance */ id: string; /** Source geometry (read-only; original is never modified) */ geometry: THREE.BufferGeometry; /** Material to render with */ material: THREE.Material; /** World position */ position?: [number, number, number]; /** Euler rotation in radians */ rotation?: [number, number, number]; /** Uniform or non-uniform scale */ scale?: [number, number, number]; } export interface BatchGroup { /** Group key (material-based, with split suffix when oversized) */ key: string; /** Shared material */ material: THREE.Material; /** The merged mesh added to the scene */ mesh: THREE.Mesh; /** IDs of source meshes baked into this batch */ sourceIds: string[]; } export interface StaticMeshBatcherStats { /** Number of source meshes registered */ totalSourceMeshes: number; /** Number of batch groups (one per material or split) */ totalBatchGroups: number; /** Draw calls after batching */ totalDrawCalls: number; /** Total vertices across all batches */ totalVertices: number; /** Total triangles across all batches */ totalTriangles: number; /** Estimated GPU memory usage in MB */ estimatedMemoryMB: number; /** Human-readable reduction summary */ drawCallReduction: string; } /** * Scene-wide static mesh batcher. * * Collects arbitrary static meshes, groups them by material, * merges their geometries with baked world transforms, and produces * one merged {@link THREE.Mesh} per material group. * * Rebuild is explicit (offline) — add/remove are cheap, but `rebuild()` * recomputes merged geometry. Designed for level-load or streaming * boundaries, not per-frame mutation. */ export declare class StaticMeshBatcher { private readonly entries; private readonly batches; private readonly scene; private readonly maxVerticesPerBatch; constructor(scene: THREE.Scene, options?: { maxVerticesPerBatch?: number; }); /** Register a static mesh for batching. Does NOT rebuild automatically. */ addMesh(entry: StaticMeshEntry): void; /** Remove a mesh by ID. Does NOT rebuild automatically. */ removeMesh(id: string): boolean; /** Clear all registered meshes and remove batched meshes from the scene. */ clear(): void; /** * Rebuild all batch groups from registered entries. * * This is the expensive operation: * 1. Groups entries by material UUID. * 2. Splits groups that exceed `maxVerticesPerBatch`. * 3. Merges geometries per group with baked transforms. * 4. Adds merged meshes to the scene. */ rebuild(): void; /** Get current batch statistics. Safe to call at any time. */ getStats(): StaticMeshBatcherStats; /** Get a batch group by key. */ getBatchGroup(key: string): BatchGroup | undefined; /** Get all batch keys. */ getBatchKeys(): string[]; /** Iterate over all active batch groups. */ iterBatches(): Generator; private materialKey; private disposeBatches; private splitIntoChunks; private mergeChunk; private inferItemSize; } //# sourceMappingURL=StaticMeshBatcher.d.ts.map