コード例 #1
0
        /// <summary>
        /// Updates the animation.
        /// </summary>
        /// <param name="gameTime">
        /// The game time.
        /// </param>
        protected override void Update(TimeSpan gameTime)
        {
            if (this.State == AnimationState.Playing || this.needUpdate)
            {
                ////Timers.BeginAveragedTimer("Update Clip");
                this.clip.FinalListenKeyframeEvents = this.OnKeyFrameEvent != null;
                this.clip = this.clip.UpdateClip();
                ////Timers.EndAveragedTimer("Update Clip");

                var sample = this.clip.Sample;

                sample?.ApplyPose();

                if (this.ApplyRootMotion)
                {
                    ////Labels.Add("PositionOffset", sample.PositionOffset);
                    ////Labels.Add("RotationOffset", Quaternion.ToEuler(sample.RotationOffset));
                    this.transform3D.LocalOrientation *= sample.RotationOffset;
                    var positionOffset = Vector3.TransformNormal(sample.PositionOffset, this.transform3D.LocalTransform);
                    this.transform3D.LocalPosition += positionOffset;
                    ////this.RenderManager.LineBatch3D.DrawAxis(this.transform3D.WorldTransform, 0.5f);
                }

                if (this.OnKeyFrameEvent != null)
                {
                    for (int i = 0; i < sample.Events.Count; i++)
                    {
                        this.OnKeyFrameEvent(this, sample.Events[i]);
                    }
                }

                this.AnimationUpdated?.Invoke(this, sample);
                this.needUpdate = false;
            }
        }
コード例 #2
0
ファイル: TransitionClip.cs プロジェクト: sibeansa/Components
 /// <summary>
 /// Initializes a new instance of the <see cref="TransitionClip" /> class.
 /// </summary>
 /// <param name="clipA">The A clip</param>
 /// <param name="clipB">The B clip</param>
 /// <param name="duration">The transition duration</param>
 /// <param name="playbackRate">Playback rate</param>
 public TransitionClip(AnimationBlendClip clipA, AnimationBlendClip clipB, float duration, float playbackRate = 1)
     : base(clipA, clipB)
 {
     this.duration     = duration;
     this.playbackRate = playbackRate;
     this.sample       = new AnimationSample();
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdditiveBlendingClip" /> class.
 /// </summary>
 /// <param name="clipA">The A clip</param>
 /// <param name="clipB">The B clip</param>
 /// <param name="loop">The animation is looping</param>
 /// <param name="blendFactor">The blend factor</param>
 public AdditiveBlendingClip(AnimationBlendClip clipA, AnimationBlendClip clipB, bool loop = true, float blendFactor = 1)
     : base(clipA, clipB)
 {
     this.sample      = new AnimationSample();
     this.Loop        = loop;
     this.BlendFactor = 1;
 }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PartialBlendingClip" /> class.
        /// </summary>
        /// <param name="clipA">The A clip</param>
        /// <param name="clipB">The B clip</param>
        /// <param name="jointWeights">The joint</param>
        /// <param name="loop">The animation is looping</param>
        public PartialBlendingClip(AnimationBlendClip clipA, AnimationBlendClip clipB, float[] jointWeights, bool loop = true)
            : base(clipA, clipB)
        {
            this.sample           = new AnimationSample();
            this.Loop             = loop;
            this.jointBlendWeight = 1;
            this.maxBlend         = 1;
            this.jointName        = null;

            this.JointWeights = jointWeights;
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PartialBlendingClip" /> class.
        /// </summary>
        /// <param name="clipA">The A clip</param>
        /// <param name="clipB">The B clip</param>
        /// <param name="replaceJoint">The joint</param>
        /// <param name="loop">The animation is looping</param>
        public PartialBlendingClip(AnimationBlendClip clipA, AnimationBlendClip clipB, string replaceJoint, bool loop = true)
            : base(clipA, clipB)
        {
            this.sample           = new AnimationSample();
            this.Loop             = loop;
            this.jointBlendWeight = 1;
            this.maxBlend         = 1;
            this.jointName        = replaceJoint;

            this.RefreshWeights();
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SynchronizedTransitionClip" /> class.
        /// </summary>
        /// <param name="clipA">The A clip</param>
        /// <param name="clipB">The B clip</param>
        /// <param name="loop">The animation is looping</param>
        /// <param name="playbackRate">Playback rate</param>
        public SynchronizedTransitionClip(AnimationBlendClip clipA, AnimationBlendClip clipB, bool loop = true, float playbackRate = 1)
            : base(clipA, clipB)
        {
            this.PlaybackRate = playbackRate;
            this.sample       = new AnimationSample();

            this.Phase = this.clipA.Phase;
            this.Loop  = loop;

            this.lerp = 0;
        }
コード例 #7
0
        /// <summary>
        /// Plays the animation between the specified frames.
        /// </summary>
        /// <param name="name">
        /// The name of the animation.
        /// </param>
        /// <param name="startTime">
        /// The frame where the animation starts playing.
        /// </param>
        /// <param name="endTime">
        /// The last frame of the animation to play.
        /// </param>
        /// <param name="loop">
        /// if set to <c>true</c> loop the animation.
        /// </param>
        /// <param name="playbackRate">
        /// the playback rate.
        /// </param>
        public void PlayAnimation(string name, int?startTime, int?endTime, bool loop = true, float playbackRate = 1)
        {
            AnimationClip track;

            if (this.InternalModel != null && this.InternalModel.Animations.TryGetValue(name, out track))
            {
                this.BoundingBoxRefreshed = true;
                this.State        = AnimationState.Playing;
                this.playbackRate = playbackRate;

                var start = startTime ?? 0;
                var end   = endTime ?? this.currentAnimationTrack.Duration;
                System.Diagnostics.Debug.WriteLine("Play " + track.Name + " " + track.Duration + " start: " + start + " end: " + end);
                this.clip = new AnimationTrackClip(track, loop, playbackRate, start, end);

                this.clip.BaseInitializeClip(this.hierarchyMapping);
            }
        }
コード例 #8
0
        /// <summary>
        /// Plays the animation between the specified frames.
        /// </summary>
        /// <param name="clip">The animation clip</param>
        /// <param name="transitionTime">The transition time</param>
        public void PlayAnimation(AnimationBlendClip clip, float transitionTime = 0)
        {
            this.BoundingBoxRefreshed = true;
            this.State = AnimationState.Playing;

            if (transitionTime <= 0 || this.clip == null)
            {
                this.clip = clip;
            }
            else
            {
                var clipA = this.clip;
                var clipB = clip;
                this.clip = new TransitionClip(clipA, clipB, transitionTime);
            }

            this.clip.BaseInitializeClip(this.hierarchyMapping);
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryAnimationBlendClip" /> class.
        /// </summary>
        /// <param name="clipA">The A clip</param>
        /// <param name="clipB">The B clip</param>
        public BinaryAnimationBlendClip(AnimationBlendClip clipA, AnimationBlendClip clipB)
        {
            if (clipA == null)
            {
                throw new ArgumentNullException("clipA");
            }

            if (clipB == null)
            {
                throw new ArgumentNullException("clipB");
            }

            this.clipA = clipA;
            this.clipB = clipB;

            this.ListenAnimationThreshold = 0;
            this.sample = this.binarySample = new BinaryAnimationSample();
        }
コード例 #10
0
        /// <summary>
        /// Plays the animation between the specified frames.
        /// </summary>
        /// <param name="name">The name of the animation.</param>
        /// <param name="loop">Looping animation</param>
        /// <param name="transitionTime">The transition time</param>
        /// <param name="playbackRate">The playback rate</param>
        /// <param name="startTime">The frame where the animation starts playing.</param>
        /// <param name="endTime">The last frame of the animation to play.</param>
        public void PlayAnimation(string name, bool loop = true, float transitionTime = 0, float playbackRate = 1, float?startTime = null, float?endTime = null)
        {
            AnimationClip track;

            if (this.InternalModel != null && this.InternalModel.Animations.TryGetValue(name, out track))
            {
                this.BoundingBoxRefreshed = true;
                this.Loop         = loop;
                this.State        = AnimationState.Playing;
                this.playbackRate = playbackRate;

                if (transitionTime <= 0 || this.clip == null)
                {
                    this.clip = new AnimationTrackClip(track, loop, playbackRate, startTime, endTime);
                }
                else
                {
                    var clipB = new AnimationTrackClip(track, loop, playbackRate, startTime, endTime);
                    this.clip = new TransitionClip(this.clip, clipB, transitionTime);
                }

                this.clip.BaseInitializeClip(this.hierarchyMapping);
            }
        }