From 23a6b5d91e942d90badeaf9ab64cf8ea3b4219a1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 11 Aug 2020 15:11:31 +1000 Subject: BMesh: add UV calculate center call Move uv_poly_center to BM_face_uv_calc_center_median as it was only defined in uvedit_intern.h --- source/blender/bmesh/intern/bmesh_query_uv.c | 14 ++++++++++++++ source/blender/bmesh/intern/bmesh_query_uv.h | 2 ++ 2 files changed, 16 insertions(+) (limited to 'source/blender/bmesh') diff --git a/source/blender/bmesh/intern/bmesh_query_uv.c b/source/blender/bmesh/intern/bmesh_query_uv.c index b9ea51f0c4d..1aa75bfb037 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.c +++ b/source/blender/bmesh/intern/bmesh_query_uv.c @@ -95,6 +95,20 @@ void BM_face_uv_calc_center_median_weighted(const BMFace *f, #undef UV_ASPECT +void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset, float r_cent[2]) +{ + const BMLoop *l_iter; + const BMLoop *l_first; + zero_v2(r_cent); + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + do { + const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); + add_v2_v2(r_cent, luv->uv); + } while ((l_iter = l_iter->next) != l_first); + + mul_v2_fl(r_cent, 1.0f / (float)f->len); +} + /** * Calculate the UV cross product (use the sign to check the winding). */ diff --git a/source/blender/bmesh/intern/bmesh_query_uv.h b/source/blender/bmesh/intern/bmesh_query_uv.h index 3465a831bea..0a86c0cbeae 100644 --- a/source/blender/bmesh/intern/bmesh_query_uv.h +++ b/source/blender/bmesh/intern/bmesh_query_uv.h @@ -31,6 +31,8 @@ void BM_face_uv_calc_center_median_weighted(const BMFace *f, const float aspect[2], const int cd_loop_uv_offset, float r_cent[2]) ATTR_NONNULL(); +void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset, float r_cent[2]) + ATTR_NONNULL(); float BM_face_uv_calc_cross(const BMFace *f, const int cd_loop_uv_offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -- cgit v1.2.3