From 89ac172748587c4daa4837632094bf9820731233 Mon Sep 17 00:00:00 2001 From: Leslie Leigh Date: Mon, 11 Oct 2021 18:35:35 +0800 Subject: [PATCH] Fix exit time greater than 1 --- cocos/core/animation/marionette/graph-eval.ts | 10 ++++- tests/animation/newgenanim.test.ts | 44 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/cocos/core/animation/marionette/graph-eval.ts b/cocos/core/animation/marionette/graph-eval.ts index 4efd8822758..599661ae3dc 100644 --- a/cocos/core/animation/marionette/graph-eval.ts +++ b/cocos/core/animation/marionette/graph-eval.ts @@ -976,11 +976,13 @@ export class MotionStateEval extends StateEval { } public sampleFromPort (weight: number) { - this._source?.sample(this._fromPort.progress, weight); + const normalized = normalizeProgress(this._fromPort.progress); + this._source?.sample(normalized, weight); } public sampleToPort (weight: number) { - this._source?.sample(this._toPort.progress, weight); + const normalized = normalizeProgress(this._toPort.progress); + this._source?.sample(normalized, weight); } public getClipStatuses (baseWeight: number): Iterable { @@ -1014,6 +1016,10 @@ function calcProgressUpdate (currentProgress: number, duration: number, deltaTim return 0.0; } const progress = currentProgress + deltaTime / duration; + return progress; +} + +function normalizeProgress (progress: number) { return progress - Math.trunc(progress); } diff --git a/tests/animation/newgenanim.test.ts b/tests/animation/newgenanim.test.ts index cd8f8c07069..a71341cda4b 100644 --- a/tests/animation/newgenanim.test.ts +++ b/tests/animation/newgenanim.test.ts @@ -336,6 +336,50 @@ describe('NewGen Anim', () => { } }); + test(`Exit time > 1`, () => { + const animationGraph = new AnimationGraph(); + const layer = animationGraph.addLayer(); + const graph = layer.stateMachine; + + const animState1 = graph.addMotion(); + animState1.name = 'AnimState'; + const animState1Clip = animState1.motion = createClipMotionPositionX(1.0, 2.0, 'AnimState1Clip'); + + const animState2 = graph.addMotion(); + animState2.name = 'AnimState'; + const animState2Clip = animState2.motion = createClipMotionPositionX(1.0, 2.0, 'AnimState2Clip'); + + graph.connect(graph.entryState, animState1); + const node1To2 = graph.connect(animState1, animState2); + node1To2.duration = 0.3; + node1To2.exitConditionEnabled = true; + node1To2.exitCondition = 2.7; + + const graphEval = createAnimationGraphEval(animationGraph, new Node()); + graphEval.update(animState1Clip.clip!.duration * 1.1); + expectAnimationGraphEvalStatusLayer0(graphEval, { + current: { + clip: animState1Clip.clip!, + weight: 1.0, + }, + }); + + graphEval.update(animState1Clip.clip!.duration * 1.8); + expectAnimationGraphEvalStatusLayer0(graphEval, { + current: { + clip: animState1Clip.clip!, + weight: 0.333333, + }, + transition: { + time: 0.2, + next: { + clip: animState2Clip.clip!, + weight: 0.666667, + }, + }, + }); + }); + test(`Transition into subgraph`, () => { const animationGraph = new AnimationGraph(); const layer = animationGraph.addLayer();