예제 #1
0
        public static void GenericTests<T>(T fbxCollection, FbxManager manager) where T : FbxCollection
        {
            // TODO: FbxScene has a member count of 3 instead of one (even after clearing), is this normal?
            int initialMemberCount = fbxCollection.GetMemberCount ();

            // test AddMember
            FbxObject obj = FbxObject.Create (manager, "");
            bool result = fbxCollection.AddMember (obj);
            Assert.IsTrue (result);
            Assert.AreEqual(initialMemberCount+1, fbxCollection.GetMemberCount());

            // test Clear
            fbxCollection.Clear ();
            Assert.AreEqual (initialMemberCount, fbxCollection.GetMemberCount());

            // test GetAnimLayerMember()
            fbxCollection.AddMember(FbxAnimLayer.Create(manager, "animLayer"));
            var animLayer = fbxCollection.GetAnimLayerMember ();
            Assert.IsInstanceOf<FbxAnimLayer> (animLayer);

            var animLayer2 = fbxCollection.GetAnimLayerMember (0);

            Assert.AreEqual (animLayer, animLayer2);

            // check invalid
            Assert.IsNull(fbxCollection.GetAnimLayerMember (1));
            Assert.IsNull(fbxCollection.GetAnimLayerMember (-1));
        }
예제 #2
0
        public void TestIdentity()
        {
            using (FbxObject obj = FbxObject.Create(m_fbxManager, "")) {
                FbxManager fbxManager2 = obj.GetFbxManager();

                Assert.AreEqual(m_fbxManager, fbxManager2);
            }
        }
예제 #3
0
        public void FbxObjectCreateTest()
        {
            int N = 5000;

            DefaultTest(
                "FbxObjectCreate",
                N,
                10,
                () => {
                for (int i = 0; i < N; i++)
                {
                    FbxObject.Create(m_fbxManager, "");
                }
            }
                );
        }
예제 #4
0
        public void TestUsing()
        {
            // Test that the using statement works, and destroys the manager.
            FbxObject obj;

            using (var mgr = FbxManager.Create()) {
                obj = FbxObject.Create(mgr, "asdf");
            }
            Assert.That(() => { obj.GetName(); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

            // Also test explicit dispose.
            var mgr2 = FbxManager.Create();

            obj = FbxObject.Create(mgr2, "hjkl");
            mgr2.Dispose();
            Assert.That(() => { obj.GetName(); }, Throws.Exception.TypeOf <System.ArgumentNullException>());
        }
        public void BasicTests()
        {
            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<FbxBool> example: VisibilityInheritance on a node
                var node = FbxNode.Create(manager, "node");
                GenericPropertyTests <FbxPropertyBool> (node.VisibilityInheritance, node, "Visibility Inheritance", Globals.FbxVisibilityInheritanceDT);

                var property = node.VisibilityInheritance;
                property.Set(false);
                Assert.AreEqual(false, property.Get());
                Assert.AreEqual(false, property.EvaluateValue());
                Assert.AreEqual(false, property.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(false, property.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<FbxDouble> example: several of them on a Lambert shader
                var obj = FbxSurfaceLambert.Create(manager, "lambert");
                GenericPropertyTests <FbxPropertyDouble> (obj.EmissiveFactor, obj, "EmissiveFactor", Globals.FbxDoubleDT);

                var property = obj.EmissiveFactor;
                property.Set(5.0); // bool Set<float> is not accessible here!
                Assert.AreEqual(5.0, property.Get());
                Assert.AreEqual(5.0, property.EvaluateValue());
                Assert.AreEqual(5.0, property.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(5.0, property.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<Double3> example: the LclTranslation on a node
                var node = FbxNode.Create(manager, "node");
                GenericPropertyTests <FbxPropertyDouble3> (node.LclTranslation, node, "Lcl Translation", Globals.FbxLocalTranslationDT);

                var property = node.LclTranslation;
                property.Set(new FbxDouble3(1, 2, 3));
                Assert.AreEqual(new FbxDouble3(1, 2, 3), property.Get());
                Assert.AreEqual(new FbxDouble3(1, 2, 3), property.EvaluateValue());
                Assert.AreEqual(new FbxDouble3(1, 2, 3), property.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(new FbxDouble3(1, 2, 3), property.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<float> example: the LeftBarnDoor on a light
                var light = FbxLight.Create(manager, "light");
                GenericPropertyTests(light.LeftBarnDoor, light, "LeftBarnDoor", Globals.FbxFloatDT);

                var property = light.LeftBarnDoor;
                light.LeftBarnDoor.Set(5.0f);
                Assert.AreEqual(5.0f, light.LeftBarnDoor.Get());
                Assert.AreEqual(5.0f, property.EvaluateValue());
                Assert.AreEqual(5.0f, property.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(5.0f, property.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<int> example: the WorldUpType on an aim constraint
                var constraint = FbxConstraintAim.Create(manager, "constraint");
                GenericPropertyTests(constraint.WorldUpType, constraint, "WorldUpType", Globals.FbxEnumDT);

                var property = constraint.WorldUpType;
                int value    = (int)FbxConstraintAim.EWorldUp.eAimAtObjectUp;
                constraint.WorldUpType.Set(value);
                Assert.That(constraint.WorldUpType.Get(), Is.EqualTo(value));
                Assert.That(property.EvaluateValue(), Is.EqualTo(value));
                Assert.That(property.EvaluateValue(FbxTime.FromSecondDouble(5)), Is.EqualTo(value));
                Assert.That(property.EvaluateValue(FbxTime.FromSecondDouble(5), true), Is.EqualTo(value));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<FbxString> example: the description of a shader implementation
                var impl = FbxImplementation.Create(manager, "name");
                GenericPropertyTests <FbxPropertyString> (impl.RenderAPI, impl, "RenderAPI", Globals.FbxStringDT);

                var property = impl.RenderAPI;
                property.Set("a value");
                Assert.AreEqual("a value", property.Get());

                // animated strings come out as empty-string
                Assert.AreEqual("", property.EvaluateValue());
                Assert.AreEqual("", property.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual("", property.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT for FbxTexture enums EBlendMode and EWrapMode
                var tex = FbxTexture.Create(manager, "tex");

                FbxPropertyTest.GenericPropertyTests(tex.CurrentTextureBlendMode, tex, "CurrentTextureBlendMode", Globals.FbxEnumDT);
                tex.CurrentTextureBlendMode.Set(FbxTexture.EBlendMode.eAdditive);
                Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.Get());
                Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.EvaluateValue());
                Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.EvaluateValue(FbxTime.FromSecondDouble(5), true));

                FbxPropertyTest.GenericPropertyTests(tex.WrapModeU, tex, "WrapModeU", Globals.FbxEnumDT);
                tex.WrapModeU.Set(FbxTexture.EWrapMode.eClamp);
                Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.Get());
                Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.EvaluateValue());
                Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<FbxNull.ELook>
                var null1 = FbxNull.Create(manager, "null1");

                FbxPropertyTest.GenericPropertyTests(null1.Look, null1, "Look", Globals.FbxEnumDT);
                null1.Look.Set(FbxNull.ELook.eCross);
                Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.Get());
                Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.EvaluateValue());
                Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<FbxMarker.ELook>
                var marker1 = FbxMarker.Create(manager, "marker1");

                FbxPropertyTest.GenericPropertyTests(marker1.Look, marker1, "Look", Globals.FbxEnumDT);
                marker1.Look.Set(FbxMarker.ELook.eCapsule);
                Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.Get());
                Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.EvaluateValue());
                Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT for FbxCamera enum EProjectionType
                var camera = FbxCamera.Create(manager, "camera");

                FbxPropertyTest.GenericPropertyTests(camera.ProjectionType, camera, "CameraProjectionType", Globals.FbxEnumDT);
                camera.ProjectionType.Set(FbxCamera.EProjectionType.ePerspective);
                Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.Get());
                Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.EvaluateValue());
                Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT for FbxCamera enum EGateFit
                var camera = FbxCamera.Create(manager, "camera");

                FbxPropertyTest.GenericPropertyTests(camera.GateFit, camera, "GateFit", Globals.FbxEnumDT);
                camera.GateFit.Set(FbxCamera.EGateFit.eFitHorizontal);
                Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.Get());
                Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.EvaluateValue());
                Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT<EInheritType>
                var node = FbxNode.Create(manager, "node");

                FbxPropertyTest.GenericPropertyTests(node.InheritType, node, "InheritType", Globals.FbxEnumDT);
                node.InheritType.Set(FbxTransform.EInheritType.eInheritRSrs);
                Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.Get());
                Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.EvaluateValue());
                Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // FbxPropertyT for FbxLight enums
                var light = FbxLight.Create(manager, "light");

                FbxPropertyTest.GenericPropertyTests(light.LightType, light, "LightType", Globals.FbxEnumDT);
                light.LightType.Set(FbxLight.EType.eSpot);
                Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.Get());
                Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.EvaluateValue());
                Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.EvaluateValue(FbxTime.FromSecondDouble(5), true));

                FbxPropertyTest.GenericPropertyTests(light.AreaLightShape, light, "AreaLightShape", Globals.FbxEnumDT);
                light.AreaLightShape.Set(FbxLight.EAreaLightShape.eSphere);
                Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.Get());
                Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.EvaluateValue());
                Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.EvaluateValue(FbxTime.FromSecondDouble(5), true));

                FbxPropertyTest.GenericPropertyTests(light.DecayType, light, "DecayType", Globals.FbxEnumDT);
                light.DecayType.Set(FbxLight.EDecayType.eCubic);
                Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.Get());
                Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.EvaluateValue());
                Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.EvaluateValue(FbxTime.FromSecondDouble(5)));
                Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.EvaluateValue(FbxTime.FromSecondDouble(5), true));
            }

            using (var manager = FbxManager.Create()) {
                // Test all the create and destroy operations
                FbxProperty root, child;
                var         obj = FbxObject.Create(manager, "obj");

                Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "a"));
                Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "b", "label"));
                Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "c", "label", false));
                bool didFind;
                Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "c", "label", true, out didFind));
                Assert.IsTrue(didFind);

                root = FbxProperty.Create(obj, Globals.FbxCompoundDT, "root");

                child = FbxProperty.Create(root, Globals.FbxStringDT, "a");
                Assert.IsNotNull(child);
                Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "b", "label"));
                Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "c", "label", false));
                Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "c", "label", true, out didFind));
                Assert.IsTrue(didFind);

                child.Destroy();

                root.DestroyChildren();
                Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "c", "label", true, out didFind));
                Assert.IsFalse(didFind);

                root.DestroyRecursively();
            }
        }
        // tests that should work for any subclass of FbxProperty
        public static void GenericPropertyTests <T>(T property, FbxObject parent, string propertyName, FbxDataType dataType) where T : FbxProperty
        {
            Assert.IsTrue(property.IsValid());
            Assert.AreEqual(dataType, property.GetPropertyDataType());
            Assert.AreEqual(propertyName, property.GetName());
            Assert.AreEqual(propertyName, property.ToString());
            Assert.AreEqual(propertyName, property.GetHierarchicalName());
            Assert.AreEqual(propertyName, property.GetLabel(true));
            property.SetLabel("label");
            Assert.AreEqual("label", property.GetLabel());
            Assert.AreEqual(parent, property.GetFbxObject());
            Assert.AreEqual(property.GetFbxObject(), parent); // test it both ways just in case equals is busted

            // test the flags using the animatable flag
            property.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true);
            Assert.IsTrue(property.GetFlag(FbxPropertyFlags.EFlags.eAnimatable));
            Assert.AreNotEqual(0, property.GetFlags() | FbxPropertyFlags.EFlags.eAnimatable);
            property.SetFlagInheritType(FbxPropertyFlags.EFlags.eAnimatable, FbxPropertyFlags.EInheritType.eInherit);
            Assert.AreEqual(FbxPropertyFlags.EInheritType.eInherit, property.GetFlagInheritType(FbxPropertyFlags.EFlags.eAnimatable));

            // not clear when this ever returns true: whether we set animatable
            // to true or false it says it has the default value.
            Assert.IsFalse(property.ModifiedFlag(FbxPropertyFlags.EFlags.eAnimatable));

            // Test setting the value with the generic float accessor.
            // The value may not round-trip: a bool property will go to 1.0
            property.Set(5.0f);
            TestGetter(property.GetFloat());
            TestGetter(property.GetBool());
            TestGetter(property.GetDouble());
            TestGetter(property.GetFbxColor());
            TestGetter(property.GetFbxDouble3());
            TestGetter(property.GetString());
            TestGetter(property.GetInt());

            // Test setting the value with color accessor
            property.Set(new FbxColor());

            // test GetCurve(). Just make sure it doesn't crash. We can't
            // generically test actually getting curves, because the details
            // (channel names etc) depend on the type of property and its
            // flags.
            FbxAnimLayer layer = FbxAnimLayer.Create(parent, "layer");

            property.GetCurve(layer);
            property.GetCurve(layer, true);
            property.GetCurve(layer, "asdf");
            property.GetCurve(layer, "asdf", true);
            property.GetCurve(layer, "asdf", "hjkl", true);
            Assert.That(() => { property.GetCurve(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

            // test GetCurveNode() (make sure it doesn't crash)
            FbxAnimCurveNode curveNode = property.GetCurveNode();

            Assert.IsNull(curveNode);  // didn't create one so should be null

            curveNode = property.GetCurveNode(true);
            // TODO: figure out why the curve node doesn't get created
            //Assert.IsNotNull (curveNode);

            property.GetCurveNode(FbxAnimStack.Create(parent, "anim stack"));
            property.GetCurveNode(FbxAnimStack.Create(parent, "anim stack"), true);
            property.GetCurveNode(FbxAnimLayer.Create(parent, "anim layer"));
            property.GetCurveNode(FbxAnimLayer.Create(parent, "anim layer"), true);

            Assert.That(() => { property.GetCurveNode((FbxAnimStack)null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());
            Assert.That(() => { property.GetCurveNode((FbxAnimLayer)null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

            using (FbxManager manager = FbxManager.Create()) {
                // Test ConnectSrcObject functions
                FbxObject obj    = FbxObject.Create(manager, "obj");
                bool      result = property.ConnectSrcObject(obj);
                Assert.IsTrue(result);
                Assert.IsTrue(property.IsConnectedSrcObject(obj));
                Assert.AreEqual(1, property.GetSrcObjectCount());
                Assert.AreEqual(obj, property.GetSrcObject());
                Assert.AreEqual(obj, property.GetSrcObject(0));
                Assert.AreEqual(obj, property.FindSrcObject("obj"));
                Assert.IsNull(property.FindSrcObject("obj", 1));
                Assert.That(() => { property.FindSrcObject(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

                Assert.IsTrue(property.DisconnectSrcObject(obj));
                Assert.IsFalse(property.IsConnectedSrcObject(obj));

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

                Assert.IsTrue(property.ConnectSrcObject(obj, FbxConnection.EType.eData));

                Assert.IsTrue(property.DisconnectAllSrcObject());

                // Test ConnectDstObject functions
                result = property.ConnectDstObject(obj);
                Assert.IsTrue(result);
                Assert.IsTrue(property.IsConnectedDstObject(obj));
                Assert.AreEqual(1, property.GetDstObjectCount());
                Assert.AreEqual(obj, property.GetDstObject());
                Assert.AreEqual(obj, property.GetDstObject(0));
                Assert.AreEqual(obj, property.FindDstObject("obj"));
                Assert.IsNull(property.FindDstObject("obj", 1));
                Assert.That(() => { property.FindDstObject(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

                Assert.IsTrue(property.DisconnectDstObject(obj));
                Assert.IsFalse(property.IsConnectedDstObject(obj));

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

                Assert.IsTrue(property.ConnectDstObject(obj, FbxConnection.EType.eData));

                Assert.IsTrue(property.DisconnectAllDstObject());
            }

            // verify this in the future: will dispose destroy?
            property.Dispose();
        }
예제 #7
0
        public void TestVarious()
        {
            FbxObject obj;

            /************************************************************
            * Test selection
            ************************************************************/
            obj = CreateObject();
            Assert.IsFalse(obj.GetSelected());
            obj.SetSelected(true);
            Assert.IsTrue(obj.GetSelected());

            /************************************************************
            * Test name-related functions.
            ************************************************************/

            /*
             * We use this also for testing that string handling works.
             * Make sure we can pass const char*, FbxString, and const
             * FbxString&.
             * Make sure we can return those too (though I'm not actually
             * seeing a return of a const-ref anywhere).
             */
            // Test a function that takes const char*.
            obj = FbxObject.Create(Manager, "MyObject");
            Assert.IsNotNull(obj);

            // Test a function that returns const char*.
            Assert.AreEqual("MyObject", obj.GetName());

            // Test a function that takes an FbxString with an accent in it.
            obj.SetNameSpace("Accentué");

            // Test a function that returns FbxString.
            Assert.AreEqual("MyObject", obj.GetNameWithoutNameSpacePrefix());

            // Test a function that returns FbxString with an accent in it.
            Assert.AreEqual("Accentué", obj.GetNameSpaceOnly());

            // Test a function that takes a const char* and returns an FbxString.
            // We don't want to convert the other StripPrefix functions, which
            // modify their argument in-place.
            Assert.AreEqual("MyObject", FbxObject.StripPrefix("NameSpace::MyObject"));

            obj.SetName("new name");
            Assert.AreEqual("new name", obj.GetName());

            obj.SetInitialName("init");
            Assert.AreEqual("init", obj.GetInitialName());

            /************************************************************
            * Test shader implementations
            ************************************************************/
            using (obj = FbxObject.Create(Manager, "MyObject")) {
                var impl = FbxImplementation.Create(obj, "impl");
                Assert.IsTrue(obj.AddImplementation(impl));
                Assert.IsTrue(obj.RemoveImplementation(impl));
                Assert.IsTrue(obj.AddImplementation(impl));
                Assert.IsTrue(obj.SetDefaultImplementation(impl));
                Assert.AreEqual(impl, obj.GetDefaultImplementation());
                Assert.IsTrue(obj.HasDefaultImplementation());
            }

            /************************************************************
            * Test property functions
            ************************************************************/
            using (obj = CreateObject("theobj")) {
                using (var obj2 = CreateObject("otherobj")) {
                    // Make a property and connect it from obj to obj2.
                    var prop  = FbxProperty.Create(obj, Globals.FbxBoolDT, "maybe");
                    var prop2 = FbxProperty.Create(obj, Globals.FbxFloatDT, "probability");

                    Assert.IsTrue(obj.ConnectSrcProperty(prop));
                    Assert.IsTrue(obj.ConnectSrcProperty(prop2));
                    Assert.IsTrue(obj2.ConnectDstProperty(prop));

                    Assert.IsTrue(obj.IsConnectedSrcProperty(prop));
                    Assert.IsTrue(obj2.IsConnectedDstProperty(prop));

                    Assert.AreEqual(2, obj.GetSrcPropertyCount());
                    Assert.AreEqual(1, obj2.GetDstPropertyCount());

                    Assert.AreEqual(prop, obj.GetSrcProperty());
                    Assert.AreEqual(prop, obj.GetSrcProperty(0));
                    Assert.AreEqual(prop2, obj.GetSrcProperty(1));
                    Assert.AreEqual(prop, obj2.GetDstProperty());
                    Assert.AreEqual(prop, obj2.GetDstProperty(0));

                    Assert.AreEqual(prop, obj.FindSrcProperty("maybe"));
                    Assert.AreEqual(prop, obj2.FindDstProperty("maybe"));
                    Assert.IsFalse(obj.FindSrcProperty("maybe", 1).IsValid());
                    Assert.IsFalse(obj2.FindDstProperty("maybe", 1).IsValid());

                    // Iterating over properties
                    Assert.IsTrue(obj.GetFirstProperty().IsValid());
                    Assert.IsTrue(obj.GetNextProperty(obj.GetFirstProperty()).IsValid());
                    Assert.IsTrue(obj.GetClassRootProperty().IsValid());

                    // FindProperty
                    Assert.AreEqual(prop, obj.FindProperty("maybe"));
                    Assert.AreEqual(prop, obj.FindProperty("mayBE", false));
                    Assert.IsFalse(obj.FindProperty("mayBE", true).IsValid());
                    Assert.AreEqual(prop, obj.FindProperty("maybe", Globals.FbxBoolDT));
                    Assert.AreEqual(prop, obj.FindProperty("mayBE", Globals.FbxBoolDT, false));

                    // FindPropertyHierarchical
                    Assert.AreEqual(prop, obj.FindPropertyHierarchical("maybe"));
                    Assert.AreEqual(prop, obj.FindPropertyHierarchical("mayBE", false));
                    Assert.IsFalse(obj.FindPropertyHierarchical("mayBE", true).IsValid());
                    Assert.AreEqual(prop, obj.FindPropertyHierarchical("maybe", Globals.FbxBoolDT));
                    Assert.AreEqual(prop, obj.FindPropertyHierarchical("mayBE", Globals.FbxBoolDT, false));

                    // Disconnecting
                    int nSrc = obj.GetSrcPropertyCount();
                    int nDst = obj2.GetDstPropertyCount();

                    Assert.IsTrue(obj.DisconnectSrcProperty(prop));
                    Assert.IsTrue(obj2.DisconnectDstProperty(prop));

                    Assert.AreEqual(nSrc - 1, obj.GetSrcPropertyCount());
                    Assert.AreEqual(nDst - 1, obj2.GetDstPropertyCount());
                }
            }

            /************************************************************
            * Test object connection functions
            ************************************************************/

            // need to order them this way for FbxScene, which deletes obj if Source Object is destroyed
            using (var ownerObj = CreateObject("ownerObj")) {
                using (obj = CreateObject("obj")) {
                    // Test ConnectSrcObject functions
                    int origCount = ownerObj.GetSrcObjectCount();

                    bool result = ownerObj.ConnectSrcObject(obj);
                    Assert.IsTrue(result);
                    Assert.IsTrue(ownerObj.IsConnectedSrcObject(obj));
                    Assert.AreEqual(origCount + 1, ownerObj.GetSrcObjectCount());
                    if (origCount == 0)
                    {
                        Assert.AreEqual(obj, ownerObj.GetSrcObject());
                    }
                    else
                    {
                        // FbxScene has more than one object set as source
                        Assert.AreNotEqual(obj, ownerObj.GetSrcObject());
                    }
                    Assert.AreEqual(obj, ownerObj.GetSrcObject(origCount));
                    Assert.AreEqual(obj, ownerObj.FindSrcObject("obj"));
                    Assert.IsNull(ownerObj.FindSrcObject("obj", origCount + 1));

                    // TODO: Fix so this doesn't crash

                    /*Assert.That (() => {
                     *  ownerObj.FindSrcObject (null);
                     * }, Throws.Exception.TypeOf<System.ArgumentNullException> ());*/

                    result = ownerObj.DisconnectSrcObject(obj);
                    Assert.IsTrue(result);
                    Assert.IsFalse(ownerObj.IsConnectedSrcObject(obj));

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

                    result = ownerObj.ConnectSrcObject(obj, FbxConnection.EType.eData);
                    Assert.IsTrue(result);
                }
            }

            // need to order them this way for FbxScene, which deletes ownerObj if Destination Object is destroyed
            using (obj = CreateObject("obj")) {
                using (var ownerObj = CreateObject("ownerObj")) {
                    // Test ConnectDstObject functions
                    int origCount = ownerObj.GetDstObjectCount();

                    bool result = ownerObj.ConnectDstObject(obj);
                    Assert.IsTrue(result);
                    Assert.IsTrue(ownerObj.IsConnectedDstObject(obj));
                    Assert.AreEqual(origCount + 1, ownerObj.GetDstObjectCount());
                    if (origCount == 0)
                    {
                        Assert.AreEqual(obj, ownerObj.GetDstObject());
                    }
                    else
                    {
                        // FbxAnimCurve has the scene as a DstObject
                        Assert.AreNotEqual(obj, ownerObj.GetDstObject());
                    }
                    Assert.AreEqual(obj, ownerObj.GetDstObject(origCount));
                    Assert.AreEqual(obj, ownerObj.FindDstObject("obj"));
                    Assert.IsNull(ownerObj.FindDstObject("obj", origCount + 1));

                    // TODO: Fix so this doesn't crash

                    /*Assert.That (() => {
                     *  ownerObj.FindDstObject (null);
                     * }, Throws.Exception.TypeOf<System.ArgumentNullException> ());*/

                    result = ownerObj.DisconnectDstObject(obj);
                    Assert.IsTrue(result);
                    Assert.IsFalse(ownerObj.IsConnectedDstObject(obj));

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

                    result = ownerObj.ConnectDstObject(obj, FbxConnection.EType.eData);
                    Assert.IsTrue(result);
                }
            }
        }
예제 #8
0
        public void TestBasics()
        {
            var scene = FbxScene.Create(Manager, "scene");

            using (FbxAnimCurve curve = FbxAnimCurve.Create(scene, "curve")) {
                // test KeyModifyBegin (make sure it doesn't crash)
                curve.KeyModifyBegin();

                // test KeyAdd
                int last  = 0;
                int index = curve.KeyAdd(FbxTime.FromFrame(5), ref last);
                Assert.GreaterOrEqual(index, 0);

                // test KeyAdd null FbxTime
                Assert.That(() => { curve.KeyAdd(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());
                Assert.That(() => { curve.KeyAdd(null, ref last); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

                // test KeySet
                FbxTime keyTime = FbxTime.FromSecondDouble(3);
                curve.KeySet(index, keyTime, 5);

                // test KeyGetValue, KeyGetTime, KeyGetCount
                Assert.AreEqual(5, curve.KeyGetValue(index));
                Assert.AreEqual(keyTime, curve.KeyGetTime(index));
                Assert.AreEqual(1, curve.KeyGetCount());

                // make sure none of the variations crash
                curve.KeySet(index, new FbxTime(), 5, FbxAnimCurveDef.EInterpolationType.eInterpolationConstant
                             );
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto
                             );
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto, 4
                             );
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 3);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0, 0);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0, 0, 0);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0, 0, 0, 0);

                // test KeyModifyEnd (make sure it doesn't crash)
                curve.KeyModifyEnd();
            }

            // Also test that the AnimCurveBase can't be created.
            Assert.That(() => FbxAnimCurveBase.Create(Manager, ""), Throws.Exception.TypeOf <System.NotImplementedException>());
            Assert.That(() => FbxAnimCurveBase.Create(FbxObject.Create(Manager, ""), ""), Throws.Exception.TypeOf <System.NotImplementedException>());
        }
예제 #9
0
        public void TestBasics()
        {
            var scene = FbxScene.Create(Manager, "scene");

            using (FbxAnimCurve curve = FbxAnimCurve.Create(scene, "curve")) {
                // test KeyModifyBegin (make sure it doesn't crash)
                curve.KeyModifyBegin();

                // test KeyAdd
                int last  = 0;
                int index = curve.KeyAdd(FbxTime.FromFrame(5), ref last);
                Assert.GreaterOrEqual(index, 0);

                // test KeyAdd null FbxTime
                Assert.That(() => { curve.KeyAdd(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());
                Assert.That(() => { curve.KeyAdd(null, ref last); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

                // test KeySet
                FbxTime keyTime = FbxTime.FromSecondDouble(3);
                curve.KeySet(index, keyTime, 5);

                // test KeyGetValue, KeyGetTime, KeyGetCount
                Assert.AreEqual(5, curve.KeyGetValue(index));
                Assert.AreEqual(keyTime, curve.KeyGetTime(index));
                Assert.AreEqual(1, curve.KeyGetCount());

                // test don't crash
                FbxAnimCurveKey key = curve.KeyGet(index);
                Assert.That(key, Is.Not.Null);

                // make sure none of the variations crash
                curve.KeySet(index, new FbxTime(), 5, FbxAnimCurveDef.EInterpolationType.eInterpolationConstant
                             );
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto
                             );
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto, 4
                             );
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 3);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0, 0);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0, 0, 0);
                curve.KeySet(index, new FbxTime(), 0,
                             FbxAnimCurveDef.EInterpolationType.eInterpolationCubic,
                             FbxAnimCurveDef.ETangentMode.eTangentAuto,
                             0, 0, FbxAnimCurveDef.EWeightedMode.eWeightedAll, 0, 0, 0, 0);

                // more setter test
                curve.KeySetTangentMode(index, FbxAnimCurveDef.ETangentMode.eTangentUser);
                Assert.That(curve.KeyGetTangentMode(index), Is.EqualTo(FbxAnimCurveDef.ETangentMode.eTangentUser));
                curve.KeySetTangentMode(index, FbxAnimCurveDef.ETangentMode.eTangentGenericBreak);
                Assert.That(curve.KeyGetTangentMode(index), Is.EqualTo(FbxAnimCurveDef.ETangentMode.eTangentGenericBreak));

                // test settings key parameters
                key.SetTangentMode(FbxAnimCurveDef.ETangentMode.eTangentUser);
                // Set break is only meaningful if tangent is eTangentAuto or eTangentUser
                key.SetBreak(true);
                Assert.True(key.GetBreak());
                key.SetDataFloat(FbxAnimCurveDef.EDataIndex.eRightSlope, 1.0f);
                Assert.That(key.GetDataFloat(FbxAnimCurveDef.EDataIndex.eRightSlope), Is.EqualTo(1.0f).Within(float.Epsilon));
                key.SetBreak(false);
                Assert.False(key.GetBreak());
                //
                key.SetTangentWeightMode(FbxAnimCurveDef.EWeightedMode.eWeightedAll);
                key.SetTangentWeightMode(FbxAnimCurveDef.EWeightedMode.eWeightedAll, FbxAnimCurveDef.EWeightedMode.eWeightedAll);
                Assert.That(key.GetTangentWeightMode(), Is.EqualTo(FbxAnimCurveDef.EWeightedMode.eWeightedAll));
                //
                key.SetBreak(true);
                key.SetTangentWeightAndAdjustTangent(FbxAnimCurveDef.EDataIndex.eRightSlope, 1.0);
                key.SetTangentWeightAndAdjustTangent(FbxAnimCurveDef.EDataIndex.eNextLeftSlope, 1.0);
                key.SetTangentWeightAndAdjustTangent(FbxAnimCurveDef.EDataIndex.eWeights, 1.0);
                key.SetTangentWeightAndAdjustTangent(FbxAnimCurveDef.EDataIndex.eRightWeight, 1.0);
                key.SetTangentWeightAndAdjustTangent(FbxAnimCurveDef.EDataIndex.eNextLeftWeight, 1.0);
                key.SetBreak(false);
                //
                key.SetTangentVelocityMode(FbxAnimCurveDef.EVelocityMode.eVelocityAll);
                key.SetTangentVelocityMode(FbxAnimCurveDef.EVelocityMode.eVelocityAll, FbxAnimCurveDef.EVelocityMode.eVelocityAll);
                Assert.That(key.GetTangentVelocityMode(), Is.EqualTo(FbxAnimCurveDef.EVelocityMode.eVelocityAll));
                //
                key.SetTangentVisibility(FbxAnimCurveDef.ETangentVisibility.eTangentShowLeft);
                Assert.That(key.GetTangentVisibility(), Is.EqualTo(FbxAnimCurveDef.ETangentVisibility.eTangentShowLeft));

                // test KeyModifyEnd (make sure it doesn't crash)
                curve.KeyModifyEnd();
            }

            // Also test that the AnimCurveBase can't be created.
            Assert.That(() => FbxAnimCurveBase.Create(Manager, ""), Throws.Exception.TypeOf <System.NotImplementedException>());
            Assert.That(() => FbxAnimCurveBase.Create(FbxObject.Create(Manager, ""), ""), Throws.Exception.TypeOf <System.NotImplementedException>());
        }