[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2197] trunk/py/scripts/addons/ io_scene_obj/export_obj.py: fix for exporting dupli's, code assumed any dupli with a parent was a dupli vert/face

Campbell Barton ideasman42 at gmail.com
Fri Jul 29 08:53:34 CEST 2011


Revision: 2197
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2197
Author:   campbellbarton
Date:     2011-07-29 06:53:33 +0000 (Fri, 29 Jul 2011)
Log Message:
-----------
fix for exporting dupli's, code assumed any dupli with a parent was a dupli vert/face

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	2011-07-29 06:41:47 UTC (rev 2196)
+++ trunk/py/scripts/addons/io_scene_obj/export_obj.py	2011-07-29 06:53:33 UTC (rev 2197)
@@ -301,7 +301,7 @@
     for ob_main in objects:
 
         # ignore dupli children
-        if ob_main.parent and ob_main.parent.dupli_type != 'NONE':
+        if ob_main.parent and ob_main.parent.dupli_type in {'VERTS', 'FACES'}:
             # XXX
             print(ob_main.name, 'is a dupli child - ignoring')
             continue
@@ -380,24 +380,9 @@
 #                   # better to recalculate them
 #                   me.calcNormals()
 
-            materials = me.materials
+            materials = me.materials[:]
+            material_names = [m.name if m else None for m in materials]
 
-            materialNames = []
-            materialItems = [m for m in materials]
-            if materials:
-                for mat in materials:
-                    if mat:
-                        materialNames.append(mat.name)
-                    else:
-                        materialNames.append(None)
-                # Cant use LC because some materials are None.
-                # materialNames = map(lambda mat: mat.name, materials) # Bug Blender, dosent account for null materials, still broken.
-
-            # Possible there null materials, will mess up indices
-            # but at least it will export, wait until Blender gets fixed.
-            materialNames.extend((16 - len(materialNames)) * [None])
-            materialItems.extend((16 - len(materialItems)) * [None])
-
             # Sort by Material, then images
             # so we dont over context switch in the obj file.
             if EXPORT_KEEP_VERT_ORDER:
@@ -498,7 +483,7 @@
 
             for f, f_index in face_index_pairs:
                 f_smooth = f.use_smooth
-                f_mat = min(f.material_index, len(materialNames) - 1)
+                f_mat = min(f.material_index, len(materials) - 1)
 
                 if faceuv:
                     tface = uv_layer[f_index]
@@ -506,9 +491,9 @@
 
                 # MAKE KEY
                 if faceuv and f_image:  # Object is always true.
-                    key = materialNames[f_mat], f_image.name
+                    key = material_names[f_mat], f_image.name
                 else:
-                    key = materialNames[f_mat], None  # No image, use None instead.
+                    key = material_names[f_mat], None  # No image, use None instead.
 
                 # Write the vertex group
                 if EXPORT_POLYGROUPS:
@@ -541,9 +526,9 @@
 
                             # 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])), materialItems[f_mat], f_image
+                                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]))), materialItems[f_mat], f_image
+                                mat_data = mtl_dict[key] = ("%s_%s" % (name_compat(key[0]), name_compat(key[1]))), materials[f_mat], f_image
 
                         if EXPORT_GROUP_BY_MAT:
                             file.write("g %s_%s_%s\n" % (name_compat(ob.name), name_compat(ob.data.name), mat_data[0]))  # can be mat_image or (null)
@@ -574,23 +559,26 @@
                         if EXPORT_NORMALS:
                             if f_smooth:  # Smoothed, use vertex normals
                                 for vi, v in f_v:
-                                    file.write(" %d/%d/%d" % \
-                                                    (v.index + totverts,
-                                                     totuvco + uv_face_mapping[f_index][vi],
-                                                     globalNormals[veckey3d(v.normal)]))  # vert, uv, normal
+                                    file.write(" %d/%d/%d" %
+                                               (v.index + totverts,
+                                                totuvco + uv_face_mapping[f_index][vi],
+                                                globalNormals[veckey3d(v.normal)],
+                                                ))  # vert, uv, normal
 
                             else:  # No smoothing, face normals
                                 no = globalNormals[veckey3d(f.normal)]
                                 for vi, v in f_v:
-                                    file.write(" %d/%d/%d" % \
-                                                    (v.index + totverts,
-                                                     totuvco + uv_face_mapping[f_index][vi],
-                                                     no))  # vert, uv, normal
+                                    file.write(" %d/%d/%d" %
+                                               (v.index + totverts,
+                                                totuvco + uv_face_mapping[f_index][vi],
+                                                no,
+                                                ))  # vert, uv, normal
                         else:  # No Normals
                             for vi, v in f_v:
-                                file.write(" %d/%d" % (\
-                                  v.index + totverts,\
-                                  totuvco + uv_face_mapping[f_index][vi]))  # vert, uv
+                                file.write(" %d/%d" % (
+                                           v.index + totverts,
+                                           totuvco + uv_face_mapping[f_index][vi],
+                                           ))  # vert, uv
 
                         face_vert_index += len(f_v)
 
@@ -598,8 +586,10 @@
                         if EXPORT_NORMALS:
                             if f_smooth:  # Smoothed, use vertex normals
                                 for vi, v in f_v:
-                                    file.write(" %d//%d" %
-                                                (v.index + totverts, globalNormals[veckey3d(v.normal)]))
+                                    file.write(" %d//%d" % (
+                                               v.index + totverts,
+                                               globalNormals[veckey3d(v.normal)],
+                                               ))
                             else:  # No smoothing, face normals
                                 no = globalNormals[veckey3d(f.normal)]
                                 for vi, v in f_v:



More information about the Bf-extensions-cvs mailing list