public void ExportAs(object sender, EventArgs args) { using (var sfd = new SaveFileDialog()) { sfd.Filter = "Source Model|*.smd|" + "All Files (*.*)|*.*"; sfd.DefaultExt = "smd"; if (sfd.ShowDialog() == DialogResult.OK) { GXVertexDecompressor decom = new GXVertexDecompressor(Root); Smd smd = new Smd(); smd.bones = RenderBones; foreach (MeleeDataObjectNode n in DataObjects.Nodes) { int[] ind; List <GXVertex> verts; n.GetVerticesAsTriangles(out ind, out verts); for (int i = 0; i < ind.Length; i += 3) { SmdTriangle t = new SmdTriangle(); t.material = "defaultmaterial"; t.v1 = GXVertexToSMDVertex(verts[ind[i]]); t.v2 = GXVertexToSMDVertex(verts[ind[i + 1]]); t.v3 = GXVertexToSMDVertex(verts[ind[i + 2]]); smd.triangles.Add(t); } } smd.Save(sfd.FileName); } } }
private void LoadMesh(string meshName) { var meshData = Smd.FromFile(meshName); using (var data = new DataStream(meshData.Indices.ToArray(), true, false)) { indices = new Buffer(device, data, new BufferDescription(meshData.Indices.Count * 4, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None)); indexCount = meshData.Indices.Count; } using (var data = new DataStream(meshData.Positions.ToArray(), true, false)) { vertices = new Buffer(device, data, new BufferDescription(meshData.Positions.Count * 4 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None)); } using (var data = new DataStream(meshData.Normals.ToArray(), true, false)) { normals = new Buffer(device, data, new BufferDescription(meshData.Normals.Count * 4 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None)); } using (var data = new DataStream(meshData.TextureCoordinates.ToArray(), true, false)) { texCoords = new Buffer(device, data, new BufferDescription(meshData.TextureCoordinates.Count * 4 * 2, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None)); } }
private void buttonImport_Click(object sender, EventArgs e) { Smd smd = new Smd(ModelSrc); DatJOBJ[] Bones = DOBJ.GetRoot().Root.GetJOBJinOrder(); VBN RenderBones = DOBJ.GetRoot().RenderBones; RenderBones.reset(); RenderBones.update(); VBN ImportedBones = smd.bones; GXAttribGroup AttrGroup = null; if (listBox1.SelectedIndex != -1) { AttrGroup = DOBJ.GetRoot().Root.Attributes[listBox1.SelectedIndex]; } else { MessageBox.Show("Please select an attribute group"); return; } DOBJ.ClearPolygons(null, null); int Flags = 0x8000; if (comboBoxBoneType.SelectedIndex == 0) { MessageBox.Show("Warning: no binds"); } if (comboBoxBoneType.SelectedIndex == 1) { Flags = 0xA001; } if (comboBoxBoneType.SelectedIndex == 2) // Rigged - needs to create bonelist { Flags = 0xA001; } DatPolygon p = new DatPolygon(); p.AttributeGroup = AttrGroup; p.Flags = Flags; p.ParentDOBJ = DOBJ.DOBJ; DOBJ.VertsToImport = new List <GXVertex[]>(); List <GXVertex> vert = new List <GXVertex>(); DatJOBJ parent = DOBJ.DOBJ.Parent; if (comboBoxBoneType.SelectedIndex == 1) { ImportedBones = RenderBones; } foreach (SmdTriangle t in smd.triangles) { if (comboBoxBoneType.SelectedIndex == 1) { // single bind t.v1.bones = new int[] { CBBone.SelectedIndex }; t.v1.weights = new float[] { 1 }; t.v2.bones = new int[] { CBBone.SelectedIndex }; t.v2.weights = new float[] { 1 }; t.v3.bones = new int[] { CBBone.SelectedIndex }; t.v3.weights = new float[] { 1 }; } List <DatBoneWeight> bwl1 = CreateWeightList(t.v1.bones, t.v1.weights, Bones, ImportedBones); List <DatBoneWeight> bwl2 = CreateWeightList(t.v2.bones, t.v2.weights, Bones, ImportedBones); List <DatBoneWeight> bwl3 = CreateWeightList(t.v3.bones, t.v3.weights, Bones, ImportedBones); int bid1 = GetWeightListIndex(p.BoneWeightList, bwl1); int bid2 = GetWeightListIndex(p.BoneWeightList, bwl2); int bid3 = GetWeightListIndex(p.BoneWeightList, bwl3); int wc = p.BoneWeightList.Count; if (bid1 == -1) { wc++; } if (bid2 == -1) { wc++; } if (bid3 == -1) { wc++; } if (wc >= 10) // need new polygon { DOBJ.VertsToImport.Add(vert.ToArray()); vert.Clear(); p = new DatPolygon(); p.AttributeGroup = AttrGroup; p.Flags = Flags; p.ParentDOBJ = DOBJ.DOBJ; } bid1 = GetWeightListIndex(p.BoneWeightList, bwl1); bid2 = GetWeightListIndex(p.BoneWeightList, bwl2); bid3 = GetWeightListIndex(p.BoneWeightList, bwl3); if (bid1 == -1) { p.BoneWeightList.Add(bwl1); } if (bid2 == -1) { p.BoneWeightList.Add(bwl2); } if (bid3 == -1) { p.BoneWeightList.Add(bwl3); } bid1 = GetWeightListIndex(p.BoneWeightList, bwl1); bid2 = GetWeightListIndex(p.BoneWeightList, bwl2); bid3 = GetWeightListIndex(p.BoneWeightList, bwl3); GXVertex v = SMDVertexToGXVertex(t.v1); v.PMXID = GetWeightListIndex(p.BoneWeightList, bwl1); RigVertex(ref v, RenderBones, p.BoneWeightList[v.PMXID / 3], Bones, parent); GXVertex v2 = SMDVertexToGXVertex(t.v2); v2.PMXID = GetWeightListIndex(p.BoneWeightList, CreateWeightList(t.v2.bones, t.v2.weights, Bones, ImportedBones)); RigVertex(ref v2, RenderBones, p.BoneWeightList[v2.PMXID / 3], Bones, parent); GXVertex v3 = SMDVertexToGXVertex(t.v3); v3.PMXID = GetWeightListIndex(p.BoneWeightList, CreateWeightList(t.v3.bones, t.v3.weights, Bones, ImportedBones)); RigVertex(ref v3, RenderBones, p.BoneWeightList[v3.PMXID / 3], Bones, parent); vert.Add(v); vert.Add(v2); vert.Add(v3); } DOBJ.VertsToImport.Add(vert.ToArray()); exitStatus = ExitStatus.Opened; Close(); }