[Bf-blender-cvs] [b701c92] master: Code cleanup:

Antony Riakiotakis noreply at git.blender.org
Mon Mar 24 22:46:50 CET 2014


Commit: b701c92588f16b25c773b1d7ba6d71a0122bbb64
Author: Antony Riakiotakis
Date:   Mon Mar 24 23:46:30 2014 +0200
https://developer.blender.org/rBb701c92588f16b25c773b1d7ba6d71a0122bbb64

Code cleanup:

* Separate some common code for sculpt raycasting
* Cleanup to radial operator commit

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

M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 06a9182..5f47de3 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -4309,52 +4309,62 @@ static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin)
 	}
 }
 
+static float sculpt_raycast_init (ViewContext *vc, const float mouse[2], float ray_start[3], float ray_end[3], float ray_normal[3], bool original)
+{
+	float obimat[4][4];
+	float dist;
+	Object *ob = vc->obact;
+	RegionView3D *rv3d = vc->ar->regiondata;
+
+	/* TODO: what if the segment is totally clipped? (return == 0) */
+	ED_view3d_win_to_segment(vc->ar, vc->v3d, mouse, ray_start, ray_end, true);
+
+	invert_m4_m4(obimat, ob->obmat);
+	mul_m4_v3(obimat, ray_start);
+	mul_m4_v3(obimat, ray_end);
+
+	sub_v3_v3v3(ray_normal, ray_end, ray_start);
+	dist = normalize_v3(ray_normal);
+
+	if (!rv3d->is_persp) {
+		BKE_pbvh_raycast_project_ray_root(ob->sculpt->pbvh, original, ray_start, ray_end, ray_normal);
+
+		/* recalculate the normal */
+		sub_v3_v3v3(ray_normal, ray_end, ray_start);
+		dist = normalize_v3(ray_normal);
+	}
+
+	return dist;
+}
+
 /* Do a raycast in the tree to find the 3d brush location
  * (This allows us to ignore the GL depth buffer)
  * Returns 0 if the ray doesn't hit the mesh, non-zero otherwise
  */
 bool sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2])
 {
-	ViewContext vc;
 	Object *ob;
 	SculptSession *ss;
 	StrokeCache *cache;
 	float ray_start[3], ray_end[3], ray_normal[3], dist;
-	float obimat[4][4];
 	SculptRaycastData srd;
 	bool original;
-	RegionView3D *rv3d;
+	ViewContext vc;
 
 	view3d_set_viewcontext(C, &vc);
-	
-	rv3d = vc.ar->regiondata;
+
 	ob = vc.obact;
+
 	ss = ob->sculpt;
 	cache = ss->cache;
 	original = (cache) ? cache->original : 0;
 
 	sculpt_stroke_modifiers_check(C, ob);
 
-	/* TODO: what if the segment is totally clipped? (return == 0) */
-	ED_view3d_win_to_segment(vc.ar, vc.v3d, mouse, ray_start, ray_end, true);
-
-	invert_m4_m4(obimat, ob->obmat);
-	mul_m4_v3(obimat, ray_start);
-	mul_m4_v3(obimat, ray_end);
-
-	sub_v3_v3v3(ray_normal, ray_end, ray_start);
-	dist = normalize_v3(ray_normal);
-
-	if (!rv3d->is_persp) {
-		BKE_pbvh_raycast_project_ray_root(ss->pbvh, original, ray_start, ray_end, ray_normal);
-
-		/* recalculate the normal */
-		sub_v3_v3v3(ray_normal, ray_end, ray_start);
-		dist = normalize_v3(ray_normal);
-	}
+	dist = sculpt_raycast_init (&vc, mouse, ray_start, ray_end, ray_normal, original);
 
 	srd.original = original;
-	srd.ss = vc.obact->sculpt;
+	srd.ss = ob->sculpt;
 	srd.hit = 0;
 	srd.ray_start = ray_start;
 	srd.ray_normal = ray_normal;
@@ -5304,36 +5314,16 @@ static void sample_detail(bContext *C, int ss_co[2])
 	Object *ob;
 	Sculpt *sd;
 	float ray_start[3], ray_end[3], ray_normal[3], dist;
-	float obimat[4][4];
 	SculptDetailRaycastData srd;
-	RegionView3D *rv3d;
 	float mouse[2] = {ss_co[0], ss_co[1]};
 	view3d_set_viewcontext(C, &vc);
 
-	rv3d = vc.ar->regiondata;
-	ob = vc.obact;
-
 	sd = CTX_data_tool_settings(C)->sculpt;
+	ob = vc.obact;
 
 	sculpt_stroke_modifiers_check(C, ob);
 
-	/* TODO: what if the segment is totally clipped? (return == 0) */
-	ED_view3d_win_to_segment(vc.ar, vc.v3d, mouse, ray_start, ray_end, true);
-
-	invert_m4_m4(obimat, ob->obmat);
-	mul_m4_v3(obimat, ray_start);
-	mul_m4_v3(obimat, ray_end);
-
-	sub_v3_v3v3(ray_normal, ray_end, ray_start);
-	dist = normalize_v3(ray_normal);
-
-	if (!rv3d->is_persp) {
-		BKE_pbvh_raycast_project_ray_root(ob->sculpt->pbvh, false, ray_start, ray_end, ray_normal);
-
-		/* recalculate the normal */
-		sub_v3_v3v3(ray_normal, ray_end, ray_start);
-		dist = normalize_v3(ray_normal);
-	}
+	dist = sculpt_raycast_init (&vc, mouse, ray_start, ray_end, ray_normal, false);
 
 	srd.hit = 0;
 	srd.ray_start = ray_start;
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 8b06a40..50db233 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3779,6 +3779,9 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
 		case PROP_ANGLE:
 			r1 = r2 = tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE;
 			alpha = 0.75;
+			rmin = WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE;
+			BLI_snprintf(str, WM_RADIAL_MAX_STR, "%3f", RAD2DEGF(rc->current_value));
+			strdrawlen = BLI_strlen_utf8(str);
 			break;
 		default:
 			tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE; /* note, this is a dummy value */
@@ -3822,14 +3825,8 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
 		glRotatef(RAD2DEGF(rc->current_value - rc->initial_value), 0, 0, 1);
 		fdrawline((float)WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE, 0.0f, (float)WM_RADIAL_CONTROL_DISPLAY_SIZE, 0.0f);
 		glPopMatrix();
-		rmin = WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE;
-		BLI_snprintf(str, WM_RADIAL_MAX_STR, "%3f", RAD2DEGF(rc->current_value));
-		strdrawlen = BLI_strlen_utf8(str);
 	}
 
-	/* adjust dpi for rmin here to account for angle */
-	rmin *= U.pixelsize;
-
 	/* draw circles on top */
 	glutil_draw_lined_arc(0.0, (float)(M_PI * 2.0), r1, 40);
 	glutil_draw_lined_arc(0.0, (float)(M_PI * 2.0), r2, 40);




More information about the Bf-blender-cvs mailing list