[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56287] trunk/blender/source: ruler snap adjustments

Campbell Barton ideasman42 at gmail.com
Thu Apr 25 11:39:04 CEST 2013


Revision: 56287
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56287
Author:   campbellbarton
Date:     2013-04-25 09:39:03 +0000 (Thu, 25 Apr 2013)
Log Message:
-----------
ruler snap adjustments
- when in wireframe mode: don't snap to faces, instead snap to the closest edge/vertex.
- when not in wireframe mode: snap to the front-most element (was a problem that it could snap to an edge/vert behind the face)
- reduce the distance for selecting ruler points, was too easy to accidentally drag a ruler.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_transform.h
    trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c
    trunk/blender/source/blender/editors/transform/transform_snap.c
    trunk/blender/source/tools/check_style_c_config.py

Modified: trunk/blender/source/blender/editors/include/ED_transform.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_transform.h	2013-04-25 08:13:46 UTC (rev 56286)
+++ trunk/blender/source/blender/editors/include/ED_transform.h	2013-04-25 09:39:03 UTC (rev 56287)
@@ -186,7 +186,8 @@
 bool snapObjectsContext(struct bContext *C, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode);
 /* taks args for all settings */
 bool snapObjectsEx(struct Scene *scene, struct Base *base_act, struct View3D *v3d, struct ARegion *ar, struct Object *obedit, short snap_mode,
-                   const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode);
+                   const float mval[2], float *r_dist_px,
+                   float r_loc[3], float r_no[3], float *r_ray_dist, SnapMode mode);
 bool snapObjectsRayEx(struct Scene *scene, struct Base *base_act, struct View3D *v3d, struct ARegion *ar, struct Object *obedit, short snap_mode,
                       struct Object **r_ob, float r_obmat[4][4],
                       const float ray_start[3], const float ray_normal[3], float *r_ray_dist,

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c	2013-04-25 08:13:46 UTC (rev 56286)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_ruler.c	2013-04-25 09:39:03 UTC (rev 56287)
@@ -27,6 +27,7 @@
 /* defines VIEW3D_OT_ruler modal operator */
 
 #include "DNA_scene_types.h"
+#include "DNA_object_types.h"
 #include "DNA_gpencil_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -60,11 +61,27 @@
 /* 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], float r_no[3],
+#define MVAL_MAX_PX_DIST 12.0f
+
+/**
+ * Convenience function for performing snapping.
+ *
+ * \param C  Context.
+ * \param r_co  hit location.
+ * \param r_no  hit normal (optional).
+ * \param co_ss  Screenspace coordinate.
+ * \param use_depth  Snap to the closest element, use when using more then one snap type.
+ * \param use_vert  Snap to verts.
+ * \param use_edge  Snap to edges.
+ * \param use_face  Snap to faces.
+ * \return Snap success
+ */
+static bool ED_view3d_snap_co(bContext *C, float r_co[3], float r_no[3], const float co_ss[2], bool use_depth,
                               bool use_vert, bool use_edge, bool use_face)
 {
-	float dist_px = 12;  /* snap dist */
+	float dist_px = MVAL_MAX_PX_DIST;  /* snap dist */
 	float r_no_dummy[3];
+	float ray_dist = TRANSFORM_DIST_MAX_RAY;
 	bool ret = false;
 	float *r_no_ptr = r_no ? r_no : r_no_dummy;
 
@@ -73,18 +90,22 @@
 	ARegion *ar = CTX_wm_region(C);
 	struct Object *obedit = CTX_data_edit_object(C);
 
+	BLI_assert(use_vert || use_edge || use_face);
+
 	/* 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_ptr, SNAP_ALL);
+		                    co_ss, &dist_px, r_co, r_no_ptr, &ray_dist, SNAP_ALL);
 	}
-	if (use_edge && (ret == false)) {
+	if (use_edge && (ret == false || use_depth)) {
+		if (use_depth == false) ray_dist = TRANSFORM_DIST_MAX_RAY;
 		ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_EDGE,
-		                    co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
+		                    co_ss, &dist_px, r_co, r_no_ptr, &ray_dist, SNAP_ALL);
 	}
-	if (use_face && (ret == false)) {
+	if (use_face && (ret == false || use_depth)) {
+		if (use_depth == false) ray_dist = TRANSFORM_DIST_MAX_RAY;
 		ret = snapObjectsEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_FACE,
-		                    co_ss, &dist_px, r_co, r_no_ptr, SNAP_ALL);
+		                    co_ss, &dist_px, r_co, r_no_ptr, &ray_dist, SNAP_ALL);
 	}
 
 	return ret;
@@ -93,7 +114,7 @@
 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 dist_px = MVAL_MAX_PX_DIST;  /* snap dist */
 	float r_no_dummy[3];
 	float ray_dist = TRANSFORM_DIST_MAX_RAY;
 	bool ret;
@@ -126,7 +147,8 @@
 	RULERITEM_DIRECTION_OUT
 };
 
-#define RULER_PICK_DIST 75.0f
+/* keep smaller then selection, since we may want click elsewhere without selecting a ruler */
+#define RULER_PICK_DIST 12.0f
 #define RULER_PICK_DIST_SQ (RULER_PICK_DIST * RULER_PICK_DIST)
 
 typedef struct RulerItem {
@@ -690,7 +712,7 @@
 
 			co_other = ruler_item->co[ruler_item->co_index == 0 ? 2 : 0];
 
-			if (ED_view3d_snap_co(C, co, mval_fl, ray_normal,
+			if (ED_view3d_snap_co(C, co, ray_normal, mval_fl, true,
 			                      false, false, true))
 			{
 				negate_v3(ray_normal);
@@ -702,8 +724,10 @@
 		}
 		else if (do_snap) {
 			const float mval_fl[2] = {UNPACK2(mval)};
-			ED_view3d_snap_co(C, co, mval_fl, NULL,
-			                  true, true, true);
+			View3D *v3d = CTX_wm_view3d(C);
+			bool use_depth = (v3d->drawtype >= OB_SOLID);
+			ED_view3d_snap_co(C, co, NULL, mval_fl, use_depth,
+			                  true, true, use_depth);
 		}
 		return true;
 	}

Modified: trunk/blender/source/blender/editors/transform/transform_snap.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_snap.c	2013-04-25 08:13:46 UTC (rev 56286)
+++ trunk/blender/source/blender/editors/transform/transform_snap.c	2013-04-25 09:39:03 UTC (rev 56287)
@@ -1615,10 +1615,10 @@
 	return retval;
 }
 static bool snapObjects(Scene *scene, short snap_mode, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit,
-                        const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
+                        const float mval[2], float *r_dist_px,
+                        float r_loc[3], float r_no[3], float *r_ray_dist, SnapMode mode)
 {
 	float ray_start[3], ray_normal[3];
-	float ray_dist = TRANSFORM_DIST_MAX_RAY;
 
 	if (ED_view3d_win_to_ray(ar, v3d, mval, ray_start, ray_normal, true) == false) {
 		return false;
@@ -1626,14 +1626,15 @@
 
 	return snapObjectsRay(scene, snap_mode, base_act, v3d, ar, obedit,
 	                      NULL, NULL,
-	                      ray_start, ray_normal, &ray_dist,
+	                      ray_start, ray_normal, r_ray_dist,
 	                      mval, r_dist_px, r_loc, r_no, mode);
 }
 
 bool snapObjectsTransform(TransInfo *t, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
 {
+	float ray_dist = TRANSFORM_DIST_MAX_RAY;
 	return snapObjects(t->scene, t->scene->toolsettings->snap_mode, t->scene->basact, t->view, t->ar, t->obedit,
-	                   mval, r_dist_px, r_loc, r_no, mode);
+	                   mval, r_dist_px, r_loc, r_no, &ray_dist, mode);
 }
 
 bool snapObjectsContext(bContext *C, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
@@ -1643,15 +1644,19 @@
 	Scene *scene = CTX_data_scene(C);
 	ARegion *ar = CTX_wm_region(C);
 	Object *obedit = CTX_data_edit_object(C);
+	float ray_dist = TRANSFORM_DIST_MAX_RAY;
 
-	return snapObjects(scene, scene->toolsettings->snap_mode, scene->basact, v3d, ar, obedit, mval, r_dist_px, r_loc, r_no, mode);
+	return snapObjects(scene, scene->toolsettings->snap_mode, scene->basact, v3d, ar, obedit,
+	                   mval, r_dist_px, r_loc, r_no, &ray_dist, mode);
 }
 
 bool snapObjectsEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, short snap_mode,
-                   const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode)
+                   const float mval[2], float *r_dist_px,
+                   float r_loc[3], float r_no[3], float *r_ray_dist, SnapMode mode)
 {
 	return snapObjects(scene, snap_mode, base_act, v3d, ar, obedit,
-	                   mval, r_dist_px, r_loc, r_no, mode);
+	                   mval, r_dist_px,
+	                   r_loc, r_no, r_ray_dist, mode);
 }
 bool snapObjectsRayEx(Scene *scene, Base *base_act, View3D *v3d, ARegion *ar, Object *obedit, short snap_mode,
                       Object **r_ob, float r_obmat[4][4],

Modified: trunk/blender/source/tools/check_style_c_config.py
===================================================================
--- trunk/blender/source/tools/check_style_c_config.py	2013-04-25 08:13:46 UTC (rev 56286)
+++ trunk/blender/source/tools/check_style_c_config.py	2013-04-25 09:39:03 UTC (rev 56287)
@@ -40,7 +40,6 @@
     "source/blender/editors/space_logic",
     "source/blender/freestyle",
     "source/blender/gpu",
-    "source/blender/nodes",
     )
 
 




More information about the Bf-blender-cvs mailing list