Abstract base class for BVH implementations. Provides core tree traversal and spatial query
methods. Subclasses implement primitive-specific logic by overriding writePrimitiveBounds
and related internal methods.
Methods
shiftPrimitiveOffsets( offset: number ): voidAdjusts all primitive offsets stored in the BVH leaf nodes by the given value. Useful when geometry buffers have been shifted or compacted (e.g. when merging geometries).
traverse( callback: function, rootIndex: number = 0 ): voidTraverses all nodes of the BVH, invoking a callback for each node.
For leaf nodes the callback receives ( depth, isLeaf, boundingData, offset, count ).
For internal nodes it receives ( depth, isLeaf, boundingData, splitAxis ) and may
return true to stop descending into that node's children.
refit(): voidRefits all BVH node bounds to reflect the current primitive positions. Faster than rebuilding the BVH but produces a less optimal tree after large vertex deformations.
getBoundingBox(
// Target box to write the result into.
target: Box3
): Box3Computes the axis-aligned bounding box of all primitives in the BVH.
shapecast(
callbacks: {
intersectsBounds: ( box: Box3, isLeaf: boolean, score: number | undefined, depth: number, nodeIndex: number ) => number,
intersectsRange?: ( offset: number, count: number, contained: boolean, depth: number, nodeIndex: number, box: Box3 ) => boolean,
boundsTraverseOrder?: ( box: Box3 ) => number
}
): booleanA generalized traversal function for performing spatial queries against the BVH. Returns
true as soon as a primitive has been reported as intersected. The tree is traversed
depth-first; boundsTraverseOrder controls which child is visited first. Returning
CONTAINED from intersectsBounds skips further child traversal and intersects all
primitives in that subtree immediately.
bvhcast(
otherBvh: BVH,
matrixToLocal: Matrix4,
callbacks: {
intersectsRanges: ( offset1: number, count1: number, offset2: number, count2: number, depth1: number, nodeIndex1: number, depth2: number, nodeIndex2: number ) => boolean
}
): booleanSimultaneously traverses two BVH structures to find intersecting primitive pairs. Returns
true as soon as any intersection is reported. Both trees are traversed depth-first with
alternating descent. matrixToLocal transforms otherBvh into the local space of this BVH.