[Bf-blender-cvs] [7b5fe4f] master: Fix flickering when transform snapping in edit mode and cursor is slightly outside the mesh.

Antony Riakiotakis noreply at git.blender.org
Thu Jun 12 00:44:01 CEST 2014


Commit: 7b5fe4f316234022a0ab761b694cd459ce98db2d
Author: Antony Riakiotakis
Date:   Thu Jun 12 01:43:38 2014 +0300
https://developer.blender.org/rB7b5fe4f316234022a0ab761b694cd459ce98db2d

Fix flickering when transform snapping in edit mode and cursor is
slightly outside the mesh.

Reported by Thomas Beck on irc. Issue here is that the mesh bounding box
changes as we are transforming the vertices. Solution is to collide
against the initial bounding box. Unfortunately the snapping functions
are made in a way that a lot of code needed to be tweaked here, but the
change should be straightforward and harmless (famous last words, I
know).

Ideally we might want to even increase the size of the bounding box a
little (as seen in screen space) to allow snapping even in cases where,
cursor is slightly outside the bounding box, but since this is not so
straightforward to do for all cases, at least for me, leaving this as
a TODO.

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

M	source/blender/editors/armature/editarmature_sketch.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/space_view3d/view3d_ruler.c
M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_snap.c
M	source/blender/makesrna/intern/rna_scene_api.c

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

diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c
index 475ffd2..56c39e4 100644
--- a/source/blender/editors/armature/editarmature_sketch.c
+++ b/source/blender/editors/armature/editarmature_sketch.c
@@ -1088,7 +1088,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S
 		mval[1] = dd->mval[1];
 
 		/* try to snap to closer object */
-		found = snapObjectsContext(C, mval, &dist_px, vec, no, SNAP_NOT_SELECTED);
+		found = snapObjectsContext(C, mval, &dist_px, vec, no, SNAP_NOT_SELECTED, NULL);
 		if (found == 1) {
 			pt->type = dd->type;
 			pt->mode = PT_SNAP;
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 61fe30e..0512980 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -5240,7 +5240,7 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 			const float mval[2] = {UNPACK2(event->mval)};
 			float no_dummy[3];
 			float dist_px_dummy;
-			snapObjectsContext(C, mval, &dist_px_dummy, location, no_dummy, SNAP_NOT_OBEDIT);
+			snapObjectsContext(C, mval, &dist_px_dummy, location, no_dummy, SNAP_NOT_OBEDIT, NULL);
 		}
 
 		RNA_float_set_array(op->ptr, "location", location);
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 41ff9b8..cfe6a7b 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -110,6 +110,7 @@ struct ScrArea;
 struct Base;
 struct Scene;
 struct Object;
+struct BoundBox;
 
 /* UNUSED */
 // int BIF_snappingSupported(struct Object *obedit);
@@ -180,15 +181,15 @@ typedef enum SnapMode {
 bool peelObjectsTransForm(struct TransInfo *t, struct ListBase *depth_peels, const float mval[2], SnapMode mode);
 bool peelObjectsContext(struct bContext *C, struct ListBase *depth_peels, const float mval[2], SnapMode mode);
 bool snapObjectsTransform(struct TransInfo *t, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode);
-bool snapObjectsContext(struct bContext *C, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode);
+bool snapObjectsContext(struct bContext *C, const float mval[2], float *r_dist_px, float r_loc[3], float r_no[3], SnapMode mode, struct BoundBox *bb_init);
 /* 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], float *r_ray_dist, SnapMode mode);
+                   float r_loc[3], float r_no[3], float *r_ray_dist, SnapMode mode, struct BoundBox *bb_init);
 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,
-                      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], SnapMode mode, struct BoundBox *bb_init);
 
 bool snapNodesTransform(struct TransInfo *t, const int mval[2], float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode);
 bool snapNodesContext(struct bContext *C, const int mval[2], float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode);
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 55ad303..12e7f00 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -305,7 +305,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
 			float mval[2], co_proj[3], no_dummy[3];
 			float dist_px_dummy;
 			if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-				if (snapObjectsContext(C, mval, &dist_px_dummy, co_proj, no_dummy, SNAP_NOT_OBEDIT)) {
+				if (snapObjectsContext(C, mval, &dist_px_dummy, co_proj, no_dummy, SNAP_NOT_OBEDIT, NULL)) {
 					mul_v3_m4v3(eve->co, obedit->imat, co_proj);
 				}
 			}
diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c
index 9d0a70e..6288b8c 100644
--- a/source/blender/editors/space_view3d/view3d_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_ruler.c
@@ -97,17 +97,17 @@ static bool ED_view3d_snap_co(bContext *C, float r_co[3], float r_no[3], const f
 	/* 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, &ray_dist, SNAP_ALL);
+		                     co_ss, &dist_px, r_co, r_no_ptr, &ray_dist, SNAP_ALL, NULL);
 	}
 	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, &ray_dist, SNAP_ALL);
+		                     co_ss, &dist_px, r_co, r_no_ptr, &ray_dist, SNAP_ALL, NULL);
 	}
 	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, &ray_dist, SNAP_ALL);
+		                     co_ss, &dist_px, r_co, r_no_ptr, &ray_dist, SNAP_ALL, NULL);
 	}
 
 	return ret;
@@ -130,7 +130,7 @@ static bool ED_view3d_snap_ray(bContext *C, float r_co[3],
 	ret = snapObjectsRayEx(scene, NULL, v3d, ar, obedit, SCE_SNAP_MODE_FACE,
 	                       NULL, NULL,
 	                       ray_start, ray_normal, &ray_dist,
-	                       NULL, &dist_px, r_co, r_no_dummy, SNAP_ALL);
+	                       NULL, &dist_px, r_co, r_no_dummy, SNAP_ALL, NULL);
 
 	return ret;
 }
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index 1c3e223..991c38f 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -393,7 +393,7 @@ static bool walk_floor_distance_get(bContext *C, RegionView3D *rv3d, WalkInfo *w
 	ret = snapObjectsRayEx(CTX_data_scene(C), NULL, NULL, NULL, NULL, SCE_SNAP_MODE_FACE,
 	                       NULL, NULL,
 	                       ray_start, ray_normal, r_distance,
-	                       NULL, &dummy_dist_px, r_location, r_normal, SNAP_ALL);
+	                       NULL, &dummy_dist_px, r_location, r_normal, SNAP_ALL, NULL);
 
 	/* artifically scale the distance to the scene size */
 	*r_distance /= walk->grid;
@@ -426,7 +426,7 @@ static bool walk_ray_cast(bContext *C, RegionView3D *rv3d, WalkInfo *walk, float
 	ret = snapObjectsRayEx(CTX_data_scene(C), NULL, NULL, NULL, NULL, SCE_SNAP_MODE_FACE,
 	                       NULL, NULL,
 	                       ray_start, ray_normal, ray_distance,
-	                       NULL, &dummy_dist_px, r_location, r_normal, SNAP_ALL);
+	                       NULL, &dummy_dist_px, r_location, r_normal, SNAP_ALL, NULL);
 
 
 	/* dot is positive if both rays are facing the same direction */
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index ae7e21f..4915297 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -38,6 +38,7 @@
 #include "ED_view3d.h"
 
 #include "DNA_listBase.h"
+#include "DNA_object_types.h"
 
 #include "BLI_smallhash.h"
 #include "BKE_editmesh.h"
@@ -98,6 +99,7 @@ typedef struct TransSnap {
 	void  (*targetSnap)(struct TransInfo *);
 	/* Get the transform distance between two points (used by Closest snap) */
 	float  (*distance)(struct TransInfo *, const float p1[3], const float p2[3]);
+	struct BoundBox BB_init;
 } TransSnap;
 
 typedef struct TransCon {
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 9afc12a..2da6b92 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -514,6 +514,10 @@ static void initSnappingMode(TransInfo *t)
 			else {
 				t->tsnap.modeSelect = t->tsnap.snap_self ? SNAP_ALL : SNAP_NOT_OBEDIT;
 			}
+
+			/* store the original bounding box -
+			 * we could slightly increase the size in screen space but leaving as TODO */
+			t->tsnap.BB_init = *BKE_object_boundbox_get(obedit);
 		}
 		/* Particles edit mode*/
 		else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
@@ -1489,13 +1493,12 @@ static bool snapCurve(short snap_mode, ARegion *ar, Object *ob, Curve *cu, float
 
 static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, BMEditMesh *em, float obmat[4][4],
                             const float ray_start[3], const float ray_normal[3], const float ray_origin[3],
-                            const float mval[2], float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth)
+                            const float mval[2], float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth, BoundBox *bb_init)
 {
 	bool retval = false;
 	int totvert = dm->getNumVerts(dm);
 
 	if (totvert > 0) {
-		BoundBox *bb;
 		float imat[4][4];
 		float timat[3][3]; /* transpose inverse matrix for normals */
 		float ray_start_local[3], ray_normal_local[3], local_scale, len_diff = TRANSFORM_DIST_MAX_RAY;
@@ -1513,8 +1516,9 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
 		/* local scale in normal direction */
 		local_scale = normalize_v3(ray_normal_local);
 
-		bb = BKE_object_boundbox_get(ob);
-		if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) {
+		if (!bb_init)
+			bb_init = BKE_object_boundbo

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list