[Bf-extensions-cvs] [02522412] master: Fix T62695: OBJ mtllib fails when filename contains spaces

Campbell Barton noreply at git.blender.org
Mon Mar 18 02:46:16 CET 2019


Commit: 02522412e2b15c63020d72fd4f27556659b8d6a3
Author: Campbell Barton
Date:   Mon Mar 18 12:44:57 2019 +1100
Branches: master
https://developer.blender.org/rBA02522412e2b15c63020d72fd4f27556659b8d6a3

Fix T62695: OBJ mtllib fails when filename contains spaces

===================================================================

M	io_scene_obj/import_obj.py

===================================================================

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':



More information about the Bf-extensions-cvs mailing list