[Bf-blender-cvs] [d14017cdcba] sculpt-mode-features: View Navigation: 2D viewport zooming

Pablo Dobarro noreply at git.blender.org
Sat Mar 30 21:28:43 CET 2019


Commit: d14017cdcba43df7bfb5b5ef52145e2ed60b60cc
Author: Pablo Dobarro
Date:   Sat Mar 30 21:27:56 2019 +0100
Branches: sculpt-mode-features
https://developer.blender.org/rBd14017cdcba43df7bfb5b5ef52145e2ed60b60cc

View Navigation: 2D viewport zooming

This implements the same concept of 2D viewport panning but for zooming.
It prevents unexpected zoom speeds when working with a pen tablet.
Zoom speed is constant and it is based on the initial distance to the
working area. Speed parameters are hardcoded for now, but they can be
exposed as options or replaced by a variable zoom speed.
I also reduced the rotation speed when 2D viewport panning is enabled
for consistency.
This navigation mode is enabled by activating 2D viewport panning in the
navigation preferences. That option should be renamed in the future.
Enabling and disabling perspective is broken most of the time, but it
also happens in master. I'm not sure if these changes are making the
problem worse.

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

M	source/blender/editors/space_view3d/view3d_edit.c

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

diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 30756b671ae..9c57975ba8b 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -162,6 +162,7 @@ typedef struct ViewOpsData {
 		float trackvec[3];
 		/** Dolly only. */
 		float mousevec[3];
+		float viewpos[3];
 	} init;
 
 	/** Previous state (previous modal event handled). */
@@ -511,6 +512,8 @@ static void viewops_data_create(
 	if (rv3d->persmat[2][1] < 0.0f)
 		vod->reverse = -1.0f;
 
+	copy_v3_v3(vod->init.viewpos, rv3d->viewinv[3]);
+
 	rv3d->rflag |= RV3D_NAVIGATING;
 }
 
@@ -728,6 +731,10 @@ static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2])
 
 		angle = (len_v3(dvec) / (2.0f * TRACKBALLSIZE)) * (float)M_PI;
 
+		if (U.uiflag2 & USER_2D_VIEWPORT_PANNING) {
+			angle *= 0.6f;
+		}
+
 		/* Allow for rotation beyond the interval [-pi, pi] */
 		angle = angle_wrap_rad(angle);
 
@@ -2051,25 +2058,61 @@ static void viewzoom_apply_3d(
 	float zfac;
 	float dist_range[2];
 
-	ED_view3d_dist_range_get(vod->v3d, dist_range);
+	float center[3], new_ofs[3], vt[3], view_dir[3];
+	float center_dist, event_dist, zf, new_dist, ft;
 
-	zfac = viewzoom_scale_value_offset(
-	       &vod->ar->winrct, viewzoom, zoom_invert, false,
-	       xy, vod->init.event_xy, vod->init.event_xy_offset,
-	       vod->rv3d->dist, vod->init.dist,
-	       &vod->prev.time);
+	ED_view3d_dist_range_get(vod->v3d, dist_range);
 
-	if (zfac != 1.0f) {
-		const float zfac_min = dist_range[0] / vod->rv3d->dist;
-		const float zfac_max = dist_range[1] / vod->rv3d->dist;
-		CLAMP(zfac, zfac_min, zfac_max);
+	if (U.uiflag2 & USER_2D_VIEWPORT_PANNING) {
+		view3d_orbit_calc_center(vod->C, center);
+		center_dist = len_v3v3(center, vod->init.viewpos);
 
-		view_zoom_to_window_xy_3d(
-		        vod->ar, zfac, zoom_to_pos ? vod->prev.event_xy : NULL);
+		if (U.uiflag & USER_ZOOM_HORIZ) {
+			event_dist = vod->init.event_xy[0] - xy[0];
+			event_dist = event_dist / vod->ar->sizex;
+		}
+		else {
+			event_dist = vod->init.event_xy[1] - xy[1];
+			event_dist = event_dist / vod->ar->sizey;
+		}
+		event_dist = event_dist * 400;
+
+		copy_v3_v3(view_dir, vod->rv3d->viewinv[2]);
+		mul_v3_fl(view_dir, -1.0f);
+		normalize_v3(view_dir);
+		zf = 0.005f * center_dist;
+		CLAMP(zf, 0, 0.05f);
+		if (vod->rv3d->is_persp) {
+			mul_v3_v3fl(vt, view_dir, event_dist * zf);
+			copy_v3_v3(new_ofs, vod->init.ofs);
+			add_v3_v3(new_ofs, vt);
+			copy_v3_v3(vod->rv3d->ofs, new_ofs);
+		}
+		else {
+			ft = event_dist * zf * 2.0f;
+			new_dist =  vod->init.dist + ft;
+			vod->rv3d->dist = new_dist;
+		}
 	}
+	else {
+		zfac = viewzoom_scale_value_offset(
+		       &vod->ar->winrct, viewzoom, zoom_invert, false,
+		       xy, vod->init.event_xy, vod->init.event_xy_offset,
+		       vod->rv3d->dist, vod->init.dist,
+		       &vod->prev.time);
+
+		if (zfac != 1.0f) {
+			const float zfac_min = dist_range[0] / vod->rv3d->dist;
+			const float zfac_max = dist_range[1] / vod->rv3d->dist;
+			CLAMP(zfac, zfac_min, zfac_max);
+
+			view_zoom_to_window_xy_3d(
+				vod->ar, zfac, zoom_to_pos ? vod->prev.event_xy : NULL);
+		}
 
-	/* these limits were in old code too */
-	CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]);
+		/* these limits were in old code too */
+		CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]);
+	}
 
 	if (vod->rv3d->viewlock & RV3D_BOXVIEW) {
 		view3d_boxview_sync(vod->sa, vod->ar);



More information about the Bf-blender-cvs mailing list