Skip to content

Geometry

toManifold() ​

ts
function toManifold<M, MeshType>(
   wasm, 
   geometry, 
   options?
): M;

Defined in: packages/wtc-gl/src/geometry/manifold.ts:191

Convert a geometry into a manifold-3d Manifold, for CSG with manifold's own API: a.subtract(b), Manifold.union([...]), translate() and so on. Pass the result back with fromManifold.

The geometry must be a closed solid made of triangles: every edge shared by exactly two triangles once coincident positions are welded. Seams in UVs or normals are fine, as is non-indexed geometry. A Plane isn't a solid.

Besides the position, the attributes in properties are carried through and interpolated across the new faces; each face keeps the attributes of the geometry it came from. The geometry's own transform isn't applied: use the manifold's transform(), translate() and so on.

The result lives in WASM memory and isn't garbage collected: call delete() on it, and on every manifold made from it, when you're done.

ts
import Module from 'manifold-3d'
const wasm = await Module()
wasm.setup()

const box = toManifold(wasm, new Box(gl))
const hole = toManifold(wasm, new Sphere(gl, { radius: 0.65 }))
const cut = box.subtract(hole)
mesh.geometry = fromManifold(gl, cut)
for (const m of [box, hole, cut]) m.delete()

Type Parameters ​

Type Parameter
M extends ManifoldLike
MeshType extends ManifoldMeshLike

Parameters ​

ParameterTypeDescription
wasmManifoldModuleLike<M, MeshType>The loaded manifold-3d module, after setup()
geometryGeometryA closed, triangulated geometry
options?Partial<ToManifoldOptions>The attributes to carry through, and fill values

Returns ​

M

A new manifold, which you own