Creating a file importer
 
 
 

Toimport a fileinto a scene (i.e., toloada scene with the contents of a file), you must first create animporterobject.importexport()callsLoadScene()to do all the steps in loading the scene:

 bool r = LoadScene(lSdkManager, lScene, ImportFileName);
 ...
bool LoadScene(
 KFbxSdkManager* pSdkManager, // Use this memory manager...
 KFbxScene* pScene, // to import into this scene
 const char* pFilename // the data from this file.
 )
 // Create an importer.
 KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager,"");

FBX can import many different kinds of files: FBX files in abinary(ornative) format, FBX files in an ASCII format, FBX files using earlier versions of the FBX file format, and even some non-FBX file formats.

The importer needs to know the file format of file it will be importing. This is because the same extension can be used for different file formats. For example, .fbx extension can refer to a binary FBX file or an ASCII FBX file.

 // Detect the file format of the file to be imported
 if (!KFbxIOPluginRegistryAccessor::Get()->DetectFileFormat(
 pFilename,
 lFileFormat
 ))
 { // ... Error handling code ... }
 lImporter->SetFileFormat(lFileFormat);

The importer also needs to know the path and name of the file to be imported.

 const bool lImportStatus = lImporter->Initialize(pFilename);

For FBX files, ImportExport checks whether the version number of the file format used by the FBX file is supported by the version number of the FBX SDK library that it is linked to:

 // Get version number of FBX SDK
 KFbxIO::GetCurrentVersion(lSDKMajor, lSDKMinor, lSDKRevision);
 ...
 // Get the version number of the FBX file format.
 lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);

Here is an example of FBX error handling:

 if( !lImportStatus ) // Problem with the file to be imported
 {
 UI_Printf("Call to KFbxImporter::Initialize() failed.");
 UI_Printf("Error returned: %s", lImporter->GetLastErrorString());
 if (lImporter->GetLastErrorID() ==
 KFbxIO::eFILE_VERSION_NOT_SUPPORTED_YET ||
 lImporter->GetLastErrorID() ==
 KFbxIO::eFILE_VERSION_NOT_SUPPORTED_ANYMORE)
 {
 UI_Printf("FBX version number for this FBX SDK is %d.%d.%d",
 lSDKMajor, lSDKMinor, lSDKRevision);
 UI_Printf("FBX version number for file %s is %d.%d.%d",
 pFilename, lFileMajor, lFileMinor, lFileRevision);
 }
 return false;
 }
 UI_Printf("FBX version number for this FBX SDK is %d.%d.%d",
 lSDKMajor, lSDKMinor, lSDKRevision);

Now we’re ready to load the scene.