Module ray_index

Source
Expand description

Caller-held broad-phase index for repeated ray casts. Cached broad phase for repeated ray casts against the same mesh.

nearest_hit scans every triangle by design: the broad phase belongs to the caller, and a one-shot caller must not pay for an index it never reuses. Measured here: the BVH only repays after ~22 rays, and at a single ray it is ~20x slower than scanning.

So the index is built lazily on the SECOND cast against a given mesh and reused afterwards. A first cast costs what it always did.

The cache key is a content digest, not an address. TriMesh exposes positions/indices as public Vecs with no version counter, so a caller can mutate a mesh in place; an address or (ptr, len) key would then serve a stale index and return hits for geometry that no longer exists. Digesting costs ~1.2% of a build and ~0.01% of a full scan.

Structsยง

MeshRayIndex
A broad-phase index a caller builds once and casts against many times.