bool LoadFBXFile()

in src/fbx/Fbx2Raw.cpp [1091:1160]


bool LoadFBXFile(
    RawModel& raw,
    const std::string fbxFileName,
    const std::set<std::string>& textureExtensions,
    const GltfOptions& options) {
  std::string fbxFileNameU8 = NativeToUTF8(fbxFileName);
  FbxManager* pManager = FbxManager::Create();

  if (!options.fbxTempDir.empty()) {
    pManager->GetXRefManager().AddXRefProject("embeddedFileProject", options.fbxTempDir.c_str());
    FbxXRefManager::sEmbeddedFileProject = "embeddedFileProject";
    pManager->GetXRefManager().AddXRefProject("configurationProject", options.fbxTempDir.c_str());
    FbxXRefManager::sConfigurationProject = "configurationProject";
    pManager->GetXRefManager().AddXRefProject("localizationProject", options.fbxTempDir.c_str());
    FbxXRefManager::sLocalizationProject = "localizationProject";
    pManager->GetXRefManager().AddXRefProject("temporaryFileProject", options.fbxTempDir.c_str());
    FbxXRefManager::sTemporaryFileProject = "temporaryFileProject";
  }

  FbxIOSettings* pIoSettings = FbxIOSettings::Create(pManager, IOSROOT);
  pManager->SetIOSettings(pIoSettings);

  FbxImporter* pImporter = FbxImporter::Create(pManager, "");

  if (!pImporter->Initialize(fbxFileNameU8.c_str(), -1, pManager->GetIOSettings())) {
    if (verboseOutput) {
      fmt::printf("%s\n", pImporter->GetStatus().GetErrorString());
    }
    pImporter->Destroy();
    pManager->Destroy();
    return false;
  }

  FbxScene* pScene = FbxScene::Create(pManager, "fbxScene");
  pImporter->Import(pScene);
  pImporter->Destroy();

  if (pScene == nullptr) {
    pImporter->Destroy();
    pManager->Destroy();
    return false;
  }

  std::map<const FbxTexture*, FbxString> textureLocations;
  FindFbxTextures(pScene, fbxFileName, textureExtensions, textureLocations);

  // Use Y up for glTF
  FbxAxisSystem::MayaYUp.ConvertScene(pScene);

  // FBX's internal unscaled unit is centimetres, and if you choose not to work in that unit,
  // you will find scaling transforms on all the children of the root node. Those transforms are
  // superfluous and cause a lot of people a lot of trouble. Luckily we can get rid of them by
  // converting to CM here (which just gets rid of the scaling), and then we pre-multiply the
  // scale factor into every vertex position (and related attributes) instead.
  FbxSystemUnit sceneSystemUnit = pScene->GetGlobalSettings().GetSystemUnit();
  if (sceneSystemUnit != FbxSystemUnit::cm) {
    FbxSystemUnit::cm.ConvertScene(pScene);
  }
  // this is always 0.01, but let's opt for clarity.
  scaleFactor = FbxSystemUnit::m.GetConversionFactorFrom(FbxSystemUnit::cm);

  ReadNodeHierarchy(raw, pScene, pScene->GetRootNode(), 0, "");
  ReadNodeAttributes(raw, pScene, pScene->GetRootNode(), textureLocations);
  ReadAnimations(raw, pScene, options);

  pScene->Destroy();
  pManager->Destroy();

  return true;
}