diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-01-10 00:09:27 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-01-11 18:00:23 +0300 |
commit | 74260a2b6da86e3f6da0a37afc6d47338c1be034 (patch) | |
tree | 711ac149390cc2809b59738ec6723296c1bdfe6a /source/blender/bmesh | |
parent | b98e6743dcaf8ec513bbbadc0015cb8729a72a18 (diff) |
BMesh: Add BM_face_calc_area_uv
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 20 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 87903b3fd58..a3b0f72fbcf 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_meshdata_types.h" #include "MEM_guardedalloc.h" @@ -262,6 +263,25 @@ float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3]) } /** + * get the area of UV face + */ +float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset) +{ + /* inline 'area_poly_v2' logic, avoid creating a temp array */ + const BMLoop *l_iter, *l_first; + + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + /* The Trapezium Area Rule */ + float cross = 0.0f; + do { + const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset); + const MLoopUV *luv_next = BM_ELEM_CD_GET_VOID_P(l_iter->next, cd_loop_uv_offset); + cross += (luv_next->uv[0] - luv->uv[0]) * (luv_next->uv[1] + luv->uv[1]); + } while ((l_iter = l_iter->next) != l_first); + return fabsf(cross * 0.5f); +} + +/** * compute the perimeter of an ngon */ float BM_face_calc_perimeter(const BMFace *f) diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h index 2003f2d2503..8033187c10b 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.h +++ b/source/blender/bmesh/intern/bmesh_polygon.h @@ -45,6 +45,7 @@ float BM_face_calc_normal_vcos( float BM_face_calc_normal_subset(const BMLoop *l_first, const BMLoop *l_last, float r_no[3]) ATTR_NONNULL(); float BM_face_calc_area(const BMFace *f) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3]) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); float BM_face_calc_perimeter(const BMFace *f) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); float BM_face_calc_perimeter_with_mat3(const BMFace *f, const float mat3[3][3]) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void BM_face_calc_tangent_edge(const BMFace *f, float r_plane[3]) ATTR_NONNULL(); |