Search in sources :

Example 36 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestMousePick method makeCharacter.

protected Spatial makeCharacter() {
    // load a character from jme3test-test-data
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);
    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    return golem;
}
Also used : Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 37 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method endElement.

@Override
public void endElement(String uri, String name, String qName) throws SAXException {
    if (qName.equals("node")) {
        node = node.getParent();
    } else if (qName.equals("nodes")) {
        node = null;
    } else if (qName.equals("entity")) {
        node = entityNode.getParent();
        entityNode = null;
    } else if (qName.equals("camera")) {
        node = cameraNode.getParent();
        cameraNode = null;
    } else if (qName.equals("light")) {
        // apply the node's world transform on the light..
        root.updateGeometricState();
        if (light != null) {
            if (light instanceof DirectionalLight) {
                DirectionalLight dl = (DirectionalLight) light;
                Quaternion q = node.getWorldRotation();
                Vector3f dir = dl.getDirection();
                q.multLocal(dir);
                dl.setDirection(dir);
            } else if (light instanceof PointLight) {
                PointLight pl = (PointLight) light;
                Vector3f pos = node.getWorldTranslation();
                pl.setPosition(pos);
            } else if (light instanceof SpotLight) {
                SpotLight sl = (SpotLight) light;
                Vector3f pos = node.getWorldTranslation();
                sl.setPosition(pos);
                Quaternion q = node.getWorldRotation();
                Vector3f dir = sl.getDirection();
                q.multLocal(dir);
                sl.setDirection(dir);
            }
        }
        light = null;
    }
    checkTopNode(qName);
    elementStack.pop();
}
Also used : Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight)

Example 38 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class LightFilterTest method testDirectionalFiltering.

@Test
public void testDirectionalFiltering() {
    geom.addLight(new DirectionalLight(Vector3f.UNIT_Y));
    // Directional lights must never be filtered
    checkFilteredLights(1);
    // Test for bounding Sphere
    geom.setModelBound(new BoundingSphere(0.5f, Vector3f.ZERO));
    // Directional lights must never be filtered
    checkFilteredLights(1);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Test(org.junit.Test)

Example 39 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class LightSortTest method testSceneGraphSort.

@Test
public void testSceneGraphSort() {
    Node n = new Node("node");
    Geometry g = new Geometry("geom", new Mesh());
    SpotLight spot = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X);
    PointLight point = new PointLight(Vector3f.UNIT_X);
    DirectionalLight directional = new DirectionalLight(Vector3f.UNIT_X);
    AmbientLight ambient = new AmbientLight();
    // Some lights are on the node
    n.addLight(spot);
    n.addLight(point);
    // .. and some on the geometry.
    g.addLight(directional);
    g.addLight(ambient);
    n.attachChild(g);
    n.updateGeometricState();
    LightList list = g.getWorldLightList();
    // check the sorting (when geom is at 0,0,0)
    assert list.get(0) instanceof AmbientLight;
    assert list.get(1) instanceof DirectionalLight;
    assert list.get(2) instanceof SpotLight;
    assert list.get(3) instanceof PointLight;
    // move the geometry closer to the point light
    g.setLocalTranslation(Vector3f.UNIT_X);
    n.updateGeometricState();
    assert list.get(0) instanceof AmbientLight;
    assert list.get(1) instanceof DirectionalLight;
    assert list.get(2) instanceof PointLight;
    assert list.get(3) instanceof SpotLight;
// now move the point light away from the geometry
// and the spot light closer
// XXX: doesn't work! jME can't detect that the light moved!
//        point.setPosition(Vector3f.ZERO);
//        spot.setPosition(Vector3f.UNIT_X);
//        n.updateGeometricState();
//        
//        assert list.get(0) instanceof AmbientLight;
//        assert list.get(1) instanceof DirectionalLight;
//        assert list.get(2) instanceof SpotLight;
//        assert list.get(3) instanceof PointLight;
}
Also used : Geometry(com.jme3.scene.Geometry) Node(com.jme3.scene.Node) Mesh(com.jme3.scene.Mesh) Test(org.junit.Test)

Example 40 with DirectionalLight

use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.

the class TestDepthOfField method simpleInitApp.

@Override
public void simpleInitApp() {
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
    mainScene.addLight(sun);
    DirectionalLight l = new DirectionalLight();
    l.setDirection(Vector3f.UNIT_Y.mult(-1));
    l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
    mainScene.addLight(l);
    flyCam.setMoveSpeed(50);
    cam.setFrustumFar(3000);
    cam.setLocation(new Vector3f(-700, 100, 300));
    cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    //     fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    dofFilter = new DepthOfFieldFilter();
    dofFilter.setFocusDistance(0);
    dofFilter.setFocusRange(50);
    dofFilter.setBlurScale(1.4f);
    fpp.addFilter(dofFilter);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("toggle")) {
                    dofFilter.setEnabled(!dofFilter.isEnabled());
                }
            }
        }
    }, "toggle");
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("blurScaleUp")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() + 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("blurScaleDown")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() - 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("focusRangeUp")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() + 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusRangeDown")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() - 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusDistanceUp")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() + 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
            if (name.equals("focusDistanceDown")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() - 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
        }
    }, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown");
    inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE));
    inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U));
    inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J));
    inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I));
    inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K));
    inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O));
    inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L));
}
Also used : Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) AnalogListener(com.jme3.input.controls.AnalogListener)

Aggregations

DirectionalLight (com.jme3.light.DirectionalLight)109 Vector3f (com.jme3.math.Vector3f)90 Geometry (com.jme3.scene.Geometry)55 Material (com.jme3.material.Material)48 Spatial (com.jme3.scene.Spatial)42 ColorRGBA (com.jme3.math.ColorRGBA)36 Node (com.jme3.scene.Node)32 Quaternion (com.jme3.math.Quaternion)30 Box (com.jme3.scene.shape.Box)27 AmbientLight (com.jme3.light.AmbientLight)26 FilterPostProcessor (com.jme3.post.FilterPostProcessor)26 Sphere (com.jme3.scene.shape.Sphere)26 PointLight (com.jme3.light.PointLight)24 KeyTrigger (com.jme3.input.controls.KeyTrigger)23 ActionListener (com.jme3.input.controls.ActionListener)14 SpotLight (com.jme3.light.SpotLight)14 Texture (com.jme3.texture.Texture)12 AnimControl (com.jme3.animation.AnimControl)9 BulletAppState (com.jme3.bullet.BulletAppState)8 Quad (com.jme3.scene.shape.Quad)8