From f9be42ee62f7dcdbaa9928458deeb27571101e39 Mon Sep 17 00:00:00 2001 From: jmekaelthas Date: Wed, 8 Apr 2015 20:02:33 +0200 Subject: [PATCH] Bugfix: fixed problem with ipo curves computin during animations import. --- .../plugins/blender/animations/AnimationHelper.java | 4 ++-- .../plugins/blender/animations/BlenderAction.java | 12 ++++++------ .../plugins/blender/animations/BoneContext.java | 11 +++++++---- .../jme3/scene/plugins/blender/animations/Ipo.java | 13 +++++++++++-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/AnimationHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/AnimationHelper.java index f8c1cdad3..1d889f992 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/AnimationHelper.java +++ b/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 animations = new ArrayList(); 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 animations = new ArrayList(); 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); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BlenderAction.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BlenderAction.java index aa36c918e..38a437ba0 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BlenderAction.java +++ b/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 tracks = new ArrayList(featuresTracks.size()); for (Entry 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 tracks = new ArrayList(featuresTracks.size()); for (Entry 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()]); } diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java index 0eb50fb65..adc0a5c4c 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java +++ b/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. diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java index f388b703f..f5113129f 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/Ipo.java +++ b/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!"); } }