Jelajahi Sumber

removed extra position for joints with default position

Nicolas Cannasse 6 tahun lalu
induk
melakukan
976266f787
4 mengubah file dengan 112 tambahan dan 89 penghapusan
  1. 96 85
      h3d/anim/BufferAnimation.hx
  2. 3 1
      h3d/anim/LinearAnimation.hx
  3. 12 2
      hxd/fmt/fbx/BaseLibrary.hx
  4. 1 1
      hxd/fmt/hmd/Library.hx

+ 96 - 85
h3d/anim/BufferAnimation.hx

@@ -103,6 +103,13 @@ class BufferAnimation extends Animation {
 			if( a.layout.has(Position) || a.layout.has(Rotation) || a.layout.has(Scale) ) {
 			if( a.layout.has(Position) || a.layout.has(Rotation) || a.layout.has(Scale) ) {
 				a.matrix = new h3d.Matrix();
 				a.matrix = new h3d.Matrix();
 				a.matrix.identity();
 				a.matrix.identity();
+				// store default position in our matrix unused parts
+				if( !a.layout.has(Position) && a.targetSkin != null ) {
+					var m2 = a.targetSkin.getSkinData().allJoints[a.targetJoint].defMat;
+					a.matrix._14 = m2._41;
+					a.matrix._24 = m2._42;
+					a.matrix._34 = m2._43;
+				}
 			}
 			}
 		}
 		}
 		// makes sure that all single frame anims are at the end so we can break early when isSync=true
 		// makes sure that all single frame anims are at the end so we can break early when isSync=true
@@ -157,41 +164,97 @@ class BufferAnimation extends Animation {
 			}
 			}
 
 
 			var m = o.matrix;
 			var m = o.matrix;
+			if( m != null ) {
 
 
-			if( layout.has(Position) ) {
-				m._41 = lerpValue();
-				m._42 = lerpValue();
-				m._43 = lerpValue();
-			}
+				if( layout.has(Position) ) {
+					m._41 = lerpValue();
+					m._42 = lerpValue();
+					m._43 = lerpValue();
+				} else {
+					m._41 = m._14;
+					m._42 = m._24;
+					m._43 = m._34;
+				}
+
+				if( layout.has(Rotation) ) {
+					var q1x : Float32 = data[offset1++];
+					var q1y : Float32 = data[offset1++];
+					var q1z : Float32 = data[offset1++];
+					var q1w : Float32 = data[offset1++];
+					var q2x : Float32 = data[offset2++];
+					var q2y : Float32 = data[offset2++];
+					var q2z : Float32 = data[offset2++];
+					var q2w : Float32 = data[offset2++];
+					// qlerp nearest
+					var dot = q1x * q1x + q1y * q2y + q1z * q2z + q1w * q2w;
+					var q2 = dot < 0 ? -k2 : k2;
+					var qx = q1x * k1 + q2x * q2;
+					var qy = q1y * k1 + q2y * q2;
+					var qz = q1z * k1 + q2z * q2;
+					var qw = q1w * k1 + q2w * q2;
+					// make sure the resulting quaternion is normalized
+					var ql = 1 / Math.sqrt(qx * qx + qy * qy + qz * qz + qw * qw);
+					qx *= ql;
+					qy *= ql;
+					qz *= ql;
+					qw *= ql;
+
+					if( decompose ) {
+						m._12 = qx;
+						m._13 = qy;
+						m._21 = qz;
+						m._23 = qw;
+						if( layout.has(Scale) ) {
+							m._11 = lerpValue();
+							m._22 = lerpValue();
+							m._33 = lerpValue();
+						} else {
+							m._11 = 1;
+							m._22 = 1;
+							m._33 = 1;
+						}
+					} else {
+						// quaternion to matrix
+						var xx = qx * qx;
+						var xy = qx * qy;
+						var xz = qx * qz;
+						var xw = qx * qw;
+						var yy = qy * qy;
+						var yz = qy * qz;
+						var yw = qy * qw;
+						var zz = qz * qz;
+						var zw = qz * qw;
+						m._11 = 1 - 2 * ( yy + zz );
+						m._12 = 2 * ( xy + zw );
+						m._13 = 2 * ( xz - yw );
+						m._21 = 2 * ( xy - zw );
+						m._22 = 1 - 2 * ( xx + zz );
+						m._23 = 2 * ( yz + xw );
+						m._31 = 2 * ( xz + yw );
+						m._32 = 2 * ( yz - xw );
+						m._33 = 1 - 2 * ( xx + yy );
+						if( layout.has(Scale) ) {
+							var sx = lerpValue();
+							var sy = lerpValue();
+							var sz = lerpValue();
+							m._11 *= sx;
+							m._12 *= sx;
+							m._13 *= sx;
+							m._21 *= sy;
+							m._22 *= sy;
+							m._23 *= sy;
+							m._31 *= sz;
+							m._32 *= sz;
+							m._33 *= sz;
+						}
+					}
+
+				} else {
+					m._12 = 0;
+					m._13 = 0;
+					m._21 = 0;
+					m._23 = decompose ? 1 : 0;
 
 
-			if( layout.has(Rotation) ) {
-				var q1x : Float32 = data[offset1++];
-				var q1y : Float32 = data[offset1++];
-				var q1z : Float32 = data[offset1++];
-				var q1w : Float32 = data[offset1++];
-				var q2x : Float32 = data[offset2++];
-				var q2y : Float32 = data[offset2++];
-				var q2z : Float32 = data[offset2++];
-				var q2w : Float32 = data[offset2++];
-				// qlerp nearest
-				var dot = q1x * q1x + q1y * q2y + q1z * q2z + q1w * q2w;
-				var q2 = dot < 0 ? -k2 : k2;
-				var qx = q1x * k1 + q2x * q2;
-				var qy = q1y * k1 + q2y * q2;
-				var qz = q1z * k1 + q2z * q2;
-				var qw = q1w * k1 + q2w * q2;
-				// make sure the resulting quaternion is normalized
-				var ql = 1 / Math.sqrt(qx * qx + qy * qy + qz * qz + qw * qw);
-				qx *= ql;
-				qy *= ql;
-				qz *= ql;
-				qw *= ql;
-
-				if( decompose ) {
-					m._12 = qx;
-					m._13 = qy;
-					m._21 = qz;
-					m._23 = qw;
 					if( layout.has(Scale) ) {
 					if( layout.has(Scale) ) {
 						m._11 = lerpValue();
 						m._11 = lerpValue();
 						m._22 = lerpValue();
 						m._22 = lerpValue();
@@ -201,60 +264,8 @@ class BufferAnimation extends Animation {
 						m._22 = 1;
 						m._22 = 1;
 						m._33 = 1;
 						m._33 = 1;
 					}
 					}
-				} else {
-					// quaternion to matrix
-					var xx = qx * qx;
-					var xy = qx * qy;
-					var xz = qx * qz;
-					var xw = qx * qw;
-					var yy = qy * qy;
-					var yz = qy * qz;
-					var yw = qy * qw;
-					var zz = qz * qz;
-					var zw = qz * qw;
-					m._11 = 1 - 2 * ( yy + zz );
-					m._12 = 2 * ( xy + zw );
-					m._13 = 2 * ( xz - yw );
-					m._21 = 2 * ( xy - zw );
-					m._22 = 1 - 2 * ( xx + zz );
-					m._23 = 2 * ( yz + xw );
-					m._31 = 2 * ( xz + yw );
-					m._32 = 2 * ( yz - xw );
-					m._33 = 1 - 2 * ( xx + yy );
-					if( layout.has(Scale) ) {
-						var sx = lerpValue();
-						var sy = lerpValue();
-						var sz = lerpValue();
-						m._11 *= sx;
-						m._12 *= sx;
-						m._13 *= sx;
-						m._21 *= sy;
-						m._22 *= sy;
-						m._23 *= sy;
-						m._31 *= sz;
-						m._32 *= sz;
-						m._33 *= sz;
-					}
 				}
 				}
 
 
-			} else if( m != null ) {
-				m._12 = 0;
-				m._13 = 0;
-				m._21 = 0;
-				m._23 = decompose ? 1 : 0;
-
-				if( layout.has(Scale) ) {
-					m._11 = lerpValue();
-					m._22 = lerpValue();
-					m._33 = lerpValue();
-				} else {
-					m._11 = 1;
-					m._22 = 1;
-					m._33 = 1;
-				}
-			}
-
-			if( m != null ) {
 				if( o.targetSkin != null ) {
 				if( o.targetSkin != null ) {
 					o.targetSkin.currentRelPose[o.targetJoint] = m;
 					o.targetSkin.currentRelPose[o.targetJoint] = m;
 					o.targetSkin.jointsUpdated = true;
 					o.targetSkin.jointsUpdated = true;

+ 3 - 1
h3d/anim/LinearAnimation.hx

@@ -36,6 +36,7 @@ class LinearObject extends AnimatedObject {
 	public var propCurrentValue : Float;
 	public var propCurrentValue : Float;
 	override function clone() : AnimatedObject {
 	override function clone() : AnimatedObject {
 		var o = new LinearObject(objectName);
 		var o = new LinearObject(objectName);
+		o.hasPosition = hasPosition;
 		o.hasRotation = hasRotation;
 		o.hasRotation = hasRotation;
 		o.hasScale = hasScale;
 		o.hasScale = hasScale;
 		o.frames = frames;
 		o.frames = frames;
@@ -56,9 +57,10 @@ class LinearAnimation extends Animation {
 		syncFrame = -1;
 		syncFrame = -1;
 	}
 	}
 
 
-	public function addCurve( objName, frames, hasRot, hasScale ) {
+	public function addCurve( objName, frames, hasPos, hasRot, hasScale ) {
 		var f = new LinearObject(objName);
 		var f = new LinearObject(objName);
 		f.frames = frames;
 		f.frames = frames;
+		f.hasPosition = hasPos;
 		f.hasRotation = hasRot;
 		f.hasRotation = hasRot;
 		f.hasScale = hasScale;
 		f.hasScale = hasScale;
 		objects.push(f);
 		objects.push(f);

+ 12 - 2
hxd/fmt/fbx/BaseLibrary.hx

@@ -29,6 +29,7 @@ class TmpObject {
 private class AnimCurve {
 private class AnimCurve {
 	public var def : DefaultMatrixes;
 	public var def : DefaultMatrixes;
 	public var object : String;
 	public var object : String;
+	public var isJoint : Bool;
 	public var t : { t : Array<Float>, x : Array<Float>, y : Array<Float>, z : Array<Float> };
 	public var t : { t : Array<Float>, x : Array<Float>, y : Array<Float>, z : Array<Float> };
 	public var r : { t : Array<Float>, x : Array<Float>, y : Array<Float>, z : Array<Float> };
 	public var r : { t : Array<Float>, x : Array<Float>, y : Array<Float>, z : Array<Float> };
 	public var s : { t : Array<Float>, x : Array<Float>, y : Array<Float>, z : Array<Float> };
 	public var s : { t : Array<Float>, x : Array<Float>, y : Array<Float>, z : Array<Float> };
@@ -595,6 +596,7 @@ class BaseLibrary {
 		}
 		}
 		if( c == null ) {
 		if( c == null ) {
 			c = new AnimCurve(def, name);
 			c = new AnimCurve(def, name);
+			c.isJoint = model.getType() == "LimbNode";
 			curves.set(model.getId(), c);
 			curves.set(model.getId(), c);
 		}
 		}
 		return c;
 		return c;
@@ -1139,8 +1141,16 @@ class BaseLibrary {
 					fov[f] = c.fov.v[fovp - 1];
 					fov[f] = c.fov.v[fovp - 1];
 				}
 				}
 			}
 			}
-			if( frames != null )
-				anim.addCurve(c.object, frames, c.r != null || def.rotate != null || def.preRot != null, c.s != null || def.scale != null);
+			if( frames != null ) {
+				var hasTrans = c.t != null;
+				var hasRot = c.r != null || def.rotate != null || def.preRot != null;
+				var hasScale = c.s != null || def.scale != null;
+				if( !hasTrans && def.trans != null )
+					hasTrans = !c.isJoint;
+				if( !hasTrans && !hasRot && !hasScale )
+					hasTrans = true; // force reset
+				anim.addCurve(c.object, frames, hasTrans, hasRot, hasScale);
+			}
 			if( alpha != null )
 			if( alpha != null )
 				anim.addAlphaCurve(c.object, alpha);
 				anim.addAlphaCurve(c.object, alpha);
 			if( uvs != null )
 			if( uvs != null )

+ 1 - 1
hxd/fmt/hmd/Library.hx

@@ -539,7 +539,7 @@ class Library {
 					}
 					}
 					fl[i] = f;
 					fl[i] = f;
 				}
 				}
-				l.addCurve(o.name, fl, rot, scale);
+				l.addCurve(o.name, fl, true, rot, scale);
 			}
 			}
 			if( o.flags.has(HasUV) ) {
 			if( o.flags.has(HasUV) ) {
 				var fl = new haxe.ds.Vector(a.frames*2);
 				var fl = new haxe.ds.Vector(a.frames*2);