Example #1
0
            public float getValue(int frame)
            {
                AnimKey f1 = null, f2 = null;

                for (int i = 0; i < keys.Count - 1; i++)
                {
                    if ((keys [i].input - 1 <= frame && keys [i + 1].input - 1 >= frame))
                    {
                        f1 = keys [i];
                        f2 = keys [i + 1];
                        break;
                    }
                }
                if (f1 == null)
                {
                    if (keys.Count <= 1)
                    {
                        return(keys [0].output);
                    }
                    else
                    {
                        f1 = keys [keys.Count - 2];
                        f2 = keys [keys.Count - 1];
                    }
                }

                return(CHR0.interHermite(frame + 1, f1.input, f2.input, weighted ? f1.t1 : 0, weighted ? f2.t1 : 0, f1.output, f2.output));
            }
Example #2
0
        public void ReplaceAnimation(object sender, EventArgs args)
        {
            using (OpenFileDialog of = new OpenFileDialog())
            {
                of.ShowDialog();

                foreach (string filename in of.FileNames)
                {
                    if (filename.EndsWith(".omo"))
                    {
                        Animation a = OMOOld.read(new FileData(filename));
                        a.Text = filename;
                        ReplaceMe(a);
                    }
                    if (filename.EndsWith(".smd"))
                    {
                        Animation a = new Animation(filename.Replace(".smd", ""));
                        SMD.read(filename, a, Runtime.TargetVBN);
                        ReplaceMe(a);
                    }
                    if (filename.EndsWith(".chr0"))
                    {
                        Animation a = (CHR0.read(new FileData(filename), Runtime.TargetVBN));
                        ReplaceMe(a);
                    }
                    if (filename.EndsWith(".anim"))
                    {
                        Animation a = (ANIM.read(filename, Runtime.TargetVBN));
                        ReplaceMe(a);
                    }
                }
            }
        }
Example #3
0
 public void Import(object sender, EventArgs args)
 {
     using (OpenFileDialog fd = new OpenFileDialog())
     {
         fd.Filter = "Supported Formats|*.omo;*.anim;*.chr0;*.smd;*.mta;|" +
                     "Object Motion|*.omo|" +
                     "Maya Animation|*.anim|" +
                     "NW4R Animation|*.chr0|" +
                     "Source Animation (SMD)|*.smd|" +
                     "Smash 4 Material Animation (MTA)|*.mta|" +
                     "All files(*.*)|*.*";
         if (fd.ShowDialog() == DialogResult.OK)
         {
             foreach (string filename in fd.FileNames)
             {
                 if (filename.EndsWith(".mta"))
                 {
                     MTA mta = new MTA();
                     try
                     {
                         mta.Read(filename);
                         Runtime.MaterialAnimations.Add(filename, mta);
                         Nodes.Add(filename);
                     }
                     catch (Exception)
                     {
                         mta = null;
                     }
                 }
                 else if (filename.EndsWith(".smd"))
                 {
                     var anim = new Animation(filename);
                     if (Runtime.TargetVBN == null)
                     {
                         Runtime.TargetVBN = new VBN();
                     }
                     SMD.read(filename, anim, Runtime.TargetVBN);
                     Nodes.Add(anim);
                 }
                 if (filename.EndsWith(".omo"))
                 {
                     Animation a = OMOOld.read(new FileData(filename));
                     a.Text = filename;
                     Nodes.Add(a);
                 }
                 if (filename.EndsWith(".chr0"))
                 {
                     Nodes.Add(CHR0.read(new FileData(filename), Runtime.TargetVBN));
                 }
                 if (filename.EndsWith(".anim"))
                 {
                     Nodes.Add(ANIM.read(filename, Runtime.TargetVBN));
                 }
             }
         }
     }
 }
Example #4
0
        private Frame[] Bake(int bone)
        {
            Frame[] frames = new Frame[anim.frameCount];
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = new Frame(i);
            }

            foreach (DAT_Animation.DATAnimTrack track in anim.nodes[bone])
            {
                int f = 0, ni = 0, currentFrame = 0, nextFrame = 0;
                DAT_Animation.KeyNode node = track.keys[ni++];
                nextFrame = (int)node.frame;
                float cvalue = node.value, ctan = node.tan;
                while (f < anim.frameCount)
                {
                    try
                    {
                        // calculate value
                        float nvalue = -99, ntan = -99;
                        for (int j = ni; j < track.keys.Count; j++)
                        {
                            //if (track.keys[j].interpolationType != DAT_Animation.InterpolationType.HermiteCurve)
                            {
                                if (track.keys[j].interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                                {
                                    ctan = track.keys[j].tan;
                                }
                                else
                                if (track.keys[j].tan != -99 && ntan == -99)
                                {
                                    ntan = track.keys[j].tan;
                                }
                                if (track.keys[j].value != -99 && nvalue == -99)
                                {
                                    nvalue = track.keys[j].value;
                                }
                                if (nvalue != -99 && ntan != -99)
                                {
                                    break;
                                }
                            }
                        }
                        if (nvalue == -99)
                        {
                            nvalue = track.keys[0].value;
                        }
                        if (ntan == -99)
                        {
                            ntan = 0;
                        }
                        if (ctan == -99)
                        {
                            ctan = 0;
                        }

                        float value = 0;
                        //Console.WriteLine(track.type + " " + node.interpolationType);
                        switch (node.interpolationType)
                        {
                        case DAT_Animation.InterpolationType.Hermite:
                        {
                            cvalue = node.value;
                            //value = Interpolate(f - currentFrame, nextFrame - currentFrame, cvalue, nvalue, ctan, ntan);
                            value = CHR0.interHermite(f, currentFrame, nextFrame + 1, ctan, ntan, cvalue, nvalue);
                        }
                        break;

                        case DAT_Animation.InterpolationType.HermiteValue:
                        {
                            cvalue = node.value;
                            ctan   = 0;
                            //value = Interpolate(f - currentFrame, nextFrame - currentFrame, cvalue, nvalue, ctan, ntan);
                            value = CHR0.interHermite(f, currentFrame, nextFrame + 1, 0, 0, cvalue, nvalue);
                        }
                        break;

                        case DAT_Animation.InterpolationType.Step:
                        {
                            value = node.value;
                        }
                        break;

                        case DAT_Animation.InterpolationType.Linear:
                        {
                            cvalue = node.value;
                            value  = CHR0.lerp(cvalue, nvalue, currentFrame, nextFrame, f);
                        }
                        break;

                        default:
                            Console.WriteLine(node.interpolationType);
                            break;
                        }

                        if (float.IsNaN(value) || f == currentFrame)
                        {
                            value = node.value;
                        }

                        switch (track.type)
                        {
                        case DAT_Animation.AnimType.XROT:
                            //Console.WriteLine(ctan + " " + ntan + " " + node.value + " " + nvalue + " " + f + " " + currentFrame + " " + nextFrame);
                            frames[f].rx = value * 180 / (float)Math.PI;
                            break;

                        case DAT_Animation.AnimType.YROT:
                            //Console.WriteLine(ctan + " " + ntan + " " + cvalue + " " + nvalue + " " + f + " " + currentFrame + " " + nextFrame);

                            frames[f].ry = value * 180 / (float)Math.PI;
                            break;

                        case DAT_Animation.AnimType.ZROT:
                            //Console.WriteLine(ctan + " " + ntan + " " + cvalue + " " + nvalue + " " + f + " " + currentFrame + " " + nextFrame);
                            frames[f].rz = value * 180 / (float)Math.PI;
                            break;

                        case DAT_Animation.AnimType.XPOS: frames[f].x = value; break;

                        case DAT_Animation.AnimType.YPOS: frames[f].y = value; break;

                        case DAT_Animation.AnimType.ZPOS: frames[f].z = value; break;

                        case DAT_Animation.AnimType.XSCA: frames[f].sx = value; break;

                        case DAT_Animation.AnimType.YSCA: frames[f].sy = value; break;

                        case DAT_Animation.AnimType.ZSCA: frames[f].sz = value; break;
                        }

                        f++;
                        if (f > nextFrame)
                        {
                            if (ni >= track.keys.Count)
                            {
                                node = track.keys[0];
                                continue;
                            }
                            node = track.keys[ni++];
                            while (node.interpolationType == DAT_Animation.InterpolationType.HermiteCurve)
                            {
                                node = track.keys[ni++];
                            }
                            currentFrame = f;
                            nextFrame   += (int)node.frame;

                            switch (node.interpolationType)
                            {
                            case DAT_Animation.InterpolationType.Hermite:
                            {
                                ctan = node.tan;
                            }
                            break;
                            }
                        }
                    }
                    catch (IndexOutOfRangeException ex)
                    {
                    }
                }
            }
            return(frames);
        }
Example #5
0
        //<summary>
        //Open an animation based on filename
        //</summary>
        public void openAnimation(string filename)
        {
            //Runtime.Animations.Clear();
            if (filename.EndsWith(".mta"))
            {
                MTA mta = new MTA();
                try
                {
                    mta.Read(filename);
                    Runtime.MaterialAnimations.Add(filename, mta);
                    mtaNode.Nodes.Add(filename);
                    MainForm.Instance.viewports[0].loadMTA(mta);
                    Runtime.TargetMTAString = filename;
                }
                catch (EndOfStreamException)
                {
                    mta = null;
                }
            }
            else if (filename.EndsWith(".smd"))
            {
                var anim = new SkelAnimation();
                if (Runtime.TargetVBN == null)
                {
                    Runtime.TargetVBN = new VBN();
                }
                SMD.read(filename, anim, Runtime.TargetVBN);
                leftPanel.treeRefresh();
                Runtime.Animations.Add(filename, anim);
                animNode.Nodes.Add(filename);
            }
            else if (filename.EndsWith(".pac"))
            {
                PAC p = new PAC();
                p.Read(filename);

                foreach (var pair in p.Files)
                {
                    if (pair.Key.EndsWith(".omo"))
                    {
                        var    anim     = OMO.read(new FileData(pair.Value));
                        string AnimName = Regex.Match(pair.Key, @"([A-Z][0-9][0-9])(.*)").Groups[0].ToString();
                        //AnimName = pair.Key;
                        //AnimName = AnimName.Remove(AnimName.Length - 4);
                        //AnimName = AnimName.Insert(3, "_");
                        if (!string.IsNullOrEmpty(AnimName))
                        {
                            if (Runtime.Animations.ContainsKey(AnimName))
                            {
                                Runtime.Animations[AnimName].children.Add(anim);
                            }
                            else
                            {
                                animNode.Nodes.Add(AnimName);
                                Runtime.Animations.Add(AnimName, anim);
                            }
                        }
                        else
                        {
                            if (Runtime.Animations.ContainsKey(pair.Key))
                            {
                                Runtime.Animations[pair.Key].children.Add(anim);
                            }
                            else
                            {
                                animNode.Nodes.Add(pair.Key);
                                Runtime.Animations.Add(pair.Key, anim);
                            }
                        }
                    }
                    else if (pair.Key.EndsWith(".mta"))
                    {
                        MTA mta = new MTA();
                        try
                        {
                            if (!Runtime.MaterialAnimations.ContainsKey(pair.Key))
                            {
                                mta.read(new FileData(pair.Value));
                                Runtime.MaterialAnimations.Add(pair.Key, mta);
                                mtaNode.Nodes.Add(pair.Key);
                            }

                            // matching
                            string AnimName = Regex.Match(pair.Key, @"([A-Z][0-9][0-9])(.*)").Groups[0].ToString().Replace(".mta", ".omo");
                            if (Runtime.Animations.ContainsKey(AnimName))
                            {
                                Runtime.Animations[AnimName].children.Add(mta);
                            }
                        }
                        catch (EndOfStreamException)
                        {
                            mta = null;
                        }
                    }
                }
            }

            if (filename.EndsWith(".dat"))
            {
                if (!filename.EndsWith("AJ.dat"))
                {
                    MessageBox.Show("Not a DAT animation");
                }
                else
                {
                    if (Runtime.ModelContainers[0].dat_melee == null)
                    {
                        MessageBox.Show("Load a DAT model first");
                    }
                    else
                    {
                        DAT_Animation.LoadAJ(filename, Runtime.ModelContainers[0].dat_melee.bones);
                    }
                }
            }
            //if (Runtime.TargetVBN.bones.Count > 0)
            //{
            if (filename.EndsWith(".omo"))
            {
                Runtime.Animations.Add(filename, OMO.read(new FileData(filename)));
                animNode.Nodes.Add(filename);
            }
            if (filename.EndsWith(".chr0"))
            {
                Runtime.Animations.Add(filename, CHR0.read(new FileData(filename), Runtime.TargetVBN));
                animNode.Nodes.Add(filename);
            }
            if (filename.EndsWith(".anim"))
            {
                Runtime.Animations.Add(filename, ANIM.read(filename, Runtime.TargetVBN));
                animNode.Nodes.Add(filename);
            }
        }