Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Oeser <info@graphics-engineer.com>2019-12-04 15:51:17 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2019-12-16 14:43:00 +0300
commitbf89c1eb28007fdd491b5a0b7cb3709b84d88b85 (patch)
tree3666709171bc18c0505be79c06dec026677bca1c /io_scene_obj
parenta7acf9e1d3ac63430b3a0671e106c0ec29d696fe (diff)
Fix T72148: OBJ import could fail with spaces in filenames
Thing here was that files could actually be loaded ('obj_image_load' has smart code for this), but tokenizing the corresponding line afterwards could still fail [would have part of a filename still in image_data list]. Now also correct this 'image_data' list in case 'obj_image_load' found images with filename spaces. Maniphest Tasks: T72148 Differential Revision: https://developer.blender.org/D6358
Diffstat (limited to 'io_scene_obj')
-rw-r--r--io_scene_obj/import_obj.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 0cb6be77..db4efb9a 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -87,13 +87,14 @@ def filenames_group_by_ext(line, ext):
i_prev = i
-def obj_image_load(context_imagepath_map, line, DIR, recursive, relpath):
+def obj_image_load(img_data, context_imagepath_map, line, DIR, recursive, relpath):
"""
Mainly uses comprehensiveImageLoad
But we try all space-separated items from current line when file is not found with last one
(users keep generating/using image files with spaces in a format that does not support them, sigh...)
Also tries to replace '_' with ' ' for Max's exporter replaces spaces with underscores.
Also handle " chars (some software use those to protect filenames with spaces, see T67266... sic).
+ Also corrects img_data (in case filenames with spaces have been split up in multiple entries, see T72148).
"""
filepath_parts = line.split(b' ')
@@ -113,7 +114,13 @@ def obj_image_load(context_imagepath_map, line, DIR, recursive, relpath):
image = load_image(imagepath.replace("_", " "), DIR, recursive=recursive, relpath=relpath)
if image is not None:
context_imagepath_map[imagepath] = image
+ del img_data[i:]
+ img_data.append(imagepath)
break;
+ else:
+ del img_data[i:]
+ img_data.append(imagepath)
+ break;
if image is None:
imagepath = os.fsdecode(filepath_parts[-1])
@@ -147,6 +154,9 @@ def create_materials(filepath, relpath,
"""
map_options = {}
+ # Absolute path - c:\.. etc would work here
+ image = obj_image_load(img_data, context_imagepath_map, line, DIR, use_image_search, relpath)
+
curr_token = []
for token in img_data[:-1]:
if token.startswith(b'-') and token[1:].isalpha():
@@ -157,9 +167,6 @@ def create_materials(filepath, relpath,
if curr_token:
map_options[curr_token[0]] = curr_token[1:]
- # Absolute path - c:\.. etc would work here
- image = obj_image_load(context_imagepath_map, line, DIR, use_image_search, relpath)
-
map_offset = map_options.get(b'-o')
map_scale = map_options.get(b'-s')
if map_offset is not None: