Example #1
0
        public void TestGetFileFormatVersion()
        {
            int major = -1, minor = -1, revision = -1;

            FbxManager.GetFileFormatVersion(out major, out minor, out revision);

            Assert.GreaterOrEqual(major, 0);
            Assert.GreaterOrEqual(minor, 0);
            Assert.GreaterOrEqual(revision, 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);
            }
        }
Example #3
0
            /// <summary>
            /// Import all from scene.
            /// Return the number of objects we imported.
            /// </summary>
            public int ImportAll()
            {
                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

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

                    // Get the version number of the FBX files generated by the
                    // version of FBX SDK that you are using.
                    int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1;
                    FbxManager.GetFileFormatVersion(out sdkMajor, out sdkMinor, out sdkRevision);

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

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

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

                    // Get the version number of the FBX file format.
                    int fileMajor = -1, fileMinor = -1, fileRevision = -1;
                    fbxImporter.GetFileVersion(out fileMajor, out fileMinor, out fileRevision);

                    // Check that initialization of the fbxImporter was successful
                    if (!status)
                    {
                        Debug.LogError(string.Format("failed to initialize FbxImporter, error returned {0}",
                                                     fbxStatus.GetErrorString()));

                        if (fbxStatus.GetCode() == FbxStatus.EStatusCode.eInvalidFileVersion)
                        {
                            Debug.LogError(string.Format("Invalid file version detected\nSDK version: {0}.{1}.{2}\nFile version: {3}.{4}.{5}",
                                                         sdkMajor, sdkMinor, sdkRevision,
                                                         fileMajor, fileMinor, fileRevision));
                        }

                        return(0);
                    }

                    // 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);

                    if (status == false)
                    {
                        Debug.LogError(string.Format("failed to import file ({0})",
                                                     fbxImporter.GetStatus().GetErrorString()));
                    }
                    else
                    {
                        // import data into scene
                        ProcessScene(fbxScene);
                    }

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

                    return(status == true ? NumNodes : 0);
                }
            }
Example #4
0
            /// <summary>
            /// Import all from scene.
            /// Return the number of objects we imported.
            /// </summary>
            public int ImportAll(IEnumerable <UnityEngine.Object> unitySelectionSet)
            {
                // Create the FBX manager
                using (var fbxManager = FbxManager.Create())
                {
                    FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT);

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

                    // Get the version number of the FBX files generated by the
                    // version of FBX SDK that you are using.
                    int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1;

                    FbxManager.GetFileFormatVersion(out sdkMajor, out sdkMinor, out sdkRevision);

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

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

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

                    // Get the version number of the FBX file format.
                    int fileMajor = -1, fileMinor = -1, fileRevision = -1;
                    fbxImporter.GetFileVersion(out fileMajor, out fileMinor, out fileRevision);

                    // Check that initialization of the fbxImporter was successful
                    if (!status)
                    {
                        Debug.LogError(string.Format("failed to initialize FbxImporter, error returned {0}",
                                                     fbxStatus.GetErrorString()));

                        if (fbxStatus.GetCode() == FbxStatus.EStatusCode.eInvalidFileVersion)
                        {
                            Debug.LogError(string.Format("Invalid file version detected\nSDK version: {0}.{1}.{2}\nFile version: {3}.{4}.{5}",
                                                         sdkMajor, sdkMinor, sdkRevision,
                                                         fileMajor, fileMinor, fileRevision));
                        }

                        return(0);
                    }

                    MsgLine.Add("Import Scene Report");
                    MsgLine.Add(kBorderLine);

                    MsgLine.Add(kPadding + string.Format("FilePath: {0}", LastFilePath));
                    MsgLine.Add(kPadding + string.Format("SDK version: {0}.{1}.{2}",
                                                         sdkMajor, sdkMinor, sdkRevision));

                    if (!fbxImporter.IsFBX())
                    {
                        Debug.LogError(string.Format("file does not contain FBX data {0}", LastFilePath));
                        return(0);
                    }

                    MsgLine.Add(kPadding + string.Format("File version: {0}.{1}.{2}",
                                                         fileMajor, fileMinor, fileRevision));

                    MsgLine.Add(kBorderLine);
                    MsgLine.Add("Animation");
                    MsgLine.Add(kBorderLine);

                    int numAnimStack = fbxImporter.GetAnimStackCount();

                    MsgLine.Add(kPadding + string.Format("number of stacks: {0}", numAnimStack));
                    MsgLine.Add(kPadding + string.Format("active animation stack: \"{0}\"\n", fbxImporter.GetActiveAnimStackName()));

                    for (int i = 0; i < numAnimStack; i++)
                    {
#if UNI_18972
                        FbxTakeInfo fbxTakeInfo = fbxImporter.GetTakeInfo(i);
                        MsgLine.Add(kPadding + string.Format("Animation Stack ({0})", i));
                        MsgLine.Add(kPadding + string.Format("name: \"{0}\"", fbxTakeInfo.mName) + string.kNewLine);
                        MsgLine.Add(kPadding + string.Format("description: \"{0}\"", fbxTakeInfo.mDescription));
                        MsgLine.Add(kPadding + string.Format("import name: \"{0}\"", fbxTakeInfo.mImportName));
                        MsgLine.Add(kPadding + string.Format("import state: \"{0}\"", fbxTakeInfo.mSelect));
#endif
                    }

                    // 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();

                    if (status == false)
                    {
                        if (fbxStatus.GetCode() == FbxStatus.EStatusCode.ePasswordError)
                        {
                            Debug.LogError(string.Format("failed to import, file is password protected ({0})", fbxStatus.GetErrorString()));
                        }
                        else
                        {
                            Debug.LogError(string.Format("failed to import file ({0})", fbxStatus.GetErrorString()));
                        }
                    }
                    else
                    {
                        // import data into scene
                        ProcessScene(fbxScene, unitySelectionSet);
                    }

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

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