The ColorInterpolator node is an interpolator
which takes a list of RGB values in the field keyValue.
For a list of the events of this node see interpolator.
Syntax:
ColorInterpolator {
key [ ]
keyValue[ ]
}
Examples:
Using this interpolator to set an initial red color, and gradually change
it to blue.
ColorInterpolator {
key [0 1 ]
keyValue[1 0 0, 0 0 1 ]
}
Using this interpolator to set an initial red color, change it to blue
and afterwards change it to green.
ColorInterpolator {
key [0 0.5 1 ]
keyValue[1 0 0, 0 0 1, 0 1 0 ]
}
A complete example is now presented. A Shape is drawn with a default black
diffuse color. The ColorInterpolator will set an initial red diffuseColor,
and gradually change it to blue. After that the Shape will remain with
a blue diffuse color.
First one needs the to define a Group
with a Shape, a TimeSensor,
and a ColorInterpolator.
#VRML V2.0 utf8
Group {
children [
Shape {
appearance Appearance {
material DEF mat Material { diffuseColor 0 0 0 }
}
geometry Sphere {}
}
DEF ci ColorInterpolator {
key [ 0 1 ]
keyValue [ 1 0 0, 0 0 1]
}
DEF ts TimeSensor {
cycleInterval 2
loop FALSE
}
]
}
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 ColorInterpolator by routing the fraction_changed
eventOut from the TimeSensor to the set_fraction eventIn from
the ColorInterpolator.
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 ColorInterpolator, this
event outputs a RGB value.
Finally we use this eventOut to set a color in the Material
node. Note that the color that we want to change is the diffuse color.
Because the diffuseColor is an exposed
field of the Material node we can use the eventIn set_diffuseColor
to change the color. To do this we route the fraction_changed eventOut
of the ColorInterpolator to the set_diffuseColor 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_diffuseColor
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.