[Bf-blender-cvs] [4b18015a1c6] vr_scene_inspection: Add positional tracking option (3DoF vs. 6DoF)

Julian Eisel noreply at git.blender.org
Wed Dec 11 15:11:45 CET 2019


Commit: 4b18015a1c6ba7c1a558f9d39a9937b98506adc2
Author: Julian Eisel
Date:   Wed Dec 11 14:30:18 2019 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB4b18015a1c6ba7c1a558f9d39a9937b98506adc2

Add positional tracking option (3DoF vs. 6DoF)

For passing around the HMD or preparing scenes for 3DoF interaction
(e.g. cardboards) this option is quite handy.

After feedback from @sebastian_k and @noemis, decision was that
disabling the positional tracking should not reset the position to the
starting one. It should just keep whatever is the current position.
So we have to get the local pose (which is different from the per eye
pose) out of OpenXR so we can have more dynamic base position that
changes depending on the positional tracking option.

Not that this isn't working 100% as wanted: There's a slight offset when
disabling the positional tracking. I don't want to spend too much time
on something minor-ish while there are more major features to get done.

===================================================================

M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/intern/wm_xr.c

===================================================================

diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 20d0f7d1e7d..9b585c54466 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -629,7 +629,8 @@ typedef struct {
   int ofsx, ofsy;
   int width, height;
 
-  GHOST_XrPose pose;
+  GHOST_XrPose eye_pose;
+  GHOST_XrPose local_pose;
 
   struct {
     float angle_left, angle_right;
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index 0a622256aa4..bfa7f3e151b 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -42,6 +42,7 @@ struct OpenXRSessionData {
   /* Only stereo rendering supported now. */
   const XrViewConfigurationType view_type{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
   XrSpace reference_space;
+  XrSpace view_space;
   std::vector<XrView> views;
   std::vector<XrSwapchain> swapchains;
   std::map<XrSwapchain, std::vector<XrSwapchainImageBaseHeader *>> swapchain_images;
@@ -110,7 +111,7 @@ void GHOST_XrSession::initSystem()
  *
  * \{ */
 
-static void create_reference_space(OpenXRSessionData *oxr, const GHOST_XrPose *base_pose)
+static void create_reference_spaces(OpenXRSessionData *oxr, const GHOST_XrPose *base_pose)
 {
   XrReferenceSpaceCreateInfo create_info{XR_TYPE_REFERENCE_SPACE_CREATE_INFO};
   create_info.poseInReferenceSpace.orientation.w = 1.0f;
@@ -141,6 +142,10 @@ static void create_reference_space(OpenXRSessionData *oxr, const GHOST_XrPose *b
 
   CHECK_XR(xrCreateReferenceSpace(oxr->session, &create_info, &oxr->reference_space),
            "Failed to create reference space.");
+
+  create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW;
+  CHECK_XR(xrCreateReferenceSpace(oxr->session, &create_info, &oxr->view_space),
+           "Failed to create view reference space.");
 }
 
 void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
@@ -187,7 +192,7 @@ void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
            "detailed error information to the command line.");
 
   prepareDrawing();
-  create_reference_space(m_oxr.get(), &begin_info->base_pose);
+  create_reference_spaces(m_oxr.get(), &begin_info->base_pose);
 }
 
 void GHOST_XrSession::requestEnd()
@@ -406,16 +411,22 @@ void GHOST_XrSession::draw(void *draw_customdata)
   endFrameDrawing(&layers);
 }
 
+static void copy_openxr_pose_to_ghost_pose(const XrPosef &oxr_pose, GHOST_XrPose &r_ghost_pose)
+{
+  /* Set and convert to Blender coodinate space. */
+  r_ghost_pose.position[0] = oxr_pose.position.x;
+  r_ghost_pose.position[1] = oxr_pose.position.y;
+  r_ghost_pose.position[2] = oxr_pose.position.z;
+  r_ghost_pose.orientation_quat[0] = oxr_pose.orientation.w;
+  r_ghost_pose.orientation_quat[1] = oxr_pose.orientation.x;
+  r_ghost_pose.orientation_quat[2] = oxr_pose.orientation.y;
+  r_ghost_pose.orientation_quat[3] = oxr_pose.orientation.z;
+}
+
 static void ghost_xr_draw_view_info_from_view(const XrView &view, GHOST_XrDrawViewInfo &r_info)
 {
   /* Set and convert to Blender coodinate space. */
-  r_info.pose.position[0] = view.pose.position.x;
-  r_info.pose.position[1] = view.pose.position.y;
-  r_info.pose.position[2] = view.pose.position.z;
-  r_info.pose.orientation_quat[0] = view.pose.orientation.w;
-  r_info.pose.orientation_quat[1] = view.pose.orientation.x;
-  r_info.pose.orientation_quat[2] = view.pose.orientation.y;
-  r_info.pose.orientation_quat[3] = view.pose.orientation.z;
+  copy_openxr_pose_to_ghost_pose(view.pose, r_info.eye_pose);
 
   r_info.fov.angle_left = view.fov.angleLeft;
   r_info.fov.angle_right = view.fov.angleRight;
@@ -433,6 +444,7 @@ static bool ghost_xr_draw_view_expects_srgb_buffer(const GHOST_XrContext *contex
 
 void GHOST_XrSession::drawView(XrSwapchain swapchain,
                                XrCompositionLayerProjectionView &proj_layer_view,
+                               XrSpaceLocation &view_location,
                                XrView &view,
                                void *draw_customdata)
 {
@@ -464,6 +476,7 @@ void GHOST_XrSession::drawView(XrSwapchain swapchain,
   draw_view_info.ofsy = proj_layer_view.subImage.imageRect.offset.y;
   draw_view_info.width = proj_layer_view.subImage.imageRect.extent.width;
   draw_view_info.height = proj_layer_view.subImage.imageRect.extent.height;
+  copy_openxr_pose_to_ghost_pose(view_location.pose, draw_view_info.local_pose);
   ghost_xr_draw_view_info_from_view(view, draw_view_info);
 
   m_context->getCustomFuncs()->draw_view_fn(&draw_view_info, draw_customdata);
@@ -479,6 +492,7 @@ XrCompositionLayerProjection GHOST_XrSession::drawLayer(
   XrViewLocateInfo viewloc_info{XR_TYPE_VIEW_LOCATE_INFO};
   XrViewState view_state{XR_TYPE_VIEW_STATE};
   XrCompositionLayerProjection layer{XR_TYPE_COMPOSITION_LAYER_PROJECTION};
+  XrSpaceLocation view_location{XR_TYPE_SPACE_LOCATION};
   uint32_t view_count;
 
   viewloc_info.viewConfigurationType = m_oxr->view_type;
@@ -494,11 +508,17 @@ XrCompositionLayerProjection GHOST_XrSession::drawLayer(
            "Failed to query frame view and projection state.");
   assert(m_oxr->swapchains.size() == view_count);
 
+  CHECK_XR(
+      xrLocateSpace(
+          m_oxr->view_space, m_oxr->reference_space, viewloc_info.displayTime, &view_location),
+      "Failed to query frame view space");
+
   proj_layer_views.resize(view_count);
 
   for (uint32_t view_idx = 0; view_idx < view_count; view_idx++) {
     drawView(m_oxr->swapchains[view_idx],
              proj_layer_views[view_idx],
+             view_location,
              m_oxr->views[view_idx],
              draw_customdata);
   }
diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h
index fdf581a758c..038b8197dae 100644
--- a/intern/ghost/intern/GHOST_XrSession.h
+++ b/intern/ghost/intern/GHOST_XrSession.h
@@ -69,6 +69,7 @@ class GHOST_XrSession {
       std::vector<XrCompositionLayerProjectionView> &proj_layer_views, void *draw_customdata);
   void drawView(XrSwapchain swapchain,
                 XrCompositionLayerProjectionView &proj_layer_view,
+                XrSpaceLocation &view_location,
                 XrView &view,
                 void *draw_customdata);
   void beginFrameDrawing();
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 49d3726a224..b85644722b6 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3990,6 +3990,8 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                                               V3D_OFSDRAW_SHOW_ANNOTATION);
         wm->xr.session_settings.clip_start = v3d_default->clip_start;
         wm->xr.session_settings.clip_end = v3d_default->clip_end;
+
+        wm->xr.session_settings.flag = XR_SESSION_USE_POSITION_TRACKING;
       }
     }
 #endif
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 5caf181314b..2bdeb9fdbdb 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -125,7 +125,12 @@ typedef struct ReportTimerInfo {
 typedef struct wmXrData {
   void *context; /* GHOST_XrContextHandle */
 
+  /** Permanent session settings (draw mode, feature toggles, etc). Stored in files and accessible
+   * even before the session runs. */
   bXrSessionSettings session_settings;
+
+  /** Runtime state information for managing Blender specific behaviors. Not stored in files. */
+  struct bXrRuntimeSessionState *session_state;
 } wmXrData;
 //#endif
 
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 0d23668a59f..4f8893b1544 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -31,7 +31,11 @@ typedef struct bXrSessionSettings {
   /** Clipping distance. */
   float clip_start, clip_end;
 
-  char _pad2[4];
+  int flag;
 } bXrSessionSettings;
 
+typedef enum eXrSessionFlag {
+  XR_SESSION_USE_POSITION_TRACKING = (1 << 0),
+} eXrSessionFlag;
+
 #endif /* __DNA_XR_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 68cf4a6ab18..0c5280b3a19 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -19,6 +19,7 @@
  */
 
 #include "DNA_view3d_types.h"
+#include "DNA_xr_types.h"
 
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
@@ -63,6 +64,12 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
   RNA_def_property_range(prop, 1e-6f, FLT_MAX);
   RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
   RNA_def_property_ui_text(prop, "Clip End", "VR View far clipping distance");
+
+  prop = RNA_def_property(srna, "use_positional_tracking", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", XR_SESSION_USE_POSITION_TRACKING);
+  RNA_def_property_ui_text(prop,
+                           "Positional Tracking",
+                           "Limit view movements to rotation only (three degrees of freedom)");
 }
 
 void RNA_def_xr(BlenderRNA *brna)
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index e88082b14e9..7de110eb9d0 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -58,7 +58,24 @@
 #include "wm_surface.h"
 #include "wm_window.h"
 
-static wmSurface *g_xr_surface = NULL;
+void wm_xr_draw_view(const GHOST_XrDrawViewInfo *, void *);
+void *wm_xr_session_gpu_binding_context_create(GHOST_TXrGraphicsBinding);
+void wm_xr_session_gpu_binding_context_destroy(GHOST_TXrGraphicsBinding, void *);
+wmSurface *wm_xr_session_surface_create(wmWindowManager *, unsigned int);
+
+/* -------------------------------------------------------------------- */
+
+typedef struct bXrRuntimeSessionState {
+  /** The pose (location + rotation) that acts as the basis for view transforms (world space). */
+  GHOST_XrPose reference_pose;
+  /** The pose (location + rotation) to which eye deltas will be applied to when drawing (world
+   * space)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list