Search in sources :

Example 66 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestSpotLightShadows method setupLighting.

public void setupLighting() {
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    rootNode.setShadowMode(ShadowMode.CastAndReceive);
    spot = new SpotLight();
    spot.setSpotRange(1000);
    spot.setSpotInnerAngle(5f * FastMath.DEG_TO_RAD);
    spot.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    spot.setPosition(new Vector3f(70.70334f, 34.013165f, 27.1017f));
    spot.setDirection(lightTarget.subtract(spot.getPosition()).normalizeLocal());
    spot.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(spot);
    //        PointLight pl=new PointLight();
    //      pl.setPosition(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    //      pl.setRadius(1000);     
    //      pl.setColor(ColorRGBA.White.mult(2));
    //      rootNode.addLight(pl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setLocalTranslation(new Vector3f(77.70334f, 34.013165f, 27.1017f));
    lightMdl.setLocalScale(5);
    rootNode.attachChild(lightMdl);
    //        DirectionalLight dl = new DirectionalLight();
    //        dl.setDirection(lightTarget.subtract(new Vector3f(77.70334f, 34.013165f, 27.1017f)));
    //        dl.setColor(ColorRGBA.White.mult(0.7f));
    //        rootNode.addLight(dl);
    final SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
    slsr.setLight(spot);
    slsr.setShadowIntensity(0.5f);
    slsr.setShadowZExtend(100);
    slsr.setShadowZFadeLength(5);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    viewPort.addProcessor(slsr);
    SpotLightShadowFilter slsf = new SpotLightShadowFilter(assetManager, 512);
    slsf.setLight(spot);
    slsf.setShadowIntensity(0.5f);
    slsf.setShadowZExtend(100);
    slsf.setShadowZFadeLength(5);
    slsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    slsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(slsf);
    viewPort.addProcessor(fpp);
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stop") && isPressed) {
                stop = !stop;
                //   slsr.displayFrustum();
                System.out.println("pos : " + spot.getPosition());
                System.out.println("dir : " + spot.getDirection());
            }
        }
    }, "stop");
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_1));
    flyCam.setDragToRotate(true);
}
Also used : SpotLightShadowFilter(com.jme3.shadow.SpotLightShadowFilter) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) SpotLightShadowRenderer(com.jme3.shadow.SpotLightShadowRenderer) SpotLight(com.jme3.light.SpotLight) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ActionListener(com.jme3.input.controls.ActionListener) AmbientLight(com.jme3.light.AmbientLight)

Example 67 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestTangentGenBadModels method simpleInitApp.

@Override
public void simpleInitApp() {
    //        assetManager.registerLocator("http://jme-glsl-shaders.googlecode.com/hg/assets/Models/LightBlow/", UrlLocator.class);
    //        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/", UrlLocator.class);
    final Spatial badModel = assetManager.loadModel("Models/TangentBugs/test.blend");
    //        badModel.setLocalScale(1f);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
    //        Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
    badModel.setMaterial(mat);
    rootNode.attachChild(badModel);
    // TODO: For some reason blender loader fails to load this.
    // need to check it
    //        Spatial model = assetManager.loadModel("test.blend");
    //        rootNode.attachChild(model);
    final Node debugTangents = new Node("debug tangents");
    debugTangents.setCullHint(CullHint.Always);
    rootNode.attachChild(debugTangents);
    final Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    badModel.depthFirstTraversal(new SceneGraphVisitorAdapter() {

        @Override
        public void visit(Geometry g) {
            Mesh m = g.getMesh();
            Material mat = g.getMaterial();
            //                if (mat.getParam("DiffuseMap") != null){
            //                    mat.setTexture("DiffuseMap", null);
            //                }
            TangentBinormalGenerator.generate(m);
            Geometry debug = new Geometry("debug tangents geom", TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f));
            debug.setMaterial(debugMat);
            debug.setCullHint(Spatial.CullHint.Never);
            debug.setLocalTransform(g.getWorldTransform());
            debugTangents.attachChild(debug);
        }
    });
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.8f, -0.6f, -0.08f).normalizeLocal());
    dl.setColor(new ColorRGBA(1, 1, 1, 1));
    rootNode.addLight(dl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    //        rootNode.addLight(pl);
    BitmapText info = new BitmapText(guiFont);
    info.setText("Press SPACE to switch between lighting and tangent display");
    info.setQueueBucket(Bucket.Gui);
    info.move(0, settings.getHeight() - info.getLineHeight(), 0);
    rootNode.attachChild(info);
    inputManager.addMapping("space", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(new ActionListener() {

        private boolean isLit = true;

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed)
                return;
            Material mat;
            if (isLit) {
                mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
                debugTangents.setCullHint(CullHint.Inherit);
            } else {
                mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
                mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
                debugTangents.setCullHint(CullHint.Always);
            }
            isLit = !isLit;
            badModel.setMaterial(mat);
        }
    }, "space");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) BitmapText(com.jme3.font.BitmapText) ActionListener(com.jme3.input.controls.ActionListener) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight)

Example 68 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestTransparentShadow method simpleInitApp.

public void simpleInitApp() {
    cam.setLocation(new Vector3f(5.700248f, 6.161693f, 5.1404157f));
    cam.setRotation(new Quaternion(-0.09441641f, 0.8993388f, -0.24089815f, -0.35248178f));
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    Quad q = new Quad(20, 20);
    q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(10));
    TangentBinormalGenerator.generate(q);
    Geometry geom = new Geometry("floor", q);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    geom.setMaterial(mat);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    geom.center();
    geom.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(geom);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.7f));
    rootNode.addLight(al);
    DirectionalLight dl1 = new DirectionalLight();
    dl1.setDirection(new Vector3f(0, -1, 0.5f).normalizeLocal());
    dl1.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(dl1);
    // create the geometry and attach it
    Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    tree.setQueueBucket(Bucket.Transparent);
    tree.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(tree);
    // Uses Texture from jme3-test-data library!
    ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
    Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    fire.setShadowMode(ShadowMode.Cast);
    fire.setMaterial(mat_red);
    fire.setImagesX(2);
    // 2x2 texture animation
    fire.setImagesY(2);
    // red
    fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
    // yellow
    fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
    fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
    fire.setStartSize(0.6f);
    fire.setEndSize(0.1f);
    fire.setGravity(0, 0, 0);
    fire.setLowLife(0.5f);
    fire.setHighLife(1.5f);
    fire.getParticleInfluencer().setVelocityVariation(0.3f);
    fire.setLocalTranslation(5.0f, 0, 1.0f);
    fire.setLocalScale(0.3f);
    fire.setQueueBucket(Bucket.Translucent);
    rootNode.attachChild(fire);
    Material mat2 = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    Geometry ball = new Geometry("sphere", new Sphere(16, 16, 0.5f));
    ball.setMaterial(mat2);
    ball.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(ball);
    ball.setLocalTranslation(-1.0f, 1.5f, 1.0f);
    final DirectionalLightShadowRenderer dlsRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 1);
    dlsRenderer.setLight(dl1);
    dlsRenderer.setLambda(0.55f);
    dlsRenderer.setShadowIntensity(0.8f);
    dlsRenderer.setShadowCompareMode(CompareMode.Software);
    dlsRenderer.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
    dlsRenderer.displayDebug();
    viewPort.addProcessor(dlsRenderer);
    inputManager.addMapping("stabilize", new KeyTrigger(KeyInput.KEY_B));
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stabilize") && isPressed) {
                dlsRenderer.setEnabledStabilization(!dlsRenderer.isEnabledStabilization());
            }
        }
    }, "stabilize");
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) Quad(com.jme3.scene.shape.Quad) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer) AmbientLight(com.jme3.light.AmbientLight)

Example 69 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestChaseCamera method registerInput.

public void registerInput() {
    inputManager.addMapping("moveForward", new KeyTrigger(keyInput.KEY_UP), new KeyTrigger(keyInput.KEY_W));
    inputManager.addMapping("moveBackward", new KeyTrigger(keyInput.KEY_DOWN), new KeyTrigger(keyInput.KEY_S));
    inputManager.addMapping("moveRight", new KeyTrigger(keyInput.KEY_RIGHT), new KeyTrigger(keyInput.KEY_D));
    inputManager.addMapping("moveLeft", new KeyTrigger(keyInput.KEY_LEFT), new KeyTrigger(keyInput.KEY_A));
    inputManager.addMapping("displayPosition", new KeyTrigger(keyInput.KEY_P));
    inputManager.addListener(this, "moveForward", "moveBackward", "moveRight", "moveLeft");
    inputManager.addListener(this, "displayPosition");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 70 with KeyTrigger

use of com.jme3.input.controls.KeyTrigger in project jmonkeyengine by jMonkeyEngine.

the class TestChaseCameraAppState method simpleInitApp.

public void simpleInitApp() {
    // Load a teapot model
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat_tea);
    rootNode.attachChild(teaGeom);
    // Load a floor model
    Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat_ground);
    rootNode.attachChild(ground);
    //disable the flyCam
    stateManager.detach(stateManager.getState(FlyCamAppState.class));
    // Enable a chase cam  
    ChaseCameraAppState chaseCamAS = new ChaseCameraAppState();
    chaseCamAS.setTarget(teaGeom);
    stateManager.attach(chaseCamAS);
    //Uncomment this to invert the camera's vertical rotation Axis 
    //chaseCamAS.setInvertVerticalAxis(true);
    //Uncomment this to invert the camera's horizontal rotation Axis
    //chaseCamAS.setInvertHorizontalAxis(true);
    //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)
    //WARNING : setting this trigger disable the rotation on right and left mouse button click
    //chaseCamAS.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    //Uncomment this to set mutiple triggers to enable rotation of the cam
    //Here space bar and middle mouse button
    //chaseCamAS.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));
    //registering inputs for target's movement
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) Material(com.jme3.material.Material) FlyCamAppState(com.jme3.app.FlyCamAppState) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)93 ActionListener (com.jme3.input.controls.ActionListener)36 Vector3f (com.jme3.math.Vector3f)30 Geometry (com.jme3.scene.Geometry)23 Material (com.jme3.material.Material)22 DirectionalLight (com.jme3.light.DirectionalLight)21 Quaternion (com.jme3.math.Quaternion)18 Spatial (com.jme3.scene.Spatial)13 FilterPostProcessor (com.jme3.post.FilterPostProcessor)11 Box (com.jme3.scene.shape.Box)11 BitmapText (com.jme3.font.BitmapText)10 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)10 Node (com.jme3.scene.Node)10 AnalogListener (com.jme3.input.controls.AnalogListener)9 ColorRGBA (com.jme3.math.ColorRGBA)9 Sphere (com.jme3.scene.shape.Sphere)8 AmbientLight (com.jme3.light.AmbientLight)7 Quad (com.jme3.scene.shape.Quad)6 ChaseCamera (com.jme3.input.ChaseCamera)4 BulletAppState (com.jme3.bullet.BulletAppState)3