private List <IRenderable> CreateMeshes(List <Chunk> chunks) { float uvWidth = 2048.0f / 16.0f; float uvCell = uvWidth / 2048.0f; float xUv = uvCell * 2.0f; float yUv = uvCell * 15.0f; Vector2 uvCoordinate = new Vector2(xUv, yUv); Vector2 uvOffset = new Vector2(uvCell, uvCell); var blockPos = new Vector3(); var list = new List <IRenderable>(); foreach (var chunk in chunks) { for (uint x = 0; x < Chunk.Width; ++x) { for (uint y = 0; y < Chunk.Height; ++y) { for (uint z = 0; z < Chunk.Depth; ++z) { blockPos.X = x; blockPos.Y = y; blockPos.Z = z; var block = chunk.At(x, y, z); if (block.BlockType != BlockType.Air) { foreach (Side side in Sides.All) { // Chunk borders TBD if (Chunk.IsChunkBorder(x, y, z)) { _pool.AddFace(Quads.QuadFor(side), block.World, uvCoordinate, uvOffset); continue; } // Check block next to current block in direction of the side. // - If neighbor exists and not air block, don't draw var dir = Directions.DirectionFor(side); if (chunk.At(blockPos + dir).BlockType == BlockType.Air) { _pool.AddFace(Quads.QuadFor(side), block.World, uvCoordinate, uvOffset); } } } } } } list.Add(new ChunkMesh(chunk, _pool.ToMesh(_program))); _pool.Reset(); } return(list); }