meshing.simplify.simplify_mesh

meshing.simplify.simplify_mesh(
    mesh,
    sdf,
    *,
    error,
    preserve_features=True,
    feature_mask=None,
    feature_angle=30.0,
    max_passes=100,
)

Simplify a dual-contour mesh by error-bounded, feature-safe collapses.

Repeatedly applies batches of independent half-edge collapses (see the module docstring for the guarantees) until no collapse passes the error bound and the safety checks. Because collapses are half-edge, every surviving vertex keeps its extracted position bitwise; with preserve_features (the default) all vertices on sharp mesh edges — box corners, crease chains, CSG seams — survive unchanged.

Parameters

Name Type Description Default
mesh Mesh The extracted mesh to simplify. required
sdf Callable[[Array], Array] The implicit field the mesh was extracted from, mapping one point (3,) to a scalar; used to reject collapses whose modified triangles stray from the zero set. required
error float Positive deviation bound in world units. Bounds both the merged region’s RMS QEF error and the sampled field deviation (centroids and edge midpoints) of every modified triangle. required
preserve_features bool Pin the endpoints of sharp mesh edges (dihedral angle above feature_angle) and any feature_mask rows. False disables both signals; boundary and non-manifold protection always stays on. True
feature_mask np.ndarray | None Optional boolean mask over the mesh’s vertex rows pinning extra vertices — for example non-FACE rows from :func:~cadjoint.meshing.features.classify_feature_cells or seam rows from :func:~cadjoint.meshing.features.detect_branch_changes, both aligned with the vertex rows of the same extraction. None
feature_angle float Dihedral angle in degrees, strictly between 0 and 180, above which a mesh edge counts as sharp. 30.0
max_passes int Safety cap on collapse passes; the loop normally stops earlier, when a pass applies no collapse. 100

Returns

Name Type Description
Mesh A new :class:~cadjoint.meshing.dual_contouring.Mesh whose vertices
Mesh are a subset of the input’s (positions, normals, and cells carried
Mesh over unchanged) with reindexed faces. quads is empty: collapsed
Mesh connectivity no longer corresponds to extraction quads.

Raises

Name Type Description
ValueError If error is not positive, feature_angle is not strictly between 0 and 180, max_passes is not positive, or feature_mask has the wrong shape.