Commit: 366bc79e2a6b97cea396644732a757109cd00094
Author: Phil Gosch
Date:   Tue Jul 26 11:23:34 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rB366bc79e2a6b97cea396644732a757109cd00094

Margin computation

Still need to quickly refactor PConvexHull to actually use margins

===================================================================

M       source/blender/blenlib/BLI_math_geom.h
M       source/blender/blenlib/intern/math_geom.c
M       source/blender/editors/uvedit/uvedit_parametrizer.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_geom.h 
b/source/blender/blenlib/BLI_math_geom.h
index 84a25f5..d09dc2d 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -416,6 +416,8 @@ void accumulate_vertex_normals_poly(
         float **vertnos, const float polyno[3],
         const float **vertcos, float vdiffs[][3], const int nverts);
 
+void edge_normal_v2_v2v2(float r[2], const float a[2], const float b[2], const 
bool left);
+
 /********************************* Tangents **********************************/
 
 void tangent_from_uv(
diff --git a/source/blender/blenlib/intern/math_geom.c 
b/source/blender/blenlib/intern/math_geom.c
index 40454a9..3ce69f0 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -4305,6 +4305,23 @@ void accumulate_vertex_normals_poly(float **vertnos, 
const float polyno[3],
        }
 }
 
+/* Calculates the 2d normal for an edge ab. 
+ * if left is true calculates the left normal (viewed in winding direction) */
+void edge_normal_v2_v2v2(float r[2], const float a[2], const float b[2], const 
bool left)
+{
+       float dx = b[0] - a[0];
+       float dy = b[1] - a[1];
+
+       if (left) {
+               r[0] = -dy;
+               r[1] = dx;
+       }
+       else {
+               r[0] = dy;
+               r[1] = -dx;
+       }
+}
+
 /********************************* Tangents **********************************/
 
 void tangent_from_uv(
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c 
b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 8348c94..f9c21d4 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -5080,9 +5080,39 @@ void p_convex_hull_restore_direction(PConvexHull *item)
        p_convex_hull_compute_edge_components(item);
 }
 
+/* Grow hull by margin amount */
 void p_convex_hull_grow(PConvexHull *chull, float margin)
 {
        /* ToDo SaphireS */
+       PVert *v1, *v2, *v3;
+       float angle, dist_fac;
+       float a[2], b[2], dir[2], end_pos[2], a_n[2], b_n[2];
+       int i;
+
+       for (i = 0; i < chull->nverts; i++) {
+               v1 = chull->h_verts[(i ? i : chull->nverts) - 1];
+               v2 = chull->h_verts[i];
+               v3 = chull->h_verts[(i + 1) < chull->nverts ? (i + 1) : 0];
+               
+               sub_v2_v2v2(a, v1, v2);
+               sub_v2_v2v2(b, v3, v2);
+
+               /* distance to offset */
+               dist_fac = shell_v2v2_mid_normalized_to_dist(a, b);
+
+               /* direction to offset */
+               edge_normal_v2_v2v2(a_n, v1, v2, true);
+               edge_normal_v2_v2v2(b_n, v2, v3, true);
+
+               add_v2_v2v2(dir, a_n, b_n);
+
+               normalize_v2(dir);
+
+               /* offset point */
+               madd_v2_v2v2fl(end_pos, v2->uv, dir, dist_fac * margin);
+
+               /*ToDo: apply end_pos */
+       }
 }
 
 PNoFitPolygon *p_inner_fit_polygon_create(PConvexHull *item)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to