Search in sources :

Example 81 with Image

use of com.jme3.texture.Image 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 82 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class TestTextureArrayCompressed method simpleInitApp.

@Override
public void simpleInitApp() {
    Material mat = new Material(assetManager, "jme3test/texture/UnshadedArray.j3md");
    for (Caps caps : renderManager.getRenderer().getCaps()) {
        System.out.println(caps.name());
    }
    if (!renderManager.getRenderer().getCaps().contains(Caps.TextureArray)) {
        throw new UnsupportedOperationException("Your hardware does not support TextureArray");
    }
    Texture tex1 = assetManager.loadTexture("Textures/Terrain/Pond/Pond.dds");
    Texture tex2 = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.dds");
    List<Image> images = new ArrayList<Image>();
    images.add(tex1.getImage());
    images.add(tex2.getImage());
    TextureArray tex3 = new TextureArray(images);
    tex3.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex3);
    Mesh m = new Mesh();
    Vector3f[] vertices = new Vector3f[8];
    vertices[0] = new Vector3f(0, 0, 0);
    vertices[1] = new Vector3f(3, 0, 0);
    vertices[2] = new Vector3f(0, 3, 0);
    vertices[3] = new Vector3f(3, 3, 0);
    vertices[4] = new Vector3f(3, 0, 0);
    vertices[5] = new Vector3f(6, 0, 0);
    vertices[6] = new Vector3f(3, 3, 0);
    vertices[7] = new Vector3f(6, 3, 0);
    Vector3f[] texCoord = new Vector3f[8];
    texCoord[0] = new Vector3f(0, 0, 0);
    texCoord[1] = new Vector3f(1, 0, 0);
    texCoord[2] = new Vector3f(0, 1, 0);
    texCoord[3] = new Vector3f(1, 1, 0);
    texCoord[4] = new Vector3f(0, 0, 1);
    texCoord[5] = new Vector3f(1, 0, 1);
    texCoord[6] = new Vector3f(0, 1, 1);
    texCoord[7] = new Vector3f(1, 1, 1);
    int[] indexes = { 2, 0, 1, 1, 3, 2, 6, 4, 5, 5, 7, 6 };
    m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
    m.setBuffer(Type.TexCoord, 3, BufferUtils.createFloatBuffer(texCoord));
    m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
    m.updateBound();
    Geometry geom = new Geometry("Mesh", m);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
Also used : ArrayList(java.util.ArrayList) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) Image(com.jme3.texture.Image) Texture(com.jme3.texture.Texture) Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f) TextureArray(com.jme3.texture.TextureArray) Caps(com.jme3.renderer.Caps)

Example 83 with Image

use of com.jme3.texture.Image 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 84 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestAdvanced method simpleInitApp.

@Override
public void simpleInitApp() {
    setupKeys();
    // 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.setFloat("Shininess", 0.0f);
    // 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"));
    // this material also supports 'AlphaMap_2', so you can get up to 12 diffuse textures
    // HEIGHTMAP image (for the terrain heightmap)
    TextureKey hmKey = new TextureKey("Textures/Terrain/splat/mountains512.png", false);
    Texture heightMapImage = assetManager.loadTexture(hmKey);
    // DIRT texture, Diffuse textures 0 to 3 use the first AlphaMap
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap", dirt);
    matTerrain.setFloat("DiffuseMap_0_scale", dirtScale);
    // DARK ROCK texture
    Texture darkRock = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
    darkRock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_1", darkRock);
    matTerrain.setFloat("DiffuseMap_1_scale", darkRockScale);
    // PINK ROCK texture
    Texture pinkRock = assetManager.loadTexture("Textures/Terrain/Rock/Rock.PNG");
    pinkRock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_2", pinkRock);
    matTerrain.setFloat("DiffuseMap_2_scale", pinkRockScale);
    // RIVER ROCK texture, this texture will use the next alphaMap: AlphaMap_1
    Texture riverRock = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
    riverRock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_3", riverRock);
    matTerrain.setFloat("DiffuseMap_3_scale", riverRockScale);
    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_4", grass);
    matTerrain.setFloat("DiffuseMap_4_scale", grassScale);
    // BRICK texture
    Texture brick = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg");
    brick.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_5", brick);
    matTerrain.setFloat("DiffuseMap_5_scale", brickScale);
    // ROAD texture
    Texture road = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    road.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("DiffuseMap_6", road);
    matTerrain.setFloat("DiffuseMap_6_scale", roadScale);
    // diffuse textures 0 to 3 use AlphaMap
    // diffuse textures 4 to 7 use AlphaMap_1
    // diffuse textures 8 to 11 use AlphaMap_2
    // NORMAL MAPS
    Texture normalMapDirt = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMapDirt.setWrap(WrapMode.Repeat);
    Texture normalMapPinkRock = assetManager.loadTexture("Textures/Terrain/Rock/Rock_normal.png");
    normalMapPinkRock.setWrap(WrapMode.Repeat);
    Texture normalMapGrass = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMapGrass.setWrap(WrapMode.Repeat);
    Texture normalMapRoad = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMapRoad.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("NormalMap", normalMapDirt);
    matTerrain.setTexture("NormalMap_1", normalMapPinkRock);
    matTerrain.setTexture("NormalMap_2", normalMapPinkRock);
    matTerrain.setTexture("NormalMap_4", normalMapGrass);
    matTerrain.setTexture("NormalMap_6", normalMapRoad);
    // WIREFRAME material (used to debug the terrain, only useful for this test case)
    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 ImageBasedHeightMap(heightMapImage.getImage(), 0.3f);
        heightmap.load();
        heightmap.smooth(0.9f, 1);
    } 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...
         */
    //, 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());
    // patch size, and a multiplier
    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);
    //Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    //terrain.generateDebugTangents(debugMat);
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.1f, -0.1f, -0.1f)).normalize());
    rootNode.addLight(light);
    cam.setLocation(new Vector3f(0, 10, -10));
    cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
    flyCam.setMoveSpeed(400);
    rootNode.attachChild(createAxisMarker(20));
}
Also used : TextureKey(com.jme3.asset.TextureKey) AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) BoundingBox(com.jme3.bounding.BoundingBox) 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 85 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class TestAnisotropicFilter method createCheckerBoardTexture.

private static Texture2D createCheckerBoardTexture() {
    Image image = new Image(Format.RGBA8, 1024, 1024, BufferUtils.createByteBuffer(1024 * 1024 * 4), ColorSpace.sRGB);
    ImageRaster raster = ImageRaster.create(image);
    for (int y = 0; y < 1024; y++) {
        for (int x = 0; x < 1024; x++) {
            if (y < 512) {
                if (x < 512) {
                    raster.setPixel(x, y, ColorRGBA.Black);
                } else {
                    raster.setPixel(x, y, ColorRGBA.White);
                }
            } else {
                if (x < 512) {
                    raster.setPixel(x, y, ColorRGBA.White);
                } else {
                    raster.setPixel(x, y, ColorRGBA.Black);
                }
            }
        }
    }
    return new Texture2D(image);
}
Also used : Texture2D(com.jme3.texture.Texture2D) ImageRaster(com.jme3.texture.image.ImageRaster) Image(com.jme3.texture.Image)

Aggregations

Image (com.jme3.texture.Image)68 ByteBuffer (java.nio.ByteBuffer)38 Texture (com.jme3.texture.Texture)27 Texture2D (com.jme3.texture.Texture2D)19 ArrayList (java.util.ArrayList)19 Material (com.jme3.material.Material)18 TextureKey (com.jme3.asset.TextureKey)17 Vector3f (com.jme3.math.Vector3f)17 Format (com.jme3.texture.Image.Format)15 TextureCubeMap (com.jme3.texture.TextureCubeMap)14 ColorRGBA (com.jme3.math.ColorRGBA)13 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)12 BufferedImage (java.awt.image.BufferedImage)12 Geometry (com.jme3.scene.Geometry)10 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)7 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)7 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)7 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)7