in IndoorSceneSynthesis/ConstraintStochasticIndoorSceneGeneration/Custom/CustomScripts/CObjectPlacerTool.cs [262:369]
public bool CustomPlaceObjectParallel() {
bool allSuccess = true;
SetSpawner();
var allReceptacles = GameObject.FindObjectsOfType<SimObjPhysics>();
List<SimObjPhysicsExtended> sopEList = GetRequiredExtendObjPhysics();
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
);
if (!successful && objectPool.beInResample) {
objectPool.RestoreObjectName(sopE.simObjName);
DestroyImmediate(sopE.simObjPhysics.gameObject);
}
Debug.Log("Place Successful? (SOPE) " + successful);
allSuccess = allSuccess && successful;
}
break;
}
}
}
//CSceneBuilderTool.objectPlacingFinish = true;
//CSceneBuilderTool.objectPlacingSuccessful = allSuccess;
return allSuccess;
}