diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-07-22 19:36:55 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-07-22 19:41:05 +0300 |
commit | 05dc8caa35da9914a0c0da61bb0dd49aa292e9ce (patch) | |
tree | 1b062d3e0ea149e555f3693212fa1c84240e9851 /io_scene_obj | |
parent | 24eec014a6fb16ca092bf77a835c95b412795017 (diff) |
Fix T67266: .obj import error with mtllib name in quotes - regression from 2.79b.
While this is not officialy part of OBJ format, some softwares 'solve'
the spaces-in-filenames issue by delimiting those with quotes.
Since this is not too much a hassle, let's add back support for this.
Based on work from Robert Guetzkow (@rjg), thanks.
Note: not sure whether this should be ported to 2.80 release, while this
change should be reasonably safe, it's not an obvious one-liner either,
and the issue is not really critical (don’t think any major software
uses that trick?)...
Diffstat (limited to 'io_scene_obj')
-rw-r--r-- | io_scene_obj/__init__.py | 2 | ||||
-rw-r--r-- | io_scene_obj/import_obj.py | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py index ae3780bd..fdcb3021 100644 --- a/io_scene_obj/__init__.py +++ b/io_scene_obj/__init__.py @@ -21,7 +21,7 @@ bl_info = { "name": "Wavefront OBJ format", "author": "Campbell Barton, Bastien Montagne", - "version": (3, 5, 9), + "version": (3, 5, 10), "blender": (2, 80, 0), "location": "File > Import-Export", "description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures", diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index c565bd05..78d80872 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -62,7 +62,21 @@ def filenames_group_by_ext(line, ext): """ Splits material libraries supporting spaces, so: b'foo bar.mtl baz spam.MTL' -> (b'foo bar.mtl', b'baz spam.MTL') + Also handle " chars (some softwares use those to protect filenames with spaces, see T67266... sic). """ + # Note that we assume that if there are some " in that line, + # then all filenames are properly enclosed within those... + start = line.find(b'"') + 1 + if start != 0: + while start != 0: + end = line.find(b'"', start) + if end != -1: + yield line[start:end] + start = line.find(b'"', end + 1) + 1 + else: + break + return + line_lower = line.lower() i_prev = 0 while i_prev != -1 and i_prev < len(line): @@ -79,8 +93,16 @@ def obj_image_load(context_imagepath_map, line, DIR, recursive, relpath): 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 softwares use those to protect filenames with spaces, see T67266... sic). """ filepath_parts = line.split(b' ') + + start = line.find(b'"') + 1 + if start != 0: + end = line.find(b'"', start) + if end != 0: + filepath_parts = (line[start:end],) + image = None for i in range(-1, -len(filepath_parts), -1): imagepath = os.fsdecode(b" ".join(filepath_parts[i:])) |