The Annotated VRML 97 Reference

1 Intro     Concepts     3 Nodes     4 Fields/Events    Conformance
A Grammar     B Java     C JavaScript     D Examples     E Related Info    References
Quick Java         Quick JavaScript         Quick Nodes   
 

  About the Book
  
Help
  Copyright © 1997-99
  Purchase the book from Amazon.com

Chapter 3:
Node Reference


Intro
Anchor
Appearance
AudioClip
Background
Billboard
Box
Collision
Color
ColorInterpolator
Cone
Coordinate
CoordinateInterpolator
Cylinder
CylinderSensor
DirectionalLight
ElevationGrid
Extrusion
Fog
FontStyle
Group
ImageTexture
IndexedFaceSet
IndexedLineSet
Inline
LOD
Material
MovieTexture
NavigationInfo
Normal
NormalInterpolator
OrientationInterpolator
PixelTexture
PlaneSensor
PointLight
PointSet
PositionInterpolator
ProximitySensor
ScalarInterpolator
Script
Shape
Sound
Sphere
SphereSensor
SpotLight
Switch
Text
TextureCoordinate
TextureTransform
TimeSensor
TouchSensor
Transform
Viewpoint
VisibilitySensor
WorldInfo

+3.39 ScalarInterpolator

ScalarInterpolator { 
  eventIn      SFFloat set_fraction         # (-INF,INF)
  exposedField MFFloat key           []     # (-INF,INF)
  exposedField MFFloat keyValue      []     # (-INF,INF)
  eventOut     SFFloat value_changed
}

This node linearly interpolates among a set of SFFloat values. This interpolator is appropriate for any parameter defined using a single floating point value. Examples include width, radius, and intensity fields. The keyValue field shall contain exactly as many numbers as there are keyframes in the key field.

A more detailed discussion of interpolators is available in "2.6.8 Interpolators."

TIP: One nonobvious use for a ScalarInterpolator is to modify the fraction_changed values of a TimeSensor before they are sent to another interpolator. Normally the fraction_changed events will range from 0 to 1 in a linear ramp, but a ScalarInterpolator can be used to modify them in interesting ways. For example, you can map the normal 0 to 1 "sawtooth" ramp of a TimeSensor into a 0 to 1 to 0 "triangle" ramp by doing this:

     DEF TS TimeSensor { }
     DEF SI ScalarInterpolator {
       key [ 0, 0.5, 1 ]
       keyValue [ 0, 1, 0 ]
     }
     DEF PI PositionInterpolator { ... }
     ROUTE TS.fraction_changed TO SI.set_fraction
     ROUTE SI.value_changed TO PI.set_fraction

Generating events that run from 1 to 0 instead of 0 to 1 is just as easy. Simply use keys of [ 0, 1 ] and keyValues of [ 1, 0 ]. Ease-in and ease-out effects (where objects move slowly when starting, speed up, then slow down to stop) are also easy to approximate using appropriate keyframes.


TIP: Remember that TimeSensor outputs fraction_changed events in the 0.0 to 1.0 range, and that interpolator nodes routed from TimeSensors should restrict their key field values to the 0.0 to 1.0 range to match the TimeSensor output and thus produce a full interpolation sequence.

EXAMPLE (click to run): The following simple example illustrates the ScalarInterpolator node. A TouchSensor is used to trigger a TimeSensor, which drives the ScalarInterpolator. The output from the ScalarInterpolator modifies the transparency field of the Cone's Material node:

#VRML V2.0 utf8
Group { children [
  DEF SI ScalarInterpolator {
    key [ 0.0, .5, 1.0 ]
    keyValue [ 0, .9, 0 ]
  }
  DEF T Transform {
    translation -3 0 0 
    children Shape {
      geometry Cone {}
      appearance Appearance {
        material DEF M Material { diffuseColor 1 0 0 }
      }
    }
  }
  DEF TOS TouchSensor {}  # Click to start
  DEF TS TimeSensor { loop TRUE cycleInterval 3.0 } # 3 sec loop
  Background { skyColor 1 1 1 }
    NavigationInfo { type "EXAMINE" }
]}
ROUTE SI.value_changed TO M.transparency
ROUTE TOS.touchTime TO TS.startTime
ROUTE TS.fraction_changed TO SI.set_fraction