Class KFbxSdkManager (sometimes called the SDK manager) is the memory manager for FBX SDK. You will use it, directly or indirectly, whenever you instantiate an FBX SDK object, and again whenever you destroy an FBX SDK object. An FBX application normally:
Normally, an FBX application needs only one SDK manager object.
Almost all classes in FBX SDK have a Create() member function and a Destroy() member function. Whenever you call these functions, SDK Manager automatically looks after allocating and releasing memory.
This code snippet declares an SDK manager object and then instantiates it:
KFbxSdkManager* mySdkManager = NULL;
...
mySdkManager = KFbxSdkManager::Create();
Using SDK manager to create a scene object
When you create a scene object, you must pass the SDK manager object that will manage memory for that scene:
// Create a scene object
KFbxScene* myScene = KFbxScene::Create(mySdkManager, "");
Most FBX applications need only one scene. But if, for example, you wish to load (i.e., import) several FBX files into memory and work with them all at the same time, you can create a separate scene for each file.
Using a scene object to create other FBX objects
Most classes in FBX SDK have a Create() member function which you use in place of a constructor.
To instantiate (create) an object of most FBX classes:
// Create a node object
KFbxNode* myNode = KFbxNode::Create (myScene, "");
// Create an mesh object
KFbxImporter* myMesh = KFbxMesh::Create (myScene, "");
The scene that you pass as a parameter knows to which SDK manager it belongs. That SDK manager is responsible for allocating memory for the node, mesh, or other FBX object that you are instantiating.
Specifying names for FBX objects
The second parameter of Create() is an optional name for the object. You can specify any name as a string: the name does not need to be unique. You can also specify an empty string. Examples:
// Create a scene object named My Scene
KFbxScene* myScene = KFbxScene::Create(mySdkManager, "My Scene");
// Create a node object named My Own Node
KFbxNode* myNode = KFbxNode::Create (myScene, "My Own Node");
// Create a mesh object named My Very Own Mesh
KFbxMesh* myMesh = KFbxMesh::Create (myScene, "My Very Own Mesh");
// Create a camera object with no name
KFbxCamera* myCamera = KFbxCamera::Create (myScene, "");
Because the names of FBX objects need not be unique, you cannot simply “get” an FBX object by specifying its name. But you can write code to enumerate all the objects in a scene that have a specified name.
Creating FBX objects that belong to no scene
If for any reason you wish to create an object that is not a part of any specified scene, you can pass an SDK manager object rather than a scene object:
// Create a camera manipulator object to be used in several scenes
KFbxCameraManipulator* myCameraManipulator =
KFbxCameraManipulator::Create (mySDKManager, "");
Always destroy an FBX object using its Destroy() member function. SDK Manager will automatically free all memory allocated for the object. SDK Manager will also update all connections to that object that are stored in other FBX objects (see Connections).
To destroy any object created with Create():
// Destroy these objects
myMesh->Destroy(); // Destroy the mesh
myNode->Destroy(); // Destroy the node
myScene->Destroy(); // Destroy the scene and its objects
mySDKManager->Destroy() // Destroy SDK Manager and its objects
Notes on destroying an object:
To clean up memory after using FBX SDK:
This will also destroy any remaining SDK objects managed by that SDK Manager.
// Destroy the FBX SDK manager.
// All the objects that
// (1) have been allocated by the memory manager, AND that
// (2) have not been explicitly destroyed
// will be automatically destroyed.
if (mySdkManager) mySdkManager->Destroy();
Specifying your own memory allocation routines
FBX implements its own memory allocation routines (i.e., malloc, calloc, realloc, free, and msize). By default, whenever you create() an FBXobject, SDK Manager allocates and manages memory for that object using the FBX memory allocation routines.
If you want FBX SDK to use another set of routines, call KFbxSdkManager::SetMemoryAllocator before creating any KFbxSdkManager object. SetMemoryAllocator() takes a KFbxMemoryAllocator object as a parameter.