public void SplitMeshByBBox()
 {
     splitTriggered = true;
     areaBound      = new BoundingBoxSystem(rs.GetList(), x_area, y_area, z_area);
     areaBound.SplitBounds();
     areaBound.SplitMesh();
 }
    // Use this for initialization
    void Start()
    {
        getRoomSaveLogic();

        specificMeshes = new List <GameObject>();
        indicator      = GameObject.Find("IndicatorObject");

        areaBound = new BoundingBoxSystem(rs.GetList(), x_area, y_area, z_area);
        areaBound.SplitBounds();
    }
    public void Load()
    {
        List <DirectoryInfo> directoryInfoList = rs.GetDirectoryList();
        int selected = rs.GetSelectedRoom();

        BoundHolder[] bhs = rs.LoadBoundingBox(directoryInfoList[selected]);
        //Debug.Log("length of bhs: " + bhs.Length);
        loadedBounds = new BoundingBoxSystem(bhs);
        loadedMeshes = new LoadedMeshHolder[bhs.Length];
    }
    // Update is called once per frame
    void Update()
    {
        if (!splitTriggered)
        {
            areaBound = new BoundingBoxSystem(rs.GetList(), x_area, y_area, z_area);
            areaBound.SplitBounds();
        }

        if (loadedBounds != null && !preLoadVer)
        {
            loadedBounds.ActivateSubBoundsByIndicator(indicator);
            for (int i = 0; i < loadedBounds.GetSubBounds().Length; i++)
            {
                if (loadedBounds.GetSubBounds()[i].GetStatus())
                {
                    if (GameObject.Find("MeshInBoundingBox_" + i) == null)
                    {
                        if (loadedMeshes[i] == null)
                        {
                            LoadMesh(i);
                        }

                        for (int j = 0; j < loadedMeshes[i].meshes.Length; j++)
                        {
                            GameObject obj = new GameObject();
                            MeshFilter mf  = obj.AddComponent <MeshFilter>();
                            mf.name = "MeshInBoundingBox_" + i;
                            mf.mesh = loadedMeshes[i].meshes[j];
                            MeshRenderer mr = obj.AddComponent <MeshRenderer>();
                            mr.material = new Material(Shader.Find("Custom/UnlitVertexColor"));
                        }
                    }
                }
                else
                {
                    if (!keepMeshes && (GameObject.Find("MeshInBoundingBox_" + i) != null))
                    {
                        GameObject obj = GameObject.Find("MeshInBoundingBox_" + i);
                        Destroy(obj);
                    }
                }
            }
        }

        if (loadedBounds != null && preLoadVer)
        {
            loadedBounds.ActivateSubBoundsByIndicator(indicator);
            for (int i = 0; i < loadedBounds.GetSubBounds().Length; i++)
            {
                Vector3 directionIndicator2Bound = (loadedBounds.GetSubBounds()[i].subBound.center - indicator.transform.position).normalized;
                float   dotProduct = Vector3.Dot(directionIndicator2Bound, indicator.transform.forward);

                if (dotProduct > 0.95)
                {
                    loadedBounds.GetSubBounds()[i].SetPreLoadStatus(true);
                }
                else
                {
                    loadedBounds.GetSubBounds()[i].SetPreLoadStatus(false);
                }

                if (loadedBounds.GetSubBounds()[i].GetStatus() || loadedBounds.GetSubBounds()[i].GetPreLoadStatus())
                {
                    if (GameObject.Find("MeshInBoundingBox_" + i) == null)
                    {
                        if (loadedMeshes[i] == null)
                        {
                            LoadMesh(i);
                        }

                        for (int j = 0; j < loadedMeshes[i].meshes.Length; j++)
                        {
                            GameObject obj = new GameObject();
                            MeshFilter mf  = obj.AddComponent <MeshFilter>();
                            mf.name = "MeshInBoundingBox_" + i;
                            mf.mesh = loadedMeshes[i].meshes[j];
                            MeshRenderer mr = obj.AddComponent <MeshRenderer>();
                            mr.material = new Material(Shader.Find("Custom/UnlitVertexColor"));
                        }
                    }
                }
                else
                {
                    if (!keepMeshes && (GameObject.Find("MeshInBoundingBox_" + i) != null || !loadedBounds.GetSubBounds()[i].GetPreLoadStatus()))
                    {
                        GameObject obj = GameObject.Find("MeshInBoundingBox_" + i);
                        Destroy(obj);
                    }
                }
            }
        }
    }