示例#1
0
        internal void ApplyCHR0(CHR0Node node, int index, bool linear)
        {
            CHR0EntryNode e;

            _frameState = _bindState;

            if (node != null && index > 0 && (e = node.FindChild(Name, false) as CHR0EntryNode) != null) //Set to anim pose
                fixed(FrameState *v = &_frameState)
                {
                    float *f = (float *)v;

                    for (int i = 0; i < 9; i++)
                    {
                        if (e.Keyframes[(KeyFrameMode)(i + 0x10)] > 0)
                        {
                            f[i] = e.GetFrameValue((KeyFrameMode)(i + 0x10), index - 1, linear, node.Loop);
                        }
                    }

                    _frameState.CalcTransforms();
                }

            foreach (MDL0BoneNode b in Children)
            {
                b.ApplyCHR0(node, index, linear);
            }
        }
示例#2
0
        internal void ApplyCHR0(CHR0Node node, float index)
        {
            CHR0EntryNode e;

            _frameState = _bindState;

            if (node != null && index >= 1 && (e = node.FindChild(Name, false) as CHR0EntryNode) != null) //Set to anim pose
                fixed(FrameState *v = &_frameState)
                {
                    float *f = (float *)v;

                    for (int i = 0; i < 9; i++)
                    {
                        if (e.Keyframes[i]._keyCount > 0)
                        {
                            f[i] = e.GetFrameValue(i, index - 1);
                        }
                    }

                    _frameState.CalcTransforms();
                }

            foreach (MDL0BoneNode b in Children)
            {
                b.ApplyCHR0(node, index);
            }
        }
示例#3
0
        public void ImportFolder(string inFolder)
        {
            DirectoryInfo dir = new DirectoryInfo(inFolder);

            FileInfo[] files;

            files = dir.GetFiles();
            foreach (FileInfo info in files)
            {
                string ext = Path.GetExtension(info.FullName).ToUpper();
                if (ext == ".PNG" || ext == ".TGA" || ext == ".BMP" || ext == ".JPG" || ext == ".JPEG" || ext == ".GIF" || ext == ".TIF" || ext == ".TIFF")
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog())
                    {
                        dlg.ImageSource = info.FullName;
                        dlg.ShowDialog(null, this);
                    }
                }
                else if (ext == ".TEX0")
                {
                    TEX0Node node = NodeFactory.FromFile(null, info.FullName) as TEX0Node;
                    GetOrCreateFolder <TEX0Node>().AddChild(node);
                }
                else if (ext == ".MDL0")
                {
                    MDL0Node node = NodeFactory.FromFile(null, info.FullName) as MDL0Node;
                    GetOrCreateFolder <MDL0Node>().AddChild(node);
                }
                else if (ext == ".CHR0")
                {
                    CHR0Node node = NodeFactory.FromFile(null, info.FullName) as CHR0Node;
                    GetOrCreateFolder <CHR0Node>().AddChild(node);
                }
                else if (ext == ".CLR0")
                {
                    CLR0Node node = NodeFactory.FromFile(null, info.FullName) as CLR0Node;
                    GetOrCreateFolder <CLR0Node>().AddChild(node);
                }
                else if (ext == ".SRT0")
                {
                    SRT0Node node = NodeFactory.FromFile(null, info.FullName) as SRT0Node;
                    GetOrCreateFolder <SRT0Node>().AddChild(node);
                }
                else if (ext == ".SHP0")
                {
                    SHP0Node node = NodeFactory.FromFile(null, info.FullName) as SHP0Node;
                    GetOrCreateFolder <SHP0Node>().AddChild(node);
                }
                else if (ext == ".PAT0")
                {
                    PAT0Node node = NodeFactory.FromFile(null, info.FullName) as PAT0Node;
                    GetOrCreateFolder <PAT0Node>().AddChild(node);
                }
                else if (ext == ".VIS0")
                {
                    VIS0Node node = NodeFactory.FromFile(null, info.FullName) as VIS0Node;
                    GetOrCreateFolder <VIS0Node>().AddChild(node);
                }
            }
        }
        public void Reverse(bool appendReverse)
        {
            CHR0Node tempReversedCHR0 = new CHR0Node();

            tempReversedCHR0.Name       = this.Name + "_Reversed";
            tempReversedCHR0.Loop       = this.Loop;
            tempReversedCHR0.FrameCount = FrameCount;

            // Fixes non-looped animations being off by a frame
            int loopfix = 0;

            if (!Loop)
            {
                loopfix = 1;
            }

            KeyframeEntry kfe;

            foreach (CHR0EntryNode tempEntry in Children)
            {
                CHR0EntryNode newIntEntry = new CHR0EntryNode()
                {
                    Name = tempEntry.Name
                };
                newIntEntry.SetSize(tempEntry.FrameCount, Loop);
                for (int x = 0; x < tempEntry.FrameCount; x++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        if ((kfe = tempEntry.GetKeyframe(i, x)) != null)
                        {
                            newIntEntry.Keyframes.SetFrameValue(i, FrameCount - (x + loopfix), kfe._value)._tangent = kfe._tangent;
                        }
                    }
                }
                tempReversedCHR0.AddChild(newIntEntry);
            }
            if (appendReverse)
            {
                Append(tempReversedCHR0, 1);
            }
            else
            {
                // Remove old keyframes
                while (HasChildren)
                {
                    RemoveChild(Children[0]);
                }
                // Add reversed keyframes
                foreach (CHR0EntryNode entryToAdd in tempReversedCHR0.Children)
                {
                    entryToAdd.SignalPropertyChange();
                    AddChild(entryToAdd);
                }
            }
        }
        /// <summary>
        /// Adds an animation opened by the user to the end of this one
        /// </summary>
        public void Append()
        {
            CHR0Node       external = null;
            OpenFileDialog o        = new OpenFileDialog();

            o.Filter = "CHR0 Animation (*.chr0)|*.chr0";
            o.Title  = "Please select an animation to append.";
            if (o.ShowDialog() == DialogResult.OK)
            {
                if ((external = (CHR0Node)NodeFactory.FromFile(null, o.FileName)) != null)
                {
                    Append(external, 1);
                }
            }
        }
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(CHR0Node external, int timesToAppend)
        {
            KeyframeEntry kfe;
            int           extCount = external.FrameCount;

            for (int appendCount = 0; appendCount < timesToAppend; ++appendCount)
            {
                int origIntCount = FrameCount;
                FrameCount += extCount;

                foreach (CHR0EntryNode extEntry in external.Children)
                {
                    CHR0EntryNode intEntry = null;
                    if ((intEntry = (CHR0EntryNode)FindChild(extEntry.Name, false)) == null)
                    {
                        CHR0EntryNode newIntEntry = new CHR0EntryNode()
                        {
                            Name = extEntry.Name
                        };
                        newIntEntry.SetSize(extEntry.FrameCount + origIntCount, Loop);
                        for (int x = 0; x < extEntry.FrameCount; x++)
                        {
                            for (int i = 0; i < 9; i++)
                            {
                                if ((kfe = extEntry.GetKeyframe(i, x)) != null)
                                {
                                    newIntEntry.Keyframes.SetFrameValue(i, x + origIntCount, kfe._value)._tangent = kfe._tangent;
                                }
                            }
                        }
                        AddChild(newIntEntry);
                    }
                    else
                    {
                        for (int x = 0; x < extEntry.FrameCount; x++)
                        {
                            for (int i = 0; i < 9; i++)
                            {
                                if ((kfe = extEntry.GetKeyframe(i, x)) != null)
                                {
                                    intEntry.Keyframes.SetFrameValue(i, x + origIntCount, kfe._value)._tangent = kfe._tangent;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(CHR0Node external)
        {
            KeyframeEntry kfe;

            int origIntCount = FrameCount;
            int extCount     = external.FrameCount;

            FrameCount += extCount;

            foreach (CHR0EntryNode _extEntry in external.Children)
            {
                CHR0EntryNode _intEntry = null;
                if ((_intEntry = (CHR0EntryNode)FindChild(_extEntry.Name, false)) == null)
                {
                    CHR0EntryNode newIntEntry = new CHR0EntryNode()
                    {
                        Name = _extEntry.Name
                    };
                    newIntEntry._numFrames = _extEntry.FrameCount + origIntCount;
                    for (int x = 0; x < _extEntry.FrameCount; x++)
                    {
                        for (int i = 0x10; i < 0x19; i++)
                        {
                            if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                newIntEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent;
                            }
                        }
                    }
                    AddChild(newIntEntry);
                }
                else
                {
                    for (int x = 0; x < _extEntry.FrameCount; x++)
                    {
                        for (int i = 0x10; i < 0x19; i++)
                        {
                            if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                _intEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent;
                            }
                        }
                    }
                }
            }
        }
示例#8
0
        public void Append(CHR0Node external)
        {
            KeyframeEntry kfe;

            int oldCount = FrameCount;

            FrameCount += external.FrameCount;

            foreach (CHR0EntryNode _target in external.Children)
            {
                CHR0EntryNode node = null;
                if ((node = (CHR0EntryNode)FindChild(_target.Name, false)) == null)
                {
                    CHR0EntryNode newNode = new CHR0EntryNode()
                    {
                        Name = _target.Name
                    };
                    newNode._numFrames = _target.FrameCount + oldCount;
                    for (int x = 0; x < _target.FrameCount; x++)
                    {
                        for (int i = 0x10; i < 0x19; i++)
                        {
                            if ((kfe = _target.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                newNode.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent;
                            }
                        }
                    }
                    AddChild(newNode);
                }
                else
                {
                    node._numFrames += oldCount;
                    for (int x = 0; x < _target.FrameCount; x++)
                    {
                        for (int i = 0x10; i < 0x19; i++)
                        {
                            if ((kfe = _target.GetKeyframe((KeyFrameMode)i, x)) != null)
                            {
                                node.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent;
                            }
                        }
                    }
                }
            }
        }
示例#9
0
        internal void ApplyCHR(CHR0Node node, int index)
        {
            //Transform bones
            if (_boneList != null)
            {
                foreach (MDL0BoneNode b in _boneList)
                {
                    b.ApplyCHR0(node, index);
                }
                foreach (MDL0BoneNode b in _boneList)
                {
                    b.RecalcFrameState();
                }
            }

            //Transform nodes
            //foreach (IMatrixProvider nr in _nodes)
            //    nr.CalcBase();
            //foreach (IMatrixProvider nr in _nodes)
            //    nr.CalcWeighted();

            foreach (Influence inf in _influences._influences)
            {
                inf.CalcMatrix();
            }

            if (_polyList != null)
            {
                foreach (MDL0PolygonNode poly in _polyList)
                {
                    poly.WeightVertices();
                }
            }

            //Weight vertices
            //if ((group = FindChild("Polygons", false)) != null)
            //    foreach (MDL0PolygonNode poly in group.Children)
            //        poly.WeightVertices(_nodes);
        }
示例#10
0
        internal void ApplyCHR0(CHR0Node node, int index)
        {
            CHR0EntryNode e;

            if ((node == null) || (index == 0)) //Reset to bind pose
            {
                _frameState = _bindState;
            }
            else if ((e = node.FindChild(Name, false) as CHR0EntryNode) != null) //Set to anim pose
            {
                _frameState = new FrameState(e.GetAnimFrame(index - 1));
            }
            else //Set to neutral pose
            {
                _frameState = _bindState;
            }

            foreach (MDL0BoneNode b in Children)
            {
                b.ApplyCHR0(node, index);
            }
        }
示例#11
0
        public static void Serialize(CHR0Node[] animations, float fps, bool bake, string outFile)
        {
            string[] types = new string[] { "scale", "rotate", "translate" };
            string[] axes = new string[] { "X", "Y", "Z" };
            bool first = true;

            using (FileStream stream = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 0x1000, FileOptions.SequentialScan))
            using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
            {
                writer.Flush();
                stream.Position = 0;

                writer.WriteStartDocument();
                writer.WriteStartElement("COLLADA", "http://www.collada.org/2008/03/COLLADASchema");
                writer.WriteAttributeString("version", "1.4.1");

                writer.WriteStartElement("asset");
                writer.WriteStartElement("contributor");
                writer.WriteElementString("authoring_tool", Application.ProductName);
                writer.WriteEndElement();
                writer.WriteEndElement();

                writer.WriteStartElement("library_animations");
                {
                    foreach (CHR0Node animation in animations)
                    {
                        string animName = animation.Name;

                        writer.WriteStartElement("animation");
                        writer.WriteAttributeString("name", animName);
                        writer.WriteAttributeString("id", animName);
                        {
                            foreach (CHR0EntryNode en in animation.Children)
                            {
                                string bone = en.Name;
                                KeyframeCollection keyframes = en.Keyframes;

                                for (int index = 0; index < 9; index++)
                                {
                                    KeyFrameMode mode = (KeyFrameMode)(index + 0x10);
                                    int keyFrameCount = keyframes[mode];

                                    if (keyFrameCount <= 0)
                                        continue;

                                    string type = types[index / 3];
                                    string axis = axes[index % 3];

                                    string name = String.Format("{0}_{1}{2}", bone, type, axis);

                                    //writer.WriteStartElement("animation");
                                    //writer.WriteAttributeString("id", name);
                                    {
                                        #region Input source
                                        writer.WriteStartElement("source");
                                        writer.WriteAttributeString("id", name + "_input");
                                        {
                                            writer.WriteStartElement("float_array");
                                            writer.WriteAttributeString("id", name + "_inputArr");
                                            writer.WriteAttributeString("count", keyFrameCount.ToString());
                                            {
                                                first = true;
                                                for (KeyframeEntry entry = keyframes._keyRoots[index]._next; (entry != keyframes._keyRoots[index]); entry = entry._next)
                                                {
                                                    if (first)
                                                        first = false;
                                                    else
                                                        writer.WriteString(" ");
                                                    writer.WriteString(((float)entry._index / fps).ToString(CultureInfo.InvariantCulture.NumberFormat));
                                                }
                                            }
                                            writer.WriteEndElement(); //float_array

                                            writer.WriteStartElement("technique_common");
                                            {
                                                writer.WriteStartElement("accessor");
                                                writer.WriteAttributeString("source", "#" + name + "_inputArr");
                                                writer.WriteAttributeString("count", keyFrameCount.ToString());
                                                writer.WriteAttributeString("stride", "1");
                                                {
                                                    writer.WriteStartElement("param");
                                                    writer.WriteAttributeString("name", "TIME");
                                                    writer.WriteAttributeString("type", "float");
                                                    writer.WriteEndElement(); //param
                                                }
                                                writer.WriteEndElement(); //accessor
                                            }
                                            writer.WriteEndElement(); //technique_common

                                            writer.WriteStartElement("technique");
                                            writer.WriteAttributeString("profile", "MAYA");
                                            {
                                                writer.WriteStartElement("pre_infinity");
                                                writer.WriteString("CONSTANT");
                                                writer.WriteEndElement(); //pre_infinity

                                                writer.WriteStartElement("post_infinity");
                                                writer.WriteString("CONSTANT");
                                                writer.WriteEndElement(); //post_infinity
                                            }
                                            writer.WriteEndElement(); //technique
                                        }
                                        writer.WriteEndElement(); //source
                                        #endregion

                                        #region Output source
                                        writer.WriteStartElement("source");
                                        writer.WriteAttributeString("id", name + "_output");
                                        {
                                            writer.WriteStartElement("float_array");
                                            writer.WriteAttributeString("id", name + "_outputArr");
                                            writer.WriteAttributeString("count", keyFrameCount.ToString());
                                            {
                                                first = true;
                                                for (KeyframeEntry entry = keyframes._keyRoots[index]._next; (entry != keyframes._keyRoots[index]); entry = entry._next)
                                                {
                                                    if (first)
                                                        first = false;
                                                    else
                                                        writer.WriteString(" ");
                                                    writer.WriteString(((float)entry._value).ToString(CultureInfo.InvariantCulture.NumberFormat));
                                                }
                                            }
                                            writer.WriteEndElement(); //float_array

                                            writer.WriteStartElement("technique_common");
                                            {
                                                writer.WriteStartElement("accessor");
                                                writer.WriteAttributeString("source", "#" + name + "_outputArr");
                                                writer.WriteAttributeString("count", keyFrameCount.ToString());
                                                writer.WriteAttributeString("stride", "1");
                                                {
                                                    writer.WriteStartElement("param");
                                                    writer.WriteAttributeString("name", "TRANSFORM");
                                                    writer.WriteAttributeString("type", "float");
                                                    writer.WriteEndElement(); //param
                                                }
                                                writer.WriteEndElement(); //accessor
                                            }
                                            writer.WriteEndElement(); //technique_common
                                        }
                                        writer.WriteEndElement(); //source
                                        #endregion

                                        #region In Tangent source
                                        writer.WriteStartElement("source");
                                        writer.WriteAttributeString("id", name + "_inTan");
                                        {
                                            writer.WriteStartElement("float_array");
                                            writer.WriteAttributeString("id", name + "_inTanArr");
                                            writer.WriteAttributeString("count", keyFrameCount.ToString());
                                            {
                                                first = true;
                                                for (KeyframeEntry entry = keyframes._keyRoots[index]._next; (entry != keyframes._keyRoots[index]); entry = entry._next)
                                                {
                                                    if (first)
                                                        first = false;
                                                    else
                                                        writer.WriteString(" ");
                                                    writer.WriteString(entry._tangent.ToString(CultureInfo.InvariantCulture.NumberFormat));
                                                }
                                            }
                                            writer.WriteEndElement(); //float_array

                                            writer.WriteStartElement("technique_common");
                                            {
                                                writer.WriteStartElement("accessor");
                                                writer.WriteAttributeString("source", "#" + name + "_inTanArr");
                                                writer.WriteAttributeString("count", keyFrameCount.ToString());
                                                writer.WriteAttributeString("stride", "1");
                                                {
                                                    writer.WriteStartElement("param");
                                                    writer.WriteAttributeString("name", "IN_TANGENT");
                                                    writer.WriteAttributeString("type", "float");
                                                    writer.WriteEndElement(); //param
                                                }
                                                writer.WriteEndElement(); //accessor
                                            }
                                            writer.WriteEndElement(); //technique_common
                                        }
                                        writer.WriteEndElement(); //source
                                        #endregion

                                        #region Out Tangent source
                                        writer.WriteStartElement("source");
                                        writer.WriteAttributeString("id", name + "_outTan");
                                        {
                                            writer.WriteStartElement("float_array");
                                            writer.WriteAttributeString("id", name + "_outTanArr");
                                            writer.WriteAttributeString("count", keyFrameCount.ToString());
                                            {
                                                first = true;
                                                for (KeyframeEntry entry = keyframes._keyRoots[index]._next; (entry != keyframes._keyRoots[index]); entry = entry._next)
                                                {
                                                    if (first)
                                                        first = false;
                                                    else
                                                        writer.WriteString(" ");
                                                    writer.WriteString(entry._tangent.ToString(CultureInfo.InvariantCulture.NumberFormat));
                                                }
                                            }
                                            writer.WriteEndElement(); //float_array

                                            writer.WriteStartElement("technique_common");
                                            {
                                                writer.WriteStartElement("accessor");
                                                writer.WriteAttributeString("source", "#" + name + "_outTanArr");
                                                writer.WriteAttributeString("count", keyFrameCount.ToString());
                                                writer.WriteAttributeString("stride", "1");
                                                {
                                                    writer.WriteStartElement("param");
                                                    writer.WriteAttributeString("name", "OUT_TANGENT");
                                                    writer.WriteAttributeString("type", "float");
                                                    writer.WriteEndElement(); //param
                                                }
                                                writer.WriteEndElement(); //accessor
                                            }
                                            writer.WriteEndElement(); //technique_common
                                        }
                                        writer.WriteEndElement(); //source
                                        #endregion

                                        #region Interpolation source
                                        writer.WriteStartElement("source");
                                        writer.WriteAttributeString("id", name + "_interp");
                                        {
                                            writer.WriteStartElement("Name_array");
                                            writer.WriteAttributeString("id", name + "_interpArr");
                                            writer.WriteAttributeString("count", keyFrameCount.ToString());
                                            {
                                                first = true;
                                                for (KeyframeEntry entry = keyframes._keyRoots[index]._next; (entry != keyframes._keyRoots[index]); entry = entry._next)
                                                {
                                                    if (first)
                                                        first = false;
                                                    else
                                                        writer.WriteString(" ");
                                                    writer.WriteString("HERMITE");
                                                }
                                            }
                                            writer.WriteEndElement(); //Name_array

                                            writer.WriteStartElement("technique_common");
                                            {
                                                writer.WriteStartElement("accessor");
                                                writer.WriteAttributeString("source", "#" + name + "_interpArr");
                                                writer.WriteAttributeString("count", keyFrameCount.ToString());
                                                writer.WriteAttributeString("stride", "1");
                                                {
                                                    writer.WriteStartElement("param");
                                                    writer.WriteAttributeString("name", "INTERPOLATION");
                                                    writer.WriteAttributeString("type", "Name");
                                                    writer.WriteEndElement(); //param
                                                }
                                                writer.WriteEndElement(); //accessor
                                            }
                                            writer.WriteEndElement(); //technique_common
                                        }
                                        writer.WriteEndElement(); //source
                                        #endregion

                                        #region Sampler
                                        writer.WriteStartElement("sampler");
                                        writer.WriteAttributeString("id", name + "_sampler");
                                        {
                                            writer.WriteStartElement("input");
                                            writer.WriteAttributeString("semantic", "INPUT");
                                            writer.WriteAttributeString("source", "#" + name + "_input");
                                            writer.WriteEndElement(); //input

                                            writer.WriteStartElement("input");
                                            writer.WriteAttributeString("semantic", "OUTPUT");
                                            writer.WriteAttributeString("source", "#" + name + "_output");
                                            writer.WriteEndElement(); //input

                                            writer.WriteStartElement("input");
                                            writer.WriteAttributeString("semantic", "IN_TANGENT");
                                            writer.WriteAttributeString("source", "#" + name + "_inTan");
                                            writer.WriteEndElement(); //input

                                            writer.WriteStartElement("input");
                                            writer.WriteAttributeString("semantic", "OUT_TANGEN");
                                            writer.WriteAttributeString("source", "#" + name + "_outTan");
                                            writer.WriteEndElement(); //input

                                            writer.WriteStartElement("input");
                                            writer.WriteAttributeString("semantic", "INTERPOLATION");
                                            writer.WriteAttributeString("source", "#" + name + "_interp");
                                            writer.WriteEndElement(); //input
                                        }
                                        writer.WriteEndElement(); //sampler
                                        #endregion

                                        writer.WriteStartElement("channel");
                                        writer.WriteAttributeString("source", "#" + name + "_sampler");
                                        writer.WriteAttributeString("target", String.Format("{0}/{1}.{2}", bone, type, axis));
                                        writer.WriteEndElement(); //channel
                                    }
                                    //writer.WriteEndElement(); //animation
                                }
                            }
                        }
                        writer.WriteEndElement(); //animation
                    }
                    writer.WriteEndElement(); //library_animations
                    writer.Close();
                }
            }
        }
示例#12
0
        public void MergeWith(CHR0Node external)
        {
            if (external.FrameCount != FrameCount && MessageBox.Show(null, "Frame counts are not equal; the shorter animation will end early. Do you still wish to continue?", "", MessageBoxButtons.YesNo) == DialogResult.No)
                return;

            if (external.FrameCount > FrameCount)
                FrameCount = external.FrameCount;

            foreach (CHR0EntryNode _extTarget in external.Children)
            {
                CHR0EntryNode node = null;
                KeyframeEntry kfe = null;

                CHR0EntryNode entry = new CHR0EntryNode() { Name = _extTarget.Name };
                entry._numFrames = _extTarget.FrameCount;

                //Apply all external keyframes to current entry.
                for (int x = 0; x < _extTarget.FrameCount; x++)
                    for (int i = 0x10; i < 0x19; i++)
                        if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null)
                            entry.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent;

                if ((node = FindChild(_extTarget.Name, false) as CHR0EntryNode) == null)
                    AddChild(entry, true);
                else
                {
                    DialogResult result = MessageBox.Show(null, "A bone entry with the name " + _extTarget.Name + " already exists.\nDo you want to rename this entry?\nOtherwise, you will have the option to merge the keyframes.", "Rename Entry?", MessageBoxButtons.YesNoCancel);
                    if (result == DialogResult.Yes)
                    {
                    Top:
                        RenameDialog d = new RenameDialog();
                        if (d.ShowDialog(null, entry) == DialogResult.OK)
                        {
                            if (entry.Name != _extTarget.Name)
                                AddChild(entry, true);
                            else
                            {
                                MessageBox.Show("The name wasn't changed!");
                                goto Top;
                            }
                        }
                    }
                    else if (result == DialogResult.No)
                    {
                        result = MessageBox.Show(null, "Do you want to merge the keyframes of the entries?", "Merge Keyframes?", MessageBoxButtons.YesNoCancel);
                        if (result == DialogResult.Yes)
                        {
                            KeyframeEntry kfe2 = null;

                            if (_extTarget.FrameCount > node.FrameCount)
                                node._numFrames = _extTarget.FrameCount;

                            //Merge all external keyframes with the current entry.
                            for (int x = 0; x < _extTarget.FrameCount; x++)
                                for (int i = 0x10; i < 0x19; i++)
                                    if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null)
                                        if ((kfe2 = node.GetKeyframe((KeyFrameMode)i, x)) == null)
                                            node.SetKeyframe((KeyFrameMode)i, x, kfe._value);
                                        else
                                        {
                                            result = MessageBox.Show(null, "A keyframe at frame " + x + " already exists.\nOld value: " + kfe2._value + "\nNew value:" + kfe._value + "\nReplace the old value with the new one?", "Replace Keyframe?", MessageBoxButtons.YesNoCancel);
                                            if (result == DialogResult.Yes)
                                                node.SetKeyframe((KeyFrameMode)i, x, kfe._value);
                                            else if (result == DialogResult.Cancel)
                                            {
                                                Restore();
                                                return;
                                            }
                                        }
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            Restore();
                            return;
                        }
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        Restore();
                        return;
                    }
                }
            }
        }
示例#13
0
        /// <summary>
        /// Adds an animation to the end of this one
        /// </summary>
        public void Append(CHR0Node external)
        {
            KeyframeEntry kfe;

            int origIntCount = FrameCount;
            int extCount = external.FrameCount;
            FrameCount += extCount;

            foreach (CHR0EntryNode _extEntry in external.Children)
            {
                CHR0EntryNode _intEntry = null;
                if ((_intEntry = (CHR0EntryNode)FindChild(_extEntry.Name, false)) == null)
                {
                    CHR0EntryNode newIntEntry = new CHR0EntryNode() { Name = _extEntry.Name };
                    newIntEntry._numFrames = _extEntry.FrameCount + origIntCount;
                    for (int x = 0; x < _extEntry.FrameCount; x++)
                        for (int i = 0x10; i < 0x19; i++)
                            if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null)
                                newIntEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent;
                    AddChild(newIntEntry);
                }
                else
                    for (int x = 0; x < _extEntry.FrameCount; x++)
                        for (int i = 0x10; i < 0x19; i++)
                            if ((kfe = _extEntry.GetKeyframe((KeyFrameMode)i, x)) != null)
                                _intEntry.Keyframes.SetFrameValue((KeyFrameMode)i, x + origIntCount, kfe._value)._tangent = kfe._tangent;
            }
        }
        public static CHR0Node Convert(string input)
        {
            try
            {
                CHR0Node chr0 = new CHR0Node();
                chr0.Name = Path.GetFileNameWithoutExtension(input);
                chr0.Loop = false;
                chr0.Version = 4;

                for (TextReader reader = new StreamReader(input); reader.Peek() != -1; )
                {
                    string line = reader.ReadLine();
                    if (line.CompareTo("Animation Keyframe Data Frames") == 0)
                    {
                        line = reader.ReadLine();

                        //Remove any non-digit characters
                        string justNumbers = new String(line.Where(Char.IsDigit).ToArray());
                        int keyFrameCount = int.Parse(justNumbers);
                        chr0.FrameCount = keyFrameCount;

                        for (line = reader.ReadLine(); line != null && line.CompareTo("End Of Animation Data") != 0; line = reader.ReadLine())
                        {
                            if (line.CompareTo("Keyframe Data") == 0)
                            {
                                CHR0EntryNode node = new CHR0EntryNode();
                                node.Name = reader.ReadLine();
                                node._numFrames = keyFrameCount;

                                Coords translation = new Coords();
                                Coords rotation = new Coords();
                                Coords scale = new Coords();

                                for (line = reader.ReadLine(); line != null && line.CompareTo("End of Keyframe Data") != 0; line = reader.ReadLine())
                                {
                                //Use goto to retry the loop without advancing the reader, when it returns from getCoords it will have the next line we need from it.
                                retry:
                                    if (line.CompareTo("Translation") == 0)
                                    {
                                        reader.ReadLine(); //Skip first blank line
                                        translation = getCoords(reader, out line);
                                        goto retry;
                                    }
                                    else if (line.CompareTo("Rotation") == 0)
                                    {
                                        reader.ReadLine(); //Skip first blank line
                                        rotation = getCoords(reader, out line);
                                        goto retry;
                                    }
                                    else if (line.CompareTo("Scale") == 0)
                                    {
                                        reader.ReadLine(); //Skip first blank line
                                        scale = getCoords(reader, out line);
                                        goto retry;
                                    }
                                    else if (line.CompareTo("End of Keyframe Data") == 0) //If line equals this now it's time to break
                                        break;
                                }
                                //Add frames to node
                                for (int frameCount = 0; translation.highestCount > frameCount || rotation.highestCount > frameCount || scale.highestCount > frameCount; frameCount++)
                                {
                                    if (translation.highestCount > frameCount)
                                    {
                                        if (translation.x.Count != 0 && frameCount < translation.x.Count)
                                            node.SetKeyframe(KeyFrameMode.TransX, frameCount, translation.x[frameCount]);
                                        if (translation.y.Count != 0 && frameCount < translation.y.Count)
                                            node.SetKeyframe(KeyFrameMode.TransY, frameCount, translation.y[frameCount]);
                                        if (translation.z.Count != 0 && frameCount < translation.z.Count)
                                            node.SetKeyframe(KeyFrameMode.TransZ, frameCount, translation.z[frameCount]);
                                    }
                                    if (rotation.highestCount > frameCount)
                                    {
                                        if (rotation.x.Count != 0 && frameCount < rotation.x.Count)
                                            node.SetKeyframe(KeyFrameMode.RotX, frameCount, rotation.x[frameCount]);
                                        if (rotation.y.Count != 0 && frameCount < rotation.y.Count)
                                            node.SetKeyframe(KeyFrameMode.RotY, frameCount, rotation.y[frameCount]);
                                        if (rotation.z.Count != 0 && frameCount < rotation.z.Count)
                                            node.SetKeyframe(KeyFrameMode.RotZ, frameCount, rotation.z[frameCount]);
                                    }
                                    if (scale.highestCount > frameCount)
                                    {
                                        if (scale.x.Count != 0 && frameCount < scale.x.Count)
                                            node.SetKeyframe(KeyFrameMode.ScaleX, frameCount, scale.x[frameCount]);
                                        if (scale.y.Count != 0 && frameCount < scale.y.Count)
                                            node.SetKeyframe(KeyFrameMode.ScaleY, frameCount, scale.y[frameCount]);
                                        if (scale.z.Count != 0 && frameCount < scale.z.Count)
                                            node.SetKeyframe(KeyFrameMode.ScaleZ, frameCount, scale.z[frameCount]);
                                    }
                                }
                                chr0.AddChild(node);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Not a valid CHR0 text file.");
                        return null;
                    }
                }
                return chr0;
            }
            catch (Exception e)
            {
                MessageBox.Show("There was a problem importing keyframes.\n\nError:\n" + e.ToString());
                return null;
            }
        }
示例#15
0
        public void ApplyCHR(CHR0Node node, int index)
        {
            //Transform bones
            if (_boneList != null)
            {
                foreach (MDL0BoneNode b in _boneList)
                    b.ApplyCHR0(node, index, CHR0EntryNode._linear);
                foreach (MDL0BoneNode b in _boneList)
                    b.RecalcFrameState();
            }

            //Transform nodes
            foreach (Influence inf in _influences._influences)
                inf.CalcMatrix();

            //Weight Vertices
            if (_objList != null)
                foreach (MDL0ObjectNode poly in _objList)
                    poly.WeightVertices();
        }
        internal void ApplyCHR0(CHR0Node node, int index, bool linear)
        {
            CHR0EntryNode e;

            _frameState = _bindState;

            if (node != null && index > 0 && (e = node.FindChild(Name, false) as CHR0EntryNode) != null) //Set to anim pose
                fixed (FrameState* v = &_frameState)
                {
                    float* f = (float*)v;
                    for (int i = 0; i < 9; i++)
                        if (e.Keyframes[(KeyFrameMode)(i + 0x10)] > 0)
                            f[i] = e.GetFrameValue((KeyFrameMode)(i + 0x10), index - 1, linear, node.Loop);

                    _frameState.CalcTransforms();
                }

            foreach (MDL0BoneNode b in Children)
                b.ApplyCHR0(node, index, linear);
        }
示例#17
0
        public void MergeWith(CHR0Node external)
        {
            if (external.FrameCount != FrameCount && MessageBox.Show(null, "Frame counts are not equal; the shorter animation will end early. Do you still wish to continue?", "", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            if (external.FrameCount > FrameCount)
            {
                FrameCount = external.FrameCount;
            }

            foreach (CHR0EntryNode _extTarget in external.Children)
            {
                CHR0EntryNode node = null;
                KeyframeEntry kfe  = null;

                CHR0EntryNode entry = new CHR0EntryNode()
                {
                    Name = _extTarget.Name
                };
                entry._numFrames = _extTarget.FrameCount;

                //Apply all external keyframes to current entry.
                for (int x = 0; x < _extTarget.FrameCount; x++)
                {
                    for (int i = 0x10; i < 0x19; i++)
                    {
                        if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null)
                        {
                            entry.Keyframes.SetFrameValue((KeyFrameMode)i, x, kfe._value)._tangent = kfe._tangent;
                        }
                    }
                }

                if ((node = FindChild(_extTarget.Name, false) as CHR0EntryNode) == null)
                {
                    AddChild(entry, true);
                }
                else
                {
                    DialogResult result = MessageBox.Show(null, "A bone entry with the name " + _extTarget.Name + " already exists.\nDo you want to rename this entry?\nOtherwise, you will have the option to merge the keyframes.", "Rename Entry?", MessageBoxButtons.YesNoCancel);
                    if (result == DialogResult.Yes)
                    {
Top:
                        RenameDialog d = new RenameDialog();
                        if (d.ShowDialog(null, entry) == DialogResult.OK)
                        {
                            if (entry.Name != _extTarget.Name)
                            {
                                AddChild(entry, true);
                            }
                            else
                            {
                                MessageBox.Show("The name wasn't changed!");
                                goto Top;
                            }
                        }
                    }
                    else if (result == DialogResult.No)
                    {
                        result = MessageBox.Show(null, "Do you want to merge the keyframes of the entries?", "Merge Keyframes?", MessageBoxButtons.YesNoCancel);
                        if (result == DialogResult.Yes)
                        {
                            KeyframeEntry kfe2 = null;

                            if (_extTarget.FrameCount > node.FrameCount)
                            {
                                node._numFrames = _extTarget.FrameCount;
                            }

                            //Merge all external keyframes with the current entry.
                            for (int x = 0; x < _extTarget.FrameCount; x++)
                            {
                                for (int i = 0x10; i < 0x19; i++)
                                {
                                    if ((kfe = _extTarget.GetKeyframe((KeyFrameMode)i, x)) != null)
                                    {
                                        if ((kfe2 = node.GetKeyframe((KeyFrameMode)i, x)) == null)
                                        {
                                            node.SetKeyframe((KeyFrameMode)i, x, kfe._value);
                                        }
                                        else
                                        {
                                            result = MessageBox.Show(null, "A keyframe at frame " + x + " already exists.\nOld value: " + kfe2._value + "\nNew value:" + kfe._value + "\nReplace the old value with the new one?", "Replace Keyframe?", MessageBoxButtons.YesNoCancel);
                                            if (result == DialogResult.Yes)
                                            {
                                                node.SetKeyframe((KeyFrameMode)i, x, kfe._value);
                                            }
                                            else if (result == DialogResult.Cancel)
                                            {
                                                Restore();
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            Restore();
                            return;
                        }
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        Restore();
                        return;
                    }
                }
            }
        }