Curve and Lattice deform Modifiers now accept optional Vertex Group name
authorTon Roosendaal <ton@blender.org>
Thu, 20 Oct 2005 18:52:29 +0000 (18:52 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 20 Oct 2005 18:52:29 +0000 (18:52 +0000)
to finetune deform further as well.
Note that curve deform requires object buttons 'track' and 'up' axes set
properly. Curve deform can twist/flip a lot, making Vertex Group based
deform hard to set up.

source/blender/blenkernel/BKE_lattice.h
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/modifier.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/src/buttons_editing.c

index c9606ea7efa761dc154893bd5b6bd0e155771f16..2f7ae6bb329f862a0650845ca85c1b880b3c5ae6 100644 (file)
@@ -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]);
index b604af0f2215da23fd1993a5fbb9e8d1310f8a1d..756f8fae8ad6445410dd87346bbe431feadba590 100644 (file)
@@ -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++;
                }
        }
index 940bd865185173c792c94554f5242306a4696ed8..29325138c152a11d8efa8f53d1e66bf10dd707db 100644 (file)
@@ -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; a<numVerts; a++) {
-               calc_curve_deform(cuOb, vertexCos[a], target->trackflag, &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; a<numVerts; a++, dvert++) {
+                               for(j=0; j<dvert->totweight; 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; a<numVerts; a++) {
+                       calc_curve_deform(cuOb, vertexCos[a], target->trackflag, &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; a<numVerts; a++) {
-               calc_latt_deform(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;
+                       int j;
+                       
+                       for(a=0; a<numVerts; a++, dvert++) {
+                               for(j=0; j<dvert->totweight; j++) {
+                                       if (dvert->dw[j].def_nr == index) {
+                                               calc_latt_deform(vertexCos[a], dvert->dw[j].weight);
+                                       }
+                               }
+                       }
+               }
+       }
+       else {
+               for(a=0; a<numVerts; a++) {
+                       calc_latt_deform(vertexCos[a], 1.0f);
+               }
        }
-
        end_latt_deform();
 }
 
@@ -600,7 +652,7 @@ int object_deform_mball(Object *ob)
                DispList *dl;
 
                for (dl=ob->disp.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;
index e69f0946bc514ad196be4aa4a57cdd9b891b9989..d8d037d31a9fc6b31a332a3030487908718e2d28 100644 (file)
@@ -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;
index 8f28eaee4bdc1e6d009a61bc30db6a8ebb1c4c14..f496537671ac97be6c16385b14720d0ed7ce85ed 100644 (file)
@@ -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 {
index cf52059e019c3b189bfbcdcd64221c66fee8a013..93751c5b655db525acc6f4937999d3294f88ad31 100644 (file)
@@ -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");