diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-09-14 13:51:04 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-09-14 13:53:52 +0300 |
commit | 34843a855e6b45cffbc0cd0ffae2d688e6ee1168 (patch) | |
tree | 1a90816443ce788ef67ae994d33b0a7d3dfb5096 /source/blender/blenkernel/intern/object.c | |
parent | 2db71782e750313fc2c7d0a420e0fab6e06e38d4 (diff) |
Fix T46099: snapping failed on objects with some NULL-dimension in their bbox.
Added a helper that ensures a bbox has some non-NULL dimension along all its axes.
Also, fixed some (rather unlikely) NULL dereference cases (though it should not in this context,
`BKE_object_boundbox_get()` can return NULL).
Diffstat (limited to 'source/blender/blenkernel/intern/object.c')
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index fa20607ce30..526a71b477d 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2665,6 +2665,66 @@ void BKE_boundbox_minmax(const BoundBox *bb, float obmat[4][4], float r_min[3], } } +/** + * 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. + * + * \param bb the input bbox to check. + * \param bb_temp the temp bbox to modify (\a bb content is never changed). + * \param epsilon the minimum dimension to ensure. + * \return either bb (if nothing needed to be changed) or bb_temp. + */ +BoundBox *BKE_boundbox_ensure_minimum_dimensions(BoundBox *bb, BoundBox *bb_temp, const float epsilon) +{ + if (fabsf(bb->vec[0][0] - bb->vec[4][0]) < epsilon) { + /* Flat along X axis... */ + *bb_temp = *bb; + bb = bb_temp; + bb->vec[0][0] -= epsilon; + bb->vec[1][0] -= epsilon; + bb->vec[2][0] -= epsilon; + bb->vec[3][0] -= epsilon; + bb->vec[4][0] += epsilon; + bb->vec[5][0] += epsilon; + bb->vec[6][0] += epsilon; + bb->vec[7][0] += epsilon; + } + + if (fabsf(bb->vec[0][1] - bb->vec[3][1]) < epsilon) { + /* Flat along Y axis... */ + if (bb != bb_temp) { + *bb_temp = *bb; + bb = bb_temp; + } + bb->vec[0][1] -= epsilon; + bb->vec[1][1] -= epsilon; + bb->vec[4][1] -= epsilon; + bb->vec[5][1] -= epsilon; + bb->vec[2][1] += epsilon; + bb->vec[3][1] += epsilon; + bb->vec[6][1] += epsilon; + bb->vec[7][1] += epsilon; + } + + if (fabsf(bb->vec[0][2] - bb->vec[1][2]) < epsilon) { + /* Flat along Z axis... */ + if (bb != bb_temp) { + *bb_temp = *bb; + bb = bb_temp; + } + bb->vec[0][2] -= epsilon; + bb->vec[3][2] -= epsilon; + bb->vec[4][2] -= epsilon; + bb->vec[7][2] -= epsilon; + bb->vec[1][2] += epsilon; + bb->vec[2][2] += epsilon; + bb->vec[5][2] += epsilon; + bb->vec[6][2] += epsilon; + } + + return bb; +} + BoundBox *BKE_object_boundbox_get(Object *ob) { BoundBox *bb = NULL; |