Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class TopLevelStateMachineEvaluation {
return transition;
}

if (sourceState.kind === NodeKind.animation || sourceState.kind === NodeKind.procedural) {
if (isRealState(sourceState)) {
const transition = this._matchAnyScoped(sourceState);
if (transition) {
return transition;
Expand All @@ -656,7 +656,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 | ProceduralPoseStateEval): TransitionEval | null {
private _matchAnyScoped (realNode: RealState): TransitionEval | null {
for (let ancestor: StateMachineInfo | null = realNode.stateMachine;
ancestor !== null;
ancestor = ancestor.parent) {
Expand Down
66 changes: 66 additions & 0 deletions tests/animation/newgenanim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,72 @@ describe('NewGen Anim', () => {
evalMock.step(0.2);
expect(listener.onDestinationStateEntered).toBeCalled();
});

test(`Any state and empty state`, () => {
const fixture = {
defaultValue: -2,
destinationMotion: new LinearRealValueAnimationFixture(0, 1, 3),
transitionDuration: 1.5,
};

const observer = new SingleRealValueObserver(fixture.defaultValue);

const animationGraph = createAnimationGraph({
variableDeclarations: { 'Transition': { type: 'trigger' } },
layers: [{
stateMachine: {
states: {
'DestinationState': {
type: 'motion',
transitionInEventBinding: 'onDestinationStateEntered',
motion: fixture.destinationMotion.createMotion(observer.getCreateMotionContext()),
},
'Empty': { type: 'empty' },
},
entryTransitions: [{ to: 'Empty' }],
anyTransitions: [{
to: 'DestinationState',
conditions: [{ type: 'trigger', variableName: 'Transition' }],
relativeDuration: true,
duration: fixture.transitionDuration,
}],
},
}],
});

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

const listener = observer.root.addComponent(Listener) as Listener;

const evalMock = new AnimationGraphEvalMock(observer.root, animationGraph);

evalMock.step(0.2);
expect(listener.onDestinationStateEntered).not.toBeCalled();
expect(observer.value).toBe(fixture.defaultValue);

evalMock.controller.setValue('Transition', true);
const transitionStartTime = evalMock.current;
for (const transitionRatio of [0.3, 0.9]) {
evalMock.goto(transitionStartTime + fixture.transitionDuration * transitionRatio);
expect(listener.onDestinationStateEntered).toBeCalled();
expect(observer.value).toBeCloseTo(
lerp(
fixture.defaultValue,
fixture.destinationMotion.getExpected(fixture.transitionDuration * transitionRatio),
transitionRatio,
),
5,
);
}

evalMock.goto(fixture.transitionDuration * 1.2);
expect(observer.value).toBeCloseTo(
fixture.destinationMotion.getExpected(evalMock.current - transitionStartTime),
5,
);
});
});

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