mesh2cad takes an STL and gives back CAD: a STEP file with real planes, cylinders and cones, and, when the part is simple enough, a CadQuery or OpenSCAD script with named parameters. The point of the script is that you can open it and change hole_1_d instead of fighting triangles.
I test on six real Original Prusa i3 MK3S printer parts. Yesterday's post got five of them to exact STEP. 0.12.0 does two things: it sews the last one, and it makes the belt idler editable as a script.
The last STEP: a bore that meets everything
On y-rod-holder every surface was already fitted in 0.11.0, but the solid didn't close. The R=4.00 mm rod bore is one cylinder band whose boundary loop touches several planes and the coaxial 45 degree chamfer circles at both ends. The sewing code only handled a band that meets one or two simple caps, so it gave up and the output was the raw mesh: valid, but 3043 triangles and nothing to edit.
0.12.0 trims a cylinder or cone band against all the planes and coaxial circles in its loop. Two smaller fixes were needed on the same part: a hole end that is a full chamfer circle can now meet a cap that is split across coplanar pads, and a short chamfer that region growing had glued onto a plane is split back off when its vertices leave that plane.
Result: 158 planes, 8 cylinders, 11 cones, Hausdorff 0.2178 mm, volume error 0.391%, 12.4 s. The cylinders and cones fit to under 0.005 mm. The remaining 0.22 mm is three shallow patches kept as single planes, with vertices 0.16 to 0.24 mm off the plane and no internal edge sharper than about 10 degrees. I'd rather report that than hide it.
So all six real parts are now exact STEP solids.
The editable part: chamfers, blind holes and pockets
STEP is good for measuring and for other CAD tools, but you can't say "make this hole 2 mm bigger" to a STEP file. For that, mesh2cad writes a small script: intersected extrusions along X, Y and Z, cuts, and holes. Until now it refused any part with a chamfer on a hole, which ruled out most printed parts.
0.12.0 adds to that vocabulary:
- a 45 degree axis-aligned chamfer on a hole, as
hole_N_chamfer(the axial length) - a blind hole, as
hole_N_depth - a blind pocket, and a shallow floor such as a hex nut pocket or an embossed logo
y-belt-idler now exports both scripts. The solid is the X and Y silhouettes intersected, plus the belt grooves, hex pockets, logo floors, an Ø3.2 hole along X with an Ø5.6 counterbore, a 0.5 mm blind hole along Y with a 45 degree taper, and two Ø3.3 holes along Z with a 0.4 mm mouth chamfer.
Every script is rebuilt and compared to the mesh before it is written. The gate is the same as before: max deviation at most max(4 x tolerance, 0.1 mm) and volume error at most 1%. For the idler the limit is 0.192 mm:
| script | max deviation | volume error |
|---|---|---|
| CadQuery | 0.1534 mm | 0.144% |
| OpenSCAD | 0.1639 mm | 0.145% |
There is a test where a chamfer on an X hole through a slanted extrusion is edited from 0.8 mm to 1.2 mm, and the volume changes by exactly the analytic ring. That is the behaviour I want: change a number, get the geometry you'd expect.
Still refused
Three of six parts are parametric now (plug-aligner, endstop-block, y-belt-idler). The other three are refused, and the message says why instead of writing a wrong script:
- y-motor-holder: "combined extrusion deviates by 7.924 mm (limit 0.266), volume error 30.07%". Its Ø5.6 / Ø3.2 screw holes run from z=0.4 to z=8 on a part that is 19 mm tall. They are stepped holes that don't go through, which the vocabulary doesn't have yet.
- y-rod-holder: "combined extrusion deviates by 1.503 mm (limit 0.138)". The Ø3.3 hole along Y isn't one radius for its whole length, so a single cylinder sits about 1.5 mm off the mesh where the opening widens.
- y-belt-holder: "combined extrusion deviates by 2.517 mm (limit 0.154), volume error 1.97%". Better than 24 mm in 0.11.0, but the outline still has a gap.
These are the next three things to build, in that order.
Try it
pip install mesh2cad
mesh2cad convert part.stl -o part.step
mesh2cad convert part.stl --openscad part.scad
It also runs as an MCP server (mesh2cad mcp), so an assistant can convert a part and then edit a parameter for you. If you have an STL of a simple mechanical part that fails, an issue with the file attached is the most useful thing you can send: github.com/emirmrkaljevic/mesh2cad.
Top comments (0)