in libraries/hvvr/samples_shared/model_import_fbx.cpp [57:125]
bool importFbx(const char* path, model_import::Model& model) {
auto managerDeleter = [](FbxManager* manager) { manager->Destroy(); };
std::unique_ptr<FbxManager, decltype(managerDeleter)> fbxManager(FbxManager::Create(), managerDeleter);
FbxIOSettings* ioSettings = FbxIOSettings::Create(fbxManager.get(), IOSROOT);
FbxScene* scene = FbxScene::Create(fbxManager.get(), "ImportScene");
FbxImporter* importer = FbxImporter::Create(fbxManager.get(), "");
fbxManager->SetIOSettings(ioSettings);
printf("info: Autodesk FBX SDK version %s\n", fbxManager->GetVersion());
if (!importer->Initialize(path, -1, ioSettings)) {
FbxString error = importer->GetStatus().GetErrorString();
printf("error: Call to FbxImporter::Initialize() failed.\n");
printf("error: Error returned: %s\n", error.Buffer());
if (importer->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion) {
int lFileMajor, lFileMinor, lFileRevision;
int lSDKMajor, lSDKMinor, lSDKRevision;
// Get the file version number generate by the FBX SDK.
FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision);
importer->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);
printf("error: FBX file format version for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
printf("error: FBX file format version for file '%s' is %d.%d.%d\n", path, lFileMajor, lFileMinor,
lFileRevision);
}
printf("error: Failed to initialize the importer for '%s'.\n", path);
return false;
}
// Set the import states. Default is true.
ioSettings->SetBoolProp(IMP_FBX_MATERIAL, true);
ioSettings->SetBoolProp(IMP_FBX_TEXTURE, true);
ioSettings->SetBoolProp(IMP_FBX_LINK, true);
ioSettings->SetBoolProp(IMP_FBX_SHAPE, true);
ioSettings->SetBoolProp(IMP_FBX_GOBO, true);
ioSettings->SetBoolProp(IMP_FBX_ANIMATION, false);
ioSettings->SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
// Import the scene.
if (!importer->Import(scene)) {
if (importer->GetStatus().GetCode() == FbxStatus::ePasswordError) {
printf("error: File is password protected.\n");
return false;
}
printf("error: Failed to load the scene : '%s'\n", path);
return false;
}
// convert to meters
if (scene->GetGlobalSettings().GetSystemUnit() != FbxSystemUnit::m)
FbxSystemUnit::m.ConvertScene(scene);
// triangulate
FbxGeometryConverter GeometryConverter(fbxManager.get());
GeometryConverter.Triangulate(scene, true, false);
FbxNode* root = scene->GetRootNode();
if (!root) {
printf("error: Scene has no root node when importing '%s'.\n", path);
return false;
}
ImportState state(model);
if (!importNode(state, root))
return false;
return true;
}