diff --git a/engine/src/blender/com/jme3/asset/BlenderKey.java b/engine/src/blender/com/jme3/asset/BlenderKey.java index c82da1083..9c62f751c 100644 --- a/engine/src/blender/com/jme3/asset/BlenderKey.java +++ b/engine/src/blender/com/jme3/asset/BlenderKey.java @@ -31,6 +31,13 @@ */ 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.collision.Collidable; import com.jme3.collision.CollisionResults; @@ -40,20 +47,15 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.light.AmbientLight; -import com.jme3.light.Light; import com.jme3.material.Material; import com.jme3.material.RenderState.FaceCullMode; import com.jme3.renderer.Camera; +import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.SceneGraphVisitor; import com.jme3.scene.Spatial; import com.jme3.scene.plugins.ogre.AnimData; 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. @@ -513,7 +515,7 @@ public class BlenderKey extends ModelKey { /** All cameras from the file. */ private List cameras; /** All lights from the file. */ - private List lights; + private List lights; /** * 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(); } if ((featuresToLoad & FeaturesToLoad.LIGHTS) != 0) { - lights = new ArrayList(); + lights = new ArrayList(); } } @@ -615,8 +617,7 @@ public class BlenderKey extends ModelKey { * @param light * light to be added to the result set */ - @Override - public void addLight(Light light) { + public void addLight(LightNode light) { if (lights != null) { lights.add(light); } @@ -674,7 +675,7 @@ public class BlenderKey extends ModelKey { * This method returns all loaded lights. * @return all loaded lights */ - public List getLights() { + public List getLights() { return lights; } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java index ce4a7ea53..9bbf006c2 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java @@ -39,6 +39,7 @@ import com.jme3.light.Light; import com.jme3.math.ColorRGBA; import com.jme3.renderer.Camera; import com.jme3.scene.Geometry; +import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.plugins.blender.cameras.CameraHelper; @@ -112,7 +113,7 @@ import java.util.logging.Logger; * structure of a light * @return light's node */ - public Light toLight(Structure structure) throws BlenderFileException { + public LightNode toLight(Structure structure) throws BlenderFileException { LightHelper lightHelper = blenderContext.getHelper(LightHelper.class); if (lightHelper.shouldBeLoaded(structure, blenderContext)) { return lightHelper.toLight(structure, blenderContext); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java index 217fa4a4b..27b3ed313 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java @@ -31,14 +31,20 @@ */ 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.BlenderKey; import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.LoadingResults; import com.jme3.asset.BlenderKey.WorldData; import com.jme3.asset.ModelKey; -import com.jme3.light.Light; import com.jme3.renderer.Camera; +import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.Spatial; 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.particles.ParticlesHelper; 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. @@ -85,7 +86,11 @@ public class BlenderLoader extends AbstractBlenderLoader { switch (block.getCode()) { case FileBlockHeader.BLOCK_OB00:// Object 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) { 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)) { @@ -96,10 +101,6 @@ public class BlenderLoader extends AbstractBlenderLoader { if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { loadingResults.addCamera((Camera) object); } - } else if (object instanceof Light) { - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { - loadingResults.addLight((Light) object); - } } break; // case FileBlockHeader.BLOCK_MA00:// Material diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java index add3e2147..264c3ef90 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java @@ -38,6 +38,7 @@ import com.jme3.light.PointLight; import com.jme3.light.SpotLight; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; +import com.jme3.scene.LightNode; import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; @@ -66,49 +67,51 @@ public class LightHelper extends AbstractBlenderHelper { super(blenderVersion, fixUpAxis); } - public Light toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException { - Light result = (Light) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); + public LightNode toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException { + LightNode result = (LightNode) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); if (result != null) { return result; } + Light light = null; int type = ((Number) structure.getFieldValue("type")).intValue(); switch (type) { case 0://Lamp - result = new PointLight(); + light = new PointLight(); float distance = ((Number) structure.getFieldValue("dist")).floatValue(); - ((PointLight) result).setRadius(distance); + ((PointLight) light).setRadius(distance); break; case 1://Sun LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine."); break; case 2://Spot - result = new SpotLight(); + light = new SpotLight(); //range - ((SpotLight)result).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue()); + ((SpotLight)light).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue()); //outer angle float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue()*FastMath.DEG_TO_RAD * 0.5f; - ((SpotLight)result).setSpotOuterAngle(outerAngle); + ((SpotLight)light).setSpotOuterAngle(outerAngle); //inner angle float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue(); spotblend = FastMath.clamp(spotblend, 0, 1); float innerAngle = outerAngle * (1 - spotblend); - ((SpotLight)result).setSpotInnerAngle(innerAngle); + ((SpotLight)light).setSpotInnerAngle(innerAngle); break; case 3://Hemi LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine."); break; case 4://Area - result = new DirectionalLight(); + light = new DirectionalLight(); break; default: throw new BlenderFileException("Unknown light source type: " + type); } - if (result != null) { + if (light != null) { float r = ((Number) structure.getFieldValue("r")).floatValue(); float g = ((Number) structure.getFieldValue("g")).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; } 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 e365b7b73..61bc046c5 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 @@ -37,16 +37,13 @@ import java.util.logging.Level; import java.util.logging.Logger; 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.Quaternion; import com.jme3.math.Transform; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; import com.jme3.scene.Geometry; +import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.Spatial.CullHint; @@ -197,34 +194,10 @@ public class ObjectHelper extends AbstractBlenderHelper { if(pLamp.isNotNull()) { LightHelper lightHelper = blenderContext.getHelper(LightHelper.class); List lampsArray = pLamp.fetchData(blenderContext.getInputStream()); - Light light = lightHelper.toLight(lampsArray.get(0), blenderContext); + LightNode light = lightHelper.toLight(lampsArray.get(0), blenderContext); if(light!=null) { light.setName(name); - } - 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); + light.setLocalTransform(t); } result = light; }