From a6d42c21bb03c89e165ef3a4c847c08ec3390c36 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Mon, 25 Jun 2012 20:30:29 +0000 Subject: [PATCH] Fix to applying properties to the mesh's geometry. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9522 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/AbstractBlenderHelper.java | 37 +++++++++++++++++++ .../plugins/blender/meshes/MeshHelper.java | 2 +- .../plugins/blender/objects/ObjectHelper.java | 34 ++++------------- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java index 665c36a99..cedcb017f 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java @@ -31,8 +31,13 @@ */ package com.jme3.scene.plugins.blender; +import java.util.Arrays; +import java.util.List; + +import com.jme3.export.Savable; import com.jme3.math.FastMath; import com.jme3.math.Quaternion; +import com.jme3.scene.Spatial; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Structure; @@ -115,6 +120,38 @@ public abstract class AbstractBlenderHelper { return properties; } + /** + * The method applies properties to the given spatial. The Properties + * instance cannot be directly applied because the end-user might not have + * the blender plugin jar file and thus receive ClassNotFoundException. The + * values are set by name instead. + * + * @param spatial + * the spatial that is to have properties applied + * @param properties + * the properties to be applied + */ + protected void applyProperties(Spatial spatial, Properties properties) { + List propertyNames = properties.getSubPropertiesNames(); + if(propertyNames != null && propertyNames.size() > 0) { + for(String propertyName : propertyNames) { + Object value = properties.findValue(propertyName); + if(value instanceof Savable || value instanceof Boolean || value instanceof String || + value instanceof Float || value instanceof Integer || value instanceof Long) { + spatial.setUserData(propertyName, value); + } else if(value instanceof Double) { + spatial.setUserData(propertyName, ((Double) value).floatValue()); + } else if(value instanceof int[]) { + spatial.setUserData(propertyName, Arrays.toString((int[])value)); + } else if(value instanceof float[]) { + spatial.setUserData(propertyName, Arrays.toString((float[])value)); + } else if(value instanceof double[]) { + spatial.setUserData(propertyName, Arrays.toString((double[])value)); + } + } + } + } + /** * This method analyzes the given structure and the data contained within * blender context and decides if the feature should be loaded. diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 8960416cf..cf740f7bb 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java @@ -195,7 +195,7 @@ public class MeshHelper extends AbstractBlenderHelper { // creating the result Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh); if (properties != null && properties.getValue() != null) { - geometry.setUserData("properties", properties); + this.applyProperties(geometry, properties); } geometries.add(geometry); meshContext.putGeometry(materialIndex, geometry); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java index 2895ec35f..e365b7b73 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java @@ -31,8 +31,12 @@ */ package com.jme3.scene.plugins.blender.objects; +import java.util.Collection; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.jme3.asset.BlenderKey.FeaturesToLoad; -import com.jme3.export.Savable; import com.jme3.light.DirectionalLight; import com.jme3.light.Light; import com.jme3.light.PointLight; @@ -61,11 +65,6 @@ import com.jme3.scene.plugins.blender.lights.LightHelper; import com.jme3.scene.plugins.blender.meshes.MeshHelper; import com.jme3.scene.plugins.blender.modifiers.Modifier; import com.jme3.scene.plugins.blender.modifiers.ModifierHelper; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * A class that is used in object calculations. @@ -279,24 +278,7 @@ public class ObjectHelper extends AbstractBlenderHelper { Properties properties = this.loadProperties(objectStructure, blenderContext); //the loaded property is a group property, so we need to get each value and set it to Spatial if(result instanceof Spatial && properties != null && properties.getValue() != null) { - List propertyNames = properties.getSubPropertiesNames(); - if(propertyNames != null && propertyNames.size() > 0) { - for(String propertyName : propertyNames) { - Object value = properties.findValue(propertyName); - if(value instanceof Savable || value instanceof Boolean || value instanceof String || - value instanceof Float || value instanceof Integer || value instanceof Long) { - ((Spatial)result).setUserData(propertyName, value); - } else if(value instanceof Double) { - ((Spatial)result).setUserData(propertyName, ((Double) value).floatValue()); - } else if(value instanceof int[]) { - ((Spatial)result).setUserData(propertyName, Arrays.toString((int[])value)); - } else if(value instanceof float[]) { - ((Spatial)result).setUserData(propertyName, Arrays.toString((float[])value)); - } else if(value instanceof double[]) { - ((Spatial)result).setUserData(propertyName, Arrays.toString((double[])value)); - } - } - } + this.applyProperties((Spatial) result, properties); } } } @@ -430,7 +412,7 @@ public class ObjectHelper extends AbstractBlenderHelper { @Override public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) { int lay = ((Number) structure.getFieldValue("lay")).intValue(); - return ((lay & blenderContext.getBlenderKey().getLayersToLoad()) != 0 - && (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0); + return (lay & blenderContext.getBlenderKey().getLayersToLoad()) != 0 + && (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0; } }