Sub topic 6
Storing a Mesh: Vertex List Plus Face Index Lists
This chapter assumes you know basic 3D coordinates, vectors, and introductory cross products. It also assumes you can read simple Python code.
A polygon mesh stores a surface using two related parts:
- A vertex list stores point positions.
- A face list stores connections between those points by using their indices.
An index is a number that identifies an item in a list. Python lists start at index 0.
Separate geometry from topology
A vertex position is geometry. It says where a point is in space, such as (1, 0, 0).
The connections between vertices are topology. Topology says which points form an edge and which edges form a face. Topology does not change when you move the points without changing their connections.
For example, a square can keep the same four connected corners while changing from small to large:
| Part | Example | Meaning |
|---|---|---|
| Geometry | `(1, 0, 0)` | A point's position |
| Topology | `(0, 1, 2, 3)` | One face using four vertex indices |
| Mesh | Vertex list plus face list | The complete representation |
This separation makes mesh editing efficient. Moving a vertex changes one position. Reusing that vertex in several faces updates all of those faces.
Build an indexed face set
An indexed face set is a mesh representation in which faces refer to shared vertices by index. Here is a unit cube:
# Each tuple contains an x, y, z position.
vertices = [
(0, 0, 0), # 0
(1, 0, 0), # 1
(1, 1, 0), # 2
(0, 1, 0), # 3
(0, 0, 1), # 4
(1, 0, 1), # 5
(1, 1, 1), # 6
(0, 1, 1), # 7
]
# Each face lists the indices of its corner vertices.
faces = [
(0, 3, 2, 1), # bottom
(4, 5, 6, 7), # top
(0, 1, 5, 4), # front
(3, 7, 6, 2), # back
(0, 4, 7, 3), # left
(1, 2, 6, 5), # right
]
for face in faces:
positions = [vertices[index] for index in face]
print(positions)The face (4, 5, 6, 7) does not contain four positions. It contains four references into vertices. The same vertex can appear in several faces. For example, vertex 0 belongs to the bottom, front, left, and other appropriate faces.
Derive edges from faces
An edge is a pair of neighboring vertex indices. In a face, the last vertex connects back to the first. Therefore, edges do not need a separate list in a simple representation.
Store each edge in sorted order so (1, 5) and (5, 1) represent the same undirected edge:
def edges_of(faces):
edges = set()
for face in faces:
for i, start in enumerate(face):
end = face[(i + 1) % len(face)]
edges.add((min(start, end), max(start, end)))
return edges
edges = edges_of(faces)
print(len(edges)) # 12This derived edge set is useful for checking boundaries, finding neighbors, and applying Euler's formula. More advanced mesh formats store explicit adjacency records when those queries must be fast.
Attributes can split a vertex
A mesh vertex may also have attributes such as a normal, color, or UV coordinate. A UV coordinate maps a surface point to a 2D texture.
One position can need different attributes on different faces. A sharp corner may need different normals, and a texture seam may need different UVs. Many renderers therefore duplicate the position in their final vertex buffer, even though the geometric mesh conceptually shares it.
Exercise
In the cube example, what does the face (0, 1, 5, 4) store, and why is vertex 0 not stored again?
Show answer
It stores four indices into the shared vertex list. Vertex 0 is reused because several faces meet at the same geometric point.