BProjection: Update version
[blender-addons-contrib.git] / space_view3d_paint_bprojection.py
1 bl_info = {
2     "name": "BProjection",
3     "description": "Help Clone tool",
4     "author": "kgeogeo",
5     "version": (2, 0),
6     "blender": (2, 66, 0),
7     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/bprojection",
8     "tracker_url":"http://projects.blender.org/tracker/index.php?func=detail&aid=30521&group_id=153&atid=468",
9     "category": "Paint"}
10
11 import bpy
12 from bpy.app.handlers import persistent
13 from bpy.types import Panel, Operator
14 from bpy.props import IntProperty, FloatProperty, BoolProperty, IntVectorProperty, StringProperty, FloatVectorProperty, CollectionProperty
15 from bpy_extras import view3d_utils
16 import math
17 from math import *
18 import mathutils
19 from mathutils import *
20
21
22 # Oprerator Class to rotate the view3D
23 class RotateView3D(Operator):
24     bl_idname = "view3d.rotate_view3d"
25     bl_label = "Rotate the View3D"
26     
27     first_mouse = Vector((0,0))
28     
29     def turnable(self, context, mx, my, origine):
30         sd = context.space_data
31         vz = Vector((0,0,1))
32         qz =  Quaternion(vz,-(mx-self.first_mouse.x)*pi/180)
33         sd.region_3d.view_rotation.rotate(qz)
34         sd.region_3d.update()
35
36         vx = Vector((1,0,0))
37         vx.rotate(sd.region_3d.view_rotation)        
38         qx =  Quaternion(vx,(my-self.first_mouse.y)*pi/180)        
39         sd.region_3d.view_rotation.rotate(qx)                
40         sd.region_3d.update()
41                 
42         self.first_mouse = Vector((mx, my))
43                 
44     def modal(self, context, event):                                
45
46         reg = context.region        
47
48         if event.type == 'MOUSEMOVE':  
49             self.turnable(context, event.mouse_region_x, event.mouse_region_y,Vector((0,0,0)))
50         if event.type == 'ESC':
51             return {'FINISHED'}   
52         return {'RUNNING_MODAL'}
53
54     def invoke(self, context, event):
55         context.window_manager.modal_handler_add(self)
56         self.first_mouse = Vector((event.mouse_region_x,event.mouse_region_y))
57
58         return {'RUNNING_MODAL'}
59
60 def register():
61     bpy.utils.register_module(__name__)
62     km = bpy.data.window_managers['WinMan'].keyconfigs['Blender'].keymaps['3D View']
63     for kmi in km.keymap_items:
64         if kmi.idname == 'view3d.rotate':
65             kmi.idname = 'view3d.rotate_view3d'
66
67 def unregister():
68     bpy.utils.unregister_module(__name__)
69     km = bpy.data.window_managers['WinMan'].keyconfigs['Blender'].keymaps['3D View']
70     for kmi in km.keymap_items:
71         if kmi.idname == 'view3d.rotate_view3d':
72             kmi.idname = 'view3d.rotate'  
73
74 if __name__ == "__main__":
75     register()