/// <summary>
        /// Retrieves and interpolates the pose of an animation channel.
        /// </summary>
        /// <param name="animationChannel">Name of the animation channel.</param>
        /// <param name="animationTime">Current animation clip time.</param>
        /// <param name="outPose">The output interpolated pose.</param>
        private void InterpolateChannelPose(AnimationChannel animationChannel, TimeSpan animationTime,
                                            out Pose outPose)
        {
            if (translationInterpolation == InterpolationMode.None &&
                orientationInterpolation == InterpolationMode.None &&
                scaleInterpolation == InterpolationMode.None)
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                outPose = animationChannel[keyframeIndex].Pose;
            }
            else
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                int nextKeyframeIndex;

                // If we are looping then the next frame may wrap around to
                // the beginning. If not we should just clamp it at the last frame
                if (loopEnabled)
                {
                    nextKeyframeIndex = (keyframeIndex + 1) % animationChannel.Count;
                }
                else
                {
                    nextKeyframeIndex = Math.Min(keyframeIndex + 1, animationChannel.Count - 1);
                }

                AnimationChannelKeyframe keyframe1 = animationChannel[keyframeIndex];
                AnimationChannelKeyframe keyframe2 = animationChannel[nextKeyframeIndex];

                // Calculate the time between the keyframes considering loop
                long keyframeDuration;
                if (keyframeIndex == (animationChannel.Count - 1))
                {
                    keyframeDuration = animationClip.Duration.Ticks - keyframe1.Time.Ticks;
                }
                else
                {
                    keyframeDuration = keyframe2.Time.Ticks - keyframe1.Time.Ticks;
                }

                // Interpolate when duration higher than zero
                if (keyframeDuration > 0)
                {
                    long  elapsedKeyframeTime = animationTime.Ticks - keyframe1.Time.Ticks;
                    float lerpFactor          = elapsedKeyframeTime / (float)keyframeDuration;

                    outPose =
                        Pose.Interpolate(keyframe1.Pose, keyframe2.Pose, lerpFactor,
                                         translationInterpolation, orientationInterpolation, scaleInterpolation);
                }
                // Otherwise don't interpolate
                else
                {
                    outPose = keyframe1.Pose;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Retrieves and interpolates the pose of an animation channel.
        /// </summary>
        /// <param name="animationChannel">Name of the animation channel.</param>
        /// <param name="animationTime">Current animation clip time.</param>
        /// <param name="outPose">The output interpolated pose.</param>
        private void InterpolateChannelPose(AnimationChannel animationChannel, TimeSpan animationTime,
                                            out Pose outPose)
        {
            if (translationInterpolation == InterpolationMode.None &&
                orientationInterpolation == InterpolationMode.None &&
                scaleInterpolation == InterpolationMode.None)
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                outPose = animationChannel[keyframeIndex].Pose;
            }
            else
            {
                int keyframeIndex     = animationChannel.GetKeyframeIndexByTime(animationTime);
                int nextKeyframeIndex = (keyframeIndex + 1) % animationChannel.Count;

                AnimationChannelKeyframe keyframe1 = animationChannel[keyframeIndex];
                AnimationChannelKeyframe keyframe2 = animationChannel[nextKeyframeIndex];

                // Calculate the time between the keyframes considering loop
                long keyframeDuration;
                if (keyframeIndex == (animationChannel.Count - 1))
                {
                    keyframeDuration = animationClip.Duration.Ticks - keyframe1.Time.Ticks;
                }
                else
                {
                    keyframeDuration = keyframe2.Time.Ticks - keyframe1.Time.Ticks;
                }

                // Interpolate when duration higher than zero
                if (keyframeDuration > 0)
                {
                    long  elapsedKeyframeTime = animationTime.Ticks - keyframe1.Time.Ticks;
                    float lerpFactor          = elapsedKeyframeTime / (float)keyframeDuration;

                    outPose =
                        Pose.Interpolate(keyframe1.Pose, keyframe2.Pose, lerpFactor,
                                         translationInterpolation, orientationInterpolation, scaleInterpolation);
                }
                // Otherwise don't interpolate
                else
                {
                    outPose = keyframe1.Pose;
                }
            }
        }
        /// <summary>
        /// Retrieves and interpolates the pose of an animation channel.
        /// </summary>
        /// <param name="animationChannel">Name of the animation channel.</param>
        /// <param name="animationTime">Current animation clip time.</param>
        /// <param name="outPose">The output interpolated pose.</param>
        private void InterpolateChannelPose(AnimationChannel animationChannel, TimeSpan animationTime,
            out Pose outPose)
        {
            if (translationInterpolation == InterpolationMode.None &&
                orientationInterpolation == InterpolationMode.None &&
                    scaleInterpolation == InterpolationMode.None)
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                outPose = animationChannel[keyframeIndex].Pose;
            }
            else
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                int nextKeyframeIndex;

                // If we are looping then the next frame may wrap around to
                // the beginning. If not we should just clamp it at the last frame
                if (loopEnabled)
                {
                    nextKeyframeIndex = (keyframeIndex + 1) % animationChannel.Count;
                }
                else
                {
                    nextKeyframeIndex = Math.Min(keyframeIndex + 1, animationChannel.Count - 1);
                }

                AnimationChannelKeyframe keyframe1 = animationChannel[keyframeIndex];
                AnimationChannelKeyframe keyframe2 = animationChannel[nextKeyframeIndex];

                // Calculate the time between the keyframes considering loop
                long keyframeDuration;
                if (keyframeIndex == (animationChannel.Count - 1))
                    keyframeDuration = animationClip.Duration.Ticks - keyframe1.Time.Ticks;
                else
                    keyframeDuration = keyframe2.Time.Ticks - keyframe1.Time.Ticks;

                // Interpolate when duration higher than zero
                if (keyframeDuration > 0)
                {
                    long elapsedKeyframeTime = animationTime.Ticks - keyframe1.Time.Ticks;
                    float lerpFactor = elapsedKeyframeTime / (float)keyframeDuration;

                    outPose =
                        Pose.Interpolate(keyframe1.Pose, keyframe2.Pose, lerpFactor,
                            translationInterpolation, orientationInterpolation, scaleInterpolation);
                }
                // Otherwise don't interpolate
                else
                    outPose = keyframe1.Pose;
            }
        }
        /// <summary>
        /// Retrieves and interpolates the pose of an animation channel.
        /// </summary>
        /// <param name="animationChannel">Name of the animation channel.</param>
        /// <param name="animationTime">Current animation clip time.</param>
        /// <param name="outPose">The output interpolated pose.</param>
        private void InterpolateChannelPose(AnimationChannel animationChannel, TimeSpan animationTime,
            out Pose outPose)
        {
            if (translationInterpolation == InterpolationMode.None &&
                orientationInterpolation == InterpolationMode.None &&
                    scaleInterpolation == InterpolationMode.None)
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                outPose = animationChannel[keyframeIndex].Pose;
            }
            else
            {
                int keyframeIndex = animationChannel.GetKeyframeIndexByTime(animationTime);
                int nextKeyframeIndex = (keyframeIndex + 1) % animationChannel.Count;

                AnimationChannelKeyframe keyframe1 = animationChannel[keyframeIndex];
                AnimationChannelKeyframe keyframe2 = animationChannel[nextKeyframeIndex];

                // Calculate the time between the keyframes considering loop
                long keyframeDuration;
                if (keyframeIndex == (animationChannel.Count - 1))
                    keyframeDuration = animationClip.Duration.Ticks - keyframe1.Time.Ticks;
                else
                    keyframeDuration = keyframe2.Time.Ticks - keyframe1.Time.Ticks;

                // Interpolate when duration higher than zero
                if (keyframeDuration > 0)
                {
                    long elapsedKeyframeTime = animationTime.Ticks - keyframe1.Time.Ticks;
                    float lerpFactor = elapsedKeyframeTime / (float)keyframeDuration;

                    outPose =
                        Pose.Interpolate(keyframe1.Pose, keyframe2.Pose, lerpFactor,
                            translationInterpolation, orientationInterpolation, scaleInterpolation);
                }
                // Otherwise don't interpolate
                else
                    outPose = keyframe1.Pose;
            }
        }