pyblenderSDIC.meshes.TriangleMesh3D.cast_rays#

TriangleMesh3D.cast_rays(rays: ndarray) IntersectPoints[source]#

Compute the intersection of rays with the mesh.

This method uses Open3D to perform ray-mesh intersection and returns the intersection points and the corresponding triangle indices as an IntersectPoints object.

# Define ray origins and directions
rays_origins = numpy.array([[0, 0, 0], [1, 1, 1]]) # shape (L, 3)
rays_directions = numpy.array([[0, 0, 1], [1, 1, 0]]) # shape (L, 3)
rays = numpy.hstack((rays_origins, rays_directions)) # shape (L, 6)

# Perform ray-mesh intersection
intersect_points = trimesh3d.cast_rays(rays)

Note

The returned IntersectPoints contains:

  • uv: A (…, 2) array of barycentric coordinates (u, v). If a ray misses the mesh, the entry is [nan, nan].

  • id: A (…) array of triangle indices hit by each ray. If a ray misses, the index is set to -1.

The barycentric coordinates are such that:

coordinates = (1 - u - v) * P_1 + u * P_2 + v * P_3

See also

  • open3d_cast_ray() for the underlying Open3D implementation.

  • IntersectPoints for the output type.

Parameters:

rays (numpy.ndarray) – An array of shape (…, 6) containing the ray origins and directions, in the form [x0, y0, z0, dx, dy, dz].

Returns:

An object containing barycentric coordinates and triangle indices of the intersections.

Return type:

IntersectPoints