VRML example: Coloring the vertices

This example shows how to define a color for each vertex of each polygon.

#VRML V1.0 ascii

Separator {
   Material {
      diffuseColor [
         1.0 1.0 0.0,
         0.0 1.0 1.0,
         1.0 0.0 1.0,

         1.0 0.0 0.0,
         0.0 1.0 0.0,
         0.0 0.0 1.0,

         1.0 1.0 0.0,
         0.0 1.0 1.0,
         1.0 0.0 1.0,

         1.0 0.0 0.0,
         0.0 1.0 0.0,
         0.0 0.0 1.0,

         1.0 1.0 0.0,
         0.0 1.0 1.0,
         1.0 0.0 1.0,

         1.0 0.0 0.0,
         0.0 1.0 0.0,
         0.0 0.0 1.0 
      ]
      ambientColor 0.1 0.1 0.1
   }
Here is the definition of 18 colors.

   MaterialBinding {
      value PER_VERTEX
   }
MaterialBinding node is used to indicate color values will be assigned to each vertex of each polygon. Although there is only 5 vertices in the pyramid, there are total 18 vertices in the definition of a pyramid in terms of 6 triangles.

   Coordinate3 {
      point [
         0    5   0,
        -2.5  0  -2.5,
         2.5  0  -2.5,
         2.5  0   2.5,
        -2.5  0   2.5
      ]
   }
   IndexedFaceSet {
      coordIndex [
         0, 4, 3, -1,
         0, 3, 2, -1,
         0, 2, 1, -1,
         0, 1, 4, -1,
         1, 3, 4, -1,
         1, 2, 3, -1
      ]
   }
}