[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55770] trunk/blender/source/blender: improved method of getting the tangent axis from a bmesh triangle,

Campbell Barton ideasman42 at gmail.com
Thu Apr 4 10:47:07 CEST 2013


Revision: 55770
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55770
Author:   campbellbarton
Date:     2013-04-04 08:47:07 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
improved method of getting the tangent axis from a bmesh triangle,
rather then getting the longest edge, get the edge which which is most different from the 2 others ends up giving more useful results: for an isosceles triangle it returns the base weather its longer or shorter then the other sides.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/math_vector.c
    trunk/blender/source/blender/bmesh/intern/bmesh_marking.c
    trunk/blender/source/blender/editors/transform/transform_manipulator.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2013-04-04 04:26:13 UTC (rev 55769)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2013-04-04 08:47:07 UTC (rev 55770)
@@ -244,6 +244,8 @@
 void dist_ensure_v3_v3fl(float v1[3], const float v2[3], const float dist);
 void dist_ensure_v2_v2fl(float v1[2], const float v2[2], const float dist);
 
+void axis_sort_v3(const float axis_values[3], int r_axis_order[3]);
+
 /***************************** Array Functions *******************************/
 /* attempted to follow fixed length vertex functions. names could be improved*/
 double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size);

Modified: trunk/blender/source/blender/blenlib/intern/math_vector.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector.c	2013-04-04 04:26:13 UTC (rev 55769)
+++ trunk/blender/source/blender/blenlib/intern/math_vector.c	2013-04-04 08:47:07 UTC (rev 55770)
@@ -527,6 +527,28 @@
 	}
 }
 
+void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
+{
+	float v[3];
+	copy_v3_v3(v, axis_values);
+
+#define SWAP_AXIS(a, b) { \
+	SWAP(float, v[a],            v[b]); \
+	SWAP(int,   r_axis_order[a], r_axis_order[b]); \
+} (void)0
+
+	if (v[0] < v[1]) {
+		if (v[2] < v[0]) {  SWAP_AXIS(0, 2); }
+	}
+	else {
+		if (v[1] < v[2]) { SWAP_AXIS(0, 1); }
+		else             { SWAP_AXIS(0, 2); }
+	}
+	if (v[2] < v[1])     { SWAP_AXIS(1, 2); }
+
+#undef SWAP_AXIS
+}
+
 /***************************** Array Functions *******************************/
 
 double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size)

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_marking.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_marking.c	2013-04-04 04:26:13 UTC (rev 55769)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_marking.c	2013-04-04 08:47:07 UTC (rev 55770)
@@ -710,8 +710,28 @@
 			cross_v3_v3v3(r_plane, efa->no, vec);
 		}
 		else {
-			if (efa->len == 4) {
-				BMVert *verts[4] = {NULL};
+			if (efa->len == 3) {
+				BMVert *verts[3];
+				float lens[3];
+				float difs[3];
+				int  order[3] = {0, 1, 2};
+
+				BM_face_as_array_vert_tri(efa, verts);
+
+				lens[0] = len_v3v3(verts[0]->co, verts[1]->co);
+				lens[1] = len_v3v3(verts[1]->co, verts[2]->co);
+				lens[2] = len_v3v3(verts[2]->co, verts[0]->co);
+
+				/* find the shortest or the longest loop */
+				difs[0] = fabsf(lens[1] - lens[2]);
+				difs[1] = fabsf(lens[2] - lens[0]);
+				difs[2] = fabsf(lens[0] - lens[1]);
+
+				axis_sort_v3(difs, order);
+				sub_v3_v3v3(r_plane, verts[order[0]]->co, verts[(order[0] + 1) % 3]->co);
+			}
+			else if (efa->len == 4) {
+				BMVert *verts[4];
 				float vecA[3], vecB[3];
 
 				// BM_iter_as_array(NULL, BM_VERTS_OF_FACE, efa, (void **)verts, 4);

Modified: trunk/blender/source/blender/editors/transform/transform_manipulator.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_manipulator.c	2013-04-04 04:26:13 UTC (rev 55769)
+++ trunk/blender/source/blender/editors/transform/transform_manipulator.c	2013-04-04 08:47:07 UTC (rev 55770)
@@ -841,27 +841,6 @@
 	glColor4ubv(col);
 }
 
-static void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
-{
-	float v[3];
-	copy_v3_v3(v, axis_values);
-
-#define SWAP_AXIS(a, b) { \
-	SWAP(float, v[a],            v[b]); \
-	SWAP(int,   r_axis_order[a], r_axis_order[b]); \
-} (void)0
-
-	if (v[0] < v[1]) {
-		if (v[2] < v[0]) {  SWAP_AXIS(0, 2); }
-	}
-	else {
-		if (v[1] < v[2]) { SWAP_AXIS(0, 1); }
-		else             { SWAP_AXIS(0, 2); }
-	}
-	if (v[2] < v[1])     { SWAP_AXIS(1, 2); }
-
-#undef SWAP_AXIS
-}
 static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
 {
 	float axis_values[3];




More information about the Bf-blender-cvs mailing list