-
Notifications
You must be signed in to change notification settings - Fork 2
/
PreviewModal.py
88 lines (71 loc) · 2.82 KB
/
PreviewModal.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import bpy
import yerface_blender.SceneUtilities
import yerface_blender.WebsocketReader
isPreviewRunning = False
myPreviewTimer = None
myReader = None
myUpdater = None
class YerFacePreviewStartOperator(bpy.types.Operator):
bl_idname = "wm.yerface_preview_start"
bl_label = "YerFace Preview Start"
bl_description = "Start previewing data from the Yer Face performance capture tool."
bl_options = {'REGISTER'}
def modal(self, context, event):
global isPreviewRunning
global myUpdater
if event.type == 'ESC' or not isPreviewRunning:
return self.cancel(context)
if event.type == 'TIMER':
myUpdater.runUpdate()
return {'PASS_THROUGH'}
def execute(self, context):
global isPreviewRunning
global myPreviewTimer
global myReader
global myUpdater
props = context.scene.yerFaceBlenderProperties
fps = context.scene.render.fps / context.scene.render.fps_base
time_step = 1/fps
isPreviewRunning = True
myReader = yerface_blender.WebsocketReader.YerFaceWebsocketReader(props.websocketURI)
myReader.openWebsocket()
myUpdater = yerface_blender.SceneUtilities.YerFaceSceneUpdater(context, myReader, fps)
if props.tickCallback != "":
tickProps = {
'userData': props.tickUserData,
'resetState': True,
'perfcapPacket': {},
'insertKeyframes': False,
'currentFrameNumber': None,
'flushLastFrame': False,
'discardLastFrameData': False,
'samplingMode': None,
'framesPerSecond': fps
}
bpy.app.driver_namespace[props.tickCallback](tickProps)
context.window_manager.modal_handler_add(self)
myPreviewTimer = context.window_manager.event_timer_add(time_step, context.window)
print("STARTED TIMER w/Time Step: ", time_step)
return {'RUNNING_MODAL'}
def cancel(self, context):
global isPreviewRunning
global myPreviewTimer
global myReader
if isPreviewRunning:
isPreviewRunning = False
context.window_manager.event_timer_remove(myPreviewTimer)
myReader.closeWebsocket()
myReader = None
print("CANCELLED TIMER")
return {'CANCELLED'}
def isPreviewRunning(self):
global isPreviewRunning
return isPreviewRunning
class YerFacePreviewStopOperator(bpy.types.Operator):
bl_idname = "wm.yerface_preview_stop"
bl_label = "YerFace Preview Stop"
bl_description = "Stop previewing data from the Yer Face performance capture tool."
bl_options = {'REGISTER'}
def execute(self, context):
YerFacePreviewStartOperator.cancel(None, context)
return {'FINISHED'}