mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
AnimationGraph: fix clip overriding in nested structure (#15932)
* Bug introduce FF * Fix clip overriding in animation graph * Fix lint * Fix lint
This commit is contained in:
committed by
GitHub
parent
2b266acce7
commit
8403962f94
@@ -289,10 +289,12 @@ const checkBindStatus = (bindStarted = false): MethodDecorator => (_, _propertyK
|
||||
if (vendor) {
|
||||
// eslint-disable-next-line func-names
|
||||
descriptor.value = function (this: { readonly _bindStarted: boolean }, ...args: unknown[]): any {
|
||||
assertIsTrue(this._bindStarted === bindStarted,
|
||||
assertIsTrue(
|
||||
this._bindStarted === bindStarted,
|
||||
bindStarted
|
||||
? `The operation is invalid since bind has not been started.`
|
||||
: `The operation is invalid since bind has already been started.`);
|
||||
: `The operation is invalid since bind has already been started.`,
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return vendor.call(this, ...args);
|
||||
};
|
||||
|
||||
@@ -80,9 +80,7 @@ export class AnimationGraphEval {
|
||||
const poseLayoutMaintainer = new AnimationGraphPoseLayoutMaintainer(root, this._auxiliaryCurveRegistry);
|
||||
this._poseLayoutMaintainer = poseLayoutMaintainer;
|
||||
|
||||
const bindingContext = new AnimationGraphBindingContext(
|
||||
root, poseLayoutMaintainer, this._varInstances, controller,
|
||||
);
|
||||
const bindingContext = new AnimationGraphBindingContext(root, poseLayoutMaintainer, this._varInstances, controller);
|
||||
bindingContext._setClipOverrides(clipOverrides ?? undefined);
|
||||
this._bindingContext = bindingContext;
|
||||
|
||||
@@ -97,7 +95,6 @@ export class AnimationGraphEval {
|
||||
this._rootPoseNode = new DefaultTopLevelPoseNode(
|
||||
graph,
|
||||
bindingContext,
|
||||
clipOverrides,
|
||||
poseStashAllocator,
|
||||
);
|
||||
|
||||
@@ -221,7 +218,8 @@ export class AnimationGraphEval {
|
||||
|
||||
poseLayoutMaintainer.startBind();
|
||||
|
||||
this._rootPoseNode.overrideClips(overrides, this._bindingContext);
|
||||
this._bindingContext._setClipOverrides(overrides);
|
||||
this._rootPoseNode.overrideClips(this._bindingContext);
|
||||
|
||||
this._updateAfterPossiblePoseLayoutChange();
|
||||
}
|
||||
|
||||
@@ -80,12 +80,15 @@ export class AnimationBlend1D extends AnimationBlend {
|
||||
|
||||
public [createEval] (
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
): any {
|
||||
const evaluation = new AnimationBlend1DEval(
|
||||
context, clipOverrides, ignoreEmbeddedPlayers,
|
||||
this, this._items, this._items.map(({ threshold }) => threshold), 0.0,
|
||||
context,
|
||||
ignoreEmbeddedPlayers,
|
||||
this,
|
||||
this._items,
|
||||
this._items.map(({ threshold }) => threshold),
|
||||
0.0,
|
||||
);
|
||||
const initialValue = bindOr(
|
||||
context,
|
||||
@@ -109,11 +112,13 @@ class AnimationBlend1DEval extends AnimationBlendEval {
|
||||
|
||||
constructor (
|
||||
context: AnimationGraphBindingContext,
|
||||
overrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
base: AnimationBlend, items: AnimationBlendItem[], thresholds: readonly number[], input: number,
|
||||
base: AnimationBlend,
|
||||
items: AnimationBlendItem[],
|
||||
thresholds: readonly number[],
|
||||
input: number,
|
||||
) {
|
||||
super(context, overrides, ignoreEmbeddedPlayers, base, items, [input]);
|
||||
super(context, ignoreEmbeddedPlayers, base, items, [input]);
|
||||
this._thresholds = thresholds;
|
||||
this.doEval();
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@ export class AnimationBlend2D extends AnimationBlend {
|
||||
|
||||
public [createEval] (
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
): AnimationBlendEval {
|
||||
const { algorithm } = this;
|
||||
@@ -126,7 +125,6 @@ export class AnimationBlend2D extends AnimationBlend {
|
||||
assertIsTrue(this._polarSpaceGBI, `The polar space interpolator is not setup correctly!`);
|
||||
evaluation = new PolarSpaceGradientBandBlend2DEval(
|
||||
context,
|
||||
clipOverrides,
|
||||
ignoreEmbeddedPlayers,
|
||||
this,
|
||||
this._items,
|
||||
@@ -141,7 +139,6 @@ export class AnimationBlend2D extends AnimationBlend {
|
||||
case Algorithm.FREEFORM_CARTESIAN:
|
||||
evaluation = new AnimationBlend2DEval(
|
||||
context,
|
||||
clipOverrides,
|
||||
ignoreEmbeddedPlayers,
|
||||
this,
|
||||
this._items,
|
||||
@@ -200,7 +197,6 @@ class AnimationBlend2DEval extends AnimationBlendEval {
|
||||
|
||||
constructor (
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
base: AnimationBlend,
|
||||
items: AnimationBlendItem[],
|
||||
@@ -208,7 +204,7 @@ class AnimationBlend2DEval extends AnimationBlendEval {
|
||||
algorithm: Algorithm.SIMPLE_DIRECTIONAL | Algorithm.FREEFORM_CARTESIAN,
|
||||
inputs: [number, number],
|
||||
) {
|
||||
super(context, clipOverrides, ignoreEmbeddedPlayers, base, items, inputs);
|
||||
super(context, ignoreEmbeddedPlayers, base, items, inputs);
|
||||
this._thresholds = thresholds;
|
||||
this._algorithm = algorithm;
|
||||
this.doEval();
|
||||
@@ -236,14 +232,13 @@ class PolarSpaceGradientBandBlend2DEval extends AnimationBlendEval {
|
||||
|
||||
constructor (
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
base: AnimationBlend,
|
||||
items: AnimationBlendItem[],
|
||||
interpolator: PolarSpaceGradientBandInterpolator2D,
|
||||
inputs: [number, number],
|
||||
) {
|
||||
super(context, clipOverrides, ignoreEmbeddedPlayers, base, items, inputs);
|
||||
super(context, ignoreEmbeddedPlayers, base, items, inputs);
|
||||
this._interpolator = interpolator;
|
||||
this.doEval();
|
||||
}
|
||||
|
||||
@@ -74,12 +74,10 @@ export class AnimationBlendDirect extends AnimationBlend {
|
||||
|
||||
public [createEval] (
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
): AnimationBlendDirectEval {
|
||||
const myEval: AnimationBlendDirectEval = new AnimationBlendDirectEval(
|
||||
context,
|
||||
clipOverrides,
|
||||
ignoreEmbeddedPlayers,
|
||||
this,
|
||||
this._items,
|
||||
|
||||
@@ -27,7 +27,6 @@ import { Motion, MotionEval, MotionPort } from './motion';
|
||||
import { createEval } from '../create-eval';
|
||||
import { VariableTypeMismatchedError } from '../errors';
|
||||
import { ClipStatus } from '../state-machine/state-machine-eval';
|
||||
import type { ReadonlyClipOverrideMap } from '../clip-overriding';
|
||||
|
||||
import { CLASS_NAME_PREFIX_ANIM } from '../../define';
|
||||
import { getMotionRuntimeID, RUNTIME_ID_ENABLED } from '../graph-debug';
|
||||
@@ -37,14 +36,6 @@ import { blendPoseInto, Pose } from '../../core/pose';
|
||||
|
||||
const { ccclass, serializable } = _decorator;
|
||||
|
||||
export interface AnimationBlend extends Motion, EditorExtendable {
|
||||
[createEval] (
|
||||
_context: AnimationGraphBindingContext,
|
||||
overrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
): MotionEval | null;
|
||||
}
|
||||
|
||||
@ccclass(`${CLASS_NAME_PREFIX_ANIM}AnimationBlendItem`)
|
||||
export class AnimationBlendItem {
|
||||
@serializable
|
||||
@@ -73,7 +64,7 @@ export abstract class AnimationBlend extends Motion {
|
||||
}
|
||||
}
|
||||
|
||||
export class AnimationBlendEval implements MotionEval {
|
||||
export abstract class AnimationBlendEval implements MotionEval {
|
||||
public declare runtimeId?: number;
|
||||
|
||||
private declare _childEvaluators: (MotionEval | null)[];
|
||||
@@ -82,13 +73,12 @@ export class AnimationBlendEval implements MotionEval {
|
||||
|
||||
constructor (
|
||||
context: AnimationGraphBindingContext,
|
||||
overrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
base: AnimationBlend,
|
||||
children: AnimationBlendItem[],
|
||||
inputs: number[],
|
||||
) {
|
||||
this._childEvaluators = children.map((child) => child.motion?.[createEval](context, overrides, ignoreEmbeddedPlayers) ?? null);
|
||||
this._childEvaluators = children.map((child) => child.motion?.[createEval](context, ignoreEmbeddedPlayers) ?? null);
|
||||
this._weights = new Array(this._childEvaluators.length).fill(0);
|
||||
this._inputs = [...inputs];
|
||||
if (RUNTIME_ID_ENABLED) {
|
||||
@@ -180,9 +170,9 @@ export class AnimationBlendEval implements MotionEval {
|
||||
return context.pushDefaultedPose();
|
||||
}
|
||||
|
||||
public overrideClips (overrides: ReadonlyClipOverrideMap, context: AnimationGraphBindingContext): void {
|
||||
public overrideClips (context: AnimationGraphBindingContext): void {
|
||||
for (let iChild = 0; iChild < this._childEvaluators.length; ++iChild) {
|
||||
this._childEvaluators[iChild]?.overrideClips(overrides, context);
|
||||
this._childEvaluators[iChild]?.overrideClips(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,9 +185,7 @@ export class AnimationBlendEval implements MotionEval {
|
||||
this.eval(this._weights, this._inputs);
|
||||
}
|
||||
|
||||
protected eval (_weights: number[], _inputs: readonly number[]): void {
|
||||
|
||||
}
|
||||
protected abstract eval (_weights: number[], _inputs: readonly number[]): void;
|
||||
}
|
||||
|
||||
class AnimationBlendPort implements MotionPort {
|
||||
@@ -212,7 +200,7 @@ class AnimationBlendPort implements MotionPort {
|
||||
return this._host.__evaluatePort(this, progress, context);
|
||||
}
|
||||
|
||||
public reenter () {
|
||||
public reenter (): void {
|
||||
const { childPorts } = this;
|
||||
const nChildPorts = childPorts.length;
|
||||
for (let iChild = 0; iChild < nChildPorts; ++iChild) {
|
||||
|
||||
@@ -48,13 +48,12 @@ export class ClipMotion extends Motion {
|
||||
|
||||
public [createEval] (
|
||||
context: AnimationGraphBindingContext,
|
||||
overrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
): ClipMotionEval | null {
|
||||
if (!this.clip) {
|
||||
return null;
|
||||
}
|
||||
const clipMotionEval = new ClipMotionEval(context, this.clip, overrides, ignoreEmbeddedPlayers);
|
||||
const clipMotionEval = new ClipMotionEval(context, this.clip, ignoreEmbeddedPlayers);
|
||||
if (RUNTIME_ID_ENABLED) {
|
||||
clipMotionEval.runtimeId = getMotionRuntimeID(this);
|
||||
}
|
||||
@@ -82,12 +81,11 @@ class ClipMotionEval implements MotionEval {
|
||||
constructor (
|
||||
context: AnimationGraphBindingContext,
|
||||
clip: AnimationClip,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
) {
|
||||
this._originalClip = clip;
|
||||
this._ignoreEmbeddedPlayers = ignoreEmbeddedPlayers;
|
||||
const overriding = clipOverrides?.get(clip) ?? clip;
|
||||
const overriding = context.clipOverrides?.get(clip) ?? clip;
|
||||
this._setClip(overriding, context);
|
||||
}
|
||||
|
||||
@@ -160,15 +158,15 @@ class ClipMotionEval implements MotionEval {
|
||||
return pose;
|
||||
}
|
||||
|
||||
public overrideClips (clipOverrides: ReadonlyClipOverrideMap, context: AnimationGraphBindingContext): void {
|
||||
public overrideClips (context: AnimationGraphBindingContext): void {
|
||||
const { _originalClip: originalClip } = this;
|
||||
const overriding = clipOverrides.get(originalClip);
|
||||
const overriding = context.clipOverrides?.get(originalClip);
|
||||
if (overriding) {
|
||||
this._setClip(overriding, context);
|
||||
}
|
||||
}
|
||||
|
||||
public reenter () {
|
||||
public reenter (): void {
|
||||
this._frameEventEval?.reset();
|
||||
}
|
||||
|
||||
@@ -216,7 +214,7 @@ class ClipMotionPort implements MotionPort {
|
||||
return this._eval[evaluatePortTag](progress, context);
|
||||
}
|
||||
|
||||
public reenter () {
|
||||
public reenter (): void {
|
||||
this._eval.reenter();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ export interface MotionEval {
|
||||
|
||||
getClipStatuses(baseWeight: number): Iterator<ClipStatus>;
|
||||
|
||||
overrideClips(clipOverrides: ReadonlyClipOverrideMap, context: AnimationGraphBindingContext): void;
|
||||
overrideClips(context: AnimationGraphBindingContext): void;
|
||||
|
||||
createPort(): MotionPort;
|
||||
}
|
||||
@@ -69,7 +69,6 @@ export interface MotionEval {
|
||||
export abstract class Motion extends EditorExtendable {
|
||||
abstract [createEval] (
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
ignoreEmbeddedPlayers: boolean,
|
||||
): MotionEval | null;
|
||||
|
||||
@@ -79,7 +78,9 @@ export abstract class Motion extends EditorExtendable {
|
||||
* // TODO: HACK
|
||||
* @internal
|
||||
*/
|
||||
__callOnAfterDeserializeRecursive (): void { }
|
||||
__callOnAfterDeserializeRecursive (): void {
|
||||
// Can be overrode in subclasses.
|
||||
}
|
||||
}
|
||||
|
||||
export interface MotionPort {
|
||||
|
||||
@@ -4,7 +4,6 @@ import { AnimationGraph, Layer } from '../animation-graph';
|
||||
import { AnimationGraphBindingContext, AnimationGraphEvaluationContext,
|
||||
AnimationGraphSettleContext, AnimationGraphUpdateContext } from '../animation-graph-context';
|
||||
import { AnimationMask } from '../animation-mask';
|
||||
import { ReadonlyClipOverrideMap } from '../clip-overriding';
|
||||
import { TopLevelStateMachineEvaluation } from '../state-machine/state-machine-eval';
|
||||
import { PoseNode } from './pose-node';
|
||||
import { RuntimeMotionSyncManager } from './motion-sync/runtime-motion-sync';
|
||||
@@ -14,7 +13,6 @@ export class DefaultTopLevelPoseNode extends PoseNode {
|
||||
constructor (
|
||||
graph: AnimationGraph,
|
||||
bindingContext: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
poseStashAllocator: PoseStashAllocator,
|
||||
) {
|
||||
super();
|
||||
@@ -23,7 +21,6 @@ export class DefaultTopLevelPoseNode extends PoseNode {
|
||||
const record = new LayerEvaluationRecord(
|
||||
layer,
|
||||
bindingContext,
|
||||
clipOverrides,
|
||||
poseStashAllocator,
|
||||
);
|
||||
|
||||
@@ -69,13 +66,13 @@ export class DefaultTopLevelPoseNode extends PoseNode {
|
||||
return this._layerRecords[layerIndex].stateMachineEvaluation;
|
||||
}
|
||||
|
||||
public overrideClips (overrides: ReadonlyClipOverrideMap, context: AnimationGraphBindingContext): void {
|
||||
public overrideClips (context: AnimationGraphBindingContext): void {
|
||||
const { _layerRecords: layerRecords } = this;
|
||||
const nLayers = layerRecords.length;
|
||||
for (let iLayer = 0; iLayer < nLayers; ++iLayer) {
|
||||
const layerRecord = layerRecords[iLayer];
|
||||
context._pushAdditiveFlag(layerRecord.additive);
|
||||
layerRecord.stateMachineEvaluation.overrideClips(overrides, context);
|
||||
layerRecord.stateMachineEvaluation.overrideClips(context);
|
||||
context._popAdditiveFlag();
|
||||
}
|
||||
}
|
||||
@@ -116,7 +113,6 @@ class LayerEvaluationRecord {
|
||||
constructor (
|
||||
layer: Layer,
|
||||
bindingContext: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
poseStashAllocator: PoseStashAllocator,
|
||||
) {
|
||||
const stashManager = new RuntimeStashManager(poseStashAllocator);
|
||||
@@ -145,7 +141,6 @@ class LayerEvaluationRecord {
|
||||
layer.stateMachine,
|
||||
layer.name,
|
||||
bindingContext,
|
||||
clipOverrides,
|
||||
);
|
||||
bindingContext._popAdditiveFlag();
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ export class PoseNodePlayMotion extends PoseNode {
|
||||
if (!motion) {
|
||||
return;
|
||||
}
|
||||
const motionEval = motion[createEval](context, context.clipOverrides ?? null, false);
|
||||
const motionEval = motion[createEval](context, false);
|
||||
if (!motionEval) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export class PoseNodeSampleMotion extends PoseNode {
|
||||
if (!motion) {
|
||||
return;
|
||||
}
|
||||
const motionEval = motion[createEval](context, context.clipOverrides ?? null, true);
|
||||
const motionEval = motion[createEval](context, true);
|
||||
if (!motionEval) {
|
||||
return;
|
||||
}
|
||||
@@ -51,11 +51,16 @@ export class PoseNodeSampleMotion extends PoseNode {
|
||||
this._workspace = workspace;
|
||||
}
|
||||
|
||||
public settle (context: AnimationGraphSettleContext): void { }
|
||||
public settle (context: AnimationGraphSettleContext): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public reenter (): void { }
|
||||
public reenter (): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected doUpdate (context: AnimationGraphUpdateContext): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected doEvaluate (context: AnimationGraphEvaluationContext): Pose {
|
||||
|
||||
@@ -42,7 +42,6 @@ export class PoseNodeStateMachine extends PoseNode {
|
||||
this.stateMachine,
|
||||
'',
|
||||
context,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,6 @@ class TopLevelStateMachineEvaluation {
|
||||
stateMachine: StateMachine,
|
||||
name: string,
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
) {
|
||||
this._additive = context.additive;
|
||||
this.name = name;
|
||||
@@ -128,7 +127,6 @@ class TopLevelStateMachineEvaluation {
|
||||
stateMachine,
|
||||
null,
|
||||
context,
|
||||
clipOverrides,
|
||||
name,
|
||||
);
|
||||
this._topLevelEntry = entry;
|
||||
@@ -252,12 +250,12 @@ class TopLevelStateMachineEvaluation {
|
||||
}
|
||||
}
|
||||
|
||||
public overrideClips (overrides: ReadonlyClipOverrideMap, context: AnimationGraphBindingContext): void {
|
||||
public overrideClips (context: AnimationGraphBindingContext): void {
|
||||
const { _motionStates: motionStates } = this;
|
||||
const nMotionStates = motionStates.length;
|
||||
for (let iMotionState = 0; iMotionState < nMotionStates; ++iMotionState) {
|
||||
const node = motionStates[iMotionState];
|
||||
node.overrideClips(overrides, context);
|
||||
node.overrideClips(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +283,6 @@ class TopLevelStateMachineEvaluation {
|
||||
graph: StateMachine,
|
||||
parentStateMachineInfo: StateMachineInfo | null,
|
||||
context: AnimationGraphBindingContext,
|
||||
clipOverrides: ReadonlyClipOverrideMap | null,
|
||||
__DEBUG_ID__: string,
|
||||
): StateMachineInfo {
|
||||
const nodes = Array.from(graph.states());
|
||||
@@ -296,7 +293,7 @@ class TopLevelStateMachineEvaluation {
|
||||
|
||||
const nodeEvaluations = nodes.map((node): NodeEval | VMSMEval | null => {
|
||||
if (node instanceof MotionState) {
|
||||
const motionStateEval = new VMSMEval(node, context, clipOverrides);
|
||||
const motionStateEval = new VMSMEval(node, context);
|
||||
this._motionStates.push(motionStateEval);
|
||||
return motionStateEval;
|
||||
} else if (node === graph.entryState) {
|
||||
@@ -342,7 +339,6 @@ class TopLevelStateMachineEvaluation {
|
||||
node.stateMachine,
|
||||
stateMachineInfo,
|
||||
context,
|
||||
clipOverrides,
|
||||
`${__DEBUG_ID__}/${node.name}`,
|
||||
);
|
||||
subStateMachineInfo.components = new InstantiatedComponents(node);
|
||||
@@ -682,9 +678,7 @@ class TopLevelStateMachineEvaluation {
|
||||
*
|
||||
* @returns The transition matched, or null if there's no matched transition.
|
||||
*/
|
||||
private _matchTransition (
|
||||
node: NodeEval, realNode: NodeEval,
|
||||
): TransitionEval | null {
|
||||
private _matchTransition (node: NodeEval, realNode: NodeEval): TransitionEval | null {
|
||||
assertIsTrue(node === realNode || node.kind === NodeKind.any);
|
||||
|
||||
const { _conditionEvaluationContext: conditionEvaluationContext } = this;
|
||||
@@ -1214,7 +1208,7 @@ interface StateMachineInfo {
|
||||
* Track the evaluation of a virtual motion state-machine.
|
||||
*/
|
||||
class VMSMEval {
|
||||
constructor (state: MotionState, context: AnimationGraphBindingContext, overrides: ReadonlyClipOverrideMap | null) {
|
||||
constructor (state: MotionState, context: AnimationGraphBindingContext) {
|
||||
const name = state.name;
|
||||
|
||||
this._baseSpeed = state.speed;
|
||||
@@ -1231,7 +1225,7 @@ class VMSMEval {
|
||||
}
|
||||
}
|
||||
|
||||
const sourceEval = state.motion?.[createEval](context, overrides, false) ?? null;
|
||||
const sourceEval = state.motion?.[createEval](context, false) ?? null;
|
||||
if (sourceEval) {
|
||||
Object.defineProperty(sourceEval, '__DEBUG_ID__', { value: name });
|
||||
}
|
||||
@@ -1298,8 +1292,8 @@ class VMSMEval {
|
||||
}
|
||||
}
|
||||
|
||||
public overrideClips (overrides: ReadonlyClipOverrideMap, context: AnimationGraphBindingContext): void {
|
||||
this._source?.overrideClips(overrides, context);
|
||||
public overrideClips (context: AnimationGraphBindingContext): void {
|
||||
this._source?.overrideClips(context);
|
||||
}
|
||||
|
||||
private _source: MotionEval | null = null;
|
||||
|
||||
@@ -432,7 +432,7 @@ class MotionEvalRecord {
|
||||
}
|
||||
|
||||
public rebind(bindContext: AnimationGraphBindingContext) {
|
||||
const motionEval = this._motion[createEval](bindContext, null, true);
|
||||
const motionEval = this._motion[createEval](bindContext, true);
|
||||
|
||||
if (!motionEval) {
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AnimationController } from "../../../../../cocos/animation/animation";
|
||||
import { AnimationGraphVariant } from "../../../../../cocos/animation/marionette/animation-graph-variant";
|
||||
import { lerp } from "../../../../../exports/base";
|
||||
import { AnimationGraphEvalMock } from "../../utils/eval-mock";
|
||||
import { createAnimationGraph, StateMachineParams, VariableDeclarationParams } from "../../utils/factory";
|
||||
@@ -187,4 +188,49 @@ describe(`Reentering`, () => {
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
test(`Clip overriding in state machine node`, () => {
|
||||
const fixture = {
|
||||
animation_1: new LinearRealValueAnimationFixture(1., 2., 3.),
|
||||
animation_2: new LinearRealValueAnimationFixture(-0.5, -3, 1),
|
||||
};
|
||||
|
||||
const valueObserver = new SingleRealValueObserver();
|
||||
|
||||
const motion1 = fixture.animation_1.createMotion(valueObserver.getCreateMotionContext());
|
||||
const motion2 = fixture.animation_2.createMotion(valueObserver.getCreateMotionContext());
|
||||
|
||||
const animationGraph = createAnimationGraph({
|
||||
layers: [{
|
||||
// Outer SM.
|
||||
stateMachine: {
|
||||
entryTransitions: [{ to: 'innerSM' }],
|
||||
states: {
|
||||
'innerSM': {
|
||||
type: 'procedural',
|
||||
graph: {
|
||||
rootNode: {
|
||||
'type': 'state-machine',
|
||||
// Inner SM.
|
||||
stateMachine: {
|
||||
entryTransitions: [{ to: 'm' }],
|
||||
states: { 'm': { type: 'motion', motion: motion1 } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
const animationGraphVariant = new AnimationGraphVariant();
|
||||
animationGraphVariant.original = animationGraph;
|
||||
animationGraphVariant.clipOverrides.set(motion1.clip, motion2.clip);
|
||||
|
||||
const evalMock = new AnimationGraphEvalMock(valueObserver.root, animationGraphVariant);
|
||||
|
||||
evalMock.step(fixture.animation_2.duration * 0.3);
|
||||
expect(valueObserver.value).toBeCloseTo(fixture.animation_2.getExpected(evalMock.current), 5);
|
||||
});
|
||||
@@ -1,12 +1,13 @@
|
||||
import { AnimationController } from "../../../../cocos/animation/animation";
|
||||
import { AnimationGraph } from "../../../../cocos/animation/marionette/animation-graph";
|
||||
import { AnimationGraphVariant } from "../../../../cocos/animation/marionette/animation-graph-variant";
|
||||
import { AnimationGraphEval } from "../../../../cocos/animation/marionette/graph-eval";
|
||||
import { Node } from "../../../../cocos/scene-graph";
|
||||
|
||||
export class AnimationGraphEvalMock {
|
||||
constructor(
|
||||
node: Node,
|
||||
animationGraph: AnimationGraph,
|
||||
animationGraph: AnimationGraph | AnimationGraphVariant,
|
||||
) {
|
||||
const controller = node.addComponent(AnimationController) as AnimationController;
|
||||
this._controller = controller;
|
||||
|
||||
Reference in New Issue
Block a user