Engines/FlatRedBallXNA/FlatRedBall.Content/ModelAnimation/ContentUtil.cs
/// <summary>
/// Merges scale, translation, and rotation keyframes into matrix keyframes.
/// </summary>
/// <param name="scale">The scale keyframes.</param>
/// <param name="translation">The translation keyframes.</param>
/// <param name="rotation">The rotation keyframes.</param>
/// <returns>The merged matrix keyframes.</returns>
Merges scale, translation, and rotation keyframes into matrix keyframes.
Merges scale translation and rotation keyframes into matrix keyframes .
public static List<AnimationKeyframe> MergeKeyFrames(AnimationKeyframe[] scale,
    AnimationKeyframe[] translation, AnimationKeyframe[] rotation)
        {
            if (scale == null)
            {
                scale = new AnimationKeyframe[] {new AnimationKeyframe(new TimeSpan(0),
                    Matrix.Identity)};
            }
            if (translation == null)
                throw new Exception("Animation data is not stored as matrices and " +
                    "has no translation component.");
            if (rotation == null)
                throw new Exception("Animation data is not stored as matrices and " +
                    "has no rotation component");
            InitializeFrames(ref scale);
            InitializeFrames(ref translation);
            InitializeFrames(ref rotation);
            SortedList<TimeSpan, object> keyframeTimes
                = new SortedList<TimeSpan, object>();
            foreach (AnimationKeyframe frame in scale)
                if (!keyframeTimes.ContainsKey(frame.Time))
                    keyframeTimes.Add(frame.Time, null);
            foreach (AnimationKeyframe frame in translation)
                if (!keyframeTimes.ContainsKey(frame.Time))
                    keyframeTimes.Add(frame.Time, null);
            foreach (AnimationKeyframe frame in rotation)
                if (!keyframeTimes.ContainsKey(frame.Time))
                    keyframeTimes.Add(frame.Time, null);
            IList<TimeSpan> times = keyframeTimes.Keys;
            Matrix[] newScales = new Matrix[keyframeTimes.Count];
            Matrix[] newTrans = new Matrix[keyframeTimes.Count];
            Matrix[] newRot = new Matrix[keyframeTimes.Count];
            List<AnimationKeyframe> returnFrames = new List<AnimationKeyframe>();
            InterpFrames(ref scale, ref newScales, times);
            InterpFrames(ref translation, ref newTrans, times);
            InterpFrames(ref rotation, ref newRot, times);
            for (int i = 0; i < times.Count; i++)
            {
                Matrix m = newRot[i];
                m = m * newTrans[i];
                m = newScales[i] * m;
                returnFrames.Add(new AnimationKeyframe(times[i], m));
            }
            return returnFrames;
        }
public static List < AnimationKeyframe > MergeKeyFrames ( AnimationKeyframe [ ] scale , AnimationKeyframe [ ] translation , AnimationKeyframe [ ] rotation ) { if ( scale == null ) { scale = new AnimationKeyframe [ ] { new AnimationKeyframe ( new TimeSpan ( 0 ) , Matrix . Identity ) } ; } if ( translation == null ) throw new Exception ( " " + " " ) ; if ( rotation == null ) throw new Exception ( " " + " " ) ; InitializeFrames ( ref scale ) ; InitializeFrames ( ref translation ) ; InitializeFrames ( ref rotation ) ; SortedList < TimeSpan , object > keyframeTimes = new SortedList < TimeSpan , object > ( ) ; foreach ( AnimationKeyframe frame in scale ) if ( ! keyframeTimes . ContainsKey ( frame . Time ) ) keyframeTimes . Add ( frame . Time , null ) ; foreach ( AnimationKeyframe frame in translation ) if ( ! keyframeTimes . ContainsKey ( frame . Time ) ) keyframeTimes . Add ( frame . Time , null ) ; foreach ( AnimationKeyframe frame in rotation ) if ( ! keyframeTimes . ContainsKey ( frame . Time ) ) keyframeTimes . Add ( frame . Time , null ) ; IList < TimeSpan > times = keyframeTimes . Keys ; Matrix [ ] newScales = new Matrix [ keyframeTimes . Count ] ; Matrix [ ] newTrans = new Matrix [ keyframeTimes . Count ] ; Matrix [ ] newRot = new Matrix [ keyframeTimes . Count ] ; List < AnimationKeyframe > returnFrames = new List < AnimationKeyframe > ( ) ; InterpFrames ( ref scale , ref newScales , times ) ; InterpFrames ( ref translation , ref newTrans , times ) ; InterpFrames ( ref rotation , ref newRot , times ) ; for ( int i = 0 ; i < times . Count ; i ++ ) { Matrix m = newRot [ i ] ; m = m * newTrans [ i ] ; m = newScales [ i ] * m ; returnFrames . Add ( new AnimationKeyframe ( times [ i ] , m ) ) ; } return returnFrames ; }
Merges scale, translation, and rotation keyframes into matrix keyframes.
Merges scale translation and rotation keyframes into matrix keyframes .
// Sort the frames by time and make sure they start at time 0 and // have length >= 1 // Get a sorted list of the timespans for all 3 keyframe types, // not counting duplicates // Allocate the interpolated frame matrices // Interpolate the frames based on the times // Merge the 3 keyframe types into one.
The merged matrix keyframes.
The merged matrix keyframes .
scale
AnimationKeyframe[]
The scale keyframes.
The scale keyframes .
translation
AnimationKeyframe[]
The translation keyframes.
The translation keyframes .
rotation
AnimationKeyframe[]
The rotation keyframes.
The rotation keyframes .