MegascansMeshUtils.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. #if UNITY_EDITOR
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor;
  6. using Newtonsoft.Json.Linq;
  7. using System.IO;
  8. using System;
  9. namespace Quixel
  10. {
  11. //This class imports the geometry and create the prefabs.
  12. public class MegascansMeshUtils : MonoBehaviour
  13. {
  14. /// <summary>
  15. /// Import meshes, start from highest LOD and import the chain.
  16. /// </summary>
  17. public static void ProcessMeshes(JObject assetJson, string assetFolderPath, bool highpoly, bool hasVariations, PrefabData prefabData)
  18. {
  19. try
  20. {
  21. bool createPrefabs = EditorPrefs.GetBool("QuixelDefaultSetupPrefabs", true);
  22. bool importLODs = EditorPrefs.GetBool("QuixelDefaultImportLODs", true);
  23. bool setupLODs = EditorPrefs.GetBool("QuixelDefaultSetupLOD", true);
  24. prefabData.setupLODs = (importLODs && setupLODs); //Only do LOD setup if lower lods were imported and LOD grouping is enabled.
  25. //get mesh components from the current object. Also, meshComps.Count can give us the number of variations ;)
  26. JArray meshComps = (JArray)assetJson["meshList"];
  27. JArray lodList = (JArray)assetJson["lodList"];
  28. string activeLOD = (string)assetJson["activeLOD"];
  29. string minLOD = (string)assetJson["minLOD"];
  30. string modelsFolderPath = MegascansUtilities.ValidateFolderCreate(assetFolderPath, "Models");
  31. if (hasVariations)
  32. {
  33. List<List<string>> importedGeometryPaths3DPlant = new List<List<string>>();
  34. for (int i = 1; i <= meshComps.Count; i++)
  35. {
  36. List<string> importedGeometryPaths = new List<string>();
  37. bool lodMatched = false; // This flag helps to import the lower lods once the active lod is found.
  38. foreach (JObject mesh in lodList)
  39. {
  40. if ((int)mesh["variation"] == i)
  41. {
  42. string currentLOD = (string)mesh["lod"];
  43. if (lodMatched || currentLOD == activeLOD || highpoly)
  44. {
  45. lodMatched = true;
  46. if ((currentLOD == "high") && !highpoly)
  47. {
  48. continue;
  49. }
  50. //get the path of the highest LOD to be imported.
  51. string sourcePath = (string)mesh["path"];
  52. string destPath = Path.Combine(modelsFolderPath, (string)mesh["nameOverride"]);
  53. ImportMesh(sourcePath, destPath);
  54. importedGeometryPaths.Add(destPath);
  55. if(!importLODs)
  56. {
  57. break;
  58. }
  59. }
  60. }
  61. }
  62. importedGeometryPaths3DPlant.Add(importedGeometryPaths);
  63. }
  64. prefabData.importedGeometryPaths3DPlant = importedGeometryPaths3DPlant;
  65. if(createPrefabs)
  66. CreatePrefab3DPlant(prefabData);
  67. }
  68. else
  69. {
  70. List<string> importedGeometryPaths3D = new List<string>();
  71. bool lodMatched = false; // This flag helps to import the lower lods once the active lod is found.
  72. foreach (JObject mesh in lodList)
  73. {
  74. string currentLOD = (string)mesh["lod"];
  75. if (lodMatched || (currentLOD == activeLOD) || highpoly)
  76. {
  77. lodMatched = true;
  78. if ((currentLOD == "high") && !highpoly)
  79. {
  80. continue;
  81. }
  82. //get the path of the highest LOD to be imported.
  83. string sourcePath = (string)mesh["path"];
  84. string destPath = Path.Combine(modelsFolderPath, (string)mesh["nameOverride"]);
  85. ImportMesh(sourcePath, destPath);
  86. importedGeometryPaths3D.Add(destPath);
  87. if (!importLODs)
  88. {
  89. break;
  90. }
  91. }
  92. }
  93. prefabData.importedGeometryPaths3D = importedGeometryPaths3D;
  94. if (createPrefabs)
  95. {
  96. if (MegascansUtilities.isScatterAsset(assetJson, importedGeometryPaths3D))
  97. {
  98. CreatePrefabsScatter(prefabData);
  99. }
  100. else
  101. {
  102. CreatePrefab3D(prefabData);
  103. }
  104. }
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. Debug.Log("Exception::MegascansMeshUtils::Processing Meshes:: " + ex.ToString());
  110. MegascansUtilities.HideProgressBar();
  111. }
  112. }
  113. static void ImportMesh(string sourcePath, string destPath)
  114. {
  115. MegascansUtilities.UpdateProgressBar(1.0f, "Importing Megascans Asset", "Importing Mesh...");
  116. MegascansUtilities.CopyFileToProject(sourcePath, destPath);
  117. }
  118. /// <summary>
  119. /// Generates prefabs from imported meshes.
  120. /// Used for normal 3D assets
  121. /// </summary>
  122. public static void CreatePrefab3D(PrefabData prefabData)
  123. {
  124. try {
  125. string prefabPath = MegascansUtilities.ValidateFolderCreate(prefabData.assetPath, "Prefabs");
  126. string prefabName = prefabData.modelNamingConvention;
  127. //Setting up prefab gameobject
  128. GameObject prefabGameObject = new GameObject();
  129. prefabGameObject.name = prefabName;
  130. prefabGameObject.isStatic = true;
  131. if (prefabData.setupLODs)
  132. {
  133. prefabGameObject.AddComponent<LODGroup>();
  134. prefabGameObject.GetComponent<LODGroup>().fadeMode = (LODFadeMode)prefabData.lodFadeMode; //Casting lod fade mode to enum.
  135. prefabGameObject.GetComponent<LODGroup>().animateCrossFading = true;
  136. }
  137. List<LOD> lodsForPrefab = new List<LOD>();
  138. int numberOfFiles = prefabData.importedGeometryPaths3D.Count;
  139. List<float> lodHeights = MegascansUtilities.getLODHeightList(numberOfFiles);
  140. //Instantiate all the meshes in the scene, add them to the material/collider to them.
  141. for (int x = 0; (x < numberOfFiles && x < 8); x++)
  142. {
  143. UnityEngine.Object loadedGeometry = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(prefabData.importedGeometryPaths3D[x]);
  144. //Highpoly mesh check.
  145. if (loadedGeometry.name.ToLower().Contains("highpoly") && !prefabData.highpoly)
  146. {
  147. continue;
  148. }
  149. GameObject geometryObject = Instantiate(loadedGeometry) as GameObject;
  150. Renderer[] r;
  151. //Parent all the objects to the prefab game object.
  152. if (geometryObject.transform.childCount > 0 && !prefabData.isAlembic)
  153. {
  154. r = new Renderer[geometryObject.transform.childCount];
  155. for (int j = 0; j < geometryObject.transform.childCount; ++j)
  156. {
  157. //Parent the child gameobject (geometry) to the prefab game object.
  158. GameObject geometryChildObject = geometryObject.transform.GetChild(j).gameObject; //Cache a reference to the child gameobject of the geometry.
  159. geometryChildObject.transform.parent = prefabGameObject.transform;
  160. geometryChildObject.transform.localPosition = Vector3.zero;
  161. geometryChildObject.name = geometryChildObject.name.Replace("(Clone)", "");
  162. r[j] = geometryChildObject.GetComponentInChildren<Renderer>();
  163. }
  164. //Destroy the empty parent container which was holding the meshes.
  165. DestroyImmediate(geometryObject);
  166. }
  167. else if (prefabData.isAlembic) //if the instantiated mesh is an alembic asset.
  168. {
  169. //Parent the child gameobject (geometry) to the prefab game object.
  170. geometryObject.transform.parent = prefabGameObject.transform;
  171. geometryObject.transform.localPosition = Vector3.zero;
  172. geometryObject.name = geometryObject.name.Replace("(Clone)", "");
  173. r = geometryObject.GetComponentsInChildren<Renderer>();
  174. }
  175. else //if the instantiated mesh does not have any children
  176. {
  177. //Parent the child gameobject (geometry) to the prefab game object.
  178. geometryObject.transform.parent = prefabGameObject.transform;
  179. geometryObject.transform.localPosition = Vector3.zero;
  180. geometryObject.name = geometryObject.name.Replace("(Clone)", "");
  181. r = geometryObject.GetComponentsInChildren<Renderer>();
  182. }
  183. foreach (Renderer ren in r)
  184. {
  185. ren.material = prefabData.finalMat;
  186. //Apply collision
  187. if (prefabData.setupCollision)
  188. ren.gameObject.AddComponent<MeshCollider>().sharedMesh = ren.gameObject.GetComponent<MeshFilter>().sharedMesh;
  189. }
  190. if (prefabData.setupLODs)
  191. {
  192. lodsForPrefab.Add(new LOD(lodHeights[0], r));
  193. lodHeights.RemoveAt(0);
  194. } else //We only set the prefab with 1 LOD if setup LODs is unchecked.
  195. break;
  196. }
  197. //Set LODs in the LOD group
  198. if (prefabData.setupLODs)
  199. {
  200. prefabGameObject.GetComponent<LODGroup>().SetLODs(lodsForPrefab.ToArray());
  201. prefabGameObject.GetComponent<LODGroup>().RecalculateBounds();
  202. }
  203. //Prefab saving
  204. string prefLocation = prefabPath + "/" + prefabName + ".prefab";
  205. prefLocation = prefLocation.Replace("(Clone)", "");
  206. SavePrefab(prefabGameObject, prefLocation, prefabData.addAssetToScene);
  207. }
  208. catch (Exception ex)
  209. {
  210. Debug.Log("Exception::MegascansMeshUtils::3D Asset Prefab:: " + ex.ToString());
  211. MegascansUtilities.HideProgressBar();
  212. }
  213. }
  214. /// <summary>
  215. /// Creates prefabs from the newer assets on bridge, has an option for billboard materials on plants.
  216. /// </summary>
  217. /// <param name="hasBillboard"></param>
  218. /// <returns></returns>
  219. public static void CreatePrefab3DPlant(PrefabData prefabData)
  220. {
  221. try
  222. {
  223. string prefabPath = MegascansUtilities.ValidateFolderCreate(prefabData.assetPath, "Prefabs");
  224. List<GameObject> prefabObjects = new List<GameObject>();
  225. for (int i = 0; i < prefabData.importedGeometryPaths3DPlant.Count; i++)
  226. {
  227. string prefabName = prefabData.modelNamingConvention + "_Var" + (i + 1).ToString();
  228. //Setting up prefab gameobject
  229. GameObject prefabGameObject = new GameObject();
  230. prefabGameObject.name = prefabName;
  231. prefabGameObject.isStatic = true;
  232. if (prefabData.setupLODs)
  233. {
  234. prefabGameObject.AddComponent<LODGroup>();
  235. prefabGameObject.GetComponent<LODGroup>().fadeMode = (LODFadeMode)prefabData.lodFadeMode; //Casting lod fade mode to enum.
  236. prefabGameObject.GetComponent<LODGroup>().animateCrossFading = true;
  237. }
  238. List<LOD> lodsForPrefab = new List<LOD>();
  239. int numberOfFiles = prefabData.importedGeometryPaths3DPlant[i].Count;
  240. List<float> lodHeights = MegascansUtilities.getLODHeightList(numberOfFiles);
  241. //Instantiate all the meshes in the scene, add them to the material/collider to them.
  242. for (int x = 0; (x < numberOfFiles && x < 8); x++)
  243. {
  244. UnityEngine.Object loadedGeometry = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(prefabData.importedGeometryPaths3DPlant[i][x]);
  245. //Highpoly mesh check.
  246. if (loadedGeometry.name.ToLower().Contains("highpoly") && !prefabData.highpoly)
  247. {
  248. continue;
  249. }
  250. GameObject geometryObject = Instantiate(loadedGeometry) as GameObject;
  251. Renderer[] r;
  252. //Parent all the objects to the prefab game object.
  253. if (geometryObject.transform.childCount > 0 && !prefabData.isAlembic)
  254. {
  255. r = new Renderer[geometryObject.transform.childCount];
  256. for (int j = 0; j < geometryObject.transform.childCount; ++j)
  257. {
  258. //Parent the child gameobject (geometry) to the prefab game object.
  259. GameObject geometryChildObject = geometryObject.transform.GetChild(j).gameObject; //Cache a reference to the child gameobject of the geometry.
  260. geometryChildObject.transform.parent = prefabGameObject.transform;
  261. geometryChildObject.transform.localPosition = Vector3.zero;
  262. geometryChildObject.name = geometryChildObject.name.Replace("(Clone)", "");
  263. r[j] = geometryChildObject.GetComponent<Renderer>();
  264. }
  265. //Destroy the empty parent container which was holding the meshes.
  266. DestroyImmediate(geometryObject);
  267. }
  268. else if (prefabData.isAlembic) //if the instantiated mesh is an alembic asset.
  269. {
  270. //Parent the child gameobject (geometry) to the prefab game object.
  271. geometryObject.transform.parent = prefabGameObject.transform;
  272. geometryObject.transform.localPosition = Vector3.zero;
  273. geometryObject.name = geometryObject.name.Replace("(Clone)", "");
  274. r = geometryObject.GetComponentsInChildren<Renderer>();
  275. }
  276. else //if the instantiated mesh does not have any children
  277. {
  278. r = new Renderer[1];
  279. //Parent the child gameobject (geometry) to the prefab game object.
  280. geometryObject.transform.parent = prefabGameObject.transform;
  281. geometryObject.transform.localPosition = Vector3.zero;
  282. geometryObject.name = geometryObject.name.Replace("(Clone)", "");
  283. r[0] = geometryObject.GetComponent<Renderer>();
  284. }
  285. foreach (Renderer ren in r)
  286. {
  287. ren.material = prefabData.finalMat;
  288. //Billboard material application
  289. if (prefabData.hasBillboardLOD && x == (numberOfFiles - 1))
  290. {
  291. ren.material = prefabData.billboardMat;
  292. }
  293. //Apply collision
  294. if (prefabData.setupCollision)
  295. ren.gameObject.AddComponent<MeshCollider>().sharedMesh = ren.gameObject.GetComponent<MeshFilter>().sharedMesh;
  296. }
  297. if (prefabData.setupLODs)
  298. {
  299. lodsForPrefab.Add(new LOD(lodHeights[0], r));
  300. lodHeights.RemoveAt(0);
  301. }
  302. else
  303. break;
  304. }
  305. //Set LODs in the LOD group
  306. if (prefabData.setupLODs)
  307. {
  308. prefabGameObject.GetComponent<LODGroup>().SetLODs(lodsForPrefab.ToArray());
  309. prefabGameObject.GetComponent<LODGroup>().RecalculateBounds();
  310. }
  311. //Prefab saving
  312. string prefLocation = prefabPath + "/" + prefabName + ".prefab";
  313. prefLocation = prefLocation.Replace("(Clone)", "");
  314. GameObject prefabObject = SavePrefab(prefabGameObject, prefLocation, prefabData.addAssetToScene);
  315. if (prefabObject)
  316. prefabObjects.Add(prefabObject);
  317. }
  318. //Setting up variation holder gameobject
  319. if (prefabData.addAssetToScene)
  320. {
  321. GameObject plantsParent = new GameObject(prefabData.assetName);
  322. plantsParent.isStatic = true;
  323. foreach (GameObject variation in prefabObjects)
  324. {
  325. variation.transform.parent = plantsParent.transform;
  326. }
  327. }
  328. }
  329. catch (Exception ex)
  330. {
  331. Debug.Log("Exception::MegascansMeshUtils::3D Plant Prefab:: " + ex.ToString());
  332. MegascansUtilities.HideProgressBar();
  333. }
  334. }
  335. /// <summary>
  336. /// Creates prefabs for the 3D Scatter assets.
  337. /// </summary>
  338. /// <param name="hasBillboard"></param>
  339. /// <returns></returns>
  340. public static void CreatePrefabsScatter(PrefabData prefabData)
  341. {
  342. try
  343. {
  344. string prefabPath = MegascansUtilities.ValidateFolderCreate(prefabData.assetPath, "Prefabs");
  345. int numberOfVariations = MegascansUtilities.GetMeshChildrenCount(prefabData.importedGeometryPaths3D);
  346. List<GameObject> prefabObjects = new List<GameObject>();
  347. for (int i = 0; i < numberOfVariations; i++)
  348. {
  349. string prefabName = prefabData.modelNamingConvention + "_Var" + (i + 1).ToString();
  350. //Setting up prefab gameobject
  351. GameObject prefabGameObject = new GameObject();
  352. prefabGameObject.name = prefabName;
  353. prefabGameObject.isStatic = true;
  354. if (prefabData.setupLODs)
  355. {
  356. prefabGameObject.AddComponent<LODGroup>();
  357. prefabGameObject.GetComponent<LODGroup>().fadeMode = (LODFadeMode)prefabData.lodFadeMode; //Casting lod fade mode to enum.
  358. prefabGameObject.GetComponent<LODGroup>().animateCrossFading = true;
  359. }
  360. List<LOD> lodsForPrefab = new List<LOD>();
  361. int numberOfFiles = prefabData.importedGeometryPaths3D.Count;
  362. List<float> lodHeights = MegascansUtilities.getLODHeightList(numberOfFiles);
  363. //Instantiate all the meshes in the scene, add them to the material/collider to them.
  364. for (int x = 0; (x < numberOfFiles && x < 8); x++)
  365. {
  366. UnityEngine.Object loadedGeometry = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(prefabData.importedGeometryPaths3D[x]);
  367. //Highpoly mesh check.
  368. if (loadedGeometry.name.ToLower().Contains("highpoly") && !prefabData.highpoly)
  369. {
  370. continue;
  371. }
  372. GameObject geometryObject = Instantiate(loadedGeometry) as GameObject;
  373. Renderer[] r;
  374. if (prefabData.isAlembic) //if the instantiated mesh is an alembic asset.
  375. {
  376. //Get all variations in a LOD
  377. List<Transform> varsInLOD = new List<Transform>();
  378. foreach (Transform var in geometryObject.transform)
  379. {
  380. varsInLOD.Add(var);
  381. }
  382. //Delete all the other variations in the LOD object
  383. for (int y = 0; y < varsInLOD.Count; y++)
  384. {
  385. //If variation does not match one currently being processed.
  386. if (y != i)
  387. {
  388. DestroyImmediate(varsInLOD[y].gameObject);
  389. }
  390. }
  391. //Parent the child gameobject (geometry) to the prefab game object.
  392. geometryObject.transform.parent = prefabGameObject.transform;
  393. geometryObject.transform.localPosition = Vector3.zero;
  394. geometryObject.name = geometryObject.name.Replace("(Clone)", "");
  395. r = geometryObject.GetComponentsInChildren<Renderer>();
  396. }
  397. else//if the instantiated mesh is a scatter type asset.
  398. {
  399. //Get all variations in a LOD
  400. List<Transform> varsInLOD = new List<Transform>();
  401. foreach (Transform var in geometryObject.transform)
  402. {
  403. varsInLOD.Add(var);
  404. }
  405. //Delete all the other variations in the LOD object
  406. for(int y = 0; y < varsInLOD.Count; y++)
  407. {
  408. //If variation does not match one currently being processed.
  409. if(y!=i)
  410. {
  411. DestroyImmediate(varsInLOD[y].gameObject);
  412. }
  413. }
  414. //Parent the child gameobject (geometry) to the prefab game object.
  415. geometryObject.transform.parent = prefabGameObject.transform;
  416. geometryObject.transform.localPosition = Vector3.zero;
  417. geometryObject.name = geometryObject.name.Replace("(Clone)", "");
  418. r = geometryObject.GetComponentsInChildren<Renderer>();
  419. }
  420. foreach (Renderer ren in r)
  421. {
  422. ren.material = prefabData.finalMat;
  423. //Apply collision
  424. if (prefabData.setupCollision)
  425. ren.gameObject.AddComponent<MeshCollider>().sharedMesh = ren.gameObject.GetComponent<MeshFilter>().sharedMesh;
  426. }
  427. if (prefabData.setupLODs)
  428. {
  429. lodsForPrefab.Add(new LOD(lodHeights[0], r));
  430. lodHeights.RemoveAt(0);
  431. }
  432. else
  433. break;
  434. }
  435. //Set LODs in the LOD group
  436. if (prefabData.setupLODs)
  437. {
  438. prefabGameObject.GetComponent<LODGroup>().SetLODs(lodsForPrefab.ToArray());
  439. prefabGameObject.GetComponent<LODGroup>().RecalculateBounds();
  440. }
  441. //Prefab saving
  442. string prefLocation = prefabPath + "/" + prefabName + ".prefab";
  443. prefLocation = prefLocation.Replace("(Clone)", "");
  444. GameObject prefabObject = SavePrefab(prefabGameObject, prefLocation, prefabData.addAssetToScene);
  445. if (prefabObject)
  446. prefabObjects.Add(prefabObject);
  447. }
  448. //Setting up variation holder gameobject
  449. if (prefabData.addAssetToScene)
  450. {
  451. GameObject scatterParent = new GameObject(prefabData.assetName);
  452. scatterParent.isStatic = true;
  453. foreach (GameObject variation in prefabObjects)
  454. {
  455. variation.transform.parent = scatterParent.transform;
  456. }
  457. }
  458. }
  459. catch (Exception ex)
  460. {
  461. Debug.Log("Exception::MegascansMeshUtils::3D Asset Prefab:: " + ex.ToString());
  462. MegascansUtilities.HideProgressBar();
  463. }
  464. }
  465. static GameObject SavePrefab(GameObject prefabGo, string savePath, bool addAssetToScene = false)
  466. {
  467. try
  468. {
  469. //Set all children objects of the prefab to static
  470. Transform[] allChildren = prefabGo.GetComponentsInChildren<Transform>();
  471. foreach (Transform child in allChildren)
  472. {
  473. child.gameObject.isStatic = true;
  474. }
  475. GameObject newPrefabObject = prefabGo;
  476. MegascansUtilities.UpdateProgressBar(1.0f, "Importing Megascans Asset", "Creating Prefab...");
  477. #if UNITY_5 || UNITY_2017 || UNITY_2018
  478. UnityEngine.Object existingPrefab = AssetDatabase.LoadAssetAtPath(savePath, typeof(UnityEngine.Object));
  479. if (!existingPrefab)
  480. PrefabUtility.CreatePrefab(savePath, prefabGo);
  481. else
  482. PrefabUtility.ReplacePrefab(prefabGo, existingPrefab, ReplacePrefabOptions.ReplaceNameBased);
  483. #else
  484. PrefabUtility.SaveAsPrefabAsset(prefabGo, savePath);
  485. #endif
  486. DestroyImmediate(prefabGo);
  487. if (addAssetToScene)
  488. {
  489. UnityEngine.Object prefabObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(savePath);
  490. newPrefabObject = (GameObject)PrefabUtility.InstantiatePrefab(prefabObject);
  491. newPrefabObject.isStatic = true;
  492. }
  493. return newPrefabObject;
  494. }
  495. catch (Exception ex)
  496. {
  497. Debug.Log("Exception::MegascansMeshUtils::Saving Prefab:: " + ex.ToString());
  498. MegascansUtilities.HideProgressBar();
  499. return null;
  500. }
  501. }
  502. public static bool ContainsLowestLOD(JArray lodList, string minLOD, string activeLOD)
  503. {
  504. bool importLODs = EditorPrefs.GetBool("QuixelDefaultImportLODs", true);
  505. if (importLODs)
  506. {
  507. for (int i = 0; i < lodList.Count; i++)
  508. {
  509. JObject meshData = (JObject)lodList[i];
  510. if ((string)meshData["lod"] == minLOD)
  511. return true;
  512. }
  513. return false;
  514. } else
  515. {
  516. return (activeLOD.ToLower() == minLOD.ToLower());
  517. }
  518. }
  519. }
  520. public struct PrefabData
  521. {
  522. public string assetPath;
  523. public string assetName;
  524. public string modelNamingConvention;
  525. public int lodFadeMode;
  526. public bool highpoly;
  527. public bool addAssetToScene;
  528. public bool setupCollision;
  529. public bool hasBillboardLOD;
  530. public bool isAlembic;
  531. public bool isScatterAsset;
  532. public bool setupLODs;
  533. public Material finalMat;
  534. public Material billboardMat;
  535. public List<string> importedGeometryPaths3D;
  536. public List<List<string>> importedGeometryPaths3DPlant;
  537. public PrefabData(string assetPath, string assetName, string modelNamingConvention, int lodFadeMode, bool highpoly, bool addAssetToScene, bool setupCollision, bool hasBillboardLOD, bool isAlembic, bool isScatterAsset, bool setupLODs, Material finalMat, Material billboardMat, List<string> importedGeometryPaths3D, List<List<string>> importedGeometryPaths3DPlant)
  538. {
  539. this.assetPath = assetPath;
  540. this.assetName = assetName;
  541. this.modelNamingConvention = modelNamingConvention;
  542. this.lodFadeMode = lodFadeMode;
  543. this.highpoly = highpoly;
  544. this.addAssetToScene = addAssetToScene;
  545. this.setupCollision = setupCollision;
  546. this.hasBillboardLOD = hasBillboardLOD;
  547. this.isAlembic = isAlembic;
  548. this.isScatterAsset = isScatterAsset;
  549. this.setupLODs = setupLODs;
  550. this.finalMat = finalMat;
  551. this.billboardMat = billboardMat;
  552. this.importedGeometryPaths3D = importedGeometryPaths3D;
  553. this.importedGeometryPaths3DPlant = importedGeometryPaths3DPlant;
  554. }
  555. }
  556. }
  557. #endif