Search in sources :

Example 1 with DirectionalLight

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

the class TerrainTest method simpleInitApp.

@Override
public void simpleInitApp() {
    setupKeys();
    // First, we load up our textures and the heightmap texture for the terrain
    // TERRAIN TEXTURE material
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    // ALPHA map (for splat textures)
    matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    // HEIGHTMAP image (for the terrain heightmap)
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex1", grass);
    matRock.setFloat("Tex1Scale", grassScale);
    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex2", dirt);
    matRock.setFloat("Tex2Scale", dirtScale);
    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex3", rock);
    matRock.setFloat("Tex3Scale", rockScale);
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    // CREATE HEIGHTMAP
    AbstractHeightMap heightmap = null;
    try {
        //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*
         * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
         * terrain will be 513x513. It uses the heightmap we created to generate the height values.
         */
    /**
         * Optimal terrain patch size is 65 (64x64).
         * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
         * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
         */
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(2f, 0.5f, 2f);
    rootNode.attachChild(terrain);
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
    cam.setLocation(new Vector3f(0, 10, -10));
    cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Example 2 with DirectionalLight

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

the class TerrainTestAndroid method simpleInitApp.

@Override
public void simpleInitApp() {
    setupKeys();
    // First, we load up our textures and the heightmap texture for the terrain
    // TERRAIN TEXTURE material
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    // ALPHA map (for splat textures)
    matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    // HEIGHTMAP image (for the terrain heightmap)
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains128.png");
    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex1", grass);
    matRock.setFloat("Tex1Scale", grassScale);
    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex2", dirt);
    matRock.setFloat("Tex2Scale", dirtScale);
    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex3", rock);
    matRock.setFloat("Tex3Scale", rockScale);
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    // CREATE HEIGHTMAP
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*
         * Here we create the actual terrain. The tiles will be 33x33, and the total size of the
         * terrain will be 129x129. It uses the heightmap we created to generate the height values.
         */
    terrain = new TerrainQuad("terrain", 33, 129, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(33, 2.7f));
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(8f, 0.5f, 8f);
    rootNode.attachChild(terrain);
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
    cam.setLocation(new Vector3f(0, 10, -10));
    cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Example 3 with DirectionalLight

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

the class TerrainTestTile method simpleInitApp.

@Override
public void simpleInitApp() {
    loadHintText();
    setupKeys();
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    terrain = new TiledTerrain();
    rootNode.attachChild(terrain);
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);
    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1, -1).normalizeLocal(), Vector3f.UNIT_Y);
    Sphere s = new Sphere(12, 12, 3);
    Geometry g = new Geometry("marker");
    g.setMesh(s);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Red);
    g.setMaterial(mat);
    g.setLocalTranslation(0, -100, 0);
    rootNode.attachChild(g);
    Geometry g2 = new Geometry("marker");
    g2.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g2.setMaterial(mat);
    g2.setLocalTranslation(10, -100, 0);
    rootNode.attachChild(g2);
    Geometry g3 = new Geometry("marker");
    g3.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g3.setMaterial(mat);
    g3.setLocalTranslation(0, -100, 10);
    rootNode.attachChild(g3);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) AmbientLight(com.jme3.light.AmbientLight)

Example 4 with DirectionalLight

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

the class TestBlendEquations method simpleInitApp.

public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(6);
    teaGeom.getMaterial().getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Add);
    teaGeom.move(0, -2f, 0);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.Red);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0.5f, 0f, 1f, 0.3f));
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Color);
    mat.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Subtract);
    Geometry geo = new Geometry("BottomLeft", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(mat);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(0, 0, 1);
    guiNode.attachChild(geo);
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.ReverseSubtract);
    m.setColor("Color", new ColorRGBA(0.0f, 1f, 1.f, 1f));
    m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.AlphaAdditive);
    geo = new Geometry("BottomRight", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(m);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(guiViewPort.getCamera().getWidth() / 2, 0, 1);
    guiNode.attachChild(geo);
    m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Min);
    m.setColor("Color", new ColorRGBA(0.3f, 0f, 0.1f, 0.3f));
    m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive);
    geo = new Geometry("TopRight", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(m);
    geo.setQueueBucket(RenderQueue.Bucket.Gui);
    geo.setLocalTranslation(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2, 1);
    guiNode.attachChild(geo);
    geo = new Geometry("OverTeaPot", new Quad(guiViewPort.getCamera().getWidth() / 2, guiViewPort.getCamera().getHeight() / 2));
    geo.setMaterial(mat);
    geo.setQueueBucket(RenderQueue.Bucket.Transparent);
    geo.setLocalTranslation(0, -100, 5);
    rootNode.attachChild(geo);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material)

Example 5 with DirectionalLight

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

the class TestParallelProjection method simpleInitApp.

public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);
    // Setup first view
    cam.setParallelProjection(true);
    float aspect = (float) cam.getWidth() / cam.getHeight();
    cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize);
    inputManager.addListener(this, "Size+", "Size-");
    inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S));
}
Also used : Geometry(com.jme3.scene.Geometry) DirectionalLight(com.jme3.light.DirectionalLight) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Aggregations

DirectionalLight (com.jme3.light.DirectionalLight)110 Vector3f (com.jme3.math.Vector3f)91 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)10 BulletAppState (com.jme3.bullet.BulletAppState)8 Quad (com.jme3.scene.shape.Quad)8