private void toolStripButton5_Click(object sender, EventArgs e) { int n = toolStripComboBox1.SelectedIndex; string selectedSkeleton = null; if (toolStripComboBox2.Enabled && toolStripComboBox2.SelectedIndex > 1) { selectedSkeleton = (string)toolStripComboBox2.SelectedItem; } ExportMeshSaveDialog emsd = new ExportMeshSaveDialog(mesh.lods.Count, 100f, false, (mesh.header.type == MeshType.MeshType_Skinned), selectedSkeleton, n); if (emsd.ShowDialog() == DialogResult.OK) { // we try to load the skeleton only if none was already selected for preview // or if one was selected and it is different from the one selected in the option window if (!skeletons.ContainsKey(toolStripComboBox2.SelectedItem.ToString()) || (skeletons.ContainsKey(toolStripComboBox2.SelectedItem.ToString()) && skeletons[toolStripComboBox2.SelectedItem.ToString()] != emsd.Skeleton)) { string sha1 = emsd.Skeleton; if (sha1 != null) { var sebx = new EBX(new MemoryStream(main.Host.getDataBySha1(Helpers.HexStringToByteArray(sha1)))); skeleton = new SkeletonAsset(sebx); } } // scale float aScale = emsd.ExportScale; // get exporter by format var exporter = MeshExporter.GetExporterByExtension(emsd.Format, skeleton); if (exporter != null) { if (emsd.AllLod) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select folder where to save the lods"; if (fbd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; for (int i = 0; i < mesh.lods.Count; i++) { PrepareLodForExport(mesh, i); } exporter.ExportAllLods(mesh, fbd.SelectedPath, aScale); MessageBox.Show("Done."); Cursor.Current = Cursors.Default; } } else { // lod int sLod = emsd.Lod; SaveFileDialog saveFileDiag = new SaveFileDialog(); saveFileDiag.Title = "Save as..."; saveFileDiag.Filter = "*" + emsd.Format + "|*" + emsd.Format; saveFileDiag.FileName = mesh.lods[n].shortName; if (saveFileDiag.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string targetFile = saveFileDiag.FileName; PrepareLodForExport(mesh, sLod); exporter.ExportLod(mesh, sLod, targetFile, aScale); MessageBox.Show("Done."); Cursor.Current = Cursors.Default; } } } else { MessageBox.Show("Unknown extension " + emsd.Format); } } }
// export selected morph : // search for base mesh and applies selected morph deformation to it and to selected skeleton and exports the result. private void exportMorphToolStripMenuItem_Click(object sender, EventArgs e) { if (rawEbxBuffer != null && rawResBuffer != null) { string morphName = Path.GetFileName(currPath); var morph = new MorphStaticExtended(new MemoryStream(rawResBuffer), new MemoryStream(rawEbxBuffer), morphName); ExportMeshSaveDialog emd = new ExportMeshSaveDialog(morph.LodCount, 100f, true); if (emd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; // look for preset Mesh DataInfo presetMeshRes = SearchItemRES(morph.PresetMesh); if (presetMeshRes != null) { byte[] meshData = main.Host.getDataBySha1(presetMeshRes.sha1); MeshAsset presetMeshAsset = new MeshAsset(new MemoryStream(meshData)); SkeletonAsset skeleton = null; int lod = emd.Lod; string sha1 = emd.Skeleton; if (sha1 != null) { var sebx = new EBX(new MemoryStream(main.Host.getDataBySha1(Helpers.HexStringToByteArray(sha1)))); skeleton = new SkeletonAsset(sebx); } float oScale = emd.ExportScale; bool bakeMorphToMesh = emd.BakeMorph; string ext = emd.Format; IMeshExporter exporter = MeshExporter.GetExporterByExtension(ext, skeleton); Cursor.Current = Cursors.Default; if (emd.AllLod) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select folder where to save all LODS..."; if (fbd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; for (int i = 0; i < morph.LodCount; i++) { ChunkInfo lodChunk = SearchChunk(Helpers.ByteArrayToHexString(presetMeshAsset.lods[i].chunkID)); if (lodChunk != null) { byte[] rawChunkBuffer = main.Host.getDataBySha1(lodChunk.sha1); presetMeshAsset.lods[i].LoadVertexData(new MemoryStream(rawChunkBuffer)); } } exporter.ExportAllLodsWithMorph(presetMeshAsset, morph, fbd.SelectedPath, oScale, bakeMorphToMesh); MessageBox.Show("Done."); Cursor.Current = Cursors.Default; } } else { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save Morph as..."; sfd.Filter = "*" + ext + "|*" + ext; sfd.FileName = Path.GetFileName(currPath) + ext; if (sfd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; ChunkInfo lodChunk = SearchChunk(Helpers.ByteArrayToHexString(presetMeshAsset.lods[lod].chunkID)); if (lodChunk != null) { byte[] rawChunkBuffer = main.Host.getDataBySha1(lodChunk.sha1); presetMeshAsset.lods[lod].LoadVertexData(new MemoryStream(rawChunkBuffer)); exporter.ExportLodWithMorph(presetMeshAsset, lod, morph, sfd.FileName, oScale, bakeMorphToMesh); MessageBox.Show("Done."); Cursor.Current = Cursors.Default; } else { MessageBox.Show("Error : chunk for this lod was not found"); } } } Cursor.Current = Cursors.Default; } else { MessageBox.Show("Error : Res data corresponding to preset mesh " + morph.PresetMesh + " not found."); } } } }