forked from simonnagel/VRED-VR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VRED-VR-move.py
714 lines (552 loc) · 35.1 KB
/
VRED-VR-move.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
'''
DISCLAIMER:
---------------------------------
In any case, all binaries, configuration code, templates and snippets of this solution are of "work in progress" character.
This also applies to GitHub "Release" versions.
Neither Simon Nagel, nor Autodesk represents that these samples are reliable, accurate, complete, or otherwise valid.
Accordingly, those configuration samples are provided ?as is? with no warranty of any kind and you use the applications at your own risk.
Scripted by Rutvik Bhatt, supported by Simon Nagel
First download and copy the osb file "VRControllerMove" provided in the GitHub repository into "C:\Users\USERNAME\Documents\Autodesk\Automotive\VRED" path in order to use the dedicated Move controller.
If you do not wish to use the dedicated controller you can skip this part.
Add all the nodes that you want to move in a tag named "Movable".
Just paste the Scene in the Script Editor of VRED and press run.
Turn on the OpenVR and press the menu button on the controller.
Press the 'Move' tools menu in the menu.
Press the trigger and point it to the object that you want to move freely, keep the trigger pressed and move the object
Release the trigger to put the object to the desired place
Press the Left Touch pad button to undo
Press the Right Touch pad button to redo
Press the Up Touch pad button to reset the scene (Note: The objects will be placed at their original positon)
This script works in VRED Collaboration.
Please make sure that, the Script is executed on each computer of each participant.
'''
import os
import math
from PySide2 import QtCore, QtGui
def roundup(x):
return int(math.ceil(x / 15.0)) * 15
moveController = 0
moveControllerFound = False
mainCustomFuncGroup = False
allMoveNodes = getAllNodes()
for node in allMoveNodes:
allMoveNodesName = node.getName()
if allMoveNodesName == "VRController_Move":
moveController+=1
elif allMoveNodesName == 'VRED-VR-Custom-Fucntion':
mainCustomFuncGroup = True
customFunctionsGroup = node
if moveController == 0:
myDocuments = os.path.join(os.path.join(os.environ['USERPROFILE']),'Documents')
filepath = myDocuments +"\Autodesk\Automotive\VRED"
filename = "\VRControllerMove"
if os.path.exists(filepath+str(filename)+".osb"):
node = loadGeometry(filepath +str(filename)+".osb")
node.setName("VRControllerMove")
moveControllerFound = True
else:
print("file doesnt exist")
moveControllerFound = False
else:
moveControllerFound = True
if not mainCustomFuncGroup:
customFunctionsGroup = createNode('Group', 'VRED-VR-Custom-Fucntion')
allFucnNames = ["VRControllerMove", "VRControllerSelect", "VRControllerNotes",
"VRControllerDraw", "VRControllerNotes_Notes", "Cloned_ref_obj",
"D_Tool", "D_Lines", "D_tempLine", "Group_html"]
allNodeFuncname = getAllNodes()
for node in allNodeFuncname:
nodeName = node.getName()
if nodeName in allFucnNames:
addChilds(customFunctionsGroup, [node])
class RenderActionMove(vrInteraction):
def __init__(self):
vrInteraction.__init__(self)
#ObjectMover.__init__(self)
self.addRender()
def preRender(self):
move.constraintCheckFunction()
class ObjectMover():
def __init__(self):
self.isEnabled = False
#RenderAction.__init__(self)
self.moverEnabled = False
self.createMenu()
self.node = None
self.undo_list = []
self.position_list = []
self.redo_list = []
self.all_nodes = []
self.resetflag = False
nodes = getAllNodes()
self.last_pos_node = []
self.startMoveFlag = False
self.snapping = False
self.timer = vrTimer()
for node in nodes:
if hasNodeTag(node, 'Movable'):
node_translation = getTransformNodeTranslation(node, True)
node_rotation = getTransformNodeRotation(node)
self.all_nodes.append([node, node_translation, node_rotation])
self.leftController = vrDeviceService.getVRDevice("left-controller")
self.rightController = vrDeviceService.getVRDevice("right-controller")
self.leftController.setVisualizationMode(Visualization_ControllerAndHand)
self.rightController.setVisualizationMode(Visualization_ControllerAndHand)
vrImmersiveInteractionService.setDefaultInteractionsActive(1)
padCenter = vrdVirtualTouchpadButton('padcenter', 0.0, 0.5, 0.0, 360.0)
padUpperLeft = vrdVirtualTouchpadButton('padupleft', 0.5, 1.0, 270.0, 330.0)
padLowerLeft = vrdVirtualTouchpadButton('paddownleft', 0.5, 1.0, 210.0, 270.0)
padUp = vrdVirtualTouchpadButton('padup', 0.5, 1.0, 330.0, 30.0)
padUpperRight = vrdVirtualTouchpadButton('padupright', 0.5, 1.0, 30.0, 90.0)
padLowerRight = vrdVirtualTouchpadButton('paddownright', 0.5, 1.0, 90.0, 150.0)
padDown = vrdVirtualTouchpadButton('paddown', 0.5, 1.0, 150.0, 210.0)
# right controller
self.rightController.addVirtualButton(padCenter, 'touchpad')
self.rightController.addVirtualButton(padUpperLeft, 'touchpad')
self.rightController.addVirtualButton(padLowerLeft, 'touchpad')
self.rightController.addVirtualButton(padUp, 'touchpad')
self.rightController.addVirtualButton(padUpperRight, 'touchpad')
self.rightController.addVirtualButton(padLowerRight, 'touchpad')
self.rightController.addVirtualButton(padDown, 'touchpad')
multiButtonPadMove = vrDeviceService.createInteraction("MultiButtonPadMove")
multiButtonPadMove.setSupportedInteractionGroups(["MoveGroup"])
toolsMenuNotes = vrDeviceService.getInteraction("Tools Menu")
toolsMenuNotes.addSupportedInteractionGroup("MoveGroup")
#setting control action for right controller Pad
self.leftUpperActionMove = multiButtonPadMove.createControllerAction("right-padupleft-pressed")
self.leftDownActionMove = multiButtonPadMove.createControllerAction("right-paddownleft-pressed")
self.upActionMove = multiButtonPadMove.createControllerAction("right-padup-pressed")
self.downActionMove = multiButtonPadMove.createControllerAction("right-paddown-pressed")
self.rightUpperActionMove = multiButtonPadMove.createControllerAction("right-padupright-pressed")
self.rightDownActionMove = multiButtonPadMove.createControllerAction("right-paddownright-pressed")
self.centerActionMove = multiButtonPadMove.createControllerAction("right-padcenter-pressed")
teleport = vrDeviceService.getInteraction("Teleport")
teleport.addSupportedInteractionGroup("MoveGroup")
teleport.setControllerActionMapping("prepare" , "left-touchpad-touched")
teleport.setControllerActionMapping("abort" , "left-touchpad-untouched")
teleport.setControllerActionMapping("execute" , "left-touchpad-pressed")
self.pointer = vrDeviceService.getInteraction("Pointer")
self.pointer.addSupportedInteractionGroup("MoveGroup")
def constraintCheckFunction(self):
global constXPressed
global constYPressed
global constZPressed
#global startMoveFlag
global device
if self.startMoveFlag == True and not self.node == None:
self.currentNodePos = getTransformNodeTranslation(self.node,1)
self.currentNodeRot = getTransformNodeRotation(self.node)
if constXPressed == True and constYPressed == True:
x_y_translation = "%f,%f,%f" %(self.currentNodePos.x(), self.currentNodePos.y(),self.originalNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+x_y_translation+', True)')
x_y_rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+x_y_rotation+')')
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.currentNodePos.x(), self.currentNodePos.y(),self.originalNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constYPressed == True and constZPressed == True:
y_z_translation = "%f,%f,%f" %(self.originalNodePos.x(), self.currentNodePos.y(),self.currentNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+y_z_translation+', True)')
y_z_rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+y_z_rotation+')')
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.originalNodePos.x(), self.currentNodePos.y(),self.currentNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constXPressed == True and constZPressed == True:
x_z_translation = "%f,%f,%f" %(self.currentNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+x_z_translation+', True)')
x_z_rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+x_z_rotation+')')
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.currentNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constXPressed == True:
x_translation = "%f,%f,%f" %(self.currentNodePos.x(), self.originalNodePos.y(),self.originalNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+x_translation+', True)')
x_rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+x_rotation+')')
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.currentNodePos.x(), self.originalNodePos.y(),self.originalNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constYPressed == True:
y_translation = "%f,%f,%f" %(self.originalNodePos.x(), self.currentNodePos.y(),self.originalNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+y_translation+', True)')
y_rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+y_rotation+')')
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.originalNodePos.x(), self.currentNodePos.y(),self.originalNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constZPressed == True:
z_translation = "%f,%f,%f" %(self.originalNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+z_translation+', True)')
z_rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+z_rotation+')')
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.originalNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif self.snapping == True:
self.currentNodeRot = getTransformNodeRotation(self.node)
self.x = roundup(self.currentNodeRot.x())
self.y = roundup(self.currentNodeRot.y())
self.z = roundup(self.currentNodeRot.z())
snap_rotation = "%f,%f,%f" %(self.x,self.y,self.z)
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+snap_rotation+')')
self.newRot = setTransformNodeRotation(self.node,self.x,self.y,self.z)
translation = "%f,%f,%f" %(self.currentNodePos.x(), self.currentNodePos.y(),self.currentNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+translation+', True)')
else:
translation = "%f,%f,%f" %(self.currentNodePos.x(), self.currentNodePos.y(),self.currentNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+translation+', True)')
rotation = "%f,%f,%f" %(self.currentNodeRot.x(),self.currentNodeRot.y(),self.currentNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+rotation+')')
def startMove(self,action,device):
global constXPressed
global constYPressed
global constZPressed
#global startMove
self.node = self.getMovable(device.pick().getNode())
if not self.node.isNull():
self.originalNodeRot = getTransformNodeRotation(self.node)
if constXPressed == True or constYPressed == True or constZPressed == True:
#self.snapping = True
self.constraint = vrConstraintService.createParentConstraint([device.getNode()],self.node,True)
mypath = getUniquePath(self.node)
nameString = "%s" %mypath
vrSessionService.sendPython('"'+nameString+'"')
vrSessionService.sendPython('nodeRef = findUniquePath("'+nameString+'")')
#nameString = "%s" % self.node.getName()
#vrSessionService.sendPython('nodeRef = findNode("'+nameString+'")')
else:
self.constraint = vrConstraintService.createParentConstraint([device.getNode()],self.node,True)
#vrSessionService.addNodeSync(self.node)
self.originalNodePos = getTransformNodeTranslation(self.node,1)
self.startMoveFlag = True
mypath = getUniquePath(self.node)
nameString = "%s" %mypath
vrSessionService.sendPython('"'+nameString+'"')
vrSessionService.sendPython('nodeRef = findUniquePath("'+nameString+'")')
#nameString = "%s" % self.node.getName()
#vrSessionService.sendPython('nodeRef = findNode("'+nameString+'")')
def stopMove(self,action,device):
#global startMoveFlag
global constXPressed
global constYPressed
global constZPressed
if not self.node == None and not self.node.isNull():
self.finalNodePos = getTransformNodeTranslation(self.node,1)
self.finalNodeRot = getTransformNodeRotation(self.node)
print("outsside")
if constXPressed == True and constYPressed == True:
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.currentNodePos.x(), self.currentNodePos.y(),self.originalNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constYPressed == True and constZPressed == True:
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.originalNodePos.x(), self.currentNodePos.y(),self.currentNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constXPressed == True and constZPressed == True:
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.currentNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constXPressed == True:
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.currentNodePos.x(), self.originalNodePos.y(),self.originalNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constYPressed == True:
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.originalNodePos.x(), self.currentNodePos.y(),self.originalNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
elif constZPressed == True:
self.afterconstraintPos = setTransformNodeTranslation(self.node,self.originalNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z(),1)
self.afterconstraintRot = setTransformNodeRotation(self.node,self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
print("insidie z ")
elif self.snapping == True:
self.currentNodeRot = getTransformNodeRotation(self.node)
self.x = roundup(self.currentNodeRot.x())
self.y = roundup(self.currentNodeRot.y())
self.z = roundup(self.currentNodeRot.z())
snap_rotation = "%f,%f,%f" %(self.x,self.y,self.z)
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+snap_rotation+')')
self.newRot = setTransformNodeRotation(self.node,self.x,self.y,self.z)
print("insside snapping true")
else:
finalTranslation = "%f,%f,%f" %(self.finalNodePos.x(), self.finalNodePos.y(),self.finalNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+finalTranslation+', True)')
finalRotation = "%f,%f,%f" %(self.finalNodeRot.x(),self.finalNodeRot.y(),self.finalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+finalRotation+')')
vrConstraintService.deleteConstraint(self.constraint)
self.startMoveFlag = False
'''
elif self.snapping == True:
self.newRot = setTransformNodeRotation(self.node,self.x,self.y,self.z)
#vrSessionService.removeNodeSync(self.node)
else:
translation = "%f,%f,%f" %(self.originalNodePos.x(), self.originalNodePos.y(),self.currentNodePos.z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+translation+', True)')
rotation = "%f,%f,%f" %(self.originalNodeRot.x(),self.originalNodeRot.y(),self.originalNodeRot.z())
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+rotation+')')
'''
def createMenu(self):
myDocuments = os.path.join(os.path.join(os.environ['USERPROFILE']),'Documents')
filepath = myDocuments +"\Autodesk\Automotive\VRED"
filename = "\objectMoveOn.png"
icon = QtGui.QIcon()
icon.addFile(filepath+filename,QtCore.QSize(),QtGui.QIcon.Mode.Normal,QtGui.QIcon.State.On)
myDocuments_second = os.path.join(os.path.join(os.environ['USERPROFILE']),'Documents')
filepath_second = myDocuments_second +"\Autodesk\Automotive\VRED"
filename_second = "\objectMoveOff.png"
icon.addFile(filepath_second+filename_second,QtCore.QSize(),QtGui.QIcon.Mode.Normal,QtGui.QIcon.State.Off)
self.tool = vrImmersiveUiService.createTool("Tool_move")
self.tool.setText("Move")
self.tool.setCheckable(True)
self.tool.setIcon(icon)
self.tool.signal().checked.connect(self.moveEnable)
self.tool.signal().unchecked.connect(self.moveDisable)
def deleteMenu(self):
vrImmersiveUiService.deleteTool(self.tool)
def moveEnable(self):
global constXPressed
global constYPressed
global constZPressed
global moveControllerFound
constXPressed = False
constYPressed = False
constZPressed = False
allTools = vrImmersiveUiService.getTools()
for tool in allTools:
if tool.getIsInternal() == False and tool.getName() != self.tool.getName() and tool.getName()[:5] == 'Tool_':
tool.setChecked(False)
tool.signal().unchecked.emit(None)
print("Entering Move Enabled")
self.isEnabled = True
vrDeviceService.setActiveInteractionGroup("MoveGroup")
self.leftUpperActionMove.signal().triggered.connect(self.undo)
self.leftDownActionMove.signal().triggered.connect(self.constX)
self.upActionMove.signal().triggered.connect(self.reset)
self.downActionMove.signal().triggered.connect(self.constY)
self.rightUpperActionMove.signal().triggered.connect(self.redo)
self.rightDownActionMove.signal().triggered.connect(self.constZ)
self.centerActionMove.signal().triggered.connect(self.constDeactive)
nodes = getAllNodes()
for node in nodes:
if hasNodeTag(node, 'Movable'):
if node.getName() not in [element[0].getName() for element in self.all_nodes]:
#print('For node inside', node.getName(), [element[0].getName() for element in self.all_nodes])
#print('Before appending, ', len(self.all_nodes), [element[0].getName() for element in self.all_nodes])
#print('new node made movable', node.getName())
node_translation = getTransformNodeTranslation(node, True)
node_rotation = getTransformNodeRotation(node)
self.all_nodes.append([node, node_translation, node_rotation])
#print('After appending', len(self.all_nodes), [element[0].getName() for element in self.all_nodes])
if not self.moverEnabled:
start = self.pointer.getControllerAction("start")
start.signal().triggered.connect(self.startMove)
execute = self.pointer.getControllerAction("execute")
execute.signal().triggered.connect(self.stopMove)
self.moverEnabled = True
if moveControllerFound == True:
self.newRightCon = findNode("VRController_Move")
self.rightController.setVisible(0)
self.newRightCon.setActive(1)
controllerPos = getTransformNodeTranslation(self.rightController.getNode(),1)
setTransformNodeTranslation(self.newRightCon, controllerPos.x(), controllerPos.y(), controllerPos.z(), True)
self.MoveControllerConstraint = vrConstraintService.createParentConstraint([self.rightController.getNode()], self.newRightCon, False)
else:
self.rightController.setVisible(1)
self.timer.setActive(0)
def moveDisable(self):
global moveControllerFound
global constXPressed
global constYPressed
global constZPressed
if self.isEnabled == False:
print("move was not enabled before " )
return
allTools = vrImmersiveUiService.getTools()
for tool in allTools:
if tool.getIsInternal() == False and tool.getName() != self.tool.getName():
tool.setCheckable(True)
#tool.setChecked(False)
print("Move Disabled")
self.isEnabled = False
vrDeviceService.setActiveInteractionGroup("Locomotion")
self.leftUpperActionMove.signal().triggered.disconnect(self.undo)
self.leftDownActionMove.signal().triggered.disconnect(self.constX)
self.upActionMove.signal().triggered.disconnect(self.reset)
self.downActionMove.signal().triggered.disconnect(self.constY)
self.rightUpperActionMove.signal().triggered.disconnect(self.redo)
self.rightDownActionMove.signal().triggered.disconnect(self.constZ)
self.centerActionMove.signal().triggered.disconnect(self.constDeactive)
if self.moverEnabled:
start = self.pointer.getControllerAction("start")
start.signal().triggered.disconnect(self.startMove)
execute = self.pointer.getControllerAction("execute")
execute.signal().triggered.disconnect(self.stopMove)
self.moverEnabled = False
self.rightController.setVisible(1)
if moveControllerFound == True:
self.newRightCon.setActive(0)
vrConstraintService.deleteConstraint(self.MoveControllerConstraint)
setSwitchMaterialChoice("C_M_Icon_X", 0)
setSwitchMaterialChoice("C_M_Icon_Y", 0)
setSwitchMaterialChoice("C_M_Icon_Z", 0)
print("Constraint deactivated")
constXPressed = False
constYPressed = False
constZPressed = False
self.timer.setActive(0)
constraints = vrConstraintService.getConstraints()
for constraint in constraints:
vrConstraintService.deleteConstraint(constraint)
#for node in self.all_nodes:
#print('Node inside all_nodes: ', node[0].getName())
#print('length of all_nodes: ', len(self.all_nodes))
def getMovable(self,node):
while not node.isNull():
x = node.getName()
if hasNodeTag(node, 'Movable'):
current_position = getTransformNodeTranslation(node, True)
current_rotation = getTransformNodeRotation(node)
self.undo_list.append([node, current_position, current_rotation])
return node
if(node.getName() == "Group" or node.getName() =="Transform"):
break
node = node.getParent()
return node
def undo(self):
for i in self.undo_list:
print(i[0].getName())
print(i[1])
if self.resetflag is True:
for i in self.last_pos_node:
mypath = getUniquePath(i[0])
nameString = "%s" %mypath
vrSessionService.sendPython('"'+nameString+'"')
vrSessionService.sendPython('nodeRef = findUniquePath("'+nameString+'")')
#nameString = "%s" % i[0].getName()
#vrSessionService.sendPython('nodeRef = findNode("'+nameString+'")')
i_translation = "%f,%f,%f" %(i[1].x(), i[1].y(), i[1].z())
i_rotation = "%f,%f,%f" %(i[2].x(), i[2].y(), i[2].z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+i_translation+', True)')
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+i_rotation+')')
self.resetflag = False
del(self.last_pos_node[:])
return
if not len(self.undo_list) == 0:
x = self.undo_list[-1]
mypath = getUniquePath(x[0])
nameString = "%s" %mypath
vrSessionService.sendPython('"'+nameString+'"')
vrSessionService.sendPython('nodeRef = findUniquePath("'+nameString+'")')
#nameString = "%s" % x[0].getName()
#vrSessionService.sendPython('nodeRef = findNode("'+nameString+'")')
x_translation = "%f,%f,%f" %(x[1].x(), x[1].y(), x[1].z())
x_rotation = "%f,%f,%f" %(x[2].x(), x[2].y(), x[2].z())
current_position = getTransformNodeTranslation(x[0], True)
current_rotation = getTransformNodeRotation(x[0])
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+x_translation+', True)')
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+x_rotation+')')
self.redo_list.append([x[0], current_position, current_rotation])
del(self.undo_list[-1])
print("UNDO")
def redo(self):
for i in self.redo_list:
print(i[0].getName())
print(i[1])
if not len(self.redo_list) == 0:
x = self.redo_list[-1]
#print(x)
mypath = getUniquePath(x[0])
nameString = "%s" %mypath
vrSessionService.sendPython('"'+nameString+'"')
vrSessionService.sendPython('nodeRef = findUniquePath("'+nameString+'")')
#nameString = "%s" % x[0].getName()
#vrSessionService.sendPython('nodeRef = findNode("'+nameString+'")')
x_translation = "%f,%f,%f" %(x[1].x(), x[1].y(), x[1].z())
x_rotation = "%f,%f,%f" %(x[2].x(), x[2].y(), x[2].z())
current_position = getTransformNodeTranslation(x[0], True)
current_rotation = getTransformNodeRotation(x[0])
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+x_translation+', True)')
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+x_rotation+')')
self.undo_list.append([x[0], current_position, current_rotation])
del(self.redo_list[-1])
print("REDO")
def reset(self):
last_pos = getAllNodes()
for node in last_pos:
if hasNodeTag(node, 'Movable'):
node_last_pos = getTransformNodeTranslation(node, True)
node_last_rot = getTransformNodeRotation(node)
self.last_pos_node.append([node, node_last_pos, node_last_rot])
print('recording the last pos of ', node.getName())
for i in self.all_nodes:
mypath = getUniquePath(i[0])
nameString = "%s" %mypath
vrSessionService.sendPython('"'+nameString+'"')
vrSessionService.sendPython('nodeRef = findUniquePath("'+nameString+'")')
#nameString = "%s" % i[0].getName()
#vrSessionService.sendPython('nodeRef = findNode("'+nameString+'")')
i_translation = "%f,%f,%f" %(i[1].x(), i[1].y(), i[1].z())
i_rotation = "%f,%f,%f" %(i[2].x(), i[2].y(), i[2].z())
vrSessionService.sendPython('setTransformNodeTranslation(nodeRef, '+i_translation+', True)')
vrSessionService.sendPython('setTransformNodeRotation(nodeRef, '+i_rotation+')')
#print('this node is in all node list ', i[0].getName())
#del(self.undo_list[:])
#del(self.redo_list[:])
self.resetflag = True
print('Reset button down touchpad pressed')
def constX(self):
print("Constraint in X direction Active")
global constXPressed
if constXPressed == False:
constXPressed = True
print("flag X pressed is: ", constXPressed)
self.moveXConstraintON()
else:
constXPressed = False
print("flag X pressed is: ", constXPressed)
self.moveXConstraintOFF()
def constY(self):
global constYPressed
print("Constraint in Y direction Active")
if constYPressed == False:
constYPressed = True
print("flag Y pressed is: ", constYPressed)
self.moveYConstraintON()
else:
constYPressed = False
print("flag Y pressed is: ", constYPressed)
self.moveYConstraintOFF()
def constZ(self):
global constZPressed
print("Constraint in Z direction Active")
if constZPressed == False:
constZPressed = True
print("flag Z pressed is: ", constZPressed)
self.moveZConstraintON()
else:
constZPressed = False
print("flag Z pressed is: ", constZPressed)
self.moveZConstraintOFF()
def constDeactive(self):
if self.snapping == True:
self.snapping = False
self.moveIconFree()
else:
self.snapping = True
self.moveIconSnap()
def moveXConstraintON(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_X", 1)
def moveXConstraintOFF(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_X", 0)
def moveYConstraintON(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_Y", 1)
def moveYConstraintOFF(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_Y", 0)
def moveZConstraintON(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_Z", 1)
def moveZConstraintOFF(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_Z", 0)
def moveIconFree(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_Move", 0)
def moveIconSnap(self):
if moveControllerFound == True:
setSwitchMaterialChoice("C_M_Icon_Move", 1)
move = ObjectMover()
render_move = RenderActionMove()