raycastNode function Picking and input

SceneRaycastHit? raycastNode(
  1. Node root,
  2. Ray ray, {
  3. double maxDistance = double.infinity,
  4. int layerMask = 0xFFFFFFFF,
  5. bool where(
    1. Node node
    )?,
  6. bool includeInvisible = false,
})

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. 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;
}