In this exercise you will create a new kind of interpolator: an integer interpolator. Your new interpolator will be used to animate the whichChoice field of a Switch node to cause the switch to cycle among different elevation grids. Your new interpolator will be implemented by using a short program script within a Script node.
In visualization, computation often produces multiple independent versions of the same shape. You might, for instance, compute multiple isosurfaces, multiple electron density clouds, or multiple 3D elevation grid plots. You can use the switch animation technique illustrated in this exercise to animate between different shapes.
This exercise focuses upon use of Inline, and Script, and Switch nodes.
For the url field in the Script node, write a program script in VRMLscript (a.k.a. JavaScript) that contains a function for the eventIn. The function should have two incoming arguments: a floating point fractional time and a time stamp. The script should multiply the fractional time by the value in the numberOfChoices field and send the result out the choice_changed eventOut.
When you load your world, the timer will repeatedly poke the program script, which will generate integer choice values for the switch. This will cause the switch to animate and cycle between your box and sphere shapes.
HINT: In the Script node's url field, start with the word vrmlscript:.
HINT: The function in the program script should be named the same as your eventIn: set_fraction.
SOLUTION: animgrd1.wrl
Inline { url "terrain_00.wrl" }
Inline { url "terrain_01.wrl" }
Inline { url "terrain_02.wrl" }
Inline { url "terrain_03.wrl" }
Inline { url "terrain_04.wrl" }
Inline { url "terrain_05.wrl" }
Inline { url "terrain_06.wrl" }
Inline { url "terrain_07.wrl" }
Inline { url "terrain_08.wrl" }
Inline { url "terrain_09.wrl" }
Change the Script node's numberOfChoices field value to 10 instead of 2.
Load the world into your VRML browser and watch as your program script animates the Switch node to cause it to cycle between the ten elevation grids. The first pass or two may stutter along as your browser reads in the grids.
SOLUTION: animgrd2.wrl