Represents an animation for a model.
Ejemplo n.º 1
0
        public float Weight = 1.0f; //For animation blending. All active animations should add up to 1 but won't break if it doesn't.

        #endregion Fields

        #region Constructors

        public VMAnimationState(Animation animation, bool backwards)
        {
            Anim = animation;

            if (backwards)
            {
                PlayingBackwards = true;
                CurrentFrame = Anim.NumFrames;
            }

            foreach (var motion in animation.Motions)
            {
                if (motion.TimeProperties == null) { continue; }

                foreach (var tp in motion.TimeProperties)
                {
                    foreach (var item in tp.Items)
                    {
                        TimePropertyLists.Add(item);
                    }
                }
            }

            /** Sort time property lists by time **/
            TimePropertyLists.Sort(new TimePropertyListItemSorter());
        }
Ejemplo n.º 2
0
 public virtual void Load(VMAnimationStateMarshal input)
 {
     Anim = FSO.Content.Content.Get().AvatarAnimations.Get(input.Anim + ".anim");
     CurrentFrame = input.CurrentFrame;
     EventCode = input.EventCode;
     EventFired = input.EventFired;
     EndReached = input.EndReached;
     PlayingBackwards = input.PlayingBackwards;
     Speed = input.Speed;
     Weight = input.Weight;
     Loop = input.Loop;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs an animation.
        /// </summary>
        /// <param name="avatar">The avatar to run animation for.</param>
        /// <param name="animation">The animation to run.</param>
        /// <returns>Handle to the animation run.</returns>
        public AnimationHandle RunAnimation(Avatar avatar, Animation animation)
        {
            var instance = new AnimationHandle(this);
            instance.Animation = animation;
            instance.Avatar = avatar;

            Animations.Add(instance);
            return instance;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renders an animation's frame.
        /// </summary>
        /// <param name="avatar">The avatar which the animation is run for.</param>
        /// <param name="animation">The animation.</param>
        /// <param name="frame">Frame number in animation.</param>
        /// <param name="fraction"></param>
        /// <param name="weight">The amount to apply this animation to the skeleton.</param>
        /// <returns>Status of animation.</returns>
        public static AnimationStatus RenderFrame(Avatar avatar, Animation animation, int frame, float fraction, float weight)
        {
            bool completed = (frame < 0 || frame > animation.NumFrames);
            frame = Math.Max(Math.Min(frame, animation.NumFrames), 0);

            var numDone = 0;

            foreach (var motion in animation.Motions)
            {
                var bone = avatar.Skeleton.GetBone(motion.BoneName);
                if (bone == null) continue; //fixes bugs with missing bones.. need to find out what R_FINGERPOLY0 is though.

                var motionFrame = frame;
                if (frame >= motion.FrameCount)
                {
                    numDone++;
                    motionFrame = (int)motion.FrameCount - 1;
                }

                if (motion.HasTranslation)
                {
                    Vector3 trans;
                    if (fraction >= 0)
                    {
                        var trans1 = animation.Translations[motion.FirstTranslationIndex + motionFrame];
                        var trans2 = (frame + 1 >= motion.FrameCount) ? trans1 : animation.Translations[motion.FirstTranslationIndex + motionFrame+1];
                        trans = Vector3.Lerp(trans1, trans2, fraction);
                    }
                    else
                    {
                        trans = animation.Translations[motion.FirstTranslationIndex + motionFrame];
                    }
                    if (weight == 1) bone.Translation = trans;
                    else bone.Translation = Vector3.Lerp(bone.Translation, trans, weight);
                }
                if (motion.HasRotation)
                {
                    Quaternion quat;
                    if (fraction >= 0)
                    {
                        var quat1 = animation.Rotations[motion.FirstRotationIndex + motionFrame];
                        var quat2 = (frame + 1 >= motion.FrameCount) ? quat1 : animation.Rotations[motion.FirstRotationIndex + motionFrame + 1];
                        quat = Quaternion.Slerp(quat1, quat2, fraction);
                    }
                    else
                    {
                        quat = animation.Rotations[motion.FirstRotationIndex + motionFrame];
                    }
                    if (weight == 1) bone.Rotation = quat;
                    else bone.Rotation = Quaternion.Slerp(bone.Rotation, quat, weight);
                }
            }

            if (completed || frame+1 > animation.NumFrames) return AnimationStatus.COMPLETED;
            return AnimationStatus.IN_PROGRESS;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Renders an animation's frame.
        /// </summary>
        /// <param name="avatar">The avatar which the animation is run for.</param>
        /// <param name="animation">The animation.</param>
        /// <param name="frame">Frame number in animation.</param>
        /// <param name="fraction"></param>
        /// <param name="weight">The amount to apply this animation to the skeleton.</param>
        /// <returns>Status of animation.</returns>
        public static AnimationStatus RenderFrame(Avatar avatar, Animation animation, int frame, float fraction, float weight)
        {
            bool completed = (frame <0 || frame> animation.NumFrames);

            frame = Math.Max(Math.Min(frame, animation.NumFrames), 0);

            var numDone = 0;

            foreach (var motion in animation.Motions)
            {
                var bone = avatar.Skeleton.GetBone(motion.BoneName);
                if (bone == null)
                {
                    continue;               //fixes bugs with missing bones.. need to find out what R_FINGERPOLY0 is though.
                }
                var motionFrame = frame;
                if (frame >= motion.FrameCount)
                {
                    numDone++;
                    motionFrame = (int)motion.FrameCount - 1;
                }

                if (motion.HasTranslation)
                {
                    Vector3 trans;
                    if (fraction >= 0)
                    {
                        var trans1 = animation.Translations[motion.FirstTranslationIndex + motionFrame];
                        var trans2 = (frame + 1 >= motion.FrameCount) ? trans1 : animation.Translations[motion.FirstTranslationIndex + motionFrame + 1];
                        trans = Vector3.Lerp(trans1, trans2, fraction);
                    }
                    else
                    {
                        trans = animation.Translations[motion.FirstTranslationIndex + motionFrame];
                    }
                    if (weight == 1)
                    {
                        bone.Translation = trans;
                    }
                    else
                    {
                        bone.Translation = Vector3.Lerp(bone.Translation, trans, weight);
                    }
                }
                if (motion.HasRotation)
                {
                    Quaternion quat;
                    if (fraction >= 0)
                    {
                        var quat1 = animation.Rotations[motion.FirstRotationIndex + motionFrame];
                        var quat2 = (frame + 1 >= motion.FrameCount) ? quat1 : animation.Rotations[motion.FirstRotationIndex + motionFrame + 1];
                        quat = Quaternion.Slerp(quat1, quat2, fraction);
                    }
                    else
                    {
                        quat = animation.Rotations[motion.FirstRotationIndex + motionFrame];
                    }
                    if (weight == 1)
                    {
                        bone.Rotation = quat;
                    }
                    else
                    {
                        bone.Rotation = Quaternion.Slerp(bone.Rotation, quat, weight);
                    }
                }
            }

            if (completed || frame + 1 > animation.NumFrames)
            {
                return(AnimationStatus.COMPLETED);
            }
            return(AnimationStatus.IN_PROGRESS);
        }