apply method

void apply(
  1. double time,
  2. ActorComponent? component,
  3. double mix
)

Implementation

void apply(double time, ActorComponent? component, double mix) {
  if (_keyFrames!.isEmpty) {
    return;
  }

  int idx = 0;
  // Binary find the keyframe index.
  {
    int mid = 0;
    double element = 0.0;
    int start = 0;
    int end = _keyFrames!.length - 1;

    while (start <= end) {
      mid = (start + end) >> 1;
      element = _keyFrames![mid]!.time;
      if (element < time) {
        start = mid + 1;
      } else if (element > time) {
        end = mid - 1;
      } else {
        start = mid;
        break;
      }
    }

    idx = start;
  }

  if (idx == 0) {
    _keyFrames![0]!.apply(component, mix);
  } else {
    if (idx < _keyFrames!.length) {
      KeyFrame? fromFrame = _keyFrames![idx - 1];
      KeyFrame toFrame = _keyFrames![idx]!;
      if (time == toFrame.time) {
        toFrame.apply(component, mix);
      } else {
        fromFrame!.applyInterpolation(component, time, toFrame, mix);
      }
    } else {
      _keyFrames![idx - 1]!.apply(component, mix);
    }
  }
}