=bmesh= merge from trunk at r36529
[blender.git] / source / blender / modifiers / intern / MOD_wave.c
index df3a7f80490627491fe761232b61ca020a17024e..11cf159edc97c03f268dbc11f1bbca3a14e621b5 100644 (file)
@@ -183,11 +183,11 @@ static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob,
        /* UVs need special handling, since they come from faces */
        if(texmapping == MOD_WAV_MAP_UV) {
                if(CustomData_has_layer(&dm->faceData, CD_MTFACE)) {
-                       MFace *mface = dm->getFaceArray(dm);
+                       MFace *mface = dm->getTessFaceArray(dm);
                        MFace *mf;
                        char *done = MEM_callocN(sizeof(*done) * numVerts,
                                        "get_texture_coords done");
-                       int numFaces = dm->getNumFaces(dm);
+                       int numFaces = dm->getNumTessFaces(dm);
                        char uvname[32];
                        MTFace *tf;
 
@@ -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;
-
-                               /*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 */