Revision: 15269
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15269
Author:   artificer
Date:     2008-06-18 17:22:42 +0200 (Wed, 18 Jun 2008)

Log Message:
-----------
Patch #8882 - Falloff in the wave modifier
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!

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/modifier.c
    trunk/blender/source/blender/makesdna/DNA_modifier_types.h
    trunk/blender/source/blender/src/buttons_editing.c

Modified: trunk/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/modifier.c   2008-06-18 
14:56:12 UTC (rev 15268)
+++ trunk/blender/source/blender/blenkernel/intern/modifier.c   2008-06-18 
15:22:42 UTC (rev 15269)
@@ -4525,13 +4525,13 @@
 
 /* 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 @@
        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 @@
        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 @@
 
                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 @@
                        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 @@
                                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 @@
                        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) {

Modified: trunk/blender/source/blender/makesdna/DNA_modifier_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_modifier_types.h  2008-06-18 
14:56:12 UTC (rev 15268)
+++ trunk/blender/source/blender/makesdna/DNA_modifier_types.h  2008-06-18 
15:22:42 UTC (rev 15269)
@@ -329,13 +329,14 @@
        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 {

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c  2008-06-18 14:56:12 UTC 
(rev 15268)
+++ trunk/blender/source/blender/src/buttons_editing.c  2008-06-18 15:22:42 UTC 
(rev 15269)
@@ -1792,7 +1792,7 @@
                        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 @@
                                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 @@
                                               &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");


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to