What follows is concise documentation for the core of OpenJSCAD (the official docs are a bit confusing as cover both V1 and 2 and include lots of deprecated stuff). I recommend opening OpenJSCAD and playing around while looking at these docs. I've used it to produce many objects for 3D printing. While it has its limitations it is a very quick way to get started (assuming you know JS).
Always have a main function which returns an object
function main() {
return union(
difference(cube({ size: 3, center: true }), sphere({ r: 2, center: true })),
intersection(
sphere({ r: 1.3, center: true }),
cube({ size: 2.1, center: true })
)
)
.translate([0, 0, 1.5])
.scale(10)
}
cube({ size: 1, center: true })
cube({ size: [1, 2, 3] })
s
or [x,y,z]
false
by default (at 'bottom' corner)All shapes follow this pattern, simple function + options
cylinder({ r: 1, h: 10 })
center
or not (default)fn
to control detailscale(2, obj)
scale([1, 2, 3], obj)
All transformations follow this pattern, function which takes options first then thing(s) to be transformed. Note that official docs can be confusing as cover old OOP-style cube().scale(2)
approach, which you shouldn't use.
translate([5, 4, 3], obj)
[x,y,z]
translate([0, 0, 5], obj)
rotate([90, 0, 45], obj)
[x,y,z]
(respectively)rotate([0, 0, 90], obj)
NB Degrees not radians
union([obj, another])
union(obj, another)
All the composition operations take either an array of shapes or can take multiple shapes as arguments. You can't mix and match.
sphere({ r: 4 })
center
is true by default (unlike other primitive objects)fn
to control detailList of points to make a (2D) polygon on x,y plane
let p1 = polygon([
[0, 0],
[3, 0],
[3, 3],
])
let p2 = polygon({
points: [
[0, 0],
[3, 0],
[3, 3],
],
})
Then extrude with linear_extrude
:
linear_extrude({ height: 10 }, p1)
linear_extrude({ height: 1 }, p2)
intersection(
sphere({ r: 1.3, center: true }),
cube({ size: 2.1, center: true })
)
difference(cube({ size: 3, center: true }), sphere({ r: 2, center: true }))
You now know enough to do create nearly any 3D shape (or an approximation to it) with OpenJSCAD.