Fix #105395: Handle quoted paths better in the OBJ importer #105478

Merged
Jesse Yurkovich merged 1 commits from deadpin/blender:fix105395-objquote into blender-v3.5-release 2023-03-06 06:29:51 +01:00
1 changed files with 10 additions and 16 deletions

View File

@ -98,39 +98,33 @@ static Image *load_texture_image(Main *bmain, const MTLTexMap &tex_map, bool rel
{
Image *image = nullptr;
/* Remove quotes. */
std::string image_path{tex_map.image_path};
auto end_pos = std::remove(image_path.begin(), image_path.end(), '"');
image_path.erase(end_pos, image_path.end());
/* First try treating texture path as relative. */
std::string tex_path{tex_map.mtl_dir_path + tex_map.image_path};
std::string tex_path{tex_map.mtl_dir_path + image_path};
image = load_image_at_path(bmain, tex_path, relative_paths);
if (image != nullptr) {
return image;
}
/* Then try using it directly as absolute path. */
std::string raw_path{tex_map.image_path};
image = load_image_at_path(bmain, raw_path, relative_paths);
image = load_image_at_path(bmain, image_path, relative_paths);
if (image != nullptr) {
return image;
}
/* Try removing quotes. */
std::string no_quote_path{tex_path};
auto end_pos = std::remove(no_quote_path.begin(), no_quote_path.end(), '"');
no_quote_path.erase(end_pos, no_quote_path.end());
if (no_quote_path != tex_path) {
image = load_image_at_path(bmain, no_quote_path, relative_paths);
if (image != nullptr) {
return image;
}
}
/* Try replacing underscores with spaces. */
std::string no_underscore_path{no_quote_path};
std::string no_underscore_path{image_path};
std::replace(no_underscore_path.begin(), no_underscore_path.end(), '_', ' ');
if (!ELEM(no_underscore_path, no_quote_path, tex_path)) {
if (!ELEM(no_underscore_path, image_path, tex_path)) {
image = load_image_at_path(bmain, no_underscore_path, relative_paths);
if (image != nullptr) {
return image;
}
}
/* Try taking just the basename from input path. */
std::string base_path{tex_map.mtl_dir_path + BLI_path_basename(tex_map.image_path.c_str())};
std::string base_path{tex_map.mtl_dir_path + BLI_path_basename(image_path.c_str())};
if (base_path != tex_path) {
image = load_image_at_path(bmain, base_path, relative_paths);
if (image != nullptr) {