Skip to content

Commit aa60932

Browse files
authored
Update TestLodStress.java
1 parent 389d91a commit aa60932

File tree

1 file changed

+61
-32
lines changed

1 file changed

+61
-32
lines changed
Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2020 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -29,63 +29,92 @@
2929
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3030
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*/
32-
3332
package jme3test.stress;
3433

3534
import com.jme3.app.SimpleApplication;
35+
import com.jme3.input.KeyInput;
36+
import com.jme3.input.controls.ActionListener;
37+
import com.jme3.input.controls.KeyTrigger;
38+
import com.jme3.input.controls.Trigger;
3639
import com.jme3.light.DirectionalLight;
3740
import com.jme3.material.Material;
38-
import com.jme3.math.Quaternion;
41+
import com.jme3.material.RenderState;
3942
import com.jme3.math.Vector3f;
4043
import com.jme3.scene.Geometry;
4144
import com.jme3.scene.Node;
4245
import com.jme3.scene.control.LodControl;
4346

44-
public class TestLodStress extends SimpleApplication {
47+
public class TestLodStress extends SimpleApplication implements ActionListener {
4548

46-
public static void main(String[] args){
49+
public static void main(String[] args) {
4750
TestLodStress app = new TestLodStress();
48-
app.setShowSettings(false);
4951
app.setPauseOnLostFocus(false);
5052
app.start();
5153
}
5254

55+
private Material lightMaterial;
56+
private final Node debugNode = new Node("DebugNode");
57+
5358
@Override
5459
public void simpleInitApp() {
60+
61+
configureCamera();
62+
5563
DirectionalLight dl = new DirectionalLight();
56-
dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
64+
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
5765
rootNode.addLight(dl);
5866

5967
Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
6068
Geometry teapot = (Geometry) teapotNode.getChild(0);
61-
62-
// Sphere sph = new Sphere(16, 16, 4);
63-
// Geometry teapot = new Geometry("teapot", sph);
64-
65-
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
66-
mat.setFloat("Shininess", 16f);
67-
mat.setBoolean("VertexLighting", true);
68-
teapot.setMaterial(mat);
69-
70-
// A special Material to visualize mesh normals:
71-
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
72-
73-
for (int y = -10; y < 10; y++){
74-
for (int x = -10; x < 10; x++){
75-
Geometry clonePot = teapot.clone();
76-
77-
//clonePot.setMaterial(mat);
78-
clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
79-
clonePot.setLocalScale(.15f);
80-
81-
LodControl control = new LodControl();
82-
clonePot.addControl(control);
83-
rootNode.attachChild(clonePot);
69+
70+
lightMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
71+
lightMaterial.setFloat("Shininess", 16f);
72+
lightMaterial.setBoolean("VertexLighting", true);
73+
lightMaterial.getAdditionalRenderState().setWireframe(true);
74+
teapot.setMaterial(lightMaterial);
75+
76+
boolean cloneMaterial = false;
77+
for (int y = -10; y < 10; y++) {
78+
for (int x = -10; x < 10; x++) {
79+
Geometry geo = teapot.clone(cloneMaterial);
80+
geo.setLocalTranslation(x * .5f, 0, y * .5f);
81+
geo.setLocalScale(.15f);
82+
83+
geo.addControl(new LodControl());
84+
debugNode.attachChild(geo);
8485
}
8586
}
8687

87-
cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
88-
cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
88+
rootNode.attachChild(debugNode);
89+
registerInputMappings();
90+
}
91+
92+
@Override
93+
public void onAction(String name, boolean isPressed, float tpf) {
94+
if (!isPressed) return;
95+
96+
if (name.equals("toggleWireframe")) {
97+
RenderState renderState = lightMaterial.getAdditionalRenderState();
98+
boolean wireframe = renderState.isWireframe();
99+
renderState.setWireframe(!wireframe);
100+
}
101+
}
102+
103+
private void registerInputMappings() {
104+
addMapping("toggleWireframe", new KeyTrigger(KeyInput.KEY_SPACE));
105+
}
106+
107+
private void addMapping(String mappingName, Trigger... triggers) {
108+
inputManager.addMapping(mappingName, triggers);
109+
inputManager.addListener(this, mappingName);
110+
}
111+
112+
private void configureCamera() {
113+
flyCam.setMoveSpeed(25f);
114+
flyCam.setDragToRotate(true);
115+
116+
cam.setLocation(Vector3f.UNIT_XYZ.mult(8f));
117+
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
89118
}
90119

91120
}

0 commit comments

Comments
 (0)