[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3142] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: BProjection: code clean up

geo kgeo kgeogeo at hotmail.com
Wed Mar 21 02:11:37 CET 2012


Revision: 3142
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3142
Author:   kgeogeo
Date:     2012-03-21 01:11:26 +0000 (Wed, 21 Mar 2012)
Log Message:
-----------
BProjection: code clean up

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

Modified: contrib/py/scripts/addons/space_view3d_paint_bprojection.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_paint_bprojection.py	2012-03-21 00:06:38 UTC (rev 3141)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py	2012-03-21 01:11:26 UTC (rev 3142)
@@ -23,14 +23,13 @@
     rotation = ob.custom_rotation
     scale = ob.custom_scale
     z = ob.custom_z
-    posx = ob.custom_location[0]
-    posy = ob.custom_location[1]
+    pos = [ob.custom_location[0], ob.custom_location[1]]
 
-    reg = bpy.context.area.regions[4]        
+    reg = context.area.regions[4]        
     width = reg.width
     height = reg.height 
         
-    r3d =  context.space_data.region_3d        
+    r3d = context.space_data.region_3d        
     r3d.update()
     vl = r3d.view_location
     vr = r3d.view_rotation
@@ -39,8 +38,6 @@
     v = Vector((1,0,z))
     v.rotate(vr)
 
-    pos = (posx,posy) 
-
     em = bpy.data.objects['Empty for BProjection']
     img = bpy.data.textures['Texture for BProjection'].image
     if img and img.size[1] != 0:
@@ -48,9 +45,9 @@
     else: prop = 1    
     
     if ob.custom_linkscale:    
-        em.scale =  Vector((prop*scale[0],scale[0],1))
+        em.scale = Vector((prop*scale[0], scale[0], 1))
     else:
-        em.scale =  Vector((prop*scale[0],scale[1],1))
+        em.scale = Vector((prop*scale[0], scale[1], 1))
             
     em.location = view3d_utils.region_2d_to_location_3d(context.area.regions[4], r3d, pos, v)        
     em.rotation_euler = Quaternion.to_euler(vr*quat)
@@ -66,24 +63,24 @@
     scale = context.object.custom_scaleuv - context.object.custom_old_scaleuv
     s = context.object.custom_scaleuv
     o = context.object.custom_old_scaleuv 
-    uvdata = bpy.context.object.data.uv_loop_layers.active.data
+    uvdata = context.object.data.uv_loop_layers.active.data
     for i in range(484):
         vres =  v - uvdata[len(uvdata)-1-i].uv 
         l.x = vres.x
         l.y = vres.y   
 
-        if bpy.context.object.custom_linkscaleuv:
+        if context.object.custom_linkscaleuv:
             uvdata[len(uvdata)-1-i].uv = [v.x - l.x/o[0]*s[0], v.y - l.y/o[0]*s[0]]
         else:
-            uvdata[len(uvdata)-1-i].uv = [v.x - l.x/o[0]*s[0], v.y - l.y/o[1]*s[1]]
-    
+            uvdata[len(uvdata)-1-i].uv = [v.x - l.x/o[0]*s[0], v.y - l.y/o[1]*s[1]]    
+
     context.object.custom_old_scaleuv = context.object.custom_scaleuv
     
     align_to_view(context)
 
 # Function to update the flip horizontal
 def update_FlipUVX(self, context):          
-    uvdata = bpy.context.object.data.uv_loop_layers.active.data
+    uvdata = context.object.data.uv_loop_layers.active.data
     for i in range(484):
         x = uvdata[len(uvdata)-1-i].uv[0]
         l = 0.5 - x
@@ -93,7 +90,7 @@
 
 # Function to update the flip vertical
 def update_FlipUVY(self, context):          
-    uvdata = bpy.context.object.data.uv_loop_layers.active.data
+    uvdata = context.object.data.uv_loop_layers.active.data
     for i in range(484):
         x = uvdata[len(uvdata)-1-i].uv[1]
         l = 0.5 - x
@@ -105,7 +102,7 @@
 def update_Rotation(self, context):              
     if context.object.custom_rotc3d:
         angle = context.object.custom_rotation - context.object.custom_old_rotation
-        c3d = bpy.context.space_data.cursor_location
+        c3d = context.space_data.cursor_location
         em = bpy.data.objects['Empty for BProjection'].location
         c = c3d
         e = em
@@ -119,10 +116,8 @@
         v = v1 - v2
         res = e - v
         context.space_data.region_3d.update()
-        x = view3d_utils.location_3d_to_region_2d(context.area.regions[4], bpy.context.space_data.region_3d, res)
-        y=[0,0]
-        y[0] = round(x[0])
-        y[1] = round(x[1])
+        x = view3d_utils.location_3d_to_region_2d(context.area.regions[4], context.space_data.region_3d, res)
+        y=[round(x[0]), round(x[1])]
         
         context.object.custom_location = y       
     else:
@@ -130,24 +125,42 @@
     context.object.custom_old_rotation = context.object.custom_rotation
 
 # Function to create custom properties
-def createcustomprops():
+def createcustomprops(context):
     Ob = bpy.types.Object    
-    Ob.custom_location = IntVectorProperty(name="Location", description="Location of the plan", default=(trunc(bpy.context.area.regions[4].width*3/4),trunc( bpy.context.area.regions[4].height*3/4)), subtype = 'XYZ', size=2, update = update_props)
-    Ob.custom_rotation = IntProperty(name="Rotation", description="Rotate the plane", min=-180, max=180, default=0,update = update_Rotation)
-    Ob.custom_old_rotation = IntProperty(name="old_Rotation", description="Old Rotate the plane", min=-180, max=180, default=0)
-    Ob.custom_scale = FloatVectorProperty(name="Scales", description="Scale the planes", subtype = 'XYZ', default=(1.0, 1.0),min = 0.1, size=2,update = update_props)
     
-    Ob.custom_z = FloatProperty(name="Z", description="Z axis for the plane", min=-10, max=10, default=-1.0,update = update_props)
+    # plane properties 
+    Ob.custom_location = IntVectorProperty(name="Location", description="Location of the plan",
+                                           default=(trunc(context.area.regions[4].width*3/4),trunc( context.area.regions[4].height*3/4)),
+                                           subtype = 'XYZ', size=2, update = update_props)
+                                           
+    Ob.custom_rotation = IntProperty(name="Rotation", description="Rotate the plane",
+                                     min=-180, max=180, default=0,update = update_Rotation)
+                                     
+    Ob.custom_old_rotation = IntProperty(name="old_Rotation", description="Old Rotate the plane",
+                                         min=-180, max=180, default=0)
+                                         
+    Ob.custom_scale = FloatVectorProperty(name="Scales", description="Scale the planes",
+                                          subtype = 'XYZ', default=(1.0, 1.0),min = 0.1, size=2,update = update_props)
+    Ob.custom_linkscale = BoolProperty(name="linkscale", default=True, update = update_props)
+    
+    Ob.custom_z = FloatProperty(name="Z", description="Z axis for the plane",
+                                min=-10, max=10, default=-1.0,update = update_props)
+    
+    # UV properties
+    Ob.custom_scaleuv = FloatVectorProperty(name="ScaleUV", description="Scale the texture's UV",
+                                            default=(1.0,1.0),min = 0.1, subtype = 'XYZ', size=2,update = update_UVScale)    
+    Ob.custom_old_scaleuv = FloatVectorProperty(name="old_ScaleUV", description="Scale the texture's UV",
+                                                default=(1.0,1.0),min = 0.1, subtype = 'XYZ', size=2)
+    Ob.custom_linkscaleuv = BoolProperty(name="linkscaleUV", default=True, update = update_UVScale)
+    Ob.custom_flipuvx = BoolProperty(name="flipuvx", default=False, update = update_FlipUVX)
+    Ob.custom_flipuvy = BoolProperty(name="flipuvy", default=False, update = update_FlipUVY)
+    
+    # other properties    
     Ob.custom_c3d = BoolProperty(name="c3d", default=True)
     Ob.custom_rot = BoolProperty(name="rot", default=True)
-    Ob.custom_rotc3d = BoolProperty(name="rotc3d", default=False)
-    Ob.custom_scaleuv = FloatVectorProperty(name="ScaleUV", description="Scale the texture's UV", default=(1.0,1.0),min = 1, subtype = 'XYZ', size=2,update = update_UVScale)
-    Ob.custom_old_scaleuv = FloatVectorProperty(name="old_ScaleUV", description="Scale the texture's UV", default=(1.0,1.0),min = 1, subtype = 'XYZ', size=2)
-    Ob.custom_flipuvx = BoolProperty(name="flipuvx", default=False, update = update_FlipUVX)
-    Ob.custom_flipuvy = BoolProperty(name="flipuvy", default=False, update = update_FlipUVY)
-    Ob.custom_linkscale = BoolProperty(name="linkscale", default=True, update = update_props)
-    Ob.custom_linkscaleuv = BoolProperty(name="linkscaleUV", default=True, update = update_UVScale)
+    Ob.custom_rotc3d = BoolProperty(name="rotc3d", default=False)    
 
+
 def removecustomprops():    
     try:
         bpy.ops.wm.properties_remove(data_path='object',property='custom_location')
@@ -231,39 +244,39 @@
             layout.template_ID_preview(tex, "image", open="image.open", rows=3, cols=3)
         
             col = layout.column(align =True)
-            col.operator('object.applyimage', text = "Apply image",icon = 'FILE_TICK')
+            col.operator('object.applyimage', text="Apply image", icon = 'FILE_TICK')
             col = layout.column(align =True)
             ob = context.object
-            col.prop(ob, "custom_c3d",text="Capture Cursor3d",icon='CURSOR')
-            col.prop(ob, "custom_rot",text="Rotate around selection",icon='ROTATE')
+            col.prop(ob, "custom_c3d",text="Capture Cursor3d", icon='CURSOR')
+            col.prop(ob, "custom_rot",text="Rotate around selection", icon='ROTATE')
             col = layout.column(align =True)
-            col.prop(ob,'custom_location', text = 'Plane Properties')
+            col.prop(ob,'custom_location', text='Plane Properties')
             col.prop(ob,'custom_z') 
             col.prop(ob,'custom_rotation')
-            col.prop(ob,'custom_rotc3d',text = "Rotate around 3D Cursor",icon = 'MANIPUL')            
+            col.prop(ob,'custom_rotc3d',text="Rotate around 3D Cursor",icon='MANIPUL')            
             row = layout.row()
             col = row.column(align =True)
             col.prop(ob,'custom_scale')
             if ob.custom_linkscale :
-                col.prop(ob, "custom_linkscale",text="Linked",icon = 'LINKED')
+                col.prop(ob, "custom_linkscale",text="Linked",icon='LINKED')
             else: 
-                col.prop(ob, "custom_linkscale",text="Unlinked",icon = 'UNLINKED')                 
+                col.prop(ob, "custom_linkscale",text="Unlinked",icon='UNLINKED')                 
             col = layout.column(align =True)
             col.prop(ob,'custom_scaleuv')
             if ob.custom_linkscaleuv:
-                col.prop(ob, "custom_linkscaleuv",text="Linked",icon = 'LINKED')
+                col.prop(ob, "custom_linkscaleuv",text="Linked",icon='LINKED')
             else: 

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list