JFLib

physics/src/bvh.rs#

Source: lib/physics/src/bvh.rs

bvh -- the fixed bounding volume hierarchy of a triangle mesh: binned SAH, built once

Boxes in f32 (a mesh's vertices are f32, so the box of a triangle is exact in f32 and so is every
union).  A node is 32 bytes; the two children of an inner node sit next to each other.  The build splits
a node where the surface area heuristic over 16 bins per axis is cheapest (cost of a node visit 1, of a
triangle 1); a node becomes a leaf when that is not cheaper than testing its triangles (at most
`max_leaf`).  Past depth 40 it splits at the median along the widest axis, which bounds the depth for
any input.  Every choice has a tie-break by axis, bin or index: the same tree on every target.
  • struct BvhNode a node of a [crate::TriMesh]'s tree: an inner node when count is 0 (children at first and first + 1), else a leaf with the triangles first .. first + count
    • min: [f32; 3] -- the box, in the mesh's frame
    • max: [f32; 3]
    • first: u32 -- the left child (an inner node) or the first triangle (a leaf)
    • count: u32 -- 0 for an inner node, else the number of triangles

impl BvhNode

  • fn is_leaf(&self) -> bool a leaf (it has triangles)

Source: docs/API.md in the JFLib repository.