Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mygame.terrain;
- import com.jme3.scene.Mesh;
- import com.jme3.scene.VertexBuffer;
- import com.jme3.util.BufferUtils;
- public class VoxelBlockMesh extends Mesh {
- private static final short[] GEOMETRY_INDICES_DATA = {
- 2, 1, 0, 3, 2, 0, // back
- 6, 5, 4, 7, 6, 4, // right
- 10, 9, 8, 11, 10, 8, // front
- 14, 13, 12, 15, 14, 12, // left
- 18, 17, 16, 19, 18, 16, // top
- 22, 21, 20, 23, 22, 20 // bottom
- };
- private static final float[] GEOMETRY_VERTICES_DATA = {
- 0, 0, -1, 1, 0, -1, 1, 1, -1, 0, 1, -1, // back
- 1, 0, -1, 1, 0, 0, 1, 1, 0, 1, 1, -1, // right
- 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, // front
- 0, 0, 0, 0, 0, -1, 0, 1, -1, 0, 1, 0, // left
- 1, 1, -1, 1, 1, 0, 0, 1, 0, 0, 1, -1, // top
- 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, -1 // bottom
- };
- private static final float[] GEOMETRY_NORMALS_DATA = {
- 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, // back
- 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // right
- 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front
- -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left
- 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top
- 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0 // bottom
- };
- private static final float[] GEOMETRY_TEXTURE_DATA = {
- 1, 0, 0, 0, 0, 1, 1, 1, // back
- 1, 0, 0, 0, 0, 1, 1, 1, // right
- 1, 0, 0, 0, 0, 1, 1, 1, // front
- 1, 0, 0, 0, 0, 1, 1, 1, // left
- 1, 0, 0, 0, 0, 1, 1, 1, // top
- 1, 0, 0, 0, 0, 1, 1, 1 // bottom
- };
- public VoxelBlockMesh() {
- }
- public VoxelBlockMesh init() {
- setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(GEOMETRY_VERTICES_DATA));
- setBuffer(VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA));
- setBuffer(VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
- setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA));
- setStatic();
- updateBound();
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement