Search in sources :

Example 56 with Image

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

the class TestTexture3D method simpleInitApp.

@Override
public void simpleInitApp() {
    //mouseInput.setCursorVisible(true);
    flyCam.setMoveSpeed(10);
    //creating a sphere
    Sphere sphere = new Sphere(32, 32, 1);
    //getting the boundingbox
    sphere.updateBound();
    BoundingBox bb = (BoundingBox) sphere.getBound();
    Vector3f min = bb.getMin(null);
    float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
    //we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
    sphere.clearBuffer(Type.TexCoord);
    VertexBuffer vb = sphere.getBuffer(Type.Position);
    FloatBuffer fb = (FloatBuffer) vb.getData();
    float[] uvCoordinates = BufferUtils.getFloatArray(fb);
    //now transform the coordinates so that they are in the range of <0; 1>
    for (int i = 0; i < uvCoordinates.length; i += 3) {
        uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
        uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
        uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
    }
    //apply new texture coordinates
    VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
    uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates));
    sphere.setBuffer(uvCoordsBuffer);
    //create geometry, and apply material and our 3D texture
    Geometry g = new Geometry("sphere", sphere);
    Material material = new Material(assetManager, "jme3test/texture/tex3D.j3md");
    try {
        Texture texture = this.getTexture();
        material.setTexture("Texture", texture);
    } catch (IOException e) {
        e.printStackTrace();
    }
    g.setMaterial(material);
    rootNode.attachChild(g);
    //add some light so that it is visible
    PointLight light = new PointLight();
    light.setColor(ColorRGBA.White);
    light.setPosition(new Vector3f(5, 5, 5));
    light.setRadius(20);
    rootNode.addLight(light);
    light = new PointLight();
    light.setColor(ColorRGBA.White);
    light.setPosition(new Vector3f(-5, -5, -5));
    light.setRadius(20);
    rootNode.addLight(light);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) VertexBuffer(com.jme3.scene.VertexBuffer) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer) Material(com.jme3.material.Material) IOException(java.io.IOException) PointLight(com.jme3.light.PointLight) Texture(com.jme3.texture.Texture)

Example 57 with Image

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

the class TestTexture3DLoading method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setEnabled(false);
    Quad q = new Quad(10, 10);
    Geometry geom = new Geometry("Quad", q);
    Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
    TextureKey key = new TextureKey("Textures/3D/flame.dds");
    key.setGenerateMips(true);
    key.setTextureTypeHint(Texture.Type.ThreeDimensional);
    Texture t = assetManager.loadTexture(key);
    //4 * 4
    int rows = 4;
    q.scaleTextureCoordinates(new Vector2f(rows, rows));
    //The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
    material.setFloat("InvDepth", 1f / 16f);
    material.setInt("Rows", rows);
    material.setTexture("Texture", t);
    geom.setMaterial(material);
    rootNode.attachChild(geom);
    cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) TextureKey(com.jme3.asset.TextureKey) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 58 with Image

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

the class TestTextureArray 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.jpg");
    Texture tex2 = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
    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 59 with Image

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

the class TerrainTestReadWrite method createMap.

private void createMap() {
    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/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);
    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);
    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);
    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();
    }
    if (new File("terrainsave.jme").exists()) {
        loadTerrain();
    } else {
        // create the terrain as normal, and give it a control for LOD management
        //, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
        TerrainQuad terrainQuad = new TerrainQuad("terrain", 65, 129, heightmap.getHeightMap());
        TerrainLodControl control = new TerrainLodControl(terrainQuad, getCamera());
        // patch size, and a multiplier
        control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
        terrainQuad.addControl(control);
        terrainQuad.setMaterial(matTerrain);
        terrainQuad.setLocalTranslation(0, -100, 0);
        terrainQuad.setLocalScale(4f, 0.25f, 4f);
        rootNode.attachChild(terrainQuad);
        this.terrain = terrainQuad;
    }
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
}
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 60 with Image

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

the class IosImageLoader method load.

public Object load(AssetInfo info) throws IOException {
    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    Image img = null;
    InputStream in = null;
    try {
        in = info.openStream();
        img = loadImageData(Format.RGBA8, flip, in);
    } finally {
        if (in != null) {
            in.close();
        }
    }
    return img;
}
Also used : TextureKey(com.jme3.asset.TextureKey) InputStream(java.io.InputStream) 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