diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-09-26 00:13:56 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-09-26 01:18:30 +0300 |
commit | f59b968cef8541803d18ef465aa56a47a3130ad0 (patch) | |
tree | bb0d3aa3a15d791c4d66e8a4de28b5d2f0231a95 /source/blender/editors/mesh/editmesh_select_similar.c | |
parent | c32b63f8fd64057d736021ff689a3838c810d269 (diff) |
Multi-Objects: Select similar face SIMFACE_NORMAL
We could/can deduplicate the code with SIMVERT_NORMAL.
Diffstat (limited to 'source/blender/editors/mesh/editmesh_select_similar.c')
-rw-r--r-- | source/blender/editors/mesh/editmesh_select_similar.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/source/blender/editors/mesh/editmesh_select_similar.c b/source/blender/editors/mesh/editmesh_select_similar.c index 5757454c7ed..d5ea7829e58 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.c +++ b/source/blender/editors/mesh/editmesh_select_similar.c @@ -181,10 +181,10 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) const int type = RNA_enum_get(op->ptr, "type"); const float thresh = RNA_float_get(op->ptr, "threshold"); + const float thresh_radians = thresh * (float)M_PI; const int compare = RNA_enum_get(op->ptr, "compare"); if (ELEM(type, - SIMFACE_NORMAL, SIMFACE_COPLANAR, SIMFACE_SMOOTH, SIMFACE_FACEMAP, @@ -216,6 +216,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) switch (type) { case SIMFACE_AREA: case SIMFACE_PERIMETER: + case SIMFACE_NORMAL: tree = BLI_kdtree_new(tot_faces_selected_all); break; case SIMFACE_SIDES: @@ -230,6 +231,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) BMEditMesh *em = BKE_editmesh_from_object(ob); BMesh *bm = em->bm; Material ***material_array; + invert_m4_m4(ob->imat, ob->obmat); if (bm->totfacesel == 0) { continue; @@ -278,6 +280,16 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) break; break; } + case SIMFACE_NORMAL: + { + float normal[3]; + copy_v3_v3(normal, face->no); + mul_transposed_mat3_m4_v3(ob->imat, normal); + normalize_v3(normal); + + BLI_kdtree_insert(tree, tree_index++, normal); + break; + } } } } @@ -361,6 +373,23 @@ static int similar_face_select_exec(bContext *C, wmOperator *op) } break; } + case SIMFACE_NORMAL: + { + float normal[3]; + copy_v3_v3(normal, face->no); + mul_transposed_mat3_m4_v3(ob->imat, normal); + normalize_v3(normal); + + /* We are treating the normals as coordinates, the "nearest" one will + * also be the one closest to the angle. */ + KDTreeNearest nearest; + if (BLI_kdtree_find_nearest(tree, normal, &nearest) != -1) { + if (angle_normalized_v3v3(normal, nearest.co) <= thresh_radians) { + select = true; + } + } + break; + } } if (select) { |