[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11647] branches/soc-2007-red_fox/source/ blender/blenkernel: One last recode - math better now

Levi Schooley redfox at hhofministries.org
Sat Aug 18 03:34:02 CEST 2007


Revision: 11647
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11647
Author:   red_fox
Date:     2007-08-18 03:33:57 +0200 (Sat, 18 Aug 2007)

Log Message:
-----------
One last recode - math better now

This commit is fairly major, but you won't tell much 
difference from the user side. The tool now should be able to 
handle concave areas of polys, and should scale well if 
n-gons are ever brought into blender. Parallel edges meeting 
at a corner will still cause it to barf, though. I also 
refined the math, and got the max limits working half the time.

This tool is, basically, ready for the masses now!

Have fun!
Levi

Modified Paths:
--------------
    branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h
    branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_eulers.c
    branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c

Modified: branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h	2007-08-18 00:02:50 UTC (rev 11646)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h	2007-08-18 01:33:57 UTC (rev 11647)
@@ -208,11 +208,12 @@
 	float co[3];  /* the original coordinate */
 	float org[3]; /* the origin */
 	float vec[3]; /* a directional vector; always, always normalize! */
+	void *loc;    /* a pointer to the data to transform */
 	float factor; /* primary scaling factor; also accumulates number of weighted edges for beveling tool */
 	float weight; /* another scaling factor; used primarily for propogating vertex weights to transforms; */
 	              /* weight is also used across recursive bevels to help with the math */
+	float maxfactor; /* used during recursive beveling to ensure factor does not overshoot */
 	float max;    /* the maximum distance this vert can be transformed; negative is infinite */
-	void *loc;    /* a pointer to the data to transform */
 } BME_TransData;
 
 typedef struct BME_TransData_Head {

Modified: branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_eulers.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_eulers.c	2007-08-18 00:02:50 UTC (rev 11646)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_eulers.c	2007-08-18 01:33:57 UTC (rev 11647)
@@ -87,6 +87,11 @@
 	-Finish inserting 'strict' validation in all Eulers
 */
 
+void *BME_exit(char *s) {
+	if (s) printf("%s\n",s);
+	return NULL;
+}
+
 #define RETCLEAR(bm) {bm->rval->v = bm->rval->e = bm->rval->f = bm->rva->l = NULL;}
 /*MAKE Eulers*/
 
@@ -127,7 +132,7 @@
 	int valance1=0, valance2=0, edok;
 	
 	/*edge must be between two distinct vertices...*/
-	if(v1 == v2) return NULL;
+	if(v1 == v2) return BME_exit("ME returned NULL");
 	
 	#ifndef BME_FASTEULER
 	/*count valance of v1*/
@@ -194,10 +199,10 @@
 	BME_Vert *curvert, *tv, *nextv,**vlist;
 	int i, j, done, cont, edok,vlen;
 	
-	if(len < 2) return NULL;
+	if(len < 2) return BME_exit("MF returned NULL");
 	
 	/*make sure that v1 and v2 are in elist[0]*/
-	if(BME_verts_in_edge(v1,v2,elist[0]) == 0) return NULL;
+	if(BME_verts_in_edge(v1,v2,elist[0]) == 0) return BME_exit("MF returned NULL");
 	
 	/*clear euler flags*/
 	for(i=0;i<len;i++) elist[i]->eflag1=elist[i]->eflag2 = 0;
@@ -215,9 +220,9 @@
 	*/
 	for(i=0; i<len; i++){
 		edok = BME_disk_count_edgeflag(elist[i]->v1, MF_CANDIDATE, 0);
-		if(edok != 2) return NULL;
+		if(edok != 2) return BME_exit("MF returned NULL");
 		edok = BME_disk_count_edgeflag(elist[i]->v2, MF_CANDIDATE, 0);
-		if(edok != 2) return NULL;
+		if(edok != 2) return BME_exit("MF returned NULL");
 	}
 	
 	/*set start edge, start vert and target vert for our loop traversal*/
@@ -425,7 +430,7 @@
 	BME_Edge *ne;
 	int i, radlen, edok, valance1=0, valance2=0;
 	
-	if(BME_vert_in_edge(e,tv) == 0) return NULL;
+	if(BME_vert_in_edge(e,tv) == 0) return BME_exit("SEMV returned NULL");
 	ov = BME_edge_getothervert(e,tv);
 	//v2 = tv;
 
@@ -596,7 +601,7 @@
 	BME_Edge *e;
 	int i, len, f1len, f2len;
 	
-	if(f->holes.first) return NULL; //not good, fix me
+	if(f->holes.first) return BME_exit("SFME returned NULL"); //not good, fix me
 	
 	/*verify that v1 and v2 are in face.*/
 	len = BME_cycle_length(f->loopbase);
@@ -605,7 +610,7 @@
 		else if(curloop->v == v2) v2loop = curloop;
 	}
 	
-	if(!v1loop || !v2loop) return NULL;
+	if(!v1loop || !v2loop) return BME_exit("SFME returned NULL");
 	
 	/*allocate new edge between v1 and v2*/
 	e = BME_addedgelist(bm, v1, v2,NULL);
@@ -876,8 +881,8 @@
 	BME_Loop *curloop, *f1loop=NULL, *f2loop=NULL;
 	int loopok = 0, newlen = 0,i, f1len=0, f2len=0, radlen=0, valance1,valance2,edok;
 	
-	if(f1->holes.first || f2->holes.first) return NULL; //dont operate on faces with holes. Not best solution but tolerable.
-	if(f1 == f2) return NULL; //can't join a face to itself
+	if(f1->holes.first || f2->holes.first) return BME_exit("JFKE returned NULL"); //dont operate on faces with holes. Not best solution but tolerable.
+	if(f1 == f2) return BME_exit("JFKE returned NULL"); //can't join a face to itself
 	/*verify that e is in both f1 and f2*/
 	f1len = BME_cycle_length(f1->loopbase);
 	f2len = BME_cycle_length(f2->loopbase);
@@ -893,23 +898,23 @@
 			break;
 		}
 	}
-	if(!(f1loop && f2loop)) return NULL;
+	if(!(f1loop && f2loop)) return BME_exit("JFKE returned NULL");
 	
 	/*validate that edge is 2-manifold edge*/
 	radlen = BME_cycle_length(&(f1loop->radial));
-	if(radlen != 2) return NULL;
+	if(radlen != 2) return BME_exit("JFKE returned NULL");
 
 	/*validate direction of f2's loop cycle is compatible.*/
-	if(f1loop->v == f2loop->v) return NULL;
+	if(f1loop->v == f2loop->v) return BME_exit("JFKE returned NULL");
 	
 	/*
 		Finally validate that for each face, each vertex has another edge in its disk cycle that is 
 		not e, and not shared.
 	*/
-	if(BME_radial_find_face(f1loop->next->e,f2)) return NULL;
-	if(BME_radial_find_face(f1loop->prev->e,f2)) return NULL;
-	if(BME_radial_find_face(f2loop->next->e,f1)) return NULL;
-	if(BME_radial_find_face(f2loop->prev->e,f1)) return NULL;
+	if(BME_radial_find_face(f1loop->next->e,f2)) return BME_exit("JFKE returned NULL");
+	if(BME_radial_find_face(f1loop->prev->e,f2)) return BME_exit("JFKE returned NULL");
+	if(BME_radial_find_face(f2loop->next->e,f1)) return BME_exit("JFKE returned NULL");
+	if(BME_radial_find_face(f2loop->prev->e,f1)) return BME_exit("JFKE returned NULL");
 	
 	/*join the two loops*/
 	f1loop->prev->next = f2loop->next;

Modified: branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c	2007-08-18 00:02:50 UTC (rev 11646)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c	2007-08-18 01:33:57 UTC (rev 11647)
@@ -54,8 +54,8 @@
  *
  *	Edge Dissolve Function:
  *
- *	Dissolves a 2-manifold edge by joining it's two faces. if 
- *	they have opposite windings it first makes them consistent 
+ *	Dissolves a 2-manifold edge by joining it's two faces. if
+ *	they have opposite windings it first makes them consistent
  *	by calling BME_loop_reverse()
  *
  *	Returns -
@@ -66,7 +66,7 @@
  *
  *	Edge Inset Function:
  *
- *	Splits a face in two along an edge and returns the next loop 
+ *	Splits a face in two along an edge and returns the next loop
  *
  *	Returns -
  *	A BME_Poly pointer.
@@ -75,7 +75,7 @@
 BME_Loop *BME_inset_edge(BME_Mesh *bm, BME_Loop *l, BME_Poly *f){
 	BME_Loop *nloop;
 	BME_SFME(bm, f, l->v, l->next->v, &nloop);
-	return nloop->next; 
+	return nloop->next;
 }
 
 /**
@@ -83,7 +83,7 @@
  *
  *	Face Inset Tool:
  *
- *	Insets a single face and returns a pointer to the face at the 
+ *	Insets a single face and returns a pointer to the face at the
  *	center of the newly created region
  *
  *	Returns -
@@ -119,8 +119,6 @@
 	cent[1] = (min[1] + max[1]) / 2.0f;
 	cent[2] = (min[2] + max[2]) / 2.0f;
 
-
-
 	/*inset each edge in the polygon.*/
 	len = f->len;
 	for(i=0,l=f->loopbase; i < len; i++){
@@ -130,10 +128,10 @@
 	}
 
 	/*for each new edge, call SEMV on it*/
-	for(i=0,l=f->loopbase; i < len; i++, l=l->next){ 
+	for(i=0,l=f->loopbase; i < len; i++, l=l->next){
 		l->tflag1 = 1; //going to store info that this loops edge still needs split
 		f = BME_SFME(bm,l->f,l->v,l->next->v,NULL);
-		l->tflag2 = l->v->tflag1 = l->v->tflag2 = 0; 
+		l->tflag2 = l->v->tflag1 = l->v->tflag2 = 0;
 	}
 
 	len = f->len;
@@ -194,7 +192,8 @@
 }
 
 BME_TransData *BME_assign_transdata(BME_TransData_Head *td, BME_Mesh *bm, BME_Vert *v,
-		float *co, float *org, float *vec, float factor, float weight) {
+		float *co, float *org, float *vec, float *loc,
+		float factor, float weight, float maxfactor, float max) {
 	BME_TransData *vtd;
 	int is_new = 0;
 
@@ -220,11 +219,12 @@
 		VECCOPY(vtd->vec,vec);
 		Normalize(vtd->vec);
 	}
+	vtd->loc = loc;
 
-	vtd->weight = weight;
 	vtd->factor = factor;
-	vtd->max = -1;
-	vtd->loc = v->co;
+	vtd->weight = weight;
+	vtd->maxfactor = maxfactor;
+	vtd->max = max;
 
 	return vtd;
 }
@@ -235,67 +235,6 @@
 	return vtd;
 }
 
-/* tests an edge to see how "long" it is, and lowers the max if it is smaller */
-float BME_bevel_set_max(BME_Edge *e,float *max) {
-	float len;
-
-	if ((e->v1->tflag1 & BME_BEVEL_BEVEL) && (e->v2->tflag1 & BME_BEVEL_BEVEL)) {
-		len = VecLenf(e->v1->co,e->v2->co)/2.0f;
-	}
-	else if ((e->v1->tflag1 & BME_BEVEL_BEVEL)==0 && (e->v2->tflag1 & BME_BEVEL_BEVEL)==0) {
-		return -1;
-	}
-	else {
-		len = VecLenf(e->v1->co,e->v2->co);
-	}
-	if (len < *max || *max < 0) {
-		*max = len;
-	}
-	return len;
-}
-
-float inset_corner_vec(float *vec, float *v1, float *v2, float *v3, float *no) {
-	float a[3], c[3], n_a[3], n_c[3], tno[3], ac, ac2, fac;
-
-	VecSubf(a, v1, v2);
-	VecSubf(c, v3, v2);
-	Normalize(a);
-	Normalize(c);
-	ac = Inpf(a, c);
-
-	if (no == NULL) {
-		no = tno;
-		Crossf(tno, a, c);
-	}
-
-	Crossf(n_a, no, a);
-	Crossf(n_c, c, no);
-	Normalize(n_a);
-	Normalize(n_c);
-
-	if (ac == 1 || ac == -1) {
-		vec[0] = vec[1] = vec[2] = 0;
-		return 0;
-	}
-
-	ac2 = ac * ac;
-	fac = (float)sqrt((ac2 + 2*ac + 1)/(1 - ac2) + 1);
-	VecAddf(vec, n_c, n_a);
-	Normalize(vec);
-
-	return fac;
-}
-
-void bevel_slide_vec(float *midvec, float *v1, float *v2, float d) {
-	float mid[3];
-
-	VecSubf(mid, v2, v1);
-	Normalize(mid);
-	VecMulf(mid, -d);
-	VecAddf(mid, mid, v1);
-	VecCopyf(midvec, mid);
-}
-
 int BME_is_nonmanifold_vert(BME_Mesh *bm, BME_Vert *v) {
 	BME_Edge *e, *oe;
 	BME_Loop *l;
@@ -370,6 +309,7 @@
 	return 0;
 }
 
+/* a wrapper for BME_SFME that transfers element flags */
 BME_Poly *BME_split_face(BME_Mesh *bm, BME_Poly *f, BME_Vert *v1, BME_Vert *v2, BME_Loop **nl, BME_Edge *example) {
 	BME_Poly *nf;
 	nf = BME_SFME(bm,f,v1,v2,nl);
@@ -387,6 +327,7 @@
 	return nf;
 }
 
+/* a wrapper for BME_SEMV that transfers element flags */
 BME_Vert *BME_split_edge(BME_Mesh *bm, BME_Vert *v, BME_Edge *e, BME_Edge **ne, float percent) {
 	BME_Vert *nv, *v2;
 	float len;
@@ -407,85 +348,204 @@
 	return nv;
 }
 
-BME_Vert *BME_bevel_split_edge(BME_Mesh *bm, BME_Edge *e, BME_Vert *v1, BME_Vert *v2, float value, BME_TransData_Head *td) {
+/* get a vector, vec, that points from v1->co to wherever makes sense to

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list