/// <summary> /// This function builds the mesh by implementing a Cube Marching algorithm, removing duplicate vertices, calculating normals, and generating biome-based vertex colors. /// </summary> private void GenerateMesh() { List <VoxelData.Tri> geom = new List <VoxelData.Tri>(); for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { for (int z = 0; z < data.GetLength(2); z++) { if (!data[x, y, z].IsHidden(0)) { data[x, y, z].MarchCube(0, geom); } } } } // combine all of the tris together into one mesh: Mesh mesh = MakeMeshFromTris(geom); // remove duplicate vertices: this.mesh.mesh = MeshTools.RemoveDuplicates(mesh, true); SetVertexColors(); }