public MixingSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); var animations = _meshNode.Mesh.Animations; _runAnimation = new AnimationClip <SkeletonPose>(animations["Run"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _idleAnimation = new AnimationClip <SkeletonPose>(animations["Idle"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Create a 'Shoot' animation that only affects the upper body. var shootAnimation = animations["Shoot"]; // The SkeletonKeyFrameAnimations allows to set a weight for each bone channel. // For the 'Shoot' animation, we set the weight to 0 for all bones that are // not descendants of the second spine bone (bone index 2). That means, the // animation affects only the upper body bones and is disabled on the lower // body bones. for (int i = 0; i < _meshNode.Mesh.Skeleton.NumberOfBones; i++) { if (!SkeletonHelper.IsAncestorOrSelf(_meshNode.SkeletonPose, 2, i)) { shootAnimation.SetWeight(i, 0); } } var loopedShootingAnimation = new AnimationClip <SkeletonPose>(shootAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Start 'Idle' animation. _idleAnimationController = AnimationService.StartAnimation(_idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose); _idleAnimationController.AutoRecycle(); // Start looping the 'Shoot' animation. We use a Compose transition. This will add the // 'Shoot' animation to the animation composition chain and keeping all other playing // animations. // The 'Idle' animation animates the whole skeleton. The 'Shoot' animation replaces // the 'Idle' animation on the bones of the upper body. AnimationService.StartAnimation(loopedShootingAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Compose() ).AutoRecycle(); }
public void ComposeAfterWithFadeIn() { var property = new AnimatableProperty <float> { Value = 100.0f }; var animationA = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 200.0f, }; var manager = new AnimationManager(); var controllerA = manager.CreateController(animationA, property); Assert.AreEqual(100.0f, property.Value); controllerA.Start(AnimationTransitions.Compose(TimeSpan.FromSeconds(1.0))); Assert.AreEqual(100.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(150.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(200.0f, property.Value); var animationB = new SingleFromToByAnimation { Duration = TimeSpan.Zero, By = 10.0f, }; var controllerB = manager.CreateController(animationB, property); Assert.AreEqual(200.0f, property.Value); controllerB.Start(AnimationTransitions.Compose(controllerA.AnimationInstance, TimeSpan.FromSeconds(1.0))); Assert.AreEqual(200.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(205.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(210.0f, property.Value); controllerA.Stop(); controllerA.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); controllerB.Stop(); controllerB.UpdateAndApply(); Assert.AreEqual(100.0f, property.Value); }
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 void FadeOut() { var property = new AnimatableProperty <float> { Value = 10.0f }; var animation = new SingleFromToByAnimation { From = 100.0f, To = 200.0f, IsAdditive = true, }; var manager = new AnimationManager(); var controller = manager.CreateController(animation, property); Assert.AreEqual(10.0f, property.Value); controller.Start(AnimationTransitions.Compose()); controller.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); // Changing the base value has no effect. manager.Update(TimeSpan.Zero); manager.ApplyAnimations(); Assert.AreEqual(110.0f, property.Value); manager.Update(TimeSpan.FromSeconds(1.0)); manager.ApplyAnimations(); Assert.AreEqual(210.0f, property.Value); controller.Stop(TimeSpan.FromSeconds(1.0)); Assert.AreEqual(210.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(110.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(10.0f, property.Value); Assert.AreEqual(AnimationState.Filling, controller.State); manager.Update(TimeSpan.FromSeconds(0.1)); manager.ApplyAnimations(); Assert.AreEqual(10.0f, property.Value); Assert.AreEqual(AnimationState.Stopped, controller.State); }
public void AdditiveAnimation() { var property = new AnimatableProperty <float> { Value = 123.4f }; var manager = new AnimationManager(); // Start base animation. var animation0 = new SingleFromToByAnimation { Duration = TimeSpan.FromSeconds(1.0), To = 234.5f, FillBehavior = FillBehavior.Stop, }; var controller0 = manager.StartAnimation(animation0, property); Assert.AreEqual(123.4f, property.Value); // Start additive animation. var animation1 = new SingleFromToByAnimation { Duration = TimeSpan.FromSeconds(1.0), From = 0.0f, To = 10.0f, IsAdditive = true, FillBehavior = FillBehavior.Hold, }; var controller1 = manager.StartAnimation(animation1, property, AnimationTransitions.Compose()); Assert.AreEqual(123.4f, property.Value); manager.Update(TimeSpan.FromSeconds(1.0)); Assert.AreEqual(123.4f, property.Value); manager.ApplyAnimations(); Assert.AreEqual(234.5f + 10.0f, property.Value); manager.Update(new TimeSpan(166666)); Assert.AreEqual(234.5f + 10.0f, property.Value); manager.ApplyAnimations(); Assert.AreEqual(123.4f + 10.0f, property.Value); // Stop additive animation. controller1.Stop(); controller1.UpdateAndApply(); Assert.AreEqual(123.4f, property.Value); }
public void Compose() { var property = new AnimatableProperty <float> { Value = 100.0f }; var animationA = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 200.0f, }; var manager = new AnimationManager(); var controllerA = manager.CreateController(animationA, property); Assert.AreEqual(100.0f, property.Value); controllerA.Start(AnimationTransitions.Compose()); controllerA.UpdateAndApply(); Assert.AreEqual(200.0f, property.Value); var animationB = new SingleFromToByAnimation { Duration = TimeSpan.Zero, By = 10.0f, }; var controllerB = manager.CreateController(animationB, property); Assert.AreEqual(200.0f, property.Value); controllerB.Start(AnimationTransitions.Compose()); controllerB.UpdateAndApply(); Assert.AreEqual(210.0f, property.Value); controllerA.Stop(); controllerA.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); controllerB.Stop(); controllerB.UpdateAndApply(); Assert.AreEqual(100.0f, property.Value); }
public void StartStopAnimationsWithinOneFrame1() { var property = new AnimatableProperty <float> { Value = 123.4f }; var manager = new AnimationManager(); // Start base animation. var animation0 = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 234.5f, FillBehavior = FillBehavior.Stop, }; var controller0 = manager.StartAnimation(animation0, property); controller0.UpdateAndApply(); Assert.AreEqual(234.5f, property.Value); // Start additive animation. var animation1 = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 10.0f, IsAdditive = true, FillBehavior = FillBehavior.Stop, }; var controller1 = manager.StartAnimation(animation1, property, AnimationTransitions.Compose()); controller1.UpdateAndApply(); Assert.AreEqual(234.5f + 10.0f, property.Value); // Stop base animation. controller0.Stop(); controller0.UpdateAndApply(); Assert.AreEqual(123.4f + 10.0f, property.Value); // Stop additive animation. controller1.Stop(); controller1.UpdateAndApply(); Assert.AreEqual(123.4f, property.Value); }