SkinnedModel.AnimationPlayer.UpdateBoneTransforms C# (CSharp) Method

UpdateBoneTransforms() public method

Helper used by the Update method to refresh the BoneTransforms data.
public UpdateBoneTransforms ( System.TimeSpan time, bool relativeToCurrentTime ) : void
time System.TimeSpan
relativeToCurrentTime bool
return void
        public void UpdateBoneTransforms(TimeSpan time, bool relativeToCurrentTime)
        {
            if (currentClipValue == null)
                throw new InvalidOperationException(
                            "AnimationPlayer.Update was called before StartClip");

            // Update the animation position.
            if (relativeToCurrentTime)
            {
                time += currentTimeValue;

                // If we reached the end, loop back to the start.
                while (time >= currentClipValue.Duration)
                    time -= currentClipValue.Duration;
            }

            if ((time < TimeSpan.Zero))
                throw new ArgumentOutOfRangeException("time");

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

            currentTimeValue = time;

            // Read keyframe matrices.
            IList<Keyframe> keyframes = currentClipValue.Keyframes;

            while (currentKeyframe < keyframes.Count)
            {
                Keyframe keyframe = keyframes[currentKeyframe];

                // Stop when we've read up to the current time position.
                if (keyframe.Time > currentTimeValue)
                    break;

               // float keyframe_time = (float)(keyframe.Time.TotalSeconds);
               // if(keyframe_time > curr_keyframe_time)
               // {
               //     prev_keyframe_time = curr_keyframe_time;
               //     curr_keyframe_time = keyframe_time;
               // }

                keyframe_matrices[keyframe.Bone] = keyframe.Transform;

                currentKeyframe++;
            }

            //float curr_time = (float)currentTimeValue.TotalSeconds;
            //float amount = 0;

            //if(curr_keyframe_time != prev_keyframe_time)
            //   amount = ((curr_time - curr_keyframe_time) / (curr_keyframe_time - prev_keyframe_time));

            float amount = 0.1f;
            for (int i = 0; i < bone_matrices.Length; i++)
            {
                Transform transform = new Transform(ref keyframe_matrices[i]);
                Transform.Lerp(ref bone_transforms[i], ref transform, amount, out bone_transforms[i]);
                bone_transforms[i].GetMatrix(out bone_matrices[i]);
            }
        }