Exemplo n.º 1
0
        //
        public AnimationInstance(Animation anim)
        {
            animation_ = anim;
            frameRate_ = anim.FrameRate;
            //  The time of the last frame is less than the duration of the animation,
            //  as the last frame has some duration itself.
            lastFrameTime_ = (anim.NumFrames - 1) / frameRate_;
            invFrameRate_  = 1.0f / frameRate_;
            duration_      = anim.NumFrames * invFrameRate_;
            int max = 0;

            //  calculate max bone index
            //  todo: do in content pipeline
            foreach (KeyValuePair <int, AnimationTrack> kvp in anim.Tracks)
            {
                if (kvp.Key >= max)
                {
                    max = kvp.Key + 1;
                }
            }
            //  Allocate animation keyframes (for lerping between times).
            keyframes_ = new Keyframe[max];
            //  Load all the tracks (one track per bone).
            tracks_ = new AnimationTrack[max];
            foreach (int i in anim.Tracks.Keys)
            {
                keyframes_[i] = new Keyframe();
                tracks_[i]    = anim.Tracks[i];
            }
        }
Exemplo n.º 2
0
        protected override AnimationTrackDictionary Read(ContentReader input, AnimationTrackDictionary existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new AnimationTrackDictionary();
            }
            int num = input.ReadInt32();

            for (int i = 0; i != num; ++i)
            {
                int            index = input.ReadInt32();
                AnimationTrack track = input.ReadObject <AnimationTrack>();
                existingInstance.Add(index, track);
            }
            return(existingInstance);
        }