public bool CustomPlaceObject()

in IndoorSceneSynthesis/ConstraintStochasticIndoorSceneGeneration/Custom/CustomScripts/CObjectPlacerTool.cs [148:260]


    public bool CustomPlaceObject() {
        bool allSuccess = true;

        SetSpawner();

        var allReceptacles = GameObject.FindObjectsOfType<SimObjPhysics>();

        List<SimObjPhysicsExtended> sopEList = GetRequiredExtendObjPhysics();

#if UNITY_EDITOR
        IEnumerator SequtialSamplingObjects() {
            foreach (SimObjPhysicsExtended sopE in sopEList) {
                //Debug.Log("Now place obj name:" + sopE.simObjName);
                SimObjType objType = sopE.ObjType;
                foreach (GameObject go in objectPool.objectList) {

                    if (go.GetComponent<SimObjPhysics>().ObjType == objType) {
                        SimObjPhysics sop = Instantiate(go, new Vector3(-100, -100, -100), Quaternion.identity).GetComponent<SimObjPhysics>();
                        sopE.simObjPhysics = sop;
                        sopE.gameObject = sop.gameObject;
                        sopE.gameObject.name = sopE.simObjName;

                        Debug.Log("Now place object (SOPE)" + sop.gameObject.name);

                        List<ReceptacleSpawnPoint> allRsps = new List<ReceptacleSpawnPoint>();
                        int receptacleIndex = 0;
                        for (int j = 0; j < sopE.directionDesc.Count; ++j) {
                            if (sopE.directionDesc[j] == "on") {
                                receptacleIndex = j;

                                string groupObjName = sopE.groupObjName[receptacleIndex];
                                //if kitchen randomly pick a countertop, cabinet, drawer
                                if (CSceneBuilderTool.samplingRoomType == CRoomType.Kitchen) {
                                    if (groupObjName.Contains("CounterTop")) {
                                        groupObjName = CKitchenPlacerTool.FindARandomSOPType(SimObjType.CounterTop);
                                    } else if (groupObjName.Contains("Cabinet")) {
                                        groupObjName = CKitchenPlacerTool.FindARandomSOPType(SimObjType.Cabinet);
                                    } else if (groupObjName.Contains("Drawer")) {
                                        groupObjName = CKitchenPlacerTool.FindARandomSOPType(SimObjType.Drawer);
                                    } else if (groupObjName.Contains("StoveBurner")) {
                                        groupObjName = CKitchenPlacerTool.FindARandomSOPType(SimObjType.StoveBurner);
                                    }
                                }


                                GameObject receptacleObj = GameObject.Find(groupObjName);
                                if (receptacleObj == null) {
                                    Debug.LogWarning("No receptable found: " + groupObjName + " for obj: " + sopE.simObjName);
                                    allSuccess = false;
                                    break;
                                }
                                SimObjPhysics receptacleSop = receptacleObj.GetComponent<SimObjPhysics>();
                                if (receptacleSop != null) {
                                    Debug.Log("Find receptable (SOPE): " + receptacleSop.gameObject.name);

                                    //fix empty parent
                                    foreach (GameObject rtb in receptacleSop.ReceptacleTriggerBoxes) {
                                        Contains containsScript = rtb.GetComponent<Contains>();
                                        if (containsScript.myParent == null) {
                                            containsScript.myParent = receptacleSop.gameObject;
                                        }

                                    }

                                    List<ReceptacleSpawnPoint> targetReceptacleSpawnPoints = receptacleSop.ReturnMySpawnPoints(false);
                                    allRsps.AddRange(targetReceptacleSpawnPoints);
                                    //break;
                                }
                            }
                        }





                        //load general rule
                        CObjectItemRule objRule = objectPool.objectItemRules[(int)sopE.ObjType - 1];

                        //shuffle rsps
                        System.Random rng = new System.Random(randomSeed);
                        allRsps.Shuffle_(rng);

                        if (allRsps.Count > 0) {
                            bool successful = CustomPlaceObjectReceptacle(
                                allRsps,
                                sopE,
                                objRule.rho,
                                objRule.theta,
                                objRule.faceCenter,
                                true,
                                3000,
                                90,
                                true
                            );

                            Debug.Log("Place Successful? (SOPE) " + successful);
                            allSuccess = allSuccess && successful;
                        }

                        break;
                    }
                }
                yield return new EditorWaitForSeconds(0.2f);
            }

            CSceneBuilderTool.objectPlacingFinish = true;
            CSceneBuilderTool.objectPlacingSuccessful = allSuccess;
        }

        EditorCoroutineUtility.StartCoroutineOwnerless(SequtialSamplingObjects());
#endif
        return allSuccess;
    }