[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11821] branches/soc-2007-red_fox/source/ blender: Added limit-by-angle to the bevel modifier.c

Levi Schooley redfox at hhofministries.org
Sat Aug 25 08:20:52 CEST 2007


Revision: 11821
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11821
Author:   red_fox
Date:     2007-08-25 08:20:52 +0200 (Sat, 25 Aug 2007)

Log Message:
-----------
Added limit-by-angle to the bevel modifier.c

Added a basic limit-by-angle option to the modifier. There 
isn't any error checking or optimization yet, so still some 
tweaking to do. It is set in much the same way as the 
EdgeSplit modifier's angle option. Smaller angle value means 
that "duller" edges will be beveled.

Levi

Modified Paths:
--------------
    branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h
    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/src/buttons_editing.c
    branches/soc-2007-red_fox/source/blender/src/editmesh_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-25 04:22:20 UTC (rev 11820)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/BKE_bmesh.h	2007-08-25 06:20:52 UTC (rev 11821)
@@ -236,7 +236,7 @@
 
 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(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, float angle, 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_tools.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c	2007-08-25 04:22:20 UTC (rev 11820)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c	2007-08-25 06:20:52 UTC (rev 11821)
@@ -405,7 +405,7 @@
 	Normalize(vec3);
 	c1 = Inpf(vec3,vec1);
 	c2 = Inpf(vec1,vec1);
-	if (c1 == 0.0f || c2 == 0.0f) {
+	if (fabs(c1) < 0.000001f || fabs(c2) < 0.000001f) {
 		factor = 0.0f;
 	}
 	else {
@@ -523,9 +523,7 @@
 		scale = vtd1->weight/vtd1->factor;
 	}
 	else {
-		/* interpolate scale (later) */
 		scale = vtd1->weight;
-		/* also, interpolate max (later) */
 	}
 
 	if (is_edge && vtd1->loc != NULL) {
@@ -546,9 +544,12 @@
 	VECSUB(vec1,sv->co,vtd1->org);
 	dis = VecLength(vec1);
 	Normalize(vec1);
-	if (!(is_split_vert && dis == 0)) {
+	//~ if (!(is_split_vert && dis == 0)) {
+		//~ if (dis == 0) {
+			//~ maxfactor = -1;
+		//~ }
 		BME_assign_transdata(td, bm, sv, vtd1->org, vtd1->org, vec1, sv->co, dis, scale, maxfactor, vtd1->max);
-	}
+	//~ }
 
 	return sv;
 }
@@ -820,6 +821,44 @@
 	}
 }
 
+float BME_bevel_get_angle(BME_Mesh *bm, BME_Edge *e, BME_Vert *v) {
+	BME_Vert *v1, *v2;
+	BME_Loop *l1, *l2;
+	float vec1[3], vec2[3], vec3[3], vec4[3];
+
+	l1 = e->loop;
+	l2 = e->loop->radial.next->data;
+	if (l1->v == v) {
+		v1 = l1->prev->v;
+		v2 = l1->next->v;
+	}
+	else {
+		v1 = l1->next->next->v;
+		v2 = l1->v;
+	}
+	VECSUB(vec1,v1->co,v->co);
+	VECSUB(vec2,v2->co,v->co);
+	Crossf(vec3,vec1,vec2);
+	
+	l1 = l2;
+	if (l1->v == v) {
+		v1 = l1->prev->v;
+		v2 = l1->next->v;
+	}
+	else {
+		v1 = l1->next->next->v;
+		v2 = l1->v;
+	}
+	VECSUB(vec1,v1->co,v->co);
+	VECSUB(vec2,v2->co,v->co);
+	Crossf(vec4,vec2,vec1);
+	
+	Normalize(vec3);
+	Normalize(vec4);
+	
+	return 180.0f - (float)acos(Inpf(vec3,vec4))*180.0f/3.141592653f;;
+}
+
 /**
  *			BME_bevel_initialize
  *
@@ -830,7 +869,7 @@
  *	Returns -
  *  A BME_Mesh pointer to the BMesh passed as a parameter.
 */
-BME_Mesh *BME_bevel_initialize(BME_Mesh *bm, int options, int defgrp_index, BME_TransData_Head *td) {
+BME_Mesh *BME_bevel_initialize(BME_Mesh *bm, int options, int defgrp_index, float angle, BME_TransData_Head *td) {
 	BME_Vert *v;
 	BME_Edge *e;
 	BME_Poly *f;
@@ -954,8 +993,19 @@
 			weight = 1.0f-e->crease/255;
 		}
 		else if (options & BME_BEVEL_ANGLE) {
-			/* hmm... this should be two vals, one per vertex (or something weird like that) */
-			weight = 0.5;
+			float ang1, ang2;
+			ang1 = BME_bevel_get_angle(bm,e,e->v1);
+			ang2 = BME_bevel_get_angle(bm,e,e->v2);
+			if (ang1 < 180 - angle) {
+				e->tflag1 |= BME_BEVEL_BEVEL;
+				e->v1->tflag1 |= BME_BEVEL_BEVEL;
+				BME_bevel_add_vweight(td, bm, e->v1, 1.0, 1.0, options);
+			}
+			if (ang2 < 180 - angle) {
+				e->tflag1 |= BME_BEVEL_BEVEL;
+				e->v2->tflag1 |= BME_BEVEL_BEVEL;
+				BME_bevel_add_vweight(td, bm, e->v2, 1.0, 1.0, options);
+			}
 		}
 		else if ((options & BME_BEVEL_VWEIGHT) && (options & BME_BEVEL_VERT) == 0) {
 			if ((e->v1->tflag1 & BME_BEVEL_BEVEL) && (e->v2->tflag1 & BME_BEVEL_BEVEL)) {
@@ -1147,7 +1197,7 @@
  * BME_BEVEL_RADIUS		<---- Will need to think about this one; will probably need to incorporate into actual bevel routine
  * All weights/limits are stored per-vertex
  */
-BME_Mesh *BME_bevel(BME_Mesh *bm, float value, int res, int options, int defgrp_index, BME_TransData_Head **rtd) {
+BME_Mesh *BME_bevel(BME_Mesh *bm, float value, int res, int options, int defgrp_index, float angle, BME_TransData_Head **rtd) {
 	BME_Vert *v;
 	BME_TransData_Head *td;
 	BME_TransData *vtd;
@@ -1156,7 +1206,7 @@
 
 	td = BME_init_transdata(BLI_MEMARENA_STD_BUFSIZE);
 
-	BME_bevel_initialize(bm, options, defgrp_index, td);
+	BME_bevel_initialize(bm, options, defgrp_index, angle, td);
 
 	/* recursion math curtesy of Martin Poirier (theeth) */
 	for (i=0; i<res-1; i++) {
@@ -1181,9 +1231,12 @@
 	for (v = bm->verts.first; v; v=v->next) {
 		if (vtd = BME_get_transdata(td, v)) {
 			if (vtd->max > 0 && value > vtd->max) {
-				value = vtd->max;
+				d = vtd->max;
 			}
-			VECADDFAC(v->co,vtd->org,vtd->vec,vtd->factor*value);
+			else {
+				d = value;
+			}
+			VECADDFAC(v->co,vtd->org,vtd->vec,vtd->factor*d);
 		}
 		v->tflag1 = 0;
 	}

Modified: branches/soc-2007-red_fox/source/blender/blenkernel/intern/modifier.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/blenkernel/intern/modifier.c	2007-08-25 04:22:20 UTC (rev 11820)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/modifier.c	2007-08-25 06:20:52 UTC (rev 11821)
@@ -2630,7 +2630,7 @@
 	bm = BME_make_mesh();
 	bm = BME_derivedmesh_to_bmesh(derivedData, bm);
 	BME_model_begin(bm);
-	BME_bevel(bm,bmd->value,bmd->res,options,defgrp_index,NULL);
+	BME_bevel(bm,bmd->value,bmd->res,options,defgrp_index,bmd->bevel_angle,NULL);
 	BME_model_end(bm);
 	result = BME_bmesh_to_derivedmesh(bm,derivedData);
 	BME_free_mesh(bm);

Modified: branches/soc-2007-red_fox/source/blender/src/buttons_editing.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/src/buttons_editing.c	2007-08-25 04:22:20 UTC (rev 11820)
+++ branches/soc-2007-red_fox/source/blender/src/buttons_editing.c	2007-08-25 06:20:52 UTC (rev 11821)
@@ -1715,19 +1715,19 @@
 					  "Bevel only verts/corners; not edges");
 			uiDefBut(block, LABEL, 1, "Limit using:",	lx, (cy-=19), buttonWidth,19, NULL, 0.0, 0.0, 0, 0, "");
 			uiDefButS(block, ROW, B_MODIFIER_RECALC, "None",
-					  lx, (cy -= 19), (buttonWidth/3), 19, &bmd->lim_flags,
+					  lx, (cy -= 19), (buttonWidth/4), 19, &bmd->lim_flags,
 					  12.0, 0, 0, 0,
 					  "Bevel the entire mesh by a constant amount");
 			uiDefButBitS(block, ROW, BME_BEVEL_EWEIGHT, B_MODIFIER_RECALC, "Crease",
-					  (lx+buttonWidth/3), cy, (buttonWidth/3), 19, &bmd->lim_flags,
+					  (lx+buttonWidth/4), cy, (buttonWidth/4), 19, &bmd->lim_flags,
 					  12.0, BME_BEVEL_EWEIGHT, 0, 0,
 					  "Use edge creases to determine how much and where the bevel is applied");
-			/*uiDefButS(block, ROW, B_MODIFIER_RECALC, "Angle",
+			uiDefButS(block, ROW, B_MODIFIER_RECALC, "Angle",
 					  (lx+2*buttonWidth/4), cy, (buttonWidth/4), 19, &bmd->lim_flags,
 					  12.0, BME_BEVEL_ANGLE, 0, 0,
-					  "Only bevel edges with sharp enough angles between faces");*/
+					  "Only bevel edges with sharp enough angles between faces");
 			uiDefButS(block, ROW, B_MODIFIER_RECALC, "VGroup",
-					  lx+(2*buttonWidth/3), cy, buttonWidth-(2*buttonWidth/3), 19, &bmd->lim_flags,
+					  lx+(3*buttonWidth/4), cy, buttonWidth-(3*buttonWidth/4), 19, &bmd->lim_flags,
 					  12.0, BME_BEVEL_VWEIGHT, 0, 0,
 					  "Use a vertex group and weights to determine how much bevel is applied");
 			if (bmd->lim_flags & BME_BEVEL_EWEIGHT) {

Modified: branches/soc-2007-red_fox/source/blender/src/editmesh_tools.c
===================================================================
--- branches/soc-2007-red_fox/source/blender/src/editmesh_tools.c	2007-08-25 04:22:20 UTC (rev 11820)
+++ branches/soc-2007-red_fox/source/blender/src/editmesh_tools.c	2007-08-25 06:20:52 UTC (rev 11821)
@@ -4427,7 +4427,7 @@
 		bm = BME_editmesh_to_bmesh(G.editMesh, bm);
 		BIF_undo_push("Pre-Bevel");
 		free_editMesh(G.editMesh);
-		BME_bevel(bm,0.1f,res,options,0,&td);
+		BME_bevel(bm,0.1f,res,options,0,0,&td);
 		BME_bmesh_to_editmesh(bm, td);
 		G.editBMesh->bm = bm;
 		G.editBMesh->td = td;





More information about the Bf-blender-cvs mailing list