Browse Source

[animgraph] Unlinked AnimNode inputs default to a global DefaultPose now

Clément Espeute 9 months ago
parent
commit
3971a06f71
3 changed files with 18 additions and 11 deletions
  1. 14 7
      hrt/animgraph/AnimGraphInstance.hx
  2. 2 0
      hrt/animgraph/Node.hx
  3. 2 4
      hrt/animgraph/nodes/Blend.hx

+ 14 - 7
hrt/animgraph/AnimGraphInstance.hx

@@ -22,13 +22,14 @@ class AnimGraphInstance extends h3d.anim.Animation {
 	var target : h3d.scene.Object = null;
 
 	var syncCtx = new hrt.animgraph.nodes.AnimNode.GetBoneTransformContext();
+	var defaultPoseNode = new hrt.animgraph.nodes.DefaultPose();
 
 	function new(animGraph:AnimGraph) {
 		// Todo : Define a true length for the animation OR make so animations can have an undefined length
 		super(animGraph.name, 1000, 1/60.0);
 		this.animGraph = animGraph;
 
-
+		defaultPoseNode = new hrt.animgraph.nodes.DefaultPose();
 		var output : hrt.animgraph.nodes.Output = cast Lambda.find(animGraph.nodes, (node) -> Std.downcast(node, hrt.animgraph.nodes.Output) != null);
 		if (output != null) {
 			map(output, updateNodeInputs);
@@ -114,15 +115,21 @@ class AnimGraphInstance extends h3d.anim.Animation {
 	function updateNodeInputs(node: Node) : Void {
 		var inputs = node.getInputs();
 		for (inputId => edge in node.inputEdges) {
-			if (edge == null) continue;
-			var outputNode = edge.target;
-			var outputs = outputNode.getOutputs();
-			var output = outputs[edge.outputIndex];
+			var outputNode = edge?.target;
+
 			switch (inputs[inputId].type) {
 				case TAnimation:
-					Reflect.setField(node, inputs[inputId].name, outputNode);
+					if (outputNode != null && Std.downcast(outputNode, hrt.animgraph.nodes.DefaultPose) == null /* use our default pose node instead of the one in the graph*/) {
+						Reflect.setField(node, inputs[inputId].name, outputNode);
+					} else {
+						Reflect.setField(node, inputs[inputId].name, defaultPoseNode);
+					}
 				case TFloat:
-					Reflect.setField(node, inputs[inputId].name, Reflect.getProperty(outputNode, output.name));
+					if (outputNode != null) {
+						var outputs = outputNode.getOutputs();
+						var output = outputs[edge.outputIndex];
+						Reflect.setField(node, inputs[inputId].name, Reflect.getProperty(outputNode, output.name));
+					}
 			}
 		}
 	}

+ 2 - 0
hrt/animgraph/Node.hx

@@ -31,6 +31,8 @@ implements hide.view.GraphInterface.IGraphNode
 	@:s public var x : Float;
 	@:s public var y : Float;
 	public var inputEdges: Array<Edge> = [];
+	var animGraph : AnimGraph;
+
 
 	var tickedThisFrame = false;
 

+ 2 - 4
hrt/animgraph/nodes/Blend.hx

@@ -12,7 +12,7 @@ class Blend extends AnimNode {
 			if (sourceBoneId != -1) {
 				a.getBoneTransform(sourceBoneId, tempMatrix, ctx);
 			} else {
-				tempMatrix = @:privateAccess h3d.anim.SmoothTransition.MZERO;
+				tempMatrix.load(ctx.getDefPose());
 			}
 		} else {
 			tempMatrix.load(ctx.getDefPose());
@@ -23,10 +23,8 @@ class Blend extends AnimNode {
 			if (sourceBoneId != -1) {
 				b.getBoneTransform(sourceBoneId, outMatrix, ctx);
 			} else {
-				outMatrix.load(@:privateAccess h3d.anim.SmoothTransition.MZERO);
+				outMatrix.load(ctx.getDefPose());
 			}
-		} else {
-			outMatrix.load(ctx.getDefPose());
 		}
 
 		var m1 = tempMatrix;