Engines/FlatRedBallXNA/FlatRedBall.Content/ModelAnimation/X File/XModelImporter.cs
/// <summary>
/// Fills in all the channels of an animation.  Each channel refers to 
/// a single bone's role in the animation.
/// </summary>
/// <param name="boneName">The name of the bone associated with the channel</param>
/// <returns>The imported animation channel</returns>
Fills in all the channels of an animation.  Each channel refers to
a single bone's role in the animation.
Fills in all the channels of an animation . Each channel refers to a single bone ' s role in the animation .
private AnimationChannel ImportAnimationChannel(out string boneName)
        {
            AnimationChannel anim = new AnimationChannel();
            AnimationKeyframe[] rotFrames = null;
            AnimationKeyframe[] transFrames = null;
            AnimationKeyframe[] scaleFrames = null;
            List<AnimationKeyframe> matrixFrames = null;
            boneName = null;
            tokens.SkipName();
            for (string next = tokens.NextToken(); next != "}"; next = tokens.NextToken())
            {
                if (next == "AnimationKey")
                {
                    int keyType;
                    AnimationKeyframe[] frames = ImportAnimationKey(out keyType);
                    if (keyType == 0)
                        rotFrames = frames;
                    else if (keyType == 1)
                        scaleFrames = frames;
                    else if (keyType == 2)
                        transFrames = frames;
                    else
                        matrixFrames = new List<AnimationKeyframe>(frames);
                }
                else if (next == "{")
                {
                    string token = tokens.NextToken();
                    if (tokens.NextToken() != "}")
                        tokens.SkipNode();
                    else
                        boneName = token;
                }
            }
            if (matrixFrames != null)
            {
                matrixFrames.Sort(new Comparison<AnimationKeyframe>(delegate(AnimationKeyframe one,
                    AnimationKeyframe two)
                    {
                        return one.Time.CompareTo(two.Time);
                    }));
                if (matrixFrames[0].Time != TimeSpan.Zero)
                    matrixFrames.Insert(0, new AnimationKeyframe(new TimeSpan(),
                        matrixFrames[0].Transform));
                for (int i = 0; i < matrixFrames.Count; i++)
                {
                    Matrix m = matrixFrames[i].Transform;
                    ContentUtil.ReflectMatrix(ref m);
                    matrixFrames[i].Transform = m;
                    anim.Add(matrixFrames[i]);
                }
            }
            else
            {
                List<AnimationKeyframe> combinedFrames = ContentUtil.MergeKeyFrames(
                    scaleFrames, transFrames, rotFrames);
                for (int i = 0; i < combinedFrames.Count; i++)
                {
                    Matrix m = combinedFrames[i].Transform;
                    ContentUtil.ReflectMatrix(ref m);
                    combinedFrames[i].Transform = m; 
                    anim.Add(combinedFrames[i]);
                }
            }
            return anim;
        }
private AnimationChannel ImportAnimationChannel ( out string boneName ) { AnimationChannel anim = new AnimationChannel ( ) ; AnimationKeyframe [ ] rotFrames = null ; AnimationKeyframe [ ] transFrames = null ; AnimationKeyframe [ ] scaleFrames = null ; List < AnimationKeyframe > matrixFrames = null ; boneName = null ; tokens . SkipName ( ) ; for ( string next = tokens . NextToken ( ) ; next != " " ; next = tokens . NextToken ( ) ) { if ( next == " " ) { int keyType ; AnimationKeyframe [ ] frames = ImportAnimationKey ( out keyType ) ; if ( keyType == 0 ) rotFrames = frames ; else if ( keyType == 1 ) scaleFrames = frames ; else if ( keyType == 2 ) transFrames = frames ; else matrixFrames = new List < AnimationKeyframe > ( frames ) ; } else if ( next == " " ) { string token = tokens . NextToken ( ) ; if ( tokens . NextToken ( ) != " " ) tokens . SkipNode ( ) ; else boneName = token ; } } if ( matrixFrames != null ) { matrixFrames . Sort ( new Comparison < AnimationKeyframe > ( delegate ( AnimationKeyframe one , AnimationKeyframe two ) { return one . Time . CompareTo ( two . Time ) ; } ) ) ; if ( matrixFrames [ 0 ] . Time != TimeSpan . Zero ) matrixFrames . Insert ( 0 , new AnimationKeyframe ( new TimeSpan ( ) , matrixFrames [ 0 ] . Transform ) ) ; for ( int i = 0 ; i < matrixFrames . Count ; i ++ ) { Matrix m = matrixFrames [ i ] . Transform ; ContentUtil . ReflectMatrix ( ref m ) ; matrixFrames [ i ] . Transform = m ; anim . Add ( matrixFrames [ i ] ) ; } } else { List < AnimationKeyframe > combinedFrames = ContentUtil . MergeKeyFrames ( scaleFrames , transFrames , rotFrames ) ; for ( int i = 0 ; i < combinedFrames . Count ; i ++ ) { Matrix m = combinedFrames [ i ] . Transform ; ContentUtil . ReflectMatrix ( ref m ) ; combinedFrames [ i ] . Transform = m ; anim . Add ( combinedFrames [ i ] ) ; } } return anim ; }
Fills in all the channels of an animation.
Fills in all the channels of an animation .
// Store the frames in an array, which acts as an intermediate data set // This will allow us to more easily provide support for non Matrix // animation keys at a later time // A set of animation keys // These keys can be rotation (0),scale(1),translation(2), or matrix(3 or 4) keys. // A possible bone name // Fill in the channel with the frames //* Matrix.CreateRotationX(MathHelper.PiOver2);
The imported animation channel
The imported animation channel
string
out
boneName
The name of the bone associated with the channel
The name of the bone associated with the channel