Search in sources :

Example 31 with InputManager

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

the class TestSSAO2 method simpleInitApp.

@Override
public void simpleInitApp() {
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    flyCam.setDragToRotate(true);
    setPauseOnLostFocus(false);
    getStateManager().attach(new DetailedProfilerState());
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 16f);
    //mat.setBoolean("VertexLighting", true);
    Geometry floor = new Geometry("floor", new Box(1000, 0.1f, 1000));
    floor.setMaterial(mat);
    rootNode.attachChild(floor);
    Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
    Geometry teapot = (Geometry) teapotNode.getChild(0);
    teapot.setMaterial(mat);
    //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    for (int f = 10; f > 3; f--) {
        for (int y = -f; y < f; y++) {
            for (int x = -f; x < f; x++) {
                Geometry clonePot = teapot.clone();
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 10 - f, y * .5f);
                clonePot.setLocalScale(.15f);
                rootNode.attachChild(clonePot);
            }
        }
    }
    cam.setLocation(new Vector3f(10.247649f, 8.275992f, 10.405156f));
    cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    SSAOFilter ssaoFilter = new SSAOFilter(2.9299974f, 25f, 5.8100376f, 0.091000035f);
    int numSamples = context.getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    //ssaoFilter.setApproximateNormals(true);
    fpp.addFilter(ssaoFilter);
    SSAOUI ui = new SSAOUI(inputManager, ssaoFilter);
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) DetailedProfilerState(com.jme3.app.DetailedProfilerState) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor)

Example 32 with InputManager

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

the class SSAOUI method init.

private void init(InputManager inputManager) {
    System.out.println("----------------- SSAO UI Debugger --------------------");
    System.out.println("-- Sample Radius : press Y to increase, H to decrease");
    System.out.println("-- AO Intensity : press U to increase, J to decrease");
    System.out.println("-- AO scale : press I to increase, K to decrease");
    System.out.println("-- AO bias : press O to increase, P to decrease");
    System.out.println("-- Toggle AO on/off : press space bar");
    System.out.println("-- Use only AO : press Num pad 0");
    System.out.println("-- Output config declaration : press P");
    System.out.println("-------------------------------------------------------");
    inputManager.addMapping("sampleRadiusUp", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("sampleRadiusDown", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("intensityUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("intensityDown", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
    inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
    inputManager.addMapping("toggleApprox", new KeyTrigger(KeyInput.KEY_NUMPAD5));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggleUseAO") && keyPressed) {
                filter.setEnabled(!filter.isEnabled());
                // filter.setUseAo(!filter.isUseAo());
                System.out.println("use AO : " + filter.isEnabled());
            }
            if (name.equals("toggleApprox") && keyPressed) {
                filter.setApproximateNormals(!filter.isApproximateNormals());
                System.out.println("Approximate Normals : " + filter.isApproximateNormals());
            }
            if (name.equals("toggleUseOnlyAo") && keyPressed) {
                filter.setUseOnlyAo(!filter.isUseOnlyAo());
                System.out.println("use Only AO : " + filter.isUseOnlyAo());
            }
            if (name.equals("outputConfig") && keyPressed) {
                System.out.println("new SSAOFilter(" + filter.getSampleRadius() + "f," + filter.getIntensity() + "f," + filter.getScale() + "f," + filter.getBias() + "f);");
            }
        }
    };
    AnalogListener anl = new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("sampleRadiusUp")) {
                filter.setSampleRadius(filter.getSampleRadius() + 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("sampleRadiusDown")) {
                filter.setSampleRadius(filter.getSampleRadius() - 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("intensityUp")) {
                filter.setIntensity(filter.getIntensity() + 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("intensityDown")) {
                filter.setIntensity(filter.getIntensity() - 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("scaleUp")) {
                filter.setScale(filter.getScale() + 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("scaleDown")) {
                filter.setScale(filter.getScale() - 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("biasUp")) {
                filter.setBias(filter.getBias() + 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
            if (name.equals("biasDown")) {
                filter.setBias(filter.getBias() - 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
        }
    };
    inputManager.addListener(acl, "toggleUseAO", "toggleApprox", "toggleUseOnlyAo", "outputConfig");
    inputManager.addListener(anl, "sampleRadiusUp", "sampleRadiusDown", "intensityUp", "intensityDown", "scaleUp", "scaleDown", "biasUp", "biasDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 33 with InputManager

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

the class TestBloom method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    //cam.setFrustumFar(1000);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0, 0, 10);
    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(800, 10, 700));
    soil.setLocalTranslation(0, -13, 550);
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    // fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    BloomFilter bloom = new BloomFilter();
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    BloomUI ui = new BloomUI(inputManager, bloom);
    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    initInputs();
}
Also used : Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 34 with InputManager

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

the class TestNiftyGui method simpleInitApp.

@Override
public void simpleInitApp() {
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("Interface/Nifty/HelloJme.xml", "start", this);
    // attach the nifty display to the gui view port as a processor
    guiViewPort.addProcessor(niftyDisplay);
    // disable the fly cam
    //        flyCam.setEnabled(false);
    //        flyCam.setDragToRotate(true);
    inputManager.setCursorVisible(true);
}
Also used : Geometry(com.jme3.scene.Geometry) NiftyJmeDisplay(com.jme3.niftygui.NiftyJmeDisplay) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 35 with InputManager

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

the class TestNiftyToMesh method simpleInitApp.

public void simpleInitApp() {
    ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
    niftyView.setClearFlags(true, true, true);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, niftyView);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("all/intro.xml", "start");
    niftyView.addProcessor(niftyDisplay);
    Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
    FrameBuffer fb = new FrameBuffer(1024, 768, 1);
    fb.setDepthTexture(depthTex);
    Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);
    fb.setColorTexture(tex);
    niftyView.setClearFlags(true, true, true);
    niftyView.setOutputFrameBuffer(fb);
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
Also used : NiftyJmeDisplay(com.jme3.niftygui.NiftyJmeDisplay) Geometry(com.jme3.scene.Geometry) Texture2D(com.jme3.texture.Texture2D) ViewPort(com.jme3.renderer.ViewPort) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) FrameBuffer(com.jme3.texture.FrameBuffer)

Aggregations

Vector3f (com.jme3.math.Vector3f)16 Geometry (com.jme3.scene.Geometry)16 Material (com.jme3.material.Material)14 FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 DirectionalLight (com.jme3.light.DirectionalLight)13 ChaseCamera (com.jme3.input.ChaseCamera)11 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 Quaternion (com.jme3.math.Quaternion)11 Spatial (com.jme3.scene.Spatial)10 Box (com.jme3.scene.shape.Box)8 BitmapText (com.jme3.font.BitmapText)7 Node (com.jme3.scene.Node)7 ActionListener (com.jme3.input.controls.ActionListener)6 NiftyJmeDisplay (com.jme3.niftygui.NiftyJmeDisplay)6 AmbientLight (com.jme3.light.AmbientLight)5 SSAOFilter (com.jme3.post.ssao.SSAOFilter)5 InputManager (com.jme3.input.InputManager)4 BloomFilter (com.jme3.post.filters.BloomFilter)4 Quad (com.jme3.scene.shape.Quad)4 Sphere (com.jme3.scene.shape.Sphere)4