|
@@ -57,6 +57,7 @@ import com.jme3.scene.Node;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.control.AbstractControl;
|
|
import com.jme3.scene.control.AbstractControl;
|
|
import com.jme3.scene.shape.Box;
|
|
import com.jme3.scene.shape.Box;
|
|
|
|
+import com.jme3.util.MaterialDebugAppState;
|
|
|
|
|
|
public class TestManyLightsSingle extends SimpleApplication {
|
|
public class TestManyLightsSingle extends SimpleApplication {
|
|
|
|
|
|
@@ -64,8 +65,12 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|
TestManyLightsSingle app = new TestManyLightsSingle();
|
|
TestManyLightsSingle app = new TestManyLightsSingle();
|
|
app.start();
|
|
app.start();
|
|
}
|
|
}
|
|
- TechniqueDef.LightMode lm = TechniqueDef.LightMode.MultiPass;
|
|
|
|
- int lightNum = 6 ;
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Switch mode with space bar at run time
|
|
|
|
+ */
|
|
|
|
+ TechniqueDef.LightMode lm = TechniqueDef.LightMode.SinglePass;
|
|
|
|
+ int lightNum = 6;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void simpleInitApp() {
|
|
public void simpleInitApp() {
|
|
@@ -79,24 +84,27 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|
rootNode.attachChild(scene);
|
|
rootNode.attachChild(scene);
|
|
Node n = (Node) rootNode.getChild(0);
|
|
Node n = (Node) rootNode.getChild(0);
|
|
LightList lightList = n.getWorldLightList();
|
|
LightList lightList = n.getWorldLightList();
|
|
- 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));
|
|
|
|
|
|
/* A colored lit cube. Needs light source! */
|
|
/* A colored lit cube. Needs light source! */
|
|
Box boxMesh = new Box(1f, 1f, 1f);
|
|
Box boxMesh = new Box(1f, 1f, 1f);
|
|
- Geometry boxGeo = new Geometry("Colored Box", boxMesh);
|
|
|
|
|
|
+ final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
|
|
Material boxMat = g.getMaterial().clone();
|
|
Material boxMat = g.getMaterial().clone();
|
|
|
|
+ boxMat.clearParam("DiffuseMap");
|
|
boxMat.setBoolean("UseMaterialColors", true);
|
|
boxMat.setBoolean("UseMaterialColors", true);
|
|
boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
|
|
boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
|
|
boxMat.setColor("Diffuse", ColorRGBA.Blue);
|
|
boxMat.setColor("Diffuse", ColorRGBA.Blue);
|
|
boxGeo.setMaterial(boxMat);
|
|
boxGeo.setMaterial(boxMat);
|
|
|
|
|
|
|
|
+ final Node cubeNodes = new Node();
|
|
|
|
+ n.attachChild(cubeNodes);
|
|
int nb = 0;
|
|
int nb = 0;
|
|
for (Light light : lightList) {
|
|
for (Light light : lightList) {
|
|
nb++;
|
|
nb++;
|
|
PointLight p = (PointLight) light;
|
|
PointLight p = (PointLight) light;
|
|
- if (nb >60) {
|
|
|
|
|
|
+ if (nb > 60) {
|
|
n.removeLight(light);
|
|
n.removeLight(light);
|
|
} else {
|
|
} else {
|
|
|
|
|
|
@@ -123,8 +131,8 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Geometry b = boxGeo.clone();
|
|
|
|
- n.attachChild(b);
|
|
|
|
|
|
+ Geometry b = boxGeo.clone(false);
|
|
|
|
+ cubeNodes.attachChild(b);
|
|
b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
|
|
b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -145,30 +153,35 @@ public class TestManyLightsSingle extends SimpleApplication {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
flyCam.setDragToRotate(true);
|
|
flyCam.setDragToRotate(true);
|
|
flyCam.setMoveSpeed(50);
|
|
flyCam.setMoveSpeed(50);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ final MaterialDebugAppState debug = new MaterialDebugAppState();
|
|
|
|
+ stateManager.attach(debug);
|
|
|
|
|
|
inputManager.addListener(new ActionListener() {
|
|
inputManager.addListener(new ActionListener() {
|
|
public void onAction(String name, boolean isPressed, float tpf) {
|
|
public void onAction(String name, boolean isPressed, float tpf) {
|
|
if (name.equals("toggle") && isPressed) {
|
|
if (name.equals("toggle") && isPressed) {
|
|
if (lm == TechniqueDef.LightMode.SinglePass) {
|
|
if (lm == TechniqueDef.LightMode.SinglePass) {
|
|
lm = TechniqueDef.LightMode.MultiPass;
|
|
lm = TechniqueDef.LightMode.MultiPass;
|
|
|
|
+ helloText.setText("(Multi pass)");
|
|
} else {
|
|
} else {
|
|
lm = TechniqueDef.LightMode.SinglePass;
|
|
lm = TechniqueDef.LightMode.SinglePass;
|
|
|
|
+ helloText.setText("(Single pass) nb lights per batch : " + lightNum);
|
|
}
|
|
}
|
|
renderManager.setPreferredLightMode(lm);
|
|
renderManager.setPreferredLightMode(lm);
|
|
|
|
+ reloadScene(g,boxGeo,cubeNodes);
|
|
}
|
|
}
|
|
if (name.equals("lightsUp") && isPressed) {
|
|
if (name.equals("lightsUp") && isPressed) {
|
|
lightNum++;
|
|
lightNum++;
|
|
renderManager.setSinglePassLightBatchSize(lightNum);
|
|
renderManager.setSinglePassLightBatchSize(lightNum);
|
|
- helloText.setText("nb lights per batch : " + lightNum);
|
|
|
|
|
|
+ helloText.setText("(Single pass) nb lights per batch : " + lightNum);
|
|
}
|
|
}
|
|
if (name.equals("lightsDown") && isPressed) {
|
|
if (name.equals("lightsDown") && isPressed) {
|
|
lightNum--;
|
|
lightNum--;
|
|
renderManager.setSinglePassLightBatchSize(lightNum);
|
|
renderManager.setSinglePassLightBatchSize(lightNum);
|
|
- helloText.setText("nb lights per batch : " + lightNum);
|
|
|
|
|
|
+ helloText.setText("(Single pass) nb lights per batch : " + lightNum);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, "toggle", "lightsUp", "lightsDown");
|
|
}, "toggle", "lightsUp", "lightsDown");
|
|
@@ -202,12 +215,26 @@ 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("nb lights per batch : " + lightNum);
|
|
|
|
|
|
+ helloText.setText("(Single pass) nb lights per batch : " + lightNum);
|
|
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) {
|
|
|
|
+ MaterialDebugAppState debug = stateManager.getState(MaterialDebugAppState.class);
|
|
|
|
+ Material m = debug.reloadMaterial(g.getMaterial());
|
|
|
|
+ if (m != null) {
|
|
|
|
+ g.setMaterial(m);
|
|
|
|
+ }
|
|
|
|
+ m = debug.reloadMaterial(boxGeo.getMaterial());
|
|
|
|
+ if (m != null) {
|
|
|
|
+ cubeNodes.setMaterial(m);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
BitmapText helloText;
|
|
BitmapText helloText;
|
|
long time;
|
|
long time;
|
|
long nbFrames;
|
|
long nbFrames;
|