I want to be able to switch certain light on and off.
This is (messy) piece of a prototype code which initializes light. When I enable light, I call com.jme.light.PointLight.setEnabled(…) and then updateRenderStates on a node which parents LightNode with that light.
It doesn't work. Here's the code, help anyone, please.
light = new PointLight();
light.setEnabled(true);
light.setShadowCaster(true);
light.setAttenuate(true);
light.setAmbient(ColorRGBA.gray);
light.setDiffuse(ColorRGBA.white);
LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
ls.setEnabled(true);
ls.attach(light);
LightNode ln = new LightNode("tablamp-light", ls);
ln.setLocalTranslation(0, 20, 0);
attachChild(ln);
// Just a test to find out light-node pos...
Sphere lightPosSphere = new Sphere("lps", 3, 3, 5);
lightPosSphere.setLocalTranslation(0, 20, 0);
WireframeState ws = DisplaySystem.getDisplaySystem().getRenderer().createWireframeState();
ws.setEnabled(true);
lightPosSphere.setRenderState(ws);
attachChild(lightPosSphere);
It truly is, it is attached to 'this' (the InteractibleNode, a customized descendant of Node), but I dunno if its of any importance. Just in case that it is: 'this' holds three nodes: 1) loaded model TriMesh, 2) LightNode and 3) Sphere.
Well, I don't know if this will help at all, since it does not use the LightNode, but:
public void simpleInitGame()
{
lightState.detachAll();
light = new PointLight();
light.setEnabled(true);
light.setShadowCaster(true);
light.setAttenuate(true);
light.setAmbient(ColorRGBA.gray);
light.setDiffuse(ColorRGBA.white);
ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
ls.setEnabled(true);
ls.attach(light);
//LightNode ln = new LightNode("tablamp-light", ls);
//ln.setLocalTranslation(0, 20, 0);
//rootNode.attachChild(ln);
rootNode.setRenderState( ls );
// Just a test to find out light-node pos...
Sphere lightPosSphere = new Sphere("lps", 30, 30, 5);
lightPosSphere.setLocalTranslation(0, -20, 0);
WireframeState ws = DisplaySystem.getDisplaySystem().getRenderer().createWireframeState();
ws.setEnabled(true);
lightPosSphere.setRenderState(ws);
rootNode.attachChild(lightPosSphere);