From 78bbe9b251295df0817468b8f9703917002d9136 Mon Sep 17 00:00:00 2001 From: "Sha..om" Date: Mon, 6 Aug 2012 20:57:45 +0000 Subject: [PATCH] * Fix issue where blender animation importer was truncating the animation duration to an integer (thanks rectalogic) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9626 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../modifiers/ObjectAnimationModifier.java | 180 +++++++++--------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java index 2dcb9220f..8d6dc7d2b 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java @@ -1,90 +1,90 @@ -package com.jme3.scene.plugins.blender.modifiers; - -import com.jme3.animation.AnimControl; -import com.jme3.animation.Animation; -import com.jme3.animation.SpatialTrack; -import com.jme3.scene.Node; -import com.jme3.scene.plugins.blender.BlenderContext; -import com.jme3.scene.plugins.blender.animations.Ipo; -import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; -import com.jme3.scene.plugins.ogre.AnimData; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * This modifier allows to add animation to the object. - * - * @author Marcin Roguski (Kaelthas) - */ -/* package */class ObjectAnimationModifier extends Modifier { - private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); - - /** Loaded animation data. */ - private AnimData animData; - - /** - * This constructor reads animation of the object itself (without bones) and - * stores it as an ArmatureModifierData modifier. The animation is returned - * as a modifier. It should be later applied regardless other modifiers. The - * reason for this is that object may not have modifiers added but it's - * animation should be working. The stored modifier is an anim data and - * additional data is given object's OMA. - * - * @param ipo - * the object's interpolation curves - * @param objectAnimationName - * the name of object's animation - * @param objectOMA - * the OMA of the object - * @param blenderContext - * the blender context - * @throws BlenderFileException - * this exception is thrown when the blender file is somehow - * corrupted - */ - public ObjectAnimationModifier(Ipo ipo, String objectAnimationName, Long objectOMA, BlenderContext blenderContext) throws BlenderFileException { - int fps = blenderContext.getBlenderKey().getFps(); - - // calculating track - SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, 0, ipo.getLastFrame(), fps, true); - - Animation animation = new Animation(objectAnimationName, ipo.getLastFrame() / fps); - animation.setTracks(new SpatialTrack[] { track }); - ArrayList animations = new ArrayList(1); - animations.add(animation); - - animData = new AnimData(null, animations); - blenderContext.setAnimData(objectOMA, animData); - } - - @Override - public Node apply(Node node, BlenderContext blenderContext) { - if (invalid) { - LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName()); - }// if invalid, animData will be null - if (animData != null) { - // INFO: constraints for this modifier are applied in the - // ObjectHelper when the whole object is loaded - ArrayList animList = animData.anims; - if (animList != null && animList.size() > 0) { - HashMap anims = new HashMap(); - for (int i = 0; i < animList.size(); ++i) { - Animation animation = animList.get(i); - anims.put(animation.getName(), animation); - } - - AnimControl control = new AnimControl(null); - control.setAnimations(anims); - node.addControl(control); - } - } - return node; - } - - @Override - public String getType() { - return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; - } -} +package com.jme3.scene.plugins.blender.modifiers; + +import com.jme3.animation.AnimControl; +import com.jme3.animation.Animation; +import com.jme3.animation.SpatialTrack; +import com.jme3.scene.Node; +import com.jme3.scene.plugins.blender.BlenderContext; +import com.jme3.scene.plugins.blender.animations.Ipo; +import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; +import com.jme3.scene.plugins.ogre.AnimData; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This modifier allows to add animation to the object. + * + * @author Marcin Roguski (Kaelthas) + */ +/* package */class ObjectAnimationModifier extends Modifier { + private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); + + /** Loaded animation data. */ + private AnimData animData; + + /** + * This constructor reads animation of the object itself (without bones) and + * stores it as an ArmatureModifierData modifier. The animation is returned + * as a modifier. It should be later applied regardless other modifiers. The + * reason for this is that object may not have modifiers added but it's + * animation should be working. The stored modifier is an anim data and + * additional data is given object's OMA. + * + * @param ipo + * the object's interpolation curves + * @param objectAnimationName + * the name of object's animation + * @param objectOMA + * the OMA of the object + * @param blenderContext + * the blender context + * @throws BlenderFileException + * this exception is thrown when the blender file is somehow + * corrupted + */ + public ObjectAnimationModifier(Ipo ipo, String objectAnimationName, Long objectOMA, BlenderContext blenderContext) throws BlenderFileException { + int fps = blenderContext.getBlenderKey().getFps(); + + // calculating track + SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, 0, ipo.getLastFrame(), fps, true); + + Animation animation = new Animation(objectAnimationName, ipo.getLastFrame() / (float)fps); + animation.setTracks(new SpatialTrack[] { track }); + ArrayList animations = new ArrayList(1); + animations.add(animation); + + animData = new AnimData(null, animations); + blenderContext.setAnimData(objectOMA, animData); + } + + @Override + public Node apply(Node node, BlenderContext blenderContext) { + if (invalid) { + LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName()); + }// if invalid, animData will be null + if (animData != null) { + // INFO: constraints for this modifier are applied in the + // ObjectHelper when the whole object is loaded + ArrayList animList = animData.anims; + if (animList != null && animList.size() > 0) { + HashMap anims = new HashMap(); + for (int i = 0; i < animList.size(); ++i) { + Animation animation = animList.get(i); + anims.put(animation.getName(), animation); + } + + AnimControl control = new AnimControl(null); + control.setAnimations(anims); + node.addControl(control); + } + } + return node; + } + + @Override + public String getType() { + return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; + } +}