//NEW CODE public Actor(ContentRegister content, MaterialLightCollection lights) { //A ModelInstance can be created without any content... //However it cannot be used until the content is set model = new ModelInstance(); model.LightCollection = lights; //this class is reused by later tutorials, which require lights //get and create the animation controller for this model. animationController = model.GetAnimationController(); //NOTE: Animations cannot be played until the model data has been loaded... content.Add(this); //At this point in this tutorial, the model is now loaded. //get the index of the walk animation //this model has 4 animations, Wave, Jog, Walk and Loiter //The animations are stored in model.ModelData.Animations int animationIndex = animationController.AnimationIndex("Walk"); //begin playing the animation, looping animation = animationController.PlayLoopingAnimation(animationIndex); //as many animations as you want can be played at any one time //to blend between animations, adjust their weighting with: //animation.Weighting = ...; //Combined weightings usually should add up to 1.0 //A weighting of 0 means the animation has no effect, 1 has normal effect. //Values outside the 0-1 range usually produces undesirable results. //Note: //Animations in xen are lossy compressed. //For the model used here, the animation data is reduced from nearly 2mb //down to around 200kb. (The model geometry is less than 300kb) //The amount of compression change can be configured in the content's properties //The 'Animation Compression Tolerance' value is a percentage //The default is .5%. This means the animation will always be within .5% //of the source. Setting this value to 0 will save a lossless animation. }
public Actor(ContentRegister content, Vector3 position, float animationSpeed, int animationIndex) { Matrix.CreateRotationZ(1-(float)animationIndex, out this.worldMatrix); this.worldMatrix.Translation = position; model = new ModelInstance(); this.animationController = model.GetAnimationController(); content.Add(this); this.animation = this.animationController.PlayLoopingAnimation(animationIndex); this.animation.PlaybackSpeed = animationSpeed; }
private void InitaliseAnimations(UpdateManager updateManager) { //create the controller as an asynchronous controller. //this will process animations as a thread task //This occurs between the update loop and the draw loop, //which is why the UpdateManager must be provided. control = model.GetAsyncAnimationController(updateManager); //these perform a linear search to find the animation index int idleAnimationIndex = control.AnimationIndex("Loiter"); int jogAnimationIndex = control.AnimationIndex("Jog"); int walkAnimationIndex = control.AnimationIndex("Walk"); //create the idle animation idle = control.PlayLoopingAnimation(idleAnimationIndex); //give it a random speed idle.PlaybackSpeed = (float)random.NextDouble() * 0.5f + 0.6f; if (moveSpeed > 0.75) { //run animation move = control.PlayLoopingAnimation(jogAnimationIndex); // play a jogging animation move.PlaybackSpeed = 0.5f; } else { //walk animation move = control.PlayLoopingAnimation(walkAnimationIndex); // play a walking animation } //initially don't want the move animation being visible move.Weighting = 0; }
public Actor(ContentRegister content, UpdateManager updateManager) { //load the model model = new ModelInstance(); content.Add(this); //create the animation controller animationController = model.GetAsyncAnimationController(updateManager); //NEW CODE //create the animation modifier int rotateBoneIndex = model.ModelData.Skeleton.GetBoneIndexByName("Bip01_Spine2"); this.animationModifer = new AnimationModifier(rotateBoneIndex, model.ModelData); //set the modifier on the animation controller this.animationController.AnimationBoneModifier = this.animationModifer; //play the run animation int animationIndex = animationController.AnimationIndex("Jog"); this.animation = animationController.PlayLoopingAnimation(animationIndex); }