public string FallbackToDefaultMtdIfNecessary(string mtd, SapLogger logger) { if (mtd != null && MaterialDefs.ContainsKey(mtd)) { return(mtd); } else { if (mtd != null) { logger?.LogWarning($"MTD {mtd} did not exist. Falling back to default, which is '{DefaultFallbackMTDName}'."); } else { logger?.LogWarning($"MTD was not specified. Falling back to default, which is '{DefaultFallbackMTDName}'."); } return(DefaultFallbackMTDName); } }
/// <summary> /// Exports a Model Asset /// </summary> private void ExportModel(Package.Entry entry, string name) { var scale = float.TryParse(Settings["ModelScale", "1.0"], out var val) ? val : 1.0f; var models = Mesh.Convert(ActivePackage.LoadEntry(entry)); var path = name.Split('.')[0]; var materials = new Dictionary <string, Model.Material>(); // Attempt to load the materials file foreach (var prefix in FileSuffixes) { if (ActivePackage.Entries.TryGetValue(MurMur3.Calculate(Encoding.Unicode.GetBytes(path.Replace("exported_files\\", "") + prefix)), out var result)) { try { materials = MaterialDefs.Convert(ActivePackage.LoadEntry(result), prefix.Split('.').Last()); break; } catch { continue; } } } var folder = Path.GetDirectoryName(path); Directory.CreateDirectory(folder); for (int mdl = 0; mdl < models.Count; mdl++) { for (int lod = 0; lod < models[mdl].Count; lod++) { // Must generate for formats that need it models[mdl][lod].GenerateGlobalBoneData(); models[mdl][lod].Scale(scale); foreach (var material in models[mdl][lod].Materials) { if (materials.TryGetValue(material.Name, out var fileMtl)) { material.Images = fileMtl.Images; material.Settings = fileMtl.Settings; // Determine image keys as they change depending on shader/type if (material.Images.ContainsKey("BaseMetalMap")) { material.DiffuseMapName = "BaseMetalMap"; } else if (material.Images.ContainsKey("BaseMap")) { material.DiffuseMapName = "BaseMap"; } if (material.Images.ContainsKey("NormalRoughnessMap")) { material.NormalMapName = "NormalRoughnessMap"; } else if (material.Images.ContainsKey("NormalMap")) { material.NormalMapName = "NormalMap"; } } } foreach (var material in models[mdl][lod].Materials) { if (Settings["ExportMaterialInfo", "Yes"] == "Yes") { ExportMaterialInfo(material, Path.Combine(folder, material.Name + ".txt")); } if (Settings["ExportImagesWithModel", "Yes"] == "Yes") { ExportMaterialImages(material, folder); } } var result = Path.Combine(folder, string.Format("{0}_model{1}_lod{2}", Path.GetFileNameWithoutExtension(path), mdl, lod)); foreach (var format in ModelFormats) { // PNG is default if (Settings["Export" + format.ToUpper(), format == "semodel" ? "Yes" : "No"] == "Yes") { models[mdl][lod].Save(result + "." + format); } } } } }