From 0b66fe6a4849b3916793cd815ffb8c0d67885cdc Mon Sep 17 00:00:00 2001 From: Ben Batt Date: Mon, 30 Apr 2007 15:20:05 +0000 Subject: Patch #6582 - Weight groups in the wave modifier This patch adds vertex group functionality to the wave modifier, allowing the user to specify a vertex group with which to modulate the wave deformation. Thanks to Michael Fox (mfoxdoggg) for the patch! --- source/blender/blenkernel/intern/modifier.c | 50 ++++++++++++++++++++++++++-- source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/src/buttons_editing.c | 10 +++--- 3 files changed, 54 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 1c8cf44a2c3..b20e8181d39 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -4140,6 +4140,7 @@ static void waveModifier_initData(ModifierData *md) wmd->lifetime= 0.0f; wmd->damp= 10.0f; wmd->texmapping = MOD_WAV_MAP_LOCAL; + wmd->defgrp_name[0] = 0; } static void waveModifier_copyData(ModifierData *md, ModifierData *target) @@ -4161,6 +4162,7 @@ static void waveModifier_copyData(ModifierData *md, ModifierData *target) twmd->texture = wmd->texture; twmd->map_object = wmd->map_object; twmd->texmapping = wmd->texmapping; + strncpy(twmd->defgrp_name, wmd->defgrp_name, 32); } static int waveModifier_dependsOnTime(ModifierData *md) @@ -4217,6 +4219,10 @@ CustomDataMask waveModifier_requiredDataMask(ModifierData *md) if(wmd->texture && wmd->texmapping == MOD_WAV_MAP_UV) dataMask |= (1 << CD_MTFACE); + /* ask for vertexgroups if we need them */ + if(wmd->defgrp_name[0]) + dataMask |= (1 << CD_MDEFORMVERT); + return dataMask; } @@ -4313,6 +4319,8 @@ static void waveModifier_do( float (*vertexCos)[3], int numVerts) { WaveModifierData *wmd = (WaveModifierData*) md; + MDeformVert *dvert = NULL; + int defgrp_index; float ctime = bsystem_time(ob, 0, (float)G.scene->r.cfra, 0.0); float minfac = (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow)); @@ -4329,6 +4337,24 @@ static void waveModifier_do( wmd->starty = mat[3][1]; } + /* get the index of the deform group */ + defgrp_index = -1; + + if(wmd->defgrp_name[0]) { + int i; + bDeformGroup *def; + for(i = 0, def = ob->defbase.first; def; def = def->next, i++) { + if(!strcmp(def->name, wmd->defgrp_name)) { + defgrp_index = i; + break; + } + } + } + + if(defgrp_index >= 0){ + dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); + } + if(wmd->damp == 0) wmd->damp = 10.0f; if(wmd->lifetime != 0.0) { @@ -4358,6 +4384,21 @@ static void waveModifier_do( float y = co[1] - wmd->starty; float amplit= 0.0f; TexResult texres; + MDeformWeight *def_weight = NULL; + + /* 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; + } + } + + /* if this vert isn't in the vgroup, don't deform it */ + if(!def_weight) continue; + } if(wmd->texture) { texres.nor = NULL; @@ -4387,6 +4428,9 @@ static void waveModifier_do( if(wmd->texture) amplit = amplit * texres.tin; + if(def_weight) + amplit = amplit * def_weight->weight; + co[2] += lifefac * amplit; } } @@ -4402,7 +4446,8 @@ static void waveModifier_deformVerts( DerivedMesh *dm; WaveModifierData *wmd = (WaveModifierData *)md; - if(!wmd->texture || derivedData) dm = derivedData; + if(!wmd->texture && !wmd->defgrp_name[0]) dm = derivedData; + else if(derivedData) dm = derivedData; else if(ob->type == OB_MESH) dm = CDDM_from_mesh(ob->data, ob); else return; @@ -4418,7 +4463,8 @@ static void waveModifier_deformVertsEM( DerivedMesh *dm; WaveModifierData *wmd = (WaveModifierData *)md; - if(!wmd->texture || derivedData) dm = derivedData; + if(!wmd->texture && !wmd->defgrp_name[0]) dm = derivedData; + else if(derivedData) dm = derivedData; else dm = CDDM_from_editmesh(editData, ob->data); waveModifier_do(wmd, ob, dm, vertexCos, numVerts); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 52ba7455284..a7b68b09f1a 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -282,6 +282,7 @@ typedef struct WaveModifierData { ModifierData modifier; struct Object *objectcenter; + char defgrp_name[32]; struct Tex *texture; struct Object *map_object; diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index 6adcdde2be9..699669675e5 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -1604,11 +1604,10 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco } else if (md->type==eModifierType_Smooth) { height = 86; } else if (md->type==eModifierType_Cast) { - height = 124; - height += 19; + height = 143; } else if (md->type==eModifierType_Wave) { WaveModifierData *wmd = (WaveModifierData *)md; - height = 280; + height = 275; if(wmd->texmapping == MOD_WAV_MAP_OBJECT || wmd->texmapping == MOD_WAV_MAP_UV) height += 19; @@ -1872,11 +1871,12 @@ 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, -1000.0, 1000.0, 100, 0, "Specify ending frame of the wave"); uiDefButF(block, NUM, B_MODIFIER_RECALC, "Lifetime:", lx,(cy-=19),buttonWidth,19, &wmd->lifetime, -1000.0, 1000.0, 100, 0, "Specify the lifespan of the wave"); uiDefButF(block, NUM, B_MODIFIER_RECALC, "Damptime:", lx,(cy-=19),buttonWidth,19, &wmd->damp, -1000.0, 1000.0, 100, 0, "Specify the dampingtime of the wave"); - cy -= 19; + 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"); uiDefButF(block, NUM, B_MODIFIER_RECALC, "Sta y:", lx+115,cy,105,19, &wmd->starty, -100.0, 100.0, 100, 0, "Starting position for the Y axis"); uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_MODIFIER_RECALC, "Ob: ", lx, (cy-=19), 220,19, &wmd->objectcenter, "Object to use as Starting Position (leave blank to disable)"); + uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ",lx, (cy -= 19), 220, 19,&wmd->defgrp_name, 0.0, 31.0, 0, 0, "Name of vertex group with which to modulate displacement"); uiDefIDPoinBut(block, modifier_testTexture, ID_TE, B_CHANGEDEP,"Texture: ", lx, (cy -= 19), 220, 19, &wmd->texture,"Texture with which to modulate wave"); sprintf(str, "Texture Coordinates%%t" "|Local%%x%d|Global%%x%d|Object%%x%d|UV%%x%d", @@ -1907,7 +1907,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco &wmd->map_object, "Object to get texture coordinates from"); } - cy -= 19; + 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"); -- cgit v1.2.3