Home | History | Annotate | Download | only in texture
      1 package jme3test.texture;
      2 
      3 
      4 import com.jme3.app.SimpleApplication;
      5 import com.jme3.material.Material;
      6 import com.jme3.math.Vector3f;
      7 import com.jme3.renderer.Caps;
      8 import com.jme3.scene.Geometry;
      9 import com.jme3.scene.Mesh;
     10 import com.jme3.scene.VertexBuffer.Type;
     11 import com.jme3.texture.Image;
     12 import com.jme3.texture.Texture;
     13 import com.jme3.texture.TextureArray;
     14 import com.jme3.util.BufferUtils;
     15 import java.util.ArrayList;
     16 import java.util.List;
     17 
     18 public class TestTextureArray extends SimpleApplication
     19 {
     20 
     21    @Override
     22    public void simpleInitApp()
     23    {
     24        Material mat = new Material(assetManager, "jme3test/texture/UnshadedArray.j3md");
     25 
     26        for (Caps caps : renderManager.getRenderer().getCaps()) {
     27            System.out.println(caps.name());
     28        }
     29        if(!renderManager.getRenderer().getCaps().contains(Caps.TextureArray)){
     30            throw new UnsupportedOperationException("Your hardware does not support TextureArray");
     31        }
     32 
     33 
     34        Texture tex1 = assetManager.loadTexture( "Textures/Terrain/Pond/Pond.jpg");
     35        Texture tex2 = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
     36        List<Image> images = new ArrayList<Image>();
     37        images.add(tex1.getImage());
     38        images.add(tex2.getImage());
     39        TextureArray tex3 = new TextureArray(images);
     40        mat.setTexture("ColorMap", tex3);
     41 
     42        Mesh m = new Mesh();
     43        Vector3f[] vertices = new Vector3f[8];
     44        vertices[0] = new Vector3f(0, 0, 0);
     45        vertices[1] = new Vector3f(3, 0, 0);
     46        vertices[2] = new Vector3f(0, 3, 0);
     47        vertices[3] = new Vector3f(3, 3, 0);
     48 
     49        vertices[4] = new Vector3f(3, 0, 0);
     50        vertices[5] = new Vector3f(6, 0, 0);
     51        vertices[6] = new Vector3f(3, 3, 0);
     52        vertices[7] = new Vector3f(6, 3, 0);
     53 
     54        Vector3f[] texCoord = new Vector3f[8];
     55        texCoord[0] = new Vector3f(0, 0, 0);
     56        texCoord[1] = new Vector3f(1, 0, 0);
     57        texCoord[2] = new Vector3f(0, 1, 0);
     58        texCoord[3] = new Vector3f(1, 1, 0);
     59 
     60        texCoord[4] = new Vector3f(0, 0, 1);
     61        texCoord[5] = new Vector3f(1, 0, 1);
     62        texCoord[6] = new Vector3f(0, 1, 1);
     63        texCoord[7] = new Vector3f(1, 1, 1);
     64 
     65        int[] indexes = { 2, 0, 1, 1, 3, 2 , 6, 4, 5, 5, 7, 6};
     66 
     67        m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
     68        m.setBuffer(Type.TexCoord, 3, BufferUtils.createFloatBuffer(texCoord));
     69        m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
     70        m.updateBound();
     71 
     72        Geometry geom = new Geometry("Mesh", m);
     73        geom.setMaterial(mat);
     74        rootNode.attachChild(geom);
     75    }
     76 
     77    /**
     78     * @param args
     79     */
     80    public static void main(String[] args)
     81    {
     82        TestTextureArray app = new TestTextureArray();
     83        app.start();
     84    }
     85 
     86 }