private void exportAsObjToolStripMenuItem_Click(object sender, EventArgs e) { byte[] data = BF2FileSystem.GetFileFromNode(tv2.SelectedNode); string path = BF2FileSystem.GetPathFromNode(tv2.SelectedNode); string name = Path.GetFileNameWithoutExtension(path) + ".obj"; string ext = Path.GetExtension(path); SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = name; dlg.Filter = "*.obj|*.obj"; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { switch (ext) { case ".staticmesh": ExporterObj.Export(new BF2StaticMesh(data), dlg.FileName, toolStripComboBox1.SelectedIndex); break; case ".bundledmesh": ExporterObj.Export(new BF2BundledMesh(data), dlg.FileName, toolStripComboBox1.SelectedIndex); break; case ".skinnedmesh": ExporterObj.Export(new BF2SkinnedMesh(data), dlg.FileName, toolStripComboBox1.SelectedIndex); break; case ".collisionmesh": ExporterObj.Export(new BF2CollisionMesh(data), dlg.FileName); break; } Log.WriteLine(dlg.FileName + " exported."); } }
private void contextMenuMeshes_Opening(object sender, CancelEventArgs e) { exportAsObjToolStripMenuItem.Enabled = true; if (tv2.SelectedNode == null) { exportAsObjToolStripMenuItem.Enabled = false; return; } byte[] data = BF2FileSystem.GetFileFromNode(tv2.SelectedNode); if (data == null) { exportAsObjToolStripMenuItem.Enabled = false; return; } string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv2.SelectedNode)).ToLower(); switch (ending) { case ".staticmesh": case ".skinnedmesh": case ".bundledmesh": case ".collisionmesh": break; default: exportAsObjToolStripMenuItem.Enabled = false; return; } }
private void tv1_DoubleClick(object sender, EventArgs e) { if (tv1.SelectedNode == null) { return; } byte[] data = BF2FileSystem.GetFileFromNode(tv1.SelectedNode); if (data == null) { return; } string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)).ToLower(); switch (ending) { case ".inc": case ".xml": case ".txt": case ".con": case ".tweak": TextEditor te = new TextEditor(); te.rtb1.Text = Encoding.ASCII.GetString(data); te.ShowDialog(); if (te._exitOk) { BF2FileSystem.SetFileFromNode(tv1.SelectedNode, Encoding.ASCII.GetBytes(te.rtb1.Text)); } break; } }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { string name = Path.GetFileName(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)); string ext = Path.GetExtension(name); OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName = name; dlg.Filter = "*" + ext + "|*" + ext; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { BF2FileSystem.SetFileFromNode(tv1.SelectedNode, File.ReadAllBytes(dlg.FileName)); Log.WriteLine(dlg.FileName + " imported."); } }
private void PickMesh() { if (tv2.SelectedNode == null) { return; } engineMeshExplorer.ClearScene(); byte[] data = BF2FileSystem.GetFileFromNode(tv2.SelectedNode); if (data == null) { return; } string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv2.SelectedNode)).ToLower(); switch (ending) { case ".staticmesh": BF2StaticMesh stm = new BF2StaticMesh(data); engineMeshExplorer.objects.AddRange(stm.ConvertForEngine(engineMeshExplorer, toolStripButton3.Checked, toolStripComboBox1.SelectedIndex)); break; case ".bundledmesh": BF2BundledMesh bm = new BF2BundledMesh(data); engineMeshExplorer.objects.AddRange(bm.ConvertForEngine(engineMeshExplorer, toolStripButton3.Checked, toolStripComboBox1.SelectedIndex)); break; case ".skinnedmesh": BF2SkinnedMesh skm = new BF2SkinnedMesh(data); engineMeshExplorer.objects.AddRange(skm.ConvertForEngine(engineMeshExplorer, toolStripButton3.Checked, toolStripComboBox1.SelectedIndex)); break; case ".collisionmesh": BF2CollisionMesh cm = new BF2CollisionMesh(data); engineMeshExplorer.objects.AddRange(cm.ConvertForEngine(engineMeshExplorer)); break; default: RenderObject o = new RenderObject(engineMeshExplorer.device, RenderObject.RenderType.TriListWired, engineMeshExplorer.defaultTexture, engineMeshExplorer); o.InitGeometry(); engineMeshExplorer.objects.Add(o); break; } engineMeshExplorer.ResetCameraDistance(); }
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) { if (tv1.SelectedNode == null) { e.Cancel = true; return; } byte[] data = BF2FileSystem.GetFileFromNode(tv1.SelectedNode); if (data == null) { e.Cancel = true; return; } string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)).ToLower(); switch (ending) { default: break; } }
private void tv1_AfterSelect(object sender, TreeViewEventArgs e) { byte[] data = BF2FileSystem.GetFileFromNode(tv1.SelectedNode); if (data == null) { return; } string ending = Path.GetExtension(BF2FileSystem.GetPathFromNode(tv1.SelectedNode)).ToLower(); rtb1.Visible = hb1.Visible = pic1.Visible = false; switch (ending) { case ".inc": case ".xml": case ".txt": case ".con": case ".tweak": rtb1.Visible = true; rtb1.Text = Encoding.ASCII.GetString(data); break; case ".png": pic1.Visible = true; pic1.Image = new Bitmap(new MemoryStream(data)); break; case ".tga": File.WriteAllBytes("temp.tga", data); Helper.ConvertToPNG("temp.tga"); pic1.Visible = true; if (File.Exists("temp.png")) { pic1.Image = new Bitmap(new MemoryStream(File.ReadAllBytes("temp.png"))); File.Delete("temp.png"); } else { pic1.Image = null; pic1.Height = pic1.Width = 1; } File.Delete("temp.tga"); break; case ".dds": File.WriteAllBytes("temp.dds", data); Helper.ConvertToPNG("temp.dds"); pic1.Visible = true; if (File.Exists("temp.png")) { pic1.Image = new Bitmap(new MemoryStream(File.ReadAllBytes("temp.png"))); File.Delete("temp.png"); } else { pic1.Image = null; pic1.Height = pic1.Width = 1; } File.Delete("temp.dds"); break; default: hb1.Visible = true; hb1.ByteProvider = new DynamicByteProvider(data); break; } }