Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exit time greater than 1 #70

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cocos/core/animation/marionette/graph-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClipStatus> {
Expand Down Expand Up @@ -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);
}

Expand Down
44 changes: 44 additions & 0 deletions tests/animation/newgenanim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down