Fit Features to Mesh
mesh_to_featuresUse this when you are handed an STL, OBJ or 3MF of a mostly prismatic mechanical part (plate, bracket, spacer, flange, housing block) and need an EDITABLE kernelCAD model of it rather than a faceted lib.fromSTL import. Deterministic, measured, self-verifying: it welds and checks the mesh, segments planes and cylinders, picks the extrusion axis, slices each band and fits exact lines / arcs / circles, snaps near-round values (each snap recorded), then emits a readable .kcad.ts with named param()s — a revolve for concentric round stacks, extruded profiles otherwise, .hole()/.holes() for through, blind and counterbored bores (axial and side-drilled), .cutout() for pockets, .fillet() for constant-radius edge blends (radius measured on the sharp edge, edges grouped by radius and picked with the shortest exact edge query), boolean subtractions for what no drilling feature can reach. It then EVALUATES that script and compares it with the mesh: volume IoU (column ray casting) and symmetric surface deviation (max + RMS), over up to 4 refinement passes. Returns { script, ledger, fidelity: { maxDeviationMm, rmsMm, volumeIoU, verdict: faithful | approximate | failed, thresholds }, unmatchedRegions, features, passes }. A fillet or sharp reading is kept by which measures better; variable-radius blends and chamfers are reported, not forced. The verdict is computed from the numbers — faithful needs IoU >= minIoU AND max deviation <= maxDeviationMm AND a watertight mesh AND no unmatched region. Freeform surfaces, tilted planes and side bosses are listed in unmatchedRegions (reference.mesh.freeform-region-unmatched), never silently dropped. The ledger uses fact ids equal to param names, so resolve_assumptions on the written .ledger.json yields paramOverrides for set_param. Pass { out } to write the script and ledger; the mesh itself is never modified. Hosted: give the file as an https:// URL, a data: URI (base64, max 25 MB) or "asset:" from request_upload (when the file is on the user's device).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| out | No | Write the emitted script to this .kcad.ts path and the assumption ledger to the sibling .ledger.json. | |
| data | No | Mesh bytes as base64 — use when the server cannot see your filesystem. | |
| file | No | Path to a .stl (binary or ASCII), .obj or .3mf mesh. One of file / data is required. Hosted server: cannot read files from your machine — pass `code`, or `project:<slug>` for a saved project. Hosted server: pass an https:// URL, a data: URI, or "asset:<id>" from request_upload — not a path on your machine. | |
| format | No | Format override; default from the extension or the content. | |
| minIoU | No | Volume IoU a faithful verdict requires. Default 0.98. | |
| maxPasses | No | Refinement passes, 1–4. Default 4; stops early at the first faithful pass. | |
| maxTriangles | No | Refuse meshes above this triangle count instead of stalling. Default 300000. | |
| maxDeviationMm | No | Max surface deviation (mm) a faithful verdict allows. Default max(0.25, 0.1 % of the bbox diagonal). | |
| weldToleranceMm | No | Vertex weld distance in mm. Default max(1e-4, 1e-6 × bbox diagonal). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||