2
2
from mathutils import Vector
3
3
from bpy.props import FloatVectorProperty
5
6
class ViewOperator(bpy.types.Operator):
6
7
'''Translate the view using mouse events.'''
7
8
bl_idname = "view3d.modal_operator"
8
9
bl_label = "Simple View Operator"
10
offset = FloatVectorProperty(name="Offset", size=3)
11
offset = FloatVectorProperty(
13
16
def execute(self, context):
14
17
v3d = context.space_data
15
18
rv3d = v3d.region_3d
17
rv3d.view_location = self._initial_location + Vector(self.properties.offset)
20
rv3d.view_location = self._initial_location + Vector(self.offset)
19
22
def modal(self, context, event):
20
23
v3d = context.space_data
21
24
rv3d = v3d.region_3d
23
26
if event.type == 'MOUSEMOVE':
24
self.properties.offset = (self._initial_mouse - Vector((event.mouse_x, event.mouse_y, 0.0))) * 0.02
27
self.offset = (self._initial_mouse - Vector((event.mouse_x, event.mouse_y, 0.0))) * 0.02
25
28
self.execute(context)
29
context.area.header_text_set("Offset %.4f %.4f %.4f" % tuple(self.offset))
27
31
elif event.type == 'LEFTMOUSE':
32
context.area.header_text_set()
28
33
return {'FINISHED'}
30
elif event.type in ('RIGHTMOUSE', 'ESC'):
35
elif event.type in {'RIGHTMOUSE', 'ESC'}:
31
36
rv3d.view_location = self._initial_location
37
context.area.header_text_set()
32
38
return {'CANCELLED'}
34
40
return {'RUNNING_MODAL'}