Content
# OpenSCAD Agent Plugin 🚀
An advanced plugin that empowers AI coding agents (like Antigravity, GitHub Copilot, Claude Code, and AWS Kiro) to design, visualize, and manufacture 3D parts using OpenSCAD.
## About 📖
This plugin bridges the gap between text-based parametric 3D modeling and real-world fabrication. While standard AI agents struggle with spatial reasoning and cannot physically "see" the 3D models they generate, this plugin provides a full CAD and partial CAM toolchain. It allows the agent to:
1. Generate and iteratively edit OpenSCAD geometry.
2. Render visual previews inside the chat window for immediate geometric feedback.
3. Check for physical interferences and collisions between components.
4. Extract structured Bill of Materials (BOM) for hardware procurement.
5. Automatically layout, nest, and export 2D templates for laser cutting or CNC routing.
6. Intelligently split oversized 3D prints into interlocking segments.
Whether you are designing a complex cyberdeck enclosure for laser cutting or a 3D-printable replacement bracket, this server provides the necessary tools for an AI assistant to act as your autonomous engineering co-pilot.
## Installation 🛠️
You can install this plugin directly via your AI agent's native plugin installer:
```bash
# Antigravity
agy plugin install https://github.com/jmo808/OpenSCAD_Plugin.git
```
### Manual Installation
If your agent doesn't support direct git installation, we provide a universal multi-agent installer out of the box.
1. Ensure you have `uv` installed (`pip install uv`).
2. Clone this repository.
3. Run the installer script:
```bash
uv run python3 install.py
```
The installer will automatically detect and configure the MCP server for:
- **Antigravity** (CLI, IDE)
- **Claude Code** (`~/.claude.json`)
- **GitHub Copilot CLI** (`~/.config/github-copilot/mcp.json`)
- **AWS Kiro** (`~/.aws/kiro/mcp.json`)
## Tools & Features 🧰
The server exposes 10 distinct tools via MCP:
- `generate_scad`: Writes and modifies OpenSCAD source files with parameter injection.
- `compile_and_preview`: Renders high-quality orthographic or perspective previews (isometric, top, front, etc.).
- `export_stl`: Finalizes verified geometry into 3D-printable `.stl` files.
- `export_2d_templates`: Flattens selected components onto the Z=0 plane and exports them to `.dxf` or `.svg`.
- `add_dimensions`: Injects blueprint-style extension lines and text annotations for 2D engineering drawings.
- `generate_multiview`: Generates a unified 4-quadrant engineering drawing (front, right, top, isometric).
- `check_interference`: Runs 3D CSG intersection logic to detect and highlight collisions between parts in red.
- `extract_bom`: Parses tagged hardware in comments into a structured JSON/CSV Bill of Materials.
- `nest_panels`: Performs 2D bin-packing to layout parts onto standard material sheets (e.g., 4x8 plywood) accounting for kerf.
- `split_for_printing`: Splits large models along optimal axes and applies interlocking joints (dovetails, flanges, pins).
---
## Nesting Algorithm Limitations 🧩
The `nest_panels` tool utilizes a highly optimized **First-Fit Decreasing (FFD) Shelf Packing** algorithm. This approach calculates the bounding box of each 2D shape and packs them as rectangles.
Because this is a pure-Python, zero-dependency implementation, it does **not** perform True Shape Nesting (which requires computationally expensive No-Fit-Polygon geometry engines typically built in C++ like `libnest2d`). As a result, the tool cannot automatically "interlock" complex non-rectangular shapes (like L-shapes or angled side panels) into one another's negative space.
**How to optimize further:**
1. The `nest_panels` tool generates a fully editable `sheet_1_layout.scad` file. You can simply open this file and manually edit the `translate()` and `rotate()` functions to nudge pieces closer together into interlocking positions.
2. The tool now also exports the individual, isolated `.dxf` profiles alongside the generated layout. For massive commercial jobs, you can drag these individual DXF files directly into a free true-shape nesting application like **Deepnest.io**.
---
## Sample Conversation 💬
Here is an example of an AI agent using this MCP server to iteratively design a cyberdeck enclosure (NOTE: VERY abbreviated conversation of something real designed with this MCP, final product turn ~ 40 iterations):
**User:**
> I want to design an enclosure for my cyberdeck. I have this original AI-generated concept art that I want you to use as inspiration:
>
> 
>
> It needs a top panel, a bottom panel, and some structural cleats to hold them together. Make it 250mm wide and 150mm deep. Render a preview so I can see it.
**Agent:**
> I'll use `generate_scad` to write the initial layout with those dimensions, and then use `compile_and_preview` to show you what it looks like.
> *(Agent calls `generate_scad` and `compile_and_preview`)*
> Here is the initial design based on your concept:
>
> 
**User:**
> Looks good, but I think the side cleats are colliding with the top panel. Can you run an interference check?
**Agent:**
> I'll run the `check_interference` tool to verify if there are any overlaps.
> *(Agent calls `check_interference`)*
> Ah, you are correct. The tool found an intersection volume of 3200mm³ between `top_panel` and `cleat_left`. I will adjust the Z-translation of the top panel to add a 0.2mm tolerance gap and fix the collision.
> *(Agent calls `generate_scad` and `compile_and_preview`)*
> How does this look?
>
> 
**User:**
> Getting closer. The support blocks are too large, and after we need some internal cylindrical standoffs for the keyboard PCB/switchplate M2 mounting screws.
**Agent:**
> Understood, I'll rotate the display faceplate by another 15 degrees and add 5mm cylindrical standoffs to the interior bottom panel.
> *(Agent calls `generate_scad` and `compile_and_preview`)*
>
> 
***... 30 iterations later ...***
**Agent:**
> I've applied the final dimension tweaks to the back plate and ensured all tolerances are correct. Here is the final, fixed version with proper clearances:
>
> 
**User:**
> This is perfect! I want to laser cut this out of a 4x4 hardboard sheet. Can you pack the parts for me? Let's extract the BOM as well.
**Agent:**
> *(Agent calls `nest_panels` with a 48x48 inch / 4x4 preset and `extract_bom`)*
> I've successfully packed all the 2D flat panels onto a 4x4 hardboard sheet to optimize material usage and exported the DXF. Here is the layout:
>
> 
>
> Based on the annotations in the design, I've also exported `bom.csv`. You will need **16x M3x12 socket head cap screws** and **3x M2x8 socket head cap screws** (for the middle support posts) to assemble the enclosure.
---
*Built with ❤️ for OpenSCAD & the MCP ecosystem.*