OpenVR c++ SDK: Receive assigned Tracker Roles from SteamVR
Hello everyone,
I am developing a c++ background application with the OpenVR SDK and I think that I am missing something.
You can assign Roles for Trackers inside SteamVR under Settings > Controllers > MANAGE VIVE TRACKERS:
How can you receive the assigned Roles inside the c++ OpenVR SDK? I tried to get my head around it, but could not find a enum inside openvr.h or a related function. I figured out, that you can receive a VREvent_TrackersSectionSettingChanged VREvent after changig the Roles inside the settings, but I could not figure out how to react to it and read the changes.
Can you give me a hint, please?
Thank you.
I don't think it's possible to get the role directly from OpenVR. The intended usage seems to be to use SteamVR Input to define pose actions for all the tracker poses you need, and then add bindings to the specific tracker types you want to control each pose. Each of the tracker roles seem to be setup as a different type of controller, so you'd need to setup separate binding files for each tracker role.
HTC also has some kind of input management plugin for Unity that seems to be able to access tracker roles. I have no idea how it does that though, but reverse engineering it might be an alternative if you don't like the SteamVR Input method. https://github.com/ViveSoftware/ViveInputUtility-Unity
I don't have Vive trackers, but generally you should be able to use the IVRSettings interface to read settings value from the k_pch_Trackers_Section section. There doesn't seem to be a direct API for this from what I can tell.
Can't find any default definitions for that section on my system, so I can't tell you how it should look like, but I suppose that's not hard to figure out if you have trackers at hand.
To those who found this issue through Google, here is how you manage to get tracker roles:
- Listen for
VREvent_TrackersSectionSettingChangedevent- This event, however, does not tell you which tracker was reassigned with a new role. The
trackedDeviceIndexis always0xffffffff
- This event, however, does not tell you which tracker was reassigned with a new role. The
- When the event is fired, call
vr::VRSettings()->GetString(vr::k_pch_Trackers_Section, trackeDeviceName, buffer, sizeof(buffer)/sizeof(*buffer), &err)to get the role settings from SteamVR-
trackerDeviceNameis either/devices/htc/vive_tracker${serial}for Vive Trackers or/devices/lighthouse/${serial}for TundraLab Trackers. There might be more exotic types but we don't have any method for enumerating all possible devices. (We can know all the serial numbers, but the/devices/...stuff is not documented anywhere to my knowledge.) - Perhaps we have to parse the settings file of SteamVR directly for this. The file is at
X:\Program Files (x86)\Steam\config\steamvr.vrsettingswhereXis the drive letter you installed Steam (not SteamVR). - You will need a method to enumerate all possible devices. If you are writing an app then
vr::VRSystem()->GetSortedTrackedDeviceIndicesOfClass(...)is enough. But if you are writing a driver, then you may have to hook into the internals of SteamVR (or parse thesteamvr.vrsettings). - The format of the settings string is
TrackerRole_${role}. Therolepart is usually something likeLeftShoulder. However, if the tracker was set as handheld, it will be eitherTrackerRole_Handed,TrackerRole_${hand}wherehandis eitherInvalid,LeftHandorRightHand. There is, as you may have guessed, no document about all possible names of tracker roles.
-