Graphics Reference
In-Depth Information
storing redundant information for all the edges with two adjacent faces. A com-
mon trick obfuscates the code a bit by eliminating this storage overhead. The trick
is to store only one half-edge for each mesh edge, and to index from a face using
two's complement when the half-edge is oriented opposite the direction that it
should appear in that face. The two's complement of a non-negative index e (writ-
ten ˜e in C-like languages) is guaranteed to be a negative number, so indices of
oppositely directed edges are easy to identify. The two's complement operator is
efficient on most architectures, so it incurs little overhead. Each edge then uses
the same trick to encode the indices of the adjacent faces, indicating whether that
half-edge or its oppositely directed mate actually appears in the face.
Listing 14.4: Sample mesh representation with full adjacency information.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
struct Mesh {
enum NO_FACE = MAX_INT;
struct Vertex {
Point3
location;
std::vector< int >
edges;
std::vector< int >
faces;
};
struct Edge {
int vertices[2];
/ * May be NO_FACE if this edge is on a boundary. * /
int
faces[2];
};
struct Face {
int
vertices[3];
int
edges[3];
};
std::vector< int >
index;
std::vector<Vertex>
vertex;
std::vector<Edge>
edge;
std::vector<Face>
face;
};
14.5.1.4 Per-Vertex Properties
It is common to label the vertices of a mesh with additional information. Com-
mon rendering properties include shading normals, texture coordinates, and
tangent-space bases.
A polygonal approximation of a curved surface appears faceted. The percep-
tion of faceting can be greatly reduced by shading the surface as if it were curved,
that is, by shading the points indicated by the surface geometry, but altering the
orientation of their tangent plane during illumination computations, as you saw in
Chapter 6. It is common to model the orientation by specifying the desired surface
normal at each vertex and interpolating between those normals within the surface
of each polygon.
Texture coordinates are the additional points or vectors specified at each ver-
tex to create a mapping from the surface of the model to a texture space that defines
material properties, such as reflectance spectrum (“color”). Mapping from the sur-
face to a 2D square using 2D points is perhaps the most common, but mappings
to 1D spaces, 3D volumetric spaces, and the 2D surface of a 3D sphere are also
 
 
Search WWH ::




Custom Search