Added support for toggling lights on and off via Light.setEnabled(boolean). This implements #393

This commit also contains some minor changes to TestManyLightsSingle which now has a key trigger (L) for toggling lights on and off.
cleanup_build_scripts
Daniel Johansson 9 years ago
parent 67eb998ef4
commit 25b9691e32
  1. 5
      jme3-core/src/main/java/com/jme3/light/DefaultLightFilter.java
  2. 27
      jme3-core/src/main/java/com/jme3/light/Light.java
  3. 43
      jme3-examples/src/main/java/jme3test/light/TestManyLightsSingle.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;

@ -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.
* <p>

@ -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;

Loading…
Cancel
Save