ManifoldCAD User Guide
    Preparing search index...

    ManifoldCAD User Guide

    A manifold mesh is a mesh that represents a solid object, and so is very important in manufacturing, CAD, structural analysis, etc. 'Manifold' implies that there are no gaps or tears, and that all faces are oriented outwards.

    [ Using Manifold | Examples | Manifold WASM Developer Guide ]

    Manifold is a geometry library dedicated to creating and operating on manifold triangle meshes. It is available as a WASM module that runs in any modern browser.

    Our primary goal is reliability: guaranteed manifold output without caveats or edge cases. Our secondary goal is performance: efficient algorithms that make extensive use of parallelization, or pipelining when only a single thread is available.

    A metallic Menger sponge

    [ ManifoldCAD | ManifoldCAD User Guide ]

    If you like OpenSCAD / JSCAD, you might also like ManifoldCAD - our own solid modelling web app where you script in JS/TS and save a GLB or 3MF file. It contains several examples showing how to use our API to make interesting shapes. You may notice that some of these examples bare a certain resemblance to my OpenSCAD designs on Thingiverse, which is no accident. Much as I love OpenSCAD, this library is dramatically faster and the code is more flexible.

    manifoldCAD = manifold + TypeScript + glTF

    Just go to ManifoldCAD.org, and check out the examples!

    ManifoldCAD has a command line interface. It can be run directly as ./bin/manifold-cad. It can also be run via npx. If Manifold is not already present, use npx manifold-3d manifold-cad or npx manifold-3d. If Manifold is already installed, npx manifold-cad will suffice.

    Usage: manifold-cad [options] <infile.js> <outfile>
    

    The output file can be in either .glb or .3mf format, determined by extension.

    ManifoldCAD uses a right-handed coordinate system where '+Z' is up. Length units are assumed to be millimetres. This is slightly at odds with glTF, which also uses a right handed coordinate system, but specifies '+Y' as up, and length units are in metres.

    ManifoldCAD will scale and rotate automatically when importing or exporting glTF models. This means that an arrow pointing in the '+Z' direction in will point in the '+Y' direction after export. However, that arrow will still point up, and will still be the same size.

    Basics

    CrossSection

    Two-dimensional cross sections guaranteed to be without self-intersections, or overlaps between polygons (from construction onwards). This class makes use of the Clipper2 library for polygon clipping (boolean) and offsetting operations.

    Manifold

    This library's internal representation of an oriented, 2-manifold, triangle mesh - a simple boundary-representation of a solid object. Use this class to store and operate on solids, and use MeshGL for input and output, or potentially Mesh if only basic geometry is required.

    In addition to storing geometric data, a Manifold can also store an arbitrary number of vertex properties. These could be anything, e.g. normals, UV coordinates, colors, etc, but this library is completely agnostic. All properties are merely float values indexed by channel number. It is up to the user to associate channel numbers with meaning.

    Manifold allows vertex properties to be shared for efficient storage, or to have multiple property verts associated with a single geometric vertex, allowing sudden property changes, e.g. at Boolean intersections, without sacrificing manifoldness.

    Manifolds also keep track of their relationships to their inputs, via OriginalIDs and the faceIDs and transforms accessible through MeshGL. This allows object-level properties to be re-associated with the output after many operations, particularly useful for materials. Since separate object's properties are not mixed, there is no requirement that channels have consistent meaning between different inputs.

    Input & Output

    importManifold

    Import a model, and convert it to a Manifold object for manipulation.

    importModel

    Import a model, for display only.

    Polygons

    triangulate

    Triangulates a set of /epsilon-valid polygons.

    Material

    GLTFMaterial

    Define a material using the glTF metallic-roughness physically-based rendering model. Materials can be applied to a model through setMaterial(), or set as a GLTFNode property.

    only

    Wrap any shape object with this method to display it and any copies as the result, while ghosting out the final result in transparent gray. Helpful for debugging as it allows you to see objects that may be hidden in the interior of the result. Multiple objects marked only() will all be shown.

    setMaterial

    Return a shallow copy of the input manifold with the given material properties applied. They will be carried along through operations.

    show

    Wrap any shape object with this method to display it and any copies in transparent red. This is particularly useful for debugging subtract() as it will allow you find the object even if it doesn't currently intersect the result.

    Scene Graph

    BaseGLTFNode

    The abstract class from which other classes inherit. Common methods and properties live here.

    GLTFNode

    Position a manifold model for later export.

    VisualizationGLTFNode

    Include an imported model for visualization purposes.

    getGLTFNodes

    Get a list of GLTF nodes that have been created in this model.

    resetGLTFNodes

    Clear the list of cached GLTF nodes.

    Animation

    getAnimationDuration

    Get the current duruation of the animation, in seconds.

    getAnimationFPS

    Get the current animation frame rate.

    getAnimationMode

    Get the current animation repeat mode.

    setMorphEnd

    Apply a morphing animation to the input manifold. Specify the end function which will be applied to the vertex positions of the last frame and linearly interpolated across the length of the overall animation. This animation will only be shown if this manifold is used directly on a GLTFNode.

    setMorphStart

    Apply a morphing animation to the input manifold. Specify the start function which will be applied to the vertex positions of the first frame and linearly interpolated across the length of the overall animation. This animation will only be shown if this manifold is used directly on a GLTFNode.

    Level of Detail

    getCircularSegments

    Determine the appropriate number of segments for a given radius.

    getMinCircularAngle

    Get the current angle constraint.

    getMinCircularEdgeLength

    Get the current edge length constraint.

    Information

    isManifoldCAD

    Is this module running in manifoldCAD.org or the ManifoldCAD CLI?

    Type Aliases

    Box

    A three dimensional box, aligned to the coordinate system.

    ErrorStatus
    FillRule
    JoinType
    Mat3

    3x3 matrix stored in column-major order.

    Mat4

    4x4 matrix stored in column-major order.

    Polygons
    Rect

    A two dimensional rectangle, aligned to the coordinate system.

    SimplePolygon
    Smoothness
    Vec2

    A vector in two dimensional space.

    Vec3

    A vector in three dimensional space.