/// <summary>
        /// animates the skeleton of bones using stored key frame
        /// in the AnimationBlender.
        /// </summary>
        protected override void OnUpdate(GameTime gameTime)
        {
            //  Reset the bone's transform by source transform
            this.ModelData.model.CopyBoneTransformsFrom(this.ModelData.boneTransforms);

            if (animationList.Count > 0)
            {
                for (int i = 0; i < this.ModelData.model.Bones.Count; i++)
                {
                    ModelBone bone = this.ModelData.model.Bones[i];

                    AnimationBlender Blender = animationBlenderList[i];

                    if (Blender.IsEmpty == false)
                    {
                        //  if exist KeyFrameSequence in the AnimationBinder,
                        //  calculates the animation key frame matrix
                        if (Blender.AnimationBinder != null)
                        {
                            //  gets calculated animation key frame on this time
                            bone.Transform =
                                Blender.GetKeyFrameMatrix(
                                    (float)gameTime.ElapsedGameTime.TotalSeconds);
                        }
                    }
                }
            }

            base.OnUpdate(gameTime);
        }
        /// <summary>
        /// processes the necessary steps for binding a model.
        /// It creates AnimationBlender to the number of the model's bone.
        /// </summary>
        public override void BindModel(ModelData modelData)
        {
            base.BindModel(modelData);

            if (animationBlenderList.Count == 0)
            {
                //  Insert all bones in the AnimationBinder
                for (int i = 0; i < modelData.model.Bones.Count; i++)
                {
                    AnimationBlender animationBlender = new AnimationBlender();
                    animationBlender.Name = modelData.model.Bones[i].Name;

                    animationBlenderList.Add(animationBlender);
                }
            }
        }
        /// <summary>
        /// plays the bone animation by index.
        /// </summary>
        /// <param name="index">stored animation index</param>
        /// <param name="startTime">begin time of the animation</param>
        /// <param name="blendTime">blending time of the animation</param>
        /// <param name="timeScaleFactor">
        /// time scale of the animation (default is 1.0)
        /// </param>
        /// <param name="playMode">animation play mode</param>
        /// <returns></returns>
        public bool PlayAnimation(int index, float startTime, float blendTime,
                                  float timeScaleFactor, AnimPlayMode playMode)
        {
            AnimationSequence animation = GetAnimation(index);

            if (animation != null)
            {
                //  Binding the playable AnimationSequence to AnimationBinder
                for (int i = 0; i < animation.KeyFrameSequences.Count; i++)
                {
                    KeyFrameSequence sequence = animation.KeyFrameSequences[i];

                    AnimationBlender blender =
                        FindAnimationBlenderByBoneName(sequence.BoneName);
                    if (blender == null)
                    {
                        throw new InvalidOperationException(
                                  "The animation specified a bone (\"" + sequence.BoneName +
                                  "\") that the model (\"" + this.Name + "\") does not have.");
                    }

                    //  Initialize KeyFrameSequence infomation
                    blender.AddKeyFrameSequence(sequence, startTime, blendTime,
                                                timeScaleFactor, playMode);
                }

                if (traceAnimation)
                {
                    System.Diagnostics.Debug.WriteLine(
                        string.Format("Play Animtion : {0} ({1})", Name, index));
                }

                return(true);
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// processes the necessary steps for binding a model.
        /// It creates AnimationBlender to the number of the model's bone.
        /// </summary>
        public override void BindModel(ModelData modelData)
        {
            base.BindModel(modelData);

            if (animationBlenderList.Count == 0)
            {
                //  Insert all bones in the AnimationBinder
                for (int i = 0; i < modelData.model.Bones.Count; i++)
                {
                    AnimationBlender animationBlender = new AnimationBlender();
                    animationBlender.Name = modelData.model.Bones[i].Name;

                    animationBlenderList.Add(animationBlender);
                }
            }
        }