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 TransformConstraint constraint =
skeleton.transformConstraints[transformConstraintIndex];
if (time < frames[0]) {
final TransformConstraintData data = constraint.data;
if (pose == MixPose.setup) {
constraint
..rotateMix = data.rotateMix
..translateMix = data.translateMix
..scaleMix = data.scaleMix
..shearMix = data.shearMix;
} else if (pose == MixPose.current) {
constraint
..rotateMix += (data.rotateMix - constraint.rotateMix) * alpha
..translateMix +=
(data.translateMix - constraint.translateMix) * alpha
..scaleMix += (data.scaleMix - constraint.scaleMix) * alpha
..shearMix += (data.shearMix - constraint.shearMix) * alpha;
}
return;
}
double rotate = 0.0, translate = 0.0, scale = 0.0, shear = 0.0;
if (time >= frames[frames.length - TransformConstraintTimeline.entries]) {
// Time is after last frame.
final int i = frames.length;
rotate = frames[i + TransformConstraintTimeline.prevRotate];
translate = frames[i + TransformConstraintTimeline.prevTranslate];
scale = frames[i + TransformConstraintTimeline.prevScale];
shear = frames[i + TransformConstraintTimeline.prevShear];
} else {
// Interpolate between the previous frame and the current frame.
final int frame = Animation.binarySearch(
frames, time, TransformConstraintTimeline.entries);
rotate = frames[frame + TransformConstraintTimeline.prevRotate];
translate = frames[frame + TransformConstraintTimeline.prevTranslate];
scale = frames[frame + TransformConstraintTimeline.prevScale];
shear = frames[frame + TransformConstraintTimeline.prevShear];
final double frameTime = frames[frame];
final double percent = getCurvePercent(
frame ~/ TransformConstraintTimeline.entries - 1,
1 -
(time - frameTime) /
(frames[frame + TransformConstraintTimeline.prevTime] -
frameTime));
rotate += (frames[frame + TransformConstraintTimeline.rotate] - rotate) *
percent;
translate +=
(frames[frame + TransformConstraintTimeline.translate] - translate) *
percent;
scale +=
(frames[frame + TransformConstraintTimeline.scale] - scale) * percent;
shear +=
(frames[frame + TransformConstraintTimeline.shear] - shear) * percent;
}
if (pose == MixPose.setup) {
final TransformConstraintData data = constraint.data;
constraint
..rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha
..translateMix =
data.translateMix + (translate - data.translateMix) * alpha
..scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha
..shearMix = data.shearMix + (shear - data.shearMix) * alpha;
} else {
constraint
..rotateMix += (rotate - constraint.rotateMix) * alpha
..translateMix += (translate - constraint.translateMix) * alpha
..scaleMix += (scale - constraint.scaleMix) * alpha
..shearMix += (shear - constraint.shearMix) * alpha;
}
}