Example #1
0
        /// <summary>
        ///     Levanta la informacion de una animacion a partir del XML
        /// </summary>
        /// <param name="xmlString">Contenido que el XML</param>
        public TgcKeyFrameAnimationData parseAnimationFromString(string xmlString)
        {
            var dom = new XmlDocument();

            dom.LoadXml(xmlString);
            var root = dom.DocumentElement;

            var animation = new TgcKeyFrameAnimationData();

            //Parsear informacion general de animation
            var animationNode = (XmlElement)root.GetElementsByTagName("animation")[0];

            animation.name           = animationNode.Attributes["name"].InnerText;
            animation.verticesCount  = int.Parse(animationNode.Attributes["verticesCount"].InnerText);
            animation.framesCount    = int.Parse(animationNode.Attributes["framesCount"].InnerText);
            animation.keyFramesCount = int.Parse(animationNode.Attributes["keyFramesCount"].InnerText);
            animation.frameRate      = int.Parse(animationNode.Attributes["frameRate"].InnerText);
            animation.startFrame     = int.Parse(animationNode.Attributes["startFrame"].InnerText);
            animation.endFrame       = int.Parse(animationNode.Attributes["endFrame"].InnerText);

            //Parsear boundingBox, si esta
            var boundingBoxNodes = animationNode.GetElementsByTagName("boundingBox");

            if (boundingBoxNodes != null && boundingBoxNodes.Count == 1)
            {
                var boundingBoxNode = boundingBoxNodes[0];
                animation.pMin = TgcParserUtils.parseFloat3Array(boundingBoxNode.Attributes["min"].InnerText);
                animation.pMax = TgcParserUtils.parseFloat3Array(boundingBoxNode.Attributes["max"].InnerText);
            }

            var frameNodes = animationNode.GetElementsByTagName("frame");

            animation.keyFrames = new TgcKeyFrameFrameData[frameNodes.Count];
            var i = 0;

            foreach (XmlElement frameNode in frameNodes)
            {
                var frame       = new TgcKeyFrameFrameData();
                var frameNumber = (int)TgcParserUtils.parseFloat(frameNode.Attributes["time"].InnerText);
                frame.relativeTime = (float)frameNumber / animation.framesCount;

                //parsear vertices
                frame.verticesCoordinates = TgcParserUtils.parseFloatStream(frameNode.InnerText, animation.verticesCount);

                animation.keyFrames[i++] = frame;
            }

            return(animation);
        }
Example #2
0
        /// <summary>
        ///     Carga una animación a un modelo ya cargado, a partir de un objeto TgcKeyFrameAnimationData ya parseado
        ///     La animación se agrega al modelo.
        /// </summary>
        /// <param name="mesh">Modelo ya cargado</param>
        /// <param name="animationData">Objeto de animacion con datos ya cargados</param>
        public TgcKeyFrameAnimation loadAnimation(TgcKeyFrameMesh mesh, TgcKeyFrameAnimationData animationData)
        {
            //BoundingBox de la animación, aprovechar lo que viene en el XML o utilizar el de la malla estática
            TgcBoundingAxisAlignBox boundingBox = null;

            if (animationData.pMin != null && animationData.pMax != null)
            {
                boundingBox = new TgcBoundingAxisAlignBox(
                    TGCVector3.Float3ArrayToVector3(animationData.pMin),
                    TGCVector3.Float3ArrayToVector3(animationData.pMax));
            }
            else
            {
                boundingBox = mesh.BoundingBox;
            }

            var animation = new TgcKeyFrameAnimation(animationData, boundingBox);

            mesh.Animations.Add(animationData.name, animation);
            return(animation);
        }
 public TgcKeyFrameAnimation(TgcKeyFrameAnimationData data, TgcBoundingAxisAlignBox boundingBox)
 {
     Data        = data;
     BoundingBox = boundingBox;
 }