in src/fbx/Fbx2Raw.cpp [1047:1089]
static void FindFbxTextures(
FbxScene* pScene,
const std::string& fbxFileName,
const std::set<std::string>& extensions,
std::map<const FbxTexture*, FbxString>& textureLocations) {
// figure out what folder the FBX file is in,
const auto& fbxFolder = FileUtils::getFolder(fbxFileName);
std::vector<std::string> folders{
// first search filename.fbm folder which the SDK itself expands embedded textures into,
fbxFolder + "/" + FileUtils::GetFileBase(fbxFileName) + ".fbm", // filename.fbm
// then the FBX folder itself,
fbxFolder,
// then finally our working directory
FileUtils::GetCurrentFolder(),
};
// List the contents of each of these folders (if they exist)
std::vector<std::vector<std::string>> folderContents;
for (const auto& folder : folders) {
if (FileUtils::FolderExists(folder)) {
folderContents.push_back(FileUtils::ListFolderFiles(folder, extensions));
} else {
folderContents.push_back({});
}
}
// Try to match the FBX texture names with the actual files on disk.
for (int i = 0; i < pScene->GetTextureCount(); i++) {
const FbxFileTexture* pFileTexture = FbxCast<FbxFileTexture>(pScene->GetTexture(i));
if (pFileTexture != nullptr) {
const std::string fileLocation =
FindFbxTexture(pFileTexture->GetFileName(), folders, folderContents);
// always extend the mapping (even for files we didn't find)
textureLocations.emplace(pFileTexture, fileLocation.c_str());
if (fileLocation.empty()) {
fmt::printf(
"Warning: could not find a image file for texture: %s.\n", pFileTexture->GetName());
} else if (verboseOutput) {
fmt::printf("Found texture '%s' at: %s\n", pFileTexture->GetName(), fileLocation);
}
}
}
}