[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11728] branches/soc-2007-red_fox/source/ blender/blenkernel/intern/BME_tools.c: Re-coded max limit routine, fixed artifacts
Levi Schooley
redfox at hhofministries.org
Mon Aug 20 07:06:34 CEST 2007
Revision: 11728
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11728
Author: red_fox
Date: 2007-08-20 07:06:34 +0200 (Mon, 20 Aug 2007)
Log Message:
-----------
Re-coded max limit routine, fixed artifacts
This commit should (finally) fix most, if not all, of the
major artifacts. The max limit routine was moved from
per-edge to per-poly, a division by zero was caught and
fixed, and the modifier uses limits now (don't know why I
forgot to add that).
In short, things should look and act a lot better now.
Levi
Modified Paths:
--------------
branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c
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-20 03:03:34 UTC (rev 11727)
+++ branches/soc-2007-red_fox/source/blender/blenkernel/intern/BME_tools.c 2007-08-20 05:06:34 UTC (rev 11728)
@@ -385,7 +385,7 @@
* up_vec is used for orientation (expected to be normalized)
* returns the length of the projected vector that lies along vec1 */
float BME_bevel_project_vec(float *vec1, float *vec2, float *up_vec, int is_forward, BME_TransData_Head *td) {
- float factor, vec3[3], tmp[3];
+ float factor, vec3[3], tmp[3],c1,c2;
Crossf(tmp,vec1,vec2);
Normalize(tmp);
@@ -397,9 +397,14 @@
Crossf(vec3,tmp,vec2); /* hmm, maybe up_vec should be used instead of tmp */
}
Normalize(vec3);
- factor = Inpf(vec3,vec1)/Inpf(vec1,vec1);
- if (factor != 0.0) factor = 1/factor;
- else factor = 1000000000000.0f; /* this should be MAX_FLOAT, whatever that is (we just need a really big number) */
+ c1 = Inpf(vec3,vec1);
+ c2 = Inpf(vec1,vec1);
+ if (c1 == 0.0f || c2 == 0.0f) {
+ factor = 0.0f;
+ }
+ else {
+ factor = c1/c2;
+ }
return factor;
}
@@ -413,7 +418,7 @@
BME_Vert *sv, *v2, *v3;
BME_Loop *lv1;
BME_Edge *ne, *e1, *e2;
- float maxfactor, old_maxfactor, maxfactor2, tmp_max, scale, len, dis, vec1[3], vec2[3], t_up_vec[3];
+ float factor, scale, len, dis, vec1[3], vec2[3], t_up_vec[3];
int is_edge, forward, is_split_vert;
if (l == NULL) {
@@ -507,53 +512,24 @@
/* also, interpolate max (later) */
}
- /* we will set up max's here */
- /* the test is a bit silly, but there's really no other way (for now) to
- * determine if this is the first recursion */
- if (value > 0.5) {
- maxfactor = scale*BME_bevel_project_vec(vec1,vec2,up_vec,forward,td);
- if (is_split_vert) {
- old_maxfactor = vtd->maxfactor;
- }
- else {
- old_maxfactor = vtd1->maxfactor;
- }
- if (old_maxfactor > 0 && maxfactor > old_maxfactor) {
- if (is_split_vert ) {
- return sv; /* we won't be changing anything (previously split vert, and it's "smaller") */
- }
- maxfactor = old_maxfactor;
- }
- maxfactor2 = vtd2->maxfactor;
- if (maxfactor2 < 0) maxfactor2 = 0;
- tmp_max = len/(maxfactor + maxfactor2);
- if (vtd1->max < 0 || tmp_max <= vtd1->max) {
- vtd->max = vtd2->max = tmp_max;
- }
- else {
- vtd->max = vtd1->max;
- }
+ if (is_edge && vtd1->loc != NULL) {
+ factor = vtd1->maxfactor;
}
else {
- if (is_edge && vtd1->loc != NULL) {
- maxfactor = vtd1->maxfactor;
- }
- else {
- maxfactor = BME_bevel_project_vec(vec1,vec2,up_vec,forward,td);
- }
- maxfactor *= scale;
- vtd->max = vtd1->max;
+ factor = BME_bevel_project_vec(vec1,vec2,up_vec,forward,td);
}
+ factor *= scale;
+
dis = (v1->tflag1 & BME_BEVEL_ORIG)? len/3 : len/2;
- if (is_edge || dis > maxfactor*value) {
- dis = maxfactor*value;
+ if (is_edge || dis > factor*value) {
+ dis = factor*value;
}
VECADDFAC(sv->co,v->co,vec1,dis);
VECSUB(vec1,sv->co,vtd1->org);
dis = VecLength(vec1);
Normalize(vec1);
- BME_assign_transdata(td, bm, sv, vtd1->org, vtd1->org, vec1, sv->co, dis, scale, maxfactor, vtd->max);
+ BME_assign_transdata(td, bm, sv, vtd1->org, vtd1->org, vec1, sv->co, dis, scale, factor, vtd1->max);
return sv;
}
@@ -704,7 +680,8 @@
*/
BME_Poly *BME_bevel_poly(BME_Mesh *bm, BME_Poly *f, float value, int options, BME_TransData_Head *td) {
BME_Loop *l, *ol;
- float up_vec[3], vec1[3], vec2[3], vec3[3];
+ BME_TransData *vtd1, *vtd2;
+ float up_vec[3], vec1[3], vec2[3], vec3[3], fac1, fac2, tmp_max, max = -1;
int len, i;
up_vec[0] = 0.0f;
@@ -725,12 +702,56 @@
for (i=0,len=f->len; i<len; i++,l=l->next) {
if ((l->e->tflag1 & BME_BEVEL_BEVEL) && (l->e->tflag1 & BME_BEVEL_ORIG)) {
+ max = 1.0f;
l = BME_bevel_edge(bm, l, value, options, up_vec, td);
}
else if ((l->v->tflag1 & BME_BEVEL_BEVEL) && (l->v->tflag1 & BME_BEVEL_ORIG) && (l->prev->e->tflag1 & BME_BEVEL_BEVEL) == 0) {
+ max = 1.0f;
l = BME_bevel_vert(bm, l, value, options, up_vec, td);
}
}
+
+ /* max pass */
+ if (value > 0.5 && max > 0) {
+ max = -1;
+ for (i=0,len=f->len; i<len; i++,l=l->next) {
+ if ((l->e->tflag1 & BME_BEVEL_BEVEL) || (l->e->tflag1 & BME_BEVEL_ORIG)) {
+ BME_bevel_get_vec(vec1,l->v,l->next->v,td);
+ vtd1 = BME_get_transdata(td,l->v);
+ vtd2 = BME_get_transdata(td,l->next->v);
+ if (vtd1->loc == NULL) {
+ fac1 = 0;
+ }
+ else {
+ VECCOPY(vec2,vtd1->vec);
+ VecMulf(vec2,vtd1->factor);
+ Projf(vec2,vec2,vec1);
+ fac1 = VecLength(vec2)/value;
+ }
+ if (vtd2->loc == NULL) {
+ fac2 = 0;
+ }
+ else {
+ VECCOPY(vec3,vtd2->vec);
+ VecMulf(vec3,vtd2->factor);
+ Projf(vec2,vec3,vec1);
+ fac2 = VecLength(vec2)/value;
+ }
+ if (fac1 || fac2) {
+ tmp_max = VecLength(vec1)/(fac1 + fac2);
+ if (max < 0 || tmp_max < max) {
+ max = tmp_max;
+ }
+ }
+ }
+ }
+ for (i=0,len=f->len; i<len; i++,l=l->next) {
+ vtd1 = BME_get_transdata(td,l->v);
+ if (vtd1->max < 0 || max < vtd1->max) {
+ vtd1->max = max;
+ }
+ }
+ }
return l->f;
}
@@ -1121,6 +1142,9 @@
/* transform pass */
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;
+ }
VECADDFAC(v->co,vtd->org,vtd->vec,vtd->factor*value);
}
v->tflag1 = 0;
More information about the Bf-blender-cvs
mailing list