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:
authorBastien Montagne <montagne29@wanadoo.fr>2012-07-15 18:23:58 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-07-15 18:23:58 +0400
commitc07f1b9a9420f28078d77aebc749000f677346ce (patch)
treecedcf305cf8a08b792b6be7abcebb873725052c3 /io_scene_obj
parentc77497348b85c707c80dfa17057d13f5633f58c0 (diff)
Fix for [#32102] Saving obj extends the material name by texture name
Changed how mtl_mat names are generated, so that we can still be sure to always have a unique mtl_name for each key (mat_name, tex_name), yet avoiding to add tex name to mat when not needed.
Diffstat (limited to 'io_scene_obj')
-rw-r--r--io_scene_obj/export_obj.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index 8a3978ca..c5fe57af 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -291,6 +291,10 @@ def write_file(filepath, objects, scene,
# A Dict of Materials
# (material.name, image.name):matname_imagename # matname_imagename has gaps removed.
mtl_dict = {}
+ # Used to reduce the usage of matname_texname materials, which can become annoying in case of
+ # repeated exports/imports, yet keeping unique mat names per keys!
+ # mtl_name: (material.name, image.name)
+ mtl_rev_dict = {}
copy_set = set()
@@ -505,10 +509,21 @@ def write_file(filepath, objects, scene,
# converting any spaces to underscores with name_compat.
# If none image dont bother adding it to the name
- if key[1] is None:
- mat_data = mtl_dict[key] = ("%s" % name_compat(key[0])), materials[f_mat], f_image
- else:
- mat_data = mtl_dict[key] = ("%s_%s" % (name_compat(key[0]), name_compat(key[1]))), materials[f_mat], f_image
+ # Try to avoid as much as possible adding texname (or other things)
+ # to the mtl name (see [#32102])...
+ mtl_name = "%s" % name_compat(key[0])
+ if mtl_rev_dict.get(mtl_name, None) not in {key, None}:
+ if key[1] is None:
+ tmp_ext = "_NONE"
+ else:
+ tmp_ext = "_%s" % name_compat(key[1])
+ i = 0
+ while mtl_rev_dict.get(mtl_name + tmp_ext, None) not in {key, None}:
+ i += 1
+ tmp_ext = "_%3d" % i
+ mtl_name += tmp_ext
+ mat_data = mtl_dict[key] = mtl_name, materials[f_mat], f_image
+ mtl_rev_dict[mtl_name] = key
if EXPORT_GROUP_BY_MAT:
fw("g %s_%s_%s\n" % (name_compat(ob.name), name_compat(ob.data.name), mat_data[0])) # can be mat_image or (null)