[Bf-blender-cvs] [66720194840] blender2.8: Gizmo: use simple unclipped win_to_ray function

Campbell Barton noreply at git.blender.org
Thu Sep 20 04:02:47 CEST 2018


Commit: 66720194840b11bdfb0f26e4191d1f214cdc2e8e
Author: Campbell Barton
Date:   Thu Sep 20 12:13:11 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB66720194840b11bdfb0f26e4191d1f214cdc2e8e

Gizmo: use simple unclipped win_to_ray function

When projecting the cursor onto a plane, clipping isn't important.

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

M	source/blender/editors/gizmo_library/gizmo_library_utils.c
M	source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
M	source/blender/editors/mesh/editmesh_add_gizmo.c

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

diff --git a/source/blender/editors/gizmo_library/gizmo_library_utils.c b/source/blender/editors/gizmo_library/gizmo_library_utils.c
index 0995a73ebfc..e3b93e671df 100644
--- a/source/blender/editors/gizmo_library/gizmo_library_utils.c
+++ b/source/blender/editors/gizmo_library/gizmo_library_utils.c
@@ -186,7 +186,6 @@ bool gizmo_window_project_2d(
 	/* rotate mouse in relation to the center and relocate it */
 	if (gz->parent_gzgroup->type->flag & WM_GIZMOGROUPTYPE_3D) {
 		/* For 3d views, transform 2D mouse pos onto plane. */
-		View3D *v3d = CTX_wm_view3d(C);
 		ARegion *ar = CTX_wm_region(C);
 
 		float plane[4];
@@ -194,19 +193,18 @@ bool gizmo_window_project_2d(
 		plane_from_point_normal_v3(plane, mat[3], mat[2]);
 
 		float ray_origin[3], ray_direction[3];
-
-		if (ED_view3d_win_to_ray_clipped(CTX_data_depsgraph(C), ar, v3d, mval, ray_origin, ray_direction, false)) {
-			float lambda;
-			if (isect_ray_plane_v3(ray_origin, ray_direction, plane, &lambda, true)) {
-				float co[3];
-				madd_v3_v3v3fl(co, ray_origin, ray_direction, lambda);
-				float imat[4][4];
-				invert_m4_m4(imat, mat);
-				mul_m4_v3(imat, co);
-				r_co[0] = co[(axis + 1) % 3];
-				r_co[1] = co[(axis + 2) % 3];
-				return true;
-			}
+		float lambda;
+
+		ED_view3d_win_to_ray(ar, mval, ray_origin, ray_direction);
+		if (isect_ray_plane_v3(ray_origin, ray_direction, plane, &lambda, true)) {
+			float co[3];
+			madd_v3_v3v3fl(co, ray_origin, ray_direction, lambda);
+			float imat[4][4];
+			invert_m4_m4(imat, mat);
+			mul_m4_v3(imat, co);
+			r_co[0] = co[(axis + 1) % 3];
+			r_co[1] = co[(axis + 2) % 3];
+			return true;
 		}
 		return false;
 	}
diff --git a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
index 8b504befa16..4e41f95a063 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c
@@ -239,7 +239,6 @@ static int gizmo_arrow_modal(
 	}
 	ArrowGizmo3D *arrow = (ArrowGizmo3D *)gz;
 	GizmoInteraction *inter = gz->interaction_data;
-	View3D *v3d = CTX_wm_view3d(C);
 	ARegion *ar = CTX_wm_region(C);
 	RegionView3D *rv3d = ar->regiondata;
 
@@ -264,31 +263,28 @@ static int gizmo_arrow_modal(
 	int ok = 0;
 
 	for (int j = 0; j < 2; j++) {
-		if (ED_view3d_win_to_ray_clipped(
-		            CTX_data_depsgraph(C),
-		            ar, v3d, proj[j].mval,
-		            proj[j].ray_origin, proj[j].ray_direction, false))
-		{
-			/* Force Y axis if we're view aligned */
-			if (j == 0) {
-				if (RAD2DEGF(acosf(dot_v3v3(proj[j].ray_direction, arrow->gizmo.matrix_basis[2]))) < 5.0f) {
-					normalize_v3_v3(arrow_no, rv3d->viewinv[1]);
-				}
+		ED_view3d_win_to_ray(
+		        ar, proj[j].mval,
+		        proj[j].ray_origin, proj[j].ray_direction);
+		/* Force Y axis if we're view aligned */
+		if (j == 0) {
+			if (RAD2DEGF(acosf(dot_v3v3(proj[j].ray_direction, arrow->gizmo.matrix_basis[2]))) < 5.0f) {
+				normalize_v3_v3(arrow_no, rv3d->viewinv[1]);
 			}
+		}
 
-			float arrow_no_proj[3];
-			project_plane_v3_v3v3(arrow_no_proj, arrow_no, proj[j].ray_direction);
+		float arrow_no_proj[3];
+		project_plane_v3_v3v3(arrow_no_proj, arrow_no, proj[j].ray_direction);
 
-			normalize_v3(arrow_no_proj);
+		normalize_v3(arrow_no_proj);
 
-			float plane[4];
-			plane_from_point_normal_v3(plane, proj[j].ray_origin, arrow_no_proj);
+		float plane[4];
+		plane_from_point_normal_v3(plane, proj[j].ray_origin, arrow_no_proj);
 
-			float lambda;
-			if (isect_ray_plane_v3(arrow_co, arrow_no, plane, &lambda, false)) {
-				madd_v3_v3v3fl(proj[j].location, arrow_co, arrow_no, lambda);
-				ok++;
-			}
+		float lambda;
+		if (isect_ray_plane_v3(arrow_co, arrow_no, plane, &lambda, false)) {
+			madd_v3_v3v3fl(proj[j].location, arrow_co, arrow_no, lambda);
+			ok++;
 		}
 	}
 
diff --git a/source/blender/editors/mesh/editmesh_add_gizmo.c b/source/blender/editors/mesh/editmesh_add_gizmo.c
index 4e8985d2a9b..850ca27d26a 100644
--- a/source/blender/editors/mesh/editmesh_add_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_add_gizmo.c
@@ -100,19 +100,16 @@ static void calc_initial_placement_point_from_view(
 
 	if (use_mouse_project) {
 		float ray_co[3], ray_no[3];
-		if (ED_view3d_win_to_ray_clipped(
-		            CTX_data_depsgraph(C),
-		            ar, v3d, mval,
-		            ray_co, ray_no, false))
-		{
-			float plane[4];
-			plane_from_point_normal_v3(plane, cursor_matrix[3], orient_matrix[2]);
-			float lambda;
-			if (isect_ray_plane_v3(ray_co, ray_no, plane, &lambda, true)) {
-				madd_v3_v3v3fl(r_location, ray_co, ray_no, lambda);
-				copy_m3_m3(r_rotation, orient_matrix);
-				return;
-			}
+		ED_view3d_win_to_ray(
+		        ar, mval,
+		        ray_co, ray_no);
+		float plane[4];
+		plane_from_point_normal_v3(plane, cursor_matrix[3], orient_matrix[2]);
+		float lambda;
+		if (isect_ray_plane_v3(ray_co, ray_no, plane, &lambda, true)) {
+			madd_v3_v3v3fl(r_location, ray_co, ray_no, lambda);
+			copy_m3_m3(r_rotation, orient_matrix);
+			return;
 		}
 	}



More information about the Bf-blender-cvs mailing list