public void PopulateValuesFromAssetSchematic(AssetSchematic schematic) { //Debug.Log("Populating values."); //Origin & Description this.item_id = schematic.origin_and_description.mcs_id; this.item_name = schematic.origin_and_description.name; this.collection_id = schematic.origin_and_description.collection_id; this.collection_name = schematic.origin_and_description.collection_name; this.vendorId = schematic.origin_and_description.vendor_id; //Version this.collection_version = schematic.version_and_control.collection_version; this.item_version = schematic.version_and_control.item_version; this.mcs_version = schematic.version_and_control.mcs_version; //Type & function this.function = schematic.type_and_function.item_function; this.rank = schematic.type_and_function.hierarchy_rank; // TODO: Should be using AssetSchematic.ItemStructure instead. this.schematic = new ItemSchematic(); this.schematic.lods = schematic.structure_and_physics.item_structure.lods; this.schematic.persistent = schematic.structure_and_physics.item_structure.persistent; if (this.function != ItemFunction.figure) { this.compatibilities = new ItemCompatibilities(); this.compatibilities.figures = schematic.version_and_control.compatibilities; } DownConvertDarwinSpecToProtoSpec(); }
//Async call to load gameobjects right now //todo: change this to load all types of objects public MCSObjectLoader LoadAnyType(AssetSchematic data) { MCSObjectLoader loader = new MCSObjectLoader(); StartCoroutine(DownloadAny(data, loader)); return(loader); }
IEnumerator AssetBundleStreamer(AssetSchematic schematic, MCSObjectLoader loader) { var datetime = DateTime.Now; //TODO: this is commented out to prevent errors with Wii U compiles /* * while (!Caching.ready) * yield return null; */ using (WWW www = WWW.LoadFromCacheOrDownload(schematic.stream_and_path.url, Convert.ToInt32(schematic.version_and_control.item_version))) { while (!www.isDone) { loader.progress = www.progress * 100; yield return(0); } if (www.error != null) { throw new Exception("Download of " + schematic.origin_and_description.mcs_id + " has failed. Error: " + www.error); } AssetBundle bundle = www.assetBundle; float difference = (float)System.DateTime.Now.Subtract(datetime).TotalMilliseconds; loader.Complete(bundle.LoadAsset(schematic.origin_and_description.name), difference); bundle.Unload(false); } }
public void AttachingCIItemToNode(GameObject currentNode, AssetSchematic schematic) { switch (schematic.type_and_function.item_function) { case ItemFunction.soft_wearable: CIclothing ciclothing = currentNode.AddComponent <CIclothing>(); ciclothing.meshType = CONSTANTS.MESH_TYPE.CLOTH; ciclothing.dazName = schematic.origin_and_description.name; ciclothing.ID = schematic.origin_and_description.mcs_id; if (schematic.structure_and_physics.item_structure.alpha_masks_key != null) { for (int i = 0; i < schematic.structure_and_physics.item_structure.alpha_masks_key.Count(); i++) { string slot = schematic.structure_and_physics.item_structure.alpha_masks_key[i]; string path = schematic.structure_and_physics.item_structure.alpha_masks[i]; switch (slot) { case "BODY": ciclothing.alphaMasks[CONSTANTS.MATERIAL_SLOT.BODY] = GetTextureFromPath(path, basePath); break; case "HEAD": ciclothing.alphaMasks[CONSTANTS.MATERIAL_SLOT.HEAD] = GetTextureFromPath(path, basePath); break; case "EYE": //do nothing, we don't support this slot yet break; } } } break; case ItemFunction.hair: CIhair cihair = currentNode.AddComponent <CIhair>(); if (schematic.structure_and_physics.item_structure.overlay != null) { cihair.overlay = GetTextureFromPath(schematic.structure_and_physics.item_structure.overlay, basePath); cihair.overlayColor = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.item_structure.overlay_color); } cihair.meshType = CONSTANTS.MESH_TYPE.HAIR; cihair.dazName = schematic.origin_and_description.name; cihair.ID = schematic.origin_and_description.mcs_id; break; case ItemFunction.prop: CIprop ciprop = currentNode.AddComponent <CIprop>(); ciprop.meshType = CONSTANTS.MESH_TYPE.PROP; ciprop.dazName = schematic.origin_and_description.name; ciprop.ID = schematic.origin_and_description.mcs_id; break; } }
//These are direct calls to load things from the resources folder; public GameObject LoadPrefabFromResources(AssetSchematic data) { GameObject gameO = null; string localpath = data.stream_and_path.generated_path.Replace(".prefab", ""); localpath = localpath.Replace("Assets/MCS/Resources/", ""); gameO = Resources.Load(localpath, typeof(GameObject)) as GameObject; return(gameO); }
public Material LoadMaterialFromResources(AssetSchematic data) { Material gameO = null; string localpath = data.stream_and_path.generated_path.Replace(".mat", ""); localpath = localpath.Replace("Assets/MCS/Resources/", ""); gameO = Resources.Load(localpath, typeof(Material)) as Material; return(gameO); }
public static Material GetMaterialFromGUIDEditor(string guid, string basePath) { AssetSchematic schematic = new AssetSchematic(); if (schematicLookup.TryGetValue(guid, out schematic)) { try { if (schematic != null && schematic.origin_and_description != null && schematic.origin_and_description.mcs_id != null && schematic.origin_and_description.mcs_id.Equals(guid)) { string matPath = MCS_Utilities.Paths.ConvertRelativeToAbsolute(basePath, schematic.stream_and_path.generated_path); //fix for maya matPath = matPath.Replace(":", "_"); Material m = AssetDatabase.LoadAssetAtPath <Material>(matPath); return(m); } } catch (Exception e) { UnityEngine.Debug.LogException(e); } } else { string[] paths = Directory.GetFiles(basePath, "*.mon", SearchOption.AllDirectories); foreach (string path in paths) { try { schematic = AssetSchematic.CreateFromJSON(File.ReadAllText(path)); if (schematic != null && schematic.origin_and_description != null && schematic.origin_and_description.mcs_id != null && schematic.origin_and_description.mcs_id.Equals(guid)) { string monDir = MCS_Utilities.Paths.ConvertFileToDir(path); string matPath = MCS_Utilities.Paths.ConvertRelativeToAbsolute(monDir, schematic.stream_and_path.generated_path); Material m = AssetDatabase.LoadAssetAtPath <Material>(matPath); return(m); } } catch (Exception e) { UnityEngine.Debug.LogException(e); } } } UnityEngine.Debug.LogWarning("Failed to locate material for GUID: " + guid); return(null); }
public void AttachCoreMeshToNode(GameObject currentNode, AssetSchematic schematic, AssetSchematic rootSchematic) { CoreMesh coreMesh = currentNode.GetComponent <CoreMesh>(); if (coreMesh == null) { coreMesh = currentNode.AddComponent <CoreMesh>(); } //where are the runtime morph files (they are in a resources folder that artist tools exports from projection) coreMesh.runtimeMorphPath = rootSchematic.origin_and_description.vendor_name + "/" + rootSchematic.origin_and_description.collection_name + "/" + rootSchematic.origin_and_description.name + "/" + currentNode.name; //clean the path up coreMesh.runtimeMorphPath = coreMesh.runtimeMorphPath.Replace(" ", "_"); Regex regex = new Regex(@"[^a-zA-Z0-9-_/]+"); //TODO: this regex or formatting should come from streaming morphs or morph extraction, not here coreMesh.runtimeMorphPath = regex.Replace(coreMesh.runtimeMorphPath, ""); coreMesh.dazName = ""; //this can't be null, but it can be blank switch (schematic.type_and_function.item_function) { case ItemFunction.soft_wearable: coreMesh.meshType = CONSTANTS.MESH_TYPE.CLOTH; break; case ItemFunction.hair: coreMesh.meshType = CONSTANTS.MESH_TYPE.HAIR; break; case ItemFunction.figure: coreMesh.meshType = CONSTANTS.MESH_TYPE.BODY; break; case ItemFunction.prop: coreMesh.meshType = CONSTANTS.MESH_TYPE.PROP; break; } if (schematic.structure_and_physics.item_structure.assigned_materials != null) { Renderer renderer = currentNode.GetComponent <Renderer>(); if (renderer != null) { Material[] mats = new Material[schematic.structure_and_physics.item_structure.assigned_materials.Length]; for (int i = 0; i < schematic.structure_and_physics.item_structure.assigned_materials.Length; i++) { string matGUID = schematic.structure_and_physics.item_structure.assigned_materials[i]; mats[i] = GetMaterialFromGUID(matGUID, basePath); } renderer.sharedMaterials = mats; } } }
IEnumerator TextureStreamer(AssetSchematic schematic, MCSObjectLoader loader) { Dictionary <string, Texture2D> textures = new Dictionary <string, Texture2D> (); Dictionary <string, string> texturePaths = new Dictionary <string, string> (); if (schematic.structure_and_physics.material_structure.albedo != null && schematic.structure_and_physics.material_structure.albedo != "") { texturePaths.Add("albedo", schematic.structure_and_physics.material_structure.albedo); } if (schematic.structure_and_physics.material_structure.metal != null && schematic.structure_and_physics.material_structure.metal != "") { texturePaths.Add("metal", schematic.structure_and_physics.material_structure.metal); } if (schematic.structure_and_physics.material_structure.normal != null && schematic.structure_and_physics.material_structure.normal != "") { texturePaths.Add("normal", schematic.structure_and_physics.material_structure.normal); } var datetime = DateTime.Now; //TODO: this is commented out to prevent errors with Wii U compiles /* * while (!Caching.ready) * yield return null; */ foreach (KeyValuePair <string, string> entry in texturePaths) { using (WWW www = new WWW(entry.Value)) { while (!www.isDone) { loader.progress += www.progress * 100 / texturePaths.Count; yield return(0); } if (www.error != null) { throw new Exception("Download of " + entry.Key + "from: " + entry.Value + " has failed. Error: " + www.error); } Texture2D streamedTexture = www.texture; if (streamedTexture != null) { textures.Add(entry.Key, streamedTexture); } } } AssetCreator ac = new AssetCreator(); float difference = (float)System.DateTime.Now.Subtract(datetime).TotalMilliseconds; loader.Complete(ac.CreateMorphMaterial(schematic, textures), difference); }
protected void GetAllSchematicsFromNodes(GameObject currentNode, Dictionary <string, AssetSchematic> schematicLookup) { AssetSchematic schematic = GetSchematicFromGameObject(currentNode, schematicLookup); if (schematic != null) { schematics.Add(schematic); } for (int i = 0; i < currentNode.transform.childCount; i++) { GetAllSchematicsFromNodes(currentNode.transform.GetChild(i).gameObject, schematicLookup); } }
IEnumerator DownloadAny(AssetSchematic schematic, MCSObjectLoader loader) { var datetime = DateTime.Now; if (GetObjectCache().ContainsKey(schematic.origin_and_description.mcs_id)) { //load it from the cache list yield return(new WaitForSeconds(0)); loader.progress = 100; float difference = (float)System.DateTime.Now.Subtract(datetime).TotalMilliseconds; loader.Complete(GetObjectCache()[schematic.origin_and_description.mcs_id], difference); } else if (schematic.stream_and_path.generated_path != null && schematic.stream_and_path.generated_path != "") { //load it from disk yield return(new WaitForSeconds(0)); loader.progress = 100; float difference = (float)System.DateTime.Now.Subtract(datetime).TotalMilliseconds; switch (schematic.type_and_function.primary_function) { case MCS.Utility.Schematic.Enumeration.PrimaryFunction.item: loader.Complete(LoadPrefabFromResources(schematic), difference); break; case MCS.Utility.Schematic.Enumeration.PrimaryFunction.material: loader.Complete(LoadMaterialFromResources(schematic), difference); break; default: loader.Complete(LoadPrefabFromResources(schematic), difference); break; } } else if (schematic.type_and_function.primary_function == MCS.Utility.Schematic.Enumeration.PrimaryFunction.material) { StartCoroutine(TextureStreamer(schematic, loader)); } else if (schematic.stream_and_path.url != null && schematic.stream_and_path.url != "") { StartCoroutine(AssetBundleStreamer(schematic, loader)); } else { Debug.LogWarning("Object: " + schematic.origin_and_description.name + " with id: " + schematic.origin_and_description.mcs_id + " was not found"); } }
public MCSObjectLoader LoadFromUrl(AssetSchematic data) { MCSObjectLoader loader = new MCSObjectLoader(); if (data.type_and_function.primary_function == MCS.Utility.Schematic.Enumeration.PrimaryFunction.material) { StartCoroutine(TextureStreamer(data, loader)); } else { StartCoroutine(AssetBundleStreamer(data, loader)); } return(loader); }
public void UpsertItem(AssetSchematic data) { if (AssetSchematicList == null) { AssetSchematicList = new List <AssetSchematic> (); } if (AssetSchematicList.Select(x => x.origin_and_description.mcs_id == data.origin_and_description.mcs_id) == null) { //does not exist AssetSchematicList.Add(data); } else { //exists already AssetSchematicList.RemoveAll(x => x.origin_and_description.mcs_id == data.origin_and_description.mcs_id); AssetSchematicList.Add(data); } }
public static bool TryToImportMaterialsFromSchematics(string str, string dirMon, AssetSchematic[] schematics) { bool materialCreationStatus = true; AssetCreator ac = new AssetCreator(); //let's look for any materials in the mon file, if we find any create and import them now before we move on for (int i = 0; i < schematics.Length && materialCreationStatus; i++) { AssetSchematic mon = schematics[i]; if (mon.origin_and_description != null && !String.IsNullOrEmpty(mon.origin_and_description.mcs_id)) { schematicLookup[mon.origin_and_description.mcs_id] = mon; } if (mon.type_and_function.artisttools_function == ArtistToolsFunction.material || mon.type_and_function.primary_function == PrimaryFunction.material) { try { Dictionary <string, Texture2D> textureDict = new Dictionary <string, Texture2D>(); bool textureLoadStatus = TextureLoader.GetTextures(mon, dirMon, out textureDict); if (textureLoadStatus == false) { //UnityEngine.Debug.LogError("Failed to find textures for material: " + str); continue; } Material mat = ac.CreateMorphMaterial(mon, textureDict); if (mon.stream_and_path.generated_path == "" || mon.stream_and_path.generated_path == null) { //mon.stream_and_path.generated_path = GENERATED_MATERIALS_FOLDER + "/" + mon.origin_and_description.name + ".mat"; string newDir = dirMon + "/Materials"; if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); } mon.stream_and_path.generated_path = "Materials/" + mon.origin_and_description.name + ".mat"; } int pos = mon.stream_and_path.generated_path.LastIndexOf('/'); string directoryPath = mon.stream_and_path.generated_path.Substring(0, pos); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } //does a material already exist, if so, replace over it string dstPath = MCS_Utilities.Paths.ConvertRelativeToAbsolute(dirMon, mon.stream_and_path.generated_path); //Convert incompatible maya ":" to "_" dstPath = dstPath.Replace(":", "_"); //UnityEngine.Debug.Log("dstPath: " + dstPath); if (!File.Exists(dstPath)) { AssetDatabase.CreateAsset(mat, dstPath); } else { Material oldMat = AssetDatabase.LoadAssetAtPath <Material>(dstPath); if (oldMat == null) { //UnityEngine.Debug.LogError("Unable to update material because we can't load it: " + dstPath); } else { oldMat.CopyPropertiesFromMaterial(mat); } } } catch (Exception e) { Debug.LogWarning("Material creation failed. " + e.Message); materialCreationStatus = false; } } } return(materialCreationStatus); }
public void DeleteItem(AssetSchematic data) { AssetSchematicList.RemoveAll(x => x.origin_and_description.mcs_id == data.origin_and_description.mcs_id); }
//pass in an id and get a coreMeshData in return public AssetSchematic GetItemData(string id) { AssetSchematic result = GetContentLibrary().AssetSchematicList.Where(x => x.origin_and_description.mcs_id == id).SingleOrDefault(); return(result); }
/// <summary> /// Deserializes the mon file. Path needs to be within the assets folder /// </summary> /// <returns>The mon file.</returns> /// <param name="path">Path.</param> public AssetSchematic[] DeserializeMonFile(string path) { string revisedPath = path.Replace("Assets", ""); string result = ""; try { string streamPath = Application.dataPath + revisedPath; using (FileStream fs = new FileStream(streamPath, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line; while ((line = sr.ReadLine()) != null) { result += line; } } } } catch (Exception e) { Debug.LogError("Caught exception while processing mon file: " + path); Debug.LogException(e); } AssetSchematic[] schematics = null; if (result != null) { //try a multi one first try { schematics = AssetSchematic.CreateArrayFromJSON(result); if (schematics != null && schematics.Length <= 0) { schematics = null; } } catch (Exception e) { Debug.Log("Exception caught while processing schematic."); Debug.LogException(e); } if (schematics == null) { //try a single one try { AssetSchematic schematic = AssetSchematic.CreateFromJSON(result); schematics = new AssetSchematic[1]; schematics[0] = schematic; } catch (Exception e) { UnityEngine.Debug.LogError("Unable to parse mon file: " + path); UnityEngine.Debug.LogException(e); } } } return(schematics); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { ContentLibrarySO content_so = (ContentLibrarySO)Resources.Load("ContentLibrarySO"); bool created = false; //set to true if we find a new asset we weren't tracking before, used to clear out our depenedency psuedo graph and prevent loops bool newAssetImported = false; HashSet <string> pathsToReimport = new HashSet <string>(); if (content_so == null) { created = true; content_so = ScriptableObject.CreateInstance <ContentLibrarySO>(); } foreach (var str in importedAssets) { //UnityEngine.Debug.Log("importing: " + str); if (!content_so.importerSeenPaths.Contains(str)) { content_so.importerSeenPaths.Add(str); newAssetImported = true; } if (str.Contains(".mr")) { // Only process install files here. morph files will be handled separately. if (!(str.Contains(".morph.mr") || str.Contains(".morphs.mr"))) { Debug.Log("Found MR File. "); MCS_Utilities.MCSResource resource = new MCS_Utilities.MCSResource(); resource.Read(str, false); foreach (string key in resource.header.Keys) { string outputDir = String.Empty; if (key.Contains(".morph") || key.Contains(".bin")) { outputDir = System.IO.Path.Combine(Application.streamingAssetsPath, key); } else { outputDir = Path.Combine(Path.Combine(Path.GetDirectoryName(str), Path.GetFileNameWithoutExtension(str)), key); } //Debug.Log("Output File :" + outputDir); resource.UnpackResource(key, outputDir); } AssetDatabase.Refresh(); } } if (str.Contains(".mon")) { schematicLookup.Clear(); int tmpPos = str.LastIndexOf('/'); string dirMon = Path.GetDirectoryName(str);// str.Substring(0, tmpPos); AssetSchematic[] schematics; AssetDependency ad = null; AssetDependencyImporter adi = null; bool skipAsset = false; if (!content_so.importerDependencies.TryGetValue(str, out ad)) { MonDeserializer monDes = new MonDeserializer(); schematics = monDes.DeserializeMonFile(str); adi = new AssetDependencyImporter(); adi.srcPath = str; adi.schematics = schematics; adi.DetermineAllDependencies(); content_so.importerDependencies.Add(str, adi); } else { adi = (AssetDependencyImporter)ad; schematics = adi.schematics; } if (!adi.HasAllDependencies()) { adi.attempts++; pathsToReimport.Add(str); skipAsset = true; } AssetCreator ac = new AssetCreator(); if (!TryToImportMaterialsFromSchematics(str, dirMon, schematics)) { //we have missing materials continue; } if (skipAsset) { continue; } //clean up the variables before re-using them. //look at the first schematic to determine the "MAIN" function, this is legacy, eventually assetschematicimporter will handle this instead AssetSchematic mon = schematics[0]; ac = new AssetCreator(); mon.stream_and_path.root_path = str; switch (mon.type_and_function.primary_function) { case PrimaryFunction.material: break; default: //handle an FBX (clothing, hair, figure, etc) string fbxFilePath = str.Replace(".mon", ".fbx"); if (File.Exists(fbxFilePath)) { //use a custom texture and material locator AssetSchematicImporter assetSchematicImporter = new AssetSchematicImporter(null, null, GetTextureFromPathEditor, GetMaterialFromGUIDEditor); assetSchematicImporter.basePath = dirMon; GameObject fbxGO = AssetDatabase.LoadAssetAtPath <GameObject>(fbxFilePath); if (fbxGO == null) { UnityEngine.Debug.LogError("Missing required FBX: " + fbxFilePath); //monDes.ResaveMonFile(str); break; } if (fbxGO != null) { List <AssetSchematic> schematicsList = new List <AssetSchematic>(); foreach (AssetSchematic schematic in schematics) { schematicsList.Add(schematic); } GameObject outputGO = assetSchematicImporter.CreateGameObjectFromExistinGameObject(fbxGO, schematicLookup, schematicsList); //one note, components like Animator and LODGroup will be STRIPPED as they are not included in the component whitelist from CreateGameObjectFromExistinGameObject if (ImportUtilities.RemapMorphsIfRequired(outputGO)) { content_so.refreshOnComplete = true; } //AssetDatabase.Refresh(); string prefabFilePath = str.Replace(".mon", ".prefab"); GameObject prefabObj; if (!File.Exists(prefabFilePath)) { //UnityEngine.Debug.Log("File does not exist: " + prefabFilePath); prefabObj = PrefabUtility.CreatePrefab(prefabFilePath, outputGO, ReplacePrefabOptions.Default); //force a completely new and clean prefab, do not allow old values to transfer over } else { prefabObj = AssetDatabase.LoadAssetAtPath <GameObject>(prefabFilePath); //UnityEngine.Debug.Log("Result of load: " + (prefabObj == null ? "null" : "not null")); if (prefabObj != null) { prefabObj = PrefabUtility.ReplacePrefab(outputGO, prefabObj, ReplacePrefabOptions.ConnectToPrefab); //UnityEngine.Debug.Log("Update of load: " + (prefabObj == null ? "null" : "not null")); } else { //replace it, there is something wrong with it's state UnityEngine.Debug.LogWarning("Replacing prefab that is in unworkable state: " + prefabFilePath); prefabObj = PrefabUtility.CreatePrefab(prefabFilePath, outputGO, ReplacePrefabOptions.Default); //force a completely new and clean prefab, do not allow old values to transfer over } } //These components automatically come back, we'll FORCE them to be destroyed b/c we don't need them try { Animator animator = prefabObj.GetComponent <Animator>(); LODGroup lodGroup = prefabObj.GetComponent <LODGroup>(); if (animator != null) { GameObject.DestroyImmediate(animator, true); } if (lodGroup != null) { GameObject.DestroyImmediate(lodGroup, true); } PrefabUtility.RecordPrefabInstancePropertyModifications(prefabObj); if (Application.isPlaying) { GameObject.Destroy(outputGO); } else { GameObject.DestroyImmediate(outputGO, false); } } catch (Exception e) { UnityEngine.Debug.Log("Caught an exception during import component update"); UnityEngine.Debug.LogException(e); } } } break; } } } foreach (var str in deletedAssets) { if (str.Contains("MCS") && str.Contains(".fbx")) { AssetSchematic mon = content_so.AssetSchematicList.Where(x => x.stream_and_path.source_path == str).SingleOrDefault(); if (mon != null) { AssetDatabase.DeleteAsset(mon.stream_and_path.generated_path); mon.stream_and_path.generated_path = ""; mon.stream_and_path.source_path = ""; if (mon.stream_and_path.root_path == "") { content_so.DeleteItem(mon); } } } else if (str.Contains("MCS") && str.Contains(".prefab")) { AssetSchematic mon = content_so.AssetSchematicList.Where(x => x.stream_and_path.generated_path == str).SingleOrDefault(); if (mon != null) { if (AssetDatabase.LoadAssetAtPath(mon.stream_and_path.generated_path, typeof(GameObject)) == null) { mon.stream_and_path.generated_path = ""; } } } else if (str.Contains("MCS") && str.Contains(".mon")) { AssetSchematic mon = content_so.AssetSchematicList.Where(x => x.stream_and_path.root_path == str).SingleOrDefault(); if (mon != null && mon.stream_and_path != null) { mon.stream_and_path.root_path = ""; if (mon.stream_and_path.source_path == "") { content_so.DeleteItem(mon); } } } else if (str.Contains("MCS") && str.Contains(".mat")) { AssetSchematic mon = content_so.AssetSchematicList.Where(x => x.stream_and_path.generated_path == str).SingleOrDefault(); if (mon != null && mon.stream_and_path.generated_path != null && AssetDatabase.LoadAssetAtPath(mon.stream_and_path.generated_path, typeof(Material)) == null) { mon.stream_and_path.generated_path = ""; } } } for (var i = 0; i < movedAssets.Length; i++) { //Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]); } if (created) { if (AssetDatabase.IsValidFolder(ROOT_FOLDER) == false) { AssetDatabase.CreateFolder("Assets", "MCS"); } if (AssetDatabase.IsValidFolder(RESOURCES_FOLDER) == false) { AssetDatabase.CreateFolder(ROOT_FOLDER, "Resources"); } if (AssetDatabase.IsValidFolder(RESOURCES_PREFAB_FOLDER) == false) { AssetDatabase.CreateFolder(RESOURCES_FOLDER, "Prefabs"); } if (AssetDatabase.IsValidFolder(RESOURCES_MATERIALS_FOLDER) == false) { AssetDatabase.CreateFolder(RESOURCES_FOLDER, "Materials"); } AssetDatabase.CreateAsset(content_so, RESOURCES_FOLDER + "/ContentLibrarySO.asset"); } bool recursed = false; if (newAssetImported) { foreach (string path in pathsToReimport) { //UnityEngine.Debug.Log("Reimporting unmet dependency asset: " + path); AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport); AssetDependencyImporter adi = (AssetDependencyImporter)content_so.importerDependencies[path]; if (adi != null) { foreach (string dependencyPath in adi.unmetDependencies) { if (dependencyPath.StartsWith("Material: ")) { continue; } if (content_so.importerSeenPaths.Contains(dependencyPath)) { continue; } AssetDatabase.ImportAsset(dependencyPath, ImportAssetOptions.ForceSynchronousImport); recursed = true; } } } } else { //nothing has changed, so stop //UnityEngine.Debug.Log("Flushing dependencies graph"); foreach (string key in content_so.importerDependencies.Keys) { AssetDependencyImporter adi = (AssetDependencyImporter)content_so.importerDependencies[key]; if (adi.unmetDependencies.Count > 0) { UnityEngine.Debug.LogError("Missing dependencies for: " + key); foreach (string dp in adi.unmetDependencies) { UnityEngine.Debug.Log("Unmet: " + dp); } } } content_so.ClearDependencies(); } if (!recursed && content_so.refreshOnComplete) { content_so.refreshOnComplete = false; //This causes an error with the prefab, but does work //AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); //This does not work //AssetDatabase.ImportAsset("Assets/StreamingAssets"); } EditorUtility.SetDirty(content_so); }
public static Dictionary <string, Texture2D> GetTextures(AssetSchematic schematic, string basePath) { Dictionary <string, Texture2D> textures = new Dictionary <string, Texture2D> (); /** * List of textures that a material can have: * albedo; * metal; * smoothness; * emission; * normal; * detail_normal; * transparency; */ Texture2D albedo = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.albedo), typeof(Texture2D)); if (albedo != null) { textures.Add("albedo", albedo); } Texture2D metal = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.metal), typeof(Texture2D)); if (metal != null) { textures.Add("metal", metal); } Texture2D height = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.height), typeof(Texture2D)); if (height != null) { textures.Add("height", height); } // Texture2D smoothness = (Texture2D)AssetDatabase.LoadAssetAtPath (schematic.structure_and_physics.material_structure.sm, typeof(Texture2D)); // if (smoothness != null) { // textures.Add ("smoothness",smoothness); // } Texture2D emission = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.emission), typeof(Texture2D)); if (emission != null) { textures.Add("emission", emission); } Texture2D specular = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.specular), typeof(Texture2D)); if (specular != null) { textures.Add("specular", specular); } Texture2D normal = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.normal), typeof(Texture2D)); if (normal != null) { TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.normal)); if (importer.textureType != TextureImporterType.NormalMap) { importer.textureType = TextureImporterType.NormalMap; AssetDatabase.ImportAsset(schematic.structure_and_physics.material_structure.normal); AssetDatabase.Refresh(); } textures.Add("normal", normal); } Texture2D detail_normal = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.detail_normal), typeof(Texture2D)); if (detail_normal != null) { TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.detail_normal)); if (importer.textureType != TextureImporterType.NormalMap) { importer.textureType = TextureImporterType.NormalMap; AssetDatabase.ImportAsset(schematic.structure_and_physics.material_structure.detail_normal); AssetDatabase.Refresh(); } textures.Add("detail_normal", detail_normal); } Texture2D transparency = (Texture2D)AssetDatabase.LoadAssetAtPath(Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.transparency), typeof(Texture2D)); if (transparency != null) { textures.Add("transparency", transparency); } return(textures); }
/// <summary> /// Create a NEW game object by cloning an existing game object and passing in schematics or reading them directly off the nodes /// NOTE: this works for BOTH runtime and editor and from loose schematics or embedded schematics /// NOTE: you will likely want to specificy several callbacks based on the delegates at the top of this file (textures/mats/guid/scehmatic/etc) /// </summary> /// <param name="gameObjectIn"></param> /// <param name="schematicsIn"></param> /// <returns></returns> public GameObject CreateGameObjectFromExistinGameObject(GameObject gameObjectIn, Dictionary <string, AssetSchematic> schematicLookup, List <AssetSchematic> schematicsIn = null) { string targetName = gameObjectIn.name; GameObject targetGO = GameObject.Instantiate(gameObjectIn); targetGO.name = gameObjectIn.name; //ditch things like "(Clone)" if (schematicsIn == null || schematicsIn.Count <= 0) { GetAllSchematicsFromNodes(targetGO, schematicLookup); } else { schematics = schematicsIn; } IndexSchematics(schematicLookup); //Debug.Log ("Number of schematics: " + schematics.Count + " | vs: " + (schematicsIn != null ? schematicsIn.Count.ToString() : "null")); GameObject rootNode = targetGO; AssetSchematic rootSchematic = GetSchematicFromGameObject(rootNode, schematicLookup); if (rootSchematic == null) { //this is the wrong root node, let's check for a child that has the same name and or has a item_function defined for (int i = 0; i < targetGO.transform.childCount; i++) { GameObject node = targetGO.transform.GetChild(i).gameObject; if (node.name == targetName || MCS_Utilities.Paths.ScrubKey(node.name) == targetName) { rootNode = node; rootSchematic = GetSchematicFromGameObject(rootNode, schematicLookup); } } } if (rootSchematic == null) { throw new Exception("Root schematic must not be null"); } //Debug.Log ("Target: " + targetGO + " RootSchematic: " + rootSchematic.type_and_function.item_function); ProcessNode(rootNode, rootSchematic, targetGO, schematicLookup); if (rootSchematic.type_and_function.primary_function == PrimaryFunction.material) { Debug.Log("Found Material Asset Schematic."); } //do some final handling now that our stuff is assembled switch (rootSchematic.type_and_function.item_function) { case ItemFunction.soft_wearable: case ItemFunction.hair: case ItemFunction.prop: //CoreMeshMetaData coreMeshMetaData = targetGO.GetComponent<CoreMeshMetaData>(); //if(rootSchematic.type_and_function.artisttools_function == ArtistToolsFunction.item) //{ //} CoreMeshMetaData coreMeshMetaData = targetGO.GetComponentInChildren <CoreMeshMetaData>(true); /* * if (coreMeshMetaData == null) * { * coreMeshMetaData = targetGO.GetComponentInChildren<CoreMeshMetaData>(true); * } */ CIclothing ciclothing = targetGO.GetComponentInChildren <CIclothing>(true); CIhair cihair = targetGO.GetComponentInChildren <CIhair>(true); CIprop ciprop = targetGO.GetComponentInChildren <CIprop>(true); CoreMesh[] coreMeshes = targetGO.GetComponentsInChildren <CoreMesh>(true); List <CoreMesh> listCoreMeshes = new List <CoreMesh>(); foreach (CoreMesh coreMesh in coreMeshes) { listCoreMeshes.Add(coreMesh); //is the geometry id empty? if (coreMeshMetaData.geometryId == null || coreMeshMetaData.geometryId.Length <= 0) { coreMeshMetaData.geometryId = coreMesh.gameObject.name; //take the left half of the name if we find a "." , eg: "NMBoots_1462.Shape" -> "NMBoots_1462" int pos = coreMeshMetaData.geometryId.LastIndexOf("."); if (pos >= 0) { coreMeshMetaData.geometryId = coreMeshMetaData.geometryId.Substring(0, pos); } } } if (ciclothing != null) { ciclothing.LODlist = listCoreMeshes; } if (cihair != null) { cihair.LODlist = listCoreMeshes; } if (ciprop != null) { ciprop.LODlist = listCoreMeshes; } break; } return(targetGO); }
protected void ProcessNode(GameObject rootNode, AssetSchematic rootSchematic, GameObject currentNode, Dictionary <string, AssetSchematic> schematicLookup) { //what am i? AssetSchematic schematic = GetSchematicFromGameObject(currentNode, schematicLookup); //strip any components we don't understand Component[] components = currentNode.GetComponents <Component>(); for (int i = 0; i < components.Length; i++) { Type type = components[i].GetType(); string typeName = type.ToString(); if (componentWhiteList.Contains(typeName)) { continue; } //only strip these if we're in play mode, it's possible we could actually mess stuff up permanently if not if (Application.isPlaying) { GameObject.Destroy(components[i]); } } //Debug.Log ("Current Node: " + currentNode + " Schematic: " + (schematic==null?"null":"not null")); bool skip = false; if (schematic != null) { //UnityEngine.Debug.Log("Found a node with a schematic: " + currentNode.name); string guid = schematic.origin_and_description.mcs_id; //UnityEngine.Debug.Log("node a: " + currentNode.name + " | " + guid + " | " + schematic.type_and_function.artisttools_function + " | " + schematic.type_and_function.item_function + " | " + rootSchematic.type_and_function.item_function); //found the schematic, do something with it /* * if (currentNode.transform.parent == null && currentNode.GetInstanceID()==rootNode.GetInstanceID()) * { * * GameObject tgo = new GameObject (); * tgo.name = currentNode.name + " Root"; * currentNode.transform.SetParent (tgo.transform); * } */ GameObject parentNode; if (currentNode.transform.parent != null) { parentNode = currentNode.transform.parent.gameObject; } else { parentNode = currentNode; } //UnityEngine.Debug.Log("Processing node: " + currentNode.name + " type: " + schematic.type_and_function.hierarchy_rank); switch (schematic.type_and_function.artisttools_function) { case ArtistToolsFunction.material: break; case ArtistToolsFunction.item: //does my parent have a CostumeItem and CoreMeshMetaData, if yes bail on processing // You can see an example item in the Lawless Survivor outfit "LSPants", the nodes will // look like LSPants -> LSPants -> LSPants_LOD0, the double name on the top is causing problems // which this check fixes if (currentNode.transform.parent != null) { CoreMeshMetaData cmmdParent = parentNode.GetComponent <CoreMeshMetaData>(); CostumeItem ciParent = parentNode.GetComponent <CostumeItem>(); if (cmmdParent != null && ciParent != null) { //UnityEngine.Debug.LogWarning("Parent node has CoreMeshMetaData and CostumeItem, skipping node: " + currentNode.name); skip = true; break; } } CoreMeshMetaData coreMeshMetaData = null; if (schematic.type_and_function.hierarchy_rank == HierarchyRank.item) { //AssetPrepper -> PrepForMCS does it this way coreMeshMetaData = currentNode.AddComponent <CoreMeshMetaData>(); AttachingCIItemToNode(currentNode, schematic); } else { //Artist tools does it this way coreMeshMetaData = parentNode.AddComponent <CoreMeshMetaData>(); } coreMeshMetaData.vendorId = schematic.origin_and_description.vendor_id; coreMeshMetaData.versionId = schematic.version_and_control.item_version.ToString(); coreMeshMetaData.geometryId = schematic.origin_and_description.name; coreMeshMetaData.ID = schematic.origin_and_description.mcs_id; //commented out fields can be skipped safely //coreMeshMetaData.compatabilityBase = schematic.compatibilities[0]; //coreMeshMetaData.compatibilities = schematic.compatibilities; //coreMeshMetaData.declarativeUse = ""; //coreMeshMetaData.controllerScales = ...'; coreMeshMetaData.item_id = schematic.origin_and_description.mcs_id; coreMeshMetaData.collection_id = schematic.origin_and_description.collection_id; coreMeshMetaData.rank = schematic.type_and_function.hierarchy_rank; coreMeshMetaData.function = schematic.type_and_function.item_function; //coreMeshMetaData.schematic = ...; coreMeshMetaData.collection_version = schematic.version_and_control.collection_version; coreMeshMetaData.item_version = schematic.version_and_control.item_version; coreMeshMetaData.mcs_version = schematic.version_and_control.mcs_version; coreMeshMetaData.item_name = schematic.origin_and_description.name; coreMeshMetaData.collection_name = schematic.origin_and_description.collection_name; switch (rootSchematic.type_and_function.item_function) { case ItemFunction.soft_wearable: coreMeshMetaData.meshType = CONSTANTS.MESH_TYPE.CLOTH; break; case ItemFunction.hair: coreMeshMetaData.meshType = CONSTANTS.MESH_TYPE.HAIR; break; case ItemFunction.prop: coreMeshMetaData.meshType = CONSTANTS.MESH_TYPE.PROP; break; } break; case ArtistToolsFunction.model: //handles path for artist tools //AttachingCIItemToNode(parentNode, schematic); break; case ArtistToolsFunction.geometry: //CoreMesh, but we'll handle it via hierarchy rank instead AttachCoreMeshToNode(currentNode, schematic, rootSchematic); break; } if (!skip) { switch (schematic.type_and_function.hierarchy_rank) { case HierarchyRank.geometry: AttachCoreMeshToNode(currentNode, schematic, rootSchematic); break; } } } //dive into each child for (int i = 0; i < currentNode.transform.childCount; i++) { GameObject child = currentNode.transform.GetChild(i).gameObject; ProcessNode(rootNode, rootSchematic, child, schematicLookup); } //return nothing, as we've modified the current game object }
public Material CreateMorphMaterial(AssetSchematic schematic, Dictionary <string, Texture2D> textures) { string shaderName = "Standard"; if (schematic.structure_and_physics.material_structure.shader != null && schematic.structure_and_physics.material_structure.shader != "") { shaderName = schematic.structure_and_physics.material_structure.shader; } Shader shader = Shader.Find(shaderName); if (shader == null) { UnityEngine.Debug.LogError("Unable to find shader: " + shaderName); throw new UnityException("Unable to locate shader"); } var material = new Material(shader); /** * List of textures that a material can have: * albedo; * metal; * smoothness; * emission; * normal; * detail_normal; * transparency; */ //we also need to enable keywords if we use certain layers // For more info see: https://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html if (textures.ContainsKey("albedo")) { material.SetTexture("_MainTex", textures["albedo"]); } if (textures.ContainsKey("metal")) { material.SetTexture("_MetallicGlossMap", textures["metal"]); material.EnableKeyword("_METALLICGLOSSMAP"); } if (textures.ContainsKey("height")) { material.SetTexture("_ParallaxMap", textures["height"]); material.EnableKeyword("_PARALLAXMAP"); } if (textures.ContainsKey("normal")) { material.SetTexture("_BumpMap", textures["normal"]); material.EnableKeyword("_NORMALMAP"); } if (textures.ContainsKey("detail_normal")) { material.SetTexture("_DetailNormalMap", textures["detail_normal"]); material.EnableKeyword("_DETAIL_MULX2"); } if (textures.ContainsKey("specular")) { material.SetTexture("_SpecGlossMap", textures["specular"]); material.EnableKeyword("_SPECGLOSSMAP"); } if (textures.ContainsKey("emission")) { material.SetTexture("_EmissionMap", textures["emission"]); material.EnableKeyword("_EMISSION"); } /* * //uncomment if you want to know which keywords were enabled * string[] shaderKeywords = material.shaderKeywords; * for(int i = 0; i < shaderKeywords.Length; i++) * { * UnityEngine.Debug.Log("Keyword: " + shaderKeywords[i]); * } */ if (!String.IsNullOrEmpty(schematic.structure_and_physics.material_structure.albedo_tint)) { Color c = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.material_structure.albedo_tint); material.SetColor("_Color", c); } if (!String.IsNullOrEmpty(schematic.structure_and_physics.material_structure.emission_value)) { Color c = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.material_structure.emission_value); material.SetColor("_EmissionColor", c); } if (material.HasProperty("_DetailNormalMapScale") && schematic.structure_and_physics.material_structure.detail_normal_value > 0f) { material.SetFloat("_DetailNormalMapScale", schematic.structure_and_physics.material_structure.detail_normal_value); } if (schematic.structure_and_physics.material_structure.shader_keywords != null) { for (int i = 0; i < schematic.structure_and_physics.material_structure.shader_keywords.Length; i++) { material.EnableKeyword(schematic.structure_and_physics.material_structure.shader_keywords[i]); } } if (schematic.structure_and_physics.material_structure.shader_tags != null) { for (int i = 0; i < schematic.structure_and_physics.material_structure.shader_tags.Length; i++) { string key = schematic.structure_and_physics.material_structure.shader_tags[i]; int pos = key.IndexOf('='); if (pos < 0) { UnityEngine.Debug.Log("Invalid material shader_tag: " + schematic.origin_and_description.name + " => " + schematic.origin_and_description.mcs_id + " tag: " + key); throw new Exception("Invalid shader tag"); } material.SetOverrideTag(key.Substring(0, pos), key.Substring(pos + 1)); } } if (schematic.structure_and_physics.material_structure.shader_properties != null) { for (int i = 0; i < schematic.structure_and_physics.material_structure.shader_properties.Length; i++) { string key = schematic.structure_and_physics.material_structure.shader_properties[i]; int typePos = key.IndexOf(':'); int equalPos = key.IndexOf('='); string type = key.Substring(0, typePos); string propertyKey = key.Substring(typePos + 1, equalPos - (typePos + 1)); string propertyValue = key.Substring(equalPos + 1); switch (type) { case "int": material.SetInt(propertyKey, Int32.Parse(propertyValue)); break; case "float": material.SetFloat(propertyKey, float.Parse(propertyValue)); break; case "color": Color c = AssetSchematicUtility.ConvertColorStringToColor(propertyValue); material.SetColor(propertyKey, c); break; default: UnityEngine.Debug.Log("Invalid material property: " + schematic.origin_and_description.name + " => " + schematic.origin_and_description.mcs_id + " key: " + key); throw new Exception("Invalid shader property"); break; } } } if (schematic.structure_and_physics.material_structure.render_queue != -2) { material.renderQueue = schematic.structure_and_physics.material_structure.render_queue; } return(material); }
//todo: expand this... /** * schematic.origin_and_description.gender = MCS.Utility.Schematic.Enumeration.Gender.male; * schematic.origin_and_description.vendor_name = "DAZ3D"; * schematic.type_and_function.item_function = MCS.Utility.Schematic.Enumeration.ItemFunction.soft_wearable; * schematic.origin_and_description.collection_name = "UrbanMetro"; * schematic.origin_and_description.id = "UMPants"; * schematic.origin_and_description.name = "UMPants"; * schematic.version_and_control.item_version = 0.01; * schematic.origin_and_description.description = "/Urban Metro Outfit for Genesis 2 Male(s)/Pants"; * schematic.version_and_control.compatibilities = new string[1]{ "/Genesis 2/Male" }; * schematic.version_and_control.mcs_version = 1.5; */ public GameObject CreateMorphGameObjectFromFbx(GameObject go, AssetSchematic schematic, Dictionary <string, Texture2D> textures, bool InstantiateNewObjectUponCreation = true) { UnityEngine.Debug.Log("CreateMorphGameObjectFromFbx: " + go.name + " | " + schematic.stream_and_path.source_path); GameObject gameObject = null; if (InstantiateNewObjectUponCreation) { gameObject = GameObject.Instantiate(go) as GameObject; } else { gameObject = go; } GameObject child = gameObject.transform.GetChild(0).gameObject; child.AddComponent <MCSItemModel> (); child.GetComponent <MCSItemModel> ().schematic = schematic; GameObject child2 = child.transform.GetChild(0).gameObject; //Adding the coremesh component to the root...ish gameobject of the item. Then we set the various values from the asset schematic (.mon file) child2.AddComponent <CoreMeshMetaData>(); CoreMeshMetaData cmmd = child2.GetComponent <CoreMeshMetaData>(); cmmd.vendorId = schematic.origin_and_description.vendor_name; cmmd.versionId = schematic.version_and_control.item_version.ToString(); switch (schematic.type_and_function.item_function) { case MCS.Utility.Schematic.Enumeration.ItemFunction.soft_wearable: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.CLOTH; break; case MCS.Utility.Schematic.Enumeration.ItemFunction.rigid_wearable: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.CLOTH; break; case MCS.Utility.Schematic.Enumeration.ItemFunction.figure: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.BODY; break; case MCS.Utility.Schematic.Enumeration.ItemFunction.hair: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.HAIR; break; case MCS.Utility.Schematic.Enumeration.ItemFunction.prop: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.PROP; break; case MCS.Utility.Schematic.Enumeration.ItemFunction.unknown: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.UNKNOWN; break; default: cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.UNKNOWN; break; } cmmd.geometryId = schematic.origin_and_description.mcs_id; cmmd.ID = schematic.origin_and_description.mcs_id; cmmd.declarativeUse = schematic.origin_and_description.description; cmmd.mcs_version = schematic.version_and_control.mcs_version; cmmd.collection_name = schematic.origin_and_description.collection_name; //Adding all the coremesh components to anything that has a skinned mesh renderer. We also add the paths to the runtime morphs here foreach (SkinnedMeshRenderer rend in gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()) { rend.gameObject.AddComponent <CoreMesh>(); CoreMesh cm = rend.gameObject.GetComponent <CoreMesh> (); cm.dazName = schematic.origin_and_description.name; cm.ID = schematic.origin_and_description.mcs_id; cm.meshType = cmmd.meshType; int index = -1; for (int i = 0; i < schematic.structure_and_physics.morph_structure.lodMorphObjectNames.Length; i++) { if (schematic.structure_and_physics.morph_structure.lodMorphObjectNames [i] == cm.gameObject.name) { index = i; } } if (index > -1) { cm.runtimeMorphPath = schematic.structure_and_physics.morph_structure.lodMorphLocations[index]; } } //Adding the different CICostumeItem classes, ie. CIClothing, CIBody, CIHair, CIProp. switch (cmmd.meshType) { case MCS.CONSTANTS.MESH_TYPE.CLOTH: child2.AddComponent <CIclothing>(); CIclothing cicl = child2.GetComponent <CIclothing>(); cicl.dazName = schematic.origin_and_description.name; cicl.ID = schematic.origin_and_description.mcs_id; cicl.meshType = cmmd.meshType; cicl.DetectCoreMeshes(); //TODO: textures is a list of textures, not a dictionary, right? /* * if (textures.ContainsKey ("alphaMask")) { * cicl.alphaMask = textures ["alphaMask"]; * } */ cicl.isAttached = false; break; case MCS.CONSTANTS.MESH_TYPE.BODY: //todo: all the figure stuff needs to be added here, ie. CharacterManager, Core Morphs, JCT stuff, etc child2.AddComponent <CIbody>(); CIbody body = child2.GetComponent <CIbody>(); break; case MCS.CONSTANTS.MESH_TYPE.HAIR: child2.AddComponent <CIhair>(); CIhair hair = child2.GetComponent <CIhair>(); hair.dazName = schematic.origin_and_description.name; hair.ID = schematic.origin_and_description.mcs_id; hair.meshType = cmmd.meshType; hair.DetectCoreMeshes(); break; case MCS.CONSTANTS.MESH_TYPE.PROP: child2.AddComponent <CIprop>(); CIprop prop = child2.GetComponent <CIprop>(); prop.dazName = schematic.origin_and_description.name; prop.ID = schematic.origin_and_description.mcs_id; prop.meshType = cmmd.meshType; prop.DetectCoreMeshes(); prop.basePosition = prop.transform.localPosition; prop.baseRotation = prop.transform.localEulerAngles; //todo: add bone and attachment point stuff to the prop object break; case MCS.CONSTANTS.MESH_TYPE.UNKNOWN: //Unknown break; } return(gameObject); }
public static bool GetTextures(AssetSchematic schematic, string basePath, out Dictionary <string, Texture2D> textures) { bool success = true; textures = new Dictionary <string, Texture2D>(); // ALBEDO if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.albedo)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.albedo.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.albedo); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.albedo); } Texture2D albedo = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (albedo == null) { success = false; return(success); } else { textures.Add("albedo", albedo); } } // metal if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.metal)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.metal.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.metal); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.metal); } Texture2D metal = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (metal == null) { success = false; return(success); } else { textures.Add("metal", metal); } } // height if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.height)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.height.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.height); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.height); } Texture2D height = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (height == null) { //optional, do not error here //success = false; //return success; } else { textures.Add("height", height); } } // emission if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.emission)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.emission.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.emission); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.emission); } Texture2D emission = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (emission == null) { //optional, do not error here //success = false; //return success; } else { textures.Add("emission", emission); } } // specular if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.specular)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.specular.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.specular); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.specular); } Texture2D specular = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (specular == null) { success = false; return(success); } else { textures.Add("specular", specular); } } // normal if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.normal)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.normal.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.normal); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.normal); } Texture2D normal = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (normal == null) { success = false; return(success); } else { TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(assetPath); if (importer.textureType != TextureImporterType.NormalMap) { importer.textureType = TextureImporterType.NormalMap; AssetDatabase.ImportAsset(assetPath); AssetDatabase.Refresh(); } textures.Add("normal", normal); } } // detail_normal if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.detail_normal)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.detail_normal.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.detail_normal); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.detail_normal); } Texture2D detail_normal = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (detail_normal == null) { success = false; return(success); } else { TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(assetPath); if (importer.textureType != TextureImporterType.NormalMap) { importer.textureType = TextureImporterType.NormalMap; AssetDatabase.ImportAsset(schematic.structure_and_physics.material_structure.detail_normal); AssetDatabase.Refresh(); } textures.Add("detail_normal", detail_normal); } } // transparency if (!string.IsNullOrEmpty(schematic.structure_and_physics.material_structure.transparency)) { string assetPath = string.Empty; if (schematic.structure_and_physics.material_structure.transparency.Contains(@"./")) { assetPath = Paths.ConvertRelativeToAbsolute(basePath, schematic.structure_and_physics.material_structure.transparency); } else { assetPath = Path.Combine(basePath, schematic.structure_and_physics.material_structure.transparency); } Texture2D transparency = AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath); if (transparency == null) { success = false; return(success); } else { textures.Add("transparency", transparency); } } return(success); }
// Used in Artist Tools public void InitializeItem() { schematic = new AssetSchematic(); schematic.InitializeSchematic(); }