pub fn slice(
mesh: &Mesh,
bvh: &Bvh,
plane: &Plane,
out: &mut Slice,
) -> Result<()>Expand description
Cuts mesh with plane and writes the contours to out, replacing what
it held and reusing its allocations. The plane and the points are in the
mesh’s stored local coordinates (the f32 positions widened to f64,
without the mesh origin).
The triangles’ segments are joined at shared crossed edges:
- An edge crossed by one triangle ends an open contour.
- An edge crossed by more than two triangles splits the cut: every piece
ending there is open, with
manifold == false. - Where two triangles disagree on their winding the pieces still join,
and the contour has
oriented == false.
On a closed, outward-wound mesh the contours are closed, oriented loops,
with the solid’s inside on their left seen from the plane normal: outer
loops run counter-clockwise in (u, v) and holes clockwise. An oriented
open contour runs the same way. A plane through vertices gives
coincident points joined by zero-length segments; they are kept.
A face lying exactly in the plane is cut or not depending on the sign of
the normal, because its vertices are all on the + side (s ≥ 0): a
cube cut at its top face with the normal +z gives the square of that
face (the side faces cross from − to + there), while with −z all of
the cube is on the + side and nothing is cut. Offset the plane slightly
to choose.
A zero-area triangle [a, a, b] crossed between a and b gives a
segment from edge (a, b) back to itself. It has no length, so it is
dropped rather than counted as a third triangle at that edge.
The order is deterministic: a closed contour starts at its smallest edge
key, an open one at its first end (its from end when oriented), and
the contours are sorted by their first edge key.
§Errors
QueryError::MeshMismatch or
QueryError::StaleBvh when bvh does not
match the current mesh, and
QueryError::OutOfMemory when an
allocation fails. On any error out is left empty.