Skip to content

Commit f6e646f

Browse files
authored
Add InstanceNode test using PBRLighting
1 parent 2fa2101 commit f6e646f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package jme3test.scene.instancing;
2+
3+
import com.jme3.app.SimpleApplication;
4+
import com.jme3.light.PointLight;
5+
import com.jme3.material.Material;
6+
import com.jme3.math.ColorRGBA;
7+
import com.jme3.math.Vector3f;
8+
import com.jme3.scene.Geometry;
9+
import com.jme3.scene.instancing.InstancedNode;
10+
import com.jme3.scene.shape.Box;
11+
12+
public class TestInstanceNodeWithPbr extends SimpleApplication {
13+
// Try to test with different offset
14+
private static float offset = 12;
15+
16+
public static void main(String[] args) {
17+
TestInstanceNodeWithPbr app = new TestInstanceNodeWithPbr();
18+
app.start();
19+
}
20+
21+
private Geometry box;
22+
private PointLight pointLight;
23+
24+
@Override
25+
public void simpleInitApp() {
26+
InstancedNode instancedNode = new InstancedNode("testInstancedNode");
27+
rootNode.attachChild(instancedNode);
28+
29+
box = new Geometry("PBRLightingBox", new Box(0.5f, 0.5f, 0.5f));
30+
Material pbrLightingMaterial = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
31+
pbrLightingMaterial.setBoolean("UseInstancing", true);
32+
pbrLightingMaterial.setColor("BaseColor", ColorRGBA.Red);
33+
box.setMaterial(pbrLightingMaterial);
34+
35+
instancedNode.attachChild(box);
36+
instancedNode.instance();
37+
38+
pointLight = new PointLight();
39+
pointLight.setColor(ColorRGBA.White);
40+
pointLight.setRadius(10f);
41+
rootNode.addLight(pointLight);
42+
43+
box.setLocalTranslation(new Vector3f(offset, 0, 0));
44+
pointLight.setPosition(new Vector3f(offset - 3f, 0, 0));
45+
46+
cam.setLocation(new Vector3f(offset - 5f, 0, 0));
47+
cam.lookAtDirection(Vector3f.UNIT_X, Vector3f.UNIT_Y);
48+
}
49+
50+
@Override
51+
public void simpleUpdate(float tpf) {
52+
offset += tpf;
53+
54+
System.err.println(offset);
55+
box.setLocalTranslation(new Vector3f(offset, 0, 0));
56+
pointLight.setPosition(new Vector3f(offset - 3f, 0, 0));
57+
58+
cam.setLocation(new Vector3f(offset - 5f, 0, 0));
59+
cam.lookAtDirection(Vector3f.UNIT_X, Vector3f.UNIT_Y);
60+
}
61+
}

0 commit comments

Comments
 (0)