diff options
author | Habib Gahbiche <habibgahbiche@gmail.com> | 2018-11-07 03:01:50 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-11-07 03:56:33 +0300 |
commit | 4e9911663a22766f6751d33ae84c1ebcc1fae559 (patch) | |
tree | 4d4e043ffaf16a81427e92caba77220407ea329c /source/blender/editors/util/select_utils.c | |
parent | c19dafd2a62fe0bebe6f834017b108e77d133682 (diff) |
Multi-Objects: CURVE_OT_select_similar
Implemented the following methods:
* SIMCURHAND_TYPE
* SIMCURHAND_RADIUS
* SIMCURHAND_WEIGHT
* SIMCURHAND_DIRECTION
Limits:
* DIRECTION does not support surfaces, because `BKE_nurb_bpoint_calc_normal`
does not work with Nurbs of type `CU_CARDINAL`. This also didn't work prior
to this patch, so we wait until surfaces are properly supported in EditMode.
* Also DIRECTION should take scaling into consideration. We need our own
versions of BKE_nurb_bpoint_calc_normal/bezt.
* Threshold default is too large. Not sure if it's better to change the default
or scale the threshold in code.
Differential Revision: https://developer.blender.org/D3846
Changes from committer (Dalai Felinto):
* Moved nurb_bpoint_direction_worldspace_get/bezt to functions.
* Comments hinting at the mode (direction) that require scaling to be
taken into account - to be addressed by patch creator in a future
patch.
Diffstat (limited to 'source/blender/editors/util/select_utils.c')
-rw-r--r-- | source/blender/editors/util/select_utils.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/editors/util/select_utils.c b/source/blender/editors/util/select_utils.c index dee49e11efb..92de124800b 100644 --- a/source/blender/editors/util/select_utils.c +++ b/source/blender/editors/util/select_utils.c @@ -23,9 +23,13 @@ */ #include "BLI_utildefines.h" +#include "BLI_kdtree.h" +#include "BLI_math.h" #include "ED_select_utils.h" +#include "float.h" + /** 1: select, 0: deselect, -1: pass. */ int ED_select_op_action(const eSelectOp sel_op, const bool is_select, const bool is_inside) { @@ -68,3 +72,54 @@ int ED_select_op_action_deselected(const eSelectOp sel_op, const bool is_select, BLI_assert(!"invalid sel_op"); return -1; } + +int ED_select_similar_compare_float(const float delta, const float thresh, const int compare) +{ + switch (compare) { + case SIM_CMP_EQ: + return (fabsf(delta) < thresh + FLT_EPSILON); + case SIM_CMP_GT: + return ((delta + thresh) > -FLT_EPSILON); + case SIM_CMP_LT: + return ((delta - thresh) < FLT_EPSILON); + default: + BLI_assert(0); + return 0; + } +} + +bool ED_select_similar_compare_float_tree(const KDTree *tree, const float length, const float thresh, const int compare) +{ + /* Length of the edge we want to compare against. */ + float nearest_edge_length; + + switch (compare) { + case SIM_CMP_EQ: + /* Compare to the edge closest to the current edge. */ + nearest_edge_length = length; + break; + case SIM_CMP_GT: + /* Compare against the shortest edge. */ + /* -FLT_MAX leads to some precision issues and the wrong edge being selected. + * For example, in a tree with 1, 2 and 3, which is stored squared as 1, 4, 9, it returns as the nearest + * length/node the "4" instead of "1". */ + nearest_edge_length = -1.0f; + break; + case SIM_CMP_LT: + /* Compare against the longest edge. */ + nearest_edge_length = FLT_MAX; + break; + default: + BLI_assert(0); + return false; + } + + KDTreeNearest nearest; + float dummy[3] = {nearest_edge_length, 0.0f, 0.0f}; + if (BLI_kdtree_find_nearest(tree, dummy, &nearest) != -1) { + float delta = length - nearest.co[0]; + return ED_select_similar_compare_float(delta, thresh, compare); + } + + return false; +} |