Sub topic 9
Manifold versus non-manifold meshes
This chapter assumes you know the indexed face set layout, can derive edges from faces, and have seen boundary edges and winding order. The question now is which meshes behave like real surfaces and which only look like them.
What "manifold" means
A surface is a manifold if every point on it has a small neighborhood that looks like a flat piece of paper (a disk). Stand on a sphere, a cube, or a donut and zoom in far enough, and the ground around you looks like a plane. That local flatness is the property modeling tools rely on.
A boundary point is allowed. At the rim of a sheet of paper, the neighborhood is a half-disk, and that still counts as a manifold with boundary. What breaks the rule is a place where the surface branches or pinches, because no small neighborhood of such a point looks like a disk.
For a polygon mesh, this local rule becomes two concrete checks:
- Edge condition. Every edge belongs to one face (a boundary edge) or two faces (an interior edge). An edge shared by three or more faces is non-manifold.
- Vertex condition. The faces that touch a vertex form a single fan. Walking from face to neighboring face around the vertex, you must be able to reach every face that uses it. If the faces split into two or more separate groups, the vertex is non-manifold.
Both conditions are about topology, not geometry. Moving vertices never turns a manifold into a non-manifold mesh, and it never repairs one. Only changing the face index lists does.
The common non-manifold defects
| Defect | What it looks like | Detected by |
|---|---|---|
| Fin or T-edge | Three or more faces meet at one edge, like a wall standing on a floor modeled as one mesh. | Edge with more than 2 faces |
| Bowtie vertex | Two cones or two sheets touch at a single vertex and nothing else. | Faces around the vertex form more than one fan |
| Internal face | A face inside a closed solid, such as a divider in a box. | Edges on it have more than 2 faces |
| Duplicate face | The same polygon listed twice. | Edge counts of 2 where the two faces overlap exactly, or a repeated sorted index tuple |
| Isolated vertex | A vertex that no face uses. | Vertex index never appears in any face |
| Degenerate face | A face with a repeated index, or zero area. | Repeated index in a face, or area near zero |
The first two defects are the ones that break algorithms. The last four are usually cleanup problems that you find with simple scans.
Manifold is not the same as consistently oriented
Orientation is a separate property. A mesh is orientable if you can choose a winding for every face so that each interior edge is traversed in opposite directions by its two faces. A Möbius strip is a valid manifold with boundary, but it is not orientable, so no winding assignment works. In practice, most meshes you meet are orientable, and a repeated directed edge usually signals a flipped face rather than a Möbius strip. Check manifoldness and orientation as two separate questions.
Why it matters
Many mesh operations assume that "the other face across this edge" is unique.
- Half-edge structures store one twin per edge side. A third face on an edge has nowhere to go.
- Subdivision and smoothing average the neighbors of a vertex. At a bowtie vertex, the "neighbors" belong to two unrelated pieces, so the result is a pinch.
- Boolean operations and 3D printing need a clear inside and outside. A fin or internal face makes the inside ambiguous, and slicers may reject the model or print it wrongly.
- Simplification (edge collapse) can fold the surface over itself when the local neighborhood is not a disk.
- Physics and volume calculations assume a closed, oriented, manifold surface so that signed volumes add up.
Rendering a single triangle needs none of this. A GPU draws non-manifold triangle soup without complaint, which is why such meshes survive until a tool that does care touches them.
Testing the edge condition
You already count faces per edge. The manifold test reuses that count. We start from the cube's faces again so the code runs on its own.
from collections import defaultdict
cube_faces = [
(0, 3, 2, 1),
(4, 5, 6, 7),
(0, 1, 5, 4),
(3, 7, 6, 2),
(0, 4, 7, 3),
(1, 2, 6, 5),
]
def edge_face_counts(faces):
counts = defaultdict(int)
for face in faces:
n = len(face)
for i in range(n):
a, b = face[i], face[(i + 1) % n]
counts[(min(a, b), max(a, b))] += 1
return counts
def non_manifold_edges(faces):
return sorted(e for e, n in edge_face_counts(faces).items() if n > 2)
# Add a fin: one extra triangle hanging off the cube edge (0, 1) via a new vertex 8.
cube_with_fin = cube_faces + [(0, 1, 8)]
print(non_manifold_edges(cube_faces)) # []
print(non_manifold_edges(cube_with_fin)) # [(0, 1)]Edge (0, 1) is used by the bottom face, the front face, and the new triangle, so its count is 3.
Testing the vertex condition
Edge counts cannot see a bowtie vertex. Two triangles that share only vertex 0 have no shared edge at all, so every edge has count 1 and looks like a plain boundary edge.
To catch it, group the faces around each vertex. Two faces belong to the same fan if they share an edge that contains the vertex. Count the groups. One group is fine, and more than one is a violation.
from collections import defaultdict
def non_manifold_vertices(faces):
incident = defaultdict(list)
for fi, face in enumerate(faces):
for v in set(face):
incident[v].append(fi)
bad = []
for v, face_ids in incident.items():
parent = {f: f for f in face_ids}
def find(x):
while parent[x] != x:
parent[x] = parent[parent[x]]
x = parent[x]
return x
edge_owner = {}
for fi in face_ids:
face = faces[fi]
n = len(face)
for i in range(n):
a, b = face[i], face[(i + 1) % n]
if v in (a, b):
key = (min(a, b), max(a, b))
if key in edge_owner:
parent[find(fi)] = find(edge_owner[key])
else:
edge_owner[key] = fi
if len({find(f) for f in face_ids}) > 1:
bad.append(v)
return sorted(bad)
bowtie = [(0, 1, 2), (0, 3, 4)] # two triangles touching only at vertex 0
cube_faces = [
(0, 3, 2, 1), (4, 5, 6, 7), (0, 1, 5, 4),
(3, 7, 6, 2), (0, 4, 7, 3), (1, 2, 6, 5),
]
print(non_manifold_vertices(bowtie)) # [0]
print(non_manifold_vertices(cube_faces)) # []This is a union-find over the faces at one vertex. A boundary vertex of an open sheet still produces one group, because its faces form an open fan whose neighbors are linked by shared edges. Open fans therefore pass, which matches the definition of a manifold with boundary.
Combining the checks into a classification
The diagram shows the order of the tests and the possible verdicts.
A closed manifold is the usual requirement for solids. A manifold with boundary is fine for terrain, cloth, and character skin that is open at the neck or wrists.
Relating the checks to Euler's formula
For a closed, connected, orientable manifold with g holes (genus), V - E + F = 2 - 2g. A sphere-like mesh gives 2 and a torus gives 0. Non-manifold meshes can produce other values, so a surprising Euler number is a hint that something is wrong. The reverse is not true: a correct Euler number does not prove the mesh is manifold. Treat it as a quick sanity check and rely on the edge and vertex tests for the verdict.
Fixing non-manifold meshes
The right fix depends on what the model is for.
- Fins and internal faces. Delete the extra faces. If the fin is real geometry, such as a wall on a floor, split it into separate manifold pieces or duplicate the shared edge's vertices so each piece owns its own boundary.
- Bowtie vertices. Split the vertex: create a copy for each fan and reassign the face indices of one fan to the copy. Positions stay identical, so the shape does not change, but the topology becomes manifold.
- Duplicate and degenerate faces. Remove them by sorting each face's indices into a key and keeping one face per key, and by discarding faces with repeated indices.
- Isolated vertices. Remove any vertex that no face references, then reindex the faces.
- Flipped faces. Propagate winding from one face across shared edges so that each interior edge is traversed in opposite directions. Then flip the whole mesh if the result points inward.
Splitting a vertex is the same operation you saw for shading: vertices that share a position can still be different vertices in the index list, and that is allowed. The topology only cares about indices.
Summary of the rules
- Manifold means every point has a disk-like (or half-disk, at a boundary) neighborhood.
- The edge rule: each edge has 1 or 2 faces.
- The vertex rule: the faces at each vertex form one fan.
- Closed means no edge has exactly 1 face. Orientable is a separate property from manifold.
- Edge counts alone miss bowtie vertices, so you need both tests.
Exercise
A mesh has the faces [(0, 1, 2), (2, 3, 4), (4, 5, 0)]. Every edge belongs to exactly one face. Is the mesh manifold? If not, which vertices are the problem and why?
Show answer
It is not manifold. Triangle 1 uses vertices 0, 1, 2, triangle 2 uses 2, 3, 4, and triangle 3 uses 4, 5, 0. No two triangles share an edge, but they touch at vertices 0, 2 and 4. At each of those vertices, two faces meet without sharing an edge, so the faces around the vertex form two separate fans instead of one. The edge test passes because all counts are 1, but the vertex test fails at vertices 0, 2 and 4.
Exercise
Starting from the bowtie mesh [(0, 1, 2), (0, 3, 4)], describe how to make it manifold without changing the shape, and give the new face list.
Show answer
Split the pinched vertex 0 into two vertices at the same position. Add a new vertex 5 with the same coordinates as vertex 0, and make the second triangle use it: [(0, 1, 2), (5, 3, 4)]. The shape is unchanged because both vertices share a position, but each vertex now has one fan of one face, so the mesh is manifold.