[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50121] trunk/blender/source/blender/bmesh /operators/bmo_connect.c: Fix #32262: mesh bridge between edge loops failed to find a good edge matching

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Aug 22 16:27:06 CEST 2012


Revision: 50121
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50121
Author:   blendix
Date:     2012-08-22 14:27:06 +0000 (Wed, 22 Aug 2012)
Log Message:
-----------
Fix #32262: mesh bridge between edge loops failed to find a good edge matching
in some cases, in particular when the the edge loops were not planar.

Now rather than finding the shortest distance between two vertices, one from
each edge loop and using that as a starting point, it now finds the smallest
sum of distances between all vertex pairs that would be connected.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/operators/bmo_connect.c

Modified: trunk/blender/source/blender/bmesh/operators/bmo_connect.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_connect.c	2012-08-22 14:23:08 UTC (rev 50120)
+++ trunk/blender/source/blender/bmesh/operators/bmo_connect.c	2012-08-22 14:27:06 UTC (rev 50121)
@@ -370,39 +370,36 @@
 			}
 		}
 
-		/* Find the shortest distance from a vert in vv1 to vv2[0]. Use that
-		 * vertex in vv1 as a starting point in the first loop, while starting
-		 * from vv2[0] in the second loop. This is a simplistic attempt to get
-		 * a better edge-to-edge match between the two loops. */
+		/* Find the smallest sum of distances from verts in vv1 to verts in vv2,
+		 * finding a starting point in the first loop, to start with vv2[0] in the
+		 * second loop. This is a simplistic attempt to get a better edge-to-edge
+		 * match between two loops. */
 		if (cl1) {
-			int previ, nexti;
 			float min = 1e32;
 
-			/* BMESH_TODO: Would be nice to do a more thorough analysis of all
-			 * the vertices in both loops to find a more accurate match for the
-			 * starting point and winding direction of the bridge generation. */
-			
-			for (i = 0; i < BLI_array_count(vv1); i++) {
-				if (len_v3v3(vv1[i]->co, vv2[0]->co) < min) {
-					min = len_v3v3(vv1[i]->co, vv2[0]->co);
+			for (i = 0; i < lenv1; i++) {
+				float len;
+
+				/* compute summed length between vertices in forward direction */
+				len = 0.0f;
+				for (j = 0; j < lenv2; j++)
+					len += len_v3v3(vv1[clamp_index(i+j, lenv1)]->co, vv2[j]->co);
+
+				if (len < min) {
+					min = len;
 					starti = i;
 				}
-			}
 
-			/* Reverse iteration order for the first loop if the distance of
-			 * the (starti - 1) vert from vv1 is a better match for vv2[1] than
-			 * the (starti + 1) vert.
-			 *
-			 * This is not always going to be right, but it will work better in
-			 * the average case.
-			 */
-			previ = clamp_index(starti - 1, lenv1);
-			nexti = clamp_index(starti + 1, lenv1);
+				/* compute summed length between vertices in backward direction */
+				len = 0.0f;
+				for (j = 0; j < lenv2; j++)
+					len += len_v3v3(vv1[clamp_index(i-j, lenv1)]->co, vv2[j]->co);
 
-			/* avoid sqrt for comparison */
-			if (len_squared_v3v3(vv1[nexti]->co, vv2[1]->co) > len_squared_v3v3(vv1[previ]->co, vv2[1]->co)) {
-				/* reverse direction for reading vv1 (1 is forward, -1 is backward) */
-				dir1 = -1;
+				if (len < min) {
+					min = len;
+					starti = i;
+					dir1 = -1;
+				}
 			}
 		}
 




More information about the Bf-blender-cvs mailing list