Expand description
Queries on meshes stored in fast_mesh_store, accelerated by fast_mesh_bvh.
Every query takes a mesh and a BVH built for it, works in the mesh’s local
f32 coordinates, and fails with QueryError::StaleBvh when the mesh was
edited after the BVH was last updated. Point, ray, region and pair queries
allocate only into the output vector they are given. slice(),
fill(), contour_gap,
triangulate and intersection_polylines
also build per-call temporaries, all reserved fallibly, so that running
out of memory is QueryError::OutOfMemory.
- Closest point:
closest_pointandclosest_point_many, with theFeatureof the triangle the nearest point lies on. - Raycasts:
raycast(nearest hit),raycast_any(occlusion),raycast_all(every hit, sorted) andraycast_many(a batch). The ray-triangle test is watertight: a ray through a shared edge or vertex never slips between the triangles meeting there. Ties go to the smallest triangle id. - Region queries:
triangles_inandvertices_infind the triangles that touch, or the vertices inside, aRegion(a box or a sphere). The box is anAabb, re-exported fromfast_mesh_bvhso that callers need not depend on that crate to build aRegion::Box. - Relative placement: a
Rigidtransform (rotation and translation, no scale) maps one mesh’s local coordinates into another’s, for queries between two meshes. Whether two triangles intersect or touch is decided exactly, by exact orientation predicates on the transformedf64coordinates. - Mesh-vs-mesh queries, with mesh B placed in mesh A’s space by a
Rigid:intersects,mesh_distance(aMeshDistancewith both points in A’s space),triangles_near(the triangles of each mesh within a margin of the other),intersecting_pairsandintersection_polylines(the intersecting pairs clipped and chained intoPolylines). Results are in A’s space; passing the same mesh twice means two coincident copies. - Self-intersection:
self_intersecting_pairsfinds the triangle pairs of one mesh that intersect and share no vertex id, by the same exact test. - Cutting planes: a
Plane(origin and unit normal, inf64mesh-local coordinates) with an orthonormal 2D frame(u, v). A point is on its+side when its signed distance is zero or more. - Sections:
slice()cuts a mesh with aPlaneinto aSliceofContours, chained by crossed edge, with flags for open, unoriented and non-manifold pieces. - Polygon fill:
triangulate::triangulatesplits a 2D polygon with holes into counter-clockwise triangles by ear clipping. - Section measurements on
(u, v)polylines:contour_length,signed_area,fill(nesting into outers and holes, then aFillof triangles) andcontour_gap(the exact in-planeGap2between two sets of polylines, found through a grid).
Modules§
- triangulate
- Triangulation of 2D polygons with holes.
Structs§
- Aabb
- The axis-aligned box type of
Region::Box, re-exported fromfast_mesh_bvh. Axis-aligned bounding box in mesh-local coordinates. - Closest
Hit - The point of a mesh nearest to a query point.
- Closest
Options - Options for
closest_point. - Contour
- One chain of the cut: a closed loop or an open polyline.
- Fill
- The filled cross-section made by
fill: triangles over(u, v)points. - Gap2
- The closest pair between two sets of polylines, found by
contour_gap. - Mesh
Distance - The closest pair of points between two meshes, found by
mesh_distance. - Pair
Segment - One intersection segment between a triangle of A and one of B, in A’s
space (B placed by the query’s
Rigid). - Plane
- A plane in mesh-local coordinates, with an orthonormal 2D frame
(u, v)in it. The frame is right-handed:normal = u × v. - Polyline
- One chain of the intersection: a closed loop or an open polyline, in A’s
space (B placed by the query’s
Rigid). - Ray
- A ray
origin + t * dir, in mesh-local coordinates. - RayHit
- Where a ray hit a triangle.
- RayOptions
- Options shared by the raycasts.
- Rigid
- Maps mesh B’s local coordinates into mesh A’s local coordinates:
p_a = rotation * p_b + translation. - Slice
- The cut of a mesh by a plane, as contours.
Enums§
- Cull
- Which triangle faces a ray ignores. A triangle’s front is the side its counter-clockwise winding is seen from.
- Feature
- The part of a triangle that is closest to a query point.
- Query
Error - Why a query could not run.
- Region
- A region of space, in mesh-local coordinates. Both shapes are closed: points on the boundary are inside.
Functions§
- closest_
point - The point of the mesh nearest to
pwithinopts.max_distance, orNonewhen the mesh has no triangle that close. Equal distances go to the smallest triangle id. Triangles with zero area take part, as their edges. - closest_
point_ many closest_pointfor many points:out[i]gets the result forpoints[i].- contour_
gap - The minimum distance between the segments of the polylines
aand those ofb, each with whether it is closed, with the closest pair of points. - contour_
length - The length of a polyline: the sum of its segment lengths. A closed one also counts the segment from its last point back to its first.
- distance_
to_ triangle - The distance from
pto a triangle, inf64: for measuring a result exactly whenf32is not enough, as on long thin triangles, whosef32distances are dominated by rounding. - fill
- Fills the closed contours
contours(each with whether it is oriented) and writes the triangles toout, replacing what it held. - intersecting_
pairs - Appends to
outevery pair(a, b)of an alive triangleaof A and an alive trianglebof B that intersect or touch, with B placed in A’s space byxf, and returns how many were appended. The appended pairs are sorted by(a, b); elements already inoutare kept and stay in front. - intersecting_
segments - Appends the intersection segment of every intersecting triangle pair of
mesh_aandmesh_b(B placed in A’s space byxf), and returns how many were appended. Elements already inoutare kept and stay in front. - intersection_
polylines - Appends to
outthe polylines wheremesh_aandmesh_b(placed in A’s space byxf) intersect, and returns how many were appended. Elements already inoutare kept and stay in front. - intersects
- Whether any alive triangle of A intersects or touches any alive triangle
of B, with B placed in A’s space by
xf. - mesh_
distance - The minimum distance between the surfaces of A and B, with B placed in A’s
space by
xf, and a closest pair of points.Nonewhen the distance is greater thanmax_distance, or when either mesh has no alive triangle. - raycast
- The nearest hit with
opts.min_t <= t <= opts.max_t, orNone. Equaltgoes to the smallest triangle id, so the result is deterministic. - raycast_
all - Appends every hit with
opts.min_t <= t <= opts.max_ttoout, sorted by(t, triangle), and returns how many were appended. Elements already inoutare kept. - raycast_
any - Some hit with
opts.min_t <= t <= opts.max_t, orNone. It stops at the first hit found, so it suits occlusion tests; which hit it returns is unspecified. - raycast_
many raycastfor many rays:out[i]gets the nearest hit of the rayorigins[i] + t * dirs[i].- self_
intersecting_ pairs - Appends to
outevery pair(a, b)witha < bof alive triangles ofmeshthat intersect or touch and share no vertex id. The appended pairs are sorted; elements already inoutare kept and stay in front. - self_
intersects - Whether any two alive triangles of
meshintersect or touch while sharing no vertex id: the early-exit form ofself_intersecting_pairs, for callers that only need the bool. - signed_
area - The signed area of the closed polygon
points, by the shoelace formula: positive when it runs counter-clockwise. Fewer than three points have no area. - slice
- Cuts
meshwithplaneand writes the contours toout, replacing what it held and reusing its allocations. The plane and the points are in the mesh’s stored local coordinates (thef32positions widened tof64, without the mesh origin). - triangles_
in - Appends to
outevery alive triangle that touchesregion(shares a point with it), and returns how many were appended. The order is unspecified. Elements already inoutare kept. - triangles_
near - Appends to
out_aevery alive triangle of A withinmarginof B, and toout_bevery alive triangle of B withinmarginof A, with B placed in A’s space byxf. Elements already in the vectors are kept and stay in front; each appended part is in ascending order without duplicates. - vertices_
in - Appends to
out, in ascending order and without duplicates, every vertex insideregionthat belongs to an alive triangle, and returns how many were appended. Elements already inoutare kept and stay in front; only the appended part is sorted.
Type Aliases§
- Result
ResultwithQueryErroras the error type.