diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index 12c8dcc..e65c310 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -237,6 +237,8 @@ int main(int argc, char* argv[]) { ->check(CLI::Range(1, 32)) ->group("Draco"); + app.add_option("--fbx-temp-dir", gltfOptions.fbxTempDir, "Temporary directory to be used by FBX SDK.")->check(CLI::ExistingDirectory); + CLI11_PARSE(app, argc, argv); bool do_flip_u = false; diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index e075bbd..cd0690b 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -122,4 +122,7 @@ struct GltfOptions { UseLongIndicesOptions useLongIndices = UseLongIndicesOptions::AUTO; /** Select baked animation framerate. */ AnimationFramerateOptions animationFramerate = AnimationFramerateOptions::BAKE24; + + /** Temporary directory used by FBX SDK. */ + std::string fbxTempDir; }; diff --git a/src/fbx/Fbx2Raw.cpp b/src/fbx/Fbx2Raw.cpp index ed74f2c..4f56f0e 100644 --- a/src/fbx/Fbx2Raw.cpp +++ b/src/fbx/Fbx2Raw.cpp @@ -34,6 +34,26 @@ float scaleFactor; +static std::string NativeToUTF8(const std::string &str) { +#if _WIN32 + char* u8cstr = nullptr; +#if (_UNICODE || UNICODE) + FbxWCToUTF8(reinterpret_cast(str.c_str()), u8cstr); +#else + FbxAnsiToUTF8(str.c_str(), u8cstr); +#endif + if (!u8cstr) { + return str; + } else { + std::string u8str = u8cstr; + delete[] u8cstr; + return u8str; + } +#else + return str; +#endif +} + static bool TriangleTexturePolarity(const Vec2f& uv0, const Vec2f& uv1, const Vec2f& uv2) { const Vec2f d0 = uv1 - uv0; const Vec2f d1 = uv2 - uv0; @@ -1073,13 +1093,26 @@ bool LoadFBXFile( const std::string fbxFileName, const std::set& 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(fbxFileName.c_str(), -1, pManager->GetIOSettings())) { + if (!pImporter->Initialize(fbxFileNameU8.c_str(), -1, pManager->GetIOSettings())) { if (verboseOutput) { fmt::printf("%s\n", pImporter->GetStatus().GetErrorString()); }