-
Notifications
You must be signed in to change notification settings - Fork 2
1) How to build a BVH
Andrea Gargaro edited this page Sep 3, 2024
·
1 revision
Instantiate a BVH using the only builder currently available: HybridBuilder
import { BVH, HybridBuilder, WebGLCoordinateSystem } from 'bvh.js';
const highPrecision = false; // 'false': float32array / 'true': float64array
const coordinateSystem = WebGLCoordinateSystem; // or WebGPUCoordinateSystem
const bvh = new BVH( new HybridBuilder( highPrecision ), coordinateSystem );
BVH nodes are created using an object and its AABB.
It can be built with two methods:
This method builds a BVH in a top down way, faster and with higher quality than using insert
or insertRange
.
const objects = [ obj1, obj2 ];
const boxes = [ box1, box2 ]; // box1 and box2 are 'float32array' or 'float64array';
bvh.createFromArray( objects, boxes );
This method inserts nodes one at a time incrementally, slower and with lower quality than createFromArray
, but it doesn't need to rebuild BVH from scratch, so it's perfect for dynamic objects.
bvh.insertRange( [ obj1, obj2 ], [ box1, box2 ] );
bvh.insert( object, box );
TODO