apply method
void
apply(
- Skeleton skeleton,
- double lastTime,
- double time,
- List<
Event?> firedEvents, - double alpha,
- MixPose pose,
- MixDirection direction,
override
Implementation
@override
void apply(
Skeleton skeleton,
double lastTime,
double time,
List<Event?> firedEvents,
double alpha,
MixPose pose,
MixDirection direction) {
final Float32List frames = this.frames;
final PathConstraint constraint =
skeleton.pathConstraints[pathConstraintIndex];
if (time < frames[0]) {
if (pose == MixPose.setup) {
constraint
..rotateMix = constraint.data.rotateMix
..translateMix = constraint.data.translateMix;
} else if (pose == MixPose.current) {
constraint
..rotateMix +=
(constraint.data.rotateMix - constraint.rotateMix) * alpha
..translateMix +=
(constraint.data.translateMix - constraint.translateMix) * alpha;
}
return;
}
double rotate = 0.0, translate = 0.0;
if (time >= frames[frames.length - PathConstraintMixTimeline.entries]) {
// Time is after last frame.
rotate = frames[frames.length + PathConstraintMixTimeline.prevRotate];
translate =
frames[frames.length + PathConstraintMixTimeline.prevTranslate];
} else {
// Interpolate between the previous frame and the current frame.
final int frame = Animation.binarySearch(
frames, time, PathConstraintMixTimeline.entries);
rotate = frames[frame + PathConstraintMixTimeline.prevRotate];
translate = frames[frame + PathConstraintMixTimeline.prevTranslate];
final double frameTime = frames[frame];
final double percent = getCurvePercent(
frame ~/ PathConstraintMixTimeline.entries - 1,
1 -
(time - frameTime) /
(frames[frame + PathConstraintMixTimeline.prevTime] -
frameTime));
rotate +=
(frames[frame + PathConstraintMixTimeline.rotate] - rotate) * percent;
translate +=
(frames[frame + PathConstraintMixTimeline.translate] - translate) *
percent;
}
if (pose == MixPose.setup) {
constraint
..rotateMix = constraint.data.rotateMix +
(rotate - constraint.data.rotateMix) * alpha
..translateMix = constraint.data.translateMix +
(translate - constraint.data.translateMix) * alpha;
} else {
constraint
..rotateMix += (rotate - constraint.rotateMix) * alpha
..translateMix += (translate - constraint.translateMix) * alpha;
}
}