Fix #145244: FBX importer does not import textures from some files
Some FBX files contain somewhat incorrect relative paths for their material textures. The old Python importer was "working" only as a side effect that it was exhaustively searching the subfolder hierarchy. Try to do a smaller version of that here too: if referenced image is still not found after trying the regular relative/absolute paths, try taking longer path parent chains from the absolute path coming from FBX file, and using that as relative path wrt the FBX file itself. Pull Request: https://projects.blender.org/blender/blender/pulls/145641
This commit is contained in:
committed by
Aras Pranckevicius
parent
59949b04b3
commit
37b1886769
@@ -214,14 +214,31 @@ static Image *load_texture_image(Main *bmain, const std::string &file_dir, const
|
||||
{
|
||||
/* Check with filename directly. */
|
||||
Image *image = BKE_image_load_exists(bmain, tex.filename.data);
|
||||
/* Try loading as a relative path. */
|
||||
if (image == nullptr) {
|
||||
/* Try loading as a relative path. */
|
||||
std::string path = file_dir + "/" + tex.filename.data;
|
||||
image = BKE_image_load_exists(bmain, path.c_str());
|
||||
if (image == nullptr) {
|
||||
/* Try loading with absolute path from FBX. */
|
||||
image = BKE_image_load_exists(bmain, tex.absolute_filename.data);
|
||||
}
|
||||
}
|
||||
/* Try loading with absolute path from FBX. */
|
||||
if (image == nullptr) {
|
||||
image = BKE_image_load_exists(bmain, tex.absolute_filename.data);
|
||||
}
|
||||
|
||||
/* If still not found, try taking progressively longer parts of the absolute path,
|
||||
* as relative to the file. */
|
||||
if (image == nullptr) {
|
||||
size_t pos = tex.absolute_filename.length;
|
||||
do {
|
||||
const char *parent_path = BLI_path_parent_dir_end(tex.absolute_filename.data, pos);
|
||||
if (parent_path == nullptr) {
|
||||
break;
|
||||
}
|
||||
char path[FILE_MAX];
|
||||
BLI_path_join(path, sizeof(path), file_dir.c_str(), parent_path);
|
||||
BLI_path_normalize(path);
|
||||
image = BKE_image_load_exists(bmain, path);
|
||||
pos = parent_path - tex.absolute_filename.data;
|
||||
} while (image == nullptr);
|
||||
}
|
||||
|
||||
/* Create dummy/placeholder image. */
|
||||
|
||||
Reference in New Issue
Block a user