From 7a2d6482e3971d669427697a8cd9fe0b1563bb83 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 28 Apr 2011 05:34:11 +0000 Subject: [PATCH] skip some calculations with the wave modifier - when the vert has no vgroup weight or 0.0 falloff. --- source/blender/modifiers/intern/MOD_wave.c | 94 +++++++++++----------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index df3a7f80490..6dfe5314131 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -263,6 +263,9 @@ static void waveModifier_do(WaveModifierData *md, (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow)); float lifefac = wmd->height; float (*tex_co)[3] = NULL; + const int wmd_axis= wmd->flag & (MOD_WAVE_X|MOD_WAVE_Y); + const float falloff= wmd->falloff; + float falloff_fac= 1.0f; /* when falloff == 0.0f this stays at 1.0f */ if(wmd->flag & MOD_WAVE_NORM && ob->type == OB_MESH) mvert = dm->getVertArray(dm); @@ -306,7 +309,7 @@ static void waveModifier_do(WaveModifierData *md, if(lifefac != 0.0f) { /* avoid divide by zero checks within the loop */ - float falloff_inv= wmd->falloff ? 1.0f / wmd->falloff : 1.0f; + float falloff_inv= falloff ? 1.0f / falloff : 1.0f; int i; for(i = 0; i < numVerts; i++) { @@ -314,52 +317,29 @@ static void waveModifier_do(WaveModifierData *md, float x = co[0] - wmd->startx; float y = co[1] - wmd->starty; float amplit= 0.0f; - float dist = 0.0f; - float falloff_fac = 0.0f; - TexResult texres; - MDeformWeight *def_weight = NULL; + float def_weight= 1.0f; /* get weights */ if(dvert) { - int j; - for(j = 0; j < dvert[i].totweight; ++j) { - if(dvert[i].dw[j].def_nr == defgrp_index) { - def_weight = &dvert[i].dw[j]; - break; - } - } + def_weight= defvert_find_weight(&dvert[i], defgrp_index); /* if this vert isn't in the vgroup, don't deform it */ - if(!def_weight) continue; - } - - if(wmd->texture) { - texres.nor = NULL; - get_texture_value(wmd->texture, tex_co[i], &texres); - } - - /*get dist*/ - if(wmd->flag & MOD_WAVE_X) { - if(wmd->flag & MOD_WAVE_Y){ - dist = (float)sqrt(x*x + y*y); - } - else{ - dist = fabs(x); + if(def_weight == 0.0f) { + continue; } } - else if(wmd->flag & MOD_WAVE_Y) { - dist = fabs(y); - } - falloff_fac = (1.0f - (dist * falloff_inv)); - CLAMP(falloff_fac, 0.0f, 1.0f); - - if(wmd->flag & MOD_WAVE_X) { - if(wmd->flag & MOD_WAVE_Y) amplit = (float)sqrt(x*x + y*y); - else amplit = x; + switch(wmd_axis) { + case MOD_WAVE_X|MOD_WAVE_Y: + amplit = sqrtf(x*x + y*y); + break; + case MOD_WAVE_X: + amplit = x; + break; + case MOD_WAVE_Y: + amplit = y; + break; } - else if(wmd->flag & MOD_WAVE_Y) - amplit= y; /* this way it makes nice circles */ amplit -= (ctime - wmd->timeoffs) * wmd->speed; @@ -369,22 +349,40 @@ static void waveModifier_do(WaveModifierData *md, + wmd->width; } + if(falloff != 0.0f) { + float dist = 0.0f; + + switch(wmd_axis) { + case MOD_WAVE_X|MOD_WAVE_Y: + dist = sqrtf(x*x + y*y); + break; + case MOD_WAVE_X: + dist = fabsf(x); + break; + case MOD_WAVE_Y: + dist = fabsf(y); + break; + } + + falloff_fac = (1.0f - (dist * falloff_inv)); + CLAMP(falloff_fac, 0.0f, 1.0f); + } + /* GAUSSIAN */ - if(amplit > -wmd->width && amplit < wmd->width) { + if((falloff_fac != 0.0f) && (amplit > -wmd->width) && (amplit < wmd->width)) { amplit = amplit * wmd->narrow; amplit = (float)(1.0f / expf(amplit * amplit) - minfac); /*apply texture*/ - if(wmd->texture) - amplit = amplit * texres.tin; + if(wmd->texture) { + TexResult texres; + texres.nor = NULL; + get_texture_value(wmd->texture, tex_co[i], &texres); + amplit *= texres.tin; + } - /*apply weight*/ - if(def_weight) - amplit = amplit * def_weight->weight; - - /*apply falloff*/ - if (wmd->falloff > 0) - amplit = amplit * falloff_fac; + /*apply weight & falloff */ + amplit *= def_weight * falloff_fac; if(mvert) { /* move along normals */