[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3625] trunk/py/scripts/addons/ io_scene_obj/export_obj.py: Fix for [#32102] Saving obj extends the material name by texture name
Bastien Montagne
montagne29 at wanadoo.fr
Sun Jul 15 16:23:58 CEST 2012
Revision: 3625
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3625
Author: mont29
Date: 2012-07-15 14:23:58 +0000 (Sun, 15 Jul 2012)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_obj/export_obj.py
Modified: trunk/py/scripts/addons/io_scene_obj/export_obj.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/export_obj.py 2012-07-14 02:41:40 UTC (rev 3624)
+++ trunk/py/scripts/addons/io_scene_obj/export_obj.py 2012-07-15 14:23:58 UTC (rev 3625)
@@ -291,6 +291,10 @@
# 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 @@
# 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)
More information about the Bf-extensions-cvs
mailing list