diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index c9606ea7efa..2f7ae6bb329 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -48,12 +48,12 @@ void free_lattice(struct Lattice *lt); void make_local_lattice(struct Lattice *lt); void calc_lat_fudu(int flag, int res, float *fu, float *du); void init_latt_deform(struct Object *oblatt, struct Object *ob); -void calc_latt_deform(float *co); +void calc_latt_deform(float *co, float weight); void end_latt_deform(void); int object_deform_mball(struct Object *ob); void outside_lattice(struct Lattice *lt); -void curve_deform_verts(struct Object *cuOb, struct Object *target, float (*vertexCos)[3], int numVerts); -void lattice_deform_verts(struct Object *laOb, struct Object *target, float (*vertexCos)[3], int numVerts); +void curve_deform_verts(struct Object *cuOb, struct Object *target, float (*vertexCos)[3], int numVerts, char *vgroup); +void lattice_deform_verts(struct Object *laOb, struct Object *target, float (*vertexCos)[3], int numVerts, char *vgroup); void armature_deform_verts(struct Object *armOb, struct Object *target, float (*vertexCos)[3], int numVerts, int deformflag); float (*lattice_getVertexCos(struct Object *ob, int *numVerts_r))[3]; void lattice_applyVertexCos(struct Object *ob, float (*vertexCos)[3]); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index b604af0f221..756f8fae8ad 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -909,7 +909,7 @@ static void make_particle_keys(RNG *rng, int depth, int nr, PartEff *paf, Partic pa= part; b= paf->totkey; while(b--) { - calc_latt_deform(pa->co); + calc_latt_deform(pa->co, 1.0f); pa++; } } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 940bd865185..29325138c15 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -161,7 +161,7 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) Mat4CpyMat4(mat, ltOb->obmat); Mat4One(ltOb->obmat); - lattice_deform_verts(ltOb, NULL, vertexCos, uNew*vNew*wNew); + lattice_deform_verts(ltOb, NULL, vertexCos, uNew*vNew*wNew, NULL); Mat4CpyMat4(ltOb->obmat, mat); lt->typeu = typeu; @@ -330,7 +330,7 @@ void init_latt_deform(Object *oblatt, Object *ob) } } -void calc_latt_deform(float *co) +void calc_latt_deform(float *co, float weight) { Lattice *lt; float u, v, w, tu[4], tv[4], tw[4]; @@ -402,7 +402,7 @@ void calc_latt_deform(float *co) else fpv= fpw; for(uu= ui-1; uu<=ui+2; uu++) { - u= v*tu[uu-ui+1]; + u= weight*v*tu[uu-ui+1]; if(u!=0.0) { if(uu>0) { @@ -556,7 +556,7 @@ static void calc_curve_deform(Object *par, float *co, short axis, CurveDeform *c } -void curve_deform_verts(Object *cuOb, Object *target, float (*vertexCos)[3], int numVerts) +void curve_deform_verts(Object *cuOb, Object *target, float (*vertexCos)[3], int numVerts, char *vgroup) { Curve *cu = cuOb->data; int a, flag = cu->flag; @@ -572,25 +572,77 @@ void curve_deform_verts(Object *cuOb, Object *target, float (*vertexCos)[3], int Mat4MulVecfl(cd.curvespace, vertexCos[a]); DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); } - - for(a=0; atrackflag, &cd); - Mat4MulVecfl(cd.objectspace, vertexCos[a]); + + if(vgroup && vgroup[0] && target->type==OB_MESH) { + bDeformGroup *curdef; + Mesh *me= target->data; + int index= 0; + + /* find the group (weak loop-in-loop) */ + for (curdef = target->defbase.first; curdef; curdef=curdef->next, index++) + if (!strcmp(curdef->name, vgroup)) + break; + /* check for numVerts because old files can have modifier over subsurf still */ + if(curdef && me->dvert && numVerts==me->totvert) { + MDeformVert *dvert= me->dvert; + float vec[3]; + int j; + + for(a=0; atotweight; j++) { + if (dvert->dw[j].def_nr == index) { + VECCOPY(vec, vertexCos[a]); + calc_curve_deform(cuOb, vec, target->trackflag, &cd); + VecLerpf(vertexCos[a], vertexCos[a], vec, dvert->dw[j].weight); + Mat4MulVecfl(cd.objectspace, vertexCos[a]); + } + } + } + } + } + else { + for(a=0; atrackflag, &cd); + Mat4MulVecfl(cd.objectspace, vertexCos[a]); + } } - cu->flag = flag; } -void lattice_deform_verts(Object *laOb, Object *target, float (*vertexCos)[3], int numVerts) +void lattice_deform_verts(Object *laOb, Object *target, float (*vertexCos)[3], int numVerts, char *vgroup) { int a; init_latt_deform(laOb, target); - - for(a=0; atype==OB_MESH) { + bDeformGroup *curdef; + Mesh *me= target->data; + int index= 0; + + /* find the group (weak loop-in-loop) */ + for (curdef = target->defbase.first; curdef; curdef=curdef->next, index++) + if (!strcmp(curdef->name, vgroup)) + break; + /* check for numVerts because old files can have modifier over subsurf still */ + if(curdef && me->dvert && numVerts==me->totvert) { + MDeformVert *dvert= me->dvert; + int j; + + for(a=0; atotweight; j++) { + if (dvert->dw[j].def_nr == index) { + calc_latt_deform(vertexCos[a], dvert->dw[j].weight); + } + } + } + } + } + else { + for(a=0; adisp.first; dl; dl=dl->next) { - lattice_deform_verts(ob->parent, ob, (float(*)[3]) dl->verts, dl->nr); + lattice_deform_verts(ob->parent, ob, (float(*)[3]) dl->verts, dl->nr, NULL); } return 1; diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index e69f0946bc5..d8d037d31a9 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -84,7 +84,7 @@ static void curveModifier_deformVerts(ModifierData *md, Object *ob, void *derive { CurveModifierData *cmd = (CurveModifierData*) md; - curve_deform_verts(cmd->object, ob, vertexCos, numVerts); + curve_deform_verts(cmd->object, ob, vertexCos, numVerts, cmd->name); } static void curveModifier_deformVertsEM(ModifierData *md, Object *ob, void *editData, void *derivedData, float (*vertexCos)[3], int numVerts) @@ -131,7 +131,7 @@ static void latticeModifier_deformVerts(ModifierData *md, Object *ob, void *deri { LatticeModifierData *lmd = (LatticeModifierData*) md; - lattice_deform_verts(lmd->object, ob, vertexCos, numVerts); + lattice_deform_verts(lmd->object, ob, vertexCos, numVerts, lmd->name); } static void latticeModifier_deformVertsEM(ModifierData *md, Object *ob, void *editData, void *derivedData, float (*vertexCos)[3], int numVerts) @@ -1233,7 +1233,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti = INIT_TYPE(Curve); mti->type = eModifierTypeType_OnlyDeform; - mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode; + mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_RequiresOriginalData; mti->copyData = curveModifier_copyData; mti->isDisabled = curveModifier_isDisabled; mti->foreachObjectLink = curveModifier_foreachObjectLink; @@ -1243,7 +1243,7 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type) mti = INIT_TYPE(Lattice); mti->type = eModifierTypeType_OnlyDeform; - mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode; + mti->flags = eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_RequiresOriginalData; mti->copyData = latticeModifier_copyData; mti->isDisabled = latticeModifier_isDisabled; mti->foreachObjectLink = latticeModifier_foreachObjectLink; diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 8f28eaee4bd..f496537671a 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -62,12 +62,14 @@ typedef struct LatticeModifierData { ModifierData modifier; struct Object *object; + char name[32]; /* optional vertexgroup name */ } LatticeModifierData; typedef struct CurveModifierData { ModifierData modifier; struct Object *object; + char name[32]; /* optional vertexgroup name */ } CurveModifierData; typedef struct BuildModifierData { diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index cf52059e019..93751c5b655 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -1270,9 +1270,11 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco } else if (md->type==eModifierType_Lattice) { LatticeModifierData *lmd = (LatticeModifierData*) md; uiDefIDPoinBut(block, modifier_testLatticeObj, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &lmd->object, "Lattice object to deform with"); + uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ", lx, (cy-=19), buttonWidth,19, &lmd->name, 0.0, 31.0, 0, 0, "Vertex Group name"); } else if (md->type==eModifierType_Curve) { CurveModifierData *cmd = (CurveModifierData*) md; uiDefIDPoinBut(block, modifier_testCurveObj, B_CHANGEDEP, "Ob: ", lx, (cy-=19), buttonWidth,19, &cmd->object, "Curve object to deform with"); + uiDefBut(block, TEX, B_MODIFIER_RECALC, "VGroup: ", lx, (cy-=19), buttonWidth,19, &cmd->name, 0.0, 31.0, 0, 0, "Vertex Group name"); } else if (md->type==eModifierType_Build) { BuildModifierData *bmd = (BuildModifierData*) md; uiDefButF(block, NUM, B_MODIFIER_RECALC, "Start:", lx, (cy-=19), buttonWidth,19, &bmd->start, 1.0, MAXFRAMEF, 100, 0, "Specify the start frame of the effect");