Professional Documents
Culture Documents
Anatomy of A Mesh
Anatomy of A Mesh
Anatomy of a Mesh
A mesh consists of triangles arranged in 3D space to create the
impression of a solid object. A triangle is defined by its three corner
points or vertices. In the Mesh class, the vertices are all stored in a single
array and each triangle is specified using three integers that correspond
to indices of the vertex array. The triangles are also collected together
into a single array of integers; the integers are taken in groups of three
from the start of this array, so elements 0, 1 and 2 define the first
triangle, 3, 4 and 5 define the second, and so on. Any given vertex can
be reused in as many triangles as desired but there are reasons why
you may not want to do this, as explained below.
Since the mesh is made up of triangles, it may seem that the normals at
corners will simply be perpendicular to the plane of their triangle.
However, normals are actually interpolated across the triangle to give
the surface direction of the intermediate positions between the corners.
If all three normals are pointing in the same direction then the triangle
will be uniformly lit all over. The effect of having separate triangles
uniformly shaded is that the edges will be very crisp and distinct. This is
exactly what is required for a model of a cube or other sharp-edged
solid but the interpolation of the normals can be used to create smooth
shading to approximate a curved surface.
Texturing
In addition to the lighting, a model will also typically make use of
texturing to create fine detail on its surface. A texture is a bit like an
image printed on a stretchable sheet of rubber. For each mesh triangle,
a triangular area of the texture image is defined and that texture triangle
is stretched and pinned to fit the mesh triangle. To make this work,
each vertex needs to store the coordinates of the image position that
will be pinned to it. These coordinates are two dimensional and scaled to
the 0..1 range (0 means the bottom/left of the image and 1 means the
right/top). To avoid confusing these coordinates with the Cartesian
coordinates of the 3D world, they are referred to as U and V rather than
the more familiar X and Y, and so they are commonly called UV
coordinates.
See Also
Using the Mesh Class page.
Mesh scripting class reference.