trimesh.ray package

Submodules

trimesh.ray.ray_pyembree module

Ray queries using the pyembree package with the API wrapped to match our native raytracer.

class trimesh.ray.ray_pyembree.RayMeshIntersector(geometry, scale_to_box=True)

Bases: object

Methods

contains_points(points)

Check if a mesh contains a list of points, using ray tests.

intersects_any(ray_origins, ray_directions)

Check if a list of rays hits the surface.

intersects_first(ray_origins, ray_directions)

Find the index of the first triangle a ray hits.

intersects_id(ray_origins, ray_directions[, …])

Find the triangles hit by a list of rays, including optionally multiple hits along a single ray.

intersects_location(ray_origins, ray_directions)

Return the location of where a ray hits a surface.

contains_points(points)

Check if a mesh contains a list of points, using ray tests.

If the point is on the surface of the mesh, behavior is undefined.

points: (n,3) points in space

Returns
contains: (n,) bool

Whether point is inside mesh or not

intersects_any(ray_origins, ray_directions)

Check if a list of rays hits the surface.

Parameters
ray_origins: (n,3) float, origins of rays
ray_directions: (n,3) float, direction (vector) of rays
Returns
hit: (n,) bool, did each ray hit the surface
intersects_first(ray_origins, ray_directions)

Find the index of the first triangle a ray hits.

Parameters
ray_origins: (n,3) float, origins of rays
ray_directions: (n,3) float, direction (vector) of rays
Returns
triangle_index: (n,) int, index of triangle ray hit, or -1 if not hit
intersects_id(ray_origins, ray_directions, multiple_hits=True, max_hits=20, return_locations=False)

Find the triangles hit by a list of rays, including optionally multiple hits along a single ray.

Parameters
ray_origins: (n,3) float, origins of rays
ray_directions: (n,3) float, direction (vector) of rays
multiple_hits: bool, if True will return every hit along the ray

if False will only return first hit

return_locations: bool, should we return hit locations or not
Returns
index_tri: (m,) int, index of triangle the ray hit
index_ray: (m,) int, index of ray
locations: (m,3) float, locations in space
intersects_location(ray_origins, ray_directions, multiple_hits=True)

Return the location of where a ray hits a surface.

Parameters
ray_origins: (n,3) float, origins of rays
ray_directions: (n,3) float, direction (vector) of rays
Returns
locations: (n) sequence of (m,3) intersection points
index_ray: (n,) int, list of ray index
index_tri: (n,) int, list of triangle (face) indexes

trimesh.ray.ray_triangle module

A basic slow implementation of ray- triangle queries.

class trimesh.ray.ray_triangle.RayMeshIntersector(mesh)

Bases: object

An object to query a mesh for ray intersections. Precomputes an r-tree for each triangle on the mesh.

Methods

contains_points(points)

Check if a mesh contains a list of points, using ray tests.

intersects_any(ray_origins, ray_directions, …)

Find out if each ray hit any triangle on the mesh.

intersects_id(ray_origins, ray_directions[, …])

Find the intersections between the current mesh and a list of rays.

intersects_location(ray_origins, …)

Return unique cartesian locations where rays hit the mesh.

contains_points(points)

Check if a mesh contains a list of points, using ray tests.

If the point is on the surface of the mesh, behavior is undefined.

Parameters
points: (n,3) points in space
Returns
contains: (n) boolean array, whether point is inside mesh or not
intersects_any(ray_origins, ray_directions, **kwargs)

Find out if each ray hit any triangle on the mesh.

Parameters
ray_origins: (m,3) float, ray origin points
ray_directions: (m,3) float, ray direction vectors
Returns
hit: boolean, whether any ray hit any triangle on the mesh
intersects_id(ray_origins, ray_directions, return_locations=False, multiple_hits=True, **kwargs)

Find the intersections between the current mesh and a list of rays.

Parameters
ray_origins: (m,3) float, ray origin points
ray_directions: (m,3) float, ray direction vectors
multiple_hits: bool, consider multiple hits of each ray or not
return_locations: bool, return hit locations or not
Returns
index_triangle: (h,) int, index of triangles hit
index_ray: (h,) int, index of ray that hit triangle
locations: (h,3) float, (optional) position of intersection in space
intersects_location(ray_origins, ray_directions, **kwargs)

Return unique cartesian locations where rays hit the mesh. If you are counting the number of hits a ray had, this method should be used as if only the triangle index is used on- edge hits will be counted twice.

Parameters
ray_origins(m, 3) float

Ray origin points

ray_directions(m, 3) float

Ray direction vectors

Returns
locations(n) sequence of (m,3) float

Intersection points

index_ray(n,) int

Array of ray indexes

index_tri: (n,) int

Array of triangle (face) indexes

trimesh.ray.ray_triangle.ray_bounds(ray_origins, ray_directions, bounds, buffer_dist=1e-05)

Given a set of rays and a bounding box for the volume of interest where the rays will be passing through, find the bounding boxes of the rays as they pass through the volume.

Parameters
ray_origins: (m,3) float, ray origin points
ray_directions: (m,3) float, ray direction vectors
bounds: (2,3) bounding box (min, max)
buffer_dist: float, distance to pad zero width bounding boxes
Returns
ray_bounding: (n) set of AABB of rays passing through volume
trimesh.ray.ray_triangle.ray_triangle_candidates(ray_origins, ray_directions, tree)

Do broad- phase search for triangles that the rays may intersect.

Does this by creating a bounding box for the ray as it passes through the volume occupied by the tree

Parameters
ray_origins: (m,3) float, ray origin points
ray_directions: (m,3) float, ray direction vectors
tree: rtree object, contains AABB of each triangle
Returns
ray_candidates: (n,) int, triangle indexes
ray_id: (n,) int, corresponding ray index for a triangle candidate
trimesh.ray.ray_triangle.ray_triangle_id(triangles, ray_origins, ray_directions, triangles_normal=None, tree=None, multiple_hits=True)

Find the intersections between a group of triangles and rays

Parameters
triangles(n, 3, 3) float

Triangles in space

ray_origins(m, 3) float

Ray origin points

ray_directions(m, 3) float

Ray direction vectors

triangles_normal(n, 3) float

Normal vector of triangles, optional

treertree.Index

Rtree object holding triangle bounds

Returns
index_triangle(h,) int

Index of triangles hit

index_ray(h,) int

Index of ray that hit triangle

locations(h, 3) float

Position of intersection in space

trimesh.ray.ray_util module

Module contents