Added support for modifiers validating. Now modifiers that are invalid will not be loaded.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8245 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent ba57377795
commit 0775b93088
  1. 8
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java
  2. 28
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java
  3. 15
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java
  4. 12
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java
  5. 18
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java
  6. 19
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java

@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme3.animation.AnimControl; import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation; import com.jme3.animation.Animation;
@ -43,6 +45,7 @@ import com.jme3.util.BufferUtils;
* @author Marcin Roguski (Kaelthas) * @author Marcin Roguski (Kaelthas)
*/ */
/* package */class ArmatureModifier extends Modifier { /* package */class ArmatureModifier extends Modifier {
private static final Logger LOGGER = Logger.getLogger(ArmatureModifier.class.getName());
private static final int MAXIMUM_WEIGHTS_PER_VERTEX = 4; // have no idea why 4, could someone please explain ? private static final int MAXIMUM_WEIGHTS_PER_VERTEX = 4; // have no idea why 4, could someone please explain ?
/** Loaded animation data. */ /** Loaded animation data. */
@ -80,6 +83,7 @@ import com.jme3.util.BufferUtils;
* corrupted * corrupted
*/ */
public ArmatureModifier(Structure objectStructure, Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException { public ArmatureModifier(Structure objectStructure, Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException {
if(this.validate(modifierStructure, blenderContext)) {
Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object"); Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object");
if (pArmatureObject.isNotNull()) { if (pArmatureObject.isNotNull()) {
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
@ -130,10 +134,14 @@ import com.jme3.util.BufferUtils;
} }
} }
} }
}
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Node apply(Node node, BlenderContext blenderContext) { 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) { if(animData == null) {
return node; return node;
} }

@ -52,18 +52,19 @@ import com.jme3.scene.shape.Curve;
* corrupted * corrupted
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ArrayModifier(Structure modifier, BlenderContext blenderContext) throws BlenderFileException { public ArrayModifier(Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException {
Number fittype = (Number) modifier.getFieldValue("fit_type"); if(this.validate(modifierStructure, blenderContext)) {
Number fittype = (Number) modifierStructure.getFieldValue("fit_type");
modifierData.put("fittype", fittype); modifierData.put("fittype", fittype);
switch (fittype.intValue()) { switch (fittype.intValue()) {
case 0:// FIXED COUNT case 0:// FIXED COUNT
modifierData.put("count", modifier.getFieldValue("count")); modifierData.put("count", modifierStructure.getFieldValue("count"));
break; break;
case 1:// FIXED LENGTH case 1:// FIXED LENGTH
modifierData.put("length", modifier.getFieldValue("length")); modifierData.put("length", modifierStructure.getFieldValue("length"));
break; break;
case 2:// FITCURVE case 2:// FITCURVE
Pointer pCurveOb = (Pointer) modifier.getFieldValue("curve_ob"); Pointer pCurveOb = (Pointer) modifierStructure.getFieldValue("curve_ob");
float length = 0; float length = 0;
if (pCurveOb.isNotNull()) { if (pCurveOb.isNotNull()) {
Structure curveStructure = pCurveOb.fetchData(blenderContext.getInputStream()).get(0); Structure curveStructure = pCurveOb.fetchData(blenderContext.getInputStream()).get(0);
@ -95,37 +96,42 @@ import com.jme3.scene.shape.Curve;
} }
// offset parameters // offset parameters
int offsettype = ((Number) modifier.getFieldValue("offset_type")).intValue(); int offsettype = ((Number) modifierStructure.getFieldValue("offset_type")).intValue();
if ((offsettype & 0x01) != 0) {// Constant offset if ((offsettype & 0x01) != 0) {// Constant offset
DynamicArray<Number> offsetArray = (DynamicArray<Number>) modifier.getFieldValue("offset"); DynamicArray<Number> offsetArray = (DynamicArray<Number>) modifierStructure.getFieldValue("offset");
float[] offset = new float[]{offsetArray.get(0).floatValue(), offsetArray.get(1).floatValue(), offsetArray.get(2).floatValue()}; float[] offset = new float[]{offsetArray.get(0).floatValue(), offsetArray.get(1).floatValue(), offsetArray.get(2).floatValue()};
modifierData.put("offset", offset); modifierData.put("offset", offset);
} }
if ((offsettype & 0x02) != 0) {// Relative offset if ((offsettype & 0x02) != 0) {// Relative offset
DynamicArray<Number> scaleArray = (DynamicArray<Number>) modifier.getFieldValue("scale"); DynamicArray<Number> scaleArray = (DynamicArray<Number>) modifierStructure.getFieldValue("scale");
float[] scale = new float[]{scaleArray.get(0).floatValue(), scaleArray.get(1).floatValue(), scaleArray.get(2).floatValue()}; float[] scale = new float[]{scaleArray.get(0).floatValue(), scaleArray.get(1).floatValue(), scaleArray.get(2).floatValue()};
modifierData.put("scale", scale); modifierData.put("scale", scale);
} }
if ((offsettype & 0x04) != 0) {// Object offset if ((offsettype & 0x04) != 0) {// Object offset
Pointer pOffsetObject = (Pointer) modifier.getFieldValue("offset_ob"); Pointer pOffsetObject = (Pointer) modifierStructure.getFieldValue("offset_ob");
if (pOffsetObject.isNotNull()) { if (pOffsetObject.isNotNull()) {
modifierData.put("offsetob", pOffsetObject); modifierData.put("offsetob", pOffsetObject);
} }
} }
// start cap and end cap // start cap and end cap
Pointer pStartCap = (Pointer) modifier.getFieldValue("start_cap"); Pointer pStartCap = (Pointer) modifierStructure.getFieldValue("start_cap");
if (pStartCap.isNotNull()) { if (pStartCap.isNotNull()) {
modifierData.put("startcap", pStartCap); modifierData.put("startcap", pStartCap);
} }
Pointer pEndCap = (Pointer) modifier.getFieldValue("end_cap"); Pointer pEndCap = (Pointer) modifierStructure.getFieldValue("end_cap");
if (pEndCap.isNotNull()) { if (pEndCap.isNotNull()) {
modifierData.put("endcap", pEndCap); modifierData.put("endcap", pEndCap);
} }
} }
}
@Override @Override
public Node apply(Node node, BlenderContext blenderContext) { public Node apply(Node node, BlenderContext blenderContext) {
if(invalid) {
LOGGER.log(Level.WARNING, "Array modifier is invalid! Cannot be applied to: {0}", node.getName());
return node;
}
int fittype = ((Number) modifierData.get("fittype")).intValue(); int fittype = ((Number) modifierData.get("fittype")).intValue();
float[] offset = (float[]) modifierData.get("offset"); float[] offset = (float[]) modifierData.get("offset");
if (offset == null) {// the node will be repeated several times in the same place if (offset == null) {// the node will be repeated several times in the same place

@ -48,17 +48,24 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public MirrorModifier(Structure modifier, BlenderContext blenderContext) { public MirrorModifier(Structure modifierStructure, BlenderContext blenderContext) {
modifierData.put("flag", modifier.getFieldValue("flag")); if(this.validate(modifierStructure, blenderContext)) {
modifierData.put("tolerance", modifier.getFieldValue("tolerance")); modifierData.put("flag", modifierStructure.getFieldValue("flag"));
Pointer pMirrorOb = (Pointer) modifier.getFieldValue("mirror_ob"); modifierData.put("tolerance", modifierStructure.getFieldValue("tolerance"));
Pointer pMirrorOb = (Pointer) modifierStructure.getFieldValue("mirror_ob");
if (pMirrorOb.isNotNull()) { if (pMirrorOb.isNotNull()) {
modifierData.put("mirrorob", pMirrorOb); modifierData.put("mirrorob", pMirrorOb);
} }
} }
}
@Override @Override
public Node apply(Node node, BlenderContext blenderContext) { public Node apply(Node node, BlenderContext blenderContext) {
if(invalid) {
LOGGER.log(Level.WARNING, "Mirror modifier is invalid! Cannot be applied to: {0}", node.getName());
return node;
}
int flag = ((Number) modifierData.get("flag")).intValue(); int flag = ((Number) modifierData.get("flag")).intValue();
float[] mirrorFactor = new float[]{ float[] mirrorFactor = new float[]{
(flag & 0x08) != 0 ? -1.0f : 1.0f, (flag & 0x08) != 0 ? -1.0f : 1.0f,

@ -2,6 +2,8 @@ package com.jme3.scene.plugins.blender.modifiers;
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.file.Pointer;
import com.jme3.scene.plugins.blender.file.Structure;
/** /**
* This class represents an object's modifier. The modifier object can be varied * This class represents an object's modifier. The modifier object can be varied
@ -19,6 +21,9 @@ public abstract class Modifier {
public static final String MIRROR_MODIFIER_DATA = "MirrorModifierData"; public static final String MIRROR_MODIFIER_DATA = "MirrorModifierData";
public static final String OBJECT_ANIMATION_MODIFIER_DATA = "ObjectAnimationModifierData"; public static final String OBJECT_ANIMATION_MODIFIER_DATA = "ObjectAnimationModifierData";
/** This variable indicates if the modifier is invalid (<b>true</b>) or not (<b>false</b>). */
protected boolean invalid;
/** /**
* This method applies the modifier to the given node. * This method applies the modifier to the given node.
* *
@ -36,4 +41,11 @@ public abstract class Modifier {
* @return blender's type of modifier * @return blender's type of modifier
*/ */
public abstract String getType(); public abstract String getType();
protected boolean validate(Structure modifierStructure, BlenderContext blenderContext) {
Structure modifierData = (Structure)modifierStructure.getFieldValue("modifier");
Pointer pError = (Pointer) modifierData.getFieldValue("error");
invalid = pError.isNotNull();
return !invalid;
}
} }

@ -1,24 +1,11 @@
package com.jme3.scene.plugins.blender.modifiers; 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 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.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.IpoHelper;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.FileBlockHeader;
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.objects.ObjectHelper;
import com.jme3.scene.plugins.ogre.AnimData; import com.jme3.scene.plugins.ogre.AnimData;
/** /**
@ -53,6 +40,8 @@ import com.jme3.scene.plugins.ogre.AnimData;
* corrupted * corrupted
*/ */
public ObjectAnimationModifier(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException { public ObjectAnimationModifier(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
LOGGER.warning("Object animation modifier not yet implemented!");
/*
Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo"); Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo");
if (pIpo.isNotNull()) { if (pIpo.isNotNull()) {
// check if there is an action name connected with this ipo // check if there is an action name connected with this ipo
@ -105,12 +94,13 @@ import com.jme3.scene.plugins.ogre.AnimData;
animData = new AnimData(new Skeleton(new Bone[] { bone }), animations); animData = new AnimData(new Skeleton(new Bone[] { bone }), animations);
objectOMA = objectStructure.getOldMemoryAddress(); objectOMA = objectStructure.getOldMemoryAddress();
} }
*/
} }
@Override @Override
public Node apply(Node node, BlenderContext blenderContext) { public Node apply(Node node, BlenderContext blenderContext) {
LOGGER.warning("Object animation modifier not yet implemented!"); LOGGER.warning("Object animation modifier not yet implemented!");
return null; return node;
} }
@Override @Override

@ -2,6 +2,8 @@ package com.jme3.scene.plugins.blender.modifiers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme3.effect.ParticleEmitter; import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.shapes.EmitterMeshVertexShape; import com.jme3.effect.shapes.EmitterMeshVertexShape;
@ -24,13 +26,16 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper;
* @author Marcin Roguski (Kaelthas) * @author Marcin Roguski (Kaelthas)
*/ */
/* package */class ParticlesModifier extends Modifier { /* package */class ParticlesModifier extends Modifier {
private static final Logger LOGGER = Logger.getLogger(MirrorModifier.class.getName());
/** Loaded particles emitter. */
private ParticleEmitter particleEmitter; private ParticleEmitter particleEmitter;
/** /**
* This constructor reads the particles system structure and stores it in * This constructor reads the particles system structure and stores it in
* order to apply it later to the node. * order to apply it later to the node.
* *
* @param modifier * @param modifierStructure
* the structure of the modifier * the structure of the modifier
* @param blenderContext * @param blenderContext
* the blender context * the blender context
@ -38,18 +43,24 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper;
* an exception is throw wneh there are problems with the * an exception is throw wneh there are problems with the
* blender file * blender file
*/ */
public ParticlesModifier(Structure modifier, BlenderContext blenderContext) public ParticlesModifier(Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException {
throws BlenderFileException { if(this.validate(modifierStructure, blenderContext)) {
Pointer pParticleSystem = (Pointer) modifier.getFieldValue("psys"); Pointer pParticleSystem = (Pointer) modifierStructure.getFieldValue("psys");
if (pParticleSystem.isNotNull()) { if (pParticleSystem.isNotNull()) {
ParticlesHelper particlesHelper = blenderContext.getHelper(ParticlesHelper.class); ParticlesHelper particlesHelper = blenderContext.getHelper(ParticlesHelper.class);
Structure particleSystem = pParticleSystem.fetchData(blenderContext.getInputStream()).get(0); Structure particleSystem = pParticleSystem.fetchData(blenderContext.getInputStream()).get(0);
particleEmitter = particlesHelper.toParticleEmitter(particleSystem, blenderContext); particleEmitter = particlesHelper.toParticleEmitter(particleSystem, blenderContext);
} }
} }
}
@Override @Override
public Node apply(Node node, BlenderContext blenderContext) { public Node apply(Node node, BlenderContext blenderContext) {
if(invalid) {
LOGGER.log(Level.WARNING, "Particles modifier is invalid! Cannot be applied to: {0}", node.getName());
return node;
}
MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
ParticleEmitter emitter = particleEmitter.clone(); ParticleEmitter emitter = particleEmitter.clone();

Loading…
Cancel
Save