warp.mesh_query_ray_anyhit#
- warp.mesh_query_ray_anyhit( ) bool#
Kernel
Check whether a ray hits the
warp.Meshwith identifierid, without computing the closest hit.Returns as soon as any intersecting face within
max_tis found, so it is cheaper thanmesh_query_ray()when only the yes/no answer is needed.startanddirare given in the mesh’s local space;max_tis measured in multiples ofdir’s length, so normalizedirfor it to be a distance in mesh-space units.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
max_t – The maximum distance along the ray to check for intersections (in multiples of
dir’s length)root – The root node index for grouped BVH queries, or -1 for global root (optional, default: -1)
- Returns:
Trueif the ray intersects any face withinmax_t,Falseotherwise.
Example
@wp.kernel def occluded(mesh_id: wp.uint64, origin: wp.vec3, dir: wp.vec3, out_hit: wp.array[wp.int32]): out_hit[0] = wp.where(wp.mesh_query_ray_anyhit(mesh_id, origin, dir, 1.0e6), 1, 0) 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_hit = wp.zeros(1, dtype=wp.int32) wp.launch(occluded, dim=1, inputs=[mesh.id, wp.vec3(0.5, 0.5, -2.0), wp.vec3(0.0, 0.0, 1.0)], outputs=[out_hit]) print("hit:", bool(out_hit.numpy()[0]))
hit: True