public EasingSample(Microsoft.Xna.Framework.Game game) : base(game) { // Initialize array of easing functions. _easingFunctions = new EasingFunction[] { null, new BackEase { Amplitude = 0.5f }, new BounceEase { Bounces = 3, Bounciness = 3 }, new CircleEase(), new CubicEase(), new ElasticEase { Oscillations = 3, Springiness = 10 }, new ExponentialEase(), new LogarithmicEase(), new HermiteEase(), new PowerEase { Power = 2 }, new QuadraticEase(), new QuinticEase(), new SineEase() }; // Create and start a horizontal from/to animation. Rectangle bounds = GraphicsService.GraphicsDevice.Viewport.TitleSafeArea; _fromToAnimation = new SingleFromToByAnimation { From = bounds.Left + 200, To = bounds.Right - 200, Duration = TimeSpan.FromSeconds(1.5), EasingFunction = _easingFunctions[_selectedEasingFunctionIndex], }; _animationController = AnimationService.StartAnimation(_fromToAnimation, _animatableFloat); _animationController.UpdateAndApply(); }
public CrossFadeSample(Microsoft.Xna.Framework.Game game) : base(game) { Rectangle bounds = GraphicsService.GraphicsDevice.Viewport.TitleSafeArea; // Set the base value of the _animatedPosition. When the animations are stopped, // _animatedPosition will return to this value. _animatedPosition.Value = new Vector2(bounds.Center.X, bounds.Center.Y); // Create an oscillating horizontal animation. Vector2FromToByAnimation fromToAnimation = new Vector2FromToByAnimation { From = new Vector2(200, bounds.Center.Y), To = new Vector2(bounds.Right - 200, bounds.Center.Y), Duration = TimeSpan.FromSeconds(2), EasingFunction = new CubicEase { Mode = EasingMode.EaseInOut }, }; _horizontalAnimation = new AnimationClip<Vector2>(fromToAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; // Create an oscillating vertical animation. fromToAnimation = new Vector2FromToByAnimation { From = new Vector2(bounds.Center.X, 100), To = new Vector2(bounds.Center.X, bounds.Bottom - 100), Duration = TimeSpan.FromSeconds(2), EasingFunction = new CubicEase { Mode = EasingMode.EaseInOut }, }; _verticalAnimation = new AnimationClip<Vector2>(fromToAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; // Start the horizontal movement. AnimationService.StartAnimation() returns an // AnimationController. We keep this AnimationController because it is needed to fade-out // the animation. _state = 1; _currentAnimationController = AnimationService.StartAnimation(_horizontalAnimation, _animatedPosition); _currentAnimationController.UpdateAndApply(); // When the animation is stopped, all intermediate animation objects should be recycled. _currentAnimationController.AutoRecycle(); }
public AdditiveAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { Rectangle bounds = GraphicsService.GraphicsDevice.Viewport.TitleSafeArea; // ----- Create and start the base animation. Vector2FromToByAnimation leftRightAnimation = new Vector2FromToByAnimation { TargetProperty = "Position", From = new Vector2(bounds.Left + 100, bounds.Center.Y), To = new Vector2(bounds.Right - 100, bounds.Center.Y), Duration = TimeSpan.FromSeconds(2), EasingFunction = new HermiteEase { Mode = EasingMode.EaseInOut }, }; AnimationClip<Vector2> baseAnimation = new AnimationClip<Vector2>(leftRightAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; _baseAnimationController = AnimationService.StartAnimation(baseAnimation, _animatablePosition); _baseAnimationController.UpdateAndApply(); // ----- Create and start the additive animation. Vector2FromToByAnimation upDownAnimation = new Vector2FromToByAnimation { TargetProperty = "Position", From = new Vector2(0, 50), To = new Vector2(0, -50), Duration = TimeSpan.FromSeconds(0.5), EasingFunction = new SineEase { Mode = EasingMode.EaseInOut }, // Set IsAdditive flag. IsAdditive = true, }; AnimationClip<Vector2> additiveAnimation = new AnimationClip<Vector2>(upDownAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; // Start animation using "Compose". _additiveAnimationController = AnimationService.StartAnimation( additiveAnimation, _animatablePosition, AnimationTransitions.Compose()); _additiveAnimationController.UpdateAndApply(); }
public DudeWalkingSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load<ModelNode>("Dude/Dude"); var meshNode = modelNode.GetSubtree().OfType<MeshNode>().First().Clone(); meshNode.PoseLocal = new Pose(new Vector3F(0, 0, 0), Matrix33F.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(meshNode); GraphicsScreen.Scene.Children.Add(meshNode); // The imported animations are stored in the mesh. Dictionary<string, SkeletonKeyFrameAnimation> animations = meshNode.Mesh.Animations; // The Dude model contains only one animation, which is a SkeletonKeyFrameAnimation with // a walk cycle. SkeletonKeyFrameAnimation walkAnimation = animations.Values.First(); // Wrap the walk animation in an animation clip that loops the animation forever. AnimationClip<SkeletonPose> loopingAnimation = new AnimationClip<SkeletonPose>(walkAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Start the animation and keep the created AnimationController. // We must cast the SkeletonPose to IAnimatableProperty because SkeletonPose implements // IAnimatableObject and IAnimatableProperty. We must tell the AnimationService if we want // to animate an animatable property of the SkeletonPose (IAnimatableObject), or if we want to // animate the whole SkeletonPose (IAnimatableProperty). _animationController = AnimationService.StartAnimation(loopingAnimation, (IAnimatableProperty)meshNode.SkeletonPose); // The animation will be applied the next time AnimationManager.ApplyAnimations() is called // in the main loop. ApplyAnimations() is called before this method is called, therefore // the model will be rendered in the bind pose in this frame and in the first animation key // frame in the next frame - this creates an annoying visual popping effect. // We can avoid this if we call AnimationController.UpdateAndApply(). This will immediately // change the model pose to the first key frame pose. _animationController.UpdateAndApply(); // (Optional) Enable Auto-Recycling: // After the animation is stopped, the animation service will recycle all // intermediate data structures. _animationController.AutoRecycle(); }
// OnLoad() is called when the GameObject is added to the IGameObjectService. protected override void OnLoad() { var contentManager = _services.GetInstance<ContentManager>(); _modelNode = contentManager.Load<ModelNode>(_assetName).Clone(); _modelNode.PoseWorld = _defaultPose; SampleHelper.EnablePerPixelLighting(_modelNode); var scene = _services.GetInstance<IScene>(); scene.Children.Add(_modelNode); // Create looping animation. var meshNode = (MeshNode)_modelNode.Children[0]; // The dude model has a single mesh node as its child. var animations = meshNode.Mesh.Animations; var animationClip = new AnimationClip<SkeletonPose>(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, // Repeat animation... Duration = TimeSpan.MaxValue, // ...forever. }; // Start animation. var animationService = _services.GetInstance<IAnimationService>(); AnimationController = animationService.StartAnimation(animationClip, (IAnimatableProperty)meshNode.SkeletonPose); AnimationController.UpdateAndApply(); }
public SceneSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); GameObjectService.Objects.Add(_cameraObject); // Create a new empty scene. _scene = new Scene(); // Add the camera node to the scene. _scene.Children.Add(_cameraObject.CameraNode); // Load a model. This model uses the DigitalRune Model Processor. Several XML // files (*.drmdl and *.drmat) in the folder of dude.fbx define the materials and other properties. // The DigitalRune Model Processor also imports the animations of the dude model. var model = ContentManager.Load<ModelNode>("Dude/Dude"); // Add two clones of the model to the scene. _model0 = model.Clone(); _model1 = model.Clone(); _scene.Children.Add(_model0); _scene.Children.Add(_model1); // The dude model contains a single mesh node. var meshNode0 = (MeshNode)_model0.Children[0]; var meshNode1 = (MeshNode)_model1.Children[0]; // The imported animation data (skeleton and animations) is stored with the mesh. var animations = meshNode0.Mesh.Animations; // The MeshNodes of skinned models has a SkeletonPose which can be animated. // Let's start the first animation. var timeline0 = new TimelineClip(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, // Loop animation... Duration = TimeSpan.MaxValue, // ...forever. }; _animationController0 = AnimationService.StartAnimation(timeline0, (IAnimatableProperty)meshNode0.SkeletonPose); _animationController0.UpdateAndApply(); var timeline1 = new TimelineClip(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, // Start second animation at a different animation time to add some variety. Delay = TimeSpan.FromSeconds(-1), }; _animationController1 = AnimationService.StartAnimation(timeline1, (IAnimatableProperty)meshNode1.SkeletonPose); _animationController1.UpdateAndApply(); // Add some lights to the scene which have the same properties as the lights // of BasicEffect.EnableDefaultLighting(). InitializeDefaultXnaLights(_scene); _meshRenderer = new MeshRenderer(); var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); }
protected override void LoadContent() { _model = Game.Content.Load<Model>("Soldier"); var additionalData = (Dictionary<string, object>)_model.Tag; var skeleton = (Skeleton)additionalData["Skeleton"]; _skeletonPose = SkeletonPose.Create(skeleton); // Get the animations from the additional data. var animations = (Dictionary<string, SkeletonKeyFrameAnimation>)additionalData["Animations"]; // The Dude model contains only one animation, which is a SkeletonKeyFrameAnimation with // a walk cycle. SkeletonKeyFrameAnimation walkAnimation = animations.Values.First(); // Wrap the walk animation in an animation clip that loops the animation forever. AnimationClip<SkeletonPose> loopingAnimation = new AnimationClip<SkeletonPose>(walkAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Start the animation and keep the created AnimationController. // We must cast the SkeletonPose to IAnimatableProperty because SkeletonPose implements // IAnimatableObject and IAnimatableProperty. We must tell the AnimationService if we want // to animate an animatable property of the SkeletonPose (IAnimatableObject), or if we want to // animate the whole SkeletonPose (IAnimatableProperty). _animationController = AnimationService.StartAnimation(loopingAnimation, (IAnimatableProperty)_skeletonPose); // The animation will be applied the next time AnimationManager.ApplyAnimations() is called // in the main loop. ApplyAnimations() is called before this method is called, therefore // the model will be rendered in the bind pose in this frame and in the first animation key // frame in the next frame - this creates an annoying visual popping effect. // We can avoid this if we call AnimationController.UpdateAndApply(). This will immediately // change the model pose to the first key frame pose. _animationController.UpdateAndApply(); // (Optional) Enable Auto-Recycling: // After the animation is stopped, the animation service will recycle all // intermediate data structures. _animationController.AutoRecycle(); base.LoadContent(); }
private void StartDudeAnimation(ModelNode dude) { // The dude model contains a single mesh node. var meshNode = (MeshNode)dude.Children[0]; // The imported animation data (skeleton and animations) is stored with the mesh. var animations = meshNode.Mesh.Animations; // The MeshNodes of skinned models has a SkeletonPose which can be animated. // Let's start the first animation. var timeline0 = new TimelineClip(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, // Loop animation... Duration = TimeSpan.MaxValue, // ...forever. }; _animationController = AnimationService.StartAnimation(timeline0, (IAnimatableProperty)meshNode.SkeletonPose); _animationController.UpdateAndApply(); }
public void Attack(int ID) { var AnimateService = ServiceLocator.Current.GetInstance<IAnimationService>(); _animationController = AnimateService.StartAnimation(Map[ID]._animations[1], (IAnimatableProperty)Map[ID]._skeleton); _animationController.UpdateAndApply(); _animationController.AutoRecycle(); }
public void Walk(int ID) { // Map[0].animate(); var AnimateService = ServiceLocator.Current.GetInstance<IAnimationService>(); // AnimateService.StartAnimation(Map[ID]._animations[0], (IAnimatableProperty)Map[ID]._skeleton).AutoRecycle(); _animationController = AnimateService.StartAnimation(Map[ID]._animations[0], (IAnimatableProperty)Map[ID]._skeleton); _animationController.Speed += 5; //ServiceLocator.Current.GetInstance<IAnimationService>().StartAnimation(Map[ID].loopingAnimation, (IAnimatableProperty)Map[ID]._skeleton).AutoRecycle(); _animationController.UpdateAndApply(); _animationController.AutoRecycle(); }