From afbce9bf4fe539affd8f197ef8ee921710885cc6 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 7 Aug 2019 17:38:12 +0800 Subject: [PATCH] fix skeletal animation (#5115) * fix animation state re-init issue * create sockets when creating states --- cocos/animation/animation-component.ts | 20 +++++++++---------- cocos/animation/animation-state.ts | 1 + .../animation/skeletal-animation-component.ts | 6 ++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cocos/animation/animation-component.ts b/cocos/animation/animation-component.ts index ea910bc41a..974388f090 100644 --- a/cocos/animation/animation-component.ts +++ b/cocos/animation/animation-component.ts @@ -451,6 +451,16 @@ export class AnimationComponent extends Component implements IEventTarget { return new AnimationState(clip, name); } + protected _doCreateState (clip: AnimationClip, name: string) { + const state = this._createState(clip, name); + state._setEventTarget(this); + if (this.node) { + state.initialize(this.node); + } + this._nameToState[state.name] = state; + return state; + } + private _getStateByNameOrDefaultClip (name?: string) { if (!name) { if (!this._defaultClip) { @@ -477,16 +487,6 @@ export class AnimationComponent extends Component implements IEventTarget { } } } - - private _doCreateState (clip: AnimationClip, name: string) { - const state = this._createState(clip, name); - state._setEventTarget(this); - if (this.node) { - state.initialize(this.node); - } - this._nameToState[state.name] = state; - return state; - } } // for restore on and off diff --git a/cocos/animation/animation-state.ts b/cocos/animation/animation-state.ts index fb5fee802d..147328ce3a 100644 --- a/cocos/animation/animation-state.ts +++ b/cocos/animation/animation-state.ts @@ -345,6 +345,7 @@ export class AnimationState extends Playable { } public initialize (root: INode) { + if (this._curveLoaded) { return; } this._curveLoaded = true; this._samplerSharedGroups.length = 0; this._targetNode = root; diff --git a/cocos/animation/skeletal-animation-component.ts b/cocos/animation/skeletal-animation-component.ts index 7cbb3fa4a3..3f45d864fc 100644 --- a/cocos/animation/skeletal-animation-component.ts +++ b/cocos/animation/skeletal-animation-component.ts @@ -141,6 +141,12 @@ export class SkeletalAnimationComponent extends AnimationComponent { protected _createState (clip: AnimationClip, name?: string) { return new SkeletalAnimationState(clip, name); } + + protected _doCreateState (clip: AnimationClip, name: string) { + const state = super._doCreateState(clip, name) as SkeletalAnimationState; + state.rebuildSocketCurves(this._sockets); + return state; + } } cc.SkeletalAnimationComponent = SkeletalAnimationComponent;