From ab066f1706565e3d3113bdb7f26149737cc263a4 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Wed, 6 May 2020 19:48:38 -0400 Subject: [PATCH] Add channel component option for batch export textures. Fix exporting texture alts from model. --- .../BFRES/Bfres Structs/SubFiles/FMDL.cs | 35 ++++-- .../Forms/BatchFormatExport.Designer.cs | 119 ++++++++++-------- .../Forms/BatchFormatExport.cs | 2 + Toolbox/MainForm.cs | 11 +- 4 files changed, 100 insertions(+), 67 deletions(-) diff --git a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs index d80142a1..4295ea87 100644 --- a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs +++ b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs @@ -561,21 +561,32 @@ namespace Bfres.Structs private List GetTextures() { + List textureRefs = new List(); + foreach (var mat in materials) { + foreach (var texref in mat.Value.TextureMaps) { + if (!textureRefs.Contains(texref.Name)) { + textureRefs.Add(texref.Name); + if (texref.Name.EndsWith(".0")) + { + for (int i = 1; i < 100; i++) + textureRefs.Add(texref.Name.Replace(".0", $".{i}")); + } + } + } + } + List textures = new List(); - foreach (var mat in materials) + foreach (var texref in textureRefs) { - foreach (var texref in mat.Value.TextureMaps) + foreach (var bntx in PluginRuntime.bntxContainers) { - foreach (var bntx in PluginRuntime.bntxContainers) - { - if (bntx.Textures.ContainsKey(texref.Name)) - textures.Add(bntx.Textures[texref.Name]); - } - foreach (var ftexCont in PluginRuntime.ftexContainers) - { - if (ftexCont.ResourceNodes.ContainsKey(texref.Name)) - textures.Add((FTEX)ftexCont.ResourceNodes[texref.Name]); - } + if (bntx.Textures.ContainsKey(texref)) + textures.Add(bntx.Textures[texref]); + } + foreach (var ftexCont in PluginRuntime.ftexContainers) + { + if (ftexCont.ResourceNodes.ContainsKey(texref)) + textures.Add((FTEX)ftexCont.ResourceNodes[texref]); } } diff --git a/Switch_Toolbox_Library/Forms/BatchFormatExport.Designer.cs b/Switch_Toolbox_Library/Forms/BatchFormatExport.Designer.cs index f0e95035..ac9f4f21 100644 --- a/Switch_Toolbox_Library/Forms/BatchFormatExport.Designer.cs +++ b/Switch_Toolbox_Library/Forms/BatchFormatExport.Designer.cs @@ -28,13 +28,73 @@ /// private void InitializeComponent() { - this.comboBox1 = new Toolbox.Library.Forms.STComboBox(); - this.button1 = new Toolbox.Library.Forms.STButton(); - this.OkButton = new Toolbox.Library.Forms.STButton(); - this.chkSeperateTextureContainers = new Toolbox.Library.Forms.STCheckBox(); + this.chkChannelComponents = new Toolbox.Library.Forms.STCheckBox(); this.chkSeperateArchives = new Toolbox.Library.Forms.STCheckBox(); + this.chkSeperateTextureContainers = new Toolbox.Library.Forms.STCheckBox(); + this.OkButton = new Toolbox.Library.Forms.STButton(); + this.button1 = new Toolbox.Library.Forms.STButton(); + this.comboBox1 = new Toolbox.Library.Forms.STComboBox(); this.SuspendLayout(); // + // chkChannelComponents + // + this.chkChannelComponents.AutoSize = true; + this.chkChannelComponents.Checked = true; + this.chkChannelComponents.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkChannelComponents.Location = new System.Drawing.Point(12, 85); + this.chkChannelComponents.Name = "chkChannelComponents"; + this.chkChannelComponents.Size = new System.Drawing.Size(161, 17); + this.chkChannelComponents.TabIndex = 5; + this.chkChannelComponents.Text = "Use Texture Channel Swaps"; + this.chkChannelComponents.UseVisualStyleBackColor = true; + // + // chkSeperateArchives + // + this.chkSeperateArchives.AutoSize = true; + this.chkSeperateArchives.Checked = true; + this.chkSeperateArchives.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkSeperateArchives.Location = new System.Drawing.Point(12, 62); + this.chkSeperateArchives.Name = "chkSeperateArchives"; + this.chkSeperateArchives.Size = new System.Drawing.Size(160, 17); + this.chkSeperateArchives.TabIndex = 4; + this.chkSeperateArchives.Text = "Use Folders for Archive Files"; + this.chkSeperateArchives.UseVisualStyleBackColor = true; + // + // chkSeperateTextureContainers + // + this.chkSeperateTextureContainers.AutoSize = true; + this.chkSeperateTextureContainers.Checked = true; + this.chkSeperateTextureContainers.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkSeperateTextureContainers.Location = new System.Drawing.Point(12, 39); + this.chkSeperateTextureContainers.Name = "chkSeperateTextureContainers"; + this.chkSeperateTextureContainers.Size = new System.Drawing.Size(219, 17); + this.chkSeperateTextureContainers.TabIndex = 3; + this.chkSeperateTextureContainers.Text = "Use Folders for Models/Texture Archives"; + this.chkSeperateTextureContainers.UseVisualStyleBackColor = true; + // + // OkButton + // + this.OkButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.OkButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.OkButton.Location = new System.Drawing.Point(82, 121); + this.OkButton.Name = "OkButton"; + this.OkButton.Size = new System.Drawing.Size(63, 23); + this.OkButton.TabIndex = 2; + this.OkButton.Text = "Ok"; + this.OkButton.UseVisualStyleBackColor = true; + this.OkButton.Click += new System.EventHandler(this.OkButton_Click); + // + // button1 + // + this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.button1.Location = new System.Drawing.Point(167, 121); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(63, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Cancel"; + this.button1.UseVisualStyleBackColor = true; + // // comboBox1 // this.comboBox1.BorderColor = System.Drawing.Color.Empty; @@ -48,58 +108,12 @@ this.comboBox1.TabIndex = 0; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // - // button1 - // - this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.button1.Location = new System.Drawing.Point(171, 96); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(63, 23); - this.button1.TabIndex = 1; - this.button1.Text = "Cancel"; - this.button1.UseVisualStyleBackColor = true; - // - // OkButton - // - this.OkButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.OkButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.OkButton.Location = new System.Drawing.Point(86, 96); - this.OkButton.Name = "OkButton"; - this.OkButton.Size = new System.Drawing.Size(63, 23); - this.OkButton.TabIndex = 2; - this.OkButton.Text = "Ok"; - this.OkButton.UseVisualStyleBackColor = true; - this.OkButton.Click += new System.EventHandler(this.OkButton_Click); - // - // chkSeperateTextureContainers - // - this.chkSeperateTextureContainers.AutoSize = true; - this.chkSeperateTextureContainers.Checked = true; - this.chkSeperateTextureContainers.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkSeperateTextureContainers.Location = new System.Drawing.Point(12, 39); - this.chkSeperateTextureContainers.Name = "chkSeperateTextureContainers"; - this.chkSeperateTextureContainers.Size = new System.Drawing.Size(219, 17); - this.chkSeperateTextureContainers.TabIndex = 3; - this.chkSeperateTextureContainers.Text = "Use Folders for Models/Texture Archives"; - this.chkSeperateTextureContainers.UseVisualStyleBackColor = true; - // - // chkSeperateArchives - // - this.chkSeperateArchives.AutoSize = true; - this.chkSeperateArchives.Checked = true; - this.chkSeperateArchives.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkSeperateArchives.Location = new System.Drawing.Point(12, 62); - this.chkSeperateArchives.Name = "chkSeperateArchives"; - this.chkSeperateArchives.Size = new System.Drawing.Size(160, 17); - this.chkSeperateArchives.TabIndex = 4; - this.chkSeperateArchives.Text = "Use Folders for Archive Files"; - this.chkSeperateArchives.UseVisualStyleBackColor = true; - // // BatchFormatExport // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(246, 131); + this.ClientSize = new System.Drawing.Size(246, 156); + this.Controls.Add(this.chkChannelComponents); this.Controls.Add(this.chkSeperateArchives); this.Controls.Add(this.chkSeperateTextureContainers); this.Controls.Add(this.OkButton); @@ -119,5 +133,6 @@ private Toolbox.Library.Forms.STButton OkButton; private Forms.STCheckBox chkSeperateTextureContainers; private Forms.STCheckBox chkSeperateArchives; + private Forms.STCheckBox chkChannelComponents; } } \ No newline at end of file diff --git a/Switch_Toolbox_Library/Forms/BatchFormatExport.cs b/Switch_Toolbox_Library/Forms/BatchFormatExport.cs index a453873a..8d398648 100644 --- a/Switch_Toolbox_Library/Forms/BatchFormatExport.cs +++ b/Switch_Toolbox_Library/Forms/BatchFormatExport.cs @@ -21,6 +21,7 @@ namespace Toolbox.Library { public bool SeperateTextureContainers; public bool SeperateArchiveFiles; + public bool UseTextureChannelComponents; } public BatchFormatExport(List Formats) @@ -61,6 +62,7 @@ namespace Toolbox.Library { BatchSettings.SeperateTextureContainers = chkSeperateTextureContainers.Checked; BatchSettings.SeperateArchiveFiles = chkSeperateArchives.Checked; + BatchSettings.UseTextureChannelComponents = chkChannelComponents.Checked; this.Close(); } diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index b905ab3d..7c67bfbb 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -1475,7 +1475,7 @@ namespace Toolbox if (fileFormat is STGenericTexture && exportMode == ExportMode.Textures) { string name = ((STGenericTexture)fileFormat).Text; - ExportTexture(((STGenericTexture)fileFormat), $"{outputFolder}/{name}", extension); + ExportTexture(((STGenericTexture)fileFormat), settings, $"{outputFolder}/{name}", extension); } else if (fileFormat is IArchiveFile) SearchArchive(settings, (IArchiveFile)fileFormat, extension, outputFolder, exportMode); @@ -1492,7 +1492,7 @@ namespace Toolbox } foreach (STGenericTexture tex in ((ITextureContainer)fileFormat).TextureList) { - ExportTexture(tex, $"{outputFolder}/{tex.Text}", extension); + ExportTexture(tex, settings, $"{outputFolder}/{tex.Text}", extension); } } else if (fileFormat is IExportableModel && exportMode == ExportMode.Models) @@ -1529,11 +1529,16 @@ namespace Toolbox Textures, } - private void ExportTexture(STGenericTexture tex, string filePath, string ext) { + private void ExportTexture(STGenericTexture tex, BatchFormatExport.Settings settings, string filePath, string ext) { filePath = Utils.RenameDuplicateString(batchExportFileList, filePath, 0, 3); batchExportFileList.Add(filePath); + //Switch the runtime comp setting to the batch settings then switch back later + bool compSetting = Runtime.ImageEditor.UseComponetSelector; + + Runtime.ImageEditor.UseComponetSelector = settings.UseTextureChannelComponents; tex.Export($"{filePath}.{ext}"); + Runtime.ImageEditor.UseComponetSelector = compSetting; } private void SearchArchive(BatchFormatExport.Settings settings, IArchiveFile archiveFile,