Fix non-manifold and broken STL files for 3D printing
A mesh can look fine on screen and still not print: a slicer needs a closed surface with an inside and an outside, and files from CAD exports, boolean operations and scans often don't have one. Here's each kind of defect, why it trips up slicing, how it usually gets there, and how to find and fix it by hand or with the API.
What a broken mesh is
An STL is a list of triangles. Nothing in the file says the triangles form a solid. A slicer has to work that out: it cuts the mesh into layers, and in each layer it needs closed outlines it can tell the inside of from the outside. That works when the mesh is watertight (every edge belongs to exactly two triangles, so there are no gaps) and manifold (the surface looks like a single skin everywhere, never a fin or a pinch), and when every triangle agrees which side is out.
When the mesh isn't like that, the slicer guesses, and the guess shows up in the print. A gap can leave a layer with an open outline, so that region gets no walls or no infill. A flipped patch can print as a hole, or fill a space that should be empty. Some slicers refuse the file with an error, and some quietly repair it in ways you didn't pick. The fix is easier before you slice, when you can see which faces are the problem.
The geometry analysis finds seven kinds of defect. Each one has its own count and its own flag on every face, so you can see where it is. The next section goes through them, and the part further down has every one on it.
The defects, one by one
Holes and boundary edges
What it is. A boundary edge belongs to only one triangle, so the surface has a gap there. A hole is a loop of boundary edges.
Why it breaks slicing. The slice through a hole is an open outline, with no inside to fill. The slicer may close it with a straight line, drop the region, or fail.
How it happens. Missing faces after a CAD export or a conversion between formats, surfaces that never got stitched together, scans with unseen areas, and mesh edits that delete triangles.
How to fix it by hand. Fill the hole in a mesh editor (most have a fill-holes tool), or go back to the CAD model, stitch the surfaces into a solid and export again.
Non-manifold edges
What it is. An edge used by three or more triangles, like a fin standing on a surface. A solid's edges always have exactly two.
Why it breaks slicing. The surface has no single inside and outside across that edge, so the outline can go either way and the slicer picks one.
How it happens. Two solids exported touching along an edge, internal walls left in by a union that didn't finish, and stray faces from sketches or imports.
How to fix it by hand. Delete the extra faces, or union the bodies into one and export again. Most mesh editors can select non-manifold edges so you can see them.
Non-manifold vertices
What it is. A vertex where the surface pinches: two parts of the model touch at a single point and share that vertex, like two blocks meeting at a corner.
Why it breaks slicing. The outline touches itself at a point, so a layer can read as one shape or two, and the toolpath may jump or leave a gap there.
How it happens. Parts placed corner to corner, boolean operations on shapes that only just touch, and sculpted meshes with a pinched point.
How to fix it by hand. Move one body so the parts overlap a little and union them, or pull them apart. A split-vertex tool in a mesh editor separates a pinch into two.
Flipped faces
What it is. Each triangle has a front side, the one its corners wind around counter-clockwise, and it should face out. A flipped triangle faces into the part. Normals is another word for this direction.
Why it breaks slicing. Slicers use the direction to decide what's inside. A flipped patch can print as a hole or fill a space that should be empty, and a whole part that's inside out can print as nothing.
How it happens. Mirroring a model without fixing its winding, merging meshes from different tools, and converting between CAD and mesh formats.
How to fix it by hand. Use a recalculate-normals or unify-normals tool, so the faces all point outward, or flip the selected faces.
Self-intersections
What it is. Triangles that pass through other triangles, as when one body overlaps another and was never merged with it.
Why it breaks slicing. The overlapped region has surface inside the part, and the slicer has to decide which side of it is solid. Parts with intersections can slice with stray walls or gaps.
How it happens. Several bodies placed to overlap and exported without a boolean union, assemblies exported as one file, and text or logos embossed on a surface as a separate shell.
How to fix it by hand. Union the overlapping bodies in CAD, or run a boolean union in a mesh editor. Many slicers also accept overlapping shells if you slice them as separate objects.
Duplicate and degenerate faces
What it is. A duplicate is a second copy of a triangle in the same place. A degenerate face has no area: its corners are in a line, or two of them are the same point.
Why it breaks slicing. A duplicate makes an edge look like it has three triangles, and a zero-area face has no direction, so both confuse the inside and outside test. They also bloat the file.
How it happens. Imports that merge vertices badly, a mesh edit that collapses a small triangle, and exports that write a face twice.
How to fix it by hand. Most mesh editors have a remove-duplicate-faces and a remove-degenerate-faces tool, often under a clean-up or mesh-repair menu.
Quick reference
What each defect does to a slice, typically, and what usually fixes it.
| Defect | What the slicer usually does | Usual fix |
|---|---|---|
| Hole (boundary edges) | Leaves an open outline: missing walls or infill, or an error. | Fill the hole. |
| Non-manifold edge | Guesses which side is inside across the edge. | Delete the extra faces, or union the bodies. |
| Non-manifold vertex | Reads a layer as one shape or two where parts touch. | Overlap and union the parts, or separate them. |
| Flipped faces | Prints a hole where there's a wall, or the reverse. | Recalculate the normals. |
| Self-intersection | Slices with stray walls inside the overlap, or gaps. | Union the overlapping bodies. |
| Duplicate or degenerate face | Confuses the inside test, and bloats the file. | Remove the extra and zero-area faces. |
Slicers differ in what they tolerate, so a defect that prints fine in one can fail in another. Fixing the mesh once means it doesn't depend on which slicer you use.
See every defect on a part
This desk organizer was damaged on purpose, the way real files get damaged: a hole in its back wall, a patch of flipped faces on the right wall, a copy of a rim face, a face with no area and a loose fin standing on the rim. It's also made of three separate bodies that were never merged: a knob that touches one corner at a single point, and a post that pokes through the front wall. Its 2,144 faces were run through the geometry analysis, and the counts below are what the API returned. Edges are counted for the edge defects, vertices for the vertex one and faces for the rest.
Tick a kind to draw it or hide it. Lines mark edges, points mark vertices and zero-area faces, and the other faces are colored in place. Then switch to After repair: that's the mesh the repair job returned, with every count at zero. The repair kept the part's own surface, filled the hole, turned the flipped faces back, and merged the overlapping bodies into one skin, so the post now joins the wall instead of passing through it. It has 2,194 faces and is watertight and manifold. Its method was exact, which is what the job reports when it could do this without wrapping a new surface around the part.
See it on a real model: Rabbit Habbit, a sculpted model with holes the repair closes.
Find and fix defects with the API
Uploading a part starts its geometry analysis, which counts each defect. The job also has a layer: a binary file with one 16-bit number per triangle, whose bits say which defects that face has (layer.bits gives the bit positions, and the viewer above reads that file). So you can show the problem faces on a mesh you already have. GET /geometry/{job_id}/layer downloads it.
The repair job fixes what it can. It runs an exact repair, which keeps your part's own surface: it removes bad faces, closes holes, fixes the winding and merges bodies that overlap. If that can't finish within the time limit, it wraps a new surface around the part instead. A wrap is an approximation, a little larger all round with rounded sharp edges, so the job reports which method ran in repaired_method (exact or wrapped). The repaired mesh comes back as an STL and as a new part linked to the original, so you can analyze or slice it directly.
# The SDK isn't on PyPI yet. The quickstart has the same calls with requests
import os
import numpy as np
from propermesh import ProperMeshClient, Units
client = ProperMeshClient(os.environ["PROPERMESH_ACCESS_KEY"], os.environ["PROPERMESH_SECRET_KEY"])
part_id = client.upload_part_file("organizer.stl", Units.mm)
# Uploading a part starts its geometry analysis, which counts the defects
geometry = client.wait_for_part_geometry_analysis_to_complete(part_id).json()
for name in ("num_boundary_edges", "num_non_manifold_edges", "num_non_manifold_vertices",
"num_degenerate_faces", "num_flipped_triangles", "num_duplicate_faces",
"num_intersecting_faces"):
print(name, geometry[name])
# Which faces: one uint16 of bit flags per face, in the mesh's face order
layer = geometry["layer"] # {"face_count": ..., "dtype": "uint16", "bits": {...}}
flags = np.frombuffer(client.download_geometry_layer(geometry["id"]), dtype="<u2")[: layer["face_count"]]
flipped = np.flatnonzero((flags >> layer["bits"]["flipped"]) & 1)
print("flipped faces:", flipped)
# Repair it, and download the result
job = client.start_repair_job(part_id).json()
result = client.wait_for_repair_job_to_complete(job["id"]).json()
print(result["repaired_method"], result["repaired_is_watertight"], result["repaired_is_manifold"])
open("organizer-repaired.stl", "wb").write(client.get_repaired_stl(job["id"]))
# The repaired mesh is also a new part, ready to analyze, slice or quote
repaired_part_id = result["repaired_part_id"]export PROPERMESH_ACCESS_KEY="your access key"
export PROPERMESH_SECRET_KEY="your secret key"
PART_ID=$(curl -s https://propermesh.com/api/v0.1/parts \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY" \
-F "file=@organizer.stl" -F "units=mm" | jq -r .id)
# Uploading a part starts its geometry analysis. Run the second command until "status" is "complete"
GEOMETRY_JOB_ID=$(curl -s https://propermesh.com/api/v0.1/parts/$PART_ID/geometry \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY" | jq -r .id)
curl -s https://propermesh.com/api/v0.1/geometry/$GEOMETRY_JOB_ID \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY" | jq '{status, num_boundary_edges, num_non_manifold_edges,
num_non_manifold_vertices, num_degenerate_faces, num_flipped_triangles,
num_duplicate_faces, num_intersecting_faces, layer}'
# The defects layer: one uint16 of flags per face (gzipped, so curl needs -L --compressed)
curl -sL --compressed -o organizer-defects.u16 \
https://propermesh.com/api/v0.1/geometry/$GEOMETRY_JOB_ID/layer \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY"
# Repair it, then run this until "status" is "complete"
JOB_ID=$(curl -s https://propermesh.com/api/v0.1/repair/$PART_ID/start \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY" \
-H "Content-Type: application/json" -d '{}' | jq -r .id)
curl -s https://propermesh.com/api/v0.1/repair/$JOB_ID \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY" | jq '{status, repaired_method, repaired_is_watertight, repaired_is_manifold, repaired_part_id}'
# The repaired mesh. The route redirects to a short-lived storage URL; fetch that without your keys
STL_URL=$(curl -s -o /dev/null -w '%{redirect_url}' \
https://propermesh.com/api/v0.1/repair/$JOB_ID/stl \
-H "x-access-key: $PROPERMESH_ACCESS_KEY" \
-H "x-secret-access-key: $PROPERMESH_SECRET_KEY")
curl -s -o organizer-repaired.stl "$STL_URL"A part that's already sound comes back unchanged. The quickstart covers API keys and uploads, and the full reference is at /docs.
How to prevent and fix broken meshes
In CAD
- Export one solid. Union bodies that overlap or touch before you export, and make sure the model is a closed solid. A body that's still a sheet is the usual source of holes.
- Don't leave bodies touching at an edge or a point. Overlap them a little and union them, or give them a gap.
- Export at a sensible tolerance. Too coarse a tolerance leaves gaps between surfaces, and too fine a one makes a huge file with tiny sliver faces.
- Check the export. Open the STL in a viewer that shows open edges before you send it on.
In the slicer or a mesh editor
- Use the slicer's repair prompt, if it has one, and look at the layer preview afterwards. An automatic fix can close a gap you meant to keep.
- Run a clean-up pass. Remove duplicate and zero-area faces first, then recalculate the normals, then fill holes. In that order, each step makes the next one easier.
- Fix the cause in the source when you can. A repaired STL is a copy, and the next export from the same CAD file will have the same defects.
- For a part you can't fix by hand, such as a scan with thousands of holes, an automatic repair is faster than editing triangles.
Repairing a mesh doesn't make a design printable on its own. Once the mesh is sound, the wall thickness guide and the overhangs guide cover what to check next.
FAQ
What does non-manifold mean?
A manifold mesh is one where the surface looks like a single skin everywhere: each edge joins exactly two triangles, and the triangles around each vertex form one fan. Non-manifold means that fails somewhere, like an edge with three triangles or two blocks meeting at a point. A real solid object is always manifold, which is why slicers expect it.
Why does my STL have holes when it looked fine in CAD?
CAD models are made of curved surfaces that meet at edges, and exporting turns them into triangles. If the surfaces didn't quite meet in the CAD file, or the export tolerance was too coarse, the triangles don't meet either. Stitching or sewing the surfaces into one solid before you export usually prevents it.
Will repairing a mesh change my part's shape?
The exact repair keeps the original surface and only changes what's broken: it closes holes, turns flipped faces back, removes bad faces and merges overlapping bodies. The fallback wrap makes a new surface a little larger than the part, so it's slightly different, and the job tells you when it was used. Compare the repaired part with the original before you print anything with tight fits.
Are self-intersections always a problem?
Not always. Some slicers merge overlapping shells without trouble, which is why many files print fine with a few. They can still leave stray walls or gaps in the overlap, and they're the one defect you can't fill or flip away, so union the bodies if you can.
How do I know my mesh is watertight?
Run the geometry analysis. It reports whether the mesh is watertight and manifold along with each defect count, and the defects layer shows where the problems are. A watertight, manifold part with no flipped faces is what slicers want.