From f2a057d78390661efa9a65448b173a0609a5ad32 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Mon, 16 Oct 2017 23:27:24 -0700 Subject: [PATCH] Do a better job resolving texture files. - Nix GetFileFolder(). It was not helping. Always search for textures - near the FBX file. - Use RawTexture::name for the texture name and ::fileName for the inferred local filename path. --- src/Fbx2Raw.cpp | 18 ++++-------------- src/Raw2Gltf.cpp | 8 ++++---- src/main.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp index b9687f0..e5cd64d 100644 --- a/src/Fbx2Raw.cpp +++ b/src/Fbx2Raw.cpp @@ -563,7 +563,9 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std: const auto maybeAddTexture = [&](FbxFileTexture *tex, RawTextureUsage usage) { if (tex != nullptr) { - textures[usage] = raw.AddTexture(tex->GetName(), tex->GetFileName(), usage); + // dig out the inferred filename from the textureNames map + const char *inferredPath = textureNames.find(tex)->second; + textures[usage] = raw.AddTexture(tex->GetName(), inferredPath, usage); } }; @@ -946,18 +948,6 @@ static void ReadAnimations(RawModel &raw, FbxScene *pScene) } } -static FbxString GetFileFolder(const char *fileName) -{ - std::string clean = Gltf::StringUtils::GetCleanPathString(fileName, Gltf::StringUtils::PATH_UNIX); - - FbxString folder = clean.c_str(); - folder = folder.Left(folder.ReverseFind('/') + 1); // strip the file name - if (folder.GetLen() < 2 || folder[1] != ':') { - folder = std::string(FileUtils::GetCurrentFolder() + folder.Buffer()).c_str(); - } - return folder; -} - static std::string GetInferredFileName(const char *fbxFileName, const char *directory, const std::vector &directoryFileList) { // Get the file name with file extension. @@ -1004,7 +994,7 @@ static void FindFbxTextures(FbxScene *pScene, const char *fbxFileName, const char *extensions, std::map &textureNames) { // Get the folder the FBX file is in. - const FbxString folder = GetFileFolder(fbxFileName); + const FbxString folder = Gltf::StringUtils::GetFolderString(fbxFileName).c_str(); // Check if there is a filename.fbm folder to which embedded textures were extracted. const FbxString fbmFolderName = folder + Gltf::StringUtils::GetFileBaseString(fbxFileName).c_str() + ".fbm/"; diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index 1149fe5..9bedb67 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -327,10 +327,10 @@ ModelData *Raw2Gltf( for (int textureIndex = 0; textureIndex < raw.GetTextureCount(); textureIndex++) { const RawTexture &texture = raw.GetTexture(textureIndex); - std::string textureName = Gltf::StringUtils::GetFileBaseString(texture.name); - // texture.name is the inferred filename on *our* system - const std::string texFilename = texture.name; - ImageData *source = nullptr; + const std::string textureName = Gltf::StringUtils::GetFileBaseString(texture.name); + const std::string texFilename = texture.fileName; + + ImageData *source = nullptr; if (options.outputBinary) { std::ifstream file(texFilename, std::ios::binary | std::ios::ate); if (file) { diff --git a/src/main.cpp b/src/main.cpp index 79e41ac..eb2d324 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,12 +169,12 @@ Copyright (c) 2016-2017 Oculus VR, LLC. } else { // in gltf mode, we create a folder and write into that outputFolder = outputPath + "_out/"; - if (!FileUtils::CreatePath(outputFolder.c_str())) { - fmt::fprintf(stderr, "ERROR: Failed to create folder: %s'\n", outputFolder.c_str()); - return 1; - } modelPath = outputFolder + Gltf::StringUtils::GetFileNameString(outputPath) + ".gltf"; } + if (!FileUtils::CreatePath(modelPath.c_str())) { + fmt::fprintf(stderr, "ERROR: Failed to create folder: %s'\n", outputFolder.c_str()); + return 1; + } ModelData *data_render_model = nullptr; RawModel raw;