3D primitives
cube(size | [x,y,z], center?) // also box()
sphere(r, segments?)
cylinder(h, r1, r2?, {center, segments})
cylinder({h, r | d | r1, r2, center})
cone(h, r1, r2 = 0)
torus(R, r)
2D shapes
square(size | [w,h], center?) rect(w, h, center?)
circle(r, segments?)
polygon([[x,y], …] | [contour, …], 'nonzero'|'evenodd')
text(str, {font, size, depth: 0, letterSpacing,
lineHeight, align, center}) // depth 0 → 2D
shape.offset(d, {join: 'round'|'miter'|'square'})
2D → 3D
extrude(shape, h, {twist, scale, divisions, center})
revolve(shape, degrees = 360, {segments}) // around Z, x ≥ 0
text(str, {font, size, depth: 2}) // → solid
hull(a, b, …) // solids, shapes or [x,y,z] points
Booleans
union(a, b, …) difference(a, b, …) intersection(a, b, …)
a.add(b, …) a.subtract(b, …) a.intersect(b, …)
// arrays are flattened: a.subtract(holes)
Transforms (degrees)
.translate(x, y, z | [x,y,z]) .rotate([rx, ry, rz])
.scale(s | [sx,sy,sz]) .mirror([nx, ny, nz])
.center() .hull()
translate([x,y,z], a, b) // functional forms
.color('#3d6b8f' | 'red' | [r,g,b]) .name('lid')
Queries
.bounds() → {min, max, size, center}
.volume() .area() .genus() .isEmpty()
solid.slice(z) / .project() → shape solid.trim([nx,ny,nz], d)
fonts() → ['Roboto', 'Source Serif 4', …]
console.log(…) → Console panel
Parameters
export const params = {
width: { value: 40, min: 10, max: 100, step: 1, label: 'Width' },
lid: true, colour: '#c8664b', label: 'hi',
style: { value: 'a', options: { a: 'Round', b: 'Square' } },
};
// or OpenJSCAD style: function getParameterDefinitions() { return [
// { name: 'w', type: 'float', initial: 40, caption: 'Width' }, … ] }