浏览代码

[animgraph] Fix bugs, added input box to float params

Clément Espeute 8 月之前
父节点
当前提交
5384dfd953
共有 4 个文件被更改,包括 45 次插入7 次删除
  1. 22 0
      hrt/animgraph/AnimGraph.hx
  2. 15 6
      hrt/animgraph/AnimGraphInstance.hx
  3. 7 0
      hrt/animgraph/Node.hx
  4. 1 1
      hrt/animgraph/nodes/FloatParameter.hx

+ 22 - 0
hrt/animgraph/AnimGraph.hx

@@ -77,9 +77,24 @@ 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);
 			var param = Std.downcast(node, hrt.animgraph.nodes.FloatParameter);
 			if (param != null) {
 			if (param != null) {
 				nodeSer.parameter = parametersIdMapping.get(param.parameter);
 				nodeSer.parameter = parametersIdMapping.get(param.parameter);
+				if (nodeSer.parameter == null) {
+					throw "save impossible";
+				}
 			}
 			}
 		}
 		}
 
 
@@ -115,6 +130,13 @@ class AnimGraph extends hrt.prefab.Prefab {
 					node.id = nodeIdCount++;
 					node.id = nodeIdCount++;
 					unserializedNodes.push(node);
 					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);
 					var param = Std.downcast(node, hrt.animgraph.nodes.FloatParameter);
 					if (param != null) {
 					if (param != null) {
 						param.parameter = parameters[nodeData.parameter];
 						param.parameter = parameters[nodeData.parameter];

+ 15 - 6
hrt/animgraph/AnimGraphInstance.hx

@@ -68,15 +68,24 @@ class AnimGraphInstance extends h3d.anim.Animation {
 	static function cloneRec(node: hrt.animgraph.Node, inst: AnimGraphInstance) : hrt.animgraph.Node {
 	static function cloneRec(node: hrt.animgraph.Node, inst: AnimGraphInstance) : hrt.animgraph.Node {
 		var cloned = hrt.animgraph.Node.createFromDynamic(node.serializeToDynamic());
 		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);
 		var clonedParam = Std.downcast(cloned, hrt.animgraph.nodes.FloatParameter);
 		if (clonedParam != null) {
 		if (clonedParam != null) {
 			var nodeParam : hrt.animgraph.nodes.FloatParameter = cast node;
 			var nodeParam : hrt.animgraph.nodes.FloatParameter = cast node;
-			clonedParam.parameter = inst.parameterMap.getOrPut(nodeParam.parameter.name, {
-				var newParam = new hrt.animgraph.AnimGraph.Parameter();
-				@:privateAccess newParam.copyFromOther(nodeParam.parameter);
-				newParam.runtimeValue = nodeParam.parameter.defaultValue;
-				newParam;
-			});
+			if (nodeParam.parameter != null) {
+				clonedParam.parameter = inst.parameterMap.getOrPut(nodeParam.parameter.name, {
+					var newParam = new hrt.animgraph.AnimGraph.Parameter();
+					@:privateAccess newParam.copyFromOther(nodeParam.parameter);
+					newParam.runtimeValue = nodeParam.parameter.defaultValue;
+					newParam;
+				});
+			}
 		}
 		}
 
 
 		for (id => edge in node.inputEdges) {
 		for (id => edge in node.inputEdges) {

+ 7 - 0
hrt/animgraph/Node.hx

@@ -126,6 +126,13 @@ implements hide.view.GraphInterface.IGraphNode
 			inputs: [for (input in getInputs()) {
 			inputs: [for (input in getInputs()) {
 				name: input.name,
 				name: input.name,
 				color: getTypeColor(input.type),
 				color: getTypeColor(input.type),
+				defaultParam: input.type != TFloat ? null : {
+					get : () -> Std.string(Reflect.getProperty(this, input.name)),
+					set : (v: String) -> {
+						Reflect.setProperty(this, input.name, Std.parseFloat(v));
+						getAnimEditor().refreshPreview();
+					},
+				},
 			}],
 			}],
 			outputs: [for (output in getOutputs()) {
 			outputs: [for (output in getOutputs()) {
 				name: getOutputNameOverride(output.name),
 				name: getOutputNameOverride(output.name),

+ 1 - 1
hrt/animgraph/nodes/FloatParameter.hx

@@ -13,6 +13,6 @@ class FloatParameter extends Node {
 	}
 	}
 
 
 	override function getOutputNameOverride(name: String) : String {
 	override function getOutputNameOverride(name: String) : String {
-		return parameter.name;
+		return parameter?.name ?? "undefined";
 	}
 	}
 }
 }