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

This commit is contained in:
Campbell Barton 2015-11-24 12:13:49 +11:00
parent 68922e4660
commit c3e7dfa82d
Notes: blender-bot 2023-02-14 08:25:17 +01:00
Referenced by issue #46862, Triangulate Beauty Ngon method leaves unfilled triangles.
Referenced by issue #46816, Ruler/Protractor: strange behavior in Snap function.
3 changed files with 20 additions and 0 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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;
}