The FbxManager class is responsible for creating, managing, and destroying FBX SDK objects. Only one FbxManager instance is required for a given program. The creation of this FbxManager singleton is typically the first action of any FBX SDK program.
FbxManager* lSdkManager = FbxManager::Create();
Objects in the FBX SDK are created or destroyed by means of their respective Create() and Destroy() member functions. At a lower level, these functions rely on the FbxManager to allocate and release memory. In the following example, the FbxManager is passed as a parameter to the FbxScene::Create() function to instantiate a new scene.
FbxScene* lScene = FbxScene::Create(lSdkManager, "Scene Name");
The SDK object manager (FbxManager) automatically allocates a sufficient amount of memory to contain the new object. Though not necessary, the memory allocation strategy of the object manager can be customized using the handler setter functions such as FbxSetMallocHandler located in fbxalloc.h. See the ViewScene/main.cxx example for information about how to use a custom memory allocator.
In the code snippet above, the second parameter of FbxScene::Create() is a string. When objects are created, a string can be used to specify the name of the new object. This string does not have to be unique, and it is acceptable to pass an empty string "". Object names can facilitate the debugging of FBX SDK applications and their outputs.
A FbxScene object can contain a variety of scene elements such as meshes, lights, animations, characters, etc. These elements should be created with a reference to the scene in which they exist. As such, when the scene is exported, so are all of its elements. When the scene is destroyed, the memory allocated to all of its objects is also released. The Nodes and the Scene Graph section describes the use of the FbxNode and FbxNodeAttribute classes to define and manipulate scene elements. For now, we will only look at how a FbxScene can be used to create these objects.
// Create a node object FbxNode* lNode = FbxNode::Create(lScene, "node"); // Create a mesh object FbxMesh* lMesh = FbxMesh::Create(lScene, "");
An FBX SDK object should be explicitly destroyed by calling its Destroy() member function. The FbxManager will automatically free the memory allocated for that object, and will update all the internal connections between that object (FbxObject), its properties (FbxProperty), and other FbxObject to remove any inconsistencies. For more information on the concept of connections in the FBX SDK, see Connections. The following code snippet illustrates how to destroy the objects we instantiated above.
// Destroy these objects lMesh->Destroy(); // Destroy the mesh lNode->Destroy(); // Destroy the node lScene->Destroy(); // Destroy the scene and its objects lSDKManager->Destroy() // Destroy SDK Manager and any remaining objects which it manages.