Validate and Optimize Meshes

Contents
[ ]

Check If a Mesh Is Manifold

A mesh is manifold when every edge is shared by exactly two polygons — the mesh forms a closed, watertight surface. Several operations like boolean operations require manifold meshes as their operands. The Mesh.isManifold() method checks this, the result is not cached so each call recalculates it:

// Check if a mesh is manifold
Mesh box = new Box(1, 1, 1).toMesh();
System.out.println("The box mesh is manifold: " + box.isManifold());

Optimize the Mesh’s Memory Usage

Real-world models exported from CAD or DCC tools often contain duplicated control points — identical vertex positions stored multiple times. The Mesh.optimize() method eliminates duplicated control points to reduce the mesh’s memory usage:

// Eliminate duplicated control points to reduce memory usage
Mesh optimized = box.optimize(true);
System.out.println("The optimized mesh is manifold: " + optimized.isManifold());

// Fine-tune the tolerances used when comparing control points
Mesh fineTuned = box.optimize(true, 1e-8f, 1e-9f, 1e-8f);
System.out.println("Control points: " + fineTuned.getControlPoints().size());

The overload with four parameters lets you specify the tolerances used when comparing control points, normals and UV coordinates — vertices closer together than the tolerance are considered identical and merged.