[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34201] trunk/blender/release/scripts/op/ io_scene_fbx/export_fbx.py: script now passes pep8 checking tool.

Campbell Barton ideasman42 at gmail.com
Sun Jan 9 18:35:30 CET 2011


Revision: 34201
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34201
Author:   campbellbarton
Date:     2011-01-09 17:35:29 +0000 (Sun, 09 Jan 2011)
Log Message:
-----------
script now passes pep8 checking tool.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py

Modified: trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py	2011-01-09 16:46:01 UTC (rev 34200)
+++ trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py	2011-01-09 17:35:29 UTC (rev 34201)
@@ -28,16 +28,17 @@
 
 import os
 import time
-import math # math.pi
-import shutil # for file copying
+import math  # math.pi
+import shutil  # for file copying
 
 import bpy
 from mathutils import Vector, Euler, Matrix
 
+
 # XXX not used anymore, images are copied one at a time
 def copy_images(dest_dir, textures):
     import shutil
-    
+
     if not dest_dir.endswith(os.sep):
         dest_dir += os.sep
 
@@ -51,16 +52,17 @@
         if Blender.sys.exists(image_path):
             # Make a name for the target path.
             dest_image_path = dest_dir + image_path.split('\\')[-1].split('/')[-1]
-            if not Blender.sys.exists(dest_image_path): # Image isnt already there
+            if not Blender.sys.exists(dest_image_path):  # Image isnt already there
                 print("\tCopying %r > %r" % (image_path, dest_image_path))
                 try:
                     shutil.copy(image_path, dest_image_path)
-                    copyCount+=1
+                    copyCount += 1
                 except:
                     print("\t\tWarning, file failed to copy, skipping.")
 
     print('\tCopied %d images' % copyCount)
 
+
 # I guess FBX uses degrees instead of radians (Arystan).
 # Call this function just before writing to FBX.
 # 180 / math.pi == 57.295779513
@@ -81,30 +83,31 @@
 sane_name_mapping_ob['Scene'] = 'Scene_'
 sane_name_mapping_ob['blend_root'] = 'blend_root_'
 
+
 def increment_string(t):
     name = t
     num = ''
     while name and name[-1].isdigit():
         num = name[-1] + num
         name = name[:-1]
-    if num:	return '%s%d' % (name, int(num)+1)
-    else:	return name + '_0'
+    if num:
+        return '%s%d' % (name, int(num) + 1)
+    else:
+        return name + '_0'
 
 
-
 # todo - Disallow the name 'Scene' and 'blend_root' - it will bugger things up.
 def sane_name(data, dct):
     #if not data: return None
 
-    if type(data)==tuple: # materials are paired up with images
+    if type(data) == tuple:  # materials are paired up with images
         data, other = data
         use_other = True
     else:
         other = None
         use_other = False
 
-    if data:	name = data.name
-    else:		name = None
+    name = data.name if data else None
     orig_name = name
 
     if other:
@@ -119,26 +122,41 @@
     #except:		pass
 
     if not name:
-        name = 'unnamed' # blank string, ASKING FOR TROUBLE!
+        name = 'unnamed'  # blank string, ASKING FOR TROUBLE!
     else:
 
-        name = bpy.path.clean_name(name) # use our own
+        name = bpy.path.clean_name(name)  # use our own
 
-    while name in iter(dct.values()):	name = increment_string(name)
+    while name in iter(dct.values()):
+        name = increment_string(name)
 
-    if use_other: # even if other is None - orig_name_other will be a string or None
+    if use_other:  # even if other is None - orig_name_other will be a string or None
         dct[orig_name, orig_name_other] = name
     else:
         dct[orig_name] = name
 
     return name
 
-def sane_obname(data):		return sane_name(data, sane_name_mapping_ob)
-def sane_matname(data):		return sane_name(data, sane_name_mapping_mat)
-def sane_texname(data):		return sane_name(data, sane_name_mapping_tex)
-def sane_takename(data):	return sane_name(data, sane_name_mapping_take)
-def sane_groupname(data):	return sane_name(data, sane_name_mapping_group)
 
+def sane_obname(data):
+    return sane_name(data, sane_name_mapping_ob)
+
+
+def sane_matname(data):
+    return sane_name(data, sane_name_mapping_mat)
+
+
+def sane_texname(data):
+    return sane_name(data, sane_name_mapping_tex)
+
+
+def sane_takename(data):
+    return sane_name(data, sane_name_mapping_take)
+
+
+def sane_groupname(data):
+    return sane_name(data, sane_name_mapping_group)
+
 # def derived_paths(fname_orig, basepath, FORCE_CWD=False):
 # 	'''
 # 	fname_orig - blender path, can be relative
@@ -160,8 +178,9 @@
 
 
 def mat4x4str(mat):
-    return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([ f for v in mat for f in v ])
+    return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([f for v in mat for f in v])
 
+
 # XXX not used
 # duplicated in OBJ exporter
 def getVertsFromGroup(me, group_index):
@@ -174,6 +193,7 @@
 
         return ret
 
+
 # ob must be OB_MESH
 def BPyMesh_meshWeight2List(ob, me):
     ''' Takes a mesh and return its group names and a list of lists, one list per vertex.
@@ -182,14 +202,14 @@
     '''
 
     # Clear the vert group.
-    groupNames= [g.name for g in ob.vertex_groups]
-    len_groupNames= len(groupNames)
+    groupNames = [g.name for g in ob.vertex_groups]
+    len_groupNames = len(groupNames)
 
     if not len_groupNames:
         # no verts? return a vert aligned empty list
         return [[] for i in range(len(me.vertices))], []
     else:
-        vWeightList= [[0.0]*len_groupNames for i in range(len(me.vertices))]
+        vWeightList = [[0.0] * len_groupNames for i in range(len(me.vertices))]
 
     for i, v in enumerate(me.vertices):
         for g in v.groups:
@@ -197,24 +217,24 @@
 
     return groupNames, vWeightList
 
+
 def meshNormalizedWeights(ob, me):
-    try: # account for old bad BPyMesh
+    try:  # account for old bad BPyMesh
         groupNames, vWeightList = BPyMesh_meshWeight2List(ob, me)
-# 		groupNames, vWeightList = BPyMesh.meshWeight2List(me)
     except:
-        return [],[]
+        return [], []
 
     if not groupNames:
-        return [],[]
+        return [], []
 
     for i, vWeights in enumerate(vWeightList):
         tot = 0.0
         for w in vWeights:
-            tot+=w
+            tot += w
 
         if tot:
             for j, w in enumerate(vWeights):
-                vWeights[j] = w/tot
+                vWeights[j] = w / tot
 
     return groupNames, vWeightList
 
@@ -226,33 +246,34 @@
 
 '''
 
+
 # This func can be called with just the filepath
 def save(operator, context, filepath="",
-        GLOBAL_MATRIX =				None,
-        EXP_OBS_SELECTED =			True,
-        EXP_MESH =					True,
-        EXP_MESH_APPLY_MOD =		True,
-        EXP_ARMATURE =				True,
-        EXP_LAMP =					True,
-        EXP_CAMERA =				True,
-        EXP_EMPTY =					True,
-        EXP_IMAGE_COPY =			False,
-        ANIM_ENABLE =				True,
-        ANIM_OPTIMIZE =				True,
-        ANIM_OPTIMIZE_PRECISSION =	6,
-        ANIM_ACTION_ALL =			False,
-        BATCH_ENABLE =				False,
-        BATCH_GROUP =				True,
-        BATCH_FILE_PREFIX =			'',
-        BATCH_OWN_DIR =				False
+        GLOBAL_MATRIX=None,
+        EXP_OBS_SELECTED=True,
+        EXP_MESH=True,
+        EXP_MESH_APPLY_MOD=True,
+        EXP_ARMATURE=True,
+        EXP_LAMP=True,
+        EXP_CAMERA=True,
+        EXP_EMPTY=True,
+        EXP_IMAGE_COPY=False,
+        ANIM_ENABLE=True,
+        ANIM_OPTIMIZE=True,
+        ANIM_OPTIMIZE_PRECISSION=6,
+        ANIM_ACTION_ALL=False,
+        BATCH_ENABLE=False,
+        BATCH_GROUP=True,
+        BATCH_FILE_PREFIX='',
+        BATCH_OWN_DIR=False
     ):
 
-    #XXX, missing arg 
+    #XXX, missing arg
     batch_objects = None
 
     # testing
-    mtx_x90		= Matrix.Rotation( math.pi/2.0, 3, 'X') # used
-    mtx4_z90	= Matrix.Rotation( math.pi/2.0, 4, 'Z')
+    mtx_x90 = Matrix.Rotation(math.pi / 2.0, 3, 'X')  # used
+    mtx4_z90 = Matrix.Rotation(math.pi / 2.0, 4, 'Z')
 
     if GLOBAL_MATRIX is None:
         GLOBAL_MATRIX = Matrix()
@@ -266,21 +287,18 @@
 
         # get the path component of filepath
         tmp_exists = bpy.utils.exists(fbxpath)
-# 		tmp_exists = Blender.sys.exists(fbxpath)
 
-        if tmp_exists != 2: # a file, we want a path
+        if tmp_exists != 2:  # a file, we want a path
             fbxpath = os.path.dirname(fbxpath)
 # 			while fbxpath and fbxpath[-1] not in ('/', '\\'):
 # 				fbxpath = fbxpath[:-1]
             if not fbxpath:
-# 			if not filepath:
                 # XXX
                 print('Error%t|Directory does not exist!')
 # 				Draw.PupMenu('Error%t|Directory does not exist!')
                 return
 
             tmp_exists = bpy.utils.exists(fbxpath)
-# 			tmp_exists = Blender.sys.exists(fbxpath)
 
         if tmp_exists != 2:
             # XXX
@@ -292,7 +310,6 @@
             fbxpath += os.sep
         del tmp_exists
 
-
         if BATCH_GROUP:
             data_seq = bpy.data.groups
         else:
@@ -300,13 +317,11 @@
 
         # call this function within a loop with BATCH_ENABLE == False
         orig_sce = context.scene
-# 		orig_sce = bpy.data.scenes.active
 
-        new_fbxpath = fbxpath # own dir option modifies, we need to keep an original
-        for data in data_seq: # scene or group
+        new_fbxpath = fbxpath  # own dir option modifies, we need to keep an original
+        for data in data_seq:  # scene or group
             newname = BATCH_FILE_PREFIX + bpy.path.clean_name(data.name)
 
-
             if BATCH_OWN_DIR:
                 new_fbxpath = fbxpath + newname + os.sep
                 # path may already exist
@@ -316,16 +331,15 @@
 # 				if Blender.sys.exists(new_fbxpath) == 0:
                     os.mkdir(new_fbxpath)
 
-
             filepath = new_fbxpath + newname + '.fbx'
 
             print('\nBatch exporting %s as...\n\t%r' % (data, filepath))
 
             # XXX don't know what to do with this, probably do the same? (Arystan)
-            if BATCH_GROUP: #group
+            if BATCH_GROUP:  # group
                 # group, so objects update properly, add a dummy scene.
                 scene = bpy.data.scenes.new()
-                scene.Layers = (1<<20) -1
+                scene.Layers = (1 << 20) - 1
                 bpy.data.scenes.active = scene
                 for ob_base in data.objects:
                     scene.objects.link(ob_base)
@@ -334,12 +348,9 @@
 
                 # TODO - BUMMER! Armatures not in the group wont animate the mesh
 
-            else:# scene
-
-
+            else:  # scene
                 data_seq.active = data
 
-
             # Call self with modified args
             # Dont pass batch options since we already usedt them
             write(filepath, data.objects,
@@ -365,7 +376,7 @@
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list