[Bf-extensions-cvs] [7d832c3] master: Fix T47018: OBJ fails images search on win32

Campbell Barton noreply at git.blender.org
Fri Jan 15 01:38:01 CET 2016


Commit: 7d832c33d5cf1632823ebfc673c9d74343e8fb3b
Author: Campbell Barton
Date:   Fri Jan 15 11:25:15 2016 +1100
Branches: master
https://developer.blender.org/rBA7d832c33d5cf1632823ebfc673c9d74343e8fb3b

Fix T47018: OBJ fails images search on win32

Workaround for a bug in Python3.5,
however bytes on win32 are deprecated so better not use them for file access at all.

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

M	io_scene_obj/import_obj.py

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

diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index f5890d6..e94e32b 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -63,8 +63,8 @@ def obj_image_load(imagepath, DIR, recursive, relpath):
     Mainly uses comprehensiveImageLoad
     but tries to replace '_' with ' ' for Max's exporter replaces spaces with underscores.
     """
-    if b'_' in imagepath:
-        image = load_image(imagepath.replace(b'_', b' '), DIR, recursive=recursive, relpath=relpath)
+    if "_" in imagepath:
+        image = load_image(imagepath.replace("_", " "), DIR, recursive=recursive, relpath=relpath)
         if image:
             return image
 
@@ -85,7 +85,7 @@ def create_materials(filepath, relpath,
         """
         Set textures defined in .mtl file.
         """
-        imagepath = img_data[-1]
+        imagepath = os.fsdecode(img_data[-1])
         map_options = {}
 
         curr_token = []
@@ -204,10 +204,10 @@ def create_materials(filepath, relpath,
                 mtex.scale.z = float(map_scale[2])
 
     # Add an MTL with the same name as the obj if no MTLs are spesified.
-    temp_mtl = os.path.splitext((os.path.basename(filepath)))[0] + b'.mtl'
+    temp_mtl = os.path.splitext((os.path.basename(filepath)))[0] + ".mtl"
 
-    if os.path.exists(os.path.join(DIR, temp_mtl)) and temp_mtl not in material_libs:
-        material_libs.append(temp_mtl)
+    if os.path.exists(os.path.join(DIR, temp_mtl)):
+        material_libs.add(temp_mtl)
     del temp_mtl
 
     # Create new materials
@@ -221,7 +221,7 @@ def create_materials(filepath, relpath,
     #~ unique_materials[None] = None
     #~ unique_material_images[None] = None
 
-    for libname in material_libs:
+    for libname in sorted(material_libs):
         # print(libname)
         mtlpath = os.path.join(DIR, libname)
         if not os.path.exists(mtlpath):
@@ -918,7 +918,7 @@ def load(context,
         verts_nor = []
         verts_tex = []
         faces = []  # tuples of the faces
-        material_libs = []  # filanems to material libs this uses
+        material_libs = set()  # filenames to material libs this OBJ uses
         vertex_groups = {}  # when use_groups_as_vgroups is true
 
         # Get the string to float conversion func for this file- is 'float' for almost all files.
@@ -1098,7 +1098,7 @@ 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 = list(set(material_libs) | set(line.split()[1:]))
+                    material_libs |= {os.fsdecode(f) for f in line.split()[1:]}
 
                     # Nurbs support
                 elif line_start == b'cstype':
@@ -1158,7 +1158,7 @@ def load(context,
 
         progress.step("Done, loading materials and images...")
 
-        create_materials(filepath.encode(), relpath, material_libs, unique_materials,
+        create_materials(filepath, relpath, material_libs, unique_materials,
                          unique_material_images, use_image_search, float_func)
 
         progress.step("Done, building geometries (verts:%i faces:%i materials: %i smoothgroups:%i) ..." %



More information about the Bf-extensions-cvs mailing list