[Bf-blender-cvs] [74260a2b6da] master: BMesh: Add BM_face_calc_area_uv
Clément Foucault
noreply at git.blender.org
Fri Jan 11 16:00:49 CET 2019
Commit: 74260a2b6da86e3f6da0a37afc6d47338c1be034
Author: Clément Foucault
Date: Wed Jan 9 22:09:27 2019 +0100
Branches: master
https://developer.blender.org/rB74260a2b6da86e3f6da0a37afc6d47338c1be034
BMesh: Add BM_face_calc_area_uv
===================================================================
M source/blender/bmesh/intern/bmesh_polygon.c
M source/blender/bmesh/intern/bmesh_polygon.h
===================================================================
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"
@@ -261,6 +262,25 @@ float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
return len_v3(n) * 0.5f;
}
+/**
+ * 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
*/
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();
More information about the Bf-blender-cvs
mailing list