Пример #1
0
        public override void TestDisposeDestroy()
        {
            // Because we can't build a recursive structure of anim curves,
            // this test is much simpler than the usual FbxObject test.
            var curve = CreateObject("a");

            DisposeTester.TestDispose(curve);
            using (CreateObject("b"));

            curve = CreateObject("c");
            curve.Destroy();
            Assert.That(() => curve.GetName(), Throws.Exception.TypeOf <System.ArgumentNullException>());

            // we can't destroy recursively, but we still get the flag
            curve = CreateObject("d");
            curve.Destroy(false);
        }
Пример #2
0
        public void TestBasics()
        {
            var table = FbxBindingTable.Create(Manager, "table");

            // Call the getters, make sure they get.
            GetSetProperty(table.DescAbsoluteURL, "file:///dev/null");
            GetSetProperty(table.DescRelativeURL, "shader.glsl");
            GetSetProperty(table.DescTAG, "user");

            // Test dispose.
            var entry = table.AddNewEntry();

            DisposeTester.TestDispose(entry);

            // Test the views.
            entry = table.AddNewEntry();

            var propertyView = new FbxPropertyEntryView(entry, false);

            Assert.IsFalse(propertyView.IsValid());
            DisposeTester.TestDispose(propertyView);

            propertyView = new FbxPropertyEntryView(entry, true, true);
            Assert.IsTrue(propertyView.IsValid());
            Assert.AreEqual("FbxPropertyEntry", propertyView.EntryType());
            propertyView.SetProperty("property");
            Assert.AreEqual("property", propertyView.GetProperty());

            var semanticView = new FbxSemanticEntryView(entry, false);

            Assert.IsFalse(semanticView.IsValid());
            DisposeTester.TestDispose(semanticView);

            semanticView = new FbxSemanticEntryView(entry, false, true);
            Assert.IsTrue(semanticView.IsValid());
            Assert.AreEqual("FbxSemanticEntry", semanticView.EntryType());
            semanticView.SetSemantic("semantic");
            Assert.AreEqual("semantic", semanticView.GetSemantic());
            Assert.AreEqual(0, semanticView.GetIndex());
            Assert.AreEqual("semantic", semanticView.GetSemantic(false));
        }
Пример #3
0
        public void TestBasics()
        {
            // just make sure it doesn't crash
            new FbxTimeSpan();
            new FbxTimeSpan(FbxTime.FromFrame(1), FbxTime.FromFrame(2));

            // test dispose
            DisposeTester.TestDispose(new FbxTimeSpan());
            using (new FbxTimeSpan(FbxTime.FromFrame(1), FbxTime.FromFrame(2))) { }

            Assert.That(() => { new FbxTimeSpan(null, null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

            // test Set/Get
            FbxTimeSpan timeSpan = new FbxTimeSpan();

            timeSpan.Set(FbxTime.FromFrame(2), FbxTime.FromFrame(3));
            Assert.AreEqual(FbxTime.FromFrame(2), timeSpan.GetStart());
            Assert.AreEqual(FbxTime.FromFrame(3), timeSpan.GetStop());
            Assert.That(() => { timeSpan.Set(null, null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());
            timeSpan.SetStart(FbxTime.FromFrame(1));
            Assert.AreEqual(FbxTime.FromFrame(1), timeSpan.GetStart());
            timeSpan.SetStop(FbxTime.FromFrame(4));
            Assert.AreEqual(FbxTime.FromFrame(4), timeSpan.GetStop());

            // test other functions
            Assert.AreEqual(FbxTime.FromFrame(3), timeSpan.GetDuration());
            Assert.AreEqual(FbxTime.FromFrame(3), timeSpan.GetSignedDuration());
            Assert.AreEqual(1, timeSpan.GetDirection());
            Assert.IsTrue(timeSpan.IsInside(FbxTime.FromFrame(2)));

            var timeSpan2 = new FbxTimeSpan(FbxTime.FromFrame(2), FbxTime.FromFrame(10));

            Assert.AreEqual(new FbxTimeSpan(FbxTime.FromFrame(2), FbxTime.FromFrame(4)), timeSpan.Intersect(timeSpan2));

            timeSpan.UnionAssignment(timeSpan2);
            Assert.AreEqual(new FbxTimeSpan(FbxTime.FromFrame(1), FbxTime.FromFrame(10)), timeSpan);

            new FbxTimeSpan(FbxTime.FromFrame(0), FbxTime.FromFrame(1)).UnionAssignment(timeSpan2, 1);
        }
Пример #4
0
        public void BasicTests()
        {
            FbxQuaternion u, v;

            // make sure the no-arg constructor doesn't crash
            new FbxQuaternion();

            // test dispose
            using (new FbxQuaternion()) { }
            DisposeTester.TestDispose(new FbxQuaternion());

            // Test other constructors
            v = new FbxQuaternion(0.1, 0.2, 0.3, 0.4);
            u = new FbxQuaternion(v);
            Assert.AreEqual(v, u);
            u[0] = 0.5;
            Assert.AreEqual(0.5, u[0]);
            Assert.AreEqual(0.1, v[0]); // check that setting u doesn't set v

            // axis-angle constructor and setter
            v = new FbxQuaternion(new FbxVector4(1, 2, 3), 90);
            u = new FbxQuaternion();
            u.SetAxisAngle(new FbxVector4(1, 2, 3), 90);
            Assert.AreEqual(u, v);

            // euler
            v = new FbxQuaternion();
            v.ComposeSphericalXYZ(new FbxVector4(20, 30, 40));
            var euler = v.DecomposeSphericalXYZ();

            Assert.That(euler.X, Is.InRange(19.99, 20.01));
            Assert.That(euler.Y, Is.InRange(29.99, 30.01));
            Assert.That(euler.Z, Is.InRange(39.99, 40.01));
            Assert.AreEqual(0, euler.W);

            v = new FbxQuaternion(0.1, 0.2, 0.3);
            Assert.AreEqual(0.1, v[0]);
            Assert.AreEqual(0.2, v[1]);
            Assert.AreEqual(0.3, v[2]);
            Assert.AreEqual(1, v[3]); // w is assumed to be a homogenous coordinate

            v.Set(0.9, 0.8, 0.7, 0.6);
            Assert.AreEqual(0.9, v[0]);
            Assert.AreEqual(0.8, v[1]);
            Assert.AreEqual(0.7, v[2]);
            Assert.AreEqual(0.6, v[3]);
            v.Set(0.9, 0.8, 0.7);
            Assert.AreEqual(0.9, v[0]);
            Assert.AreEqual(0.8, v[1]);
            Assert.AreEqual(0.7, v[2]);

            v.SetAt(1, 2);
            Assert.AreEqual(2, v.GetAt(1));

            // Test operator[]
            v    = new FbxQuaternion();
            v[0] = 0.1;
            Assert.AreEqual(0.1, v[0]);
            v[1] = 0.2;
            Assert.AreEqual(0.2, v[1]);
            v[2] = 0.3;
            Assert.AreEqual(0.3, v[2]);
            v[3] = 0.4;
            Assert.AreEqual(0.4, v[3]);
            v.SetAt(3, 0.5);
            Assert.AreEqual(0.5, v.GetAt(3));
            Assert.That(() => v[-1], Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v[4], Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v.GetAt(-1), Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v.GetAt(4), Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v[-1] = 0.5, Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v[4]  = 0.5, Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v.SetAt(-1, 0.5), Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());
            Assert.That(() => v.SetAt(4, 0.5), Throws.Exception.TypeOf <System.ArgumentOutOfRangeException>());

            // Test W/X/Y/Z
            v.X = 0.1;
            Assert.AreEqual(0.1, v.X);
            v.Y = 0.2;
            Assert.AreEqual(0.2, v.Y);
            v.Z = 0.3;
            Assert.AreEqual(0.3, v.Z);
            v.W = 0.4;
            Assert.AreEqual(0.4, v.W);

            // call the multiply/divide/add/sub operators, make sure they're vaguely sane
            u = new FbxQuaternion(v);
            v = v * v;
            Assert.AreNotEqual(0, u.Compare(v, 1e-15)); // test compare can return false
            v = v * 9;
            v = 9 * v;
            v = v + 5;
            v = v - 5;                        // undo v + 5
            v = v + u;
            v = v - u;                        // undo v + u
            v = v / 81;                       // undo 9 * (v * 9)
            v = v / u;                        // undo v*v
            Assert.AreEqual(0, u.Compare(v)); // u and v are the same up to rounding
            Assert.AreEqual(u * u, u.Product(u));

            // unary negate and dot product
            Assert.AreEqual(0, (-u).Compare(-v));
            Assert.AreEqual(-0.3, v.DotProduct(-v), 1e-6);
            Assert.AreEqual(System.Math.Sqrt(0.3), v.Length(), 1e-6);
            v.Normalize();
            Assert.AreEqual(1, v.DotProduct(v), 1e-6);

            // various others where we assume that FBX works, just test that they don't crash
            v.Conjugate();
            v.Inverse();
            v.Slerp(u, 0.5);
        }
Пример #5
0
        public void TestBasics()
        {
            // try the static functions
            var mode = FbxTime.GetGlobalTimeMode();

            FbxTime.SetGlobalTimeMode(FbxTime.EMode.ePAL);
            Assert.AreEqual(FbxTime.EMode.ePAL, FbxTime.GetGlobalTimeMode());
            FbxTime.SetGlobalTimeMode(mode);

            var protocol = FbxTime.GetGlobalTimeProtocol();

            FbxTime.SetGlobalTimeProtocol(FbxTime.EProtocol.eSMPTE);
            Assert.AreEqual(FbxTime.EProtocol.eSMPTE, FbxTime.GetGlobalTimeProtocol());
            FbxTime.SetGlobalTimeProtocol(protocol);

            Assert.AreEqual(24, FbxTime.GetFrameRate(FbxTime.EMode.eFrames24));
            Assert.AreEqual(FbxTime.EMode.eFrames24, FbxTime.ConvertFrameRateToTimeMode(24));
            Assert.AreEqual(FbxTime.EMode.eFrames24, FbxTime.ConvertFrameRateToTimeMode(24.01, 0.1));
            Assert.AreEqual(FbxTime.EMode.eDefaultMode, FbxTime.ConvertFrameRateToTimeMode(24.1, 0.01));

            TestGetter(FbxTime.GetOneFrameValue());
            TestGetter(FbxTime.GetOneFrameValue(FbxTime.EMode.ePAL));

            Assert.IsFalse(FbxTime.IsDropFrame());
            Assert.IsTrue(FbxTime.IsDropFrame(FbxTime.EMode.eNTSCDropFrame));

            // just make sure it doesn't crash
            new FbxTime();

            // test dispose
            DisposeTester.TestDispose(new FbxTime());
            using (new FbxTime()) {}

            // try the extension constructors
            Assert.AreEqual(5, FbxTime.FromRaw(5).GetRaw());
            Assert.AreEqual(5, FbxTime.FromMilliSeconds(5000).GetSecondDouble());
            Assert.AreEqual(5, FbxTime.FromSecondDouble(5).GetSecondDouble());
            Assert.AreEqual(126210.02, FbxTime.FromTime(pSecond: 7, pHour: 1, pMinute: 10, pResidual: 2).GetFrameCountPrecise());
            Assert.AreEqual(5, FbxTime.FromFrame(5).GetFrameCountPrecise());
            Assert.AreEqual(5.125, FbxTime.FromFramePrecise(5.125).GetFrameCountPrecise());
            Assert.AreEqual(5, FbxTime.FromRaw(5).GetRaw());
            Assert.AreEqual(126211.2, FbxTime.FromFrame(105176, FbxTime.EMode.ePAL).GetFrameCountPrecise());
            Assert.AreEqual(126211.8, FbxTime.FromFramePrecise(105176.5, FbxTime.EMode.ePAL).GetFrameCountPrecise());
            Assert.AreEqual(126211.8, FbxTime.FromTimeString("105176.5", FbxTime.EMode.ePAL).GetFrameCountPrecise());

            // try breaking a time down
            var t = FbxTime.FromTime(pSecond: 7, pHour: 1, pMinute: 10, pField: 4, pResidual: 2);

            Assert.AreEqual(1, t.GetHourCount());
            Assert.AreEqual(70, t.GetMinuteCount());
            Assert.AreEqual(4207, t.GetSecondCount());
            Assert.AreEqual(4207067, t.GetMilliSeconds());
            Assert.AreEqual(126212, t.GetFrameCount());
            Assert.AreEqual(105176, t.GetFrameCount(FbxTime.EMode.ePAL));
            Assert.AreEqual(252424.04, t.GetFrameCountPrecise(FbxTime.EMode.eFrames60));
            Assert.AreEqual(252424, t.GetFieldCount());
            Assert.AreEqual(210353, t.GetFieldCount(FbxTime.EMode.ePAL));
            Assert.AreEqual(2, t.GetResidual());
            Assert.AreEqual(68, t.GetResidual(FbxTime.EMode.ePAL));
            Assert.AreEqual(':', t.GetFrameSeparator());
            Assert.AreEqual(':', t.GetFrameSeparator(FbxTime.EMode.ePAL));

            int h, m, s, frame, field, residual;

            t.GetTime(out h, out m, out s, out frame, out field, out residual);
            Assert.AreEqual(1, h);
            Assert.AreEqual(10, m);
            Assert.AreEqual(2, frame);
            Assert.AreEqual(0, field);
            Assert.AreEqual(2, residual);

            t.GetTime(out h, out m, out s, out frame, out field, out residual, FbxTime.EMode.ePAL);
            Assert.AreEqual(1, h);
            Assert.AreEqual(10, m);
            Assert.AreEqual(1, frame);
            Assert.AreEqual(1, field);
            Assert.AreEqual(68, residual);

            Assert.AreEqual("126212*", t.GetTimeString());
            Assert.AreEqual("126212*", t.GetTimeString(FbxTime.EElement.eSeconds));
            Assert.AreEqual("001:10:07", t.GetTimeString(pEnd: FbxTime.EElement.eSeconds, pTimeFormat: FbxTime.EProtocol.eSMPTE));

            Assert.AreEqual("126212", t.GetFramedTime().GetTimeString());
            Assert.AreEqual("126212", t.GetFramedTime(false).GetTimeString());
        }