Fix to applying properties to the mesh's geometry.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9522 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
fde6b4a447
commit
a6d42c21bb
@ -31,8 +31,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender;
|
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.FastMath;
|
||||||
import com.jme3.math.Quaternion;
|
import com.jme3.math.Quaternion;
|
||||||
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
||||||
import com.jme3.scene.plugins.blender.file.Pointer;
|
import com.jme3.scene.plugins.blender.file.Pointer;
|
||||||
import com.jme3.scene.plugins.blender.file.Structure;
|
import com.jme3.scene.plugins.blender.file.Structure;
|
||||||
@ -115,6 +120,38 @@ public abstract class AbstractBlenderHelper {
|
|||||||
return properties;
|
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<String> 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
|
* This method analyzes the given structure and the data contained within
|
||||||
* blender context and decides if the feature should be loaded.
|
* blender context and decides if the feature should be loaded.
|
||||||
|
@ -195,7 +195,7 @@ public class MeshHelper extends AbstractBlenderHelper {
|
|||||||
// creating the result
|
// creating the result
|
||||||
Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);
|
Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);
|
||||||
if (properties != null && properties.getValue() != null) {
|
if (properties != null && properties.getValue() != null) {
|
||||||
geometry.setUserData("properties", properties);
|
this.applyProperties(geometry, properties);
|
||||||
}
|
}
|
||||||
geometries.add(geometry);
|
geometries.add(geometry);
|
||||||
meshContext.putGeometry(materialIndex, geometry);
|
meshContext.putGeometry(materialIndex, geometry);
|
||||||
|
@ -31,8 +31,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.scene.plugins.blender.objects;
|
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.asset.BlenderKey.FeaturesToLoad;
|
||||||
import com.jme3.export.Savable;
|
|
||||||
import com.jme3.light.DirectionalLight;
|
import com.jme3.light.DirectionalLight;
|
||||||
import com.jme3.light.Light;
|
import com.jme3.light.Light;
|
||||||
import com.jme3.light.PointLight;
|
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.meshes.MeshHelper;
|
||||||
import com.jme3.scene.plugins.blender.modifiers.Modifier;
|
import com.jme3.scene.plugins.blender.modifiers.Modifier;
|
||||||
import com.jme3.scene.plugins.blender.modifiers.ModifierHelper;
|
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.
|
* A class that is used in object calculations.
|
||||||
@ -279,24 +278,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
|||||||
Properties properties = this.loadProperties(objectStructure, blenderContext);
|
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
|
//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) {
|
if(result instanceof Spatial && properties != null && properties.getValue() != null) {
|
||||||
List<String> propertyNames = properties.getSubPropertiesNames();
|
this.applyProperties((Spatial) result, properties);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -430,7 +412,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
|
public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
|
||||||
int lay = ((Number) structure.getFieldValue("lay")).intValue();
|
int lay = ((Number) structure.getFieldValue("lay")).intValue();
|
||||||
return ((lay & blenderContext.getBlenderKey().getLayersToLoad()) != 0
|
return (lay & blenderContext.getBlenderKey().getLayersToLoad()) != 0
|
||||||
&& (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0);
|
&& (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user