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
3.0
Kae..pl 12 years ago
parent c1402b30e9
commit 217a1a6273
  1. 8
      engine/src/blender/com/jme3/asset/BlenderKey.java
  2. 8
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java
  3. 29
      engine/src/blender/com/jme3/scene/plugins/blender/animations/AnimationData.java
  4. 16
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java
  5. 13
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java

@ -54,7 +54,7 @@ import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.SceneGraphVisitor; import com.jme3.scene.SceneGraphVisitor;
import com.jme3.scene.Spatial; 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; import com.jme3.texture.Texture;
/** /**
@ -541,7 +541,7 @@ public class BlenderKey extends ModelKey {
/** Textures from all objects. */ /** Textures from all objects. */
private List<Texture> textures; private List<Texture> textures;
/** Animations of all objects. */ /** Animations of all objects. */
private List<AnimData> animations; private List<AnimationData> animations;
/** All cameras from the file. */ /** All cameras from the file. */
private List<CameraNode> cameras; private List<CameraNode> cameras;
/** All lights from the file. */ /** All lights from the file. */
@ -567,7 +567,7 @@ public class BlenderKey extends ModelKey {
} }
} }
if ((featuresToLoad & FeaturesToLoad.ANIMATIONS) != 0) { if ((featuresToLoad & FeaturesToLoad.ANIMATIONS) != 0) {
animations = new ArrayList<AnimData>(); animations = new ArrayList<AnimationData>();
} }
} }
if ((featuresToLoad & FeaturesToLoad.CAMERAS) != 0) { if ((featuresToLoad & FeaturesToLoad.CAMERAS) != 0) {
@ -689,7 +689,7 @@ public class BlenderKey extends ModelKey {
* This method returns all loaded animations. * This method returns all loaded animations.
* @return all loaded animations * @return all loaded animations
*/ */
public List<AnimData> getAnimations() { public List<AnimationData> getAnimations() {
return animations; return animations;
} }

@ -47,6 +47,7 @@ import com.jme3.asset.BlenderKey;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.scene.Node; 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.animations.BoneContext;
import com.jme3.scene.plugins.blender.constraints.Constraint; import com.jme3.scene.plugins.blender.constraints.Constraint;
import com.jme3.scene.plugins.blender.file.BlenderInputStream; 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.FileBlockHeader;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.scene.plugins.blender.meshes.MeshContext; 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 * 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. */ /** A list of constraints for the specified object. */
protected Map<Long, List<Constraint>> constraints = new HashMap<Long, List<Constraint>>(); protected Map<Long, List<Constraint>> constraints = new HashMap<Long, List<Constraint>>();
/** Anim data loaded for features. */ /** Anim data loaded for features. */
private Map<Long, AnimData> animData = new HashMap<Long, AnimData>(); private Map<Long, AnimationData> animData = new HashMap<Long, AnimationData>();
/** Loaded skeletons. */ /** Loaded skeletons. */
private Map<Long, Skeleton> skeletons = new HashMap<Long, Skeleton>(); private Map<Long, Skeleton> skeletons = new HashMap<Long, Skeleton>();
/** A map between skeleton and node it modifies. */ /** A map between skeleton and node it modifies. */
@ -406,7 +406,7 @@ public class BlenderContext {
* @param animData * @param animData
* the animation data for the feature specified by ownerOMA * 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); this.animData.put(ownerOMA, animData);
} }
@ -417,7 +417,7 @@ public class BlenderContext {
* the old memory address of the animation data owner * the old memory address of the animation data owner
* @return the animation data or null if none exists * @return the animation data or null if none exists
*/ */
public AnimData getAnimData(Long ownerOMA) { public AnimationData getAnimData(Long ownerOMA) {
return this.animData.get(ownerOMA); return this.animData.get(ownerOMA);
} }

@ -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<Animation> anims;
public AnimationData(List<Animation> anims) {
this.anims = anims;
skeleton = null;
}
public AnimationData(Skeleton skeleton, List<Animation> anims) {
this.skeleton = skeleton;
this.anims = anims;
}
}

@ -27,6 +27,7 @@ import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; 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.ArmatureHelper;
import com.jme3.scene.plugins.blender.animations.BoneContext; import com.jme3.scene.plugins.blender.animations.BoneContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; 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.file.Structure;
import com.jme3.scene.plugins.blender.meshes.MeshContext; import com.jme3.scene.plugins.blender.meshes.MeshContext;
import com.jme3.scene.plugins.blender.objects.ObjectHelper; import com.jme3.scene.plugins.blender.objects.ObjectHelper;
import com.jme3.scene.plugins.ogre.AnimData;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
/** /**
@ -53,7 +53,7 @@ import com.jme3.util.BufferUtils;
private Structure meshStructure; private Structure meshStructure;
/** Loaded animation data. */ /** Loaded animation data. */
private AnimData animData; private AnimationData animationData;
/** Old memory address of the mesh that will have the skeleton applied. */ /** Old memory address of the mesh that will have the skeleton applied. */
private Long meshOMA; 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 // store the animation data for each bone
for (Bone bone : bones) { for (Bone bone : bones) {
@ -165,7 +165,7 @@ import com.jme3.util.BufferUtils;
BoneContext boneContext = blenderContext.getBoneContext(bone); BoneContext boneContext = blenderContext.getBoneContext(bone);
Long boneOma = boneContext.getBoneOma(); Long boneOma = boneContext.getBoneOma();
if (boneOma != null) { if (boneOma != null) {
blenderContext.setAnimData(boneOma, animData); blenderContext.setAnimData(boneOma, animationData);
} }
} }
} }
@ -181,7 +181,7 @@ import com.jme3.util.BufferUtils;
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 || skeleton == null) { if (animationData == null || skeleton == null) {
return node; return node;
} }
@ -221,8 +221,8 @@ import com.jme3.util.BufferUtils;
} }
// applying animations // applying animations
AnimControl control = new AnimControl(animData.skeleton); AnimControl control = new AnimControl(animationData.skeleton);
ArrayList<Animation> animList = animData.anims; List<Animation> animList = animationData.anims;
if (animList != null && animList.size() > 0) { if (animList != null && animList.size() > 0) {
HashMap<String, Animation> anims = new HashMap<String, Animation>(animList.size()); HashMap<String, Animation> anims = new HashMap<String, Animation>(animList.size());
for (int i = 0; i < animList.size(); ++i) { for (int i = 0; i < animList.size(); ++i) {
@ -232,7 +232,7 @@ import com.jme3.util.BufferUtils;
control.setAnimations(anims); control.setAnimations(anims);
} }
node.addControl(control); node.addControl(control);
node.addControl(new SkeletonControl(animData.skeleton)); node.addControl(new SkeletonControl(animationData.skeleton));
blenderContext.setNodeForSkeleton(skeleton, node); blenderContext.setNodeForSkeleton(skeleton, node);

@ -2,6 +2,7 @@ package com.jme3.scene.plugins.blender.modifiers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -12,9 +13,9 @@ import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; 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.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;
/** /**
* This modifier allows to add animation to the object. * 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()); private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName());
/** Loaded animation data. */ /** Loaded animation data. */
private AnimData animData; private AnimationData animationData;
/** /**
* This constructor reads animation of the object itself (without bones) and * This constructor reads animation of the object itself (without bones) and
@ -59,8 +60,8 @@ import com.jme3.scene.plugins.ogre.AnimData;
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); animationData = new AnimationData(animations);
blenderContext.setAnimData(objectOMA, animData); blenderContext.setAnimData(objectOMA, animationData);
} }
@Override @Override
@ -68,10 +69,10 @@ import com.jme3.scene.plugins.ogre.AnimData;
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 (animationData != 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; List<Animation> animList = animationData.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) {

Loading…
Cancel
Save