/** * Per-triangle BVH for closest-point queries (BIM ↔ scan deviation). * * Distinct from `bvh.ts` which is a per-mesh BVH used for raycasting: * for closest-point we want fine-grained pruning, so each leaf holds * a contiguous range of triangles. The build also flattens the tree * to a `Float32Array` ready for direct GPU upload — no second pass. * * Node layout (32 bytes = 8 floats per node, packed Float32 + bitcast u32): * [0..2] aabbMin (vec3) * [3] childA / triStart (u32 bitcast: leaf flag = high bit) * [4..6] aabbMax (vec3) * [7] childB / triCount (u32 bitcast) * * Triangle layout (48 bytes = 12 floats per triangle): * [0..2] v0 (vec3) * [3..5] v1 (vec3) * [6..8] v2 (vec3) * [9..11] normalised face normal (vec3) — sign convention: outward * from mesh interior assuming CCW winding (right-hand rule) * * Maximum supported triangles: ~2³¹ (one bit reserved for the leaf * flag). Real BIMs top out around 10⁷ triangles before other bottle- * necks kick in. */ import type { MeshData } from '@ifc-lite/geometry'; export interface TriangleBVHResult { /** Flat node buffer (Float32Array). Each node is 8 floats. */ nodes: Float32Array; /** Flat triangle buffer (Float32Array). Each triangle is 12 floats. */ triangles: Float32Array; /** Total number of triangles. */ triangleCount: number; /** Total number of nodes (root at index 0). */ nodeCount: number; /** Number of source meshes folded into this BVH. */ meshCount: number; /** Aggregate bounds of all triangles. */ bounds: { min: [number, number, number]; max: [number, number, number]; }; } /** * Build the per-triangle BVH. * * Splits leaves until each holds at most `maxTrisPerLeaf` triangles * (default 16, balancing tree depth vs. per-leaf work). Median split * along the longest AABB axis — fast O(n log n) build, no SAH for v1. * * For typical BIMs (1M triangles) the build runs in ~1–3 seconds on * the main thread. Acceptable since it only re-runs when the mesh * set changes (load / federation update). */ export declare function buildTriangleBVH(meshes: ReadonlyArray, options?: { maxTrisPerLeaf?: number; }): TriangleBVHResult; //# sourceMappingURL=triangle-bvh.d.ts.map