Beispiel #1
0
        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;
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
 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();
 }
Beispiel #7
0
        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();
            }
        }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        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.tType != -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.rType != -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.sType != -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();
        }