Search in sources :

Example 71 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestModifyHeight method createTerrain.

private void createTerrain() {
    // First, we load up our textures and the heightmap texture for the terrain
    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    matTerrain.setFloat("Shininess", 0);
    // ALPHA map (for splat textures)
    matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.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);
    // HEIGHTMAP image (for the terrain heightmap)
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f);
        heightmap.load();
        heightmap.smooth(0.9f, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // CREATE THE TERRAIN
    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(matTerrain);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(2.5f, 0.5f, 2.5f);
    rootNode.attachChild(terrain);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) 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 72 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestModifyHeight method createTerrainGrid.

private void createTerrainGrid() {
    // TERRAIN TEXTURE material
    matTerrain = new Material(this.assetManager, "Common/MatDefs/Terrain/HeightBasedTerrain.j3md");
    // Parameters to material:
    // regionXColorMap: X = 1..4 the texture that should be appliad to state X
    // regionX: a Vector3f containing the following information:
    //      regionX.x: the start height of the region
    //      regionX.y: the end height of the region
    //      regionX.z: the texture scale for the region
    //  it might not be the most elegant way for storing these 3 values, but it packs the data nicely :)
    // slopeColorMap: the texture to be used for cliffs, and steep mountain sites
    // slopeTileFactor: the texture scale for slopes
    // terrainSize: the total size of the terrain (used for scaling the texture)
    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("region1ColorMap", grass);
    matTerrain.setVector3("region1", new Vector3f(88, 200, this.grassScale));
    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("region2ColorMap", dirt);
    matTerrain.setVector3("region2", new Vector3f(0, 90, this.dirtScale));
    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
    rock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("region3ColorMap", rock);
    matTerrain.setVector3("region3", new Vector3f(198, 260, this.rockScale));
    matTerrain.setTexture("region4ColorMap", rock);
    matTerrain.setVector3("region4", new Vector3f(198, 260, this.rockScale));
    matTerrain.setTexture("slopeColorMap", rock);
    matTerrain.setFloat("slopeTileFactor", 32);
    matTerrain.setFloat("terrainSize", 513);
    FractalSum base = new FractalSum();
    base.setRoughness(0.7f);
    base.setFrequency(1.0f);
    base.setAmplitude(1.0f);
    base.setLacunarity(2.12f);
    base.setOctaves(8);
    base.setScale(0.02125f);
    base.addModulator(new NoiseModulator() {

        @Override
        public float value(float... in) {
            return ShaderUtils.clamp(in[0] * 0.5f + 0.5f, 0, 1);
        }
    });
    FilteredBasis ground = new FilteredBasis(base);
    PerturbFilter perturb = new PerturbFilter();
    perturb.setMagnitude(0.119f);
    OptimizedErode therm = new OptimizedErode();
    therm.setRadius(5);
    therm.setTalus(0.011f);
    SmoothFilter smooth = new SmoothFilter();
    smooth.setRadius(1);
    smooth.setEffect(0.7f);
    IterativeFilter iterate = new IterativeFilter();
    iterate.addPreFilter(perturb);
    iterate.addPostFilter(smooth);
    iterate.setFilter(therm);
    iterate.setIterations(1);
    ground.addPreFilter(iterate);
    this.terrain = new TerrainGrid("terrain", 65, 257, new FractalTileLoader(ground, 256f));
    terrain.setMaterial(matTerrain);
    terrain.setLocalTranslation(0, 0, 0);
    terrain.setLocalScale(2f, 1f, 2f);
    rootNode.attachChild(this.terrain);
    TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());
    this.terrain.addControl(control);
}
Also used : FractalTileLoader(com.jme3.terrain.geomipmap.grid.FractalTileLoader) PerturbFilter(com.jme3.terrain.noise.filter.PerturbFilter) FilteredBasis(com.jme3.terrain.noise.basis.FilteredBasis) TerrainGrid(com.jme3.terrain.geomipmap.TerrainGrid) IterativeFilter(com.jme3.terrain.noise.filter.IterativeFilter) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) OptimizedErode(com.jme3.terrain.noise.filter.OptimizedErode) NoiseModulator(com.jme3.terrain.noise.modulator.NoiseModulator) Vector3f(com.jme3.math.Vector3f) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) SmoothFilter(com.jme3.terrain.noise.filter.SmoothFilter) FractalSum(com.jme3.terrain.noise.fractal.FractalSum)

Example 73 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestSceneStress method createOctSplit.

protected Spatial createOctSplit(String name, int size, int depth) {
    if (depth == 0) {
        // Done splitting
        Geometry geom = new Geometry(name, BOX);
        totalGeometry++;
        geom.setMaterial(mat);
        if (random.nextFloat() < 0.01) {
            RotatorControl control = new RotatorControl(random.nextFloat(), random.nextFloat(), random.nextFloat());
            geom.addControl(control);
            totalControls++;
        }
        return geom;
    }
    Node root = new Node(name);
    totalNodes++;
    int half = size / 2;
    float quarter = half * 0.5f;
    for (int i = 0; i < 2; i++) {
        float x = i * half - quarter;
        for (int j = 0; j < 2; j++) {
            float y = j * half - quarter;
            for (int k = 0; k < 2; k++) {
                float z = k * half - quarter;
                Spatial child = createOctSplit(name + "(" + i + ", " + j + ", " + k + ")", half, depth - 1);
                child.setLocalTranslation(x, y, z);
                root.attachChild(child);
            }
        }
    }
    return root;
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 74 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestBatchLod method simpleInitApp.

public void simpleInitApp() {
    //        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
    Geometry teapot = (Geometry) teapotNode.getChild(0);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 16f);
    mat.setBoolean("VertexLighting", true);
    teapot.setMaterial(mat);
    // show normals as material
    //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    flyCam.setMoveSpeed(5);
    for (int y = -5; y < 5; y++) {
        for (int x = -5; x < 5; x++) {
            Geometry clonePot = teapot.clone();
            //clonePot.setMaterial(mat);
            clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
            clonePot.setLocalScale(.15f);
            clonePot.setMaterial(mat);
            rootNode.attachChild(clonePot);
        }
    }
    GeometryBatchFactory.optimize(rootNode, true);
    LodControl control = new LodControl();
    rootNode.getChild(0).addControl(control);
    cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
    cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));
}
Also used : Geometry(com.jme3.scene.Geometry) LodControl(com.jme3.scene.control.LodControl) Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 75 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestLodStress method simpleInitApp.

public void simpleInitApp() {
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
    Geometry teapot = (Geometry) teapotNode.getChild(0);
    //        Sphere sph = new Sphere(16, 16, 4);
    //        Geometry teapot = new Geometry("teapot", sph);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 16f);
    mat.setBoolean("VertexLighting", true);
    teapot.setMaterial(mat);
    for (int y = -10; y < 10; y++) {
        for (int x = -10; x < 10; x++) {
            Geometry clonePot = teapot.clone();
            //clonePot.setMaterial(mat);
            clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
            clonePot.setLocalScale(.15f);
            LodControl control = new LodControl();
            clonePot.addControl(control);
            rootNode.attachChild(clonePot);
        }
    }
    cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
    cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
}
Also used : Geometry(com.jme3.scene.Geometry) LodControl(com.jme3.scene.control.LodControl) Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Aggregations

Vector3f (com.jme3.math.Vector3f)51 DirectionalLight (com.jme3.light.DirectionalLight)24 Material (com.jme3.material.Material)23 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)19 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)18 Texture (com.jme3.texture.Texture)16 AnimControl (com.jme3.animation.AnimControl)15 ColorRGBA (com.jme3.math.ColorRGBA)15 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)15 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)14 Geometry (com.jme3.scene.Geometry)14 Spatial (com.jme3.scene.Spatial)13 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 BulletAppState (com.jme3.bullet.BulletAppState)12 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)11 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)11 ArrayList (java.util.ArrayList)10 Box (com.jme3.scene.shape.Box)7 Animation (com.jme3.animation.Animation)5