[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1468] trunk/py/scripts/addons/ io_scene_obj/export_obj.py: pass the pep8 checker.

Campbell Barton ideasman42 at gmail.com
Fri Jan 21 15:08:17 CET 2011


Revision: 1468
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1468
Author:   campbellbarton
Date:     2011-01-21 14:08:17 +0000 (Fri, 21 Jan 2011)
Log Message:
-----------
pass the pep8 checker.

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-01-21 13:46:37 UTC (rev 1467)
+++ trunk/py/scripts/addons/io_scene_obj/export_obj.py	2011-01-21 14:08:17 UTC (rev 1468)
@@ -25,12 +25,14 @@
 import bpy
 import mathutils
 
-def fixName(name):
+
+def name_compat(name):
     if name is None:
         return 'None'
     else:
         return name.replace(' ', '_')
 
+
 def write_mtl(scene, filepath, copy_images, mtl_dict):
 
     world = scene.world
@@ -55,10 +57,8 @@
             rel = os.path.relpath(fn, dest_dir)
         else:
             rel = fn
-
         return rel
 
-
     file = open(filepath, "w", encoding='utf8')
     file.write('# Blender MTL File: %r\n' % os.path.basename(bpy.data.filepath))
     file.write('# Material Count: %i\n' % len(mtl_dict))
@@ -68,50 +68,50 @@
         # Get the Blender data for the material and the image.
         # Having an image named None will make a bug, dont do it :)
 
-        file.write('newmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
+        file.write('newmtl %s\n' % mtl_mat_name)  # Define a new material: matname_imgname
 
         if mat:
-            file.write('Ns %.6f\n' % ((mat.specular_hardness-1) * 1.9607843137254901)) # Hardness, convert blenders 1-511 to MTL's
-            file.write('Ka %.6f %.6f %.6f\n' %  tuple(c * mat.ambient for c in worldAmb)) # Ambient, uses mirror colour,
-            file.write('Kd %.6f %.6f %.6f\n' % tuple(c * mat.diffuse_intensity for c in mat.diffuse_color)) # Diffuse
-            file.write('Ks %.6f %.6f %.6f\n' % tuple(c * mat.specular_intensity for c in mat.specular_color)) # Specular
+            file.write('Ns %.6f\n' % ((mat.specular_hardness - 1) * 1.9607843137254901))  # Hardness, convert blenders 1-511 to MTL's
+            file.write('Ka %.6f %.6f %.6f\n' % tuple(c * mat.ambient for c in worldAmb))  # Ambient, uses mirror colour,
+            file.write('Kd %.6f %.6f %.6f\n' % tuple(c * mat.diffuse_intensity for c in mat.diffuse_color))  # Diffuse
+            file.write('Ks %.6f %.6f %.6f\n' % tuple(c * mat.specular_intensity for c in mat.specular_color))  # Specular
             if hasattr(mat, "ior"):
-                file.write('Ni %.6f\n' % mat.ior) # Refraction index
+                file.write('Ni %.6f\n' % mat.ior)  # Refraction index
             else:
                 file.write('Ni %.6f\n' % 1.0)
-            file.write('d %.6f\n' % mat.alpha) # Alpha (obj uses 'd' for dissolve)
+            file.write('d %.6f\n' % mat.alpha)  # Alpha (obj uses 'd' for dissolve)
 
             # 0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting.
             if mat.use_shadeless:
-                file.write('illum 0\n') # ignore lighting
+                file.write('illum 0\n')  # ignore lighting
             elif mat.specular_intensity == 0:
-                file.write('illum 1\n') # no specular.
+                file.write('illum 1\n')  # no specular.
             else:
-                file.write('illum 2\n') # light normaly
+                file.write('illum 2\n')  # light normaly
 
         else:
             #write a dummy material here?
             file.write('Ns 0\n')
-            file.write('Ka %.6f %.6f %.6f\n' %  tuple(c for c in worldAmb)) # Ambient, uses mirror colour,
+            file.write('Ka %.6f %.6f %.6f\n' % tuple(c for c in worldAmb))  # Ambient, uses mirror colour,
             file.write('Kd 0.8 0.8 0.8\n')
             file.write('Ks 0.8 0.8 0.8\n')
-            file.write('d 1\n') # No alpha
-            file.write('illum 2\n') # light normaly
+            file.write('d 1\n')  # No alpha
+            file.write('illum 2\n')  # light normaly
 
         # Write images!
         if img:  # We have an image on the face!
             # write relative image path
             rel = copy_image(img)
-            file.write('map_Kd %s\n' % rel) # Diffuse mapping image
+            file.write('map_Kd %s\n' % rel)  # Diffuse mapping image
 #           file.write('map_Kd %s\n' % img.filepath.split('\\')[-1].split('/')[-1]) # Diffuse mapping image
 
-        elif mat: # No face image. if we havea material search for MTex image.
+        elif mat:  # No face image. if we havea material search for MTex image.
             for mtex in mat.texture_slots:
                 if mtex and mtex.texture.type == 'IMAGE':
                     try:
                         filepath = copy_image(mtex.texture.image)
 #                       filepath = mtex.texture.image.filepath.split('\\')[-1].split('/')[-1]
-                        file.write('map_Kd %s\n' % repr(filepath)[1:-1]) # Diffuse mapping image
+                        file.write('map_Kd %s\n' % repr(filepath)[1:-1])  # Diffuse mapping image
                         break
                     except:
                         # Texture has no image though its an image type, best ignore.
@@ -121,6 +121,7 @@
 
     file.close()
 
+
 # XXX not used
 def copy_file(source, dest):
     file = open(source, 'rb')
@@ -139,10 +140,10 @@
 
     # Get unique image names
     uniqueImages = {}
-    for matname, mat, image in mtl_dict.values(): # Only use image name
+    for matname, mat, image in mtl_dict.values():  # Only use image name
         # Get Texface images
         if image:
-            uniqueImages[image] = image # Should use sets here. wait until Python 2.4 is default.
+            uniqueImages[image] = image  # Should use sets here. wait until Python 2.4 is default.
 
         # Get MTex images
         if mat:
@@ -178,7 +179,7 @@
         return False
 
     for nu in ob.data.splines:
-        if nu.point_count_v == 1 and nu.type != 'BEZIER': # not a surface and not bezier
+        if nu.point_count_v == 1 and nu.type != 'BEZIER':  # not a surface and not bezier
             return True
 
     return False
@@ -217,11 +218,11 @@
             pt_num += 1
         tot_verts += pt_num
 
-        file.write('g %s\n' % (fixName(ob.name))) # fixName(ob.getData(1)) could use the data name too
-        file.write('cstype bspline\n') # not ideal, hard coded
-        file.write('deg %d\n' % DEG_ORDER_U) # not used for curves but most files have it still
+        file.write('g %s\n' % (name_compat(ob.name)))  # name_compat(ob.getData(1)) could use the data name too
+        file.write('cstype bspline\n')  # not ideal, hard coded
+        file.write('deg %d\n' % DEG_ORDER_U)  # not used for curves but most files have it still
 
-        curve_ls = [-(i+1) for i in range(pt_num)]
+        curve_ls = [-(i + 1) for i in range(pt_num)]
 
         # 'curv' keyword
         if do_closed:
@@ -232,17 +233,17 @@
                 pt_num += DEG_ORDER_U
                 curve_ls = curve_ls + curve_ls[0:DEG_ORDER_U]
 
-        file.write('curv 0.0 1.0 %s\n' % (" ".join([str(i) for i in curve_ls]))) # Blender has no U and V values for the curve
+        file.write('curv 0.0 1.0 %s\n' % (" ".join([str(i) for i in curve_ls])))  # Blender has no U and V values for the curve
 
         # 'parm' keyword
         tot_parm = (DEG_ORDER_U + 1) + pt_num
-        tot_parm_div = float(tot_parm-1)
-        parm_ls = [(i/tot_parm_div) for i in range(tot_parm)]
+        tot_parm_div = float(tot_parm - 1)
+        parm_ls = [(i / tot_parm_div) for i in range(tot_parm)]
 
-        if do_endpoints: # end points, force param
-            for i in range(DEG_ORDER_U+1):
+        if do_endpoints:  # end points, force param
+            for i in range(DEG_ORDER_U + 1):
                 parm_ls[i] = 0.0
-                parm_ls[-(1+i)] = 1.0
+                parm_ls[-(1 + i)] = 1.0
 
         file.write("parm u %s\n" % " ".join(["%.6f" % i for i in parm_ls]))
 
@@ -250,6 +251,7 @@
 
     return tot_verts
 
+
 def write_file(filepath, objects, scene,
           EXPORT_TRI=False,
           EXPORT_EDGES=False,
@@ -300,9 +302,9 @@
                 weightDict[vGroupName] = weightDict.get(vGroupName, 0) + weight
 
         if weightDict:
-            alist = [(weight,vGroupName) for vGroupName, weight in weightDict.items()] # sort least to greatest amount of weight
+            alist = [(weight, vGroupName) for vGroupName, weight in weightDict.items()]  # sort least to greatest amount of weight
             alist.sort()
-            return(alist[-1][1]) # highest value last
+            return(alist[-1][1])  # highest value last
         else:
             return '(null)'
 
@@ -322,10 +324,10 @@
     # Tell the obj file what material file to use.
     if EXPORT_MTL:
         mtlfilepath = os.path.splitext(filepath)[0] + ".mtl"
-        file.write('mtllib %s\n' % repr(os.path.basename(mtlfilepath))[1:-1]) # filepath can contain non utf8 chars, use repr
+        file.write('mtllib %s\n' % repr(os.path.basename(mtlfilepath))[1:-1])  # filepath can contain non utf8 chars, use repr
 
     if EXPORT_ROTX90:
-        mat_xrot90= mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')
+        mat_xrot90 = mathutils.Matrix.Rotation(-math.pi / 2.0, 4, 'X')
 
     # Initialize totals, these are updated each object
     totverts = totuvco = totno = 1
@@ -365,7 +367,7 @@
             # Nurbs curve support
             if EXPORT_CURVE_AS_NURBS and test_nurbs_compat(ob):
                 if EXPORT_ROTX90:
-                   ob_mat = ob_mat * mat_xrot90
+                    ob_mat = ob_mat * mat_xrot90
                 totverts += write_nurb(file, ob, ob_mat)
                 continue
             # END NURBS
@@ -395,7 +397,7 @@
             me_verts = me.vertices[:]
 
             # Make our own list so it can be sorted to reduce context switching
-            face_index_pairs = [ (face, index) for index, face in enumerate(me.faces)]
+            face_index_pairs = [(face, index) for index, face in enumerate(me.faces)]
             # faces = [ f for f in me.faces ]
 
             if EXPORT_EDGES:
@@ -403,12 +405,12 @@
             else:
                 edges = []
 
-            if not (len(face_index_pairs)+len(edges)+len(me.vertices)): # Make sure there is somthing to write
+            if not (len(face_index_pairs) + len(edges) + len(me.vertices)):  # Make sure there is somthing to write
 
                 # clean up
                 bpy.data.meshes.remove(me)
 
-                continue # dont bother with this mesh.
+                continue  # dont bother with this mesh.
 

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list