Search in sources :

Example 11 with ChaseCamera

use of com.jme3.input.ChaseCamera in project jmonkeyengine by jMonkeyEngine.

the class TestLodGeneration method simpleInitApp.

public void simpleInitApp() {
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.6f));
    rootNode.addLight(al);
    // model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
    BoundingBox b = ((BoundingBox) model.getWorldBound());
    model.setLocalScale(1.2f / (b.getYExtent() * 2));
    //  model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0);
    for (Spatial spatial : model.getChildren()) {
        if (spatial instanceof Geometry) {
            listGeoms.add((Geometry) spatial);
        }
    }
    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    model.addControl(chaseCam);
    chaseCam.setLookAtOffset(b.getCenter());
    chaseCam.setDefaultDistance(5);
    chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);
    chaseCam.setZoomSensitivity(0.5f);
    //           ch = model.getControl(AnimControl.class).createChannel();
    //          ch.setAnim("Wave");
    SkeletonControl c = model.getControl(SkeletonControl.class);
    if (c != null) {
        c.setEnabled(false);
    }
    reductionvalue = 0.80f;
    lodLevel = 1;
    for (final Geometry geometry : listGeoms) {
        LodGenerator lodGenerator = new LodGenerator(geometry);
        lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
        geometry.setLodLevel(lodLevel);
    }
    rootNode.attachChild(model);
    flyCam.setEnabled(false);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    hudText = new BitmapText(guiFont, false);
    hudText.setSize(guiFont.getCharSet().getRenderedSize());
    hudText.setText(computeNbTri() + " tris");
    hudText.setLocalTranslation(cam.getWidth() / 2, hudText.getLineHeight(), 0);
    guiNode.attachChild(hudText);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("plus")) {
                    //                        lodLevel++;
                    //                        for (Geometry geometry : listGeoms) {
                    //                            if (geometry.getMesh().getNumLodLevels() <= lodLevel) {
                    //                                lodLevel = 0;
                    //                            }
                    //                            geometry.setLodLevel(lodLevel);
                    //                        }
                    //                        jaimeText.setText(computeNbTri() + " tris");
                    reductionvalue += 0.05f;
                    updateLod();
                }
                if (name.equals("minus")) {
                    //                        lodLevel--;
                    //                        for (Geometry geometry : listGeoms) {
                    //                            if (lodLevel < 0) {
                    //                                lodLevel = geometry.getMesh().getNumLodLevels() - 1;
                    //                            }
                    //                            geometry.setLodLevel(lodLevel);
                    //                        }
                    //                        jaimeText.setText(computeNbTri() + " tris");
                    reductionvalue -= 0.05f;
                    updateLod();
                }
                if (name.equals("wireFrame")) {
                    wireFrame = !wireFrame;
                    for (Geometry geometry : listGeoms) {
                        geometry.getMaterial().getAdditionalRenderState().setWireframe(wireFrame);
                    }
                }
            }
        }

        private void updateLod() {
            reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f);
            makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1);
        }
    }, "plus", "minus", "wireFrame");
    inputManager.addMapping("plus", new KeyTrigger(KeyInput.KEY_ADD));
    inputManager.addMapping("minus", new KeyTrigger(KeyInput.KEY_SUBTRACT));
    inputManager.addMapping("wireFrame", new KeyTrigger(KeyInput.KEY_SPACE));
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) SkeletonControl(com.jme3.animation.SkeletonControl) Geometry(com.jme3.scene.Geometry) LodGenerator(jme3tools.optimize.LodGenerator) BitmapText(com.jme3.font.BitmapText) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

ChaseCamera (com.jme3.input.ChaseCamera)11 Vector3f (com.jme3.math.Vector3f)8 DirectionalLight (com.jme3.light.DirectionalLight)5 Geometry (com.jme3.scene.Geometry)5 BitmapText (com.jme3.font.BitmapText)4 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 Material (com.jme3.material.Material)3 Quaternion (com.jme3.math.Quaternion)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 Node (com.jme3.scene.Node)3 Spatial (com.jme3.scene.Spatial)3 MotionPath (com.jme3.cinematic.MotionPath)2 MotionPathListener (com.jme3.cinematic.MotionPathListener)2 MotionEvent (com.jme3.cinematic.events.MotionEvent)2 ActionListener (com.jme3.input.controls.ActionListener)2 ColorRGBA (com.jme3.math.ColorRGBA)2 BloomFilter (com.jme3.post.filters.BloomFilter)2 AnimControl (com.jme3.animation.AnimControl)1 AnimationFactory (com.jme3.animation.AnimationFactory)1 SkeletonControl (com.jme3.animation.SkeletonControl)1