diff options
author | Habib Gahbiche <habibgahbiche@gmail.com> | 2018-11-09 22:03:41 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-11-09 22:19:04 +0300 |
commit | 0c1934f3c2d3dff3bce65e2e8169866bafea04e0 (patch) | |
tree | 4b5e8baf24fe1946bcf6eb1ce76286025e8eb67d /source/blender/bmesh/intern/bmesh_polygon.c | |
parent | dc346c05fe32c7d90be261a2e970ef976b13c1fc (diff) |
Multi-Objects: MESH_OT_select_similar worldspace completion
This makes the operator to work 100% with worldspace similarity:
* SIMFACE_PERIMETER
* SIMFACE_AREA
* SIMEDGE_FACE_ANGLE
Note from revisor (Dalai Felinto):
I'm not sure we want to pass Object * to the bmesh api, though I
personally don't see why not. Either way I group the patches together so
we can more easily roll them back if needs be.
Maniphest Tasks: T56948
Differential Revision: D3908, D3899, D3896
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_polygon.c')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 8c96c938cef..8374fd8f51f 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -30,6 +30,7 @@ #include "DNA_listBase.h" #include "DNA_modifier_types.h" +#include "DNA_object_types.h" #include "MEM_guardedalloc.h" @@ -240,6 +241,30 @@ float BM_face_calc_area(const BMFace *f) } /** + * Get the area of the face in world space. + */ +float BM_face_calc_area_worldspace(Object *ob, const BMFace *f) +{ + /* inline 'area_poly_v3' logic, avoid creating a temp array */ + const BMLoop *l_iter, *l_first; + float n[3]; + + zero_v3(n); + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + float rsmat[3][3]; + copy_m3_m4(rsmat, ob->obmat); + do { + float co[3], co_next[3]; + copy_v3_v3(co, l_iter->v->co); + copy_v3_v3(co_next, l_iter->next->v->co); + mul_m3_v3(rsmat, co); + mul_m3_v3(rsmat, co_next); + add_newell_cross_v3_v3v3(n, co, co_next); + } while ((l_iter = l_iter->next) != l_first); + return len_v3(n) * 0.5f; +} + +/** * compute the perimeter of an ngon */ float BM_face_calc_perimeter(const BMFace *f) @@ -256,6 +281,29 @@ float BM_face_calc_perimeter(const BMFace *f) } /** + * Calculate the perimeter of a ngon in world space. + */ +float BM_face_calc_perimeter_worldspace(Object *ob, const BMFace *f) +{ + const BMLoop *l_iter, *l_first; + float perimeter = 0.0f; + + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + float rsmat[3][3]; + copy_m3_m4(rsmat, ob->obmat); + do { + float co[3], co_next[3]; + copy_v3_v3(co, l_iter->v->co); + copy_v3_v3(co_next, l_iter->next->v->co); + mul_m3_v3(rsmat, co); + mul_m3_v3(rsmat, co_next); + perimeter += len_v3v3(co, co_next); + } while ((l_iter = l_iter->next) != l_first); + + return perimeter; +} + +/** * Utility function to calculate the edge which is most different from the other two. * * \return The first edge index, where the second vertex is ``(index + 1) % 3``. |