[Bf-blender-cvs] [2f0d8e799a] HMD_viewport: Use view orientation data from current 3D view for creating HMD view
Julian Eisel
noreply at git.blender.org
Sun Mar 5 18:32:28 CET 2017
Commit: 2f0d8e799aa264267c5dbaf3a48b6b2375b11ace
Author: Julian Eisel
Date: Sun Mar 5 18:31:17 2017 +0100
Branches: HMD_viewport
https://developer.blender.org/rB2f0d8e799aa264267c5dbaf3a48b6b2375b11ace
Use view orientation data from current 3D view for creating HMD view
===================================================================
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/space_view3d/view3d_view.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 79176d9e9c..fd69a911b7 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -360,6 +360,7 @@ char ED_view3d_quat_to_axis_view(const float quat[4], const float epsilon);
char ED_view3d_lock_view_from_index(int index);
char ED_view3d_axis_view_opposite(char view);
bool ED_view3d_lock(struct RegionView3D *rv3d);
+void ED_view3d_copy_region_view_data(const struct RegionView3D *src, struct RegionView3D *dst);
uint64_t ED_view3d_datamask(const struct Scene *scene, const struct View3D *v3d);
uint64_t ED_view3d_screen_datamask(const struct bScreen *screen);
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 8582952d1a..8c2b342b35 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -1024,6 +1024,25 @@ bool ED_view3d_lock(RegionView3D *rv3d)
return ED_view3d_quat_from_axis_view(rv3d->view, rv3d->viewquat);
}
+/**
+ * Copy all view navigation/orientation related data from \a src into \a dst. Local view data is not included.
+ */
+void ED_view3d_copy_region_view_data(const RegionView3D *src, RegionView3D *dst)
+{
+ copy_v4_v4(dst->viewquat, src->viewquat);
+ copy_v3_v3(dst->ofs, src->ofs);
+ copy_v4_v4(dst->lviewquat, src->lviewquat);
+ dst->dist = src->dist;
+ dst->camdx = src->camdx;
+ dst->camdy = src->camdy;
+ dst->pixsize = src->pixsize;
+ dst->camzoom = src->camzoom;
+ dst->persp = src->persp;
+ dst->view = src->view;
+ dst->lpersp = src->lpersp;
+ dst->lview = src->lview;
+}
+
/* don't set windows active in here, is used by renderwin too */
void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d)
{
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 2a3f333e44..14b01bfc1e 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -4130,25 +4130,25 @@ static void WM_OT_stereo3d_set(wmOperatorType *ot)
/* ******************************************************* */
/* Head Mounted Display */
-static void hmd_view_prepare_screen(wmWindowManager *wm, wmWindow *win)
+static void hmd_view_prepare_screen(wmWindowManager *wm, wmWindow *win, const RegionView3D *rv3d_current)
{
- ScrArea *sa = win->screen->areabase.first;
- View3D *v3d = sa->spacedata.first;
- RegionView3D *rv3d = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW)->regiondata;
+ ScrArea *sa_hmd = win->screen->areabase.first;
+ View3D *v3d_hmd = sa_hmd->spacedata.first;
+ RegionView3D *rv3d_hmd = BKE_area_find_region_type(sa_hmd, RGN_TYPE_WINDOW)->regiondata;
- BLI_assert(sa->spacetype == SPACE_VIEW3D);
+ BLI_assert(sa_hmd->spacetype == SPACE_VIEW3D);
/* sync view options */
- v3d->drawtype = wm->hmd_view.view_shade;
+ v3d_hmd->drawtype = wm->hmd_view.view_shade;
if (U.hmd_settings.lensdist_shader != GPU_FX_LENSDIST_NONE) {
- v3d->fx_settings.fx_flag |= GPU_FX_FLAG_LensDist;
+ v3d_hmd->fx_settings.fx_flag |= GPU_FX_FLAG_LensDist;
/* Set distortion type for 3D View but first we need to validate fx settings. */
- BKE_screen_gpu_fx_validate(&v3d->fx_settings);
- v3d->fx_settings.lensdist->type = U.hmd_settings.lensdist_shader;
+ BKE_screen_gpu_fx_validate(&v3d_hmd->fx_settings);
+ v3d_hmd->fx_settings.lensdist->type = U.hmd_settings.lensdist_shader;
}
- rv3d->persp = RV3D_CAMOB;
- rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(1.0f);
+ /* copy view orientation from current 3D view to newly opened HMD view */
+ ED_view3d_copy_region_view_data(rv3d_current, rv3d_hmd);
}
static int wm_hmd_view_toggle_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
@@ -4167,12 +4167,22 @@ static int wm_hmd_view_toggle_invoke(bContext *C, wmOperator *UNUSED(op), const
}
/* open */
else {
+ ARegion *ar_current;
+ View3D *v3d_current;
+ RegionView3D *rv3d_current;
+
rcti rect = {prevwin->posx, prevwin->posx + (int)(prevwin->sizex * 0.9f),
prevwin->posy, prevwin->posy + (int)(prevwin->sizey * 0.9f)};
+
+ /* WM_window_open_restricted changes context, so get current context data first */
+ ED_view3d_context_user_region(C, &v3d_current, &ar_current);
+ rv3d_current = ar_current->regiondata;
+ BLI_assert(v3d_current && ar_current && rv3d_current);
+
win = WM_window_open_restricted(C, &rect, WM_WINDOW_HMD);
wm->hmd_view.hmd_win = win;
- hmd_view_prepare_screen(wm, win);
+ hmd_view_prepare_screen(wm, win, rv3d_current);
}
return OPERATOR_FINISHED;
More information about the Bf-blender-cvs
mailing list