Bugfix: fixed how blender importer handled ambient light.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@11013 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent b06cdfc77c
commit fa845e33c8
  1. 4
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java
  2. 13
      engine/src/blender/com/jme3/scene/plugins/blender/landscape/LandscapeHelper.java
  3. 16
      engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java

@ -126,7 +126,9 @@ public class BlenderLoader implements AssetLoader {
if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) {
LandscapeHelper landscapeHelper = blenderContext.getHelper(LandscapeHelper.class);
Light ambientLight = landscapeHelper.toAmbientLight(worldStructure);
loadingResults.addLight(new LightNode(null, ambientLight));
if(ambientLight != null) {
loadingResults.addLight(new LightNode(null, ambientLight));
}
loadingResults.setSky(landscapeHelper.toSky(worldStructure));
loadingResults.setBackgroundColor(landscapeHelper.toBackgroundColor(worldStructure));
}

@ -49,13 +49,18 @@ public class LandscapeHelper extends AbstractBlenderHelper {
*/
public Light toAmbientLight(Structure worldStructure) {
LOGGER.fine("Loading ambient light.");
AmbientLight ambientLight = new AmbientLight();
AmbientLight ambientLight = null;
float ambr = ((Number) worldStructure.getFieldValue("ambr")).floatValue();
float ambg = ((Number) worldStructure.getFieldValue("ambg")).floatValue();
float ambb = ((Number) worldStructure.getFieldValue("ambb")).floatValue();
ColorRGBA ambientLightColor = new ColorRGBA(ambr, ambg, ambb, 0.0f);
ambientLight.setColor(ambientLightColor);
LOGGER.log(Level.FINE, "Loaded ambient light: {0}.", ambientLightColor);
if(ambr > 0 || ambg > 0 || ambb > 0) {
ambientLight = new AmbientLight();
ColorRGBA ambientLightColor = new ColorRGBA(ambr, ambg, ambb, 0.0f);
ambientLight.setColor(ambientLightColor);
LOGGER.log(Level.FINE, "Loaded ambient light: {0}.", ambientLightColor);
} else {
LOGGER.finer("Ambient light is set to BLACK which means: no ambient light! The ambient light node will not be included in the result.");
}
return ambientLight;
}

@ -48,7 +48,7 @@ public final class MaterialContext {
/* package */final DiffuseShader diffuseShader;
/* package */final SpecularShader specularShader;
/* package */final ColorRGBA specularColor;
/* package */final ColorRGBA ambientColor;
/* package */final float ambientFactor;
/* package */final float shininess;
/* package */final boolean shadeless;
/* package */final boolean vertexColor;
@ -66,6 +66,7 @@ public final class MaterialContext {
int diff_shader = ((Number) structure.getFieldValue("diff_shader")).intValue();
diffuseShader = DiffuseShader.values()[diff_shader];
ambientFactor = ((Number) structure.getFieldValue("amb")).floatValue();
if (shadeless) {
float r = ((Number) structure.getFieldValue("r")).floatValue();
@ -75,7 +76,7 @@ public final class MaterialContext {
diffuseColor = new ColorRGBA(r, g, b, alpha);
specularShader = null;
specularColor = ambientColor = null;
specularColor = null;
shininess = 0.0f;
} else {
diffuseColor = this.readDiffuseColor(structure, diffuseShader);
@ -85,12 +86,6 @@ public final class MaterialContext {
specularColor = this.readSpecularColor(structure);
float shininess = ((Number) structure.getFieldValue("har")).floatValue();// this is (probably) the specular hardness in blender
this.shininess = shininess > 0.0f ? shininess : MaterialHelper.DEFAULT_SHININESS;
float r = ((Number) structure.getFieldValue("ambr")).floatValue();
float g = ((Number) structure.getFieldValue("ambg")).floatValue();
float b = ((Number) structure.getFieldValue("ambb")).floatValue();
float alpha = ((Number) structure.getFieldValue("alpha")).floatValue();
ambientColor = new ColorRGBA(r, g, b, alpha);
}
TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
@ -109,9 +104,6 @@ public final class MaterialContext {
if (specularColor != null) {
transparent = transparent || specularColor.a < 1.0f;
}
if (ambientColor != null) {
transparent = transparent || ambientColor.a < 1.0f;
}
this.transparent = transparent;
}
@ -152,7 +144,7 @@ public final class MaterialContext {
material.setColor("Specular", specularColor);
material.setFloat("Shininess", shininess);
material.setColor("Ambient", ambientColor);
material.setColor("Ambient", new ColorRGBA(ambientFactor, ambientFactor, ambientFactor, 1f));
}
// applying textures

Loading…
Cancel
Save