Convert STL / 3MF triangle meshes of mechanical / prismatic parts into STEP BREP solids with true analytic geometry — real planes, cylinders, cones, spheres, and tori with analytic edges (lines, circles), not faceted triangles wrapped as faces.
This is a "Tier-3" converter: it performs surface reconstruction (feature
recognition), scoped to the tractable prismatic case. See
docs/plans/2026-06-11-stl2step-design.md for the full design.
STL mesh
-> preprocess merge verts, per-face normals, adjacency
-> segment region-grow triangles across smooth edges -> one region/surface
-> fit plane / cylinder / cone per region (+ scipy refine)
-> merge regroup fragmented same-surface regions into one primitive
-> strip remove engraving (small surfaces embedded in one face)
-> build feed analytic surfaces to OpenCASCADE MakerVolume ->
exact analytic-edge intersections -> watertight solid
-> verify score the STEP against the input mesh (pass / warn / fail)
-> export write STEP (AP214)
On the bundled test part (a plate with two through-holes) the output is a single watertight solid: 6 planes + 2 cylinders, 8 analytic-edge faces, 0 splines.
Every conversion is scored against the input mesh before the STEP is trusted.
The oracle (reshape/verify.py) tessellates the built solid, measures the
symmetric surface deviation (both directions, so a missing feature can't
hide), the volume ratio, and watertightness (from BRepCheck_Analyzer,
the authoritative BREP signal), then returns a pass / warn / fail verdict:
- fail — surface deviates > 5% of the part size, or volume is wildly off (< 50% or > 200%). The output does not resemble the input.
- warn — close but imperfect: not a valid closed solid, mean deviation > 1%, or volume off by more than 15%.
- pass — faithful reconstruction.
The CLI prints the report; --strict makes it refuse to write a failing STEP
and exit non-zero. The desktop UI shows a green/amber/red banner plus a
side-by-side render of input vs. output, so a bad conversion is impossible to
miss. (Out-of-scope organic parts now surface as a clear fail instead of a
silently wrong file.)
When analytic reconstruction fails (bad verdict or a build exception), reSHape
automatically writes a faithful tessellated STEP built directly from the
input mesh via OCC sewing. The output geometry is triangulated, not analytic, but
it precisely matches the input surface. The CLI reports method: mesh-fallback
and the desktop UI shows a blue [MESH FALLBACK] banner.
Use --no-fallback to disable this behaviour and get a hard refusal (exit 1)
instead. Analytic-first logic is unchanged: in-scope prismatic parts always go
through the full reconstruction pipeline; the fallback only activates on failure.
- Fits: planes + cylinders + cones + spheres + tori. Covers most machined faces, slots, bosses, round holes, countersinks, tapers, ball ends, and rings.
- Fragmented faces (one surface split by engraved text / chamfers / uneven tessellation) are merged back into one primitive before building.
- Engraving is removed. A cluster of small surfaces embedded in (bordering) exactly one larger face is treated as decorative engraving and stripped; the base face is extended to reconstruct the clean part. Real features are kept: through-holes and fillets/chamfers border two faces, step ledges are large.
- Base-face recovery. When engraving shatters a face into slivers, the furthest-out plane behind a recess is protected from sliver-dropping so the base face is recovered. (A heavily engraved math block reconstructs to a clean 6-face box.) Step ledges are unaffected — they survive on size.
- Non-convex parts (steps, holes) are handled: surfaces are intersected into cells and every cell whose interior lies inside the mesh is kept and fused, so the part can be the union of several cells.
- Not yet: spheres, tori, fillets/chamfers (deferred), organic freeform surfaces (out of scope).
- Known edge: because each planar surface is currently extended across the whole part, deep one-sided pockets whose extended plane would clip unrelated geometry can still mis-cell. Per-region face bounding is the next hardening step.
pythonocc-core requires conda:
conda create -n reshape -c conda-forge python=3.11 \
pythonocc-core=7.8.1 trimesh numpy scipy pytest lxml -y
conda activate reshape
pip install -e .Desktop UI (simplest): double-click run_gui.bat (Windows), or run
reshape-gui. Click Choose part…, pick an STL/3MF, and the STEP is written
next to the original file with the same name.
Command line:
reshape part.stl -o part.step
# options: --feature-angle 25 --tol 0.5
# --strict refuse to write (exit 1) if the fidelity check fails
# --report print the fidelity report as JSONpython tests/make_fixtures.py # (re)generate ground-truth parts
pytest -q # 33 tests, one suite per pipeline stageTests assert against known ground truth (we build the BREP, mesh it, then check the converter recovers it) — correctness is verified by assertion, not by eye.