From c3e7dfa82d1734505dfb82d68690bab9544795ee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Nov 2015 12:13:49 +1100 Subject: Fix T46816: Vert/Edge snap fails at edge of bounds --- source/blender/blenkernel/BKE_object.h | 1 + source/blender/blenkernel/intern/object.c | 12 ++++++++++++ source/blender/editors/transform/transform_snap.c | 7 +++++++ 3 files changed, 20 insertions(+) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 91ea55f07f9..af3185becf4 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 b30538719ae..70da0111752 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 4f003830238..2251dedc268 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; } -- cgit v1.2.3