//=====================================================================================================================
    //this Function saves the linear Node array as a text file
    //=====================================================================================================================
    void SaveTree(string path)
    {
        string file = "";

        //Start with the Tree Depth ,number of nodes; and Root Size
        file += TreeDepth.ToString() + "," + nodeArray.Length.ToString() + ";" + VoxelSize.ToString();

        for (int i = 0; i < nodeArray.Length; ++i)
        {
            SDF_Node n = nodeArray[i];
            file += "/" + n.index.ToString() + "," + n.c0.ToString() + "," + n.c1.ToString()
                    + "," + n.c2.ToString() + "," + n.c3.ToString() + "," + n.c4.ToString()
                    + "," + n.c5.ToString() + "," + n.c6.ToString() + "," + n.c7.ToString()
                    + "," + n.Min.x.ToString() + "," + n.Min.y.ToString() + "," + n.Min.z.ToString()
                    + "," + n.Max.x.ToString() + "," + n.Max.y.ToString() + "," + n.Max.z.ToString()
                    + "," + n.SurfacePoint.x.ToString() + "," + n.SurfacePoint.y.ToString() + "," + n.SurfacePoint.z.ToString();
        }
        //finally add the center of the Octree
        Vector3 p = transform.position;

        file += '*' + p.x.ToString() + "," + p.y.ToString() + "," + p.z.ToString() + ",";

        //PlayerPrefs.SetString(Octree_Name, file);
        System.IO.File.WriteAllText(path, file);
    }
    //Final step Get the Unpacked tree and then pack it into a linear Buffer
    void PackTree()
    {
        //the unpacked Tree is recursively built so we have to turn it into a linear list here before we copy it with proper
        //indexing into the final LinearList below
        List <TreeNode> LinearUnpackedTree = new List <TreeNode>();

        for (int i = 0; i < Unpacked_Tree.Count - 1; ++i) //ignore last node some reason the recursion f***s up when adding an extra garbage node
        {
            LinearUnpackedTree.Add(Unpacked_Tree[i]);
        }
        Unpacked_Tree.Clear();

        //Go through the unpacked tree and build it linearly
        List <SDF_Node> LinearList = new List <SDF_Node>();

        for (int i = 0; i < LinearUnpackedTree.Count; ++i)
        {
            SDF_Node current = new SDF_Node();

            Octree.OctreeNode node = LinearUnpackedTree[i].mNode;
            Vector3           p    = node.Position;
            float             s    = node.SDF.mSize;

            current.Min.x = p.x - s;
            current.Min.y = p.y - s;
            current.Min.z = p.z - s;

            current.Max.x = p.x + s;
            current.Max.y = p.y + s;
            current.Max.z = p.z + s;

            current.index        = i;
            current.SurfacePoint = node.SDF.mPoint;
            if (LinearUnpackedTree[i].mChildren != null)
            {
                current.c0 = FindIndex(LinearUnpackedTree[i].mChildren[0], ref LinearUnpackedTree);
                current.c1 = FindIndex(LinearUnpackedTree[i].mChildren[1], ref LinearUnpackedTree);
                current.c2 = FindIndex(LinearUnpackedTree[i].mChildren[2], ref LinearUnpackedTree);
                current.c3 = FindIndex(LinearUnpackedTree[i].mChildren[3], ref LinearUnpackedTree);
                current.c4 = FindIndex(LinearUnpackedTree[i].mChildren[4], ref LinearUnpackedTree);
                current.c5 = FindIndex(LinearUnpackedTree[i].mChildren[5], ref LinearUnpackedTree);
                current.c6 = FindIndex(LinearUnpackedTree[i].mChildren[6], ref LinearUnpackedTree);
                current.c7 = FindIndex(LinearUnpackedTree[i].mChildren[7], ref LinearUnpackedTree);
            }
            else
            {
                current.c0 = -1;
                current.c1 = -1;
                current.c2 = -1;
                current.c3 = -1;
                current.c4 = -1;
                current.c5 = -1;
                current.c6 = -1;
                current.c7 = -1;
            }

            LinearList.Add(current);
        }

        //used to set a ComputeBuffer later on
        nodeArray = LinearList.ToArray();
    }