-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoboreceiver.py
202 lines (181 loc) · 5.84 KB
/
moboreceiver.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# MoBoReceiver runs inside Motionbuilder. It is responsible for parsing the remote input strings,
# and running Motionbuilder commands.
import re
import math
import telnetlib
from pyfbsdk import *
from PySide.QtCore import QTimer, QObject
class MoBoReceiver(QObject):
FStopMap = [0.6, 0.7, 0.8, 1.0, 1.4, 1.7, 2.0, 2.4, 2.8, 3.3, 4.0, 5.6, 6.7, 8.0, 9.5, 11, 13, 16, 22]
ISOMap = [0.01, 0.02, 0.03, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1, 1.6, 3, 6, 12, 25, 50, 100, 200, 400, 800, 1600, 3200, 6400]
def __init__(self, remoteIP=None, remotePort=23):
super(MoBoReceiver, self).__init__()
self.remoteIP = remoteIP
self.remotePort = remotePort
@staticmethod
def mapVal(x, out_min, out_max, in_min=0, in_max=1023):
return (x - in_min) * (out_max - out_min) / float(in_max - in_min) + out_min
def processInput(self, data):
print "ProcessInput", [data]
down = re.findall(r'dn(\d\d)', data)
if down:
down = down[0]
if down == '00':
self.playToggle()
elif down == '01':
self.recordToggle()
elif down == '02':
self.prevCamera()
elif down == '03':
self.nextCamera()
elif down == '04':
self.setCameraFov( self.currentCamera().FieldOfView + 1 )
elif down == '05':
self.setCameraSpecificDistance( self.currentCamera().FocusSpecificDistance + 1 )
elif down == '06':
self.setCameraFocusAngle( self.FStopMap[self.closestFStopIndex(1)] )
elif down == '07':
self.setISO(self.ISOMap[self.closestISOIndex(1)])
elif down == '08':
self.setCameraFov( self.currentCamera().FieldOfView - 1 )
elif down == '09':
self.setCameraSpecificDistance( self.currentCamera().FocusSpecificDistance - 1 )
elif down == '10':
self.setCameraFocusAngle( self.FStopMap[self.closestFStopIndex(-1)] )
elif down == '11':
self.setISO(self.ISOMap[self.closestISOIndex(-1)])
elif down == '12':
self.startFrame()
elif down == '13':
self.loopToggle()
# elif down == '14':
# pass
elif down == '15':
print "press Esc"
return
# Use this to process button releases
# up = re.findall(r'up(\d\d)', data)
# if up:
# if up == '00':
# pass
potVal = re.findall(r'p([A-C])(\d{,4})', data)
if potVal:
pot, value = potVal[0]
if pot == 'A':
fov = self.mapVal(int(value), 8, 150)
self.setCameraFov(fov)
if pot == 'B':
dist = self.mapVal(int(value), 1, 500)
self.setCameraSpecificDistance(dist)
# if pot == 'C':
# # -999999.99 - 100
# angle = self.mapVal(int(value), 0.8, 11)
# self.setCameraFocusAngle(angle)
if pot == 'C':
# Map ISO arithmetric range: 25-6400
# isoLog = self.mapVal(int(value), 14.98, 39.09)
isoLog = self.mapVal(int(value), 0.005, 39.09)
self.setLogISO(isoLog)
def closestFStopIndex(self, inc=0):
current = self.currentCamera().FocusAngle
index = self.FStopMap.index(min(self.FStopMap, key=lambda x:abs(x - current)))
index += inc
if index < 0:
index = 0
elif index >= len(self.FStopMap):
index = len(self.FStopMap) - 1
return index
def closestISOIndex(self, inc=0):
current = self.currentISO()
index = self.ISOMap.index(min(self.ISOMap, key=lambda x: abs(x - current)))
index += inc
if index < 0:
index = 0
elif index >= len(self.ISOMap):
index = len(self.ISOMap) - 1
return index
def currentCamera(self):
cameraSwitcher = FBCameraSwitcher()
return cameraSwitcher.CurrentCamera
def currentISO(self):
# TODO: Implement ISO
return 400
def findCameras(self):
ret = []
for child in FBSystem().Scene.RootModel.Children:
if isinstance(child, FBCamera):
ret.append(child)
return ret
def nextCamera(self):
cameras = self.findCameras()
FBSystem().Scene.Renderer.UseCameraSwitcher = True
# Set our view to the newly created camera.
cameraSwitcher = FBCameraSwitcher()
current = cameraSwitcher.CurrentCamera
for i, cam in enumerate(cameras):
if cam == current:
i += 1
if i == len(cameras):
i = 0
cameraSwitcher.CurrentCamera = cameras[i]
print 'Switched to camera:', cameras[i].Name
return
else:
print 'Unable to find the camera'
def prevCamera(self):
print 'previous camera'
cameras = self.findCameras()
FBSystem().Scene.Renderer.UseCameraSwitcher = True
# Set our view to the newly created camera.
cameraSwitcher = FBCameraSwitcher()
current = cameraSwitcher.CurrentCamera
for i, cam in enumerate(cameras):
if cam == current:
i -= 1
if i < 0:
i = len(cameras) - 1
cameraSwitcher.CurrentCamera = cameras[i]
print 'Switched to camera:', cameras[i].Name
return
else:
print 'Unable to find the camera'
def setCameraFov(self, fov):
self.currentCamera().FieldOfView = fov
def setCameraFocusAngle(self, angle):
print 'F-Stop', angle
self.currentCamera().FocusAngle = angle
def setLogISO(self, speed):
""" Maps the ISO logarithmic scale values to map the arithmetric iso value.
The ISO standard rounds to the nerest value in a table just to make it complicated
"""
arithmeticSpeed = math.pow(10.0, (speed-1.0)/10.0)
print 'arithmeticSpeed', speed, arithmeticSpeed
self.setISO(speed)
def setISO(self, speed):
print 'setISO', speed
# TODO: Implement ISO
def setCameraSpecificDistance(self, dist):
self.currentCamera().FocusSpecificDistance = dist
def playToggle(self):
print 'Play toggle'
playback = FBPlayerControl()
if playback.IsPlaying:
playback.Stop()
else:
playback.Play()
def recordToggle(self):
print 'Record Toggle'
# this doesn't seem to work reliably.
playback = FBPlayerControl()
if playback.IsRecording:
playback.Stop()
host = telnetlib.Telnet(self.remoteIP, self.remotePort, 2).write('s\r\n')
else:
playback.Record()
host = telnetlib.Telnet(self.remoteIP, self.remotePort, 2).write('r\r\n')
def loopToggle(self):
playback = FBPlayerControl()
playback.LoopActive = not playback.LoopActive
def startFrame(self):
print 'Start Frame'
FBPlayerControl().GotoStart()