TestTextureArray.java 2.7 KB

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