|
1 | 1 | /* |
2 | | - * Copyright (c) 2009-2020 jMonkeyEngine |
| 2 | + * Copyright (c) 2009-2025 jMonkeyEngine |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
|
29 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | | - |
33 | 32 | package jme3test.stress; |
34 | 33 |
|
35 | 34 | 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; |
36 | 39 | import com.jme3.light.DirectionalLight; |
37 | 40 | import com.jme3.material.Material; |
38 | | -import com.jme3.math.Quaternion; |
| 41 | +import com.jme3.material.RenderState; |
39 | 42 | import com.jme3.math.Vector3f; |
40 | 43 | import com.jme3.scene.Geometry; |
41 | 44 | import com.jme3.scene.Node; |
42 | 45 | import com.jme3.scene.control.LodControl; |
43 | 46 |
|
44 | | -public class TestLodStress extends SimpleApplication { |
| 47 | +public class TestLodStress extends SimpleApplication implements ActionListener { |
45 | 48 |
|
46 | | - public static void main(String[] args){ |
| 49 | + public static void main(String[] args) { |
47 | 50 | TestLodStress app = new TestLodStress(); |
48 | | - app.setShowSettings(false); |
49 | 51 | app.setPauseOnLostFocus(false); |
50 | 52 | app.start(); |
51 | 53 | } |
52 | 54 |
|
| 55 | + private Material lightMaterial; |
| 56 | + private final Node debugNode = new Node("DebugNode"); |
| 57 | + |
53 | 58 | @Override |
54 | 59 | public void simpleInitApp() { |
| 60 | + |
| 61 | + configureCamera(); |
| 62 | + |
55 | 63 | DirectionalLight dl = new DirectionalLight(); |
56 | | - dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal()); |
| 64 | + dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); |
57 | 65 | rootNode.addLight(dl); |
58 | 66 |
|
59 | 67 | Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml"); |
60 | 68 | 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); |
84 | 85 | } |
85 | 86 | } |
86 | 87 |
|
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); |
89 | 118 | } |
90 | 119 |
|
91 | 120 | } |
0 commit comments