diff options
author | Andre Susano Pinto <andresusanopinto@gmail.com> | 2008-08-04 17:12:35 +0400 |
---|---|---|
committer | Andre Susano Pinto <andresusanopinto@gmail.com> | 2008-08-04 17:12:35 +0400 |
commit | 919eba04de19fbf5edbfdf3d4cbfec446645e5ac (patch) | |
tree | 0190c951da3134f64b2164374826dd25545b8bfc | |
parent | d786fead104fc4ce1a42286631fb74a3b0dfd620 (diff) |
SimpleDeform modifications:
* Added "Lock axis" options on taper and strech/squash (suggested by ZanQdo)
* Better control of deform factor (suggested by ZanQdo)
* Added eModifierTypeFlag_AcceptsCVs (so it now accepts both curves and meshes)
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/simple_deform.c | 99 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 20 | ||||
-rw-r--r-- | source/blender/src/buttons_editing.c | 33 |
4 files changed, 74 insertions, 93 deletions
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 502be6b3af3..89de5ee9e45 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -7289,10 +7289,12 @@ static void simpledeformModifier_initData(ModifierData *md) SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md; smd->mode = MOD_SIMPLEDEFORM_MODE_TWIST; - smd->origin = 0; - smd->factor[0] = 0.35; - smd->factor[1] = -1000.0; - smd->factor[2] = 1000.0; + smd->axis = 0; + + smd->origin = NULL; + smd->factor = 0.35; + smd->limit[0] = -1000.0f; + smd->limit[1] = 1000.0f; } static void simpledeformModifier_copyData(ModifierData *md, ModifierData *target) @@ -7301,8 +7303,10 @@ static void simpledeformModifier_copyData(ModifierData *md, ModifierData *target SimpleDeformModifierData *tsmd = (SimpleDeformModifierData*)target; tsmd->mode = smd->mode; + tsmd->axis = smd->axis; tsmd->origin= smd->origin; - memcpy(tsmd->factor, smd->factor, sizeof(tsmd->factor)); + tsmd->factor= smd->factor; + memcpy(tsmd->limit, smd->limit, sizeof(tsmd->limit)); } static void simpledeformModifier_deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) @@ -7681,6 +7685,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti = INIT_TYPE(SimpleDeform); mti->type = eModifierTypeType_OnlyDeform; mti->flags = eModifierTypeFlag_AcceptsMesh + | eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode; mti->initData = simpledeformModifier_initData; diff --git a/source/blender/blenkernel/intern/simple_deform.c b/source/blender/blenkernel/intern/simple_deform.c index 86fef7208a1..20cba28ab5a 100644 --- a/source/blender/blenkernel/intern/simple_deform.c +++ b/source/blender/blenkernel/intern/simple_deform.c @@ -40,7 +40,9 @@ #include <math.h> -static void axis_limit(int axis, const float limits[2], float *co, float *dcut) +//Clamps/Limits the given coordinate to: limits[0] <= co[axis] <= limits[1] +//The ammount of clamp is saved on dcut +static void axis_limit(int axis, const float limits[2], float co[3], float dcut[3]) { float val = co[axis]; if(limits[0] > val) val = limits[0]; @@ -50,10 +52,9 @@ static void axis_limit(int axis, const float limits[2], float *co, float *dcut) co[axis] = val; } -static void simpleDeform_tapperXY(const float factor, const float *dcut, float *co) +static void simpleDeform_taper(const float factor, const float dcut[3], float *co) { float x = co[0], y = co[1], z = co[2]; - float scale = z*factor; co[0] = x + x*scale; @@ -62,13 +63,13 @@ static void simpleDeform_tapperXY(const float factor, const float *dcut, float * if(dcut) { - co[0] += dcut[0]*scale; - co[1] += dcut[1]*scale; + co[0] += dcut[0]; + co[1] += dcut[1]; co[2] += dcut[2]; } } -static void simpleDeform_strech(const float factor, const float dcut[3], float *co) +static void simpleDeform_stretch(const float factor, const float dcut[3], float *co) { float x = co[0], y = co[1], z = co[2]; float scale; @@ -82,46 +83,9 @@ static void simpleDeform_strech(const float factor, const float dcut[3], float * if(dcut) { - co[0] += dcut[0]*scale; - co[1] += dcut[0]*scale; - co[2] += dcut[2]; - } -} - -static void simpleDeform_squash(const float factor, const float dcut[3], float *co) -{ - float x = co[0], y = co[1], z = co[2]; - float scale; - - scale = z*factor; - scale = -scale*scale; - - co[0] += x+x*scale; - co[1] += y+y*scale; - - if(dcut) - { - co[0] += dcut[0]*scale; - co[1] += dcut[0]*scale; - co[2] += dcut[2]; - } -} - -static void simpleDeform_tapperX(const float factor, const float *dcut, float *co) -{ - float x = co[0], y = co[1], z = co[2]; - - float scale = z*factor; - - co[0] = x+ x*scale; - co[1] = y; - co[2] = z; - - if(dcut) - { - co[0] += dcut[0]*scale; + co[0] += dcut[0]; co[1] += dcut[1]; - co[2] += dcut[2]; + co[2] += dcut[2]; } } @@ -179,6 +143,7 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s int i; float (*ob2mod)[4] = NULL, (*mod2ob)[4] = NULL; float tmp_matrix[2][4][4]; + static const float lock_axis[2] = {0.0f, 0.0f}; int vgroup = get_named_vertexgroup_num(ob, smd->vgroup_name); @@ -205,41 +170,41 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s { float co[3], dcut[3]; float weight = vertexgroup_get_vertex_weight(dvert, i, vgroup); + float factor = smd->factor; if(weight == 0) continue; if(ob2mod) Mat4MulVecfl(ob2mod, vertexCos[i]); - dcut[0] = dcut[1] = dcut[2] = 0.0f; VECCOPY(co, vertexCos[i]); + dcut[0] = dcut[1] = dcut[2] = 0.0f; + if(smd->axis & MOD_SIMPLEDEFORM_LOCK_AXIS_X) axis_limit(0, lock_axis, co, dcut); + if(smd->axis & MOD_SIMPLEDEFORM_LOCK_AXIS_Y) axis_limit(1, lock_axis, co, dcut); + switch(smd->mode) { case MOD_SIMPLEDEFORM_MODE_TWIST: - axis_limit(2, smd->factor+1, co, dcut); - simpleDeform_twist (smd->factor[0], dcut, co); - break; + axis_limit(2, smd->limit, co, dcut); + simpleDeform_twist(factor, dcut, co); + break; case MOD_SIMPLEDEFORM_MODE_BEND: - axis_limit(0, smd->factor+1, co, dcut); - simpleDeform_bend (smd->factor[0], dcut, co); - break; - - case MOD_SIMPLEDEFORM_MODE_TAPER_X: - axis_limit(2, smd->factor+1, co, dcut); - simpleDeform_tapperX (smd->factor[0], dcut, co); - break; - - case MOD_SIMPLEDEFORM_MODE_TAPER_XY: - axis_limit(2, smd->factor+1, co, dcut); - simpleDeform_tapperXY(smd->factor[0], dcut, co); - break; - - case MOD_SIMPLEDEFORM_MODE_STRECH_SQUASH: - axis_limit(2, smd->factor+1, co, dcut); - simpleDeform_strech(smd->factor[0], dcut, co); - break; + axis_limit(0, smd->limit, co, dcut); + simpleDeform_bend(factor, dcut, co); + break; + + case MOD_SIMPLEDEFORM_MODE_TAPER: + axis_limit(2, smd->limit, co, dcut); + simpleDeform_taper(factor, dcut, co); + break; + + + case MOD_SIMPLEDEFORM_MODE_STRETCH: + axis_limit(2, smd->limit, co, dcut); + simpleDeform_stretch(factor, dcut, co); + break; } //linear interpolation diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index e63eb608295..b3d80f2e554 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -524,17 +524,21 @@ typedef struct SimpleDeformModifierData { struct Object *origin; /* object to control the origin of modifier space coordinates */ char vgroup_name[32]; /* optional vertexgroup name */ - float factor[4]; /* factors to control simple deforms */ + float factor; /* factors to control simple deforms */ + float limit[2]; /* lower and upper limit */ - char mode; - char pad[7]; + char mode; /* deform function */ + char axis; /* lock axis (for taper and strech) */ + char pad[2]; } SimpleDeformModifierData; -#define MOD_SIMPLEDEFORM_MODE_TWIST 1 -#define MOD_SIMPLEDEFORM_MODE_BEND 2 -#define MOD_SIMPLEDEFORM_MODE_TAPER_X 3 -#define MOD_SIMPLEDEFORM_MODE_TAPER_XY 4 -#define MOD_SIMPLEDEFORM_MODE_STRECH_SQUASH 5 +#define MOD_SIMPLEDEFORM_MODE_TWIST 1 +#define MOD_SIMPLEDEFORM_MODE_BEND 2 +#define MOD_SIMPLEDEFORM_MODE_TAPER 3 +#define MOD_SIMPLEDEFORM_MODE_STRETCH 4 + +#define MOD_SIMPLEDEFORM_LOCK_AXIS_X (1<<0) +#define MOD_SIMPLEDEFORM_LOCK_AXIS_Y (1<<1) #endif diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index 31f4596c264..63ef31b6062 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -962,7 +962,7 @@ static void modifiers_add(void *ob_v, int type) static void do_modifiers_select_simpledeform_typemenu(void *ob_v, int event) { - static const char *default_name[] = { "", "Twist", "Bend", "Taper X", "Taper XY", "Strech", "Squash" }; + static const char *default_name[] = { "", "Twist", "Bend", "Taper", "Strech" }; SimpleDeformModifierData *smd = (SimpleDeformModifierData*)modifier_new(eModifierType_SimpleDeform); smd->mode = event; @@ -984,9 +984,8 @@ static uiBlock *modifiers_select_simpledeform_typemenu(void *ob_v) uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Twist", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_TWIST, ""); uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Bend", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_BEND, ""); - uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Tapper X", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_TAPER_X, ""); - uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Tapper XY", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_TAPER_XY, ""); - uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Strech Squash", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_STRECH_SQUASH, ""); + uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Taper", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_TAPER, ""); + uiDefBut(block, BUTM, B_MODIFIER_RECALC, "Stretch", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, MOD_SIMPLEDEFORM_MODE_STRETCH, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 50); @@ -1909,7 +1908,13 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco height += 19; } else if (md->type==eModifierType_SimpleDeform) { - height += 19*5; + SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md; + + height += 19*4; + + if(smd->mode == MOD_SIMPLEDEFORM_MODE_STRETCH + || smd->mode == MOD_SIMPLEDEFORM_MODE_TAPER ) + height += 19; } /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */ uiDefBut(block, ROUNDBOX, 0, "", x-10, y-height-2, width, height-2, NULL, 5.0, 0.0, 12, 40, ""); @@ -2566,11 +2571,6 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco } else if (md->type==eModifierType_SimpleDeform) { SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md; -/* - char simpledeform_typemenu[]="Deform type%t|Twist %x1|Bend %x2|Taper %x3|TaperXY %x4|Strech %x5|Squash %x6"; - uiDefButC(block, MENU, B_MODIFIER_RECALC, simpledeform_typemenu, lx,(cy-=19),buttonWidth,19, &smd->mode, 0, 0, 0, 0, "Selects type of deform"); -*/ - but=uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ", lx, (cy-=19), buttonWidth,19, &smd->vgroup_name, 0, 31, 0, 0, "Vertex Group name"); uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob); @@ -2588,10 +2588,17 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco bt= uiDefIconBut(block, BUT, B_CHANGEDEP, ICON_ZOOMIN, lx+buttonWidth-17, cy, 17, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Creates a new empty"); uiButSetFunc(bt, modifier_link_new_empty, &smd->origin, ob); } - uiDefButF(block, NUM, B_MODIFIER_RECALC, "Factor:", lx,(cy-=19),buttonWidth,19, &smd->factor[0], -3000.0f, 3000.0f, 1.0f, 0, "Deform Factor"); + uiDefButF(block, NUM, B_MODIFIER_RECALC, "Factor:", lx,(cy-=19),buttonWidth,19, &smd->factor, -10.0f, 10.0f, 0.5f, 0, "Deform Factor"); + + uiDefButF(block, NUM, B_MODIFIER_RECALC, "Upper Limit:", lx,(cy-=19),buttonWidth,19, &smd->limit[1], -1000.0f, 1000.0f, 5.0f, 0, "Upper Limit Bend on X"); + uiDefButF(block, NUM, B_MODIFIER_RECALC, "Lower Limit:", lx,(cy-=19),buttonWidth,19, &smd->limit[0], -1000.0f, 1000.0f, 5.0f, 0, "Lower Limit Bend on X"); - uiDefButF(block, NUM, B_MODIFIER_RECALC, "Upper Limit:", lx,(cy-=19),buttonWidth,19, &smd->factor[2], -3000.0f, 3000.0f, 1.0f, 0, "Upper Limit Bend on X"); - uiDefButF(block, NUM, B_MODIFIER_RECALC, "Lower Limit:", lx,(cy-=19),buttonWidth,19, &smd->factor[1], -3000.0f, 3000.0f, 1.0f, 0, "Lower Limit Bend on X"); + if(smd->mode == MOD_SIMPLEDEFORM_MODE_STRETCH + || smd->mode == MOD_SIMPLEDEFORM_MODE_TAPER ) + { + uiDefButBitC(block, TOG, MOD_SIMPLEDEFORM_LOCK_AXIS_X, B_MODIFIER_RECALC, "Loc X", lx, (cy-=19),buttonWidth/2,19, &smd->axis, 0, 0, 0, 0, "Disallow changes on the X coordinate"); + uiDefButBitC(block, TOG, MOD_SIMPLEDEFORM_LOCK_AXIS_Y, B_MODIFIER_RECALC, "Loc Y", lx+(buttonWidth/2), (cy),buttonWidth/2,19, &smd->axis, 0, 0, 0, 0, "Disallow changes on the Y coordinate"); + } } |