EXAMPLE
(click to run):
The following example illustrates the use of the Color node
in conjunction with the IndexedFaceSet node (see Figure 3-9).
The first IndexedFaceSet uses a Color node that specifies
two colors: black (0,0,0) and white (1,1,1). Each vertex of
each face of the IndexedFaceSet is assigned one of these two
colors by the colorIndex field of the IndexedFaceSet.
The second IndexedFaceSet/Color is almost identical, but does
not specify a colorIndex field in the IndexedFaceSet
and thus relies on the coordIndex field to assign colors
(see IndexedFaceSet). The third IndexedFaceSet/Color applies
color to each face of the IndexedFaceSet by setting colorPerVertex
FALSE and specifying colorIndex for each face.
#VRML V2.0 utf8
Group { children [
Transform {
translation -3 0 0
children Shape {
appearance DEF A1 Appearance { material Material {} }
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 ]
color Color { color [ 0 0 0, 1 1 1 ] }
colorIndex [ 0 0 1 -1 0 0 1 -1 0 0 1 -1 0 0 1 ]
}
}
}
Transform {
children Shape {
appearance USE A1
geometry IndexedFaceSet {
# uses coordIndex for colorIndex
coord USE C1
coordIndex [ 0 1 4 -1 1 2 4 -1 2 3 4 -1 3 0 4 ]
color Color { color [ 1 1 1, 1 1 1, 1 1 1, 1 1 1, 0 0 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 ]
color Color { color [ 0 0 0, 1 1 1 ] }
colorIndex [ 0, 1, 0, 1 ] # alt every other face
colorPerVertex FALSE
}
}
}
Background { skyColor 1 1 1 }
]}
|