You are viewing the documentation for Deformable v0.1.0, an older version. Read the latest, v0.9.0
Rust API Reference
Mesh checks
Check a surface for problems before you use it, and find tetrahedral meshes that overlap.
On this page
verify_surface checks a surface for problems before you use it and reports one MeshIssue per problem it finds. meshes_intersect tells whether two tetrahedral meshes overlap, so that objects do not start inside each other.
SelfIntersectionCheck
Enum · deformable::tools::SelfIntersectionCheck
pub enum SelfIntersectionCheck {
Skip,
PerIsland,
Full,
}How far the self-intersection stage of verify_surface goes: the stage that reports an
edge crossing a face it does not touch.
The stage also splits the surface into islands, the parts whose faces join through shared edges, which the
inward-normal and nesting stage of MeshChecks::closed_boundary needs.
Values
SkipNo self-intersection, island, inward-normal or nesting check.PerIslandThe default: a face crossed by an edge of another island is not reported; the two islands count as intersecting for the inward-normal and nesting stage.FullEvery face crossed by an edge is reported, whatever the islands.
Implements Clone · Copy · Debug · Default · Eq · PartialEq · Send · Sync
See also Guide: Check a mesh before you use it · C DeformableSelfIntersectionCheck · Python SelfIntersectionCheck
MeshChecks
Struct · deformable::tools::MeshChecks
pub struct MeshChecks {
pub angle_threshold_degrees: f64,
pub gap_threshold: f64,
pub planar_threshold: f64,
pub uv_threshold: Option<f64>,
pub same_uv: bool,
pub convex: bool,
pub closed_boundary: bool,
pub self_intersection: SelfIntersectionCheck,
}Which checks verify_surface runs, and their thresholds.
MeshChecks::default() gives the defaults the fields list. Some checks run whatever the fields say: lone and
co-located vertices, co-located, non-manifold, inverted and degenerate edges, degenerate faces and holes, corners of
one face at one position, outer loops that do not wind once, and faces with holes.
The mesh radius is the largest distance of a vertex position from the mean of the distinct positions. A face’s radius is the largest distance of its corners from the mean of its outer loop’s corners.
Fields
angle_threshold_degrees(f64)A face whose outer loop has a corner angle below this many degrees is aMeshIssue::SmallAngle. The angle is the one between the corner’s two edges, from 0 to 180 degrees, so a reflex corner counts as 360 degrees minus its interior angle. Default2.gap_threshold(f64)Two corners of a face at different positions closer than this fraction of the mesh radius areMeshIssue::NearVertices; a negative threshold counts as its absolute value. At 0, only corners whose squared distance is 0 are reported: asMeshIssue::CoLocatedFaceVerticeswhen they sit at one position, which no threshold turns off, and asNearVerticeswhen they are so close that the square of their distance rounds to 0. Default0.001.planar_threshold(f64)A face with a corner farther from its outer loop’s plane than this fraction of its radius isMeshIssue::NonPlanar, and skips theMeshIssue::InconsistentUvcheck. A triangle without holes is always planar. Default0.05.uv_threshold(Option<f64>)A corner farther than this fraction of the face radius from where the UV map of its face puts it isMeshIssue::InconsistentUv;Noneskips the check. DefaultNone.same_uv(bool)ReportsMeshIssue::SameUv: two corners of a face at different places with identical UVs. Defaultfalse.convex(bool)ReportsMeshIssue::NonConvex: a face with a reflex corner. Defaultfalse.closed_boundary(bool)ReportsMeshIssue::NonClosedBoundary, an edge with one face, and runs the inward-normal and nesting stage last. Defaultfalse.self_intersection(SelfIntersectionCheck)How far the self-intersection stage goes. DefaultSelfIntersectionCheck::PerIsland.
Implements Clone · Copy · Debug · Default · PartialEq · Send · Sync
Example
// A cage for tetrahedralize: every edge on two faces, none crossed.
let checks = MeshChecks {
closed_boundary: true,
self_intersection: SelfIntersectionCheck::Full,
..MeshChecks::default()
};
let surface = SurfaceMesh { mesh: polygons, ..SurfaceMesh::default() };
assert!(verify_surface(&surface, &[], &checks)?.is_empty());See also Guide: Check a mesh before you use it · C DeformableMeshChecks · Python MeshChecks
MeshIssue
Enum · deformable::tools::MeshIssue
pub enum MeshIssue {
LoneVertex { vertex: u32 },
NonClosedBoundary { edge: [u32; 2] },
NonManifold { edge: [u32; 2], use_count: u32 },
CoLocatedVertices { vertices: Vec<u32> },
CoLocatedEdges { edges: Vec<[u32; 2]> },
InvertedNormal { edge: [u32; 2] },
DegenerateEdge { edge: [u32; 2] },
DegenerateFace { face: u32 },
DegenerateHole { face: u32, hole: u32 },
CoLocatedFaceVertices { face: u32, corners: [u32; 2] },
NearVertices {
face: u32,
corners: [u32; 2],
distance: f64,
relative_distance: f64,
},
SmallAngle { face: u32, degrees: f64 },
NonPlanar { face: u32, relative_deviation: f64 },
NonConvex { face: u32, interior_angle_degrees: f64 },
MultipleWinding { face: u32 },
SameUv { face: u32, corners: [u32; 2], uv_set: u32 },
InconsistentUv {
face: u32,
corner: u32,
uv_set: u32,
relative_distance: f64,
},
FaceHasHoles { face: u32, hole_count: u32 },
SelfIntersection { face: u32, edge: [u32; 2] },
InwardIslandIntersects { island: u32 },
NestedIslands { island: u32, container: u32, inward: bool },
InwardNormals { uncontained: Vec<u32>, island_count: u32 },
}One problem verify_surface found, with the elements that locate it.
Vertices are input vertex indices. An edge is named by the two vertex indices of the first loop edge on it, smaller first. Corners count within their polygon, outer loop first, then the holes; holes count within their face in corner order; islands, the parts of the surface whose faces join through shared edges, are numbered in order of their lowest face.
NonClosedBoundary and NonManifold are checked twice: on the
edges between distinct vertex indices, then on the edges between distinct positions. So an edge of a surface without
co-located vertices is reported once by each; remove the duplicates before showing the issues.
Values
LoneVertexA vertex no face uses. It is reported for the vertex, then once more for its position, named by the lowest vertex there, when no vertex at that position is used.vertex(u32)The unused vertex.
NonClosedBoundaryAn edge with one face; only withMeshChecks::closed_boundary.edge([u32; 2])The edge with one face.
NonManifoldAn edge with more than two faces.edge([u32; 2])The edge with more than two faces.use_count(u32)Its face count on an edge between vertex indices, its loop-edge count on an edge between positions.
CoLocatedVerticesSeveral vertices at exactly one position; reported whatever the checks.vertices(Vec<u32>)The vertices, ascending.
CoLocatedEdgesSeveral edges between vertex indices that join the same two positions.edges(Vec<[u32; 2]>)The edges, in order of first use.
InvertedNormalThe two faces of an edge disagree on their orientation.edge([u32; 2])The edge whose two faces disagree.
DegenerateEdgeAn edge whose two ends are at one position.edge([u32; 2])The edge whose two ends are at one position.
DegenerateFaceA face whose outer loop encloses no area, so it has no normal.face(u32)The face with no area.
DegenerateHoleA hole whose loop encloses no area, so it has no normal.face(u32)The face that holds the hole.hole(u32)The hole within the face.
CoLocatedFaceVerticesTwo corners of one face at one position, across its outer loop and holes.face(u32)The face whose two corners meet.corners([u32; 2])The two corners, smaller first.
NearVerticesTwo corners of one face at different positions, closer thanMeshChecks::gap_thresholdtimes the mesh radius.face(u32)The face whose two corners are close.corners([u32; 2])The two corners, smaller first.distance(f64)Their distance.relative_distance(f64)Their distance over the mesh radius.
SmallAngleThe smallest corner angle of a face’s outer loop is belowMeshChecks::angle_threshold_degrees. The angle is the one between the corner’s two edges, from 0 to 180 degrees.face(u32)The face with the small angle.degrees(f64)That angle, in degrees.
NonPlanarA corner of a face lies farther from its outer loop’s plane thanMeshChecks::planar_thresholdtimes the face radius.face(u32)The face that is not flat.relative_deviation(f64)The largest distance of a corner from the plane, over the face radius.
NonConvexThe outer loop of a face has a reflex corner; only withMeshChecks::convex.face(u32)The face with the reflex corner.interior_angle_degrees(f64)The interior angle of its most reflex corner, in degrees, above 180.
MultipleWindingThe turns of a face’s outer loop do not add up to one turn, within a quarter turn; reported whateverMeshChecks::convexsays.face(u32)The face whose outer loop turns more than once.
SameUvTwo corners of a face at different places with identical coordinates in a UV set; only withMeshChecks::same_uv. The two corners then drop out of theInconsistentUvcheck of that set.face(u32)The face whose two corners share their UV coordinates.corners([u32; 2])The two corners, smaller first.uv_set(u32)The UV set, 0 or 1.
InconsistentUvA corner lies farther thanMeshChecks::uv_thresholdtimes the face radius from where the UV map of its face puts it. The map is the affine one that fits the face’s best-shaped triple of outer corners; only a face within the planar threshold, with a hole or more than three outer corners, is checked.face(u32)The face whose UV map misplaces a corner.corner(u32)The misplaced corner, within the face.uv_set(u32)The UV set, 0 or 1.relative_distance(f64)The distance between the corner and where the map puts it, over the face radius.
FaceHasHolesA face with holes; reported for every such face, whatever the checks.face(u32)The face with holes.hole_count(u32)Its number of holes.
SelfIntersectionAn edge crosses a face it does not touch. WithSelfIntersectionCheck::PerIsland, only an edge and a face of one island are reported.face(u32)The crossed face.edge([u32; 2])The crossing edge.
InwardIslandIntersectsFrom the inward-normal and nesting stage: an island with inward face normals intersects another island. The stage reports nothing else then.island(u32)The inward island.
NestedIslandsFrom the inward-normal and nesting stage: an island lies inside an island of the same orientation, its innermost container.island(u32)The contained island.container(u32)Its innermost container.inward(bool)Whether both have inward face normals.
InwardNormalsFrom the inward-normal and nesting stage: islands with inward face normals that no island contains.uncontained(Vec<u32>)Those islands, ascending.island_count(u32)The number of islands of the surface.
Implements Clone · Debug · PartialEq · Send · Sync
See also Guide: Check a mesh before you use it · C DeformableMeshIssue · Python MeshIssue
verify_surface
Function · deformable::tools::verify_surface
pub fn verify_surface(
mesh: &SurfaceMesh,
holes: &[FaceHole],
checks: &MeshChecks,
) -> Result<Vec<MeshIssue>, Error>Checks the polygon mesh of a surface mesh for problems before you use it, such as a cage before
triangulate, and returns one MeshIssue per problem found.
The checks read the positions, the polygons, the holes and the first two UV sets of mesh, not its normals or
colours. Malformed input is an error, not an issue. With MeshChecks::closed_boundary, a last stage looks for
islands with inward face normals and for islands nested inside an island of the same orientation; it runs only
when every check before it passed. Its containment rays come from a stream with a fixed seed, so equal calls give
equal results.
Parameters
mesh(&SurfaceMesh)The surface mesh to check.holes(&[FaceHole])The runs of polygon corners that form hole loops; empty when no polygon has a hole.checks(&MeshChecks)Which checks run, and their thresholds.
Returns
Vec<MeshIssue>: The issues in check order; an empty list means the mesh passes.
Errors
IndexOutOfRangeA corner names a vertex past the end of the positions, a polygon has no corners, a hole names a polygon past the last, or a polygon’s hole runs do not cover the corners after its outer loop end to end. Each run needs at least one corner, and so does the outer loop.LengthMismatchThe polygon sizes do not add up to the number of corners, or a UV set does not have one coordinate pair per corner.NonFiniteValueA position or a UV of the first two sets is NaN or infinite, or so isangle_threshold_degrees,gap_threshold,planar_thresholdor auv_thresholdthat is notNone.UnrecognizedThe library reports an issue kind this crate does not know, which only a newer library does; the checks have run.- The license kinds every engine call can return.
Example
// The unit cube without its last face.
let mut open_box = polygons;
open_box.polygon_sizes.pop();
open_box.polygon_vertices.truncate(20);
let surface = SurfaceMesh { mesh: open_box, ..SurfaceMesh::default() };
let checks = MeshChecks {
closed_boundary: true,
..MeshChecks::default()
};
let issues = verify_surface(&surface, &[], &checks)?;
assert_eq!(issues[0], MeshIssue::NonClosedBoundary { edge: [1, 3] });See also Guide: Check a mesh before you use it · C deformable_verify_surface · Python verify_surface
meshes_intersect
Function · deformable::tools::meshes_intersect
pub fn meshes_intersect(
first: &TetrahedralMesh,
second: &TetrahedralMesh,
) -> Result<bool, Error>Whether two tetrahedral meshes in world space overlap, to find objects that start inside each other: true when a
tetrahedron of first and one of second have bounding boxes that meet and an overlap volume above 1e-10 with a
nonzero normal.
The normal of a pair is the summed area of the second tetrahedron’s faces clipped to the first. It vanishes, and the pair does not count, when either tetrahedron lies inside the other, the two coincide, or their overlap is symmetric about its centre, as some partial overlaps are: two identical meshes do not intersect, and faces on each other’s planes can make the answer depend on the argument order. The clipping tolerance, 1e-12 times the longest edge, also comes from the first tetrahedron alone.
Parameters
first(&TetrahedralMesh)One mesh, in world space.second(&TetrahedralMesh)The other mesh, in world space.
Errors
EmptyMeshfirstorsecondhas no tetrahedrons.IndexOutOfRangeA tetrahedron names a node past the end of its mesh’s positions.NonFiniteValueA position is NaN or infinite.- The license kinds every engine call can return.
Example
// A copy of mesh moved half a unit along x overlaps it.
let mut moved = mesh.clone();
for position in &mut moved.positions {
position.x += 0.5;
}
assert!(meshes_intersect(&mesh, &moved)?);See also Guide: Find objects that start inside each other · C deformable_meshes_intersect · Python meshes_intersect
DegenerateKind
Enum · deformable::mesh::DegenerateKind
pub enum DegenerateKind {
TooSmall,
Flat,
Inverted,
}How a tetrahedron fails the quality check of
Scene::add_object, which needs its orientation determinant
above 1e-9; ErrorKind::DegenerateTetrahedron carries it.
The orientation determinant is six times the tetrahedron’s signed volume: positive when its corners are ordered
left-handed, as every mesh of this crate orders them, and negative when they are ordered right-handed. A kind
prints as too small, flat or inverted.
Values
TooSmallThe determinant is above 1e-15 but at most 1e-9, or NaN: the tetrahedron is positively oriented but too small. Remesh it.FlatThe determinant lies between -1e-15 and 1e-15: the corners lie in one plane, or nearly. Remesh it.InvertedThe determinant is below -1e-15: the corners are ordered right-handed. Swap two of them.
Implements Clone · Copy · Debug · Display · Eq · Hash · PartialEq · Send · Sync
See also Guide: The error type
DegenerateKind::classify
Associated function · deformable::mesh::DegenerateKind::classify
pub fn classify(orientation_determinant: f64) -> Option<Self>The failure an orientation determinant gives, or None when it is above 1e-9 and the tetrahedron passes.
Parameters
orientation_determinant(f64)Six times the signed volume of a tetrahedron, positive when its corners are ordered left-handed.