Patch #8882 - Falloff in the wave modifier
authorBen Batt <benbatt@gmail.com>
Wed, 18 Jun 2008 15:22:42 +0000 (15:22 +0000)
committerBen Batt <benbatt@gmail.com>
Wed, 18 Jun 2008 15:22:42 +0000 (15:22 +0000)
This patch adds the ability to specify a falloff radius in the Wave modifier.
Currently only linear falloff is supported.

Thanks to Michael Fox for the patch!

source/blender/blenkernel/intern/modifier.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/src/buttons_editing.c

index 861534deb80dcff6fdaac56a1e8db237c5e9d246..eceab9f32d8f5bfdb5dda0551e094421bb54362d 100644 (file)
@@ -4525,13 +4525,13 @@ static void castModifier_deformVertsEM(
 
 /* Wave */
 
-static void waveModifier_initData(ModifierData *md) 
+static void waveModifier_initData(ModifierData *md)
 {
        WaveModifierData *wmd = (WaveModifierData*) md; // whadya know, moved here from Iraq
-               
+
        wmd->flag |= (MOD_WAVE_X | MOD_WAVE_Y | MOD_WAVE_CYCL
                        | MOD_WAVE_NORM_X | MOD_WAVE_NORM_Y | MOD_WAVE_NORM_Z);
-       
+
        wmd->objectcenter = NULL;
        wmd->texture = NULL;
        wmd->map_object = NULL;
@@ -4541,6 +4541,7 @@ static void waveModifier_initData(ModifierData *md)
        wmd->narrow= 1.5f;
        wmd->lifetime= 0.0f;
        wmd->damp= 10.0f;
+       wmd->falloff= 0.0f;
        wmd->texmapping = MOD_WAV_MAP_LOCAL;
        wmd->defgrp_name[0] = 0;
 }
@@ -4560,6 +4561,7 @@ static void waveModifier_copyData(ModifierData *md, ModifierData *target)
        twmd->starty = wmd->starty;
        twmd->timeoffs = wmd->timeoffs;
        twmd->width = wmd->width;
+       twmd->falloff = wmd->falloff;
        twmd->objectcenter = wmd->objectcenter;
        twmd->texture = wmd->texture;
        twmd->map_object = wmd->map_object;
@@ -4770,7 +4772,7 @@ static void waveModifier_do(
 
                if(x > wmd->lifetime) {
                        lifefac = x - wmd->lifetime;
-                       
+
                        if(lifefac > wmd->damp) lifefac = 0.0;
                        else lifefac =
                                (float)(wmd->height * (1.0 - sqrt(lifefac / wmd->damp)));
@@ -4791,6 +4793,8 @@ static void waveModifier_do(
                        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;
 
@@ -4813,14 +4817,29 @@ static void waveModifier_do(
                                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);
+                               }
+                       }
+                       else if(wmd->flag & MOD_WAVE_Y) {
+                               dist = fabs(y);
+                       }
+
+                       falloff_fac = (1.0-(dist / wmd->falloff));
+                       CLAMP(falloff_fac,0,1);
 
                        if(wmd->flag & MOD_WAVE_X) {
                                if(wmd->flag & MOD_WAVE_Y) amplit = (float)sqrt(x*x + y*y);
                                else amplit = x;
                        }
-                       else if(wmd->flag & MOD_WAVE_Y) 
+                       else if(wmd->flag & MOD_WAVE_Y)
                                amplit= y;
-                       
+
                        /* this way it makes nice circles */
                        amplit -= (ctime - wmd->timeoffs) * wmd->speed;
 
@@ -4833,12 +4852,19 @@ static void waveModifier_do(
                        if(amplit > -wmd->width && amplit < wmd->width) {
                                amplit = amplit * wmd->narrow;
                                amplit = (float)(1.0 / exp(amplit * amplit) - minfac);
+
+                               /*apply texture*/
                                if(wmd->texture)
                                        amplit = amplit * texres.tin;
 
+                               /*apply weight*/
                                if(def_weight)
                                        amplit = amplit * def_weight->weight;
 
+                               /*apply falloff*/
+                               if (wmd->falloff > 0)
+                                       amplit = amplit * falloff_fac;
+
                                if(mvert) {
                                        /* move along normals */
                                        if(wmd->flag & MOD_WAVE_NORM_X) {
index 8c1df1450e8f97c292e965659928bca11942c49c..a44d9793062e3bc2e7ca445921593c64c0dd9f89 100644 (file)
@@ -329,13 +329,14 @@ typedef struct WaveModifierData {
        short flag, pad;
 
        float startx, starty, height, width;
-       float narrow, speed, damp;
+       float narrow, speed, damp, falloff;
 
        int texmapping, uvlayer_tmp;
 
        char uvlayer_name[32];
-       
+
        float timeoffs, lifetime;
+       float pad1;
 } WaveModifierData;
 
 typedef struct ArmatureModifierData {
index caa1f2195e2764de1de08057491846c69dadf2f9..88b72e5f5144ff077e7935d6370986290e96ce23 100644 (file)
@@ -1792,7 +1792,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
                        height = 143;
                } else if (md->type==eModifierType_Wave) {
                        WaveModifierData *wmd = (WaveModifierData *)md;
-                       height = 294;
+                       height = 315;
                        if(wmd->texmapping == MOD_WAV_MAP_OBJECT ||
                           wmd->texmapping == MOD_WAV_MAP_UV)
                                height += 19;
@@ -2154,6 +2154,8 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
                                uiDefButF(block, NUM, B_MODIFIER_RECALC, "Time end:",   lx,(cy-=19),buttonWidth,19, &wmd->timeoffs, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify ending frame of the wave");
                        uiDefButF(block, NUM, B_MODIFIER_RECALC, "Lifetime:",   lx,(cy-=19),buttonWidth,19, &wmd->lifetime,  -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify the lifespan of the wave");
                        uiDefButF(block, NUM, B_MODIFIER_RECALC, "Damptime:",   lx,(cy-=19),buttonWidth,19, &wmd->damp,  -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify the dampingtime of the wave");
+                       uiDefButF(block, NUM, B_MODIFIER_RECALC, "Falloff:",    lx,(cy-=19),buttonWidth,19, &wmd->falloff,  0, 100, 100, 0, "Specify the falloff radius of the waves");
+
                        cy -= 9;
                        uiBlockBeginAlign(block);
                        uiDefButF(block, NUM, B_MODIFIER_RECALC, "Sta x:",              lx,(cy-=19),113,19, &wmd->startx, -100.0, 100.0, 100, 0, "Starting position for the X axis");
@@ -2190,7 +2192,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
                                               &wmd->map_object,
                                               "Object to get texture coordinates from");
                        }
-            cy -= 9;
+                       cy -= 9;
                        uiBlockBeginAlign(block);
                        uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Speed:",   lx,(cy-=19),220,19, &wmd->speed, -2.0, 2.0, 0, 0, "Specify the wave speed");
                        uiDefButF(block, NUMSLI, B_MODIFIER_RECALC, "Height:",  lx,(cy-=19),220,19, &wmd->height, -2.0, 2.0, 0, 0, "Specify the amplitude of the wave");