3D Animation Workshop: Lesson 29: VRML 97--On the Move | 2 | WebReference

3D Animation Workshop: Lesson 29: VRML 97--On the Move | 2


Lesson 29 - VRML 97--On the Move - Part 3

Here is just about the simplest possible animation, yet there is a great deal to understand. Go over the code and see what you can make of it.

DEF MovingBox Transform {
  translation 0 0 0
  children  [
    Shape  {
      geometry Box {}
      appearance  Appearance {
        material Material { diffuseColor 1 0 0 }
      }
    }
  ]
}# end of MovingBox Transform
DEF Timer TimeSensor {
  cycleInterval 10
  loop TRUE
}# end of Timer
DEF Translator PositionInterpolator {
  key [0, 1]
  keyValue [0 0 0, 5 0 0]
}# end of Translator  
ROUTE Timer.fraction_changed TO Translator.set_fraction
ROUTE Translator.value_changed TO MovingBox.set_translation

The first node, the Transform, should be familiar from the previous lesson. The node has been defined (named) MovingBox and contains a red box of the default dimensions.

The second node is the TimeSensor named Timer. It defines a 10-second cycle that loops continuously.

The third node is the interpolator, specifically a PositionInterpolator, which we have named Translator. There are different interpolator nodes for different animatable parameters. For example, color changes can be animated using a ColorInterpolator. But all interpolator nodes are the same in that they define the number and position of keys in the time cycle and the values at each key. In this case, there are two keys. The first is at 0, at the start of the 10-second timer cycle. The second key is at 1, ten seconds later at the end of the cycle. Thus these keys represent percentages of time along the cycle defined by the TimeSensor. A value of .5 would be half the length of the cycle.

The keyValue numbers represent the position (translation) values associated with the keys. Thus there must be exactly as many keyValues as there are keys. In this case, the first key at time 0 in the cycle corresponds to a translation value of 0,0,0 (the center of world space). The key at time 1 (at the end of the cycle) corresponds to a position value of 5,0,0 in world space. Thus the node moves an object 5 meters in the x dimension over the 10-second cycle defined by the Timer.

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

If you don't have a VRML browser, download CosmoPlayer from the Cosmo Software site.

The actual animation is achieved by the ROUTE statements at the end of the file. The TimeSensor, Timer, has a field named fraction_changed that contains the percentage of time elapsed along the cycle. This may seem peculiar, but is necessary to accommodate the different screen refresh speeds of different computers. Every time the computer is prepared to refresh the screen, the TimeSensor determines the current point in the time cycle. If that point is, for example, 50 percent of the cycle (5 seconds in this case), it copies (routes) that .5 value to the interpolator node. The interpolator node then determines the proper position of the object at 50 percent of the time cycle. This position value is then copied (routed) to the Transform node containing the box, thereby moving the box to the proper position.

This long, and admittedly confusing logical chain is necessary to make sure that an animation is completed in the allotted time, regardless of how many interpolated frames are used to achieve it. A slower machine or a more complex scene may use fewer frames to achieve the animation, and therefore run less smoothly. But the developer is at least certain that the animation will not run slower than the defined time.

Next time, we get interactive.

To Return to Parts 1 and 2, Use Arrow Buttons

Previous Lesson / Table of Contents / Next Lesson

Created: December 8, 1997
Revised: December 8, 1997

URL: https://webreference.com/3d/lesson29/part3.html