Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 61 additions & 32 deletions jme3-examples/src/main/java/jme3test/stress/TestLodStress.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2020 jMonkeyEngine
* Copyright (c) 2009-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,63 +29,92 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package jme3test.stress;

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.Trigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.Quaternion;
import com.jme3.material.RenderState;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.LodControl;

public class TestLodStress extends SimpleApplication {
public class TestLodStress extends SimpleApplication implements ActionListener {

public static void main(String[] args){
public static void main(String[] args) {
TestLodStress app = new TestLodStress();
app.setShowSettings(false);
app.setPauseOnLostFocus(false);
app.start();
}

private Material lightMaterial;
private final Node debugNode = new Node("DebugNode");

@Override
public void simpleInitApp() {

configureCamera();

DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);

Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
Geometry teapot = (Geometry) teapotNode.getChild(0);

// Sphere sph = new Sphere(16, 16, 4);
// Geometry teapot = new Geometry("teapot", sph);

Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setFloat("Shininess", 16f);
mat.setBoolean("VertexLighting", true);
teapot.setMaterial(mat);

// A special Material to visualize mesh normals:
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

for (int y = -10; y < 10; y++){
for (int x = -10; x < 10; x++){
Geometry clonePot = teapot.clone();

//clonePot.setMaterial(mat);
clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
clonePot.setLocalScale(.15f);

LodControl control = new LodControl();
clonePot.addControl(control);
rootNode.attachChild(clonePot);

lightMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
lightMaterial.setFloat("Shininess", 16f);
lightMaterial.setBoolean("VertexLighting", true);
lightMaterial.getAdditionalRenderState().setWireframe(true);
teapot.setMaterial(lightMaterial);

boolean cloneMaterial = false;
for (int y = -10; y < 10; y++) {
for (int x = -10; x < 10; x++) {
Geometry geo = teapot.clone(cloneMaterial);
geo.setLocalTranslation(x * .5f, 0, y * .5f);
geo.setLocalScale(.15f);

geo.addControl(new LodControl());
debugNode.attachChild(geo);
}
}

cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
rootNode.attachChild(debugNode);
registerInputMappings();
}

@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (!isPressed) return;

if (name.equals("toggleWireframe")) {
RenderState renderState = lightMaterial.getAdditionalRenderState();
boolean wireframe = renderState.isWireframe();
renderState.setWireframe(!wireframe);
}
}

private void registerInputMappings() {
addMapping("toggleWireframe", new KeyTrigger(KeyInput.KEY_SPACE));
}

private void addMapping(String mappingName, Trigger... triggers) {
inputManager.addMapping(mappingName, triggers);
inputManager.addListener(this, mappingName);
}

private void configureCamera() {
flyCam.setMoveSpeed(25f);
flyCam.setDragToRotate(true);

cam.setLocation(Vector3f.UNIT_XYZ.mult(8f));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
}

}