cad2scad 0.2.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.
- cad2scad-0.2.0/LICENSE +21 -0
- cad2scad-0.2.0/PKG-INFO +236 -0
- cad2scad-0.2.0/README.md +207 -0
- cad2scad-0.2.0/pyproject.toml +48 -0
- cad2scad-0.2.0/setup.cfg +4 -0
- cad2scad-0.2.0/src/cad2scad/__init__.py +58 -0
- cad2scad-0.2.0/src/cad2scad/__main__.py +6 -0
- cad2scad-0.2.0/src/cad2scad/analysis.py +164 -0
- cad2scad-0.2.0/src/cad2scad/cli.py +312 -0
- cad2scad-0.2.0/src/cad2scad/converter.py +191 -0
- cad2scad-0.2.0/src/cad2scad/loader.py +225 -0
- cad2scad-0.2.0/src/cad2scad/optimizer.py +249 -0
- cad2scad-0.2.0/src/cad2scad/parameterizer.py +484 -0
- cad2scad-0.2.0/src/cad2scad/physics.py +660 -0
- cad2scad-0.2.0/src/cad2scad/scad_writer.py +389 -0
- cad2scad-0.2.0/src/cad2scad.egg-info/PKG-INFO +236 -0
- cad2scad-0.2.0/src/cad2scad.egg-info/SOURCES.txt +20 -0
- cad2scad-0.2.0/src/cad2scad.egg-info/dependency_links.txt +1 -0
- cad2scad-0.2.0/src/cad2scad.egg-info/entry_points.txt +2 -0
- cad2scad-0.2.0/src/cad2scad.egg-info/requires.txt +12 -0
- cad2scad-0.2.0/src/cad2scad.egg-info/top_level.txt +1 -0
- cad2scad-0.2.0/tests/test_cad2scad.py +509 -0
cad2scad-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joel Ajitesh Varun
|
|
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.
|
cad2scad-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cad2scad
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Convert CAD/mesh files to parameterized OpenSCAD .scad with physics-aware Customizer sliders
|
|
5
|
+
Author: Joel Ajitesh Varun
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/joelvarun/cad2scad
|
|
8
|
+
Keywords: openscad,cad,3mf,stl,mesh,converter,3d-printing,physics,customizer,parametric
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Manufacturing
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: numpy>=1.24
|
|
19
|
+
Requires-Dist: trimesh>=4.0
|
|
20
|
+
Requires-Dist: lxml>=4.9
|
|
21
|
+
Provides-Extra: full
|
|
22
|
+
Requires-Dist: scipy>=1.10; extra == "full"
|
|
23
|
+
Requires-Dist: networkx>=3.0; extra == "full"
|
|
24
|
+
Requires-Dist: rich>=13.0; extra == "full"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# cad2scad
|
|
31
|
+
|
|
32
|
+
**Convert CAD/mesh files to parameterized OpenSCAD `.scad` with physics-aware Customizer sliders.**
|
|
33
|
+
|
|
34
|
+
Unlike simple "dump polyhedron" converters, `cad2scad` provides a full pipeline with material-aware physics constraints.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
| Feature | Description |
|
|
39
|
+
|---------|-------------|
|
|
40
|
+
| **Multi-format input** | STL, 3MF, OBJ, PLY, OFF, GLTF/GLB, DAE, STEP* |
|
|
41
|
+
| **Vertex welding** | Merge duplicate vertices -> smaller `.scad` files |
|
|
42
|
+
| **Mesh decimation** | Reduce triangles while preserving shape |
|
|
43
|
+
| **Multi-body splitting** | Each solid -> separate OpenSCAD `module` |
|
|
44
|
+
| **Auto-centering** | Move bounding box center to origin |
|
|
45
|
+
| **Color extraction** | Preserve materials from 3MF/OBJ as `color()` wrappers |
|
|
46
|
+
| **Printability analysis** | Wall thickness, overhang detection, watertight checks |
|
|
47
|
+
| **Physics engine** | Mass, center of mass, stress, stability, warp risk |
|
|
48
|
+
| **8 materials** | PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin properties |
|
|
49
|
+
| **Customizer output** | Auto-generated sliders with physics constraints |
|
|
50
|
+
| **Feature detection** | Holes, flat surfaces, symmetry axes |
|
|
51
|
+
| **Parameterized .scad** | Scale, rotate, hollow with material-safe limits |
|
|
52
|
+
| **CLI + Python API** | Use from command line or as a library |
|
|
53
|
+
|
|
54
|
+
*\*STEP support requires `cadquery` (`pip install cadquery`)*
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install cad2scad
|
|
60
|
+
|
|
61
|
+
# With all optional features (decimation, splitting, pretty CLI)
|
|
62
|
+
pip install cad2scad[full]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
### Command Line
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Basic conversion
|
|
71
|
+
cad2scad model.3mf -o model.scad
|
|
72
|
+
|
|
73
|
+
# Parameterized with physics Customizer sliders
|
|
74
|
+
cad2scad model.3mf -o model.scad --parameterize --material PLA
|
|
75
|
+
|
|
76
|
+
# Decimate to 50% triangles, center on origin
|
|
77
|
+
cad2scad model.stl -o model.scad --decimate 0.5 --center
|
|
78
|
+
|
|
79
|
+
# Physics analysis
|
|
80
|
+
cad2scad model.3mf --analyze --physics --material PETG
|
|
81
|
+
|
|
82
|
+
# Split multi-body file into separate modules
|
|
83
|
+
cad2scad assembly.3mf -o assembly.scad --split
|
|
84
|
+
|
|
85
|
+
# Batch convert all STLs in a directory
|
|
86
|
+
cad2scad *.stl -o converted/
|
|
87
|
+
|
|
88
|
+
# Compact output (smaller file, less readable)
|
|
89
|
+
cad2scad model.3mf -o model.scad --compact --precision 4
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Python API
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# One-liner
|
|
96
|
+
from cad2scad import convert
|
|
97
|
+
convert("model.3mf", "model.scad")
|
|
98
|
+
|
|
99
|
+
# Parameterized with physics
|
|
100
|
+
convert("model.3mf", "model.scad", parameterize=True, material="PETG")
|
|
101
|
+
|
|
102
|
+
# Full control
|
|
103
|
+
from cad2scad import Converter
|
|
104
|
+
c = Converter(parameterize=True, material="PLA", decimate=0.5)
|
|
105
|
+
c.load("model.3mf")
|
|
106
|
+
print(c.summary())
|
|
107
|
+
c.save("model.scad")
|
|
108
|
+
|
|
109
|
+
# Physics engine directly
|
|
110
|
+
from cad2scad import PhysicsEngine
|
|
111
|
+
engine = PhysicsEngine("PLA")
|
|
112
|
+
report = engine.analyze(vertices, faces)
|
|
113
|
+
print(f"Mass: {report.mass_grams:.1f}g, Stability: {report.stability_score}/100")
|
|
114
|
+
|
|
115
|
+
# Feature detection
|
|
116
|
+
from cad2scad import Parameterizer
|
|
117
|
+
p = Parameterizer(material="PETG")
|
|
118
|
+
features = p.detect_features(vertices, faces)
|
|
119
|
+
print(f"Holes: {len(features.holes)}, Symmetry: {[s.axis for s in features.symmetry]}")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Output Example
|
|
123
|
+
|
|
124
|
+
### Standard mode
|
|
125
|
+
Input: `box.3mf` (100x115x50mm box)
|
|
126
|
+
|
|
127
|
+
```openscad
|
|
128
|
+
// Generated by cad2scad v0.2.0
|
|
129
|
+
// Source: box.3mf
|
|
130
|
+
module box() {
|
|
131
|
+
polyhedron(points = [...], faces = [...]);
|
|
132
|
+
}
|
|
133
|
+
box();
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Parameterized mode (`--parameterize --material PLA`)
|
|
137
|
+
|
|
138
|
+
```openscad
|
|
139
|
+
/* [Material] */
|
|
140
|
+
material = "PLA"; // ["PLA", "ABS", "PETG", "TPU", "Nylon", "ASA", "PC", "Resin"]
|
|
141
|
+
|
|
142
|
+
/* [Dimensions] */
|
|
143
|
+
scale_x = 1.0; // [0.1:0.01:5.0] X scale (100.0mm nominal)
|
|
144
|
+
// ^ constraint: Min 0.8mm wall for PLA
|
|
145
|
+
|
|
146
|
+
/* [Structure] */
|
|
147
|
+
hollow = 0; // [0:1:1] Hollow the part
|
|
148
|
+
shell_thickness = 1.6; // [0.8:0.1:10.0] Shell wall thickness
|
|
149
|
+
|
|
150
|
+
/* [Physics (read-only)] */
|
|
151
|
+
_mass_g = 140.19; // Estimated mass (g)
|
|
152
|
+
_printability = 71; // Printability score (/100)
|
|
153
|
+
_stability = 85; // Stability score (/100)
|
|
154
|
+
_warp_risk = 30; // Warp risk (/100)
|
|
155
|
+
_safety_factor = 999.0; // Structural safety factor (x)
|
|
156
|
+
|
|
157
|
+
module box_base() { polyhedron(...); }
|
|
158
|
+
module box() {
|
|
159
|
+
translate([offset_x, offset_y, offset_z])
|
|
160
|
+
rotate([rotate_x, rotate_y, rotate_z])
|
|
161
|
+
scale([_x_eff, _y_eff, _z_eff])
|
|
162
|
+
if (hollow == 1) {
|
|
163
|
+
difference() { box_base(); scale([...]) box_base(); }
|
|
164
|
+
} else { box_base(); }
|
|
165
|
+
}
|
|
166
|
+
box();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Open in OpenSCAD -> **Window > Customizer** to get interactive sliders.
|
|
170
|
+
|
|
171
|
+
## CLI Options
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
cad2scad [OPTIONS] INPUT [INPUT ...]
|
|
175
|
+
|
|
176
|
+
Optimization:
|
|
177
|
+
--decimate RATIO Reduce faces (0.0-1.0). 0.5 = halve triangles
|
|
178
|
+
--decimate-target N Reduce to exactly N faces
|
|
179
|
+
--center Center mesh at origin
|
|
180
|
+
--split Split disconnected bodies into modules
|
|
181
|
+
--weld TOL Vertex weld tolerance (default: 1e-6 mm)
|
|
182
|
+
--round N Round coordinates to N decimal places
|
|
183
|
+
|
|
184
|
+
Formatting:
|
|
185
|
+
--precision N Decimal places in output (default: 6)
|
|
186
|
+
--compact Compact arrays (smaller files)
|
|
187
|
+
--no-color Strip color data
|
|
188
|
+
--prefix STR Module name prefix
|
|
189
|
+
|
|
190
|
+
Analysis:
|
|
191
|
+
--analyze Print analysis report (no conversion)
|
|
192
|
+
--min-wall MM Min wall threshold (default: 0.8mm)
|
|
193
|
+
--overhang DEG Overhang angle threshold (default: 45 deg)
|
|
194
|
+
|
|
195
|
+
Physics / Customizer:
|
|
196
|
+
--parameterize Generate OpenSCAD Customizer with physics constraints
|
|
197
|
+
--material MAT Material: PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin
|
|
198
|
+
--physics Include physics report in --analyze output
|
|
199
|
+
|
|
200
|
+
General:
|
|
201
|
+
-o, --output PATH Output file or directory
|
|
202
|
+
-v, --verbose Increase verbosity (-v info, -vv debug)
|
|
203
|
+
--version Show version
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Material Database
|
|
207
|
+
|
|
208
|
+
| Material | Density | Tensile | Min Wall | Max Overhang | Shrinkage |
|
|
209
|
+
|----------|---------|---------|----------|--------------|-----------|
|
|
210
|
+
| PLA | 1.24 | 50 MPa | 0.8 mm | 45 deg | 0.3% |
|
|
211
|
+
| ABS | 1.04 | 40 MPa | 1.0 mm | 40 deg | 0.7% |
|
|
212
|
+
| PETG | 1.27 | 50 MPa | 0.8 mm | 40 deg | 0.4% |
|
|
213
|
+
| TPU | 1.21 | 30 MPa | 1.2 mm | 35 deg | 0.5% |
|
|
214
|
+
| Nylon | 1.14 | 70 MPa | 1.0 mm | 35 deg | 1.5% |
|
|
215
|
+
| ASA | 1.07 | 45 MPa | 1.0 mm | 40 deg | 0.6% |
|
|
216
|
+
| PC | 1.20 | 65 MPa | 1.0 mm | 35 deg | 0.7% |
|
|
217
|
+
| Resin | 1.12 | 45 MPa | 0.3 mm | 80 deg | 0.5% |
|
|
218
|
+
|
|
219
|
+
## Supported Formats
|
|
220
|
+
|
|
221
|
+
| Format | Extension | Notes |
|
|
222
|
+
|--------|-----------|-------|
|
|
223
|
+
| STL | `.stl` | Binary & ASCII |
|
|
224
|
+
| 3MF | `.3mf` | Multi-body, colors |
|
|
225
|
+
| OBJ | `.obj` | With materials |
|
|
226
|
+
| PLY | `.ply` | Binary & ASCII |
|
|
227
|
+
| OFF | `.off` | — |
|
|
228
|
+
| GLTF/GLB | `.gltf`, `.glb` | Scenes → modules |
|
|
229
|
+
| COLLADA | `.dae` | — |
|
|
230
|
+
| AMF | `.amf` | — |
|
|
231
|
+
| STEP | `.step`, `.stp` | Requires `cadquery` |
|
|
232
|
+
| IGES | `.iges`, `.igs` | Requires `cadquery` |
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT
|
cad2scad-0.2.0/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# cad2scad
|
|
2
|
+
|
|
3
|
+
**Convert CAD/mesh files to parameterized OpenSCAD `.scad` with physics-aware Customizer sliders.**
|
|
4
|
+
|
|
5
|
+
Unlike simple "dump polyhedron" converters, `cad2scad` provides a full pipeline with material-aware physics constraints.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
| Feature | Description |
|
|
10
|
+
|---------|-------------|
|
|
11
|
+
| **Multi-format input** | STL, 3MF, OBJ, PLY, OFF, GLTF/GLB, DAE, STEP* |
|
|
12
|
+
| **Vertex welding** | Merge duplicate vertices -> smaller `.scad` files |
|
|
13
|
+
| **Mesh decimation** | Reduce triangles while preserving shape |
|
|
14
|
+
| **Multi-body splitting** | Each solid -> separate OpenSCAD `module` |
|
|
15
|
+
| **Auto-centering** | Move bounding box center to origin |
|
|
16
|
+
| **Color extraction** | Preserve materials from 3MF/OBJ as `color()` wrappers |
|
|
17
|
+
| **Printability analysis** | Wall thickness, overhang detection, watertight checks |
|
|
18
|
+
| **Physics engine** | Mass, center of mass, stress, stability, warp risk |
|
|
19
|
+
| **8 materials** | PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin properties |
|
|
20
|
+
| **Customizer output** | Auto-generated sliders with physics constraints |
|
|
21
|
+
| **Feature detection** | Holes, flat surfaces, symmetry axes |
|
|
22
|
+
| **Parameterized .scad** | Scale, rotate, hollow with material-safe limits |
|
|
23
|
+
| **CLI + Python API** | Use from command line or as a library |
|
|
24
|
+
|
|
25
|
+
*\*STEP support requires `cadquery` (`pip install cadquery`)*
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install cad2scad
|
|
31
|
+
|
|
32
|
+
# With all optional features (decimation, splitting, pretty CLI)
|
|
33
|
+
pip install cad2scad[full]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### Command Line
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Basic conversion
|
|
42
|
+
cad2scad model.3mf -o model.scad
|
|
43
|
+
|
|
44
|
+
# Parameterized with physics Customizer sliders
|
|
45
|
+
cad2scad model.3mf -o model.scad --parameterize --material PLA
|
|
46
|
+
|
|
47
|
+
# Decimate to 50% triangles, center on origin
|
|
48
|
+
cad2scad model.stl -o model.scad --decimate 0.5 --center
|
|
49
|
+
|
|
50
|
+
# Physics analysis
|
|
51
|
+
cad2scad model.3mf --analyze --physics --material PETG
|
|
52
|
+
|
|
53
|
+
# Split multi-body file into separate modules
|
|
54
|
+
cad2scad assembly.3mf -o assembly.scad --split
|
|
55
|
+
|
|
56
|
+
# Batch convert all STLs in a directory
|
|
57
|
+
cad2scad *.stl -o converted/
|
|
58
|
+
|
|
59
|
+
# Compact output (smaller file, less readable)
|
|
60
|
+
cad2scad model.3mf -o model.scad --compact --precision 4
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Python API
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# One-liner
|
|
67
|
+
from cad2scad import convert
|
|
68
|
+
convert("model.3mf", "model.scad")
|
|
69
|
+
|
|
70
|
+
# Parameterized with physics
|
|
71
|
+
convert("model.3mf", "model.scad", parameterize=True, material="PETG")
|
|
72
|
+
|
|
73
|
+
# Full control
|
|
74
|
+
from cad2scad import Converter
|
|
75
|
+
c = Converter(parameterize=True, material="PLA", decimate=0.5)
|
|
76
|
+
c.load("model.3mf")
|
|
77
|
+
print(c.summary())
|
|
78
|
+
c.save("model.scad")
|
|
79
|
+
|
|
80
|
+
# Physics engine directly
|
|
81
|
+
from cad2scad import PhysicsEngine
|
|
82
|
+
engine = PhysicsEngine("PLA")
|
|
83
|
+
report = engine.analyze(vertices, faces)
|
|
84
|
+
print(f"Mass: {report.mass_grams:.1f}g, Stability: {report.stability_score}/100")
|
|
85
|
+
|
|
86
|
+
# Feature detection
|
|
87
|
+
from cad2scad import Parameterizer
|
|
88
|
+
p = Parameterizer(material="PETG")
|
|
89
|
+
features = p.detect_features(vertices, faces)
|
|
90
|
+
print(f"Holes: {len(features.holes)}, Symmetry: {[s.axis for s in features.symmetry]}")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Output Example
|
|
94
|
+
|
|
95
|
+
### Standard mode
|
|
96
|
+
Input: `box.3mf` (100x115x50mm box)
|
|
97
|
+
|
|
98
|
+
```openscad
|
|
99
|
+
// Generated by cad2scad v0.2.0
|
|
100
|
+
// Source: box.3mf
|
|
101
|
+
module box() {
|
|
102
|
+
polyhedron(points = [...], faces = [...]);
|
|
103
|
+
}
|
|
104
|
+
box();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Parameterized mode (`--parameterize --material PLA`)
|
|
108
|
+
|
|
109
|
+
```openscad
|
|
110
|
+
/* [Material] */
|
|
111
|
+
material = "PLA"; // ["PLA", "ABS", "PETG", "TPU", "Nylon", "ASA", "PC", "Resin"]
|
|
112
|
+
|
|
113
|
+
/* [Dimensions] */
|
|
114
|
+
scale_x = 1.0; // [0.1:0.01:5.0] X scale (100.0mm nominal)
|
|
115
|
+
// ^ constraint: Min 0.8mm wall for PLA
|
|
116
|
+
|
|
117
|
+
/* [Structure] */
|
|
118
|
+
hollow = 0; // [0:1:1] Hollow the part
|
|
119
|
+
shell_thickness = 1.6; // [0.8:0.1:10.0] Shell wall thickness
|
|
120
|
+
|
|
121
|
+
/* [Physics (read-only)] */
|
|
122
|
+
_mass_g = 140.19; // Estimated mass (g)
|
|
123
|
+
_printability = 71; // Printability score (/100)
|
|
124
|
+
_stability = 85; // Stability score (/100)
|
|
125
|
+
_warp_risk = 30; // Warp risk (/100)
|
|
126
|
+
_safety_factor = 999.0; // Structural safety factor (x)
|
|
127
|
+
|
|
128
|
+
module box_base() { polyhedron(...); }
|
|
129
|
+
module box() {
|
|
130
|
+
translate([offset_x, offset_y, offset_z])
|
|
131
|
+
rotate([rotate_x, rotate_y, rotate_z])
|
|
132
|
+
scale([_x_eff, _y_eff, _z_eff])
|
|
133
|
+
if (hollow == 1) {
|
|
134
|
+
difference() { box_base(); scale([...]) box_base(); }
|
|
135
|
+
} else { box_base(); }
|
|
136
|
+
}
|
|
137
|
+
box();
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Open in OpenSCAD -> **Window > Customizer** to get interactive sliders.
|
|
141
|
+
|
|
142
|
+
## CLI Options
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
cad2scad [OPTIONS] INPUT [INPUT ...]
|
|
146
|
+
|
|
147
|
+
Optimization:
|
|
148
|
+
--decimate RATIO Reduce faces (0.0-1.0). 0.5 = halve triangles
|
|
149
|
+
--decimate-target N Reduce to exactly N faces
|
|
150
|
+
--center Center mesh at origin
|
|
151
|
+
--split Split disconnected bodies into modules
|
|
152
|
+
--weld TOL Vertex weld tolerance (default: 1e-6 mm)
|
|
153
|
+
--round N Round coordinates to N decimal places
|
|
154
|
+
|
|
155
|
+
Formatting:
|
|
156
|
+
--precision N Decimal places in output (default: 6)
|
|
157
|
+
--compact Compact arrays (smaller files)
|
|
158
|
+
--no-color Strip color data
|
|
159
|
+
--prefix STR Module name prefix
|
|
160
|
+
|
|
161
|
+
Analysis:
|
|
162
|
+
--analyze Print analysis report (no conversion)
|
|
163
|
+
--min-wall MM Min wall threshold (default: 0.8mm)
|
|
164
|
+
--overhang DEG Overhang angle threshold (default: 45 deg)
|
|
165
|
+
|
|
166
|
+
Physics / Customizer:
|
|
167
|
+
--parameterize Generate OpenSCAD Customizer with physics constraints
|
|
168
|
+
--material MAT Material: PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin
|
|
169
|
+
--physics Include physics report in --analyze output
|
|
170
|
+
|
|
171
|
+
General:
|
|
172
|
+
-o, --output PATH Output file or directory
|
|
173
|
+
-v, --verbose Increase verbosity (-v info, -vv debug)
|
|
174
|
+
--version Show version
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Material Database
|
|
178
|
+
|
|
179
|
+
| Material | Density | Tensile | Min Wall | Max Overhang | Shrinkage |
|
|
180
|
+
|----------|---------|---------|----------|--------------|-----------|
|
|
181
|
+
| PLA | 1.24 | 50 MPa | 0.8 mm | 45 deg | 0.3% |
|
|
182
|
+
| ABS | 1.04 | 40 MPa | 1.0 mm | 40 deg | 0.7% |
|
|
183
|
+
| PETG | 1.27 | 50 MPa | 0.8 mm | 40 deg | 0.4% |
|
|
184
|
+
| TPU | 1.21 | 30 MPa | 1.2 mm | 35 deg | 0.5% |
|
|
185
|
+
| Nylon | 1.14 | 70 MPa | 1.0 mm | 35 deg | 1.5% |
|
|
186
|
+
| ASA | 1.07 | 45 MPa | 1.0 mm | 40 deg | 0.6% |
|
|
187
|
+
| PC | 1.20 | 65 MPa | 1.0 mm | 35 deg | 0.7% |
|
|
188
|
+
| Resin | 1.12 | 45 MPa | 0.3 mm | 80 deg | 0.5% |
|
|
189
|
+
|
|
190
|
+
## Supported Formats
|
|
191
|
+
|
|
192
|
+
| Format | Extension | Notes |
|
|
193
|
+
|--------|-----------|-------|
|
|
194
|
+
| STL | `.stl` | Binary & ASCII |
|
|
195
|
+
| 3MF | `.3mf` | Multi-body, colors |
|
|
196
|
+
| OBJ | `.obj` | With materials |
|
|
197
|
+
| PLY | `.ply` | Binary & ASCII |
|
|
198
|
+
| OFF | `.off` | — |
|
|
199
|
+
| GLTF/GLB | `.gltf`, `.glb` | Scenes → modules |
|
|
200
|
+
| COLLADA | `.dae` | — |
|
|
201
|
+
| AMF | `.amf` | — |
|
|
202
|
+
| STEP | `.step`, `.stp` | Requires `cadquery` |
|
|
203
|
+
| IGES | `.iges`, `.igs` | Requires `cadquery` |
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cad2scad"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Convert CAD/mesh files to parameterized OpenSCAD .scad with physics-aware Customizer sliders"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{name = "Joel Ajitesh Varun"}]
|
|
13
|
+
keywords = ["openscad", "cad", "3mf", "stl", "mesh", "converter", "3d-printing", "physics", "customizer", "parametric"]
|
|
14
|
+
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Manufacturing",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
dependencies = [
|
|
25
|
+
"numpy>=1.24",
|
|
26
|
+
"trimesh>=4.0",
|
|
27
|
+
"lxml>=4.9", # for 3MF/XML mesh formats
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
full = [
|
|
32
|
+
"scipy>=1.10", # mesh decimation, spatial ops
|
|
33
|
+
"networkx>=3.0", # connected component splitting
|
|
34
|
+
"rich>=13.0", # pretty CLI output
|
|
35
|
+
]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=7.0",
|
|
38
|
+
"pytest-cov",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
cad2scad = "cad2scad.cli:main"
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Repository = "https://github.com/joelvarun/cad2scad"
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.packages.find]
|
|
48
|
+
where = ["src"]
|
cad2scad-0.2.0/setup.cfg
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cad2scad — Convert any CAD/mesh file to OpenSCAD .scad
|
|
3
|
+
======================================================
|
|
4
|
+
|
|
5
|
+
Supports: STL, 3MF, OBJ, PLY, OFF, GLTF/GLB, STEP* (via CadQuery), DAE
|
|
6
|
+
|
|
7
|
+
Features beyond raw polyhedron dump:
|
|
8
|
+
* Vertex deduplication & weld (shared vertices -> smaller files)
|
|
9
|
+
* Mesh decimation (configurable triangle reduction for faster OpenSCAD preview)
|
|
10
|
+
* Multi-body splitting (each solid -> separate OpenSCAD module)
|
|
11
|
+
* Auto-centering & bounding-box analysis
|
|
12
|
+
* Color/material extraction from 3MF & OBJ
|
|
13
|
+
* Wall-thickness estimation for FDM printability warnings
|
|
14
|
+
* Clean, human-readable .scad output with metadata comments
|
|
15
|
+
* Physics engine: centre-of-mass, stress, overhang, stability, warp risk
|
|
16
|
+
* OpenSCAD Customizer: auto-generated sliders with physics constraints
|
|
17
|
+
* Material database: PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin
|
|
18
|
+
* Feature detection: holes, flat surfaces, symmetry axes
|
|
19
|
+
* CLI tool + full Python API
|
|
20
|
+
|
|
21
|
+
Quick start::
|
|
22
|
+
|
|
23
|
+
from cad2scad import convert
|
|
24
|
+
convert("model.3mf", "model.scad")
|
|
25
|
+
|
|
26
|
+
# Parameterized with physics constraints
|
|
27
|
+
convert("model.3mf", "model.scad", parameterize=True, material="PETG")
|
|
28
|
+
|
|
29
|
+
# Full control
|
|
30
|
+
from cad2scad import Converter
|
|
31
|
+
c = Converter(parameterize=True, material="PLA", decimate=0.5)
|
|
32
|
+
c.load("model.3mf")
|
|
33
|
+
c.save("model.scad")
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
__version__ = "0.2.0"
|
|
37
|
+
|
|
38
|
+
from cad2scad.converter import Converter, convert
|
|
39
|
+
from cad2scad.loader import MeshBundle, load_mesh
|
|
40
|
+
from cad2scad.scad_writer import ScadWriter
|
|
41
|
+
from cad2scad.optimizer import MeshOptimizer
|
|
42
|
+
from cad2scad.physics import PhysicsEngine, PhysicsReport, Material, MATERIALS
|
|
43
|
+
from cad2scad.parameterizer import Parameterizer, MeshFeatures
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
"Converter",
|
|
47
|
+
"convert",
|
|
48
|
+
"MeshBundle",
|
|
49
|
+
"load_mesh",
|
|
50
|
+
"ScadWriter",
|
|
51
|
+
"MeshOptimizer",
|
|
52
|
+
"PhysicsEngine",
|
|
53
|
+
"PhysicsReport",
|
|
54
|
+
"Material",
|
|
55
|
+
"MATERIALS",
|
|
56
|
+
"Parameterizer",
|
|
57
|
+
"MeshFeatures",
|
|
58
|
+
]
|