void CreateTerrain() { for (int x = 0; x < terrainArray.GetLength(0); x++) { for (int y = 0; y < terrainArray.GetLength(0); y++) { for (int z = 0; z < terrainArray.GetLength(0); z++) { if (terrainArray[x, y, z] != 0) { string tex; switch (terrainArray[x, y, z]) { case 1: tex = "Grass"; break; case 2: tex = "Dirt"; break; case 3: tex = "Sand"; break; case 4: tex = "Stone"; break; default: tex = "Grass"; break; } if (x == 0 || terrainArray[x - 1, y, z] == 0) { voxelGenerator.CreateNegativeXFace(x, y, z, tex); } if (x == terrainArray.GetLength(0) - 1 || terrainArray[x + 1, y, z] == 0) { voxelGenerator.CreatePositiveXFace(x, y, z, tex); } if (y == 0 || terrainArray[x, y - 1, z] == 0) { voxelGenerator.CreateNegativeYFace(x, y, z, tex); } if (y == terrainArray.GetLength(1) - 1 || terrainArray[x, y + 1, z] == 0) { voxelGenerator.CreatePositiveYFace(x, y, z, tex); } if (z == 0 || terrainArray[x, y, z - 1] == 0) { voxelGenerator.CreateNegativeZFace(x, y, z, tex); } if (z == terrainArray.GetLength(2) - 1 || terrainArray[x, y, z + 1] == 0) { voxelGenerator.CreatePositiveZFace(x, y, z, tex); } //print("Create " + tex + " block,"); } } } } }
void CreateTerrain() { // iterate horizontally on width for (int x = 0; x < terrainArray.GetLength(0); x++) { // iterate vertically for (int y = 0; y < terrainArray.GetLength(1); y++) { // iterate per voxel horizontally on depth for (int z = 0; z < terrainArray.GetLength(2); z++) { // if this voxel is not empty if (terrainArray[x, y, z] != 0) { string tex; // set texture name by value switch (terrainArray[x, y, z]) { case 1: tex = "Grass"; break; case 2: tex = "Dirt"; break; case 3: tex = "Sand"; break; case 4: tex = "Stone"; break; default: tex = "Grass"; break; } // check if we need to draw the negative x face if (x == 0 || terrainArray[x - 1, y, z] == 0) { voxelGenerator.CreateNegativeXFace(x, y, z, tex); } // check if we need to draw the positive x face if (x == terrainArray.GetLength(0) - 1 || terrainArray[x + 1, y, z] == 0) { voxelGenerator.CreatePositiveXFace(x, y, z, tex); } // check if we need to draw the negative y face if (y == 0 || terrainArray[x, y - 1, z] == 0) { voxelGenerator.CreateNegativeYFace(x, y, z, tex); } // check if we need to draw the positive y face if (y == terrainArray.GetLength(1) - 1 || terrainArray[x, y + 1, z] == 0) { voxelGenerator.CreatePositiveYFace(x, y, z, tex); } // check if we need to draw the negative z face if (z == 0 || terrainArray[x, y, z - 1] == 0) { voxelGenerator.CreateNegativeZFace(x, y, z, tex); } // check if we need to draw the positive z face if (z == terrainArray.GetLength(2) - 1 || terrainArray[x, y, z + 1] == 0) { voxelGenerator.CreatePositiveZFace(x, y, z, tex); } print("Create " + tex + " block,"); } } } } }
void CreateTerrain() { // For every voxel (width) for (int x = 0; x < terrainArray.GetLength(0); x++) { // For every voxel (height) for (int y = 0; y < terrainArray.GetLength(1); y++) { // For every voxel (depth) for (int z = 0; z < terrainArray.GetLength(2); z++) { // If the voxel isn't empty if (terrainArray[x, y, z] != 0) { string tex; // Assign texture name depending on value switch (terrainArray[x, y, z]) { case 1: tex = "Grass"; break; case 2: tex = "Dirt"; break; case 3: tex = "Sand"; break; case 4: tex = "Stone"; break; default: tex = "Grass"; break; } // If we need to draw the negative x face if (x == 0 || terrainArray[x - 1, y, z] == 0) { voxelGenerator.CreateNegativeXFace(x, y, z, tex); } // If we need to draw the positive x face if (x == terrainArray.GetLength(0) - 1 || terrainArray[x + 1, y, z] == 0) { voxelGenerator.CreatePositiveXFace(x, y, z, tex); } // If we need to draw the negative y face if (y == 0 || terrainArray[x, y - 1, z] == 0) { voxelGenerator.CreateNegativeYFace(x, y, z, tex); } // If we need to draw the positive y face if (y == terrainArray.GetLength(1) - 1 || terrainArray[x, y + 1, z] == 0) { voxelGenerator.CreatePositiveYFace(x, y, z, tex); } // If we need to draw the negative z face if (z == 0 || terrainArray[x, y, z - 1] == 0) { voxelGenerator.CreateNegativeZFace(x, y, z, tex); } // If we need to draw the positive z face if (z == terrainArray.GetLength(2) - 1 || terrainArray[x, y, z + 1] == 0) { voxelGenerator.CreatePositiveZFace(x, y, z, tex); } } } } } }