public static void Export(BF2SkinnedMesh mesh, string filename, int geoMatIdx) { StringBuilder sb = new StringBuilder(); Helper.BF2MeshSKMGeometryMaterial lod0 = mesh.geomat[geoMatIdx]; int vertexcounter = 1; for (int i = 0; i < lod0.numMaterials; i++) { Helper.BF2MeshSKMMaterial mat = lod0.materials[i]; List <RenderObject.VertexTextured> list = new List <RenderObject.VertexTextured>(); int m = mesh.geometry.vertices.Count / (int)mesh.geometry.numVertices; for (int j = 0; j < mat.numIndicies; j++) { int pos = (mesh.geometry.indices[(int)mat.indiciesStartIndex + j] + (int)mat.vertexStartIndex) * m; list.Add(mesh.GetVertex(pos)); } if (mat.numIndicies != 0) { WriteObject(sb, list, "Material" + i, vertexcounter); vertexcounter += list.Count(); } } File.WriteAllText(filename, sb.ToString()); }
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 exportALLAsObjToolStripMenuItem_Click(object sender, EventArgs e) { exportALLAsObjToolStripMenuItem.Enabled = false; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string basePath = fbd.SelectedPath + "\\"; pb1.Maximum = BF2FileSystem.clientFS.Count; int count = 0; foreach (BF2FileSystem.BF2FSEntry entry in BF2FileSystem.clientFS) { pb1.Value = count++; try { string ending = Path.GetExtension(entry.inFSPath).ToLower(); switch (ending) { case ".staticmesh": case ".bundledmesh": case ".skinnedmesh": case ".collisionmesh": break; default: continue; } string path = basePath + Path.GetDirectoryName(entry.inFSPath); byte[] data = BF2FileSystem.GetFileFromEntry(entry); if (data == null) { continue; } switch (ending) { case ".staticmesh": CheckAndMakeDir(path); path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath); Log.WriteLine("Exporting \"" + path + ".staticmesh\"..."); BF2StaticMesh stm = new BF2StaticMesh(data); for (int i = 0; i < stm.geomat.Count; i++) { ExporterObj.Export(stm, path + ".lod" + i + ".obj", i); } break; case ".bundledmesh": CheckAndMakeDir(path); path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath); Log.WriteLine("Exporting \"" + path + ".bundledmesh\"..."); BF2BundledMesh bm = new BF2BundledMesh(data); for (int i = 0; i < bm.geomat.Count; i++) { ExporterObj.Export(bm, path + ".lod" + i + ".obj", i); } break; case ".skinnedmesh": CheckAndMakeDir(path); path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath); Log.WriteLine("Exporting \"" + path + ".skinnedmesh\"..."); BF2SkinnedMesh skm = new BF2SkinnedMesh(data); for (int i = 0; i < skm.geomat.Count; i++) { ExporterObj.Export(skm, path + ".lod" + i + ".obj", i); } break; case ".collisionmesh": CheckAndMakeDir(path); path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath); Log.WriteLine("Exporting \"" + path + ".bundledmesh\"..."); ExporterObj.Export(new BF2CollisionMesh(data), path + ".obj"); break; } } catch (Exception ex) { Log.WriteLine("ERROR: " + ex.Message); } Application.DoEvents(); } pb1.Value = 0; exportALLAsObjToolStripMenuItem.Enabled = true; } }