i
i
i
i
i
i
i
i
266 12. Data Structures for Graphics
• Triangle. Three vectors per triangle, for 9n
t
units of storage;
• IndexedMesh. One vector per vertex and three ints per triangle, for 3n
v
+
3n
t
units of storage.
The relative storage requirements depend on the ratio of n
t
to n
v
.
Is this factor of two worth
the complication? I think
the answer is yes, and it be-
comes an even bigger win
as soon as you start adding
“properties” to the vertices.
As a rule of thumb, a large mesh has each vertex connected to about six tri-
angles (although there can be any number for extreme cases). Since each triangle
connects to three vertices, this means that there are generally twice as many tri-
angles as vertices in a large mesh: n
t
≈ 2n
v
. Making this substitution, we can
conclude that the storage requirementsare 18n
v
for the Triangle structure and 9n
v
for IndexedMesh. Using shared vertices reduces storage requirements by about a
factor of two; and this seems to hold in practice for most implementations.
12.1.3 Triangle Strips and Fans
Indexed meshes are the most common in-memory representation of triangle
meshes, because they achieve a good balance of simplicity, convenience, and
compactness. They are also commonly used to transfer meshes over networks
and between the application and graphics pipeline. In applications where even
more compactness is desirable, the triangle vertex indices (which take up two-
thirds of the space in an indexed mesh with only positions at the vertices) can be
expressed more efficiently using triangle strips and triangle fans.
Figure 12.9. A triangle
fan.
A triangle fan is shown in Figure 12.9. In an indexed mesh, the triangles
array would contain [(0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 5)]. We are storing
12 vertex indices, although there are only six distinct vertices. In a triangle fan,
all the triangles share one common vertex, and the other vertices generate a set
of triangles like the vanes of a collapsible fan. The fan in the figure could be
specified with the sequence [0, 1, 2, 3, 4, 5]: the first vertex establishes the center,
and subsequently each pair of adjacent vertices (1-2, 2-3, etc.) creates a triangle.
The triangle strip is a similar concept, but it is useful for a wider range of
meshes. Here, vertices are added alternating top and bottom in a linear strip as
shown in Figure 12.10. The triangle strip in the figure could be specified by the
sequence[01234567],andeverysubsequenceofthreeadjacent vertices (0-
1-2, 1-2-3, etc.) creates a triangle. For consistent orientation, every other triangle
needs to have its order reversed. In the example, this results in the triangles (0, 1,
Figure 12.10. A triangle
strip.
2), (2, 1, 3), (2, 3, 4), (4, 3, 5), etc. For each new vertex that comes in, the oldest
vertex is forgotten and the order of the two remaining vertices is swapped. See
Figure 12.11 for a larger example.