From aa3c2e8931f30119ef6bf7c4fee49d9b93086d62 Mon Sep 17 00:00:00 2001 From: Leslie Date: Tue, 29 Jan 2019 11:25:14 +0800 Subject: [PATCH] fix animation bug --- cocos/3d/assets/animation-clip.ts | 11 ++++++++++- cocos/3d/framework/animation-component.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cocos/3d/assets/animation-clip.ts b/cocos/3d/assets/animation-clip.ts index 321ff63aaf..1256937441 100644 --- a/cocos/3d/assets/animation-clip.ts +++ b/cocos/3d/assets/animation-clip.ts @@ -198,7 +198,7 @@ export class AnimationSampler { const getState = (channel: IAnimationChannel) => { const iNode = this._animationTarget.get(channel.target); - if (!iNode) { + if (iNode === undefined) { return null; } return this._nodeSamplingStates[iNode]; @@ -299,6 +299,9 @@ class NodeSamplingState { * https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions */ public blendRotation (rotation: Quat, weight: number) { + if (weight === 0) { + return; + } const t = weight / (this._sumRotWeight + weight); quat.slerp(tmpquat, this._target.getRotation(), rotation, t); this._target.setRotation(tmpquat); @@ -306,6 +309,12 @@ class NodeSamplingState { } public apply () { + if (CC_DEV) { + if (this._sumPosWeight > 1.0 || this._sumRotWeight > 1.0 || this._sumScaleWeight > 1.0) { + throw new Error(`Unexpected.`); + } + } + if (this._sumPosWeight < 1.0) { this.blendPosition(this._defaultPosition, 1.0 - this._sumPosWeight); } diff --git a/cocos/3d/framework/animation-component.ts b/cocos/3d/framework/animation-component.ts index c308fb1f82..19b9578021 100644 --- a/cocos/3d/framework/animation-component.ts +++ b/cocos/3d/framework/animation-component.ts @@ -216,7 +216,7 @@ class AnimationCtrl { } // handle playing - if (this._current) { + else if (this._current) { const t0 = this._getTime(this._current); this._animationSampler.sample(this._current.clip, t0, 1.0); this._current.time += deltaTime;