---
id: "mesh-boolean-manifold"
title: "Manifold Mesh Booleans"
aliases: [manifold-3d]
domain: "geometry"
stage: "geometry"
realtime: "interactive"
platforms: [cpu, webgl2, webgpu, python]
year_introduced: 2022
inputs: [mesh]
outputs: [mesh]
style: "both"
dynamic: "static"
cost: "interactive"
authority: "elalish, 2019"
url: "https://texelatlas.vercel.app/t/mesh-boolean-manifold/"
sources_verified_at: "2026-11-29"
---
# Manifold Mesh Booleans (elalish, 2019)

> A mesh boolean library that guarantees manifold output and runs in parallel, using symbolic perturbation instead of tolerance fudging. Union, difference and intersection of triangle meshes in the browser or natively.

## Reach for it when

- boolean cut leaves holes or non-manifold results
- need robust union and difference of meshes in the browser
- csg for cad or 3d-print prep
- mesh intersections fail from tolerance issues
- fast parallel mesh subtraction

## How it works

Inputs must be manifold triangle meshes. The library finds all edge-triangle intersections using a spatial structure (a BVH or Morton-sorted hash), then decides inside/outside using a winding-number-like shadow test with symbolic perturbation: vertices are treated as if infinitesimally nudged so that degenerate coincidences, such as coplanar faces or vertices on faces, resolve consistently rather than via epsilons. New vertices are placed at the exact intersection of an edge with a face. Kept triangles from both meshes are stitched along the new intersection edges into a manifold result. The code runs in parallel and ships as a WebAssembly build for JavaScript.

## When to use it

Choose it for CSG-style modelling on meshes (CAD in the browser, procedural parts, 3D-print prep) where robustness and manifold output matter and inputs are already manifold. Prefer [SDF Modeling: CSG and Smooth Minimum](https://texelatlas.vercel.app/t/sdf-csg-smooth-min.md) when blends or smooth results are wanted, and a mesh clean-up pass or [Screened Poisson Surface Reconstruction](https://texelatlas.vercel.app/t/screened-poisson-surface-reconstruction.md) when inputs are triangle soups with self-intersections.

## Cost

interactive — Roughly linear to n log n; sub-second for hundreds of thousands of triangles on a modern CPU in native builds, slower in WASM.
Measured GPU Weight: 16.18× baseline (moderate) — 0.5081 ms median / 0.6058 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 14.42× baseline (moderate) — 0.2279 ms median (2.23× faster on L4).
Ampere A100 scaling: 10.93× baseline (moderate) — 0.3147 ms median (1.61× faster on A100).

## Failure modes

- Requires manifold, closed inputs; open or self-intersecting meshes are rejected or give undefined results
- Exact coincident faces resolve via perturbation, which can leave razor-thin slivers
- Single-precision input can limit accuracy of tiny features
- Attributes such as UVs need extra bookkeeping to survive the cut

## Engine support

- babylonjs: builtin — `BABYLON.CSG2 (Manifold-based; await InitializeCSG2Async())` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Meshes/csg2.ts, checked 2026-12-01)
- blender: builtin — `Add Modifier > Generate > Boolean > Solver = Manifold` (evidence: https://docs.blender.org/manual/en/5.2/modeling/modifiers/generate/booleans.html, checked 2026-12-01)
- godot: builtin — `Add CSGShape3D nodes (CSGCombiner3D, CSGBox3D...) and set operation` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/modules/csg/csg_shape.cpp, checked 2026-12-01) — CSG meshes are combined with the bundled Manifold library.
- unreal: builtin — `Modeling Mode > Model > Boolean Tool (Union, Difference, Intersection) and GeometryScript_MeshBooleans` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/boolean-tool-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: mesh
- Outputs: mesh
- Platforms: cpu, webgl2, webgpu, python

## Presets

### Manifold Mesh Booleans — interactive CSG Union / Difference / Intersection with highlighted 1-manifold seam curves (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_BOOL_OP": 1,
  "P_SEAM_GLOW": 1.15,
  "P_ORBIT_AMP": 0.34,
  "P_ROT_SPEED": 1
}
```

```glsl
const float P_BOOL_OP = 1.0; // P Bool Op (0:U 1:Diff 2:Int) [0.0, 2.0, 1.0]
const float P_SEAM_GLOW = 1.15; // P Seam Curve Glow [0.0, 2.2, 0.05]
const float P_ORBIT_AMP = 0.34; // P Cutter Offset [0.05, 0.62, 0.02]
const float P_ROT_SPEED = 1.0; // P Orbit Speed [0.0, 2.5, 0.05]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

float sdTorus(vec3 p, vec2 t) {
  vec2 q = vec2(length(p.xz) - t.x, p.y);
  return length(q) - t.y;
}

// Evaluate both manifold operand SDFs A (chamfered steel cube) & B (cutter sphere + crossing cylinder)
void evalOperands(vec3 p, float spin, float orbitAmp, out float dA, out float dB) {
  vec3 q = p;
  q.xz = rot2(spin * 0.38) * q.xz;
  q.yz = rot2(0.35) * q.yz;

  dA = sdBox(q, vec3(0.56)) - 0.04;

  // Dynamic manifold operand B orbiting through A
  vec3 bOff = vec3(orbitAmp * cos(spin * 0.75), orbitAmp * 0.65 * sin(spin * 0.92), orbitAmp * sin(spin * 0.75));
  float dSph = length(q - bOff) - 0.46;
  vec3 tq = q;
  tq.xy = rot2(spin * 0.5) * tq.xy;
  float dTor = sdTorus(tq, vec2(0.52, 0.16));
  dB = min(dSph, dTor);
}

// Exact CSG boolean combination returning vec3(distance, matID, seamProximity)
vec3 mapCSG(vec3 p, float opMode, float spin, float orbitAmp) {
  float dA, dB;
  evalOperands(p, spin, orbitAmp, dA, dB);

  float d;
  float matId;
  float seam;
  if (opMode < 0.5) {
    // Union: A U B
    d = min(dA, dB);
    matId = (dA < dB) ? 1.0 : 2.0;
    seam = abs(dA - dB);
  } else if (opMode < 1.5) {
    // Difference: A  B
    d = max(dA, -dB);
    matId = (dA > -dB) ? 1.0 : 3.0; // interior carved face gets distinct warm-copper ID
    seam = abs(dA + dB);
  } else {
    // Intersection: A n B
    d = max(dA, dB);
    matId = (dA > dB) ? 1.0 : 2.0;
    seam = abs(dA - dB);
  }
  return vec3(d, matId, seam);
}

vec3 calcNormal(vec3 p, float opMode, float spin, float orbitAmp) {
  vec2 e = vec2(0.002, 0.0);
  return normalize(vec3(
    mapCSG(p + e.xyy, opMode, spin, orbitAmp).x - mapCSG(p - e.xyy, opMode, spin, orbitAmp).x,
    mapCSG(p + e.yxy, opMode, spin, orbitAmp).x - mapCSG(p - e.yxy, opMode, spin, orbitAmp).x,
    mapCSG(p + e.yyx, opMode, spin, orbitAmp).x - mapCSG(p - e.yyx, opMode, spin, orbitAmp).x
  ));
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float opMode = floor(clamp(P_BOOL_OP + 0.5, 0.0, 2.0));
  float seamGlow = clamp(P_SEAM_GLOW, 0.0, 2.5);
  float orbitAmp = clamp(P_ORBIT_AMP, 0.04, 0.65);
  float spin = iTime * max(P_ROT_SPEED, 0.0);

  vec3 ro = vec3(0.0, 0.14, 2.52);
  vec3 rd = normalize(vec3(uv, -1.52));

  vec3 col = mix(vec3(0.03, 0.04, 0.068), vec3(0.09, 0.115, 0.168), smoothstep(-0.55, 0.55, uv.y));
  vec2 bgG = abs(fract(uv * 10.0 - 0.5) - 0.5);
  col += vec3(0.018, 0.028, 0.045) * smoothstep(0.03, 0.0, min(bgG.x, bgG.y));

  float t = 0.0;
  vec3 res = vec3(0.0);
  bool hit = false;
  for (int i = 0; i < 72; i++) {
    res = mapCSG(ro + rd * t, opMode, spin, orbitAmp);
    if (res.x < 0.0018) { hit = true; break; }
    t += max(res.x * 0.85, 0.002);
    if (t > 9.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p, opMode, spin, orbitAmp);
    float matId = res.y;
    float seamD = res.z;

    // Distinct crisp materials for operand A (brushed slate-steel), operand B (cobalt), and carved inner B (warm brass)
    vec3 alb;
    if (matId < 1.5) alb = vec3(0.68, 0.72, 0.78);
    else if (matId < 2.5) alb = vec3(0.18, 0.56, 0.88);
    else alb = vec3(0.92, 0.52, 0.22);

    // Subtle CAD grid on operand surfaces
    vec3 objP = p;
    objP.xz = rot2(spin * 0.38) * objP.xz;
    objP.yz = rot2(0.35) * objP.yz;
    vec3 gf = abs(fract(objP * 7.5 - 0.5) - 0.5);
    float grid = smoothstep(0.035, 0.008, min(gf.x, min(gf.y, gf.z)));
    alb *= (1.0 - 0.12 * grid);

    vec3 l1 = normalize(vec3(0.62, 0.86, 0.55));
    vec3 l2 = normalize(vec3(-0.75, -0.25, 0.52));
    float diff1 = max(dot(n, l1), 0.0);
    float diff2 = max(dot(n, l2), 0.0);
    vec3 hVec = normalize(l1 - rd);
    float spec = pow(max(dot(n, hVec), 0.0), 46.0) * 0.58;
    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.30;

    col = alb * (0.24 + 0.84 * diff1 + 0.25 * diff2) + vec3(spec) + vec3(0.45, 0.75, 1.0) * rim;

    // Crisp glowing exact 1-manifold CSG intersection seam curve!
    float seamLine = smoothstep(0.022, 0.003, seamD);
    col = mix(col, vec3(0.28, 1.0, 0.86) * (1.25 + 0.5 * seamGlow), seamLine * min(seamGlow, 1.0));
    col += vec3(0.18, 0.92, 0.84) * exp(-seamD * 45.0) * 0.35 * seamGlow;
  }

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Combines with

- [Manifold Dual Contouring](https://texelatlas.vercel.app/t/manifold-dual-contouring.md): MDC output is guaranteed manifold, so it can feed booleans.
- [three-mesh-bvh](https://texelatlas.vercel.app/t/three-mesh-bvh.md): three-mesh-bvh can pick and raycast the resulting meshes in the browser.

## Sources

1. [primary] elalish (2019) elalish/manifold. https://github.com/elalish/manifold License: Apache-2.0. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Manifold Mesh Booleans." https://texelatlas.vercel.app/t/mesh-boolean-manifold/ (accessed 2026-12-01).
