A
KeyFrame
Evaluator
for
Shape
objects.
This
Evaluator
can be used to morph between the geometries
of two relatively arbitrary shapes with the only restrictions being
that the two different numbers of subpaths or two shapes with
disparate winding rules may not blend together in a pleasing
manner.
The ShapeEvaluator will do the best job it can if the shapes do
not match in winding rule or number of subpaths, but the geometry
of the shapes may need to be adjusted by other means to make the
shapes more like each other for best aesthetic effect.
Note that the process of comparing two geometries and finding similar
structures between them to blend for the morphing operation can be
expensive.
Instances of ShapeEvaluator
will properly perform the necessary
geometric analysis of their arguments on every method call and attempt
to cache the information so that they can operate more quickly if called
multiple times in a row on the same pair of Shape
objects.
As a result attempting to mutate a Shape
object that is stored
in one of their keyframes may not have any effect if the associated
ShapeEvaluator
has already cached the geometry.
Also, it is advisable to use different instances of ShapeEvaluator
for every pair of keyframes being morphed so that the cached information
can be reused as much as possible.
An example of proper usage:
SGShape s = ...;
Shape s0 = ...;
Shape s1 = ...;
Shape s2 = ...;
KeyFrame k0 = KeyFrame.create(0.0f, s0, new ShapeEvaluator());
KeyFrame k1 = KeyFrame.create(0.6f, s1, new ShapeEvaluator());
KeyFrame k2 = KeyFrame.create(1.0f, s2, new ShapeEvaluator());
KeyFrames morphFrames = KeyFrames.create(s, "shape", k0, k1, k2);
Clip.create(5000, 1, morphFrames).start();