[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12231] branches/bmesh/source/blender: -> Face split tools

Geoffrey Bantle hairbat at yahoo.com
Mon Oct 8 15:03:00 CEST 2007


Revision: 12231
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12231
Author:   briggs
Date:     2007-10-08 15:03:00 +0200 (Mon, 08 Oct 2007)

Log Message:
-----------
-> Face split tools
	
Two simple face split tools, 'connect verts' and 'connect edges'.
In the vertex connect tool, for any face in the mesh, if it has 
two selected vertices, it will connect them by splitting the face 
in two and adding an edge. Similarly in the edge connect tool, 
for any face in the mesh with two selected edges it will split them
in half and then split the face by connecting the two new vertices.


Note that these are mostly simple examples and to give people something
to play with. In reality there should not be the restriction of just
connecting two verts/edges in a face at a time.

Modified Paths:
--------------
    branches/bmesh/source/blender/blenkernel/BKE_bmesh.h
    branches/bmesh/source/blender/blenkernel/intern/BME_tools.c
    branches/bmesh/source/blender/include/editbmesh.h
    branches/bmesh/source/blender/src/editbmesh_tools.c
    branches/bmesh/source/blender/src/editobject.c

Modified: branches/bmesh/source/blender/blenkernel/BKE_bmesh.h
===================================================================
--- branches/bmesh/source/blender/blenkernel/BKE_bmesh.h	2007-10-08 09:24:29 UTC (rev 12230)
+++ branches/bmesh/source/blender/blenkernel/BKE_bmesh.h	2007-10-08 13:03:00 UTC (rev 12231)
@@ -231,7 +231,7 @@
 void BME_connect_verts(struct BME_Mesh *bm);
 void BME_delete_verts(struct BME_Mesh *bm);
 /*Edge Tools*/
-void BME_cut_edge(struct BME_Mesh *bm, BME_Edge *e, int numcuts);
+struct BME_Vert  *BME_cut_edge(struct BME_Mesh *bm, BME_Edge *e, int numcuts);
 void BME_cut_edges(struct BME_Mesh *bm, int numcuts);
 void BME_dissolve_edges(struct BME_Mesh *bm);
 void BME_delete_edges(struct BME_Mesh *bm);

Modified: branches/bmesh/source/blender/blenkernel/intern/BME_tools.c
===================================================================
--- branches/bmesh/source/blender/blenkernel/intern/BME_tools.c	2007-10-08 09:24:29 UTC (rev 12230)
+++ branches/bmesh/source/blender/blenkernel/intern/BME_tools.c	2007-10-08 13:03:00 UTC (rev 12231)
@@ -63,32 +63,64 @@
 void BME_connect_verts(BME_Mesh *bm)
 {
 	BME_Poly *f;
-	BME_Loop *l;
-	int split;
+	BME_Loop *l, *v1loop, *v2loop;
+	int pass;
 	
 	/*visit the faces with selected verts*/
 	for(f=BME_first(bm,BME_POLY);f;f=BME_next(bm,BME_POLY,f)){
-		split = 0;
+		v1loop = v2loop = NULL;
+		pass = 0;
 		if(!(BME_NEWELEM(f))){
 			l = f->loopbase;
 			do{
-				if(BME_SELECTED(l->v)){ 
-					BME_VISIT(l->v);
-					split ++;
+				if(BME_ISVISITED(l->v)){ 
+					if(v2loop) pass = 1;
+					else if(v1loop) v2loop = l;
+					else v1loop = l;
 				}
 				l = l->next;
 			}while(l != f->loopbase);
+
+			if(v1loop && v2loop && (!pass) && (v1loop->next != v2loop) && (v2loop->next != v1loop)) BME_SFME(bm,f,v1loop->v, v2loop->v,NULL);
 			
-			if(split>1){ 
-				BME_split_face(bm,f);
+		}
+	}
+}
+
+void BME_connect_edges(BME_Mesh *bm)
+{
+	BME_Vert *nv;
+	BME_Edge *e, *e1, *e2;
+	BME_Loop *l;
+	BME_Poly *f;
+	int pass;
+	
+	for(f=BME_first(bm,BME_POLY);f;f=BME_next(bm,BME_POLY,f)){
+		e1 = e2 = NULL;
+		pass = 0;
+		l=f->loopbase;
+		do{
+			if(BME_SELECTED(l->e)){
+				if(e2) pass = 1;
+				else if(e1) e2 = l->e;
+				else e1 = l->e;
 			}
+			l = l->next;
+		}while(l!=f->loopbase);
+		
+		//if two edges selected and not pass, mark each one for split
+		if((e1) && (e2) && (pass == 0)) e1->tflag1 = e2->tflag1 = 1;
+	}
+	for(e=BME_first(bm,BME_EDGE);e;e=BME_next(bm,BME_EDGE,e)){
+		if(e->tflag1){
+			nv= BME_cut_edge(bm,e,1);
+			BME_VISIT(nv);
 		}
 	}
+	BME_connect_verts(bm);
 }
 
 
-
-
 /**
  *			BME_dissolve_edge
  *
@@ -128,7 +160,7 @@
  *
  */
 
-void BME_cut_edge(BME_Mesh *bm, BME_Edge *e, int numcuts)
+BME_Vert  *BME_cut_edge(BME_Mesh *bm, BME_Edge *e, int numcuts)
 {
 	int i;
 	float percent, step,length, vt1[3], v2[3];
@@ -148,6 +180,7 @@
 		VecMulf(nv->co,percent);
 		VecAddf(nv->co,v2,nv->co);
 	}
+	return nv;
 }
 
 

Modified: branches/bmesh/source/blender/include/editbmesh.h
===================================================================
--- branches/bmesh/source/blender/include/editbmesh.h	2007-10-08 09:24:29 UTC (rev 12230)
+++ branches/bmesh/source/blender/include/editbmesh.h	2007-10-08 13:03:00 UTC (rev 12231)
@@ -32,6 +32,7 @@
 void EM_extrude_mesh(void);
 void EM_clone_mesh(void);
 void EM_addedgeface(void);
+void EM_connect_edges(void);
 
 /*editbmesh_select.c*/
 void EM_deselectall_mesh(void);

Modified: branches/bmesh/source/blender/src/editbmesh_tools.c
===================================================================
--- branches/bmesh/source/blender/src/editbmesh_tools.c	2007-10-08 09:24:29 UTC (rev 12230)
+++ branches/bmesh/source/blender/src/editbmesh_tools.c	2007-10-08 13:03:00 UTC (rev 12231)
@@ -75,13 +75,26 @@
 #include "mydevice.h"
 
 void EM_cut_edges(int numcuts){
+	BME_Vert *v;
 	BME_model_begin(G.editMesh);
+	for(v=BME_first(G.editMesh,BME_VERT);v;v=BME_next(G.editMesh,BME_VERT,v)){
+		if(BME_SELECTED(v)) BME_VISIT(v);
+	}
 	BME_cut_edges(G.editMesh,numcuts);
 	BME_model_end(G.editMesh);
 	countall();
 	DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
 	allqueue(REDRAWVIEW3D, 0);
 }
+void EM_connect_edges(void){
+	BME_model_begin(G.editMesh);
+	BME_connect_edges(G.editMesh);
+	BME_model_end(G.editMesh);
+	countall();
+	DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
+	allqueue(REDRAWVIEW3D, 0);
+	
+}
 
 void EM_dissolve_edges(void){
 	BME_model_begin(G.editMesh);

Modified: branches/bmesh/source/blender/src/editobject.c
===================================================================
--- branches/bmesh/source/blender/src/editobject.c	2007-10-08 09:24:29 UTC (rev 12230)
+++ branches/bmesh/source/blender/src/editobject.c	2007-10-08 13:03:00 UTC (rev 12231)
@@ -2348,6 +2348,12 @@
 				BIF_undo_push("Cut Edges");            
 			}
 			break;
+		case 203:
+			{
+				EM_connect_edges();
+				BIF_undo_push("Connect Edges");
+			}
+			break;
 		case 205:
 			{
 				EM_dissolve_edges();





More information about the Bf-blender-cvs mailing list