Advertisement
Guest User

VoxelBlockMesh

a guest
Apr 18th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package mygame.terrain;
  2.  
  3. import com.jme3.scene.Mesh;
  4. import com.jme3.scene.VertexBuffer;
  5. import com.jme3.util.BufferUtils;
  6.  
  7. public class VoxelBlockMesh extends Mesh {
  8.  
  9.   private static final short[] GEOMETRY_INDICES_DATA = {
  10.     2, 1, 0, 3, 2, 0, // back
  11.     6, 5, 4, 7, 6, 4, // right
  12.     10, 9, 8, 11, 10, 8, // front
  13.     14, 13, 12, 15, 14, 12, // left
  14.     18, 17, 16, 19, 18, 16, // top
  15.     22, 21, 20, 23, 22, 20 // bottom
  16.   };
  17.  
  18.   private static final float[] GEOMETRY_VERTICES_DATA = {
  19.     0, 0, -1, 1, 0, -1, 1, 1, -1, 0, 1, -1, // back
  20.     1, 0, -1, 1, 0, 0, 1, 1, 0, 1, 1, -1, // right
  21.     1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, // front
  22.     0, 0, 0, 0, 0, -1, 0, 1, -1, 0, 1, 0, // left
  23.     1, 1, -1, 1, 1, 0, 0, 1, 0, 0, 1, -1, // top
  24.     0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, -1 // bottom
  25.   };
  26.  
  27.   private static final float[] GEOMETRY_NORMALS_DATA = {
  28.     0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, // back
  29.     1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // right
  30.     0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front
  31.     -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left
  32.     0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top
  33.     0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0 // bottom
  34.   };
  35.  
  36.   private static final float[] GEOMETRY_TEXTURE_DATA = {
  37.     1, 0, 0, 0, 0, 1, 1, 1, // back
  38.     1, 0, 0, 0, 0, 1, 1, 1, // right
  39.     1, 0, 0, 0, 0, 1, 1, 1, // front
  40.     1, 0, 0, 0, 0, 1, 1, 1, // left
  41.     1, 0, 0, 0, 0, 1, 1, 1, // top
  42.     1, 0, 0, 0, 0, 1, 1, 1 // bottom
  43.   };
  44.  
  45.   public VoxelBlockMesh() {
  46.   }
  47.  
  48.   public VoxelBlockMesh init() {
  49.     setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(GEOMETRY_VERTICES_DATA));
  50.     setBuffer(VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA));
  51.     setBuffer(VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
  52.     setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA));
  53.     setStatic();
  54.     updateBound();
  55.     return this;
  56.   }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement