apply method

  1. @override
void apply(
  1. Skeleton skeleton,
  2. double lastTime,
  3. double time,
  4. List<Event?> events,
  5. double alpha,
  6. MixPose pose,
  7. MixDirection direction,
)
override

Implementation

@override
void apply(Skeleton skeleton, double lastTime, double time,
    List<Event?> events, double alpha, MixPose pose, MixDirection direction) {
  final Bone bone = skeleton.bones[boneIndex];
  final Float32List frames = this.frames;
  if (time < frames[0]) {
    if (pose == MixPose.setup) {
      bone.rotation = bone.data.rotation;
    } else if (pose == MixPose.current) {
      double r = bone.data.rotation - bone.rotation;
      r -= (16384 - (16384.499999999996 - r / 360).toInt()) * 360;
      bone.rotation = bone.rotation + r * alpha;
    }
    return;
  }

  if (time >= frames[frames.length - RotateTimeline.entries]) {
    // Time is after last frame.
    if (pose == MixPose.setup) {
      bone.rotation = bone.data.rotation +
          frames[frames.length + RotateTimeline.prevRotation] * alpha;
    } else {
      double r = bone.data.rotation +
          frames[frames.length + RotateTimeline.prevRotation] -
          bone.rotation;
      r -= (16384 - (16384.499999999996 - r / 360).toInt()) * 360;
      bone.rotation = bone.rotation + r * alpha;
    }
    return;
  }

  // Interpolate between the previous frame and the current frame.
  final int frame =
      Animation.binarySearch(frames, time, RotateTimeline.entries);
  final double prevRotation = frames[frame + RotateTimeline.prevRotation];
  final double frameTime = frames[frame];
  final double percent = getCurvePercent(
      (frame >> 1) - 1,
      1 -
          (time - frameTime) /
              (frames[frame + RotateTimeline.prevTime] - frameTime));

  double r = frames[frame + RotateTimeline.rotation] - prevRotation;
  r -= (16384 - (16384.499999999996 - r / 360).toInt()) * 360;
  r = prevRotation + r * percent;
  if (pose == MixPose.setup) {
    r -= (16384 - (16384.499999999996 - r / 360).toInt()) * 360;
    bone.rotation = bone.data.rotation + r * alpha;
  } else {
    r = bone.data.rotation + r - bone.rotation;
    r -= (16384 - (16384.499999999996 - r / 360).toInt()) * 360;
    bone.rotation = bone.rotation + r * alpha;
  }
}