STP Repair: How It Works

The pipeline

Page STEP file, drop three.js viewer Web Worker (OpenCascade in WASM) STEPCAFControl_Reader, healing off BRepMesh_IncrementalMesh → triangles, edges ten detectors → items per issue type your fix → ShapeFix / ShapeUpgrade / Sewing re-mesh, run every detector again STEPCAFControl_Writer (on Export) read the export back to check Issue list colors, zoom, selection Download repaired .step

OpenCascade in the browser. The geometry engine is OpenCascade 7.6, the open-source CAD kernel, compiled to WebAssembly (the opencascade.js 2.0 full build, served from this site, about 50 MB and cached after the first visit). It runs in a Web Worker, so the page stays responsive while a fix runs. Nothing is uploaded: the file never leaves your computer.

What the page holds. The worker sends triangles for each face, a polyline for each edge and a point for each vertex, all numbered the way OpenCascade numbers the sub-shapes of the model. Every finding is a list of those numbers plus a measure (a gap, a deviation, an area), so the page can draw any item in its type's color without asking the worker again.

Reading the raw file

When OpenCascade reads STEP it normally runs a shape-processing pass afterward, which for a WebAssembly build means a full ShapeFix_Shape on every body. That quietly repairs the file, so a repair tool would never see the problems. STP Repair points the reader at its own processing recipe whose sequence is empty, so the model arrives exactly as the file describes it. The Heal on import box in step 1 switches the normal pass back on, which is handy for comparing.

A raw file often has no curves on its faces at all (STEP only requires the 3D edge curves). OpenCascade cannot mesh such a face, so until the inexact edges are fixed the viewer draws those faces from a healed copy; the model itself is untouched. Assemblies are walked down to their parts and each part is split into bodies: each solid, each shell that is not inside a solid, and the loose faces together. Part names and colors, including face colors, are read through the XCAF document and written back on export.

Workflow

  1. Load STEP. The model is read raw, meshed and shown. Nothing is analyzed yet.
  2. Analyze. Every detector runs and the list shows each issue type with its count, highest priority first. The settings (inexact limit, stitch tolerance, small-face area, sliver width, relax limit) feed the detectors; change one and analyze again.
  3. Review and fix. Click a type: its items light up in its color and everything else dims. Click an item to select it (Shift-click for a range, Ctrl-click to add), double-click or use the magnifier to zoom to it. Fix selected or Fix all applies that type's fix, and only that one. Undo puts the model back as it was before the last fix.
  4. Export. The repaired model is written as STEP. Check the export reads the file back the same raw way and runs every detector on it, next to the counts from when you loaded the file.

The order of the list matters: the validity fix runs ShapeFix_Shape over each body it touches, and many inexact, wire and tolerance findings disappear with it. Fixing inexact edges next gives every remaining face proper curves. Stitching before looking for missing faces avoids counting every loose face as a hole.

The issue types at a glance

TypeFound withFixed withItem
Validity checkBRepCheck_AnalyzerShapeFix_Shapeface, edge or vertex
Inexact edgesShapeAnalysis_EdgeShapeFix_Edge, ShapeBuild_Edge, BRepLibedge
Split edgesShapeUpgrade_UnifySameDomainShapeUpgrade_UnifySameDomainvertex
Extra edges (merge faces)ShapeUpgrade_UnifySameDomainShapeUpgrade_UnifySameDomainedge and its two faces
Stitch (free edges)edge-to-face counts, gap to the nearest free edgeBRepBuilderAPI_Sewing, ShapeFix_Solidedge
Wire problemsShapeAnalysis_WireShapeFix_Face, ShapeFix_Wire, ShapeBuild_ReShapeface
Small and sliver facesBRepGPropShapeBuild_ReShape, BRepBuilderAPI_Sewingface
Face orientationShapeAnalysis_Shell, BRepClass3d_SolidClassifierShapeFix_Shellfaces of a shell
Relax tolerancesShapeAnalysis_EdgeShapeFix_ShapeToleranceedge or vertex
Missing facesShapeAnalysis_FreeBoundsBRepFill_Filling, BRepBuilderAPI_Sewingloop of edges

Validity check

BRepCheck_Analyzer is OpenCascade's overall check. Each face, edge and vertex it rejects is listed with the reason it gives (an invalid curve on a surface, a shell that is not closed, an unorientable shape, and so on). A body that fails as a whole without a failing part is listed as one item.

The fix runs ShapeFix_Shape on each body involved. It is the catch-all OpenCascade normally runs on import. It is listed first because it repairs boundaries, face curves and tolerances in one pass, so it often clears many of the inexact edge, wire and tolerance findings too. The targeted fixes below then deal with what it leaves, with control over which items change.

Inexact edges

An edge in a B-rep is described more than once: a 3D curve, plus a 2D curve on each face it bounds (the pcurve). The descriptions should agree to within the edge's tolerance. An edge is inexact when they disagree by more than the Inexact above limit (0.001 mm by default), when a face curve is missing and the 3D curve lies further than that limit from the face, when the edge's tolerance itself is looser than the limit, or when its vertices sit further off than that. ShapeAnalysis_Edge measures each of these: CheckSameParameter gives the largest distance between the 3D curve and each face curve, CheckVertexTolerance the tolerance the vertices would need.

The limit is set when a file loads, from the accuracy the file states for itself. Every STEP file carries an uncertainty (UNCERTAINTY_MEASURE_WITH_UNIT), converted to millimetres from the file's length unit. Edges are judged by that value, but never by less than 0.001 mm, the model tolerance CATIA and Rhino use. CAD exports usually state far less than that, around 0.00001 mm, so they are judged at 0.001 mm. Files fitted from a mesh, such as those from STL to STEP, state their fitting accuracy, often 0.005 to 0.02 mm, and are judged by it. Without this, every edge within the file's own stated accuracy would be flagged. The note under the setting shows the stated value. You can still type a different limit before analyzing.

Raw files often leave the face curves out altogether. Before the detectors run, each edge without one is sampled and its points projected onto the face's surface (ShapeAnalysis_Surface). Where every point lies within the limit, the face curve is simply computed and filled in: nothing moves, so it is not listed. The same step restores two other things STEP cannot store: the zero-length degenerate edges at a cone tip or sphere pole, and face curves on cylinders, cones and tori that were read one full turn apart (ShapeFix_Wire FixDegenerated and FixShifted; nothing moves), and a seam that came back with only one of its two face curves, which the reader can do when the missing degenerate edge leaves both uses of the seam side by side. The status line says how many were filled in. Only edges that are further off than the limit count as inexact, so raising the limit lowers the count.

The fix adds any missing face curve (ShapeFix_Edge::FixAddPCurve). An edge on one face only whose 3D curve strays is rebuilt from its face curve, since the face is the more trustworthy description. The edge tolerance is then reset and BRepLib::SameParameter computes the smallest one that holds; each vertex moves to the middle of the curve ends that meet there and gets just enough tolerance to reach them, and ShapeFix_Edge::FixVertexTolerance checks the result. An edge between two faces that really do not meet keeps a tolerance as wide as the gap, and stays listed: that is a gap in the design, not a numerical slip.

Split edges

A split edge is one smooth curve cut into several edges by vertices that serve no purpose: the pieces lie on the same curve and bound the same faces. The detector runs ShapeUpgrade_UnifySameDomain on a copy of each body with edge merging on and face merging off, and lists every vertex its history reports as removed. The item is drawn as a dot, with the edges it joins as lighter lines.

The fix runs the same tool on the real body. With only some items selected, every unselected vertex is handed to KeepShapes, so the tool leaves it alone.

Extra edges (merge faces)

An extra edge separates two faces that lie on the same surface (two halves of one plane, two strips of one cylinder), typically left behind by a Boolean operation or a translator. The detector runs ShapeUpgrade_UnifySameDomain with face merging on and edge merging off and lists every edge the history removes; the two faces it separates are tinted.

The fix merges the faces, keeping any unselected edge through KeepShapes. Edge merging stays off so the fix does only what this type says; the boundary edges of a merged face often become split edges, which then show up in that type to fix next.

Stitch (free edges)

In a closed solid every edge is shared by exactly two faces. A free edge belongs to one face only, so the model is open there (a seam edge, used twice by the same face, does not count). For each free edge the detector also finds the nearest other free edge and shows the gap between them: that is the tolerance sewing would need, which makes it easy to choose one.

The fix runs BRepBuilderAPI_Sewing with the Stitch tolerance, which you can also set right in the fix panel. Bodies whose free edges face each other within the tolerance are sewn into one body, as SpaceClaim's Stitch merges them; a file that stores each face as its own part comes out as one body. Shells that come out closed become solids (ShapeFix_Solid::SolidFromShell). With only some items selected, just the faces along those edges and their partners are sewn. Edges sewn across a real gap keep a tolerance as wide as the gap, so they then show as inexact edges: worth a look, because the faces do not truly meet.

Wire problems

Each face is bounded by one or more wires (closed loops of edges). ShapeAnalysis_Wire checks each loop for edges out of order, gaps between consecutive edges in 3D and on the face, tiny or degenerate edges, self-intersection, and loops that do not close. The detector also flags a face that wraps all the way around a cylinder, cone or sphere but has no seam edge to close its boundary, a common sight in raw files.

The fix runs ShapeFix_Face, which uses ShapeFix_Wire on each loop and adds missing seams. A shared ShapeBuild_ReShape context records every edge it replaces, so the neighboring faces get the same new edges. Adding a seam splits each boundary circle at a new vertex that nothing else uses; the fix merges those arcs back right away (UnifySameDomain, keeping every vertex the file already had), so it does not leave a batch of split edges behind.

Small and sliver faces

A small face has less area than the Small face area setting; a sliver is narrower than the Sliver width, measured as 2 × area ÷ perimeter (for a long thin strip that is its width). Areas and perimeters come from BRepGProp. Faces whose edges have no face curves yet, or whose boundary is broken, are skipped until the inexact edges and wires are fixed, because their area means nothing until then.

The fix removes the faces with ShapeBuild_ReShape and sews their neighbors together across the gap, with a tolerance of at least 1.5 × the widest face removed.

Face orientation

Neighboring faces must agree on which side is outside: the edge they share should run one way in one face and the other way in the other. ShapeAnalysis_Shell::CheckOrientedShells finds the edges where they do not, and the faces along them are listed as one item per shell. A closed solid is also tested from a point far outside with BRepClass3d_SolidClassifier; if that point counts as inside, the solid is inside out.

The fix re-orients each shell with ShapeFix_Shell and reverses an inside-out solid.

Relax tolerances

Many files are almost exact: an edge strays from its face by a few millionths of a millimeter, more than the tolerance the file declares but far below anything that matters. Those are not inexact edges, only tolerances set too tight. This type lists the edges whose mismatch lies between their tolerance and the inexact limit, and the vertices that sit further from their edges' ends than their tolerance allows.

The fix raises each tolerance just enough with ShapeFix_ShapeTolerance::LimitTolerance (which only ever raises), never past Relax up to. STEP has no place for per-edge tolerances, so these come back when the file is read raw again; most CAD systems apply their own on import anyway.

Missing faces

A closed loop of free edges is a hole where a face is missing. ShapeAnalysis_FreeBounds connects the free edges of each body into wires and keeps the closed ones. Stitch first: before stitching, every loose face is a closed loop of free edges too.

The fix builds a patch inside each loop with BRepFill_Filling (a surface constrained to pass through the loop's edges) and sews it into the body. It works best on gently curved or flat holes; it does not reproduce a missing fillet or a sharp feature.

After each fix

A fix replaces geometry: UnifySameDomain and Sewing build new faces, ShapeBuild_ReShape substitutes new edges and faces for old ones. The numbers of the sub-shapes change, so a finding from before a fix could point at the wrong face afterward. STP Repair therefore never carries findings across a fix: after every fix the model is meshed again and every detector runs again, so the list always describes the model as it is now. The fix log shows how the count of the type you fixed changed, and any other type that changed with it.

What does carry across is what belongs to the faces: each fix reports the faces each old face became (from the algorithm's history: BRepTools_History for UnifySameDomain, Modified for Sewing, Value for ReShape), and face colors follow along to the export. Before every fix the model is copied (BRepBuilderAPI_Copy), which is what Undo restores; up to twelve fixes can be undone.

Export and check

The repaired model goes into a fresh XCAF document, one part per original part with its name, part color and face colors, and STEPCAFControl_Writer writes it (AP214). Parts that were placed inside an assembly are written with the placement applied, as separate parts; the assembly structure itself is not kept. Parts merged by stitching keep the name of the first one.

STEP stores a single uncertainty for the whole file rather than a tolerance per edge. The export writes the Inexact above limit there, so an edge counted as exact in the app is still exact when the file is read back.

Check the export reads the written file in the worker exactly as a fresh load would, healing off, and runs every detector. Like any importer, it first restores what STEP cannot carry: face curves, degenerate edges and period shifts (see Inexact edges), and per-edge tolerances, recomputed as the Relax fix does. The table shows each type's count when you loaded the file, in the app now, and in the exported file, with the drops in green. Geometry and topology fixes (inexact edges rebuilt, edges and faces merged, gaps stitched) stay fixed.

Libraries and limits

  • OpenCascade 7.6 through opencascade.js 2.0 (full build), served from /_scripts/vendor/occt/; three.js 0.160 for the viewer.
  • Not covered: SpaceClaim's tangency and duplicate-face checks have no counterpart in OpenCascade's healing tools, so they are not offered.
  • Simplify (turning spline surfaces back into planes, cylinders and cones) needs GeomConvert_SurfToAnaSurf, which this build of opencascade.js does not include, so it is not offered either.
  • Missing-face filling and small-face removal are heuristic: check the result in Section view before exporting.
  • Large files: each fix copies the model (for Undo) and re-runs every detector, so a model with tens of thousands of faces takes a while per fix. The first visit also downloads the 50 MB OpenCascade module.