- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I had this script working but it stopped and I can't get it running again even when running older versions that used to work. It seems to be unpredictable. This script adds custom interactions to the controller that let you do things like press the menu button to aim a pointer or move the touchpad around to move a node in the scene. I run VR_ENABLE and VR_DISABLE through variant sets.
VR_DISABLE script is just:
setDisplayMode(VR_DISPLAY_STANDARD)
VR_ENABLE script is (I'll attach the file as well for better viewing):
# Enables VR and setups up the exterior mover/custom interactions
DISPLAY_MODE = VR_DISPLAY_OPEN_VR #Display modes: VR_DISPLAY_STANDARD, VR_DISPLAY_OCULUS_RIFT, VR_DISPLAY_SONY_10BIT, VR_DISPLAY_SIM2_HDR, VR_DISPLAY_OPEN_VR,VR_DISPLAY_VRHERO_XTAL, VR_DISPLAY_VARJO, VR_DISPLAY_HDR10
class Iterator:
iterator1 = 0
iterator2 = 0
class Mover:
#Constants:
MOVE_SPEED = 20
ROTATE_SPEED = 0.5
INTERIOR = False
EXTERIOR = True
Mode=EXTERIOR #Set the starting mode
def __init__(self):
self.moveNode = vrNodeService.findNode('TruckMover')
self.Mode = self.EXTERIOR
def translate(self, speed, dirVector):
if self.Mode == self.EXTERIOR:
current = self.moveNode.getWorldTranslation()
dist = speed * self.MOVE_SPEED
newX = current.x() - dirVector.x() * dist
newY = current.y() - dirVector.y() * dist
self.moveNode.setTranslation(QVector3D(newX, newY, current.z()))
def rotate(self, speed):
if self.Mode == self.EXTERIOR:
current = self.moveNode.getRotationAsEuler()
newZ = current.z() - speed * self.ROTATE_SPEED
self.moveNode.setRotationAsEuler(QVector3D(0, 0, newZ))
def setExteriorMode(self):
self.Mode = self.EXTERIOR
def setInteriorMode(self):
self.Mode = self.INTERIOR
self.moveNode.setTranslation(QVector3D(0, 0, 0))
self.moveNode.setRotationAsEuler(QVector3D(0, 0, 0))
def triggerSensor(self, node):
print("here")
if node.hasAttachment("TouchSensorAttachment"):
touchAttachment = node.getAttachment("TouchSensorAttachment")
acc = vrFieldAccess(touchAttachment)
if acc.isValid():
variantSetName = acc.getMString("variantSets")
for vset in variantSetName:
selectVariantSet(vset)
else:
parentNode = node.getParent()
if parentNode.isValid():
triggerSensor(parentNode)
class MyCustomInteraction:
def __init__(self):
# Create new interaction
self.customInteraction = vrDeviceService.createInteraction("CustomInteraction")
# Limit the interaction to a new mode to not interfere with other interactions
self.customInteraction.setSupportedInteractionGroups(["CustomGroup"])
# Create action objects that a triggered by some input
self.leftTriggerAction = self.customInteraction.createControllerAction("left-trigger-pressed")
self.rightTriggerAction = self.customInteraction.createControllerAction("right-trigger-released")
self.leftTouchpadPressedAction = self.customInteraction.createControllerAction("left-touchpad-pressed")
self.rightTouchpadPressedAction = self.customInteraction.createControllerAction("right-touchpad-pressed")
self.leftTouchpadReleasedAction = self.customInteraction.createControllerAction("left-touchpad-released")
self.rightTouchpadReleasedAction = self.customInteraction.createControllerAction("right-touchpad-released")
self.menuPressedAction = self.customInteraction.createControllerAction("any-menu-pressed")
self.menuReleasedAction = self.customInteraction.createControllerAction("any-menu-released")
# Connect these actions to the actual python functions
self.leftTriggerAction.signal().triggered.connect(self.leftTriggerPressed)
self.rightTriggerAction.signal().triggered.connect(self.rightTriggerPressed)
self.leftTouchpadPressedAction.signal().triggered.connect(self.touchpadMovePressed)
self.rightTouchpadPressedAction.signal().triggered.connect(self.touchpadRotatePressed)
self.leftTouchpadReleasedAction.signal().triggered.connect(self.touchpadMoveReleased)
self.rightTouchpadReleasedAction.signal().triggered.connect(self.touchpadRotateReleased)
self.menuPressedAction.signal().triggered.connect(self.menuButtonPressed)
self.menuReleasedAction.signal().triggered.connect(self.menuButtonReleased)
# Activate the mode that supports the new interaction
vrDeviceService.setActiveInteractionGroup("CustomGroup")
def leftTriggerPressed(self, action, device):
selectVariantSet("ITERATE1")
def rightTriggerPressed(self, action, device):
selectVariantSet("ITERATE2")
def menuButtonPressed(self, action, device):
device.enableRay("y")
def menuButtonReleased(self, action, device):
pickedNode = device.pick.getNode()
device.disableRay()
mover.triggerSensor(pickedNode)
def touchpadMovePressed(self, action, device):
device.signal().moved.connect(self.touchpadMove)
def touchpadMoveReleased(self, action, device):
device.signal().moved.disconnect(self.touchpadMove)
def touchpadRotatePressed(self, action, device):
device.signal().moved.connect(self.touchpadRotate)
def touchpadRotateReleased(self, action, device):
device.signal().moved.disconnect(self.touchpadRotate)
def touchpadMove(self, device):
touch = device.getButtonState("Touchpad").getPosition()
matrix = device.getNode().getWorldTransform()
mover.translate(touch.y(), Vec3f(matrix[0,2], matrix[1,2], 0)) #Vec3f: x, y, z
mover.translate(-touch.x(), Vec3f(matrix[0,0], matrix[1,0], 0))
def touchpadRotate(self, device):
touch = device.getButtonState("Touchpad").getPosition()
mover.rotate(touch.x())
mover = None
mover = Mover()
myCustomInteraction = None
myCustomInteraction = MyCustomInteraction()
vrImmersiveInteractionService.setDefaultInteractionsActive(False)
setDisplayMode(DISPLAY_MODE)
print('VR_ENABLE script has ran to completion!')
I can't get this to work, things I have:
Windows 10 Pro PC (Xeon E-2186M, 128gb Ram, Nvidia Quadro P5200)
VRED PRO 2022.1
Things I've tried:
Restarting STEAMVR/VRED/PC
Removing all device interactions and making sure the one I created is added to the devices (it is)
Creating a new empty project
There's nothing in the console that indicates any errors, just a warning for "
Removing current mapping set CustomGroup not possible" when re-running the script for a 2nd time.
What I think might be happening is there is some kind of mode that's preventing the controllers from working at all? Is there some kind of hard controller reset I can do in the script?
I've attached the console output as a text file. I'd really appreciate any insights/help
Cheers!
Restarting VRED/SteamVR/
Solved! Go to Solution.