private void BtnConvert_Click(object sender, EventArgs e) { if (!Directory.Exists(TxtInputFolder.Text)) { MessageBox.Show( "Input folder not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Directory.Exists(TxtOutFolder.Text)) { MessageBox.Show( "Output folder not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string[] Files = Directory.GetFiles(TxtInputFolder.Text); bool ExportModels = ChkExportModels.Checked; bool ExportAnims = ChkExportAnimations.Checked; bool ExportTexs = ChkExportTextures.Checked; bool PrefixNames = ChkPrefixNames.Checked; int Format = CmbFormat.SelectedIndex; int FileIndex = 0; //TODO: Use Parallel loop for more speed and keep UI responsive foreach (string File in Files) { H3D Data = FormatIdentifier.IdentifyAndOpen(File); 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++) { string FileName = BaseName + Data.Models[Index].Name; 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, new int[] { Index }).Save(FileName + ".dae"); break; case 1: new SMD(Data, 0, Index).Save(FileName + ".smd"); break; } } } if (ExportTexs) { foreach (H3DTexture Tex in Data.Textures) { Tex.ToBitmap().Save(Path.Combine(TxtOutFolder.Text, Tex.Name + ".png")); } } } float Progress = ++FileIndex; Progress = (Progress / Files.Length) * 100; ProgressConv.Value = (int)Progress; Application.DoEvents(); } }
private void BtnConvert_Click(object sender, EventArgs e) { if (!Directory.Exists(TxtInputFolder.Text)) { MessageBox.Show( "Input folder not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Directory.Exists(TxtOutFolder.Text)) { //TODO: offer to create output dir "Output folder not found! Should it be created?" MessageBox.Show( "Output folder not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } bool ExportModels = ChkExportModels.Checked; bool ExportAnims = ChkExportAnimations.Checked; bool ExportTexs = ChkExportTextures.Checked; bool PrefixNames = ChkPrefixNames.Checked; bool ExportMats = ChkExportMaterials.Checked; bool Recurse = ChkRecurse.Checked; int Format = CmbFormat.SelectedIndex; int MatFormat = CmbMatFormat.SelectedIndex; BtnConvert.Enabled = false; //get all files (optionally recursive) in input folder DirectoryInfo Folder = new DirectoryInfo(TxtInputFolder.Text); FileInfo[] Files = Folder.GetFiles("*.*", Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); //TODO: check and warn on empty input folder string subPath; string outPath = TxtOutFolder.Text; if (!outPath.EndsWith(Path.DirectorySeparatorChar.ToString())) { outPath += Path.DirectorySeparatorChar; } int FileIndex = 0; string[] ignoredExts = TxtIgnoredExt.Text.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); //for each one //TODO: Use Parallel loop for more speed and keep UI responsive foreach (FileInfo File in Files) { //TODO: add ext blacklist if (Array.IndexOf(ignoredExts, File.Extension.ToLower().Remove(0, 1)) > -1) { FileIndex++; continue; } subPath = GetRelativePath(File.DirectoryName, TxtInputFolder.Text); if (subPath.Length > 0 && !Directory.Exists(outPath + subPath)) { Directory.CreateDirectory(outPath + subPath); } //open input file, read and convert to H3D data H3D Data = FormatIdentifier.IdentifyAndOpen(File.FullName); //if there is data (input file was valid) if (Data != null) { string BaseName = PrefixNames ? Path.GetFileNameWithoutExtension(File.FullName) + "_" : string.Empty; BaseName = Path.Combine(outPath + subPath, BaseName); if (!PrefixNames) { BaseName += Path.DirectorySeparatorChar; } if (ExportModels) { for (int Index = 0; Index < Data.Models.Count; Index++) { string FileName = BaseName + Data.Models[Index].Name; switch (Format) { case 0: new DAE(Data, Index, -1, Settings.Default.DebugCopyVtxAlpha).Save(FileName + ".dae"); break; case 1: new SMD(Data, Index).Save(FileName + ".smd"); break; } } } if (ExportMats) { for (int Index = 0; Index < Data.Models.Count; Index++) { string FileName = BaseName + Data.Models[Index].Name; switch (MatFormat) { case 0: new MaterialScript(Data, Index).Save(FileName + ".ms"); break; case 1: new MaterialDump(Data, Index).Save(FileName + ".txt"); 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 (ExportTexs) { foreach (H3DTexture Tex in Data.Textures) { Tex.ToBitmap().Save(Path.Combine(outPath + subPath, Tex.Name + ".png")); } } } //update progress bar float Progress = ++FileIndex; Progress = (Progress / Files.Length) * 100; ProgressConv.Value = (int)Progress; Application.DoEvents(); } ProgressConv.Value = 100; BtnConvert.Enabled = true; }