minor speedup for scanfill, dont calculate the normal if its already known - use for editmode ngon filling.

This commit is contained in:
2012-04-16 18:24:49 +00:00
parent 67f8e3a3a7
commit 195d6c1b1a
6 changed files with 33 additions and 18 deletions

View File

@@ -218,7 +218,7 @@ static void BMEdit_RecalcTessellation_intern(BMEditMesh *tm)
/*complete the loop*/
BLI_addfilledge(&sf_ctx, firstv, v);
totfilltri = BLI_edgefill(&sf_ctx, FALSE);
totfilltri = BLI_edgefill_ex(&sf_ctx, FALSE, f->no);
BLI_array_growitems(looptris, totfilltri);
for (efa = sf_ctx.fillfacebase.first; efa; efa=efa->next) {

View File

@@ -100,6 +100,8 @@ struct ScanFillEdge *BLI_addfilledge(ScanFillContext *sf_ctx, struct ScanFillVer
int BLI_begin_edgefill(ScanFillContext *sf_ctx);
int BLI_edgefill(ScanFillContext *sf_ctx, const short do_quad_tri_speedup);
int BLI_edgefill_ex(ScanFillContext *sf_ctx, const short do_quad_tri_speedup,
const float nor_proj[3]);
void BLI_end_edgefill(ScanFillContext *sf_ctx);
/* These callbacks are needed to make the lib finction properly */

View File

@@ -773,6 +773,11 @@ int BLI_begin_edgefill(ScanFillContext *sf_ctx)
}
int BLI_edgefill(ScanFillContext *sf_ctx, const short do_quad_tri_speedup)
{
return BLI_edgefill_ex(sf_ctx, do_quad_tri_speedup, NULL);
}
int BLI_edgefill_ex(ScanFillContext *sf_ctx, const short do_quad_tri_speedup, const float nor_proj[3])
{
/*
* - fill works with its own lists, so create that first (no faces!)
@@ -852,21 +857,28 @@ int BLI_edgefill(ScanFillContext *sf_ctx, const short do_quad_tri_speedup)
return 0;
}
else {
/* define projection: with 'best' normal */
/* Newell's Method */
/* Similar code used elsewhere, but this checks for double ups
* which historically this function supports so better not change */
float *v_prev;
float n[3] = {0.0f};
float n[3];
eve = sf_ctx->fillvertbase.last;
v_prev = eve->co;
if (nor_proj) {
copy_v3_v3(n, nor_proj);
}
else {
/* define projection: with 'best' normal */
/* Newell's Method */
/* Similar code used elsewhere, but this checks for double ups
* which historically this function supports so better not change */
float *v_prev;
for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
if (LIKELY(!compare_v3v3(v_prev, eve->co, COMPLIMIT))) {
add_newell_cross_v3_v3v3(n, v_prev, eve->co);
}
zero_v3(n);
eve = sf_ctx->fillvertbase.last;
v_prev = eve->co;
for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
if (LIKELY(!compare_v3v3(v_prev, eve->co, COMPLIMIT))) {
add_newell_cross_v3_v3v3(n, v_prev, eve->co);
}
v_prev = eve->co;
}
}
if (UNLIKELY(normalize_v3(n) == 0.0f)) {

View File

@@ -529,8 +529,8 @@ static int linecrossesf(const float v1[2], const float v2[2], const float v3[2],
GETMIN2(v1, v2, mv1, mv2);
GETMIN2(v3, v4, mv3, mv4);
/* do an interval test on the x and y axe */
/* first do x axi */
/* do an interval test on the x and y axes */
/* first do x axis */
if (ABS(v1[1] - v2[1]) < EPS &&
ABS(v3[1] - v4[1]) < EPS &&
ABS(v1[1] - v3[1]) < EPS)
@@ -538,7 +538,7 @@ static int linecrossesf(const float v1[2], const float v2[2], const float v3[2],
return (mv4[0] >= mv1[0] && mv3[0] <= mv2[0]);
}
/* now do y axi */
/* now do y axis */
if (ABS(v1[0] - v2[0]) < EPS &&
ABS(v3[0] - v4[0]) < EPS &&
ABS(v1[0] - v3[0]) < EPS)

View File

@@ -288,7 +288,7 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em,
BLI_addfilledge(&sf_ctx, firstv, v);
BLI_edgefill(&sf_ctx, TRUE);
BLI_edgefill_ex(&sf_ctx, TRUE, efa->no);
for (sefa = sf_ctx.fillfacebase.first; sefa; sefa = sefa->next) {
ls[0] = sefa->v1->tmp.p;
ls[1] = sefa->v2->tmp.p;

View File

@@ -253,8 +253,9 @@ static void draw_filled_lasso(wmGesture *gt)
/* highly unlikely this will fail, but could crash if (gt->points == 0) */
if (firstv) {
float zvec[3] = {0.0f, 0.0f, 1.0f};
BLI_addfilledge(&sf_ctx, firstv, v);
BLI_edgefill(&sf_ctx, FALSE);
BLI_edgefill_ex(&sf_ctx, FALSE, zvec);
glEnable(GL_BLEND);
glColor4f(1.0, 1.0, 1.0, 0.05);