Removal of Light from root, use within LightNode

root.RemoveLight doesnt seem to remove a light source,

scenario:

I have a campfireNode within it is a model, particle emitter and a light node with a point light,



now if i call a method to remove the fire it would also have to remove the light node,



[java] public void enableFire(){

if(this.getChild(“Campfire_fire”) == null){

this.attachChild(fpe);

fire = true;

}

if(this.getChild(“Campfire_light”)== null){

this.attachChild(nl);

Root.addLight(pl);

}

}



public void disableFire(){

this.detachChildNamed(“Campfire_fire”);

Root.removeLight(pl);

this.detachChildNamed(“Campfire_light”);

fire=false;

}[/java]



however the removal of the light seems to cause this:



fire on:

http://i52.tinypic.com/2dllwjo.jpg



fire off:

http://i53.tinypic.com/1678qvs.jpg



The light seems to apply to the entire scene

What is n1 and this?

apologies, nl = LightNode class

and this is a extension of Node

i think its working as expected, or i didnt understand what you expected it to do,



Do you have other lights on your game ? You need at least one.

ok, the problem is, when i remove the point light used to create the light around the fire ( as seen in the first pic), when i try to remove this light, it goes and applies to all of the scene, i.e. the yellow tint in the 2nd picture.



I have 2 lights in general always on, ambient light and a point light acting as a sun going round the scene.

What does your scene look like before the fire is added?

I thought the problem was obvious… the yellow light i use on the campfire im trying to turn off by “root.removeLight(pl)” but for some reason it applies it to the entire scene, hence the yellow tint everywhere.



requested pic:

http://i54.tinypic.com/nqptly.jpg

How many lights does light node have?

You are extending Node, which is generally considered bad practice… Do you override any default methods of your node? You should put your code in a Control, this way you can add it to any spatial w/o that spatial having to extend any special classes.

glaucomardano said:
How many lights does light node have?


just the one point light, radius 20f, colour: yellowish

i will try Normens thing, im not overwriting any methods in my node extension, perhaps i should just copy and paste the whole class here:
[java]package Models;

import com.jme3.asset.AssetManager;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.LightNode;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

public class Campfire extends Node{

private AssetManager assetManager;
private Spatial model;
private boolean fire;
private PointLight pl;
private LightNode nl;
private Node Root;
private ParticleEffects.FireParticleEffect fpe;

public Campfire(boolean fireon, AssetManager assetManager, Node root){
super("CampfireNode");
fire = fireon;
Root = root;
this.assetManager = assetManager;
this.attachChild(loadModel());
loadFire();
setUpLight();
root.addLight(pl);
if(fireon){
this.attachChild(fpe);
//nl.addLight(pl);
this.attachChild(nl);
nl.setEnabled(true);
}
}

private void setUpLight(){
pl = new PointLight();
pl.setRadius(20f);
pl.setColor(new ColorRGBA(1f, 1f, .7f, .75f));
nl = new LightNode("Campfire_light", pl);
nl.setLocalTranslation(model.getWorldBound().getCenter());
}

private Spatial loadModel(){
model = assetManager.loadModel("OgreModels/Campfire_old/Mesh.mesh.xml");
model.setName("Campfire");
Material mat = assetManager.loadMaterial("Materials/campfire.j3m");
model.setMaterial(mat);
Quaternion q = new Quaternion();
q.fromAngleAxis(-1*FastMath.QUARTER_PI, Vector3f.UNIT_Z);
model.rotate(0, 0, FastMath.PI);
return model;
}

public boolean hasFire(){
return fire;
}

public void enableFire(){
if(this.getChild("Campfire_fire") == null){
this.attachChild(fpe);
fire = true;
}
if(this.getChild("Campfire_light")== null){
this.attachChild(nl);
nl.setEnabled(true);
//Root.addLight(pl);
}
}

public void disableFire(){
this.detachChildNamed("Campfire_fire");
//Root.removeLight(pl);
this.detachChildNamed("Campfire_light");
nl.setEnabled(false);
fire=false;
}

private void loadFire(){
fpe = new ParticleEffects.FireParticleEffect("Campfire_fire", assetManager, 0);
fpe.setLocalTranslation(model.getWorldBound().getCenter());
fpe.setName("Campfire_fire");
//fpe.setEnabled(false);
}
}
[/java]

You are adding the same point light to 2 nodes(root and nl). It might be the problem.

1 Like

lightnode functionality doesn’t work without adding the light to the root,

is this still in effect:

http://hub.jmonkeyengine.org/groups/development-discussion-jme3/forum/topic/removing-light/

This topic is very old :roll:. I think you don’t need to add the LightNode to the root. Just add/remove the point light from root.

But you don’t wanna “touch” in the root lightning ok? Then create 2 lights, 1 for the root and another for the fire.

Create a fireNode…create the fireParticle…attach the fireParticle to the fireNode…create a pointLight…add it to the fireNode…attach the fireNode to the root…and create another pointLight…add it to the root.



[java]

public void enableFire() {

if(!fire)

fireNode.addLight(fireLight);

fire = true;

}



public void disableLight() {

if(fire)

fireNode.removeLight(fireLight);

fire = false;

}

[/java]

im sorry that doesnt make sense, if you add a light to a Node or spatial such as a box, it affects the entire area for me, even if i use a 0.2f radius,

thats why i used LightNode which works great when fire is on, however if i want to turn the fire off i disable particle emitter (works) and i try to remove the pointlight from the root and disable LightNode, but the yellow light moves from the campfire to the entire model.



im trying controls, but i cant figure out if i should add the particle emitter, light stuff in the control or seperate class which loads the model into a default Node.

I think you got confused when you saw that topic.

ryuu said:
lightnode functionality doesn't work without adding the light to the root,
is this still in effect:
http://hub.jmonkeyengine.org/groups/development-discussion-jme3/forum/topic/removing-light/

It was 1 year ago, and there wasn't a method to remove a light from a node. But now there is this feature : "node.removeLight(light)", so doesn't make sense to remove a light from scene by removing the whole node. Your "root" node have to have a point light, and the fire node have to have another light.

Edit:
ryuu said:
im sorry that doesnt make sense, if you add a light to a Node or spatial such as a box, it affects the entire area for me, even if i use a 0.2f radius,


Then resize the fireNode.

I appreciate the help, but what you’re saying doesnt actually work, scaling node doesn’t affect the light thats attached to it.

The problem is removeLight, not how the class is created or how LightNode or where i add the light, removing a light (one of 3 attached) causes that wierd behaviour, of where it affects the whole scene.



Also this is how LightNode works:

you assign it a Light in the LightNode constructor, but for this light to appear when running the game, you must add that specific light to the root Node otherwise it will not show up, (see the LightNode test if you are unsure)

I don’t know why you’re saying “one of 3 attached” if i can see just one instance of light in your code at line 37, and you attached it twice at line 28 and 40. Then 2 nodes are controlling the same light. Maybe it is causing a feeling of “pseudo working” for you.

ryuu said:
Also this is how LightNode works:
you assign it a Light in the LightNode constructor, but for this light to appear when running the game, you must add that specific light to the root Node otherwise it will not show up, (see the LightNode test if you are unsure)


Hmm, ok i'm going to see it.
glaucomardano said:
I don't know why you're saying "one of 3 attached" if i can see just one instance of light in your code at line 37, and you attached it twice at line 28 and 40. Then 2 nodes are controlling the same light. Maybe it is causing a feeling of "pseudo working" for you.


in an earlier post someone asked what other lights are attached to rootNode, and i said, ambient light and a pointlight i use as the sun, so hence total = 3 with the campfire point light, because someone else earlier said make sure there is atleast one light attached to root node, so thatis why i included "removing (one of 3 attached)"