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 IkConstraint constraint = skeleton.ikConstraints[ikConstraintIndex];
if (time < frames[0]) {
if (pose == MixPose.setup) {
constraint
..mix = constraint.data.mix
..bendDirection = constraint.data.bendDirection;
} else if (pose == MixPose.current) {
constraint
..mix += (constraint.data.mix - constraint.mix) * alpha
..bendDirection = constraint.data.bendDirection;
}
return;
}
if (time >= frames[frames.length - IkConstraintTimeline.entries]) {
// Time is after last frame.
if (pose == MixPose.setup) {
constraint
..mix = constraint.data.mix +
(frames[frames.length + IkConstraintTimeline.prevMix] -
constraint.data.mix) *
alpha
..bendDirection = direction == MixDirection.mixOut
? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.prevBendDirection]
as int;
} else {
constraint.mix = constraint.mix +
(frames[frames.length + IkConstraintTimeline.prevMix] -
constraint.mix) *
alpha;
if (direction == MixDirection.mixIn) {
constraint.bendDirection =
frames[frames.length + IkConstraintTimeline.prevBendDirection]
.toInt();
}
}
return;
}
// Interpolate between the previous frame and the current frame.
final int frame =
Animation.binarySearch(frames, time, IkConstraintTimeline.entries);
final double mix = frames[frame + IkConstraintTimeline.prevMix];
final double frameTime = frames[frame];
final double percent = getCurvePercent(
frame ~/ IkConstraintTimeline.entries - 1,
1 -
(time - frameTime) /
(frames[frame + IkConstraintTimeline.prevTime] - frameTime));
if (pose == MixPose.setup) {
constraint
..mix = constraint.data.mix +
(mix +
(frames[frame + IkConstraintTimeline.mix] - mix) * percent -
constraint.data.mix) *
alpha
..bendDirection = direction == MixDirection.mixOut
? constraint.data.bendDirection
: frames[frame + IkConstraintTimeline.prevBendDirection] as int;
} else {
constraint.mix = constraint.mix +
(mix +
(frames[frame + IkConstraintTimeline.mix] - mix) * percent -
constraint.mix) *
alpha;
if (direction == MixDirection.mixIn) {
constraint.bendDirection =
frames[frame + IkConstraintTimeline.prevBendDirection].toInt();
}
}
}