Search in sources :

Example 26 with AL

use of com.jme3.audio.openal.AL in project jmonkeyengine by jMonkeyEngine.

the class TestSaveGame method simpleInitApp.

public void simpleInitApp() {
    //node that is used to store player data
    Node myPlayer = new Node();
    myPlayer.setName("PlayerNode");
    myPlayer.setUserData("name", "Mario");
    myPlayer.setUserData("health", 100.0f);
    myPlayer.setUserData("points", 0);
    //the actual model would be attached to this node
    Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    myPlayer.attachChild(model);
    //before saving the game, the model should be detached so its not saved along with the node
    myPlayer.detachAllChildren();
    SaveGame.saveGame("mycompany/mygame", "savegame_001", myPlayer);
    //later the game is loaded again
    Node player = (Node) SaveGame.loadGame("mycompany/mygame", "savegame_001");
    player.attachChild(model);
    rootNode.attachChild(player);
    //and the data is available
    System.out.println("Name: " + player.getUserData("name"));
    System.out.println("Health: " + player.getUserData("health"));
    System.out.println("Points: " + player.getUserData("points"));
    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);
//note you can also implement your own classes that implement the Savable interface.
}
Also used : Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) AmbientLight(com.jme3.light.AmbientLight)

Example 27 with AL

use of com.jme3.audio.openal.AL in project jmonkeyengine by jMonkeyEngine.

the class TestTextureAtlas method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(50);
    Node scene = new Node("Scene");
    Spatial obj1 = assetManager.loadModel("Models/Ferrari/Car.scene");
    obj1.setLocalTranslation(-4, 0, 0);
    Spatial obj2 = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    obj2.setLocalTranslation(-2, 0, 0);
    Spatial obj3 = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    obj3.setLocalTranslation(-0, 0, 0);
    Spatial obj4 = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    obj4.setLocalTranslation(2, 0, 0);
    Spatial obj5 = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    obj5.setLocalTranslation(4, 0, 0);
    scene.attachChild(obj1);
    scene.attachChild(obj2);
    scene.attachChild(obj3);
    scene.attachChild(obj4);
    scene.attachChild(obj5);
    Geometry geom = TextureAtlas.makeAtlasBatch(scene, assetManager, 2048);
    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0.69077975f, -0.6277887f, -0.35875428f).normalizeLocal());
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    rootNode.addLight(sun);
    rootNode.attachChild(geom);
    //quad to display material
    Geometry box = new Geometry("displayquad", new Quad(4, 4));
    box.setMaterial(geom.getMaterial());
    box.setLocalTranslation(0, 1, 3);
    rootNode.attachChild(box);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) AmbientLight(com.jme3.light.AmbientLight)

Example 28 with AL

use of com.jme3.audio.openal.AL in project jmonkeyengine by jMonkeyEngine.

the class TestPostWater method simpleInitApp.

@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1f));
    mainScene.addLight(sun);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
    mainScene.addLight(al);
    flyCam.setMoveSpeed(50);
    //cam.setLocation(new Vector3f(-700, 100, 300));
    //cam.setRotation(new Quaternion().fromAngleAxis(0.5f, Vector3f.UNIT_Z));
    //        cam.setLocation(new Vector3f(-327.21957f, 61.6459f, 126.884346f));
    //        cam.setRotation(new Quaternion(0.052168474f, 0.9443102f, -0.18395276f, 0.2678024f));
    cam.setLocation(new Vector3f(-370.31592f, 182.04016f, 196.81192f));
    cam.setRotation(new Quaternion(0.015302252f, 0.9304095f, -0.039101653f, 0.3641086f));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    cam.setFrustumFar(4000);
    //Water Filter
    water = new WaterFilter(rootNode, lightDir);
    water.setWaterColor(new ColorRGBA().setAsSrgb(0.0078f, 0.3176f, 0.5f, 1.0f));
    water.setDeepWaterColor(new ColorRGBA().setAsSrgb(0.0039f, 0.00196f, 0.145f, 1.0f));
    water.setUnderWaterFogDistance(80);
    water.setWaterTransparency(0.12f);
    water.setFoamIntensity(0.4f);
    water.setFoamHardness(0.3f);
    water.setFoamExistence(new Vector3f(0.8f, 8f, 1f));
    water.setReflectionDisplace(50);
    water.setRefractionConstant(0.25f);
    water.setColorExtinction(new Vector3f(30, 50, 70));
    water.setCausticsIntensity(0.4f);
    water.setWaveScale(0.003f);
    water.setMaxAmplitude(2f);
    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
    water.setRefractionStrength(0.2f);
    water.setWaterHeight(initialWaterHeight);
    //Bloom Filter
    BloomFilter bloom = new BloomFilter();
    bloom.setExposurePower(55);
    bloom.setBloomIntensity(1.0f);
    //Light Scattering Filter
    LightScatteringFilter lsf = new LightScatteringFilter(lightDir.mult(-300));
    lsf.setLightDensity(0.5f);
    //Depth of field Filter
    DepthOfFieldFilter dof = new DepthOfFieldFilter();
    dof.setFocusDistance(0);
    dof.setFocusRange(100);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(water);
    fpp.addFilter(bloom);
    fpp.addFilter(dof);
    fpp.addFilter(lsf);
    fpp.addFilter(new FXAAFilter());
    //      fpp.addFilter(new TranslucentBucketFilter());
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    uw = cam.getLocation().y < waterHeight;
    waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
    waves.setLooping(true);
    waves.setReverbEnabled(true);
    if (uw) {
        waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
    } else {
        waves.setDryFilter(aboveWaterAudioFilter);
    }
    audioRenderer.playSource(waves);
    //  
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("foam1")) {
                    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg"));
                }
                if (name.equals("foam2")) {
                    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
                }
                if (name.equals("foam3")) {
                    water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam3.jpg"));
                }
                if (name.equals("upRM")) {
                    water.setReflectionMapSize(Math.min(water.getReflectionMapSize() * 2, 4096));
                    System.out.println("Reflection map size : " + water.getReflectionMapSize());
                }
                if (name.equals("downRM")) {
                    water.setReflectionMapSize(Math.max(water.getReflectionMapSize() / 2, 32));
                    System.out.println("Reflection map size : " + water.getReflectionMapSize());
                }
            }
        }
    }, "foam1", "foam2", "foam3", "upRM", "downRM");
    inputManager.addMapping("foam1", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("foam2", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("foam3", new KeyTrigger(KeyInput.KEY_3));
    inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
    inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
//        createBox();
//        createFire();
}
Also used : FXAAFilter(com.jme3.post.filters.FXAAFilter) Texture2D(com.jme3.texture.Texture2D) LightScatteringFilter(com.jme3.post.filters.LightScatteringFilter) LowPassFilter(com.jme3.audio.LowPassFilter) Quaternion(com.jme3.math.Quaternion) AudioNode(com.jme3.audio.AudioNode) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ColorRGBA(com.jme3.math.ColorRGBA) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WaterFilter(com.jme3.water.WaterFilter) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) AmbientLight(com.jme3.light.AmbientLight) AudioNode(com.jme3.audio.AudioNode)

Example 29 with AL

use of com.jme3.audio.openal.AL 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)

Example 30 with AL

use of com.jme3.audio.openal.AL in project jmonkeyengine by jMonkeyEngine.

the class TestTransparentSSAO method simpleInitApp.

public void simpleInitApp() {
    renderManager.setAlphaToCoverage(true);
    cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f));
    cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f));
    //        cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f));
    //        cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f, -0.13857932f));
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    Quad q = new Quad(20, 20);
    q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5));
    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.Receive);
    TangentBinormalGenerator.generate(geom);
    rootNode.attachChild(geom);
    // create the geometry and attach it
    Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    teaGeom.setQueueBucket(Bucket.Transparent);
    teaGeom.setShadowMode(ShadowMode.Cast);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(al);
    DirectionalLight dl1 = new DirectionalLight();
    dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal());
    dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl1);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //0.49997783f, 42.598858f, 35.999966f, 0.39299846f
    SSAOFilter ssao = new SSAOFilter();
    fpp.addFilter(ssao);
    SSAOUI ui = new SSAOUI(inputManager, ssao);
    viewPort.addProcessor(fpp);
}
Also used : Geometry(com.jme3.scene.Geometry) SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quad(com.jme3.scene.shape.Quad) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

AmbientLight (com.jme3.light.AmbientLight)26 DirectionalLight (com.jme3.light.DirectionalLight)19 Vector3f (com.jme3.math.Vector3f)19 Geometry (com.jme3.scene.Geometry)18 Material (com.jme3.material.Material)12 Spatial (com.jme3.scene.Spatial)12 Node (com.jme3.scene.Node)10 Box (com.jme3.scene.shape.Box)10 Sphere (com.jme3.scene.shape.Sphere)9 KeyTrigger (com.jme3.input.controls.KeyTrigger)8 Quaternion (com.jme3.math.Quaternion)8 FilterPostProcessor (com.jme3.post.FilterPostProcessor)8 ActionListener (com.jme3.input.controls.ActionListener)7 ColorRGBA (com.jme3.math.ColorRGBA)7 SpotLight (com.jme3.light.SpotLight)5 Vector2f (com.jme3.math.Vector2f)5 Texture (com.jme3.texture.Texture)5 AL (com.jme3.audio.openal.AL)3 ALAudioRenderer (com.jme3.audio.openal.ALAudioRenderer)3 ALC (com.jme3.audio.openal.ALC)3