[Bf-committers] Collapse Loop Patch - Version 1

Johnny Matthews johnny.matthews at gmail.com
Fri Feb 11 17:23:49 CET 2005


Here is a first version of collapse loop for you to check out

It is activated with keystroke CTRL-SHIFT-R after selecting 2 adjacent 
vert rings that are full rings with 5 or more verts each.

--TODO--
**edge and face mode. Only works in vertex mode right now.
**work for loops with 3 or 4 verts per ring. Only works now with loops 
with 5 or more verts per ring.
**Anything other bugs that people find.

I have this info here http://guitargeek.superihost.com/collapse


-------------- next part --------------
Index: source/blender/include/BIF_editmesh.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/include/BIF_editmesh.h,v
retrieving revision 1.36
diff -u -r1.36 BIF_editmesh.h
--- source/blender/include/BIF_editmesh.h	24 Nov 2004 16:29:10 -0000	1.36
+++ source/blender/include/BIF_editmesh.h	11 Feb 2005 14:28:48 -0000
@@ -148,6 +148,7 @@
 #define LOOP_CUT	2
 
 extern void loopoperations(char mode);
+extern void collapseedgeloop();
 extern void vertex_loop_select(void); 
 
 /* ******************* editmesh_tools.c */

Index: source/blender/src/editmesh_loop.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editmesh_loop.c,v
retrieving revision 1.11
diff -u -r1.11 editmesh_loop.c
--- source/blender/src/editmesh_loop.c	28 Dec 2004 05:38:56 -0000	1.11
+++ source/blender/src/editmesh_loop.c	11 Feb 2005 15:49:00 -0000
@@ -92,6 +92,208 @@
 #include "winlay.h"
 
 
+
+void collapseedgeloop()
+{
+	EditMesh *em = G.editMesh;
+	EditEdge *eed = NULL;
+	EditFace *ef = NULL;
+	EditVert *ev = NULL, **index, **vertChart, **collapse, **tree;
+	int selectedVertCount = 0;
+	int i,n=0,m,vertno[3],matchno=0,next, shared, exit = 0;
+
+	/*Change Face and Edge selection to vertex selection*/
+	for(eed=em->edges.first; eed; eed=eed->next){
+		if(eed->f & 1){
+			eed->v1->f |= 1;
+			eed->v2->f |= 1;
+			eed->f &= ~(1);
+		}
+	}
+	for(ef=em->faces.first; ef; ef=ef->next){
+		if(ef->f & 1){
+			ef->v1->f |= 1;
+			ef->v2->f |= 1;
+			ef->v3->f |= 1;
+			if(ef->v4)
+				ef->v4->f |= 1;
+			ef->f &= ~(1);
+		}
+	}
+
+	/*Count Number of Selected Verts*/
+	for(ev=em->verts.first; ev; ev=ev->next){
+		if(ev->f & 1)
+			selectedVertCount++;
+	}
+		
+	/*If it is odd or 0 it is not 2 similar loops and 8 is a cube*/
+	if(selectedVertCount == 0 || selectedVertCount % 2 != 0 || selectedVertCount == 8){
+		okee("Sorry, I can't collapse that");
+		return;
+	}		
+	vertChart = MEM_mallocN(4*selectedVertCount*sizeof(EditVert*), "vertChart Created");
+	index     = MEM_mallocN(selectedVertCount*sizeof(EditVert*), "index Created");
+	tree      = MEM_mallocN(12*sizeof(EditVert*), "collapselist Created");
+	collapse  = MEM_mallocN(selectedVertCount*sizeof(EditVert*), "collapselist Created");
+	
+	
+	/*Fill in the Index Array for our selected verts*/
+	n=0;
+	for(ev=em->verts.first; ev; ev=ev->next){
+		if(ev->f & 1){
+			index[n] = ev;
+			n++;
+		}
+	}
+	
+	/* Null out the vert arrays */
+	for(n=0;n<selectedVertCount*4;n++)
+		vertChart[n] = NULL;
+	for(n=0;n<selectedVertCount;n++)
+		collapse[n] = NULL;
+	for(n=0;n<12;n++)
+		tree[n] = NULL;
+		
+	/*Fill the Vert Chart*/
+	/* the vert chart is a vert folled by the 3 verts it connects to */
+	for(n=0;n<selectedVertCount;n++){
+		shared = 0;
+		m=0;
+		if(vertChart[n*4-1]==NULL){
+			exit = 1;
+			break;
+		}
+		vertChart[n*4] = index[n];
+		for(eed=em->edges.first; eed; eed=eed->next){
+			m++;
+			if((eed->v1 == index[n] && eed->v2->f & 1) || (eed->v2 == index[n] && eed->v1->f & 1)){
+				shared++;
+				if(shared>3){
+					exit = 1;
+					break;
+				}
+				if(eed->v1 == index[n])
+					vertChart[n*4+shared] = eed->v2;
+				else
+					vertChart[n*4+shared] = eed->v1;
+			}
+		}
+		if(exit)
+			break;
+	}
+	
+	if(!exit){
+		/*Pair up the Verts*/
+		for(n=0;n<selectedVertCount;n++){
+			/*if we have paired the vert, skip it*/
+			next = 0;
+			for(i=0;i<selectedVertCount;i++){
+				if(index[n] == collapse[i])
+					next = 1;
+					continue;
+			}
+			if(next)
+				continue;
+			
+			
+			/*make our vert tree*/
+				
+			tree[0] = vertChart[n*4+1];
+			tree[4] = vertChart[n*4+2];
+			tree[8] = vertChart[n*4+3];
+
+			for(m=0;m<selectedVertCount;m++){
+				if(index[m] == tree[0]){
+					vertno[0] = m;
+				}
+				if(index[m] == tree[4]){
+					vertno[1] = m;
+				}
+				if(index[m] == tree[8]){
+					vertno[2] = m;
+				}
+			}
+			
+			tree[1]  = vertChart[vertno[0]*4+1];
+			tree[2]  = vertChart[vertno[0]*4+2];
+			tree[3]  = vertChart[vertno[0]*4+3];
+			
+			tree[5]  = vertChart[vertno[1]*4+1];
+			tree[6]  = vertChart[vertno[1]*4+2];
+			tree[7]  = vertChart[vertno[1]*4+3];
+			
+			tree[9]  = vertChart[vertno[2]*4+1];
+			tree[10] = vertChart[vertno[2]*4+2];
+			tree[11] = vertChart[vertno[2]*4+3];
+			
+			/*remove duplicates from the vert tree*/
+			
+			for(m=0;m<11;m++){
+				if(tree[m] == NULL)
+					continue;
+				ev = tree[m];
+				for(i=m+1;i<12;i++){
+					if(ev == tree[i]){
+						tree[m] = NULL;
+						tree[i] = NULL;
+					}
+				}
+			}
+			
+			/*determine which branch has the paired vertex*/
+			
+			i=0;
+			for(m=0;m<12;m++){
+				if(m==0 || m==4 || m == 8)
+					continue;
+				if(tree[m]){
+					if(m<4)i=4;
+					else if (m<8 && i==4)i=8;
+				}
+			}
+			
+			/*enter verticies into collapse array*/
+			collapse[matchno*2]  = index[n];
+			collapse[matchno*2+1]= tree[i];
+			matchno++;
+		}
+		
+		/*select verts in pairs*/
+		for(i=0;i<selectedVertCount/2;i++){
+			for(ev=em->verts.first; ev; ev=ev->next){
+				ev->f &= ~(1);
+			}
+						
+			collapse[i*2]->f |= 1;
+			collapse[i*2+1]->f |= 1;
+			snap_to_center();	
+			removedoublesflag(1, 0.1);
+		}
+		/*clear selection*/
+		for(ev=em->verts.first; ev; ev=ev->next){
+			ev->f &= ~(1);
+		}
+		allqueue(REDRAWVIEW3D, 0);
+		countall();			
+		BIF_undo_push("Merge"); /* push the mesh down the undo pipe */			
+	}
+	
+	else{
+		okee("The loop to collapse could not be determined");
+	}
+	if(tree)
+		MEM_freeN(tree);
+	if(collapse)
+		MEM_freeN(collapse);
+	if(vertChart)
+		MEM_freeN(vertChart);	
+	if(index)
+		MEM_freeN(index);
+}
+
+
+
 /* *************** LOOP SELECT ************* */
 
 short edgeFaces(EditEdge *e){
 
Index: source/blender/src/space.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/space.c,v
retrieving revision 1.217
diff -u -r1.217 space.c
--- source/blender/src/space.c	31 Jan 2005 18:37:54 -0000	1.217
+++ source/blender/src/space.c	11 Feb 2005 15:20:17 -0000
@@ -1456,6 +1456,10 @@
 						if (G.obedit->type==OB_MESH)
 							loopoperations(LOOP_CUT);
 					}
+					else if(G.qual & LR_CTRLKEY && G.qual & LR_SHIFTKEY) {
+						if (G.obedit->type==OB_MESH)
+							collapseedgeloop();
+					}
 					else if((G.qual==0))
 						transform('r');
 				}


More information about the Bf-committers mailing list