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.
This commit is contained in:
parent
e9067850e1
commit
f2a057d783
|
@ -563,7 +563,9 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std:
|
||||||
|
|
||||||
const auto maybeAddTexture = [&](FbxFileTexture *tex, RawTextureUsage usage) {
|
const auto maybeAddTexture = [&](FbxFileTexture *tex, RawTextureUsage usage) {
|
||||||
if (tex != nullptr) {
|
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<std::string> &directoryFileList)
|
static std::string GetInferredFileName(const char *fbxFileName, const char *directory, const std::vector<std::string> &directoryFileList)
|
||||||
{
|
{
|
||||||
// Get the file name with file extension.
|
// Get the file name with file extension.
|
||||||
|
@ -1004,7 +994,7 @@ static void
|
||||||
FindFbxTextures(FbxScene *pScene, const char *fbxFileName, const char *extensions, std::map<const FbxTexture *, FbxString> &textureNames)
|
FindFbxTextures(FbxScene *pScene, const char *fbxFileName, const char *extensions, std::map<const FbxTexture *, FbxString> &textureNames)
|
||||||
{
|
{
|
||||||
// Get the folder the FBX file is in.
|
// 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.
|
// 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/";
|
const FbxString fbmFolderName = folder + Gltf::StringUtils::GetFileBaseString(fbxFileName).c_str() + ".fbm/";
|
||||||
|
|
|
@ -327,10 +327,10 @@ ModelData *Raw2Gltf(
|
||||||
|
|
||||||
for (int textureIndex = 0; textureIndex < raw.GetTextureCount(); textureIndex++) {
|
for (int textureIndex = 0; textureIndex < raw.GetTextureCount(); textureIndex++) {
|
||||||
const RawTexture &texture = raw.GetTexture(textureIndex);
|
const RawTexture &texture = raw.GetTexture(textureIndex);
|
||||||
std::string textureName = Gltf::StringUtils::GetFileBaseString(texture.name);
|
const std::string textureName = Gltf::StringUtils::GetFileBaseString(texture.name);
|
||||||
// texture.name is the inferred filename on *our* system
|
const std::string texFilename = texture.fileName;
|
||||||
const std::string texFilename = texture.name;
|
|
||||||
ImageData *source = nullptr;
|
ImageData *source = nullptr;
|
||||||
if (options.outputBinary) {
|
if (options.outputBinary) {
|
||||||
std::ifstream file(texFilename, std::ios::binary | std::ios::ate);
|
std::ifstream file(texFilename, std::ios::binary | std::ios::ate);
|
||||||
if (file) {
|
if (file) {
|
||||||
|
|
|
@ -169,12 +169,12 @@ Copyright (c) 2016-2017 Oculus VR, LLC.
|
||||||
} else {
|
} else {
|
||||||
// in gltf mode, we create a folder and write into that
|
// in gltf mode, we create a folder and write into that
|
||||||
outputFolder = outputPath + "_out/";
|
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";
|
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;
|
ModelData *data_render_model = nullptr;
|
||||||
RawModel raw;
|
RawModel raw;
|
||||||
|
|
Loading…
Reference in New Issue