Search in sources :

Example 1 with AmbientLight

use of com.jme3.light.AmbientLight 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 2 with AmbientLight

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

the class TestCustomAnim method simpleInitApp.

@Override
public void simpleInitApp() {
    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    Box box = new Box(1, 1, 1);
    VertexBuffer weightsHW = new VertexBuffer(Type.HWBoneWeight);
    VertexBuffer indicesHW = new VertexBuffer(Type.HWBoneIndex);
    indicesHW.setUsage(Usage.CpuOnly);
    weightsHW.setUsage(Usage.CpuOnly);
    box.setBuffer(weightsHW);
    box.setBuffer(indicesHW);
    // Setup bone weight buffer
    FloatBuffer weights = FloatBuffer.allocate(box.getVertexCount() * 4);
    VertexBuffer weightsBuf = new VertexBuffer(Type.BoneWeight);
    weightsBuf.setupData(Usage.CpuOnly, 4, Format.Float, weights);
    box.setBuffer(weightsBuf);
    // Setup bone index buffer
    ByteBuffer indices = ByteBuffer.allocate(box.getVertexCount() * 4);
    VertexBuffer indicesBuf = new VertexBuffer(Type.BoneIndex);
    indicesBuf.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indices);
    box.setBuffer(indicesBuf);
    // Create bind pose buffers
    box.generateBindPose(true);
    // Create skeleton
    bone = new Bone("root");
    bone.setBindTransforms(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ);
    bone.setUserControl(true);
    skeleton = new Skeleton(new Bone[] { bone });
    // Assign all verticies to bone 0 with weight 1
    for (int i = 0; i < box.getVertexCount() * 4; i += 4) {
        // assign vertex to bone index 0
        indices.array()[i + 0] = 0;
        indices.array()[i + 1] = 0;
        indices.array()[i + 2] = 0;
        indices.array()[i + 3] = 0;
        // set weight to 1 only for first entry
        weights.array()[i + 0] = 1;
        weights.array()[i + 1] = 0;
        weights.array()[i + 2] = 0;
        weights.array()[i + 3] = 0;
    }
    // Maximum number of weights per bone is 1
    box.setMaxNumWeights(1);
    // Create model
    Geometry geom = new Geometry("box", box);
    geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
    Node model = new Node("model");
    model.attachChild(geom);
    // Create skeleton control
    SkeletonControl skeletonControl = new SkeletonControl(skeleton);
    model.addControl(skeletonControl);
    rootNode.attachChild(model);
}
Also used : Geometry(com.jme3.scene.Geometry) VertexBuffer(com.jme3.scene.VertexBuffer) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) SkeletonControl(com.jme3.animation.SkeletonControl) Box(com.jme3.scene.shape.Box) FloatBuffer(java.nio.FloatBuffer) Skeleton(com.jme3.animation.Skeleton) Bone(com.jme3.animation.Bone) ByteBuffer(java.nio.ByteBuffer) AmbientLight(com.jme3.light.AmbientLight)

Example 3 with AmbientLight

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

the class TestTransparentCartoonEdge 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);
    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);
    makeToonish(teaGeom);
    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);
    CartoonEdgeFilter toon = new CartoonEdgeFilter();
    toon.setEdgeWidth(0.5f);
    toon.setEdgeIntensity(1.0f);
    toon.setNormalThreshold(0.8f);
    fpp.addFilter(toon);
    viewPort.addProcessor(fpp);
}
Also used : Geometry(com.jme3.scene.Geometry) 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) CartoonEdgeFilter(com.jme3.post.filters.CartoonEdgeFilter)

Example 4 with AmbientLight

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

the class TestConeVSFrustum method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    frustumCam = cam.clone();
    frustumCam.setFrustumFar(25);
    Vector3f[] points = new Vector3f[8];
    for (int i = 0; i < 8; i++) {
        points[i] = new Vector3f();
    }
    ShadowUtil.updateFrustumPoints2(frustumCam, points);
    WireFrustum frustumShape = new WireFrustum(points);
    Geometry frustum = new Geometry("frustum", frustumShape);
    frustum.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(frustum);
    rootNode.addLight(new DirectionalLight());
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.2f));
    rootNode.addLight(al);
    Grid grid = new Grid(50, 50, 5);
    Geometry gridGeom = new Geometry("grid", grid);
    gridGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    gridGeom.getMaterial().setColor("Color", ColorRGBA.Gray);
    rootNode.attachChild(gridGeom);
    gridGeom.setLocalTranslation(-125, -25, -125);
    //        flyCam.setMoveSpeed(30);
    //        flyCam.setDragToRotate(true);
    //        cam.setLocation(new Vector3f(56.182674f, 19.037334f, 7.093905f));
    //        cam.setRotation(new Quaternion(0.0816657f, -0.82228005f, 0.12213967f, 0.5497892f));
    spotLight = new SpotLight();
    spotLight.setSpotRange(25);
    spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange();
    Cylinder cylinder = new Cylinder(5, 16, 0, radius, spotLight.getSpotRange(), true, false);
    geom = new Geometry("light", cylinder);
    geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
    geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
    geom.getMaterial().setColor("Ambient", ColorRGBA.DarkGray);
    geom.getMaterial().setBoolean("UseMaterialColors", true);
    final LightNode ln = new LightNode("lb", spotLight);
    ln.attachChild(geom);
    geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    rootNode.attachChild(ln);
    //        ln.rotate(FastMath.QUARTER_PI, 0, 0);
    //      ln.setLocalTranslation(0, 0, -16);
    inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("shift", new KeyTrigger(KeyInput.KEY_LSHIFT), new KeyTrigger(KeyInput.KEY_RSHIFT));
    inputManager.addMapping("middleClick", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    final Node camTarget = new Node("CamTarget");
    rootNode.attachChild(camTarget);
    ChaseCameraAppState chaser = new ChaseCameraAppState();
    chaser.setTarget(camTarget);
    chaser.setMaxDistance(150);
    chaser.setDefaultDistance(70);
    chaser.setDefaultHorizontalRotation(FastMath.HALF_PI);
    chaser.setMinVerticalRotation(-FastMath.PI);
    chaser.setMaxVerticalRotation(FastMath.PI * 2);
    chaser.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    stateManager.attach(chaser);
    flyCam.setEnabled(false);
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            Spatial s = null;
            float mult = 1;
            if (moving) {
                s = ln;
            }
            if (panning) {
                s = camTarget;
                mult = -1;
            }
            if ((moving || panning) && s != null) {
                if (shift) {
                    if (name.equals("left")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(value, tmp));
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
                    }
                } else {
                    value *= MOVE_SPEED * mult;
                    if (name.equals("up")) {
                        tmp.set(cam.getUp()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("down")) {
                        tmp.set(cam.getUp()).multLocal(-value);
                        s.move(tmp);
                    }
                    if (name.equals("left")) {
                        tmp.set(cam.getLeft()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getLeft()).multLocal(-value);
                        s.move(tmp);
                    }
                }
            }
        }
    }, "up", "down", "left", "right");
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("click")) {
                if (isPressed) {
                    moving = true;
                } else {
                    moving = false;
                }
            }
            if (name.equals("middleClick")) {
                if (isPressed) {
                    panning = true;
                } else {
                    panning = false;
                }
            }
            if (name.equals("shift")) {
                if (isPressed) {
                    shift = true;
                } else {
                    shift = false;
                }
            }
        }
    }, "click", "middleClick", "shift");
    /**
         * An unshaded textured cube. // * Uses texture from jme3-test-data
         * library!
         */
    Box boxMesh = new Box(1f, 1f, 1f);
    boxGeo = new Geometry("A Textured Box", boxMesh);
    Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture monkeyTex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    boxMat.setTexture("ColorMap", monkeyTex);
    boxGeo.setMaterial(boxMat);
    //        rootNode.attachChild(boxGeo);
    //
    //boxGeo2 = boxGeo.clone();
    //rootNode.attachChild(boxGeo2); 
    System.err.println("light " + spotLight.getPosition());
}
Also used : Grid(com.jme3.scene.debug.Grid) KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) SpotLight(com.jme3.light.SpotLight) Texture(com.jme3.texture.Texture) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState) Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WireFrustum(com.jme3.scene.debug.WireFrustum) AnalogListener(com.jme3.input.controls.AnalogListener) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) AmbientLight(com.jme3.light.AmbientLight)

Example 5 with AmbientLight

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

the class TestDirectionalLightShadow method loadScene.

public void loadScene() {
    obj = new Spatial[2];
    // Setup first view
    mat = new Material[2];
    mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat[1].setBoolean("UseMaterialColors", true);
    mat[1].setColor("Ambient", ColorRGBA.White);
    mat[1].setColor("Diffuse", ColorRGBA.White.clone());
    obj[0] = new Geometry("sphere", new Sphere(30, 30, 2));
    obj[0].setShadowMode(ShadowMode.CastAndReceive);
    obj[1] = new Geometry("cube", new Box(1.0f, 1.0f, 1.0f));
    obj[1].setShadowMode(ShadowMode.CastAndReceive);
    TangentBinormalGenerator.generate(obj[1]);
    TangentBinormalGenerator.generate(obj[0]);
    Spatial t = obj[0].clone(false);
    t.setLocalScale(10f);
    t.setMaterial(mat[1]);
    rootNode.attachChild(t);
    t.setLocalTranslation(0, 25, 0);
    for (int i = 0; i < 60; i++) {
        t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false);
        t.setLocalScale(FastMath.nextRandomFloat() * 10f);
        t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]);
        rootNode.attachChild(t);
        t.setLocalTranslation(FastMath.nextRandomFloat() * 200f, FastMath.nextRandomFloat() * 30f + 20, 30f * (i + 2f));
    }
    Box b = new Box(1000, 2, 1000);
    b.scaleTextureCoordinates(new Vector2f(10, 10));
    ground = new Geometry("soil", b);
    ground.setLocalTranslation(0, 10, 550);
    matGroundU = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matGroundU.setColor("Color", ColorRGBA.Green);
    matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matGroundL.setTexture("DiffuseMap", grass);
    ground.setMaterial(matGroundL);
    ground.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(ground);
    l = new DirectionalLight();
    //l.setDirection(new Vector3f(0.5973172f, -0.16583486f, 0.7846725f).normalizeLocal());
    l.setDirection(new Vector3f(-1, -1, -1));
    rootNode.addLight(l);
    al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    rootNode.attachChild(sky);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Spatial(com.jme3.scene.Spatial) Vector2f(com.jme3.math.Vector2f) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

AmbientLight (com.jme3.light.AmbientLight)35 DirectionalLight (com.jme3.light.DirectionalLight)24 Vector3f (com.jme3.math.Vector3f)24 Geometry (com.jme3.scene.Geometry)24 Material (com.jme3.material.Material)16 Box (com.jme3.scene.shape.Box)13 Node (com.jme3.scene.Node)12 Spatial (com.jme3.scene.Spatial)12 Sphere (com.jme3.scene.shape.Sphere)12 ColorRGBA (com.jme3.math.ColorRGBA)11 Quaternion (com.jme3.math.Quaternion)9 SpotLight (com.jme3.light.SpotLight)8 ActionListener (com.jme3.input.controls.ActionListener)7 KeyTrigger (com.jme3.input.controls.KeyTrigger)7 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 PointLight (com.jme3.light.PointLight)6 Texture (com.jme3.texture.Texture)6 Vector2f (com.jme3.math.Vector2f)5 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 SSAOFilter (com.jme3.post.ssao.SSAOFilter)3