Support for loading SpotLight.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8100 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent cb3f57009f
commit 578c92affc
  1. 22
      engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java
  2. 8
      engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

@ -38,7 +38,9 @@ import com.jme3.asset.BlenderKey.FeaturesToLoad;
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;
import com.jme3.light.SpotLight;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.DataRepository;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; 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."); LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine.");
break; break;
case 2://Spot 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; 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.");
@ -94,7 +112,7 @@ public class LightHelper extends AbstractBlenderHelper {
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, 0.0f));//TODO: 0 czy 1 ??? result.setColor(new ColorRGBA(r, g, b, 1.0f));
} }
return result; return result;
} }

@ -41,6 +41,7 @@ import com.jme3.asset.BlenderKey.FeaturesToLoad;
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;
import com.jme3.light.SpotLight;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
@ -237,6 +238,13 @@ public class ObjectHelper extends AbstractBlenderHelper {
Vector3f[] axes = new Vector3f[3]; Vector3f[] axes = new Vector3f[3];
quaternion.toAxes(axes); quaternion.toAxes(axes);
((DirectionalLight)light).setDirection(axes[2].negate());//-Z is the direction axis of area lamp in blender ((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 { } else {
LOGGER.log(Level.WARNING, "Unknown type of light: {0}", light); LOGGER.log(Level.WARNING, "Unknown type of light: {0}", light);
} }

Loading…
Cancel
Save