Skip to content
ghadinehmePublic

About

An AI-native parametric CAD environment for the web

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Repository files navigation

Studio CAD

An AI-native parametric CAD environment for the web.

Load CAD generated by AI models into a real, editable feature tree, refine it with a B-rep kernel — sketch, extrude, revolve, fillet, patterns — and export it straight back to clean CadQuery .py (or STEP / STL) for an AI model to pick up and edit on the fly.

Powered by CadQuery (OpenCascade / OCCT) on the backend and Three.js in the browser.

AI-generated CAD ⇄ editable feature tree ⇄ CadQuery code


Table of contents


Why Studio CAD

AI models are getting good at generating CAD — from a prompt, an image, or a mesh — but their output is usually a dead end: a blob of geometry or a one-shot script you can look at but not really work with. There is no clean loop where a human engineer and an AI model edit the same model and hand it back and forth.

Studio CAD is built to be that loop. It is an AI-native CAD environment:

  • Load AI-generated CAD code — today, the CadQuery scripts produced by CADFit (a mesh/image → CAD fitter) — straight into an editable parametric feature tree of sketches, extrudes, revolves, fillets and patterns, not a frozen mesh.
  • Edit it like real CAD. A human engineer fixes, refines and extends the model with a genuine B-rep kernel (OCCT via CadQuery) — the full modeling toolset below.
  • Export it back as clean CadQuery .py so an AI model (Claude, ChatGPT, an agent, …) can read it, reason about it, and edit it on the fly — then hand it back to the engineer.

The property that makes this loop trustworthy is that the model is a linear list of parametric features and every feature maps one-to-one to a line of CadQuery code. The .py is not a lossy screenshot of the model — it is the model, equally editable by a person in the UI and by a model in a prompt. Round-trips (import → edit → export) match their reference geometry to < 0.2%.


Community & contributing

Studio CAD is an early, open foundation for AI-native CAD — a shared, editable bridge between AI models and real engineering CAD. It gets more useful the more people build on it. High-value directions:

  • More CadQuery parsers. The bundled importer targets the CadQuery dialect emitted by CADFit. Every AI CAD generator writes its own style — add parsers so their output loads into an editable feature tree too. Parsers live in cadkernel/cqimport.py; every construct a parser recovers becomes an editable feature. (See The CadQuery script format.)
  • Deeper AI-agent connections. Wire Studio directly to agents — Claude, ChatGPT, and others — so a model can read the current .py, propose an edit, and stream it back into the feature tree live. The /api/code and /api/run_code endpoints already make this a few lines; the goal is a first-class "ask an agent to edit this model" loop inside the UI.
  • Keep improving the UI and kernel — expose loft/sweep in the toolbar, add constraints and assemblies, richer sketching, drawings, and more interchange formats.

If you build a parser, an agent integration, or a UI feature, please open a PR or an issue. The point is a common, faithful, human-and-AI-editable representation of a CAD model — let's grow it together.


Feature overview

Sketching (in-viewport, Onshape-style)

  • Draw directly on a base plane (XY / XZ / YZ), a datum plane, or any model face — pick the face in 3D and the sketch snaps to it.
  • Tools: line / polyline, rectangle, circle, arc (3-point), polygon (n-gon), slot.
  • Zoom-adaptive resolution — the snap grid and merge tolerance track the on-screen scale, so you can draw arbitrarily fine detail just by zooming in. Toggle grid snap; live coordinate readout with precision matched to the grid.
  • Edit any sketch by dragging its points — reopen a sketch and use the Move tool to drag vertices, arc midpoints, circle centers, and circle rims. Coincident corners move together so loops stay closed. Full undo (per-move).

Modeling features

  • Extrude (new body / add / cut / intersect · up / both / down)
  • Revolve (around a base axis, a picked model edge, or a sketch line)
  • Fillet and Chamfer (all edges, or specific picked edges)
  • Shell (uniform, or removing picked faces)
  • Hole — click a face to place; through-all or blind; optional counterbore
  • Mirror (about XY / XZ / YZ, optionally merged)
  • Linear pattern and Circular pattern (with an editable axis position)
  • Boolean (union / cut / intersect between bodies)
  • Datum planes — from a base + offset, or an arbitrary origin/normal; fully editable
  • Import a STEP file as a body and keep modeling on it

Selection & inspection (CAD-style)

  • Hover to pre-highlight the frontmost vertex / edge / face under the cursor — hidden geometry behind the shape is never picked.
  • Click to select and read out its measurement: vertex XYZ, edge length, face area.
  • Pick edges and faces as inputs to features (revolve axis, fillet edges, shell faces) by clicking them in 3D.

Feature tree

  • Live edit (changes preview as you type), reorder, suppress, delete, rename.
  • Error badges on features that fail to build, with the reason.
  • Multi-body model with a bodies panel: isolate, hide/show, recolor.

Interoperability

  • Import a CadQuery .py → reconstructed, editable feature tree (AST-based; imports match their reference STLs to < 0.2 %).
  • View STEP / STL files (read-only display).
  • Export the model as CadQuery .py, STEP, or STL.
  • Code panel — see the generated CadQuery live, edit it, and run it back into the model.
  • Drag-and-drop a .py, .stl, or .step/.stp file anywhere onto the app to load it.

Viewport

  • Orbit / pan / zoom, fit, standard views, and an Onshape-style navigation cube.
  • Display modes: shaded / shaded-with-edges / wireframe.
  • Section view (clip along X / Y / Z), measure tool, grid & axes toggles.
  • Light / dark theme, undo / redo.

Quick start

Studio CAD needs Python 3.10+ and CadQuery. CadQuery ships compiled OCCT binaries; conda is the most reliable way to install it, but pip works on most platforms too.

Option A — conda (recommended)

conda env create -f environment.yml     # creates the "studio-cad" env
conda activate studio-cad
./run.sh                                 # → http://localhost:5001

Option B — pip / venv

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt          # cadquery, flask, flask-cors, numpy
python server.py                         # → http://localhost:5001

run.sh will create and populate a venv/ automatically if no environment is active.

Option C — Docker

docker build -t studio-cad .
docker run --rm -p 5001:5001 studio-cad  # → http://localhost:5001

Then open http://localhost:5001. Change the port with PORT=8080 python server.py.

First run: the model starts empty. Click Sketch to begin, drag one of the files from examples/ onto the window, or open one of the machine-generated samples/.


Using the app

Draw your first part

  1. Click Sketch in the toolbar, then click a base plane (or a model face).
  2. Draw a closed loop with the sketch tools, then Finish.
  3. Click Extrude, set a distance, OK. You have a body.
  4. Add Fillet / Hole / Pattern / … — each opens a small panel; pick edges or faces by clicking them in 3D; the result previews live.

Edit anything

  • Double-click a feature in the tree to edit it (a sketch reopens in Move mode so you can drag points).
  • Right-click a feature for reorder / suppress / delete / sketch-on-plane.
  • Drag the tree to reorder; the model rebuilds incrementally.

Inspect

  • With no command active, hover the model — the frontmost edge / face / vertex highlights.
  • Click it to read its length / area / coordinates (bottom-left).

Import / export

  • Import CadQuery .py (toolbar or drag-drop) → editable feature tree.
  • Export .py / STEP / STL from the toolbar.
  • Code panel (terminal icon) — edit the generated script and Run it back.

Keyboard

Key Action
F Fit view
M Measure
Esc Cancel the current command / sketch
Enter Confirm the open feature panel
Ctrl/Cmd + Z / Shift+Z Undo / Redo
Delete Delete the selected feature/body

The CadQuery script format

Studio imports the subset of CadQuery it can reconstruct into features. Scripts look like this (see examples/):

import cadquery as cq

# a plane (optional — cq.Workplane("XY") also works)
plane_1 = cq.Plane(origin=(0, 0, 0), normal=(0, 1, 0), xDir=(1, 0, 0))

# a sketch = a Workplane + one or more closed loops
sketch_1 = cq.Workplane(plane_1)
loop_1 = sketch_1.moveTo(6, -8).lineTo(22, -8).threePointArc((24, 0), (22, 8)).lineTo(6, 8).close()
sketch_1 = sketch_1.add(loop_1)

# a solid = the sketch extruded or revolved
solid_1 = sketch_1.revolve(360, (0, 0, 0), (0, 0, 1))

# multiple bodies are a display compound
result = solid_1

Recognised grammar: cq.Plane(origin=, normal=, xDir=) → a datum plane; cq.Workplane(plane | "XY"|"XZ"|"YZ") → a sketch; loop segments .moveTo / .lineTo / .threePointArc / .circle / .close; multi-loop profiles combined with .add(...); .extrude(dist) and .revolve(angle, start, end); result = solid_1; result = result.add(solid_2) as the display compound.

Features created in the UI that have no single CadQuery constructor (fillet on picked edges, holes, booleans, patterns) still export faithfully — the generated script reproduces them exactly, including a small selector helper for point-picked edges/faces. They just can't be re-imported as individual features from an arbitrary script (they come back as one run body); the feature tree is the source of truth for those.


Examples

Complex, multi-step assemblies — each imports into a fully editable feature tree of several bodies built across multiple sketches, planes and revolves. Drag any onto the app or import from the toolbar, then double-click a feature to change it and watch the model rebuild.

File Bodies Built from
examples/01_chair.py 6 Four legs, a seat on a raised datum plane, and a backrest.
examples/02_house.py 5 Walls, a gable roof (triangle → prism on the end plane), a chimney, a door and a window.
examples/03_rocket.py 7 A flared tail, body tube and nose cone (three revolves) plus four fins (extruded triangles).
examples/04_snowman.py 8 Three revolved spheres, a carrot nose, a top hat (brim + crown) and two stick arms.
examples/05_chess_set.py 16 A back row of eight pieces with a pawn in front of each - every piece an extruded silhouette.

samples/ holds larger, machine-generated CadQuery models (from a mesh→CAD fitter) that exercise the importer with dozens of arc-heavy loops and many bodies.


Architecture

cadkernel/
  kernel.py       Document: feature list, incremental rebuild, body tracking,
                  transactional add/edit/delete/reorder, scene deltas
  tessellate.py   triangulation (correct angular deflection), STL/STEP export,
                  STEP/STL import, per-face triangle groups & edge extraction
  codegen.py      feature list  ->  CadQuery .py  (faithful, incl. picked geometry)
  cqimport.py     CadQuery .py  ->  feature list  (AST parser)
server.py         Flask REST API — thin, delta-aware, single in-memory Document
static/
  index.html
  css/style.css
  js/viewport.js  Three.js scene, picking/hover, section, nav cube, inspect
  js/sketch3d.js  in-viewport sketcher + point-editing (Move tool)
  js/pm.js        PropertyManager (feature panels, live preview)
  js/app.js       controller: tree, bodies, import/export, drag-drop, shortcuts
  js/sketcher.js  2D sketch helpers

Incremental rebuild. Features form a linear history; each gets a cumulative fingerprint fp[i] = hash(feature[i], fp[i-1]). On an edit, the longest unchanged prefix is found and only the features after it recompute — the prefix is reused from a cheap reference snapshot (CadQuery's API is functional, so prior solids are never mutated and can be shared, not copied).

Mesh cache + delta transfer. A body whose solid didn't change keeps the same tessellation. The browser sends the content-hashes of the bodies it already holds; the server returns triangle data only for bodies whose hash changed. An edit ships a delta, not the whole model.

Stable IDs & transactional edits. Every feature has an id; references (sketch→plane, extrude→sketch, fillet→body) use ids. Edits are transactional — a failed rebuild leaves the previous good state intact, and per-feature try/except isolates a broken feature so the rest of the model still shows.

Geometry selection without persistent naming. Picked edges/faces are stored as 3-D points; on each rebuild the nearest sub-shape is resolved (OCCT BRepExtrema distance), sidestepping the topological naming problem. Codegen emits the same nearest-point selection so exported scripts reproduce the pick.


REST API

All state lives in a single in-memory Document. Endpoints are delta-aware: send known (a map of body_id → content_hash) and the response only includes meshes for bodies that changed.

Method & path Purpose
GET / The app.
POST /api/scene Current scene (delta vs known).
POST /api/preview Non-committing preview of an add/edit (for live panels).
GET /api/features The feature list.
POST /api/feature Add a feature {type, params}.
PATCH /api/feature/<id> Edit a feature's params (or rename).
DELETE /api/feature/<id> Delete a feature.
POST /api/feature/<id>/move Reorder to index {to}.
POST /api/undo · POST /api/redo · POST /api/reset History.
POST /api/import/script CadQuery .py → features.
GET /api/code Generated CadQuery for the current model.
POST /api/run_code Parse/run edited code back into the model.
POST /api/face_at 3-D point → the plane of the face there (sketch-on-face).
POST /api/import/solid STEP (base64) → a body.
POST /api/view_file Load a STEP/STL for read-only display.
GET /api/export/stl · /api/export/step · /api/export/script Download.

Example — add an extrude and get back just the changed body:

curl -s localhost:5001/api/feature -H 'Content-Type: application/json' -d '{
  "feature": {"type": "extrude", "params": {"sketch": "<sketch_id>", "distance": 8}},
  "known": {}
}'

Performance

  • Edit latency is dominated by the changed features only. Editing the last feature of an 8-body model rebuilds in ~10 ms and ships one body's triangles.
  • Meshing uses a fixed angular deflection (independent of the linear tolerance) so curved and revolved faces stay smooth without exploding the triangle count.
  • The server keeps one Document in memory; it is single-user by design (a modeling session), not a multi-tenant service. Run one instance per session.

Project layout

studio-cad/
├── server.py            # Flask app / REST API
├── cadkernel/           # geometry kernel (see Architecture)
├── static/              # front-end (no build step — plain ES modules + Three.js r128)
├── examples/            # hand-written CadQuery starter scripts
├── samples/             # larger machine-generated models
├── requirements.txt     # pip deps
├── environment.yml      # conda env (reliable CadQuery)
├── Dockerfile           # container image
└── run.sh               # dev launcher

There is no front-end build step — static/ is served as-is (Three.js loads from a CDN), so you can edit the JS and hard-reload.


License

Released under the MIT License — see LICENSE.

Built on CadQuery (Apache-2.0) and Three.js (MIT).

About

An AI-native parametric CAD environment for the web

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages