Skip to content

Geometry cleanup and repair operations. Use these after boolean operations to reduce polygon count, snap near-duplicate vertices, and merge coplanar faces. None of these functions change the visible shape of the geometry.

See also:

function generalize( options: { snap?: boolean; simplify?: boolean; triangulate?: boolean }, ...geometries: AnyGeom[] ): AnyGeom | AnyGeom[]

Apply one or more cleanup passes to a geometry in the recommended order.

The passes are applied in sequence: snap → simplify → triangulate. Each pass is opt-in via the options object. Accepts geom2, geom3, or path2; passing an array or multiple arguments processes each geometry individually.

Useful after boolean operations that produce many small or near-degenerate faces — snap + simplify can dramatically reduce polygon count.

Parameters:

Name Type Description
options — Which passes to run.
options.snap — Snap vertex coordinates to the geometry’s epsilon. Default false.
options.simplify — Merge coplanar adjacent polygons. Default false.
options.triangulate — Convert all polygons to triangles. Default false.
geometries — One or more geometries to process.

Returns: Cleaned geometry, or an array of cleaned geometries.

const { generalize } = jscad.modifiers
const { union } = jscad.booleans
const { sphere, cube } = jscad.primitives
async function main() {
const raw = union(sphere({ radius: 5 }), cube({ size: 6 }))
return generalize({ snap: true, simplify: true }, raw)
}

See also:

function snap(...geometries: AnyGeom[]): AnyGeom | AnyGeom[]

Snap all vertex coordinates in a geometry to its natural epsilon.

Eliminates near-zero-length edges and near-degenerate polygons caused by floating-point drift during boolean operations. Equivalent to calling generalize({ snap: true }, ...).

Parameters:

Name Type Description
geometries — One or more geometries to snap.

Returns: Snapped geometry, or an array of snapped geometries.

const { snap } = jscad.modifiers
const { subtract } = jscad.booleans
const { sphere, cube } = jscad.primitives
async function main() {
return snap(subtract(sphere({ radius: 5 }), cube({ size: 6 })))
}

See also:

function retessellate(geometry: Geom3): Geom3

Merge coplanar adjacent polygons in a 3D geometry to reduce face count.

After boolean operations, solids often contain many small coplanar triangles where one logical face was split. Retessellation merges these back into larger convex polygons, improving rendering performance and export quality.

Parameters:

Name Type Description
geometry — A Geom3 to retessellate.

Returns: A new Geom3 with coplanar polygons merged.

const { retessellate } = jscad.modifiers
const { union } = jscad.booleans
const { cuboid } = jscad.primitives
async function main() {
const merged = union(cuboid({ size: [10,4,4] }), cuboid({ size: [4,10,4] }))
return retessellate(merged)
}

See also: