Sfoglia il codice sorgente

Allowing only a single armature modifier and object animation modifier to be applied over an object.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9792 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Kae..pl 13 anni fa
parent
commit
2148c256d3

+ 14 - 1
engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java

@@ -14,7 +14,6 @@ import com.jme3.scene.plugins.blender.file.Structure;
  * @author Marcin Roguski (Kaelthas)
  */
 public abstract class Modifier {
-
 	public static final String ARRAY_MODIFIER_DATA = "ArrayModifierData";
 	public static final String ARMATURE_MODIFIER_DATA = "ArmatureModifierData";
 	public static final String PARTICLE_MODIFIER_DATA = "ParticleSystemModifierData";
@@ -43,6 +42,20 @@ public abstract class Modifier {
 	 */
 	public abstract String getType();
 	
+	/**
+	 * Determines if the modifier can be applied multiple times over one mesh.
+	 * At this moment only armature and object animation modifiers cannot be
+	 * applied multiple times.
+	 * 
+	 * @param modifierType
+	 *            the type name of the modifier
+	 * @return <b>true</b> if the modifier can be applied many times and
+	 *         <b>false</b> otherwise
+	 */
+	public static boolean canBeAppliedMultipleTimes(String modifierType) {
+		return !(ARMATURE_MODIFIER_DATA.equals(modifierType) || OBJECT_ANIMATION_MODIFIER_DATA.equals(modifierType));
+	}
+	
 	protected boolean validate(Structure modifierStructure, BlenderContext blenderContext) {
 		Structure modifierData = (Structure)modifierStructure.getFieldValue("modifier");
 		Pointer pError = (Pointer) modifierData.getFieldValue("error");

+ 24 - 15
engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java

@@ -40,7 +40,9 @@ import com.jme3.scene.plugins.blender.file.Pointer;
 import com.jme3.scene.plugins.blender.file.Structure;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -78,26 +80,33 @@ public class ModifierHelper extends AbstractBlenderHelper {
 	 *             corrupted
 	 */
 	public Collection<Modifier> readModifiers(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
+		Set<String> alreadyReadModifiers = new HashSet<String>();
 		Collection<Modifier> result = new ArrayList<Modifier>();
 		Structure modifiersListBase = (Structure) objectStructure.getFieldValue("modifiers");
 		List<Structure> modifiers = modifiersListBase.evaluateListBase(blenderContext);
 		for (Structure modifierStructure : modifiers) {
-			Modifier modifier = null;
-			if (Modifier.ARRAY_MODIFIER_DATA.equals(modifierStructure.getType())) {
-				modifier = new ArrayModifier(modifierStructure, blenderContext);
-			} else if (Modifier.MIRROR_MODIFIER_DATA.equals(modifierStructure.getType())) {
-				modifier = new MirrorModifier(modifierStructure, blenderContext);
-			} else if (Modifier.ARMATURE_MODIFIER_DATA.equals(modifierStructure.getType())) {
-				modifier = new ArmatureModifier(objectStructure, modifierStructure, blenderContext);
-			} else if (Modifier.PARTICLE_MODIFIER_DATA.equals(modifierStructure.getType())) {
-				modifier = new ParticlesModifier(modifierStructure, blenderContext);
-			}
-
-			if (modifier != null) {
-				result.add(modifier);
-				blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier);
+			String modifierType = modifierStructure.getType();
+			if(!Modifier.canBeAppliedMultipleTimes(modifierType) && alreadyReadModifiers.contains(modifierType)) {
+				LOGGER.log(Level.WARNING, "Modifier {0} can only be applied once to object: {1}", new Object[] { modifierType, objectStructure.getName() });
 			} else {
-				LOGGER.log(Level.WARNING, "Unsupported modifier type: {0}", modifierStructure.getType());
+				Modifier modifier = null;
+				if (Modifier.ARRAY_MODIFIER_DATA.equals(modifierStructure.getType())) {
+					modifier = new ArrayModifier(modifierStructure, blenderContext);
+				} else if (Modifier.MIRROR_MODIFIER_DATA.equals(modifierStructure.getType())) {
+					modifier = new MirrorModifier(modifierStructure, blenderContext);
+				} else if (Modifier.ARMATURE_MODIFIER_DATA.equals(modifierStructure.getType())) {
+					modifier = new ArmatureModifier(objectStructure, modifierStructure, blenderContext);
+				} else if (Modifier.PARTICLE_MODIFIER_DATA.equals(modifierStructure.getType())) {
+					modifier = new ParticlesModifier(modifierStructure, blenderContext);
+				}
+
+				if (modifier != null) {
+					result.add(modifier);
+					blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier);
+					alreadyReadModifiers.add(modifierType);
+				} else {
+					LOGGER.log(Level.WARNING, "Unsupported modifier type: {0}", modifierStructure.getType());
+				}
 			}
 		}