Parcourir la source

Fix for animation rotations computation (in blender earlier than 2.50 the rotations were stored in degrees and later in radians). Thanks to @rectalogic for finding this :).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9717 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Kae..pl il y a 13 ans
Parent
commit
e83b15028b

+ 1 - 1
engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java

@@ -199,7 +199,7 @@ public class ArmatureHelper extends AbstractBlenderHelper {
 					bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
 					bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
 				}
 				}
 
 
-				Ipo ipo = new Ipo(bezierCurves, fixUpAxis);
+				Ipo ipo = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
 				tracks.add((BoneTrack) ipo.calculateTrack(boneIndex, 0, ipo.getLastFrame(), fps, false));
 				tracks.add((BoneTrack) ipo.calculateTrack(boneIndex, 0, ipo.getLastFrame(), fps, false));
 			}
 			}
 		}
 		}

+ 14 - 4
engine/src/blender/com/jme3/scene/plugins/blender/animations/Ipo.java

@@ -40,16 +40,23 @@ public class Ipo {
 	private Track			calculatedTrack;
 	private Track			calculatedTrack;
 	/** This variable indicates if the Y asxis is the UP axis or not. */
 	/** This variable indicates if the Y asxis is the UP axis or not. */
 	protected boolean		fixUpAxis;
 	protected boolean		fixUpAxis;
+	/** Depending on the blender version rotations are stored in degrees or radians so we need to know the version that is used. */
+	protected final int		blenderVersion;
 
 
 	/**
 	/**
 	 * Constructor. Stores the bezier curves.
 	 * Constructor. Stores the bezier curves.
 	 * 
 	 * 
 	 * @param bezierCurves
 	 * @param bezierCurves
 	 *            a table of bezier curves
 	 *            a table of bezier curves
+	 * @param fixUpAxis
+	 * 			  indicates if the Y is the up axis or not
+	 * @param blenderVersion
+	 * 			  the blender version that is currently used
 	 */
 	 */
-	public Ipo(BezierCurve[] bezierCurves, boolean fixUpAxis) {
+	public Ipo(BezierCurve[] bezierCurves, boolean fixUpAxis, int blenderVersion) {
 		this.bezierCurves = bezierCurves;
 		this.bezierCurves = bezierCurves;
 		this.fixUpAxis = fixUpAxis;
 		this.fixUpAxis = fixUpAxis;
+		this.blenderVersion = blenderVersion;
 	}
 	}
 
 
 	/**
 	/**
@@ -141,8 +148,11 @@ public class Ipo {
 			float[] objectRotation = new float[3];
 			float[] objectRotation = new float[3];
 			Vector3f[] scales = new Vector3f[framesAmount + 1];
 			Vector3f[] scales = new Vector3f[framesAmount + 1];
 			float[] scale = new float[] { 1.0f, 1.0f, 1.0f };
 			float[] scale = new float[] { 1.0f, 1.0f, 1.0f };
-			float degreeToRadiansFactor = FastMath.DEG_TO_RAD * 10;// the values in blender are divided by 10, so we need to mult it here
-
+			float degreeToRadiansFactor = 1;
+			if(blenderVersion < 250) {//in blender earlier than 2.50 the values are stored in degrees
+				degreeToRadiansFactor *= FastMath.DEG_TO_RAD * 10;// the values in blender are divided by 10, so we need to mult it here
+			}
+			
 			// calculating track data
 			// calculating track data
 			for (int frame = startFrame; frame <= stopFrame; ++frame) {
 			for (int frame = startFrame; frame <= stopFrame; ++frame) {
 				int index = frame - startFrame;
 				int index = frame - startFrame;
@@ -150,7 +160,7 @@ public class Ipo {
 				for (int j = 0; j < bezierCurves.length; ++j) {
 				for (int j = 0; j < bezierCurves.length; ++j) {
 					double value = bezierCurves[j].evaluate(frame, BezierCurve.Y_VALUE);
 					double value = bezierCurves[j].evaluate(frame, BezierCurve.Y_VALUE);
 					switch (bezierCurves[j].getType()) {
 					switch (bezierCurves[j].getType()) {
-					// LOCATION
+						// LOCATION
 						case AC_LOC_X:
 						case AC_LOC_X:
 							translation[0] = (float) value;
 							translation[0] = (float) value;
 							break;
 							break;

+ 3 - 3
engine/src/blender/com/jme3/scene/plugins/blender/animations/IpoHelper.java

@@ -63,7 +63,7 @@ public class IpoHelper extends AbstractBlenderHelper {
 				bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
 				bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
 			}
 			}
 			curves.clear();
 			curves.clear();
-			result = new Ipo(bezierCurves, fixUpAxis);
+			result = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
 			blenderContext.addLoadedFeatures(ipoStructure.getOldMemoryAddress(), ipoStructure.getName(), ipoStructure, result);
 			blenderContext.addLoadedFeatures(ipoStructure.getOldMemoryAddress(), ipoStructure.getName(), ipoStructure, result);
 		}
 		}
 		return result;
 		return result;
@@ -95,7 +95,7 @@ public class IpoHelper extends AbstractBlenderHelper {
 				bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
 				bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
 			}
 			}
 			curves.clear();
 			curves.clear();
-			result = new Ipo(bezierCurves, fixUpAxis);
+			result = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
 		}
 		}
 		return result;
 		return result;
 	}
 	}
@@ -174,7 +174,7 @@ public class IpoHelper extends AbstractBlenderHelper {
 		 *            the constant value of this ipo
 		 *            the constant value of this ipo
 		 */
 		 */
 		public ConstIpo(float constValue) {
 		public ConstIpo(float constValue) {
-			super(null, false);
+			super(null, false, 0);//the version is not important here
 			this.constValue = constValue;
 			this.constValue = constValue;
 		}
 		}