[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53696] trunk/blender/source/blender: bmesh todo: uv stretch area draw mode wasn' t calculating ngon area - added area_poly_v2().
Campbell Barton
ideasman42 at gmail.com
Thu Jan 10 09:16:23 CET 2013
Revision: 53696
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53696
Author: campbellbarton
Date: 2013-01-10 08:16:19 +0000 (Thu, 10 Jan 2013)
Log Message:
-----------
bmesh todo: uv stretch area draw mode wasn't calculating ngon area - added area_poly_v2().
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_geom.h
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
trunk/blender/source/blender/editors/uvedit/uvedit_draw.c
trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
trunk/blender/source/blender/editors/uvedit/uvedit_ops.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h 2013-01-10 08:01:19 UTC (rev 53695)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h 2013-01-10 08:16:19 UTC (rev 53696)
@@ -53,6 +53,7 @@
float area_tri_v3(const float a[3], const float b[3], const float c[3]);
float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]);
float area_poly_v3(int nr, float verts[][3], const float normal[3]);
+float area_poly_v2(int nr, float verts[][2]);
int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
int is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2013-01-10 08:01:19 UTC (rev 53695)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2013-01-10 08:16:19 UTC (rev 53696)
@@ -149,6 +149,25 @@
return fabsf(0.5f * area / max);
}
+float area_poly_v2(int nr, float verts[][2])
+{
+ int a;
+ float area;
+ float *co_curr, *co_prev;
+
+ /* The Trapezium Area Rule */
+ co_prev = verts[nr - 1];
+ co_curr = verts[0];
+ area = 0.0f;
+ for (a = 0; a < nr; a++) {
+ area += (co_curr[0] - co_prev[0]) * (co_curr[1] + co_prev[1]);
+ co_prev = verts[a];
+ co_curr = verts[a + 1];
+ }
+
+ return fabsf(0.5f * area);
+}
+
/********************************* Distance **********************************/
/* distance p to line v1-v2
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c 2013-01-10 08:01:19 UTC (rev 53695)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c 2013-01-10 08:16:19 UTC (rev 53696)
@@ -158,7 +158,6 @@
BMLoop *l;
BMIter iter;
float (*verts)[3] = BLI_array_alloca(verts, f->len);
- float normal[3];
float area;
int i;
@@ -173,6 +172,7 @@
area = area_quad_v3(verts[0], verts[1], verts[2], verts[3]);
}
else {
+ float normal[3];
calc_poly_normal(normal, verts, f->len);
area = area_poly_v3(f->len, verts, normal);
}
Modified: trunk/blender/source/blender/editors/uvedit/uvedit_draw.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_draw.c 2013-01-10 08:01:19 UTC (rev 53695)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_draw.c 2013-01-10 08:16:19 UTC (rev 53696)
@@ -194,8 +194,7 @@
uv_poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len);
totarea += BM_face_calc_area(efa);
- //totuvarea += tf_area(tf, efa->v4!=0);
- totuvarea += uv_poly_area(tf_uv, efa->len);
+ totuvarea += area_poly_v2(efa->len, tf_uv);
if (uvedit_face_visible_test(scene, ima, efa, tf)) {
BM_elem_flag_enable(efa, BM_ELEM_TAG);
@@ -238,8 +237,7 @@
uv_poly_copy_aspect(tf_uvorig, tf_uv, aspx, aspy, efa->len);
- //uvarea = tf_area(tf, efa->v4!=0) / totuvarea;
- uvarea = uv_poly_area(tf_uv, efa->len) / totuvarea;
+ uvarea = area_poly_v2(efa->len, tf_uv) / totuvarea;
if (area < FLT_EPSILON || uvarea < FLT_EPSILON)
areadiff = 1.0f;
Modified: trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_intern.h 2013-01-10 08:01:19 UTC (rev 53695)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_intern.h 2013-01-10 08:16:19 UTC (rev 53696)
@@ -50,7 +50,6 @@
int uvedit_face_visible_nolocal(struct Scene *scene, struct BMFace *efa);
/* geometric utilities */
-float uv_poly_area(float uv[][2], int len);
void uv_poly_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy, int len);
void uv_poly_center(struct BMEditMesh *em, struct BMFace *f, float r_cent[2]);
Modified: trunk/blender/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_ops.c 2013-01-10 08:01:19 UTC (rev 53695)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_ops.c 2013-01-10 08:16:19 UTC (rev 53696)
@@ -575,19 +575,6 @@
mul_v2_fl(r_cent, 1.0f / (float)f->len);
}
-float uv_poly_area(float uv[][2], int len)
-{
- //BMESH_TODO: make this not suck
- //maybe use scanfill? I dunno.
-
- if (len >= 4)
- return area_tri_v2(uv[0], uv[1], uv[2]) + area_tri_v2(uv[0], uv[2], uv[3]);
- else
- return area_tri_v2(uv[0], uv[1], uv[2]);
-
- return 1.0;
-}
-
void uv_poly_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy, int len)
{
int i;
More information about the Bf-blender-cvs
mailing list