The FBX SDK can export a scene into various file formats (see Supported File Formats), including both binary and ASCII FBX file formats. Note that only the binary FBX file format supports embedded media (see I/O Settings).
The scene exporting functionality of the FBX SDK is abstracted by the FbxExporter class. The steps required to initialize the exporter object and to export the scene are analogous to the steps detailed in Importing a Scene. A FbxExporter object is created using a reference to the program's FbxManager singleton. The FbxExporter::Initialize() method determines the filename and configuration settings of the exporter. This method requires three parameters:
#include <fbxsdk.h> #include <fbxfilesdk/fbxio/fbxiosettings.h> // ... // Create the FBX SDK manager FbxManager* lSdkManager = FbxManager::Create(); // Create an IOSettings object. FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT ); lSdkManager->SetIOSettings(ios); // ... Configure the FbxIOSettings object here ... // Create an exporter. FbxExporter* lExporter = FbxExporter::Create(lSdkManager, ""); // Declare the path and filename of the file to which the scene will be exported. // In this case, the file will be in the same directory as the executable. const char* lFilename = "file.fbx"; // Initialize the exporter. bool lExportStatus lExporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings());
If any errors occur in the call to FbxExporter::Initialize(), the method returns false. To retrieve the error, you must call GetStatus().GetErrorString() from the FbxExporter object. For more information on error handling, see Error Handling.
if(!lExportStatus) { printf("Call to FbxExporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", lExporter->GetStatus().GetErrorString()); return false; }
The FbxExporter::Export() method exports the specified scene (FbxScene) to the file . For more information on building and manipulating scenes with the FBX SDK, see Nodes and the Scene Graph.
// Create a new scene so it can be populated by the imported file. FbxScene* lScene = FbxScene::Create(lSdkManager,"myScene"); // ... Import a scene, or build a new one ... // Export the scene to the file. lExporter->Export(lScene);
Once the scene has been exported, the exporter can safely be destroyed to minimize memory allocation.
// Destroy the exporter. lExporter->Destroy();
Use the FbxManager::GetFileFormatVersion() method to obtain the exported FBX file version number. For the latest FBX file version number, see Supported File Formats.
// File format version numbers to be populated. int lMajor, lMinor, lRevision; // Populate the exported file format version numbers. FbxManager::GetFileFormatVersion(lMajor, lMinor, lRevision);
As of FBX SDK 2012.0, the header file fbxfilesdk_version.h defines the preprocessor identifer FBXSDK_VERSION_STRING, which represents the version information as a string.
To export a scene and have its media embedded within the exported FBX file, the binary (or native) FBX file format identifier must be specified in the call to FbxExporter::Initialize(). The following code snippet illustrates how to perform this task. Recall that the FbxIOSettings object must also be configured to embed the scene's media into the file (see I/O Settings).
// ... Initialize the required objects and variables ... // Set the FbxIOSettings EXP_FBX_EMBEDDED property to true. (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_EMBEDDED, true); // Get the appropriate file format. int lFileFormat = lSdkManager->GetIOPluginRegistry()->GetNativeWriterFormat(); // Initialize the exporter to embed the scene's media into the exported file. bool lExportStatus lExporter->Initialize(lFilename, lFileFormat, lSdkManager->GetIOSettings()); // ... Export the scene ...