Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void createTop(Float startX, Float startZ, Float startHeight, Float size) {
- Mesh mesh = new Mesh();
- Float half = size / 2;
- Vector3f[] vertices = new Vector3f[7];
- vertices[0] = new Vector3f(startX, startHeight, startZ);
- vertices[1] = new Vector3f(vertices[0].x - size, startHeight, vertices[0].z);
- vertices[2] = new Vector3f(vertices[1].x + half, startHeight, vertices[0].z - size);
- vertices[3] = new Vector3f(vertices[2].x + size, startHeight, vertices[2].z);
- vertices[4] = new Vector3f(vertices[3].x + half, startHeight, vertices[3].z + size);
- vertices[5] = new Vector3f(vertices[4].x - half, startHeight, vertices[4].z + size);
- vertices[6] = new Vector3f(vertices[5].x - size, startHeight, vertices[5].z);
- int[] indexes = {
- 0,1,2, 2,3,0, 0,3,4, 4,5,0, 0,5,6, 6,1,0, // bottom
- 0,1,6, 6,5,0, 0,5,4, 4,3,0, 0,3,2, 2,1,0 // reverse bottom
- };
- float[] normals = new float[21];
- normals = new float[] {
- 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0
- };
- Vector2f[] texCoord = new Vector2f[4];
- texCoord[0] = new Vector2f(0, 0);
- texCoord[1] = new Vector2f(0, 1);
- texCoord[2] = new Vector2f(1, 0);
- texCoord[3] = new Vector2f(1, 1);
- mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
- mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
- mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
- mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));
- mesh.updateBound();
- Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
- mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture("Textures/Pond.jpg"));
- Geometry geo = new Geometry("MyMesh", mesh);
- geo.setMaterial(mat);
- geo.setShadowMode(ShadowMode.Cast);
- app.getRootNode().attachChild(geo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement