Convert CAD/mesh files to parameterized OpenSCAD .scad with physics-aware Customizer sliders
Project description
cad2scad
Convert CAD/mesh files to parameterized OpenSCAD .scad with physics-aware Customizer sliders.
Unlike simple "dump polyhedron" converters, cad2scad provides a full pipeline with material-aware physics constraints.
Features
| Feature | Description |
|---|---|
| Multi-format input | STL, 3MF, OBJ, PLY, OFF, GLTF/GLB, DAE, STEP* |
| Vertex welding | Merge duplicate vertices -> smaller .scad files |
| Mesh decimation | Reduce triangles while preserving shape |
| Multi-body splitting | Each solid -> separate OpenSCAD module |
| Auto-centering | Move bounding box center to origin |
| Color extraction | Preserve materials from 3MF/OBJ as color() wrappers |
| Printability analysis | Wall thickness, overhang detection, watertight checks |
| Physics engine | Mass, center of mass, stress, stability, warp risk |
| 8 materials | PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin properties |
| Customizer output | Auto-generated sliders with physics constraints |
| Feature detection | Holes, flat surfaces, symmetry axes |
| Parameterized .scad | Scale, rotate, hollow with material-safe limits |
| CLI + Python API | Use from command line or as a library |
*STEP support requires cadquery (pip install cadquery)
Install
pip install cad2scad
# With all optional features (decimation, splitting, pretty CLI)
pip install cad2scad[full]
Quick Start
Command Line
# Basic conversion
cad2scad model.3mf -o model.scad
# Parameterized with physics Customizer sliders
cad2scad model.3mf -o model.scad --parameterize --material PLA
# Decimate to 50% triangles, center on origin
cad2scad model.stl -o model.scad --decimate 0.5 --center
# Physics analysis
cad2scad model.3mf --analyze --physics --material PETG
# Split multi-body file into separate modules
cad2scad assembly.3mf -o assembly.scad --split
# Batch convert all STLs in a directory
cad2scad *.stl -o converted/
# Compact output (smaller file, less readable)
cad2scad model.3mf -o model.scad --compact --precision 4
Python API
# One-liner
from cad2scad import convert
convert("model.3mf", "model.scad")
# Parameterized with physics
convert("model.3mf", "model.scad", parameterize=True, material="PETG")
# Full control
from cad2scad import Converter
c = Converter(parameterize=True, material="PLA", decimate=0.5)
c.load("model.3mf")
print(c.summary())
c.save("model.scad")
# Physics engine directly
from cad2scad import PhysicsEngine
engine = PhysicsEngine("PLA")
report = engine.analyze(vertices, faces)
print(f"Mass: {report.mass_grams:.1f}g, Stability: {report.stability_score}/100")
# Feature detection
from cad2scad import Parameterizer
p = Parameterizer(material="PETG")
features = p.detect_features(vertices, faces)
print(f"Holes: {len(features.holes)}, Symmetry: {[s.axis for s in features.symmetry]}")
Output Example
Standard mode
Input: box.3mf (100x115x50mm box)
// Generated by cad2scad v0.2.0
// Source: box.3mf
module box() {
polyhedron(points = [...], faces = [...]);
}
box();
Parameterized mode (--parameterize --material PLA)
/* [Material] */
material = "PLA"; // ["PLA", "ABS", "PETG", "TPU", "Nylon", "ASA", "PC", "Resin"]
/* [Dimensions] */
scale_x = 1.0; // [0.1:0.01:5.0] X scale (100.0mm nominal)
// ^ constraint: Min 0.8mm wall for PLA
/* [Structure] */
hollow = 0; // [0:1:1] Hollow the part
shell_thickness = 1.6; // [0.8:0.1:10.0] Shell wall thickness
/* [Physics (read-only)] */
_mass_g = 140.19; // Estimated mass (g)
_printability = 71; // Printability score (/100)
_stability = 85; // Stability score (/100)
_warp_risk = 30; // Warp risk (/100)
_safety_factor = 999.0; // Structural safety factor (x)
module box_base() { polyhedron(...); }
module box() {
translate([offset_x, offset_y, offset_z])
rotate([rotate_x, rotate_y, rotate_z])
scale([_x_eff, _y_eff, _z_eff])
if (hollow == 1) {
difference() { box_base(); scale([...]) box_base(); }
} else { box_base(); }
}
box();
Open in OpenSCAD -> Window > Customizer to get interactive sliders.
CLI Options
cad2scad [OPTIONS] INPUT [INPUT ...]
Optimization:
--decimate RATIO Reduce faces (0.0-1.0). 0.5 = halve triangles
--decimate-target N Reduce to exactly N faces
--center Center mesh at origin
--split Split disconnected bodies into modules
--weld TOL Vertex weld tolerance (default: 1e-6 mm)
--round N Round coordinates to N decimal places
Formatting:
--precision N Decimal places in output (default: 6)
--compact Compact arrays (smaller files)
--no-color Strip color data
--prefix STR Module name prefix
Analysis:
--analyze Print analysis report (no conversion)
--min-wall MM Min wall threshold (default: 0.8mm)
--overhang DEG Overhang angle threshold (default: 45 deg)
Physics / Customizer:
--parameterize Generate OpenSCAD Customizer with physics constraints
--material MAT Material: PLA, ABS, PETG, TPU, Nylon, ASA, PC, Resin
--physics Include physics report in --analyze output
General:
-o, --output PATH Output file or directory
-v, --verbose Increase verbosity (-v info, -vv debug)
--version Show version
Material Database
| Material | Density | Tensile | Min Wall | Max Overhang | Shrinkage |
|---|---|---|---|---|---|
| PLA | 1.24 | 50 MPa | 0.8 mm | 45 deg | 0.3% |
| ABS | 1.04 | 40 MPa | 1.0 mm | 40 deg | 0.7% |
| PETG | 1.27 | 50 MPa | 0.8 mm | 40 deg | 0.4% |
| TPU | 1.21 | 30 MPa | 1.2 mm | 35 deg | 0.5% |
| Nylon | 1.14 | 70 MPa | 1.0 mm | 35 deg | 1.5% |
| ASA | 1.07 | 45 MPa | 1.0 mm | 40 deg | 0.6% |
| PC | 1.20 | 65 MPa | 1.0 mm | 35 deg | 0.7% |
| Resin | 1.12 | 45 MPa | 0.3 mm | 80 deg | 0.5% |
Supported Formats
| Format | Extension | Notes |
|---|---|---|
| STL | .stl |
Binary & ASCII |
| 3MF | .3mf |
Multi-body, colors |
| OBJ | .obj |
With materials |
| PLY | .ply |
Binary & ASCII |
| OFF | .off |
— |
| GLTF/GLB | .gltf, .glb |
Scenes → modules |
| COLLADA | .dae |
— |
| AMF | .amf |
— |
| STEP | .step, .stp |
Requires cadquery |
| IGES | .iges, .igs |
Requires cadquery |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cad2scad-0.2.0.tar.gz.
File metadata
- Download URL: cad2scad-0.2.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae26a1be693ff590cd696d618fd190841b6a350f10922e802be3ef9afb82ab24
|
|
| MD5 |
1ef655d4533557fe0b5915d05d83abb4
|
|
| BLAKE2b-256 |
6e76616dac36c05da9a160c0c753241f614b62bf1b8dbf9cdebbf11fd5ea24e1
|
File details
Details for the file cad2scad-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cad2scad-0.2.0-py3-none-any.whl
- Upload date:
- Size: 34.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eba0aa1bf66a482461d82ec7f83e8e065b832e3b9698b65ff94ff377fb61a862
|
|
| MD5 |
42f05006fd2b54470236d5d9f235cc06
|
|
| BLAKE2b-256 |
d567bfba0a4d7a4922b34fe310412c01a2cbaf086640dbfdfabfc1c170e1f92a
|