public void TestDocumentInfo()
        {
            using (var doc = CreateObject("RootDoc"))
            {
                // NOTE: we'll get a ArgumentNullException warning if we use the using
                // scope because doc.Clear() will destroy the FbxDocumentInfo.
                var docInfo = FbxDocumentInfo.Create(this.Manager, "myDocumentInfo");
                Assert.IsNotNull(docInfo);

                doc.SetDocumentInfo(FbxDocumentInfoTest.InitDocumentInfo(docInfo, this.dataValues));

                var docInfo2 = doc.GetDocumentInfo();
                Assert.IsNotNull(docInfo2);

                FbxDocumentInfoTest.CheckDocumentInfo(docInfo2, this.dataValues);

                // TODO: test identity
                // Assert.AreEqual (docInfo2, docInfo);
                // Assert.AreSame (docInfo2, docInfo);

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

                // CRASH ALERT!!! remove reference to document info before
                // going out of using docInfo scope.
                doc.Clear();

                Assert.IsNull(doc.GetDocumentInfo());

                FbxCollectionTest.GenericTests(doc, Manager);
            }
        }
    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();
        }
    }
            /// <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);
                }
            }
Exemple #4
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);
            }
        }
        public void TestBasics()
        {
            using (var scene = FbxScene.Create(Manager, "scene")) {
                // Just call every function. TODO: and test them at least minimally!
                scene.GetGlobalSettings();
                scene.GetRootNode();

                var docInfo = FbxDocumentInfo.Create(Manager, "info");
                scene.SetDocumentInfo(docInfo);
                Assert.AreEqual(docInfo, scene.GetDocumentInfo());

                docInfo = FbxDocumentInfo.Create(Manager, "info2");
                scene.SetSceneInfo(docInfo);
                Assert.AreEqual(docInfo, scene.GetSceneInfo());

                scene.Clear();

                FbxCollectionTest.GenericTests(scene, Manager);
            }
        }
Exemple #6
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);
        }
Exemple #7
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)
    }
Exemple #8
0
    public static void ExportMesh(Mesh mesh, string directory, string fileName)
    {
        var filePath = Path.Combine(directory, fileName);
        // Make a temporary copy of the mesh to modify it
        Mesh tempMesh = Object.Instantiate(mesh);

        tempMesh.name = mesh.name;

        // If meters, divide by 100 since default is cm. Assume centered at origin.
        if (fbxUnit == FbxSystemUnit.m)
        {
            Vector3[] vertices = tempMesh.vertices;
            for (int i = 0; i < vertices.Length; ++i)
            {
                vertices[i] /= 100.0f;
            }
            tempMesh.vertices = vertices;
        }
        // You could handle other SystemUnits here

        // FBX Manager
        FbxManager manager = FbxManager.Create();

        manager.SetIOSettings(FbxIOSettings.Create(manager, Globals.IOSROOT));

        // FBX Exporter
        FbxExporter fbxExporter = FbxExporter.Create(manager, "Exporter");

        // Binary
        int fileFormat = -1;

        // Ascii
        if (saveFbxAsAscii)
        {
            fileFormat = manager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)");
        }

        fbxExporter.Initialize(filePath, fileFormat, manager.GetIOSettings());
        fbxExporter.SetFileExportVersion("FBX201400");

        // FBX Scene
        FbxScene        fbxScene  = FbxScene.Create(manager, "Scene");
        FbxDocumentInfo sceneInfo = FbxDocumentInfo.Create(manager, "SceneInfo");

        // Set up scene info
        sceneInfo.mTitle    = fbxFileTitle;
        sceneInfo.mSubject  = fbxFileSubject;
        sceneInfo.mComment  = fbxFileComment;
        sceneInfo.mAuthor   = fbxFileAuthor;
        sceneInfo.mRevision = fbxFileRevision;
        sceneInfo.mKeywords = fbxFileKeywords;
        sceneInfo.Original_ApplicationName.Set(fbxFileApplication);
        sceneInfo.LastSaved_ApplicationName.Set(fbxFileApplication);
        fbxScene.SetSceneInfo(sceneInfo);

        // Set up Global settings
        FbxGlobalSettings globalSettings = fbxScene.GetGlobalSettings();

        globalSettings.SetSystemUnit(fbxUnit);
        globalSettings.SetAxisSystem(fbxAxisSystem);

        FbxNode modelNode = FbxNode.Create(fbxScene, tempMesh.name);

        // Add mesh to a node in the scene
        // TODO Wat???
//        using (ModelExporter modelExporter = new ModelExporter())
//        {
//            if (!modelExporter.ExportMesh(tempMesh, modelNode))
//                Debug.LogError("Problem Exporting Mesh");
//        }
        // add the model to the scene
        fbxScene.GetRootNode().AddChild(modelNode);

        // Finally actually save the scene
        bool sceneSuccess = fbxExporter.Export(fbxScene);

        AssetDatabase.Refresh();

        // clean up temporary model
        if (Application.isPlaying)
        {
            Object.Destroy(tempMesh);
        }
        else
        {
            Object.DestroyImmediate(tempMesh);
        }
    }
            /// <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; it cleans everything up at the end of the using block.
                using (var fbxManager = FbxManager.Create())
                {
                    // Configure the IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                    // 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, fbxManager.GetIOSettings());
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        return(0);
                    }

                    // Set compatibility to 2014
                    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);

                    var fbxSettings = fbxScene.GetGlobalSettings();
                    fbxSettings.SetSystemUnit(FbxSystemUnit.m); // Unity unit is meters

                    // While Unity is Y-up, Z-forward, left-handed, the FBX SDK can't convert to
                    // right-handed. So we just lie and say that we're right-handed like Maya.
                    fbxSettings.SetAxisSystem(FbxAxisSystem.MayaYUp);

                    FbxNode fbxRootNode = fbxScene.GetRootNode();

                    // export set of objects
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);
                        if (!unityGo)
                        {
                            continue;
                        }

                        ExportComponents(unityGo, fbxScene, fbxRootNode);
                    }

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

                    return(status == true ? NumNodes : 0);
                }
            }
Exemple #10
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())
                {
                    // Configure the IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                    // 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, fbxManager.GetIOSettings());
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        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);

                    FbxNode fbxRootNode = fbxScene.GetRootNode();

                    // export set of object
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);

                        if (unityGo)
                        {
                            this.ExportComponents(unityGo, fbxScene, fbxRootNode);
                        }
                    }

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

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

                    if (!status)
                    {
                        return(0);
                    }
                }
                return(NumNodes);
            }
            /// <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())
                {
                    // Configure IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                    // 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, fbxManager.GetIOSettings());

                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        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);

                    var fbxSettings = fbxScene.GetGlobalSettings();
                    fbxSettings.SetSystemUnit(FbxSystemUnit.m); // Unity unit is meters

                    // The Unity axis system has Y up, Z forward, X to the right.
                    // Export as Maya axis system.
                    fbxSettings.SetAxisSystem(FbxAxisSystem.MayaYUp);

                    FbxNode fbxRootNode = fbxScene.GetRootNode();

                    // export set of objects
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);

                        if (unityGo)
                        {
                            var unityGoIOSettings = unityGo.GetComponent <FbxSharp.IOSettings> ();
                            if (unityGoIOSettings)
                            {
                                if (unityGoIOSettings.SystemUnit == FbxSharp.SystemUnitType.m)
                                {
                                    fbxSettings.SetSystemUnit(FbxSystemUnit.m);
                                }
                                if (unityGoIOSettings.AxisSystem == FbxSharp.AxisSystemType.Unity)
                                {
                                    Debug.Log("setting unity axis system");
                                    fbxSettings.SetAxisSystem(UnityAxisSystem);
                                }
                            }

                            this.ExportComponents(unityGo, fbxScene, fbxRootNode);
                        }
                    }

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

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

                    return(status == true ? NumNodes : 0);
                }
            }
Exemple #12
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()) {
                    // Configure the IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                    // 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, fbxManager.GetIOSettings());
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        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);

                    var fbxSettings = fbxScene.GetGlobalSettings();
                    fbxSettings.SetSystemUnit(FbxSystemUnit.m);      // Unity unit is meters

                    // TODO: Uni-15896
                    //fbxSettings.SetAxisSystem(FbxAxisSystem.OpenGL); // Unity axes are Y-up, odd parity, right-handed

                    FbxNode fbxRootNode = fbxScene.GetRootNode();

                    // export set of object
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);

                        if (unityGo)
                        {
                            this.ExportComponents(unityGo, fbxScene, fbxRootNode);
                        }
                    }

                    fbxSceneInfo.mComment =
                        string.Format("Mesh Count : {0}, Triangle Count: {1}, Vertex Count: {2} ",
                                      NumMeshes, NumTriangles, NumVertices);

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

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

                    return(status == true ? NumNodes : 0);
                }
            }
    public void TestWriteEmptyFbxFile()
    {
        /*
         * Runtime test that writes an fbx scene file in the directory where the
         * player is (temp folder while running tests)
         */

        // Build the fbx scene file path
        // (player/player_data/emptySceneFromRuntime.fbx)
        string fbxFilePath = Application.dataPath;

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

        // The file should not exist. We are running the test from the Test
        // Runner, which should always create a new player with its own fresh
        // data directory
        FileInfo fbxFileInfo = new FileInfo(fbxFilePath);

        Assert.That(!fbxFileInfo.Exists, string.Format("\"{0}\" already exists but the test did not create it yet", 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);

            Assert.That(status, string.Format("failed to initialize exporter, reason:D {0}",
                                              fbxExporter.GetStatus().GetErrorString()));
            // 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    = "emptySceneFromRuntime";
            fbxSceneInfo.mSubject  = "Exported from a Unity runtime while testing in play mode";
            fbxSceneInfo.mAuthor   = "Unity Technologies";
            fbxSceneInfo.mRevision = "1.0";
            fbxSceneInfo.mKeywords = "export fbx runtime player play mode";
            fbxSceneInfo.mComment  = "This is to test 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);
            Assert.That(status, string.Format("Failed to export scene, reason: {0}",
                                              fbxExporter.GetStatus().GetErrorString()));

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

        // Test that the file exists
        fbxFileInfo = new FileInfo(fbxFilePath);
        Assert.That(fbxFileInfo.Exists, string.Format("\"{0}\" was not created", fbxFilePath));
    }
            /// <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())
                {
                    // Configure the IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                    // 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, fbxManager.GetIOSettings());
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        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);

                    var fbxSettings = fbxScene.GetGlobalSettings();
                    /// Set system units : Unity unit is meters
                    fbxSettings.SetSystemUnit(FbxSystemUnit.m);
                    /// Set axis system : Unity Y Up, Z Forward, X Right (left-handed with odd parity)
                    /// The Maya axis system has Y up, Z forward, X Left (right handed system with odd parity).
                    /// We export right-handed for Maya because ConvertScene can't switch handedness:
                    /// https://forums.autodesk.com/t5/fbx-forum/get-confused-with-fbxaxissystem-convertscene/td-p/4265472
                    /// NOTE: models will flipped about the -X axis.
                    fbxSettings.SetAxisSystem(FbxAxisSystem.MayaYUp);

                    FbxNode fbxRootNode = fbxScene.GetRootNode();

                    // export set of object
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);

                        if (unityGo)
                        {
                            this.ExportComponents(unityGo, fbxScene, fbxRootNode);
                        }
                    }

                    // Export animations
                    ExportAllAnimation(fbxScene);

                    // Set the scene's ambient lighting.
                    SetAmbientLighting(fbxScene);

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

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

                    if (!status)
                    {
                        return(0);
                    }
                }
                return(NumNodes);
            }
            /// <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)
            {
                Verbose = true;

                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    // Configure fbx IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

                    // Export texture as embedded
                    fbxManager.GetIOSettings().SetBoolProp(Globals.EXP_FBX_EMBEDDED, true);

                    // 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, fbxManager.GetIOSettings());
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        return(0);
                    }

                    // Set compatibility to 2014
                    fbxExporter.SetFileExportVersion("FBX201400");

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

                    // set up the scene info
                    FbxDocumentInfo fbxSceneInfo = FbxDocumentInfo.Create(fbxManager, "SceneInfo");
                    fbxSceneInfo.mTitle    = Title;
                    fbxSceneInfo.mSubject  = Subject;
                    fbxSceneInfo.mAuthor   = "Unity Technologies";
                    fbxSceneInfo.mRevision = "1.0";
                    fbxSceneInfo.mKeywords = Keywords;
                    fbxSceneInfo.mComment  = Comments;
                    fbxScene.SetSceneInfo(fbxSceneInfo);

                    // Set up the axes (Y up, Z forward, X to the right) and units (meters)
                    var fbxSettings = fbxScene.GetGlobalSettings();
                    fbxSettings.SetSystemUnit(FbxSystemUnit.m);

                    // The Unity axis system has Y up, Z forward, X to the right (left handed system with odd parity).
                    // The Maya axis system has Y up, Z forward, X to the left (right handed system with odd parity).
                    // We need to export right-handed for Maya because ConvertScene can't switch handedness:
                    // https://forums.autodesk.com/t5/fbx-forum/get-confused-with-fbxaxissystem-convertscene/td-p/4265472
                    fbxSettings.SetAxisSystem(FbxAxisSystem.MayaYUp);

                    // export set of object
                    FbxNode fbxRootNode = fbxScene.GetRootNode();
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);

                        if (unityGo)
                        {
                            this.ExportComponents(unityGo, fbxScene, fbxRootNode);
                        }
                    }

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

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

                    return(status == true ? NumNodes : 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)
            {
                Verbose = true;

                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    // Configure the IO settings.
                    fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT));

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

                    // Initialize the exporter.
                    var  fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)");
                    bool status     = fbxExporter.Initialize(LastFilePath, fileFormat, fbxManager.GetIOSettings());
                    // Check that initialization of the fbxExporter was successful
                    if (!status)
                    {
                        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);

                    // set system units, Unity unit is meters
                    var fbxSettings = fbxScene.GetGlobalSettings();
                    fbxSettings.SetSystemUnit(FbxSystemUnit.m);

                    // set axis system
                    // The Unity axis system has Y up, Z forward, X to the right but since
                    // FbxAxisSystem.ConvertScene doesn't work we'll set it to right handed so
                    // that it will import into Maya right way up just mirrored.
                    var fbxAxisSystem = new FbxAxisSystem(FbxAxisSystem.EUpVector.eYAxis,
                                                          FbxAxisSystem.EFrontVector.eParityOdd,
                                                          FbxAxisSystem.ECoordSystem.eRightHanded);
                    fbxSettings.SetAxisSystem(fbxAxisSystem);

                    FbxNode fbxRootNode = fbxScene.GetRootNode();

                    // export set of object
                    foreach (var obj in unityExportSet)
                    {
                        var unityGo = GetGameObject(obj);

                        if (unityGo)
                        {
                            this.ExportComponents(unityGo, fbxScene, fbxRootNode);
                        }
                    }

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

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

                    return(status == true ? NumNodes : 0);
                }
            }