[Bf-blender-cvs] [25b3287ce60] vr_scene_inspection: Support mirroring the VR view in regular 3D Views

Julian Eisel noreply at git.blender.org
Tue Mar 3 18:40:04 CET 2020


Commit: 25b3287ce604015d07fe71a8e0bbb39af89bc982
Author: Julian Eisel
Date:   Tue Mar 3 18:25:18 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB25b3287ce604015d07fe71a8e0bbb39af89bc982

Support mirroring the VR view in regular 3D Views

Adds a per 3D View option to mirror the 3D session view. When enabled,
the viewport (continuously) renders using the same location and rotation
as the 3D view. While navigation is disabled then, other interactions
are working, so you can select and edit data as usual.
To be precise, we use the pose of the centroid, not the ones used by the
eyes.

Extra attention was put into forbidding viewport navigation while the VR
mirror runs (it overrides the current viewpoint anyway). Tried to make
this a generic feature. There may still be some navigation operators
that are not covered. So using them while the mirror runs will have an
affect on what you see once you end the session or mirroring.

Quadview is preserved, only the un-locked view shows the mirror then.
All of this is runtime data, no state changes should end up being read
from saved files.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_fly.c
M	source/blender/editors/space_view3d/view3d_gizmo_navigate.c
M	source/blender/editors/space_view3d/view3d_utils.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_xr.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 069ddf25181..8eefe29c5e0 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7043,6 +7043,10 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
         rv3d->smooth_timer = NULL;
 
         rv3d->rflag &= ~(RV3D_NAVIGATING | RV3D_PAINTING);
+        /* Clear runtime-only locks. */
+        if (rv3d->viewlock & RV3D_LOCK_RUNTIME_ONLY) {
+          rv3d->viewlock &= ~(RV3D_LOCK_ANY_TRANSFORM | RV3D_LOCK_RUNTIME_ONLY);
+        }
       }
     }
   }
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 296ddfcba03..5f889910009 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -592,7 +592,8 @@ void ED_view3d_draw_offscreen_simple(struct Depsgraph *depsgraph,
                                      const bool do_color_management,
                                      struct GPUOffScreen *ofs,
                                      struct GPUViewport *viewport);
-void ED_view3d_draw_setup_view(struct wmWindow *win,
+void ED_view3d_draw_setup_view(const struct wmWindowManager *wm,
+                               struct wmWindow *win,
                                struct Depsgraph *depsgraph,
                                struct Scene *scene,
                                struct ARegion *ar,
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 35d84d5d75e..073031f84f8 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3908,7 +3908,7 @@ static int region_quadview_exec(bContext *C, wmOperator *op)
       RegionView3D *rv3d = ar->regiondata;
       const char viewlock = (rv3d->viewlock_quad & RV3D_VIEWLOCK_INIT) ?
                                 (rv3d->viewlock_quad & ~RV3D_VIEWLOCK_INIT) :
-                                RV3D_LOCKED;
+                                RV3D_LOCK_ROTATION;
 
       region_quadview_init_rv3d(
           sa, ar, viewlock, ED_view3d_lock_view_from_index(index_qsplit++), RV3D_ORTHO);
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index a5da577859a..09770d3fc2a 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -1302,6 +1302,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
     return;
   }
 
+  const wmWindowManager *wm = CTX_wm_manager(C);
   Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
   Scene *scene = CTX_data_scene(C);
   UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
@@ -1502,7 +1503,8 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
 
           /* Draw 3D brush cursor. */
           GPU_matrix_push_projection();
-          ED_view3d_draw_setup_view(CTX_wm_window(C),
+          ED_view3d_draw_setup_view(wm,
+                                    CTX_wm_window(C),
                                     CTX_data_depsgraph_pointer(C),
                                     CTX_data_scene(C),
                                     ar,
@@ -1596,7 +1598,8 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
               !is_multires) {
             if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES && ss->deform_modifiers_active) {
               GPU_matrix_push_projection();
-              ED_view3d_draw_setup_view(CTX_wm_window(C),
+              ED_view3d_draw_setup_view(wm,
+                                        CTX_wm_window(C),
                                         CTX_data_depsgraph_pointer(C),
                                         CTX_data_scene(C),
                                         ar,
@@ -1615,7 +1618,8 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
           if (brush->sculpt_tool == SCULPT_TOOL_MULTIPLANE_SCRAPE &&
               brush->flag2 & BRUSH_MULTIPLANE_SCRAPE_PLANES_PREVIEW && !ss->cache->first_time) {
             GPU_matrix_push_projection();
-            ED_view3d_draw_setup_view(CTX_wm_window(C),
+            ED_view3d_draw_setup_view(wm,
+                                      CTX_wm_window(C),
                                       CTX_data_depsgraph_pointer(C),
                                       CTX_data_scene(C),
                                       ar,
@@ -1632,7 +1636,8 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
 
           if (brush->sculpt_tool == SCULPT_TOOL_CLOTH && !ss->cache->first_time) {
             GPU_matrix_push_projection();
-            ED_view3d_draw_setup_view(CTX_wm_window(C),
+            ED_view3d_draw_setup_view(CTX_wm_manager(C),
+                                      CTX_wm_window(C),
                                       CTX_data_depsgraph_pointer(C),
                                       CTX_data_scene(C),
                                       ar,
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index 91694cfc1ef..382c4d25d8c 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -94,6 +94,10 @@ if(WITH_FREESTYLE)
   add_definitions(-DWITH_FREESTYLE)
 endif()
 
+if(WITH_OPENXR)
+  add_definitions(-DWITH_OPENXR)
+endif()
+
 blender_add_lib(bf_editor_space_view3d "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
 
 # Needed so we can use dna_type_offsets.h for defaults initialization.
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index d9e4a41f8fc..555e52306e1 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -114,7 +114,7 @@ bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_ar)
     if (ar) {
       RegionView3D *rv3d;
       if ((ar->regiontype == RGN_TYPE_WINDOW) && (rv3d = ar->regiondata) &&
-          (rv3d->viewlock & RV3D_LOCKED) == 0) {
+          (rv3d->viewlock & RV3D_LOCK_ROTATION) == 0) {
         *r_v3d = v3d;
         *r_ar = ar;
         return true;
@@ -126,7 +126,7 @@ bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_ar)
           /* find the first unlocked rv3d */
           if (ar->regiondata && ar->regiontype == RGN_TYPE_WINDOW) {
             rv3d = ar->regiondata;
-            if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
+            if ((rv3d->viewlock & RV3D_LOCK_ROTATION) == 0) {
               ar_unlock = ar;
               if (rv3d->persp == RV3D_PERSP || rv3d->persp == RV3D_CAMOB) {
                 ar_unlock_user = ar;
@@ -335,7 +335,7 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
   }
 
   v3dn->local_collections_uuid = 0;
-  v3dn->flag &= ~V3D_LOCAL_COLLECTIONS;
+  v3dn->flag &= ~(V3D_LOCAL_COLLECTIONS | V3D_XR_SESSION_MIRROR);
 
   if (v3dn->shading.type == OB_RENDER) {
     v3dn->shading.type = OB_SOLID;
@@ -700,6 +700,15 @@ static void view3d_main_region_listener(
       if (ELEM(wmn->data, ND_UNDO)) {
         WM_gizmomap_tag_refresh(gzmap);
       }
+#ifdef WITH_OPENXR
+      else if (ELEM(wmn->data, ND_XR_DATA_CHANGED)) {
+        /* Only cause a redraw if this a VR session mirror. Should more features be added that
+         * require redraws, we could pass something to wmn->reference, e.g. the flag value. */
+        if (v3d->flag & V3D_XR_SESSION_MIRROR) {
+          ED_region_tag_redraw(ar);
+        }
+      }
+#endif
       break;
     case NC_ANIMATION:
       switch (wmn->data) {
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 2180b4a4abc..23e2dc23d17 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -313,10 +313,51 @@ static void view3d_stereo3d_setup(
   }
 }
 
+#ifdef WITH_OPENXR
+static bool view3d_xr_mirror_active(const wmWindowManager *wm,
+                                    const View3D *v3d,
+                                    const ARegion *ar)
+{
+  return (v3d->flag & V3D_XR_SESSION_MIRROR) &&
+         /* The free region (e.g. the camera region in quad-view) is always the last in the list
+            base. We don't want any other to be affected. */
+         !ar->next &&
+         /* NULL'ed when sending session end request. */
+         wm->xr.session_state &&  //
+         WM_xr_is_session_running(&wm->xr);
+}
+
+static void view3d_xr_mirror_setup(const wmWindowManager *wm,
+                                   Depsgraph *depsgraph,
+                                   Scene *scene,
+                                   View3D *v3d,
+                                   ARegion *ar,
+                                   const rcti *rect)
+{
+  RegionView3D *rv3d = ar->regiondata;
+  float viewmat[4][4];
+  const float lens_old = v3d->lens;
+
+  /* Ensure valid fallback value. */
+  copy_m4_m4(viewmat, rv3d->viewmat);
+
+  WM_xr_session_state_viewer_matrix_info_get(&wm->xr, viewmat, &v3d->lens);
+  rv3d->viewlock |= (RV3D_LOCK_ANY_TRANSFORM | RV3D_LOCK_RUNTIME_ONLY);
+  /* Just change to perspective mode, not worth resetting this. */
+  rv3d->persp = RV3D_PERSP;
+
+  view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect);
+
+  /* Reset overridden View3D data */
+  v3d->lens = lens_old;
+}
+#endif /* WITH_OPENXR */
+
 /**
  * Set the correct matrices
  */
-void ED_view3d_draw_setup_view(wmWindow *win,
+void ED_view3d_draw_setup_view(const wmWindowManager *wm,
+                               wmWindow *win,
                                Depsgraph *depsgraph,
                                Scene *scene,
                                ARegion *ar,
@@ -327,8 +368,14 @@ void ED_view3d_draw_setup_view(wmWindow *win,
 {
   RegionView3D *rv3d = ar->regiondata;
 
+#ifdef WITH_OPENXR
   /* Setup the view matrix. */
-  if (view3d_stereo3d_active(win, scene, v3d, rv3d)) {
+  if

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list