in IndoorSceneSynthesis/ConstraintStochasticIndoorSceneGeneration/Custom/Visualization/CSunCGVisualizer.cs [37:168]
public void LoadObjectPrefab(bool loadCommonObject = true, bool canDuplicate = false)
{
//load pool
Debug.Log("LoadFurniturePrefab");
CFurniturePool objPool = furniturePool;
objPool.furnitureList.Clear();
List<string> prefabPathList = new List<string>();
List<SimObjType> nonDuplicatedObjTypeList = new List<SimObjType>();
void LoadPrefabPaths(string dirPath)
{
//DirectoryInfo dir = new DirectoryInfo(dirPath);
string[] fileInfoList = Directory.GetDirectories(dirPath);
foreach (string file in fileInfoList)
{
string prefabDirPath = file.ToString() + "/Prefabs";
DirectoryInfo prefabDir = new DirectoryInfo(prefabDirPath);
try
{
FileInfo[] prefabInfoList = prefabDir.GetFiles("*.prefab");
foreach (FileInfo prefabFile in prefabInfoList)
{
int prefabRelativepathStart = prefabFile.ToString().IndexOf(dirPath);
string prefabPath = prefabFile.ToString().Substring(prefabRelativepathStart);
Debug.Log("LoadFurniturePrefab: " + prefabPath);
prefabPathList.Add(prefabPath);
}
}
catch
{
Debug.LogWarning("the prefab path is wrong: " + prefabDirPath);
}
}
}
string dirPath1 = "Assets/Physics/SimObjsPhysics/Living Room Objects";
LoadPrefabPaths(dirPath1);
string dirPath2 = "Assets/Physics/SimObjsPhysics/Living Room and Bedroom Objects";
LoadPrefabPaths(dirPath2);
string dirPath3 = "Assets/Physics/SimObjsPhysics/Bedroom Objects";
LoadPrefabPaths(dirPath3);
string dirPath4 = "Assets/Physics/SimObjsPhysics/Kitchen Objects";
LoadPrefabPaths(dirPath4);
//addtional prefabs
string dirPath_ad = "Assets/Custom/Visualization/Prefabs";
DirectoryInfo additionalPrefabDir = new DirectoryInfo(dirPath_ad);
FileInfo[] ad_prefabInfoList = additionalPrefabDir.GetFiles("*.prefab");
foreach (FileInfo prefabFile in ad_prefabInfoList)
{
int ad_prefabRelativepathStart = prefabFile.ToString().IndexOf(dirPath_ad);
string ad_prefabPath = prefabFile.ToString().Substring(ad_prefabRelativepathStart);
Debug.Log("LoadFurniturePrefab: " + ad_prefabPath);
prefabPathList.Add(ad_prefabPath);
}
//LoadPrefabPaths(dirPath_ad);
if (loadCommonObject)
{
string dirPath5 = "Assets/Physics/SimObjsPhysics/Common Objects";
LoadPrefabPaths(dirPath5);
//string dirPath2 = "Assets/Physics/SimObjsPhysics/Custom Project Objects";
//LoadPrefabPaths(dirPath2);
string dirPath6 = "Assets/Physics/SimObjsPhysics/Miscellaneous Objects";
LoadPrefabPaths(dirPath6);
}
//shuffle list
System.Random rng = new System.Random(objPool.randomSeed++);
prefabPathList.Shuffle_(rng);
//put prefab into furniture pool
foreach (string prefabPath in prefabPathList)
{
GameObject objPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
if (!canDuplicate)
{
//string[] pathParts = prefabPath.Split('/');
//string prefabName = pathParts[pathParts.Length - 1].Split('.')[0].Split('_')[0];
//Debug.Log("prefab name " + " " + prefabPath + " " + prefabName);
//GameObject objPrefabGo = Instantiate(objPrefab);
SimObjPhysics sop = objPrefab.GetComponent<SimObjPhysics>();
StructureObject sto = objPrefab.GetComponent<StructureObject>();
if (sop != null)
{
//not a good object, continue
//Debug.Log("loading prefab from path: " + prefabPath + " --- " + objPrefab.name);
if (nonDuplicatedObjTypeList.Contains(sop.ObjType))
{
continue;
}
else
{
nonDuplicatedObjTypeList.Add(sop.ObjType);
objPool.furnitureList.Add(objPrefab);
}
}
else if (sto != null)
{
objPool.furnitureList.Add(objPrefab);
}
}
else
{
objPool.furnitureList.Add(objPrefab);
}
}
objPool.furnitureList.Sort((x, y) => string.Compare(x.name, y.name));
//DirectoryInfo dir = new DirectoryInfo("Assets/Physics/SimObjsPhysics");
//FileInfo[] fileInfo = dir.GetFiles();
//foreach (var file in fileInfo)
// Debug.Log(file);
}