Fixing a bug that raised an exception when bone animation was attached directly to the object for Blender 2.49.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9514 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent 1c429f0eb2
commit 440217fbd2
  1. 40
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java
  2. 29
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java

@ -1,5 +1,14 @@
package com.jme3.scene.plugins.blender.modifiers; package com.jme3.scene.plugins.blender.modifiers;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme3.animation.AnimControl; import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation; import com.jme3.animation.Animation;
import com.jme3.animation.Bone; import com.jme3.animation.Bone;
@ -26,14 +35,6 @@ import com.jme3.scene.plugins.blender.meshes.MeshContext;
import com.jme3.scene.plugins.blender.objects.ObjectHelper; import com.jme3.scene.plugins.blender.objects.ObjectHelper;
import com.jme3.scene.plugins.ogre.AnimData; import com.jme3.scene.plugins.ogre.AnimData;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* This modifier allows to add bone animation to the object. * This modifier allows to add bone animation to the object.
@ -145,6 +146,29 @@ import java.util.logging.Logger;
} }
} }
} }
//fetching action defined in object
Pointer pAction = (Pointer) objectStructure.getFieldValue("action");
if (pAction.isNotNull()) {
Structure actionStructure = pAction.fetchData(blenderContext.getInputStream()).get(0);
String actionName = actionStructure.getName();
BoneTrack[] tracks = armatureHelper.getTracks(actionStructure, skeleton, blenderContext);
if(tracks != null && tracks.length > 0) {
// determining the animation time
float maximumTrackLength = 0;
for (BoneTrack track : tracks) {
float length = track.getLength();
if (length > maximumTrackLength) {
maximumTrackLength = length;
}
}
Animation boneAnimation = new Animation(actionName, maximumTrackLength);
boneAnimation.setTracks(tracks);
animations.add(boneAnimation);
}
}
animData = new AnimData(skeleton, animations); animData = new AnimData(skeleton, animations);
// store the animation data for each bone // store the animation data for each bone

@ -135,28 +135,13 @@ public class ModifierHelper extends AbstractBlenderHelper {
*/ */
private Modifier readAnimationModifier249(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException { private Modifier readAnimationModifier249(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
Modifier result = null; Modifier result = null;
Pointer pAction = (Pointer) objectStructure.getFieldValue("action"); Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo");
IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class); if (pIpo.isNotNull()) {
if (pAction.isNotNull()) { IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
Structure action = pAction.fetchData(blenderContext.getInputStream()).get(0); Structure ipoStructure = pIpo.fetchData(blenderContext.getInputStream()).get(0);
List<Structure> actionChannels = ((Structure) action.getFieldValue("chanbase")).evaluateListBase(blenderContext); Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext);
if (actionChannels.size() == 1) {// object's animtion action has only one channel result = new ObjectAnimationModifier(ipo, objectStructure.getName(), objectStructure.getOldMemoryAddress(), blenderContext);
Pointer pChannelIpo = (Pointer) actionChannels.get(0).getFieldValue("ipo"); blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result);
Structure ipoStructure = pChannelIpo.fetchData(blenderContext.getInputStream()).get(0);
Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext);
result = new ObjectAnimationModifier(ipo, action.getName(), objectStructure.getOldMemoryAddress(), blenderContext);
blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result);
} else {
throw new IllegalStateException("Object's action cannot have more than one channel!");
}
} else {
Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo");
if (pIpo.isNotNull()) {
Structure ipoStructure = pIpo.fetchData(blenderContext.getInputStream()).get(0);
Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext);
result = new ObjectAnimationModifier(ipo, objectStructure.getName(), objectStructure.getOldMemoryAddress(), blenderContext);
blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result);
}
} }
return result; return result;
} }

Loading…
Cancel
Save