[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11575] branches/soc-2007-red_fox/source/ blender: Initial go at multi-resolution

Levi Schooley redfox at hhofministries.org
Mon Aug 13 21:19:18 CEST 2007


Revision: 11575
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11575
Author:   red_fox
Date:     2007-08-13 21:19:18 +0200 (Mon, 13 Aug 2007)

Log Message:
-----------
Initial go at multi-resolution

This is primarily working code. I needed to commit before I 
jumped into a brief algorithm refactor. Multi-resolution 
works by recursively beveling the mesh. It doesn't work 
properly on corners for higher levels. Press numpad +/- to 
move between levels, or set the option in the modifier.c

Levi

Modified Paths:
--------------
    branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h
    branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c
    branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c
    branches/soc-2007-red_fox/source/blender/blenkernel/intern/modifier.c
    branches/soc-2007-red_fox/source/blender/makesdna/DNA_modifier_types.h
    branches/soc-2007-red_fox/source/blender/src/buttons_editing.c
    branches/soc-2007-red_fox/source/blender/src/editmesh_tools.c
    branches/soc-2007-red_fox/source/blender/src/transform.c
    branches/soc-2007-red_fox/source/blender/src/transform_conversions.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-13 18:04:38 UTC (rev 11574)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h	2007-08-13 19:19:18 UTC (rev 11575)
@@ -209,7 +209,9 @@
 	float org[3]; /* the origin */
 	float vec[3]; /* a directional vector; always, always normalize! */
 	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 */
+	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 max;    /* the maximum distance this vert can be transformed; negative is infinite */
 	void *loc;    /* a pointer to the data to transform */
 } BME_TransData;
 
@@ -217,7 +219,6 @@
 	GHash *gh;       /* the hash structure for element lookup */
 	MemArena *ma;    /* the memory "pool" we will be drawing individual elements from */
 	int len;
-	float max;       /* the maximum bevel value that can be applied during transform */
 } BME_TransData_Head;
 
 typedef struct BME_Glob { /* stored in Global G for Transform() purposes */
@@ -226,11 +227,12 @@
 	struct TransInfo *Trans; /* a pointer to the global Trans struct */
 	int imval[2]; /* for restoring original mouse co when initTransform() is called multiple times */
 	int options;
+	int res;
 } BME_Glob;
 
 struct BME_TransData *BME_get_transdata(struct BME_TransData_Head *td, struct BME_Vert *v);
 void BME_free_transdata(struct BME_TransData_Head *td);
-struct BME_Mesh *BME_bevel_mesh(struct BME_Mesh *bm, float value, int res, int options, int defgrp_index, BME_TransData_Head **rtd);
+struct BME_Mesh *BME_bevel(struct BME_Mesh *bm, float value, int res, int options, int defgrp_index, BME_TransData_Head **rtd);
 
 /*CONVERSION FUNCTIONS*/
 struct BME_Mesh *BME_editmesh_to_bmesh(EditMesh *em, struct BME_Mesh *bm);

Modified: branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c	2007-08-13 18:04:38 UTC (rev 11574)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_conversions.c	2007-08-13 19:19:18 UTC (rev 11575)
@@ -92,8 +92,8 @@
 	CustomData_copy(&em->edata, &bm->edata, CD_MASK_EDITMESH, CD_CALLOC, 0);
 	eed= em->edges.first;
 	while(eed) {
-		v1 = (BME_Vert*)eed->v1->tmp.l;
-		v2 = (BME_Vert*)eed->v2->tmp.l;
+		v1 = (BME_Vert*)eed->v1->tmp.v;
+		v2 = (BME_Vert*)eed->v2->tmp.v;
 		e = BME_ME(bm, v1, v2);
 		e->crease = eed->crease;
 		e->flag = eed->f & SELECT;

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-13 18:04:38 UTC (rev 11574)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c	2007-08-13 19:19:18 UTC (rev 11575)
@@ -194,7 +194,7 @@
 }
 
 BME_TransData *BME_assign_transdata(BME_TransData_Head *td, BME_Mesh *bm, BME_Vert *v,
-		float *co, float *org, float *vec, float weight, float factor) {
+		float *co, float *org, float *vec, float factor, float weight) {
 	BME_TransData *vtd;
 	int is_new = 0;
 
@@ -207,6 +207,8 @@
 		is_new = 1;
 	}
 
+	vtd->bm = bm;
+	vtd->v = v;
 	if (co != NULL) VECCOPY(vtd->co,co);
 	if (org == NULL && is_new) { VECCOPY(vtd->org,v->co); } /* default */
 	else if (org != NULL) VECCOPY(vtd->org,org);
@@ -221,6 +223,8 @@
 
 	vtd->weight = weight;
 	vtd->factor = factor;
+	vtd->max = -1;
+	vtd->loc = v->co;
 
 	return vtd;
 }
@@ -234,7 +238,7 @@
 /* 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;
 	}
@@ -282,39 +286,6 @@
 	return fac;
 }
 
-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);
-	nf->flag = f->flag;
-	nf->h = f->h;
-	nf->mat_nr = f->mat_nr;
-	if (nl && example) {
-		(*nl)->e->flag = example->flag;
-		(*nl)->e->h = example->h;
-		(*nl)->e->crease = example->crease;
-	}
-
-	return nf;
-}
-
-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;
-
-	v2 = BME_edge_getothervert(e,v);
-	nv = BME_SEMV(bm,v,e,ne);
-	if (nv == NULL) return NULL;
-	VECSUB(nv->co,v2->co,v->co);
-	len = VecLength(nv->co);
-	VECADDFAC(nv->co,v->co,nv->co,len*percent);
-	nv->flag = v->flag;
-	(*ne)->flag = e->flag;
-	(*ne)->h = e->h;
-	(*ne)->crease = e->crease;
-
-	return nv;
-}
-
 void bevel_slide_vec(float *midvec, float *v1, float *v2, float d) {
 	float mid[3];
 
@@ -354,7 +325,7 @@
 	e = NULL;
 	oe = v->edge;
 	l = oe->loop;
-	do {
+	while(e != oe) {
 		if (l->v == v) l = l->prev;
 		else l = l->next;
 		e = l->e;
@@ -375,7 +346,7 @@
 		else {
 			l = l->radial.next->data;
 		}
-	} while(e != oe);
+	}
 
 	if (count < len) {
 		/* vert shared by multiple regions */
@@ -385,39 +356,6 @@
 	return 0;
 }
 
-BME_Vert *BME_bevel_wire(BME_Mesh *bm, BME_Vert *v, float value, int res, int options, BME_TransData_Head *td) {
-	BME_Edge *e, *ne;
-	BME_Vert *nv;
-	BME_TransData *vtd;
-	float vec[3];
-
-	/* this edge will be split; v->edge will remain intact */
-	e = BME_disk_nextedge(v->edge, v);
-
-	/* get transform vector */
-	nv = BME_edge_getothervert(e, v);
-	VECSUB(vec,nv->co,v->co);
-
-	/* split the edge */
-	nv = BME_SEMV(bm, v, e, &ne);
-	/* assign the transform vector to the new vert */
-	vtd = BME_assign_transdata(td, bm, nv, v->co, v->co, vec, 1.0, 1.0);
-	/* copy flags */
-	nv->flag = v->flag;
-	ne->crease = e->crease;
-	ne->flag = e->flag;
-
-	/* gather and assign transform data for the original vert and edge */
-	nv = BME_edge_getothervert(v->edge, v);
-	VECSUB(vec,nv->co,v->co);
-	vtd = BME_assign_transdata(td, bm, v, v->co, v->co, vec, 1.0, 1.0);
-
-	/* temporary test - see if transform data was stored correctly */
-	VECADDFAC(v->co,vtd->org,vtd->vec,(vtd->factor*value));
-	vtd = BME_get_transdata(td, v);
-	return v;
-}
-
 int BME_bevel_is_split_vert(BME_Loop *l) {
 	/* look for verts that have already been added to the edge when
 	 * beveling other polys; this can be determined by testing the
@@ -432,48 +370,233 @@
 	return 0;
 }
 
+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);
+	nf->flag = f->flag;
+	/* if the edge was selected, select this face, too */
+	if (example->flag & SELECT) f->flag |= ME_FACE_SEL;
+	nf->h = f->h;
+	nf->mat_nr = f->mat_nr;
+	if (nl && example) {
+		(*nl)->e->flag = example->flag;
+		(*nl)->e->h = example->h;
+		(*nl)->e->crease = example->crease;
+	}
+
+	return nf;
+}
+
+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;
+
+	v2 = BME_edge_getothervert(e,v);
+	nv = BME_SEMV(bm,v,e,ne);
+	if (nv == NULL) return NULL;
+	VECSUB(nv->co,v2->co,v->co);
+	len = VecLength(nv->co);
+	VECADDFAC(nv->co,v->co,nv->co,len*percent);
+	nv->flag = v->flag;
+	if (ne) {
+		(*ne)->flag = e->flag;
+		(*ne)->h = e->h;
+		(*ne)->crease = e->crease;
+	}
+
+	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) {
+	BME_TransData *vtd1, *vtd2;
+	BME_Edge *ne;
+	float scale, vec[3], len;
+	int edge_vert;
+
+	/* note: in order to best support recursive beveling prior to the
+	 * final transform operation, we are beveling in a strange combination
+	 * of virtual and actual coordinates. vtd and vtd2 are used to obtain
+	 * and store the "virtual" coordinates, but the transform data will
+	 * ultimately be derived from the verts' coordinates */
+	vtd1 = BME_get_transdata(td, v1);
+	vtd2 = BME_get_transdata(td,v2);
+
+	if (vtd1->loc == NULL) {
+		/* this is a vert with data only for calculating initial weights */
+		scale = vtd1->weight/vtd1->factor;
+	}
+	else {
+		scale = vtd1->weight;
+	}
+
+	if (vtd1->loc == NULL) {
+		/* set max */
+		/* but to do this, we'll need more info */
+	}
+
+	/* note: edge verts (verts that lie on an edge existing from the first bevel)
+	 * are special in that we do not want to clip their distance or, even, use the
+	 * adjacent vert on the edge to determine the "displacement" vector (since in
+	 * our crazy virtual/actual coordinates, they may overlap). */
+	/* test to see if this will be an edge vert by comparing the transform origins */
+	VECSUB(vec,vtd2->org,vtd1->org);
+	if (VecLength(vec) > 0.000001) {
+		edge_vert = 1;
+		Normalize(vec);
+	}
+	else {
+		edge_vert = 0;
+		VECSUB(vec,v2->co,v1->co);
+	}
+	v1 = BME_split_edge(bm,v1,e,&ne,0);
+	v1->tflag1 |= BME_BEVEL_BEVEL;
+	ne->tflag1 = BME_BEVEL_ORIG; /* mark edge as original, even though it isn't */
+	if (edge_vert) {
+		VECADDFAC(v1->co,vtd1->v->co,vec,value*scale);
+	}
+	else {
+		len = VecLength(vec);
+		Normalize(vec);
+		if (len/3 < value*scale) {
+			VECADDFAC(v1->co,vtd1->v->co,vec, len/3);
+		}
+		else {
+			VECADDFAC(v1->co,vtd1->v->co,vec, value*scale);
+		}
+	}
+	VECSUB(vec,v1->co,vtd1->org);
+	len = VecLength(vec);
+	Normalize(vec);
+	BME_assign_transdata(td, bm, v1, vtd1->org, vtd1->org, vec, len, scale);
+
+	return v1;
+}
+
+BME_Vert *BME_bevel_wire(BME_Mesh *bm, BME_Vert *v, float value, int res, int options, BME_TransData_Head *td) {
+	BME_Edge *e1, *e2;
+	BME_Vert *v1, *v2;
+
+	e1 = v->edge;
+	e2 = BME_disk_nextedge(v->edge, v);
+	v1 = BME_edge_getothervert(e1, v);
+	v2 = BME_edge_getothervert(e2, v);
+
+	/* get transform vector */
+
+	/* split the edges */
+	v1 = BME_bevel_split_edge(bm,e1,v,v1,value,td);
+	v2 = BME_bevel_split_edge(bm,e2,v,v2,value,td);
+	v1->tflag1 |= BME_BEVEL_NONMAN;
+	v2->tflag1 |= BME_BEVEL_NONMAN;
+
+	/* remove the original vert */
+	BME_JEKV(bm,v->edge,v);
+
+	return v1;
+}
+
 BME_Loop *BME_bevel_corner(BME_Mesh *bm, BME_Loop *l, float value, int options, BME_TransData_Head *td, float *max) {
-	BME_TransData *vtd;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list