diff --git a/SPICA.WinForms/FrmExport.Designer.cs b/SPICA.WinForms/FrmExport.Designer.cs index f5e08c75..25eb8eeb 100644 --- a/SPICA.WinForms/FrmExport.Designer.cs +++ b/SPICA.WinForms/FrmExport.Designer.cs @@ -29,8 +29,11 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.GrpInput = new System.Windows.Forms.GroupBox(); + this.GrpAnimationInput = new System.Windows.Forms.GroupBox(); this.BtnBrowseIn = new System.Windows.Forms.Button(); this.TxtInputFolder = new System.Windows.Forms.TextBox(); + this.BtnBrowseAnimationIn = new System.Windows.Forms.Button(); + this.TxtInputAnimationFolder = new System.Windows.Forms.TextBox(); this.GrpOutput = new System.Windows.Forms.GroupBox(); this.ChkPrefixNames = new System.Windows.Forms.CheckBox(); this.ChkExportModels = new System.Windows.Forms.CheckBox(); @@ -42,6 +45,7 @@ private void InitializeComponent() this.BtnConvert = new System.Windows.Forms.Button(); this.ProgressConv = new System.Windows.Forms.ProgressBar(); this.GrpInput.SuspendLayout(); + this.GrpAnimationInput.SuspendLayout(); this.GrpOutput.SuspendLayout(); this.SuspendLayout(); // @@ -56,6 +60,17 @@ private void InitializeComponent() this.GrpInput.TabStop = false; this.GrpInput.Text = "Input folder"; // + // GrpAnimationInput + // + this.GrpAnimationInput.Controls.Add(this.BtnBrowseAnimationIn); + this.GrpAnimationInput.Controls.Add(this.TxtInputAnimationFolder); + this.GrpAnimationInput.Location = new System.Drawing.Point(12, 63); + this.GrpAnimationInput.Name = "GrpAnimationInput"; + this.GrpAnimationInput.Size = new System.Drawing.Size(360, 51); + this.GrpAnimationInput.TabIndex = 0; + this.GrpAnimationInput.TabStop = false; + this.GrpAnimationInput.Text = "Input animation folder"; + // // BtnBrowseIn // this.BtnBrowseIn.Location = new System.Drawing.Point(322, 21); @@ -73,6 +88,23 @@ private void InitializeComponent() this.TxtInputFolder.Size = new System.Drawing.Size(310, 22); this.TxtInputFolder.TabIndex = 0; // + // TxtInputAnimationFolder + // + this.TxtInputAnimationFolder.Location = new System.Drawing.Point(6, 22); + this.TxtInputAnimationFolder.Name = "TxtInputAnimationFolder"; + this.TxtInputAnimationFolder.Size = new System.Drawing.Size(310, 22); + this.TxtInputAnimationFolder.TabIndex = 0; + // + // BtnBrowseAnimationIn + // + this.BtnBrowseAnimationIn.Location = new System.Drawing.Point(322, 21); + this.BtnBrowseAnimationIn.Name = "BtnBrowseAnimationIn"; + this.BtnBrowseAnimationIn.Size = new System.Drawing.Size(32, 24); + this.BtnBrowseAnimationIn.TabIndex = 1; + this.BtnBrowseAnimationIn.Text = "..."; + this.BtnBrowseAnimationIn.UseVisualStyleBackColor = true; + this.BtnBrowseAnimationIn.Click += new System.EventHandler(this.BtnBrowseAnimationIn_Click); + // // GrpOutput // this.GrpOutput.Controls.Add(this.ChkPrefixNames); @@ -82,7 +114,7 @@ private void InitializeComponent() this.GrpOutput.Controls.Add(this.CmbFormat); this.GrpOutput.Controls.Add(this.BtnBrowseOut); this.GrpOutput.Controls.Add(this.TxtOutFolder); - this.GrpOutput.Location = new System.Drawing.Point(12, 69); + this.GrpOutput.Location = new System.Drawing.Point(12, 114); this.GrpOutput.Name = "GrpOutput"; this.GrpOutput.Size = new System.Drawing.Size(360, 140); this.GrpOutput.TabIndex = 0; @@ -184,6 +216,7 @@ private void InitializeComponent() this.Controls.Add(this.BtnConvert); this.Controls.Add(this.GrpOutput); this.Controls.Add(this.GrpInput); + this.Controls.Add(this.GrpAnimationInput); this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; @@ -193,6 +226,8 @@ private void InitializeComponent() this.Load += new System.EventHandler(this.FrmExport_Load); this.GrpInput.ResumeLayout(false); this.GrpInput.PerformLayout(); + this.GrpAnimationInput.ResumeLayout(false); + this.GrpAnimationInput.PerformLayout(); this.GrpOutput.ResumeLayout(false); this.GrpOutput.PerformLayout(); this.ResumeLayout(false); @@ -202,8 +237,11 @@ private void InitializeComponent() #endregion private System.Windows.Forms.GroupBox GrpInput; + private System.Windows.Forms.GroupBox GrpAnimationInput; private System.Windows.Forms.Button BtnBrowseIn; private System.Windows.Forms.TextBox TxtInputFolder; + private System.Windows.Forms.Button BtnBrowseAnimationIn; + private System.Windows.Forms.TextBox TxtInputAnimationFolder; private System.Windows.Forms.GroupBox GrpOutput; private System.Windows.Forms.CheckBox ChkPrefixNames; private System.Windows.Forms.CheckBox ChkExportModels; diff --git a/SPICA.WinForms/FrmExport.cs b/SPICA.WinForms/FrmExport.cs index fb7de035..86852ef6 100644 --- a/SPICA.WinForms/FrmExport.cs +++ b/SPICA.WinForms/FrmExport.cs @@ -1,4 +1,5 @@ using SPICA.Formats.CtrH3D; +using SPICA.Formats.CtrH3D.Model; using SPICA.Formats.CtrH3D.Texture; using SPICA.Formats.Generic.COLLADA; using SPICA.Formats.Generic.StudioMdl; @@ -9,40 +10,34 @@ using System.Threading.Tasks; using System.Windows.Forms; -namespace SPICA.WinForms -{ - public partial class FrmExport : Form - { - public FrmExport() - { +namespace SPICA.WinForms { + public partial class FrmExport : Form { + public FrmExport() { InitializeComponent(); } - private void FrmExport_Load(object sender, EventArgs e) - { + private void FrmExport_Load(object sender, EventArgs e) { CmbFormat.SelectedIndex = 0; } - private void BtnBrowseIn_Click(object sender, EventArgs e) - { - using (FolderBrowserDialog Browser = new FolderBrowserDialog()) - { + private void BtnBrowseIn_Click(object sender, EventArgs e) { + using (FolderBrowserDialog Browser = new FolderBrowserDialog()) { if (Browser.ShowDialog() == DialogResult.OK) TxtInputFolder.Text = Browser.SelectedPath; } } - - private void BtnBrowseOut_Click(object sender, EventArgs e) - { - using (FolderBrowserDialog Browser = new FolderBrowserDialog()) - { + private void BtnBrowseAnimationIn_Click(object sender, EventArgs e) { + using (FolderBrowserDialog Browser = new FolderBrowserDialog()) { + if (Browser.ShowDialog() == DialogResult.OK) TxtInputAnimationFolder.Text = Browser.SelectedPath; + } + } + private void BtnBrowseOut_Click(object sender, EventArgs e) { + using (FolderBrowserDialog Browser = new FolderBrowserDialog()) { if (Browser.ShowDialog() == DialogResult.OK) TxtOutFolder.Text = Browser.SelectedPath; } } - private void BtnConvert_Click(object sender, EventArgs e) - { - if (!Directory.Exists(TxtInputFolder.Text)) - { + private void BtnConvert_Click(object sender, EventArgs e) { + if (!Directory.Exists(TxtInputFolder.Text)) { MessageBox.Show( "Input folder not found!", "Error", @@ -52,8 +47,7 @@ private void BtnConvert_Click(object sender, EventArgs e) return; } - if (!Directory.Exists(TxtOutFolder.Text)) - { + if (!Directory.Exists(TxtOutFolder.Text)) { MessageBox.Show( "Output folder not found!", "Error", @@ -64,6 +58,7 @@ private void BtnConvert_Click(object sender, EventArgs e) } string[] Files = Directory.GetFiles(TxtInputFolder.Text); + string[] AnimationFiles = Directory.GetFiles(TxtInputAnimationFolder.Text); bool ExportModels = ChkExportModels.Checked; bool ExportAnims = ChkExportAnimations.Checked; @@ -74,51 +69,49 @@ private void BtnConvert_Click(object sender, EventArgs e) int FileIndex = 0; + int CountFiles = 0; //TODO: Use Parallel loop for more speed and keep UI responsive - foreach (string File in Files) - { + foreach (string File in Files) { H3D Data = FormatIdentifier.IdentifyAndOpen(File); - - if (Data != null) - { + if (Data != null) { string BaseName = PrefixNames ? Path.GetFileNameWithoutExtension(File) + "_" : string.Empty; BaseName = Path.Combine(TxtOutFolder.Text, BaseName); if (!PrefixNames) BaseName += Path.DirectorySeparatorChar; - if (ExportModels) - { - for (int Index = 0; Index < Data.Models.Count; Index++) - { + if (ExportModels) { + for (int Index = 0; Index < Data.Models.Count; Index++) { string FileName = BaseName + Data.Models[Index].Name; - switch (Format) - { + switch (Format) { case 0: new DAE(Data, Index).Save(FileName + ".dae"); break; case 1: new SMD(Data, Index).Save(FileName + ".smd"); break; } } } - - if (ExportAnims && Data.Models.Count > 0) - { - for (int Index = 0; Index < Data.SkeletalAnimations.Count; Index++) - { - string FileName = BaseName + Data.Models[0].Name + "_" + Data.SkeletalAnimations[Index].Name; - - switch (Format) - { - case 0: new DAE(Data, 0, Index).Save(FileName + ".dae"); break; - case 1: new SMD(Data, 0, Index).Save(FileName + ".smd"); break; + if (ExportAnims) { + string Filename = Path.GetFileName(File); + string ModelFolder = File.Replace(Filename, ""); + + foreach (string AnimationFile in AnimationFiles) { + if (AnimationFile.Contains(Filename)) { + string AnimationFolder = AnimationFile.Replace(Filename, ""); + string[] MergedFiles = new string[] { Path.Combine(ModelFolder, Filename), Path.Combine(AnimationFolder, Filename) }; + H3D MergedData = FileIO.Merge(MergedFiles, new Rendering.Renderer(1, 1), Data); + for (int Index = 0; Index < MergedData.SkeletalAnimations.Count; Index++) { + string FileName = BaseName + MergedData.Models[0].Name + "_" + MergedData.SkeletalAnimations[Index].Name; + switch (Format) { + case 0: new DAE(MergedData, 0, Index).Save(FileName + ".dae"); break; + case 1: new SMD(MergedData, 0, Index).Save(FileName + ".smd"); break; + } + } } } } - if (ExportTexs) - { - foreach (H3DTexture Tex in Data.Textures) - { + if (ExportTexs) { + foreach (H3DTexture Tex in Data.Textures) { Tex.ToBitmap().Save(Path.Combine(TxtOutFolder.Text, Tex.Name + ".png")); } } @@ -131,6 +124,7 @@ private void BtnConvert_Click(object sender, EventArgs e) ProgressConv.Value = (int)Progress; Application.DoEvents(); + CountFiles++; } } }