99
bDeformGroup *get_named_vertexgroup(Object *ob, char *name)
101
/* return a pointer to the deform group with this name
102
* or return NULL otherwise.
104
bDeformGroup *curdef;
106
for (curdef = ob->defbase.first; curdef; curdef=curdef->next){
107
if (!strcmp(curdef->name, name)){
114
int get_defgroup_num (Object *ob, bDeformGroup *dg)
116
/* Fetch the location of this deform group
117
* within the linked list of deform groups.
118
* (this number is stored in the deform
119
* weights of the deform verts to link them
120
* to this deform group) deform deform
121
* deform blah blah deform
127
eg = ob->defbase.first;
130
/* loop through all deform groups
134
/* if the current deform group is
135
* the one we are after, return
145
/* if there was no deform group found then
146
* return -1 (should set up a nice symbolic
149
if (eg == NULL) return -1;
155
/* *************** HOOK ****************** */
158
vec is supposed to be local coord, deform happens in local space
161
void hook_object_deform(Object *ob, int index, float *vec)
165
float vect[3], vectot[3];
167
if(ob->hooks.first==NULL) return;
169
/* reinitialize if... */
172
for(hook= ob->hooks.first; hook; hook= hook->next) {
175
Mat4Invert(ob->imat, ob->obmat);
176
/* apparently this call goes from right to left... */
177
Mat4MulSerie(hook->mat, ob->imat, hook->parent->obmat, hook->parentinv, NULL,
178
NULL, NULL, NULL, NULL);
185
vectot[0]= vectot[1]= vectot[2]= 0.0;
187
for(hook= ob->hooks.first; hook; hook= hook->next) {
190
/* is 'index' in hook array? */
191
while(hook->curindex < hook->totindex-1) {
192
if( hook->indexar[hook->curindex] < index ) hook->curindex++;
196
if( hook->indexar[hook->curindex]==index ) {
197
float fac= hook->force, len;
199
VecMat4MulVecfl(vect, hook->mat, vec);
201
if(hook->falloff!=0.0) {
202
/* hook->cent is in local coords */
203
len= VecLenf(vec, hook->cent);
204
if(len > hook->falloff) fac= 0.0;
205
else if(len>0.0) fac*= sqrt(1.0 - len/hook->falloff);
209
vectot[0]+= fac*vect[0];
210
vectot[1]+= fac*vect[1];
211
vectot[2]+= fac*vect[2];
217
/* if totforce < 1.0, we take old position also into account */
219
vectot[0]+= (1.0-totforce)*vec[0];
220
vectot[1]+= (1.0-totforce)*vec[1];
221
vectot[2]+= (1.0-totforce)*vec[2];
223
else VecMulf(vectot, 1.0/totforce);
225
VECCOPY(vec, vectot);
229
/* modifiers: hooks, deform, softbody
230
mode=='s' is start, 'e' is end , 'a' is apply
233
int mesh_modifier(Object *ob, char mode)
235
static MVert *mvert=NULL;
240
/* conditions if it's needed */
242
else if(ob->effect.first); // weak... particles too
243
else if(ob->parent && ob->parent->type==OB_LATTICE);
244
else if(ob->parent && ob->partype==PARSKEL);
245
else if(ob->softflag & OB_SB_ENABLE);
248
if(me->totvert==0) return 0;
250
if(mode=='s') { // "start"
252
mvert= MEM_dupallocN(me->mvert);
255
if(ob->hooks.first) {
258
/* NULL signals initialize */
259
hook_object_deform(ob, 0, NULL);
261
for(a=0, mv= me->mvert; a<me->totvert; a++, mv++) {
262
hook_object_deform(ob, a, mv->co);
266
if(ob->effect.first) done |= object_wave(ob);
268
if((ob->softflag & OB_SB_ENABLE) && !(ob->softflag & OB_SB_POSTDEF)) {
270
sbObjectStep(ob, (float)G.scene->r.cfra);
273
/* object_deform: output for mesh is in mesh->mvert */
274
done |= object_deform(ob);
276
if((ob->softflag & OB_SB_ENABLE) && (ob->softflag & OB_SB_POSTDEF)) {
278
sbObjectStep(ob, (float)G.scene->r.cfra);
281
/* put deformed vertices in dl->verts, optional subsurf will replace that */
283
DispList *dl= find_displist_create(&ob->disp, DL_VERTS);
286
if(dl->verts) MEM_freeN(dl->verts);
287
if(dl->nors) MEM_freeN(dl->nors);
291
/* make disp array */
292
dl->verts= fp= MEM_mallocN(3*sizeof(float)*me->totvert, "deform1");
294
for(a=0; a<me->totvert; a++, mv++, fp+=3) {
301
else if(mode=='e') { // end
303
if(me->mvert) MEM_freeN(me->mvert);
308
else if(mode=='a') { // apply
309
if(mvert) MEM_freeN(mvert);
316
int curve_modifier(Object *ob, char mode)
318
static ListBase nurb={NULL, NULL};
323
int a, index, done= 0;
325
/* conditions if it's needed */
327
else if(ob->parent && ob->partype==PARSKEL);
328
else if(ob->parent && ob->parent->type==OB_LATTICE);
331
if(mode=='s') { // "start"
333
nurb.first= nurb.last= NULL;
336
newnu= duplicateNurb(nu);
337
BLI_addtail(&nurb, newnu);
342
if(ob->hooks.first) {
345
/* NULL signals initialize */
346
hook_object_deform(ob, 0, NULL);
351
if((nu->type & 7)==CU_BEZIER) {
355
hook_object_deform(ob, index++, bezt->vec[0]);
356
hook_object_deform(ob, index++, bezt->vec[1]);
357
hook_object_deform(ob, index++, bezt->vec[2]);
363
a= nu->pntsu*nu->pntsv;
365
hook_object_deform(ob, index++, bp->vec);
376
freeNurblist(&cu->nurb);
386
int lattice_modifier(Object *ob, char mode)
388
static BPoint *bpoint;
389
Lattice *lt= ob->data;
391
int a, index, done= 0;
393
/* conditions if it's needed */
395
else if(ob->parent && ob->partype==PARSKEL);
396
else if((ob->softflag & OB_SB_ENABLE));
399
if(mode=='s') { // "start"
401
bpoint= MEM_dupallocN(lt->def);
404
if(ob->hooks.first) {
407
/* NULL signals initialize */
408
hook_object_deform(ob, 0, NULL);
411
a= lt->pntsu*lt->pntsv*lt->pntsw;
413
hook_object_deform(ob, index++, bp->vec);
418
if((ob->softflag & OB_SB_ENABLE)) {
419
sbObjectStep(ob, (float)G.scene->r.cfra);