[Bf-blender-cvs] [4ad5449c92f] vr_scene_inspection: Refactor XR mirror toggling
Julian Eisel
noreply at git.blender.org
Thu Mar 12 12:24:42 CET 2020
Commit: 4ad5449c92f958c05f5518b4af05c2cdfa01a4bf
Author: Julian Eisel
Date: Thu Mar 12 12:23:28 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB4ad5449c92f958c05f5518b4af05c2cdfa01a4bf
Refactor XR mirror toggling
===================================================================
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/space_view3d/view3d_view.c
M source/blender/makesrna/intern/rna_space.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/intern/wm_xr.c
===================================================================
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 60d19b41071..a2d36b6c716 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -731,6 +731,11 @@ void ED_view3d_buttons_region_layout_ex(const struct bContext *C,
bool ED_view3d_local_collections_set(struct Main *bmain, struct View3D *v3d);
void ED_view3d_local_collections_reset(struct bContext *C, const bool reset_all);
+#ifdef WITH_XR_OPENXR
+void ED_view3d_xr_mirror_begin(RegionView3D *rv3d);
+void ED_view3d_xr_mirror_end(RegionView3D *rv3d);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index ee9cbeeb5ba..f3e37d6b2b9 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -1686,3 +1686,28 @@ void ED_view3d_local_collections_reset(struct bContext *C, const bool reset_all)
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name XR Functionality
+ * \{ */
+
+#ifdef WITH_XR_OPENXR
+
+void ED_view3d_xr_mirror_begin(RegionView3D *rv3d)
+{
+ /* If the session is not running yet, changes below should not be applied! */
+ BLI_assert(WM_xr_session_was_started(&((wmWindowManager *)G_MAIN->wm.first)->xr));
+
+ rv3d->runtime_viewlock |= RV3D_LOCK_ANY_TRANSFORM;
+ /* Force perspective view. This isn't reset but that's not really an issue. */
+ rv3d->persp = RV3D_PERSP;
+}
+
+void ED_view3d_xr_mirror_end(RegionView3D *rv3d)
+{
+ rv3d->runtime_viewlock &= ~RV3D_LOCK_ANY_TRANSFORM;
+}
+
+#endif
+
+/** \} */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index fad75cd57f3..c72f6d50b04 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1335,21 +1335,43 @@ static const EnumPropertyItem *rna_SpaceView3D_stereo3d_camera_itemf(bContext *C
static void rna_SpaceView3D_mirror_xr_session_set(PointerRNA *ptr, bool value)
{
+# ifdef WITH_XR_OPENXR
View3D *v3d = ptr->data;
+ SET_FLAG_FROM_TEST(v3d->flag, value, V3D_XR_SESSION_MIRROR);
+# else
+ UNUSED_VARS(ptr, value);
+# endif
+}
- if (value) {
- v3d->flag |= V3D_XR_SESSION_MIRROR;
- }
- else {
- PointerRNA rv3d_ptr = RNA_pointer_get(ptr, "region_3d");
- RegionView3D *rv3d = rv3d_ptr.data;
+static void rna_SpaceView3D_mirror_xr_session_update(Main *main,
+ Scene *UNUSED(scene),
+ PointerRNA *ptr)
+{
+# ifdef WITH_XR_OPENXR
+ View3D *v3d = ptr->data;
+ PointerRNA rv3d_ptr = RNA_pointer_get(ptr, "region_3d");
+ RegionView3D *rv3d = rv3d_ptr.data;
+ wmWindowManager *wm = main->wm.first;
+
+ /* Handle mirror toggling while a VR session runs. */
- BLI_assert(rv3d_ptr.type == &RNA_RegionView3D);
+ BLI_assert(rv3d_ptr.type == &RNA_RegionView3D);
- /* Make sure the view is unlocked. */
- rv3d->runtime_viewlock &= ~RV3D_LOCK_ANY_TRANSFORM;
- v3d->flag &= ~V3D_XR_SESSION_MIRROR;
+ /* The VR session may not have been started yet, so the view should only be tagged to
+ * let the VR code manage the call to ED_view3d_xr_mirror_begin/end(). */
+ if (!WM_xr_session_was_started(&wm->xr)) {
+ return;
+ }
+
+ if (v3d->flag & V3D_XR_SESSION_MIRROR) {
+ ED_view3d_xr_mirror_begin(rv3d);
+ }
+ else {
+ ED_view3d_xr_mirror_end(rv3d);
}
+# else
+ UNUSED_VARS(main, scene, ptr);
+# endif
}
static int rna_SpaceView3D_icon_from_show_object_viewport_get(PointerRNA *ptr)
@@ -4215,7 +4237,8 @@ static void rna_def_space_view3d(BlenderRNA *brna)
prop,
"Mirror VR Session",
"Synchronize the viewer perspective of virtual reality sessions with this 3D viewport");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ RNA_def_property_update(
+ prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_mirror_xr_session_update");
{
struct {
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index b9ee08be35e..62ec5a491c4 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -873,6 +873,7 @@ void WM_generic_user_data_free(struct wmGenericUserData *user_data);
#ifdef WITH_XR_OPENXR
/* wm_xr.c */
+bool WM_xr_session_was_started(const wmXrData *xr);
bool WM_xr_session_is_running(const wmXrData *xr);
void WM_xr_session_state_viewer_location_get(const wmXrData *xr, float r_location[3]);
void WM_xr_session_state_viewer_rotation_get(const wmXrData *xr, float r_rotation[4]);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index dcad1c14d8e..ed975490d1d 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3647,8 +3647,10 @@ static void WM_OT_stereo3d_set(wmOperatorType *ot)
#ifdef WITH_XR_OPENXR
-static void wm_xr_session_disable_mirror_views(Main *bmain)
+static void wm_xr_session_update_mirror_views(Main *bmain, wmWindowManager *wm)
{
+ const bool enable = WM_xr_session_was_started(&wm->xr);
+
for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
for (ScrArea *area = screen->areabase.first; area; area = area->next) {
for (SpaceLink *slink = area->spacedata.first; slink; slink = slink->next) {
@@ -3660,8 +3662,13 @@ static void wm_xr_session_disable_mirror_views(Main *bmain)
/* The free main region (e.g. the unlocked one in quad-view) is always the last one,
* see rna_SpaceView3D_region_3d_get(). */
ARegion *region = region_list->last;
- RegionView3D *rv3d = region->regiondata;
- rv3d->runtime_viewlock &= ~RV3D_LOCK_ANY_TRANSFORM;
+
+ if (enable) {
+ ED_view3d_xr_mirror_begin(region->regiondata);
+ }
+ else {
+ ED_view3d_xr_mirror_end(region->regiondata);
+ }
}
}
}
@@ -3680,9 +3687,7 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
wm_xr_session_toggle(&wm->xr);
- if (!WM_xr_session_is_running(&wm->xr)) {
- wm_xr_session_disable_mirror_views(CTX_data_main(C));
- }
+ wm_xr_session_update_mirror_views(CTX_data_main(C), wm);
WM_event_add_notifier(C, NC_WM | ND_XR_DATA_CHANGED, NULL);
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index b1d542f2a6b..0eb72e1b8e2 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -402,6 +402,15 @@ void wm_xr_session_toggle(wmXrData *xr_data)
}
}
+/**
+ * Check if a session start was triggered and that there is no pending request to end the session.
+ * If an error happened while trying to start a session, this returns false too.
+ */
+bool WM_xr_session_was_started(const wmXrData *xr)
+{
+ return xr->context && xr->session_state;
+}
+
/**
* The definition used here to define a session as running differs slightly from the OpenXR
* specification one: Here we already consider a session as stopped when session-end request was
@@ -416,7 +425,7 @@ bool WM_xr_session_is_running(const wmXrData *xr)
/* wmXrData.session_state will be NULL if session end was requested. That's what we use here to
* define if the session was already stopped (even if according to OpenXR, it's still considered
* running). */
- return xr->context && xr->session_state && GHOST_XrSessionIsRunning(xr->context);
+ return WM_xr_session_was_started(xr) && GHOST_XrSessionIsRunning(xr->context);
}
/** \} */ /* XR-Session */
More information about the Bf-blender-cvs
mailing list