Skip to content

Commit

Permalink
Marionette/StateMachine: fix any state won't match proc pose states (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit authored Jun 8, 2023
1 parent fa936a9 commit 2091f46
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class TopLevelStateMachineEvaluation {
return transition;
}

if (sourceState.kind === NodeKind.animation) {
if (sourceState.kind === NodeKind.animation || sourceState.kind === NodeKind.procedural) {
const transition = this._matchAnyScoped(sourceState);
if (transition) {
return transition;
Expand All @@ -660,7 +660,7 @@ class TopLevelStateMachineEvaluation {
* - to determinate the starting state machine from where the any states are matched;
* - so we can solve transitions' relative durations.
*/
private _matchAnyScoped (realNode: VMSMInternalState) {
private _matchAnyScoped (realNode: VMSMInternalState | ProceduralPoseStateEval) {
for (let ancestor: StateMachineInfo | null = realNode.stateMachine;
ancestor !== null;
ancestor = ancestor.parent) {
Expand Down
35 changes: 34 additions & 1 deletion tests/animation/newgenanim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ describe('NewGen Anim', () => {
expect(isAnimationTransition(anyTransition)).toBe(true);
});

test('Any transition shall only match motion states', () => {
test('Any transition shall only match motion states and procedural pose state', () => {
const graphEval = createAnimationGraphEval(createAnimationGraph({
layers: [{
stateMachine: {
Expand Down Expand Up @@ -2089,6 +2089,39 @@ describe('NewGen Anim', () => {
},
});
});

test(`Any state and procedural pose state`, () => {
const animationGraph = createAnimationGraph({
variableDeclarations: { 'Transition': { type: 'trigger' } },
layers: [{
stateMachine: {
states: {
'DestinationState': { type: 'motion', transitionInEventBinding: 'onDestinationStateEntered' },
'P': { type: 'procedural', graph: { } },
},
entryTransitions: [{ to: 'P' }],
anyTransitions: [{ to: 'DestinationState', conditions: [{ type: 'trigger', variableName: 'Transition' }], }],
},
}],
});

const node = new Node();

class Listener extends Component {
onDestinationStateEntered = jest.fn();
}

const listener = node.addComponent(Listener) as Listener;

const evalMock = new AnimationGraphEvalMock(node, animationGraph);

evalMock.step(0.2);
expect(listener.onDestinationStateEntered).not.toBeCalled();

evalMock.controller.setValue('Transition', true);
evalMock.step(0.2);
expect(listener.onDestinationStateEntered).toBeCalled();
});
});

describe(`Empty state`, () => {
Expand Down

0 comments on commit 2091f46

Please sign in to comment.