3D Primitives
-- Cube / Cuboid
cube(size)
cube { size = {x, y, z}, center = true }
cube(x, y, z)
-- Sphere
sphere(r)
sphere { r = radius }
sphere { d = diameter }
-- Cylinder / Cone
cylinder { h = height, r = radius, center = false }
cylinder { h = height, r1 = bottom_r, r2 = top_r }
cylinder { h = height, d = diameter }
-- Polyhedron
polyhedron { points = {...}, faces = {...} }
-- Pyramid
pyramid { size = {x, y}, h = height }
-- Torus
torus { r1 = major_radius, r2 = minor_radius }
-- Octahedron
octahedron { r = radius }
-- Icosahedron
icosahedron { r = radius }
-- Ellipsoid
ellipsoid { rx = rx, ry = ry, rz = rz }
2D Primitives
-- Circle
circle(r)
circle { r = radius }
circle { d = diameter }
-- Rectangle / Square
rect { size = {width, height}, center = false }
square { size = width, center = false }
-- Polygon
polygon { points = {{x1,y1}, {x2,y2}, ...} }
-- Text (SCAD export only)
text("string", { size = 10, font = "Liberation Sans" })
-- Text 3D
text3d("string", { size = 10, h = 5 })
Boolean Operations
-- Union
a + b
-- Difference
a - b
-- Intersection
a * b
Transformations
-- Translate
obj:translate(x, y, z)
-- Rotate (Euler angles in degrees)
obj:rotate(x, y, z)
-- Rotate around center point
obj:rotate(cx, cy, cz, rx, ry, rz)
-- Scale
obj:scale(sx, sy, sz)
-- Resize
obj:resize(x, y, z)
-- Mirror
obj:mirror(x, y, z)
-- Transformation matrix (4x4)
obj:multmatrix(matrix)
Extrusions & Hulls
-- Extrude 2D shape into 3D
shape:linear_extrude(height)
shape:linear_extrude(height, { twist = 90, slices = 10, scale = 2 })
-- Revolve 2D shape around Z axis
shape:rotate_extrude()
shape:rotate_extrude(360, 64) -- angle, segments
-- Convex hull
obj:hull()
-- Minkowski sum
obj:minkowski(other)
-- Offset (2D)
shape:offset(delta)
shape:offset { delta = d, chamfer = true }
shape:offset { r = radius }
Color
-- By name
obj:color("red")
-- By RGB (0-1)
obj:color(r, g, b)
-- By RGBA
obj:color(r, g, b, a)
-- Alias
obj:setcolor(...)
Modifier Characters
obj:skip() -- * disable (hide in preview)
obj:only() -- ! show only
obj:debug() -- # highlight
obj:transparent() -- % transparent / background
Other Operations
-- Clone / copy
obj:clone()
obj:copy()
-- Projection (3D to 2D)
obj:projection()
obj:projection(true) -- cut mode
-- Force render
obj:render_node(convexity)
Utility Functions
-- Add geometry to output
render(geometry)
-- Import external file (SCAD export only)
import("model.stl", convexity)
-- Import surface heightmap (SCAD export only)
surface("heightmap.dat", center, convexity)
-- Insert verbatim OpenSCAD code
scad("cylinder(h=10, r=5, center=true);")
-- OpenSCAD customizer variable (returns value as-is)
var("name", value)
-- Empty CAD object
cad()
-- Random numbers
rands(min, max, count)
rands(min, max, count, seed)
-- Linear interpolation lookup
lookup(key, {{k1,v1}, {k2,v2}, ...})
-- Version
version() -- returns {major, minor, patch}
-- Print to console
print(...)
Vector Operations
-- Create vector
local v = vector(x, y, z)
local v = vec(x, y)
-- Arithmetic
v1 + v2 -- addition
v1 - v2 -- subtraction
5 * v or v * 5 -- scalar multiplication
-v -- negation
-- Methods
v:getx() v:gety() v:getz()
v:len() -- length / magnitude
v:unit() -- unit vector
v:normal() -- 2D normal
v:scalar(v2) -- dot product
v:cross(v2) -- cross product
v:rot(angle) -- rotate vector
v:angle(v2) -- angle between vectors
-- Global functions
cross(v1, v2)
norm(v)
Math Functions
-- Available as bare globals (degrees for trig):
sin(deg) cos(deg) tan(deg)
asin(x) acos(x) atan(x) atan2(y, x)
abs(x) floor(x) ceil(x) round(x)
sqrt(x) pow(x,y) exp(x) log(x) ln(x)
min(...) max(...) sign(x)
PI -- 3.14159...
-- Type checking
is_bool(v) is_num(v) is_str(v)
is_table(v) is_list(v) is_func(v)
-- List operations
concat(a, b) -- concatenate two tables
Settings
settings.fa -- minimum angle (default 12)
settings.fs -- minimum size (default 2)
settings.fn -- number of fragments (default 0)
settings.t -- animation step (default 0)
settings.vpr -- viewport rotation
settings.vpt -- viewport translation
settings.vpd -- viewport distance
settings.vpf -- viewport field of view
settings.preview -- true in preview mode