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 ff5adcd3e..c26251f4f 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 @@ -45,6 +45,8 @@ import com.jme3.util.BufferUtils; /* package */class ArmatureModifier extends Modifier { private static final int MAXIMUM_WEIGHTS_PER_VERTEX = 4; // have no idea why 4, could someone please explain ? + /** Loaded animation data. */ + private AnimData animData; /** Old memory address of the armature's object. */ private Long armatureObjectOMA; /** Old memory address of the mesh that will have the skeleton applied. */ @@ -124,7 +126,7 @@ import com.jme3.util.BufferUtils; animations.add(boneAnimation); } } - jmeModifierRepresentation = new AnimData(new Skeleton(bones), animations); + animData = new AnimData(new Skeleton(bones), animations); } } } @@ -132,7 +134,7 @@ import com.jme3.util.BufferUtils; @Override @SuppressWarnings("unchecked") public Node apply(Node node, DataRepository dataRepository) { - if(jmeModifierRepresentation == null) { + if(animData == null) { return node; } @@ -147,8 +149,7 @@ import com.jme3.util.BufferUtils; } } - AnimData ad = (AnimData) jmeModifierRepresentation; - ArrayList animList = ad.anims; + ArrayList animList = animData.anims; if (animList != null && animList.size() > 0) { List constraints = dataRepository.getConstraints(this.armatureObjectOMA); HashMap anims = new HashMap(); @@ -158,7 +159,7 @@ import com.jme3.util.BufferUtils; // baking constraints into animations if (constraints != null && constraints.size() > 0) { for (Constraint constraint : constraints) { - constraint.affectAnimation(ad.skeleton, boneAnimation); + constraint.affectAnimation(animData.skeleton, boneAnimation); } } @@ -179,8 +180,8 @@ import com.jme3.util.BufferUtils; } // applying the control to the node - SkeletonControl skeletonControl = new SkeletonControl(meshes, ad.skeleton); - AnimControl control = new AnimControl(ad.skeleton); + SkeletonControl skeletonControl = new SkeletonControl(meshes, animData.skeleton); + AnimControl control = new AnimControl(animData.skeleton); control.setAnimations(anims); node.addControl(control); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java index 0f285a0e6..bbbeb7aac 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java @@ -33,6 +33,9 @@ import com.jme3.scene.shape.Curve; /*package*/ class ArrayModifier extends Modifier { private static final Logger LOGGER = Logger.getLogger(ArrayModifier.class.getName()); + /** Parameters of the modifier. */ + private Map modifierData = new HashMap(); + /** * This constructor reads array data from the modifier structure. The * stored data is a map of parameters for array modifier. No additional data @@ -50,16 +53,14 @@ import com.jme3.scene.shape.Curve; */ @SuppressWarnings("unchecked") public ArrayModifier(Structure modifier, DataRepository dataRepository) throws BlenderFileException { - Map params = new HashMap(); - Number fittype = (Number) modifier.getFieldValue("fit_type"); - params.put("fittype", fittype); + modifierData.put("fittype", fittype); switch (fittype.intValue()) { case 0:// FIXED COUNT - params.put("count", modifier.getFieldValue("count")); + modifierData.put("count", modifier.getFieldValue("count")); break; case 1:// FIXED LENGTH - params.put("length", modifier.getFieldValue("length")); + modifierData.put("length", modifier.getFieldValue("length")); break; case 2:// FITCURVE Pointer pCurveOb = (Pointer) modifier.getFieldValue("curve_ob"); @@ -86,8 +87,8 @@ import com.jme3.scene.shape.Curve; } } } - params.put("length", Float.valueOf(length)); - params.put("fittype", Integer.valueOf(1));// treat it like FIXED LENGTH + modifierData.put("length", Float.valueOf(length)); + modifierData.put("fittype", Integer.valueOf(1));// treat it like FIXED LENGTH break; default: assert false : "Unknown array modifier fit type: " + fittype; @@ -98,36 +99,33 @@ import com.jme3.scene.shape.Curve; if ((offsettype & 0x01) != 0) {// Constant offset DynamicArray offsetArray = (DynamicArray) modifier.getFieldValue("offset"); float[] offset = new float[]{offsetArray.get(0).floatValue(), offsetArray.get(1).floatValue(), offsetArray.get(2).floatValue()}; - params.put("offset", offset); + modifierData.put("offset", offset); } if ((offsettype & 0x02) != 0) {// Relative offset DynamicArray scaleArray = (DynamicArray) modifier.getFieldValue("scale"); float[] scale = new float[]{scaleArray.get(0).floatValue(), scaleArray.get(1).floatValue(), scaleArray.get(2).floatValue()}; - params.put("scale", scale); + modifierData.put("scale", scale); } if ((offsettype & 0x04) != 0) {// Object offset Pointer pOffsetObject = (Pointer) modifier.getFieldValue("offset_ob"); if (pOffsetObject.isNotNull()) { - params.put("offsetob", pOffsetObject); + modifierData.put("offsetob", pOffsetObject); } } // start cap and end cap Pointer pStartCap = (Pointer) modifier.getFieldValue("start_cap"); if (pStartCap.isNotNull()) { - params.put("startcap", pStartCap); + modifierData.put("startcap", pStartCap); } Pointer pEndCap = (Pointer) modifier.getFieldValue("end_cap"); if (pEndCap.isNotNull()) { - params.put("endcap", pEndCap); + modifierData.put("endcap", pEndCap); } - jmeModifierRepresentation = params; } @Override - @SuppressWarnings("unchecked") public Node apply(Node node, DataRepository dataRepository) { - Map modifierData = (Map) jmeModifierRepresentation; int fittype = ((Number) modifierData.get("fittype")).intValue(); float[] offset = (float[]) modifierData.get("offset"); if (offset == null) {// the node will be repeated several times in the same place diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java index 0107cb8a5..f9d9b00e1 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java @@ -29,6 +29,9 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; /*package*/ class MirrorModifier extends Modifier { private static final Logger LOGGER = Logger.getLogger(MirrorModifier.class.getName()); + /** Parameters of the modifier. */ + private Map modifierData = new HashMap(); + /** * This constructor reads mirror data from the modifier structure. The * stored data is a map of parameters for mirror modifier. No additional data @@ -46,21 +49,16 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; * corrupted */ public MirrorModifier(Structure modifier, DataRepository dataRepository) { - Map params = new HashMap(); - - params.put("flag", modifier.getFieldValue("flag")); - params.put("tolerance", modifier.getFieldValue("tolerance")); + modifierData.put("flag", modifier.getFieldValue("flag")); + modifierData.put("tolerance", modifier.getFieldValue("tolerance")); Pointer pMirrorOb = (Pointer) modifier.getFieldValue("mirror_ob"); if (pMirrorOb.isNotNull()) { - params.put("mirrorob", pMirrorOb); + modifierData.put("mirrorob", pMirrorOb); } - jmeModifierRepresentation = params; } @Override - @SuppressWarnings("unchecked") public Node apply(Node node, DataRepository dataRepository) { - Map modifierData = (Map) jmeModifierRepresentation; int flag = ((Number) modifierData.get("flag")).intValue(); float[] mirrorFactor = new float[]{ (flag & 0x08) != 0 ? -1.0f : 1.0f, diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java index 4dae0ff26..17ccf8aab 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java @@ -19,34 +19,6 @@ public abstract class Modifier { public static final String MIRROR_MODIFIER_DATA = "MirrorModifierData"; public static final String OBJECT_ANIMATION_MODIFIER_DATA = "ObjectAnimationModifierData"; - /** - * JME modifier representation object. - */ - protected Object jmeModifierRepresentation; - - /** - * Various additional data used by modifiers. - */ - protected Object additionalData; - - /** - * This method returns JME modifier representation object. - * - * @return JME modifier representation object - */ - public Object getJmeModifierRepresentation() { - return jmeModifierRepresentation; - } - - /** - * This method returns additional data stored in the modifier. - * - * @return the additional data stored in the modifier - */ - public Object getAdditionalData() { - return additionalData; - } - /** * This method applies the modifier to the given 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 72e21db8b..38b05c4d4 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 @@ -3,12 +3,14 @@ package com.jme3.scene.plugins.blender.modifiers; import com.jme3.animation.Animation; import java.util.ArrayList; import java.util.List; +import java.util.logging.Logger; import com.jme3.animation.Bone; import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneTrack; import com.jme3.animation.Skeleton; import com.jme3.math.Transform; +import com.jme3.scene.Node; import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.IpoHelper; @@ -24,8 +26,14 @@ import com.jme3.scene.plugins.ogre.AnimData; * * @author Marcin Roguski (Kaelthas) */ -/* package */class ObjectAnimationModifier extends ArmatureModifier { +/* package */class ObjectAnimationModifier extends Modifier { + private static final Logger LOGGER = Logger.getLogger(ObjectAnimationModifier.class.getName()); + /** Loaded animation data. */ + private AnimData animData; + /** Old memory address of the object structure that will have the modifier applied. */ + private Long objectOMA; + /** * This constructor reads animation of the object itself (without bones) and * stores it as an ArmatureModifierData modifier. The animation is returned @@ -44,8 +52,7 @@ import com.jme3.scene.plugins.ogre.AnimData; * this exception is thrown when the blender file is somehow * corrupted */ - public ObjectAnimationModifier(Structure objectStructure, - DataRepository dataRepository) throws BlenderFileException { + public ObjectAnimationModifier(Structure objectStructure, DataRepository dataRepository) throws BlenderFileException { Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo"); if (pIpo.isNotNull()) { // check if there is an action name connected with this ipo @@ -54,13 +61,9 @@ import com.jme3.scene.plugins.ogre.AnimData; .getFileBlocks(Integer.valueOf(FileBlockHeader.BLOCK_AC00)); for (FileBlockHeader actionBlock : actionBlocks) { Structure action = actionBlock.getStructure(dataRepository); - List actionChannels = ((Structure) action - .getFieldValue("chanbase")) - .evaluateListBase(dataRepository); - if (actionChannels.size() == 1) {// object's animtion action has - // only one channel - Pointer pChannelIpo = (Pointer) actionChannels.get(0) - .getFieldValue("ipo"); + List actionChannels = ((Structure) action.getFieldValue("chanbase")).evaluateListBase(dataRepository); + if (actionChannels.size() == 1) {// object's animtion action has only one channel + Pointer pChannelIpo = (Pointer) actionChannels.get(0).getFieldValue("ipo"); if (pChannelIpo.equals(pIpo)) { objectAnimationName = action.getName(); break; @@ -69,20 +72,15 @@ import com.jme3.scene.plugins.ogre.AnimData; } String objectName = objectStructure.getName(); - if (objectAnimationName == null) {// set the object's animation name - // to object's name + if (objectAnimationName == null) {// set the object's animation name to object's name objectAnimationName = objectName; } IpoHelper ipoHelper = dataRepository.getHelper(IpoHelper.class); - Structure ipoStructure = pIpo.fetchData( - dataRepository.getInputStream()).get(0); + Structure ipoStructure = pIpo.fetchData(dataRepository.getInputStream()).get(0); Ipo ipo = ipoHelper.createIpo(ipoStructure, dataRepository); - int[] animationFrames = dataRepository.getBlenderKey() - .getAnimationFrames(objectName, objectAnimationName); - if (animationFrames == null) {// if the name was created here there - // are no frames set for the - // animation + int[] animationFrames = dataRepository.getBlenderKey().getAnimationFrames(objectName, objectAnimationName); + if (animationFrames == null) {// if the name was created here there are no frames set for the animation animationFrames = new int[] { 1, ipo.getLastFrame() }; } int fps = dataRepository.getBlenderKey().getFps(); @@ -91,30 +89,29 @@ import com.jme3.scene.plugins.ogre.AnimData; // calculating track for the only bone in this skeleton BoneTrack[] tracks = new BoneTrack[1]; - tracks[0] = ipo.calculateTrack(0, animationFrames[0], - animationFrames[1], fps); + tracks[0] = ipo.calculateTrack(0, animationFrames[0], animationFrames[1], fps); - BoneAnimation boneAnimation = new BoneAnimation( - objectAnimationName, stop - start); + BoneAnimation boneAnimation = new BoneAnimation(objectAnimationName, stop - start); boneAnimation.setTracks(tracks); - ArrayList animations = new ArrayList( - 1); + ArrayList animations = new ArrayList(1); animations.add(boneAnimation); // preparing the object's bone - ObjectHelper objectHelper = dataRepository - .getHelper(ObjectHelper.class); - Transform t = objectHelper.getTransformation(objectStructure, - dataRepository); + ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); + Transform t = objectHelper.getTransformation(objectStructure, dataRepository); Bone bone = new Bone(null); - bone.setBindTransforms(t.getTranslation(), t.getRotation(), - t.getScale()); + bone.setBindTransforms(t.getTranslation(), t.getRotation(), t.getScale()); - jmeModifierRepresentation = new AnimData(new Skeleton( - new Bone[] { bone }), animations); - additionalData = objectStructure.getOldMemoryAddress(); + animData = new AnimData(new Skeleton(new Bone[] { bone }), animations); + objectOMA = objectStructure.getOldMemoryAddress(); } } + + @Override + public Node apply(Node node, DataRepository dataRepository) { + LOGGER.warning("Object animation modifier not yet implemented!"); + return null; + } @Override public String getType() { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java index e0f417b1e..23054bc1c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java @@ -24,7 +24,8 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper; * @author Marcin Roguski (Kaelthas) */ /* package */class ParticlesModifier extends Modifier { - + private ParticleEmitter particleEmitter; + /** * This constructor reads the particles system structure and stores it in * order to apply it later to the node. @@ -41,32 +42,25 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper; throws BlenderFileException { Pointer pParticleSystem = (Pointer) modifier.getFieldValue("psys"); if (pParticleSystem.isNotNull()) { - ParticlesHelper particlesHelper = dataRepository - .getHelper(ParticlesHelper.class); - Structure particleSystem = pParticleSystem.fetchData( - dataRepository.getInputStream()).get(0); - jmeModifierRepresentation = particlesHelper.toParticleEmitter( - particleSystem, dataRepository); + ParticlesHelper particlesHelper = dataRepository.getHelper(ParticlesHelper.class); + Structure particleSystem = pParticleSystem.fetchData(dataRepository.getInputStream()).get(0); + particleEmitter = particlesHelper.toParticleEmitter(particleSystem, dataRepository); } } @Override public Node apply(Node node, DataRepository dataRepository) { - MaterialHelper materialHelper = dataRepository - .getHelper(MaterialHelper.class); - ParticleEmitter emitter = (ParticleEmitter) jmeModifierRepresentation; - emitter = emitter.clone(); + MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); + ParticleEmitter emitter = particleEmitter.clone(); // veryfying the alpha function for particles' texture Integer alphaFunction = MaterialHelper.ALPHA_MASK_HYPERBOLE; - char nameSuffix = emitter.getName().charAt( - emitter.getName().length() - 1); + char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1); if (nameSuffix == 'B' || nameSuffix == 'N') { alphaFunction = MaterialHelper.ALPHA_MASK_NONE; } // removing the type suffix from the name - emitter.setName(emitter.getName().substring(0, - emitter.getName().length() - 1)); + emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1)); // applying emitter shape EmitterShape emitterShape = emitter.getShape(); @@ -77,10 +71,8 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper; if (mesh != null) { meshes.add(mesh); Material material = materialHelper.getParticlesMaterial( - ((Geometry) spatial).getMaterial(), alphaFunction, - dataRepository); - emitter.setMaterial(material);// TODO: divide into several - // pieces + ((Geometry) spatial).getMaterial(), alphaFunction, dataRepository); + emitter.setMaterial(material);// TODO: divide into several pieces } } }