private void cHRTToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "CHRT|*.chrt"; if (openFileDialog.ShowDialog() == DialogResult.OK) { CHRT chrt = new CHRT(); chrt.Read(openFileDialog.FileName); List <ModelNode> nodes = chrt.RootNode.GetAllNodes(); foreach (ModelNode node in nodes) { Console.WriteLine("ID: {0}, Model: {1}, Position: {2}", node.CHRTID, node.ModelName, node.Position); } } }
static void ExportCHRT(string path, string outPath, string archiveDir) { if (archiveDir == null) { Console.WriteLine("No archive directory supplied."); return; } if (!File.Exists(path)) { Console.WriteLine("{0} does not exist as a file, falling back to batch mode.", path); if (Directory.Exists(path)) { var ext = new List <string> { ".chrt" }; var myFiles = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s).ToLower())); foreach (string file in myFiles) { var currentChildDir = outPath + "\\" + Path.GetDirectoryName(file.Replace(path, "")); string filename = Path.GetFileName(file); string dest = currentChildDir + "\\_" + filename + "_\\" + Path.ChangeExtension(filename, ".chrt.obj"); string dir = Path.GetDirectoryName(dest); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } try { ExportCHRT(file, dest, archiveDir); if (bVerbose) { Console.WriteLine("Converting {0} to {1}", file, dest); } } catch (Exception e) { Console.WriteLine("Oops! {0} failed!\nException: {1}", file, e.ToString()); ++iNumFailedOperations; } ++iNumOperations; } } else { Console.WriteLine("{0} does not exist. Cancelling operation.", path); return; } } else { try { CHRT chrt = new CHRT(); chrt.Read(path); if (chrt != null) { foreach (ModelNode node in chrt.RootNode.GetAllNodes()) { if (node.ModelName == "" || node.CHRTID == null) { continue; } if (node.Position == Vector3.Zero) { continue; } var tempOutputPath = outPath; var ext = new List <string> { ".mt5", ".MT5" }; var myFiles = Directory.GetFiles(archiveDir, "*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s).ToLower())); foreach (string file in myFiles) { string filename = Path.GetFileName(file); try { if (Path.GetFileNameWithoutExtension(file).ToUpper() == node.ModelName.ToUpper()) { tempOutputPath += "\\" + node.ModelName + ".chrt.obj"; MT5 newNode = new MT5(file); OBJ newModel = new OBJ(newNode); if (newNode != null && newModel != null) { newModel.RootNode.Position = node.Position; newModel.RootNode.Rotation = node.Rotation; newModel.RootNode.Scale = node.Scale; newModel.Write(tempOutputPath); } Console.WriteLine("Converted {0} into {1}", node.ModelName, tempOutputPath); break; } } catch (Exception e) { Console.WriteLine("Oops! {0} failed!\nException: {1}", file, e.ToString()); ++iNumFailedOperations; } } } } } catch (Exception e) { Console.WriteLine("Oops! {0} failed!\nException: {1}", path, e.ToString()); ++iNumFailedOperations; } ++iNumOperations; } return; }