Wrapping Light into LightNodes (this allows to add constraints and properties to lights).

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9698 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 12 years ago
parent e253546982
commit be5428736d
  1. 23
      engine/src/blender/com/jme3/asset/BlenderKey.java
  2. 3
      engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java
  3. 23
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java
  4. 25
      engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java
  5. 33
      engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

@ -31,6 +31,13 @@
*/ */
package com.jme3.asset; package com.jme3.asset;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import org.lwjgl.opengl.GL11;
import com.jme3.bounding.BoundingVolume; import com.jme3.bounding.BoundingVolume;
import com.jme3.collision.Collidable; import com.jme3.collision.Collidable;
import com.jme3.collision.CollisionResults; import com.jme3.collision.CollisionResults;
@ -40,20 +47,15 @@ import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.light.AmbientLight; import com.jme3.light.AmbientLight;
import com.jme3.light.Light;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.RenderState.FaceCullMode; import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.SceneGraphVisitor; import com.jme3.scene.SceneGraphVisitor;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.plugins.ogre.AnimData; import com.jme3.scene.plugins.ogre.AnimData;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import org.lwjgl.opengl.GL11;
/** /**
* Blender key. Contains path of the blender file and its loading properties. * Blender key. Contains path of the blender file and its loading properties.
@ -513,7 +515,7 @@ public class BlenderKey extends ModelKey {
/** All cameras from the file. */ /** All cameras from the file. */
private List<Camera> cameras; private List<Camera> cameras;
/** All lights from the file. */ /** All lights from the file. */
private List<Light> lights; private List<LightNode> lights;
/** /**
* Private constructor prevents users to create an instance of this class from outside the * Private constructor prevents users to create an instance of this class from outside the
@ -542,7 +544,7 @@ public class BlenderKey extends ModelKey {
cameras = new ArrayList<Camera>(); cameras = new ArrayList<Camera>();
} }
if ((featuresToLoad & FeaturesToLoad.LIGHTS) != 0) { if ((featuresToLoad & FeaturesToLoad.LIGHTS) != 0) {
lights = new ArrayList<Light>(); lights = new ArrayList<LightNode>();
} }
} }
@ -615,8 +617,7 @@ public class BlenderKey extends ModelKey {
* @param light * @param light
* light to be added to the result set * light to be added to the result set
*/ */
@Override public void addLight(LightNode light) {
public void addLight(Light light) {
if (lights != null) { if (lights != null) {
lights.add(light); lights.add(light);
} }
@ -674,7 +675,7 @@ public class BlenderKey extends ModelKey {
* This method returns all loaded lights. * This method returns all loaded lights.
* @return all loaded lights * @return all loaded lights
*/ */
public List<Light> getLights() { public List<LightNode> getLights() {
return lights; return lights;
} }

@ -39,6 +39,7 @@ import com.jme3.light.Light;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.plugins.blender.cameras.CameraHelper; import com.jme3.scene.plugins.blender.cameras.CameraHelper;
@ -112,7 +113,7 @@ import java.util.logging.Logger;
* structure of a light * structure of a light
* @return light's node * @return light's node
*/ */
public Light toLight(Structure structure) throws BlenderFileException { public LightNode toLight(Structure structure) throws BlenderFileException {
LightHelper lightHelper = blenderContext.getHelper(LightHelper.class); LightHelper lightHelper = blenderContext.getHelper(LightHelper.class);
if (lightHelper.shouldBeLoaded(structure, blenderContext)) { if (lightHelper.shouldBeLoaded(structure, blenderContext)) {
return lightHelper.toLight(structure, blenderContext); return lightHelper.toLight(structure, blenderContext);

@ -31,14 +31,20 @@
*/ */
package com.jme3.scene.plugins.blender; package com.jme3.scene.plugins.blender;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetInfo;
import com.jme3.asset.BlenderKey; import com.jme3.asset.BlenderKey;
import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.FeaturesToLoad;
import com.jme3.asset.BlenderKey.LoadingResults; import com.jme3.asset.BlenderKey.LoadingResults;
import com.jme3.asset.BlenderKey.WorldData; import com.jme3.asset.BlenderKey.WorldData;
import com.jme3.asset.ModelKey; import com.jme3.asset.ModelKey;
import com.jme3.light.Light;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.plugins.blender.animations.ArmatureHelper; import com.jme3.scene.plugins.blender.animations.ArmatureHelper;
@ -57,11 +63,6 @@ import com.jme3.scene.plugins.blender.modifiers.ModifierHelper;
import com.jme3.scene.plugins.blender.objects.ObjectHelper; import com.jme3.scene.plugins.blender.objects.ObjectHelper;
import com.jme3.scene.plugins.blender.particles.ParticlesHelper; import com.jme3.scene.plugins.blender.particles.ParticlesHelper;
import com.jme3.scene.plugins.blender.textures.TextureHelper; import com.jme3.scene.plugins.blender.textures.TextureHelper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* This is the main loading class. Have in notice that asset manager needs to have loaders for resources like textures. * This is the main loading class. Have in notice that asset manager needs to have loaders for resources like textures.
@ -85,7 +86,11 @@ public class BlenderLoader extends AbstractBlenderLoader {
switch (block.getCode()) { switch (block.getCode()) {
case FileBlockHeader.BLOCK_OB00:// Object case FileBlockHeader.BLOCK_OB00:// Object
Object object = this.toObject(block.getStructure(blenderContext)); Object object = this.toObject(block.getStructure(blenderContext));
if (object instanceof Node) { if(object instanceof LightNode) {
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) {
loadingResults.addLight((LightNode) object);
}
} else if (object instanceof Node) {
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) { if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) {
LOGGER.log(Level.INFO, "{0}: {1}--> {2}", new Object[] { ((Node) object).getName(), ((Node) object).getLocalTranslation().toString(), ((Node) object).getParent() == null ? "null" : ((Node) object).getParent().getName() }); LOGGER.log(Level.INFO, "{0}: {1}--> {2}", new Object[] { ((Node) object).getName(), ((Node) object).getLocalTranslation().toString(), ((Node) object).getParent() == null ? "null" : ((Node) object).getParent().getName() });
if (this.isRootObject(loadingResults, (Node)object)) { if (this.isRootObject(loadingResults, (Node)object)) {
@ -96,10 +101,6 @@ public class BlenderLoader extends AbstractBlenderLoader {
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) {
loadingResults.addCamera((Camera) object); loadingResults.addCamera((Camera) object);
} }
} else if (object instanceof Light) {
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) {
loadingResults.addLight((Light) object);
}
} }
break; break;
// case FileBlockHeader.BLOCK_MA00:// Material // case FileBlockHeader.BLOCK_MA00:// Material

@ -38,6 +38,7 @@ import com.jme3.light.PointLight;
import com.jme3.light.SpotLight; import com.jme3.light.SpotLight;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.LightNode;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
@ -66,49 +67,51 @@ public class LightHelper extends AbstractBlenderHelper {
super(blenderVersion, fixUpAxis); super(blenderVersion, fixUpAxis);
} }
public Light toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException { public LightNode toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
Light result = (Light) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); LightNode result = (LightNode) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (result != null) { if (result != null) {
return result; return result;
} }
Light light = null;
int type = ((Number) structure.getFieldValue("type")).intValue(); int type = ((Number) structure.getFieldValue("type")).intValue();
switch (type) { switch (type) {
case 0://Lamp case 0://Lamp
result = new PointLight(); light = new PointLight();
float distance = ((Number) structure.getFieldValue("dist")).floatValue(); float distance = ((Number) structure.getFieldValue("dist")).floatValue();
((PointLight) result).setRadius(distance); ((PointLight) light).setRadius(distance);
break; break;
case 1://Sun case 1://Sun
LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine."); LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine.");
break; break;
case 2://Spot case 2://Spot
result = new SpotLight(); light = new SpotLight();
//range //range
((SpotLight)result).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue()); ((SpotLight)light).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue());
//outer angle //outer angle
float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue()*FastMath.DEG_TO_RAD * 0.5f; float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue()*FastMath.DEG_TO_RAD * 0.5f;
((SpotLight)result).setSpotOuterAngle(outerAngle); ((SpotLight)light).setSpotOuterAngle(outerAngle);
//inner angle //inner angle
float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue(); float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue();
spotblend = FastMath.clamp(spotblend, 0, 1); spotblend = FastMath.clamp(spotblend, 0, 1);
float innerAngle = outerAngle * (1 - spotblend); float innerAngle = outerAngle * (1 - spotblend);
((SpotLight)result).setSpotInnerAngle(innerAngle); ((SpotLight)light).setSpotInnerAngle(innerAngle);
break; break;
case 3://Hemi case 3://Hemi
LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine."); LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine.");
break; break;
case 4://Area case 4://Area
result = new DirectionalLight(); light = new DirectionalLight();
break; break;
default: default:
throw new BlenderFileException("Unknown light source type: " + type); throw new BlenderFileException("Unknown light source type: " + type);
} }
if (result != null) { if (light != null) {
float r = ((Number) structure.getFieldValue("r")).floatValue(); float r = ((Number) structure.getFieldValue("r")).floatValue();
float g = ((Number) structure.getFieldValue("g")).floatValue(); float g = ((Number) structure.getFieldValue("g")).floatValue();
float b = ((Number) structure.getFieldValue("b")).floatValue(); float b = ((Number) structure.getFieldValue("b")).floatValue();
result.setColor(new ColorRGBA(r, g, b, 1.0f)); light.setColor(new ColorRGBA(r, g, b, 1.0f));
result = new LightNode(null, light);
} }
return result; return result;
} }

@ -37,16 +37,13 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.FeaturesToLoad;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.light.PointLight;
import com.jme3.light.SpotLight;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Transform; import com.jme3.math.Transform;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.Spatial.CullHint; import com.jme3.scene.Spatial.CullHint;
@ -197,34 +194,10 @@ public class ObjectHelper extends AbstractBlenderHelper {
if(pLamp.isNotNull()) { if(pLamp.isNotNull()) {
LightHelper lightHelper = blenderContext.getHelper(LightHelper.class); LightHelper lightHelper = blenderContext.getHelper(LightHelper.class);
List<Structure> lampsArray = pLamp.fetchData(blenderContext.getInputStream()); List<Structure> lampsArray = pLamp.fetchData(blenderContext.getInputStream());
Light light = lightHelper.toLight(lampsArray.get(0), blenderContext); LightNode light = lightHelper.toLight(lampsArray.get(0), blenderContext);
if(light!=null) { if(light!=null) {
light.setName(name); light.setName(name);
} light.setLocalTransform(t);
if(light instanceof PointLight) {
((PointLight)light).setPosition(t.getTranslation());
} else if(light instanceof DirectionalLight) {
Quaternion quaternion = t.getRotation();
Vector3f[] axes = new Vector3f[3];
quaternion.toAxes(axes);
if(fixUpAxis) {
((DirectionalLight)light).setDirection(axes[1].negate());//-Z is the direction axis of area lamp in blender
} else {
((DirectionalLight)light).setDirection(axes[2].negate());
}
} else if(light instanceof SpotLight) {
((SpotLight)light).setPosition(t.getTranslation());
Quaternion quaternion = t.getRotation();
Vector3f[] axes = new Vector3f[3];
quaternion.toAxes(axes);
if(fixUpAxis) {
((SpotLight)light).setDirection(axes[1].negate());//-Z is the direction axis of area lamp in blender
} else {
((SpotLight)light).setDirection(axes[2].negate());
}
} else {
LOGGER.log(Level.WARNING, "Unknown type of light: {0}", light);
} }
result = light; result = light;
} }

Loading…
Cancel
Save