package com.blarg.gdx.tilemap3d;

import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.g3d.ModelBatch;

public class TileMapRenderer {
	public void render(ModelBatch modelBatch, Camera camera, TileMap tileMap) {
		for (int y = 0; y < tileMap.heightInChunks; ++y)
		{
			for (int z = 0; z < tileMap.depthInChunks; ++z)
			{
				for (int x = 0; x < tileMap.widthInChunks; ++x)
				{
					TileChunk chunk = tileMap.getChunk(x, y, z);
					if (chunk.mesh.mesh.getNumVertices() > 0 && camera.frustum.boundsInFrustum(chunk.mesh.bounds))
						modelBatch.render(chunk.mesh);
					if (chunk.alphaMesh.mesh.getNumVertices() > 0 && camera.frustum.boundsInFrustum(chunk.alphaMesh.bounds))
						modelBatch.render(chunk.alphaMesh);
				}
			}
		}
	}
}

@@ -232,119 +232,45 @@
 %7B%0A%09%09
-for (int y = 0; y %3C tileMap.heightInChunks; ++y)%0A%09%09%7B%0A%09%09%09for (int z = 0; z %3C tileMap.depthInChunks; ++z)%0A%09%09%09%7B%0A%09%09
+TileChunk%5B%5D chunks = tileMap.chunks;%0A
 %09%09fo
@@ -280,58 +280,44 @@
 int 
-x
+i
  = 0; 
-x %3C tileMap.widthInChunks; ++x)%0A%09%09%09%09
+i %3C chunks.length; ++i) 
 %7B%0A%09%09%09
-%09%09
 Tile
@@ -334,226 +334,26 @@
 k = 
-tileMap.getChunk(x, y, z);%0A%09%09%09%09%09if (chunk.mesh.mesh.getNumVertices() %3E 0 && camera.frustum.boundsInFrustum(chunk.mesh.bounds))%0A%09%09%09%09%09%09modelBatch.render(chunk.mesh);%0A%09%09%09%09%09if (chunk.alphaMesh.mesh.getNumVertices() %3E 0 && 
+chunks%5Bi%5D;%0A%09%09%09if (
 came
@@ -389,33 +389,30 @@
 unk.
-alpha
+get
 Mesh
-.b
+B
 ounds
+()
 ))%0A%09%09%09%09
-%09%09
 mode
@@ -434,31 +434,10 @@
 hunk
-.alphaMesh);%0A%09%09%09%09%7D%0A%09%09%09%7D
+);
 %0A%09%09%7D

update TileMapRenderer