public void GenerateTrainingForOneTaskInCurrentScene()

in Luminous4Alfred/TaskSolver/Algorithms/AlfredTaskHelperTool.cs [126:247]


    public void GenerateTrainingForOneTaskInCurrentScene() {
        //open scene
        EditorSceneManager.OpenScene(AlfredTaskHelperTool.targetGeneratingScenePath);
        var currentScene = EditorSceneManager.GetActiveScene();
        string currentScenePath = currentScene.path;
        string scene_name = currentScene.name;
        string sceneIndexStr = scene_name.Substring(scene_name.Length - 3);
        if (CSceneBuilderTool.samplingRoomType == CRoomType.Kitchen) {
            sceneIndexStr = scene_name.Substring(8);
        }


        IEnumerator GenerateTrainingForOneTaskIE() {
            int debug_idx = 0;
            string jsonFolder = "Assets/Custom/Json/Floorplans/FloorPlan" + sceneIndexStr + "/tasks";
            DirectoryInfo scenesDir = new DirectoryInfo(jsonFolder);
            FileInfo[] sceneFileList = scenesDir.GetFiles("*.json");
            foreach (FileInfo jsonFile in sceneFileList) {
                //debug_idx++;
                //if(debug_idx > 2) {
                //    break;
                //}
                Debug.Log("Generate Scene and Render Training Data At:" + jsonFile.ToString());

                //filter json for specific task
                if (!jsonFile.ToString().Contains("look_at_obj_in_light")) {
                    continue;
                }

                CObjectPool objectPool = GameObject.FindObjectOfType<CObjectPool>();


                CSceneBuilderTool.jsonPath = jsonFile.ToString();
                CSceneBuilderTool.LoadJsonInfo();


                objectPool.taskPath = CSceneBuilderTool.jsonPath;

                //reset
                CSceneBuilderTool.objectPlacingSuccessful = false;
                CSceneBuilderTool.objectPlacingFinish = false;
                CSceneBuilderTool.furniturePlacingSuccessful = false;
                CSceneBuilderTool.furniturePlacingFinish = false;

                //set furniture
                CFurniturePlacerTool furniturePlacerTool = GameObject.Find("FurniturePlacer").GetComponent<CFurniturePlacerTool>();
                //furniturePlacerTool.randomSeed = (int)UnityEngine.Random.Range(0f, 10000f);
                CFurniturePool furnturePool = furniturePlacerTool.gameObject.GetComponent<CFurniturePool>();
                furnturePool.randomSeed = (int)UnityEngine.Random.Range(0f, 10000f);
                furnturePool.roomType = CSceneBuilderTool.samplingRoomType;

                furniturePlacerTool.SetFloorAndScaleDoor();
                if (CSceneBuilderTool.samplingRoomType == CRoomType.Kitchen || CSceneBuilderTool.samplingRoomType == CRoomType.Bathroom) {
                    //additional process for Kitchen
                    CKitchenPlacerTool kitchenPlacerTool = GameObject.Find("KitchenObjSet").GetComponent<CKitchenPlacerTool>();
                    kitchenPlacerTool.ReNameKitchenSceneObjs();
                }
                furniturePlacerTool.LoadFurniturePrefab();

                furniturePlacerTool.CustomPlaceFurniture();
                while (!CSceneBuilderTool.furniturePlacingFinish) {
                    yield return new EditorWaitForSeconds(0.2f);
                }

                Debug.Log("CSceneBuilderTool.furniturePlacingFinish" + CSceneBuilderTool.furniturePlacingSuccessful);

                if (CSceneBuilderTool.furniturePlacingSuccessful) {
                    Debug.Log("Place Furniture Successful!");

                    //rename cabinet,drawer,shelf
                    CKitchenPlacerTool kitchenPlacerTool = GameObject.Find("KitchenObjSet").GetComponent<CKitchenPlacerTool>();
                    kitchenPlacerTool.ReNameKitchenSceneObjs();

                    CObjectPlacerTool objectPlacerTool = GameObject.Find("ObjectPlacer").GetComponent<CObjectPlacerTool>();
                    objectPlacerTool.randomSeed = (int)UnityEngine.Random.Range(0f, 1000f);

                    CObjectPool qobjectPool = objectPlacerTool.gameObject.GetComponent<CObjectPool>();
                    qobjectPool.randomSeed = (int)UnityEngine.Random.Range(0f, 1000f);
         
                    qobjectPool.roomType = CSceneBuilderTool.samplingRoomType;
                    objectPlacerTool.LoadObjectPrefab();
                    objectPlacerTool.CustomPlaceObject();
                    while (!CSceneBuilderTool.objectPlacingFinish) {
                        yield return new EditorWaitForSeconds(1f);
                    }

                    //Set celling
                    StructureObject[] structObjs = Resources.FindObjectsOfTypeAll<StructureObject>();
                    foreach (StructureObject structObj in structObjs) {
                        if (structObj.WhatIsMyStructureObjectTag == StructureObjectTag.Ceiling) {
                            structObj.gameObject.SetActive(true);
                        }
                    }

                    //generate alfred training data
                    AlfredAgent.taskFinish = false;
                    AlfredAgent.hasGraph = false;
                    AlfredAgent.taskJsonPath = CSceneBuilderTool.jsonPath;

                    if (CSceneBuilderTool.objectPlacingSuccessful) {
                        AlfredAgent alfredAgent = GameObject.FindObjectOfType<AlfredAgent>();

                        alfredAgent.OneJsonForCurrentScene();
                        while (!AlfredAgent.taskFinish) {
                            yield return new EditorWaitForSeconds(2);
                        }
                    }
                }

                if (!(CSceneBuilderTool.objectPlacingSuccessful && CSceneBuilderTool.furniturePlacingSuccessful)) {
                    Debug.LogWarning("Wrong json/Wrong scene/Wrong solution: " + AlfredAgent.taskJsonPath);
                }

                EditorSceneManager.OpenScene(currentScenePath);
            }

            oneSceneLock = false;
            yield return null;
        }

        EditorCoroutineUtility.StartCoroutineOwnerless(GenerateTrainingForOneTaskIE());
    }