[Bf-blender-cvs] [c3e7dfa] master: Fix T46816: Vert/Edge snap fails at edge of bounds

Campbell Barton noreply at git.blender.org
Tue Nov 24 02:23:05 CET 2015


Commit: c3e7dfa82d1734505dfb82d68690bab9544795ee
Author: Campbell Barton
Date:   Tue Nov 24 12:13:49 2015 +1100
Branches: master
https://developer.blender.org/rBc3e7dfa82d1734505dfb82d68690bab9544795ee

Fix T46816: Vert/Edge snap fails at edge of bounds

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/transform/transform_snap.c

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 91ea55f..af3185b 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -144,6 +144,7 @@ bool BKE_boundbox_ray_hit_check(
 void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]);
 void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]);
 void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3]);
+void BKE_boundbox_scale(struct BoundBox *bb_dst, const struct BoundBox *bb_src, float scale);
 struct BoundBox *BKE_boundbox_ensure_minimum_dimensions(
         struct BoundBox *bb, struct BoundBox *bb_temp, const float epsilon);
 
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index b305387..70da011 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2682,6 +2682,18 @@ void BKE_boundbox_minmax(const BoundBox *bb, float obmat[4][4], float r_min[3],
 	}
 }
 
+void BKE_boundbox_scale(struct BoundBox *bb_dst, const struct BoundBox *bb_src, float scale)
+{
+	float cent[3];
+	BKE_boundbox_calc_center_aabb(bb_src, cent);
+
+	for (int i = 0; i < ARRAY_SIZE(bb_dst->vec); i++) {
+		bb_dst->vec[i][0] = ((bb_src->vec[i][0] - cent[0]) * scale) + cent[0];
+		bb_dst->vec[i][1] = ((bb_src->vec[i][1] - cent[1]) * scale) + cent[1];
+		bb_dst->vec[i][2] = ((bb_src->vec[i][2] - cent[2]) * scale) + cent[2];
+	}
+}
+
 /**
  * Returns a BBox which each dimensions are at least epsilon.
  * \note In case a given dimension needs to be enlarged, its final value will be in [epsilon, 3 * epsilon] range.
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 4f00383..2251ded 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -1546,6 +1546,13 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
 				 * Threshold is rather high, but seems to be needed to get good behavior, see T46099. */
 				bb = BKE_boundbox_ensure_minimum_dimensions(bb, &bb_temp, 1e-1f);
 
+				/* Exact value here is arbitrary (ideally we would scale in pixel-space based on 'r_dist_px'),
+				 * scale up so we can snap against verts & edges on the boundbox, see T46816. */
+				if (ELEM(snap_mode, SCE_SNAP_MODE_VERTEX, SCE_SNAP_MODE_EDGE)) {
+					BKE_boundbox_scale(&bb_temp, bb, 1.0f + 1e-1f);
+					bb = &bb_temp;
+				}
+
 				if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) {
 					return retval;
 				}




More information about the Bf-blender-cvs mailing list