Generating 3D Objects with AI: The OpenSCAD Approach
An Introduction to OpenSCAD
OpenSCAD is a free, open-source software application for creating solid 3D CAD objects. It is available for download at openscad.org for all major operating systems.
Unlike interactive, visual CAD tools where users manipulate 3D models interactively with a mouse and graphical interface, OpenSCAD operates more like a 3D compiler. It reads a script file written in its own custom, functional programming language and renders the 3D model entirely from that code.
Users define geometric primitives (such as cubes and cylinders) and modify them using mathematical transformations (translate, rotate) and boolean operations (union, difference, intersection). This script-based approach makes the software inherently parametric; altering a single variable at the top of the script systematically updates the entire downstream model. This deterministic nature makes it a highly effective target for AI code generation.
The ChArUco Calibration Target
To apply this parametric design approach, we tackled the generation of a ChArUco board. A ChArUco board is a calibration target that combines a traditional checkerboard with unique, embedded ArUco markers. It is used in computer vision to accurately determine a camera's intrinsic parameters, correcting for lens distortion and calculating focal length. Precise calibration is a strict requirement for applications relying on accurate spatial measurements, such as the targeting systems used by FIRST Robotics Team 5199, the Robot Dolphins from Outer Space.
To optimize tracking, the system required a rigid, large-scale 15x15 target. Standard commercial boards are costly, and paper printouts are prone to warping, which degrades calibration data. 3D printing provides the necessary flatness and contrast, but standard print beds are too small to manufacture a full-sized board as a single piece.
The solution was to develop a parametric model capable of slicing itself into interlocking, printable sections. To build this, AI was utilized to generate the geometry using OpenSCAD.
The Iterative Process: 45 Versions
Engineering a functional, multi-material 3D model through an LLM requires a highly iterative approach. Outputting a viable board—complete with customizable bed sizes, automatic cut strategies, and screw-reinforced joiners—took over 45 distinct versions.
This sustained iteration was necessary to address the various edge cases, boolean logic errors, and physical tolerance issues that only became evident after compiling and previewing the script within OpenSCAD.
Addressing Constraints: The Dovetail Problem
A specific structural challenge emerged when designing the interlocking puzzle joints. To connect the printed plates, the initial scripts generated male and female dovetail joints uniformly along the split seams. However, if a dovetail joint intersected a white ArUco marker square, it altered the marker's visual geometry, which would cause the computer vision tracking to fail.
When prompted with this operational constraint, the generated solution utilized a "smart indexing" mathematical function based on grid coordinate parity. This logic ensured the interlocking dovetails were dynamically shifted so they only spawned on the solid black squares of the pattern. This resolved the structural requirement while preserving the optical integrity of the markers.
Incremental Updates
This workflow highlights a practical utility of generating OpenSCAD code compared to generating raw 3D meshes or images.
Generative models generally struggle with isolated, incremental updates. Requesting a localized modification to a generated image or mesh frequently results in the regeneration of the entire latent space, unintentionally altering previously established features.
Because OpenSCAD relies entirely on mathematics and code, this limitation is bypassed. When an adjustment was needed for the dovetail anchor depths in Version 33, the AI modified only the specific geometric variables responsible for that dimension. The surrounding logic—the grid array, the text labels, and the joiner bosses—remained isolated and unchanged.
Using an AI to write parametric CAD code enables structured, incremental development, applying programmatic isolation to iterative problem-solving.
All source code for this project, including the OpenSCAD scripts and the Python geometry generator, is available here:
https://github.com/jywilson2/charuco
Authored by Gemini 3.1 Pro, assisted by organic intelligence.
Comments ()