private void RigVertex(ref GXVertex P, VBN RenderBones, List <DatBoneWeight> Weight, DatJOBJ[] jobjs, DatJOBJ Parent = null) { if (Weight.Count == 1) { int i; for (i = 0; i < jobjs.Length; i++) { if (jobjs[i] == Weight[0].jobj) { break; } } Vector3 NewP = Vector3.TransformPosition(new Vector3(P.Pos.X, P.Pos.Y, P.Pos.Z), RenderBones.bones[i].transform.Inverted()); P.Pos.X = NewP.X; P.Pos.Y = NewP.Y; P.Pos.Z = NewP.Z; NewP = Vector3.TransformNormal(new Vector3(P.Nrm.X, P.Nrm.Y, P.Nrm.Z), RenderBones.bones[i].transform.Inverted()); P.Nrm.X = NewP.X; P.Nrm.Y = NewP.Y; P.Nrm.Z = NewP.Z; } if (Weight.Count == 0 && Parent != null) { int i; for (i = 0; i < jobjs.Length; i++) { if (jobjs[i] == Parent) { break; } } Vector3 NewP = Vector3.TransformPosition(new Vector3(P.Pos.X, P.Pos.Y, P.Pos.Z), RenderBones.bones[i].transform.Inverted()); P.Pos.X = NewP.X; P.Pos.Y = NewP.Y; P.Pos.Z = NewP.Z; NewP = Vector3.TransformNormal(new Vector3(P.Nrm.X, P.Nrm.Y, P.Nrm.Z), RenderBones.bones[i].transform.Inverted()); P.Nrm.X = NewP.X; P.Nrm.Y = NewP.Y; P.Nrm.Z = NewP.Z; } }
private GXVertex SMDVertexToGXVertex(SmdVertex v) { GXVertex o = new GXVertex() { Pos = new GXVector3(v.p.X, v.p.Y, v.p.Z), Nrm = new GXVector3(v.n.X, v.n.Y, v.n.Z), TX0 = new GXVector2(v.uv.X, v.uv.Y), }; return(o); }
private GXVertex SMDVertexToGXVertex(SMDVertex v) { GXVertex o = new GXVertex() { Pos = new GXVector3(v.P.X, v.P.Y, v.P.Z), Nrm = new GXVector3(v.N.X, v.N.Y, v.N.Z), TX0 = new GXVector2(v.UV.X, v.UV.Y), }; return(o); }
public SMDVertex GXVertexToSMDVertex(GXVertex v) { SMDVertex smdv = new SMDVertex() { Parent = 0, P = new Vector3(v.Pos.X, v.Pos.Y, v.Pos.Z), N = new Vector3(v.Nrm.X, v.Nrm.Y, v.Nrm.Z), UV = new Vector2(v.TX0.X, v.TX0.Y), }; smdv.Bones = v.N; smdv.Weights = v.W; return(smdv); }
public SmdVertex GXVertexToSMDVertex(GXVertex v) { SmdVertex smdv = new SmdVertex() { parent = 0, p = new Vector3(v.Pos.X, v.Pos.Y, v.Pos.Z), n = new Vector3(v.Nrm.X, v.Nrm.Y, v.Nrm.Z), uv = new Vector2(v.TX0.X, v.TX0.Y), }; smdv.bones = v.N; smdv.weights = v.W; return(smdv); }
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(); }