protected override FbxScene CreateScene(FbxManager manager)
        {
            // create the following node hierarchy to test:
            //       Root
            //      /    \
            // Child0    Child1
            //              |
            //            Child2
            //         /    |     \
            //    Child3  Child4  Child5
            FbxScene scene = FbxScene.Create(manager, "myScene");

            FbxNode root = FbxNode.Create(scene, "Root");

            FbxNode[] children = new FbxNode[6];
            for (int i = 0; i < children.Length; i++)
            {
                children [i] = FbxNode.Create(scene, "Child" + i);
            }

            scene.GetRootNode().AddChild(root);
            root.AddChild(children [0]);
            root.AddChild(children [1]);
            children [1].AddChild(children [2]);
            children [2].AddChild(children [3]);
            children [2].AddChild(children [4]);
            children [2].AddChild(children [5]);

            return(scene);
        }
        public void TestBasics()
        {
            var scene = FbxScene.Create(Manager, "scene");
            var node  = FbxNode.Create(scene, "node");

            /* Test all we can test with a non-composite curve node, namely one that points to
             * a lcl translation. */
            var animNode = FbxAnimCurveNode.CreateTypedCurveNode(node.LclTranslation, scene);

            Assert.IsFalse(animNode.IsComposite());
            Assert.AreEqual(3, animNode.GetChannelsCount());
            Assert.AreEqual(0, animNode.GetChannelIndex(Globals.FBXSDK_CURVENODE_COMPONENT_X));
            Assert.AreEqual(Globals.FBXSDK_CURVENODE_COMPONENT_Y, animNode.GetChannelName(1));

            var xcurve = animNode.CreateCurve(animNode.GetName(), Globals.FBXSDK_CURVENODE_COMPONENT_X);

            Assert.IsNotNull(xcurve);
            var xcurve2 = animNode.CreateCurve(animNode.GetName());

            Assert.IsNotNull(xcurve2);
            var ycurve = animNode.CreateCurve(animNode.GetName(), 1);

            Assert.IsNotNull(ycurve);

            animNode.SetChannelValue(Globals.FBXSDK_CURVENODE_COMPONENT_Z, 6);
            Assert.AreEqual(6, animNode.GetChannelValue(Globals.FBXSDK_CURVENODE_COMPONENT_Z, 0));
            Assert.AreEqual(6, animNode.GetChannelValue(2, 0));
            animNode.SetChannelValue(2, 0);

            Assert.AreEqual(2, animNode.GetCurveCount(0));
            Assert.AreEqual(1, animNode.GetCurveCount(1, animNode.GetName()));

            Assert.AreEqual(xcurve, animNode.GetCurve(0));
            Assert.AreEqual(xcurve2, animNode.GetCurve(0, 1));
            Assert.AreEqual(xcurve2, animNode.GetCurve(0, 1, animNode.GetName()));
            Assert.IsNull(animNode.GetCurve(1, 1));

            var key = xcurve.KeyAdd(FbxTime.FromSecondDouble(0));

            xcurve.KeySet(key, FbxTime.FromSecondDouble(0), 5);
            key = xcurve.KeyAdd(FbxTime.FromSecondDouble(1));
            xcurve.KeySet(key, FbxTime.FromSecondDouble(1), -5);

            Assert.IsTrue(animNode.IsAnimated());
            /* TODO: build a composite anim node and test this for real. */
            Assert.IsTrue(animNode.IsAnimated(true));

            var timespan = new FbxTimeSpan();

            Assert.IsTrue(animNode.GetAnimationInterval(timespan));
            Assert.AreEqual(FbxTime.FromSecondDouble(0), timespan.GetStart());
            Assert.AreEqual(FbxTime.FromSecondDouble(1), timespan.GetStop());

            /* Get a property that isn't a Double3; add a channel for it. */
            var boolNode = FbxAnimCurveNode.CreateTypedCurveNode(node.VisibilityInheritance, scene);

            Assert.IsFalse(boolNode.IsComposite());
            Assert.IsFalse(boolNode.IsAnimated());
            Assert.IsTrue(boolNode.AddChannel("vis", 1));
        }
        protected override FbxScene CreateScene(FbxManager manager)
        {
            // Create a scene with a single node that has an animation clip
            // attached to it
            FbxScene scene = FbxScene.Create(manager, "myScene");

            FbxNode animNode = FbxNode.Create(scene, "animNode");

            // setup anim stack
            FbxAnimStack fbxAnimStack = CreateAnimStack(scene);

            // add an animation layer
            FbxAnimLayer fbxAnimLayer = FbxAnimLayer.Create(scene, "animBaseLayer");

            fbxAnimStack.AddMember(fbxAnimLayer);

            // set up the translation
            CreateAnimCurves(
                animNode, fbxAnimLayer, PropertyComponentList, (index) => { return(index * 2.0); }, (index) => { return(index * 3.0f - 1); }
                );

            // TODO: avoid needing to this by creating typemaps for
            //       FbxObject::GetSrcObjectCount and FbxCast.
            //       Not trivial to do as both fbxobject.i and fbxemitter.i
            //       have to be moved up before the ignore all statement
            //       to allow use of templates.
            scene.SetCurrentAnimationStack(fbxAnimStack);
            scene.GetRootNode().AddChild(animNode);
            return(scene);
        }
예제 #4
0
    void TaskOnClick()
    {
        // Build the fbx scene file path
        // (player/player_data/emptySceneFromRuntime.fbx)
        string fbxFilePath = Application.dataPath;

        fbxFilePath = Path.Combine(fbxFilePath, "emptySceneFromRuntime.fbx");
        fbxFilePath = Path.GetFullPath(fbxFilePath);

        Debug.Log(string.Format("The file that will be written is {0}", fbxFilePath));

        using (var fbxManager = FbxManager.Create())
        {
            FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

            // Configure the IO settings.
            fbxManager.SetIOSettings(fbxIOSettings);

            // Create the exporter
            var fbxExporter = FbxExporter.Create(fbxManager, "Exporter");

            // Initialize the exporter.
            int fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)");

            bool status = fbxExporter.Initialize(fbxFilePath, fileFormat, fbxIOSettings);
            // Check that initialization of the fbxExporter was successful
            if (!status)
            {
                Debug.LogError(string.Format("failed to initialize exporter, reason: {0}",
                                             fbxExporter.GetStatus().GetErrorString()));
                return;
            }

            // Create a scene
            var fbxScene = FbxScene.Create(fbxManager, "Scene");

            // create scene info
            FbxDocumentInfo fbxSceneInfo = FbxDocumentInfo.Create(fbxManager, "SceneInfo");

            // set some scene info values
            fbxSceneInfo.mTitle    = "fromRuntime";
            fbxSceneInfo.mSubject  = "Exported from a Unity runtime";
            fbxSceneInfo.mAuthor   = "Unity Technologies";
            fbxSceneInfo.mRevision = "1.0";
            fbxSceneInfo.mKeywords = "export runtime";
            fbxSceneInfo.mComment  = "This is to demonstrate the capability of exporting from a Unity runtime, using the FBX SDK C# bindings";

            fbxScene.SetSceneInfo(fbxSceneInfo);

            // Export the scene to the file.
            status = fbxExporter.Export(fbxScene);

            // cleanup
            fbxScene.Destroy();
            fbxExporter.Destroy();
        }
    }
예제 #5
0
        public void EmptyExportImportTest()
        {
            int  N     = 10;
            long total = 0;

            for (int i = 0; i < N; i++)
            {
                m_stopwatch.Reset();
                m_stopwatch.Start();

                FbxIOSettings ioSettings = FbxIOSettings.Create(m_fbxManager, Globals.IOSROOT);
                m_fbxManager.SetIOSettings(ioSettings);

                FbxExporter exporter = FbxExporter.Create(m_fbxManager, "");

                string filename = "test.fbx";

                bool exportStatus = exporter.Initialize(filename, -1, m_fbxManager.GetIOSettings());

                // Check that export status is True
                Assert.IsTrue(exportStatus);

                // Create an empty scene to export
                FbxScene scene = FbxScene.Create(m_fbxManager, "myScene");

                // Export the scene to the file.
                exporter.Export(scene);

                exporter.Destroy();

                // Import to make sure file is valid

                FbxImporter importer = FbxImporter.Create(m_fbxManager, "");

                bool importStatus = importer.Initialize(filename, -1, m_fbxManager.GetIOSettings());

                Assert.IsTrue(importStatus);

                // Create a new scene so it can be populated
                FbxScene newScene = FbxScene.Create(m_fbxManager, "myScene2");

                importer.Import(newScene);

                importer.Destroy();

                m_stopwatch.Stop();

                total += m_stopwatch.ElapsedMilliseconds;

                // Delete the file once the test is complete
                File.Delete(filename);
            }

            CheckAgainstNative("EmptyExportImport", total / (float)N, N, 4);
        }
예제 #6
0
            /// <summary>
            /// Export all the objects in the set.
            /// Return the number of objects in the set that we exported.
            /// </summary>
            public int ExportAll(IEnumerable <UnityEngine.Object> unityExportSet)
            {
                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

                    // Configure the IO settings.
                    fbxManager.SetIOSettings(fbxIOSettings);

                    // Create the exporter
                    var fbxExporter = FbxExporter.Create(fbxManager, "Exporter");

                    // Initialize the exporter.
                    int fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)");

                    bool status = fbxExporter.Initialize(LastFilePath, fileFormat, fbxIOSettings);
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        Debug.LogError(string.Format("failed to initialize exporter, reason:D {0}",
                                                     fbxExporter.GetStatus().GetErrorString()));
                        return(0);
                    }

                    // By default, FBX exports in its most recent version. You might want to specify
                    // an older version for compatibility with other applications.
                    fbxExporter.SetFileExportVersion("FBX201400");

                    // Create a scene
                    var fbxScene = FbxScene.Create(fbxManager, "Scene");

                    // create scene info
                    FbxDocumentInfo fbxSceneInfo = FbxDocumentInfo.Create(fbxManager, "SceneInfo");

                    // set some scene info values
                    fbxSceneInfo.mTitle    = Title;
                    fbxSceneInfo.mSubject  = Subject;
                    fbxSceneInfo.mAuthor   = "Unity Technologies";
                    fbxSceneInfo.mRevision = "1.0";
                    fbxSceneInfo.mKeywords = Keywords;
                    fbxSceneInfo.mComment  = Comments;

                    fbxScene.SetSceneInfo(fbxSceneInfo);

                    // Export the scene to the file.
                    status = fbxExporter.Export(fbxScene);

                    // cleanup
                    fbxScene.Destroy();
                    fbxExporter.Destroy();

                    return(status == true ? NumNodes : 0);
                }
            }
예제 #7
0
        public override void TestBasics()
        {
            base.TestBasics();

            using (FbxImporter newImporter = CreateObject("MyImporter"))
            {
                // import a null document.
                Assert.IsFalse(newImporter.Import(null));

                // set a callback function
                newImporter.SetProgressCallback(null);
                newImporter.SetProgressCallback((float a, string b) => true);
                newImporter.SetProgressCallback(null);
            }

            // Export an empty scene to a temp file, then import.
            var filename = GetRandomFile();

            try {
                using (var exporter = FbxExporter.Create(Manager, "exporter")) {
                    using (var scene = FbxScene.Create(Manager, "exported scene")) {
                        Assert.IsTrue(exporter.Initialize(filename));
                        Assert.IsTrue(exporter.Export(scene));
                    }
                }
                var scene_in = FbxScene.Create(Manager, "imported scene");
                using (var importer = FbxImporter.Create(Manager, "import")) {
                    Assert.IsTrue(importer.Initialize(filename));
                    Assert.IsTrue(importer.Import(scene_in));
                    Assert.IsTrue(importer.IsFBX());

                    int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1;
                    FbxManager.GetFileFormatVersion(out sdkMajor, out sdkMinor, out sdkRevision);
                    int fileMajor = -1, fileMinor = -1, fileRevision = -1;
                    importer.GetFileVersion(out fileMajor, out fileMinor, out fileRevision);
                    Assert.AreNotSame(fileMajor, -1);
                    Assert.AreNotSame(fileMinor, -1);
                    Assert.AreNotSame(fileRevision, -1);
                    Assert.AreEqual(sdkMajor, fileMajor);
                    Assert.AreEqual(sdkMinor, fileMinor);
                    Assert.AreEqual(sdkRevision, fileRevision);

                    Assert.IsEmpty(importer.GetActiveAnimStackName());
                    Assert.AreEqual(importer.GetAnimStackCount(), 0);

                    // test GetFileHeaderInfo()
                    TestGetter(importer.GetFileHeaderInfo());
                    Assert.IsNotNull(importer.GetFileHeaderInfo());
                }
                // we actually don't care about the scene itself!
            } finally {
                System.IO.File.Delete(filename);
            }
        }
예제 #8
0
        public void TestConvertScene()
        {
            var axes = new FbxAxisSystem(
                FbxAxisSystem.EUpVector.eYAxis,
                FbxAxisSystem.EFrontVector.eParityOddNegative, // negative! check the sign goes through
                FbxAxisSystem.ECoordSystem.eLeftHanded);

            using (var Manager = FbxManager.Create()) {
                var scene = FbxScene.Create(Manager, "scene");
                axes.ConvertScene(scene);
            }
        }
예제 #9
0
        public void TestBasics()
        {
            // Call all the functions. Test that a few of them actually work
            // (rather than merely not crashing).
            using (FbxSystemUnit.mm) { }
            using (FbxSystemUnit.cm) { }
            using (FbxSystemUnit.dm) { }
            using (FbxSystemUnit.m) { }
            using (FbxSystemUnit.km) { }
            using (FbxSystemUnit.Inch) { }
            using (FbxSystemUnit.Foot) { }
            using (FbxSystemUnit.Yard) { }

            var units = new FbxSystemUnit(0.1);

            Assert.AreEqual(0.1, units.GetScaleFactor());
            Assert.AreEqual(1, units.GetMultiplier(), 1);
            Assert.AreEqual("mm", units.GetScaleFactorAsString());
            Assert.AreEqual(FbxSystemUnit.mm, units);
            Assert.AreNotEqual(FbxSystemUnit.km, units);
            units.GetHashCode();
            units.ToString();
            units.Dispose();

            units = new FbxSystemUnit(0.1378123891, 324823);
            units.ToString();
            Assert.AreEqual("custom unit", units.GetScaleFactorAsString(pAbbreviated: false));
            Assert.AreNotEqual(units, FbxSystemUnit.mm);

            // test GetGetConversionFactor
            Assert.AreEqual(FbxSystemUnit.cm.GetConversionFactorTo(FbxSystemUnit.Foot),
                            FbxSystemUnit.Foot.GetConversionFactorFrom(FbxSystemUnit.cm));

            // test ConversionOptions.Dispose()
            FbxSystemUnit.ConversionOptions options = new FbxSystemUnit.ConversionOptions();
            options.Dispose();

            using (var manager = FbxManager.Create()) {
                FbxScene scene = FbxScene.Create(manager, "scene");

                // test ConvertScene (make sure it doesn't crash)
                FbxSystemUnit.cm.ConvertScene(scene);
                FbxSystemUnit.m.ConvertScene(scene, new FbxSystemUnit.ConversionOptions());

                // test null
                Assert.That(() => { FbxSystemUnit.dm.ConvertScene(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>());

                // test destroyed
                scene.Destroy();
                Assert.That(() => { FbxSystemUnit.dm.ConvertScene(scene); }, Throws.Exception.TypeOf <System.ArgumentNullException>());
            }
        }
예제 #10
0
        /// Main entry point
        public static bool Export(string outputFile, string format, string fbxVersion = null)
        {
            using (var G = new FbxExportGlobals(outputFile)) {
                int fmt = G.m_manager.GetIOPluginRegistry().FindWriterIDByDescription(format);
                if (!G.m_exporter.Initialize(outputFile, fmt, G.m_ioSettings))
                {
                    OutputWindowScript.Error("FBX export failed", "Could not initialize exporter");
                    return(false);
                }
                if (!String.IsNullOrEmpty(fbxVersion))
                {
                    G.m_exporter.SetFileExportVersion(new FbxString(fbxVersion));
                }

                G.m_scene = FbxScene.Create(G.m_manager, "scene");
                if (G.m_scene == null)
                {
                    OutputWindowScript.Error("FBX export failed", "Could not initialize scene");
                    return(false);
                }

                String version = string.Format("{0}.{1}", App.Config.m_VersionNumber,
                                               App.Config.m_BuildStamp);
                FbxDocumentInfo info = FbxDocumentInfo.Create(G.m_manager, "DocInfo");
                info.Original_ApplicationVendor.Set(new FbxString(App.kDisplayVendorName));
                info.Original_ApplicationName.Set(new FbxString(App.kAppDisplayName));
                info.Original_ApplicationVersion.Set(new FbxString(version));
                info.LastSaved_ApplicationVendor.Set(new FbxString(App.kDisplayVendorName));
                info.LastSaved_ApplicationName.Set(new FbxString(App.kAppDisplayName));
                info.LastSaved_ApplicationVersion.Set(new FbxString(version));
                // The toolkit's FBX parser is too simple to be able to read anything but
                // the UserData/Properties70 node, so add the extra info as a custom property
                var stringType = info.Original_ApplicationVersion.GetPropertyDataType();
                var prop       = FbxProperty.Create(info.Original, stringType, "RequiredToolkitVersion");
                prop.SetString(FbxUtils.kRequiredToolkitVersion);

                G.m_scene.SetDocumentInfo(info);
                G.m_scene.GetGlobalSettings().SetSystemUnit(FbxSystemUnit.m);

                try {
                    WriteObjectsAndConnections2(G);
                    G.m_exporter.Export(G.m_scene);
                } catch (InvalidOperationException e) {
                    OutputWindowScript.Error("FBX export failed", e.Message);
                    return(false);
                } catch (IOException e) {
                    OutputWindowScript.Error("FBX export failed", e.Message);
                    return(false);
                }
                return(true);
            }
        }
예제 #11
0
        /// <summary>
        /// Test that an object created within a scene knows its scene.
        /// Override for objects that can't be in a scene.
        /// </summary>
        protected virtual void TestSceneContainer()
        {
            using (var scene = FbxScene.Create(Manager, "thescene")) {
                var obj = CreateObject(scene, "scene_object");
                Assert.AreEqual(scene, obj.GetScene());
                var child = CreateObject(obj, "scene_object_child");
                Assert.AreEqual(scene, child.GetScene());
            }

            {
                var obj = CreateObject(Manager, "not_scene_object");
                Assert.AreEqual(null, obj.GetScene());
            }
        }
        public void TestCrashOnGetSceneInfo()
        {
            using (var scene = FbxScene.Create(Manager, "")) {
                using (var docInfo = CreateObject()) {
                    scene.SetSceneInfo(docInfo);
                    docInfo.Destroy();

                    // Crash! Normally FBX disconnects when you destroy an
                    // object, but not so for the link between the scene and
                    // its scene info.
                    scene.GetSceneInfo().Url.Get();
                }
            }
        }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        // If we need to re-import, do that.
        if (!m_Settings.Equals(m_OldSettings))
        {
            // Try to import; only nuke the old stuff if we succeed.
            var newManager = FbxManager.Create();
            var newScene   = FbxScene.Create(newManager, "");
            var newNodes   = TryImport(m_Settings, newScene);
            if (newNodes != null)
            {
                // success; zero out the time, destroy what we previously
                // imported, save the settings so we can compare
                m_time        = 0;
                m_OldSettings = m_Settings;

                if (m_fbxManager != null)
                {
                    m_fbxManager.Dispose();
                }
                m_fbxManager = newManager;

                foreach (var kvp in m_nodes)
                {
                    DestroyImmediate(kvp.Key);
                }
                m_nodes = newNodes;
            }
        }

        // Update the time
        m_time += Time.deltaTime * m_timeScale;
        var fbxtime = FbxTime.FromSecondDouble(m_time);

        // Update the transforms (todo: update other animatable properties)
        if (m_animate)
        {
            foreach (var kvp in m_nodes)
            {
                var fbxNode   = kvp.Value;
                var unityNode = kvp.Key.transform;
                var mx        = fbxNode.EvaluateLocalTransform(fbxtime);

                unityNode.localPosition = V3(mx.GetT());
                unityNode.localRotation = Q(mx.GetQ());
                unityNode.localScale    = V3(mx.GetS());
            }
        }
    }
예제 #14
0
 protected override void TestSceneContainer()
 {
     // The base test tries to make FbxAnimCurve with an FbxAnimCurve as
     // parent; that doesn't work for some reason. So simplify it.
     using (var scene = FbxScene.Create(Manager, "thescene")) {
         var obj = CreateObject(scene, "scene_object");
         Assert.AreEqual(scene, obj.GetScene());
     }
     {
         // The base test assumes that if there's no scene, the object
         // won't be in a scene. But FbxAnimCurve synthesizes a test
         // scene.
         var obj = CreateObject(Manager, "not_scene_object");
         Assert.AreNotEqual(null, obj.GetScene());
     }
 }
예제 #15
0
        public void TestDeepConvertScene()
        {
            var axes = new FbxAxisSystem(
                FbxAxisSystem.EUpVector.eYAxis,
                FbxAxisSystem.EFrontVector.eParityOddNegative, // negative! check the sign goes through
                FbxAxisSystem.ECoordSystem.eLeftHanded);

            using (var Manager = FbxManager.Create()) {
                var scene = FbxScene.Create(Manager, "scene");
                try {
                    axes.DeepConvertScene(scene);
                } catch (System.EntryPointNotFoundException) {
                    Assert.Ignore("Testing against FBX SDK that doesn't have DeepConvertScene");
                }
            }
        }
예제 #16
0
        public (GameObject, List <string> warnings, ImportMaterialCollector) Import()
        {
            FbxManager    fbxManager = FbxManager.Create();
            FbxIOSettings ioSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

            fbxManager.SetIOSettings(ioSettings);
            FbxImporter fbxImporter = FbxImporter.Create(fbxManager, "");

            if (!fbxImporter.Initialize(m_path, -1, ioSettings))
            {
                warnings.Add("Failed to initialize FBX importer");
                return(null, warnings, null);
            }
            FbxScene scene = FbxScene.Create(fbxManager, "scene");

            fbxImporter.Import(scene);

            FbxNode root = scene.GetRootNode();

            SetPivots(root);
            root.ConvertPivotAnimationRecursive(null, FbxNode.EPivotSet.eDestinationPivot, 30);
            long totalVerts     = GetTotalVerts(root);
            long completedVerts = 0;

            float fbxUnitToTiltUnit; {
                var unit = scene.GetGlobalSettings().GetSystemUnit();
                if (Path.GetExtension(m_path).ToLower() == ".obj")
                {
                    // Obj doesn't specify units. We'd rather assume m, but fbx assumes cm.
                    unit = FbxSystemUnit.m;
                }
                fbxUnitToTiltUnit = (float)unit.GetConversionFactorTo(FbxSystemUnit.m)
                                    * App.METERS_TO_UNITS;
            }

            GameObject go = ImportNodes(
                root, fbxUnitToTiltUnit, ref completedVerts, totalVerts);

            Debug.Assert(completedVerts == totalVerts);
            fbxImporter.Destroy();
            ioSettings.Destroy();
            fbxManager.Destroy();

            return(go, warnings.Distinct().ToList(), m_collector);
        }
예제 #17
0
        public override FbxAnimCurve CreateObject(FbxManager mgr, string name = "")
        {
            if (mgr == null)
            {
                throw new System.ArgumentNullException();
            }

            /* Creating in a manager doesn't work for AnimCurves, but for the benefit of
             * testing, just fudge it by creating a scene for the manager. */
            FbxScene scene;

            if (!m_scenes.TryGetValue(mgr, out scene))
            {
                scene = FbxScene.Create(mgr, "__testscene");
                m_scenes.Add(mgr, scene);
            }
            return(FbxAnimCurve.Create(scene, name));
        }
        protected override FbxScene CreateScene(FbxManager manager)
        {
            // Create a cube as a static mesh

            FbxScene scene = FbxScene.Create(manager, "myScene");

            FbxNode meshNode = FbxNode.Create(scene, "MeshNode");
            FbxMesh cubeMesh = FbxMesh.Create(scene, "cube");

            meshNode.SetNodeAttribute(cubeMesh);

            scene.GetRootNode().AddChild(meshNode);

            cubeMesh.InitControlPoints(24);

            for (int i = 0; i < cubeMesh.GetControlPointsCount(); i++)
            {
                cubeMesh.SetControlPointAt(m_controlPoints [i], i);
            }

            // A cube: 6 polygons with 4 vertices each
            int[] vertices =
            {
                0,   1,  2,  3,
                4,   5,  6,  7,
                8,   9, 10, 11,
                12, 13, 14, 15,
                16, 17, 18, 19,
                20, 21, 22, 23
            };

            for (int i = 0; i < 6; i++)
            {
                cubeMesh.BeginPolygon(pGroup: -1);
                for (int j = 0; j < 4; j++)
                {
                    cubeMesh.AddPolygon(vertices[i * 4 + j]);
                }

                cubeMesh.EndPolygon();
            }

            return(scene);
        }
        private void FbxImportAndTestBlendshapes(string fbxPath)
        {
            // Create the FBX manager
            using (var fbxManager = FbxManager.Create())
            {
                FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

                // Configure the IO settings.
                fbxManager.SetIOSettings(fbxIOSettings);

                // Create the importer
                var fbxImporter = FbxImporter.Create(fbxManager, "Importer");

                // Initialize the importer.
                int fileFormat = -1;

                bool      status    = fbxImporter.Initialize(fbxPath, fileFormat, fbxIOSettings);
                FbxStatus fbxStatus = fbxImporter.GetStatus();

                Assert.That(status, Is.True, fbxStatus.GetErrorString());
                Assert.That(fbxImporter.IsFBX(), "file does not contain FBX data");

                // Import options. Determine what kind of data is to be imported.
                // The default is true, but here we set the options explictly.
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_MATERIAL, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_TEXTURE, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_ANIMATION, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_EXTRACT_EMBEDDED_DATA, false);
                fbxIOSettings.SetBoolProp(Globals.IMP_FBX_GLOBAL_SETTINGS, true);

                // Create a scene
                var fbxScene = FbxScene.Create(fbxManager, "Scene");

                // Import the scene to the file.
                status    = fbxImporter.Import(fbxScene);
                fbxStatus = fbxImporter.GetStatus();
                Assert.That(status, Is.True, fbxStatus.GetErrorString());

                // Get blendshapes and check that the FbxShapes all have names
                var rootNode = fbxScene.GetRootNode();
                TestFbxShapeNamesNotEmpty(rootNode);
            }
        }
        protected void ImportScene(string fileName)
        {
            // Import the scene to make sure file is valid
            using (FbxImporter importer = FbxImporter.Create(FbxManager, "myImporter")) {
                // Initialize the importer.
                bool status = importer.Initialize(fileName, -1, FbxManager.GetIOSettings());

                Assert.IsTrue(status);

                // Create a new scene so it can be populated by the imported file.
                FbxScene scene = FbxScene.Create(FbxManager, "myScene");

                // Import the contents of the file into the scene.
                importer.Import(scene);

                // check that the scene is valid
                CheckScene(scene);
            }
        }
예제 #21
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            // Create a scene with a single node that has an animation clip
            // attached to it
            FbxScene scene = FbxScene.Create(manager, "myScene");

            FbxNode sourceNode      = FbxNode.Create(scene, "source");
            FbxNode constrainedNode = FbxNode.Create(scene, "constrained");

            scene.GetRootNode().AddChild(sourceNode);
            scene.GetRootNode().AddChild(constrainedNode);

            FbxConstraint posConstraint = CreatePositionConstraint(scene, sourceNode, constrainedNode);

            Assert.That(posConstraint, Is.Not.Null);

            bool result = posConstraint.ConnectDstObject(scene);

            Assert.That(result, Is.True);

            // animate weight + active
            // setup anim stack
            FbxAnimStack fbxAnimStack = CreateAnimStack(scene);

            // add an animation layer
            FbxAnimLayer fbxAnimLayer = FbxAnimLayer.Create(scene, "animBaseLayer");

            fbxAnimStack.AddMember(fbxAnimLayer);

            // set up the translation
            CreateAnimCurves(
                posConstraint, fbxAnimLayer, PropertyComponentList, (index) => { return(index * 2.0); }, (index) => { return(index * 3 - 2); }
                );

            // TODO: avoid needing to do this by creating typemaps for
            //       FbxObject::GetSrcObjectCount and FbxCast.
            //       Not trivial to do as both fbxobject.i and fbxemitter.i
            //       have to be moved up before the ignore all statement
            //       to allow use of templates.
            scene.SetCurrentAnimationStack(fbxAnimStack);
            return(scene);
        }
예제 #22
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            FbxScene scene = FbxScene.Create(manager, "myScene");

            // create scene info
            FbxDocumentInfo sceneInfo = FbxDocumentInfo.Create(manager, "mySceneInfo");

            sceneInfo.mTitle    = dataValues ["title"];
            sceneInfo.mSubject  = dataValues ["subject"];
            sceneInfo.mAuthor   = dataValues ["author"];
            sceneInfo.mRevision = dataValues ["revision"];
            sceneInfo.mKeywords = dataValues ["keywords"];
            sceneInfo.mComment  = dataValues ["comment"];

            scene.SetSceneInfo(sceneInfo);

            // TODO: port SetSceneThumbnail

            return(scene);
        }
예제 #23
0
        public void TestBasics()
        {
            var scene    = FbxScene.Create(Manager, "");
            var settings = scene.GetGlobalSettings();

            settings.SetAxisSystem(FbxAxisSystem.MayaYUp);
            var axes = settings.GetAxisSystem();

            Assert.AreEqual(axes, FbxAxisSystem.MayaYUp);

            settings.SetSystemUnit(FbxSystemUnit.m);
            var units = settings.GetSystemUnit();

            Assert.AreEqual(units, FbxSystemUnit.m);

            var settingsB = scene.GetGlobalSettings();

            Assert.AreEqual(settings, settingsB);

            var scene2    = FbxScene.Create(Manager, "");
            var settings2 = scene2.GetGlobalSettings();

            Assert.AreNotEqual(settings, settings2);

            // Cover all the equality and inequality operators
            Assert.That(settings != settings2);
            Assert.That(settings as FbxObject != settings2 as FbxObject);
            Assert.That(settings as FbxEmitter != settings2 as FbxEmitter);

            // test SetDefaultCamera
            settings.SetDefaultCamera("camera");
            Assert.AreEqual("camera", settings.GetDefaultCamera());

            // test SetAmbientColor
            settings.SetAmbientColor(new FbxColor(1, 1, 1));
            Assert.AreEqual(new FbxColor(1, 1, 1), settings.GetAmbientColor());

            // test SetTimeMode
            settings.SetTimeMode(FbxTime.EMode.eFrames100);
            Assert.That(settings.GetTimeMode(), Is.EqualTo(FbxTime.EMode.eFrames100));
        }
예제 #24
0
        // Export scene sample
        protected void ExportScene(string fileName)
        {
            using (FbxManager fbxManager = FbxManager.Create())
            {
                // configure IO settings.
                fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                // Export the scene
                using (Autodesk.Fbx.FbxExporter exporter = Autodesk.Fbx.FbxExporter.Create(fbxManager, "myExporter"))
                {
                    // Initialize the exporter.
                    bool status = exporter.Initialize(fileName, -1, fbxManager.GetIOSettings());

                    // Create a new scene to export
                    FbxScene scene = FbxScene.Create(fbxManager, "myScene");

                    // Export the scene to the file.
                    exporter.Export(scene);
                }
            }
        }
예제 #25
0
        // Import scene sample
        protected void ImportScene(string fileName)
        {
            using (FbxManager fbxManager = FbxManager.Create())
            {
                // configure IO settings.
                fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                // Import the scene to make sure file is valid
                using (FbxImporter importer = FbxImporter.Create(fbxManager, "myImporter"))
                {
                    // Initialize the importer.
                    bool status = importer.Initialize(fileName, -1, fbxManager.GetIOSettings());

                    // Create a new scene so it can be populated by the imported file.
                    FbxScene scene = FbxScene.Create(fbxManager, "myScene");

                    // Import the contents of the file into the scene.
                    importer.Import(scene);
                }
            }
        }
예제 #26
0
    public void CreateDocument()
    {
        Scene = FbxScene.Create(SdkManager, "");

        FbxDocumentInfo SceneInfo = FbxDocumentInfo.Create(SdkManager, "SceneInfo");

        SceneInfo.mTitle   = new FbxString("Unreal FBX Exporter");
        SceneInfo.mSubject = new FbxString("Export FBX meshes from Unreal");
        SceneInfo.Original_ApplicationVendor.Set(new FbxString("Epic Games"));
        SceneInfo.Original_ApplicationName.Set(new FbxString("Unreal Engine"));
        SceneInfo.Original_ApplicationVersion.Set(new FbxString("4.18"));
        SceneInfo.LastSaved_ApplicationVendor.Set(new FbxString("Epic Games"));
        SceneInfo.LastSaved_ApplicationName.Set(new FbxString("Unreal Engine"));
        SceneInfo.LastSaved_ApplicationVersion.Set(new FbxString("4.18"));

        FbxAxisSystem.EFrontVector FrontVector = (FbxAxisSystem.EFrontVector)(0 - FbxAxisSystem.EFrontVector.eParityOdd);
        if (bForceFrontXAxis)
        {
            FrontVector = FbxAxisSystem.EFrontVector.eParityEven;
        }

        FbxAxisSystem UnrealZUp = new FbxAxisSystem(FbxAxisSystem.EUpVector.eZAxis, FrontVector, FbxAxisSystem.ECoordSystem.eRightHanded);

        //const FbxAxisSystem UnrealZUp(FbxAxisSystem.EUpVector, FrontVector, FbxAxisSystem::eRightHanded);
        Scene.GetGlobalSettings().SetAxisSystem(FbxAxisSystem.Max);
        Scene.GetGlobalSettings().SetOriginalUpAxis(FbxAxisSystem.Max);
        Scene.GetGlobalSettings().SetSystemUnit(FbxSystemUnit.cm);

        Scene.SetSceneInfo(SceneInfo);

        // setup anim stack
        AnimStack = FbxAnimStack.Create(Scene, "Unreal Take");
        //KFbxSet<KTime>(AnimStack.LocalStart, KTIME_ONE_SECOND);
        AnimStack.Description.Set((new FbxString("Animation Take for Unreal.")));

        // this take contains one base layer. In fact having at least one layer is mandatory.
        AnimLayer = FbxAnimLayer.Create(Scene, "Base Layer");
        AnimStack.AddMember(AnimLayer);
        //if(Mathf)
    }
예제 #27
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            // Create a cube as a static mesh

            FbxScene scene = FbxScene.Create(manager, "myScene");

            FbxNode meshNode = FbxNode.Create(scene, "MeshNode");
            FbxMesh cubeMesh = FbxMesh.Create(scene, "cube");

            meshNode.SetNodeAttribute(cubeMesh);

            scene.GetRootNode().AddChild(meshNode);

            cubeMesh.InitControlPoints(24);

            for (int i = 0; i < cubeMesh.GetControlPointsCount(); i++)
            {
                cubeMesh.SetControlPointAt(m_controlPoints [i], i);
            }

            return(scene);
        }
예제 #28
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            // create the following node hierarchy to test:
            //       Root
            //      /    \
            // Child0    Child1
            //              |
            //            Child2
            //         /    |     \
            //    Child3  Child4  Child5
            FbxScene scene = FbxScene.Create(manager, "myScene");

            FbxNode root = FbxNode.Create(scene, "Root");

            // set the root invisible
            root.SetVisibility(false);

            // don't let children inherit visibility of invisible root node
            root.VisibilityInheritance.Set(false);

            FbxNode[] children = new FbxNode[6];
            for (int i = 0; i < children.Length; i++)
            {
                children [i] = FbxNode.Create(scene, "Child" + i);
                // set even nodes visible, and odd nodes invisible
                children [i].SetVisibility(i % 2 == 0);
            }

            scene.GetRootNode().AddChild(root);
            root.AddChild(children [0]);
            root.AddChild(children [1]);
            children [1].AddChild(children [2]);
            children [2].AddChild(children [3]);
            children [2].AddChild(children [4]);
            children [2].AddChild(children [5]);

            return(scene);
        }
예제 #29
0
            static FbxScene BuildScene(FbxManager fbxManager)
            {
                // Create a scene
                var fbxScene = FbxScene.Create(fbxManager, "Scene");

                // Create 5000 nulls. Show progress on this task from [0,0.5]
                EditorUtility.DisplayProgressBar(ProgressBarTitle, "Creating the scene", 0);
                int percent = 1 + NumNulls / 100;

                for (int i = 0; i < NumNulls; ++i)
                {
                    FbxNode.Create(fbxScene, "node_" + i);
                    if (i % percent == 0)
                    {
                        if (EditorUtility.DisplayCancelableProgressBar(ProgressBarTitle, "Creating the scene", 0.5f * (float)i / (float)NumNulls))
                        {
                            // cancel silently
                            return(null);
                        }
                    }
                }
                return(fbxScene);
            }
예제 #30
0
        void Run()
        {
            FbxManager    manager = FbxManager.Create();
            FbxIOSettings setting = FbxIOSettings.Create(manager, "IOSRoot");

            manager.SetIOSettings(setting);

            FbxImporter impoter = FbxImporter.Create(manager, "");

            bool status = impoter.Initialize(@"D:\develop\FbxWrapper\1.fbx", -1, setting);

            Log.Info(status);

            if (!status)
            {
                return;
            }

            FbxScene scene = FbxScene.Create(manager, "scene1");

            status = impoter.Import(scene);
            Log.Info(status);


            int numTrack = scene.GetSrcObjectCount(FbxAnimStack.ClassId);

            Log.Info("num stack " + numTrack);

            FbxObject obj = scene.GetSrcObject(FbxAnimStack.ClassId, 0);

            FbxAnimStack stack = FbxAnimStack.Cast(obj);

            if (stack == null)
            {
                Log.Error("can not get anim stack!");
                return;
            }

            FbxCriteria cri      = FbxCriteria.ObjectTypeStrict(FbxAnimLayer.ClassId);
            int         numLayer = stack.GetMemberCount(cri);

            Log.Info("anim layer count : " + numLayer);

            FbxAnimLayer layer = null;

            if (numLayer > 0)
            {
                FbxObject layerobj = stack.GetMember(cri, 0);
                layer = FbxAnimLayer.Cast(layerobj);
                if (layer == null)
                {
                    Log.Error("anim layer is null!");
                    return;
                }

                Log.Info("anim layer name " + layer.GetName());
            }


            Log.Info("node count " + scene.GetNodeCount());
            for (int i = 0; i < scene.GetNodeCount(); i++)
            {
                FbxNode node = scene.GetNode(i);
                Log.Info("node " + i + " " + node.GetName());

                if (node.LclTranslation.IsAnimated(layer))
                {
                    FbxAnimCurveNode curveNode = node.LclTranslation.GetCurveNode(layer);
                    if (curveNode == null)
                    {
                        Log.Error("curve node is null");
                    }
                    else
                    {
                        for (int c = 0; c < curveNode.GetCurveCount(0); c++)
                        {
                            FbxAnimCurve curve = curveNode.GetCurve(0, (uint)c);
                            if (curve != null)
                            {
                                Log.Info("curve " + curve.GetName());
                                Log.Info("key count " + curve.KeyGetCount());
                                FbxAnimCurveKey key = curve.KeyGet(0);
                                FbxTime         t   = key.GetTime();
                                Log.Info("key " + t.GetTimeString() + " value " + key.GetValue());
                            }
                        }
                    }
                }



                if (node.GetNodeAttribute() != null)
                {
                    Log.Info("got attribu");
                    FbxNodeAttribute att = node.GetNodeAttribute();
                    PrintAttribute(att);
                }
                else
                {
                    Log.Info("att count " + node.GetNodeAttributeCount());
                    for (int j = 0; j < node.GetNodeAttributeCount(); j++)
                    {
                        FbxNodeAttribute att = node.GetNodeAttributeByIndex(j);
                        PrintAttribute(att);
                    }
                }

                FbxVector4    rot = node.GetPostRotation(FbxNode.EPivotSet.eSourcePivot);
                FbxQuaternion q;
            }
        }