EXAMPLE
(click to run):
The following example illustrates three typical uses of the
Normal node (see Figure 3-39). The first IndexedFaceSet
defines a Normal node that has five normals and uses the normalIndex
field to assign the correct normal to the corresponding vertex
of each face. The second IndexedFaceSet defaults to using the
coordIndex field to index into the Normal node. This
is probably the most common use of the Normal node (i.e., one
normal for each coordinate). The third IndexedFaceSet applies
a Normal node to the faces of the geometry. This produces a
faceted polygonal object and may render faster than when specifying
normals per vertex:
#VRML V2.0 utf8
Group { children [
Transform {
translation -3 0 0
children Shape {
appearance DEF A1 Appearance {
material Material { diffuseColor 1 1 1 }
}
geometry IndexedFaceSet {
coord DEF C1 Coordinate {
point [ 1 0 1, 1 0 -1, -1 0 -1, -1 0 1, 0 3 0 ]
}
coordIndex [ 0 1 4 -1 1 2 4 -1 2 3 4 -1 3 0 4 ]
normal Normal {
vector [ .707 0 .707, .707 0 -.707, -.707 0 -.707,
-.707 0 .707, .707 .707 0, 0 .707 -.707,
-.707 .707 0, 0 .707 .707 ]
}
normalIndex [ 0 1 4 -1 1 2 5 -1 2 3 6 -1 3 0 7 ]
}
}
}
Transform {
children Shape {
appearance USE A1
geometry IndexedFaceSet {
coord USE C1
coordIndex [ 0 1 4 -1, 1 2 4 -1, 2 3 4 -1, 3 0 4 ]
normal Normal { # use coordIndex for normal indices
vector [ .707 0 .707, .707 0 -.707,
-.707 0 -.707, -.707 0 .707, 0 1 0 ]
}
}
}
}
Transform {
translation 3 0 0
children Shape {
appearance USE A1
geometry IndexedFaceSet {
coord USE C1
coordIndex [ 0 1 4 -1, 1 2 4 -1, 2 3 4 -1, 3 0 4 ]
normal Normal {
vector [ .707 .707 0, 0 .707 -.707, -.707 .707 0,
0 .707 .707 ]
}
normalIndex [ 0, 1, 2, 3 ]
normalPerVertex FALSE
}
}
}
DirectionalLight { direction 1 0 0 }
Background { skyColor 1 1 1 }
] }
|