Example #1
0
 public void StopMixing()
 {
     mixing = false;
     secondClipValue = null;
 }
Example #2
0
        private void UpdateSecondTime(TimeSpan time, bool relativeToCurrentTime)
        {
            // Update the animation position.
            if (relativeToCurrentTime)
            {
                time += secondTimeValue;

                // If we reached the end, stop mixing
                if(time >= secondClipValue.Duration || (!playMixedOnce && time >= mixDur))
                {
                    if (!playMixedOnce)
                    {
                        currentClipValue = secondClipValue;
                        currentTimeValue = TimeSpan.Zero;
                        currentKeyframe = 0;

                        // Initialize bone transforms to the bind pose.
                        skinningDataValue.BindPose.CopyTo(boneTransforms, 0);
                        UpdateCurrentTime(time, relativeToCurrentTime);
                    }
                    StopMixing();
                    return;
                }
            }

            if ((time < TimeSpan.Zero) || (time >= secondClipValue.Duration))
                throw new ArgumentOutOfRangeException("time");

            // If the position moved backwards, reset the keyframe index.
            if (time < secondTimeValue)
            {
                secondKeyframe = 0;
                skinningDataValue.BindPose.CopyTo(boneTransforms, 0);
            }

            secondTimeValue = time;
        }
Example #3
0
        public void StartClip(string clipName, MixType t, float playbackRate)
        {
            this.PlaybackRate = playbackRate;
            pauseAtEnd = false;
            paused = false;
            mixing = false;
            secondClipValue = null;
            switch (t)
            {
                case MixType.None:
                    currentClipValue = skinningDataValue.AnimationClips[clipName];
                    currentTimeValue = TimeSpan.Zero;
                    currentKeyframe = 0;

                    // Initialize bone transforms to the bind pose.
                    skinningDataValue.BindPose.CopyTo(boneTransforms, 0);
                    break;
                case MixType.MixOnce:
                    mixing = true;
                    playMixedOnce = true;
                    secondClipValue = skinningDataValue.AnimationClips[clipName];
                    mixDur = secondClipValue.Duration;
                    secondTimeValue = TimeSpan.Zero;
                    secondKeyframe = 0;
                    break;
                case MixType.MixInto:
                    playMixedOnce = false;
                    mixing = true;
                    secondClipValue = skinningDataValue.AnimationClips[clipName];
                    //takes the shortest: 1 second, time remaining in current animation, or half of the new animation's duration
                    mixDur = TimeSpan.FromMilliseconds(Math.Min(1000, Math.Min((currentClipValue.Duration - CurrentTime).TotalMilliseconds, secondClipValue.Duration.TotalMilliseconds / 2)));
                    secondTimeValue = TimeSpan.Zero;
                    secondKeyframe = 0;
                    bonesToIgnore = null;
                    break;
                case MixType.PauseAtEnd:
                    currentClipValue = skinningDataValue.AnimationClips[clipName];
                    currentTimeValue = TimeSpan.Zero;
                    currentKeyframe = 0;

                    // Initialize bone transforms to the bind pose.
                    skinningDataValue.BindPose.CopyTo(boneTransforms, 0);

                    pauseAtEnd = true;
                    break;
            }
        }