|
|
VRML Script Tutorial
Full list
VRML Interactive Tutorial
Introduction
VRML File Structure
Drawing: Shape node
Geometry Nodes:
Appearance
Let there be Light
Materials with Colored Lights
Hierarchical Node Structures
Inlining Files
Defining and Instancing Nodes
Defining Levels of Detail
Events in VRML
Interpolators
Let the Music Play
Bindable Nodes
Adding Realism to the world
Information about your world
Definition for Auxiliary Nodes
|
|
|
|
ScalarInterpolator
The ScalarInterpolator node is an interpolator
which takes a list of floating point values in the field keyValue.
For a list of the events of this node see interpolator.
Syntax:
|
ScalarInterpolator { |
key [ ]
keyValue[ ]
|
} |
|
You can use this interpolator with any single floating point value
exposed field. Examples:
change the speed at which a movie
or sound is played.
change the shininess or transparency of a Material.
change the visibility Range of the Fog
node, etc...
A complete example is now presented. A red Shape is drawn with a default
transparency of 0.0 . The ScalarInterpolator will gradually change
it to 1.0 and back to 0.2. The cycle is repeated forever.
First one needs the to define a Group
with a Shape, a TimeSensor,
and a ScalarInterpolator.
Example:
-
#VRML V2.0 utf8
Group {
-
children [
-
Shape {
-
appearance Appearance {
-
material DEF mat Material { diffuseColor 1 0 0 }
-
}
-
geometry Sphere {}
-
}
-
DEF ci ScalarInterpolator {
-
key [ 0 0.5 1 ]
-
keyValue [ 0 1 0]
-
}
-
DEF ts TimeSensor {
-
cycleInterval 2
-
loop TRUE
-
}
-
]
}
Now the only thing which is missing is routing
the events.
We need to get the eventOut fraction_changed generated by the TimeSensor.
This event outputs a value between 0 and 1. We can use this value to set
a key for the ScalarInterpolator by routing the fraction_changed
eventOut from the TimeSensor to the set_fraction eventIn from
the ScalarInterpolator.
A new fraction being set in an interpolator causes the keyValue to
be changed. As a consequence the interpolator will generate the fraction_changed
eventOut. Because the interpolator used is a ScalarInterpolator, this
event outputs a floating point value.
Finally we use this eventOut to set the transparency in the Material
node. Because the transparency is an exposed
field of the Material node we can use the eventIn set_transparency
to change it. To do this we route the fraction_changed eventOut
of the ScalarInterpolator to the set_transparency eventIn of the
Material node.
The ROUTE statements to do this are:
-
ROUTE ts.fraction_changed TO ci.set_fraction
-
ROUTE ci.value_changed TO mat.set_transparency
Note that the nodes being routed are given a name using the DEF
statement. This is because a name is required in a ROUTE statement.
|