Browse Source

[animgraph] Refactored node param default value overrides

Clément Espeute 8 months ago
parent
commit
e78028452c
3 changed files with 21 additions and 26 deletions
  1. 0 19
      hrt/animgraph/AnimGraph.hx
  2. 0 7
      hrt/animgraph/AnimGraphInstance.hx
  3. 21 0
      hrt/animgraph/Node.hx

+ 0 - 19
hrt/animgraph/AnimGraph.hx

@@ -77,18 +77,6 @@ class AnimGraph extends hrt.prefab.Prefab {
 				});
 			}
 
-			// Serialize unconected node inputs values (that can be changed in the editor)
-			for (i => inputInfo in node.getInputs()) {
-				if (node.inputEdges[i] != null)
-					continue;
-				var inputValue = Reflect.getProperty(node, inputInfo.name);
-				if (inputValue == inputInfo.def)
-					continue;
-				if (inputInfo.type == TFloat) {
-					Reflect.setField(nodeSer, inputInfo.name, inputValue);
-				}
-			}
-
 			var param = Std.downcast(node, hrt.animgraph.nodes.FloatParameter);
 			if (param != null) {
 				nodeSer.parameter = parametersIdMapping.get(param.parameter);
@@ -130,13 +118,6 @@ class AnimGraph extends hrt.prefab.Prefab {
 					node.id = nodeIdCount++;
 					unserializedNodes.push(node);
 
-					for (inputInfo in node.getInputs()) {
-						var val = Reflect.getProperty(nodeData, inputInfo.name);
-						if (val != null) {
-							Reflect.setProperty(node, inputInfo.name, val);
-						}
-					}
-
 					var param = Std.downcast(node, hrt.animgraph.nodes.FloatParameter);
 					if (param != null) {
 						param.parameter = parameters[nodeData.parameter];

+ 0 - 7
hrt/animgraph/AnimGraphInstance.hx

@@ -68,13 +68,6 @@ class AnimGraphInstance extends h3d.anim.Animation {
 	static function cloneRec(node: hrt.animgraph.Node, inst: AnimGraphInstance) : hrt.animgraph.Node {
 		var cloned = hrt.animgraph.Node.createFromDynamic(node.serializeToDynamic());
 
-		for (inputInfo in node.getInputs()) {
-			var val = Reflect.getProperty(node, inputInfo.name);
-			if (val != null) {
-				Reflect.setProperty(cloned, inputInfo.name, val);
-			}
-		}
-
 		var clonedParam = Std.downcast(cloned, hrt.animgraph.nodes.FloatParameter);
 		if (clonedParam != null) {
 			var nodeParam : hrt.animgraph.nodes.FloatParameter = cast node;

+ 21 - 0
hrt/animgraph/Node.hx

@@ -60,6 +60,19 @@ implements hide.view.GraphInterface.IGraphNode
 		};
 
 		copyToDynamic(data);
+
+		// Serialize unconected node inputs values (that can be changed in the editor)
+		for (i => inputInfo in getInputs()) {
+			if (inputEdges[i] != null)
+				continue;
+			var inputValue = Reflect.getProperty(this, inputInfo.name);
+			if (inputValue == inputInfo.def)
+				continue;
+			if (inputInfo.type == TFloat) {
+				Reflect.setField(data, inputInfo.name, inputValue);
+			}
+		}
+
 		return data;
 	}
 
@@ -71,6 +84,14 @@ implements hide.view.GraphInterface.IGraphNode
 			throw 'Could\'t not create node form type ${data.type}';
 		}
 		inst.copyFromDynamic(data);
+
+		for (inputInfo in inst.getInputs()) {
+			var val = Reflect.getProperty(data, inputInfo.name);
+			if (val != null) {
+				Reflect.setProperty(inst, inputInfo.name, val);
+			}
+		}
+
 		return inst;
 	}