OpenSCAD 3D primitives
Four built-in solid primitives — cube, sphere,
cylinder, polyhedron — plus import
for bringing in external meshes. Everything else in your model is built
from these, transformed, and combined with boolean operations.
cube
Generates an axis-aligned box. Default origin is the box's lower-front-left
corner; pass center=true to place the origin at the box's
centroid instead.
cube(size, center=false);
cube([width, depth, height], center=false);
| Parameter | Type | Description |
|---|---|---|
size | number or 3-vector | Edge length (uniform) or per-axis lengths in mm. |
center | bool | If true, centroid is at the origin. |
Examples
cube(10); // 10×10×10 cube, corner at origin
cube([40, 20, 4]); // rectangular plate
cube([40, 20, 4], center=true); // centered
sphere
Generates a sphere centered on the origin. Pass r OR d (diameter), not both.
sphere(r);
sphere(d=diameter);
| Parameter | Type | Description |
|---|---|---|
r | number | Radius in mm. |
d | number | Diameter in mm. |
$fn / $fa / $fs | special | Control facet density (see special variables). |
Examples
sphere(10); // radius 10, default smoothness
sphere(d=20); // diameter 20 (same shape)
sphere(5, $fn=128); // silky-smooth showcase render
cylinder
Generates a cylinder or a cone along the Z axis. The base sits at
Z = 0 unless center=true, in which case the centroid is at the
origin and the cylinder extends from -h/2 to +h/2.
cylinder(h, r | d=D, center=false);
cylinder(h, r1, r2 | d1=D1, d2=D2, center=false);
| Parameter | Type | Description |
|---|---|---|
h | number | Height in mm. |
r / d | number | Radius / diameter — uniform cylinder. |
r1, r2 / d1, d2 | number | Bottom and top radii — produces a cone or truncated cone. |
center | bool | Center along Z if true. |
Examples
cylinder(h=20, r=5); // straight cylinder
cylinder(h=20, d=10, $fn=64); // smoother
cylinder(h=30, r1=15, r2=0); // pointed cone
cylinder(h=30, r1=15, r2=5); // truncated cone
cylinder(h=5, d=8, $fn=6); // hexagonal prism
cylinder($fn=6) = hex prism, $fn=4 = square pyramid base.
Low-facet cylinders are the cheapest way to get polygonal prisms — bolts, knurls, hex sockets — without writing a polygon by hand.
polyhedron
For anything that isn't a primitive — sweeps, parametric meshes, ports of external geometry — build it from raw points and faces.
polyhedron(points, faces, convexity=1);
| Parameter | Type | Description |
|---|---|---|
points | list of [x,y,z] | Vertex coordinates. |
faces | list of index lists | Each entry lists the points (CW when viewed from outside) of one face. |
convexity | int | Render hint — max number of front+back surfaces a ray crosses. |
Example: a tetrahedron
polyhedron(
points = [[0,0,0], [10,0,0],
[5,10,0], [5,5,10]],
faces = [[0,2,1], [0,1,3],
[1,2,3], [0,3,2]]
);
OpenSCAD expects face vertex indices in clockwise order when
viewed from outside the solid. Wrong winding produces inverted
normals, non-manifold geometry, and a warning in the console. The AI CAD
agent tends to use linear_extrude over polyhedron
for exactly this reason.
import
Pull an existing mesh into the scene. Useful for ingesting community parts, vendor models, or scan data.
import("my_part.stl", convexity=10);
import("frame.3mf");
import("mesh.off");
Supported formats: .stl, .off, .amf, .3mf. 2D variants of import handle .dxf and .svg.
Cookbook
Through-hole plate
difference() {
cube([40, 40, 4]);
translate([20, 20, -1])
cylinder(h=6, d=6, $fn=48);
}
Hemisphere
difference() {
sphere(10, $fn=96);
translate([0,0,-10])
cube([22,22,10], center=true);
}
Bolt blank (M3 × 16)
union() {
cylinder(h=3, d=6, $fn=6); // hex head
cylinder(h=19, d=3, $fn=32); // shank
}
Rounded plate (Minkowski)
minkowski() {
cube([38, 28, 3]);
cylinder(r=3, h=0.5, $fn=32);
}
Need a specific shape? Just describe it.
"M3 corner bracket with 30 mm legs and two countersunk holes per leg" → the AI agent picks the right primitives, transforms, and booleans.