VRML example: Coloring each polygon

This example shows how to assign a color to each polygon face in the object.

#VRML V1.0 ascii

Separator {
   Material {
      diffuseColor [
         1.0 1.0 1.0,
         0.0 0.5 1.0,
         1.0 1.0 0.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 because there are six triangles making up the pyramid.

   MaterialBinding {
      value PER_FACE
   }
Tell the browser to pick a color from the list in order.

   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

      ]
   }
}