diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-18 04:44:57 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-18 04:44:57 +0300 |
commit | 02522412e2b15c63020d72fd4f27556659b8d6a3 (patch) | |
tree | 6b1fdb98f2d2bf913cf68c2efb84f79ba3d3b377 /io_scene_obj | |
parent | 7e12649226fa6eeda7026cc2e8ba9f5a09be1400 (diff) |
Fix T62695: OBJ mtllib fails when filename contains spaces
Diffstat (limited to 'io_scene_obj')
-rw-r--r-- | io_scene_obj/import_obj.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index 8cdedc77..290445f5 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -58,6 +58,21 @@ def line_value(line_split): return b' '.join(line_split[1:]) +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') + """ + line_lower = line.lower() + i_prev = 0 + while i_prev != -1 and i_prev < len(line): + i = line_lower.find(ext, i_prev) + if i != -1: + i += len(ext) + yield line[i_prev:i].strip() + i_prev = i + + def obj_image_load(context_imagepath_map, line, DIR, recursive, relpath): """ Mainly uses comprehensiveImageLoad @@ -1118,7 +1133,8 @@ def load(context, elif line_start == b'mtllib': # usemap or usemat # can have multiple mtllib filenames per line, mtllib can appear more than once, # so make sure only occurrence of material exists - material_libs |= {os.fsdecode(f) for f in line.split()[1:]} + material_libs |= {os.fsdecode(f) for f in filenames_group_by_ext(line.lstrip()[7:].strip(), b'.mtl') + } # Nurbs support elif line_start == b'cstype': |