コード例 #1
0
        /// <summary>
        /// Converts an intermediate format content pipeline AnimationContent
        /// object to our runtime AnimationClip format.
        /// </summary>
        static AnimationClip ProcessAnimation(AnimationContent animation,
            Dictionary<string, int> boneMap)
        {
            //System.Diagnostics.Debugger.Launch();
            List<Keyframe> keyframes = new List<Keyframe>();

            int affectedBones = animation.Channels.Count;
            int[] affectedBoneIndices = new int[affectedBones];

            int affectedBoneIndex = 0;
            // For each input animation channel.
            foreach (KeyValuePair<string, AnimationChannel> channel in
                animation.Channels)
            {
                // Look up what bone this channel is controlling.
                int boneIndex;

                if (!boneMap.TryGetValue(channel.Key, out boneIndex))
                {
                    throw new InvalidContentException(string.Format(
                        "Found animation for bone '{0}', " +
                        "which is not part of the skeleton.", channel.Key));
                }
                // save the index of the affected bone
                affectedBoneIndices[affectedBoneIndex++] = boneIndex;

                // Convert the keyframe data.
                foreach (AnimationKeyframe keyframe in channel.Value)
                {
                    keyframes.Add(new Keyframe(boneIndex, keyframe.Time,
                                               keyframe.Transform));
                }
            }

            // Sort the merged keyframes by time.
            keyframes.Sort(CompareKeyframeTimes);

            if (keyframes.Count == 0)
                throw new InvalidContentException("Animation has no keyframes.");

            if (animation.Duration <= TimeSpan.Zero)
                throw new InvalidContentException("Animation has a zero duration.");

            AnimationClip clip = new AnimationClip(animation.Duration, keyframes, affectedBoneIndices);
            return clip;
        }
コード例 #2
0
ファイル: AnimationPlayer.cs プロジェクト: DelBero/XnaScrap
        /// <summary>
        /// Starts decoding the specified animation clip.
        /// </summary>
        public void StartClip(AnimationClip clip, bool loop)
        {
            if (clip == null)
                throw new ArgumentNullException("clip");

            _CurrentClip newClip = new _CurrentClip();
            newClip.clipValue = clip;
            newClip.timeValue = TimeSpan.Zero;
            newClip.keyframe = 0;
            newClip.loop = loop;

            m_currentClips.Add(newClip);

            Update(TimeSpan.Zero, true,Root,true);

            //currentClipValue = clip;
            //currentTimeValue = TimeSpan.Zero;
            //currentKeyframe = 0;

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