[Bf-blender-cvs] [6732d31f184] xr-controller-support: XR: Fixes/adjustments when viewer scale != 1.0

Peter Kim noreply at git.blender.org
Fri Jun 18 14:37:17 CEST 2021


Commit: 6732d31f184e26ab38ead02e0f97d07063ee66d4
Author: Peter Kim
Date:   Fri Jun 18 21:22:15 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rB6732d31f184e26ab38ead02e0f97d07063ee66d4

XR: Fixes/adjustments when viewer scale != 1.0

This corrects some clipping and shading issues when a scale factor
is applied to the XR viewmat. Also fixes the viewer pose calculation
with VR navigation.

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

M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/editors/transform/transform_ops.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_gesture_ops.c
M	source/blender/windowmanager/xr/intern/wm_xr_draw.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 8aa9f6112d7..aecdf15509b 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -359,8 +359,10 @@ static void view3d_xr_mirror_setup(const wmWindowManager *wm,
   else {
     v3d->flag2 &= ~V3D_XR_SHOW_CUSTOM_OVERLAYS;
   }
+  /* Hide navigation gizmo. */
+  v3d->gizmo_flag |= V3D_GIZMO_HIDE_NAVIGATE;
 
-  /* Reset overridden View3D data */
+  /* Reset overridden View3D data. */
   v3d->lens = lens_old;
   v3d->clip_start = clip_start_old;
   v3d->clip_end = clip_end_old;
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index c6da8f41c76..215cc030f46 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -2770,12 +2770,6 @@ static int view3d_select_invoke_3d(bContext *C, wmOperator *op, const wmEvent *e
   int mval[2];
   int retval;
 
-  /* Scale to apply to clip distances. */
-  float viewer_scale = 1.0f;
-#ifdef WITH_XR_OPENXR
-  WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
-#endif
-
   /* Since this function is called in a window context, we need to replace the
    * window view parameters with the XR surface counterparts to get a correct
    * result for GPU select. */
@@ -2785,8 +2779,8 @@ static int view3d_select_invoke_3d(bContext *C, wmOperator *op, const wmEvent *e
                             v3d,
                             region,
                             actiondata->eye_lens,
-                            xr->session_settings.clip_start * viewer_scale,
-                            xr->session_settings.clip_end * viewer_scale,
+                            xr->session_settings.clip_start,
+                            xr->session_settings.clip_end,
                             actiondata->eye_viewmat);
 
   map_to_pixel(mval,
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 79207b02e0a..a10a4b45d3f 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -1767,8 +1767,6 @@ void ED_view3d_xr_shading_update(wmWindowManager *wm, const View3D *v3d, const S
 {
   if (v3d->runtime.flag & V3D_RUNTIME_XR_SESSION_ROOT) {
     View3DShading *xr_shading = &wm->xr.session_settings.shading;
-    /* Flags that shouldn't be overridden by the 3D View shading. */
-    const int flag_copy = V3D_SHADING_WORLD_ORIENTATION;
 
     BLI_assert(WM_xr_session_exists(&wm->xr));
 
@@ -1786,9 +1784,7 @@ void ED_view3d_xr_shading_update(wmWindowManager *wm, const View3D *v3d, const S
     }
 
     /* Copy shading from View3D to VR view. */
-    const int old_xr_shading_flag = xr_shading->flag;
     *xr_shading = v3d->shading;
-    xr_shading->flag = (xr_shading->flag & ~flag_copy) | (old_xr_shading_flag & flag_copy);
     if (v3d->shading.prop) {
       xr_shading->prop = IDP_CopyProperty(xr_shading->prop);
     }
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 86d15c33439..bebdf47bd12 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -491,12 +491,6 @@ static int transform_modal_3d(bContext *C, wmOperator *op, const wmEvent *event)
   float viewmat_prev[4][4];
   int retval;
 
-  /* Scale to apply to clip distances. */
-  float viewer_scale = 1.0f;
-#ifdef WITH_XR_OPENXR
-  WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
-#endif
-
   wmEvent event_mut;
   memcpy(&event_mut, event, sizeof(wmEvent));
 
@@ -508,8 +502,8 @@ static int transform_modal_3d(bContext *C, wmOperator *op, const wmEvent *event)
       v3d,
       region,
       actiondata->eye_lens,
-      xr->session_settings.clip_start * viewer_scale,
-      xr->session_settings.clip_end * viewer_scale,
+      xr->session_settings.clip_start,
+      xr->session_settings.clip_end,
       t->viewmat); /* Use viewmat from when transform was invoked instead of latest XR viewmat. */
 
   map_to_pixel(event_mut.mval,
@@ -617,12 +611,6 @@ static int transform_invoke_3d(bContext *C, wmOperator *op, const wmEvent *event
   float viewmat_prev[4][4];
   int retval;
 
-  /* Scale to apply to clip distances. */
-  float viewer_scale = 1.0f;
-#ifdef WITH_XR_OPENXR
-  WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
-#endif
-
   wmEvent event_mut;
   memcpy(&event_mut, event, sizeof(wmEvent));
   event_mut.type = LEFTMOUSE;
@@ -634,8 +622,8 @@ static int transform_invoke_3d(bContext *C, wmOperator *op, const wmEvent *event
                             v3d,
                             region,
                             actiondata->eye_lens,
-                            xr->session_settings.clip_start * viewer_scale,
-                            xr->session_settings.clip_end * viewer_scale,
+                            xr->session_settings.clip_start,
+                            xr->session_settings.clip_end,
                             actiondata->eye_viewmat);
 
   map_to_pixel(event_mut.mval,
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 80bcfe5b6a6..82ba0ec7dfc 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -988,7 +988,6 @@ bool WM_xr_session_state_nav_rotation_get(const wmXrData *xr, float r_rotation[4
 void WM_xr_session_state_nav_rotation_set(wmXrData *xr, const float rotation[4]);
 bool WM_xr_session_state_nav_scale_get(const wmXrData *xr, float *r_scale);
 void WM_xr_session_state_nav_scale_set(wmXrData *xr, float scale);
-bool WM_xr_session_state_viewer_scale_get(const wmXrData *xr, float *r_scale);
 void WM_xr_session_state_navigation_reset(struct wmXrSessionState *state);
 void WM_xr_session_state_viewer_object_get(const wmXrData *xr, Object *ob);
 void WM_xr_session_state_viewer_object_set(wmXrData *xr, const Object *ob);
diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c
index f913b32e76e..cb441f8861c 100644
--- a/source/blender/windowmanager/intern/wm_gesture_ops.c
+++ b/source/blender/windowmanager/intern/wm_gesture_ops.c
@@ -225,12 +225,6 @@ int WM_gesture_box_invoke_3d(bContext *C, wmOperator *op, const wmEvent *event)
   int mval[2];
   int retval;
 
-  /* Scale to apply to clip distances. */
-  float viewer_scale = 1.0f;
-#ifdef WITH_XR_OPENXR
-  WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
-#endif
-
   wmEvent event_mut;
   memcpy(&event_mut, event, sizeof(wmEvent));
 
@@ -241,8 +235,8 @@ int WM_gesture_box_invoke_3d(bContext *C, wmOperator *op, const wmEvent *event)
                             v3d,
                             region,
                             actiondata->eye_lens,
-                            xr->session_settings.clip_start * viewer_scale,
-                            xr->session_settings.clip_end * viewer_scale,
+                            xr->session_settings.clip_start,
+                            xr->session_settings.clip_end,
                             NULL);
 
   map_to_pixel(mval,
@@ -366,12 +360,6 @@ int WM_gesture_box_modal_3d(bContext *C, wmOperator *op, const wmEvent *event)
   int mval[2];
   int retval;
 
-  /* Scale to apply to clip distances. */
-  float viewer_scale = 1.0f;
-#ifdef WITH_XR_OPENXR
-  WM_xr_session_state_viewer_scale_get(xr, &viewer_scale);
-#endif
-
   wmEvent event_mut;
   memcpy(&event_mut, event, sizeof(wmEvent));
 
@@ -385,8 +373,8 @@ int WM_gesture_box_modal_3d(bContext *C, wmOperator *op, const wmEvent *event)
                             v3d,
                             region,
                             actiondata->eye_lens,
-                            xr->session_settings.clip_start * viewer_scale,
-                            xr->session_settings.clip_end * viewer_scale,
+                            xr->session_settings.clip_start,
+                            xr->session_settings.clip_end,
                             release ? actiondata->eye_viewmat : NULL);
 
   map_to_pixel(mval,
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
index 774a13e2a8a..3629b1a2f5e 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
@@ -42,30 +42,43 @@
 #include "wm_surface.h"
 #include "wm_xr_intern.h"
 
-void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4])
+void wm_xr_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4])
+{
+  quat_to_mat4(r_mat, pose->orientation_quat);
+  copy_v3_v3(r_mat[3], pose->position);
+}
+
+void wm_xr_pose_scale_to_mat(const GHOST_XrPose *pose, float scale, float r_mat[4][4])
+{
+  wm_xr_pose_to_mat(pose, r_mat);
+
+  BLI_assert(scale > 0.0f);
+  mul_v3_fl(r_mat[0], scale);
+  mul_v3_fl(r_mat[1], scale);
+  mul_v3_fl(r_mat[2], scale);
+}
+
+void wm_xr_pose_to_imat(const GHOST_XrPose *pose, float r_imat[4][4])
 {
   float iquat[4];
   invert_qt_qt_normalized(iquat, pose->orientation_quat);
-  quat_to_mat4(r_viewmat, iquat);
-  translate_m4(r_viewmat, -pose->position[0], -pose->position[1], -pose->position[2]);
+  quat_to_mat4(r_imat, iquat);
+  translate_m4(r_imat, -pose->position[0], -pose->position[1], -pose->position[2]);
 }
 
-void wm_xr_pose_scale_to_viewmat(const GHOST_XrPose *pose, float scale, float r_viewmat[4][4])
+void wm_xr_pose_scale_to_imat(const GHOST_XrPose *pose, float scale, float r_imat[4][4])
 {
-  wm_xr_pose_to_viewmat(pose, r_viewmat);
+  float iquat[4];
+  invert_qt_qt_normalized(iquat, pose->orientation_quat);
+  quat_to_mat4(r_imat, iquat);
 
-  /* Clamp to reasonable values. */
-  CLAMP(scale, 0.001f, 1000.0f);
+  BLI_assert(scale > 0.0f);
   scale = 1.0f / scale;
-  mul_v3_fl(r_viewmat[0], scale);
-  mul_v3_fl(r_viewmat[1], scale);
-  mul_v3_fl(r_viewmat[2], scale);
-}
+  mul_v3_fl(r_imat[0], scale);
+  mul_v3_fl(r_imat[1], scale);
+  mul_v3_fl(r_imat[2], scale);
 
-void wm_xr_controller_pose_to_mat(const GHOST_XrPose

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list