Engines/FlatRedBallXNA/FlatRedBall.Content/ModelAnimation/AsfAmc/AmcImporter.cs
/// <summary>
/// Imports Acclaim AMC (motion capture data).
/// For a foo_bar.amc, expects skeleton in a file named foo.asf.
/// Returns a skeleton with Animations in root bone. 
/// </summary>
Imports Acclaim AMC (motion capture data).
For a foo_bar.amc, expects skeleton in a file named foo.asf.
Returns a skeleton with Animations in root bone.
Imports Acclaim AMC ( motion capture data ) . For a foo_bar . amc expects skeleton in a file named foo . asf . Returns a skeleton with Animations in root bone .
public override BoneContent Import(string filename, ContentImporterContext context)
        {
            this.context = context;
            contentId = new ContentIdentity(filename, GetType().ToString());
            reader = new StreamReader(filename);
            AnimationContent animation = new AnimationContent();
            animation.Name = Path.GetFileNameWithoutExtension(filename);
            animation.Identity = contentId;
            string dir=Path.GetDirectoryName(filename);
            string asfFilename=animation.Name+".asf";
            if (animation.Name.Contains("_"))
            {
            }
            asfFilename = dir+@"\"+asfFilename;
            context.Logger.LogWarning("", contentId, "using skeleton from {0}", asfFilename);
            AsfImporter asfImporter = new AsfImporter();
            BoneContent root = asfImporter.Import(asfFilename, context);
            bones = asfImporter.Bones;
            int frameNumber = 1;
            int maxFrameNumber = 0;
            string line;
            animation.Channels.Add("root", new AnimationChannel());
            while ((line = readLine()) != null)
            {
                if (line[0]!='#' && line[0]!=':')
                {
                    int fn = 0;
                    if (int.TryParse(line, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out fn))
                    {
                        ++frameNumber;
                        maxFrameNumber = System.Math.Max(frameNumber, maxFrameNumber);
                        TimeSpan time = TimeSpan.FromTicks(frameNumber * ticksPerFrame);
                        animation.Channels["root"].Add(new AnimationKeyframe(time, Matrix.Identity));
                    }
                    else
                    {
                        string[] s=line.Split(' ');
                        string bone = s[0];
                        if (!animation.Channels.ContainsKey(bone))
                        {
                            animation.Channels.Add(bone, new AnimationChannel());
                        }
                        AnimationChannel channel = animation.Channels[bone];
                        AnimationKeyframe keyframe = importKeyframe(s, frameNumber);
                        if (keyframe!=null) 
                            channel.Add(keyframe);
                    }
                }
            }
            animation.Duration = TimeSpan.FromTicks(maxFrameNumber * ticksPerFrame);
            context.Logger.LogImportantMessage("imported {0} animation frames for {1} bones", 
                maxFrameNumber, animation.Channels.Count);
            root.Animations.Add(animation.Name, animation);
            return root;
        }
public override BoneContent Import ( string filename , ContentImporterContext context ) { this . context = context ; contentId = new ContentIdentity ( filename , GetType ( ) . ToString ( ) ) ; reader = new StreamReader ( filename ) ; AnimationContent animation = new AnimationContent ( ) ; animation . Name = Path . GetFileNameWithoutExtension ( filename ) ; animation . Identity = contentId ; string dir = Path . GetDirectoryName ( filename ) ; string asfFilename = animation . Name + " " ; if ( animation . Name . Contains ( " " ) ) { } asfFilename = dir + @"\" + asfFilename ; context . Logger . LogWarning ( " " , contentId , " " , asfFilename ) ; AsfImporter asfImporter = new AsfImporter ( ) ; BoneContent root = asfImporter . Import ( asfFilename , context ) ; bones = asfImporter . Bones ; int frameNumber = 1 ; int maxFrameNumber = 0 ; string line ; animation . Channels . Add ( " " , new AnimationChannel ( ) ) ; while ( ( line = readLine ( ) ) != null ) { if ( line [ 0 ] != ' ' && line [ 0 ] != ' ' ) { int fn = 0 ; if ( int . TryParse ( line , NumberStyles . Float , CultureInfo . InvariantCulture . NumberFormat , out fn ) ) { ++ frameNumber ; maxFrameNumber = System . Math . Max ( frameNumber , maxFrameNumber ) ; TimeSpan time = TimeSpan . FromTicks ( frameNumber * ticksPerFrame ) ; animation . Channels [ " " ] . Add ( new AnimationKeyframe ( time , Matrix . Identity ) ) ; } else { string [ ] s = line . Split ( ' ' ) ; string bone = s [ 0 ] ; if ( ! animation . Channels . ContainsKey ( bone ) ) { animation . Channels . Add ( bone , new AnimationChannel ( ) ) ; } AnimationChannel channel = animation . Channels [ bone ] ; AnimationKeyframe keyframe = importKeyframe ( s , frameNumber ) ; if ( keyframe != null ) channel . Add ( keyframe ) ; } } } animation . Duration = TimeSpan . FromTicks ( maxFrameNumber * ticksPerFrame ) ; context . Logger . LogImportantMessage ( " " , maxFrameNumber , animation . Channels . Count ) ; root . Animations . Add ( animation . Name , animation ) ; return root ; }
Imports Acclaim AMC (motion capture data).
Imports Acclaim AMC ( motion capture data ) .
//asfFilename = animation.Name.Split('_')[0] + ".asf"; // = int.Parse(line, NumberStyles.Int, CultureInfo.InvariantCulture.NumberFormat);
filename
string
context
ContentImporterContext