Patch #5181: Option to use an object to determine the startX&Y in the

Wave Modifier

This patch allows the option to use an object to determine the wave modifier's
start X & Y, it also allows for animated objects giving a moving wave
start X & Y.

Thanks to Michael Fox for the patch!
This commit is contained in:
Ben Batt 2006-11-20 11:58:48 +00:00
parent af0d38d6ef
commit f7c24e1b11
3 changed files with 42 additions and 1 deletions

@ -2846,6 +2846,7 @@ static void waveModifier_initData(ModifierData *md)
wmd->flag |= (WAV_X+WAV_Y+WAV_CYCL);
wmd->objectcenter = NULL;
wmd->height= 0.5f;
wmd->width= 1.5f;
wmd->speed= 0.5f;
@ -2869,6 +2870,7 @@ static void waveModifier_copyData(ModifierData *md, ModifierData *target)
twmd->starty = wmd->starty;
twmd->timeoffs = wmd->timeoffs;
twmd->width = wmd->width;
twmd->objectcenter = wmd->objectcenter;
}
static int waveModifier_dependsOnTime(ModifierData *md)
@ -2876,6 +2878,29 @@ static int waveModifier_dependsOnTime(ModifierData *md)
return 1;
}
static void waveModifier_foreachObjectLink(
ModifierData *md, Object *ob,
void (*walk)(void *userData, Object *ob, Object **obpoin),
void *userData)
{
WaveModifierData *wmd = (WaveModifierData*) md;
walk(userData, ob, &wmd->objectcenter);
}
static void waveModifier_updateDepgraph(
ModifierData *md, DagForest *forest, Object *ob,
DagNode *obNode)
{
WaveModifierData *wmd = (WaveModifierData*) md;
if(wmd->objectcenter) {
DagNode *curNode = dag_get_node(forest, wmd->objectcenter);
dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA);
}
}
static void waveModifier_deformVerts(
ModifierData *md, Object *ob, DerivedMesh *derivedData,
float (*vertexCos)[3], int numVerts)
@ -2886,6 +2911,16 @@ static void waveModifier_deformVerts(
(float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow));
float lifefac = wmd->height;
if(wmd->objectcenter){
float mat[4][4];
/* get the control object's location in local coordinates */
Mat4Invert(ob->imat, ob->obmat);
Mat4MulMat4(mat, wmd->objectcenter->obmat, ob->imat);
wmd->startx = mat[3][0];
wmd->starty = mat[3][1];
}
if(wmd->damp == 0) wmd->damp = 10.0f;
if(wmd->lifetime != 0.0) {
@ -3432,6 +3467,8 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
mti->initData = waveModifier_initData;
mti->copyData = waveModifier_copyData;
mti->dependsOnTime = waveModifier_dependsOnTime;
mti->foreachObjectLink = waveModifier_foreachObjectLink;
mti->updateDepgraph = waveModifier_updateDepgraph;
mti->deformVerts = waveModifier_deformVerts;
mti->deformVertsEM = waveModifier_deformVertsEM;

@ -222,6 +222,8 @@ typedef struct DecimateModifierData {
typedef struct WaveModifierData {
ModifierData modifier;
struct Object *objectcenter;
short flag, pad;
float startx, starty, height, width;

@ -1359,7 +1359,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
} else if (md->type==eModifierType_Decimate) {
height = 48;
} else if (md->type==eModifierType_Wave) {
height = 200;
height = 248;
} else if (md->type==eModifierType_Armature) {
height = 67;
} else if (md->type==eModifierType_Hook) {
@ -1541,6 +1541,8 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
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)");
cy -= 19;
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, "Heigth:", lx,(cy-=19),220,19, &wmd->height, -2.0, 2.0, 0, 0, "Specify the amplitude of the wave");