[Bf-blender-cvs] [4950ce4cd9] HMD_viewport: Don't allow orthographic view in HMD view

Julian Eisel noreply at git.blender.org
Sun Mar 5 22:03:48 CET 2017


Commit: 4950ce4cd9c886c4fa885a3ad63b215c50542893
Author: Julian Eisel
Date:   Sun Mar 5 21:56:49 2017 +0100
Branches: HMD_viewport
https://developer.blender.org/rB4950ce4cd9c886c4fa885a3ad63b215c50542893

Don't allow orthographic view in HMD view

Displaying camera in orthographic mode is still allowed. We don't want
to mess with render data and forcing perspective viewport rendering in
HMD view even if the camera is set to be orthographic might be
confusing.

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

M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_view3d/view3d_camera_control.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index afc05354b3..1b06e93b32 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3016,7 +3016,8 @@ static void view3d_localview_update_rv3d(struct RegionView3D *rv3d)
 {
 	if (rv3d->localvd) {
 		rv3d->localvd->view = rv3d->view;
-		rv3d->localvd->persp = rv3d->persp;
+		rv3d->localvd->persp = ((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) && (rv3d->localvd->persp == RV3D_ORTHO)) ?
+		                            RV3D_PERSP : rv3d->persp;
 		copy_qt_qt(rv3d->localvd->viewquat, rv3d->viewquat);
 	}
 }
@@ -3030,6 +3031,7 @@ static void region_quadview_init_rv3d(ScrArea *sa, ARegion *ar,
 		ED_view3d_lastview_store(rv3d);
 	}
 
+	BLI_assert((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) == 0 || view != RV3D_ORTHO);
 	rv3d->viewlock = viewlock;
 	rv3d->view = view;
 	rv3d->persp = persp;
diff --git a/source/blender/editors/space_view3d/view3d_camera_control.c b/source/blender/editors/space_view3d/view3d_camera_control.c
index f717f1c0a4..59e94f7a5b 100644
--- a/source/blender/editors/space_view3d/view3d_camera_control.c
+++ b/source/blender/editors/space_view3d/view3d_camera_control.c
@@ -304,7 +304,8 @@ void ED_view3d_cameracontrol_release(
 		else {
 			/* Non Camera we need to reset the view back to the original location bacause the user canceled*/
 			copy_qt_qt(rv3d->viewquat, vctrl->rot_backup);
-			rv3d->persp = vctrl->persp_backup;
+			rv3d->persp = ((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) && vctrl != RV3D_ORTHO) ?
+			                  vctrl->persp_backup : RV3D_PERSP;
 		}
 		/* always, is set to zero otherwise */
 		copy_v3_v3(rv3d->ofs, vctrl->ofs_backup);
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 5e13b3f27f..ca7d9447be 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -269,7 +269,7 @@ static void view3d_persp_switch_from_camera(View3D *v3d, RegionView3D *rv3d, con
 	}
 
 	if (!ED_view3d_camera_lock_check(v3d, rv3d)) {
-		rv3d->persp = persp;
+		rv3d->persp = ((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) && persp != RV3D_ORTHO) ? persp : RV3D_PERSP;
 	}
 }
 
@@ -505,6 +505,7 @@ void ED_view3d_quadview_update(ScrArea *sa, ARegion *ar, bool do_clip)
 					if (!RV3D_VIEW_IS_AXIS(rv3d->view)) {
 						rv3d->view = ED_view3d_lock_view_from_index(index_qsplit);
 						rv3d->persp = RV3D_ORTHO;
+						BLI_assert((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) == 0);
 						ED_view3d_lock(rv3d);
 					}
 				}
@@ -3820,7 +3821,12 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
 	}
 
 	if (U.uiflag & USER_AUTOPERSP) {
-		rv3d->persp = RV3D_VIEW_IS_AXIS(view) ? RV3D_ORTHO : perspo;
+		if (RV3D_VIEW_IS_AXIS(view)) {
+			rv3d->persp = (rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) ? RV3D_PERSP : RV3D_ORTHO;
+		}
+		else {
+			rv3d->persp = perspo;
+		}
 	}
 	else if (rv3d->persp == RV3D_CAMOB) {
 		rv3d->persp = perspo;
@@ -4415,9 +4421,12 @@ static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op))
 	rv3d = ar->regiondata;
 
 	if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
-		if (rv3d->persp != RV3D_ORTHO)
+		if (rv3d->persp != RV3D_ORTHO && (rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) == 0) {
 			rv3d->persp = RV3D_ORTHO;
-		else rv3d->persp = RV3D_PERSP;
+		}
+		else {
+			rv3d->persp = RV3D_PERSP;
+		}
 		ED_region_tag_redraw(ar);
 	}
 
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 8c2b342b35..3356abd3b0 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -279,6 +279,7 @@ void ED_view3d_smooth_view_ex(
 				                (sview->camera->type == OB_CAMERA) &&
 				                (((Camera *)sview->camera->data)->type == CAM_ORTHO)) ?
 				                RV3D_ORTHO : RV3D_PERSP);
+				BLI_assert((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) == 0 || rv3d->persp == RV3D_PERSP);
 			}
 
 			rv3d->rflag |= RV3D_NAVIGATING;
@@ -917,6 +918,8 @@ void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rctf *rect)
 	
 	is_ortho = ED_view3d_viewplane_get(v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
 	rv3d->is_persp = !is_ortho;
+	/* don't check for is_persp in assert, we allow showing orthographic camera view even with LOCK_PERSP_VIEW */
+	BLI_assert((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) == 0 || rv3d->persp != RV3D_ORTHO);
 
 #if 0
 	printf("%s: %d %d %f %f %f %f %f %f\n", __func__, winx, winy,
@@ -1038,6 +1041,7 @@ void ED_view3d_copy_region_view_data(const RegionView3D *src, RegionView3D *dst)
 	dst->pixsize = src->pixsize;
 	dst->camzoom = src->camzoom;
 	dst->persp = src->persp;
+	BLI_assert((dst->viewlock & RV3D_LOCK_PERSP_VIEW) == 0 || dst->persp != RV3D_ORTHO);
 	dst->view = src->view;
 	dst->lpersp = src->lpersp;
 	dst->lview = src->lview;
@@ -1484,7 +1488,8 @@ static void restore_localviewdata(wmWindowManager *wm, wmWindow *win, Main *bmai
 				camera_old_rv3d = (rv3d->persp          == RV3D_CAMOB) ? camera_old : NULL;
 				camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : NULL;
 
-				rv3d->view = rv3d->localvd->view;
+				rv3d->view = ((rv3d->viewlock & RV3D_LOCK_PERSP_VIEW) && rv3d->localvd->view == RV3D_ORTHO) ?
+				                 RV3D_PERSP : rv3d->localvd->view;
 				rv3d->persp = rv3d->localvd->persp;
 				rv3d->camzoom = rv3d->localvd->camzoom;
 
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index dbe71e3162..6759da8907 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -280,13 +280,19 @@ typedef struct View3D {
  */
 #define RV3D_ZOFFSET_DISABLED		64
 
-/* RegionView3d->viewlock */
-#define RV3D_LOCKED			(1 << 0)
-#define RV3D_BOXVIEW		(1 << 1)
-#define RV3D_BOXCLIP		(1 << 2)
-#define RV3D_LOCKED_SHARED	(RV3D_LOCKED | (1 << 3)) /* uses viewdata from another rv3d so view manipulation is disabled. */
-/* RegionView3d->viewlock_quad */
-#define RV3D_VIEWLOCK_INIT	(1 << 7)
+enum {
+	/* RegionView3d->viewlock */
+	RV3D_LOCKED          = (1 << 0),
+	RV3D_BOXVIEW         = (1 << 1),
+	RV3D_BOXCLIP         = (1 << 2),
+	/* uses viewdata from another rv3d so view manipulation is disabled */
+	RV3D_LOCKED_SHARED   = (RV3D_LOCKED | (1 << 3)),
+	/* Don't allow changing to othographic view. Note that orthographic camera views are allowed though. */
+	RV3D_LOCK_PERSP_VIEW = (1 << 4),
+
+	/* RegionView3d->viewlock_quad */
+	RV3D_VIEWLOCK_INIT   = (1 << 7),
+};
 
 /* check if the region is both, locked and shared */
 #define RV3D_IS_LOCKED_SHARED(rv3d) (((rv3d)->viewlock & RV3D_LOCKED_SHARED) == RV3D_LOCKED_SHARED)
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 14b01bfc1e..37c5bd2e5e 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -4241,14 +4241,20 @@ static int hmd_session_toggle_invoke(bContext *C, wmOperator *UNUSED(op), const
 	}
 
 	if (hmd_win->screen->is_hmd_running) {
+		/* exit session */
 		hmd_win->screen->is_hmd_running = false;
 		WM_window_fullscreen_toggle(hmd_win, false, true);
 		WM_device_HMD_state_set(U.hmd_settings.device, false);
+		hmd_session_disable_viewlocks(wm);
+
 		return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
 	}
 	else {
+		/* start session */
 		ScrArea *sa = hmd_win->screen->areabase.first;
-		BLI_assert(sa->spacetype = SPACE_VIEW3D);
+		ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+		RegionView3D *rv3d = ar->regiondata;
+		BLI_assert(ar && sa->spacetype == SPACE_VIEW3D);
 
 		hmd_win->screen->is_hmd_running = true;
 		WM_device_HMD_state_set(U.hmd_settings.device, true);
@@ -4256,8 +4262,11 @@ static int hmd_session_toggle_invoke(bContext *C, wmOperator *UNUSED(op), const
 			U.hmd_settings.init_ipd = WM_device_HMD_IPD_get();
 			WM_device_HMD_IPD_set(U.hmd_settings.custom_ipd);
 		}
-		hmd_session_disable_viewlocks(wm);
 
+		if (rv3d->persp == RV3D_ORTHO) {
+			rv3d->persp = RV3D_PERSP;
+		}
+		rv3d->viewlock |= RV3D_LOCK_PERSP_VIEW;
 		WM_window_fullscreen_toggle(hmd_win, true, false);
 
 		return OPERATOR_FINISHED;




More information about the Bf-blender-cvs mailing list