Complementarily implement pose graph (#14952)

* Implement pose graph

* Add test for query output node's input/outputs

* Fix isWellFormedInputKey()

* Tweak

* Use `Map` instead of `shellTag`

* Rename XNode -> PureValueNode

* Rename node input manager and node input options
This commit is contained in:
Leslie Leigh (李的序)
2023-05-12 13:45:55 +08:00
committed by GitHub
parent b119ee5bcf
commit 4304c05745
29 changed files with 3068 additions and 59 deletions
@@ -0,0 +1,77 @@
import { PoseGraphNode } from "../../../cocos/animation/marionette/pose-graph/foundation/pose-graph-node";
import {
getPoseGraphNodeEditorMetadata, PoseGraphCreateNodeContext, PoseGraphNodeAppearanceOptions,
} from "../../../cocos/animation/marionette/pose-graph/foundation/authoring/node-authoring";
import { js } from "../../../cocos/core/utils";
import { PoseNode } from "../../../cocos/animation/marionette/pose-graph/pose-node";
import { PureValueNode } from "../../../cocos/animation/marionette/pose-graph/pure-value-node";
type Constructor<T = unknown> = new (...args: any[]) => T;
export interface PoseGraphCreateNodeEntry {
menu: string;
arg: unknown;
}
export function* getCreatePoseGraphNodeEntries(
classConstructor: Constructor<PoseGraphNode>,
createNodeContext: PoseGraphCreateNodeContext,
): Iterable<PoseGraphCreateNodeEntry> {
type AbstractedConstructor<T = unknown> = abstract new (...args: any[]) => T;
if ((classConstructor as AbstractedConstructor) === PoseNode || (classConstructor as AbstractedConstructor) === PureValueNode) {
return;
}
const nodeClassMetadata = getPoseGraphNodeEditorMetadata(classConstructor as Constructor<PoseNode | PureValueNode>);
if (nodeClassMetadata) {
if (nodeClassMetadata.factory) {
yield* nodeClassMetadata.factory.listEntries(createNodeContext);
return;
} else if (nodeClassMetadata.menu) {
yield { arg: undefined, menu: nodeClassMetadata.menu };
return;
} else if (nodeClassMetadata.hide) {
return;
}
}
const displayName = js.getClassName(classConstructor) || classConstructor.name;
yield { arg: undefined, menu: displayName };
}
export function createPoseGraphNode(
classConstructor: Constructor<PoseGraphNode>,
arg: unknown,
): PoseGraphNode {
const nodeClassMetadata = getPoseGraphNodeEditorMetadata(classConstructor as Constructor<PoseNode | PureValueNode>);
if (nodeClassMetadata?.factory) {
return nodeClassMetadata.factory.create(arg) as PoseNode | PureValueNode;
}
return new classConstructor();
}
export type { PoseGraphCreateNodeContext };
export function getNodeTitle(node: PoseGraphNode) {
if (node.getTitle) {
return node.getTitle();
}
const classConstructor = node.constructor as Constructor<PoseNode | PureValueNode>;
const metadata = getPoseGraphNodeEditorMetadata(classConstructor);
if (metadata?.menu) {
return metadata.menu.split('/').pop() ?? '';
}
const className = js.getClassName(node);
if (className) {
return className;
}
return classConstructor.name;
}
export type { PoseGraphNodeAppearanceOptions };
export function getNodeAppearanceOptions(node: PoseGraphNode) {
const classConstructor = node.constructor as Constructor<PoseGraphNode>;
const metadata = getPoseGraphNodeEditorMetadata(classConstructor);
return metadata?.appearance;
}
+15
View File
@@ -6,9 +6,11 @@ import {
StateMachine,
SubStateMachine,
AnimationGraph,
PoseState,
} from "../../../cocos/animation/marionette/animation-graph";
import { MotionState } from "../../../cocos/animation/marionette/state-machine/motion-state";
import { EditorExtendableObject } from "../../../cocos/core/data/editor-extras-tag";
import { PoseGraphNode } from "../../../cocos/animation/marionette/pose-graph/foundation/pose-graph-node";
export function* visitAnimationGraphEditorExtras(animationGraph: AnimationGraph): Generator<EditorExtendableObject> {
for (const layer of animationGraph.layers) {
@@ -60,6 +62,10 @@ export function* visitAnimationClips(animationGraph: AnimationGraph): Generator<
if (motion) {
yield* visitMotion(motion);
}
} else if (state instanceof PoseState) {
for (const shell of state.graph.nodes()) {
yield* visitPoseNode(shell);
}
} else if (state instanceof SubStateMachine) {
yield* visitStateMachine(state.stateMachine);
}
@@ -79,6 +85,15 @@ export function* visitAnimationClips(animationGraph: AnimationGraph): Generator<
}
}
}
function* visitPoseNode(node: PoseGraphNode): Generator<AnimationClip> {
// FIXME: HACK HERE
for (const [_, v] of Object.entries(node)) {
if (v instanceof Motion) {
yield* visitMotion(v);
}
}
}
}
export function* visitAnimationClipsInController(animationController: AnimationController): Generator<AnimationClip> {