Feature: added support for fog loading from blender file.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/branches/gradle-restructure@11035 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
00eacd3b66
commit
c5448f9aae
@ -52,6 +52,7 @@ import com.jme3.export.OutputCapsule;
|
|||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.material.RenderState.FaceCullMode;
|
import com.jme3.material.RenderState.FaceCullMode;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.post.Filter;
|
||||||
import com.jme3.scene.CameraNode;
|
import com.jme3.scene.CameraNode;
|
||||||
import com.jme3.scene.LightNode;
|
import com.jme3.scene.LightNode;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
@ -796,6 +797,8 @@ public class BlenderKey extends ModelKey {
|
|||||||
private List<LightNode> lights;
|
private List<LightNode> lights;
|
||||||
/** Loaded sky. */
|
/** Loaded sky. */
|
||||||
private Spatial 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
|
* 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.
|
* is set to default (as in blender editor.
|
||||||
@ -917,6 +920,21 @@ public class BlenderKey extends ModelKey {
|
|||||||
this.sky = sky;
|
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
|
* @param backgroundColor
|
||||||
* the background color
|
* the background color
|
||||||
@ -981,6 +999,13 @@ public class BlenderKey extends ModelKey {
|
|||||||
return sky;
|
return sky;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return scene filters
|
||||||
|
*/
|
||||||
|
public List<Filter> getFilters() {
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the background color
|
* @return the background color
|
||||||
*/
|
*/
|
||||||
@ -988,6 +1013,7 @@ public class BlenderKey extends ModelKey {
|
|||||||
return backgroundColor;
|
return backgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {
|
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ public class BlenderLoader implements AssetLoader {
|
|||||||
/** The blender context. */
|
/** The blender context. */
|
||||||
protected BlenderContext blenderContext;
|
protected BlenderContext blenderContext;
|
||||||
|
|
||||||
|
@Override
|
||||||
public Spatial load(AssetInfo assetInfo) throws IOException {
|
public Spatial load(AssetInfo assetInfo) throws IOException {
|
||||||
try {
|
try {
|
||||||
this.setup(assetInfo);
|
this.setup(assetInfo);
|
||||||
@ -130,6 +131,7 @@ public class BlenderLoader implements AssetLoader {
|
|||||||
loadingResults.addLight(new LightNode(null, ambientLight));
|
loadingResults.addLight(new LightNode(null, ambientLight));
|
||||||
}
|
}
|
||||||
loadingResults.setSky(landscapeHelper.toSky(worldStructure));
|
loadingResults.setSky(landscapeHelper.toSky(worldStructure));
|
||||||
|
loadingResults.addFilter(landscapeHelper.toFog(worldStructure));
|
||||||
loadingResults.setBackgroundColor(landscapeHelper.toBackgroundColor(worldStructure));
|
loadingResults.setBackgroundColor(landscapeHelper.toBackgroundColor(worldStructure));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import java.util.logging.Logger;
|
|||||||
import com.jme3.light.AmbientLight;
|
import com.jme3.light.AmbientLight;
|
||||||
import com.jme3.light.Light;
|
import com.jme3.light.Light;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.post.filters.FogFilter;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
|
import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
|
||||||
import com.jme3.scene.plugins.blender.BlenderContext;
|
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_REAL = 2;
|
||||||
private static final int SKYTYPE_PAPER = 4;
|
private static final int SKYTYPE_PAPER = 4;
|
||||||
|
|
||||||
|
private static final int MODE_MIST = 0x01;
|
||||||
|
|
||||||
public LandscapeHelper(String blenderVersion, BlenderContext blenderContext) {
|
public LandscapeHelper(String blenderVersion, BlenderContext blenderContext) {
|
||||||
super(blenderVersion, blenderContext);
|
super(blenderVersion, blenderContext);
|
||||||
}
|
}
|
||||||
@ -53,7 +56,7 @@ public class LandscapeHelper extends AbstractBlenderHelper {
|
|||||||
float ambr = ((Number) worldStructure.getFieldValue("ambr")).floatValue();
|
float ambr = ((Number) worldStructure.getFieldValue("ambr")).floatValue();
|
||||||
float ambg = ((Number) worldStructure.getFieldValue("ambg")).floatValue();
|
float ambg = ((Number) worldStructure.getFieldValue("ambg")).floatValue();
|
||||||
float ambb = ((Number) worldStructure.getFieldValue("ambb")).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();
|
ambientLight = new AmbientLight();
|
||||||
ColorRGBA ambientLightColor = new ColorRGBA(ambr, ambg, ambb, 0.0f);
|
ColorRGBA ambientLightColor = new ColorRGBA(ambr, ambg, ambb, 0.0f);
|
||||||
ambientLight.setColor(ambientLightColor);
|
ambientLight.setColor(ambientLightColor);
|
||||||
@ -64,6 +67,25 @@ public class LandscapeHelper extends AbstractBlenderHelper {
|
|||||||
return ambientLight;
|
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.
|
* Loads the background color.
|
||||||
* @param worldStructure
|
* @param worldStructure
|
||||||
|
Loading…
x
Reference in New Issue
Block a user