[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4343] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: BProjection: add new feature, new clone method

geo kgeo kgeogeo at hotmail.com
Tue Mar 5 12:27:02 CET 2013


Revision: 4343
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4343
Author:   kgeogeo
Date:     2013-03-05 11:27:01 +0000 (Tue, 05 Mar 2013)
Log Message:
-----------
BProjection: add new feature, new clone method

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	2013-03-04 23:05:13 UTC (rev 4342)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py	2013-03-05 11:27:01 UTC (rev 4343)
@@ -1,5 +1,5 @@
 bl_info = {
-    "name": "BProjection",
+    "name": "BProjection_mega_test",
     "description": "Help Clone tool",
     "author": "kgeogeo",
     "version": (2, 0),
@@ -24,6 +24,8 @@
 
 # Main function for align the plan to view
 def align_to_view(context):
+    global last_mouse
+    last_mouse = Vector((0,0))
     ob = context.object
     em = bpy.data.objects[BProjection_Empty]       
     rotation = em.custom_rotation
@@ -252,6 +254,16 @@
     if self.custom_active:
         em.custom_active_view = self.custom_active_view
 
+def update_style_clone(self, context):    
+    km = context.window_manager.keyconfigs.default.keymaps['Image Paint']
+    for kmi in km.keymap_items:
+        if self.custom_style_clone:         
+            if kmi.idname == 'paint.image_paint':
+                kmi.idname = 'paint.bp_paint'
+        else:
+            if kmi.idname == 'paint.bp_paint':
+                kmi.idname = 'paint.image_paint'    
+
 class custom_props(bpy.types.PropertyGroup):
     custom_fnlevel = IntProperty(name="Fast navigate level", description="Increase or decrease the SubSurf level, decrease make navigation faster", default=0)
     
@@ -299,6 +311,7 @@
     # other properties
     custom_active= BoolProperty(name="custom_active", default=True)   
     custom_expand = BoolProperty(name="expand", default=False)
+    custom_style_clone = BoolProperty(name="custom_style_clone", default=False)
     
     custom_active_view = StringProperty(name = "custom_active_view",default = "View",update = update_activeviewname)
     
@@ -320,7 +333,7 @@
                                            step     = 0.5,
                                            soft_min = -10,
                                            soft_max = 10,
-                                           update   = update_Location)
+                                           update = update_Location)
                                            
     Ob.custom_rotation = FloatProperty(name="Rotation", description="Rotate the plane",
                                        min=-180, max=180, default=0,update = update_Rotation)
@@ -388,6 +401,8 @@
     Ob.custom_rotc3d = BoolProperty(name="rotc3d", default=False)
     Ob.custom_scac3d = BoolProperty(name="scac3d", default=False)
     Ob.custom_expand = BoolProperty(name="expand", default=True)
+    Ob.custom_style_clone = BoolProperty(name="custom_style_clone", default=False, update = update_style_clone)
+    
     Ob.custom_active_view = StringProperty(name = "custom_active_view",default = "View")
     try:
         Ob.custom_active_object = StringProperty(name = "custom_active_object",default = context.object.name)
@@ -400,7 +415,7 @@
     list_prop = ['custom_location', 'custom_rotation', 'custom_old_rotation', 'custom_scale', 'custom_old_scale', 'custom_c3d',
                  'custom_rotc3d', 'custom_scaleuv', 'custom_flipuvx', 'custom_flipuvy', 'custom_linkscale',
                  'custom_linkscaleuv', 'custom_old_scaleuv', 'custom_offsetuv', 'custom_old_offsetuv', 'custom_scac3d', 'custom_sub',
-                 'custom_expand', 'custom_active_view', 'custom_propscaleuv', 'custom_props', 'custom_propscale']
+                 'custom_expand', 'custom_style_clone', 'custom_active_view', 'custom_propscaleuv', 'custom_props', 'custom_propscale']
     for prop in list_prop:
         try:
             del bpy.data.objects[BProjection_Empty][prop]
@@ -644,7 +659,11 @@
                     row = box.column(align =True)
                     row.prop(ob,"custom_fnlevel")
                     row = box.column(align =True)
-                        
+                    if not em.custom_style_clone:
+                        row.prop(em,"custom_style_clone",text="Style Clone Normal", icon='RENDERLAYERS')
+                    else:
+                        row.prop(em,"custom_style_clone",text="Style Clone New", icon='RENDERLAYERS')    
+                    row = box.column(align =True)    
     
                 if ob == bpy.data.objects[em.custom_active_object]:    
                     for item in em.custom_props:
@@ -821,7 +840,7 @@
             bpy.ops.object.create_view()
                     
             km = bpy.data.window_managers['WinMan'].keyconfigs['Blender'].keymaps['3D View']
-            l = ['view3d.rotate','view3d.move','view3d.zoom','view3d.viewnumpad','MOUSE','KEYBOARD','MIDDLEMOUSE','WHEELINMOUSE','WHEELOUTMOUSE','NUMPAD_1','NUMPAD_3','NUMPAD_7']
+            l = ['view3d.rotate','view3d.move','view3d.zoom','view3d.viewnumpad','paint.bp_paint','MOUSE','KEYBOARD','LEFT','MIDDLEMOUSE','WHEELINMOUSE','WHEELOUTMOUSE','NUMPAD_1','NUMPAD_3','NUMPAD_7']
             for kmi in km.keymap_items:
                 if kmi.idname in l and kmi.map_type in l and kmi.type in l:
                     try:
@@ -839,9 +858,10 @@
                             if kmi.idname == 'view3d.rotate':
                                 kmi.idname = 'view3d.rotate_view3d'  
                             if kmi.idname == 'view3d.move':
-                                kmi.idname = 'view3d.pan_view3d' 
-                                                       
+                                kmi.idname = 'view3d.pan_view3d'
+                                                              
             km = context.window_manager.keyconfigs.default.keymaps['Image Paint']
+                    
             kmi = km.keymap_items.new("object.intuitivescale", 'LEFTMOUSE', 'PRESS', shift=True)
             kmi = km.keymap_items.new("object.bp_grab", 'G', 'PRESS')
             kmi = km.keymap_items.new("object.bp_rotate", 'R', 'PRESS') 
@@ -849,6 +869,7 @@
             kmi = km.keymap_items.new("object.bp_scaleuv", 'U', 'PRESS')
             kmi = km.keymap_items.new("object.bp_offsetuv", 'Y', 'PRESS')
             kmi = km.keymap_items.new("object.bp_clear_prop", 'C', 'PRESS')
+            kmi = km.keymap_items.new("object.bp_toggle_alpha", 'Q', 'PRESS')
             align_to_view(context)
             
             context.space_data.cursor_location = em.location
@@ -958,8 +979,12 @@
                         kmi.idname = 'view3d.move'            
             
     km = bpy.context.window_manager.keyconfigs.default.keymaps['Image Paint']
-    #to do
-    for kmi in (kmi for kmi in km.keymap_items if kmi.idname in {"object.intuitivescale", "object.bp_grab", "object.bp_rotate", "object.bp_scale", "object.bp_scaleuv", "object.bp_clear_prop", "object.bp_offsetuv", }):
+                
+    for kmi in km.keymap_items:
+        if kmi.idname == 'paint.bp_paint':
+            kmi.idname = 'paint.image_paint'
+            
+    for kmi in (kmi for kmi in km.keymap_items if kmi.idname in {"object.intuitivescale", "object.bp_grab", "object.bp_rotate", "object.bp_scale", "object.bp_scaleuv", "object.bp_clear_prop", "object.bp_offsetuv","object.bp_toggle_alpha", }):
             km.keymap_items.remove(kmi)
 
 # Oprerator Class to remove what is no more needed    
@@ -1068,7 +1093,121 @@
                 em.custom_c3d = tmp
                     
             return {'FINISHED'}
+    
+#Paint from the bp_plan
 
+last_mouse = Vector((0,0))
+
+def move_bp(self,context,cm,fm):
+    em = bpy.data.objects['Empty for BProjection']
+    
+    deltax = cm.x - round(fm.x)
+    deltay = cm.y - round(fm.y)
+    
+    sd = context.space_data              
+    l =  sd.region_3d
+    vr = l.view_rotation.copy()
+    vr.invert()
+    
+    v_init = Vector((0.0,0.0,1.0))
+    
+    pos = [-deltax,-deltay]
+    v = view3d_utils.region_2d_to_location_3d(context.region, l, pos, v_init)
+    pos = [0,0]
+    vbl = view3d_utils.region_2d_to_location_3d(context.region, l, pos, v_init)        
+    loc = vbl - v 
+      
+    loc.rotate(vr)
+        
+    em.custom_location -= loc
+    
+    self.first_mouse = cm
+            
+class BP_Paint(bpy.types.Operator):
+    bl_idname = "paint.bp_paint"
+    bl_label = "Paint BProjection Plane"
+    
+    first_mouse = Vector((0,0))
+    
+    @classmethod
+    def poll(cls, context):
+        return 1
+
+    def modal(self, context, event):
+        global last_mouse
+        em = bpy.data.objects['Empty for BProjection']        
+        sd = context.space_data
+        
+        center = view3d_utils.location_3d_to_region_2d(context.region, sd.region_3d, em.location)
+        vec_init = self.first_mouse - center        
+        vec_act = Vector((event.mouse_region_x, event.mouse_region_y)) - center               
+        
+        print(event.type)
+            
+        if event.type == 'MOUSEMOVE':#'INBETWEEN_MOUSEMOVE':                
+             
+            move_bp(self,context,Vector((event.mouse_region_x, event.mouse_region_y)) - self.v_offset,self.first_mouse)   
+            
+            bpy.ops.paint.image_paint(stroke=[{"name":"", "location":(0, 0, 0), "mouse":(event.mouse_region_x, event.mouse_region_y),
+                                                   "pressure":1, "pen_flip":False, "time":0, "is_start":False}])
+
+        if event.type == 'LEFTMOUSE':
+            em.custom_c3d = True
+            bpy.data.materials['Material for BProjection'].alpha = self.alpha
+            em.custom_location = self.first_location
+            return {'FINISHED'}
+        
+        if event.type == 'ESC' or event.type == 'RIGHTMOUSE':
+            em.custom_c3d = True
+            bpy.data.materials['Material for BProjection'].alpha = self.alpha
+            em.custom_location = self.first_location
+            return {'FINISHED'}
+        
+        return {'PASS_THROUGH'}
+                
+    def invoke(self, context, event):   
+        em = bpy.data.objects['Empty for BProjection']
+        context.window_manager.modal_handler_add(self)
+        self.first_mouse = Vector((event.mouse_region_x, event.mouse_region_y))
+        
+        sd = context.space_data              
+        l =  sd.region_3d        
+        v_init = Vector((0.0,0.0,1.0))
+        context.scene.cursor_location = view3d_utils.region_2d_to_location_3d(context.region, l, [event.mouse_region_x, event.mouse_region_y], v_init)
+        

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list