From 578c92affc369fb01b28b0bf58fb177c57eb890b Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Thu, 25 Aug 2011 21:05:10 +0000 Subject: [PATCH] Support for loading SpotLight. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8100 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../plugins/blender/lights/LightHelper.java | 22 +++++++++++++++++-- .../plugins/blender/objects/ObjectHelper.java | 8 +++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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 de456779d..0ce6f0a49 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,7 +38,9 @@ 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.ColorRGBA; +import com.jme3.math.FastMath; import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; @@ -79,7 +81,23 @@ public class LightHelper extends AbstractBlenderHelper { LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine."); break; case 2://Spot - LOGGER.log(Level.WARNING, "'Spot' lamp is not supported in jMonkeyEngine."); + result = new SpotLight(); + //range + ((SpotLight)result).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue()); + //outer angle + float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue()*FastMath.DEG_TO_RAD; + ((SpotLight)result).setSpotOuterAngle(outerAngle); + + //inner angle + float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue(); + if(spotblend > 1.0f) {//floating point errors fix + spotblend = 1.0f; + } + if(spotblend < 0.0f) {//floating point errors fix + spotblend = 0.0f; + } + float innerAngle = 2.0f * (float)Math.atan((1.0f-spotblend)*Math.tan(spotblend/2.0f)); + ((SpotLight)result).setSpotInnerAngle(innerAngle); break; case 3://Hemi LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine."); @@ -94,7 +112,7 @@ public class LightHelper extends AbstractBlenderHelper { 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, 0.0f));//TODO: 0 czy 1 ??? + result.setColor(new ColorRGBA(r, g, b, 1.0f)); } 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 4baa7a3ba..f5781e392 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 @@ -41,6 +41,7 @@ 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.FastMath; import com.jme3.math.Matrix4f; import com.jme3.math.Quaternion; @@ -237,6 +238,13 @@ public class ObjectHelper extends AbstractBlenderHelper { Vector3f[] axes = new Vector3f[3]; quaternion.toAxes(axes); ((DirectionalLight)light).setDirection(axes[2].negate());//-Z is the direction axis of area lamp in blender + } else if(light instanceof SpotLight) { + ((SpotLight)light).setPosition(t.getTranslation()); + + Quaternion quaternion = t.getRotation(); + Vector3f[] axes = new Vector3f[3]; + quaternion.toAxes(axes); + ((SpotLight)light).setDirection(axes[2].negate());//-Z is the direction axis of area lamp in blender } else { LOGGER.log(Level.WARNING, "Unknown type of light: {0}", light); }