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

Bugfix: applied fix suggested by Tobiad Downer that properly computes tracks for rotated bones.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10138 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Kae..pl 12 жил өмнө
parent
commit
fada1b5b90

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

@@ -201,8 +201,9 @@ public class ArmatureHelper extends AbstractBlenderHelper {
 					bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
 				}
 
+				Bone bone = skeleton.getBone(boneIndex);
 				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, bone.getLocalRotation(), 0, ipo.getLastFrame(), fps, false));
 			}
 		}
 		return tracks.toArray(new BoneTrack[tracks.size()]);
@@ -235,9 +236,11 @@ public class ArmatureHelper extends AbstractBlenderHelper {
 				Pointer p = (Pointer) bActionChannel.getFieldValue("ipo");
 				if (!p.isNull()) {
 					Structure ipoStructure = p.fetchData(blenderContext.getInputStream()).get(0);
+					
+					Bone bone = skeleton.getBone(boneIndex);
 					Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext);
 					if(ipo != null) {
-						tracks.add((BoneTrack) ipo.calculateTrack(boneIndex, 0, ipo.getLastFrame(), fps, false));
+						tracks.add((BoneTrack) ipo.calculateTrack(boneIndex, bone.getLocalRotation(), 0, ipo.getLastFrame(), fps, false));
 					}
 				}
 			}

+ 9 - 6
engine/src/blender/com/jme3/scene/plugins/blender/animations/Ipo.java

@@ -120,6 +120,9 @@ public class Ipo {
 	 *            the index of the target for which the method calculates the
 	 *            tracks IMPORTANT! Aet to -1 (or any negative number) if you
 	 *            want to load spatial animation.
+	 * @param localQuaternionRotation
+	 *            the local rotation of the object/bone that will be animated by
+	 *            the track
 	 * @param startFrame
 	 *            the firs frame of tracks (inclusive)
 	 * @param stopFrame
@@ -133,7 +136,7 @@ public class Ipo {
 	 *            as jme while other features have different one (Z is UP)
 	 * @return bone track for the specified bone
 	 */
-	public Track calculateTrack(int targetIndex, int startFrame, int stopFrame, int fps, boolean spatialTrack) {
+	public Track calculateTrack(int targetIndex, Quaternion localQuaternionRotation, int startFrame, int stopFrame, int fps, boolean spatialTrack) {
 		if (calculatedTrack == null) {
 			// preparing data for track
 			int framesAmount = stopFrame - startFrame;
@@ -165,14 +168,14 @@ public class Ipo {
 							translation[0] = (float) value;
 							break;
 						case AC_LOC_Y:
-							if (fixUpAxis && spatialTrack) {
+							if (fixUpAxis) {
 								translation[2] = (float) -value;
 							} else {
 								translation[1] = (float) value;
 							}
 							break;
 						case AC_LOC_Z:
-							translation[fixUpAxis && spatialTrack ? 1 : 2] = (float) value;
+							translation[fixUpAxis ? 1 : 2] = (float) value;
 							break;
 
 						// ROTATION (used with object animation)
@@ -197,14 +200,14 @@ public class Ipo {
 							scale[0] = (float) value;
 							break;
 						case AC_SIZE_Y:
-							if (fixUpAxis && spatialTrack) {
+							if (fixUpAxis) {
 								scale[2] = (float) value;
 							} else {
 								scale[1] = (float) value;
 							}
 							break;
 						case AC_SIZE_Z:
-							scale[fixUpAxis && spatialTrack ? 1 : 2] = (float) value;
+							scale[fixUpAxis ? 1 : 2] = (float) value;
 							break;
 
 						// QUATERNION ROTATION (used with bone animation), dunno
@@ -234,7 +237,7 @@ public class Ipo {
 							LOGGER.warning("Unknown ipo curve type: " + bezierCurves[j].getType());
 					}
 				}
-				translations[index] = new Vector3f(translation[0], translation[1], translation[2]);
+				translations[index] = localQuaternionRotation.multLocal(new Vector3f(translation[0], translation[1], translation[2]));
 				rotations[index] = spatialTrack ? new Quaternion().fromAngles(objectRotation) : new Quaternion(quaternionRotation[0], quaternionRotation[1], quaternionRotation[2], quaternionRotation[3]);
 				scales[index] = new Vector3f(scale[0], scale[1], scale[2]);
 			}

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

@@ -1,6 +1,7 @@
 package com.jme3.scene.plugins.blender.animations;
 
 import com.jme3.animation.BoneTrack;
+import com.jme3.math.Quaternion;
 import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
 import com.jme3.scene.plugins.blender.BlenderContext;
 import com.jme3.scene.plugins.blender.curves.BezierCurve;
@@ -194,7 +195,7 @@ public class IpoHelper extends AbstractBlenderHelper {
 		}
 
 		@Override
-		public BoneTrack calculateTrack(int boneIndex, int startFrame, int stopFrame, int fps, boolean boneTrack) {
+		public BoneTrack calculateTrack(int boneIndex, Quaternion localQuaternionRotation, int startFrame, int stopFrame, int fps, boolean boneTrack) {
 			throw new IllegalStateException("Constatnt ipo object cannot be used for calculating bone tracks!");
 		}
 	}

+ 10 - 6
engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java

@@ -1,17 +1,20 @@
 package com.jme3.scene.plugins.blender.modifiers;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import com.jme3.animation.AnimControl;
 import com.jme3.animation.Animation;
 import com.jme3.animation.SpatialTrack;
 import com.jme3.scene.Node;
+import com.jme3.scene.Spatial;
 import com.jme3.scene.plugins.blender.BlenderContext;
+import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
 import com.jme3.scene.plugins.blender.animations.Ipo;
 import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
 import com.jme3.scene.plugins.ogre.AnimData;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 /**
  * This modifier allows to add animation to the object.
@@ -46,9 +49,10 @@ import java.util.logging.Logger;
 	 */
 	public ObjectAnimationModifier(Ipo ipo, String objectAnimationName, Long objectOMA, BlenderContext blenderContext) throws BlenderFileException {
 		int fps = blenderContext.getBlenderKey().getFps();
-
+		
+		Spatial object = (Spatial) blenderContext.getLoadedFeature(objectOMA, LoadedFeatureDataType.LOADED_FEATURE);
 		// calculating track
-		SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, 0, ipo.getLastFrame(), fps, true);
+		SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, object.getLocalRotation(), 0, ipo.getLastFrame(), fps, true);
 
 		Animation animation = new Animation(objectAnimationName, ipo.getLastFrame() / (float)fps);
 		animation.setTracks(new SpatialTrack[] { track });