Esempio n. 1
0
        protected virtual int ReduceKeyframes(Keyframe[] frames, float tolerance)
        {
#if DEBUG
            if (frames == null)
            {
                throw new ArgumentNullException("frames");
            }
#endif
            int      nReduced  = 0;
            Keyframe lerp      = new Keyframe();
            int      nFrames   = frames.Length;
            int      prevFrame = 0;
            Keyframe prevData  = frames[0];
            for (int curFrame = 1; curFrame < nFrames - 1; ++curFrame)
            {
                Keyframe curData   = frames[curFrame];
                int      nextFrame = curFrame + 1;
                Keyframe nextData  = frames[nextFrame];
                Keyframe.Interpolate(prevData, nextData,
                                     (float)(curFrame - prevFrame) / (float)(nextFrame - prevFrame),
                                     lerp);
                if (lerp.DifferenceFrom(curData) < tolerance)
                {
                    frames[curFrame] = null;
                    ++nReduced;
                }
                else
                {
                    prevFrame = curFrame;
                    prevData  = curData;
                }
            }
            return(nReduced);
        }
Esempio n. 2
0
        /// <summary>
        /// Given the animation tracks in the dictionary (for an animation with the given
        /// name), figure out what the latest frame is that contains unique data for any
        /// track, and trim the animation from the end to that length.
        /// </summary>
        /// <param name="name">name of the animation to trim</param>
        /// <param name="tracks">the tracks of the animation to trim</param>
        /// <param name="context">for logging etc</param>
        protected virtual void TrimAnimationTracks(string name, AnimationTrackDictionary tracks,
                                                   ContentProcessorContext context)
        {
            int latestUnique = 1;
            int latestFrame  = 0;

            foreach (AnimationTrack at in tracks.Values)
            {
                Keyframe last          = at.Keyframes[0];
                int      latestCurrent = 0;
                int      index         = 0;
                if (at.NumFrames > latestFrame)
                {
                    latestFrame = at.NumFrames;
                }
                foreach (Keyframe kf in at.Keyframes)
                {
                    if (kf != null && last.DifferenceFrom(kf) >= tolerance_)
                    {
                        latestCurrent = index;
                        last          = kf;
                    }
                    ++index;
                }
                if (latestCurrent > latestUnique)
                {
                    latestUnique = latestCurrent;
                }
            }
            if (latestUnique + 1 < latestFrame)
            {
                context.Logger.LogMessage("Trimming animation {0} from {1} to {2} frames.",
                                          name, latestFrame, latestUnique + 1);
                foreach (AnimationTrack at in tracks.Values)
                {
                    at.ChopToLength(latestUnique + 1);
                }
            }
        }
Esempio n. 3
0
 protected virtual int ReduceKeyframes(Keyframe[] frames, float tolerance)
 {
     #if DEBUG
       if (frames == null)
     throw new ArgumentNullException("frames");
     #endif
       int nReduced = 0;
       Keyframe lerp = new Keyframe();
       int nFrames = frames.Length;
       int prevFrame = 0;
       Keyframe prevData = frames[0];
       for (int curFrame = 1; curFrame < nFrames-1; ++curFrame)
       {
     Keyframe curData = frames[curFrame];
     int nextFrame = curFrame+1;
     Keyframe nextData = frames[nextFrame];
     Keyframe.Interpolate(prevData, nextData,
     (float)(curFrame - prevFrame)/(float)(nextFrame - prevFrame),
     lerp);
     if (lerp.DifferenceFrom(curData) < tolerance)
     {
       frames[curFrame] = null;
       ++nReduced;
     }
     else
     {
       prevFrame = curFrame;
       prevData = curData;
     }
       }
       return nReduced;
 }