[Bf-blender-cvs] [f2c483d] master: Fix T39429: Project paint error with UV bleed

Campbell Barton noreply at git.blender.org
Tue Apr 22 20:33:57 CEST 2014


Commit: f2c483d108a33cb30f3f9c984c289e98a25ce5c2
Author: Campbell Barton
Date:   Wed Apr 23 04:23:54 2014 +1000
https://developer.blender.org/rBf2c483d108a33cb30f3f9c984c289e98a25ce5c2

Fix T39429: Project paint error with UV bleed

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

M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom_inline.c
M	source/blender/bmesh/operators/bmo_inset.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c

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

diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 6000b8d..f4bcc81 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -319,6 +319,8 @@ MINLINE int poly_to_tri_count(const int poly_count, const int corner_count);
 MINLINE float shell_angle_to_dist(const float angle);
 MINLINE float shell_v3v3_normalized_to_dist(const float a[3], const float b[3]);
 MINLINE float shell_v2v2_normalized_to_dist(const float a[2], const float b[2]);
+MINLINE float shell_v3v3_mid_normalized_to_dist(const float a[3], const float b[3]);
+MINLINE float shell_v2v2_mid_normalized_to_dist(const float a[2], const float b[2]);
 
 /**************************** Inline Definitions ******************************/
 
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c
index 1e54dd1..5a64ed6 100644
--- a/source/blender/blenlib/intern/math_geom_inline.c
+++ b/source/blender/blenlib/intern/math_geom_inline.c
@@ -259,6 +259,34 @@ MINLINE float shell_v2v2_normalized_to_dist(const float a[2], const float b[2])
 	return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos);
 }
 
+/**
+ * equivalent to ``shell_angle_to_dist(angle_normalized_v3v3(a, b) / 2)``
+ */
+MINLINE float shell_v3v3_mid_normalized_to_dist(const float a[3], const float b[3])
+{
+	float angle_cos;
+	float ab[3];
+	BLI_ASSERT_UNIT_V3(a);
+	BLI_ASSERT_UNIT_V3(b);
+	add_v3_v3v3(ab, a, b);
+	angle_cos = (normalize_v3(ab) != 0.0f) ? fabsf(dot_v3v3(a, ab)) : 0.0f;
+	return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos);
+}
+
+/**
+ * equivalent to ``shell_angle_to_dist(angle_normalized_v2v2(a, b) / 2)``
+ */
+MINLINE float shell_v2v2_mid_normalized_to_dist(const float a[2], const float b[2])
+{
+	float angle_cos;
+	float ab[2];
+	BLI_ASSERT_UNIT_V2(a);
+	BLI_ASSERT_UNIT_V2(b);
+	add_v2_v2v2(ab, a, b);
+	angle_cos = (normalize_v2(ab) != 0.0f) ? fabsf(dot_v2v2(a, ab)) : 0.0f;
+	return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos);
+}
+
 #undef SMALL_NUMBER
 
 #endif /* __MATH_GEOM_INLINE_C__ */
diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c
index a23f8f3..5e2e057 100644
--- a/source/blender/bmesh/operators/bmo_inset.c
+++ b/source/blender/bmesh/operators/bmo_inset.c
@@ -201,7 +201,7 @@ static void bmo_face_inset_individual(
 		copy_v3_v3(v_new_co, l_iter->v->co);
 
 		if (use_even_offset) {
-			mul_v3_fl(tvec, shell_angle_to_dist(angle_normalized_v3v3(eno_prev,  eno_next) / 2.0f));
+			mul_v3_fl(tvec, shell_v3v3_mid_normalized_to_dist(eno_prev,  eno_next));
 		}
 
 		/* Modify vertices and their normals */
@@ -694,14 +694,16 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
 							/* scale by edge angle */
 							if (use_even_offset) {
 								if (is_mid) {
-									mul_v3_fl(tvec, shell_angle_to_dist(angle_normalized_v3v3(e_info_a->no,
-									                                                          e_info_b->no) / 2.0f));
+									mul_v3_fl(tvec, shell_v3v3_mid_normalized_to_dist(e_info_a->no,
+									                                                  e_info_b->no));
 								}
 								else {
-									mul_v3_fl(tvec, shell_angle_to_dist(max_ff(angle_normalized_v3v3(tvec,
-									                                                                 e_info_a->no),
-									                                           angle_normalized_v3v3(tvec,
-									                                                                 e_info_b->no))));
+									/* use the largest angle */
+									mul_v3_fl(tvec,
+									          shell_v3v3_normalized_to_dist(tvec,
+									                                        len_squared_v3v3(tvec, e_info_a->no) >
+									                                        len_squared_v3v3(tvec, e_info_b->no) ?
+									                                            e_info_a->no : e_info_b->no));
 								}
 							}
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 5ad3919..af88ff1 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -963,15 +963,15 @@ static void uv_image_outset(float (*orig_uv)[2], float (*outset_uv)[2], const fl
 	}
 
 	if (is_quad) {
-		a1 = shell_v2v2_normalized_to_dist(dir4, dir1);
-		a2 = shell_v2v2_normalized_to_dist(dir1, dir2);
-		a3 = shell_v2v2_normalized_to_dist(dir2, dir3);
-		a4 = shell_v2v2_normalized_to_dist(dir3, dir4);
+		a1 = shell_v2v2_mid_normalized_to_dist(dir4, dir1);
+		a2 = shell_v2v2_mid_normalized_to_dist(dir1, dir2);
+		a3 = shell_v2v2_mid_normalized_to_dist(dir2, dir3);
+		a4 = shell_v2v2_mid_normalized_to_dist(dir3, dir4);
 	}
 	else {
-		a1 = shell_v2v2_normalized_to_dist(dir3, dir1);
-		a2 = shell_v2v2_normalized_to_dist(dir1, dir2);
-		a3 = shell_v2v2_normalized_to_dist(dir2, dir3);
+		a1 = shell_v2v2_mid_normalized_to_dist(dir3, dir1);
+		a2 = shell_v2v2_mid_normalized_to_dist(dir1, dir2);
+		a3 = shell_v2v2_mid_normalized_to_dist(dir2, dir3);
 	}
 
 	if (is_quad) {




More information about the Bf-blender-cvs mailing list