public void ConstructMesh()
    {
        int resolution = pointDensity * terrainSize;

        Vector3[] verticies = new Vector3[resolution * resolution];
        Debug.Log("Num Vertices = " + (resolution * resolution));
        int[] triangles = new int[(resolution - 1) * (resolution - 1) * 6];
        Debug.Log("Num Triangles = " + ((resolution - 1) * (resolution - 1) * 6));
        int triIndex = 0;

        mesh = meshFilter.sharedMesh;
        // set indexFormat from 16bit to 32bit so that we can have a more detailed mesh
        meshFilter.sharedMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

        for (int y = 0; y < resolution; y++)
        {
            for (int x = 0; x < resolution; x++)
            {
                // (x,y) / pointDensity = game coordinate
                Vector2 point = new Vector2(x, y) / (float)pointDensity;

                // noiseVal is the height value at our coordinate
                float noiseVal = terrainGenerator.CalculatePointOnPlanet(point + center);
                elevationMinMax.AddValue(noiseVal);                 // track min/max values for our terrain

                // index of the current point
                int i = y + x * resolution;
                // set the vertex for our mesh
                verticies[i] = new Vector3(point.x, noiseVal, point.y);

                // create triangles for mesh
                // triangles are created in clockwise pattern
                if (x != resolution - 1 && y != resolution - 1)
                {
                    triangles[triIndex]     = i;                  // starting point
                    triangles[triIndex + 1] = i + resolution + 1; // point on the next row + 1
                    triangles[triIndex + 2] = i + resolution;

                    triangles[triIndex + 3] = i;
                    triangles[triIndex + 4] = i + 1;
                    triangles[triIndex + 5] = i + 1 + resolution;

                    triIndex += 6;
                }
            }
        }

        // update color generator with new minmax values
        colorGenerator.UpdateElevation(elevationMinMax);
        //colorGenerator.UpdateColors();

        // update mesh with new triangles
        mesh.Clear();
        mesh.vertices  = verticies;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
    }