When writing new Python scripts for VRED version 2020.1 and later, please use Python API v2 for VR instead.
With the HTC Vive there is only one display mode option, OpenVR HMD.
In Standing or Room Scale mode, a camera's Z-translation value defines the floor level. This means the Z-value in the scene corresponds to the physical floor in the tracked space.
Since how to set the camera in VRED, such that the virtual floor in the scene and the real floor match, is the same for the HTC Vive, see How to Set Floor Level by Changing Camera Translation.
Another possibility is to use the Python function setOpenVRTrackingOrigin(Pnt3f(x,y,z))
to adjust tracking values, if the floor in your scene is NOT at Z = 0.
In this image, the tracking values are modified with the setOpenVRTrackingOrigin
Python function:
If you want to set the floor level using a Python function, here's an example:
setOpenVRTrackingOrigin(Pnt3f(0.0, 337.0, 0.0))
.The Python function setOpenVRTrackingOrigin
specifies an offset vector. This is subtracted from OpenVR's positional tracking values. This function can be executed before OpenVR is activated or while OpenVR is running. Note that the function expects the position to be in a special coordinate system.
If the tracking origin in the VRED scene should be at pos = (x\_scene, y\_scene, z_scene)
, call the Python function setOpenVRTrackingOrigin(Pnt3f(-x\_scene, -z\_scene, y_scene))
.
Activate the viewpoint after enabling the OpenVR HMD display mode. Paste the following Python function into the Terminal to create a shortcut that will activate OpenVR or Script Editor and set a viewpoint named VR\_initial\_view
. For information on how to setup viewpoints for VR, see Viewpoints.
def activateOpenVR():
setDisplayMode(VR_DISPLAY_OPEN_VR)
jumpViewPoint('VR_initial_view')
keyA = vrKey(Key_A)
keyA.connect(activateOpenVR)
Now, whenever you press the A key, VRED will go into OpenVR mode and activate the viewpoint.
Scripts executed in the Terminal are not saved in the scene file. To save this scripted shortcut in your scene for future use, enter the Python code into the Script Editor. The script will be saved within the vpb file, next time you save the scene.
If you want to query the current absolute position of the tracked HMD in the VRED scene, use:
matrix = getActiveCameraNode().getWorldTransform()
The position is:
x=matrix[3], y=matrix[7], z=matrix[11]
The function, getWorldTransform()
, includes the tracking transformation when used with the active camera node.
You can enable Seated mode, using the following Python function, with mode 0 = seated and mode 1 = standing/room scale:
setOpenVRTrackingOriginType(0)
Default mode is room scale.
When enabling the seated tracking origin type, the tracking origin is no longer the center of the play area, but at the head position of the player. That means, the VRED camera should be positioned where the head of the user should be in the VR scene.
A certain pose, defined by the user during setup, is assumed as the default head pose or Seated Zero Pose. Tracking values are delivered relative to that pose. The Seated Zero Pose can be reset while OpenVR is running in VRED, using the Python function resetOpenVRHMDPose()
.
VRED resets the zero pose each time OpenVR mode is enabled.
Here are the steps for setting up Seated mode with OpenVR. The correct order is very is important!
setOpenVRTrackingOriginType(0)
to activate Seated mode.resetOpenVRHMDPose()
in the Terminal. It is already reset upon activation of OpenVR; however, if the user did not wear the HMD in the correct position at that time, resetting is necessary.