Skip to content

Commit 473a358

Browse files
committed
fix global lights refresh flag propagation
1 parent 13edd16 commit 473a358

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

jme3-core/src/main/java/com/jme3/scene/Node.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,27 @@ protected void setTransformRefresh() {
127127
@Override
128128
protected void setLightListRefresh() {
129129
super.setLightListRefresh();
130+
boolean hasGlobalLights = false;
130131
for (Spatial child : children.getArray()) {
131132
if ((child.refreshFlags & RF_LIGHTLIST) != 0) {
133+
if( !hasGlobalLights && (child.refreshFlags & RF_GLOBAL_LIGHTS) != 0){
134+
hasGlobalLights = true;
135+
}
132136
continue;
133137
}
134-
135138
child.setLightListRefresh();
136139
}
140+
if(hasGlobalLights){
141+
refreshFlags |= RF_GLOBAL_LIGHTS;
142+
Node p = this.parent;
143+
while (p != null) {
144+
if ((p.refreshFlags & RF_GLOBAL_LIGHTS) != 0) {
145+
break;
146+
}
147+
p.refreshFlags |= RF_GLOBAL_LIGHTS;
148+
p = p.parent;
149+
}
150+
}
137151
}
138152

139153
@Override
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package jme3test.light;
2+
3+
import com.jme3.app.SimpleApplication;
4+
import com.jme3.asset.AssetManager;
5+
import com.jme3.light.AmbientLight;
6+
import com.jme3.light.PointLight;
7+
import com.jme3.material.Material;
8+
import com.jme3.math.ColorRGBA;
9+
import com.jme3.math.Vector3f;
10+
import com.jme3.scene.Geometry;
11+
import com.jme3.scene.Node;
12+
import com.jme3.scene.shape.Box;
13+
14+
public class TestGlobalLight extends SimpleApplication {
15+
public static void main(String[] args) {
16+
TestGlobalLight test = new TestGlobalLight();
17+
test.start();
18+
}
19+
20+
private static Geometry createLitWhiteCube(AssetManager assetManager, String name) {
21+
Box box = new Box(1, 1, 1);
22+
Geometry cube = new Geometry(name, box);
23+
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
24+
mat.setColor("Diffuse", ColorRGBA.White);
25+
mat.setColor("Ambient", ColorRGBA.White);
26+
mat.setBoolean("UseMaterialColors", true);
27+
cube.setMaterial(mat);
28+
return cube;
29+
}
30+
31+
@Override
32+
public void simpleInitApp() {
33+
flyCam.setEnabled(false);
34+
final PointLight globalPointLight = new PointLight(true);
35+
final Node lightsAttachedNode = new Node("lightsAttachedNode");
36+
Vector3f testOffset = new Vector3f(0, 0, 0);
37+
38+
lightsAttachedNode.setLocalTranslation(testOffset);
39+
40+
Node lightsNotAttachedNode = new Node("lightsNotAttachedNode");
41+
lightsNotAttachedNode.setLocalTranslation(testOffset);
42+
43+
Geometry litByAll = createLitWhiteCube(getAssetManager(), "litByAll");
44+
litByAll.setLocalTranslation(2, 0, -1);
45+
lightsAttachedNode.attachChild(litByAll);
46+
47+
Geometry litOnlyByGlobal = createLitWhiteCube(getAssetManager(), "litOnlyByGlobal");
48+
litOnlyByGlobal.setLocalTranslation(-2, 0, -1);
49+
lightsNotAttachedNode.attachChild(litOnlyByGlobal);
50+
51+
PointLight localPointLight = new PointLight();
52+
localPointLight.setColor(ColorRGBA.Red);
53+
54+
globalPointLight.setColor(ColorRGBA.Green);
55+
56+
getCamera().setLocation(testOffset.add(new Vector3f(0, 0, 10)));
57+
getCamera().lookAt(testOffset, Vector3f.UNIT_Y);
58+
59+
Node rootNode = new Node();
60+
rootNode.attachChild(lightsAttachedNode);
61+
rootNode.attachChild(lightsNotAttachedNode);
62+
63+
Node rootRootNode = new Node();
64+
getRootNode().attachChild(rootRootNode);
65+
66+
lightsAttachedNode.addLight(localPointLight);
67+
lightsAttachedNode.addLight(globalPointLight);
68+
69+
rootRootNode.attachChild(rootNode);
70+
71+
getRootNode().addLight(new AmbientLight(new ColorRGBA(0.01f, 0.01f, 0.01f, 1)));
72+
}
73+
}

0 commit comments

Comments
 (0)