newton.intersect_ray#

newton.intersect_ray(model, *, ray_origins, ray_directions, ray_worlds, enable_global_world=True, out_dist=None, out_shape_id=None, out_normal=None)[source]#

Intersect rays with model shapes.

finalize() builds the model shape BVH for the initial model state. If the queried state changes shape transforms, refit the BVH with bvh_refit_shapes() before raycasting again. Manually populated models must build the BVH with bvh_build_shapes() before first use.

Each ray is cast against the shapes of its own world (given by ray_worlds) and against the shapes of the global world (index -1), which are accessible from every world. A ray whose world is -1 is cast against the global world only.

out_dist, out_shape_id and out_normal are optional outputs. Pass None to skip writing a channel.

Parameters:
  • model (Model) – Model containing the shapes to query.

  • ray_origins (wp.array[wp.vec3]) – Ray origins in world space [m], shape [ray_count, 3].

  • ray_directions (wp.array[wp.vec3]) – Ray directions in world space, shape [ray_count, 3]. Values must be normalized and nonzero.

  • ray_worlds (wp.array[wp.int32]) – Per-ray world index, shape [ray_count]. Use -1 for the global world.

  • enable_global_world (bool) – Whether to enable global world raycasting.

  • out_dist (wp.array[float] | None) – Optional output hit distances [m], shape [ray_count]. -1 on miss.

  • out_shape_id (wp.array[wp.int32] | None) – Optional output hit shape indices, shape [ray_count]. -1 on miss.

  • out_normal (wp.array[wp.vec3] | None) – Optional output hit normals, shape [ray_count, 3].