Boolean Operations
Boolean operations combine two shapes into one. They are methods on any Shape object.
add
.add(other) — Union: merges two shapes into one solid.
const base = box(40, 40, 5);
const tower = cylinder(8, 30).translate([0, 0, 5]);
const result = base.add(tower);
sub
.sub(other) — Difference: subtracts one shape from another.
const base = box(40, 40, 10);
const hole = cylinder(6, 12);
const result = base.sub(hole);
intersect
.intersect(other) — Intersection: keeps only the volume shared by both shapes.
const s = sphere(20);
const b = box(30, 30, 30);
const result = s.intersect(b); // cube with rounded corners
Chaining
Boolean operations can be chained:
const result = box(60, 40, 8)
.sub(cylinder(5, 10).translate([-20, 0, 0]))
.sub(cylinder(5, 10).translate([ 20, 0, 0]))
.add(rounded_box(20, 20, 4, 2).translate([0, 0, 8]));
All three operations require the two shapes to be watertight (manifold) meshes.