public void treeRefresh() { if (VBN == null) { return; } treeView1.Nodes.Clear(); VBN.reset(false); treeView1.BeginUpdate(); foreach (Bone b in VBN.bones) { if (b.Parent == null) { treeView1.Nodes.Add(b); } } treeView1.EndUpdate(); treeView1.ExpandAll(); listBox1.Items.Clear(); foreach (var item in VBN.bones) { listBox1.Items.Add(item); } cBLE.Checked = VBN.Endian == Endianness.Little; }
public void Apply(VBN vbn, int frame) { if (frame == 0) { vbn.reset(); } OMOFrame keys = Frames[frame]; foreach (OMONode node in Nodes) { foreach (Bone b in vbn.bones) { if (b.boneId == node.hash) { // apply interpolation frames Console.WriteLine(b.Text); node.Apply(b, keys); break; } } } vbn.update(); }
public static void ArrangeBones(VBN vbn, NUD nud) { Dictionary <int, int> boneReorder = new Dictionary <int, int>(); int i = 0; for (i = 0; i < boneOrder.Count; i++) { int j = 0; for (j = 0; j < vbn.bones.Count; j++) { if (vbn.bones[j].Text.Equals(boneOrder[i])) { break; } } boneReorder.Add(j, i); } // get rest of the bones for (int j = 0; j < vbn.bones.Count; j++) { if (!boneReorder.Keys.Contains(j)) { boneReorder.Add(j, i++); } } // reorder vbn Bone[] nList = new Bone[vbn.bones.Count]; foreach (int k in boneReorder.Keys) { nList[boneReorder[k]] = vbn.bones[k]; //if (new string(vbn.bones[k].boneName).Equals("RotN")) vbn.bones[k].parentIndex = 0; if (vbn.bones[k].parentIndex != -1 && vbn.bones[k].parentIndex != 0x0FFFFFFF) { vbn.bones[k].parentIndex = boneReorder[vbn.bones[k].parentIndex]; } } vbn.bones.Clear(); vbn.bones.AddRange(nList); vbn.reset(); // now fix the nud foreach (NUD.Mesh mesh in nud.Nodes) { foreach (NUD.Polygon poly in mesh.Nodes) { foreach (NUD.Vertex v in poly.vertices) { for (int k = 0; k < v.boneIds.Count; k++) { v.boneIds[k] = boneReorder[v.boneIds[k]]; } } } } nud.UpdateRenderMeshes(); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.ToLower().Equals("make pichu plz")) { using (FolderBrowserDialog ofd = new FolderBrowserDialog()) { if (ofd.ShowDialog() == DialogResult.OK) { Pichu.MakePichu(ofd.SelectedPath); } } Close(); return; } else if (textBox1.Text.Equals("THRoW")) { //If you are reading this he kidnapped me and made me do it System.Diagnostics.Process.Start("https://twitter.com/realheroofwinds"); Close(); return; } if (textBox1.Text.Equals("")) { return; } Bone temp = new Bone(vbn); temp.Text = textBox1.Text; if (!textBox2.Text.Equals("")) { temp.boneId = (uint)int.Parse(textBox2.Text, System.Globalization.NumberStyles.HexNumber); } if (!textBox3.Text.Equals("")) { temp.boneType = Convert.ToUInt32(textBox3.Text); } if (parent != null) { parent.Nodes.Add(temp); } //if (Runtime.TargetVBN.bones.Count > 0) // temp.ParentBone = parent; temp.position = new float[] { 0f, 0f, 0f }; temp.rotation = new float[] { 0f, 0f, 0f }; temp.scale = new float[] { 1f, 1f, 1f }; vbn.bones.Add(temp); vbn.totalBoneCount++; vbn.boneCountPerType[temp.boneType]++; vbn.reset(); //MainForm.Instance.boneTreePanel.treeRefresh(); Close(); }
public static void effectiveScale(NUD nud, VBN vbn, Matrix4 sca) { foreach (Bone b in vbn.bones) { Vector3 pos = Vector3.TransformVector(new Vector3(b.position[0], b.position[1], b.position[2]), sca); b.position[0] = pos.X; b.position[1] = pos.Y; b.position[2] = pos.Z; } vbn.reset(); foreach (NUD.Mesh mesh in nud.Nodes) { foreach (NUD.Polygon poly in mesh.Nodes) { foreach (NUD.Vertex v in poly.vertices) { v.pos = Vector3.TransformVector(v.pos, sca); } } } nud.UpdateRenderMeshes(); }
public void treeRefresh() { if (VBN == null) { return; } treeView1.Nodes.Clear(); VBN.reset(false); treeView1.BeginUpdate(); foreach (Bone b in VBN.bones) { if (b.Parent == null) { treeView1.Nodes.Add(b); } } treeView1.EndUpdate(); treeView1.ExpandAll(); }
public void NextFrame(VBN skeleton, bool isChild = false) { if (Frame >= FrameCount) { return; } if (Frame == 0 && !isChild) { skeleton.reset(); } foreach (object child in Children) { if (child is Animation) { ((Animation)child).SetFrame(Frame); ((Animation)child).NextFrame(skeleton, isChild: true); } if (child is MTA) { //foreach (ModelContainer con in Runtime.ModelContainers) { if (((ModelContainer)skeleton.Parent).NUD != null) { ((ModelContainer)skeleton.Parent).NUD.ApplyMta(((MTA)child), (int)Frame); } } } if (child is BFRES.MTA) //For BFRES { { if (((ModelContainer)skeleton.Parent).BFRES != null) { ((ModelContainer)skeleton.Parent).BFRES.ApplyMta(((BFRES.MTA)child), (int)Frame); } } } } bool Updated = false; // no need to update skeleton of animations that didn't change foreach (KeyNode node in Bones) { // Get Skeleton Node Bone b = null; if (node.Hash == -1) { b = skeleton.getBone(node.Text); } else { b = skeleton.GetBone((uint)node.Hash); } if (b == null) { continue; } Updated = true; if (node.XPOS.HasAnimation() && b.boneType != 3) { b.pos.X = node.XPOS.GetValue(Frame); } if (node.YPOS.HasAnimation() && b.boneType != 3) { b.pos.Y = node.YPOS.GetValue(Frame); } if (node.ZPOS.HasAnimation() && b.boneType != 3) { b.pos.Z = node.ZPOS.GetValue(Frame); } if (node.XSCA.HasAnimation()) { b.sca.X = node.XSCA.GetValue(Frame); } else { b.sca.X = 1; } if (node.YSCA.HasAnimation()) { b.sca.Y = node.YSCA.GetValue(Frame); } else { b.sca.Y = 1; } if (node.ZSCA.HasAnimation()) { b.sca.Z = node.ZSCA.GetValue(Frame); } else { b.sca.Z = 1; } if (node.XROT.HasAnimation() || node.YROT.HasAnimation() || node.ZROT.HasAnimation()) { if (node.RotType == RotationType.QUATERNION) { KeyFrame[] x = node.XROT.GetFrame(Frame); KeyFrame[] y = node.YROT.GetFrame(Frame); KeyFrame[] z = node.ZROT.GetFrame(Frame); KeyFrame[] w = node.WROT.GetFrame(Frame); Quaternion q1 = new Quaternion(x[0].Value, y[0].Value, z[0].Value, w[0].Value); Quaternion q2 = new Quaternion(x[1].Value, y[1].Value, z[1].Value, w[1].Value); if (x[0].Frame == Frame) { b.rot = q1; } else if (x[1].Frame == Frame) { b.rot = q2; } else { b.rot = Quaternion.Slerp(q1, q2, (Frame - x[0].Frame) / (x[1].Frame - x[0].Frame)); } } else if (node.RotType == RotationType.EULER) { float x = node.XROT.HasAnimation() ? node.XROT.GetValue(Frame) : b.rotation[0]; float y = node.YROT.HasAnimation() ? node.YROT.GetValue(Frame) : b.rotation[1]; float z = node.ZROT.HasAnimation() ? node.ZROT.GetValue(Frame) : b.rotation[2]; b.rot = EulerToQuat(z, y, x); } } } Frame += 1f; if (Frame >= FrameCount) { Frame = 0; } if (!isChild && Updated) { skeleton.update(); } }
public void nextFrame(VBN vbn) { if (frame >= frames.Count) { return; } if (frame == 0 && Main) { vbn.reset(); foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null && con.mta != null) { con.nud.applyMTA(con.mta, 0); } } } if (children.Count > 0) { Main = true; } foreach (object child in children) { if (child is SkelAnimation) { ((SkelAnimation)child).setFrame(frame); ((SkelAnimation)child).nextFrame(vbn); } if (child is MTA) { foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null) { con.nud.applyMTA(((MTA)child), frame); } } } } KeyFrame key = frames[frame]; foreach (KeyNode n in key.nodes) { //if (n.id == -1) // continue; //if (n.hash == 0) { //continue; //n.hash = vbn.bones [n.id].boneId; //} int id = -1; foreach (Bone bo in vbn.bones) { if (bo.boneId == n.hash) { id = vbn.bones.IndexOf(bo); n.id = id; break; } } if (id == -1) { continue; } Bone b = vbn.bones[id]; if (n.t_type != -1) { b.pos = n.t; } if (n.r_type != -1) { //if(new string(b.boneName).Equals("HeadN")) // Console.WriteLine(n.r.ToString() + (n.r.X + n.r.Y + n.r.X + n.r.W)); //Console.WriteLine(new string(b.boneName) + " " + b.rot.ToString() + " " + n.r.ToString() + "\n" + (n.r.X + n.r.Y + n.r.X + n.r.W)); b.rot = n.r; } if (n.s_type != -1) { b.sca = n.s; } else { b.sca = new Vector3(b.scale[0], b.scale[1], b.scale[2]); } } frame++; if (frame >= frames.Count) { frame = 0; } vbn.update(); }
public void nextFrame(VBN vbn, bool isChild = false) { if (frame >= frames.Count) { return; } if (frame == 0 && (!isChild || children.Count > 0)) { vbn.reset(); foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null && con.mta != null) { con.nud.applyMTA(con.mta, 0); } } } foreach (object child in children) { if (child is SkelAnimation) { ((SkelAnimation)child).setFrame(frame); ((SkelAnimation)child).nextFrame(vbn, isChild: true); } if (child is MTA) { foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null) { con.nud.applyMTA(((MTA)child), frame); } } } } KeyFrame key = frames[frame]; foreach (KeyNode n in key.nodes) { //if (n.id == -1) // continue; //if (n.hash == 0) { //continue; //n.hash = vbn.bones [n.id].boneId; //} int id = -1; foreach (Bone bo in vbn.bones) { if (bo.boneId == n.hash) { id = vbn.bones.IndexOf(bo); n.id = id; break; } } if (id == -1) { continue; } Bone b = vbn.bones[id]; if (n.t_type != -1)// !b.isSwingBone) { b.pos = n.t; } // We don't do the same swingBone check on rotation because as of yet // I have not seen an example of the rotation data being garbage, and it's // actually used properly in the animations - Struz if (n.r_type != -1) { if (b.Text.Equals("HeadN")) { //Console.WriteLine(b.transform.ExtractRotation().ToString()); //Console.WriteLine(VBN.FromEulerAngles(b.rotation[0], b.rotation[1], b.rotation[2]).ToString()); //Console.WriteLine(n.r.ToString() + " " + Math.Sqrt(n.r.X* n.r.X + n.r.Y* n.r.Y + n.r.Z* n.r.Z + n.r.W*n.r.W) + " " + n.r.Normalized().ToString()); } //Console.WriteLine(new string(b.boneName) + " " + b.rot.ToString() + " " + n.r.ToString() + "\n" + (n.r.X + n.r.Y + n.r.X + n.r.W)); b.rot = n.r; } if (n.s_type != -1) { b.sca = n.s; } else { b.sca = new Vector3(b.scale[0], b.scale[1], b.scale[2]); } } frame++; if (frame >= frames.Count) { frame = 0; } vbn.update(); }
public void NextFrame(VBN skeleton, bool isChild = false) { if (Frame == 0 && !isChild) { skeleton.reset(); } foreach (object child in Children) { if (child is Animation) { ((Animation)child).SetFrame(Frame); ((Animation)child).NextFrame(skeleton, isChild: true); } if (child is MTA) { foreach (ModelContainer con in Runtime.ModelContainers) { if (con.nud != null) { con.nud.applyMTA(((MTA)child), (int)Frame); } } } } foreach (KeyNode node in Bones) { // Get Skeleton Node Bone b = skeleton.getBone(node.Text); if (b == null) { continue; } if (node.XPOS.HasAnimation()) { b.pos.X = node.XPOS.GetValue(Frame); } if (node.YPOS.HasAnimation()) { b.pos.Y = node.YPOS.GetValue(Frame); } if (node.ZPOS.HasAnimation()) { b.pos.Z = node.ZPOS.GetValue(Frame); } if (node.XSCA.HasAnimation()) { b.sca.X = node.XSCA.GetValue(Frame); } else { b.sca.X = 1; } if (node.YSCA.HasAnimation()) { b.sca.Y = node.YSCA.GetValue(Frame); } else { b.sca.Y = 1; } if (node.ZSCA.HasAnimation()) { b.sca.Z = node.ZSCA.GetValue(Frame); } else { b.sca.Z = 1; } if (node.XROT.HasAnimation()) { if (node.RotType == RotationType.QUATERNION) { KeyFrame[] x = node.XROT.GetFrame(Frame); KeyFrame[] y = node.YROT.GetFrame(Frame); KeyFrame[] z = node.ZROT.GetFrame(Frame); KeyFrame[] w = node.WROT.GetFrame(Frame); Quaternion q1 = new Quaternion(x[0].Value, y[0].Value, z[0].Value, w[0].Value); Quaternion q2 = new Quaternion(x[1].Value, y[1].Value, z[1].Value, w[1].Value); if (x[0].Frame == Frame) { b.rot = q1; } else if (x[1].Frame == Frame) { b.rot = q2; } else { b.rot = Quaternion.Slerp(q1, q2, (Frame - x[0].Frame) / (x[1].Frame - x[0].Frame)); } } else if (node.RotType == RotationType.EULER) { float x = node.XROT.HasAnimation() ? node.XROT.GetValue(Frame) : b.rotation[0]; float y = node.YROT.HasAnimation() ? node.YROT.GetValue(Frame) : b.rotation[1]; float z = node.ZROT.HasAnimation() ? node.ZROT.GetValue(Frame) : b.rotation[2]; b.rot = EulerToQuat(z, y, x); } } } Frame += 1f; if (Frame >= FrameCount) { Frame = 0; } skeleton.update(); }
public void Read(string fname) { StreamReader reader = File.OpenText(fname); string line; string current = ""; Bones = new VBN(); Triangles = new List <SMDTriangle>(); Dictionary <int, Bone> BoneList = new Dictionary <int, Bone>(); int time = 0; while ((line = reader.ReadLine()) != null) { line = Regex.Replace(line, @"\s+", " "); string[] args = line.Replace(";", "").TrimStart().Split(' '); if (args[0].Equals("triangles") || args[0].Equals("end") || args[0].Equals("skeleton") || args[0].Equals("nodes")) { current = args[0]; continue; } if (current.Equals("nodes")) { int id = int.Parse(args[0]); Bone b = new Bone(Bones); b.Text = args[1].Replace('"', ' ').Trim(); int s = 2; while (args[s].Contains("\"")) { b.Text += args[s++]; } b.parentIndex = int.Parse(args[s]); BoneList.Add(id, b); } if (current.Equals("skeleton")) { if (args[0].Contains("time")) { time = int.Parse(args[1]); } else { if (time == 0) { Bone b = BoneList[int.Parse(args[0])]; b.position = new float[3]; b.rotation = new float[3]; b.scale = new float[3]; b.position[0] = float.Parse(args[1]); b.position[1] = float.Parse(args[2]); b.position[2] = float.Parse(args[3]); b.rotation[0] = float.Parse(args[4]); b.rotation[1] = float.Parse(args[5]); b.rotation[2] = float.Parse(args[6]); b.scale[0] = 1f; b.scale[1] = 1f; b.scale[2] = 1f; b.pos = new Vector3(float.Parse(args[1]), float.Parse(args[2]), float.Parse(args[3])); b.rot = VBN.FromEulerAngles(float.Parse(args[6]), float.Parse(args[5]), float.Parse(args[4])); Bones.bones.Add(b); if (b.parentIndex != -1) { b.parentIndex = Bones.bones.IndexOf(BoneList[b.parentIndex]); } } } } if (current.Equals("triangles")) { string meshName = args[0]; if (args[0].Equals("")) { continue; } SMDTriangle t = new SMDTriangle(); Triangles.Add(t); t.Material = meshName; for (int j = 0; j < 3; j++) { line = reader.ReadLine(); line = Regex.Replace(line, @"\s+", " "); args = line.Replace(";", "").TrimStart().Split(' '); int parent = int.Parse(args[0]); SMDVertex vert = new SMDVertex(); vert.P = new Vector3(float.Parse(args[1]), float.Parse(args[2]), float.Parse(args[3])); vert.N = new Vector3(float.Parse(args[4]), float.Parse(args[5]), float.Parse(args[6])); vert.UV = new Vector2(float.Parse(args[7]), float.Parse(args[8])); vert.Bones = new int[0]; vert.Weights = new float[0]; if (args.Length > 9) { int wCount = int.Parse(args[9]); int w = 10; vert.Bones = new int[wCount]; vert.Weights = new float[wCount]; for (int i = 0; i < wCount; i++) { vert.Bones[i] = (int.Parse(args[w++])); vert.Weights[i] = (float.Parse(args[w++])); } } switch (j) { case 0: t.v1 = vert; break; case 1: t.v2 = vert; break; case 2: t.v3 = vert; break; } } } } Bones.reset(); }