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
This commit is contained in:
parent
6e027bd51e
commit
2148c256d3
@ -14,7 +14,6 @@ import com.jme3.scene.plugins.blender.file.Structure;
|
|||||||
* @author Marcin Roguski (Kaelthas)
|
* @author Marcin Roguski (Kaelthas)
|
||||||
*/
|
*/
|
||||||
public abstract class Modifier {
|
public abstract class Modifier {
|
||||||
|
|
||||||
public static final String ARRAY_MODIFIER_DATA = "ArrayModifierData";
|
public static final String ARRAY_MODIFIER_DATA = "ArrayModifierData";
|
||||||
public static final String ARMATURE_MODIFIER_DATA = "ArmatureModifierData";
|
public static final String ARMATURE_MODIFIER_DATA = "ArmatureModifierData";
|
||||||
public static final String PARTICLE_MODIFIER_DATA = "ParticleSystemModifierData";
|
public static final String PARTICLE_MODIFIER_DATA = "ParticleSystemModifierData";
|
||||||
@ -43,6 +42,20 @@ public abstract class Modifier {
|
|||||||
*/
|
*/
|
||||||
public abstract String getType();
|
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) {
|
protected boolean validate(Structure modifierStructure, BlenderContext blenderContext) {
|
||||||
Structure modifierData = (Structure)modifierStructure.getFieldValue("modifier");
|
Structure modifierData = (Structure)modifierStructure.getFieldValue("modifier");
|
||||||
Pointer pError = (Pointer) modifierData.getFieldValue("error");
|
Pointer pError = (Pointer) modifierData.getFieldValue("error");
|
||||||
|
@ -40,7 +40,9 @@ 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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -78,10 +80,15 @@ public class ModifierHelper extends AbstractBlenderHelper {
|
|||||||
* corrupted
|
* corrupted
|
||||||
*/
|
*/
|
||||||
public Collection<Modifier> readModifiers(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
|
public Collection<Modifier> readModifiers(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
|
||||||
|
Set<String> alreadyReadModifiers = new HashSet<String>();
|
||||||
Collection<Modifier> result = new ArrayList<Modifier>();
|
Collection<Modifier> result = new ArrayList<Modifier>();
|
||||||
Structure modifiersListBase = (Structure) objectStructure.getFieldValue("modifiers");
|
Structure modifiersListBase = (Structure) objectStructure.getFieldValue("modifiers");
|
||||||
List<Structure> modifiers = modifiersListBase.evaluateListBase(blenderContext);
|
List<Structure> modifiers = modifiersListBase.evaluateListBase(blenderContext);
|
||||||
for (Structure modifierStructure : modifiers) {
|
for (Structure modifierStructure : modifiers) {
|
||||||
|
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 {
|
||||||
Modifier modifier = null;
|
Modifier modifier = null;
|
||||||
if (Modifier.ARRAY_MODIFIER_DATA.equals(modifierStructure.getType())) {
|
if (Modifier.ARRAY_MODIFIER_DATA.equals(modifierStructure.getType())) {
|
||||||
modifier = new ArrayModifier(modifierStructure, blenderContext);
|
modifier = new ArrayModifier(modifierStructure, blenderContext);
|
||||||
@ -96,10 +103,12 @@ public class ModifierHelper extends AbstractBlenderHelper {
|
|||||||
if (modifier != null) {
|
if (modifier != null) {
|
||||||
result.add(modifier);
|
result.add(modifier);
|
||||||
blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier);
|
blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier);
|
||||||
|
alreadyReadModifiers.add(modifierType);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(Level.WARNING, "Unsupported modifier type: {0}", modifierStructure.getType());
|
LOGGER.log(Level.WARNING, "Unsupported modifier type: {0}", modifierStructure.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// at the end read object's animation modifier (object animation is
|
// at the end read object's animation modifier (object animation is
|
||||||
// either described by action or by ipo of the object)
|
// either described by action or by ipo of the object)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user