Skip to content

Language 3D Primitives

Revar Desmera edited this page Nov 26, 2026 · 20 revisions

3D Primitives

All 3D primitives are centered on the origin in X and Y unless stated otherwise, and sit with their base at z = 0 unless center=true.

Curved surfaces are faceted according to $fn / $fa / $fs — see Special Variables.

Bad arguments follow OpenSCAD: a size, radius or height that isn't a number keeps its default of 1; a size or radius of zero or less, or one that isn't finite, draws nothing (BelfrySCAD 1.67 and earlier built an inside-out sphere(-1), which added material to a difference(), and a zero-thickness sheet for cube([1,1,0])); center counts only as a real true. Giving both r and d warns that r is ignored, and cylinder() warns Cylinder parameters ambiguous when r meets r1 or r2.


cube

cube(size = 1, center = false)
Argument Positional Default Meaning
size 1st 1 A number (all three sides) or [x, y, z]
center 2nd false true centers the cube on the origin
cube(10);                       // 10 × 10 × 10, corner at origin
cube([10, 20, 30]);             // rectangular box
cube([10, 20, 30], center=true);
cube(size=[1,2,3], center=true);
cube([20,14,10]) cube([20,14,10], center=true)

Axes shown, so what center actually moves is visible: by default one corner sits at the origin and the solid fills the +X+Y+Z octant; center=true straddles it.

A size vector shorter than 3 elements pads the missing axes with 0, producing a degenerate (empty) solid.


sphere

sphere(r = 1, style = "orig")
sphere(d = ..., style = "orig")
Argument Positional Default Meaning
r 1st 1 Radius
d named only — Diameter; overrides r when given
style named only "orig" How the surface is tessellated — see below; mostly a BelfrySCAD extension
sphere(10);
sphere(r=10, $fn=64);
sphere(d=20);

By default the sphere is a stack of max(2, ceil($fn_segments / 2)) latitude rings, each with $fn_segments longitude segments — so raising $fn refines both directions at once.

style=

Mostly a BelfrySCAD extension — feature name sphere-styles. Detect it with supported_feature("sphere-styles"), which is 0 where it is missing. See Language Extensions.

OpenSCAD is gaining style= too, with just "orig" and "octa" (added upstream 2026-09-29; in the 2026.10 test builds, not yet in a release). Where the styles stand against it:

  • "orig" is the same sphere in both.
  • "octa" is built the same way in both (since BelfrySCAD 1.67.1), so the mesh matches OpenSCAD's to rounding. Earlier BelfrySCAD placed the interior vertices differently, up to 2% of the radius away.
  • "aligned", "stagger" and "icosa" exist only here. OpenSCAD warns about them and falls back to "orig"; releases before style= existed warn that style is not a parameter and ignore it.

The same five styles as BOSL2's spheroid(). "aligned", "stagger" and "icosa" are BOSL2's constructions exactly; "octa" is OpenSCAD's (see above), which has the same vertex count as BOSL2's but places the interior vertices differently.

All five at $fn=12, where the constructions are easiest to tell apart — the same sphere, the same viewpoint, the same scale:

"orig" "aligned" "stagger" "octa" "icosa"
fan converging to a
pole with no vertex
vertex at the pole,
rings stacked below
rings rotated half a
face, no quad seams
subdivided
octahedron
subdivided icosahedron,
most even facets

Raise $fn and they converge on the same ball; the differences that matter — where vertices land, how even the triangles are — are the ones visible above.

style Construction At $fn=24, r=10
"orig" Latitude rings offset half a step from the poles, so there is no vertex at the pole. What OpenSCAD builds. 288 verts, 572 tris
"aligned" A vertex at each pole, rings on the latitudes between 266 / 528
"stagger" "aligned", with alternate rings rotated half a face 266 / 528
"octa" A subdivided octahedron on the sphere, interior vertices where great-circle arcs meet. Exactly symmetric — see below 146 / 288
"icosa" A subdivided icosahedron — the most even triangle sizes of the five 252 / 500

For "octa" and "icosa" those counts are not specific to 24 — see what $fn means below. $fn 21 through 24 all give the same 146-vertex "octa".

An unrecognized style warns and falls back to "orig".

What $fn means, per style

The three latitude-ring styles take $fn as segments around the equator. "octa" and "icosa" do not — they subdivide a solid, so $fn is converted to a subdivision frequency and quantized:

style $fn becomes vertices
"orig" "aligned" "stagger" segments around, used as given —
"octa" frequency ceil($fn / 4) 4f² + 2
"icosa" frequency ceil($fn / 5) 10f² + 2

So $fn of 9, 10, 11 and 12 all give the identical "octa" sphere (38 vertices), and 13 through 17 give the identical "icosa" one (92). Raising $fn by one often changes nothing; the next distinct sphere is a step of 4 or 5 away.

Which styles land vertices on the axes

Measured across $fn 4–24, sphere(r=10), asking whether the bounding box reaches exactly ±10 on each axis:

style ±X ±Y ±Z
"orig" only when $fn % 4 is 1 or 2 never never
"aligned" when $fn % 4 is 0 or 3 only when $fn % 4 == 0 always
"stagger" only when $fn % 8 == 0 only when $fn % 8 == 0 always
"octa" always always always
"icosa" at even frequency only at even frequency only at even frequency only

"octa" is the reliable one. An octahedron already has a vertex on each of ±X, ±Y and ±Z, and subdividing keeps them there — so it hits the nominal radius on every axis at every $fn, with the fewest triangles of any style. If a sphere has to meet a stated dimension, or is being subtracted to make a socket a real ball must sit in, that is the one to reach for.

"octa" is also exactly symmetric. Its mesh is identical under every 90° rotation about an axis and every mirror through a coordinate plane, to the last bit, not merely to rounding. So a copy turned by rotate([90, 0, 0]) coincides with the original exactly, and booleans between such copies come out clean: difference() { A; rotate([90, 0, 0]) A; } leaves nothing at all, where an almost-coincident surface would leave a mass of thin shards. No other style has this; the latitude-ring styles are not symmetric under those turns even in principle.

"aligned" gets there too, but only when $fn is a multiple of 4; "stagger" only at multiples of 8; and "orig" never reaches the nominal radius on Y or Z at all, so it always measures slightly under its stated size.

"icosa" alternates. An icosahedron has no vertex on an axis, but at even subdivision frequency the geometry lands on all three:

f=1   12 verts   9.79 max   not aligned
f=2   42 verts  10.00       aligned
f=3   92 verts   9.79       not aligned
f=4  162 verts  10.00       aligned

Since f is ceil($fn / 5), whether a given $fn aligns is not obvious from the number you wrote — treat "icosa" as not axis-aligned unless you have checked the specific $fn you are using.

"icosa" still gives the most uniform facets for a given triangle budget, which is what you want for a smooth-looking ball or anything that will be further offset or Minkowski'd. "stagger" avoids the aligned styles' stacked-quad seams running pole to pole.


cylinder

cylinder(h=20, d=15) and the tapered form, cylinder(h=20, d1=20, d2=6).

cylinder(h = 1, r = 1, center = false)
cylinder(h = 1, r1 = ..., r2 = ..., center = false)
cylinder(h = 1, d = ...)
cylinder(h = 1, d1 = ..., d2 = ...)
Argument Positional Default Meaning
h 1st 1 Height along Z
r1 2nd 1 Bottom radius
r2 3rd 1 Top radius
center 4th false true centers on Z (-h/2 … +h/2)
r named only — Radius, both ends
d named only — Diameter, both ends
d1 / d2 named only — Bottom / top diameter
cylinder(h=20, r=5);
cylinder(h=20, r1=5, r2=0);          // cone
cylinder(h=20, d1=10, d2=4);         // truncated cone
cylinder(h=20, r=5, center=true);
cylinder(20, 5, 2, true);            // same as r1=5, r2=2, center=true

Radius resolution

Arguments are applied in this order, each overwriting what came before:

  1. r — sets both ends
  2. d — sets both ends, overriding r outright
  3. r1, r2 — set their own end
  4. d1, d2 — set their own end

Two consequences that surprise people, both matching OpenSCAD exactly:

cylinder(h=10, r=5, d=8);      // r = 4  — d wins over r
cylinder(h=10, r1=5);          // cone 5 → 1, NOT a straight r=5 cylinder

Each end defaults to 1 independently — r2 does not fall back to r1. So a lone r1 (or a lone positional second argument) always produces a cone. Use r= when you want a straight cylinder.


polyhedron

polyhedron(points, faces)
polyhedron(vnf)         // [vertices, faces] -- BOSL2's own shape
polyhedron(obj)         // an object with `vertices` and `faces` keys

The two-argument form is standard OpenSCAD. The vnf/object forms are a BelfrySCAD extension — feature name polyhedron-vnf. Detect them with supported_feature("polyhedron-vnf"); OpenSCAD reads a 2-list as a points list and produces something quite different rather than failing.

Argument Positional Default Meaning
points 1st — List of [x, y, z] vertices
faces 2nd — List of index lists, each a face
triangles named only — Deprecated alias for faces, with OpenSCAD's DEPRECATED notice

The single-argument forms exist so a mesh can be passed around as one value. All four of these are the same call:

obj = render() { cube(10); };

polyhedron(obj);                        // the object
polyhedron(obj.vnf);                    // the [vertices, faces] 2-list
polyhedron(obj.vertices, obj.faces);    // the two halves
polyhedron(spheroid(d = 30));           // any BOSL2 VNF

The object form accepts any object carrying vertices and faces, not only one render() produced, so a script can build or reshape its own. points is accepted as an alias for vertices.

A 2-list is only read as a VNF when faces was not supplied separately, so the two-argument call is never reinterpreted. A points list that happens to hold exactly two points is left alone — its second element is a point, not a list of faces.

Faces are listed clockwise when viewed from outside the solid (equivalently, counter-clockwise from inside), matching OpenSCAD. Faces with more than three vertices must be planar and convex; they are triangulated on load.

polyhedron(
    points = [[0,0,0], [10,0,0], [0,10,0], [0,0,10]],
    faces  = [[0,2,1], [0,1,3], [1,2,3], [0,3,2]]
);

Vertex welding. Coincident vertices are merged (positions matched within 1e-6) and degenerate triangles dropped. This is why VNF meshes from libraries such as BOSL2 — which routinely carry duplicate vertices at seams and poles — build cleanly here instead of failing as non-manifold.

Welding is a repair, applied only when the mesh needs it. Coincident vertices are not always redundant: a solid whose shells touch — the two halves of an XOR meeting along a shared surface, or the stubs of a rod where it leaves the block it passes through — has genuinely separate vertices at identical positions, and merging those would fuse the shells into edges with four faces. So the mesh is checked first, and left alone when it is already sound. A mesh that arrives closed and manifold is used exactly as given.

When the mesh isn't a closed solid

Only a closed mesh — every edge shared by exactly two triangles — can become a solid. A closed one always does, however ugly: reversed winding, non-manifold vertices and self-intersections all build fine. (Reversed faces show their backs in magenta, which is a useful tell.)

A closed mesh with every face reversed — inside out as a whole — is turned right side out before it is drawn, as OpenSCAD 2026.11 does, so it subtracts and exports like any other solid. It warns, since the fix belongs in the face list:

WARNING: polyhedron: the solid is inside out -- every face is wound backwards;
drawing it turned right side out. Reverse the point order of every face to fix it

import() does the same for a mesh file. OpenSCAD 2026.11 flips both silently, but only once the solid takes part in a boolean; a lone inside-out object at the top level is exported inside out there. Only some faces reversed is left as given, magenta backs and all.

An open mesh — one with boundary edges, typically because a face is missing — can't. It is still drawn as a surface so you can see what you built, alongside a console warning naming how many edges are open:

WARNING: polyhedron: mesh is not closed -- 4 boundary edge(s), first at
[-10, -10, -10] - [-10, 10, -10]; drawing the object as an open surface
rather than a solid -- nothing is patched. hull() can still use its points,
but it cannot take part in union/difference/intersection
in file my_model.scad, line 12, from my_model.scad, line 30

It names one of the open edges. A count alone is enough when you wrote the face list yourself; it is useless on generated geometry, where three bad edges in a few thousand triangles cannot be found by eye. The coordinates give you somewhere to look — and, if you mean to repair it rather than fix the generator, the gap to pass to mesh_repair().

The from clause names the line of your own script that reached it, which matters when the polyhedron() is inside a library — see Troubleshooting.

Such a surface is display-only. It is skipped by union(), difference(), intersection(), hull() and minkowski() rather than merged into them, and its siblings in those operations are unaffected. It still exports, and ⌘-clicking it still selects it and highlights the source line.

mesh_repair() can turn one into a real solid — welding near-coincident vertices, filling holes and fixing the winding — when the mesh is nearly right and you would rather patch it than fix whatever produced it.

If the vertex data is broken rather than the topology — a nan coordinate, say — the body is discarded instead, since those coordinates can't be drawn. The console says which.


See also

  • surface() — build a solid from a heightmap
  • import() — load STL / OBJ / OFF / 3MF
  • mesh_repair() — make an almost-closed mesh into a solid
  • 2D to 3D — linear_extrude, rotate_extrude, roof

Clone this wiki locally