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
This commit is contained in:
parent
1c429f0eb2
commit
440217fbd2
@ -1,5 +1,14 @@
|
||||
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.Animation;
|
||||
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.ogre.AnimData;
|
||||
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.
|
||||
@ -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);
|
||||
|
||||
// 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 {
|
||||
Modifier result = null;
|
||||
Pointer pAction = (Pointer) objectStructure.getFieldValue("action");
|
||||
IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
|
||||
if (pAction.isNotNull()) {
|
||||
Structure action = pAction.fetchData(blenderContext.getInputStream()).get(0);
|
||||
List<Structure> actionChannels = ((Structure) action.getFieldValue("chanbase")).evaluateListBase(blenderContext);
|
||||
if (actionChannels.size() == 1) {// object's animtion action has only one channel
|
||||
Pointer pChannelIpo = (Pointer) actionChannels.get(0).getFieldValue("ipo");
|
||||
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);
|
||||
}
|
||||
Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo");
|
||||
if (pIpo.isNotNull()) {
|
||||
IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user