|
|
|
|
|
 |
Tutorial: IndexedFaceSet
|
The IndexedFaceSet Node
|
|
The IndexedFaceSet is the most powerful and flexible of the geometry
nodes. When creating objects with meshes the IndexedFaceSet is the natural choice.
Unfortunately an IndexedFaceSet has so many different uses that it can be
quite a daunting task setting it up correctly.
Constructing the geometry part of the node is not difficult. It consists
of a collection of vertices in the coord field. The faces are defined in
the coordIndex field by indices into the vertex list. For example, a pyramid
could be defined as
|
|
|
|
| |
geometry IndexedFaceSet {
coord Coordinate {
point [ -1 0 1, 1 0 1, -1 0 -1, 1 0 -1, 0 1 0 ]
}
coordIndex [ 0, 1, 4, -1, 1, 3, 4, -1,
3, 2, 4, -1, 2, 0, 4, -1,
1, 0, 2, 3, -1 ]
}
|
|
|
|
The faces, in order, are front, right, back, left, and bottom.
It is when choosing the color, normal and texture coordinate attributes that
the number of choices becomes overwhelming. To keep the number of options down,
only the most common cases are discussed.
|
Colors
|
|
(1) If the geometry has a single color or it has a texture, then the color and
colorIndex fields can be left empty.
|
|
|
|
|
(2) If there is color associated to each vertex, set colorPerVertex=TRUE and
insert the colors in the Color node in the same order that the vertices appear
in the Coordinate node. The number of colors must be the same as the number of vertices.
In this case, it is not necessary to set the colorIndex field.
|
|
|
|
|
| |
colorPerVertex TRUE
color Color {
color [ 1 0 0, 0 1 0, 0 0 1, 1 1 0, 0 1 1 ]
}
|
|
|
|
|
|
|
(3) If each face is a different color, set colorPerVertex=FALSE and insert the
colors in the same order as the faces described in the coordIndex field. The
number of colors must equal the number of faces. The colorIndex field is not needed
in this case.
|
|
|
|
|
| |
colorPerVertex FALSE
color Color {
color [ 1 0 0, 0 1 0, 0 0 1, 1 1 0, 0 1 1 ]
}
|
|
|
|
(4) If there is a great deal of duplication in the Color node, it is possible
to compress the data by using the colorIndex field. At this point, things start
getting complicated and it is time to refer to the X3D specification (Chapter 13.3.6)
to sort out all the possibilities.
|
Normals
|
|
The easiest way to handle the normals is to let the browser calculate them
automatically. The creaseAngle can be used to determine how much the edges are
smoothed over. If the creaseAngle is zero, there will be no smoothing and object
will be faceted. If the creaseAngle is 1.57 (pi over two = 90 degrees), then
edges whose face normals differ by less than 90 degrees will be smoothed over.
|
Texture Coordinates
|
|
|
|
|
(1) If a single texture is draped over the geometry, then leave the texCoordIndex
field blank, and in the texCoord field insert the texture coordinates corresponding
to each of the vertices. The number of texture coordinates must equal the number of
vertices and must be in the same order.
|
|
|
|
|
| |
texCoord TextureCoordinate {
point [ 0 0, 1 0, 0 1, 1 1, 0.5 0.5 ]
}
|
|
|
|
|
|
|
(2) If each face has a different texture applied to it, then put all the face
textures into a single image file. Set the texCoordIndex field to be similar to
the ccordIndex field, except that it contains consecutive numbers starting from 0,
with -1's in the same place as the coordIndex field. In the texCoord field,
list all the texture coordinates. The number of texture coordinates equals the
size of the texCoordIndex field minus the number of -1's that it contains.
|
|
|
|
|
| |
texCoordIndex [ 0, 1, 2, -1, 3, 4, 5, -1,
6, 7, 8, -1, 9, 10, 11, -1,
12, 13, 14, 15, -1 ]
texCoord TextureCoordinate {
point [ 0 0, 1 0, 0.5 1, 0 0, 1 0, 0.5 1,
0 0, 1 0, 0.5 1, 0 0, 1 0, 0.5 1,
0 0, 1 0, 1 1, 0 1 ]
}
|
|
|
|
(3) If there is repetition, the method in (2) can be very inefficient. To improve
the efficiency, refer to other options for texCoordIndex in the X3D specification.
The above example can be simplified to
|
|
|
|
| |
texCoordIndex [ 0, 1, 2, -1, 0, 1, 2, -1,
0, 1, 2, -1, 0, 1, 2, -1,
3, 4, 5, 6, -1 ]
texCoord TextureCoordinate {
point [ 0 0, 1 0, 0.5 1,
0 0, 1 0, 1 1, 0 1 ]
}
|
|
|
|
or
|
|
|
|
| |
texCoordIndex [ 0, 1, 2, -1, 0, 1, 2, -1,
0, 1, 2, -1, 0, 1, 2, -1,
0, 1, 3, 4, -1 ]
texCoord TextureCoordinate {
point [ 0 0, 1 0, 0.5 1, 1 1, 0 1 ]
}
|
|
|
|
Download tutorial files
|
Copyright © Pinecoast Software 2000-2008. All rights reserved. |  |
|
|
|