[Bf-extensions-cvs] [e42f47d] master: OBJ Import: prevent loading an image many times

Campbell Barton noreply at git.blender.org
Tue Mar 29 10:07:23 CEST 2016


Commit: e42f47d181a4d725b95200fd33d873fc85be6704
Author: Campbell Barton
Date:   Tue Mar 29 19:03:31 2016 +1100
Branches: master
https://developer.blender.org/rBAe42f47d181a4d725b95200fd33d873fc85be6704

OBJ Import: prevent loading an image many times

When an MTL made multiple references to the same image,
it would create a new data-block for each reference.

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

M	io_scene_obj/import_obj.py

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

diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 2028a1c..b0889d1 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -81,6 +81,9 @@ def create_materials(filepath, relpath,
     DIR = os.path.dirname(filepath)
     context_material_vars = set()
 
+    # Don't load the same image multiple times
+    context_imagepath_map = {}
+
     def load_material_image(blender_material, context_material_name, img_data, type):
         """
         Set textures defined in .mtl file.
@@ -99,7 +102,10 @@ def create_materials(filepath, relpath,
         texture = bpy.data.textures.new(name=type, type='IMAGE')
 
         # Absolute path - c:\.. etc would work here
-        image = obj_image_load(imagepath, DIR, use_image_search, relpath)
+        image = context_imagepath_map.get(imagepath, ...)
+        if image == ...:
+            image = context_imagepath_map[imagepath] = \
+                    obj_image_load(imagepath, DIR, use_image_search, relpath)
 
         if image is not None:
             texture.image = image



More information about the Bf-extensions-cvs mailing list