OpenSCAD
OpenSCAD is a language used to create parametric and accurate 3d models using nothing but code. Note: I refer to CSG multiple times in this post; this stands for Constructive Solid Geometry. This means constructing a model through a combination of combining objects, subtracting objects, and intersecting objects. Factoid:
Since a .scad file is plain text, it occupies very little space, and you can use tools like diff effectively. Length 1:
Well, there isn't too much you can do with one character, but one very useful character is the debug modifier:
#
This character can be placed in front of any CSG tree to highlight it, even if it would be invisible in the final output (such as if the CSG object was subtracted from another object). I'm not allowed to write any more code to explain this, so I'll use pictures.
Without the modifier:
With the modifier:
(Image Source: OpenSCAD User Manual, Wikibooks, CC-BY-SA)
Length 2:
In OpenSCAD, you can create simple animations. How, you ask? This is done using a special variable for animation:
$t
This variable repeatedly loops from 0 to 1, which your code can use to change the position of an object, rotate an object, or do pretty much anything when combined with control flow structures. OpenSCAD can dump png frames at user specified intervals to create videos and/or gifs.
Adding a single line of code to a program (in this case, one of the examples, which also happens to be the OpenSCAD logo), and running the output through a gif maker can turn it into an animation like this: Length 3
There are a wealth of libraries in OpenSCAD, and one way to access them is via the command:
use
There are actually two commands with similar functionality, but the other one has too many bytes. The main difference is that any top-level code (code outside a function/module) isn't executed with use
, while it is executed for the other command. Both commands must be placed before any use of imported functions.
There are a couple of widely used libraries (Note that some of these should be added to the project with the other command instead):
- MCAD- this contains basic utilities (more shapes, gears, some math, etc), and often is installed automatically with OpenSCAD.
- Write.scad- Many of it's functions have been superseded by built-in functions in OpenSCAD, but it allows you to do a little more than the built-in functions can do (write curved text, for example).
- BOLTS- This extensive library allows you to use standard hardware parts (and some non-standard hardware) in your projects.
- The General Library of Relativity- Allows creating and positioning of objects relative to other objects.
- String Theory- Made by the same person as Relativity, this provides various string utilities, along with regex functionality.