The CoordinateInterpolator node is an interpolator
which takes a list of 3D coordinate values in the field keyValue.
As opposed to the PositionInterpolator
node, which provides a way to translate a shape as a whole along a predefined
path, the CoordinateInterpolator allows you to control each of the points
defined in a Coordinate node (Coordinate
node appears inside of a IndexedFaceSet,
IndexedLineSet, or PointSet).
For a list of the events of this node see interpolator.
The number of keyValue entries must be equal to the number of keys provided
times the number of points specified in the field coord, i.e. for
each key specified there must be as many values as points in the coord
field to which the fraction_changed eventOut is routed to. Note
that by value it is meant a 3D coordinate.
This interpolator can be used to create morphs between shapes, moving
lines or points.
A complete example is now presented. A single square face is drawn in an
IndexedFaceSet. The interpolator will be used to morph this square face
to a trapezoid face, and back again. The cycle is repeated forever.
First one needs the to define a Group with a IndexedFaceSet,
a TimeSensor, and a CoordinateInterpolator.
#VRML V2.0 utf8
Group {
children [
Shape{ appearance Appearance { material Material { }}
geometry IndexedFaceSet {
coord DEF co Coordinate {
point [-1 -1 0, 1 -1 0, 1 1 0, -1 1 0 ]
}
coordIndex [0 1 2 3]
}
}
DEF ci CoordinateInterpolator {
key [0 0.5 1]
keyValue [-1 -1 0, 1 -1 0, 1 1 0, -1 1 0,
-1 -1 0, 1 -0.5 0, 1 0.5 0, -1 1 0,
-1 -1 0, 1 -1 0, 1 1 0, -1 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 interpolator by routing the fraction_changed eventOut
from the TimeSensor to the set_fraction eventIn from the interpolator.
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 CoordinateInterpolator,
this event outputs a list of 3D coordinate value.
Finally we use this eventOut to change the Coordinate
node inside the IndexedFaceSet
node. Because the point field in a Coordinate node is an exposed
field we can use the eventIn set_point to change it. To do this
we route the fraction_changed eventOut of the CoordinateInterpolator
to the set_point eventIn of the Coordinate
node.
The ROUTE statements to do this are:
ROUTE ts.fraction_changed TO ci.set_fraction
ROUTE ci.value_changed TO co.set_point
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.