VRML example: Coloring vertices by using indices

This example shows how to assign a color to each vertex of the object.

#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
      ]
      ambientColor 0.1 0.1 0.1
   }
Six colors are defined, but only five are needed. The colors are labeled from 0 to 5.

   MaterialBinding {
      value PER_VERTEX_INDEXED
   }
Tell the browser that the color of the vertices will be assigned according to the indexed value.

   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
      ]
      materialIndex [
         0, 4, 3, -1,
         0, 3, 2, -1,
         0, 2, 1, -1,
         0, 1, 4, -1,
         1, 3, 4, -1,
         1, 2, 3, -1
      ]
   }
}
The index of the color of the vertices are given in the materialIndex node.