# Creating floor

I need to create a floor “the right way”. Before, I was using a Box to draw the floor. I noticed when I deleted it that my performance and fps improved dramatically. Is there a good way to draw the floor without losing performance? It is a static large floor.

I create a custom mesh (just a normal plane positioned at ground), tutorial can be found here.

Just make sure to reuse the material, you don’t want to create a new material for every piece of floor you have (if you want to remove/add floor), that would take up a lot of ram in the end. Easiest way imo is to use a public material variable with the material loaded from assetManager.

You want some code for it? Here’s mine.

[java]

private Geometry createFloorPiece(Vector2f position)

{

Mesh m = new Mesh();

Vector3f[] vertices = new Vector3f;

vertices = new Vector3f(position.x - 0.5f, 0.1f, position.y - 0.5f); //–

vertices = new Vector3f(position.x - 0.5f, 0.1f, position.y + 0.5f); //-+

vertices = new Vector3f(position.x + 0.5f, 0.1f, position.y - 0.5f); //±

vertices = new Vector3f(position.x + 0.5f, 0.1f, position.y + 0.5f); //++

Vector3f[] normals = new Vector3f;

normals = new Vector3f(0, 1, 0);

normals = new Vector3f(0, 1, 0);

normals = new Vector3f(0, 1, 0);

normals = new Vector3f(0, 1, 0);

Vector2f[] texCoord = new Vector2f;

texCoord = new Vector2f(0, 0);

texCoord = new Vector2f(1, 0);

texCoord = new Vector2f(0, 1);

texCoord = new Vector2f(1, 1);

int[] indexes = {

2, 0, 1, 1, 3, 2

};

m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));

m.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));

m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));

m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));

m.updateBound();

Geometry geom = new Geometry(“FloorPiece”, m);

return geom;

}[/java]

Keep in mind that this function is for creating a tile on a large floor, made of something like 70*50 pieces, hence the Vector2f positioning.

Just use a quad. If you want a very simple, flat, surface.

Obviously Quad is more efficient so I’d like to use it however my previous code was:

Box floor = new Box(boxCenter, boxX, boxY, boxZ);

the constructor of Quad does not take a Center and it does not contain a method setCenter. Any work around that?

thanks