CubeMesh[,,] GenerateRenderableCubes(Cube[,,] cubes) { var cubeMeshes = new CubeMesh[cubes.GetLength(0), cubes.GetLength(1), cubes.GetLength(2)]; var visualVertexCount = 0; var collisionVertexCount = 0; var begin = gridPosition * dimensionsInCubes; var end = begin + dimensionsInCubes; for (var cubeX = begin.x; cubeX < end.x; ++cubeX) { for (var cubeY = begin.y; cubeY < end.y; ++cubeY) { for (var cubeZ = begin.z; cubeZ < end.z; ++cubeZ) { var cube = cubes[cubeX, cubeY, cubeZ]; if (cube == null) continue; var cubeGridPosition = new Vector3i(cubeX, cubeY, cubeZ); var cubeMesh = CalculateRenderableCube(cube, ref visualVertexCount, ref collisionVertexCount, cubes, cubeGridPosition); cubeMeshes[cubeX, cubeY, cubeZ] = cubeMesh; cubes[cubeX, cubeY, cubeZ] = cube; } } } return cubeMeshes; }