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 animator play backwards error and onStateExit not triggered when crossFade finished and actualDeltaTime error #2325

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 38 additions & 0 deletions e2e/case/animator-play-backwards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @title Animation Play
* @category Animation
*/
import { Animator, Camera, DirectLight, GLTFResource, Logger, Vector3, WebGLEngine } from "@galacean/engine";
import { OrbitControl } from "@galacean/engine-toolkit";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

Logger.enable();
WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
engine.canvas.resizeByClientSize(2);
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();

// camera
const cameraEntity = rootEntity.createChild("camera_node");
cameraEntity.transform.position = new Vector3(0, 1, 5);
const camera = cameraEntity.addComponent(Camera);
cameraEntity.addComponent(OrbitControl).target = new Vector3(0, 1, 0);

const lightNode = rootEntity.createChild("light_node");
lightNode.addComponent(DirectLight).intensity = 0.6;
lightNode.transform.lookAt(new Vector3(0, 0, 1));
lightNode.transform.rotate(new Vector3(0, 90, 0));

engine.resourceManager
.load<GLTFResource>("https://gw.alipayobjects.com/os/bmw-prod/5e3c1e4e-496e-45f8-8e05-f89f2bd5e4a4.glb")
.then((gltfResource) => {
const { defaultSceneRoot } = gltfResource;
rootEntity.addChild(defaultSceneRoot);
const animator = defaultSceneRoot.getComponent(Animator);
animator.findAnimatorState("walk").speed = -1;
animator.play("walk");
updateForE2E(engine);

initScreenshot(engine, camera);
});
});
5 changes: 5 additions & 0 deletions e2e/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const E2E_CONFIG = {
caseFileName: "animator-play",
threshold: 0.1
},
playBackWards: {
category: "Animator",
caseFileName: "animator-play-backwards",
threshold: 0.1
},
playBeforeActive: {
category: "Animator",
caseFileName: "animator-play-beforeActive",
Expand Down
3 changes: 3 additions & 0 deletions e2e/fixtures/originImage/Animator_animator-play-backwards.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 35 additions & 40 deletions packages/core/src/animation/Animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,27 +548,25 @@ export class Animator extends Component {
srcPlayData.update(playDeltaTime);

const { clipTime, isForwards } = srcPlayData;
const { transitions } = state;
const { anyStateTransitions } = layer.stateMachine;

const transition =
this._applyTransitionsByCondition(
layerIndex,
layerData,
layer,
state,
layer.stateMachine.anyStateTransitions,
aniUpdate
) ||
this._applyStateTransitions(
layerIndex,
layerData,
layer,
isForwards,
srcPlayData,
state.transitions,
lastClipTime,
clipTime,
playDeltaTime,
aniUpdate
);
(anyStateTransitions.length &&
this._applyTransitionsByCondition(layerIndex, layerData, layer, state, anyStateTransitions, aniUpdate)) ||
(transitions.length &&
this._applyStateTransitions(
layerIndex,
layerData,
layer,
isForwards,
srcPlayData,
transitions,
lastClipTime,
clipTime,
playDeltaTime,
aniUpdate
));

let playCostTime: number;
if (transition) {
Expand Down Expand Up @@ -899,28 +897,25 @@ export class Animator extends Component {
playData.updateOrientation(actualDeltaTime);

const { clipTime, isForwards } = playData;
const { transitions } = state;
const { anyStateTransitions } = layer.stateMachine;

const transition =
this._applyTransitionsByCondition(
layerIndex,
layerData,
layer,
state,
stateMachine.anyStateTransitions,
aniUpdate
) ||
this._applyStateTransitions(
layerIndex,
layerData,
layer,
isForwards,
playData,
state.transitions,
clipTime,
clipTime,
actualDeltaTime,
aniUpdate
);
(anyStateTransitions.length &&
this._applyTransitionsByCondition(layerIndex, layerData, layer, state, anyStateTransitions, aniUpdate)) ||
(transitions.length &&
this._applyStateTransitions(
layerIndex,
layerData,
layer,
isForwards,
playData,
transitions,
clipTime,
clipTime,
actualDeltaTime,
aniUpdate
));

if (transition) {
this._updateState(layerIndex, layerData, layer, deltaTime, aniUpdate);
Expand Down
Loading