Ejemplo n.º 1
0
        public Animation ToAnimation(VBN vbn)
        {
            Animation animation = new Animation(anim.Name);

            animation.frameCount = anim.frameCount;

            int i = 0;

            foreach (Bone b in vbn.bones)
            {
                i = vbn.boneIndex(b.Text);

                if (i < anim.nodes.Count)
                {
                    List <DAT_Animation.DATAnimTrack> tracks = anim.nodes[i];

                    Animation.KeyNode node = new Animation.KeyNode(b.Text);
                    node.rotType = Animation.RotationType.Euler;

                    foreach (DAT_Animation.DATAnimTrack track in tracks)
                    {
                        switch (track.type)
                        {
                        case DAT_Animation.AnimType.XPOS:
                            node.xpos = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.YPOS:
                            node.ypos = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.ZPOS:
                            node.zpos = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.XROT:
                            node.xrot = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.YROT:
                            node.yrot = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.ZROT:
                            node.zrot = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.XSCA:
                            node.xsca = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.YSCA:
                            node.ysca = CreateKeyGroup(i, track, false);
                            break;

                        case DAT_Animation.AnimType.ZSCA:
                            node.zsca = CreateKeyGroup(i, track, false);
                            break;
                        }
                    }

                    if (node.xsca.HasAnimation() || node.ysca.HasAnimation() || node.zsca.HasAnimation() ||
                        node.xpos.HasAnimation() || node.ypos.HasAnimation() || node.zpos.HasAnimation() ||
                        node.xrot.HasAnimation() || node.yrot.HasAnimation() || node.zrot.HasAnimation())
                    {
                        animation.bones.Add(node);
                    }
                }
            }

            return(animation);
        }
Ejemplo n.º 2
0
        private static void writeKey(StreamWriter file, Animation.KeyGroup keys, Animation.KeyNode rt, int size, string type)
        {
            file.WriteLine("animData {\n input time;\n output linear;\n weighted 1;\n preInfinity constant;\n postInfinity constant;\n keys {");

            if (((Animation.KeyFrame)keys.keys[0]).interType == Animation.InterpolationType.Constant)
            {
                size = 1;
            }

            foreach (Animation.KeyFrame key in keys.keys)
            {
                float v = 0;

                float scale = 1;
                switch (type)
                {
                case "translateX":
                    v = key.Value;
                    break;

                case "translateY":
                    v = key.Value;
                    break;

                case "translateZ":
                    v = key.Value;
                    break;

                case "rotateX":
                    if (rt.rotType == Animation.RotationType.Euler)
                    {
                        v = key.Value * (float)(180f / Math.PI);
                    }
                    if (rt.rotType == Animation.RotationType.Quaternion)
                    {
                        Quaternion q = new Quaternion(rt.xrot.GetValue(key.Frame), rt.yrot.GetValue(key.Frame), rt.zrot.GetValue(key.Frame), rt.wrot.GetValue(key.Frame));
                        v = quattoeul(q).X *(float)(180f / Math.PI);
                    }
                    scale = (float)(180f / Math.PI);
                    break;

                case "rotateY":
                    if (rt.rotType == Animation.RotationType.Euler)
                    {
                        v = key.Value * (float)(180f / Math.PI);
                    }
                    if (rt.rotType == Animation.RotationType.Quaternion)
                    {
                        Quaternion q = new Quaternion(rt.xrot.GetValue(key.Frame), rt.yrot.GetValue(key.Frame), rt.zrot.GetValue(key.Frame), rt.wrot.GetValue(key.Frame));
                        v = quattoeul(q).Y *(float)(180f / Math.PI);
                    }
                    scale = (float)(180f / Math.PI);
                    break;

                case "rotateZ":
                    if (rt.rotType == Animation.RotationType.Euler)
                    {
                        v = key.Value * (float)(180f / Math.PI);
                    }
                    if (rt.rotType == Animation.RotationType.Quaternion)
                    {
                        Quaternion q = new Quaternion(rt.xrot.GetValue(key.Frame), rt.yrot.GetValue(key.Frame), rt.zrot.GetValue(key.Frame), rt.wrot.GetValue(key.Frame));
                        v = quattoeul(q).Z *(float)(180f / Math.PI);
                    }
                    scale = (float)(180f / Math.PI);
                    break;

                case "scaleX":
                    v = key.Value;
                    break;

                case "scaleY":
                    v = key.Value;
                    break;

                case "scaleZ":
                    v = key.Value;
                    break;
                }

                file.WriteLine(" " + (key.Frame + 1) + " {0:N6} fixed fixed 1 1 0 " + key.In * scale + " 1 " + (key.Out != -1 ? key.Out : key.In) * scale + " 1;", v);
            }

            file.WriteLine(" }");
        }
Ejemplo n.º 3
0
        public static Animation read(string filename, VBN vbn)
        {
            Animation a = new Animation(filename);

            Animation.KeyNode  current = null;
            Animation.KeyFrame att     = new Animation.KeyFrame();

            StreamReader reader = File.OpenText(filename);
            string       line;

            AnimHeader header   = new AnimHeader();
            bool       inHeader = true;
            bool       inKeys   = false;
            string     type     = "";

            while ((line = reader.ReadLine()) != null)
            {
                string[] args = line.Replace(";", "").TrimStart().Split(' ');

                if (inHeader)
                {
                    if (args[0].Equals("anim"))
                    {
                        inHeader = false;
                    }
                    else if (args[0].Equals("animVersion"))
                    {
                        header.animVersion = args[1];
                    }
                    else if (args[0].Equals("mayaVersion"))
                    {
                        header.mayaVersion = args[1];
                    }
                    else if (args[0].Equals("startTime"))
                    {
                        header.startTime = float.Parse(args[1]);
                    }
                    else if (args[0].Equals("endTime"))
                    {
                        header.endTime = float.Parse(args[1]);
                    }
                    else if (args[0].Equals("startUnitless"))
                    {
                        header.startUnitless = float.Parse(args[1]);
                    }
                    else if (args[0].Equals("endUnitless"))
                    {
                        header.endUnitless = float.Parse(args[1]);
                    }
                    else if (args[0].Equals("timeUnit"))
                    {
                        header.timeUnit = args[1];
                    }
                    else if (args[0].Equals("linearUnit"))
                    {
                        header.linearUnit = args[1];
                    }
                    else if (args[0].Equals("angularUnit"))
                    {
                        header.angularUnit = args[1];
                    }
                }
                if (!inHeader)
                {
                    if (inKeys)
                    {
                        if (args[0].Equals("}"))
                        {
                            inKeys = false;
                            continue;
                        }
                        Animation.KeyFrame k = new Animation.KeyFrame();
                        //att.keys.Add (k);
                        if (type.Contains("translate"))
                        {
                            if (type.Contains("X"))
                            {
                                current.xpos.keys.Add(k);
                            }
                            if (type.Contains("Y"))
                            {
                                current.ypos.keys.Add(k);
                            }
                            if (type.Contains("Z"))
                            {
                                current.zpos.keys.Add(k);
                            }
                        }
                        if (type.Contains("rotate"))
                        {
                            if (type.Contains("X"))
                            {
                                current.xrot.keys.Add(k);
                            }
                            if (type.Contains("Y"))
                            {
                                current.yrot.keys.Add(k);
                            }
                            if (type.Contains("Z"))
                            {
                                current.zrot.keys.Add(k);
                            }
                        }
                        if (type.Contains("scale"))
                        {
                            if (type.Contains("X"))
                            {
                                current.xsca.keys.Add(k);
                            }
                            if (type.Contains("Y"))
                            {
                                current.ysca.keys.Add(k);
                            }
                            if (type.Contains("Z"))
                            {
                                current.zsca.keys.Add(k);
                            }
                        }
                        k.Frame = float.Parse(args[0]) - 1;
                        k.Value = float.Parse(args[1]);
                        if (type.Contains("rotate"))
                        {
                            k.Value *= (float)(Math.PI / 180f);
                        }
                        //k.intan = (args [2]);
                        //k.outtan = (args [3]);
                        if (args.Length > 7 && att.weighted)
                        {
                            k.In  = float.Parse(args[7]) * (float)(Math.PI / 180f);
                            k.Out = float.Parse(args[8]) * (float)(Math.PI / 180f);
                        }
                    }

                    if (args[0].Equals("anim"))
                    {
                        inKeys = false;
                        if (args.Length == 5)
                        {
                            //TODO: finish this type
                            // can be name of attribute
                        }
                        if (args.Length == 7)
                        {
                            // see of the bone of this attribute exists
                            current = null;
                            foreach (Animation.KeyNode b in a.bones)
                            {
                                if (b.Text.Equals(args[3]))
                                {
                                    current = b;
                                    break;
                                }
                            }
                            if (current == null)
                            {
                                current         = new Animation.KeyNode(args[3]);
                                current.rotType = Animation.RotationType.Euler;
                                a.bones.Add(current);
                            }
                            current.Text = args[3];

                            att           = new Animation.KeyFrame();
                            att.interType = Animation.InterpolationType.Hermite;
                            type          = args[2];
                            //current.Nodes.Add (att);

                            // row child attribute aren't needed here
                        }
                    }

                    /*if (args [0].Equals ("input"))
                     *  att.input = args [1];
                     * if (args [0].Equals ("output"))
                     *  att.output = args [1];
                     * if (args [0].Equals ("preInfinity"))
                     *  att.preInfinity = args [1];
                     * if (args [0].Equals ("postInfinity"))
                     *  att.postInfinity = args [1];*/
                    if (args[0].Equals("weighted"))
                    {
                        att.weighted = args[1].Equals("1");
                    }


                    // begining keys section
                    if (args[0].Contains("keys"))
                    {
                        inKeys = true;
                    }
                }
            }

            int startTime = (int)Math.Ceiling(header.startTime);
            int endTime   = (int)Math.Ceiling(header.endTime);

            a.frameCount = (endTime + 1) - startTime;

            reader.Close();
            return(a);
        }
Ejemplo n.º 4
0
        public static byte[] CreateOMOFromAnimation(Animation a, VBN vbn)
        {
            if (vbn == null || a == null)
            {
                return new byte[] { }
            }
            ;

            // Test Actual Bones
            //-------------------------

            List <Animation.KeyNode> toRem = new List <Animation.KeyNode>();

            for (int j = 0; j < a.bones.Count; j++)
            {
                Animation.KeyNode keynode = ((Animation.KeyNode)a.bones[j]);
                Bone b = vbn.getBone(keynode.Text);

                if (b == null)
                {
                    toRem.Add(keynode);
                }
            }
            foreach (Animation.KeyNode r in toRem)
            {
                Console.WriteLine("Removing " + r.Text);
                a.bones.Remove(r);
            }

            //-------------------------

            FileOutput o = new FileOutput();

            o.endian = Endianness.Big;

            FileOutput t1 = new FileOutput();

            t1.endian = Endianness.Big;

            FileOutput t2 = new FileOutput();

            t2.endian = Endianness.Big;

            o.WriteString("OMO ");
            o.WriteShort(1);        //idk
            o.WriteShort(3);        //idk

            o.WriteInt(0x091E100C); //flags??


            o.WriteShort(0);             //padding
            o.WriteShort(a.bones.Count); // numOfNodes

            o.WriteShort(a.frameCount);  // frame size
            o.WriteShort(0);             // frame start ??

            o.WriteInt(0);
            o.WriteInt(0);
            o.WriteInt(0);

            o.WriteIntAt(o.Size(), 0x14);

            // ASSESSMENT
            Vector3[] maxT     = new Vector3[a.bones.Count], minT = new Vector3[a.bones.Count];
            Vector4[] maxR     = new Vector4[a.bones.Count], minR = new Vector4[a.bones.Count];
            Vector3[] maxS     = new Vector3[a.bones.Count], minS = new Vector3[a.bones.Count];
            bool[]    hasScale = new bool[a.bones.Count];
            bool[]    hasTrans = new bool[a.bones.Count];
            bool[]    hasRot   = new bool[a.bones.Count];

            bool[] conScale = new bool[a.bones.Count];
            bool[] conTrans = new bool[a.bones.Count];
            bool[] conRot   = new bool[a.bones.Count];

            a.SetFrame(0);

            List <List <Bone> > Frames = new List <List <Bone> >();

            {
                for (int j = 0; j < a.bones.Count; j++)
                {
                    Animation.KeyNode keynode = ((Animation.KeyNode)a.bones[j]);
                    if (keynode.xpos.HasAnimation() || keynode.ypos.HasAnimation() || keynode.zpos.HasAnimation())
                    {
                        hasTrans[j] = true;
                    }
                    if (keynode.xrot.HasAnimation())
                    {
                        hasRot[j] = true;
                    }
                    if (keynode.xsca.HasAnimation() || keynode.ysca.HasAnimation() || keynode.zsca.HasAnimation())
                    {
                        hasScale[j] = true;
                    }

                    maxT[j] = new Vector3(-999f, -999f, -999f);
                    minT[j] = new Vector3(999f, 999f, 999f);
                    maxS[j] = new Vector3(-999f, -999f, -999f);
                    minS[j] = new Vector3(999f, 999f, 999f);
                    maxR[j] = new Vector4(-999f, -999f, -999f, -999f);
                    minR[j] = new Vector4(999f, 999f, 999f, 999f);

                    foreach (Animation.KeyFrame key in keynode.xpos.keys)
                    {
                        maxT[j].X = Math.Max(maxT[j].X, key.Value);
                        minT[j].X = Math.Min(minT[j].X, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.ypos.keys)
                    {
                        maxT[j].Y = Math.Max(maxT[j].Y, key.Value);
                        minT[j].Y = Math.Min(minT[j].Y, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.zpos.keys)
                    {
                        maxT[j].Z = Math.Max(maxT[j].Z, key.Value);
                        minT[j].Z = Math.Min(minT[j].Z, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.xsca.keys)
                    {
                        maxS[j].X = Math.Max(maxS[j].X, key.Value);
                        minS[j].X = Math.Min(minS[j].X, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.ysca.keys)
                    {
                        maxS[j].Y = Math.Max(maxS[j].Y, key.Value);
                        minS[j].Y = Math.Min(minS[j].Y, key.Value);
                    }
                    foreach (Animation.KeyFrame key in keynode.zsca.keys)
                    {
                        maxS[j].Z = Math.Max(maxS[j].Z, key.Value);
                        minS[j].Z = Math.Min(minS[j].Z, key.Value);
                    }

                    Bone b = vbn.getBone(keynode.Text);
                    for (int i = 0; i < a.frameCount; i++)
                    {
                        Quaternion r = new Quaternion();
                        if (keynode.rotType == Animation.RotationType.Quaternion)
                        {
                            Animation.KeyFrame[] x  = keynode.xrot.GetFrame(i);
                            Animation.KeyFrame[] y  = keynode.yrot.GetFrame(i);
                            Animation.KeyFrame[] z  = keynode.zrot.GetFrame(i);
                            Animation.KeyFrame[] w  = keynode.wrot.GetFrame(i);
                            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 == i)
                            {
                                r = q1;
                            }
                            else
                            if (x[1].Frame == i)
                            {
                                r = q2;
                            }
                            else
                            {
                                r = Quaternion.Slerp(q1, q2, (i - x[0].Frame) / (x[1].Frame - x[0].Frame));
                            }
                        }
                        else
                        if (keynode.rotType == Animation.RotationType.Euler)
                        {
                            float x = keynode.xrot.HasAnimation() ? keynode.xrot.GetValue(i) : b.rotation[0];
                            float y = keynode.yrot.HasAnimation() ? keynode.yrot.GetValue(i) : b.rotation[1];
                            float z = keynode.zrot.HasAnimation() ? keynode.zrot.GetValue(i) : b.rotation[2];
                            r = Animation.EulerToQuat(z, y, x);
                        }
                        r.Normalize();

                        maxR[j].X = Math.Max(maxR[j].X, r.X);
                        minR[j].X = Math.Min(minR[j].X, r.X);
                        maxR[j].Y = Math.Max(maxR[j].Y, r.Y);
                        minR[j].Y = Math.Min(minR[j].Y, r.Y);
                        maxR[j].Z = Math.Max(maxR[j].Z, r.Z);
                        minR[j].Z = Math.Min(minR[j].Z, r.Z);
                    }

                    //if (b == null)continue;
                    if (b != null)
                    {
                        if (maxT[j].X == -999)
                        {
                            maxT[j].X = b.position[0];
                        }
                        if (maxT[j].Y == -999)
                        {
                            maxT[j].Y = b.position[1];
                        }
                        if (maxT[j].Z == -999)
                        {
                            maxT[j].Z = b.position[2];
                        }
                        if (minT[j].X == -999)
                        {
                            minT[j].X = b.position[0];
                        }
                        if (minT[j].Y == -999)
                        {
                            minT[j].Y = b.position[1];
                        }
                        if (minT[j].Z == -999)
                        {
                            minT[j].Z = b.position[2];
                        }

                        if (maxS[j].X == -999)
                        {
                            maxS[j].X = b.scale[0];
                        }
                        if (maxS[j].Y == -999)
                        {
                            maxS[j].Y = b.scale[1];
                        }
                        if (maxS[j].Z == -999)
                        {
                            maxS[j].Z = b.scale[2];
                        }
                        if (minS[j].X == -999)
                        {
                            minS[j].X = b.scale[0];
                        }
                        if (minS[j].Y == -999)
                        {
                            minS[j].Y = b.scale[1];
                        }
                        if (minS[j].Z == -999)
                        {
                            minS[j].Z = b.scale[2];
                        }
                    }
                }
            }

            //TODO: Euler Rotation Values

            /*VBN tempvbn = new VBN();
             * a.SetFrame(0);
             * for (int i = 0; i < a.FrameCount; i++)
             * {
             *  //Frames.Add(new List<Bone>());
             *  for (int j = 0; j < a.Bones.Count; j++)
             *  {
             *      Animation.KeyNode keynode = a.Bones[j];
             *      Bone b = vbn.getBone(keynode.Text);
             *      //if(b == null) continue;
             *      maxR[j].X = Math.Max(maxR[j].X, b.rot.X);
             *      minR[j].X = Math.Min(minR[j].X, b.rot.X);
             *      maxR[j].Y = Math.Max(maxR[j].Y, b.rot.Y);
             *      minR[j].Y = Math.Min(minR[j].Y, b.rot.Y);
             *      maxR[j].Z = Math.Max(maxR[j].Z, b.rot.Z);
             *      minR[j].Z = Math.Min(minR[j].Z, b.rot.Z);
             *
             *      Bone f1 = new Bone(tempvbn);
             *      f1.pos = b.pos;
             *      f1.rot = b.rot;
             *      f1.sca = b.sca;
             *      //Frames[i].Add(f1);
             *  }
             *  a.NextFrame(vbn);
             * }*/

            // NODE INFO

            int t2Size = 0;

            for (int i = 0; i < a.bones.Count; i++)
            {
                int flag = 0;

                conRot[i]   = false;
                conScale[i] = false;
                conTrans[i] = false;

                // check for constant
                if (maxT[i].Equals(minT[i]))
                {
                    conTrans[i] = true;
                }
                if (maxR[i].Equals(minR[i]))
                {
                    conRot[i] = true;
                }
                if (maxS[i].Equals(minS[i]))
                {
                    conScale[i] = true;
                }

                if (hasTrans[i])
                {
                    flag |= 0x01000000;
                }
                if (hasRot[i])
                {
                    flag |= 0x02000000;
                }
                if (hasScale[i])
                {
                    flag |= 0x04000000;
                }

                if (conTrans[i] && hasTrans[i])
                {
                    flag |= 0x00200000;
                }
                else
                {
                    flag |= 0x00080000;
                }

                if (conRot[i] && hasRot[i])
                {
                    flag |= 0x00007000;
                }
                else
                {
                    flag |= 0x00005000;
                }

                if (conScale[i] && hasScale[i])
                {
                    flag |= 0x00000200;
                }
                else
                {
                    flag |= 0x00000080;
                }

                flag |= 0x00000001;

                //uint id = 999;

                Bone b    = vbn.getBone(a.bones[i].Text);
                int  hash = -1;
                if (MainForm.hashes.names.ContainsKey(a.bones[i].Text))
                {
                    hash = (int)MainForm.hashes.names[a.bones[i].Text];
                }
                else
                {
                    if (b != null)
                    {
                        hash = (int)b.boneId;
                    }
                    else
                    {
                        continue;
                    }
                }
                //if(hash == -1)
                //hash = (int)FileData.crc32(getNodeId(nodeid.get(i)).name);
                o.WriteInt(flag);      // flags...
                o.WriteInt(hash);      //hash
                o.WriteInt(t1.Size()); // Offset in 1 table
                o.WriteInt(t2Size);    // Offset in 2 table

                // calculate size needed
                if (hasTrans[i])
                {
                    t1.WriteFloat(minT[i].X);
                    t1.WriteFloat(minT[i].Y);
                    t1.WriteFloat(minT[i].Z);

                    if (!conTrans[i])
                    {
                        maxT[i].X -= minT[i].X;
                        maxT[i].Y -= minT[i].Y;
                        maxT[i].Z -= minT[i].Z;

                        t1.WriteFloat(maxT[i].X);
                        t1.WriteFloat(maxT[i].Y);
                        t1.WriteFloat(maxT[i].Z);

                        t2Size += 6;
                    }
                }

                if (hasRot[i])
                {
                    t1.WriteFloat(minR[i].X);
                    t1.WriteFloat(minR[i].Y);
                    t1.WriteFloat(minR[i].Z);

                    if (!conRot[i])
                    {
                        maxR[i].X -= minR[i].X;
                        maxR[i].Y -= minR[i].Y;
                        maxR[i].Z -= minR[i].Z;

                        t1.WriteFloat(maxR[i].X);
                        t1.WriteFloat(maxR[i].Y);
                        t1.WriteFloat(maxR[i].Z);

                        t2Size += 6;
                    }
                }

                if (hasScale[i])
                {
                    t1.WriteFloat(minS[i].X);
                    t1.WriteFloat(minS[i].Y);
                    t1.WriteFloat(minS[i].Z);

                    if (!conScale[i])
                    {
                        maxS[i].X -= minS[i].X;
                        maxS[i].Y -= minS[i].Y;
                        maxS[i].Z -= minS[i].Z;

                        t1.WriteFloat(maxS[i].X);
                        t1.WriteFloat(maxS[i].Y);
                        t1.WriteFloat(maxS[i].Z);

                        t2Size += 6;
                    }
                }
            }

            o.WriteIntAt(o.Size(), 0x18);

            o.WriteOutput(t1);

            o.WriteIntAt(o.Size(), 0x1C);

            // INTERPOLATION

            a.SetFrame(0);

            bool go = true;

            for (int i = 0; i < a.frameCount; i++)
            {
                //a.NextFrame(vbn);
                for (int j = 0; j < a.bones.Count; j++)
                {
                    Bone node = vbn.getBone(a.bones[j].Text);

                    Animation.KeyNode anode = a.bones[j];
                    //if (node == null) continue;

                    if (hasTrans[j] && !conTrans[j])
                    {
                        t2.WriteShort((int)(((anode.xpos.GetValue(i) - minT[j].X) / maxT[j].X) * 0xFFFF));
                        t2.WriteShort((int)(((anode.ypos.GetValue(i) - minT[j].Y) / maxT[j].Y) * 0xFFFF));
                        t2.WriteShort((int)(((anode.zpos.GetValue(i) - minT[j].Z) / maxT[j].Z) * 0xFFFF));
                    }

                    if (hasRot[j] && !conRot[j])
                    {
                        Quaternion r = new Quaternion();
                        if (anode.rotType == Animation.RotationType.Quaternion)
                        {
                            Animation.KeyFrame[] x  = anode.xrot.GetFrame(i);
                            Animation.KeyFrame[] y  = anode.yrot.GetFrame(i);
                            Animation.KeyFrame[] z  = anode.zrot.GetFrame(i);
                            Animation.KeyFrame[] w  = anode.wrot.GetFrame(i);
                            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 == i)
                            {
                                r = q1;
                            }
                            else
                            if (x[1].Frame == i)
                            {
                                r = q2;
                            }
                            else
                            {
                                r = Quaternion.Slerp(q1, q2, (i - x[0].Frame) / (x[1].Frame - x[0].Frame));
                            }
                        }
                        else
                        if (anode.rotType == Animation.RotationType.Euler)
                        {
                            float x = anode.xrot.HasAnimation() ? anode.xrot.GetValue(i) : node.rotation[0];
                            float y = anode.yrot.HasAnimation() ? anode.yrot.GetValue(i) : node.rotation[1];
                            float z = anode.zrot.HasAnimation() ? anode.zrot.GetValue(i) : node.rotation[2];
                            r = Animation.EulerToQuat(z, y, x);
                        }
                        r.Normalize();
                        t2.WriteShort((int)(((r.X - minR[j].X) / maxR[j].X) * 0xFFFF));
                        t2.WriteShort((int)(((r.Y - minR[j].Y) / maxR[j].Y) * 0xFFFF));
                        t2.WriteShort((int)(((r.Z - minR[j].Z) / maxR[j].Z) * 0xFFFF));
                    }

                    if (hasScale[j] && !conScale[j])
                    {
                        t2.WriteShort((int)(((anode.xsca.GetValue(i) - minS[j].X) / maxS[j].X) * 0xFFFF));
                        t2.WriteShort((int)(((anode.ysca.GetValue(i) - minS[j].Y) / maxS[j].Y) * 0xFFFF));
                        t2.WriteShort((int)(((anode.zsca.GetValue(i) - minS[j].Z) / maxS[j].Z) * 0xFFFF));
                    }
                }

                if (go)
                {
                    o.WriteShortAt(t2.Size(), 0x12);
                    go = false;
                }
            }

            o.WriteOutput(t2);
            return(o.GetBytes());
        }
    }
Ejemplo n.º 5
0
        public static void CreateANIM(string fname, Animation a, VBN vbn)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fname))
            {
                AnimHeader header = new AnimHeader();
                file.WriteLine("animVersion " + header.animVersion + ";");
                file.WriteLine("mayaVersion " + header.mayaVersion + ";");
                file.WriteLine("timeUnit " + header.timeUnit + ";");
                file.WriteLine("linearUnit " + header.linearUnit + ";");
                file.WriteLine("angularUnit " + header.angularUnit + ";");
                file.WriteLine("startTime " + 1 + ";");
                file.WriteLine("endTime " + a.frameCount + ";");

                a.SetFrame(a.frameCount - 1);             //from last frame
                for (int li = 0; li < a.frameCount; ++li) //go through each frame with nextFrame
                {
                    a.NextFrame(vbn);
                }
                a.NextFrame(vbn);  //go on first frame

                int i = 0;

                // writing node attributes
                foreach (Bone b in vbn.getBoneTreeOrder())
                {
                    i = vbn.boneIndex(b.Text);

                    if (a.HasBone(b.Text))
                    {
                        // write the bone attributes
                        // count the attributes
                        Animation.KeyNode n = a.GetBone(b.Text);
                        int ac = 0;

                        if (n.xpos.HasAnimation())
                        {
                            file.WriteLine("anim translate.translateX translateX " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.xpos, n, a.Size(), "translateX");
                            file.WriteLine("}");
                        }
                        if (n.ypos.HasAnimation())
                        {
                            file.WriteLine("anim translate.translateY translateY " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.ypos, n, a.Size(), "translateY");
                            file.WriteLine("}");
                        }
                        if (n.zpos.HasAnimation())
                        {
                            file.WriteLine("anim translate.translateZ translateZ " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.zpos, n, a.Size(), "translateZ");
                            file.WriteLine("}");
                        }
                        if (n.xrot.HasAnimation())
                        {
                            file.WriteLine("anim rotate.rotateX rotateX " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.xrot, n, a.Size(), "rotateX");
                            file.WriteLine("}");
                        }
                        if (n.yrot.HasAnimation())
                        {
                            file.WriteLine("anim rotate.rotateY rotateY " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.yrot, n, a.Size(), "rotateY");
                            file.WriteLine("}");
                        }
                        if (n.zrot.HasAnimation())
                        {
                            file.WriteLine("anim rotate.rotateZ rotateZ " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.zrot, n, a.Size(), "rotateZ");
                            file.WriteLine("}");
                        }
                        if (n.xsca.HasAnimation())
                        {
                            file.WriteLine("anim scale.scaleX scaleX " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.xsca, n, a.Size(), "scaleX");
                            file.WriteLine("}");
                        }
                        if (n.ysca.HasAnimation())
                        {
                            file.WriteLine("anim scale.scaleY scaleY " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.ysca, n, a.Size(), "scaleY");
                            file.WriteLine("}");
                        }
                        if (n.zsca.HasAnimation())
                        {
                            file.WriteLine("anim scale.scaleZ scaleZ " + b.Text + " 0 0 " + (ac++) + ";");
                            writeKey(file, n.zsca, n, a.Size(), "scaleZ");
                            file.WriteLine("}");
                        }

                        if (ac == 0)
                        {
                            file.WriteLine("anim " + b.Text + " 0 0 0;");
                        }
                    }
                    else
                    {
                        file.WriteLine("anim " + b.Text + " 0 0 0;");
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void process(FileData d, int type, int secOff, Animation.KeyNode node, String part, bool debug, Animation a)
        {
            int offset = d.ReadInt() + secOff;
            int temp   = d.Pos();

            d.Seek(offset);

            int   max    = 0;
            int   fCount = -1;
            float scale  = 0;

            float[] frame = null, step = null, tan = null;

            if (type == 0x1)
            {
                fCount = d.ReadUShort();
                d.Skip(2);
                scale = d.ReadFloat();
                float stepb = d.ReadFloat();
                float base2 = d.ReadFloat();

                frame = new float[fCount];
                step  = new float[fCount];
                tan   = new float[fCount];

                for (int i = 0; i < fCount; i++)
                {
                    frame[i] = d.ReadByte();
                    int th = d.ReadThree();
                    step[i] = base2 + ((th >> 12) & 0xfff) * stepb;
                    tan[i]  = (FileData.Sign12Bit(th & 0xfff) / 32f);

                    if (frame[i] > max)
                    {
                        max = (int)frame[i];
                    }
                }
            }

            if (type == 0x2)
            {
                fCount = d.ReadUShort();
                d.Skip(2);
                scale = d.ReadFloat();
                float stepb = d.ReadFloat();
                float base2 = d.ReadFloat();

                frame = new float[fCount];
                step  = new float[fCount];
                tan   = new float[fCount];

                for (int i = 0; i < fCount; i++)
                {
                    frame[i] = d.ReadUShort() / 32f;
                    step[i]  = base2 + d.ReadUShort() * stepb;
                    tan[i]   = (d.ReadShort() / 256f);

                    if (frame[i] > max)
                    {
                        max = (int)frame[i];
                    }
                }
            }

            if (type == 0x3)
            {
                //if(debug)
                //System.out.println(part + "\tInterpolated 12 " + Integer.toHexString(offset));

                fCount = d.ReadUShort();
                d.Skip(2);
                scale = d.ReadFloat();

                frame = new float[fCount];
                step  = new float[fCount];
                tan   = new float[fCount];

                for (int i = 0; i < fCount; i++)
                {
                    frame[i] = d.ReadFloat();
                    step[i]  = d.ReadFloat();
                    tan[i]   = d.ReadFloat();

                    if (frame[i] > max)
                    {
                        max = (int)frame[i];
                    }
                }
            }

            //a.FrameCount = max;

            float degrad = (float)(Math.PI / 180f);

            if (frame != null)
            {
                for (int i = 0; i < fCount; i++)
                {
                    Animation.KeyFrame f = new Animation.KeyFrame();
                    f.interType = Animation.InterpolationType.Hermite;
                    f.Value     = step[i];
                    f.Frame     = frame[i];
                    f.In        = tan[i];
                    switch (part)
                    {
                    case "RX":
                        f.Value = step[i] * degrad;
                        node.xrot.keys.Add(f);
                        f.degrees = true;
                        break;

                    case "RY":
                        f.Value = step[i] * degrad;
                        node.yrot.keys.Add(f);
                        f.degrees = true;
                        break;

                    case "RZ":
                        f.Value = step[i] * degrad;
                        node.zrot.keys.Add(f);
                        f.degrees = true;
                        break;

                    case "X":
                        node.xpos.keys.Add(f);
                        break;

                    case "Y":
                        node.ypos.keys.Add(f);
                        break;

                    case "Z":
                        node.zpos.keys.Add(f);
                        break;

                    case "SX":
                        node.xsca.keys.Add(f);
                        break;

                    case "SY":
                        node.ysca.keys.Add(f);
                        break;

                    case "SZ":
                        node.zsca.keys.Add(f);
                        break;
                    }
                }
            }

            if (type == 0x4)
            {
                float stepb = d.ReadFloat();
                float base2 = d.ReadFloat();
                for (int i = 0; i < a.frameCount; i++)
                {
                    float v = base2 + stepb * (d.ReadByte());

                    Animation.KeyFrame f = new Animation.KeyFrame();
                    f.interType = Animation.InterpolationType.Linear;
                    f.Value     = v;
                    f.Frame     = i;

                    switch (part)
                    {
                    case "RX":
                        f.Value = v * degrad;
                        node.xrot.keys.Add(f);
                        break;

                    case "RY":
                        f.Value = v * degrad;
                        node.yrot.keys.Add(f);
                        break;

                    case "RZ":
                        f.Value = v * degrad;
                        node.zrot.keys.Add(f);
                        break;

                    case "X":
                        node.xpos.keys.Add(f);
                        break;

                    case "Y":
                        node.ypos.keys.Add(f);
                        break;

                    case "Z":
                        node.zpos.keys.Add(f);
                        break;

                    case "SX":
                        node.xsca.keys.Add(f);
                        break;

                    case "SY":
                        node.ysca.keys.Add(f);
                        break;

                    case "SZ":
                        node.zsca.keys.Add(f);
                        break;
                    }
                }
            }

            if (type == 0x6)
            {
                for (int i = 0; i < a.frameCount; i++)
                {
                    float v = d.ReadFloat();

                    Animation.KeyFrame f = new Animation.KeyFrame();
                    f.interType = Animation.InterpolationType.Linear;
                    f.Value     = v;
                    f.Frame     = i;
                    switch (part)
                    {
                    case "RX":
                        f.Value = v * degrad;
                        node.xrot.keys.Add(f);
                        break;

                    case "RY":
                        f.Value = v * degrad;
                        node.yrot.keys.Add(f);
                        break;

                    case "RZ":
                        f.Value = v * degrad;
                        node.zrot.keys.Add(f);
                        break;

                    case "X":
                        node.xpos.keys.Add(f);
                        break;

                    case "Y":
                        node.ypos.keys.Add(f);
                        break;

                    case "Z":
                        node.zpos.keys.Add(f);
                        break;

                    case "SX":
                        node.xsca.keys.Add(f);
                        break;

                    case "SY":
                        node.ysca.keys.Add(f);
                        break;

                    case "SZ":
                        node.zsca.keys.Add(f);
                        break;
                    }
                }
            }

            d.Seek(temp);
        }
Ejemplo n.º 7
0
        public static Animation read(FileData d)
        {
            d.endian = Endianness.Big;

            d.Skip(4); // header OMO
            d.Skip(4); // two shorts, idk

            d.Skip(4); //flags?

            d.Skip(2);
            int boneCount  = d.ReadUShort();
            int frameCount = d.ReadUShort();
            int frameSize  = d.ReadUShort();

            int offset1 = d.ReadInt();  // nodeOffset
            int offset2 = d.ReadInt();  // interOffset
            int offset3 = d.ReadInt();  // keyOffset

            SkelAnimation anim = new SkelAnimation();

            anim.tag = d;

            if (boneCount > offset2 / 0x10)
            {
                boneCount = offset2 / 0x10;
                anim.tag  = null;
            }

            // base frames
            // These are linked to bones via hashes
            d.Seek(offset1); //
            int[]     framekey = new int[boneCount];
            KeyNode[] baseNode = new KeyNode[boneCount];

            // Start positions for bones/nodes
            for (int i = 0; i < boneCount; i++)
            {
                flagsused = flagsused | d.ReadInt(); d.Seek(d.Pos() - 4);
                //Console.WriteLine(flagsused.ToString("x"));

                int flags = d.ReadByte();
                int tFlag = d.ReadByte();
                int rFlag = d.ReadByte();
                int sFlag = d.ReadByte();
                int hash  = d.ReadInt(); // used to find the identifying bone
                int off1  = d.ReadInt() + offset2;
                framekey[i] = d.ReadInt();

                bool hasTrans = (flags & 0x01) == 0x01;
                bool hasScale = (flags & 0x04) == 0x04;
                bool hasRot   = (flags & 0x02) == 0x02;

                KeyNode node = new KeyNode();
                baseNode[i] = node;

                node.hash = (uint)hash;

                int temp = d.Pos();
                d.Seek(off1);

                if (hasTrans)
                {
                    if (tFlag == 0x8)
                    { // interpolated
                        node.tType = KeyNode.Interpolated;
                        node.t     = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                        node.t2    = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                    }
                    else if (tFlag == 0x20)
                    {
                        node.tType = KeyNode.Constant;
                        node.t     = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                    }
                    else if (tFlag == 0x4)
                    {
                        // entire Vector3 provided in keyframe data i.e. KEYFRAME type
                        node.tType = KeyNode.Keyframe;
                    }
                }
                if (hasRot)
                {
                    if ((rFlag & 0xF0) != 0x50 && (rFlag & 0xF0) != 0x70 && (rFlag & 0xF0) != 0x60 && (rFlag & 0xF0) != 0xA0)
                    {
                        //Console.WriteLine(rFlag);
                    }

                    if ((rFlag & 0xF0) == 0xA0)
                    {
                        // All data is in the keyframe for this type
                        node.rType = KeyNode.Compressed;
                    }

                    if ((rFlag & 0xF0) == 0x50)
                    { // interpolated
                        node.rType = KeyNode.Interpolated;
                        node.rv    = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                        node.rv2   = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                    }

                    if ((rFlag & 0xF0) == 0x60)
                    {
                        node.rType  = KeyNode.Keyframe;
                        node.rv     = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                        node.rExtra = d.ReadFloat() / 65535;
                    }

                    if ((rFlag & 0xF0) == 0x70)
                    {
                        node.rType = KeyNode.Constant;
                        node.rv    = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                    }
                }

                if (hasScale)
                {
                    if ((sFlag & 0xF0) == 0x80)
                    { // interpolated
                        node.sType = KeyNode.Interpolated;
                        node.s     = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                        node.s2    = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                    }
                    // TODO: investigate the difference between these
                    if ((rFlag & 0x0F) == 0x02 || (rFlag & 0x0F) == 0x03)
                    { // constant
                        node.sType = KeyNode.Constant;
                        node.s     = new Vector3(d.ReadFloat(), d.ReadFloat(), d.ReadFloat());
                    }
                }
                d.Seek(temp);
            }

            // Interpolated type below here is always a set translation/rotation/scale
            // from the coords specified with the bone node above

            Animation a = new Animation("Anim");

            a.Tag        = anim.tag;
            a.frameCount = frameCount;

            d.Seek(offset3);

            for (int j = 0; j < boneCount; j++)
            {
                string bid  = "";
                int    hash = -1;
                if (!MainForm.hashes.ids.TryGetValue(baseNode[j].hash, out bid))
                {
                    hash = (int)baseNode[j].hash;
                }
                Animation.KeyNode n = new Animation.KeyNode(bid);
                n.hash = hash;
                a.bones.Add(n);
                n.type = Animation.BoneType.Normal;

                /*foreach (ModelContainer con in Runtime.ModelContainers)
                 *  if (con.VBN != null)
                 *      bid = con.VBN.getBone(baseNode[j].hash) == null ? "" : con.VBN.getBone(baseNode[j].hash).Text;*/

                for (int i = 0; i < a.frameCount; i++)
                {
                    d.Seek(offset3 + frameSize * i + framekey[j]);

                    if (baseNode[j].tType == KeyNode.Interpolated)
                    {
                        float i1 = ((float)d.ReadUShort() / 0xffff);
                        float i2 = ((float)d.ReadUShort() / 0xffff);
                        float i3 = ((float)d.ReadUShort() / 0xffff);

                        float x = baseNode[j].t.X + (baseNode[j].t2.X * (i1));
                        float y = baseNode[j].t.Y + (baseNode[j].t2.Y * (i2));
                        float z = baseNode[j].t.Z + (baseNode[j].t2.Z * (i3));

                        //node.t = new Vector3(x, y, z);  // Translation
                        n.xpos.keys.Add(new Animation.KeyFrame(x, i));
                        n.ypos.keys.Add(new Animation.KeyFrame(y, i));
                        n.zpos.keys.Add(new Animation.KeyFrame(z, i));
                    }
                    else if (baseNode[j].tType == KeyNode.Constant)
                    {
                        //node.t = baseNode[j].t;
                        n.xpos.keys.Add(new Animation.KeyFrame(baseNode[j].t.X, i));
                        n.ypos.keys.Add(new Animation.KeyFrame(baseNode[j].t.Y, i));
                        n.zpos.keys.Add(new Animation.KeyFrame(baseNode[j].t.Z, i));
                    }
                    else if (baseNode[j].tType == 2)
                    {
                        float x = d.ReadFloat();
                        float y = d.ReadFloat();
                        float z = d.ReadFloat();

                        //node.t = new Vector3(x, y, z);
                        n.xpos.keys.Add(new Animation.KeyFrame(x, i));
                        n.ypos.keys.Add(new Animation.KeyFrame(y, i));
                        n.zpos.keys.Add(new Animation.KeyFrame(z, i));
                    }

                    if (baseNode[j].rType == KeyNode.Compressed)
                    {
                        // There are 64 bits present for each node of this rot type
                        // The format is: 20bits * 3 of encoded floats, and 4 bits of flags
                        // The flags describe which 3 components of the quaternion are being presented
                        int b1 = d.ReadByte();
                        int b2 = d.ReadByte();
                        int b3 = d.ReadByte();
                        int b4 = d.ReadByte();
                        int b5 = d.ReadByte();
                        int b6 = d.ReadByte();
                        int b7 = d.ReadByte();
                        int b8 = d.ReadByte();

                        // Capture 20 bits at a time of the raw data
                        int f1    = (b1 << 12) | (b2 << 4) | ((b3 & 0xF0) >> 4);
                        int f2    = ((b3 & 0xF) << 16) | (b4 << 8) | b5;
                        int f3    = (b6 << 12) | (b7 << 4) | ((b8 & 0xF0) >> 4);
                        int flags = b8 & 0xF;

                        Quaternion r = new Quaternion();
                        switch (flags)
                        {
                        case 0:      // y, z, w provided
                            r.Y = encodedRot10ToQuaternionComponent(f1);
                            r.Z = encodedRot10ToQuaternionComponent(f2);
                            r.W = encodedRot10ToQuaternionComponent(f3);

                            r.X = (float)Math.Sqrt(Math.Abs(1 - (r.Y * r.Y + r.Z * r.Z + r.W * r.W)));
                            break;

                        case 1:      // x, z, w provided
                            r.X = encodedRot10ToQuaternionComponent(f1);
                            r.Z = encodedRot10ToQuaternionComponent(f2);
                            r.W = encodedRot10ToQuaternionComponent(f3);

                            r.Y = (float)Math.Sqrt(Math.Abs(1 - (r.X * r.X + r.Z * r.Z + r.W * r.W)));
                            break;

                        case 2:      // x, y, w provided
                            r.X = encodedRot10ToQuaternionComponent(f1);
                            r.Y = encodedRot10ToQuaternionComponent(f2);
                            r.W = encodedRot10ToQuaternionComponent(f3);

                            r.Z = (float)Math.Sqrt(Math.Abs(1 - (r.X * r.X + r.Y * r.Y + r.W * r.W)));
                            break;

                        case 3:      // x, y, z, provided
                            r.X = encodedRot10ToQuaternionComponent(f1);
                            r.Y = encodedRot10ToQuaternionComponent(f2);
                            r.Z = encodedRot10ToQuaternionComponent(f3);

                            r.W = (float)Math.Sqrt(Math.Abs(1 - (r.X * r.X + r.Y * r.Y + r.Z * r.Z)));
                            break;

                        default:
                            Console.WriteLine("Unknown rotation type3 flags: " + flags);
                            break;
                        }
                        n.rotType = Animation.RotationType.Quaternion;
                        n.xrot.keys.Add(new Animation.KeyFrame(r.X, i));
                        n.yrot.keys.Add(new Animation.KeyFrame(r.Y, i));
                        n.zrot.keys.Add(new Animation.KeyFrame(r.Z, i));
                        n.wrot.keys.Add(new Animation.KeyFrame(r.W, i));
                    }
                    else if (baseNode[j].rType == KeyNode.Interpolated)
                    {
                        float i1 = ((float)d.ReadUShort() / (0xffff));
                        float i2 = ((float)d.ReadUShort() / (0xffff));
                        float i3 = ((float)d.ReadUShort() / (0xffff));

                        float x = baseNode[j].rv.X + (baseNode[j].rv2.X * (i1));
                        float y = baseNode[j].rv.Y + (baseNode[j].rv2.Y * (i2));
                        float z = baseNode[j].rv.Z + (baseNode[j].rv2.Z * (i3));

                        float w = (float)Math.Sqrt(Math.Abs(1 - (x * x + y * y + z * z)));

                        Quaternion r = new Quaternion(new Vector3(x, y, z), w);
                        r.Normalize();

                        n.rotType = Animation.RotationType.Quaternion;
                        n.xrot.keys.Add(new Animation.KeyFrame(r.X, i));
                        n.yrot.keys.Add(new Animation.KeyFrame(r.Y, i));
                        n.zrot.keys.Add(new Animation.KeyFrame(r.Z, i));
                        n.wrot.keys.Add(new Animation.KeyFrame(r.W, i));
                    }
                    else if (baseNode[j].rType == KeyNode.Keyframe)
                    {
                        float scale = d.ReadUShort() * baseNode[j].rExtra;
                        float x     = baseNode[j].rv.X;
                        float y     = baseNode[j].rv.Y;
                        float z     = baseNode[j].rv.Z + scale;
                        float w     = rot6CalculateW(x, y, z);

                        Quaternion r = new Quaternion(x, y, z, w);
                        n.rotType = Animation.RotationType.Quaternion;
                        n.xrot.keys.Add(new Animation.KeyFrame(r.X, i));
                        n.yrot.keys.Add(new Animation.KeyFrame(r.Y, i));
                        n.zrot.keys.Add(new Animation.KeyFrame(r.Z, i));
                        n.wrot.keys.Add(new Animation.KeyFrame(r.W, i));
                    }
                    else
                    {
                        float x = baseNode[j].rv.X;
                        float y = baseNode[j].rv.Y;
                        float z = baseNode[j].rv.Z;
                        float w = (float)Math.Sqrt(Math.Abs(1 - (x * x + y * y + z * z)));

                        Quaternion r = new Quaternion(baseNode[j].rv, w);
                        r.Normalize();
                        n.rotType = Animation.RotationType.Quaternion;
                        n.xrot.keys.Add(new Animation.KeyFrame(r.X, i));
                        n.yrot.keys.Add(new Animation.KeyFrame(r.Y, i));
                        n.zrot.keys.Add(new Animation.KeyFrame(r.Z, i));
                        n.wrot.keys.Add(new Animation.KeyFrame(r.W, i));
                    }

                    if (baseNode[j].sType == KeyNode.Interpolated)
                    {
                        float i1 = ((float)d.ReadUShort() / (0xffff));
                        float i2 = ((float)d.ReadUShort() / (0xffff));
                        float i3 = ((float)d.ReadUShort() / (0xffff));

                        float x = baseNode[j].s.X + (baseNode[j].s2.X * (i1));
                        float y = baseNode[j].s.Y + (baseNode[j].s2.Y * (i2));
                        float z = baseNode[j].s.Z + (baseNode[j].s2.Z * (i3));

                        //node.s = new Vector3(x, y, z);
                        n.xsca.keys.Add(new Animation.KeyFrame(x, i));
                        n.ysca.keys.Add(new Animation.KeyFrame(y, i));
                        n.zsca.keys.Add(new Animation.KeyFrame(z, i));
                    }
                    else
                    {
                        //node.s = baseNode[j].s;
                        n.xsca.keys.Add(new Animation.KeyFrame(baseNode[j].s.X, i));
                        n.ysca.keys.Add(new Animation.KeyFrame(baseNode[j].s.Y, i));
                        n.zsca.keys.Add(new Animation.KeyFrame(baseNode[j].s.Z, i));
                    }
                }
            }

            return(a);
        }
Ejemplo n.º 8
0
        public static Animation readAnim(FileData d, VBN m)
        {
            int offset  = d.ReadInt();
            int nameoff = d.ReadInt();

            d.Skip(4);
            int fCount        = d.ReadUShort();
            int animDataCount = d.ReadUShort();

            d.Skip(8);

            Animation anim = new Animation(d.ReadString(nameoff, -1));

            anim.frameCount = fCount;

            //anim.setModel(m);

            d.Seek(offset);
            int sectionOffset = d.ReadInt() + offset;
            int size          = d.ReadInt();    // size again

            for (int i = 0; i < size; i++)
            {
                //			System.out.print(d.readShort()); // id
                d.Skip(4);                 // id and unknown
                d.ReadUShort();            //left
                d.ReadUShort();            //right
                int nameOffset = d.ReadInt() + offset;
                int dataOffset = d.ReadInt() + offset;
                if (dataOffset == offset)
                {
                    i--;
                    continue;
                    //				d.skip(8);
                    //				nameOffset = d.readInt() + 4;
                    //				dataOffset = d.readInt() + offset;
                }


                int temp = d.Pos();

                d.Seek(dataOffset);

                int pos     = d.Pos();
                int nameOff = d.ReadInt() + sectionOffset + (d.Pos() - sectionOffset) - 4;
                int flags   = d.ReadInt();

                int t_type = (flags >> 0x1e) & 0x3;
                int r_type = (flags >> 0x1b) & 0x7;
                int s_type = (flags >> 0x19) & 0x3;

                int hasT = (flags >> 0x18) & 0x1;
                int hasR = (flags >> 0x17) & 0x1;
                int hasS = (flags >> 0x16) & 0x1;

                int Zfixed = (flags >> 0x15) & 0x1;
                int Yfixed = (flags >> 0x14) & 0x1;
                int Xfixed = (flags >> 0x13) & 0x1;

                int RZfixed = (flags >> 0x12) & 0x1;
                int RYfixed = (flags >> 0x11) & 0x1;
                int RXfixed = (flags >> 0x10) & 0x1;

                int SZfixed = (flags >> 0xf) & 0x1;
                int SYfixed = (flags >> 0xe) & 0x1;
                int SXfixed = (flags >> 0xd) & 0x1;

                int Tiso = (flags >> 0x6) & 0x1;
                int Riso = (flags >> 0x5) & 0x1;
                int Siso = (flags >> 0x4) & 0x1;

                Animation.KeyNode node = new Animation.KeyNode(d.ReadString(nameOff, -1));
                anim.bones.Add(node);
                node.rotType = Animation.RotationType.Euler;

                if (hasS == 1)
                {
                    if (Siso == 1)
                    {
                        float iss = d.ReadFloat();
                        node.xsca.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                        node.ysca.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                        node.zsca.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                    }
                    else
                    {
                        if (SXfixed == 1)
                        {
                            node.xsca.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = d.ReadFloat()
                            });
                        }
                        else
                        {
                            process(d, s_type, pos, node, "SX", false, anim);
                        }
                        if (SYfixed == 1)
                        {
                            node.ysca.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = d.ReadFloat()
                            });
                        }
                        else
                        {
                            process(d, s_type, pos, node, "SY", false, anim);
                        }
                        if (SZfixed == 1)
                        {
                            node.zsca.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = d.ReadFloat()
                            });
                        }
                        else
                        {
                            process(d, s_type, pos, node, "SZ", false, anim);
                        }
                    }
                }

                if (hasR == 1)
                {
                    if (Riso == 1)
                    {
                        float iss = (float)((d.ReadFloat()) * Math.PI / 180f);
                        node.xrot.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                        node.yrot.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                        node.zrot.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                    }
                    else
                    {
                        if (RXfixed == 1)
                        {
                            node.xrot.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = (float)(Math.PI / 180f) * (d.ReadFloat())
                            });
                        }
                        else
                        {
                            process(d, r_type, pos, node, "RX", false, anim);
                        }
                        if (RYfixed == 1)
                        {
                            node.yrot.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = (float)(Math.PI / 180f) * (d.ReadFloat())
                            });
                        }
                        else
                        {
                            process(d, r_type, pos, node, "RY", false, anim);
                        }
                        if (RZfixed == 1)
                        {
                            node.zrot.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = (float)(Math.PI / 180f) * (d.ReadFloat())
                            });
                        }
                        else
                        {
                            process(d, r_type, pos, node, "RZ", false, anim);
                        }
                    }
                }

                if (hasT == 1)
                {
                    if (Tiso == 1)
                    {
                        float iss = d.ReadFloat();
                        node.xpos.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                        node.ypos.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                        node.zpos.keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = iss
                        });
                    }
                    else
                    {
                        if (Xfixed == 1)
                        {
                            node.xpos.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = d.ReadFloat()
                            });
                        }
                        else
                        {
                            process(d, t_type, pos, node, "X", false, anim);
                        }
                        if (Yfixed == 1)
                        {
                            node.ypos.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = d.ReadFloat()
                            });
                        }
                        else
                        {
                            process(d, t_type, pos, node, "Y", false, anim);
                        }
                        if (Zfixed == 1)
                        {
                            node.zpos.keys.Add(new Animation.KeyFrame()
                            {
                                Frame = 0, Value = d.ReadFloat()
                            });
                        }
                        else
                        {
                            process(d, t_type, pos, node, "Z", false, anim);
                        }
                    }
                }

                d.Seek(temp);
            }

            return(anim);
        }
Ejemplo n.º 9
0
        public static AnimationGroupNode Read(string filename)
        {
            bchHeader header = new bchHeader();
            FileData  f      = new FileData(filename);

            f.endian = System.IO.Endianness.Little;

            f.Skip(4);
            header.backwardCompatibility = f.ReadByte();
            header.forwardCompatibility  = f.ReadByte();
            header.version = f.ReadUShort();

            header.mainHeaderOffset  = f.ReadInt();
            header.stringTableOffset = f.ReadInt();
            header.gpuCommandsOffset = f.ReadInt();
            header.dataOffset        = f.ReadInt();
            if (header.backwardCompatibility > 0x20)
            {
                header.dataExtendedOffset = f.ReadInt();
            }
            header.relocationTableOffset = f.ReadInt();

            header.mainHeaderLength  = f.ReadInt();
            header.stringTableLength = f.ReadInt();
            header.gpuCommandsLength = f.ReadInt();
            header.dataLength        = f.ReadInt();
            if (header.backwardCompatibility > 0x20)
            {
                header.dataExtendedLength = f.ReadInt();
            }
            header.relocationTableLength = f.ReadInt();

            header.uninitializedDataSectionLength        = f.ReadInt();
            header.uninitializedDescriptionSectionLength = f.ReadInt();

            if (header.backwardCompatibility > 7)
            {
                header.flags        = f.ReadUShort();
                header.addressCount = f.ReadUShort();
            }

            // Relocation table
            for (int i = 0; i < header.relocationTableLength; i += 4)
            {
                f.Seek(header.relocationTableOffset + i);
                int  val  = f.ReadInt();
                int  off  = val & 0x1FFFFFF;
                byte flag = (byte)(val >> 25);

                switch (flag)
                {
                case 0:
                    f.Seek((off * 4) + header.mainHeaderOffset);
                    f.WriteInt((off * 4) + header.mainHeaderOffset, f.ReadInt() + header.mainHeaderOffset);
                    break;

                case 1:
                    f.Seek(off + header.mainHeaderOffset);
                    f.WriteInt((off) + header.mainHeaderOffset, f.ReadInt() + header.stringTableOffset);
                    break;

                case 2:
                    f.Seek((off * 4) + header.mainHeaderOffset);
                    f.WriteInt((off * 4) + header.mainHeaderOffset, f.ReadInt() + header.gpuCommandsOffset);
                    break;

                case 0xc:
                    f.Seek((off * 4) + header.mainHeaderOffset);
                    f.WriteInt((off * 4) + header.mainHeaderOffset, f.ReadInt() + header.dataOffset);
                    break;
                }
            }


            // Content Header
            f.Seek(header.mainHeaderOffset);
            bchContentHeader content = new bchContentHeader();
            {
                content.modelsPointerTableOffset        = f.ReadInt();
                content.modelsPointerTableEntries       = f.ReadInt();
                content.modelsNameOffset                = f.ReadInt();
                content.materialsPointerTableOffset     = f.ReadInt();
                content.materialsPointerTableEntries    = f.ReadInt();
                content.materialsNameOffset             = f.ReadInt();
                content.shadersPointerTableOffset       = f.ReadInt();
                content.shadersPointerTableEntries      = f.ReadInt();
                content.shadersNameOffset               = f.ReadInt();
                content.texturesPointerTableOffset      = f.ReadInt();
                content.texturesPointerTableEntries     = f.ReadInt();
                content.texturesNameOffset              = f.ReadInt();
                content.materialsLUTPointerTableOffset  = f.ReadInt();
                content.materialsLUTPointerTableEntries = f.ReadInt();
                content.materialsLUTNameOffset          = f.ReadInt();
                content.lightsPointerTableOffset        = f.ReadInt();
                content.lightsPointerTableEntries       = f.ReadInt();
                content.lightsNameOffset                = f.ReadInt();
                content.camerasPointerTableOffset       = f.ReadInt();
                content.camerasPointerTableEntries      = f.ReadInt();
                content.camerasNameOffset               = f.ReadInt();
                content.fogsPointerTableOffset          = f.ReadInt();
                content.fogsPointerTableEntries         = f.ReadInt();
                content.fogsNameOffset = f.ReadInt();
                content.skeletalAnimationsPointerTableOffset    = f.ReadInt();
                content.skeletalAnimationsPointerTableEntries   = f.ReadInt();
                content.skeletalAnimationsNameOffset            = f.ReadInt();
                content.materialAnimationsPointerTableOffset    = f.ReadInt();
                content.materialAnimationsPointerTableEntries   = f.ReadInt();
                content.materialAnimationsNameOffset            = f.ReadInt();
                content.visibilityAnimationsPointerTableOffset  = f.ReadInt();
                content.visibilityAnimationsPointerTableEntries = f.ReadInt();
                content.visibilityAnimationsNameOffset          = f.ReadInt();
                content.lightAnimationsPointerTableOffset       = f.ReadInt();
                content.lightAnimationsPointerTableEntries      = f.ReadInt();
                content.lightAnimationsNameOffset           = f.ReadInt();
                content.cameraAnimationsPointerTableOffset  = f.ReadInt();
                content.cameraAnimationsPointerTableEntries = f.ReadInt();
                content.cameraAnimationsNameOffset          = f.ReadInt();
                content.fogAnimationsPointerTableOffset     = f.ReadInt();
                content.fogAnimationsPointerTableEntries    = f.ReadInt();
                content.fogAnimationsNameOffset             = f.ReadInt();
                content.scenePointerTableOffset             = f.ReadInt();
                content.scenePointerTableEntries            = f.ReadInt();
                content.sceneNameOffset = f.ReadInt();
            }


            //Skeletal animation
            AnimationGroupNode ThisAnimation = new AnimationGroupNode()
            {
                Text = filename
            };

            for (int index1 = 0; index1 < content.skeletalAnimationsPointerTableEntries; index1++)//
            {
                f.Seek(content.skeletalAnimationsPointerTableOffset + (index1 * 4));
                int dataOffset = f.ReadInt();
                f.Seek(dataOffset);


                string skeletalAnimationName = f.ReadString(f.ReadInt(), -1);
                int    animationFlags        = f.ReadInt();
                //int skeletalAnimationloopMode = f.readByte();  //pas ça du tout
                float skeletalAnimationframeSize = f.ReadFloat();
                int   boneTableOffset            = f.ReadInt();
                int   boneTableEntries           = f.ReadInt();
                int   metaDataPointerOffset      = f.ReadInt();

                //Runtime.Animations.Add(skeletalAnimationName, a);
                //MainForm.animNode.Nodes.Add(skeletalAnimationName);

                Animation a = new Animation(skeletalAnimationName);
                ThisAnimation.Nodes.Add(a);

                for (int i = 0; i < boneTableEntries; i++)
                {
                    f.Seek(boneTableOffset + (i * 4));
                    int offset = f.ReadInt();

                    Animation.KeyNode bone = new Animation.KeyNode("");
                    a.bones.Add(bone);
                    f.Seek(offset);
                    bone.Text = f.ReadString(f.ReadInt(), -1);
                    //Console.WriteLine("Bone Name: " + bone.name);
                    int  animationTypeFlags = f.ReadInt();
                    uint flags = (uint)f.ReadInt();

                    OSegmentType segmentType = (OSegmentType)((animationTypeFlags >> 16) & 0xf);
                    //Debug.WriteLine(bone.Text + " " + flags.ToString("x"));
                    switch (segmentType)
                    {
                    case OSegmentType.transform:
                        f.Seek(offset + 0xC);
                        //Console.WriteLine(f.pos().ToString("x") + " " + flags.ToString("x"));

                        uint notExistMask = 0x10000;
                        uint constantMask = 0x40;

                        for (int j = 0; j < 3; j++)
                        {
                            for (int axis = 0; axis < 3; axis++)
                            {
                                bool notExist = (flags & notExistMask) > 0;
                                bool constant = (flags & constantMask) > 0;
                                //Console.WriteLine(notExist + " " + constant);

                                Animation.KeyGroup group = new Animation.KeyGroup();
                                //frame.exists = !notExist;
                                if (!notExist)
                                {
                                    if (constant)
                                    {
                                        Animation.KeyFrame frame = new Animation.KeyFrame();
                                        frame.interType = Animation.InterpolationType.Linear;
                                        frame.Value     = f.ReadFloat();
                                        frame.Frame     = 0;
                                        group.keys.Add(frame);
                                    }
                                    else
                                    {
                                        int frameOffset = f.ReadInt();
                                        int position    = f.Pos();
                                        f.Seek(frameOffset);
                                        float c = 0;
                                        //Debug.WriteLine(j + " " + axis + " " + bone.Text);
                                        getAnimationKeyFrame(f, group, out c);
                                        if (c > a.frameCount)
                                        {
                                            a.frameCount = (int)c;
                                        }
                                        f.Seek(position);
                                    }
                                }
                                else
                                {
                                    f.Seek(f.Pos() + 0x04);
                                }
                                bone.rotType = Animation.RotationType.Euler;

                                if (j == 0)
                                {
                                    switch (axis)
                                    {
                                    case 0: bone.xsca = group; break;

                                    case 1: bone.ysca = group; break;

                                    case 2: bone.zsca = group; break;
                                    }
                                }
                                else
                                if (j == 1)
                                {
                                    switch (axis)
                                    {
                                    case 0: bone.xrot = group; break;

                                    case 1: bone.yrot = group; break;

                                    case 2: bone.zrot = group; break;
                                    }
                                }
                                else
                                if (j == 2)
                                {
                                    switch (axis)
                                    {
                                    case 0: bone.xpos = group; break;

                                    case 1: bone.ypos = group; break;

                                    case 2: bone.zpos = group; break;
                                    }
                                }

                                notExistMask <<= 1;
                                constantMask <<= 1;
                            }
                            if (j == 1)
                            {
                                constantMask <<= 1;
                            }
                        }

                        break;

                    /*case OSegmentType.transformQuaternion:
                     *  bone.isFrameFormat = true;
                     *
                     *  int scaleOffset = f.readInt();
                     *  int rotationOffset = f.readInt();
                     *  int translationOffset = f.readInt();
                     *
                     *  if ((flags & 0x20) == 0)
                     *  {
                     *      bone.scale.exists = true;
                     *      f.seek(scaleOffset);
                     *
                     *      if ((flags & 4) > 0)
                     *      {
                     *          bone.scale.vector.Add(new Vector4(
                     *              f.readFloat(),
                     *              f.readFloat(),
                     *              f.readFloat(),
                     *              0));
                     *      }
                     *      else
                     *      {
                     *          bone.scale.startFrame = f.readFloat();
                     *          bone.scale.endFrame = f.readFloat();
                     *
                     *          int scaleFlags = f.readInt();
                     *          int scaleDataOffset = f.readInt();
                     *          int scaleEntries = f.readInt();
                     *
                     *          f.seek(scaleDataOffset);
                     *          for (int j = 0; j < scaleEntries; j++)
                     *          {
                     *              bone.scale.vector.Add(new Vector4(
                     *                  f.readFloat(),
                     *                  f.readFloat(),
                     *                  f.readFloat(),
                     *                  0));
                     *          }
                     *      }
                     *  }
                     *
                     *  if ((flags & 0x10) == 0)
                     *  {
                     *      bone.rotationQuaternion.exists = true;
                     *      f.seek(rotationOffset);
                     *
                     *      if ((flags & 2) > 0)
                     *      {
                     *          bone.rotationQuaternion.vector.Add(new Vector4(
                     *              f.readFloat(),
                     *              f.readFloat(),
                     *              f.readFloat(),
                     *              f.readFloat()));
                     *      }
                     *      else
                     *      {
                     *          bone.rotationQuaternion.startFrame = f.readFloat();
                     *          bone.rotationQuaternion.endFrame = f.readFloat();
                     *
                     *          int rotationFlags = f.readInt();
                     *          int rotationDataOffset = f.readInt();
                     *          int rotationEntries = f.readInt();
                     *
                     *          f.seek(rotationDataOffset);
                     *          for (int j = 0; j < rotationEntries; j++)
                     *          {
                     *              bone.rotationQuaternion.vector.Add(new Vector4(
                     *                  f.readFloat(),
                     *                  f.readFloat(),
                     *                  f.readFloat(),
                     *                  f.readFloat()));
                     *          }
                     *      }
                     *  }
                     *
                     *  if ((flags & 8) == 0)
                     *  {
                     *      bone.translation.exists = true;
                     *      f.seek(translationOffset);
                     *
                     *      if ((flags & 1) > 0)
                     *      {
                     *          bone.translation.vector.Add(new Vector4(
                     *              f.readFloat(),
                     *              f.readFloat(),
                     *              f.readFloat(),
                     *              0));
                     *      }
                     *      else
                     *      {
                     *          bone.translation.startFrame = f.readFloat();
                     *          bone.translation.endFrame = f.readFloat();
                     *
                     *          int translationFlags = f.readInt();
                     *          int translationDataOffset = f.readInt();
                     *          int translationEntries = f.readInt();
                     *
                     *          f.seek(translationDataOffset);
                     *          for (int j = 0; j < translationEntries; j++)
                     *          {
                     *              bone.translation.vector.Add(new Vector4(
                     *                  f.readFloat(),
                     *                  f.readFloat(),
                     *                  f.readFloat(),
                     *                  0));
                     *          }
                     *      }
                     *  }
                     *
                     *  break;
                     * case OSegmentType.transformMatrix:
                     *  bone.isFullBakedFormat = true;
                     *
                     *  f.readInt();
                     *  f.readInt();
                     *  int matrixOffset = f.readInt();
                     *  int entries = f.readInt();
                     *
                     *  f.seek(matrixOffset);
                     *  for (int j = 0; j < entries; j++)
                     *  {
                     *      OMatrix transform = new OMatrix();
                     *      transform.M11 = f.readFloat();
                     *      transform.M21 = f.readFloat();
                     *      transform.M31 = f.readFloat();
                     *      transform.M41 = f.readFloat();
                     *
                     *      transform.M12 = f.readFloat();
                     *      transform.M22 = f.readFloat();
                     *      transform.M32 = f.readFloat();
                     *      transform.M42 = f.readFloat();
                     *
                     *      transform.M13 = f.readFloat();
                     *      transform.M23 = f.readFloat();
                     *      transform.M33 = f.readFloat();
                     *      transform.M43 = f.readFloat();
                     *
                     *      bone.transform.Add(transform);
                     *  }
                     *
                     *  break;*/
                    default: throw new Exception(string.Format("BCH: Unknow Segment Type {0} on Skeletal Animation bone {1}! STOP!", segmentType, bone.Text));
                    }

                    //skeletalAnimation.bone.Add(bone);
                }
            }
            //return a;
            return(ThisAnimation);
        }
Ejemplo n.º 10
0
        public static void Read(string fname, Animation a, VBN v)
        {
            StreamReader reader = File.OpenText(fname);
            string       line;

            string   current = "";
            bool     readBones = false;
            int      frame = 0, prevframe = 0;
            KeyFrame k = new KeyFrame();

            VBN vbn = v;

            if (v != null && v.bones.Count == 0)
            {
                readBones = true;
            }
            else
            {
                vbn = new VBN();
            }

            while ((line = reader.ReadLine()) != null)
            {
                line = Regex.Replace(line, @"\s+", " ");
                string[] args = line.Replace(";", "").TrimStart().Split(' ');

                if (args[0].Equals("nodes") || args[0].Equals("skeleton") || args[0].Equals("end") || args[0].Equals("time"))
                {
                    current = args[0];
                    if (args.Length > 1)
                    {
                        prevframe = frame;
                        frame     = int.Parse(args[1]);

                        /*if (frame != prevframe + 1) {
                         *                              Console.WriteLine ("Needs interpolation " + frame);
                         *                      }*/

                        k       = new KeyFrame();
                        k.frame = frame;
                        //a.addKeyframe(k);
                    }
                    continue;
                }

                if (current.Equals("nodes"))
                {
                    Bone b = new Bone(vbn);
                    b.Text        = args[1].Replace("\"", "");
                    b.parentIndex = int.Parse(args[2]);
                    //b.children = new System.Collections.Generic.List<int> ();
                    vbn.totalBoneCount++;
                    vbn.bones.Add(b);
                    Animation.KeyNode node = new Animation.KeyNode(b.Text);
                    a.bones.Add(node);
                }

                if (current.Equals("time"))
                {
                    //Animation.KeyFrame n = new Animation.KeyFrame();

                    /*n.id = v.boneIndex(vbn.bones[int.Parse(args[0])].Text);
                     * if (n.id == -1)
                     * {
                     *  continue;
                     * }
                     * else
                     *  n.hash = v.bones[n.id].boneId;*/

                    // only if it finds the node
                    //k.addNode(n);

                    // reading the skeleton if this isn't an animation
                    if (readBones && frame == 0)
                    {
                        Bone b = vbn.bones[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]));

                        if (b.parentIndex != -1)
                        {
                            vbn.bones [b.parentIndex].Nodes.Add(b);
                        }
                    }
                    Animation.KeyNode bone = a.GetBone(vbn.bones[int.Parse(args[0])].Text);
                    bone.rotType = Animation.RotationType.Euler;

                    Animation.KeyFrame n = new Animation.KeyFrame();
                    n.Value = float.Parse(args[1]);
                    n.Frame = frame;
                    bone.xpos.keys.Add(n);

                    n       = new Animation.KeyFrame();
                    n.Value = float.Parse(args[2]);
                    n.Frame = frame;
                    bone.ypos.keys.Add(n);

                    n       = new Animation.KeyFrame();
                    n.Value = float.Parse(args[3]);
                    n.Frame = frame;
                    bone.zpos.keys.Add(n);

                    n       = new Animation.KeyFrame();
                    n.Value = float.Parse(args[4]);
                    n.Frame = frame;
                    bone.xrot.keys.Add(n);

                    n       = new Animation.KeyFrame();
                    n.Value = float.Parse(args[5]);
                    n.Frame = frame;
                    bone.yrot.keys.Add(n);

                    n       = new Animation.KeyFrame();
                    n.Value = float.Parse(args[6]);
                    n.Frame = frame;
                    bone.zrot.keys.Add(n);

                    if (args.Length > 7)
                    {
                        n       = new Animation.KeyFrame();
                        n.Value = float.Parse(args[7]);
                        n.Frame = frame;
                        bone.xsca.keys.Add(n);

                        n       = new Animation.KeyFrame();
                        n.Value = float.Parse(args[8]);
                        n.Frame = frame;
                        bone.ysca.keys.Add(n);

                        n       = new Animation.KeyFrame();
                        n.Value = float.Parse(args[9]);
                        n.Frame = frame;
                        bone.zsca.keys.Add(n);
                    }
                }
            }

            a.frameCount = frame;

            vbn.boneCountPerType[0] = (uint)vbn.bones.Count;
            vbn.update();
        }
Ejemplo n.º 11
0
            public void Read(ResFile TargetWiiUBFRES, AnimationGroupNode ThisAnimation, ResNSW.ResFile b)
            {
                Console.WriteLine("Reading Skeleton Animations ...");

                if (b != null)
                {
                    TreeNode SkeletonAnimation = new TreeNode()
                    {
                        Text = "Skeleton Animations"
                    };

                    ThisAnimation.Nodes.Add(SkeletonAnimation);

                    TreeNode dummy = new TreeNode()
                    {
                        Text = "Animation Set"
                    };

                    int i = 0;
                    foreach (ResNSW.SkeletalAnim ska in b.SkeletalAnims)
                    {
                        if (i == 0)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "0 - 100"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 100)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "100 - 200"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 200)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "200 - 300"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 300)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "300 - 400"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 400)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "400 - 500"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 500)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "500 - 600"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 600)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "600 - 700"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 700)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "700 - 800"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 800)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "800 - 900"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 900)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "900 - 1000"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 1000)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "1000+"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }

                        Animation a = new Animation(ska.Name);
                        SkeletonAnimations.Add(a);

                        a.frameCount = ska.FrameCount;

                        if (i >= 0 && i < 100)
                        {
                            SkeletonAnimation.Nodes[0].Nodes.Add(a);
                        }
                        if (i >= 100 && i < 200)
                        {
                            SkeletonAnimation.Nodes[1].Nodes.Add(a);
                        }
                        if (i >= 200 && i < 300)
                        {
                            SkeletonAnimation.Nodes[2].Nodes.Add(a);
                        }
                        if (i >= 300 && i < 400)
                        {
                            SkeletonAnimation.Nodes[3].Nodes.Add(a);
                        }
                        if (i >= 400 && i < 500)
                        {
                            SkeletonAnimation.Nodes[4].Nodes.Add(a);
                        }
                        if (i >= 500 && i < 600)
                        {
                            SkeletonAnimation.Nodes[5].Nodes.Add(a);
                        }
                        if (i >= 600 && i < 700)
                        {
                            SkeletonAnimation.Nodes[6].Nodes.Add(a);
                        }
                        if (i >= 700 && i < 800)
                        {
                            SkeletonAnimation.Nodes[7].Nodes.Add(a);
                        }
                        if (i >= 800 && i < 900)
                        {
                            SkeletonAnimation.Nodes[8].Nodes.Add(a);
                        }
                        if (i >= 900 && i < 1000)
                        {
                            SkeletonAnimation.Nodes[9].Nodes.Add(a);
                        }

                        i++;
                        try
                        {
                            foreach (ResNSW.BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANode bonean = new FSKANode(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.bones.Add(bone);
                                if (ska.FlagsRotate == ResNSW.SkeletalAnimFlagsRotate.EulerXYZ)
                                {
                                    bone.rotType = Animation.RotationType.Euler;
                                }
                                else
                                {
                                    bone.rotType = Animation.RotationType.Quaternion;
                                }

                                bone.Text = bonean.Text;

                                for (int Frame = 0; Frame < ska.FrameCount; Frame++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (Frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Scale))
                                        {
                                            bone.xsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.ysca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.zsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.xrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.yrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.zrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.wrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Translate))
                                        {
                                            bone.xpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.ypos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.zpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame frame = new Animation.KeyFrame();
                                        frame.interType = Animation.InterpolationType.Hermite;
                                        frame.Frame     = Frame;

                                        FSKAKey left  = track.GetLeft(Frame);
                                        FSKAKey right = track.GetRight(Frame);
                                        float   value;



                                        value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);

                                        // interpolate the value and apply
                                        switch (track.flag)
                                        {
                                        case (int)TrackType.XPOS: frame.Value = value; bone.xpos.keys.Add(frame); break;

                                        case (int)TrackType.YPOS: frame.Value = value; bone.ypos.keys.Add(frame); break;

                                        case (int)TrackType.ZPOS: frame.Value = value; bone.zpos.keys.Add(frame); break;

                                        case (int)TrackType.XROT: frame.Value = value; bone.xrot.keys.Add(frame); break;

                                        case (int)TrackType.YROT: frame.Value = value; bone.yrot.keys.Add(frame); break;

                                        case (int)TrackType.ZROT: frame.Value = value; bone.zrot.keys.Add(frame); break;

                                        case (int)TrackType.XSCA: frame.Value = value; bone.xsca.keys.Add(frame); break;

                                        case (int)TrackType.YSCA: frame.Value = value; bone.ysca.keys.Add(frame); break;

                                        case (int)TrackType.ZSCA: frame.Value = value; bone.zsca.keys.Add(frame); break;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    TreeNode SkeletonAnimation = new TreeNode()
                    {
                        Text = "Skeleton Animations"
                    };

                    ThisAnimation.Nodes.Add(SkeletonAnimation);

                    TreeNode dummy = new TreeNode()
                    {
                        Text = "Animation Set"
                    };

                    int i = 0;
                    foreach (SkeletalAnim ska in TargetWiiUBFRES.SkeletalAnims.Values)
                    {
                        if (i == 0)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "0 - 100"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 100)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "100 - 200"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 200)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "200 - 300"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 300)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "300 - 400"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 400)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "400 - 500"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 500)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "500 - 600"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 600)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "600 - 700"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 700)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "700 - 800"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 800)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "800 - 900"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 900)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "900 - 1000"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 1000)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "1000+"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }

                        Animation a = new Animation(ska.Name);

                        if (i >= 0 && i < 100)
                        {
                            SkeletonAnimation.Nodes[0].Nodes.Add(a);
                        }
                        if (i >= 100 && i < 200)
                        {
                            SkeletonAnimation.Nodes[1].Nodes.Add(a);
                        }
                        if (i >= 200 && i < 300)
                        {
                            SkeletonAnimation.Nodes[2].Nodes.Add(a);
                        }
                        if (i >= 300 && i < 400)
                        {
                            SkeletonAnimation.Nodes[3].Nodes.Add(a);
                        }
                        if (i >= 400 && i < 500)
                        {
                            SkeletonAnimation.Nodes[4].Nodes.Add(a);
                        }
                        if (i >= 500 && i < 600)
                        {
                            SkeletonAnimation.Nodes[5].Nodes.Add(a);
                        }
                        if (i >= 600 && i < 700)
                        {
                            SkeletonAnimation.Nodes[6].Nodes.Add(a);
                        }
                        if (i >= 700 && i < 800)
                        {
                            SkeletonAnimation.Nodes[7].Nodes.Add(a);
                        }
                        if (i >= 800 && i < 900)
                        {
                            SkeletonAnimation.Nodes[8].Nodes.Add(a);
                        }
                        if (i >= 900 && i < 1000)
                        {
                            SkeletonAnimation.Nodes[9].Nodes.Add(a);
                        }


                        a.frameCount = ska.FrameCount;
                        i++;
                        try
                        {
                            foreach (BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANodeWiiU bonean = new FSKANodeWiiU(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.bones.Add(bone);
                                if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                                {
                                    bone.rotType = Animation.RotationType.Euler;
                                }
                                else
                                {
                                    bone.rotType = Animation.RotationType.Quaternion;
                                }

                                bone.Text = bonean.Text;


                                for (int Frame = 0; Frame < ska.FrameCount; Frame++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (Frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
                                        {
                                            bone.xsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.ysca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.zsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.xrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.yrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.zrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.wrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
                                        {
                                            bone.xpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.ypos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.zpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame frame = new Animation.KeyFrame();
                                        frame.interType = Animation.InterpolationType.Hermite;
                                        frame.Frame     = Frame;

                                        FSKAKey left  = track.GetLeft(Frame);
                                        FSKAKey right = track.GetRight(Frame);
                                        float   value;



                                        value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);

                                        // interpolate the value and apply
                                        switch (track.flag)
                                        {
                                        case (int)TrackType.XPOS: frame.Value = value; bone.xpos.keys.Add(frame); break;

                                        case (int)TrackType.YPOS: frame.Value = value; bone.ypos.keys.Add(frame); break;

                                        case (int)TrackType.ZPOS: frame.Value = value; bone.zpos.keys.Add(frame); break;

                                        case (int)TrackType.XROT: frame.Value = value; bone.xrot.keys.Add(frame); break;

                                        case (int)TrackType.YROT: frame.Value = value; bone.yrot.keys.Add(frame); break;

                                        case (int)TrackType.ZROT: frame.Value = value; bone.zrot.keys.Add(frame); break;

                                        case (int)TrackType.XSCA: frame.Value = value; bone.xsca.keys.Add(frame); break;

                                        case (int)TrackType.YSCA: frame.Value = value; bone.ysca.keys.Add(frame); break;

                                        case (int)TrackType.ZSCA: frame.Value = value; bone.zsca.keys.Add(frame); break;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
Ejemplo n.º 12
0
            public void Read(ResFile targetWiiUbfres, AnimationGroupNode thisAnimation, ResNSW.ResFile b)
            {
                Console.WriteLine("Reading Skeleton Animations ...");

                if (b != null)
                {
                    TreeNode skeletonAnimationNode = new TreeNode {
                        Text = "Skeleton Animations"
                    };

                    thisAnimation.Nodes.Add(skeletonAnimationNode);

                    // Split animation nodes into groups so they can all fit inside the view.
                    // Make sure to add an additional set if the animations can't be divided evenly.
                    int setCount = b.SkeletalAnims.Count / setSize;
                    if (b.SkeletalAnims.Count % setSize != 0)
                    {
                        setCount += 1;
                    }

                    for (int i = 0; i < setCount; i++)
                    {
                        int start = i * setSize;
                        int end   = start + setSize - 1;
                        skeletonAnimationNode.Nodes.Add(new TreeNode {
                            Text = $"Animation Set {start} - {end}"
                        });
                    }

                    for (int i = 0; i < b.SkeletalAnims.Count; i++)
                    {
                        var ska      = b.SkeletalAnims[i];
                        int setIndex = i / setSize;

                        Animation a = new Animation(ska.Name);
                        SkeletonAnimations.Add(a);

                        a.frameCount = ska.FrameCount;

                        skeletonAnimationNode.Nodes[setIndex].Nodes.Add(a);

                        try
                        {
                            foreach (ResNSW.BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANode bonean = new FSKANode(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.bones.Add(bone);
                                if (ska.FlagsRotate == ResNSW.SkeletalAnimFlagsRotate.EulerXYZ)
                                {
                                    bone.rotType = Animation.RotationType.Euler;
                                }
                                else
                                {
                                    bone.rotType = Animation.RotationType.Quaternion;
                                }

                                bone.Text = bonean.Text;

                                for (int frame = 0; frame < ska.FrameCount; frame++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Scale))
                                        {
                                            bone.xsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.ysca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.zsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.xrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.yrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.zrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.wrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Translate))
                                        {
                                            bone.xpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.ypos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.zpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame keyFrame = new Animation.KeyFrame();
                                        keyFrame.interType = Animation.InterpolationType.Hermite;
                                        keyFrame.Frame     = frame;

                                        FSKAKey left  = track.GetLeft(frame);
                                        FSKAKey right = track.GetRight(frame);

                                        // interpolate the value and apply
                                        float value = Animation.Hermite(frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);
                                        switch (track.flag)
                                        {
                                        case (int)TrackType.XPOS: keyFrame.Value = value; bone.xpos.keys.Add(keyFrame); break;

                                        case (int)TrackType.YPOS: keyFrame.Value = value; bone.ypos.keys.Add(keyFrame); break;

                                        case (int)TrackType.ZPOS: keyFrame.Value = value; bone.zpos.keys.Add(keyFrame); break;

                                        case (int)TrackType.XROT: keyFrame.Value = value; bone.xrot.keys.Add(keyFrame); break;

                                        case (int)TrackType.YROT: keyFrame.Value = value; bone.yrot.keys.Add(keyFrame); break;

                                        case (int)TrackType.ZROT: keyFrame.Value = value; bone.zrot.keys.Add(keyFrame); break;

                                        case (int)TrackType.XSCA: keyFrame.Value = value; bone.xsca.keys.Add(keyFrame); break;

                                        case (int)TrackType.YSCA: keyFrame.Value = value; bone.ysca.keys.Add(keyFrame); break;

                                        case (int)TrackType.ZSCA: keyFrame.Value = value; bone.zsca.keys.Add(keyFrame); break;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    TreeNode SkeletonAnimation = new TreeNode()
                    {
                        Text = "Skeleton Animations"
                    };

                    thisAnimation.Nodes.Add(SkeletonAnimation);

                    TreeNode dummy = new TreeNode()
                    {
                        Text = "Animation Set"
                    };

                    int i = 0;
                    foreach (SkeletalAnim ska in targetWiiUbfres.SkeletalAnims.Values)
                    {
                        if (i == 0)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "0 - 100"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 100)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "100 - 200"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 200)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "200 - 300"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 300)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "300 - 400"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 400)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "400 - 500"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 500)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "500 - 600"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 600)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "600 - 700"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 700)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "700 - 800"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 800)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "800 - 900"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 900)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "900 - 1000"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 1000)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "1000+"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }

                        Animation a = new Animation(ska.Name);

                        if (i >= 0 && i < 100)
                        {
                            SkeletonAnimation.Nodes[0].Nodes.Add(a);
                        }
                        if (i >= 100 && i < 200)
                        {
                            SkeletonAnimation.Nodes[1].Nodes.Add(a);
                        }
                        if (i >= 200 && i < 300)
                        {
                            SkeletonAnimation.Nodes[2].Nodes.Add(a);
                        }
                        if (i >= 300 && i < 400)
                        {
                            SkeletonAnimation.Nodes[3].Nodes.Add(a);
                        }
                        if (i >= 400 && i < 500)
                        {
                            SkeletonAnimation.Nodes[4].Nodes.Add(a);
                        }
                        if (i >= 500 && i < 600)
                        {
                            SkeletonAnimation.Nodes[5].Nodes.Add(a);
                        }
                        if (i >= 600 && i < 700)
                        {
                            SkeletonAnimation.Nodes[6].Nodes.Add(a);
                        }
                        if (i >= 700 && i < 800)
                        {
                            SkeletonAnimation.Nodes[7].Nodes.Add(a);
                        }
                        if (i >= 800 && i < 900)
                        {
                            SkeletonAnimation.Nodes[8].Nodes.Add(a);
                        }
                        if (i >= 900 && i < 1000)
                        {
                            SkeletonAnimation.Nodes[9].Nodes.Add(a);
                        }


                        a.frameCount = ska.FrameCount;
                        i++;
                        try
                        {
                            foreach (BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANodeWiiU bonean = new FSKANodeWiiU(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.bones.Add(bone);
                                if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                                {
                                    bone.rotType = Animation.RotationType.Euler;
                                }
                                else
                                {
                                    bone.rotType = Animation.RotationType.Quaternion;
                                }

                                bone.Text = bonean.Text;


                                for (int Frame = 0; Frame < ska.FrameCount; Frame++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (Frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
                                        {
                                            bone.xsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.ysca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.zsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.xrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.yrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.zrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.wrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
                                        {
                                            bone.xpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.ypos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.zpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame frame = new Animation.KeyFrame();
                                        frame.interType = Animation.InterpolationType.Hermite;
                                        frame.Frame     = Frame;

                                        FSKAKey left  = track.GetLeft(Frame);
                                        FSKAKey right = track.GetRight(Frame);
                                        float   value;



                                        value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);

                                        // interpolate the value and apply
                                        switch (track.flag)
                                        {
                                        case (int)TrackType.XPOS: frame.Value = value; bone.xpos.keys.Add(frame); break;

                                        case (int)TrackType.YPOS: frame.Value = value; bone.ypos.keys.Add(frame); break;

                                        case (int)TrackType.ZPOS: frame.Value = value; bone.zpos.keys.Add(frame); break;

                                        case (int)TrackType.XROT: frame.Value = value; bone.xrot.keys.Add(frame); break;

                                        case (int)TrackType.YROT: frame.Value = value; bone.yrot.keys.Add(frame); break;

                                        case (int)TrackType.ZROT: frame.Value = value; bone.zrot.keys.Add(frame); break;

                                        case (int)TrackType.XSCA: frame.Value = value; bone.xsca.keys.Add(frame); break;

                                        case (int)TrackType.YSCA: frame.Value = value; bone.ysca.keys.Add(frame); break;

                                        case (int)TrackType.ZSCA: frame.Value = value; bone.zsca.keys.Add(frame); break;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }