-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvizconnect_config_CaveFloor+ART_headnode.py
778 lines (621 loc) · 25.6 KB
/
vizconnect_config_CaveFloor+ART_headnode.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
"""
This module was generated by Vizconnect.
Version: 1.01
Generated on: 2014-08-05 11:37:38.656000
APG: This file assumes running cluster
on a single machine (localhost)
"""
#Andrew Grace, Feb 23, 2018
#Intended to run from the head node
import viz
import vizconnect
#################################
# Parent configuration, if any
#################################
def getParentConfiguration():
#VC: set the parent configuration
_parent = ''
#VC: return the parent configuration
return _parent
#################################
# Pre viz.go() Code
#################################
def preVizGo():
return True
#################################
# Pre-initialization Code
#################################
def preInit():
"""Add any code here which should be called after viz.go but before any initializations happen.
Returned values can be obtained by calling getPreInitResult for this file's vizconnect.Configuration instance."""
return None
#################################
# Group Code
#################################
def initGroups(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawGroup = vizconnect.getRawGroupDict()
#VC: initialize a new group
_name = 'cave_manual_configuration'
if vizconnect.isPendingInit('group', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: create the raw object
rawGroup[_name] = viz.addGroup()
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addGroup(rawGroup[_name], _name, make='Virtual', model='Origin')
#VC: set the parent of the node
if initFlag&vizconnect.INIT_PARENTS:
vizconnect.getGroup(_name).setParent(vizconnect.getTransport('wandmagiccarpet'))
#VC: return values can be modified here
return None
#################################
# Display Code
#################################
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawDisplay = vizconnect.getRawDisplayDict()
#VC: initialize a new display
CAVE_CONFIG_NAME = 'cave_manual_configuration'
if vizconnect.isPendingInit('display', CAVE_CONFIG_NAME, initFlag, initList):
#VC: init which needs to happen before viz.go
if initFlag&vizconnect.INIT_PREVIZGO:
viz.setOption('viz.stereo', viz.QUAD_BUFFER)
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set the window for the display
_window = viz.MainWindow
#APG: constants, 5 total instances running...
FRONT_WALL_CLUSTER_CLIENT = viz.CLIENT1
LEFT_WALL_CLUSTER_CLIENT = viz.CLIENT2
RIGHT_WALL_CLUSTER_CLIENT = viz.CLIENT3
FLOOR_LEFT_CLUSTER_CLIENT = viz.CLIENT4
FLOOR_RIGHT_CLUSTER_CLIENT = viz.CLIENT5
#These are determined by testing the monitors
FRONT_WALL_MONITOR_ID = 1
LEFT_WALL_MONITOR_ID = 4
RIGHT_WALL_MONITOR_ID = 5
FLOOR_LEFT_MONITOR_ID = 3
FLOOR_RIGHT_MONITOR_ID = 2
#==============================================
#Cave calculations
#VC: create the raw object
# Create a cave object
import vizcave
cave = vizcave.Cave(stereo=viz.QUAD_BUFFER)
# get an origin node
originName = CAVE_CONFIG_NAME
initGroups(vizconnect.INIT_INDEPENDENT, [originName])# ensure it's been created
originNode = vizconnect.getGroup(originName).getNode3d()
frontImageWidth = 5.5372
imageHeight = 2.2225
imageRise = 0.0
originLeft = 3.5503
originRight = 3.5503
sideImageWidth = 2.9591
shiftRight = 0
shiftUp = 0
shiftForward = 0
# get the originLeft angle from the origin measurements
import math
aOR = math.pi/4.0
aAOR = (originRight**2 - originLeft**2 - frontImageWidth**2)/(-2*originLeft*frontImageWidth)
if abs(aAOR) <= 1:
aOR = math.acos(aAOR)
# convert the angle to front and right shifts
Sr = -(math.cos(aOR)*originLeft-frontImageWidth/2.0)
Sf = (math.sin(aOR)*originLeft-sideImageWidth/2.0)
# find left/right, up/down, front/back (x,y,z) extent of caves
R = frontImageWidth/2.0 + Sr + shiftRight # right
L = -frontImageWidth/2.0 + Sr +shiftRight # left
U = imageRise+imageHeight + shiftUp # up/top
D = imageRise + shiftUp # bottom/down
F = sideImageWidth/2.0 + Sf + shiftForward # front
B = -sideImageWidth/2.0 + Sf + shiftForward # back
# find corners
# e.g.
# Front Wall: C1,C2,C5,C6
# Left Wall: C0,C1,C4,C5
# Right Wall: C2,C3,C6,C7
C0 = L, U, B
C1 = L, U, F
C2 = R, U, F
C3 = R, U, B
C4 = L, D, B
C5 = L, D, F
C6 = R, D, F
C7 = R, D, B
C8 = L, D, 0
C9 = R, D, 0
C10 = -0.19939, D, F
C11 = 0.19939, D, F
C12 = -0.19939, D, 0
C13 = 0.19939, D, 0
# wall_list = [C0, C1, C2, C3, C4,
# C5, C6, C7, C8,
# C9, C10, C11, C12, C13]
#
# for item in wall_list:
# print(item)
#==============================================
WALL_CORNERS = "corners"
WALL_NAME = "name"
WALL_CLUSTER_ID = "cluster_id"
WALL_MONITOR_ID = "monitor_id"
#Creates wall, then adds it to the vizcave obj
def config_wall(wall_config, window):
points = wall_config[WALL_CORNERS]
cluster_client_id = wall_config[WALL_CLUSTER_ID]
monitor_id = wall_config[WALL_MONITOR_ID]
new_wall = vizcave.Wall(upperLeft = points[0],
upperRight = points[1],
lowerLeft = points[2],
lowerRight = points[3],
name = wall_config[WALL_NAME])
cave.addWall(new_wall, mask=cluster_client_id, window=window)
with viz.cluster.MaskedContext(cluster_client_id):
viz.window.setFullscreenMonitor(monitor_id)
_window.setStereoSwap(False)
viz.window.setFullscreen(True)
#Create front wall
#==================================
wall_config={}
wall_config[WALL_CORNERS] = [C1, C2, C5, C6]
wall_config[WALL_NAME] = "Front Wall"
wall_config[WALL_CLUSTER_ID] = FRONT_WALL_CLUSTER_CLIENT
wall_config[WALL_MONITOR_ID] = FRONT_WALL_MONITOR_ID
config_wall(wall_config, _window)
#Create right wall
#==================================
wall_config={}
wall_config[WALL_CORNERS] = [C2, C3, C6, C7]
wall_config[WALL_NAME] = "Right Wall"
wall_config[WALL_CLUSTER_ID] = RIGHT_WALL_CLUSTER_CLIENT
wall_config[WALL_MONITOR_ID] = RIGHT_WALL_MONITOR_ID
config_wall(wall_config, _window)
# #Create left wall
# #=================================
wall_config={}
wall_config[WALL_CORNERS] = [C0, C1, C4, C5]
wall_config[WALL_NAME] = "Left Wall"
wall_config[WALL_CLUSTER_ID] = LEFT_WALL_CLUSTER_CLIENT
wall_config[WALL_MONITOR_ID] = LEFT_WALL_MONITOR_ID
config_wall(wall_config, _window)
#Create floor_left
#==================================
wall_config={}
wall_config[WALL_CORNERS] = [C5, C11, C8, C13]
wall_config[WALL_NAME] = "Floor Left"
wall_config[WALL_CLUSTER_ID] = FLOOR_LEFT_CLUSTER_CLIENT
wall_config[WALL_MONITOR_ID] = FLOOR_LEFT_MONITOR_ID
config_wall(wall_config, _window)
#Create floor_right
#==================================
wall_config={}
wall_config[WALL_CORNERS] = [C10, C6, C12, C9]
wall_config[WALL_NAME] = "Floor Right"
wall_config[WALL_CLUSTER_ID] = FLOOR_RIGHT_CLUSTER_CLIENT
wall_config[WALL_MONITOR_ID] = FLOOR_RIGHT_MONITOR_ID
config_wall(wall_config, _window)
#==================================
# We need to pass an object which will be used to update the projection
# or the display to the view's position, typically this would be the
# node attached to an avatar's head tracker.
viewpoint = viz.addGroup()
cave.setTracker(viewpoint)
# Create a CaveView object for manipulating the entire cave environment.
# The caveView is a node that can be adjusted to move the entire
# cave around the virtual environment.
caveView = vizcave.CaveView(viewpoint)
_window.originLink = viz.link(originNode, caveView, dstFlag=viz.ABS_GLOBAL, srcFlag=viz.ABS_GLOBAL)
_window.caveView = caveView
_window.originNode = originNode
_window.displayNode = cave
_window.viewpointNode = viewpoint
rawDisplay[CAVE_CONFIG_NAME] = _window
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addDisplay(rawDisplay[CAVE_CONFIG_NAME], CAVE_CONFIG_NAME,
make='Generic', model='Cave Manual Configuration')
#VC: set the parent of the node
if initFlag&vizconnect.INIT_PARENTS:
vizconnect.getDisplay(CAVE_CONFIG_NAME).setParent(vizconnect.getAvatar('head_and_hand').getAttachmentPoint('head'))
#VC: set the name of the default
vizconnect.setDefault('display', 'cave_manual_configuration')
#VC: return values can be modified here
return None
#################################
# Tracker Code
#################################
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawTracker = vizconnect.getRawTrackerDict()
#VC: initialize a new tracker
_name = 'dtrack_head'
if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
vrpnName = 'DTrack'
ip = '192.168.5.160'
index = 1
#VC: create the raw object
vrpn7 = viz.add('vrpn7.dle')
rawTracker[_name] = vrpn7.addTracker(vrpnName+'@'+ip, index)
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addTracker(rawTracker[_name], _name, make='A.R.T.', model='DTrack')
#VC: init the offsets
if initFlag&vizconnect.INIT_OFFSETS:
_link = vizconnect.getTracker(_name).getLink()
#VC: clear link offsets
_link.reset(viz.RESET_OPERATORS)
#VC: reset orientation
_link.preEuler([0, 0, 0], target=viz.LINK_ORI_OP, priority=-20)
#VC: apply offsets
_link.postTrans([0, 0, -0.02])
#VC: initialize a new tracker
_name = 'dtrack_flystick'
if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
vrpnName = 'DTrack'
ip = '192.168.5.160'
index = 3
#VC: create the raw object
vrpn7 = viz.add('vrpn7.dle')
rawTracker[_name] = vrpn7.addTracker(vrpnName+'@'+ip, index)
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addTracker(rawTracker[_name], _name, make='A.R.T.', model='DTrack')
#VC: init the mappings for the wrapper
if initFlag&vizconnect.INIT_WRAPPER_MAPPINGS:
#VC: on-state mappings
if initFlag&vizconnect.INIT_MAPPINGS_ON_STATE:
vizconnect.getTracker(_name).setOnStateEventList([
vizconnect.onstate(lambda rawInput: rawInput['flystick'].isButtonDown(2), vizconnect.getTracker(_name).resetHeading),# make=ART, model=Flystick, name=flystick, signal=Button 2
])
#VC: set the name of the default
vizconnect.setDefault('tracker', 'dtrack_head')
#VC: return values can be modified here
return None
#################################
# Input Code
#################################
def initInputs(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawInput = vizconnect.getRawInputDict()
#VC: initialize a new input
_name = 'flystick'
if vizconnect.isPendingInit('input', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
hostname = '192.168.5.160'
#VC: create the raw object
from vizconnect.util.input import vrpn_joystick
sensor = vrpn_joystick.VRPNJoystick(basename='DTrack',hostname=hostname)
rawInput[_name] = sensor
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addInput(rawInput[_name], _name, make='ART', model='Flystick')
#VC: initialize a new input
_name = 'keyboard'
if vizconnect.isPendingInit('input', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
index = 0
#VC: create the raw object
d = viz.add('directinput.dle')
device = d.getKeyboardDevices()[index]
rawInput[_name] = d.addKeyboard(device)
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addInput(rawInput[_name], _name, make='Generic', model='Keyboard')
#VC: set the name of the default
vizconnect.setDefault('input', 'flystick')
#VC: return values can be modified here
return None
#################################
# Event Code
#################################
def initEvents(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawEvent = vizconnect.getRawEventDict()
#VC: return values can be modified here
return None
#################################
# Transport Code
#################################
def initTransports(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawTransport = vizconnect.getRawTransportDict()
#VC: initialize a new transport
_name = 'wandmagiccarpet'
if vizconnect.isPendingInit('transport', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
orientationTracker = None
debug = False
acceleration = 2
maxSpeed = 2
rotationAcceleration = 60
maxRotationSpeed = 65
autoBreakingDragCoef = 0.1
dragCoef = 0.0001
rotationAutoBreakingDragCoef = 0.2
rotationDragCoef = 0.0001
usingPhysics = False
parentedTracker = False
transportationGroup = None
#VC: create the raw object
from transportation import wand_magic_carpet
rawTransport[_name] = wand_magic_carpet.WandMagicCarpet( orientationTracker=orientationTracker,
debug=debug,
acceleration=acceleration,
maxSpeed=maxSpeed,
rotationAcceleration=rotationAcceleration,
maxRotationSpeed=maxRotationSpeed,
autoBreakingDragCoef=autoBreakingDragCoef,
dragCoef=dragCoef,
rotationAutoBreakingDragCoef=rotationAutoBreakingDragCoef,
rotationDragCoef=rotationDragCoef,
usingPhysics=usingPhysics,
parentedTracker=parentedTracker,
node=transportationGroup)
#VC: init the mappings for the raw object
if initFlag&vizconnect.INIT_MAPPINGS:
#VC: per frame mappings
if initFlag&vizconnect.INIT_MAPPINGS_PER_FRAME:
#VC: get the raw input dict so we have access to signals
import vizact
rawInput = vizconnect.getConfiguration().getRawDict('input')
#VC: set the update function which checks for input signals
def update(transport):
if rawInput['flystick'].getJoystickPosition()[1] > 0.05:# make=ART, model=Flystick, name=flystick, signal=Analog Down
transport.moveForward(mag=1.0)
if rawInput['keyboard'].isButtonDown(17):# make=Generic, model=Keyboard, name=keyboard, signal=Key W
transport.moveForward(mag=1)
if rawInput['flystick'].getJoystickPosition()[1] < -0.05:# make=ART, model=Flystick, name=flystick, signal=Analog Up
transport.moveBackward(mag=1.0)
if rawInput['keyboard'].isButtonDown(31):# make=Generic, model=Keyboard, name=keyboard, signal=Key S
transport.moveBackward(mag=1)
if rawInput['keyboard'].isButtonDown(30):# make=Generic, model=Keyboard, name=keyboard, signal=Key A
transport.moveLeft(mag=1)
if rawInput['keyboard'].isButtonDown(32):# make=Generic, model=Keyboard, name=keyboard, signal=Key D
transport.moveRight(mag=1)
# if rawInput['flystick'].isButtonDown(2):# make=ART, model=Flystick, name=flystick, signal=Button 2
# transport.moveUp(mag=1.0)
# if rawInput['flystick'].isButtonDown(1):# make=ART, model=Flystick, name=flystick, signal=Button 1
# transport.moveDown(mag=1.0)
if rawInput['flystick'].getJoystickPosition()[0] < -0.05:# make=ART, model=Flystick, name=flystick, signal=Analog Left
transport.turnLeft(mag=1.0)
if rawInput['flystick'].getJoystickPosition()[0] > 0.05:# make=ART, model=Flystick, name=flystick, signal=Analog Right
transport.turnRight(mag=1.0)
rawTransport[_name].setUpdateFunction(update)
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addTransport(rawTransport[_name], _name, make='Virtual', model='WandMagicCarpet')
#VC: set the name of the default
vizconnect.setDefault('transport', 'wandmagiccarpet')
#VC: return values can be modified here
return None
#################################
# Tool Code
#################################
def initTools(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawTool = vizconnect.getRawToolDict()
#VC: initialize a new tool
_name = 'grabber'
if vizconnect.isPendingInit('tool', _name, initFlag, initList):
#VC: init which needs to happen before viz.go
if initFlag&vizconnect.INIT_PREVIZGO:
viz.setOption('viz.display.stencil',1)
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: initialization code needed by the parameters
import tools
from tools import grabber
from tools import highlighter
#VC: set some parameters
usingPhysics = True
highlightMode = tools.highlighter.MODE_OUTLINE
placementMode = tools.placer.MODE_MID_AIR
#VC: create the raw object
rawTool[_name] = grabber.Grabber(usingPhysics=usingPhysics, usingSprings=usingPhysics, highlightMode=highlightMode, placementMode=placementMode, updatePriority=vizconnect.PRIORITY_ANIMATOR+3)
#VC: init the mappings for the raw object
if initFlag&vizconnect.INIT_MAPPINGS:
#VC: per frame mappings
if initFlag&vizconnect.INIT_MAPPINGS_PER_FRAME:
#VC: get the raw input dict so we have access to signals
import vizact
rawInput = vizconnect.getConfiguration().getRawDict('input')
#VC: set the update function which checks for input signals
def update(tool):
if rawInput['flystick'].isButtonDown(0):# make=ART, model=Flystick, name=flystick, signal=Button 0
tool.grabAndHold()
rawTool[_name].setUpdateFunction(update)
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addTool(rawTool[_name], _name, make='Virtual', model='Grabber')
#VC: set the parent of the node
if initFlag&vizconnect.INIT_PARENTS:
vizconnect.getTool(_name).setParent(vizconnect.getAvatar('head_and_hand').getAttachmentPoint('r_hand'))
#VC: initialize a new tool
_name = 'laser_pointer'
if vizconnect.isPendingInit('tool', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
displayDistance = True
#VC: create the raw object
from tools import laser_pointer
rawTool[_name] = laser_pointer.LaserPointer(displayDistance=displayDistance, updatePriority=vizconnect.PRIORITY_ANIMATOR+3)
#VC: init the mappings for the raw object
if initFlag&vizconnect.INIT_MAPPINGS:
#VC: per frame mappings
if initFlag&vizconnect.INIT_MAPPINGS_PER_FRAME:
#VC: get the raw input dict so we have access to signals
import vizact
rawInput = vizconnect.getConfiguration().getRawDict('input')
#VC: set the update function which checks for input signals
def update(tool):
if rawInput['flystick'].isButtonDown(5):# make=ART, model=Flystick, name=flystick, signal=Button 5
tool.shoot()
rawTool[_name].setUpdateFunction(update)
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addTool(rawTool[_name], _name, make='Virtual', model='Laser Pointer')
#VC: set the parent of the node
if initFlag&vizconnect.INIT_PARENTS:
vizconnect.getTool(_name).setParent(vizconnect.getAvatar('head_and_hand').getAttachmentPoint('r_hand'))
#VC: set the name of the default
vizconnect.setDefault('tool', 'grabber')
#VC: return values can be modified here
return None
#################################
# Avatar Code
#################################
def initAvatars(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
#VC: place any general initialization code here
rawAvatar = vizconnect.getRawAvatarDict()
#VC: initialize a new avatar
_name = 'head_and_hand'
if vizconnect.isPendingInit('avatar', _name, initFlag, initList):
#VC: init the raw object
if initFlag&vizconnect.INIT_RAW:
#VC: set some parameters
# rightHandFilename = 'glove.cfg'
rightHandFilename = ''
leftHandFilename = ''
#VC: create the raw object
# base avatar
avatar = viz.addGroup()
avatar._bodyPartDict = {}
avatar._handModelDict = {}
# head
head = viz.addGroup()
head.setParent(avatar)
avatar._bodyPartDict[vizconnect.AVATAR_HEAD] = head
# left hand
if leftHandFilename:
leftHand = avatar.add(leftHandFilename)
avatar.leftHandFilename = leftHandFilename
else:
leftHand = viz.addGroup()
avatar.leftHandFilename = None
leftHand.setParent(avatar)
avatar._bodyPartDict[vizconnect.AVATAR_L_HAND] = leftHand
# right hand
if rightHandFilename:
rightHand = avatar.add(rightHandFilename)
avatar.rightHandFilename = rightHandFilename
else:
rightHand = viz.addGroup()
avatar.rightHandFilename = None
rightHand.setParent(avatar)
avatar._bodyPartDict[vizconnect.AVATAR_R_HAND] = rightHand
# done
rawAvatar[_name] = avatar
#VC: init the wrapper (DO NOT EDIT)
if initFlag&vizconnect.INIT_WRAPPERS:
vizconnect.addAvatar(rawAvatar[_name], _name, make='Generic', model='Head and Hand')
#VC: init the gestures
if initFlag&vizconnect.INIT_GESTURES:
#VC: need to get the raw input dict so we have access to signals
import vizact
rawInput = vizconnect.getConfiguration().getRawDict('input')
#VC: gestures for the avatar's r_hand
import hand
# remove the old hand
rightHand = rawAvatar[_name]._bodyPartDict[vizconnect.AVATAR_R_HAND]
if rightHand:
rightHand.remove()
# add a new hand
def initHand():
sensor = hand.InputSensor()
rawAvatar[_name].handSensor = sensor
sensor.createHandRenderer = lambda *args,**kw: hand._InputDeviceRenderer(*args,**kw)
def appliedGetData():
#VC: set the mappings for the gestures
if rawInput['flystick'].isButtonDown(0):# make=ART, model=Flystick, name=flystick, signal=Button 0
return (hand.GESTURE_FIST, False, False)# GESTURE_FIST
#VC: end gesture mappings
return (hand.GESTURE_FLAT_HAND,False,False)
sensor.getData = appliedGetData
file=None
if hasattr(rawAvatar[_name], "rightHandFilename"):
file = rawAvatar[_name].rightHandFilename
return hand.HandModel(left=False, type=hand.GLOVE_5DT, file=file, sensor=sensor)
rightHand = initHand()
rightHand.setParent(rawAvatar[_name])
rawAvatar[_name]._bodyPartDict[vizconnect.AVATAR_R_HAND] = rightHand
rawAvatar[_name]._handModelDict[vizconnect.AVATAR_R_HAND] = rightHand
#VC: gestures may change the raw avatar, so refresh the raw in the wrapper
vizconnect.getAvatar(_name).setRaw(rawAvatar[_name])
#VC: init the animator
if initFlag&vizconnect.INIT_ANIMATOR:
# need to get the raw tracker dict for animating the avatars
from vizconnect.util.avatar import animator
from vizconnect.util.avatar import skeleton
# get the skeleton from the avatar
_skeleton = skeleton.Disembodied(rawAvatar[_name])
#VC: set which trackers animate which body part
# format is: bone: (tracker, parent, degrees of freedom used)
_trackerAssignmentDict = {
vizconnect.AVATAR_HEAD:(vizconnect.getTracker('dtrack_head').getNode3d(), None, vizconnect.DOF_6DOF),
vizconnect.AVATAR_R_HAND:(vizconnect.getTracker('dtrack_flystick').getNode3d(), None, vizconnect.DOF_6DOF),
}
#VC: create the raw object
_rawAnimator = animator.Disembodied(rawAvatar[_name], _skeleton, _trackerAssignmentDict)
#VC: set animator in wrapper (DO NOT EDIT)
vizconnect.getAvatar(_name).setAnimator(_rawAnimator, make='Virtual', model='Disembodied')
#VC: set the parent of the node
if initFlag&vizconnect.INIT_PARENTS:
vizconnect.getAvatar(_name).setParent(vizconnect.getGroup('cave_manual_configuration'))
#VC: set the name of the default
vizconnect.setDefault('avatar', 'head_and_hand')
#VC: return values can be modified here
return None
#################################
# Application Settings
#################################
def initSettings():
#VC: apply general application settings
viz.mouse.setTrap(False)
viz.mouse.setVisible(viz.MOUSE_AUTO_HIDE)
vizconnect.setMouseTrapToggleKey('')
#VC: return values can be modified here
return None
#################################
# Post-initialization Code
#################################
def postInit():
"""Add any code here which should be called after all of the initialization of this configuration is complete.
Returned values can be obtained by calling getPostInitResult for this file's vizconnect.Configuration instance."""
vizconnect.getTracker('dtrack_head').getRaw().swapPos([1,2,-3])
vizconnect.getTracker('dtrack_head').getRaw().swapQuat([-1,-2,3,4])
vizconnect.getTracker('dtrack_flystick').getRaw().swapPos([1,2,-3])
vizconnect.getTracker('dtrack_flystick').getRaw().swapQuat([-1,-2,3,4])
return None
#################################
# Stand alone configuration
#################################
def initInterface():
#VC: start the interface
vizconnect.interface.go(__file__,
live=True,
openBrowserWindow=True,
startingInterface=vizconnect.interface.INTERFACE_ADVANCED)
#VC: return values can be modified here
return None
###############################################
if __name__ == "__main__":
initInterface()
viz.add('piazza.osgb')
viz.add('piazza_animations.osgb')