NestedBVH
Builds a nested bounding volume hierarchy: an outer, BVH-accelerated CSG union whose primitives
are themselves BVH-backed mesh signed distance functions. One triangle mesh is loaded once into a
TriMeshSDF (which owns an inner PackedBVH over its triangle groups) and then instanced at
several positions – each placement a Translate wrapper sharing a pointer to that same
TriMeshSDF – and the placements are combined with BVHUnion, which builds the outer
PackedBVH over them. A single distance query therefore descends two levels of BVH — the outer
union hierarchy to locate the nearby placement, then the mesh’s own inner hierarchy to find the
nearest triangle (see Bounding volume hierarchies and Geometries).
The outer union shares each placement by pointer (the default BVH::SharedPtrStorage) rather than
copying it, so the one inner mesh BVH is built and stored just once — the recommended way to nest
BVHs. See the Storage policy section of
BVH for why the outer level must not use BVH::ValueStorage here.
The source for this example is at Examples/NestedBVH/main.cpp. See Building
for how to compile it with CMake, GNU Make, or a direct compiler invocation. Unlike the mesh-reading
examples above, it defaults to the dodecahedron.stl fixture shipped in the repository, so it
needs no submodule.
cd Examples/NestedBVH
./NestedBVH.ex # defaults to ../../Tests/data/dodecahedron.stl
./NestedBVH.ex path/to/mesh.stl # place copies of your own triangle mesh