Code Your Objects: Programming 3D Shapes
When code meets geometry
When code meets geometry
Every 3D object starts with simple shapes called primitives: cubes, spheres, cylinders, and cones. In code, you describe them with a function call and dimensions. Click each shape to see its code and 3D view.
Click a primitive to see it.
Constructive Solid Geometry builds complex shapes from simple ones using three operations. This is how OpenSCAD, Blender's boolean modifiers, and most CAD software create objects.
Union: joins two shapes into one combined solid.
Merge shapes together. Like gluing two objects. The combined volume becomes one solid.
Cut one shape out of another. Like drilling a hole. The subtracted volume is removed.
Keep only the overlap. Like a Venn diagram: only the region where both shapes exist survives.
Replace numbers with variables, and one design becomes infinitely adjustable. Change a single parameter and everything that depends on it updates automatically.
OpenSCAD was created in 2010 specifically for programmers who wanted to design 3D-printable objects. Unlike drag-and-drop CAD tools, everything is a text file. You can diff, merge, and version-control your designs like software.
Programmatic 3D modeling powers industries where precision and repeatability matter.
Design a part in code, export as STL, print it in plastic, metal, or resin. Parametric models let you adjust dimensions for the perfect fit every time.
CNC machines cut metal based on CAD models. The same CSG operations you just learned drive billion-dollar manufacturing processes.
Parametric architecture uses code to generate building facades, structural supports, and organic forms that would be impossible to design by hand.
CSG is used in level editors to carve rooms from solid blocks (subtractive) or build structures from primitives (additive). The Unreal Engine uses both approaches.
The workspace is split into two panels. On the left is the code editor where you write OpenSCAD commands. On the right is the 3D viewer that renders your model. Write code, hit Render, and see the result instantly.
Full syntax highlighting, autocomplete, and error reporting. Supports all OpenSCAD keywords, built-in functions, and popular libraries like BOSL2.
Interactive preview of your rendered model. Rotate, pan, and zoom to inspect your design from any angle. Toggle edges, grid lines, and axis helpers.
Render your model, change STL color and opacity, toggle wireframe edges, enable the measurement grid, center the model, and export to STL.
Rotate the model. Click and drag anywhere on the viewer to orbit around the object.
Pan the view. Right-click and drag to slide the camera without rotating.
Pan the view (touchpad-friendly). Hold the spacebar and left-click drag for easy panning without a mouse.
Zoom in and out. Scroll up to zoom in, scroll down to zoom out. Pinch on a touchpad also works.
Save your project. Your code and settings are saved to the platform so you can pick up where you left off.
Return focus to the code editor. If you clicked in the 3D viewer, press Escape to jump back to editing.
You've learned how code creates physical objects. Union, difference, and intersection: three operations that build anything from a cup to a rocket engine. This is the foundation of CAD, 3D printing, and manufacturing.
Instead of sculpting by hand, you write instructions: "make a cube 20mm wide" or "make a sphere with radius 10." The computer builds it exactly.
Union joins shapes together. Difference cuts one from another. Intersection keeps only where they overlap. Three operations build anything.
Replace fixed numbers with variables. Change one value and the whole design updates. This is parametric design: one model, infinite variations.
A coded design can be shared, version-controlled, and reproduced exactly. No ambiguity, no interpretation. The code IS the blueprint.
Put your new knowledge into practice!