diff --git a/jme3-core/src/main/java/com/jme3/light/DefaultLightFilter.java b/jme3-core/src/main/java/com/jme3/light/DefaultLightFilter.java index 5d07e1a8d..cbd89dc8c 100644 --- a/jme3-core/src/main/java/com/jme3/light/DefaultLightFilter.java +++ b/jme3-core/src/main/java/com/jme3/light/DefaultLightFilter.java @@ -60,6 +60,11 @@ public final class DefaultLightFilter implements LightFilter { for (int i = 0; i < worldLights.size(); i++) { Light light = worldLights.get(i); + // If this light is not enabled it will be ignored. + if (!light.isEnabled()) { + continue; + } + if (light.frustumCheckNeeded) { processedLights.add(light); light.frustumCheckNeeded = false; diff --git a/jme3-core/src/main/java/com/jme3/light/Light.java b/jme3-core/src/main/java/com/jme3/light/Light.java index 39a30980b..afef33b1d 100644 --- a/jme3-core/src/main/java/com/jme3/light/Light.java +++ b/jme3-core/src/main/java/com/jme3/light/Light.java @@ -103,9 +103,6 @@ public abstract class Light implements Savable, Cloneable { */ protected transient float lastDistance = -1; - /** - * If light is disabled, it will not have any - */ protected boolean enabled = true; /** @@ -169,20 +166,24 @@ public abstract class Light implements Savable, Cloneable { this.color.set(color); } - - /* - * Returns true if the light is enabled - * - * @return true if the light is enabled - * - * @see Light#setEnabled(boolean) + + /** + * Returns true if this light is enabled. + * @return true if enabled, otherwise false. */ - /* public boolean isEnabled() { return enabled; } - */ - + + /** + * Set to false in order to disable a light and have it filtered out from being included in rendering. + * + * @param enabled true to enable and false to disable the light. + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + /** * Determines if the light intersects with the given bounding box. *

diff --git a/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java b/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java index d3ba9b7c6..005634bcd 100644 --- a/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java +++ b/jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.java @@ -65,25 +65,23 @@ public class TestManyLightsSingle extends SimpleApplication { TestManyLightsSingle app = new TestManyLightsSingle(); app.start(); } - + /** * Switch mode with space bar at run time */ TechniqueDef.LightMode lm = TechniqueDef.LightMode.SinglePass; - int lightNum = 6; @Override public void simpleInitApp() { renderManager.setPreferredLightMode(lm); - renderManager.setSinglePassLightBatchSize(lightNum); - + renderManager.setSinglePassLightBatchSize(6); flyCam.setMoveSpeed(10); Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene"); rootNode.attachChild(scene); Node n = (Node) rootNode.getChild(0); - LightList lightList = n.getWorldLightList(); + final LightList lightList = n.getWorldLightList(); final Geometry g = (Geometry) n.getChild("Grid-geom-1"); g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f)); @@ -152,8 +150,6 @@ public class TestManyLightsSingle extends SimpleApplication { // guiNode.setCullHint(CullHint.Always); - - flyCam.setDragToRotate(true); flyCam.setMoveSpeed(50); @@ -168,27 +164,35 @@ public class TestManyLightsSingle extends SimpleApplication { helloText.setText("(Multi pass)"); } else { lm = TechniqueDef.LightMode.SinglePass; - helloText.setText("(Single pass) nb lights per batch : " + lightNum); + helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize()); } renderManager.setPreferredLightMode(lm); - reloadScene(g,boxGeo,cubeNodes); + reloadScene(g, boxGeo, cubeNodes); } if (name.equals("lightsUp") && isPressed) { - lightNum++; - renderManager.setSinglePassLightBatchSize(lightNum); - helloText.setText("(Single pass) nb lights per batch : " + lightNum); + renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1); + helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize()); } if (name.equals("lightsDown") && isPressed) { - lightNum--; - renderManager.setSinglePassLightBatchSize(lightNum); - helloText.setText("(Single pass) nb lights per batch : " + lightNum); + renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1); + helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize()); + } + if (name.equals("toggleOnOff") && isPressed) { + for (final Light light : lightList) { + if (light instanceof AmbientLight) { + continue; + } + + light.setEnabled(!light.isEnabled()); + } } } - }, "toggle", "lightsUp", "lightsDown"); + }, "toggle", "lightsUp", "lightsDown", "toggleOnOff"); inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE)); inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP)); inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN)); + inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L)); SpotLight spot = new SpotLight(); @@ -215,12 +219,9 @@ public class TestManyLightsSingle extends SimpleApplication { guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); helloText = new BitmapText(guiFont, false); helloText.setSize(guiFont.getCharSet().getRenderedSize()); - helloText.setText("(Single pass) nb lights per batch : " + lightNum); + helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize()); helloText.setLocalTranslation(300, helloText.getLineHeight(), 0); guiNode.attachChild(helloText); - - - } protected void reloadScene(Geometry g, Geometry boxGeo, Node cubeNodes) { @@ -234,7 +235,7 @@ public class TestManyLightsSingle extends SimpleApplication { cubeNodes.setMaterial(m); } } - + BitmapText helloText; long time; long nbFrames;