You are viewing the documentation for Deformable v0.3.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

c
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

c
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 a DEFORMABLE_MESH_ISSUE_KIND_SMALL_ANGLE issue. 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. Default 2.
  • gap_threshold (double)Two corners of a face at different positions closer than this fraction of the mesh radius are a DEFORMABLE_MESH_ISSUE_KIND_NEAR_VERTICES issue; a negative threshold counts as its absolute value. At 0, only corners whose squared distance is 0 are reported: as DEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_FACE_VERTICES when they sit at one position, which no threshold turns off, and as DEFORMABLE_MESH_ISSUE_KIND_NEAR_VERTICES when they are so close that the square of their distance rounds to 0. Default 0.001.
  • planar_threshold (double)A face with a corner farther from its outer loop’s plane than this fraction of its radius is a DEFORMABLE_MESH_ISSUE_KIND_NON_PLANAR issue, and skips the DEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UV check. A triangle without holes is always planar. Default 0.05.
  • check_uv_consistency (uint8_t)Not 0: run the DEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UV check with uv_threshold. Default 0.
  • uv_threshold (double)A corner farther than this fraction of the face radius from where the UV map of its face puts it is a DEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UV issue; read only when check_uv_consistency is not 0. Default 0.
  • same_uv (uint8_t)Not 0: report DEFORMABLE_MESH_ISSUE_KIND_SAME_UV, two corners of a face at different places with identical UVs. Default 0.
  • convex (uint8_t)Not 0: report DEFORMABLE_MESH_ISSUE_KIND_NON_CONVEX, a face with a reflex corner. Default 0.
  • closed_boundary (uint8_t)Not 0: report DEFORMABLE_MESH_ISSUE_KIND_NON_CLOSED_BOUNDARY, an edge with one face, and run the inward-normal and nesting stage last. Default 0.
  • self_intersection (DeformableSelfIntersectionCheck)How far the self-intersection stage goes. Default DEFORMABLE_SELF_INTERSECTION_CHECK_PER_ISLAND.

Example

c
// 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

c
DeformableStatus deformable_mesh_checks_default(
    DeformableMeshChecks *checks);

Writes the defaults the fields of DeformableMeshChecks list to checks.

Parameters

Errors

  • Only the statuses every call can give, which the conventions describe.

See also Python MeshChecks.default

DeformableMeshIssueKind

Enum · deformable.h

c
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 vertex vertex. 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 edge edge has one face; only when closed_boundary is not 0.
  • DEFORMABLE_MESH_ISSUE_KIND_NON_MANIFOLD (2)The edge edge has more than two faces: use_count is 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)The vertex_count vertices vertices, ascending, sit at exactly one position; reported whatever the checks.
  • DEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_EDGES (4)The edge_count edges between vertex indices edges, in order of first use, join the same two positions.
  • DEFORMABLE_MESH_ISSUE_KIND_INVERTED_NORMAL (5)The two faces of the edge edge disagree on their orientation.
  • DEFORMABLE_MESH_ISSUE_KIND_DEGENERATE_EDGE (6)The two ends of the edge edge are at one position.
  • DEFORMABLE_MESH_ISSUE_KIND_DEGENERATE_FACE (7)The outer loop of the face face encloses no area, so it has no normal.
  • DEFORMABLE_MESH_ISSUE_KIND_DEGENERATE_HOLE (8)The loop of the hole hole of the face face encloses no area, so it has no normal.
  • DEFORMABLE_MESH_ISSUE_KIND_CO_LOCATED_FACE_VERTICES (9)The two corners corners of the face face sit at one position, across its outer loop and holes.
  • DEFORMABLE_MESH_ISSUE_KIND_NEAR_VERTICES (10)The two corners corners of the face face sit at different positions, closer than gap_threshold times the mesh radius: distance apart, relative_distance of the mesh radius.
  • DEFORMABLE_MESH_ISSUE_KIND_SMALL_ANGLE (11)The smallest corner angle of the outer loop of the face face, degrees, is below angle_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 face face lies farther from its outer loop’s plane than planar_threshold times the face radius: relative_deviation is 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 face face has a reflex corner; only when convex is not 0. interior_angle_degrees is 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 face face do not add up to one turn, within a quarter turn; reported whatever convex says.
  • DEFORMABLE_MESH_ISSUE_KIND_SAME_UV (15)The two corners corners of the face face sit at different places with identical coordinates in the UV set uv_set, 0 or 1; only when same_uv is not 0. The two corners then drop out of the DEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UV check of that set.
  • DEFORMABLE_MESH_ISSUE_KIND_INCONSISTENT_UV (16)The corner corner of the face face lies farther than uv_threshold times the face radius from where the UV map of the face puts it, in the UV set uv_set: relative_distance is 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 face face has hole_count holes; reported for every face with holes, whatever the checks.
  • DEFORMABLE_MESH_ISSUE_KIND_SELF_INTERSECTION (18)The edge edge crosses the face face, which it does not touch. With DEFORMABLE_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 island island, 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 island island lies inside an island of the same orientation, its innermost container container; inward is 1 when both have inward face normals.
  • DEFORMABLE_MESH_ISSUE_KIND_INWARD_NORMALS (21)From the inward-normal and nesting stage: the uncontained_count islands uncontained, ascending, have inward face normals and no island contains them; island_count is the number of islands of the surface.

See also Guide: Check a mesh for problems · Python MeshIssueKind

DeformableMeshIssue

Struct · deformable.h

c
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 of DEFORMABLE_MESH_ISSUE_KIND_LONE_VERTEX.
  • face (uint32_t)The face the issue names: the face of a face, corner or UV issue, or the face DEFORMABLE_MESH_ISSUE_KIND_SELF_INTERSECTION crosses.
  • 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_count co-located vertices, ascending.
  • vertex_count (size_t)The number of co-located vertices.
  • edges (const uint32_t (*)[2])edge_count co-located edges, in order of first use.
  • edge_count (size_t)The number of co-located edges.
  • uncontained (const uint32_t *)uncontained_count uncontained 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

c
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

c
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

Errors

  • Only the statuses every call can give, which the conventions describe.

deformable_mesh_issue_list_destroy

Function · deformable.h

c
void deformable_mesh_issue_list_destroy(
    DeformableMeshIssueList *issues);

Destroys a list of mesh issues; NULL is ignored. Issues lent from it become invalid.

Parameters

deformable_verify_surface

Function · deformable.h

c
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

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 the corner_count of mesh.
  • DEFORMABLE_STATUS_NON_FINITE_VALUEA position or a UV of the first two sets is NaN or infinite, or so is angle_threshold_degrees, gap_threshold, planar_threshold or, when check_uv_consistency is not 0, uv_threshold.

Example

c
// 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

c
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

Errors

Example

c
// 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