Advertisement
Guest User

Custom Mesh Hex Texturing

a guest
Jul 22nd, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. private void createTop(Float startX, Float startZ, Float startHeight, Float size) {
  2.         Mesh mesh = new Mesh();
  3.  
  4.         Float half = size / 2;
  5.  
  6.         Vector3f[] vertices = new Vector3f[7];        
  7.         vertices[0] = new Vector3f(startX, startHeight, startZ);
  8.         vertices[1] = new Vector3f(vertices[0].x - size, startHeight, vertices[0].z);
  9.         vertices[2] = new Vector3f(vertices[1].x + half, startHeight, vertices[0].z - size);
  10.         vertices[3] = new Vector3f(vertices[2].x + size, startHeight, vertices[2].z);
  11.         vertices[4] = new Vector3f(vertices[3].x + half, startHeight, vertices[3].z + size);
  12.         vertices[5] = new Vector3f(vertices[4].x - half, startHeight, vertices[4].z + size);
  13.         vertices[6] = new Vector3f(vertices[5].x - size, startHeight, vertices[5].z);
  14.        
  15.         int[] indexes = {
  16.             0,1,2, 2,3,0, 0,3,4, 4,5,0, 0,5,6, 6,1,0, // bottom
  17.             0,1,6, 6,5,0, 0,5,4, 4,3,0, 0,3,2, 2,1,0 // reverse bottom
  18.         };
  19.        
  20.         float[] normals = new float[21];        
  21.         normals = new float[] {
  22.             0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0
  23.         };
  24.        
  25.         Vector2f[] texCoord = new Vector2f[4];
  26.         texCoord[0] = new Vector2f(0, 0);
  27.         texCoord[1] = new Vector2f(0, 1);
  28.         texCoord[2] = new Vector2f(1, 0);
  29.         texCoord[3] = new Vector2f(1, 1);
  30.        
  31.         mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));        
  32.         mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
  33.         mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
  34.         mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));
  35.         mesh.updateBound();
  36.          
  37.         Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
  38.         mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture("Textures/Pond.jpg"));
  39.        
  40.         Geometry geo = new Geometry("MyMesh", mesh);      
  41.         geo.setMaterial(mat);
  42.         geo.setShadowMode(ShadowMode.Cast);
  43.  
  44.         app.getRootNode().attachChild(geo);
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement