diff --git a/Penumbra/Import/Models/ModelManager.cs b/Penumbra/Import/Models/ModelManager.cs index e71b8baf..217450dd 100644 --- a/Penumbra/Import/Models/ModelManager.cs +++ b/Penumbra/Import/Models/ModelManager.cs @@ -4,7 +4,6 @@ using Penumbra.Collections.Manager; using Penumbra.GameData.Files; using Penumbra.Import.Models.Export; using SharpGLTF.Scenes; -using SharpGLTF.Transforms; namespace Penumbra.Import.Models; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs index 31f2f7e0..ba6435c7 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs @@ -13,7 +13,7 @@ public partial class ModEditWindow private ModEditWindow _edit; public readonly MdlFile Mdl; - public readonly List GamePaths; + public List? GamePaths { get; private set ;} private readonly List[] _attributes; public bool PendingIo { get; private set; } = false; @@ -28,8 +28,10 @@ public partial class ModEditWindow _edit = edit; Mdl = new MdlFile(bytes); - GamePaths = mod == null ? new() : FindGamePaths(path, mod); _attributes = CreateAttributes(Mdl); + + if (mod != null) + FindGamePaths(path, mod); } /// @@ -40,36 +42,41 @@ public partial class ModEditWindow public byte[] Write() => Mdl.Write(); - // TODO: this _needs_ to be done asynchronously, kart mods hang for a good second or so /// Find the list of game paths that may correspond to this model. /// Resolved path to a .mdl. /// Mod within which the .mdl is resolved. - private List FindGamePaths(string path, Mod mod) + private void FindGamePaths(string path, Mod mod) { - // todo: might be worth ordering based on prio + selection for disambiguating between multiple matches? not sure. same for the multi group case - return mod.AllSubMods - .SelectMany(submod => submod.Files.Concat(submod.FileSwaps)) - // todo: using ordinal ignore case because the option group paths in mods being lowerecased somewhere, but the mod editor using fs paths, which may be uppercase. i'd say this will blow up on linux, but it's already the case so can't be too much worse than present right - .Where(kv => kv.Value.FullName.Equals(path, StringComparison.OrdinalIgnoreCase)) - .Select(kv => kv.Key) - .ToList(); + PendingIo = true; + var task = Task.Run(() => { + // TODO: Is it worth trying to order results based on option priorities for cases where more than one match is found? + // NOTE: We're using case insensitive comparisons, as option group paths in mods are stored in lower case, but the mod editor uses paths directly from the file system, which may be mixed case. + return mod.AllSubMods + .SelectMany(submod => submod.Files.Concat(submod.FileSwaps)) + .Where(kv => kv.Value.FullName.Equals(path, StringComparison.OrdinalIgnoreCase)) + .Select(kv => kv.Key) + .ToList(); + }); + + task.ContinueWith(task => { + IoException = task.Exception?.ToString(); + PendingIo = false; + GamePaths = task.Result; + }); } /// Export model to an interchange format. /// Disk path to save the resulting file to. - public void Export(string outputPath) + public void Export(string outputPath, Utf8GamePath mdlPath) { - // NOTES ON EST (i don't think it's worth supporting yet...) + // NOTES ON EST // for collection wide lookup; // Collections.Cache.EstCache::GetEstEntry // Collections.Cache.MetaCache::GetEstEntry // Collections.ModCollection.MetaCache? // for default lookup, probably; // EstFile.GetDefault(...) - - // TODO: allow user to pick the gamepath in the ui - // TODO: what if there's no gamepaths? - var mdlPath = GamePaths.First(); + var sklbPath = GetSklbPath(mdlPath.ToString()); var sklb = sklbPath != null ? ReadSklb(sklbPath) : null; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs index 57c47b8f..9af2dd91 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs @@ -34,13 +34,13 @@ public partial class ModEditWindow ); } - if (ImGuiUtil.DrawDisabledButton("bingo bango", Vector2.Zero, "description", tab.PendingIo)) - { - tab.Export("C:\\Users\\ackwell\\blender\\gltf-tests\\bingo.gltf"); - } + if (tab.GamePaths != null) + if (ImGuiUtil.DrawDisabledButton("bingo bango", Vector2.Zero, "description", tab.PendingIo)) + tab.Export("C:\\Users\\ackwell\\blender\\gltf-tests\\bingo.gltf", tab.GamePaths.First()); ImGui.TextUnformatted("blippity blap"); - foreach (var gamePath in tab.GamePaths) - ImGui.TextUnformatted(gamePath.ToString()); + if (tab.GamePaths != null) + foreach (var gamePath in tab.GamePaths) + ImGui.TextUnformatted(gamePath.ToString()); if (tab.IoException != null) ImGui.TextUnformatted(tab.IoException);