forked from bartvdbraak/blender
Curve and Lattice deform Modifiers now accept optional Vertex Group name
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.
This commit is contained in:
parent
acf2fda50e
commit
197fdd2e36
@ -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]);
|
||||
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user