Search in sources :

Example 41 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestPssmShadow method loadScene.

public void loadScene() {
    obj = new Spatial[2];
    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.mult(0.5f));
    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]);
    for (int i = 0; i < 60; i++) {
        Spatial 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(-1, -1, -1));
    rootNode.addLight(l);
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.5f));
    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)

Example 42 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestShadowBug method makeFloor.

protected Geometry makeFloor() {
    Box box = new Box(220, .2f, 220);
    box.scaleTextureCoordinates(new Vector2f(10, 10));
    Geometry floor = new Geometry("the Floor", box);
    floor.setLocalTranslation(200, -9, 200);
    Material 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);
    floor.setMaterial(matGroundL);
    floor.setShadowMode(ShadowMode.CastAndReceive);
    return floor;
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 43 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestSpotLight method setupFloor.

public void setupFloor() {
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
    // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess", 3);
    //  mat.setBoolean("VertexLighting", true);
    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Example 44 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestSpotLightTerrain method makeTerrain.

private void makeTerrain() {
    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    // ALPHA map (for splat textures)
    matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alpha1.png"));
    matTerrain.setTexture("AlphaMap_1", assetManager.loadTexture("Textures/Terrain/splat/alpha2.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);
    matTerrain.setTexture("DiffuseMap", grass);
    matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_1", dirt);
    matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_2", rock);
    matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
    // BRICK texture
    Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
    brick.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_3", brick);
    matTerrain.setFloat("DiffuseMap_3_scale", rockScale);
    // RIVER ROCK texture
    Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
    riverRock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_4", riverRock);
    matTerrain.setFloat("DiffuseMap_4_scale", rockScale);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("NormalMap", normalMap0);
    matTerrain.setTexture("NormalMap_1", normalMap2);
    matTerrain.setTexture("NormalMap_2", normalMap2);
    matTerrain.setTexture("NormalMap_4", normalMap2);
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    createSky();
    // 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();
    }
    //, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
    terrain.addControl(control);
    terrain.setMaterial(matTerrain);
    terrain.setModelBound(new BoundingBox());
    terrain.updateModelBound();
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(1f, 1f, 1f);
    rootNode.attachChild(terrain);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) BoundingBox(com.jme3.bounding.BoundingBox) 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 45 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TestTangentCube method simpleInitApp.

@Override
public void simpleInitApp() {
    Box aBox = new Box(1, 1, 1);
    Geometry aGeometry = new Geometry("Box", aBox);
    TangentBinormalGenerator.generate(aBox);
    Material aMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    aMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    aMaterial.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_normal.jpg"));
    aMaterial.setBoolean("UseMaterialColors", false);
    aMaterial.setColor("Diffuse", ColorRGBA.White);
    aMaterial.setColor("Specular", ColorRGBA.White);
    aMaterial.setFloat("Shininess", 64f);
    aGeometry.setMaterial(aMaterial);
    // Rotate 45 degrees to see multiple faces
    aGeometry.rotate(FastMath.QUARTER_PI, FastMath.QUARTER_PI, 0.0f);
    rootNode.attachChild(aGeometry);
    /**
         * Must add a light to make the lit object visible!
         */
    PointLight aLight = new PointLight();
    aLight.setPosition(new Vector3f(0, 3, 3));
    aLight.setColor(ColorRGBA.Red);
    rootNode.addLight(aLight);
    //
    //        AmbientLight bLight = new AmbientLight();
    //        bLight.setColor(ColorRGBA.Gray);
    //        rootNode.addLight(bLight);
    ChaseCameraAppState chaser = new ChaseCameraAppState();
    chaser.setTarget(aGeometry);
    getStateManager().attach(chaser);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) PointLight(com.jme3.light.PointLight) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState)

Aggregations

Material (com.jme3.material.Material)54 Vector3f (com.jme3.math.Vector3f)43 Texture (com.jme3.texture.Texture)38 Geometry (com.jme3.scene.Geometry)32 DirectionalLight (com.jme3.light.DirectionalLight)23 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)21 Box (com.jme3.scene.shape.Box)20 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)17 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)15 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)15 AmbientLight (com.jme3.light.AmbientLight)14 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 Node (com.jme3.scene.Node)12 Sphere (com.jme3.scene.shape.Sphere)11 Vector2f (com.jme3.math.Vector2f)10 Spatial (com.jme3.scene.Spatial)10 ArrayList (java.util.ArrayList)10 TextureKey (com.jme3.asset.TextureKey)9 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)9 ColorRGBA (com.jme3.math.ColorRGBA)8