[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4647] contrib/py/scripts/addons/ oscurart_mesh_cache_tools.py: Code Cleanup

Eugenio Pignataro info at oscurart.com.ar
Fri Aug 2 15:44:45 CEST 2013


Revision: 4647
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4647
Author:   oscurart
Date:     2013-08-02 13:44:45 +0000 (Fri, 02 Aug 2013)
Log Message:
-----------
Code Cleanup

Modified Paths:
--------------
    contrib/py/scripts/addons/oscurart_mesh_cache_tools.py

Modified: contrib/py/scripts/addons/oscurart_mesh_cache_tools.py
===================================================================
--- contrib/py/scripts/addons/oscurart_mesh_cache_tools.py	2013-08-01 13:33:38 UTC (rev 4646)
+++ contrib/py/scripts/addons/oscurart_mesh_cache_tools.py	2013-08-02 13:44:45 UTC (rev 4647)
@@ -35,56 +35,55 @@
     def draw(self, context):
         layout = self.layout
 
-        obj = context.object        
-        row= layout.column(align=1)
-        row.prop(bpy.context.scene,"muu_pc2_folder",text="Folder")
-        row.operator("import_shape.pc2_copy" , icon='FILESEL', text="Set Filepath")
+        obj = context.object
+        row = layout.column(align=1)
+        row.prop(bpy.context.scene, "muu_pc2_folder", text="Folder")
+        row.operator("import_shape.pc2_copy", icon='FILESEL', text="Set Filepath")
         row = layout.box().column(align=1)
         row.label("EXPORTER:")
-        row.operator("group.linked_group_to_local", text="Linked To Local" , icon="LINKED") 
-        row.operator("object.remove_subsurf_modifier" , text="Remove Gen Modifiers" , icon="MOD_SUBSURF")   
-        row.operator("export_shape.pc2_selection", text="Export!" , icon="POSE_DATA")             
+        row.operator("group.linked_group_to_local", text="Linked To Local", icon="LINKED")
+        row.operator("object.remove_subsurf_modifier", text="Remove Gen Modifiers", icon="MOD_SUBSURF")
+        row.operator("export_shape.pc2_selection", text="Export!", icon="POSE_DATA")
         #row.prop(bpy.context.scene,"muu_pc2_rotx", text= "RotX90")
-        row.prop(bpy.context.scene,"muu_pc2_world_space", text="World Space")
-        #row.prop(bpy.context.scene,"muu_pc2_modifiers", text="Apply Modifiers") 
-        #row.prop(bpy.context.scene,"muu_pc2_subsurf", text="Turn Off SubSurf") 
+        row.prop(bpy.context.scene, "muu_pc2_world_space", text="World Space")
+        #row.prop(bpy.context.scene,"muu_pc2_modifiers", text="Apply Modifiers")
+        #row.prop(bpy.context.scene,"muu_pc2_subsurf", text="Turn Off SubSurf")
         row = layout.column(align=1)
-        row.prop(bpy.context.scene,"muu_pc2_start", text="Frame Start")  
-        row.prop(bpy.context.scene,"muu_pc2_end", text="Frame End")
-        row.prop_search(bpy.context.scene, "muu_pc2_group", bpy.data, "groups", text= "") 
+        row.prop(bpy.context.scene, "muu_pc2_start", text="Frame Start")
+        row.prop(bpy.context.scene, "muu_pc2_end", text="Frame End")
+        row.prop_search(bpy.context.scene, "muu_pc2_group", bpy.data, "groups", text="")
         row = layout.box().column(align=1)
         row.label("IMPORTER:")
-        row.operator("import_shape.pc2_selection", text="Import", icon="POSE_DATA")        
-                        
+        row.operator("import_shape.pc2_selection", text="Import", icon="POSE_DATA")
+
 def OscFuncExportPc2(self):
     start = bpy.context.scene.muu_pc2_start
     end = bpy.context.scene.muu_pc2_end
     folderpath = bpy.context.scene.muu_pc2_folder
-    
-    
+
     for ob in bpy.data.groups[bpy.context.scene.muu_pc2_group].objects[:]:
         pc2list = []
         if ob.type == "MESH":
-            with open("%s/%s.pc2" % (os.path.normpath(folderpath),ob.name), mode="wb") as file:  
+            with open("%s/%s.pc2" % (os.path.normpath(folderpath), ob.name), mode="wb") as file:
                 #encabezado
-                headerFormat='<12siiffi'
-                headerStr = struct.pack(headerFormat, 
-                    b'POINTCACHE2\0', 1, len(ob.data.vertices[:]), 0, 1.0, (end+1)-start)          
-                file.write(headerStr)        
+                headerFormat = '<12siiffi'
+                headerStr = struct.pack(headerFormat,
+                         b'POINTCACHE2\0', 1, len(ob.data.vertices[:]), 0, 1.0, (end + 1) - start)
+                file.write(headerStr)
                 #bakeado
-                obmat = ob.matrix_world  
-                for frame in range((end+1)-start):
-                    print("Percentage of %s bake: %s " % ( ob.name, frame/end*100))
-                    bpy.context.scene.frame_set(frame)      
+                obmat = ob.matrix_world
+                for frame in range((end + 1) - start):
+                    print("Percentage of %s bake: %s " % (ob.name, frame / end * 100))
+                    bpy.context.scene.frame_set(frame)
                     me = bpy.data.meshes.new_from_object(
                         scene=bpy.context.scene,
                         object=ob,
                         apply_modifiers=True,
                         settings="RENDER",
                         calc_tessface=True,
-                        calc_undeformed=False)          
+                        calc_undeformed=False)
                     #rotate
-                    if bpy.context.scene.muu_pc2_world_space:                        
+                    if bpy.context.scene.muu_pc2_world_space:
                         me.transform(obmat)
                         me.calc_normals()
                     #creo archivo
@@ -92,29 +91,29 @@
                         pc2list.append((
                             float(vert.co[0]),
                             float(vert.co[1]),
-                            float(vert.co[2])                            
+                            float(vert.co[2])
                             ))
 
-                    #dreno mesh    
-                    bpy.data.meshes.remove(me) 
-                
+                    #dreno mesh
+                    bpy.data.meshes.remove(me)
+
                 print("%s Bake finished! \nAwaiting Compile file..." % (ob.name))
-                
+
                 # write file
-                for i,frame in enumerate(pc2list):
+                for i, frame in enumerate(pc2list):
                     #print("Percentage of %s Compiled file: %s " % ( ob.name, i*100/len(pc2list)))
-                    file.write(struct.pack("<3f", *frame)) 
-                print("%s File Compiled Write finished!" % (ob.name)) 
+                    file.write(struct.pack("<3f", *frame))
+                print("%s File Compiled Write finished!" % (ob.name))
                 del(pc2list)
-                     
-    print("Bake Finished!")        
-        
+
+    print("Bake Finished!")
+
 class OscPc2ExporterBatch(bpy.types.Operator):
     bl_idname = "export_shape.pc2_selection"
     bl_label = "Export pc2 for selected Objects"
     bl_description = "Export pc2 for selected Objects"
     bl_options = {'REGISTER', 'UNDO'}
-    
+
     def execute(self, context):
         OscFuncExportPc2(self)
         return {'FINISHED'}
@@ -123,8 +122,8 @@
     bl_idname = "object.remove_subsurf_modifier"
     bl_label = "Remove SubSurf Modifier"
     bl_description = "Remove SubSurf Modifier"
-    bl_options = {'REGISTER', 'UNDO'}   
-    
+    bl_options = {'REGISTER', 'UNDO'}
+
     def execute(self, context):
         GENERATE = ['MULTIRES', 'ARRAY', 'BEVEL', 'BOOLEAN', 'BUILD', 'DECIMATE', 'MASK', 'MIRROR', 'REMESH', 'SCREW', 'SKIN', 'SOLIDIFY', 'SUBSURF', 'TRIANGULATE']
         for OBJ in bpy.data.groups[bpy.context.scene.muu_pc2_group].objects[:]:
@@ -138,16 +137,16 @@
     bl_idname = "import_shape.pc2_selection"
     bl_label = "Import pc2 for selected Objects"
     bl_description = "Import pc2 for selected Objects"
-    bl_options = {'REGISTER', 'UNDO'}   
+    bl_options = {'REGISTER', 'UNDO'}
 
     def execute(self, context):
         for OBJ in bpy.context.selected_objects[:]:
-            MOD=OBJ.modifiers.new("MeshCache", 'MESH_CACHE')
-            MOD.filepath="%s%s%s.pc2" % (bpy.context.scene.muu_pc2_folder,os.sep,OBJ.name)
-            MOD.cache_format = "PC2"  
+            MOD = OBJ.modifiers.new("MeshCache", 'MESH_CACHE')
+            MOD.filepath = "%s%s%s.pc2" % (bpy.context.scene.muu_pc2_folder, os.sep, OBJ.name)
+            MOD.cache_format = "PC2"
             MOD.forward_axis = "POS_Y"
             MOD.up_axis = "POS_Z"
-            MOD.flip_axis = set(())          
+            MOD.flip_axis = set(())
 
         return {'FINISHED'}
 
@@ -155,42 +154,40 @@
     bl_idname = "import_shape.pc2_copy"
     bl_label = "Copy Filepath"
     bl_description = "Copy Filepath"
-    bl_options = {'REGISTER', 'UNDO'}    
+    bl_options = {'REGISTER', 'UNDO'}
 
     def execute(self, context):
-        bpy.context.scene.muu_pc2_folder=str(bpy.data.filepath.rpartition(os.sep)[0])
+        bpy.context.scene.muu_pc2_folder = str(bpy.data.filepath.rpartition(os.sep)[0])
         return {'FINISHED'}
 
 def OscLinkedGroupToLocal():
     ACTOBJ = bpy.context.active_object
     GROBJS = [ob for ob in ACTOBJ.id_data.dupli_group.objects[:] if ob.type == "MESH"]
 
-    for ob in ACTOBJ.id_data.dupli_group.objects[:]:        
+    for ob in ACTOBJ.id_data.dupli_group.objects[:]:
         bpy.context.scene.objects.link(ob)
     NEWGROUP = bpy.data.groups.new("%s_CLEAN" % (ACTOBJ.name))
-    bpy.context.scene.objects.unlink(ACTOBJ)   
-    NEWOBJ = [] 
+    bpy.context.scene.objects.unlink(ACTOBJ)
+    NEWOBJ = []
     for ob in GROBJS:
-        NEWGROUP.objects.link(ob)    
-        NEWOBJ.append(ob) 
-    for ob in NEWOBJ:    
-        if ob.type == "MESH":  
+        NEWGROUP.objects.link(ob)
+        NEWOBJ.append(ob)
+    for ob in NEWOBJ:
+        if ob.type == "MESH":
             if len(ob.modifiers):
                 for MODIFIER in ob.modifiers[:]:
                     if MODIFIER.type == "SUBSURF" or MODIFIER.type == "MASK":
-                        ob.modifiers.remove(MODIFIER)    
-                   
-        
+                        ob.modifiers.remove(MODIFIER)
+
 class OscGroupLinkedToLocal(bpy.types.Operator):
     bl_idname = "group.linked_group_to_local"
     bl_label = "Group Linked To Local"
     bl_description = "Group Linked To Local"
-    bl_options = {'REGISTER', 'UNDO'}    
+    bl_options = {'REGISTER', 'UNDO'}
 
     def execute(self, context):
         OscLinkedGroupToLocal()
         return {'FINISHED'}
-    
 
 def register():
     bpy.utils.register_module(__name__)
@@ -199,8 +196,4 @@
     bpy.utils.unregister_module(__name__)
 
 if __name__ == "__main__":
-    register()
-    
-    
-    
-import bpy
\ No newline at end of file
+    register()
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list