示例#1
0
        void LoadAnimations()
        {
            //  clear current state
            curAnimationInstance_ = -1;
            instances_            = null;
            blended_ = null;

            //  get the list of animations from our dictionary
            Dictionary <string, object> tag = loadedModel_.Model.Tag as Dictionary <string, object>;
            object aobj = null;

            if (tag != null)
            {
                tag.TryGetValue("AnimationSet", out aobj);
            }
            animations_ = aobj as AnimationSet;

            //  set up animations
            if (animations_ != null)
            {
                instances_ = new AnimationInstance[animations_.NumAnimations];
                //  I'll need a BlendedAnimation per animation, so that I can let the
                //  blender object transition between them.
                blended_ = new IBlendedAnimation[instances_.Length];
                int ix = 0;
                foreach (Animation a in animations_.Animations)
                {
                    instances_[ix] = new AnimationInstance(a);
                    blended_[ix]   = AnimationBlender.CreateBlendedAnimation(instances_[ix]);
                    ++ix;
                }
            }
        }
 /// <summary>
 /// Over the given amount of time, transition from using some previous animation,
 /// to using the currently specified animation. The previous animation will be
 /// ramped to 0 weight and removed; the new animation will be ramped from 0 weight
 /// to 1 over the time of the duration. The arguments must have been created with
 /// CreateBlendedAnimation().
 /// You probably want to create a short stationary animation to use for things that
 /// don't move, because blending from an animation to null (when that's the last
 /// running animation) will result in the last animation playing fully until the
 /// blend duration runs out, because of the re-normalization to 1.0 weight.
 /// Unfortunately, this results in a small amount of garbage when complete.
 /// </summary>
 /// <param name="from">Previous animation to transition out, or null.</param>
 /// <param name="to">New animation to transition in, or null.</param>
 /// <param name="duration">How long to run the transition for.</param>
 public void TransitionAnimations(IBlendedAnimation from, IBlendedAnimation to, float duration)
 {
     if (to != null)
     {
         AddAnimation(to, 0);
     }
     transitions_.Add(new Transition(from, (from == null) ? 0 : from.Weight, to, 1, duration));
 }
 internal Transition(IBlendedAnimation from, float fromWeight, IBlendedAnimation to, float toWeight, float duration)
 {
     From       = from;
     FromWeight = fromWeight;
     To         = to;
     ToWeight   = toWeight;
     Duration   = duration;
     Elapsed    = 0;
 }
        /// <summary>
        /// Add a new blended animation, that will keep playing until you remove it or it
        /// completes. The animation must have been created with CreateBlendedAnimation()
        /// or CreateComposedAnimation().
        /// </summary>
        /// <param name="nu">The animation to start blending.</param>
        /// <param name="weight">The relative weight of this animation, compared to other
        /// blended animations.</param>
        public void AddAnimation(IBlendedAnimation nu, float weight)
        {
            BlendedAnimation ba = (BlendedAnimation)nu;

            if (nu.BlendType == BlendType.NormalizedBlend)
            {
                blendedAnimations_.Add(ba);
            }
            else
            {
                composedAnimations_.Add(ba);
            }
            ba.Attach(this);
            nu.Weight = weight;
        }
 internal void OnRemove(IBlendedAnimation anim)
 {
     if (anim == From)
     {
         //  make sure it completes in the next step
         From    = null;
         Elapsed = Duration;
         if (To != null)
         {
             To.Weight = 1;
         }
     }
     if (anim == To)
     {
         To = null;
         //  keep fading out "From" here, or just set to 0 ?
     }
 }
示例#6
0
 internal void OnRemove(IBlendedAnimation anim)
 {
     if (anim == From)
     {
       //  make sure it completes in the next step
       From = null;
       Elapsed = Duration;
       if (To != null)
     To.Weight = 1;
     }
     if (anim == To)
     {
       To = null;
       //  keep fading out "From" here, or just set to 0 ?
     }
 }
示例#7
0
 internal Transition(IBlendedAnimation from, float fromWeight, IBlendedAnimation to, float toWeight, float duration)
 {
     From = from;
     FromWeight = fromWeight;
     To = to;
     ToWeight = toWeight;
     Duration = duration;
     Elapsed = 0;
 }
示例#8
0
 /// <summary>
 /// Over the given amount of time, transition from using some previous animation, 
 /// to using the currently specified animation. The previous animation will be 
 /// ramped to 0 weight and removed; the new animation will be ramped from 0 weight 
 /// to 1 over the time of the duration. The arguments must have been created with 
 /// CreateBlendedAnimation().
 /// You probably want to create a short stationary animation to use for things that 
 /// don't move, because blending from an animation to null (when that's the last 
 /// running animation) will result in the last animation playing fully until the 
 /// blend duration runs out, because of the re-normalization to 1.0 weight.
 /// Unfortunately, this results in a small amount of garbage when complete.
 /// </summary>
 /// <param name="from">Previous animation to transition out, or null.</param>
 /// <param name="to">New animation to transition in, or null.</param>
 /// <param name="duration">How long to run the transition for.</param>
 public void TransitionAnimations(IBlendedAnimation from, IBlendedAnimation to, float duration)
 {
     if (to != null)
     AddAnimation(to, 0);
       transitions_.Add(new Transition(from, (from == null) ? 0 : from.Weight, to, 1, duration));
 }
示例#9
0
 /// <summary>
 /// Add a new blended animation, that will keep playing until you remove it or it 
 /// completes. The animation must have been created with CreateBlendedAnimation()
 /// or CreateComposedAnimation().
 /// </summary>
 /// <param name="nu">The animation to start blending.</param>
 /// <param name="weight">The relative weight of this animation, compared to other 
 /// blended animations.</param>
 public void AddAnimation(IBlendedAnimation nu, float weight)
 {
     BlendedAnimation ba = (BlendedAnimation)nu;
       if (nu.BlendType == BlendType.NormalizedBlend)
     blendedAnimations_.Add(ba);
       else
     composedAnimations_.Add(ba);
       ba.Attach(this);
       nu.Weight = weight;
 }