Skip to content

Commit 69ae036

Browse files
committed
fix bug: #19162
1 parent 411f98d commit 69ae036

6 files changed

Lines changed: 50 additions & 8 deletions

File tree

cocos/animation/marionette/pose-graph/instantiation.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class InstantiatedPoseGraph {
2525
constructor (
2626
private _rootPoseNode: PoseNode | undefined,
2727
private _countingPlayMotionNodes: readonly PoseNodePlayMotion[] | undefined,
28+
private _allPoseNodes: readonly PoseNode[],
2829
) {
2930

3031
}
@@ -33,6 +34,14 @@ class InstantiatedPoseGraph {
3334
this._rootPoseNode?.bind(context);
3435
}
3536

37+
public overrideClips (context: AnimationGraphBindingContext): void {
38+
const { _allPoseNodes: allPoseNodes } = this;
39+
const nNodes = allPoseNodes.length;
40+
for (let iNode = 0; iNode < nNodes; ++iNode) {
41+
allPoseNodes[iNode].overrideClips(context);
42+
}
43+
}
44+
3645
public settle (context: AnimationGraphSettleContext): void {
3746
this._rootPoseNode?.settle(context);
3847
}
@@ -97,6 +106,7 @@ export function instantiatePoseGraph (
97106
return new InstantiatedPoseGraph(
98107
undefined,
99108
mayCountMotionTime ? [] : undefined,
109+
[],
100110
);
101111
}
102112
// If the output node has a binding, it must be pose node.
@@ -113,11 +123,13 @@ export function instantiatePoseGraph (
113123
);
114124
assertIsTrue(mainRecord instanceof PoseNode);
115125

126+
const allPoseNodes = Array.from(instantiationMap.values()).filter((node): node is PoseNode => node instanceof PoseNode);
116127
return new InstantiatedPoseGraph(
117128
mainRecord,
118129
mayCountMotionTime
119130
? Array.from(instantiationMap.values()).filter((node): node is PoseNodePlayMotion => node instanceof PoseNodePlayMotion)
120131
: undefined,
132+
allPoseNodes,
121133
);
122134
}
123135

@@ -287,6 +299,7 @@ function linkPoseNode (
287299

288300
if (producerOutputIndex !== 0) {
289301
// Rule: pose nodes have and only have one output.
302+
// eslint-disable-next-line no-implicit-coercion
290303
warn(`Node ${producerNode.toString()} does not have specified output ${producerOutputIndex}.`);
291304
return;
292305
}

cocos/animation/marionette/pose-graph/pose-node.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export abstract class PoseNode extends PoseGraphNode {
5151
*/
5252
public abstract settle (context: AnimationGraphSettleContext): void;
5353

54+
/**
55+
* Rebinds motions when clip overrides on the binding context change.
56+
* Pose nodes that own motion evaluations or nested graphs override this.
57+
*/
58+
public overrideClips (_context: AnimationGraphBindingContext): void {}
59+
5460
/**
5561
* Reenter this pose nodes.
5662
*
@@ -94,12 +100,16 @@ export abstract class PoseNode extends PoseGraphNode {
94100

95101
if (POSE_NODE_EVALUATION_STACK_ORDER_DEBUG_ENABLED) {
96102
// The stack should certainly increase 1.
97-
assertIsTrue(context._stackSize_debugging === stackSizeBefore + 1,
98-
`PoseNode.doEvaluate() should certainly push a pose node onto the stack and return it.`);
103+
assertIsTrue(
104+
context._stackSize_debugging === stackSizeBefore + 1,
105+
`PoseNode.doEvaluate() should certainly push a pose node onto the stack and return it.`
106+
);
99107
// The returned pose should be the increased pose, that's,
100108
// can not return a already-popped pose.
101-
assertIsTrue(context._isStackTopPose_debugging(pose),
102-
`PoseNode.doEvaluate() should certainly push a pose node onto the stack and return it.`);
109+
assertIsTrue(
110+
context._isStackTopPose_debugging(pose),
111+
`PoseNode.doEvaluate() should certainly push a pose node onto the stack and return it.`
112+
);
103113
}
104114

105115
const currentSpace = pose._poseTransformSpace;

cocos/animation/marionette/pose-graph/pose-nodes/play-motion.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EDITOR } from 'internal:constants';
2-
import { ccclass, displayName, editable, serializable, unit } from '../../../../core/data/decorators';
2+
import { ccclass, editable, serializable, unit } from '../../../../core/data/decorators';
33
import { CLASS_NAME_PREFIX_ANIM } from '../../../define';
44
import { ClipMotion } from '../../motion/clip-motion';
55
import { createEval } from '../../create-eval';
@@ -79,6 +79,10 @@ export class PoseNodePlayMotion extends PoseNode {
7979
}
8080
}
8181

82+
public overrideClips (context: AnimationGraphBindingContext): void {
83+
this._workspace?.motionEval.overrideClips(context);
84+
}
85+
8286
public settle (context: AnimationGraphSettleContext): void {
8387
// override
8488
}

cocos/animation/marionette/pose-graph/pose-nodes/sample-motion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export class PoseNodeSampleMotion extends PoseNode {
5151
this._workspace = workspace;
5252
}
5353

54+
public overrideClips (context: AnimationGraphBindingContext): void {
55+
this._workspace?.motionEval.overrideClips(context);
56+
}
57+
5458
public settle (context: AnimationGraphSettleContext): void {
5559
// Do nothing.
5660
}

cocos/animation/marionette/pose-graph/pose-nodes/state-machine.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class PoseNodeStateMachine extends PoseNode {
4545
);
4646
}
4747

48+
public overrideClips (context: AnimationGraphBindingContext): void {
49+
this._stateMachineEval?.overrideClips(context);
50+
}
51+
4852
public settle (context: AnimationGraphSettleContext): void {
4953
this._stateMachineEval?.settle(context);
5054
}

cocos/animation/marionette/state-machine/state-machine-eval.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../animation-graph';
77
import { MotionEval, MotionPort } from '../motion';
88
import { createEval } from '../create-eval';
9-
import { BindContext, validateVariableExistence, validateVariableType, VariableType } from '../parametric';
9+
import { validateVariableExistence, validateVariableType, VariableType } from '../parametric';
1010
import { ConditionEval, TriggerCondition } from './condition';
1111
import { MotionState } from './motion-state';
1212
import { warnID, assertIsTrue, assertIsNonNullable, Pool, approx, clamp01 } from '../../../core';
@@ -21,10 +21,8 @@ import {
2121
TriggerResetter,
2222
} from '../animation-graph-context';
2323
import { blendPoseInto, Pose } from '../../core/pose';
24-
import { PoseNode } from '../pose-graph/pose-node';
2524
import { instantiatePoseGraph, InstantiatedPoseGraph } from '../pose-graph/instantiation';
2625
import { ConditionEvaluationContext } from './condition/condition-base';
27-
import { ReadonlyClipOverrideMap } from '../clip-overriding';
2826
import { AnimationGraphEventBinding } from '../event/event-binding';
2927

3028
/**
@@ -257,6 +255,11 @@ class TopLevelStateMachineEvaluation {
257255
const node = motionStates[iMotionState];
258256
node.overrideClips(context);
259257
}
258+
const { _proceduralPoseStates: proceduralPoseStates } = this;
259+
const nProcedural = proceduralPoseStates.length;
260+
for (let iProcedural = 0; iProcedural < nProcedural; ++iProcedural) {
261+
proceduralPoseStates[iProcedural].overrideClips(context);
262+
}
260263
}
261264

262265
private declare _controller: AnimationController;
@@ -1451,6 +1454,10 @@ class ProceduralPoseStateEval extends EventifiedStateEval {
14511454
return this._instantiatedPoseGraph.countMotionTime();
14521455
}
14531456

1457+
public overrideClips (context: AnimationGraphBindingContext): void {
1458+
this._instantiatedPoseGraph.overrideClips(context);
1459+
}
1460+
14541461
private _instantiatedPoseGraph: InstantiatedPoseGraph;
14551462

14561463
private readonly _statusCache: MotionStateStatus = createStateStatusCache();

0 commit comments

Comments
 (0)