3D Animation Workshop: Lesson 28: VRML 97 Free Fall | WebReference

3D Animation Workshop: Lesson 28: VRML 97 Free Fall

Lesson 28 - VRML 97 Free Fall - Part 2

The Shape nodes are indeed confusing. They are divided into geometry and appearance fields, but this is not the difficult part. The appearance field calls for a node named Appearance and this node contains a field named material. The material field in turn calls for a node named Material which in turn contains a diffuseColor field. Believe it or not, all this makes sense.

Consider this example.

#VRML V2.0 utf8
Transform {
  children [
    DEF Ball Shape {
      geometry Sphere {radius .5}
      appearance Appearance {
        material  DEF Red Material { diffuseColor 1 0 0 }
      } #end of Appearance
    } #end of shape        
    Transform {
      translation  2 0 0 
      children [
        Shape {
          geometry Box {}
          appearance Appearance {
            material USE Red
        }# End of Shape
      ]#end of children of this transform
    }#end of this transform
    Transform {
      translation -2 0 0
      children [
        USE Ball
      ] #end of children of this transform
    }#end of this transform
  ]#end of children of world transform
} #end of world transform

CLICK HERE to load example if you have a VRML browser.

Before addressing the appearance issue, notice again how the entire world is placed in a Transform node composed of three children. The first child is a Shape (a Sphere) outside its own Transform and therefore cannot be transformed independently in the scene. It is placed at the center of world space. The second and third Shapes (a Box and another Sphere) are in their own Transforms, and translated two units to the right and left respectively.

The first Shape is defined. The DEF tag means that the Shape node is being named Ball, though I could have called it anything. Once the Shape node has been so named, the same name can be used in any other shape node to produce the same result, both as to geometry and appearance. Note how the last Shape uses the Ball node defined before. Thus the third Shape (the one on the left of the screen) has the same geometry and appearance as the first Shape in the world. The one is said to be an "instance" of the other, and if any of the properties of the first node changed, the instance would change with it.

This same power of defining and instancing can be used with appearance. Notice how the Material node of the first Shape is defined as Red. The diffuseColor field of that node is set to 1, 0, 0, (red in the red, green, blue color system). Thus the Material is red in color. The Material node of the second Shape (the Box) is made an instance of the Red node already defined. Thus the color of this node is red as well. This is why the material and appearance fields are made to contain Material and Appearance nodes. As nodes, they can be defined or instanced, and thus used again and again with a simple syntax that reveals a connection between different elements of the world.

Every object in the scene is red. The central Sphere is red because it was made red directly. The Box is red because it instances the Red Material node defined in the first Sphere. And the sphere on the left is red because the entire Shape (both geometry and appearance) is an instance of the first Sphere. (Notice the way that we capitalize the first letter in a node name, but not in a field name.)

This basic concept of instancing can now be taken a further important step.

To Continue to Part 3, or Return to Part 1, Use Arrow Buttons

Created: November 24, 1997
Revised: November 24, 1997

URL: http://webreference.com/3d/lesson28/part2.html