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

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 – Whether point is inside mesh or not

Return type

(n,) bool

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

Return type

(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

Return type

(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.

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 the behavior is undefined.

Parameters

points ((n, 3) float) – Points in space

Returns

contains – Whether point is inside mesh or not

Return type

(n,) bool

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 – Whether any ray hit any triangle on the mesh

Return type

(m,) bool

intersects_id(ray_origins, ray_directions, return_locations=False, multiple_hits=True, **kwargs)

Find the intersections between the current mesh and an array 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

Return type

  1. 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

  • tree (rtree.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