Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-03-29 11:03:31 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-04-05 11:54:35 +0300
commitcbc986ae520d0e8fa8829f4f2d686a06011b6544 (patch)
tree23abbce1f93d4034434dafa94f33cbcf5af10e1d
parentd464ae7c75d5a69f3713796fe069a399ba225fd8 (diff)
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.
-rw-r--r--io_scene_obj/import_obj.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 2028a1ca..b0889d15 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