/// <summary>
        /// Helper used by the Update method to refresh the BoneTransforms data.
        /// </summary>
        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) || (time >= currentClipValue.Duration))
            {
                throw new ArgumentOutOfRangeException("time");
            }

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

            currentTimeValue = time;

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

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

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

                // Use this keyframe.
                boneTransforms[keyframe.Bone] = keyframe.Transform;

                currentKeyframe++;
            }
        }
示例#2
0
        public Matrix[] GetTransformsFromTime(TimeSpan ts)
        {
            Matrix[] xforms = new Matrix[_SkinData.BindPose.Count];
            _SkinData.BindPose.CopyTo(xforms, 0);
            int keyNum = 0;

            while (keyNum < _KeyframeList.Count)
            {
                CTKeyframe3D key = _KeyframeList[keyNum];
                if (key.Time > ts)
                {
                    break;
                }
                xforms[key.Bone] = key.Transform;
                keyNum++;
            }
            return(xforms);
        }