From 440217fbd2e2d9bf78786d71a92b4e268249bf66 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Wed, 20 Jun 2012 12:41:37 +0000 Subject: [PATCH] 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 --- .../blender/modifiers/ArmatureModifier.java | 40 +++++++++++++++---- .../blender/modifiers/ModifierHelper.java | 29 ++++---------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index 1680f6437..d361e9055 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java @@ -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 diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java index 7378a2eab..5e4e4371a 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java @@ -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 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; }