raycastNode function Picking and input
Casts ray (direction need not be normalized) through root's subtree
and returns the nearest hit, or null.
Only visible nodes participate unless includeInvisible is set, and a
primitive with MeshPrimitive.visible false is likewise skipped unless
includeInvisible is set. Nodes must intersect layerMask (against
Node.layers), have Node.raycastable set, and pass where when
provided. Skinned meshes are tested at rest pose. Geometry with
caller-managed vertex buffers (setVertices) or non-triangle topology is
skipped.
Implementation
// TODO(raycast): test InstancedMesh components (one local-space test per
// instance transform).
// TODO(raycast): a per-mesh triangle BVH for dense meshes; today each
// candidate mesh is tested per triangle after the node-bounds early-out.
SceneRaycastHit? raycastNode(
Node root,
Ray ray, {
double maxDistance = double.infinity,
int layerMask = 0xFFFFFFFF,
bool Function(Node node)? where,
bool includeInvisible = false,
}) {
SceneRaycastHit? nearest;
_walk(root, ray, maxDistance, layerMask, where, includeInvisible, true, (
hit,
) {
if (nearest == null || hit.distance < nearest!.distance) nearest = hit;
});
return nearest;
}