private void DisplayMorphDetails(DataInfo res, DataInfo ebx) { currPath = res.path; rawEbxBuffer = main.Host.getDataBySha1(ebx.sha1); rawResBuffer = main.Host.getDataBySha1(res.sha1); if (rawResBuffer == null || rawEbxBuffer == null) { TreeNode noDataNode = new TreeNode(); noDataNode.Text = "Unable to find raw data buffers for this morph"; tv3.Nodes.Clear(); tv3.Nodes.Add(noDataNode); return; } try { hb1.ByteProvider = new DynamicByteProvider(rawEbxBuffer); hb2.ByteProvider = new DynamicByteProvider(rawResBuffer); string morphName = Path.GetFileName(currPath); var morph = new MorphStaticExtended(new MemoryStream(rawResBuffer), new MemoryStream(rawEbxBuffer), morphName); MorphDetailsTB.Text = morph.ToJson(); tv3.Nodes.Clear(); tv3.Nodes.Add(JsonToTree.ToNode(morph.ToJson(), "MorphStatic")); } catch (Exception ex) { TreeNode ErrorNode = new TreeNode(); ErrorNode.Text = "ERROR!!!:\n" + ex.Message + "\n\n"; tv3.Nodes.Clear(); tv3.Nodes.Add(ErrorNode); } }
// 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."); } } } }