diff options
author | Joseph Eagar <joeedh@gmail.com> | 2011-05-09 03:43:18 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2011-05-09 03:43:18 +0400 |
commit | 6ef77cf95accc3cb914e7efd964118ce6e9521cf (patch) | |
tree | 1d8dbf95355038c93f79f9053a0bf1d55b561ec3 /source/blender/modifiers/intern/MOD_wave.c | |
parent | 3462ddf17f38eb61fc3bb2751d55de15a47455c3 (diff) | |
parent | 770119d16f7dbee99a60d19540818892c970c4e2 (diff) |
=bmesh= merge from trunk at r36529
Diffstat (limited to 'source/blender/modifiers/intern/MOD_wave.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_wave.c | 93 |
1 files changed, 46 insertions, 47 deletions
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index e3ee612374a..11cf159edc9 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,51 +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)); - 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; @@ -368,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; - - /*apply weight*/ - if(def_weight) - amplit = amplit * def_weight->weight; + if(wmd->texture) { + TexResult texres; + texres.nor = NULL; + get_texture_value(wmd->texture, tex_co[i], &texres); + amplit *= texres.tin; + } - /*apply falloff*/ - if (wmd->falloff > 0) - amplit = amplit * falloff_fac; + /*apply weight & falloff */ + amplit *= def_weight * falloff_fac; if(mvert) { /* move along normals */ |