[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36181] branches/bmesh/blender/source/ blender: =bmesh= connected PET now works, for the most part

Joseph Eagar joeedh at gmail.com
Fri Apr 15 09:08:36 CEST 2011


Revision: 36181
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36181
Author:   joeedh
Date:     2011-04-15 07:08:36 +0000 (Fri, 15 Apr 2011)
Log Message:
-----------
=bmesh= connected PET now works, for the most part

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_structure.c
    branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
    branches/bmesh/blender/source/blender/editors/transform/transform_conversions.c

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c	2011-04-15 05:20:18 UTC (rev 36180)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_construct.c	2011-04-15 07:08:36 UTC (rev 36181)
@@ -335,7 +335,7 @@
 	for (i=0; i<len; i++) {
 		edges2[i] = BM_Edge_Exist(verts[i], verts[(i+1)%len]);
 		if (!edges2[i])
-			return NULL;
+			goto err;
 	}
 
 	/*check if face already exists*/

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators.c	2011-04-15 05:20:18 UTC (rev 36180)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_iterators.c	2011-04-15 07:08:36 UTC (rev 36181)
@@ -216,12 +216,10 @@
 	BMLoop *l;
 
 	l = iter->edata->l;
-	if (!l)
-		return;
 
 	/*note sure why this sets ldata. . .*/
 	init_iterator(iter);
-
+	
 	iter->firstloop = iter->nextloop = l;
 }
 

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c	2011-04-15 05:20:18 UTC (rev 36180)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c	2011-04-15 07:08:36 UTC (rev 36181)
@@ -579,6 +579,11 @@
 			
 			do {
 				lnext = l->radial_next;
+				if (lnext->f == l->f) {
+					BM_Kill_Face(bm, l->f);
+					break;					
+				}
+				
 				BM_Kill_Face(bm, l->f);
 			
 				if (l == lnext)

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_structure.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_structure.c	2011-04-15 05:20:18 UTC (rev 36180)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_structure.c	2011-04-15 07:08:36 UTC (rev 36181)
@@ -317,16 +317,28 @@
 int bmesh_radial_validate(int radlen, BMLoop *l)
 {
 	BMLoop *l2 = l;
-
+	int i=0;
+	
 	if (bmesh_radial_length(l) != radlen)
 		return 0;
 
 	do {
+		if (!l2) {
+			bmesh_error();
+			return 0;
+		}
+		
 		if (l2->e != l->e)
 			return 0;
 		if (l2->v != l->e->v1 && l2->v != l->e->v2)
 			return 0;
-
+		
+		if (i > 3000000) {
+			bmesh_error();
+			return 0;
+		}
+		
+		i++;
 		l2 = l2->radial_next;
 	} while (l2 != l);
 
@@ -394,6 +406,11 @@
 		return 0;
 
 	do {
+		if (!l2) {
+			bmesh_error();
+			return 0;
+		}
+		
 		i++;
 		l2 = l2->radial_next;
 		if (i >= 555555)

Modified: branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/bevel.c	2011-04-15 05:20:18 UTC (rev 36180)
+++ branches/bmesh/blender/source/blender/bmesh/operators/bevel.c	2011-04-15 07:08:36 UTC (rev 36181)
@@ -32,29 +32,61 @@
 	BMVert *newv1, *newv2;
 } EdgeTag;
 
-void calc_corner_co(BMesh *UNUSED(bm), BMLoop *l, float *co, float fac)
+void calc_corner_co(BMesh *bm, BMLoop *l, float *co, float fac)
 {
-	float /* no[3], tan[3], */ vec1[3], vec2[3], v1[3], v2[3], v3[3], v4[3];
-	// float p1[3], p2[3], w[3];
-	// float l1, l2;
-	// int ret;
+	float  no[3], tan[3], vec1[3], vec2[3], v1[3], v2[3], v3[3], v4[3];
+	float p1[3], p2[3], w[3];
+	float l1, l2;
+	int ret, inv=0;
+	
+	if (l->f->len > 2) {
+		copy_v3_v3(v1, l->prev->v->co);
+		copy_v3_v3(v2, l->v->co);
+		copy_v3_v3(v3, l->v->co);
+		copy_v3_v3(v4, l->next->v->co);
+	} else {
+		BMIter iter;
+		BMLoop *l2;
+		float up[3] = {0.0f, 0.0f, 1.0f};
+		
+		copy_v3_v3(v1, l->prev->v->co);
+		copy_v3_v3(v2, l->v->co);
+		copy_v3_v3(v3, l->v->co);
+		
+		BM_ITER(l2, &iter, bm, BM_LOOPS_OF_VERT, l->v) {
+			if (l2->f != l) {
+				copy_v3_v3(v4, BM_OtherEdgeVert(l2->e, l2->next->v));
+				break;
+			}
+		}
+		
+		sub_v3_v3v3(vec1, v1, v2);
+		sub_v3_v3v3(vec2, v4, v3);
 
-	copy_v3_v3(v1, l->prev->v->co);
-	copy_v3_v3(v2, l->v->co);
-	copy_v3_v3(v3, l->v->co);
-	copy_v3_v3(v4, l->next->v->co);
+		cross_v3_v3v3(no, vec1, vec2);
+		if (dot_v3v3(no, no) == 0.0) {
+			no[0] = no[1] = 0.0f; no[2] = -1.0f;	
+		}
+		
+		inv = dot_v3v3(no, up) < 0.0;
+	}
 	
 	/*calculate normal*/
 	sub_v3_v3v3(vec1, v1, v2);
 	sub_v3_v3v3(vec2, v4, v3);
+	
 #if 0
 	cross_v3_v3v3(no, vec2, vec1);
 	normalize_v3(no);
 	
-	if (dot_v3v3(no, no) < DBL_EPSILON*10) {
+	if (dot_v3v3(no, no) < FLT_EPSILON*10) {
 		copy_v3_v3(no, l->f->no);
 	}
 	
+	if (dot_v3v3(no, no) < FLT_EPSILON*10) {
+		no[0] = 0.0; no[1] = 0.0; no[2] = 1.0f;
+	}
+	
 	/*compute offsets*/
 	l1 = len_v3(vec1)*fac;
 	l2 = len_v3(vec2)*fac;
@@ -83,6 +115,12 @@
 	
 	/*compute intersection*/
 	ret = isect_line_line_v3(v1, v2, v3, v4, p1, p2);
+	if (len_v3v3(p1, v1) > len_v3v3(v1, v2) || len_v3v3(p1, v2) > len_v3v3(v1, v2))
+		copy_v3_v3(p1, v2);
+	
+	if (len_v3v3(p1, v3) > len_v3v3(v3, v4) || len_v3v3(p1, v4) > len_v3v3(v3, v4))
+		copy_v3_v3(p2, v3);
+	
 	if (ret==1) {
 		copy_v3_v3(co, p1);
 	} else if (ret==2) {
@@ -92,14 +130,18 @@
 		add_v3_v3v3(co, v2, v3);
 		mul_v3_fl(co, 0.5);
 	}
-#endif
+#else
 	/*oddly, this simplistic method seems to work the best*/
 	mul_v3_fl(vec1, fac);
 	mul_v3_fl(vec2, fac);
 	add_v3_v3(vec1, vec2);
 	mul_v3_fl(vec1, 0.5);
+
+	if (inv)
+		negate_v3(vec1);
 	
 	add_v3_v3v3(co, vec1, l->v->co);
+#endif
 }
 
 #define ETAG_SET(e, v, nv) (v) == (e)->v1 ? (etags[BMINDEX_GET((e))].newv1 = (nv)) : (etags[BMINDEX_GET((e))].newv2 = (nv))
@@ -111,7 +153,7 @@
 	BMIter iter;
 	BMEdge *e;
 	BMVert *v;
-	BMFace **faces = NULL;
+	BMFace **faces = NULL, *f;
 	LoopTag *tags=NULL, *tag;
 	EdgeTag *etags = NULL, *etag;
 	BMVert **verts = NULL;
@@ -137,6 +179,15 @@
 			BMO_ClearFlag(bm, e->v1, BEVEL_DEL);
 			BMO_ClearFlag(bm, e->v2, BEVEL_DEL);
 		}
+#if 0
+		if (BM_Edge_FaceCount(e) == 0) {
+			BMVert *verts[2] = {e->v1, e->v2};
+			BMEdge *edges[2] = {e, BM_Make_Edge(bm, e->v1, e->v2, e, 0)};
+			
+			BMO_SetFlag(bm, edges[1], BEVEL_FLAG);
+			BM_Make_Face(bm, verts, edges, 2);
+		}
+#endif
 	}
 	
 	BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) {
@@ -198,7 +249,6 @@
 			BMO_ClearFlag(bm, e, BEVEL_DEL);
 			BMO_ClearFlag(bm, e->v1, BEVEL_DEL);
 			BMO_ClearFlag(bm, e->v2, BEVEL_DEL);
-			//continue;	
 		}
 		
 		if (!BLI_smallhash_haskey(&hash, (intptr_t)e)) {
@@ -338,14 +388,35 @@
 			}
 		}
 		
-		for (j=0; j<BLI_array_count(verts); j++) {
-			BMVert *next = verts[(j+1)%BLI_array_count(verts)];
-
-			e = BM_Make_Edge(bm, next, verts[j], NULL, 1);
-			BLI_array_append(edges, e);
+		if (BLI_array_count(verts) == 2) {
+			BMEdge *e1=NULL, *e2=NULL;
+			
+			BM_ITER(l, &liter, bm, BM_LOOPS_OF_VERT, verts[0]) {
+				if (BM_Vert_In_Edge(l->e, verts[1])) {
+					if (!e1)
+						e1 = l->e;
+					else if (!e2) 
+						e2 = l->e;
+				}	
+			}
+			
+			if (!e1)
+				e1 = BM_Make_Edge(bm, verts[0], verts[1], NULL, 0);
+			if (!e2) 
+				e2 = BM_Make_Edge(bm, verts[0], verts[1], NULL, 0);
+			
+			BLI_array_append(edges, e1);
+			BLI_array_append(edges, e2);
+		} else {
+			for (j=0; j<BLI_array_count(verts); j++) {
+				BMVert *next = verts[(j+1)%BLI_array_count(verts)];
+				
+				e = BM_Make_Edge(bm, next, verts[j], NULL, 1);
+				BLI_array_append(edges, e);
+			}
 		}
 		
-		f = BM_Make_Face(bm, verts, edges, BLI_array_count(verts));
+		f = BM_Make_Ngon(bm, verts[0], verts[1], edges, BLI_array_count(verts), 0);
 		if (!f) {
 			printf("eck!!\n");
 			continue;
@@ -657,7 +728,20 @@
 			}
 		}
 	}
-
+#if 0
+	/*clean up any remainin 2-edged faces*/
+	BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
+		if (f->len == 2) {
+			BMFace *faces[2] = {f, bm_firstfaceloop(f)->radial_next->f};
+			
+			if (faces[0] == faces[1])
+				BM_Kill_Face(bm, f);
+			else
+				BM_Join_Faces(bm, faces, 2);
+		}
+	}
+#endif
+	
 	BMO_CallOpf(bm, "del geom=%fv context=%i", BEVEL_DEL, DEL_VERTS);
 
 	/*clean up any edges that might not get properly deleted*/

Modified: branches/bmesh/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/transform/transform_conversions.c	2011-04-15 05:20:18 UTC (rev 36180)
+++ branches/bmesh/blender/source/blender/editors/transform/transform_conversions.c	2011-04-15 07:08:36 UTC (rev 36181)
@@ -1824,17 +1824,16 @@
   or slow this is.*/
 static void editmesh_set_connectivity_distance(BMEditMesh *em, float mtx[][3], float *dists)
 {
-	BMVert **stack = NULL;
-	float *dstack = NULL;
-	BLI_array_declare(stack);
-	BLI_array_declare(dstack);
+	BMVert **queue = NULL;
+	float *dqueue = NULL;
+	int *tots = MEM_callocN(sizeof(int)*em->bm->totvert, "tots editmesh_set_connectivity_distance");
+	BLI_array_declare(queue);
+	BLI_array_declare(dqueue);
 	SmallHash svisit, *visit=&svisit;
 	BMVert *v;
 	BMIter viter;
 	int i;
 	
-	BLI_smallhash_init(visit);
-	
 	i = 0;
 	BM_ITER(v, &viter, em->bm, BM_VERTS_OF_MESH, NULL) {
 		BMINDEX_SET(v, i);
@@ -1844,26 +1843,30 @@
 	
 	BM_ITER(v, &viter, em->bm, BM_VERTS_OF_MESH, NULL) {
 		BMVert *v2;
+		int start;
 		
-		if (BLI_smallhash_haskey(visit, (uintptr_t)v) || BM_TestHFlag(v, BM_SELECT)==0 || BM_TestHFlag(v, BM_HIDDEN))
+		if (BM_TestHFlag(v, BM_SELECT)==0 || BM_TestHFlag(v, BM_HIDDEN))
 			continue;
 			
-		BLI_array_empty(stack);
-		BLI_array_append(stack, v);
-		BLI_array_append(dstack, 0.0f);
+		BLI_smallhash_init(visit);
 
+		BLI_array_empty(queue);
+		BLI_array_append(queue, v);
+		BLI_array_append(dqueue, 0.0f);
+		dists[BMINDEX_GET(v)] = 0.0f;
+		
 		BLI_smallhash_insert(visit, (uintptr_t)v, NULL);		
+		start = 0;
 		
-		while (BLI_array_count(stack)) {
+		while (start < BLI_array_count(queue)) {
 			BMIter eiter;
 			BMEdge *e;
 			BMVert *v3;
 			float d, d2, vec[3];
 			
-			v2 = BLI_array_pop(stack);
-			d = BLI_array_pop(dstack);
+			v2 = queue[start];
+			d = dqueue[start];
 			
-			dists[BMINDEX_GET(v2)] = d;
 			BM_ITER(e, &eiter, em->bm, BM_EDGES_OF_VERT, v2) {
 				float d2;
 				v3 = BM_OtherEdgeVert(e, v2);
@@ -1876,22 +1879,37 @@
 				
 				d2 = d + len_v3(vec);
 				
-				if (d2 >= dists[BMINDEX_GET(v3)] && BLI_smallhash_haskey(visit, (uintptr_t)v3))
+				if (BLI_smallhash_haskey(visit, (uintptr_t)v3))
 					continue;
 				
-				dists[BMINDEX_GET(v3)] = d2;
+				if (dists[BMINDEX_GET(v3)] != FLT_MAX)
+					dists[BMINDEX_GET(v3)] += d2;
+				else
+					dists[BMINDEX_GET(v3)] = d2;
+				
+				tots[BMINDEX_GET(v3)]++;
+				
 				if (!BLI_smallhash_haskey(visit, (uintptr_t)v3))

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list