diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-09-25 23:36:37 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-09-26 01:18:30 +0300 |
commit | c32b63f8fd64057d736021ff689a3838c810d269 (patch) | |
tree | fd8ba0634bf72589ab76dbf27785491235b0198d /source/blender/editors/mesh/editmesh_select_similar.c | |
parent | 3618646e71b80d30060a91a47d80c5a7e3c42e55 (diff) |
Multi-Objects: Select similar face SIMFACE_AREA and SIMFACE_PERIMETER
Note: Not doing worldspace comparison for now. We would need to create new
BM_face_calc_area and BM_face_calc_perimeter equivalent functions for that.
Not sure if it is worth the trouble.
Diffstat (limited to 'source/blender/editors/mesh/editmesh_select_similar.c')
-rw-r--r-- | source/blender/editors/mesh/editmesh_select_similar.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/source/blender/editors/mesh/editmesh_select_similar.c b/source/blender/editors/mesh/editmesh_select_similar.c index a911fe0c16e..5757454c7ed 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.c +++ b/source/blender/editors/mesh/editmesh_select_similar.c @@ -171,18 +171,19 @@ static bool select_similar_compare_float_tree(const KDTree *tree, const float le /** \name Select Similar Face * \{ */ +/* TODO(dfelinto): `types` that should technically be compared in world space but are not: + * -SIMFACE_AREA + * -SIMFACE_PERIMETER + */ static int similar_face_select_exec(bContext *C, wmOperator *op) { ViewLayer *view_layer = CTX_data_view_layer(C); - /* get the type from RNA */ const int type = RNA_enum_get(op->ptr, "type"); - //const float thresh = RNA_float_get(op->ptr, "threshold"); + const float thresh = RNA_float_get(op->ptr, "threshold"); const int compare = RNA_enum_get(op->ptr, "compare"); if (ELEM(type, - SIMFACE_AREA, - SIMFACE_PERIMETER, SIMFACE_NORMAL, SIMFACE_COPLANAR, SIMFACE_SMOOTH, @@ -209,15 +210,21 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + KDTree *tree = NULL; GSet *gset = NULL; switch (type) { + case SIMFACE_AREA: + case SIMFACE_PERIMETER: + tree = BLI_kdtree_new(tot_faces_selected_all); + break; case SIMFACE_SIDES: case SIMFACE_MATERIAL: gset = BLI_gset_ptr_new("Select similar face"); break; } + int tree_index = 0; for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; BMEditMesh *em = BKE_editmesh_from_object(ob); @@ -256,11 +263,30 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) } break; } + case SIMFACE_AREA: + { + float area = BM_face_calc_area(face); + float dummy[3] = {area, 0.0f, 0.0f}; + BLI_kdtree_insert(tree, tree_index++, dummy); + break; + } + case SIMFACE_PERIMETER: + { + float perimeter = BM_face_calc_perimeter(face); + float dummy[3] = {perimeter, 0.0f, 0.0f}; + BLI_kdtree_insert(tree, tree_index++, dummy); + break; + break; + } } } } } + if (tree != NULL) { + BLI_kdtree_balance(tree); + } + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; BMEditMesh *em = BKE_editmesh_from_object(ob); @@ -319,6 +345,22 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) } break; } + case SIMFACE_AREA: + { + float area = BM_face_calc_area(face); + if (select_similar_compare_float_tree(tree, area, thresh, compare)) { + select = true; + } + break; + } + case SIMFACE_PERIMETER: + { + float perimeter = BM_face_calc_perimeter(face); + if (select_similar_compare_float_tree(tree, perimeter, thresh, compare)) { + select = true; + } + break; + } } if (select) { @@ -335,6 +377,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) } MEM_freeN(objects); + BLI_kdtree_free(tree); if (gset != NULL) { BLI_gset_free(gset, NULL); } |