全局
MeshBVH
SerializedBVH
MeshBVHVisualizer
ExtendedTriangle
OrientedBox
Raycaster
StaticGeometryGenerator
GenerateMeshBVHWorker

MeshBVH.refit

描述

MeshBVH.refit 方法用于重新构建三角形网格的 Bounding Volume Hierarchy (BVH)。

BVH是一种空间分割数据结构,用于快速计算与物体之间的碰撞和交互。在三维图形渲染中,常常使用BVH加速光线跟踪和阴影计算等任务。

MeshBVH.refit 方法的实现基于"Bounding Volume Hierarchy Construction via Rotation-based Refinement",该方法通过旋转三角形以改进BVH的质量。

用法

meshBVH.refit();

MeshBVH.refit 方法没有参数。调用该方法后,将重新构建BVH,以适应于当前三角形网格的状态。

注意事项

MeshBVH.refit 方法并不会改变三角形的位置、旋转和尺寸等属性。如果三角形发生了这些变化,应该调用MeshBVH.rebuild 方法来重建BVH。

MeshBVH.refit 方法是一个耗时操作,特别是当三角形的数量很大时。因此,建议仅在需要更新三角形位置或添加或删除少量三角形时使用该方法。

示例

import { Mesh, MeshBVH } from 'three';

const mesh = new Mesh(geometry, material);
const meshBVH = new MeshBVH(mesh);

// 更新三角形位置后重新构建 BVH
meshBVH.refit();

// 添加或删除三角形后重新构建BVH
mesh.geometry.dispose();
mesh.geometry = newGeometry;
meshBVH.rebuild();

参考资料

  • "Bounding Volume Hierarchy Construction via Rotation-based Refinement" by Larson, et al. (https://www.cs.utah.edu/~ladislav/bvh/bvh08-sah-even.pdf)
  • "A Survey of Constructive Solid Geometry Techniques" by Li, et al. (https://www.cs.purdue.edu/homes/edf/papers/li_chen.pdf)