Feature: added support for fog loading from blender file.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@11035 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent 5afe5b35c1
commit 6132141f9f
  1. 26
      engine/src/blender/com/jme3/asset/BlenderKey.java
  2. 2
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java
  3. 24
      engine/src/blender/com/jme3/scene/plugins/blender/landscape/LandscapeHelper.java

@ -52,6 +52,7 @@ import com.jme3.export.OutputCapsule;
import com.jme3.material.Material;
import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.math.ColorRGBA;
import com.jme3.post.Filter;
import com.jme3.scene.CameraNode;
import com.jme3.scene.LightNode;
import com.jme3.scene.Node;
@ -796,6 +797,8 @@ public class BlenderKey extends ModelKey {
private List<LightNode> lights;
/** Loaded sky. */
private Spatial sky;
/** Scene filters (ie. FOG). */
private List<Filter> filters;
/**
* The background color of the render loaded from the horizon color of the world. If no world is used than the gray color
* is set to default (as in blender editor.
@ -917,6 +920,21 @@ public class BlenderKey extends ModelKey {
this.sky = sky;
}
/**
* This method adds a scene filter. Filters are used to load FOG or other
* scene effects that blender can define.
* @param filter
* the filter to be added
*/
public void addFilter(Filter filter) {
if (filter != null) {
if (filters == null) {
filters = new ArrayList<Filter>(5);
}
filters.add(filter);
}
}
/**
* @param backgroundColor
* the background color
@ -981,6 +999,13 @@ public class BlenderKey extends ModelKey {
return sky;
}
/**
* @return scene filters
*/
public List<Filter> getFilters() {
return filters;
}
/**
* @return the background color
*/
@ -988,6 +1013,7 @@ public class BlenderKey extends ModelKey {
return backgroundColor;
}
@Override
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {
return 0;
}

@ -78,6 +78,7 @@ public class BlenderLoader implements AssetLoader {
/** The blender context. */
protected BlenderContext blenderContext;
@Override
public Spatial load(AssetInfo assetInfo) throws IOException {
try {
this.setup(assetInfo);
@ -130,6 +131,7 @@ public class BlenderLoader implements AssetLoader {
loadingResults.addLight(new LightNode(null, ambientLight));
}
loadingResults.setSky(landscapeHelper.toSky(worldStructure));
loadingResults.addFilter(landscapeHelper.toFog(worldStructure));
loadingResults.setBackgroundColor(landscapeHelper.toBackgroundColor(worldStructure));
}
}

@ -8,6 +8,7 @@ import java.util.logging.Logger;
import com.jme3.light.AmbientLight;
import com.jme3.light.Light;
import com.jme3.math.ColorRGBA;
import com.jme3.post.filters.FogFilter;
import com.jme3.scene.Spatial;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.BlenderContext;
@ -37,6 +38,8 @@ public class LandscapeHelper extends AbstractBlenderHelper {
private static final int SKYTYPE_REAL = 2;
private static final int SKYTYPE_PAPER = 4;
private static final int MODE_MIST = 0x01;
public LandscapeHelper(String blenderVersion, BlenderContext blenderContext) {
super(blenderVersion, blenderContext);
}
@ -53,7 +56,7 @@ public class LandscapeHelper extends AbstractBlenderHelper {
float ambr = ((Number) worldStructure.getFieldValue("ambr")).floatValue();
float ambg = ((Number) worldStructure.getFieldValue("ambg")).floatValue();
float ambb = ((Number) worldStructure.getFieldValue("ambb")).floatValue();
if(ambr > 0 || ambg > 0 || ambb > 0) {
if (ambr > 0 || ambg > 0 || ambb > 0) {
ambientLight = new AmbientLight();
ColorRGBA ambientLightColor = new ColorRGBA(ambr, ambg, ambb, 0.0f);
ambientLight.setColor(ambientLightColor);
@ -64,6 +67,25 @@ public class LandscapeHelper extends AbstractBlenderHelper {
return ambientLight;
}
/**
* The method loads fog for the scene.
* NOTICE! Remember to manually set the distance and density of the fog.
* Unfortunately blender's fog parameters in no way fit to the JME.
* @param worldStructure
* the world's structure
* @return fog filter or null if scene does not define it
*/
public FogFilter toFog(Structure worldStructure) {
FogFilter result = null;
int mode = ((Number) worldStructure.getFieldValue("mode")).intValue();
if ((mode & MODE_MIST) != 0) {
LOGGER.fine("Loading fog.");
result = new FogFilter();
result.setFogColor(this.toBackgroundColor(worldStructure));
}
return result;
}
/**
* Loads the background color.
* @param worldStructure

Loading…
Cancel
Save