Bitbybit Docs
    Preparing search index...

    Class ManifoldOperations

    Changing Manifold solids beyond booleans: wrapping them in a convex hull, slicing and projecting them into cross-sections, refining and smoothing their meshes, simplifying them, composing and decomposing them, and computing normals and curvature into vertex property channels. A property channel is one number per vertex stored on the mesh, such as the three channels of a normal. Every method returns a new solid.

    Index

    Constructors

    adjustments

    • Computes a normal for every vertex from the mesh and stores it in three property channels starting at normalIdx.

      Edges sharper than minSharpAngle, in degrees, keep separate normals on each side and stay crisp; at 0 every triangle keeps its own normal. Flat faces of several triangles stay flat.

      Parameters

      Returns Promise<ManifoldPointer>

      The solid with normals stored

      const withNormals = await bitbybit.manifold.manifold.operations.calculateNormals({ manifold: shape, normalIdx: 0, minSharpAngle: 60 });
      
    • Computes how strongly the surface bends at every vertex and stores it in property channels: Gaussian curvature at gaussianIdx, mean curvature at meanIdx.

      Curvature is the inverse of the bending radius, positive where the surface is convex and negative where it is concave; an index below 0 skips that channel.

      Parameters

      Returns Promise<ManifoldPointer>

      The solid with curvature stored

      const withCurvature = await bitbybit.manifold.manifold.operations.calculateCurvature({ manifold: shape, gaussianIdx: 0, meanIdx: 1 });
      
    • Adds triangles to a smoothed solid until every point of its mesh lies within tolerance of the smooth surface, so tightly curved regions get more triangles than flat ones.

      Only a solid that was smoothed with smoothOut or smoothByNormals changes; any other comes back as a copy.

      Parameters

      Returns Promise<ManifoldPointer>

      The refined solid

      const finer = await bitbybit.manifold.manifold.operations.refineToTolerance({ manifold: smoothed, tolerance: 0.01 });
      
    • Adds triangles to a solid by splitting every edge into pieces of roughly the given length, adding inner vertices to keep the triangles even.

      On a solid smoothed with smoothOut or smoothByNormals the new vertices move onto the smooth surface; otherwise the surface stays as it is.

      Parameters

      Returns Promise<ManifoldPointer>

      The refined solid

      const finer = await bitbybit.manifold.manifold.operations.refineToLength({ manifold: smoothed, length: 0.5 });
      
    • Adds triangles to a solid by splitting every edge into number pieces; with 2, each triangle becomes four.

      On a solid smoothed with smoothOut or smoothByNormals the new vertices move onto the smooth surface; otherwise the new triangles stay flat.

      Parameters

      Returns Promise<ManifoldPointer>

      The refined solid

      const finer = await bitbybit.manifold.manifold.operations.refine({ manifold: smoothed, number: 2 });
      
    • Marks a solid for smoothing by working out tangents from its triangles, so a later refine or refineToLength bends the new triangles into a smooth surface.

      Edges sharper than minSharpAngle, in degrees, stay sharp; minSmoothness above 0 rounds those a little, and 1 smooths everything. The geometry itself does not change until it is refined.

      Parameters

      Returns Promise<ManifoldPointer>

      The solid with smoothing tangents

      const smoothed = await bitbybit.manifold.manifold.operations.smoothOut({ manifold: cube, minSharpAngle: 60, minSmoothness: 0 });
      const rounded = await bitbybit.manifold.manifold.operations.refineToLength({ manifold: smoothed, length: 0.5 });
    • Marks a solid for smoothing using the normals stored in its vertex properties, so a later refine or refineToLength bends the new triangles into a smooth surface.

      normalIdx is the first of the three normal channels, as calculateNormals stores them; where the normals on a vertex disagree the edge stays sharp.

      Parameters

      Returns Promise<ManifoldPointer>

      The solid with smoothing tangents

      const smoothed = await bitbybit.manifold.manifold.operations.smoothByNormals({ manifold: withNormals, normalIdx: 0 });
      
    • Removes vertices from a solid's mesh while keeping every surface within tolerance of where it was, to cut the triangle count.

      The result keeps a subset of the original vertices; the solid's own tolerance value stays unchanged.

      Parameters

      Returns Promise<ManifoldPointer>

      The simplified solid

      const lighter = await bitbybit.manifold.manifold.operations.simplify({ manifold: shape, tolerance: 0.05 });
      
    • Rewrites the vertex properties of a solid with a function that receives each vertex's position and old properties and fills in the new ones.

      numProp sets how many properties each vertex has afterwards, so channels can be added or dropped; reading past the old count or writing past the new one is undefined.

      Parameters

      Returns Promise<ManifoldPointer>

      The solid with the new properties

      const colored = await bitbybit.manifold.manifold.operations.setProperties({
      manifold: shape,
      numProp: 3,
      propFunc: (newProp, position) => { newProp[0] = position[0]; newProp[1] = position[1]; newProp[2] = position[2]; },
      });

    basic

    • Gives a solid a new tolerance, the rounding error it is allowed to carry, and simplifies its mesh when the tolerance grows.

      Triangles thinner than the tolerance are treated as degenerate and removed.

      Parameters

      Returns Promise<ManifoldPointer>

      The solid with the new tolerance

      const coarser = await bitbybit.manifold.manifold.operations.setTolerance({ manifold: shape, tolerance: 0.01 });
      
    • Reserves a run of count unique mesh ids and returns the first, for marking sets of triangles that can be found again after later operations.

      Assign them to a mesh's runOriginalID before building a solid from it, for instance to keep several materials apart.

      Parameters

      • inputs: CountDto

        How many ids to reserve

      Returns Promise<number>

      The first of the reserved ids; the rest follow in sequence

      const firstId = await bitbybit.manifold.manifold.operations.reserveIds({ count: 2 });
      
    • Makes a copy of a solid that counts as a new original, so the copy can carry its own vertex properties, such as a different UV mapping, and be told apart from what it was built from.

      Coplanar faces are merged and the edges between them collapsed on the way; keep the mesh route instead when those edges must stay.

      Parameters

      Returns Promise<ManifoldPointer>

      The copy marked as an original

      const original = await bitbybit.manifold.manifold.operations.asOriginal({ manifold: shape });
      

    composition

    • Packs several solids into one, the inverse of decompose.

      Solids that overlap are fused, as a boolean union would; solids kept apart stay separate pieces of the one result.

      Parameters

      Returns Promise<ManifoldPointer>

      One solid holding all of them

      const packed = await bitbybit.manifold.manifold.operations.compose({ manifolds: [cube, sphere] });
      
    • Splits a solid into its separate, unconnected pieces, the inverse of compose.

      A solid that is all one piece comes back as a list of one copy.

      Parameters

      Returns Promise<ManifoldPointer[]>

      The separate pieces

      const pieces = await bitbybit.manifold.manifold.operations.decompose({ manifold: packed });
      

    cross sections

    • Cuts a solid with a plane parallel to the XY plane at the given Z height and returns the flat section as a cross-section.

      A height at the bottom of the solid's bounding box gives its bottom faces; a height at the top gives an empty cross-section.

      Parameters

      Returns Promise<CrossSectionPointer>

      The section as a cross-section

      const section = await bitbybit.manifold.manifold.operations.slice({ manifold: sphere, height: 2 });
      
    • Flattens a solid onto the XY plane and returns its outline as a cross-section, like its shadow under a light straight above.

      Parameters

      Returns Promise<CrossSectionPointer>

      The outline as a cross-section

      const shadow = await bitbybit.manifold.manifold.operations.project({ manifold: shape });
      

    hulls

    • Wraps a solid in its convex hull, the smallest shape without dents that contains it, like shrink-wrap pulled tight over it.

      Parameters

      Returns Promise<ManifoldPointer>

      The convex hull

      const wrapped = await bitbybit.manifold.manifold.operations.hull({ manifold: shape });
      
    • Wraps points, solids or a mix of both in one convex hull, the smallest shape without dents that contains them all.

      Parameters

      Returns Promise<ManifoldPointer>

      The convex hull

      const wrapped = await bitbybit.manifold.manifold.operations.hullPoints({ points: [[0, 0, 0], [10, 0, 0], [0, 10, 0], [0, 0, 10]] });