How I Detect Undercuts in a STEP File Without Uploading the Geometry

# showdev# manufacturing# hardware# rust
How I Detect Undercuts in a STEP File Without Uploading the GeometryFabdose

Fabdose is a desktop tool I built that checks whether a CAD part can actually be injection molded,...

Fabdose is a desktop tool I built that checks whether a CAD part can actually be injection molded, before you send it to a shop for a quote. Drop in a STEP file, pick a process, get a report back in about a minute: which faces have undercuts, which have insufficient draft angle, where the walls are too thin or too thick.

The part I want to write about here is the one requirement I set for myself early on and then had to keep re-earning: the CAD geometry never leaves the computer. The report text is generated by a cloud model, but the actual geometry analysis, the ray casting, the mesh work, the angle math, all of it runs locally. That constraint shaped the undercut detector more than anything else, so this is a post about what that detector actually does.

What an undercut even is, geometrically

In injection molding, the mold has to open in a straight line (the pull direction) and the part has to slide out. An undercut is any face whose geometry blocks that. Picture a part shaped like a hook, or a boss with a lip on the underside: pull the mold straight up and something on the part is now in the way of the mold wall. That's an undercut, and it's exactly the kind of thing that's easy to miss looking at a 3D view on screen and expensive to discover after a mold is already cut.

Faces, not pixels

A STEP file isn't a mesh, it's a boundary representation, a mathematical description of surfaces and edges. Before I can shoot rays at anything, I have to triangulate it, turn each face into a mesh dense enough to sample without missing detail on curved surfaces but not so dense that a part with hundreds of faces takes forever to process.

Once a face has a mesh, the check for that face is conceptually simple: pick sample points across the surface, and for each one, cast a ray back along the pull direction. If the ray is blocked by another part of the same solid before it reaches "outside," that point is shadowed, meaning the mold can't reach it in a straight pull. Enough shadowed points on a face and the whole face gets flagged as an undercut, with a severity that depends on how much of the face is affected and how steep the blocking angle is.

The bug that taught me the most: rays hitting their own face

The failure mode I didn't expect going in was a ray hitting the same face it started from. It sounds like it shouldn't happen, the ray starts just off the surface and travels away from it, but on curved or nearly-tangent faces, floating point rounding from the STEP export can put the ray's origin points close enough to the surface that the very first intersection it finds is itself. The result was faces getting flagged as blocked when they weren't blocked by anything, they were just tripping over their own geometry.

The fix was a self-hit filter: when a ray's first intersection is suspiciously close to its own origin face, on the same solid, within a small tolerance, discard that hit and look at the next one. It's an unglamorous fix and it's the kind of thing that never comes up in a spec, but it moved a real chunk of parts from "false undercut" to "correctly clear."

Why this stays honest about what it doesn't do

Injection molding gets the deepest version of this analysis, face-level undercuts plus draft angle. CNC and sheet metal are included for comparison but aren't run through the same face-level pipeline yet, and I'd rather say that plainly than let the report imply otherwise. A DFM check that quietly overstates its own coverage is worse than useless, it's a check you can't trust the one time it matters.

Why local geometry processing was worth the extra work

It would have been simpler to upload the STEP file to a server, run the same ray casting there, and ship the result back. I didn't do that because the people I built this for are the same people who get nervous about sending an unreleased product's CAD file to a random web service, and they're right to be. Keeping the geometry on the machine means the file never has to leave in the first place. It also means the code doing the ray casting has to be fast enough to run on a laptop in about a minute, which is its own constraint, but it's one I'd rather have than the alternative.

Fabdose is free for the first 5 analyses, no card required, if you want to see what it flags on a part of your own: fabdose.app.