From 18fd36d2d7123d3519b29c12bb580943b0f67e1c Mon Sep 17 00:00:00 2001 From: ackwell Date: Fri, 29 Dec 2023 23:49:55 +1100 Subject: [PATCH] Bit of cleanup --- Penumbra/Import/Models/ModelManager.cs | 12 +++++------ .../ModEditWindow.Models.MdlTab.cs | 21 +++++++++++++++++-- .../UI/AdvancedWindow/ModEditWindow.Models.cs | 7 ++----- Penumbra/UI/AdvancedWindow/ModEditWindow.cs | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Penumbra/Import/Models/ModelManager.cs b/Penumbra/Import/Models/ModelManager.cs index 6a9ef334..42134037 100644 --- a/Penumbra/Import/Models/ModelManager.cs +++ b/Penumbra/Import/Models/ModelManager.cs @@ -54,8 +54,8 @@ public sealed class ModelManager : SingleTaskQueue, IDisposable return task; } - public Task ExportToGltf(MdlFile mdl, string path) - => Enqueue(new ExportToGltfAction(mdl, path)); + public Task ExportToGltf(MdlFile mdl, string outputPath) + => Enqueue(new ExportToGltfAction(mdl, outputPath)); public void SkeletonTest() { @@ -122,12 +122,12 @@ public sealed class ModelManager : SingleTaskQueue, IDisposable private class ExportToGltfAction : IAction { private readonly MdlFile _mdl; - private readonly string _path; + private readonly string _outputPath; - public ExportToGltfAction(MdlFile mdl, string path) + public ExportToGltfAction(MdlFile mdl, string outputPath) { _mdl = mdl; - _path = path; + _outputPath = outputPath; } public void Execute(CancellationToken token) @@ -148,7 +148,7 @@ public sealed class ModelManager : SingleTaskQueue, IDisposable } var model = scene.ToGltf2(); - model.SaveGLTF(_path); + model.SaveGLTF(_outputPath); } public bool Equals(IAction? other) diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs index 254db841..4552078a 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.MdlTab.cs @@ -10,13 +10,18 @@ public partial class ModEditWindow { private class MdlTab : IWritable { + private ModEditWindow _edit; + public readonly MdlFile Mdl; public readonly List GamePaths; - private readonly List[] _attributes; - public MdlTab(byte[] bytes, string path, Mod? mod) + public bool PendingIo { get; private set; } = false; + + public MdlTab(ModEditWindow edit, byte[] bytes, string path, Mod? mod) { + _edit = edit; + Mdl = new MdlFile(bytes); GamePaths = mod == null ? new() : FindGamePaths(path, mod); _attributes = CreateAttributes(Mdl); @@ -31,6 +36,9 @@ public partial class ModEditWindow => 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) { // todo: might be worth ordering based on prio + selection for disambiguating between multiple matches? not sure. same for the multi group case @@ -42,6 +50,15 @@ public partial class ModEditWindow .ToList(); } + /// Export model to an interchange format. + /// Disk path to save the resulting file to. + public void Export(string outputPath) + { + PendingIo = true; + _edit._models.ExportToGltf(Mdl, outputPath) + .ContinueWith(_ => PendingIo = false); + } + /// Remove the material given by the index. /// Meshes using the removed material are redirected to material 0, and those after the index are corrected. public void RemoveMaterial(int materialIndex) diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs index d5ca6fa5..0b145b89 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.Models.cs @@ -17,7 +17,6 @@ public partial class ModEditWindow private readonly FileEditor _modelTab; private readonly ModelManager _models; - private bool _pendingIo = false; private string _modelNewMaterial = string.Empty; private readonly List _subMeshAttributeTagWidgets = []; @@ -35,11 +34,9 @@ public partial class ModEditWindow ); } - if (ImGuiUtil.DrawDisabledButton("bingo bango", Vector2.Zero, "description", _pendingIo)) + if (ImGuiUtil.DrawDisabledButton("bingo bango", Vector2.Zero, "description", tab.PendingIo)) { - _pendingIo = true; - var task = _models.ExportToGltf(file, "C:\\Users\\ackwell\\blender\\gltf-tests\\bingo.gltf"); - task.ContinueWith(_ => _pendingIo = false); + tab.Export("C:\\Users\\ackwell\\blender\\gltf-tests\\bingo.gltf"); } if (ImGui.Button("zoingo boingo")) { diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs index 181538ec..20ad92c3 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs @@ -587,7 +587,7 @@ public partial class ModEditWindow : Window, IDisposable () => PopulateIsOnPlayer(_editor.Files.Mtrl, ResourceType.Mtrl), DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty, (bytes, path, writable) => new MtrlTab(this, new MtrlFile(bytes), path, writable)); _modelTab = new FileEditor(this, gameData, config, _editor.Compactor, _fileDialog, "Models", ".mdl", - () => PopulateIsOnPlayer(_editor.Files.Mdl, ResourceType.Mdl), DrawModelPanel, () => _mod?.ModPath.FullName ?? string.Empty, (bytes, path, _) => new MdlTab(bytes, path, _mod)); + () => PopulateIsOnPlayer(_editor.Files.Mdl, ResourceType.Mdl), DrawModelPanel, () => _mod?.ModPath.FullName ?? string.Empty, (bytes, path, _) => new MdlTab(this, bytes, path, _mod)); _shaderPackageTab = new FileEditor(this, gameData, config, _editor.Compactor, _fileDialog, "Shaders", ".shpk", () => PopulateIsOnPlayer(_editor.Files.Shpk, ResourceType.Shpk), DrawShaderPackagePanel, () => _mod?.ModPath.FullName ?? string.Empty, (bytes, _, _) => new ShpkTab(_fileDialog, bytes));