-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeScrubOperator.py
56 lines (39 loc) · 1.48 KB
/
TimeScrubOperator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import bpy
from mathutils import Vector
from bpy.props import FloatVectorProperty
class TimeScrubOperator(bpy.types.Operator):
"""Translate the view using mouse events"""
bl_idname = "view3d.time_scrub_operator"
bl_label = "Time Scrub Operator"
def execute(self, context):
context.scene.frame_set(self._initial_time - (self.offset*0.2))
pass
def modal(self, context, event):
v3d = context.space_data
rv3d = v3d.region_3d
if event.value == 'RELEASE':
context.area.header_text_set()
return {'CANCELLED'}
if event.type == 'MOUSEMOVE':
self.offset = self._initial_mouse_x - event.mouse_x
self.execute(context)
elif event.type in {'RIGHTMOUSE', 'ESC'}:
context.area.header_text_set()
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.space_data.type == 'VIEW_3D':
self._initial_mouse_x = event.mouse_x
self._initial_time = context.scene.frame_current
context.window_manager.modal_handler_add(self)
print("invokin")
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "Active space must be a View3d")
return {'CANCELLED'}
def register():
bpy.utils.register_class(TimeScrubOperator)
def unregister():
bpy.utils.unregister_class(TimeScrubOperator)
if __name__ == "__main__":
register()