Sub topic 3
Boundary Edges and Closed Surfaces
This chapter assumes you can index a mesh as a vertex list plus face index lists, and that you can read simple Python. The code uses collections.Counter.
Boundary edges and closed surfaces
An edge is boundary when only one face uses it. A mesh with no boundary edges is closed, like a sealed box. An open box has a rim of boundary edges where the missing face would be.
Manifold versus non-manifold meshes
A mesh is manifold when every edge has one or two faces, and every vertex's faces form a single connected fan or strip. An edge with three or more faces is non-manifold. Modeling tools and game engines often reject these meshes because they make inside and outside ambiguous.
from collections import Counter
def edge_counts(faces):
counts = Counter()
for face in faces:
for i in range(len(face)):
a, b = face[i], face[(i + 1) % len(face)]
counts[(min(a, b), max(a, b))] += 1
return counts
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),
]
open_box = cube_faces[:-1] # drop one face
counts = edge_counts(open_box)
print(sum(1 for n in counts.values() if n == 1)) # 4 boundary edges
print(sum(1 for n in counts.values() if n > 2)) # 0 non-manifold edgesChecking a mesh with Euler's formula
For a closed, manifold mesh of genus zero (no holes), V − E + F = 2. The cube gives 8 − 12 + 6 = 2. Removing one face from the cube gives 8 − 12 + 5 = 1, which signals that the mesh is open. A mismatch does not prove a fault, but it tells you where to look.
Vertex attributes: normals, UVs and split vertices
Normals and UV coordinates are stored per vertex, not per position. Where two faces meet at a hard edge, their normals differ, so the shared position must be stored as two vertices. This is called a split vertex. The geometry stays the same, but the topology gains extra vertices.
Triangulating polygons for rendering
Renderers draw triangles. A quad (a, b, c, d) becomes (a, b, c) and (a, c, d). Triangulation does not change the surface, only how it is stored.
Adjacency queries and the half-edge structure
To answer "which faces touch this edge?" quickly, a half-edge structure splits each edge into two directed half-edges, each linked to its opposite "twin." Finding neighbors then takes constant time per step instead of a full scan.
Exercise
Using open_box from the code above, which edge is boundary after you drop the face (1, 2, 6, 5) instead of the last one, and why does the count stay at 4?
Show answer
Dropping (1, 2, 6, 5) leaves the edges (1, 2), (2, 6), (6, 5) and (5, 1) with only one face each. The rim still has four edges, so the count is 4. Any single removed face from a cube leaves a four-edge rim, because each face has four edges and every one of them is shared with a face that remains.