* 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-0572b91ccdca3.0
parent
ef98888ce7
commit
78bbe9b251
@ -1,90 +1,90 @@ |
|||||||
package com.jme3.scene.plugins.blender.modifiers; |
package com.jme3.scene.plugins.blender.modifiers; |
||||||
|
|
||||||
import com.jme3.animation.AnimControl; |
import com.jme3.animation.AnimControl; |
||||||
import com.jme3.animation.Animation; |
import com.jme3.animation.Animation; |
||||||
import com.jme3.animation.SpatialTrack; |
import com.jme3.animation.SpatialTrack; |
||||||
import com.jme3.scene.Node; |
import com.jme3.scene.Node; |
||||||
import com.jme3.scene.plugins.blender.BlenderContext; |
import com.jme3.scene.plugins.blender.BlenderContext; |
||||||
import com.jme3.scene.plugins.blender.animations.Ipo; |
import com.jme3.scene.plugins.blender.animations.Ipo; |
||||||
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; |
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; |
||||||
import com.jme3.scene.plugins.ogre.AnimData; |
import com.jme3.scene.plugins.ogre.AnimData; |
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.HashMap; |
import java.util.HashMap; |
||||||
import java.util.logging.Level; |
import java.util.logging.Level; |
||||||
import java.util.logging.Logger; |
import java.util.logging.Logger; |
||||||
|
|
||||||
/** |
/** |
||||||
* This modifier allows to add animation to the object. |
* This modifier allows to add animation to the object. |
||||||
* |
* |
||||||
* @author Marcin Roguski (Kaelthas) |
* @author Marcin Roguski (Kaelthas) |
||||||
*/ |
*/ |
||||||
/* package */class ObjectAnimationModifier extends Modifier { |
/* package */class ObjectAnimationModifier extends Modifier { |
||||||
private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); |
private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); |
||||||
|
|
||||||
/** Loaded animation data. */ |
/** Loaded animation data. */ |
||||||
private AnimData animData; |
private AnimData animData; |
||||||
|
|
||||||
/** |
/** |
||||||
* This constructor reads animation of the object itself (without bones) and |
* This constructor reads animation of the object itself (without bones) and |
||||||
* stores it as an ArmatureModifierData modifier. The animation is returned |
* stores it as an ArmatureModifierData modifier. The animation is returned |
||||||
* as a modifier. It should be later applied regardless other modifiers. The |
* 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 |
* 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 |
* animation should be working. The stored modifier is an anim data and |
||||||
* additional data is given object's OMA. |
* additional data is given object's OMA. |
||||||
* |
* |
||||||
* @param ipo |
* @param ipo |
||||||
* the object's interpolation curves |
* the object's interpolation curves |
||||||
* @param objectAnimationName |
* @param objectAnimationName |
||||||
* the name of object's animation |
* the name of object's animation |
||||||
* @param objectOMA |
* @param objectOMA |
||||||
* the OMA of the object |
* the OMA of the object |
||||||
* @param blenderContext |
* @param blenderContext |
||||||
* the blender context |
* the blender context |
||||||
* @throws BlenderFileException |
* @throws BlenderFileException |
||||||
* this exception is thrown when the blender file is somehow |
* this exception is thrown when the blender file is somehow |
||||||
* corrupted |
* corrupted |
||||||
*/ |
*/ |
||||||
public ObjectAnimationModifier(Ipo ipo, String objectAnimationName, Long objectOMA, BlenderContext blenderContext) throws BlenderFileException { |
public ObjectAnimationModifier(Ipo ipo, String objectAnimationName, Long objectOMA, BlenderContext blenderContext) throws BlenderFileException { |
||||||
int fps = blenderContext.getBlenderKey().getFps(); |
int fps = blenderContext.getBlenderKey().getFps(); |
||||||
|
|
||||||
// calculating track
|
// calculating track
|
||||||
SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, 0, ipo.getLastFrame(), fps, true); |
SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, 0, ipo.getLastFrame(), fps, true); |
||||||
|
|
||||||
Animation animation = new Animation(objectAnimationName, ipo.getLastFrame() / fps); |
Animation animation = new Animation(objectAnimationName, ipo.getLastFrame() / (float)fps); |
||||||
animation.setTracks(new SpatialTrack[] { track }); |
animation.setTracks(new SpatialTrack[] { track }); |
||||||
ArrayList<Animation> animations = new ArrayList<Animation>(1); |
ArrayList<Animation> animations = new ArrayList<Animation>(1); |
||||||
animations.add(animation); |
animations.add(animation); |
||||||
|
|
||||||
animData = new AnimData(null, animations); |
animData = new AnimData(null, animations); |
||||||
blenderContext.setAnimData(objectOMA, animData); |
blenderContext.setAnimData(objectOMA, animData); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public Node apply(Node node, BlenderContext blenderContext) { |
public Node apply(Node node, BlenderContext blenderContext) { |
||||||
if (invalid) { |
if (invalid) { |
||||||
LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName()); |
LOGGER.log(Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName()); |
||||||
}// if invalid, animData will be null
|
}// if invalid, animData will be null
|
||||||
if (animData != null) { |
if (animData != null) { |
||||||
// INFO: constraints for this modifier are applied in the
|
// INFO: constraints for this modifier are applied in the
|
||||||
// ObjectHelper when the whole object is loaded
|
// ObjectHelper when the whole object is loaded
|
||||||
ArrayList<Animation> animList = animData.anims; |
ArrayList<Animation> animList = animData.anims; |
||||||
if (animList != null && animList.size() > 0) { |
if (animList != null && animList.size() > 0) { |
||||||
HashMap<String, Animation> anims = new HashMap<String, Animation>(); |
HashMap<String, Animation> anims = new HashMap<String, Animation>(); |
||||||
for (int i = 0; i < animList.size(); ++i) { |
for (int i = 0; i < animList.size(); ++i) { |
||||||
Animation animation = animList.get(i); |
Animation animation = animList.get(i); |
||||||
anims.put(animation.getName(), animation); |
anims.put(animation.getName(), animation); |
||||||
} |
} |
||||||
|
|
||||||
AnimControl control = new AnimControl(null); |
AnimControl control = new AnimControl(null); |
||||||
control.setAnimations(anims); |
control.setAnimations(anims); |
||||||
node.addControl(control); |
node.addControl(control); |
||||||
} |
} |
||||||
} |
} |
||||||
return node; |
return node; |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public String getType() { |
public String getType() { |
||||||
return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; |
return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue