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.
This commit is contained in:
parent
67eb998ef4
commit
25b9691e32
@ -60,6 +60,11 @@ public final class DefaultLightFilter implements LightFilter {
|
|||||||
for (int i = 0; i < worldLights.size(); i++) {
|
for (int i = 0; i < worldLights.size(); i++) {
|
||||||
Light light = worldLights.get(i);
|
Light light = worldLights.get(i);
|
||||||
|
|
||||||
|
// If this light is not enabled it will be ignored.
|
||||||
|
if (!light.isEnabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (light.frustumCheckNeeded) {
|
if (light.frustumCheckNeeded) {
|
||||||
processedLights.add(light);
|
processedLights.add(light);
|
||||||
light.frustumCheckNeeded = false;
|
light.frustumCheckNeeded = false;
|
||||||
|
@ -103,9 +103,6 @@ public abstract class Light implements Savable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
protected transient float lastDistance = -1;
|
protected transient float lastDistance = -1;
|
||||||
|
|
||||||
/**
|
|
||||||
* If light is disabled, it will not have any
|
|
||||||
*/
|
|
||||||
protected boolean enabled = true;
|
protected boolean enabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,18 +167,22 @@ public abstract class Light implements Savable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Returns true if the light is enabled
|
* Returns true if this light is enabled.
|
||||||
*
|
* @return true if enabled, otherwise false.
|
||||||
* @return true if the light is enabled
|
|
||||||
*
|
|
||||||
* @see Light#setEnabled(boolean)
|
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
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.
|
* Determines if the light intersects with the given bounding box.
|
||||||
|
@ -70,20 +70,18 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|||||||
* Switch mode with space bar at run time
|
* Switch mode with space bar at run time
|
||||||
*/
|
*/
|
||||||
TechniqueDef.LightMode lm = TechniqueDef.LightMode.SinglePass;
|
TechniqueDef.LightMode lm = TechniqueDef.LightMode.SinglePass;
|
||||||
int lightNum = 6;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
renderManager.setPreferredLightMode(lm);
|
renderManager.setPreferredLightMode(lm);
|
||||||
renderManager.setSinglePassLightBatchSize(lightNum);
|
renderManager.setSinglePassLightBatchSize(6);
|
||||||
|
|
||||||
|
|
||||||
flyCam.setMoveSpeed(10);
|
flyCam.setMoveSpeed(10);
|
||||||
|
|
||||||
Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
|
Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
|
||||||
rootNode.attachChild(scene);
|
rootNode.attachChild(scene);
|
||||||
Node n = (Node) rootNode.getChild(0);
|
Node n = (Node) rootNode.getChild(0);
|
||||||
LightList lightList = n.getWorldLightList();
|
final LightList lightList = n.getWorldLightList();
|
||||||
final Geometry g = (Geometry) n.getChild("Grid-geom-1");
|
final Geometry g = (Geometry) n.getChild("Grid-geom-1");
|
||||||
|
|
||||||
g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
|
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);
|
// guiNode.setCullHint(CullHint.Always);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
flyCam.setDragToRotate(true);
|
flyCam.setDragToRotate(true);
|
||||||
flyCam.setMoveSpeed(50);
|
flyCam.setMoveSpeed(50);
|
||||||
|
|
||||||
@ -168,27 +164,35 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|||||||
helloText.setText("(Multi pass)");
|
helloText.setText("(Multi pass)");
|
||||||
} else {
|
} else {
|
||||||
lm = TechniqueDef.LightMode.SinglePass;
|
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);
|
renderManager.setPreferredLightMode(lm);
|
||||||
reloadScene(g,boxGeo,cubeNodes);
|
reloadScene(g, boxGeo, cubeNodes);
|
||||||
}
|
}
|
||||||
if (name.equals("lightsUp") && isPressed) {
|
if (name.equals("lightsUp") && isPressed) {
|
||||||
lightNum++;
|
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
|
||||||
renderManager.setSinglePassLightBatchSize(lightNum);
|
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
|
||||||
helloText.setText("(Single pass) nb lights per batch : " + lightNum);
|
|
||||||
}
|
}
|
||||||
if (name.equals("lightsDown") && isPressed) {
|
if (name.equals("lightsDown") && isPressed) {
|
||||||
lightNum--;
|
renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
|
||||||
renderManager.setSinglePassLightBatchSize(lightNum);
|
helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
|
||||||
helloText.setText("(Single pass) nb lights per batch : " + lightNum);
|
}
|
||||||
|
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("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
|
||||||
inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
|
inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
|
||||||
inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
|
inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
|
||||||
|
inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
|
||||||
|
|
||||||
|
|
||||||
SpotLight spot = new SpotLight();
|
SpotLight spot = new SpotLight();
|
||||||
@ -215,12 +219,9 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|||||||
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
||||||
helloText = new BitmapText(guiFont, false);
|
helloText = new BitmapText(guiFont, false);
|
||||||
helloText.setSize(guiFont.getCharSet().getRenderedSize());
|
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);
|
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
|
||||||
guiNode.attachChild(helloText);
|
guiNode.attachChild(helloText);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reloadScene(Geometry g, Geometry boxGeo, Node cubeNodes) {
|
protected void reloadScene(Geometry g, Geometry boxGeo, Node cubeNodes) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user