Beispiel #1
0
        public void CompressEmptySrtKeyFrameAnimation4()
        {
            var random = new Random(12345);

            // Animation with 2 keyframe, which are not Identity.
            var srtKeyFrameAnimation = new SrtKeyFrameAnimation();
            var time0  = TimeSpan.FromTicks(100000);
            var value0 = new SrtTransform(random.NextVector3F(-2, 2), random.NextQuaternionF(), random.NextVector3F(-10, 10));

            var time1  = TimeSpan.FromTicks(200000);
            var value1 = new SrtTransform(random.NextVector3F(-2, 2), random.NextQuaternionF(), random.NextVector3F(-10, 10));

            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time0, value0));
            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time1, value1));

            var srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, 2, 360, 10);

            Assert.IsNotNull(srtAnimation);
            Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());

            var defaultSource = SrtTransform.Identity;
            var defaultTarget = SrtTransform.Identity;
            var result        = new SrtTransform();

            srtAnimation.GetValue(time0, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames[0].Value, result);

            srtAnimation.GetValue(time1, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames[1].Value, result);
        }
Beispiel #2
0
        public void CompressEmptySrtKeyFrameAnimation1()
        {
            // Animation with 1 keyframe, which is Identity.
              var srtKeyFrameAnimation = new SrtKeyFrameAnimation();
              var time = TimeSpan.FromTicks(100000);
              srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame<SrtTransform>(time, SrtTransform.Identity));

              var srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, 0, 0, 0);

              Assert.IsNotNull(srtAnimation);
              Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());

              var defaultSource = SrtTransform.Identity;
              var defaultTarget = SrtTransform.Identity;
              var result = new SrtTransform();
              srtAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref result);
              Assert.AreEqual(srtKeyFrameAnimation.KeyFrames[0].Value, result);

              // Only 1 channel is needed.
              int numberOfChannels = 0;
              if (srtAnimation.Scale != null)
            numberOfChannels++;
              if (srtAnimation.Rotation != null)
            numberOfChannels++;
              if (srtAnimation.Translation != null)
            numberOfChannels++;

              Assert.AreEqual(1, numberOfChannels);
        }
Beispiel #3
0
        public void CompressEmptySrtKeyFrameAnimation3()
        {
            // Animation with 2 keyframes, which are Identity.
            var srtKeyFrameAnimation = new SrtKeyFrameAnimation();
            var time0 = TimeSpan.FromTicks(100000);
            var time1 = TimeSpan.FromTicks(200000);

            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time0, SrtTransform.Identity));
            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time1, SrtTransform.Identity));

            var srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, 1, 90, 1);

            Assert.IsNotNull(srtAnimation);
            Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());

            var defaultSource = SrtTransform.Identity;
            var defaultTarget = SrtTransform.Identity;
            var result        = new SrtTransform();

            srtAnimation.GetValue(time0, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames[0].Value, result);

            srtAnimation.GetValue(time1, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames[1].Value, result);

            // Only 1 channel is needed.
            int numberOfChannels = 0;

            if (srtAnimation.Scale != null)
            {
                numberOfChannels++;
            }
            if (srtAnimation.Rotation != null)
            {
                numberOfChannels++;
            }
            if (srtAnimation.Translation != null)
            {
                numberOfChannels++;
            }

            Assert.AreEqual(1, numberOfChannels);
        }
Beispiel #4
0
        public void CompressSrtKeyFrameAnimation()
        {
            var random = new Random(12345);

            float scaleThreshold       = 0.1f;
            float rotationThreshold    = 2; // [°]
            float translationThreshold = 0.2f;

            var srtKeyFrameAnimation = new SrtKeyFrameAnimation();

            // Define a view important keyframes.
            var time0  = TimeSpan.FromTicks(100000);
            var value0 = new SrtTransform(Vector3F.One, QuaternionF.Identity, Vector3F.Zero);

            var time1  = TimeSpan.FromTicks(200000);
            var value1 = new SrtTransform(new Vector3F(2, 2, 2), QuaternionF.CreateRotationX(MathHelper.ToRadians(10)), new Vector3F(1, 1, 1));

            var time2  = TimeSpan.FromTicks(400000);
            var value2 = new SrtTransform(new Vector3F(-1, -1, -1), QuaternionF.CreateRotationX(MathHelper.ToRadians(80)), new Vector3F(10, 10, 10));

            var time3  = TimeSpan.FromTicks(500000);
            var value3 = new SrtTransform(new Vector3F(3, 3, 3), QuaternionF.CreateRotationX(MathHelper.ToRadians(-10)), new Vector3F(-2, -2, -2));

            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time0, value0));
            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time1, value1));
            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time2, value2));
            srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame <SrtTransform>(time3, value3));

            // Add random keyframes within tolerance.
            InsertRandomKeyFrames(random, srtKeyFrameAnimation, time0, time1, scaleThreshold, rotationThreshold, translationThreshold);
            InsertRandomKeyFrames(random, srtKeyFrameAnimation, time1, time2, scaleThreshold, rotationThreshold, translationThreshold);
            InsertRandomKeyFrames(random, srtKeyFrameAnimation, time2, time3, scaleThreshold, rotationThreshold, translationThreshold);

            // ---- Compress animation with tolerance.
            var srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, scaleThreshold, rotationThreshold, translationThreshold);

            Assert.IsNotNull(srtAnimation);
            Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());
            Assert.IsNotNull(srtAnimation.Scale);

            Assert.AreEqual(4, ((KeyFrameAnimation <Vector3F>)srtAnimation.Scale).KeyFrames.Count);
            Assert.AreEqual(4, ((KeyFrameAnimation <QuaternionF>)srtAnimation.Rotation).KeyFrames.Count);
            Assert.AreEqual(4, ((KeyFrameAnimation <Vector3F>)srtAnimation.Translation).KeyFrames.Count);

            var defaultSource = SrtTransform.Identity;
            var defaultTarget = SrtTransform.Identity;
            var result        = new SrtTransform();

            srtAnimation.GetValue(time0, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(value0, result);

            srtAnimation.GetValue(time1, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(value1, result);

            srtAnimation.GetValue(time2, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(value2, result);

            srtAnimation.GetValue(time3, ref defaultSource, ref defaultTarget, ref result);
            Assert.AreEqual(value3, result);

            // Take a view samples.
            const int numberOfSamples = 10;
            long      tickIncrement   = (time3 - time0).Ticks / (numberOfSamples + 1);

            for (int i = 0; i < numberOfSamples; i++)
            {
                var time = TimeSpan.FromTicks(time0.Ticks + (i + 1) * tickIncrement);

                var valueRef = new SrtTransform();
                srtKeyFrameAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueRef);

                var valueNew = new SrtTransform();
                srtAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueNew);

                Assert.IsTrue((valueRef.Scale - valueNew.Scale).Length <= scaleThreshold);
                Assert.IsTrue(QuaternionF.GetAngle(valueRef.Rotation, valueNew.Rotation) <= MathHelper.ToRadians(rotationThreshold));
                Assert.IsTrue((valueRef.Translation - valueNew.Translation).Length <= translationThreshold);
            }

            // ----- Compress animation with zero tolerance.
            srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, 0, 0, 0);

            Assert.IsNotNull(srtAnimation);
            Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());
            Assert.IsNotNull(srtAnimation.Scale);

            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames.Count, ((KeyFrameAnimation <Vector3F>)srtAnimation.Scale).KeyFrames.Count);
            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames.Count, ((KeyFrameAnimation <QuaternionF>)srtAnimation.Rotation).KeyFrames.Count);
            Assert.AreEqual(srtKeyFrameAnimation.KeyFrames.Count, ((KeyFrameAnimation <Vector3F>)srtAnimation.Translation).KeyFrames.Count);

            // Take a view samples.
            for (int i = 0; i < numberOfSamples; i++)
            {
                var time = TimeSpan.FromTicks(time0.Ticks + (i + 1) * tickIncrement);

                var valueRef = new SrtTransform();
                srtKeyFrameAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueRef);

                var valueNew = new SrtTransform();
                srtAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueNew);

                Assert.IsTrue(SrtTransform.AreNumericallyEqual(valueRef, valueNew));
            }
        }
Beispiel #5
0
        public void CompressEmptySrtKeyFrameAnimation2()
        {
            var random = new Random(12345);

              // Animation with 1 keyframe, which is not Identity.
              var srtKeyFrameAnimation = new SrtKeyFrameAnimation();
              var time = TimeSpan.FromTicks(100000);
              var value = new SrtTransform(random.NextVector3F(-2, 2), random.NextQuaternionF(), random.NextVector3F(-10, 10));
              srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame<SrtTransform>(time, value));

              var srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, 2, 360, 10);

              Assert.IsNotNull(srtAnimation);
              Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());

              var defaultSource = SrtTransform.Identity;
              var defaultTarget = SrtTransform.Identity;
              var result = new SrtTransform();
              srtAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref result);
              Assert.AreEqual(srtKeyFrameAnimation.KeyFrames[0].Value, result);
        }
Beispiel #6
0
        public void CompressSrtKeyFrameAnimation()
        {
            var random = new Random(12345);

              float scaleThreshold = 0.1f;
              float rotationThreshold = 2;  // [°]
              float translationThreshold = 0.2f;

              var srtKeyFrameAnimation = new SrtKeyFrameAnimation();

              // Define a view important keyframes.
              var time0 = TimeSpan.FromTicks(100000);
              var value0 = new SrtTransform(Vector3F.One, QuaternionF.Identity, Vector3F.Zero);

              var time1 = TimeSpan.FromTicks(200000);
              var value1 = new SrtTransform(new Vector3F(2, 2, 2), QuaternionF.CreateRotationX(MathHelper.ToRadians(10)), new Vector3F(1, 1, 1));

              var time2 = TimeSpan.FromTicks(400000);
              var value2 = new SrtTransform(new Vector3F(-1, -1, -1), QuaternionF.CreateRotationX(MathHelper.ToRadians(80)), new Vector3F(10, 10, 10));

              var time3 = TimeSpan.FromTicks(500000);
              var value3 = new SrtTransform(new Vector3F(3, 3, 3), QuaternionF.CreateRotationX(MathHelper.ToRadians(-10)), new Vector3F(-2, -2, -2));

              srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame<SrtTransform>(time0, value0));
              srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame<SrtTransform>(time1, value1));
              srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame<SrtTransform>(time2, value2));
              srtKeyFrameAnimation.KeyFrames.Add(new KeyFrame<SrtTransform>(time3, value3));

              // Add random keyframes within tolerance.
              InsertRandomKeyFrames(random, srtKeyFrameAnimation, time0, time1, scaleThreshold, rotationThreshold, translationThreshold);
              InsertRandomKeyFrames(random, srtKeyFrameAnimation, time1, time2, scaleThreshold, rotationThreshold, translationThreshold);
              InsertRandomKeyFrames(random, srtKeyFrameAnimation, time2, time3, scaleThreshold, rotationThreshold, translationThreshold);

              // ---- Compress animation with tolerance.
              var srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, scaleThreshold, rotationThreshold, translationThreshold);

              Assert.IsNotNull(srtAnimation);
              Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());
              Assert.IsNotNull(srtAnimation.Scale);

              Assert.AreEqual(4, ((KeyFrameAnimation<Vector3F>)srtAnimation.Scale).KeyFrames.Count);
              Assert.AreEqual(4, ((KeyFrameAnimation<QuaternionF>)srtAnimation.Rotation).KeyFrames.Count);
              Assert.AreEqual(4, ((KeyFrameAnimation<Vector3F>)srtAnimation.Translation).KeyFrames.Count);

              var defaultSource = SrtTransform.Identity;
              var defaultTarget = SrtTransform.Identity;
              var result = new SrtTransform();
              srtAnimation.GetValue(time0, ref defaultSource, ref defaultTarget, ref result);
              Assert.AreEqual(value0, result);

              srtAnimation.GetValue(time1, ref defaultSource, ref defaultTarget, ref result);
              Assert.AreEqual(value1, result);

              srtAnimation.GetValue(time2, ref defaultSource, ref defaultTarget, ref result);
              Assert.AreEqual(value2, result);

              srtAnimation.GetValue(time3, ref defaultSource, ref defaultTarget, ref result);
              Assert.AreEqual(value3, result);

              // Take a view samples.
              const int numberOfSamples = 10;
              long tickIncrement = (time3 - time0).Ticks / (numberOfSamples + 1);
              for (int i = 0; i < numberOfSamples; i++)
              {
            var time = TimeSpan.FromTicks(time0.Ticks + (i + 1) * tickIncrement);

            var valueRef = new SrtTransform();
            srtKeyFrameAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueRef);

            var valueNew = new SrtTransform();
            srtAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueNew);

            Assert.IsTrue((valueRef.Scale - valueNew.Scale).Length <= scaleThreshold);
            Assert.IsTrue(QuaternionF.GetAngle(valueRef.Rotation, valueNew.Rotation) <= MathHelper.ToRadians(rotationThreshold));
            Assert.IsTrue((valueRef.Translation - valueNew.Translation).Length <= translationThreshold);
              }

              // ----- Compress animation with zero tolerance.
              srtAnimation = AnimationHelper.Compress(srtKeyFrameAnimation, 0, 0, 0);

              Assert.IsNotNull(srtAnimation);
              Assert.AreEqual(srtKeyFrameAnimation.GetTotalDuration(), srtAnimation.GetTotalDuration());
              Assert.IsNotNull(srtAnimation.Scale);

              Assert.AreEqual(srtKeyFrameAnimation.KeyFrames.Count, ((KeyFrameAnimation<Vector3F>)srtAnimation.Scale).KeyFrames.Count);
              Assert.AreEqual(srtKeyFrameAnimation.KeyFrames.Count, ((KeyFrameAnimation<QuaternionF>)srtAnimation.Rotation).KeyFrames.Count);
              Assert.AreEqual(srtKeyFrameAnimation.KeyFrames.Count, ((KeyFrameAnimation<Vector3F>)srtAnimation.Translation).KeyFrames.Count);

              // Take a view samples.
              for (int i = 0; i < numberOfSamples; i++)
              {
            var time = TimeSpan.FromTicks(time0.Ticks + (i + 1) * tickIncrement);

            var valueRef = new SrtTransform();
            srtKeyFrameAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueRef);

            var valueNew = new SrtTransform();
            srtAnimation.GetValue(time, ref defaultSource, ref defaultTarget, ref valueNew);

            Assert.IsTrue(SrtTransform.AreNumericallyEqual(valueRef, valueNew));
              }
        }