Build a BVH
A BVH (Bounding Volume Hierarchy) is a spatial index that stores the bounding boxes of all instances.
It speeds up frustum culling and
raycasting by discarding entire branches of the tree at once.
iMesh.computeBVH();Dynamic and Static Scenes
- Static or mostly static scenes: building the BVH once is the fastest option, as culling and raycasting become much cheaper.
- Highly dynamic scenes: updating the BVH can cost more than it saves. Passing a
marginmakes updates faster, or the linear approach may be preferable.
Configuration
iMesh.computeBVH({ margin: 10, // extra space around each box, for moving instances getBBoxFromBSphere: false, // compute boxes from the geometry bounding sphere (faster, less precise) accurateCulling: true // ignore the margin during frustum culling, avoiding false positives (default)});See BVHParams for more details.
Remove the BVH
iMesh.disposeBVH(); // back to the linear approach