Example #1
0
        // <Animation name="Take 001" trackcount="60" framecount="61" duration="1.199999928" dtime="4">
        /// <summary>
        ///
        /// </summary>
        /// <param name="xAnimation"></param>
        /// <returns></returns>
        public static EZMAnimation Parse(System.Xml.Linq.XElement xElement)
        {
            EZMAnimation result = null;

            if (xElement.Name == "Animation")
            {
                result = new EZMAnimation();
                {
                    var xAttr = xElement.Attribute("name");
                    if (xAttr != null)
                    {
                        result.Name = xAttr.Value;
                    }
                }
                {
                    var xAttr = xElement.Attribute("trackcount");
                    if (xAttr != null)
                    {
                        result.TrackCount = int.Parse(xAttr.Value);
                    }
                }
                {
                    var xAttr = xElement.Attribute("framecount");
                    if (xAttr != null)
                    {
                        result.FrameCount = int.Parse(xAttr.Value);
                    }
                }
                {
                    var xAttr = xElement.Attribute("duration");
                    if (xAttr != null)
                    {
                        result.duration = float.Parse(xAttr.Value);
                    }
                }
                {
                    var xAttr = xElement.Attribute("dtime");
                    if (xAttr != null)
                    {
                        result.dtime = float.Parse(xAttr.Value);
                    }
                }
                {
                    var xAnimTracks = xElement.Elements("AnimTrack");
                    var animTracks  = new EZMAnimTrack[xAnimTracks.Count()];
                    int index       = 0;
                    foreach (var xAnimTrack in xAnimTracks)
                    {
                        animTracks[index++] = EZMAnimTrack.Parse(xAnimTrack);
                    }
                    result.AnimTracks = animTracks;
                }
            }

            return(result);
        }
Example #2
0
        private static AiAnimation Parse(EZMAnimation ezmAnimation)
        {
            var aiAnimation = new AiAnimation();

            aiAnimation.Name = ezmAnimation.Name;

            /*
             * double ticksPerSecond = aiScene.Animations[0].TicksPerSecond;
             * if (ticksPerSecond == 0) { ticksPerSecond = 25.0; }
             * double timeInTicks = TimeInSeconds * ticksPerSecond;
             * float animationTime = (float)(timeInTicks % aiScene.Animations[0].DurationInTicks);
             */
            /*
             * DateTime now = DateTime.Now;
             *  var deltaTime = now.Subtract(this.lastTime).TotalSeconds;
             *  float frameDuration = animation.duration / animation.FrameCount;
             *  if (deltaTime + passedTime > frameDuration)
             *  {
             *      this.currentFrame = (this.currentFrame + 1) % animation.FrameCount;
             *      passedTime = deltaTime - frameDuration;
             *  }
             *  this.lastTime = now;*/
            float durationInSeconds = ezmAnimation.duration;

            aiAnimation.TicksPerSecond  = 1;
            aiAnimation.DurationInTicks = ezmAnimation.duration;
            // nothing to do with ezmAnimation.dtime...
            int trackCount = ezmAnimation.TrackCount;
            var channels   = new AiNodeAnimationChannel[trackCount];

            for (int i = 0; i < trackCount; i++)
            {
                var            channel     = new AiNodeAnimationChannel();
                EZMAnimTrack   track       = ezmAnimation.AnimTracks[i];
                EZMBoneState[] states      = track.States;
                int            stateCount  = states.Length;
                var            positions   = new VectorKey[stateCount];
                var            quaternions = new QuaternionKey[stateCount];
                var            scalings    = new VectorKey[stateCount];
                for (int t = 0; t < stateCount; t++)
                {
                    EZMBoneState state = states[t];
                    positions[i]   = new VectorKey(0, state.position);
                    quaternions[i] = new QuaternionKey(0, state.orientation);
                    scalings[i]    = new VectorKey(0, state.scale);
                }
                channel.PositionKeys   = positions;
                channel.QuaternionKeys = quaternions;
                channel.ScalingKeys    = scalings;
                channels[i]            = channel;
            }
            aiAnimation.NodeAnimationChannels = channels;

            return(aiAnimation);
        }
Example #3
0
        // <AnimTrack name="RootNode" count="61" has_scale="true">
        /// <summary>
        /// Tracks a bone's states of all frames in one pose.
        /// </summary>
        /// <param name="xAnimTrack"></param>
        /// <returns></returns>
        public static EZMAnimTrack Parse(System.Xml.Linq.XElement xElement)
        {
            EZMAnimTrack result = null;

            if (xElement.Name == "AnimTrack")
            {
                result = new EZMAnimTrack();
                {
                    var name = xElement.Attribute("name");
                    if (name != null)
                    {
                        result.BoneName = name.Value;
                    }
                }
                int  count    = 0;
                bool hasScale = false;
                {
                    var c = xElement.Attribute("count");
                    if (c != null)
                    {
                        count = int.Parse(c.Value);
                    }
                    var h = xElement.Attribute("has_scale");
                    if (h != null)
                    {
                        hasScale = bool.Parse(h.Value);
                    }
                }
                {
                    string[] parts = xElement.Value.Split(Separator.separators, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length % 10 != 0)
                    {
                        throw new Exception("Parsing failed.");
                    }
                    var  values = new float[parts.Length];
                    var  states = new EZMBoneState[parts.Length / 10];
                    int  index = 0;
                    vec3 p = new vec3(); Quaternion o = new Quaternion(); vec3 s = new vec3();
                    while (index < parts.Length)
                    {
                        {
                            var x = float.Parse(parts[index++]);
                            var y = float.Parse(parts[index++]);
                            var z = float.Parse(parts[index++]);
                            p = new vec3(x, y, z);
                        }
                        {
                            var x = float.Parse(parts[index++]);
                            var y = float.Parse(parts[index++]);
                            var z = float.Parse(parts[index++]);
                            var w = float.Parse(parts[index++]);
                            o = new Quaternion(x, y, z, w);
                        }
                        {
                            var x = float.Parse(parts[index++]);
                            var y = float.Parse(parts[index++]);
                            var z = float.Parse(parts[index++]);
                            s = new vec3(x, y, z);
                        }

                        states[index / 10 - 1] = new EZMBoneState(p, o, s);
                    }
                    result.States = states;
                }
            }

            return(result);
        }