img2cad 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. img2cad-0.12.0/LICENSE +21 -0
  2. img2cad-0.12.0/PKG-INFO +209 -0
  3. img2cad-0.12.0/README.md +190 -0
  4. img2cad-0.12.0/VERSION +1 -0
  5. img2cad-0.12.0/img2cad.egg-info/PKG-INFO +209 -0
  6. img2cad-0.12.0/img2cad.egg-info/SOURCES.txt +63 -0
  7. img2cad-0.12.0/img2cad.egg-info/dependency_links.txt +1 -0
  8. img2cad-0.12.0/img2cad.egg-info/entry_points.txt +2 -0
  9. img2cad-0.12.0/img2cad.egg-info/requires.txt +4 -0
  10. img2cad-0.12.0/img2cad.egg-info/top_level.txt +1 -0
  11. img2cad-0.12.0/pyproject.toml +40 -0
  12. img2cad-0.12.0/scripts/__init__.py +1 -0
  13. img2cad-0.12.0/scripts/agent_cad_worker.py +234 -0
  14. img2cad-0.12.0/scripts/agent_workflow.py +818 -0
  15. img2cad-0.12.0/scripts/build_site.py +149 -0
  16. img2cad-0.12.0/scripts/cad_worker.py +120 -0
  17. img2cad-0.12.0/scripts/camera_fit.py +428 -0
  18. img2cad-0.12.0/scripts/cli_args.py +36 -0
  19. img2cad-0.12.0/scripts/drawing.py +225 -0
  20. img2cad-0.12.0/scripts/generate_cad.py +113 -0
  21. img2cad-0.12.0/scripts/img2cad_cli.py +126 -0
  22. img2cad-0.12.0/scripts/img2cad_lib.py +264 -0
  23. img2cad-0.12.0/scripts/inspect_step.py +176 -0
  24. img2cad-0.12.0/scripts/make_mask.py +114 -0
  25. img2cad-0.12.0/scripts/mcp_server.py +191 -0
  26. img2cad-0.12.0/scripts/mesh_export.py +117 -0
  27. img2cad-0.12.0/scripts/model_params.py +147 -0
  28. img2cad-0.12.0/scripts/pipeline_state.py +459 -0
  29. img2cad-0.12.0/scripts/prepare_spec.py +62 -0
  30. img2cad-0.12.0/scripts/printcheck.py +235 -0
  31. img2cad-0.12.0/scripts/record_visual_review.py +144 -0
  32. img2cad-0.12.0/scripts/run_agent_cad.py +491 -0
  33. img2cad-0.12.0/scripts/run_pipeline.py +215 -0
  34. img2cad-0.12.0/scripts/silhouette.py +212 -0
  35. img2cad-0.12.0/scripts/spec_contract.py +154 -0
  36. img2cad-0.12.0/scripts/trace_regions.py +184 -0
  37. img2cad-0.12.0/scripts/validate_benchmark.py +273 -0
  38. img2cad-0.12.0/scripts/vendor/three/LICENSE +21 -0
  39. img2cad-0.12.0/scripts/vendor/three/README.md +1 -0
  40. img2cad-0.12.0/scripts/vendor/three/build/three.module.min.js +6 -0
  41. img2cad-0.12.0/scripts/vendor/three/examples/jsm/controls/OrbitControls.js +1417 -0
  42. img2cad-0.12.0/scripts/vendor/three/examples/jsm/libs/fflate.module.js +2474 -0
  43. img2cad-0.12.0/scripts/vendor/three/examples/jsm/loaders/3MFLoader.js +1478 -0
  44. img2cad-0.12.0/scripts/vendor/three/examples/jsm/loaders/GLTFLoader.js +4663 -0
  45. img2cad-0.12.0/scripts/vendor/three/examples/jsm/loaders/STLLoader.js +410 -0
  46. img2cad-0.12.0/scripts/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1375 -0
  47. img2cad-0.12.0/scripts/viewer.html +612 -0
  48. img2cad-0.12.0/scripts/viewer.py +297 -0
  49. img2cad-0.12.0/scripts/vision_adapter.py +137 -0
  50. img2cad-0.12.0/scripts/visual_hull.py +107 -0
  51. img2cad-0.12.0/setup.cfg +4 -0
  52. img2cad-0.12.0/tests/test_acceptance_profiles.py +126 -0
  53. img2cad-0.12.0/tests/test_agent_workflow.py +360 -0
  54. img2cad-0.12.0/tests/test_camera_mask.py +102 -0
  55. img2cad-0.12.0/tests/test_cli.py +53 -0
  56. img2cad-0.12.0/tests/test_cli_args.py +32 -0
  57. img2cad-0.12.0/tests/test_distribution.py +153 -0
  58. img2cad-0.12.0/tests/test_examples.py +196 -0
  59. img2cad-0.12.0/tests/test_model_params.py +93 -0
  60. img2cad-0.12.0/tests/test_model_source_policy.py +91 -0
  61. img2cad-0.12.0/tests/test_object2cad_spec.py +72 -0
  62. img2cad-0.12.0/tests/test_silhouette.py +107 -0
  63. img2cad-0.12.0/tests/test_trace_regions.py +67 -0
  64. img2cad-0.12.0/tests/test_visual_hull.py +48 -0
  65. img2cad-0.12.0/tests/test_visual_review.py +106 -0
img2cad-0.12.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YUI-TIEN
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: img2cad
3
+ Version: 0.12.0
4
+ Summary: Turn images, sketches and drawings into editable, coloured CAD (STEP/GLB/STL/3MF) with an agent workflow.
5
+ Author: YUI-TIEN
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://yui-tien.github.io/img2cad/
8
+ Project-URL: Repository, https://github.com/YUI-TIEN/img2cad
9
+ Project-URL: Issues, https://github.com/YUI-TIEN/img2cad/issues
10
+ Keywords: cad,image-to-cad,build123d,step,agents
11
+ Requires-Python: <3.14,>=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: build123d==0.13.0
15
+ Requires-Dist: numpy>=1.26
16
+ Requires-Dist: scipy>=1.11
17
+ Requires-Dist: pillow>=10
18
+ Dynamic: license-file
19
+
20
+ # img2cad
21
+
22
+ An image-to-parametric-CAD workflow: turn a product image, sketch, or engineering drawing into a reviewable CAD specification, an editable solid model, and validated exchange files such as STEP.
23
+
24
+ > **Status:** early workflow prototype. The repository has an agent skill, a local runner for reviewed agent-authored build123d source, generic STEP inspection and preview generation, plus a constrained spec-to-CAD benchmark runner. The agent still performs image interpretation, model authoring, preview review, and refinement; the local runner handles CAD execution and artifact checks.
25
+
26
+ **Website:** <https://yui-tien.github.io/img2cad/> — how the pipeline works, with interactive 3D examples.
27
+
28
+ ## Quick start
29
+
30
+ img2cad is a set of agent skills plus one command-line tool, `img2cad`. Install it in your agent, then give the agent an image and ask for CAD.
31
+
32
+ | Host | Install |
33
+ |---|---|
34
+ | Claude Code | `/plugin marketplace add YUI-TIEN/img2cad` then `/plugin install img2cad@img2cad` |
35
+ | Codex, Cursor | add this repository as a plugin (`.codex-plugin/`, `.cursor-plugin/`) |
36
+ | Gemini CLI | `gemini extensions install https://github.com/YUI-TIEN/img2cad` |
37
+ | Any agent with skills | `npx skills add YUI-TIEN/img2cad` |
38
+ | Any MCP host | server command `uvx --python 3.13 --from git+https://github.com/YUI-TIEN/img2cad img2cad mcp` |
39
+
40
+ The command line works without a clone (needs [uv](https://docs.astral.sh/uv/)):
41
+
42
+ ```sh
43
+ uvx --python 3.13 --from git+https://github.com/YUI-TIEN/img2cad img2cad doctor # check the CAD stack
44
+ uv tool install --python 3.13 git+https://github.com/YUI-TIEN/img2cad # or put `img2cad` on PATH
45
+ pip install img2cad # once released to PyPI
46
+ ```
47
+
48
+ From a clone, use `.venv-cad/bin/python scripts/img2cad_cli.py` in place of `img2cad`:
49
+
50
+ ```sh
51
+ python3 -m venv .venv-cad && .venv-cad/bin/pip install -r requirements-cad.lock
52
+ .venv-cad/bin/python scripts/img2cad_cli.py doctor
53
+ ```
54
+
55
+ | Command | What it does |
56
+ |---|---|
57
+ | `img2cad workflow ...` | staged, resumable image → CAD workflow (init, observations, plan, preview, source-review, run, review, new-revision, promote, status) |
58
+ | `img2cad build model.py out/` | build one `model.py`: STEP + GLB/STL/3MF, checks, previews, comparison, registered overlay |
59
+ | `img2cad trace image.png ...` | trace colour regions of a reference image into pixel outlines |
60
+ | `img2cad inspect model.step` | measure a STEP: validity, solids, parts and colours, bounds, volume, holes/bosses |
61
+ | `img2cad view model.py` | 3D viewer with a live parameter panel (drag, type, rebuild locally, save back); also opens STEP/GLB/STL/3MF |
62
+ | `img2cad params model.py` | list or set a model's parameters (module-level UPPERCASE numbers) |
63
+ | `img2cad camera camera.json` | fit the photo's camera to known circles/points; refuses poor or under-constrained fits |
64
+ | `img2cad mask photo.png mask.png` | subject mask from polygons, ellipses, colour seeds |
65
+ | `img2cad export model.step out/` | GLB (coloured), 3MF (coloured parts), STL |
66
+ | `img2cad drawing model.step out/` | three-view SVG/DXF drawing with overall dimensions and a hole table |
67
+ | `img2cad printcheck model.step` | watertight, overhangs, bed contact, thin walls, build volume |
68
+ | `img2cad mcp` | the same tools over MCP (stdio) |
69
+ | `img2cad doctor` / `version` | environment check / version |
70
+
71
+ **Outputs of every run:** `model.py` (the editable source of truth), `model.step` (B-rep with part names and colours), `model.glb`, `model.3mf`, `model.stl`, `preview.png`, `comparison.png`, `silhouette.png`, `registered.png` (when the model registers the image), `inspection.json` and `run_report.json`.
72
+
73
+ ## Problem
74
+
75
+ Image-to-3D tools can create visually convincing 3D models, while CAD tools can create editable solids from code. img2cad's intended workflow is for an agent to inspect the image, plan the geometry, author a parametric CAD model, and compare a render with the reference. The difficult gap is making that model both visually faithful and a valid, editable CAD artifact—not choosing a particular vision API.
76
+
77
+ A single image cannot reveal hidden geometry or true scale. The workflow must expose uncertainty and distinguish an approximate visual model from dimensionally constrained engineering CAD.
78
+
79
+ ## Product goal
80
+
81
+ Given one or more images and optional dimensions, the agent should help a user produce:
82
+
83
+ 1. A structured, inspectable description of the part or assembly.
84
+ 2. A native parametric model that can be edited and regenerated.
85
+ 3. A valid STEP export, plus preview formats when useful.
86
+ 4. Evidence of geometric checks and a visual comparison against the reference.
87
+
88
+ The primary success criterion is a useful CAD artifact whose fidelity and editability are reported honestly. A visually similar organic model and a dimensionally constrained engineering part are both valid targets, but they have different acceptance criteria.
89
+
90
+ ## Proposed workflow
91
+
92
+ ```text
93
+ Image(s) + optional measurements
94
+ → agent inspects image using its already-available visual capability
95
+ → observations, geometry plan, confidence / unknowns
96
+ → agent authors an editable build123d CAD model
97
+ → local CAD kernel builds, measures, and exports STEP / preview
98
+ → compare preview with reference and revise the model
99
+ → report estimates, checks, and remaining limitations
100
+ ```
101
+
102
+ No separate third-party vision service or API key is required by this workflow. The optional vision adapter is a separate integration for users who explicitly choose provider-backed inference; it is not the default agent path.
103
+
104
+ ### 1. Assess the input
105
+
106
+ Classify the input as a product photo, sketch, or dimensioned drawing. Identify view count, occlusion, perspective, visible scale cues, and whether the target is primarily prismatic/mechanical or organic. If the image is unsuitable or confidence is low, request another view or route the task to manual input.
107
+
108
+ ### 2. Plan the geometry and record an `Object2CADSpec`
109
+
110
+ Create a versioned JSON specification before generating geometry. It should record:
111
+
112
+ - Components and assembly relationships.
113
+ - Candidate features (for example, base extrusion, hole pattern, revolve, pocket, rib).
114
+ - Coordinate frame, units, datums, and dimensional constraints.
115
+ - Observed evidence and source view for each feature.
116
+ - Confidence, assumptions, and unresolved questions per feature/dimension.
117
+ - Manufacturing intent when known (3D print, CNC, sheet metal, or visual prototype).
118
+
119
+ Keep observed facts separate from inferred geometry. For a visual prototype, proceed with clearly labeled estimates rather than blocking on engineering dimensions. Ask only when a missing fact materially changes the requested result. The current v1 schema is limited to one rectangular prism and holes; it is a benchmark fixture, not yet a general geometry plan for organic shapes or assemblies.
120
+
121
+ ### 3. Generate native CAD
122
+
123
+ The intended agent path is to author ordinary, parameterized build123d code using Open CASCADE from the image observations and geometry plan. Preserve meaningful parameters and feature-level structure so the model can be edited and regenerated. Organic forms may need lofts, sweeps, or carefully joined solids; a mesh-only result is not equivalent to an editable CAD model. STEP is the primary interchange output; STL/GLB are derived previews, not the source of truth.
124
+
125
+ ### 4. Validate geometry
126
+
127
+ Before claiming success, check that the model builds, contains valid positive-volume solids where expected, satisfies any explicit dimensions and constraints, and can be exported and re-imported from STEP. For an approximate visual model, report estimated scale and visual fidelity separately from dimensional validation. Add manufacturability checks only for the chosen process; a successful export alone does not establish engineering correctness.
128
+
129
+ ### 5. Review and refine
130
+
131
+ Render the generated CAD from the input camera/view where possible and from a small set of diagnostic views. Compare silhouette, proportions, component placement, and specified feature locations using the agent's already-available image capability; this does not imply adding a vision service. Use deterministic checks for measurable geometry. Every correction should identify whether it changes the spec, the code, or an assumption.
132
+
133
+ ## Design principles
134
+
135
+ - **CAD-first:** the editable parametric solid is canonical; meshes and renders are derived.
136
+ - **Evidence-aware:** every inferred feature has a confidence and an evidence source.
137
+ - **Human-confirmed constraints:** do not invent scale or hidden dimensions and label them as facts.
138
+ - **Progressive automation:** support visual organic models and constrained mechanical parts with the right fidelity/measurement criteria for each; route genuinely ambiguous requirements to a question or documented best-effort result.
139
+ - **Reviewable loop:** retain input, spec, generated source, validation results, and revision history together.
140
+ - **Controlled execution:** review model source before running it. Agent-authored model source is ordinary Python with the full build123d API, run in an isolated subprocess with a timeout; it is **not sandboxed**, so only execute source you have inspected. An optional `--strict-source` allowlist check exists for source you did not write.
141
+
142
+ ## MVP scope
143
+
144
+ Start with the agent-led loop: inspect a user image, plan geometry, author a build123d model, run local checks, inspect a preview, and make a bounded correction. Include both a visual-model case (the frozen synthetic dog illustration) and a dimensioned mechanical case, with different acceptance criteria. Defer guaranteed hidden-surface reconstruction and claims of production readiness without process-specific engineering checks.
145
+
146
+ ## Relationship to existing projects
147
+
148
+ The original concept combines **img2threejs**' staged image inspection and render/revise loop with **txt2cad**'s CAD modeling/output direction. The exact upstream repository identity of `txt2cad` has not been verified; do not equate it with a similarly named GitHub repository. These are conceptual inputs, not claims that this repository imports their code or reproduces their implementation.
149
+
150
+ The proposed contribution is the agent workflow that bridges image evidence → geometry plan / uncertainty-bearing spec → agent-authored native parametric model → geometry and visual review. Requiring a pre-filled spec and a fixed shape generator is useful for a deterministic fixture, but is not the intended general image-to-CAD interaction.
151
+
152
+ ## Initial acceptance criteria
153
+
154
+ For a supported test part with a reference image and known key dimensions:
155
+
156
+ - The workflow produces a spec that distinguishes observed, inferred, and user-confirmed values.
157
+ - The generated build123d model executes and exports a STEP file that can be re-imported.
158
+ - Explicit dimensions and feature counts pass geometric checks.
159
+ - A reviewer can inspect and edit model parameters without editing a triangle mesh.
160
+ - The review screen shows the reference, generated preview, validation results, and remaining assumptions.
161
+ - Unsupported or ambiguous input is reported as such rather than marked as a successful engineering reconstruction.
162
+
163
+ ## Suggested first prototype
164
+
165
+ Use the frozen synthetic dog illustration in `benchmark/cases/visual-pose-dog` as an initial visual-model acceptance case: inspect the image, document observed/inferred/unknown geometry, author an editable approximation, export and check it locally, inspect the preview, and record a separate finding for each visual criterion. It is an illustration fixture, not evidence of performance on real photographs. Keep `benchmark/cases/repro-block` as the separate dimensioned mechanical case for exact constraints and STEP round-trip behavior. Neither case requires adding a third-party vision API solely to follow the workflow.
166
+
167
+ ## Repeatable validation
168
+
169
+ The benchmark format and local validation commands are defined in [`benchmark/README.md`](benchmark/README.md). Two frozen fixtures separate visual approximation (`benchmark/cases/visual-pose-dog`) from dimension-constrained CAD (`benchmark/cases/repro-block`). The validator checks case/run metadata, input and artifact hashes, per-case gates, criterion-level visual review, and dimension tolerances across repeat runs. It is a reproducibility scaffold—not a CAD kernel or an independent visual judge; geometry and STEP round-trip checks must be performed by the CAD runner, and visual criteria must be reviewed against the comparison image.
170
+
171
+ ## Agent workflow
172
+
173
+ The repository-owned agent procedure is [`skills/img2cad/SKILL.md`](skills/img2cad/SKILL.md), routed through [`AGENTS.md`](AGENTS.md). For the general path, use the resumable `scripts/agent_workflow.py` coordinator around `scripts/run_agent_cad.py` and `scripts/record_visual_review.py`. It records image evidence and plan, pins inspected model source, executes the local CAD/STEP gate, and binds review to that run's hashes. An optional manual camera direction can replace the generic isometric preview; it is not automatic photo alignment. `run_report.json` records **geometry/STEP success only**, never visual fidelity. The review record preserves the declared reviewer and notes but cannot independently prove a human inspected or accepted the image. The separate `scripts/run_pipeline.py` remains a constrained benchmark path requiring a pre-authored spec; its generator only creates a rectangular prism with optional through-holes. The optional vision adapter is not required for an agent that already has image input capability.
174
+
175
+ ### Resumable general workflow CLI
176
+
177
+ Use `img2cad workflow` (`scripts/agent_workflow.py`) for the ordinary image-led path. It stores a local `workflow.json`, pins the reference image, records stage input/output hashes and a `next_step` for each stage, and reports the next action on `status`. Each workflow directory is new; revisions are append-only, with the earlier CAD run retained. This state machine coordinates the agent's judgments—it does not infer observations, inspect visual quality, or turn an agent review into human acceptance.
178
+
179
+ ```sh
180
+ img2cad workflow init /path/to/work --reference /path/to/image.png --target-type visual_approximation
181
+ img2cad workflow status /path/to/work
182
+ img2cad workflow observations /path/to/work --file /path/to/observations.json
183
+ img2cad workflow plan /path/to/work --file /path/to/plan.json
184
+ img2cad workflow preview /path/to/work --model /path/to/draft.py # iterate freely; no stage changes
185
+ img2cad workflow source-review /path/to/work --model /path/to/model.py \
186
+ --inspection-note "Checked the source against the plan; only intended build123d geometry is created."
187
+ img2cad workflow run /path/to/work
188
+ img2cad workflow review /path/to/work --notes /path/to/review.json
189
+ img2cad workflow promote /path/to/work --name short-slug --technique "what it demonstrates"
190
+ ```
191
+
192
+ `run` uses `--cad-python`, else `$IMG2CAD_CAD_PYTHON`, else the clone's `.venv-cad/bin/python`, else the interpreter running `img2cad`.
193
+
194
+ ### Learning material for agents
195
+
196
+ - [`skills/img2cad/MODELING.md`](skills/img2cad/MODELING.md): the allowed build123d API, plane orientation, technique-by-object-type table, how to read sizes from images, and the declarable checks.
197
+ - [`examples/`](examples/README.md): accepted end-to-end runs (dimensioned plate, revolved bushing, revolved and shelled vase, lofted fish with a revise round, jointed standing horse, tiered pagoda), each with reference, observations, plan, model, comparison, silhouette overlay, review, and a short write-up.
198
+ - [`skills/img2cad/LESSONS.md`](skills/img2cad/LESSONS.md): verified pitfalls from real runs.
199
+ - [`skills/cad-output/SKILL.md`](skills/cad-output/SKILL.md): viewing, mesh export, engineering drawings, and printability checks for a finished model.
200
+ - Precision tools:
201
+ - `scripts/trace_regions.py` traces colour regions of the photo into pixel outlines.
202
+ - `scripts/img2cad_lib.py`, importable from `model.py`, provides `ImageFrame` registration, `projected_decal` for exact painted details on curved surfaces, and helpers for revolves, limbs, and joints.
203
+ - With `IMAGE_FRAME` set, runs draw the CAD on the photo (`registered.png`) and score each colour region against it.
204
+
205
+ `promote` copies an accepted workflow into `examples/` so later agents can reuse it; new pitfalls go into `LESSONS.md`. This is how the repository accumulates experience across runs; agents do not otherwise remember earlier sessions.
206
+
207
+ Observation JSON uses `observed`, `inferred`, `unknowns` string arrays and `evidence` objects with `claim` and `source`. Plan JSON includes `target_type` (`visual_approximation` or `dimension_constrained`), `goal`, nonempty `geometry_plan`, `constraints`, and `unknowns`. For dimension-constrained plans, `constraints` can declare overall bounds (`length`/`width`/`height` or `x`/`y`/`z`, optional `tolerance`, default 0.02 model units), `volume` (explicit absolute tolerance), and `hole`/`boss` diameter and count; the workflow compares them with the STEP inspection. Feature positions are not checked and remain review criteria. The geometry gate requires each part to be one solid (a single fused body, or each part of a coloured `Compound(children=[...])` assembly, whose part colours and names are kept in the STEP) unless the plan sets `"allow_multiple_solids": true`. `run` and `preview` also write an advisory silhouette comparison (`silhouette.png` and a best-view IoU, with a `reliable` flag that is false when the image's background could not be separated); for real photos pass a traced `--reference-mask`. It helps spot proportion errors but is never a gate. Review JSON follows `scripts/record_visual_review.py`: reviewer, verdict (`acceptable`, `revise`, or `blocked`), compared views, matches, mismatches, next_changes, and assumptions. `revise` must name mismatches and geometry/parameter changes; `blocked` must identify missing evidence in `next_changes`.
208
+
209
+ The CLI refuses to run CAD before source review, refuses visual review unless geometry/STEP and (for dimension-constrained work) declared bounding-dimension gates pass, checks source/reference/artifact hashes, and stores the exact reviewer/verdict separately from geometry status. After `revise` or `blocked` (or a failed geometry/dimension run), start a fresh revision with `new-revision --reason ...`; it preserves the prior run and inherits observations/plan. If new evidence or a changed plan is needed, record it into the new revision; source, geometry, dimensions, and visual-review gates reset. Do not reuse a previous preview's review for the new source. `human_acceptance` remains `not_verified` even when the agent review is acceptable.
@@ -0,0 +1,190 @@
1
+ # img2cad
2
+
3
+ An image-to-parametric-CAD workflow: turn a product image, sketch, or engineering drawing into a reviewable CAD specification, an editable solid model, and validated exchange files such as STEP.
4
+
5
+ > **Status:** early workflow prototype. The repository has an agent skill, a local runner for reviewed agent-authored build123d source, generic STEP inspection and preview generation, plus a constrained spec-to-CAD benchmark runner. The agent still performs image interpretation, model authoring, preview review, and refinement; the local runner handles CAD execution and artifact checks.
6
+
7
+ **Website:** <https://yui-tien.github.io/img2cad/> — how the pipeline works, with interactive 3D examples.
8
+
9
+ ## Quick start
10
+
11
+ img2cad is a set of agent skills plus one command-line tool, `img2cad`. Install it in your agent, then give the agent an image and ask for CAD.
12
+
13
+ | Host | Install |
14
+ |---|---|
15
+ | Claude Code | `/plugin marketplace add YUI-TIEN/img2cad` then `/plugin install img2cad@img2cad` |
16
+ | Codex, Cursor | add this repository as a plugin (`.codex-plugin/`, `.cursor-plugin/`) |
17
+ | Gemini CLI | `gemini extensions install https://github.com/YUI-TIEN/img2cad` |
18
+ | Any agent with skills | `npx skills add YUI-TIEN/img2cad` |
19
+ | Any MCP host | server command `uvx --python 3.13 --from git+https://github.com/YUI-TIEN/img2cad img2cad mcp` |
20
+
21
+ The command line works without a clone (needs [uv](https://docs.astral.sh/uv/)):
22
+
23
+ ```sh
24
+ uvx --python 3.13 --from git+https://github.com/YUI-TIEN/img2cad img2cad doctor # check the CAD stack
25
+ uv tool install --python 3.13 git+https://github.com/YUI-TIEN/img2cad # or put `img2cad` on PATH
26
+ pip install img2cad # once released to PyPI
27
+ ```
28
+
29
+ From a clone, use `.venv-cad/bin/python scripts/img2cad_cli.py` in place of `img2cad`:
30
+
31
+ ```sh
32
+ python3 -m venv .venv-cad && .venv-cad/bin/pip install -r requirements-cad.lock
33
+ .venv-cad/bin/python scripts/img2cad_cli.py doctor
34
+ ```
35
+
36
+ | Command | What it does |
37
+ |---|---|
38
+ | `img2cad workflow ...` | staged, resumable image → CAD workflow (init, observations, plan, preview, source-review, run, review, new-revision, promote, status) |
39
+ | `img2cad build model.py out/` | build one `model.py`: STEP + GLB/STL/3MF, checks, previews, comparison, registered overlay |
40
+ | `img2cad trace image.png ...` | trace colour regions of a reference image into pixel outlines |
41
+ | `img2cad inspect model.step` | measure a STEP: validity, solids, parts and colours, bounds, volume, holes/bosses |
42
+ | `img2cad view model.py` | 3D viewer with a live parameter panel (drag, type, rebuild locally, save back); also opens STEP/GLB/STL/3MF |
43
+ | `img2cad params model.py` | list or set a model's parameters (module-level UPPERCASE numbers) |
44
+ | `img2cad camera camera.json` | fit the photo's camera to known circles/points; refuses poor or under-constrained fits |
45
+ | `img2cad mask photo.png mask.png` | subject mask from polygons, ellipses, colour seeds |
46
+ | `img2cad export model.step out/` | GLB (coloured), 3MF (coloured parts), STL |
47
+ | `img2cad drawing model.step out/` | three-view SVG/DXF drawing with overall dimensions and a hole table |
48
+ | `img2cad printcheck model.step` | watertight, overhangs, bed contact, thin walls, build volume |
49
+ | `img2cad mcp` | the same tools over MCP (stdio) |
50
+ | `img2cad doctor` / `version` | environment check / version |
51
+
52
+ **Outputs of every run:** `model.py` (the editable source of truth), `model.step` (B-rep with part names and colours), `model.glb`, `model.3mf`, `model.stl`, `preview.png`, `comparison.png`, `silhouette.png`, `registered.png` (when the model registers the image), `inspection.json` and `run_report.json`.
53
+
54
+ ## Problem
55
+
56
+ Image-to-3D tools can create visually convincing 3D models, while CAD tools can create editable solids from code. img2cad's intended workflow is for an agent to inspect the image, plan the geometry, author a parametric CAD model, and compare a render with the reference. The difficult gap is making that model both visually faithful and a valid, editable CAD artifact—not choosing a particular vision API.
57
+
58
+ A single image cannot reveal hidden geometry or true scale. The workflow must expose uncertainty and distinguish an approximate visual model from dimensionally constrained engineering CAD.
59
+
60
+ ## Product goal
61
+
62
+ Given one or more images and optional dimensions, the agent should help a user produce:
63
+
64
+ 1. A structured, inspectable description of the part or assembly.
65
+ 2. A native parametric model that can be edited and regenerated.
66
+ 3. A valid STEP export, plus preview formats when useful.
67
+ 4. Evidence of geometric checks and a visual comparison against the reference.
68
+
69
+ The primary success criterion is a useful CAD artifact whose fidelity and editability are reported honestly. A visually similar organic model and a dimensionally constrained engineering part are both valid targets, but they have different acceptance criteria.
70
+
71
+ ## Proposed workflow
72
+
73
+ ```text
74
+ Image(s) + optional measurements
75
+ → agent inspects image using its already-available visual capability
76
+ → observations, geometry plan, confidence / unknowns
77
+ → agent authors an editable build123d CAD model
78
+ → local CAD kernel builds, measures, and exports STEP / preview
79
+ → compare preview with reference and revise the model
80
+ → report estimates, checks, and remaining limitations
81
+ ```
82
+
83
+ No separate third-party vision service or API key is required by this workflow. The optional vision adapter is a separate integration for users who explicitly choose provider-backed inference; it is not the default agent path.
84
+
85
+ ### 1. Assess the input
86
+
87
+ Classify the input as a product photo, sketch, or dimensioned drawing. Identify view count, occlusion, perspective, visible scale cues, and whether the target is primarily prismatic/mechanical or organic. If the image is unsuitable or confidence is low, request another view or route the task to manual input.
88
+
89
+ ### 2. Plan the geometry and record an `Object2CADSpec`
90
+
91
+ Create a versioned JSON specification before generating geometry. It should record:
92
+
93
+ - Components and assembly relationships.
94
+ - Candidate features (for example, base extrusion, hole pattern, revolve, pocket, rib).
95
+ - Coordinate frame, units, datums, and dimensional constraints.
96
+ - Observed evidence and source view for each feature.
97
+ - Confidence, assumptions, and unresolved questions per feature/dimension.
98
+ - Manufacturing intent when known (3D print, CNC, sheet metal, or visual prototype).
99
+
100
+ Keep observed facts separate from inferred geometry. For a visual prototype, proceed with clearly labeled estimates rather than blocking on engineering dimensions. Ask only when a missing fact materially changes the requested result. The current v1 schema is limited to one rectangular prism and holes; it is a benchmark fixture, not yet a general geometry plan for organic shapes or assemblies.
101
+
102
+ ### 3. Generate native CAD
103
+
104
+ The intended agent path is to author ordinary, parameterized build123d code using Open CASCADE from the image observations and geometry plan. Preserve meaningful parameters and feature-level structure so the model can be edited and regenerated. Organic forms may need lofts, sweeps, or carefully joined solids; a mesh-only result is not equivalent to an editable CAD model. STEP is the primary interchange output; STL/GLB are derived previews, not the source of truth.
105
+
106
+ ### 4. Validate geometry
107
+
108
+ Before claiming success, check that the model builds, contains valid positive-volume solids where expected, satisfies any explicit dimensions and constraints, and can be exported and re-imported from STEP. For an approximate visual model, report estimated scale and visual fidelity separately from dimensional validation. Add manufacturability checks only for the chosen process; a successful export alone does not establish engineering correctness.
109
+
110
+ ### 5. Review and refine
111
+
112
+ Render the generated CAD from the input camera/view where possible and from a small set of diagnostic views. Compare silhouette, proportions, component placement, and specified feature locations using the agent's already-available image capability; this does not imply adding a vision service. Use deterministic checks for measurable geometry. Every correction should identify whether it changes the spec, the code, or an assumption.
113
+
114
+ ## Design principles
115
+
116
+ - **CAD-first:** the editable parametric solid is canonical; meshes and renders are derived.
117
+ - **Evidence-aware:** every inferred feature has a confidence and an evidence source.
118
+ - **Human-confirmed constraints:** do not invent scale or hidden dimensions and label them as facts.
119
+ - **Progressive automation:** support visual organic models and constrained mechanical parts with the right fidelity/measurement criteria for each; route genuinely ambiguous requirements to a question or documented best-effort result.
120
+ - **Reviewable loop:** retain input, spec, generated source, validation results, and revision history together.
121
+ - **Controlled execution:** review model source before running it. Agent-authored model source is ordinary Python with the full build123d API, run in an isolated subprocess with a timeout; it is **not sandboxed**, so only execute source you have inspected. An optional `--strict-source` allowlist check exists for source you did not write.
122
+
123
+ ## MVP scope
124
+
125
+ Start with the agent-led loop: inspect a user image, plan geometry, author a build123d model, run local checks, inspect a preview, and make a bounded correction. Include both a visual-model case (the frozen synthetic dog illustration) and a dimensioned mechanical case, with different acceptance criteria. Defer guaranteed hidden-surface reconstruction and claims of production readiness without process-specific engineering checks.
126
+
127
+ ## Relationship to existing projects
128
+
129
+ The original concept combines **img2threejs**' staged image inspection and render/revise loop with **txt2cad**'s CAD modeling/output direction. The exact upstream repository identity of `txt2cad` has not been verified; do not equate it with a similarly named GitHub repository. These are conceptual inputs, not claims that this repository imports their code or reproduces their implementation.
130
+
131
+ The proposed contribution is the agent workflow that bridges image evidence → geometry plan / uncertainty-bearing spec → agent-authored native parametric model → geometry and visual review. Requiring a pre-filled spec and a fixed shape generator is useful for a deterministic fixture, but is not the intended general image-to-CAD interaction.
132
+
133
+ ## Initial acceptance criteria
134
+
135
+ For a supported test part with a reference image and known key dimensions:
136
+
137
+ - The workflow produces a spec that distinguishes observed, inferred, and user-confirmed values.
138
+ - The generated build123d model executes and exports a STEP file that can be re-imported.
139
+ - Explicit dimensions and feature counts pass geometric checks.
140
+ - A reviewer can inspect and edit model parameters without editing a triangle mesh.
141
+ - The review screen shows the reference, generated preview, validation results, and remaining assumptions.
142
+ - Unsupported or ambiguous input is reported as such rather than marked as a successful engineering reconstruction.
143
+
144
+ ## Suggested first prototype
145
+
146
+ Use the frozen synthetic dog illustration in `benchmark/cases/visual-pose-dog` as an initial visual-model acceptance case: inspect the image, document observed/inferred/unknown geometry, author an editable approximation, export and check it locally, inspect the preview, and record a separate finding for each visual criterion. It is an illustration fixture, not evidence of performance on real photographs. Keep `benchmark/cases/repro-block` as the separate dimensioned mechanical case for exact constraints and STEP round-trip behavior. Neither case requires adding a third-party vision API solely to follow the workflow.
147
+
148
+ ## Repeatable validation
149
+
150
+ The benchmark format and local validation commands are defined in [`benchmark/README.md`](benchmark/README.md). Two frozen fixtures separate visual approximation (`benchmark/cases/visual-pose-dog`) from dimension-constrained CAD (`benchmark/cases/repro-block`). The validator checks case/run metadata, input and artifact hashes, per-case gates, criterion-level visual review, and dimension tolerances across repeat runs. It is a reproducibility scaffold—not a CAD kernel or an independent visual judge; geometry and STEP round-trip checks must be performed by the CAD runner, and visual criteria must be reviewed against the comparison image.
151
+
152
+ ## Agent workflow
153
+
154
+ The repository-owned agent procedure is [`skills/img2cad/SKILL.md`](skills/img2cad/SKILL.md), routed through [`AGENTS.md`](AGENTS.md). For the general path, use the resumable `scripts/agent_workflow.py` coordinator around `scripts/run_agent_cad.py` and `scripts/record_visual_review.py`. It records image evidence and plan, pins inspected model source, executes the local CAD/STEP gate, and binds review to that run's hashes. An optional manual camera direction can replace the generic isometric preview; it is not automatic photo alignment. `run_report.json` records **geometry/STEP success only**, never visual fidelity. The review record preserves the declared reviewer and notes but cannot independently prove a human inspected or accepted the image. The separate `scripts/run_pipeline.py` remains a constrained benchmark path requiring a pre-authored spec; its generator only creates a rectangular prism with optional through-holes. The optional vision adapter is not required for an agent that already has image input capability.
155
+
156
+ ### Resumable general workflow CLI
157
+
158
+ Use `img2cad workflow` (`scripts/agent_workflow.py`) for the ordinary image-led path. It stores a local `workflow.json`, pins the reference image, records stage input/output hashes and a `next_step` for each stage, and reports the next action on `status`. Each workflow directory is new; revisions are append-only, with the earlier CAD run retained. This state machine coordinates the agent's judgments—it does not infer observations, inspect visual quality, or turn an agent review into human acceptance.
159
+
160
+ ```sh
161
+ img2cad workflow init /path/to/work --reference /path/to/image.png --target-type visual_approximation
162
+ img2cad workflow status /path/to/work
163
+ img2cad workflow observations /path/to/work --file /path/to/observations.json
164
+ img2cad workflow plan /path/to/work --file /path/to/plan.json
165
+ img2cad workflow preview /path/to/work --model /path/to/draft.py # iterate freely; no stage changes
166
+ img2cad workflow source-review /path/to/work --model /path/to/model.py \
167
+ --inspection-note "Checked the source against the plan; only intended build123d geometry is created."
168
+ img2cad workflow run /path/to/work
169
+ img2cad workflow review /path/to/work --notes /path/to/review.json
170
+ img2cad workflow promote /path/to/work --name short-slug --technique "what it demonstrates"
171
+ ```
172
+
173
+ `run` uses `--cad-python`, else `$IMG2CAD_CAD_PYTHON`, else the clone's `.venv-cad/bin/python`, else the interpreter running `img2cad`.
174
+
175
+ ### Learning material for agents
176
+
177
+ - [`skills/img2cad/MODELING.md`](skills/img2cad/MODELING.md): the allowed build123d API, plane orientation, technique-by-object-type table, how to read sizes from images, and the declarable checks.
178
+ - [`examples/`](examples/README.md): accepted end-to-end runs (dimensioned plate, revolved bushing, revolved and shelled vase, lofted fish with a revise round, jointed standing horse, tiered pagoda), each with reference, observations, plan, model, comparison, silhouette overlay, review, and a short write-up.
179
+ - [`skills/img2cad/LESSONS.md`](skills/img2cad/LESSONS.md): verified pitfalls from real runs.
180
+ - [`skills/cad-output/SKILL.md`](skills/cad-output/SKILL.md): viewing, mesh export, engineering drawings, and printability checks for a finished model.
181
+ - Precision tools:
182
+ - `scripts/trace_regions.py` traces colour regions of the photo into pixel outlines.
183
+ - `scripts/img2cad_lib.py`, importable from `model.py`, provides `ImageFrame` registration, `projected_decal` for exact painted details on curved surfaces, and helpers for revolves, limbs, and joints.
184
+ - With `IMAGE_FRAME` set, runs draw the CAD on the photo (`registered.png`) and score each colour region against it.
185
+
186
+ `promote` copies an accepted workflow into `examples/` so later agents can reuse it; new pitfalls go into `LESSONS.md`. This is how the repository accumulates experience across runs; agents do not otherwise remember earlier sessions.
187
+
188
+ Observation JSON uses `observed`, `inferred`, `unknowns` string arrays and `evidence` objects with `claim` and `source`. Plan JSON includes `target_type` (`visual_approximation` or `dimension_constrained`), `goal`, nonempty `geometry_plan`, `constraints`, and `unknowns`. For dimension-constrained plans, `constraints` can declare overall bounds (`length`/`width`/`height` or `x`/`y`/`z`, optional `tolerance`, default 0.02 model units), `volume` (explicit absolute tolerance), and `hole`/`boss` diameter and count; the workflow compares them with the STEP inspection. Feature positions are not checked and remain review criteria. The geometry gate requires each part to be one solid (a single fused body, or each part of a coloured `Compound(children=[...])` assembly, whose part colours and names are kept in the STEP) unless the plan sets `"allow_multiple_solids": true`. `run` and `preview` also write an advisory silhouette comparison (`silhouette.png` and a best-view IoU, with a `reliable` flag that is false when the image's background could not be separated); for real photos pass a traced `--reference-mask`. It helps spot proportion errors but is never a gate. Review JSON follows `scripts/record_visual_review.py`: reviewer, verdict (`acceptable`, `revise`, or `blocked`), compared views, matches, mismatches, next_changes, and assumptions. `revise` must name mismatches and geometry/parameter changes; `blocked` must identify missing evidence in `next_changes`.
189
+
190
+ The CLI refuses to run CAD before source review, refuses visual review unless geometry/STEP and (for dimension-constrained work) declared bounding-dimension gates pass, checks source/reference/artifact hashes, and stores the exact reviewer/verdict separately from geometry status. After `revise` or `blocked` (or a failed geometry/dimension run), start a fresh revision with `new-revision --reason ...`; it preserves the prior run and inherits observations/plan. If new evidence or a changed plan is needed, record it into the new revision; source, geometry, dimensions, and visual-review gates reset. Do not reuse a previous preview's review for the new source. `human_acceptance` remains `not_verified` even when the agent review is acceptable.
img2cad-0.12.0/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.12.0