diff options
author | Peter Kim <pk15950@gmail.com> | 2021-07-23 08:41:31 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2021-07-23 08:54:56 +0300 |
commit | 36c0649d32aa458061df45bf280f989e1f8527db (patch) | |
tree | f9cd0631d985099edabd36a800d8b81db9e35a8e /intern | |
parent | 66548007a804a9f74a6d93065ed3c1194ce3f211 (diff) |
XR: Reference Space Improvements
Improves control over the XR reference space by using the stage ref
space (user-defined tracking bounds) instead of local ref space
(position at application launch), if available. Also adds an
"absolute tracking" session option to skip applying eye offsets that
are normally added for placing users exactly at landmarks.
By enabling absolute tracking, users can define the tracking origin
in a way that is not linked to the headset position. Instead, the
tracking values given by the XR runtime are left unadjusted and a
user can manually calibrate an "origin" landmark object to adjust to
their real world space.
Can be useful for applications that use external tracking systems
and those that primarily only need to use controllers and not the
headset (e.g. motion capture).
The absolute tracking option requires an update to the VR
Scene Inspection addon to be accessible by regular users.
Reviewed By: Julian Eisel
Differential Revision: http://developer.blender.org/D10946
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_XrSession.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp index 35280e77e22..263b2b6cfbd 100644 --- a/intern/ghost/intern/GHOST_XrSession.cpp +++ b/intern/ghost/intern/GHOST_XrSession.cpp @@ -120,7 +120,7 @@ static void create_reference_spaces(OpenXRSessionData &oxr, const GHOST_XrPose & XrReferenceSpaceCreateInfo create_info = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO}; create_info.poseInReferenceSpace.orientation.w = 1.0f; - create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; + create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE; #if 0 /* TODO * @@ -144,8 +144,47 @@ static void create_reference_spaces(OpenXRSessionData &oxr, const GHOST_XrPose & (void)base_pose; #endif - CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.reference_space), - "Failed to create reference space."); + XrResult result = xrCreateReferenceSpace(oxr.session, &create_info, &oxr.reference_space); + + if (XR_FAILED(result)) { + /* One of the rare cases where we don't want to immediately throw an exception on failure, + * since runtimes are not required to support the stage reference space. Although we need the + * stage reference space for absolute tracking, if the runtime doesn't support it then just + * fallback to the local space. */ + if (result == XR_ERROR_REFERENCE_SPACE_UNSUPPORTED) { + printf( + "Warning: XR runtime does not support stage reference space, disabling absolute " + "tracking.\n"); + + create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; + CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.reference_space), + "Failed to create local reference space."); + } + else { + throw GHOST_XrException("Failed to create stage reference space.", result); + } + } + else { + /* Check if tracking bounds are valid. Tracking bounds may be invalid if the user did not + * define a tracking space via the XR runtime. */ + XrExtent2Df extents; + CHECK_XR(xrGetReferenceSpaceBoundsRect(oxr.session, XR_REFERENCE_SPACE_TYPE_STAGE, &extents), + "Failed to get stage reference space bounds."); + if (extents.width == 0.0f || extents.height == 0.0f) { + printf( + "Warning: Invalid stage reference space bounds, disabling absolute tracking. To enable " + "absolute tracking, please define a tracking space via the XR runtime.\n"); + + /* Fallback to local space. */ + if (oxr.reference_space != XR_NULL_HANDLE) { + CHECK_XR(xrDestroySpace(oxr.reference_space), "Failed to destroy stage reference space."); + } + + create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; + CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.reference_space), + "Failed to create local reference space."); + } + } create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW; CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.view_space), |