From 217a1a6273a22e225c3b5188c6f0b24d44794adb Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Sun, 12 May 2013 19:05:24 +0000 Subject: [PATCH] Refactoring: removing AnimData class use in blender importer to make it independent on the OGRE plugin (this way the usage of the importer will not require the presence of Ogre plugin in the classpath). git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10611 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/com/jme3/asset/BlenderKey.java | 8 ++--- .../scene/plugins/blender/BlenderContext.java | 8 ++--- .../blender/animations/AnimationData.java | 29 +++++++++++++++++++ .../blender/modifiers/ArmatureModifier.java | 16 +++++----- .../modifiers/ObjectAnimationModifier.java | 13 +++++---- 5 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 engine/src/blender/com/jme3/scene/plugins/blender/animations/AnimationData.java diff --git a/engine/src/blender/com/jme3/asset/BlenderKey.java b/engine/src/blender/com/jme3/asset/BlenderKey.java index dedbbd4d6..a283e824d 100644 --- a/engine/src/blender/com/jme3/asset/BlenderKey.java +++ b/engine/src/blender/com/jme3/asset/BlenderKey.java @@ -54,7 +54,7 @@ import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.SceneGraphVisitor; import com.jme3.scene.Spatial; -import com.jme3.scene.plugins.ogre.AnimData; +import com.jme3.scene.plugins.blender.animations.AnimationData; import com.jme3.texture.Texture; /** @@ -541,7 +541,7 @@ public class BlenderKey extends ModelKey { /** Textures from all objects. */ private List textures; /** Animations of all objects. */ - private List animations; + private List animations; /** All cameras from the file. */ private List cameras; /** All lights from the file. */ @@ -567,7 +567,7 @@ public class BlenderKey extends ModelKey { } } if ((featuresToLoad & FeaturesToLoad.ANIMATIONS) != 0) { - animations = new ArrayList(); + animations = new ArrayList(); } } if ((featuresToLoad & FeaturesToLoad.CAMERAS) != 0) { @@ -689,7 +689,7 @@ public class BlenderKey extends ModelKey { * This method returns all loaded animations. * @return all loaded animations */ - public List getAnimations() { + public List getAnimations() { return animations; } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java index ac8fda76e..cb64b0619 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java @@ -47,6 +47,7 @@ import com.jme3.asset.BlenderKey; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.scene.Node; +import com.jme3.scene.plugins.blender.animations.AnimationData; import com.jme3.scene.plugins.blender.animations.BoneContext; import com.jme3.scene.plugins.blender.constraints.Constraint; import com.jme3.scene.plugins.blender.file.BlenderInputStream; @@ -54,7 +55,6 @@ import com.jme3.scene.plugins.blender.file.DnaBlockData; import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.meshes.MeshContext; -import com.jme3.scene.plugins.ogre.AnimData; /** * The class that stores temporary data and manages it during loading the belnd @@ -103,7 +103,7 @@ public class BlenderContext { /** A list of constraints for the specified object. */ protected Map> constraints = new HashMap>(); /** Anim data loaded for features. */ - private Map animData = new HashMap(); + private Map animData = new HashMap(); /** Loaded skeletons. */ private Map skeletons = new HashMap(); /** A map between skeleton and node it modifies. */ @@ -406,7 +406,7 @@ public class BlenderContext { * @param animData * the animation data for the feature specified by ownerOMA */ - public void setAnimData(Long ownerOMA, AnimData animData) { + public void setAnimData(Long ownerOMA, AnimationData animData) { this.animData.put(ownerOMA, animData); } @@ -417,7 +417,7 @@ public class BlenderContext { * the old memory address of the animation data owner * @return the animation data or null if none exists */ - public AnimData getAnimData(Long ownerOMA) { + public AnimationData getAnimData(Long ownerOMA) { return this.animData.get(ownerOMA); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/animations/AnimationData.java b/engine/src/blender/com/jme3/scene/plugins/blender/animations/AnimationData.java new file mode 100644 index 000000000..05f405fc1 --- /dev/null +++ b/engine/src/blender/com/jme3/scene/plugins/blender/animations/AnimationData.java @@ -0,0 +1,29 @@ +package com.jme3.scene.plugins.blender.animations; + +import java.util.List; + +import com.jme3.animation.Animation; +import com.jme3.animation.Skeleton; + +/** + * A simple class that sotres animation data. + * If skeleton is null then we deal with object animation. + * + * @author Marcin Roguski (Kaelthas) + */ +public class AnimationData { + /** The skeleton. */ + public final Skeleton skeleton; + /** The animations list. */ + public final List anims; + + public AnimationData(List anims) { + this.anims = anims; + skeleton = null; + } + + public AnimationData(Skeleton skeleton, List anims) { + this.skeleton = skeleton; + this.anims = anims; + } +} 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 8b1e029fe..40b36ac22 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 @@ -27,6 +27,7 @@ import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; +import com.jme3.scene.plugins.blender.animations.AnimationData; import com.jme3.scene.plugins.blender.animations.ArmatureHelper; import com.jme3.scene.plugins.blender.animations.BoneContext; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -35,7 +36,6 @@ import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Structure; 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; /** @@ -53,7 +53,7 @@ import com.jme3.util.BufferUtils; private Structure meshStructure; /** Loaded animation data. */ - private AnimData animData; + private AnimationData animationData; /** Old memory address of the mesh that will have the skeleton applied. */ private Long meshOMA; @@ -157,7 +157,7 @@ import com.jme3.util.BufferUtils; } } - animData = new AnimData(skeleton, animations); + animationData = new AnimationData(skeleton, animations); // store the animation data for each bone for (Bone bone : bones) { @@ -165,7 +165,7 @@ import com.jme3.util.BufferUtils; BoneContext boneContext = blenderContext.getBoneContext(bone); Long boneOma = boneContext.getBoneOma(); if (boneOma != null) { - blenderContext.setAnimData(boneOma, animData); + blenderContext.setAnimData(boneOma, animationData); } } } @@ -181,7 +181,7 @@ import com.jme3.util.BufferUtils; 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 || skeleton == null) { + if (animationData == null || skeleton == null) { return node; } @@ -221,8 +221,8 @@ import com.jme3.util.BufferUtils; } // applying animations - AnimControl control = new AnimControl(animData.skeleton); - ArrayList animList = animData.anims; + AnimControl control = new AnimControl(animationData.skeleton); + List animList = animationData.anims; if (animList != null && animList.size() > 0) { HashMap anims = new HashMap(animList.size()); for (int i = 0; i < animList.size(); ++i) { @@ -232,7 +232,7 @@ import com.jme3.util.BufferUtils; control.setAnimations(anims); } node.addControl(control); - node.addControl(new SkeletonControl(animData.skeleton)); + node.addControl(new SkeletonControl(animationData.skeleton)); blenderContext.setNodeForSkeleton(skeleton, node); 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 4dee2246e..daa75a793 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 @@ -2,6 +2,7 @@ package com.jme3.scene.plugins.blender.modifiers; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -12,9 +13,9 @@ import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; +import com.jme3.scene.plugins.blender.animations.AnimationData; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; -import com.jme3.scene.plugins.ogre.AnimData; /** * This modifier allows to add animation to the object. @@ -25,7 +26,7 @@ import com.jme3.scene.plugins.ogre.AnimData; private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); /** Loaded animation data. */ - private AnimData animData; + private AnimationData animationData; /** * This constructor reads animation of the object itself (without bones) and @@ -59,8 +60,8 @@ import com.jme3.scene.plugins.ogre.AnimData; ArrayList animations = new ArrayList(1); animations.add(animation); - animData = new AnimData(null, animations); - blenderContext.setAnimData(objectOMA, animData); + animationData = new AnimationData(animations); + blenderContext.setAnimData(objectOMA, animationData); } @Override @@ -68,10 +69,10 @@ import com.jme3.scene.plugins.ogre.AnimData; 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) { + if (animationData != null) { // INFO: constraints for this modifier are applied in the // ObjectHelper when the whole object is loaded - ArrayList animList = animData.anims; + List animList = animationData.anims; if (animList != null && animList.size() > 0) { HashMap anims = new HashMap(); for (int i = 0; i < animList.size(); ++i) {