use of com.jme3.scene.control.LodControl in project jmonkeyengine by jMonkeyEngine.
the class TestHoverTank method simpleInitApp.
@Override
public void simpleInitApp() {
Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
flyCam.setEnabled(false);
ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
chaseCam.setSmoothMotion(true);
chaseCam.setMaxDistance(100000);
chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
Geometry tankGeom = (Geometry) tank.getChild(0);
LodControl control = new LodControl();
tankGeom.addControl(control);
rootNode.attachChild(tank);
Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
DirectionalLight dl = new DirectionalLight();
dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
dl.setDirection(lightDir);
Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
DirectionalLight dl2 = new DirectionalLight();
dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
dl2.setDirection(lightDir2);
rootNode.addLight(dl);
rootNode.addLight(dl2);
rootNode.attachChild(tank);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
bf.setBloomIntensity(2.0f);
bf.setExposurePower(1.3f);
fpp.addFilter(bf);
BloomUI bui = new BloomUI(inputManager, bf);
viewPort.addProcessor(fpp);
}
use of com.jme3.scene.control.LodControl in project jmonkeyengine by jMonkeyEngine.
the class LodControl method setSpatial.
@Override
public void setSpatial(Spatial spatial) {
if (!(spatial instanceof Geometry)) {
throw new IllegalArgumentException("LodControl can only be attached to Geometry!");
}
super.setSpatial(spatial);
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
numLevels = mesh.getNumLodLevels();
numTris = new int[numLevels];
for (int i = numLevels - 1; i >= 0; i--) {
numTris[i] = mesh.getTriangleCount(i);
}
}
use of com.jme3.scene.control.LodControl in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestReadWrite method loadTerrain.
private void loadTerrain() {
FileInputStream fis = null;
try {
long start = System.currentTimeMillis();
// remove the existing terrain and detach it from the root node.
if (terrain != null) {
Node existingTerrain = (Node) terrain;
existingTerrain.removeFromParent();
existingTerrain.removeControl(TerrainLodControl.class);
existingTerrain.detachAllChildren();
terrain = null;
}
// import the saved terrain, and attach it back to the root node
File f = new File("terrainsave.jme");
fis = new FileInputStream(f);
BinaryImporter imp = BinaryImporter.getInstance();
imp.setAssetManager(assetManager);
terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
rootNode.attachChild((Node) terrain);
float duration = (System.currentTimeMillis() - start) / 1000.0f;
System.out.println("Load took " + duration + " seconds");
// now we have to add back the camera to the LOD control
TerrainLodControl lodControl = ((Node) terrain).getControl(TerrainLodControl.class);
if (lodControl != null)
lodControl.setCamera(getCamera());
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ex) {
Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
use of com.jme3.scene.control.LodControl in project jmonkeyengine by jMonkeyEngine.
the class TestBatchLod method simpleInitApp.
public void simpleInitApp() {
// inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);
DirectionalLight dl = new DirectionalLight();
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);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setFloat("Shininess", 16f);
mat.setBoolean("VertexLighting", true);
teapot.setMaterial(mat);
// show normals as material
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
flyCam.setMoveSpeed(5);
for (int y = -5; y < 5; y++) {
for (int x = -5; x < 5; x++) {
Geometry clonePot = teapot.clone();
//clonePot.setMaterial(mat);
clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
clonePot.setLocalScale(.15f);
clonePot.setMaterial(mat);
rootNode.attachChild(clonePot);
}
}
GeometryBatchFactory.optimize(rootNode, true);
LodControl control = new LodControl();
rootNode.getChild(0).addControl(control);
cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));
}
use of com.jme3.scene.control.LodControl in project jmonkeyengine by jMonkeyEngine.
the class TestLodStress method simpleInitApp.
public void simpleInitApp() {
DirectionalLight dl = new DirectionalLight();
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);
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);
}
}
cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
}
Aggregations