warp.mesh_query_ray_count_intersections#
- warp.mesh_query_ray_count_intersections( ) int#
Kernel
Count the number of intersections between a ray and a
warp.Mesh.This function casts a ray through the mesh and counts all triangle intersections with
t >= 0. Unlikemesh_query_ray(), this function does not stop at the first hit and continues traversing to count all intersections along the entire ray.This function can be used to determine whether the ray origin lies inside a watertight, intersection-free mesh. An odd number of intersections indicates the origin is inside the mesh, while an even number indicates it is outside.
The
rootparameter can be obtained using themesh_get_group_root()function when creating a grouped mesh. Whenrootis a valid (>=0) value, the traversal will be confined to the subtree starting from the root. Ifrootis -1 (default), traversal starts at the mesh’s global root.- Parameters:
id – The mesh identifier
start – The ray origin, in the mesh’s local space
dir – The ray direction, in the mesh’s local space (only its direction matters; the count is independent of its length)
root – The root node index for grouped BVH queries, or -1 for global root (optional, default: -1)
- Returns:
The number of intersections (with
t >= 0) between the ray and the mesh.
Example
@wp.kernel def crossings(mesh_id: wp.uint64, origin: wp.vec3, dir: wp.vec3, out_n: wp.array[wp.int32]): out_n[0] = wp.mesh_query_ray_count_intersections(mesh_id, origin, dir) points = wp.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]], dtype=wp.vec3) indices = wp.array([0,3,2, 0,2,1, 4,5,6, 4,6,7, 0,1,5, 0,5,4, 2,3,7, 2,7,6, 0,4,7, 0,7,3, 1,2,6, 1,6,5], dtype=wp.int32) mesh = wp.Mesh(points=points, indices=indices) out_n = wp.zeros(1, dtype=wp.int32) wp.launch(crossings, dim=1, inputs=[mesh.id, wp.vec3(0.3, 0.6, -2.0), wp.vec3(0.0, 0.0, 1.0)], outputs=[out_n]) print("crossings:", out_n.numpy()[0])
crossings: 2