[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55754] trunk/blender/source/blender/ editors/space_view3d/view3d_ruler.c: new ruler option to be able to interactively measure surface thichness as you drag the ruler about .

Campbell Barton ideasman42 at gmail.com
Wed Apr 3 12:45:13 CEST 2013


Revision: 55754
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55754
Author:   campbellbarton
Date:     2013-04-03 10:45:13 +0000 (Wed, 03 Apr 2013)
Log Message:
-----------
new ruler option to be able to interactively measure surface thichness as you drag the ruler about.
Request from Bart Veldhuizen.

Access with Shift+Drag

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c	2013-04-03 09:48:21 UTC (rev 55753)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c	2013-04-03 10:45:13 UTC (rev 55754)
@@ -60,12 +60,13 @@
 /* NOTE - this is not very nice use of transform snapping */
 #include "ED_transform.h"
 
-static bool ED_view3d_snap_co(bContext *C, float r_co[3], const float co_ss[2],
+static bool ED_view3d_snap_co(bContext *C, float r_co[3], const float co_ss[2], float r_no[3],
                               bool use_vert, bool use_edge, bool use_face)
 {
 	float dist_px = 12;  /* snap dist */
 	float r_no_dummy[3];
 	bool ret = false;
+	float *r_no_ptr = r_no ? r_no : r_no_dummy;
 
 	Scene *scene = CTX_data_scene(C);
 	View3D *v3d = CTX_wm_view3d(C);
@@ -75,19 +76,39 @@
 	/* try snap edge, then face if it fails */
 	if (use_vert) {
 		ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_VERTEX,
-		                    co_ss, &dist_px, r_co, r_no_dummy, SNAP_ALL);
+		                    co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
 	}
 	if (use_edge && (ret == false)) {
 		ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_EDGE,
-		                    co_ss, &dist_px, r_co, r_no_dummy, SNAP_ALL);
+		                    co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
 	}
 	if (use_face && (ret == false)) {
 		ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_FACE,
-		                    co_ss, &dist_px, r_co, r_no_dummy, SNAP_ALL);
+		                    co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
 	}
 
 	return ret;
 }
+
+static bool ED_view3d_snap_ray(bContext *C, float r_co[3],
+                               const float ray_start[3], const float ray_normal[3])
+{
+	float dist_px = 12;  /* snap dist */
+	float r_no_dummy[3];
+	bool ret = false;
+
+	Scene *scene = CTX_data_scene(C);
+	View3D *v3d = CTX_wm_view3d(C);
+	ARegion *ar = CTX_wm_region(C);
+	struct Object *obedit = CTX_data_edit_object(C);
+
+	/* try snap edge, then face if it fails */
+	ret = snapObjectsRayEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_FACE,
+	                       ray_start, ray_normal,
+	                       NULL, &dist_px, r_co, r_no_dummy, SNAP_ALL);
+
+	return ret;
+}
 /* done snapping */
 
 
@@ -646,17 +667,37 @@
 }
 
 /* use for mousemove events */
-static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, const int mval[2], const bool do_snap)
+static bool view3d_ruler_item_mousemove(bContext *C, RulerInfo *ruler_info, const int mval[2],
+                                        const bool do_thickness, const bool do_snap)
 {
 	RulerItem *ruler_item = ruler_item_active_get(ruler_info);
 
 	if (ruler_item) {
 		float *co = ruler_item->co[ruler_item->co_index];
 		view3d_ruler_item_project(ruler_info, co, mval);
-		if (do_snap) {
+		if (do_thickness && ruler_item->co_index != 1) {
 			const float mval_fl[2] = {UNPACK2(mval)};
-			ED_view3d_snap_co(C, co, mval_fl, true, true, true);
+			float ray_normal[3];
+			float ray_start[3];
+			float *co_other;
+
+			co_other = ruler_item->co[ruler_item->co_index == 0 ? 2 : 0];
+
+			if (ED_view3d_snap_co(C, co, mval_fl, ray_normal,
+			                      false, false, true))
+			{
+				negate_v3(ray_normal);
+				/* add some bias */
+				madd_v3_v3v3fl(ray_start, co, ray_normal, 0.0001f);
+				ED_view3d_snap_ray(C, co_other,
+				                   ray_start, ray_normal);
+			}
 		}
+		else if (do_snap) {
+			const float mval_fl[2] = {UNPACK2(mval)};
+			ED_view3d_snap_co(C, co, mval_fl, NULL,
+			                  true, true, true);
+		}
 		return true;
 	}
 	else {
@@ -669,6 +710,7 @@
 	const char *text = "Ctrl+LMB: Add, "
 	                   "Del: Remove, "
 	                   "Ctrl+Drag: Snap, "
+	                   "Shift+Drag: Thickness, "
 	                   "Ctrl+C: Copy Value, "
 	                   "Enter: Store,  "
 	                   "Esc: Cancel";
@@ -763,7 +805,7 @@
 						/* snap the first point added, not essential but handy */
 						{
 							ruler_item->co_index = 0;
-							view3d_ruler_item_mousemove(C, ruler_info, event->mval, true);
+							view3d_ruler_item_mousemove(C, ruler_info, event->mval, event->shift != 0, true);
 						}
 
 						copy_v3_v3(ruler_item->co[2], ruler_item->co[0]);
@@ -803,7 +845,8 @@
 									}
 
 									/* update the new location */
-									view3d_ruler_item_mousemove(C, ruler_info, event->mval, event->ctrl != 0);
+									view3d_ruler_item_mousemove(C, ruler_info, event->mval,
+									                            event->shift != 0, event->ctrl != 0);
 									do_draw = true;
 								}
 							}
@@ -846,7 +889,8 @@
 		case MOUSEMOVE:
 		{
 			if (ruler_info->state == RULER_STATE_DRAG) {
-				if (view3d_ruler_item_mousemove(C, ruler_info, event->mval, event->ctrl != 0)) {
+				if (view3d_ruler_item_mousemove(C, ruler_info, event->mval,
+				                                event->shift != 0, event->ctrl != 0)) {
 					do_draw = true;
 				}
 			}




More information about the Bf-blender-cvs mailing list