Parcourir la source

hmd-v3: synthesize quaternion w at runtime

Nicolas Cannasse il y a 6 ans
Parent
commit
9961dbc568
5 fichiers modifiés avec 8 ajouts et 7 suppressions
  1. 4 3
      h3d/anim/BufferAnimation.hx
  2. 1 1
      hxd/fmt/fbx/HMDOut.hx
  3. 1 1
      hxd/fmt/hmd/Data.hx
  4. 1 1
      hxd/fmt/hmd/Dump.hx
  5. 1 1
      hxd/fmt/hmd/Library.hx

+ 4 - 3
h3d/anim/BufferAnimation.hx

@@ -28,7 +28,7 @@ class BufferObject extends AnimatedObject {
 	public function getStride() {
 	public function getStride() {
 		var stride = 0;
 		var stride = 0;
 		if( layout.has(Position) ) stride += 3;
 		if( layout.has(Position) ) stride += 3;
-		if( layout.has(Rotation) ) stride += 4;
+		if( layout.has(Rotation) ) stride += 3;
 		if( layout.has(Scale) ) stride += 3;
 		if( layout.has(Scale) ) stride += 3;
 		if( layout.has(UV) ) stride += 2;
 		if( layout.has(UV) ) stride += 2;
 		if( layout.has(Alpha) ) stride += 1;
 		if( layout.has(Alpha) ) stride += 1;
@@ -180,11 +180,12 @@ class BufferAnimation extends Animation {
 					var q1x : Float32 = data[offset1++];
 					var q1x : Float32 = data[offset1++];
 					var q1y : Float32 = data[offset1++];
 					var q1y : Float32 = data[offset1++];
 					var q1z : Float32 = data[offset1++];
 					var q1z : Float32 = data[offset1++];
-					var q1w : Float32 = data[offset1++];
+					var q1w : Float32 = Math.sqrt(hxd.Math.abs(1 - (q1x*q1x+q1y*q1y+q1z*q1z)));
 					var q2x : Float32 = data[offset2++];
 					var q2x : Float32 = data[offset2++];
 					var q2y : Float32 = data[offset2++];
 					var q2y : Float32 = data[offset2++];
 					var q2z : Float32 = data[offset2++];
 					var q2z : Float32 = data[offset2++];
-					var q2w : Float32 = data[offset2++];
+					var q2w : Float32 = Math.sqrt(hxd.Math.abs(1 - (q2x*q2x+q2y*q2y+q2z*q2z)));
+
 					// qlerp nearest
 					// qlerp nearest
 					var dot = q1x * q2x + q1y * q2y + q1z * q2z + q1w * q2w;
 					var dot = q1x * q2x + q1y * q2y + q1z * q2z + q1w * q2w;
 					var q2 = dot < 0 ? -k2 : k2;
 					var q2 = dot < 0 ? -k2 : k2;

+ 1 - 1
hxd/fmt/fbx/HMDOut.hx

@@ -721,10 +721,10 @@ class HMDOut extends BaseLibrary {
 			}
 			}
 			if( o.hasRotation ) {
 			if( o.hasRotation ) {
 				var ql = Math.sqrt(f.qx * f.qx + f.qy * f.qy + f.qz * f.qz + f.qw * f.qw);
 				var ql = Math.sqrt(f.qx * f.qx + f.qy * f.qy + f.qz * f.qz + f.qw * f.qw);
+				if( ql * f.qw < 0 ) ql = -ql; // make sure normalized qw > 0
 				writeFloat(round(f.qx / ql));
 				writeFloat(round(f.qx / ql));
 				writeFloat(round(f.qy / ql));
 				writeFloat(round(f.qy / ql));
 				writeFloat(round(f.qz / ql));
 				writeFloat(round(f.qz / ql));
-				writeFloat(round(f.qw / ql));
 			}
 			}
 			if( o.hasScale ) {
 			if( o.hasScale ) {
 				writeFloat(f.sx);
 				writeFloat(f.sx);

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

@@ -192,7 +192,7 @@ class AnimationObject {
 	public function getStride() {
 	public function getStride() {
 		var stride = 0;
 		var stride = 0;
 		if( flags.has(HasPosition) ) stride += 3;
 		if( flags.has(HasPosition) ) stride += 3;
-		if( flags.has(HasRotation) ) stride += 4;
+		if( flags.has(HasRotation) ) stride += 3;
 		if( flags.has(HasScale) ) stride += 3;
 		if( flags.has(HasScale) ) stride += 3;
 		if( flags.has(HasUV) ) stride += 2;
 		if( flags.has(HasUV) ) stride += 2;
 		if( flags.has(HasAlpha) ) stride += 1;
 		if( flags.has(HasAlpha) ) stride += 1;

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

@@ -201,7 +201,7 @@ class Dump {
 				if( o.flags.has(HasPosition) )
 				if( o.flags.has(HasPosition) )
 					stride += 3;
 					stride += 3;
 				if( o.flags.has(HasRotation) )
 				if( o.flags.has(HasRotation) )
-					stride += h.version < 3 ? 3 : 4;
+					stride += 3;
 				if( o.flags.has(HasScale) )
 				if( o.flags.has(HasScale) )
 					stride += 3;
 					stride += 3;
 				if( o.flags.has(SingleFrame) )
 				if( o.flags.has(SingleFrame) )

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

@@ -425,7 +425,7 @@ class Library {
 			}
 			}
 			if( o.flags.has(HasRotation) ) {
 			if( o.flags.has(HasRotation) ) {
 				c.layout.set(Rotation);
 				c.layout.set(Rotation);
-				stride += 4 * sm;
+				stride += 3 * sm;
 			}
 			}
 			if( o.flags.has(HasScale) ) {
 			if( o.flags.has(HasScale) ) {
 				c.layout.set(Scale);
 				c.layout.set(Scale);