コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IKSolver"/> class.
        /// </summary>
        protected IKSolver()
        {
            MaxAngularVelocity = float.PositiveInfinity;

            _weightProperty       = new AnimatableProperty <float>();
            _weightProperty.Value = 1.0f;
        }
コード例 #2
0
ファイル: AnimationEngine.cs プロジェクト: AnthonyMir/vrtist
        public void AddFilteredKeyframeTangent(GameObject gobjet, AnimatableProperty property, AnimationKey key, int start, int end, bool updateCurves = true)
        {
            AnimationSet animationSet = GetObjectAnimation(gobjet);
            Curve        curve        = animationSet.GetCurve(property);

            // Filter rotation
            if (property == AnimatableProperty.RotationX || property == AnimatableProperty.RotationY || property == AnimatableProperty.RotationZ)
            {
                AnimationKey previousKey = curve.GetPreviousKey(key.frame);
                if (null != previousKey)
                {
                    float delta = Mathf.DeltaAngle(previousKey.value, key.value);
                    key.value = previousKey.value + delta;
                }
                else
                {
                    float delta = Mathf.DeltaAngle(0, key.value);
                    key.value = delta;
                }
            }
            curve.AddTangentKey(key, start, end);
            if (updateCurves)
            {
                onChangeCurve.Invoke(gobjet, property);
            }
        }
コード例 #3
0
 public CommandMoveKeyframe(GameObject obj, AnimatableProperty property, int frame, int newFrame)
 {
     gObject       = obj;
     this.property = property;
     this.oldFrame = frame;
     this.newFrame = newFrame;
 }
コード例 #4
0
        public void ShouldDoNothingIfInvalid()
        {
            var manager    = new AnimationManager();
            var property   = new AnimatableProperty <float>();
            var animation  = new SingleFromToByAnimation();
            var controller = manager.CreateController(animation, property);

            controller.Recycle();
            Assert.IsFalse(controller.IsValid);

            // The following has no effect.
            controller.AutoRecycleEnabled = false;
            controller.Time = TimeSpan.Zero;
            controller.AutoRecycle();
            controller.Recycle();
            controller.Pause();
            controller.Resume();
            controller.Stop();
            controller.Stop(TimeSpan.Zero);
            controller.Stop(TimeSpan.FromSeconds(1.0));

            // Only Start and UpdateAndApply should throw an exceptions.
            Assert.That(() => controller.Start(), Throws.TypeOf <AnimationException>());
            Assert.That(() => controller.UpdateAndApply(), Throws.TypeOf <AnimationException>());
        }
コード例 #5
0
ファイル: VRtistMixer.cs プロジェクト: ubisoft/vrtist
        public static void CreateAnimationCurve(string objectName, string channel, int channelIndex, int[] frames, float[] values, int[] interpolations)
        {
            AnimatableProperty property = BlenderToVRtistAnimationProperty(channel, channelIndex);

            int keyCount             = frames.Length;
            List <AnimationKey> keys = new List <AnimationKey>();

            for (int i = 0; i < keyCount; i++)
            {
                float value = values[i];
                if (property == AnimatableProperty.RotationX || property == AnimatableProperty.RotationY || property == AnimatableProperty.RotationZ)
                {
                    value = Mathf.Rad2Deg * value;
                }

                keys.Add(new AnimationKey(frames[i], value, (Interpolation)interpolations[i]));
            }


            Node node = SyncData.nodes[objectName];

            // Apply to instances
            foreach (Tuple <GameObject, string> t in node.instances)
            {
                GameObject   gobj         = t.Item1;
                AnimationSet animationSet = GlobalState.Animation.GetOrCreateObjectAnimation(gobj);
                animationSet.SetCurve(property, keys);
            }
        }
コード例 #6
0
        public void StartStopAnimationWithinOneFrame()
        {
            var property = new AnimatableProperty <float> {
                Value = 123.4f
            };
            var manager = new AnimationManager();

            var animation = new SingleFromToByAnimation
            {
                Duration     = TimeSpan.Zero,
                To           = 234.5f,
                FillBehavior = FillBehavior.Stop,
            };

            var controller = manager.CreateController(animation, property);

            Assert.AreEqual(123.4f, property.Value);

            // Start
            controller.Start();
            controller.UpdateAndApply();
            Assert.AreEqual(234.5f, property.Value);

            // Stop
            controller.Stop();
            controller.UpdateAndApply();
            Assert.AreEqual(123.4f, property.Value);
        }
コード例 #7
0
        public void AnimationWeight()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation
              {
            Duration = TimeSpan.FromSeconds(1.0),
            From = 100.0f,
            To = 200.0f,
              };

              var controller = manager.StartAnimation(animation, property);
              controller.AutoRecycle();
              controller.UpdateAndApply();
              Assert.AreEqual(1.0f, controller.Weight);
              Assert.AreEqual(100.0f, property.Value);

              controller.Weight = 0.5f;
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(50.0f, property.Value);

              controller.Stop();
              Assert.IsNaN(controller.Weight);
        }
コード例 #8
0
        public void AnimationWeight()
        {
            var manager   = new AnimationManager();
            var property  = new AnimatableProperty <float>();
            var animation = new SingleFromToByAnimation
            {
                Duration = TimeSpan.FromSeconds(1.0),
                From     = 100.0f,
                To       = 200.0f,
            };

            var controller = manager.StartAnimation(animation, property);

            controller.AutoRecycle();
            controller.UpdateAndApply();
            Assert.AreEqual(1.0f, controller.Weight);
            Assert.AreEqual(100.0f, property.Value);

            controller.Weight = 0.5f;
            manager.Update(TimeSpan.Zero);
            manager.ApplyAnimations();
            Assert.AreEqual(50.0f, property.Value);

            controller.Stop();
            Assert.IsNaN(controller.Weight);
        }
コード例 #9
0
        public void FadeOutAnimation()
        {
            var manager   = new AnimationManager();
            var property  = new AnimatableProperty <float>();
            var animation = new SingleFromToByAnimation
            {
                Duration = TimeSpan.Zero,
                To       = 100.0f,
            };
            var controller = manager.StartAnimation(animation, property);

            controller.UpdateAndApply();
            Assert.AreEqual(100.0f, property.Value);
            Assert.AreEqual(AnimationState.Playing, controller.State);

            controller.Stop(TimeSpan.FromSeconds(1.0));
            Assert.AreEqual(100.0f, property.Value);
            Assert.AreEqual(AnimationState.Playing, controller.State);

            manager.Update(TimeSpan.FromSeconds(0.5));
            manager.ApplyAnimations();
            Assert.AreEqual(50.0f, property.Value);
            Assert.AreEqual(AnimationState.Filling, controller.State);

            manager.Update(TimeSpan.FromSeconds(0.5));
            manager.ApplyAnimations();
            Assert.AreEqual(0.0f, property.Value);
            Assert.AreEqual(AnimationState.Filling, controller.State);

            manager.Update(TimeSpan.FromSeconds(0.5));
            manager.ApplyAnimations();
            Assert.AreEqual(0.0f, property.Value);
            Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
コード例 #10
0
        public void InvalidParameters()
        {
            var objectA   = new AnimatableObject("ObjectA");
            var objectB   = new AnimatableObject("ObjectA");
            var property  = new AnimatableProperty <float>();
            var animation = new SingleFromToByAnimation();
            var objects   = new[] { objectA, objectB };

            var manager = new AnimationManager();

            // Should throw exception.
            Assert.That(() => { manager.IsAnimated((IAnimatableObject)null); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.IsAnimated((IAnimatableProperty)null); }, Throws.TypeOf <ArgumentNullException>());

            // Should throw exception.
            Assert.That(() => { manager.CreateController(null, objects); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.CreateController(animation, (IEnumerable <IAnimatableObject>)null); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.CreateController(null, objectA); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.CreateController(animation, (IAnimatableObject)null); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.CreateController(null, property); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.CreateController(animation, (IAnimatableProperty)null); }, Throws.TypeOf <ArgumentNullException>());

            // Should throw exception.
            Assert.That(() => { manager.StartAnimation(null, objects); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.StartAnimation(animation, (IEnumerable <IAnimatableObject>)null); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.StartAnimation(null, objectA); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.StartAnimation(animation, (IAnimatableObject)null); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.StartAnimation(null, property); }, Throws.TypeOf <ArgumentNullException>());
            Assert.That(() => { manager.StartAnimation(animation, (IAnimatableProperty)null); }, Throws.TypeOf <ArgumentNullException>());

            // Should not throw exception.
            Assert.That(() => manager.StopAnimation((IEnumerable <IAnimatableObject>)null), Throws.Nothing);
            Assert.That(() => manager.StopAnimation((IAnimatableObject)null), Throws.Nothing);
            Assert.That(() => manager.StopAnimation((IAnimatableProperty)null), Throws.Nothing);
        }
コード例 #11
0
        // OnUnload() is called when the GameObject is removed from the IGameObjectService.
        protected override void OnUnload()
        {
            // Remove models from scene.
            foreach (var model in _models)
            {
                model.Parent.Children.Remove(_modelPrototype);
                model.Dispose(false);
            }

            // Remove rigid bodies from physics simulation.
            foreach (var body in _bodies)
            {
                body.Simulation.RigidBodies.Remove(body);
            }

            _models.Clear();
            _bodies.Clear();

            // Remove prototype.
            _modelPrototype.Dispose(false);
            _modelPrototype = null;
            _bodyPrototype  = null;

            // Stop animation.
            var animationService = _services.GetInstance <IAnimationService>();

            animationService.StopAnimation(_glowIntensity);
            _glowIntensity = null;
        }
コード例 #12
0
ファイル: VRtistMixer.cs プロジェクト: ubisoft/vrtist
        public static void CreateAnimationKey(string objectName, string channel, int channelIndex, int frame, float value, int interpolation)
        {
            AnimatableProperty property = BlenderToVRtistAnimationProperty(channel, channelIndex);

            if (property == AnimatableProperty.Unknown)
            {
                Debug.LogError("Unknown Animation Property " + objectName + " " + channel + " " + channelIndex);
                return;
            }

            Node node = SyncData.nodes[objectName];

            // Apply to instances
            foreach (Tuple <GameObject, string> t in node.instances)
            {
                GameObject   gobj         = t.Item1;
                AnimationSet animationSet = GlobalState.Animation.GetOrCreateObjectAnimation(gobj);
                Curve        curve        = animationSet.GetCurve(property);

                if (property == AnimatableProperty.RotationX || property == AnimatableProperty.RotationY || property == AnimatableProperty.RotationZ)
                {
                    value = Mathf.Rad2Deg * value;
                }

                curve.AddKey(new AnimationKey(frame, value, (Interpolation)interpolation));
            }
        }
コード例 #13
0
        // To be used by in-app add key (not from networked keys)
        public void AddFilteredKeyframe(GameObject gobject, AnimatableProperty property, AnimationKey key)
        {
            AnimationSet animationSet = GetObjectAnimation(gobject);

            if (null == animationSet)
            {
                animationSet = new AnimationSet(gobject);
                animations.Add(gobject, animationSet);
            }
            Curve curve = animationSet.GetCurve(property);

            // Filter rotation
            if (property == AnimatableProperty.RotationX || property == AnimatableProperty.RotationY || property == AnimatableProperty.RotationZ)
            {
                AnimationKey previousKey = curve.GetPreviousKey(key.frame);
                if (null != previousKey)
                {
                    float delta = Mathf.DeltaAngle(previousKey.value, key.value);
                    key.value = previousKey.value + delta;
                }
            }

            curve.AddKey(key);
            onChangeCurve.Invoke(gobject, property);
        }
コード例 #14
0
 void OnCurveUpdated(GameObject gobject, AnimatableProperty property)
 {
     if (property == AnimatableProperty.PositionX)
     {
         UpdateCurrentObjectAnimation(gobject);
     }
 }
コード例 #15
0
        void OnCurveChanged(GameObject gObject, AnimatableProperty property)
        {
            RigGoalController[] controllers = gObject.GetComponentsInChildren <RigGoalController>();
            if (controllers.Length > 0)
            {
                if ((ToolsManager.CurrentToolName() == "Animation"))
                {
                    //update all goals' curves
                    UpdateGoalCurve(controllers);
                }
                else
                {
                    //only update rig's root curve
                    UpdateGoalCurve(new RigGoalController[] { controllers[0] });
                }
            }
            if (property != AnimatableProperty.PositionX && property != AnimatableProperty.PositionY && property != AnimatableProperty.PositionZ)
            {
                return;
            }

            if (!Selection.IsSelected(gObject))
            {
                return;
            }

            UpdateCurve(gObject);
        }
コード例 #16
0
    // OnLoad() is called when the GameObject is added to the IGameObjectService.
    protected override void OnLoad()
    {
      // ----- Create prototype of a lava ball:

      // Use a sphere for physics simulation.
      _bodyPrototype = new RigidBody(new SphereShape(0.5f));

      // Load the graphics model.
      var content = _services.GetInstance<ContentManager>();
      _modelPrototype = content.Load<ModelNode>("LavaBall/LavaBall").Clone();

      // Attach a point light to the model. The light projects the glowing lava 
      // veins (cube map texture) onto the environment.
      _pointLight = new PointLight
      {
        Color = new Vector3F(1, 1, 1),
        DiffuseIntensity = 2,
        SpecularIntensity = 2,
        Range = 1.5f,
        Attenuation = 0.5f,
        Texture = content.Load<TextureCube>("LavaBall/LavaCubeMap"),
      };
      var pointLightNode = new LightNode(_pointLight);
      _modelPrototype.Children.Add(pointLightNode);

      // Get the emissive color binding of the material because the emissive color
      // will be animated.
      // The model contains one mesh node with a single material.
      var meshNode = (MeshNode)_modelPrototype.Children[0];
      var mesh = meshNode.Mesh;
      var material = mesh.Materials[0];

      // The material contains several effect bindings. The "EmissiveColor" is applied
      // in the "Material" pass. 
      // (For reference see material definition file: Samples\Media\LavaBall\Lava.drmat)
      _emissiveColorBinding = (ConstParameterBinding<Vector3>)material["Material"].ParameterBindings["EmissiveColor"];

      // Use the animation service to animate glow intensity of the lava.
      var animationService = _services.GetInstance<IAnimationService>();

      // Create an AnimatableProperty<float>, which stores the animation value.
      _glowIntensity = new AnimatableProperty<float>();

      // Create sine animation and play the animation back-and-forth.
      var animation = new SingleFromToByAnimation
      {
        From = 0.3f,
        To = 3.0f,
        Duration = TimeSpan.FromSeconds(1),
        EasingFunction = new SineEase { Mode = EasingMode.EaseInOut },
      };
      var clip = new AnimationClip<float>
      {
        Animation = animation,
        Duration = TimeSpan.MaxValue,
        LoopBehavior = LoopBehavior.Oscillate
      };
      animationService.StartAnimation(clip, _glowIntensity).AutoRecycle();
    }
コード例 #17
0
        public void ShouldReturnNullWhenTypeDoesNotMatch()
        {
            var widthProperty = new AnimatableProperty<float>();
              var animatable = new AnimatableObject("Object");
              animatable.Properties.Add("Width", widthProperty);

              Assert.IsNull(animatable.GetAnimatableProperty<string>("Width"));
        }
コード例 #18
0
        public void ShouldReturnNullWhenNameIsNotFound()
        {
            var widthProperty = new AnimatableProperty<float>();
              var animatable = new AnimatableObject("Object");
              animatable.Properties.Add("Width", widthProperty);

              Assert.IsNull(animatable.GetAnimatableProperty<float>("WrongName"));
        }
コード例 #19
0
 public void SetterShouldSetBaseValue()
 {
     var animatableProperty = new AnimatableProperty<float>();
       animatableProperty.Value = 123;
       Assert.IsTrue(((IAnimatableProperty<float>)animatableProperty).HasBaseValue);
       Assert.IsFalse(((IAnimatableProperty<float>)animatableProperty).IsAnimated);
       Assert.AreEqual(123, ((IAnimatableProperty<float>)animatableProperty).BaseValue);
 }
コード例 #20
0
        public void AnimateProperty()
        {
            var property = new AnimatableProperty <float> {
                Value = 10.0f
            };

            var animationA = new SingleFromToByAnimation
            {
                From           = 100.0f,
                To             = 200.0f,
                TargetObject   = "ObjectA",   // Should be ignored.
                TargetProperty = "PropertyA", // Should be ignored.
            };
            var animationB = new SingleFromToByAnimation
            {
                From           = 200.0f,
                To             = 300.0f,
                TargetObject   = "ObjectB",   // Should be ignored.
                TargetProperty = "PropertyB", // Should be ignored.
            };
            var animationGroup = new TimelineGroup();

            animationGroup.Add(animationA);
            animationGroup.Add(animationB);

            var manager = new AnimationManager();

            // Should assign both animations to 'property'.
            var controller = manager.CreateController(animationGroup, property);

            Assert.AreEqual(property, ((AnimationInstance <float>)controller.AnimationInstance.Children[0]).Property);
            Assert.AreEqual(property, ((AnimationInstance <float>)controller.AnimationInstance.Children[1]).Property);
            Assert.IsFalse(manager.IsAnimated(property));

            // When started then animationB (last in the composition chain) should be active.
            controller.Start();
            controller.UpdateAndApply();
            Assert.AreEqual(200.0f, property.Value);
            Assert.IsTrue(manager.IsAnimated(property));

            controller.Stop();
            controller.UpdateAndApply();
            Assert.AreEqual(10.0f, property.Value);
            Assert.IsFalse(manager.IsAnimated(property));

            // Same test for AnimationManager.StartAnimation()
            controller = manager.StartAnimation(animationGroup, property);
            controller.UpdateAndApply();
            Assert.AreEqual(property, ((AnimationInstance <float>)controller.AnimationInstance.Children[0]).Property);
            Assert.AreEqual(property, ((AnimationInstance <float>)controller.AnimationInstance.Children[1]).Property);
            Assert.AreEqual(200.0f, property.Value);
            Assert.IsTrue(manager.IsAnimated(property));

            manager.StopAnimation(property);
            manager.UpdateAndApplyAnimation(property);
            Assert.AreEqual(10.0f, property.Value);
            Assert.IsFalse(manager.IsAnimated(property));
        }
コード例 #21
0
        public void ShouldImplementIList()
        {
            var property         = new AnimatableProperty <float>();
            var compositionChain = AnimationCompositionChain <float> .Create(property, SingleTraits.Instance);

            var list = (IList <AnimationInstance>)compositionChain;
            var animationInstance0 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var animationInstance1 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var animationInstance2 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var wrongInstance = AnimationInstance.Create(new TimelineGroup());

            // The enumerator is not implemented (to prevent garbage).
            Assert.That(() => { list.GetEnumerator(); }, Throws.TypeOf <NotImplementedException>());

            // Add
            Assert.That(() => list.Add(wrongInstance), Throws.ArgumentException);
            list.Add(animationInstance0);

            // Contains
            Assert.IsTrue(list.Contains(animationInstance0));
            Assert.IsFalse(list.Contains(animationInstance1));
            Assert.IsFalse(list.Contains(wrongInstance));

            // IndexOf
            Assert.AreEqual(0, list.IndexOf(animationInstance0));
            Assert.AreEqual(-1, list.IndexOf(animationInstance1));
            Assert.AreEqual(-1, list.IndexOf(wrongInstance));

            // IsReadOnly
            Assert.IsFalse(list.IsReadOnly);

            // Insert
            list.Insert(1, animationInstance1);
            Assert.That(() => list.Insert(0, wrongInstance), Throws.ArgumentException);

            // Indexer
            Assert.AreEqual(animationInstance1, list[1]);
            list[0] = animationInstance2;
            Assert.That(() => list[0] = wrongInstance, Throws.ArgumentException);

            // CopyTo
            AnimationInstance[] array = new AnimationInstance[2];
            list.CopyTo(array, 0);
            Assert.AreEqual(animationInstance2, array[0]);
            Assert.AreEqual(animationInstance1, array[1]);

            // Remove
            Assert.IsTrue(list.Remove(animationInstance2));
            Assert.AreEqual(1, list.Count);
            Assert.IsFalse(list.Remove(wrongInstance));

            // RemoveAt
            list.RemoveAt(0);
            Assert.AreEqual(0, list.Count);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
 public CommandAddKeyframes(GameObject obj, int frame, int startFrame, int endFrame, Dictionary <AnimatableProperty, List <AnimationKey> > newKeys)
 {
     gObject = obj;
     for (int i = 0; i < 6; i++)
     {
         AnimatableProperty property = (AnimatableProperty)i;
         new CommandAddKeyframeTangent(gObject, property, frame, startFrame, endFrame, newKeys[property]).Submit();
     }
 }
コード例 #24
0
        public void SetterShouldSetBaseValue()
        {
            var animatableProperty = new AnimatableProperty <float>();

            animatableProperty.Value = 123;
            Assert.IsTrue(((IAnimatableProperty <float>)animatableProperty).HasBaseValue);
            Assert.IsFalse(((IAnimatableProperty <float>)animatableProperty).IsAnimated);
            Assert.AreEqual(123, ((IAnimatableProperty <float>)animatableProperty).BaseValue);
        }
コード例 #25
0
ファイル: AnimationSet.cs プロジェクト: AnthonyMir/vrtist
 public void SetCurve(AnimatableProperty property, List <AnimationKey> keys)
 {
     if (!curves.TryGetValue(property, out Curve curve))
     {
         Debug.LogError("Curve not found : " + transform.name + " " + property.ToString());
         return;
     }
     curve.SetKeys(keys);
 }
コード例 #26
0
        public void ShouldReturnNullWhenNameIsNotFound()
        {
            var widthProperty = new AnimatableProperty <float>();
            var animatable    = new AnimatableObject("Object");

            animatable.Properties.Add("Width", widthProperty);

            Assert.IsNull(animatable.GetAnimatableProperty <float>("WrongName"));
        }
コード例 #27
0
        public void ShouldReturnNullWhenTypeDoesNotMatch()
        {
            var widthProperty = new AnimatableProperty <float>();
            var animatable    = new AnimatableObject("Object");

            animatable.Properties.Add("Width", widthProperty);

            Assert.IsNull(animatable.GetAnimatableProperty <string>("Width"));
        }
コード例 #28
0
        public void BlendGroupWithTwoAnimationsSynchronized()
        {
            var property1 = new AnimatableProperty <float> {
                Value = 123.45f
            };

            var blendGroup = new BlendGroup {
                FillBehavior = FillBehavior.Stop
            };
            var animation1 = new SingleFromToByAnimation {
                From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0)
            };
            var animation2 = new SingleFromToByAnimation {
                From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0)
            };

            blendGroup.Add(animation1);
            blendGroup.Add(animation2);
            Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
            Assert.AreEqual(1.0f, blendGroup.GetWeight(1));
            Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());

            blendGroup.SynchronizeDurations();
            Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(blendGroup, property1);

            controller.UpdateAndApply();
            Assert.AreEqual(50.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75
            manager.ApplyAnimations();
            Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
            Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

            blendGroup.SetWeight(0, 0);
            Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0
            manager.ApplyAnimations();
            Assert.AreEqual(200.0f, property1.Value);

            blendGroup.SetWeight(0, 10);
            blendGroup.SetWeight(1, 0);
            Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.Zero); // t = 1.0
            manager.ApplyAnimations();
            Assert.AreEqual(100.0f, property1.Value);

            blendGroup.SetWeight(0, 10);
            blendGroup.SetWeight(1, 1);
            Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5
            manager.ApplyAnimations();
            Assert.AreEqual(123.45f, property1.Value);
            Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
コード例 #29
0
        double[,] dc_dtheta(int frame, int n, int p, int K, List <int> requiredKeyframeIndices)
        {
            double[,] Js2 = new double[n, p];
            float dtheta = 1;

            for (int i = 0; i < 6; i++)
            {
                AnimatableProperty property = (AnimatableProperty)i;
                Curve curve = ObjectAnimation.curves[property];
                for (int k = 0; k < K; k++)
                {
                    Vector2 inTangent = curve.keys[requiredKeyframeIndices[k]].inTangent;
                    Vector2 outTangent = curve.keys[requiredKeyframeIndices[k]].outTangent;
                    float   c_plus, c_minus;

                    int j1 = 4 * (i * K + k);
                    inTangent.x += dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_plus);
                    inTangent.x -= dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_minus);
                    Js2[i, j1] = (double)((c_plus - c_minus) / dtheta);

                    int j2 = 4 * (i * K + k) + 1;
                    inTangent.y += dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_plus);
                    inTangent.y -= dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_minus);
                    Js2[i, j2] = (double)((c_plus - c_minus) / dtheta);

                    int j3 = 4 * (i * K + k) + 2;
                    outTangent.x += dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_plus);
                    outTangent.x -= dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_minus);
                    Js2[i, j3] = (double)((c_plus - c_minus) / dtheta);

                    int j4 = 4 * (i * K + k) + 3;
                    outTangent.y += dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_plus);
                    outTangent.y -= dtheta;
                    ModifyTangents(curve, requiredKeyframeIndices[k], inTangent, outTangent);
                    curve.Evaluate(frame, out c_minus);
                    Js2[i, j4] = (double)((c_plus - c_minus) / dtheta);
                }
            }
            return(Js2);
        }
コード例 #30
0
        public void ShouldImplementIList()
        {
            var property = new AnimatableProperty<float>();
              var compositionChain = AnimationCompositionChain<float>.Create(property, SingleTraits.Instance);
              var list = (IList<AnimationInstance>)compositionChain;
              var animationInstance0 = AnimationInstance<float>.Create(new SingleFromToByAnimation());
              var animationInstance1 = AnimationInstance<float>.Create(new SingleFromToByAnimation());
              var animationInstance2 = AnimationInstance<float>.Create(new SingleFromToByAnimation());
              var wrongInstance = AnimationInstance.Create(new TimelineGroup());

              // The enumerator is not implemented (to prevent garbage).
              Assert.That(() => { list.GetEnumerator(); }, Throws.TypeOf<NotImplementedException>());

              // Add
              Assert.That(() => list.Add(wrongInstance), Throws.ArgumentException);
              list.Add(animationInstance0);

              // Contains
              Assert.IsTrue(list.Contains(animationInstance0));
              Assert.IsFalse(list.Contains(animationInstance1));
              Assert.IsFalse(list.Contains(wrongInstance));

              // IndexOf
              Assert.AreEqual(0, list.IndexOf(animationInstance0));
              Assert.AreEqual(-1, list.IndexOf(animationInstance1));
              Assert.AreEqual(-1, list.IndexOf(wrongInstance));

              // IsReadOnly
              Assert.IsFalse(list.IsReadOnly);

              // Insert
              list.Insert(1, animationInstance1);
              Assert.That(() => list.Insert(0, wrongInstance), Throws.ArgumentException);

              // Indexer
              Assert.AreEqual(animationInstance1, list[1]);
              list[0] = animationInstance2;
              Assert.That(() => list[0] = wrongInstance, Throws.ArgumentException);

              // CopyTo
              AnimationInstance[] array = new AnimationInstance[2];
              list.CopyTo(array, 0);
              Assert.AreEqual(animationInstance2, array[0]);
              Assert.AreEqual(animationInstance1, array[1]);

              // Remove
              Assert.IsTrue(list.Remove(animationInstance2));
              Assert.AreEqual(1, list.Count);
              Assert.IsFalse(list.Remove(wrongInstance));

              // RemoveAt
              list.RemoveAt(0);
              Assert.AreEqual(0, list.Count);
        }
コード例 #31
0
        public void GetEnumerator()
        {
            var property = new AnimatableProperty<float>();
              var compositionChain = AnimationCompositionChain<float>.Create(property, SingleTraits.Instance);

              foreach (var animationInstance in compositionChain)
              { }

              Assert.That(() => { compositionChain.GetEnumerator(); }, Throws.Nothing);
              Assert.That(() => { ((IEnumerable<AnimationInstance>)compositionChain).GetEnumerator(); }, Throws.TypeOf<NotImplementedException>());
        }
コード例 #32
0
ファイル: Curve.cs プロジェクト: ubisoft/vrtist
 public Curve(AnimatableProperty property)
 {
     this.property     = property;
     keys              = new List <AnimationKey>();
     cachedKeysIndices = new int[GlobalState.Animation.EndFrame - GlobalState.Animation.StartFrame + 1];
     for (int i = 0; i < cachedKeysIndices.Length; i++)
     {
         cachedKeysIndices[i] = -1;
     }
     cachedValues = new float[GlobalState.Animation.EndFrame - GlobalState.Animation.StartFrame + 1];
 }
コード例 #33
0
        public void SetAnimationTime()
        {
            var manager    = new AnimationManager();
            var property   = new AnimatableProperty <float>();
            var animation  = new SingleFromToByAnimation();
            var controller = manager.StartAnimation(animation, property);

            Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);
            controller.Time = TimeSpan.FromSeconds(0.5);
            Assert.AreEqual(TimeSpan.FromSeconds(0.5), controller.Time);
            Assert.AreEqual(TimeSpan.FromSeconds(0.5), controller.AnimationInstance.Time);
        }
コード例 #34
0
        public void GetEnumerator()
        {
            var property         = new AnimatableProperty <float>();
            var compositionChain = AnimationCompositionChain <float> .Create(property, SingleTraits.Instance);

            foreach (var animationInstance in compositionChain)
            {
            }

            Assert.That(() => { compositionChain.GetEnumerator(); }, Throws.Nothing);
            Assert.That(() => { ((IEnumerable <AnimationInstance>)compositionChain).GetEnumerator(); }, Throws.TypeOf <NotImplementedException>());
        }
コード例 #35
0
        public void FromBytes(byte[] buffer, ref int index)
        {
            property = (AnimatableProperty)Converter.GetInt(buffer, ref index);
            int count = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < count; ++i)
            {
                KeyframeData keyframe = new KeyframeData();
                keyframe.FromBytes(buffer, ref index);
                keyframes.Add(keyframe);
            }
        }
コード例 #36
0
        public void BlendGroupWithOneAnimation()
        {
            var property1 = new AnimatableProperty <float> {
                Value = 123.45f
            };

            var blendGroup = new BlendGroup {
                FillBehavior = FillBehavior.Stop
            };
            var animation = new SingleFromToByAnimation {
                From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0)
            };

            blendGroup.Add(animation);
            Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
            Assert.AreEqual(1.0f, blendGroup.GetWeight(animation));

            blendGroup.SetWeight(0, 10.0f);
            Assert.AreEqual(10.0f, blendGroup.GetWeight(0));
            Assert.AreEqual(10.0f, blendGroup.GetWeight(animation));

            blendGroup.SetWeight(animation, 0.5f);
            Assert.AreEqual(0.5f, blendGroup.GetWeight(0));
            Assert.AreEqual(0.5f, blendGroup.GetWeight(animation));

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(blendGroup, property1);

            controller.UpdateAndApply();
            Assert.AreEqual(0.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(25.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(50.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(75.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(100.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(123.45f, property1.Value);
            Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
コード例 #37
0
 public CommandAddKeyframes(GameObject obj, List <GameObject> objs, int frame, int startFrame, int endFrame, List <Dictionary <AnimatableProperty, List <AnimationKey> > > newKeys)
 {
     gObject = obj;
     for (int l = 0; l < objs.Count; l++)
     {
         GameObject go = objs[l];
         for (int i = 0; i < 6; i++)
         {
             AnimatableProperty property = (AnimatableProperty)i;
             new CommandAddKeyframeTangent(go, property, frame, startFrame, endFrame, newKeys[l][property]).Submit();
         }
     }
 }
コード例 #38
0
        public void BlendGroupWithAnimationAndTimelineGroups()
        {
            var testObject = new AnimatableObject("TestObject");
              var property1 = new AnimatableProperty<float> { Value = 123.45f };
              testObject.Properties.Add("Property1", property1);

              var blendGroup = new BlendGroup
              {
            new SingleFromToByAnimation { From = 0, To = 100, TargetProperty = "Property1" },
            new TimelineGroup { new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0), TargetProperty = "Property1" }, },
              };
              blendGroup.SynchronizeDurations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, testObject);
              controller.UpdateAndApply();
              Assert.AreEqual(50.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.75));      // t = 0.75
              manager.ApplyAnimations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
              Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

              blendGroup.SetWeight(0, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.25));       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.Zero);       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 1);
              Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.5));       // t = 1.5
              manager.ApplyAnimations();
              Assert.AreEqual(AnimationState.Filling, controller.State);
              Assert.IsTrue(Numeric.AreEqual(100.0f * 10.0f / 11.0f + 300.0f * 1.0f / 11.0f, property1.Value));

              controller.Stop();
              controller.UpdateAndApply();
              Assert.AreEqual(AnimationState.Stopped, controller.State);
              Assert.AreEqual(123.45f, property1.Value);
        }
コード例 #39
0
        public void ShouldReturnAllAnimatableProperties()
        {
            var widthProperty = new AnimatableProperty<float>();
              var heightProperty = new AnimatableProperty<float>();
              var textProperty = new AnimatableProperty<string>();
              var animatable = new AnimatableObject("Object");
              animatable.Properties.Add("Width", widthProperty);
              animatable.Properties.Add("Height", heightProperty);
              animatable.Properties.Add("Text", textProperty);

              Assert.That(animatable.GetAnimatedProperties(), Has.Member(widthProperty));
              Assert.That(animatable.GetAnimatedProperties(), Has.Member(heightProperty));
              Assert.That(animatable.GetAnimatedProperties(), Has.Member(textProperty));
        }
コード例 #40
0
        public void AutoRecycleEnabled()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation();
              var controller = manager.CreateController(animation, property);

              controller.Start();
              controller.Stop();
              Assert.IsTrue(controller.IsValid);

              controller.AutoRecycleEnabled = true;

              controller.Start();
              controller.Stop();
              Assert.IsFalse(controller.IsValid);
        }
コード例 #41
0
        public void BlendGroupWithOneAnimation()
        {
            var property1 = new AnimatableProperty<float> { Value = 123.45f };

              var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop };
              var animation = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) };
              blendGroup.Add(animation);
              Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
              Assert.AreEqual(1.0f, blendGroup.GetWeight(animation));

              blendGroup.SetWeight(0, 10.0f);
              Assert.AreEqual(10.0f, blendGroup.GetWeight(0));
              Assert.AreEqual(10.0f, blendGroup.GetWeight(animation));

              blendGroup.SetWeight(animation, 0.5f);
              Assert.AreEqual(0.5f, blendGroup.GetWeight(0));
              Assert.AreEqual(0.5f, blendGroup.GetWeight(animation));

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, property1);
              controller.UpdateAndApply();
              Assert.AreEqual(0.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(25.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(50.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(75.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(123.45f, property1.Value);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
コード例 #42
0
        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);
        }
コード例 #43
0
        public void ComposeAfter()
        {
            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.AnimationInstance));
              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);
        }
コード例 #44
0
        public void SimulateAnimation()
        {
            var animatableProperty = new AnimatableProperty<float>();

              // Simulate an animation that sets IsAnimated and the AnimationValue.
              ((IAnimatableProperty<float>)animatableProperty).IsAnimated = true;
              ((IAnimatableProperty<float>)animatableProperty).AnimationValue = 999;

              Assert.IsTrue(((IAnimatableProperty<float>)animatableProperty).HasBaseValue);
              Assert.IsTrue(((IAnimatableProperty<float>)animatableProperty).IsAnimated);
              Assert.AreEqual(0, ((IAnimatableProperty)animatableProperty).BaseValue);
              Assert.AreEqual(999, ((IAnimatableProperty)animatableProperty).AnimationValue);
              Assert.AreEqual(0, ((IAnimatableProperty<float>)animatableProperty).BaseValue);
              Assert.AreEqual(999, ((IAnimatableProperty<float>)animatableProperty).AnimationValue);
              Assert.AreEqual(999, animatableProperty.Value);

              // Remove the animation.
              ((IAnimatableProperty<float>)animatableProperty).IsAnimated = false;
              Assert.IsTrue(((IAnimatableProperty<float>)animatableProperty).HasBaseValue);
              Assert.IsFalse(((IAnimatableProperty<float>)animatableProperty).IsAnimated);
              Assert.AreEqual(0, ((IAnimatableProperty<float>)animatableProperty).BaseValue);
              Assert.AreEqual(0, animatableProperty.Value);
        }
コード例 #45
0
        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);
        }
コード例 #46
0
        public void ReplaceWithFadeIn()
        {
            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.Replace(TimeSpan.FromSeconds(1.0)));
              Assert.AreEqual(100.0f, property.Value);

              // Changing the base value has no effect.
              property.Value = 150.0f;
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(150.0f, property.Value);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(175.0f, property.Value);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property.Value);

              // Start second animation using Replace.
              var animationB = new SingleFromToByAnimation
              {
            Duration = TimeSpan.Zero,
            To = 100.0f,
              };

              var controllerB = manager.CreateController(animationB, property);
              Assert.AreEqual(200.0f, property.Value);

              controllerB.Start(AnimationTransitions.Replace(controllerA.AnimationInstance, TimeSpan.FromSeconds(1.0)));
              Assert.AreEqual(200.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(100.0f, property.Value);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property.Value);
              Assert.AreEqual(AnimationState.Stopped, controllerA.State);
        }
コード例 #47
0
        public void StartAnimation()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation();
              var controller = manager.StartAnimation(animation, property);

              Assert.AreEqual(manager, controller.AnimationService);
              Assert.AreEqual(animation, controller.AnimationInstance.Animation);
              Assert.IsFalse(controller.AutoRecycleEnabled);
              Assert.IsTrue(controller.IsValid);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);
        }
コード例 #48
0
        public void SnapshotAndReplace()
        {
            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.SnapshotAndReplace());
              controller.UpdateAndApply();
              Assert.AreEqual(110.0f, property.Value);

              // Changing the base value has no effect.
              property.Value = 20.0f;
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(110.0f, property.Value);

              // Start second animation using SnapshotAndReplace.
              controller = manager.CreateController(animation, property);
              Assert.AreEqual(110.0f, property.Value);

              controller.Start(AnimationTransitions.SnapshotAndReplace());
              controller.UpdateAndApply();
              Assert.AreEqual(210.0f, property.Value);

              controller.Stop();
              controller.UpdateAndApply();
              Assert.AreEqual(20.0f, property.Value);
        }
コード例 #49
0
        public void FadeOutAnimation()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation
              {
            Duration = TimeSpan.Zero,
            To = 100.0f,
              };
              var controller = manager.StartAnimation(animation, property);
              controller.UpdateAndApply();
              Assert.AreEqual(100.0f, property.Value);
              Assert.AreEqual(AnimationState.Playing, controller.State);

              controller.Stop(TimeSpan.FromSeconds(1.0));
              Assert.AreEqual(100.0f, property.Value);
              Assert.AreEqual(AnimationState.Playing, controller.State);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(50.0f, property.Value);
              Assert.AreEqual(AnimationState.Filling, controller.State);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(0.0f, property.Value);
              Assert.AreEqual(AnimationState.Filling, controller.State);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(0.0f, property.Value);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
コード例 #50
0
 public void ShouldNotHaveEffectiveValueWhenNotAnimated()
 {
     var animatableProperty = new AnimatableProperty<float>();
       Assert.IsFalse(((IAnimatableProperty<float>)animatableProperty).IsAnimated);
 }
コード例 #51
0
        public void EmptyBlendGroup()
        {
            var property1 = new AnimatableProperty<float>();
              var blendGroup = new BlendGroup();

              Assert.That(() => blendGroup.GetWeight(0), Throws.TypeOf<ArgumentOutOfRangeException>());
              Assert.That(() => blendGroup.SetWeight(0, 1.0f), Throws.TypeOf<ArgumentOutOfRangeException>());

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, property1);
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(AnimationState.Stopped, controller.State);

              blendGroup.SynchronizeDurations();
              blendGroup.Clear();
              controller = manager.StartAnimation(blendGroup, property1);
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
コード例 #52
0
        public void ControlAnimation()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation
              {
            From = 100.0f,
            To = 200.0f,
              };
              var controller = manager.CreateController(animation, property);

              Assert.AreEqual(0.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
              Assert.IsFalse(controller.Time.HasValue);

              controller.Pause();
              Assert.AreEqual(0.0f, property.Value);
              Assert.IsTrue(controller.IsPaused);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
              Assert.IsFalse(controller.Time.HasValue);

              controller.Start();
              controller.UpdateAndApply();
              Assert.AreEqual(100.0f, property.Value);
              Assert.IsTrue(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property.Value);
              Assert.IsTrue(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);

              controller.Resume();
              Assert.AreEqual(100.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(150.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.5), controller.Time);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(1.0), controller.Time);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Filling, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), controller.Time);

              Assert.That(() => controller.Start(), Throws.TypeOf<AnimationException>());

              controller.Stop();
              controller.UpdateAndApply();
              Assert.AreEqual(0.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
              Assert.IsFalse(controller.Time.HasValue);

              // Restart
              controller.Start();
              controller.UpdateAndApply();
              Assert.AreEqual(100.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);

              manager.Update(TimeSpan.FromSeconds(0.5));
              manager.ApplyAnimations();
              Assert.AreEqual(150.0f, property.Value);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Playing, controller.State);
              Assert.AreEqual(TimeSpan.FromSeconds(0.5), controller.Time);
        }
コード例 #53
0
    // OnUnload() is called when the GameObject is removed from the IGameObjectService.
    protected override void OnUnload()
    {
      // Remove models from scene.
      foreach (var model in _models)
      {
        model.Parent.Children.Remove(_modelPrototype);
        model.Dispose(false);
      }

      // Remove rigid bodies from physics simulation.
      foreach (var body in _bodies)
        body.Simulation.RigidBodies.Remove(body);

      _models.Clear();
      _bodies.Clear();

      // Remove prototype.
      _modelPrototype.Dispose(false);
      _modelPrototype = null;
      _bodyPrototype = null;

      // Stop animation.
      var animationService = _services.GetInstance<IAnimationService>();
      animationService.StopAnimation(_glowIntensity);
      _glowIntensity = null;
    }
コード例 #54
0
        public void ShouldDoNothingIfInvalid()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation();
              var controller = manager.CreateController(animation, property);

              controller.Recycle();
              Assert.IsFalse(controller.IsValid);

              // The following has no effect.
              controller.AutoRecycleEnabled = false;
              controller.Time = TimeSpan.Zero;
              controller.AutoRecycle();
              controller.Recycle();
              controller.Pause();
              controller.Resume();
              controller.Stop();
              controller.Stop(TimeSpan.Zero);
              controller.Stop(TimeSpan.FromSeconds(1.0));

              // Only Start and UpdateAndApply should throw an exceptions.
              Assert.That(() => controller.Start(), Throws.TypeOf<AnimationException>());
              Assert.That(() => controller.UpdateAndApply(), Throws.TypeOf<AnimationException>());
        }
コード例 #55
0
        public void Speed()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation
              {
            Duration = TimeSpan.FromSeconds(1),
            From = 100.0f,
            To = 200.0f,
              };

              var controller = manager.StartAnimation(animation, property);
              controller.AutoRecycle();
              controller.UpdateAndApply();
              Assert.AreEqual(1.0f, controller.Speed);

              // Normal speed.
              controller.Speed = 1.0f;
              Assert.AreEqual(100.0f, property.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(125.0f, property.Value);

              // Double speed.
              controller.Speed = 2.0f;
              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(175.0f, property.Value);

              // Half speed.
              controller.Speed = 0.5f;
              manager.Update(TimeSpan.FromSeconds(0.2));
              manager.ApplyAnimations();
              Assert.AreEqual(185.0f, property.Value);

              // Negative speed.
              controller.Speed = -0.5f;
              manager.Update(TimeSpan.FromSeconds(0.2));
              manager.ApplyAnimations();
              Assert.AreEqual(175.0f, property.Value);

              controller.Stop();
              Assert.IsNaN(controller.Speed);
        }
コード例 #56
0
        public void StopAnimationImmediately()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation
              {
            From = 100.0f,
            To = 200.0f,
              };
              var controller = manager.StartAnimation(animation, property);
              controller.UpdateAndApply();
              Assert.AreEqual(100.0f, property.Value);

              controller.Stop(TimeSpan.Zero);
              controller.UpdateAndApply();
              Assert.AreEqual(0.0f, property.Value);
        }
コード例 #57
0
 public void ShouldHaveBaseValue()
 {
     var animatableProperty = new AnimatableProperty<float>();
       Assert.IsTrue(((IAnimatableProperty<float>)animatableProperty).HasBaseValue);
 }
コード例 #58
0
        public void SetAnimationTime()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation();
              var controller = manager.StartAnimation(animation, property);

              Assert.AreEqual(TimeSpan.FromSeconds(0.0), controller.Time);
              controller.Time = TimeSpan.FromSeconds(0.5);
              Assert.AreEqual(TimeSpan.FromSeconds(0.5), controller.Time);
              Assert.AreEqual(TimeSpan.FromSeconds(0.5), controller.AnimationInstance.Time);
        }
コード例 #59
0
        public void RecycleController()
        {
            var manager = new AnimationManager();
              var property = new AnimatableProperty<float>();
              var animation = new SingleFromToByAnimation();
              var controller = manager.CreateController(animation, property);

              controller.Recycle();
              Assert.AreEqual(manager, controller.AnimationService);
              Assert.AreEqual(null, controller.AnimationInstance);
              Assert.IsFalse(controller.IsValid);
              Assert.IsFalse(controller.IsPaused);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
              Assert.IsFalse(controller.Time.HasValue);
        }
コード例 #60
0
        public void BlendGroupWithTwoAnimationsSynchronized()
        {
            var property1 = new AnimatableProperty<float> { Value = 123.45f };

              var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop };
              var animation1 = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) };
              var animation2 = new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0) };
              blendGroup.Add(animation1);
              blendGroup.Add(animation2);
              Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
              Assert.AreEqual(1.0f, blendGroup.GetWeight(1));
              Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());

              blendGroup.SynchronizeDurations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, property1);
              controller.UpdateAndApply();
              Assert.AreEqual(50.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.75));      // t = 0.75
              manager.ApplyAnimations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
              Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

              blendGroup.SetWeight(0, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.25));       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.Zero);       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 1);
              Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.5));       // t = 1.5
              manager.ApplyAnimations();
              Assert.AreEqual(123.45f, property1.Value);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }