Engines/FlatRedBallXNA/FlatRedBall.Content/ModelAnimation/X File/XModelImporter.cs
/// <summary>
///  Imports a key frame list associated with an animation channel
/// </summary>
/// <param name="keyType">The type of animation keys used by the current channel</param>
/// <returns>The list of key frames for the given key type in the current channel</returns>
Imports a key frame list associated with an animation channel
Imports a key frame list associated with an animation channel
private AnimationKeyframe[] ImportAnimationKey(out int keyType)
        {
            keyType = tokens.SkipName().NextInt();
            int numFrames = tokens.NextInt();
            AnimationKeyframe[] frames = new AnimationKeyframe[numFrames];
            double ticksPerMS = animTicksPerSecond == null ? DEFAULT_TICKS_PER_SECOND /1000.0 
                : (double)animTicksPerSecond / 1000.0;
            for (int i = 0; i < numFrames; i++)
            {
                TimeSpan time = new TimeSpan(0, 0, 0, 0,
                    (int)(tokens.NextInt() / ticksPerMS));
                int numKeys = tokens.NextInt();
                Matrix transform = new Matrix();
                if (numKeys == 16)
                    transform = tokens.NextMatrix();
                else if (numKeys == 4)
                {
                    Vector4 v = tokens.NextVector4();
                    Quaternion q = new Quaternion(
                        new Vector3(-v.Y,-v.Z,-v.W),
                        v.X);
                    transform = Matrix.CreateFromQuaternion(q);
                }
                else if (numKeys == 3)
                {
                    Vector3 v = tokens.NextVector3();
                    if (keyType == 1)
                    {
                        Matrix.CreateScale(ref v, out transform);
                    }
                    else
                    {
                        Matrix.CreateTranslation(ref v, out transform);
                    }
                }
                tokens.SkipToken();
                frames[i] = new AnimationKeyframe(time, transform);
            }
            tokens.SkipToken();
            return frames;
        }
private AnimationKeyframe [ ] ImportAnimationKey ( out int keyType ) { keyType = tokens . SkipName ( ) . NextInt ( ) ; int numFrames = tokens . NextInt ( ) ; AnimationKeyframe [ ] frames = new AnimationKeyframe [ numFrames ] ; double ticksPerMS = animTicksPerSecond == null ? DEFAULT_TICKS_PER_SECOND / 1000.0 : ( double ) animTicksPerSecond / 1000.0 ; for ( int i = 0 ; i < numFrames ; i ++ ) { TimeSpan time = new TimeSpan ( 0 , 0 , 0 , 0 , ( int ) ( tokens . NextInt ( ) / ticksPerMS ) ) ; int numKeys = tokens . NextInt ( ) ; Matrix transform = new Matrix ( ) ; if ( numKeys == 16 ) transform = tokens . NextMatrix ( ) ; else if ( numKeys == 4 ) { Vector4 v = tokens . NextVector4 ( ) ; Quaternion q = new Quaternion ( new Vector3 ( - v . Y , - v . Z , - v . W ) , v . X ) ; transform = Matrix . CreateFromQuaternion ( q ) ; } else if ( numKeys == 3 ) { Vector3 v = tokens . NextVector3 ( ) ; if ( keyType == 1 ) { Matrix . CreateScale ( ref v , out transform ) ; } else { Matrix . CreateTranslation ( ref v , out transform ) ; } } tokens . SkipToken ( ) ; frames [ i ] = new AnimationKeyframe ( time , transform ) ; } tokens . SkipToken ( ) ; return frames ; }
Imports a key frame list associated with an animation channel
Imports a key frame list associated with an animation channel
// These keys can be rotation (0),scale(1),translation(2), or matrix(3 or 4) keys. // Number of frames in channel // Find the ticks per millisecond that defines how fast the animation should go // fill in the frames // Create a timespan object that represents the time that the current keyframe // occurs // The number of keys that represents the transform for this keyframe.  // Quaternions (rotation keys) have 4, // Vectors (scale and translation) have 3, // Matrices have 16
The list of key frames for the given key type in the current channel
The list of key frames for the given key type in the current channel
int
out
keyType
The type of animation keys used by the current channel
The type of animation keys used by the current channel