Skip to content

Commit

Permalink
fix: cubicInterpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhuang committed Oct 12, 2021
1 parent 451c765 commit 0e7dd50
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions packages/core/src/animation/AnimationCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ export class AnimationCurve {
case InterpolationType.Linear:
value = this._evaluateLinear(curIndex, nextIndex, t);
break;
case InterpolationType.CubicSpine:
value = this._evaluateCubicSpline(curIndex, nextIndex, t);
break;
case InterpolationType.Step:
value = this._evaluateStep(nextIndex);
break;
case InterpolationType.CubicSpine:
case InterpolationType.Hermite:
value = this._evaluateHermite(curIndex, nextIndex, t, dur);
}
Expand Down Expand Up @@ -206,24 +204,6 @@ export class AnimationCurve {
}
}

private _evaluateCubicSpline(frameIndex: number, nextFrameIndex: number, t: number): Vector3 {
const { keys } = this;
const squared = t * t;
const cubed = t * squared;
const part1 = 2.0 * cubed - 3.0 * squared + 1.0;
const part2 = -2.0 * cubed + 3.0 * squared;
const part3 = cubed - 2.0 * squared + t;
const part4 = cubed - squared;

const t1: Vector3 = (<Vector3Keyframe>keys[frameIndex]).value;
const v1: Vector3 = (<Vector3Keyframe>keys[frameIndex + 1]).value;
const t2: Vector3 = (<Vector3Keyframe>keys[frameIndex + 2]).value;
const v2: Vector3 = (<Vector3Keyframe>keys[nextFrameIndex + 1]).value;

//CM:clone
return v1.scale(part1).add(v2.scale(part2)).add(t1.scale(part3)).add(t2.scale(part4)).clone();
}

private _evaluateStep(nextFrameIndex: number): InterpolableValue {
const { _valueSize, keys } = this;
if (_valueSize === 1) {
Expand Down

0 comments on commit 0e7dd50

Please sign in to comment.