Пример #1
0
        public static void SaveMatrixAnimationData(ColladaAnimationData data, string SourceFilePath, string DestFilePath)
        {
            int totalFrameCount = data.frameTimelapse.Count;

            XmlDocument colladaDocument = new XmlDocument();

            colladaDocument.Load(SourceFilePath);

            if (colladaDocument.DocumentElement == null)
            {
                // TODO: Return if document not found, gracefully.
                return;
            }

            XmlNode root = colladaDocument.DocumentElement;
            XmlNode library_animation = colladaDocument.CreateElement("library_animations");

            root.AppendChild(library_animation);

            for (int i = 0; i < data.joints.Count; i++)
            {
                XmlNode animationParent = colladaDocument.CreateElement("animation");
                library_animation.AppendChild(animationParent);

                XmlAttribute animationParentIdAttribute = colladaDocument.CreateAttribute("id");
                animationParentIdAttribute.Value = string.Format("{0}-anim", data.joints[i]);
                animationParent.Attributes.Append(animationParentIdAttribute);
                XmlAttribute animationParentNameAttribute = colladaDocument.CreateAttribute("name");
                animationParentNameAttribute.Value = data.joints[i];
                animationParent.Attributes.Append(animationParentNameAttribute);

                XmlNode animationChild = colladaDocument.CreateElement("animation");
                animationParent.AppendChild(animationChild);

                // Add input source node
                XmlNode sourceInput = createInputSourceElement(colladaDocument, data.joints[i], totalFrameCount, data.frameTimelapse);
                animationChild.AppendChild(sourceInput);

                // Add output source node
                XmlNode sourceOutput = createOutputSourceElement(colladaDocument, data.joints[i], totalFrameCount, data.jointValues[data.joints[i]]);
                animationChild.AppendChild(sourceOutput);

                // Add interp source node
                XmlNode sourceInterp = createInterpolationsSourceElement(colladaDocument, data.joints[i], totalFrameCount, "LINEAR");
                animationChild.AppendChild(sourceInterp);

                // Add sampler node
                XmlNode sampler = createSamplerElement(colladaDocument, data.joints[i]);
                animationChild.AppendChild(sampler);

                // Add channel node
                XmlNode channel = createChannelElement(colladaDocument, data.joints[i]);
                animationChild.AppendChild(channel);
            }

            colladaDocument.Save(DestFilePath);
        }
Пример #2
0
 /// <summary>
 /// Save the animation Data
 /// </summary>
 public static void SaveAnimationData(ColladaAnimationData data, string SourceFilePath, string DestFilePath, bool isMatrix)
 {
     if (isMatrix)
     {
         SaveMatrixAnimationData(data, SourceFilePath, DestFilePath);
     }
     else
     {
         SaveComponentAnimationData(data, SourceFilePath, DestFilePath);
     }
 }
Пример #3
0
        public static void SaveComponentAnimationData(ColladaAnimationData data, string SourceFilePath, string DestFilePath)
        {
            int         totalFrameCount = data.frameTimelapse.Count;
            XmlDocument colladaDocument = new XmlDocument();

            colladaDocument.Load(SourceFilePath);

            if (colladaDocument.DocumentElement == null)
            {
                // TODO: Return if document not found, gracefully.
                return;
            }

            XmlNode root = colladaDocument.DocumentElement;
            XmlNode library_animation = colladaDocument.CreateElement("library_animations");

            root.AppendChild(library_animation);

            foreach (string jointId in data.joints)
            {
                for (int j = 0; j < 6; j++)
                {
                    string values = data.jointTranslateX[jointId];
                    string prefix = "translate.X";
                    if (j == 1)
                    {
                        prefix = "translate.Y";
                        values = data.jointTranslateY[jointId];
                    }
                    else if (j == 2)
                    {
                        prefix = "translate.Z";
                        values = data.jointTranslateZ[jointId];
                    }
                    else if (j == 3)
                    {
                        prefix = "rotateX.ANGLE";
                        values = data.jointRotateX[jointId];
                    }
                    else if (j == 4)
                    {
                        prefix = "rotateY.ANGLE";
                        values = data.jointRotateY[jointId];
                    }
                    else if (j == 5)
                    {
                        prefix = "rotateZ.ANGLE";
                        values = data.jointRotateZ[jointId];
                    }
                    XmlNode animationChild = colladaDocument.CreateElement("animation");
                    library_animation.AppendChild(animationChild);

                    // Add input source node
                    XmlNode sourceInput = createComponentInputSourceElement(colladaDocument, jointId, totalFrameCount, data.frameTimelapse, prefix);
                    animationChild.AppendChild(sourceInput);

                    // Add output source node
                    XmlNode sourceOutput = createComponentOutputSourceElement(colladaDocument, jointId, totalFrameCount, values, prefix);
                    animationChild.AppendChild(sourceOutput);

                    // Add interp source node
                    XmlNode sourceInterp = createComponentInterpolationsSourceElement(colladaDocument, jointId, totalFrameCount, "LINEAR", prefix);
                    animationChild.AppendChild(sourceInterp);

                    // Add intan node?
                    // Add out-tan node?

                    // Add sampler node
                    XmlNode sampler = createComponentSamplerElement(colladaDocument, jointId, prefix);
                    animationChild.AppendChild(sampler);

                    // Add channel node
                    XmlNode channel = createComponentChannelElement(colladaDocument, jointId, prefix);
                    animationChild.AppendChild(channel);
                }
            }

            colladaDocument.Save(DestFilePath);
        }