public void CreatePlanet()
    {
        // script for mesh generation
        meshGenerator = GetComponent <PlanetMesh>();

        // Setup parameters for our planet patches
        meshGenerator.uPatchCount = xPatchCount;
        meshGenerator.vPatchCount = yPatchCount;
        meshGenerator.radius      = radius;
        meshGenerator.xVertCount  = xVertices;
        meshGenerator.yVertCount  = yVertices;

        // Build one patch for each cardinal direction using meshGenerator
        for (int i = 0; i < 6; i++)
        {
            QuadTreeNode root = new QuadTreeNode(i, meshGenerator);

            // Parent all meshpatches under one GO
            root.meshPatch.transform.parent = this.gameObject.transform;

            // Add node to our list of nodes
            nodes.Add(root);
        }

        this.maxDepth = 0;
    }
 // Node Splitting Constructor - doesn't create meshPatch GO, just updates the model //
 public QuadTreeNode(int childNr, QuadTreeNode parent, PlanetMesh meshGenerator)
 {
     this.parent      = parent;
     this.direction   = parent.direction;
     this.depth       = parent.depth + 1;
     this.childNumber = childNr;
 }
    // Root node constructor //
    public QuadTreeNode(int direction, PlanetMesh meshGenerator)
    {
        this.depth     = 0;
        this.direction = direction;
        this.u         = 0;
        this.v         = 0;

        // Crate patch, name it and parent it to root
        this.meshPatch      = CreatePatch(meshGenerator);
        this.meshPatch.name = "Patch_" + PlanetMesh.patches[direction].name + "_" + u + "_" + v;
        this.meshPatch.tag  = "patch";
    }
    private GameObject CreatePatch(PlanetMesh meshGenerator)
    {
        // Generate mesh with u,v from class state
        GameObject patch = meshGenerator.GeneratePatch(this.direction, this.u, this.v);

        // Set position of node
        Mesh    mesh     = patch.GetComponent <MeshFilter>().sharedMesh;
        Vector3 worldPos = patch.transform.TransformPoint(mesh.vertices[meshGenerator.yVertCount * (meshGenerator.yVertCount / 2) + meshGenerator.xVertCount / 2]);

        this.position = worldPos;

        return(patch);
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PlanetMesh script = (PlanetMesh)target;

        if (GUI.changed)
        {
        }

        if (GUILayout.Button("Create Planet"))
        {
            script.GeneratePatches(script.uPatchCount, script.vPatchCount);
        }
    }