2
0
Эх сурвалжийг харах

[animgraph] Code review cleanup

Clément Espeute 8 сар өмнө
parent
commit
37f65760cc

+ 0 - 1
hide.hxml

@@ -19,5 +19,4 @@ common.hxml
 --macro include("hrt")
 -dce no
 -debug
--D dump=pretty
 #-D shader_debug_dump

+ 0 - 42
hrt/animgraph/AnimGraph.hx

@@ -159,48 +159,6 @@ class AnimGraph extends hrt.prefab.Prefab {
 
 	override function copy(other: hrt.prefab.Prefab) {
 		load(other.save());
-		// super.copy(other);
-		// var other : AnimGraph = cast other;
-
-		// var nodeCopy: Map<{}, Node> = [];
-		// var parameterCopy: Map<{}, Parameter> = [];
-
-		// this.nodes = [];
-		// this.parameters = [];
-
-		// for (parameter in other.parameters) {
-		// 	var copy = new Parameter();
-		// 	@:privateAccess copy.copyFromOther(parameter);
-		// 	this.parameters.push(copy);
-		// 	parameterCopy.set(parameter, copy);
-		// }
-
-		// for (node in other.nodes) {
-		// 	var copy = Node.createFromDynamic(node.serializeToDynamic());
-		// 	this.nodes.push(copy);
-		// 	nodeCopy.set(node, copy);
-
-		// 	var copyParam = Std.downcast(copy, hrt.animgraph.nodes.FloatParameter);
-		// 	var nodeParam = Std.downcast(node, hrt.animgraph.nodes.FloatParameter);
-		// 	if (copyParam != null) {
-		// 		copyParam.parameter = parameterCopy.get(nodeParam.parameter);
-		// 	}
-		// }
-
-		// // restore edges
-		// for (node in other.nodes) {
-		// 	var ours = nodeCopy.get(node);
-		// 	for (id => edge in node.inputEdges) {
-		// 		if (edge == null)
-		// 			continue;
-		// 		ours.inputEdges[id] = {
-		// 			target: nodeCopy.get(edge.target),
-		// 			outputIndex: edge.outputIndex,
-		// 		};
-		// 	}
-		// }
-
-		// this.parameters = haxe.Json.parse(haxe.Json.stringify(other.parameters));
 	}
 
 	#if editor

+ 5 - 30
hrt/animgraph/AnimGraphInstance.hx

@@ -35,11 +35,6 @@ class AnimGraphInstance extends h3d.anim.Animation {
 
 		var inst = new AnimGraphInstance(outputNode, animGraph.name, 1000, 1/60.0);
 
-		// for (param in animGraph.parameters) {
-		// 	inst.parameterMap.set(param.name, param);
-		// 	param.runtimeValue = param.defaultValue;
-		// }
-
 		return inst;
 	}
 
@@ -52,7 +47,10 @@ class AnimGraphInstance extends h3d.anim.Animation {
 	}
 
 	public function setParam(name: String, value: Float) {
-		parameterMap.get(name)?.runtimeValue = value;
+		var param = parameterMap.get(name);
+		if (param != null) {
+			param.runtimeValue = value;
+		}
 	}
 
 	public function getParam(name: String) : Null<Float> {
@@ -158,12 +156,9 @@ class AnimGraphInstance extends h3d.anim.Animation {
 			}
 
 			if (!decompose) {
-				decomposeMatrix(workMatrix, targetMatrix);
+				Tools.recomposeMatrix(workMatrix, targetMatrix);
 				if (obj.targetSkin != null) {
 					var def = obj.targetSkin.getSkinData().allJoints[obj.targetJoint].defMat;
-					// targetMatrix._41 = def._41;
-					// targetMatrix._42 = def._42;
-					// targetMatrix._43 = def._43;
 				}
 			} else {
 				targetMatrix.load(workMatrix);
@@ -171,26 +166,6 @@ class AnimGraphInstance extends h3d.anim.Animation {
 		}
 	}
 
-	static function decomposeMatrix(inMatrix: h3d.Matrix, outMatrix: h3d.Matrix) {
-		var quat = inline new h3d.Quat(inMatrix._12, inMatrix._13, inMatrix._21, inMatrix._23);
-		inline quat.toMatrix(outMatrix);
-
-		outMatrix._11 *= inMatrix._11;
-		outMatrix._12 *= inMatrix._11;
-		outMatrix._13 *= inMatrix._11;
-		outMatrix._21 *= inMatrix._22;
-		outMatrix._22 *= inMatrix._22;
-		outMatrix._23 *= inMatrix._22;
-		outMatrix._31 *= inMatrix._33;
-		outMatrix._32 *= inMatrix._33;
-		outMatrix._33 *= inMatrix._33;
-
-		outMatrix._41 = inMatrix._41;
-		outMatrix._42 = inMatrix._42;
-		outMatrix._43 = inMatrix._43;
-
-	}
-
 	function updateNodeInputs(node: Node) : Void {
 		var inputs = node.getInputs();
 		for (inputId => edge in node.inputEdges) {

+ 30 - 2
hrt/animgraph/Tools.hx

@@ -1,9 +1,9 @@
 package hrt.animgraph;
 
 class Tools {
-	@:haxe.warning("-WInlineOptimizedField")
 
 	// from https://theorangeduck.com/page/quaternion-weighted-average
+	@:haxe.warning("-WInlineOptimizedField")
 	static public function weightedBlend(inRotations: Array<h3d.Quat>, inReference: h3d.Quat, inWeights: Array<Float>, outRotation: h3d.Quat) {
 		outRotation.set(0,0,0,0);
 
@@ -35,7 +35,12 @@ class Tools {
 
 
 	static var workMatrix = new h3d.Matrix();
-	static public function splitMatrix(inMatrix: h3d.Matrix, outMatrix: h3d.Matrix) {
+
+	/**
+		Decompose a 3d matrix so the rotation quaternion is stored in [m12,m13,m21,m23] instead of mixed with the scale
+	**/
+	@:haxe.warning("-WInlineOptimizedField")
+	static public function decomposeMatrix(inMatrix: h3d.Matrix, outMatrix: h3d.Matrix) {
 		workMatrix.load(inMatrix);
 		var scale = inline workMatrix.getScale();
 		workMatrix.prependScale(1.0/scale.x, 1.0/scale.y, 1.0/scale.z);
@@ -55,4 +60,27 @@ class Tools {
 		outMatrix.ty = inMatrix.ty;
 		outMatrix.tz = inMatrix.tz;
 	}
+
+	/**
+		Transform a decomposed matrix into a normal one
+	**/
+	@:haxe.warning("-WInlineOptimizedField")
+	static public function recomposeMatrix(inMatrix: h3d.Matrix, outMatrix: h3d.Matrix) {
+		var quat = inline new h3d.Quat(inMatrix._12, inMatrix._13, inMatrix._21, inMatrix._23);
+		inline quat.toMatrix(outMatrix);
+
+		outMatrix._11 *= inMatrix._11;
+		outMatrix._12 *= inMatrix._11;
+		outMatrix._13 *= inMatrix._11;
+		outMatrix._21 *= inMatrix._22;
+		outMatrix._22 *= inMatrix._22;
+		outMatrix._23 *= inMatrix._22;
+		outMatrix._31 *= inMatrix._33;
+		outMatrix._32 *= inMatrix._33;
+		outMatrix._33 *= inMatrix._33;
+
+		outMatrix._41 = inMatrix._41;
+		outMatrix._42 = inMatrix._42;
+		outMatrix._43 = inMatrix._43;
+	}
 }

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

@@ -37,7 +37,7 @@ class GetBoneTransformContext {
 		} else {
 			targetObj.targetObject.defaultTransform ?? @:privateAccess h3d.anim.SmoothTransition.MZERO;
 		}
-		Tools.splitMatrix(m, tmpDefMatrix);
+		Tools.decomposeMatrix(m, tmpDefMatrix);
 
 		defMatrix = tmpDefMatrix;
 		return defMatrix;

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

@@ -33,7 +33,7 @@ class DefaultPose extends AnimNode {
 			var m = bone.skin != null ? bone.skin.getSkinData().allJoints[bone.joint].defMat : bone.object.defaultTransform;
 			if (m != null) {
 				bone.matDecomposed = new h3d.Matrix();
-				Tools.splitMatrix(m, bone.matDecomposed);
+				Tools.decomposeMatrix(m, bone.matDecomposed);
 			} else {
 				bone.matDecomposed = @:privateAccess h3d.anim.SmoothTransition.MZERO;
 			}