Add option "--fbx-tmp-dir" (#219)

Merge code from @shrinktofit that allows control over where temporary files are created.

(Most commonly the .fbm directory where the SDK extracts embedded resources.)
This commit is contained in:
Leslie Leigh 2019-08-06 23:39:59 +08:00 committed by Pär Winzell
parent 6437d02e5f
commit 648fdfb944
3 changed files with 39 additions and 1 deletions

View File

@ -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;

View File

@ -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;
};

View File

@ -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<const char*>(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<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(fbxFileName.c_str(), -1, pManager->GetIOSettings())) {
if (!pImporter->Initialize(fbxFileNameU8.c_str(), -1, pManager->GetIOSettings())) {
if (verboseOutput) {
fmt::printf("%s\n", pImporter->GetStatus().GetErrorString());
}