该类实现了生成网格BVH的工作线程。
constructor(geometry: THREE.BufferGeometry, progress: (progress: number) => void, onComplete: (bvh: THREE.MeshBVH) => void, options?: MeshBVH.Options);
geometry
:要为其构建BVH的BufferGeometry。progress
:一个回调函数,用于报告BVH构建的进度。onComplete
:一个回调函数,用于在工作完成后返回构建的BVH。options
:可选项对象,用于配置构建的BVH。支持以下属性:
depth
:用于生成BVH的递归深度。默认值为20
。leafSize
:在BVH层次结构中的每个叶子节点上存储的最大对象数。默认值为4
。isWorker
:标记该实例为工作者线程。始终为true
。.run()
执行BVH构建操作。该方法在工作者线程中运行。
const geometry = new THREE.BufferGeometry().fromGeometry(new THREE.BoxGeometry(1, 1, 1));
const worker = new THREE.MeshBVHWorker(geometry, (progress) => {
console.log(`Progress: ${progress}%`);
}, (bvh) => {
console.log(`BVH generated:`, bvh);
}, {
depth: 25,
leafSize: 8
});
worker.run();