From 5842613c2be81c5e8663b39842fe7bd3fa5d0a5e Mon Sep 17 00:00:00 2001 From: jmekaelthas <76w1dxnh> Date: Wed, 3 Sep 2014 10:58:02 +0200 Subject: [PATCH] Bugfix: fixed a bug in skeleton animation constraints applying procedure. --- .../blender/constraints/SimulationNode.java | 43 ++++--------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/SimulationNode.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/SimulationNode.java index 1e1b2caa4..c1e64bfa1 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/SimulationNode.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/SimulationNode.java @@ -258,7 +258,6 @@ public class SimulationNode { float maxTime = animationTimeBoundaries[1]; Map tracks = new HashMap(); - Map previousTransforms = this.getInitialTransforms(); for (int frame = 0; frame < maxFrame; ++frame) { // this MUST be done here, otherwise setting next frame of animation will // lead to possible errors @@ -291,26 +290,15 @@ public class SimulationNode { // ... and fill in another frame in the result track for (Entry trackEntry : tracks.entrySet()) { - Integer boneIndex = trackEntry.getKey(); - Bone bone = skeleton.getBone(boneIndex); - - // take the initial transform of a bone and its virtual track - Transform previousTransform = previousTransforms.get(boneIndex); - VirtualTrack vTrack = trackEntry.getValue(); - - Vector3f bonePositionDifference = bone.getLocalPosition().subtract(previousTransform.getTranslation()); - Quaternion boneRotationDifference = bone.getLocalRotation().mult(previousTransform.getRotation().inverse()).normalizeLocal(); - Vector3f boneScaleDifference = bone.getLocalScale().divide(previousTransform.getScale()); - if (frame > 0) { - bonePositionDifference = vTrack.translations.get(frame - 1).add(bonePositionDifference); - boneRotationDifference = vTrack.rotations.get(frame - 1).mult(boneRotationDifference); - boneScaleDifference = vTrack.scales.get(frame - 1).mult(boneScaleDifference); - } - vTrack.setTransform(frame, new Transform(bonePositionDifference, boneRotationDifference, boneScaleDifference)); - - previousTransform.setTranslation(bone.getLocalPosition()); - previousTransform.setRotation(bone.getLocalRotation()); - previousTransform.setScale(bone.getLocalScale()); + Bone bone = skeleton.getBone(trackEntry.getKey()); + Transform startTransform = boneStartTransforms.get(bone); + + // track contains differences between the frame position and bind positions of bones/spatials + Vector3f bonePositionDifference = bone.getLocalPosition().subtract(startTransform.getTranslation()); + Quaternion boneRotationDifference = bone.getLocalRotation().mult(startTransform.getRotation().inverse()).normalizeLocal(); + Vector3f boneScaleDifference = bone.getLocalScale().divide(startTransform.getScale()); + + trackEntry.getValue().setTransform(frame, new Transform(bonePositionDifference, boneRotationDifference, boneScaleDifference)); } } @@ -427,19 +415,6 @@ public class SimulationNode { return result.size() > 0 ? result : null; } - /** - * Creates the initial transforms for all bones in the skelketon. - * @return the map where the key is the bone index and the value us the bone's initial transformation - */ - private Map getInitialTransforms() { - Map result = new HashMap(); - for (int i = 0; i < skeleton.getBoneCount(); ++i) { - Bone bone = skeleton.getBone(i); - result.put(i, new Transform(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale())); - } - return result; - } - @Override public String toString() { return name;