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/mesh | |
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/mesh')
-rw-r--r-- | source/blender/editors/mesh/editmesh_select_similar.c | 70 |
1 files changed, 7 insertions, 63 deletions
diff --git a/source/blender/editors/mesh/editmesh_select_similar.c b/source/blender/editors/mesh/editmesh_select_similar.c index 49675c2deb0..d33802dca05 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.c +++ b/source/blender/editors/mesh/editmesh_select_similar.c @@ -51,6 +51,7 @@ #include "ED_mesh.h" #include "ED_screen.h" +#include "ED_select_utils.h" #include "mesh_intern.h" /* own include */ @@ -58,12 +59,6 @@ /** \name Select Similar (Vert/Edge/Face) Operator - common * \{ */ -enum { - SIM_CMP_EQ = 0, - SIM_CMP_GT, - SIM_CMP_LT -}; - static const EnumPropertyItem prop_similar_compare_types[] = { {SIM_CMP_EQ, "EQUAL", 0, "Equal", ""}, {SIM_CMP_GT, "GREATER", 0, "Greater", ""}, @@ -105,21 +100,6 @@ static const EnumPropertyItem prop_similar_types[] = { {0, NULL, 0, NULL, NULL} }; -static int mesh_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; - } -} - static int mesh_select_similar_compare_int(const int delta, const int compare) { switch (compare) { @@ -135,42 +115,6 @@ static int mesh_select_similar_compare_int(const int delta, const int compare) } } -static bool mesh_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 mesh_select_similar_compare_float(delta, thresh, compare); - } - - return false; -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -497,7 +441,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) case SIMFACE_AREA: { float area = BM_face_calc_area(face); - if (mesh_select_similar_compare_float_tree(tree, area, thresh, compare)) { + if (ED_select_similar_compare_float_tree(tree, area, thresh, compare)) { select = true; } break; @@ -505,7 +449,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) case SIMFACE_PERIMETER: { float perimeter = BM_face_calc_perimeter(face); - if (mesh_select_similar_compare_float_tree(tree, perimeter, thresh, compare)) { + if (ED_select_similar_compare_float_tree(tree, perimeter, thresh, compare)) { select = true; } break; @@ -904,7 +848,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op) /* Proceed only if we have to select all the edges that have custom data value of 0.0f. * In this case we will just select all the edges. * Otherwise continue the for loop. */ - if (!mesh_select_similar_compare_float_tree(tree, 0.0f, thresh, compare)) { + if (!ED_select_similar_compare_float_tree(tree, 0.0f, thresh, compare)) { continue; } } @@ -952,7 +896,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op) case SIMEDGE_LENGTH: { float length = edge_length_squared_worldspace_get(ob, edge); - if (mesh_select_similar_compare_float_tree(tree, length, thresh, compare)) { + if (ED_select_similar_compare_float_tree(tree, length, thresh, compare)) { select = true; } break; @@ -961,7 +905,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op) { if (BM_edge_face_count_at_most(edge, 2) == 2) { float angle = BM_edge_calc_face_angle(edge); - if (mesh_select_similar_compare_float_tree(tree, angle, thresh, SIM_CMP_EQ)) { + if (ED_select_similar_compare_float_tree(tree, angle, thresh, SIM_CMP_EQ)) { select = true; } } @@ -1008,7 +952,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op) } const float *value = CustomData_bmesh_get(&bm->edata, edge->head.data, custom_data_type); - if (mesh_select_similar_compare_float_tree(tree, *value, thresh, compare)) { + if (ED_select_similar_compare_float_tree(tree, *value, thresh, compare)) { select = true; } break; |