Search in sources :

Example 1 with LodControl

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);
}
Also used : Geometry(com.jme3.scene.Geometry) BloomUI(jme3test.post.BloomUI) LodControl(com.jme3.scene.control.LodControl) ColorRGBA(com.jme3.math.ColorRGBA) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 2 with LodControl

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);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Mesh(com.jme3.scene.Mesh)

Example 3 with LodControl

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);
        }
    }
}
Also used : BinaryImporter(com.jme3.export.binary.BinaryImporter) Node(com.jme3.scene.Node) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl)

Example 4 with LodControl

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));
}
Also used : Geometry(com.jme3.scene.Geometry) LodControl(com.jme3.scene.control.LodControl) Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 5 with LodControl

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));
}
Also used : Geometry(com.jme3.scene.Geometry) LodControl(com.jme3.scene.control.LodControl) Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Aggregations

Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 DirectionalLight (com.jme3.light.DirectionalLight)3 Vector3f (com.jme3.math.Vector3f)3 LodControl (com.jme3.scene.control.LodControl)3 Material (com.jme3.material.Material)2 Quaternion (com.jme3.math.Quaternion)2 BinaryImporter (com.jme3.export.binary.BinaryImporter)1 ChaseCamera (com.jme3.input.ChaseCamera)1 ColorRGBA (com.jme3.math.ColorRGBA)1 FilterPostProcessor (com.jme3.post.FilterPostProcessor)1 BloomFilter (com.jme3.post.filters.BloomFilter)1 Mesh (com.jme3.scene.Mesh)1 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)1 BloomUI (jme3test.post.BloomUI)1