Fix T51354: Final take on multi-view (single view) issues
We now handle selection and transform manipulators (kudos to Julian Eisel to help hunting down the latter).
This commit is contained in:
		@@ -358,7 +358,7 @@ void ED_view3d_draw_offscreen(
 | 
			
		||||
        struct GPUOffScreen *ofs);
 | 
			
		||||
void ED_view3d_draw_setup_view(
 | 
			
		||||
        struct wmWindow *win, struct Scene *scene, struct ARegion *ar, struct View3D *v3d,
 | 
			
		||||
        float viewmat[4][4], float winmat[4][4]);
 | 
			
		||||
        float viewmat[4][4], float winmat[4][4], const struct rcti *rect);
 | 
			
		||||
 | 
			
		||||
struct ImBuf *ED_view3d_draw_offscreen_imbuf(
 | 
			
		||||
        struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey,
 | 
			
		||||
@@ -373,7 +373,9 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
 | 
			
		||||
 | 
			
		||||
struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
 | 
			
		||||
void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);
 | 
			
		||||
void ED_view3d_update_viewmat(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4]);
 | 
			
		||||
void ED_view3d_update_viewmat(
 | 
			
		||||
        struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
 | 
			
		||||
        float viewmat[4][4], float winmat[4][4], const struct rcti *rect);
 | 
			
		||||
bool ED_view3d_quat_from_axis_view(const char view, float quat[4]);
 | 
			
		||||
char ED_view3d_quat_to_axis_view(const float quat[4], const float epsilon);
 | 
			
		||||
char ED_view3d_lock_view_from_index(int index);
 | 
			
		||||
 
 | 
			
		||||
@@ -106,7 +106,7 @@
 | 
			
		||||
 | 
			
		||||
/* prototypes */
 | 
			
		||||
static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d);
 | 
			
		||||
static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar);
 | 
			
		||||
static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect);
 | 
			
		||||
static void view3d_stereo3d_setup_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
 | 
			
		||||
                                            float winmat[4][4], const char *viewname);
 | 
			
		||||
 | 
			
		||||
@@ -2373,7 +2373,7 @@ void ED_view3d_draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d)
 | 
			
		||||
	RegionView3D *rv3d = ar->regiondata;
 | 
			
		||||
 | 
			
		||||
	/* Setup view matrix. */
 | 
			
		||||
	ED_view3d_draw_setup_view(NULL, scene, ar, v3d, rv3d->winmat, rv3d->viewmat);
 | 
			
		||||
	ED_view3d_draw_setup_view(NULL, scene, ar, v3d, rv3d->winmat, rv3d->viewmat, NULL);
 | 
			
		||||
 | 
			
		||||
	glClear(GL_DEPTH_BUFFER_BIT);
 | 
			
		||||
 | 
			
		||||
@@ -2484,7 +2484,7 @@ void ED_view3d_draw_depth(Scene *scene, ARegion *ar, View3D *v3d, bool alphaover
 | 
			
		||||
	U.obcenter_dia = 0;
 | 
			
		||||
	
 | 
			
		||||
	/* Setup view matrix. */
 | 
			
		||||
	ED_view3d_draw_setup_view(NULL, scene, ar, v3d, rv3d->viewmat, rv3d->winmat);
 | 
			
		||||
	ED_view3d_draw_setup_view(NULL, scene, ar, v3d, rv3d->viewmat, rv3d->winmat, NULL);
 | 
			
		||||
	
 | 
			
		||||
	glClear(GL_DEPTH_BUFFER_BIT);
 | 
			
		||||
	
 | 
			
		||||
@@ -2732,7 +2732,8 @@ CustomDataMask ED_view3d_screen_datamask(const bScreen *screen)
 | 
			
		||||
/**
 | 
			
		||||
 * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore
 | 
			
		||||
 */
 | 
			
		||||
void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4])
 | 
			
		||||
void ED_view3d_update_viewmat(
 | 
			
		||||
        Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect)
 | 
			
		||||
{
 | 
			
		||||
	RegionView3D *rv3d = ar->regiondata;
 | 
			
		||||
 | 
			
		||||
@@ -2740,7 +2741,7 @@ void ED_view3d_update_viewmat(Scene *scene, View3D *v3d, ARegion *ar, float view
 | 
			
		||||
	if (winmat)
 | 
			
		||||
		copy_m4_m4(rv3d->winmat, winmat);
 | 
			
		||||
	else
 | 
			
		||||
		view3d_winmatrix_set(ar, v3d, NULL);
 | 
			
		||||
		view3d_winmatrix_set(ar, v3d, rect);
 | 
			
		||||
 | 
			
		||||
	/* setup view matrix */
 | 
			
		||||
	if (viewmat)
 | 
			
		||||
@@ -3003,11 +3004,12 @@ static void view3d_draw_objects(
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void view3d_main_region_setup_view(Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4])
 | 
			
		||||
static void view3d_main_region_setup_view(
 | 
			
		||||
        Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect)
 | 
			
		||||
{
 | 
			
		||||
	RegionView3D *rv3d = ar->regiondata;
 | 
			
		||||
 | 
			
		||||
	ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat);
 | 
			
		||||
	ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat, rect);
 | 
			
		||||
 | 
			
		||||
	/* set for opengl */
 | 
			
		||||
	glMatrixMode(GL_PROJECTION);
 | 
			
		||||
@@ -3190,7 +3192,7 @@ void ED_view3d_draw_offscreen(
 | 
			
		||||
	if ((viewname != NULL && viewname[0] != '\0') && (viewmat == NULL) && rv3d->persp == RV3D_CAMOB && v3d->camera)
 | 
			
		||||
		view3d_stereo3d_setup_offscreen(scene, v3d, ar, winmat, viewname);
 | 
			
		||||
	else
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, NULL);
 | 
			
		||||
 | 
			
		||||
	/* framebuffer fx needed, we need to draw offscreen first */
 | 
			
		||||
	if (v3d->fx_settings.fx_flag && fx) {
 | 
			
		||||
@@ -3255,16 +3257,17 @@ void ED_view3d_draw_offscreen(
 | 
			
		||||
/**
 | 
			
		||||
 * Set the correct matrices
 | 
			
		||||
 */
 | 
			
		||||
void ED_view3d_draw_setup_view(wmWindow *win, Scene *scene, ARegion *ar, View3D *v3d, float viewmat[4][4], float winmat[4][4])
 | 
			
		||||
void ED_view3d_draw_setup_view(
 | 
			
		||||
        wmWindow *win, Scene *scene, ARegion *ar, View3D *v3d, float viewmat[4][4], float winmat[4][4], const rcti *rect)
 | 
			
		||||
{
 | 
			
		||||
	RegionView3D *rv3d = ar->regiondata;
 | 
			
		||||
 | 
			
		||||
	/* Setup the view matrix. */
 | 
			
		||||
	if (view3d_stereo3d_active(win, scene, v3d, rv3d)) {
 | 
			
		||||
		view3d_stereo3d_setup(scene, v3d, ar);
 | 
			
		||||
		view3d_stereo3d_setup(scene, v3d, ar, rect);
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, rect);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -3635,7 +3638,7 @@ static bool view3d_main_region_draw_engine(const bContext *C, Scene *scene,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* setup view matrices */
 | 
			
		||||
	view3d_main_region_setup_view(scene, v3d, ar, NULL, NULL);
 | 
			
		||||
	view3d_main_region_setup_view(scene, v3d, ar, NULL, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
	/* background draw */
 | 
			
		||||
	ED_region_pixelspace(ar);
 | 
			
		||||
@@ -3744,7 +3747,7 @@ static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, Reg
 | 
			
		||||
 * we do a small hack to replace it temporarily so we don't need to change the
 | 
			
		||||
 * view3d)main_region_setup_view() code to account for that.
 | 
			
		||||
 */
 | 
			
		||||
static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar)
 | 
			
		||||
static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect)
 | 
			
		||||
{
 | 
			
		||||
	bool is_left;
 | 
			
		||||
	const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
 | 
			
		||||
@@ -3770,7 +3773,7 @@ static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar)
 | 
			
		||||
		data->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname);
 | 
			
		||||
 | 
			
		||||
		BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, NULL);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, NULL, rect);
 | 
			
		||||
 | 
			
		||||
		data->shiftx = shiftx;
 | 
			
		||||
		BLI_unlock_thread(LOCK_VIEW3D);
 | 
			
		||||
@@ -3784,7 +3787,7 @@ static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar)
 | 
			
		||||
		v3d->camera = camera;
 | 
			
		||||
 | 
			
		||||
		BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, NULL);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, NULL, rect);
 | 
			
		||||
 | 
			
		||||
		v3d->camera = view_ob;
 | 
			
		||||
		BLI_unlock_thread(LOCK_VIEW3D);
 | 
			
		||||
@@ -3800,14 +3803,14 @@ static void view3d_stereo3d_setup_offscreen(Scene *scene, View3D *v3d, ARegion *
 | 
			
		||||
		const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
 | 
			
		||||
 | 
			
		||||
		BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, NULL);
 | 
			
		||||
	}
 | 
			
		||||
	else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
 | 
			
		||||
		float viewmat[4][4];
 | 
			
		||||
		Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
 | 
			
		||||
 | 
			
		||||
		BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat);
 | 
			
		||||
		view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, NULL);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -3846,7 +3849,7 @@ static void view3d_main_region_draw_objects(const bContext *C, Scene *scene, Vie
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Setup the view matrix. */
 | 
			
		||||
	ED_view3d_draw_setup_view(CTX_wm_window(C), scene, ar, v3d, NULL, NULL);
 | 
			
		||||
	ED_view3d_draw_setup_view(CTX_wm_window(C), scene, ar, v3d, NULL, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
	rv3d->rflag &= ~RV3D_IS_GAME_ENGINE;
 | 
			
		||||
#ifdef WITH_GAMEENGINE
 | 
			
		||||
 
 | 
			
		||||
@@ -449,7 +449,7 @@ void ED_view3d_smooth_view_force_finish(
 | 
			
		||||
		/* force update of view matrix so tools that run immediately after
 | 
			
		||||
		 * can use them without redrawing first */
 | 
			
		||||
		Scene *scene = CTX_data_scene(C);
 | 
			
		||||
		ED_view3d_update_viewmat(scene, v3d, ar, NULL, NULL);
 | 
			
		||||
		ED_view3d_update_viewmat(scene, v3d, ar, NULL, NULL, NULL);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1172,9 +1172,8 @@ int view3d_opengl_select(
 | 
			
		||||
 | 
			
		||||
	G.f |= G_PICKSEL;
 | 
			
		||||
 | 
			
		||||
	view3d_winmatrix_set(ar, v3d, &rect);
 | 
			
		||||
	mul_m4_m4m4(vc->rv3d->persmat, vc->rv3d->winmat, vc->rv3d->viewmat);
 | 
			
		||||
	
 | 
			
		||||
	ED_view3d_draw_setup_view(vc->win, scene, ar, v3d, NULL, NULL, &rect);
 | 
			
		||||
 | 
			
		||||
	if (v3d->drawtype > OB_WIRE) {
 | 
			
		||||
		v3d->zbuf = true;
 | 
			
		||||
		glEnable(GL_DEPTH_TEST);
 | 
			
		||||
@@ -1199,8 +1198,7 @@ int view3d_opengl_select(
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	G.f &= ~G_PICKSEL;
 | 
			
		||||
	view3d_winmatrix_set(ar, v3d, NULL);
 | 
			
		||||
	mul_m4_m4m4(vc->rv3d->persmat, vc->rv3d->winmat, vc->rv3d->viewmat);
 | 
			
		||||
	ED_view3d_draw_setup_view(vc->win, scene, ar, v3d, NULL, NULL, NULL);
 | 
			
		||||
	
 | 
			
		||||
	if (v3d->drawtype > OB_WIRE) {
 | 
			
		||||
		v3d->zbuf = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -1716,7 +1716,7 @@ void BIF_draw_manipulator(const bContext *C)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], float hotspot)
 | 
			
		||||
static int manipulator_selectbuf(Scene *scene, ScrArea *sa, ARegion *ar, const int mval[2], float hotspot)
 | 
			
		||||
{
 | 
			
		||||
	View3D *v3d = sa->spacedata.first;
 | 
			
		||||
	RegionView3D *rv3d = ar->regiondata;
 | 
			
		||||
@@ -1726,9 +1726,6 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], fl
 | 
			
		||||
	const bool is_picksel = true;
 | 
			
		||||
	const bool do_passes = GPU_select_query_check_active();
 | 
			
		||||
 | 
			
		||||
	/* XXX check a bit later on this... (ton) */
 | 
			
		||||
	extern void view3d_winmatrix_set(ARegion *ar, View3D *v3d, const rcti *rect);
 | 
			
		||||
 | 
			
		||||
	/* when looking through a selected camera, the manipulator can be at the
 | 
			
		||||
	 * exact same position as the view, skip so we don't break selection */
 | 
			
		||||
	if (fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f)
 | 
			
		||||
@@ -1739,8 +1736,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], fl
 | 
			
		||||
	rect.ymin = mval[1] - hotspot;
 | 
			
		||||
	rect.ymax = mval[1] + hotspot;
 | 
			
		||||
 | 
			
		||||
	view3d_winmatrix_set(ar, v3d, &rect);
 | 
			
		||||
	mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
 | 
			
		||||
	ED_view3d_draw_setup_view(NULL, scene, ar, v3d, NULL, NULL, &rect);
 | 
			
		||||
 | 
			
		||||
	if (do_passes)
 | 
			
		||||
		GPU_select_begin(buffer, 64, &rect, GPU_SELECT_NEAREST_FIRST_PASS, 0);
 | 
			
		||||
@@ -1775,8 +1771,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], fl
 | 
			
		||||
		GPU_select_end();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view3d_winmatrix_set(ar, v3d, NULL);
 | 
			
		||||
	mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
 | 
			
		||||
	ED_view3d_draw_setup_view(NULL, scene, ar, v3d, NULL, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
	if (hits == 1) return buffer[3];
 | 
			
		||||
	else if (hits > 1) {
 | 
			
		||||
@@ -1841,6 +1836,7 @@ static const char *manipulator_get_operator_name(int man_val)
 | 
			
		||||
/* return 0; nothing happened */
 | 
			
		||||
int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmOperator *op)
 | 
			
		||||
{
 | 
			
		||||
	Scene *scene = CTX_data_scene(C);
 | 
			
		||||
	ScrArea *sa = CTX_wm_area(C);
 | 
			
		||||
	View3D *v3d = sa->spacedata.first;
 | 
			
		||||
	ARegion *ar = CTX_wm_region(C);
 | 
			
		||||
@@ -1855,7 +1851,7 @@ int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmOperator *op)
 | 
			
		||||
	RNA_enum_set(op->ptr, "constraint_orientation", v3d->twmode);
 | 
			
		||||
 | 
			
		||||
	// find the hotspots first test narrow hotspot
 | 
			
		||||
	val = manipulator_selectbuf(sa, ar, event->mval, 0.5f * (float)U.tw_hotspot);
 | 
			
		||||
	val = manipulator_selectbuf(scene, sa, ar, event->mval, 0.5f * (float)U.tw_hotspot);
 | 
			
		||||
	if (val) {
 | 
			
		||||
		wmOperatorType *ot;
 | 
			
		||||
		PointerRNA props_ptr;
 | 
			
		||||
@@ -1863,7 +1859,7 @@ int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmOperator *op)
 | 
			
		||||
		const char *opname;
 | 
			
		||||
 | 
			
		||||
		// drawflags still global, for drawing call above
 | 
			
		||||
		drawflags = manipulator_selectbuf(sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
 | 
			
		||||
		drawflags = manipulator_selectbuf(scene, sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
 | 
			
		||||
		if (drawflags == 0) drawflags = val;
 | 
			
		||||
 | 
			
		||||
		/* Planar constraint doesn't make sense for rotation, give other keymaps a chance */
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,7 @@ static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d)
 | 
			
		||||
 | 
			
		||||
		v3d = (View3D *)sa->spacedata.first;
 | 
			
		||||
 | 
			
		||||
		ED_view3d_update_viewmat(sc->scene, v3d, ar, NULL, NULL);
 | 
			
		||||
		ED_view3d_update_viewmat(sc->scene, v3d, ar, NULL, NULL, NULL);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user