You are viewing the documentation for Deformable v0.7.0, an older version. Read the latest, v0.9.0
C API Reference
Mesh checks
Check a surface for problems before you use it, and find tetrahedral meshes that overlap.
On this page
deformable_verify_surface checks a surface for problems before you use it and reports one DeformableMeshIssue per problem it finds. deformable_meshes_intersect tells whether two tetrahedral meshes overlap, so that objects do not start inside each other.
DeformableSelfIntersectionCheck
Enum · deformable.h
typedef int32_t DeformableSelfIntersectionCheck;How far the self-intersection stage of deformable_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 the closed_boundary check of DeformableMeshChecks needs.
Values
DEFORMABLE_SELF_INTERSECTION_CHECK_SKIP(0)No self-intersection, island, inward-normal or nesting check.DEFORMABLE_SELF_INTERSECTION_CHECK_PER_ISLAND(1)The 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.DEFORMABLE_SELF_INTERSECTION_CHECK_FULL(2)Every face crossed by an edge is reported, whatever the islands.
See also Guide: Check a mesh for problems · Rust SelfIntersectionCheck · Python SelfIntersectionCheck
DeformableMeshChecks
Struct · deformable.h
typedef struct DeformableMeshChecks {
double angle_threshold_degrees;
double gap_threshold;
double planar_threshold;
uint8_t check_uv_consistency;
double uv_threshold;
uint8_t same_uv;
uint8_t convex;
uint8_t closed_boundary;
DeformableSelfIntersectionCheck self_intersection;
} DeformableMeshChecks;Which checks deformable_verify_surface runs, and their thresholds; booleans are 0 or not 0.
deformable_mesh_checks_default writes 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(double)A face whose outer loop has a corner angle below this many degrees is aDEFORMABLE_MESH_ISSUE_KIND_SMALL_ANGLEissue. 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(double)Two corners of a face at different positions closer than this fraction of the mesh radius are aDEFORMABLE_MESH_ISSUE_KIND_NEAR_VERTICESissue; a negative threshold counts as its absolute value. At 0, only corners whose squared distance is 0 are reported: asDEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_FACE_VERTICESwhen they sit at one position, which no threshold turns off, and asDEFORMABLE_MESH_ISSUE_KIND_NEAR_VERTICESwhen they are so close that the square of their distance rounds to 0. Default0.001.planar_threshold(double)A face with a corner farther from its outer loop’s plane than this fraction of its radius is aDEFORMABLE_MESH_ISSUE_KIND_NON_PLANARissue, and skips theDEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UVcheck. A triangle without holes is always planar. Default0.05.check_uv_consistency(uint8_t)Not 0: run theDEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UVcheck withuv_threshold. Default0.uv_threshold(double)A corner farther than this fraction of the face radius from where the UV map of its face puts it is aDEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UVissue; read only whencheck_uv_consistencyis not 0. Default0.same_uv(uint8_t)Not 0: reportDEFORMABLE_MESH_ISSUE_KIND_SAME_UV, two corners of a face at different places with identical UVs. Default0.convex(uint8_t)Not 0: reportDEFORMABLE_MESH_ISSUE_KIND_NON_CONVEX, a face with a reflex corner. Default0.closed_boundary(uint8_t)Not 0: reportDEFORMABLE_MESH_ISSUE_KIND_NON_CLOSED_BOUNDARY, an edge with one face, and run the inward-normal and nesting stage last. Default0.self_intersection(DeformableSelfIntersectionCheck)How far the self-intersection stage goes. DefaultDEFORMABLE_SELF_INTERSECTION_CHECK_PER_ISLAND.
Example
// A cage for tetrahedralize: every edge on two faces, none crossed.
DeformableMeshChecks checks;
CHECK(deformable_mesh_checks_default(&checks));
checks.closed_boundary = 1;
checks.self_intersection = DEFORMABLE_SELF_INTERSECTION_CHECK_FULL;See also Guide: Check a mesh for problems · Rust MeshChecks · Python MeshChecks
deformable_mesh_checks_default
Function · deformable.h
DeformableStatus deformable_mesh_checks_default(
DeformableMeshChecks *checks);Writes the defaults the fields of DeformableMeshChecks list to checks.
Parameters
checks(DeformableMeshChecks *)Out. Receives the defaults.
Errors
- Only the statuses every call can give, which the conventions describe.
See also Python MeshChecks.default
DeformableMeshIssueKind
Enum · deformable.h
typedef int32_t DeformableMeshIssueKind;The kind of a DeformableMeshIssue: each constant says which fields of the issue it fills; the others are 0 or
NULL. The thresholds and switches the constants name, such as gap_threshold and closed_boundary, are fields of
DeformableMeshChecks.
Values
DEFORMABLE_MESH_ISSUE_KIND_LONE_VERTEX(0)No face uses the vertexvertex. 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.DEFORMABLE_MESH_ISSUE_KIND_NON_CLOSED_BOUNDARY(1)The edgeedgehas one face; only whenclosed_boundaryis not 0.DEFORMABLE_MESH_ISSUE_KIND_NON_MANIFOLD(2)The edgeedgehas more than two faces:use_countis its face count on an edge between vertex indices, its loop-edge count on an edge between positions.DEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_VERTICES(3)Thevertex_countverticesvertices, ascending, sit at exactly one position; reported whatever the checks.DEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_EDGES(4)Theedge_countedges between vertex indicesedges, in order of first use, join the same two positions.DEFORMABLE_MESH_ISSUE_KIND_INVERTED_NORMAL(5)The two faces of the edgeedgedisagree on their orientation.DEFORMABLE_MESH_ISSUE_KIND_DEGENERATE_EDGE(6)The two ends of the edgeedgeare at one position.DEFORMABLE_MESH_ISSUE_KIND_DEGENERATE_FACE(7)The outer loop of the facefaceencloses no area, so it has no normal.DEFORMABLE_MESH_ISSUE_KIND_DEGENERATE_HOLE(8)The loop of the holeholeof the facefaceencloses no area, so it has no normal.DEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_FACE_VERTICES(9)The two cornerscornersof the facefacesit at one position, across its outer loop and holes.DEFORMABLE_MESH_ISSUE_KIND_NEAR_VERTICES(10)The two cornerscornersof the facefacesit at different positions, closer thangap_thresholdtimes the mesh radius:distanceapart,relative_distanceof the mesh radius.DEFORMABLE_MESH_ISSUE_KIND_SMALL_ANGLE(11)The smallest corner angle of the outer loop of the faceface,degrees, is belowangle_threshold_degrees. The angle is the one between the corner’s two edges, from 0 to 180 degrees.DEFORMABLE_MESH_ISSUE_KIND_NON_PLANAR(12)A corner of the facefacelies farther from its outer loop’s plane thanplanar_thresholdtimes the face radius:relative_deviationis the largest distance of a corner from the plane, over the face radius.DEFORMABLE_MESH_ISSUE_KIND_NON_CONVEX(13)The outer loop of the facefacehas a reflex corner; only whenconvexis not 0.interior_angle_degreesis the interior angle of the most reflex one, in degrees, above 180.DEFORMABLE_MESH_ISSUE_KIND_MULTIPLE_WINDING(14)The turns of the outer loop of the facefacedo not add up to one turn, within a quarter turn; reported whateverconvexsays.DEFORMABLE_MESH_ISSUE_KIND_SAME_UV(15)The two cornerscornersof the facefacesit at different places with identical coordinates in the UV setuv_set, 0 or 1; only whensame_uvis not 0. The two corners then drop out of theDEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UVcheck of that set.DEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UV(16)The cornercornerof the facefacelies farther thanuv_thresholdtimes the face radius from where the UV map of the face puts it, in the UV setuv_set:relative_distanceis that distance over the face radius. 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.DEFORMABLE_MESH_ISSUE_KIND_FACE_HAS_HOLES(17)The facefacehashole_countholes; reported for every face with holes, whatever the checks.DEFORMABLE_MESH_ISSUE_KIND_SELF_INTERSECTION(18)The edgeedgecrosses the faceface, which it does not touch. WithDEFORMABLE_SELF_INTERSECTION_CHECK_PER_ISLAND, only an edge and a face of one island are reported.DEFORMABLE_MESH_ISSUE_KIND_INWARD_ISLAND_INTERSECTS(19)From the inward-normal and nesting stage: the islandisland, whose face normals point inward, intersects another island. The stage reports nothing else then.DEFORMABLE_MESH_ISSUE_KIND_NESTED_ISLANDS(20)From the inward-normal and nesting stage: the islandislandlies inside an island of the same orientation, its innermost containercontainer;inwardis 1 when both have inward face normals.DEFORMABLE_MESH_ISSUE_KIND_INWARD_NORMALS(21)From the inward-normal and nesting stage: theuncontained_countislandsuncontained, ascending, have inward face normals and no island contains them;island_countis the number of islands of the surface.
See also Guide: Check a mesh for problems · Python MeshIssueKind
DeformableMeshIssue
Struct · deformable.h
typedef struct DeformableMeshIssue {
DeformableMeshIssueKind kind;
uint32_t vertex;
uint32_t face;
uint32_t hole;
uint32_t corner;
uint32_t uv_set;
uint32_t island;
uint32_t container;
uint32_t use_count;
uint32_t hole_count;
uint32_t island_count;
uint32_t edge[2];
uint32_t corners[2];
uint8_t inward;
double distance;
double relative_distance;
double degrees;
double relative_deviation;
double interior_angle_degrees;
const uint32_t *vertices;
size_t vertex_count;
const uint32_t (*edges)[2];
size_t edge_count;
const uint32_t *uncontained;
size_t uncontained_count;
} DeformableMeshIssue;One problem deformable_verify_surface found, with the elements that locate it, flattened: kind says which fields
it fills, as each DeformableMeshIssueKind constant lists; the others are 0 or NULL.
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.
DEFORMABLE_MESH_ISSUE_KIND_NON_CLOSED_BOUNDARY and DEFORMABLE_MESH_ISSUE_KIND_NON_MANIFOLD 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.
Fields
kind(DeformableMeshIssueKind)What the issue is, which says the fields it fills.vertex(uint32_t)The unused vertex ofDEFORMABLE_MESH_ISSUE_KIND_LONE_VERTEX.face(uint32_t)The face the issue names: the face of a face, corner or UV issue, or the faceDEFORMABLE_MESH_ISSUE_KIND_SELF_INTERSECTIONcrosses.hole(uint32_t)The hole within the face.corner(uint32_t)The corner within the face.uv_set(uint32_t)The UV set, 0 or 1.island(uint32_t)The island an inward-normal or nesting issue names: the inward one, or the contained one.container(uint32_t)The innermost container island.use_count(uint32_t)The face count of a non-manifold edge between vertex indices, or the loop-edge count of one between positions.hole_count(uint32_t)The number of holes of the face.island_count(uint32_t)The number of islands of the surface.edge(uint32_t[2])The edge’s two vertices.corners(uint32_t[2])The two corners within the face, smaller first.inward(uint8_t)1 when both nested islands have inward face normals.distance(double)The distance between the two corners.relative_distance(double)The distance between the two corners over the mesh radius, or between a corner and where the UV map puts it over the face radius.degrees(double)The smallest corner angle of the outer loop, in degrees, measured between the corner’s two edges.relative_deviation(double)The largest distance of a corner from the plane, over the face radius.interior_angle_degrees(double)The interior angle of the most reflex corner, in degrees, above 180.vertices(const uint32_t *)vertex_countco-located vertices, ascending.vertex_count(size_t)The number of co-located vertices.edges(const uint32_t (*)[2])edge_countco-located edges, in order of first use.edge_count(size_t)The number of co-located edges.uncontained(const uint32_t *)uncontained_countuncontained inward islands, ascending.uncontained_count(size_t)The number of uncontained inward islands.
See also Guide: Check a mesh for problems · Rust MeshIssue · Python MeshIssue
DeformableMeshIssueList
Opaque handle · deformable.h
typedef struct DeformableMeshIssueList DeformableMeshIssueList;The issues deformable_verify_surface found, in check order: read them with deformable_mesh_issue_list_issues and
free the list with deformable_mesh_issue_list_destroy.
See also Guide: Check a mesh for problems
deformable_mesh_issue_list_issues
Function · deformable.h
DeformableStatus deformable_mesh_issue_list_issues(
const DeformableMeshIssueList *issues,
const DeformableMeshIssue **records,
size_t *count);Lends the issues of a list, in check order: their records, and the lists the records point to, are owned by
issues and valid until it is destroyed.
Parameters
issues(const DeformableMeshIssueList *)The list to read.records(const DeformableMeshIssue **)Out. Receives a pointer to thecountissues.count(size_t *)Out. Receives the length ofrecords; 0 when the mesh passed.
Errors
- Only the statuses every call can give, which the conventions describe.
deformable_mesh_issue_list_destroy
Function · deformable.h
void deformable_mesh_issue_list_destroy(
DeformableMeshIssueList *issues);Destroys a list of mesh issues; NULL is ignored. Issues lent from it become invalid.
Parameters
issues(DeformableMeshIssueList *)The list to destroy, orNULL.
deformable_verify_surface
Function · deformable.h
DeformableStatus deformable_verify_surface(
const DeformableSurfaceMeshView *mesh,
const DeformableFaceHole *holes,
size_t hole_count,
const DeformableMeshChecks *checks,
DeformableMeshIssueList **issues);Checks the polygon mesh of a surface mesh for problems before you use it, such as a cage before
deformable_triangulate, and makes one DeformableMeshIssue 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 status, not an issue. When closed_boundary is not 0, 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(const DeformableSurfaceMeshView *)The surface mesh to check.holes(const DeformableFaceHole *)hole_countruns of polygon corners that form hole loops. May beNULLwhenhole_countis 0.hole_count(size_t)The number ofholes; 0 when no polygon has a hole.checks(const DeformableMeshChecks *)Which checks run, and their thresholds.issues(DeformableMeshIssueList **)Out. Receives a new handle; free it withdeformable_mesh_issue_list_destroy.
Returns
DEFORMABLE_STATUS_OK, and the handle in issues: read the issues, in check order, with deformable_mesh_issue_list_issues. No issue means the mesh passes.
Errors
DEFORMABLE_STATUS_INDEX_OUT_OF_RANGEA 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.DEFORMABLE_STATUS_LENGTH_MISMATCHThe polygon sizes do not add up to thecorner_countofmesh.DEFORMABLE_STATUS_NON_FINITE_VALUEA position or a UV of the first two sets is NaN or infinite, or so isangle_threshold_degrees,gap_threshold,planar_thresholdor, whencheck_uv_consistencyis not 0,uv_threshold.
Example
// The unit cube without its last face.
DeformableSurfaceMeshView surface = {0};
surface.mesh = polygons;
surface.mesh.polygon_count = 5;
surface.mesh.corner_count = 20;
DeformableMeshChecks checks;
CHECK(deformable_mesh_checks_default(&checks));
checks.closed_boundary = 1;
DeformableMeshIssueList *issues = NULL;
CHECK(deformable_verify_surface(&surface, NULL, 0, &checks, &issues));
const DeformableMeshIssue *records;
size_t count;
CHECK(deformable_mesh_issue_list_issues(issues, &records, &count));
printf("%zu issues\n", count); // 8: 4 edges with one face, twice.
deformable_mesh_issue_list_destroy(issues);See also Guide: Check a mesh for problems · Rust verify_surface · Python verify_surface
deformable_meshes_intersect
Function · deformable.h
DeformableStatus deformable_meshes_intersect(
const DeformableTetrahedralMeshView *first,
const DeformableTetrahedralMeshView *second,
uint8_t *intersect);Tells whether two tetrahedral meshes in world space overlap, to find objects that start inside each other: they do
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(const DeformableTetrahedralMeshView *)One mesh, in world space.second(const DeformableTetrahedralMeshView *)The other mesh, in world space.intersect(uint8_t *)Out. Receives 1 when the meshes overlap, 0 otherwise.
Errors
DEFORMABLE_STATUS_EMPTY_MESHfirstorsecondhas no tetrahedrons.DEFORMABLE_STATUS_INDEX_OUT_OF_RANGEA tetrahedron names a node past the end of its mesh’s positions.DEFORMABLE_STATUS_NON_FINITE_VALUEA position is NaN or infinite.
Example
// A copy of mesh moved half a unit along x overlaps it.
DeformableVector3 *positions =
malloc(mesh.position_count * sizeof *positions);
for (size_t node = 0; node < mesh.position_count; node++) {
positions[node] = mesh.positions[node];
positions[node].x += 0.5;
}
DeformableTetrahedralMeshView moved = mesh;
moved.positions = positions;
uint8_t intersect;
CHECK(deformable_meshes_intersect(&mesh, &moved, &intersect));
puts(intersect ? "overlap" : "apart"); // overlap
free(positions);See also Guide: Find overlapping objects · Rust meshes_intersect · Python meshes_intersect