浏览代码

Bugfix: fixed problem with ipo curves computin during animations import.

jmekaelthas 10 年之前
父节点
当前提交
f9be42ee62

+ 2 - 2
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/AnimationHelper.java

@@ -71,7 +71,7 @@ public class AnimationHelper extends AbstractBlenderHelper {
         if (actions.size() > 0) {
             List<Animation> animations = new ArrayList<Animation>();
             for (BlenderAction action : actions) {
-                SpatialTrack[] tracks = action.toTracks(node);
+                SpatialTrack[] tracks = action.toTracks(node, blenderContext);
                 if (tracks != null && tracks.length > 0) {
                     Animation spatialAnimation = new Animation(action.getName(), action.getAnimationTime());
                     spatialAnimation.setTracks(tracks);
@@ -110,7 +110,7 @@ public class AnimationHelper extends AbstractBlenderHelper {
         if (actions.size() > 0) {
             List<Animation> animations = new ArrayList<Animation>();
             for (BlenderAction action : actions) {
-                BoneTrack[] tracks = action.toTracks(skeleton);
+                BoneTrack[] tracks = action.toTracks(skeleton, blenderContext);
                 if (tracks != null && tracks.length > 0) {
                     Animation boneAnimation = new Animation(action.getName(), action.getAnimationTime());
                     boneAnimation.setTracks(tracks);

+ 6 - 6
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BlenderAction.java

@@ -10,9 +10,8 @@ import java.util.Map.Entry;
 import com.jme3.animation.BoneTrack;
 import com.jme3.animation.Skeleton;
 import com.jme3.animation.SpatialTrack;
-import com.jme3.math.Quaternion;
-import com.jme3.math.Vector3f;
 import com.jme3.scene.Node;
+import com.jme3.scene.plugins.blender.BlenderContext;
 
 /**
  * An abstract representation of animation. The data stored here is mainly a
@@ -69,10 +68,10 @@ public class BlenderAction implements Cloneable {
      *            the node that will be animated
      * @return the spatial tracks for the node
      */
-    public SpatialTrack[] toTracks(Node node) {
+    public SpatialTrack[] toTracks(Node node, BlenderContext blenderContext) {
         List<SpatialTrack> tracks = new ArrayList<SpatialTrack>(featuresTracks.size());
         for (Entry<String, Ipo> entry : featuresTracks.entrySet()) {
-            tracks.add((SpatialTrack) entry.getValue().calculateTrack(0, node.getLocalTranslation(), node.getLocalRotation(), node.getLocalScale(), 1, stopFrame, fps, true));
+            tracks.add((SpatialTrack) entry.getValue().calculateTrack(0, null, node.getLocalTranslation(), node.getLocalRotation(), node.getLocalScale(), 1, stopFrame, fps, true));
         }
         return tracks.toArray(new SpatialTrack[tracks.size()]);
     }
@@ -84,11 +83,12 @@ public class BlenderAction implements Cloneable {
      *            the skeleton that will be animated
      * @return the bone tracks for the node
      */
-    public BoneTrack[] toTracks(Skeleton skeleton) {
+    public BoneTrack[] toTracks(Skeleton skeleton, BlenderContext blenderContext) {
         List<BoneTrack> tracks = new ArrayList<BoneTrack>(featuresTracks.size());
         for (Entry<String, Ipo> entry : featuresTracks.entrySet()) {
             int boneIndex = skeleton.getBoneIndex(entry.getKey());
-            tracks.add((BoneTrack) entry.getValue().calculateTrack(boneIndex, Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ, 1, stopFrame, fps, false));
+            BoneContext boneContext = blenderContext.getBoneContext(skeleton.getBone(boneIndex));
+            tracks.add((BoneTrack) entry.getValue().calculateTrack(boneIndex, boneContext, boneContext.getBone().getBindPosition(), boneContext.getBone().getBindRotation(), boneContext.getBone().getBindScale(), 1, stopFrame, fps, false));
         }
         return tracks.toArray(new BoneTrack[tracks.size()]);
     }

+ 7 - 4
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java

@@ -25,10 +25,13 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
  */
 public class BoneContext {
     // the flags of the bone
-    public static final int      SELECTED                            = 0x0001;
-    public static final int      CONNECTED_TO_PARENT                 = 0x0010;
-    public static final int      DEFORM                              = 0x1000;
-
+    public static final int      SELECTED                            = 0x000001;
+    public static final int      CONNECTED_TO_PARENT                 = 0x000010;
+    public static final int      DEFORM                              = 0x001000;
+    public static final int      NO_LOCAL_LOCATION                   = 0x400000;
+    public static final int      NO_INHERIT_SCALE                    = 0x008000;
+    public static final int      NO_INHERIT_ROTATION                 = 0x000200;
+    
     /**
      * The bones' matrices have, unlike objects', the coordinate system identical to JME's (Y axis is UP, X to the right and Z toward us).
      * So in order to have them loaded properly we need to transform their armature matrix (which blender sees as rotated) to make sure we get identical results.

+ 11 - 2
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java

@@ -137,7 +137,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, Vector3f localTranslation, Quaternion localRotation, Vector3f localScale, int startFrame, int stopFrame, int fps, boolean spatialTrack) {
+    public Track calculateTrack(int targetIndex, BoneContext boneContext, Vector3f localTranslation, Quaternion localRotation, Vector3f localScale, int startFrame, int stopFrame, int fps, boolean spatialTrack) {
         if (calculatedTrack == null) {
             // preparing data for track
             int framesAmount = stopFrame - startFrame;
@@ -236,6 +236,15 @@ public class Ipo {
                     }
                 }
                 translations[index] = localRotation.multLocal(new Vector3f(translation[0], translation[1], translation[2]));
+                
+                if(boneContext != null) {
+                    if(boneContext.getBone().getParent() == null && boneContext.is(BoneContext.NO_LOCAL_LOCATION)) {
+                        float temp = translations[index].z;
+                        translations[index].z = -translations[index].y;
+                        translations[index].y = temp;
+                    }
+                }
+                
                 if (queternionRotationUsed) {
                     rotations[index] = new Quaternion(quaternionRotation[0], quaternionRotation[1], quaternionRotation[2], quaternionRotation[3]);
                 } else {
@@ -292,7 +301,7 @@ public class Ipo {
         }
 
         @Override
-        public BoneTrack calculateTrack(int boneIndex, Vector3f localTranslation, Quaternion localRotation, Vector3f localScale, int startFrame, int stopFrame, int fps, boolean boneTrack) {
+        public BoneTrack calculateTrack(int boneIndex, BoneContext boneContext, Vector3f localTranslation, Quaternion localRotation, Vector3f localScale, int startFrame, int stopFrame, int fps, boolean boneTrack) {
             throw new IllegalStateException("Constatnt ipo object cannot be used for calculating bone tracks!");
         }
     }