From 3756f920f4894c9ec748c0ece5f63e1bc9c616df Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Nov 2018 19:54:49 +1100 Subject: BMesh: backport minor changes from 2.8 --- source/blender/bmesh/intern/bmesh_polygon.c | 45 ++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'source/blender/bmesh/intern/bmesh_polygon.c') diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 3137725d6e7..5e3f5958a32 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -239,6 +239,28 @@ float BM_face_calc_area(const BMFace *f) return len_v3(n) * 0.5f; } +/** + * Get the area of the face in world space. + */ +float BM_face_calc_area_with_mat3(const BMFace *f, float mat3[3][3]) +{ + /* inline 'area_poly_v3' logic, avoid creating a temp array */ + const BMLoop *l_iter, *l_first; + float co[3]; + float n[3]; + + zero_v3(n); + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + mul_v3_m3v3(co, mat3, l_iter->v->co); + do { + float co_next[3]; + mul_v3_m3v3(co_next, mat3, l_iter->next->v->co); + add_newell_cross_v3_v3v3(n, co, co_next); + copy_v3_v3(co, co_next); + } while ((l_iter = l_iter->next) != l_first); + return len_v3(n) * 0.5f; +} + /** * compute the perimeter of an ngon */ @@ -255,6 +277,27 @@ float BM_face_calc_perimeter(const BMFace *f) return perimeter; } +/** + * Calculate the perimeter of a ngon in world space. + */ +float BM_face_calc_perimeter_with_mat3(const BMFace *f, float mat3[3][3]) +{ + const BMLoop *l_iter, *l_first; + float co[3]; + float perimeter = 0.0f; + + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + mul_v3_m3v3(co, mat3, l_iter->v->co); + do { + float co_next[3]; + mul_v3_m3v3(co_next, mat3, l_iter->next->v->co); + perimeter += len_v3v3(co, co_next); + copy_v3_v3(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. * @@ -487,7 +530,7 @@ void BM_face_calc_tangent_vert_diagonal(const BMFace *f, float r_tangent[3]) } /** - * Compute a meaningful direction along the face (use for manipulator axis). + * Compute a meaningful direction along the face (use for gizmo axis). * * \note Callers shouldn't depend on the *exact* method used here. */ -- cgit v1.2.3