5
* $Id: key.c,v 1.21 2006/04/17 17:35:19 ton Exp $
5
* $Id: key.c 14444 2008-04-16 22:40:48Z hos $
7
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
7
* ***** BEGIN GPL LICENSE BLOCK *****
9
9
* This program is free software; you can redistribute it and/or
10
10
* modify it under the terms of the GNU General Public License
11
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version. The Blender
13
* Foundation also sells licenses for use in proprietary software under
14
* the Blender License. See http://www.blender.org/BL/ for information
12
* of the License, or (at your option) any later version.
17
14
* This program is distributed in the hope that it will be useful,
18
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
185
184
make_local_ipo(key->ipo);
188
* Sort shape keys and Ipo curves after a change. This assumes that at most
189
* one key was moved, which is a valid assumption for the places it's
190
* currently being called.
189
193
void sort_keys(Key *key)
197
for(kb= key->block.first; kb; kb= kb->next) {
199
if(kb->pos > kb->next->pos) {
200
BLI_remlink(&key->block, kb);
202
BLI_insertlink(&key->block, kb->next, kb);
197
IpoCurve *icu = NULL;
200
/* locate the key which is out of position */
201
for( kb= key->block.first; kb; kb= kb->next )
202
if( kb->next && kb->pos > kb->next->pos )
205
/* if we find a key, move it */
207
kb = kb->next; /* next key is the out-of-order one */
208
BLI_remlink(&key->block, kb);
210
/* find the right location and insert before */
211
for( kb2=key->block.first; kb2; kb2= kb2->next ) {
212
if( kb2->pos > kb->pos ) {
213
BLI_insertlink(&key->block, kb2->prev, kb);
218
/* if more than one Ipo curve, see if this key had a curve */
220
if(key->ipo && key->ipo->curve.first != key->ipo->curve.last ) {
221
for(icu= key->ipo->curve.first; icu; icu= icu->next) {
222
/* if we find the curve, remove it and reinsert in the
224
if(icu->adrcode==kb->adrcode) {
226
BLI_remlink(&key->ipo->curve, icu);
227
for(icu2= key->ipo->curve.first; icu2; icu2= icu2->next) {
228
if(icu2->adrcode >= kb2->adrcode) {
229
BLI_insertlink(&key->ipo->curve, icu2->prev, icu);
238
/* kb points at the moved key, icu at the moved ipo (if it exists).
239
* go back now and renumber adrcodes */
242
adrcode = kb2->adrcode;
243
for( i = kb->adrcode - adrcode; i >= 0; --i, ++adrcode ) {
244
/* if the next ipo curve matches the current key, renumber it */
245
if(icu && icu->adrcode == kb->adrcode ) {
246
icu->adrcode = adrcode;
249
/* renumber the shape key */
250
kb->adrcode = adrcode;
211
255
/* new rule; first key is refkey, this to match drawing channels... */
501
memcpy(poin, kref, 4*cp[0]);
545
memcpy(poin, kref, sizeof(float)*cp[0]);
502
546
if(*weights!=0.0f)
503
547
rel_flerp(cp[0], (float *)poin, (float *)kref, (float *)k1, *weights);
507
memcpy(poin, k1, 4*cp[0]);
551
memcpy(poin, k1, sizeof(float)*cp[0]);
513
memcpy(poin, k1, 3*4);
514
memcpy(poin+16, k1+12, 4);
557
memcpy(poin, k1, 3*sizeof(float));
558
memcpy(poin+4*sizeof(float), k1+3*sizeof(float), sizeof(float));
519
563
case IPO_BEZTRIPLE:
520
memcpy(poin, k1, 4*12);
564
memcpy(poin, k1, sizeof(float)*10);
626
670
/* step 2: do it */
628
kb= key->block.first;
672
for(kb=key->block.first; kb; kb=kb->next) {
631
673
if(kb!=key->refkey) {
632
674
float icuval= kb->curval;
634
676
/* only with value, and no difference allowed */
635
if(icuval!=0.0f && kb->totelem==tot) {
677
if(!(kb->flag & KEYBLOCK_MUTE) && icuval!=0.0f && kb->totelem==tot) {
636
679
float weight, *weights= kb->weights;
639
reffrom= key->refkey->data;
683
/* reference now can be any block */
684
refb= BLI_findlink(&key->block, kb->relative);
685
if(refb==NULL) continue;
642
688
poin+= start*ofs[0];
643
689
reffrom+= key->elemsize*start; // key elemsize yes!
906
static float *get_weights_array(Object *ob, Mesh *me, char *vgroup)
951
static float *get_weights_array(Object *ob, char *vgroup)
908
953
bDeformGroup *curdef;
954
MDeformVert *dvert= NULL;
955
int totvert= 0, index= 0;
957
/* no vgroup string set? */
911
958
if(vgroup[0]==0) return NULL;
912
if(me->dvert==NULL) return NULL;
960
/* gather dvert and totvert */
961
if(ob->type==OB_MESH) {
964
totvert= me->totvert;
966
else if(ob->type==OB_LATTICE) {
967
Lattice *lt= ob->data;
969
totvert= lt->pntsu*lt->pntsv*lt->pntsw;
972
if(dvert==NULL) return NULL;
914
974
/* find the group (weak loop-in-loop) */
915
975
for (curdef = ob->defbase.first; curdef; curdef=curdef->next, index++)
920
MDeformVert *dvert= me->dvert;
924
weights= MEM_callocN(me->totvert*sizeof(float), "weights");
983
weights= MEM_callocN(totvert*sizeof(float), "weights");
926
for (i=0; i < me->totvert; i++, dvert++) {
985
for (i=0; i < totvert; i++, dvert++) {
927
986
for(j=0; j<dvert->totweight; j++) {
928
987
if (dvert->dw[j].def_nr == index) {
929
988
weights[i]= dvert->dw[j].weight;
965
1024
for(a=0; a<me->totvert; a+=step, cfra+= delta) {
967
ctime= bsystem_time(0, 0, cfra, 0.0);
1026
ctime= bsystem_time(0, cfra, 0.0);
968
1027
if(calc_ipo_spec(me->key->ipo, KEY_SPEED, &ctime)==0) {
970
1029
CLAMP(ctime, 0.0, 1.0);
991
1050
for(kb= me->key->block.first; kb; kb= kb->next)
992
kb->weights= get_weights_array(ob, me, kb->vgroup);
1051
kb->weights= get_weights_array(ob, kb->vgroup);
994
1053
do_rel_key(0, me->totvert, me->totvert, (char *)me->mvert->co, me->key, 0);
1002
ctime= bsystem_time(ob, 0, G.scene->r.cfra, 0.0);
1061
ctime= bsystem_time(ob, G.scene->r.cfra, 0.0);
1004
1063
if(calc_ipo_spec(me->key->ipo, KEY_SPEED, &ctime)==0) {
1005
1064
ctime /= 100.0;
1120
1179
for(a=0; a<tot; a+=step, cfra+= delta) {
1122
ctime= bsystem_time(0, 0, cfra, 0.0);
1181
ctime= bsystem_time(0, cfra, 0.0);
1123
1182
if(calc_ipo_spec(cu->key->ipo, KEY_SPEED, &ctime)==0) {
1124
1183
ctime /= 100.0;
1125
1184
CLAMP(ctime, 0.0, 1.0);
1144
ctime= bsystem_time(NULL, 0, (float)G.scene->r.cfra, 0.0);
1203
ctime= bsystem_time(NULL, (float)G.scene->r.cfra, 0.0);
1146
1205
if(cu->key->type==KEY_RELATIVE) {
1147
1206
do_rel_cu_key(cu, ctime);
1184
1243
for(a=0; a<tot; a++, cfra+= delta) {
1186
ctime= bsystem_time(0, 0, cfra, 0.0);
1245
ctime= bsystem_time(0, cfra, 0.0);
1187
1246
if(calc_ipo_spec(lt->key->ipo, KEY_SPEED, &ctime)==0) {
1188
1247
ctime /= 100.0;
1189
1248
CLAMP(ctime, 0.0, 1.0);
1203
ctime= bsystem_time(NULL, 0, (float)G.scene->r.cfra, 0.0);
1262
ctime= bsystem_time(NULL, (float)G.scene->r.cfra, 0.0);
1205
1264
if(lt->key->type==KEY_RELATIVE) {
1267
for(kb= lt->key->block.first; kb; kb= kb->next)
1268
kb->weights= get_weights_array(ob, kb->vgroup);
1206
1270
do_rel_key(0, tot, tot, (char *)lt->def->vec, lt->key, 0);
1272
for(kb= lt->key->block.first; kb; kb= kb->next) {
1273
if(kb->weights) MEM_freeN(kb->weights);
1209
1278
if(calc_ipo_spec(lt->key->ipo, KEY_SPEED, &ctime)==0) {
1245
1317
if(ob->type==OB_MESH) {
1246
1318
Mesh *me= ob->data;
1247
float *weights= get_weights_array(ob, me, kb->vgroup);
1319
float *weights= get_weights_array(ob, kb->vgroup);
1249
1321
cp_key(0, me->totvert, me->totvert, (char *)me->mvert->co, key, kb, weights, 0);
1253
1325
else if(ob->type==OB_LATTICE) {
1254
1326
Lattice *lt= ob->data;
1327
float *weights= get_weights_array(ob, kb->vgroup);
1255
1328
int tot= lt->pntsu*lt->pntsv*lt->pntsw;
1257
cp_key(0, tot, tot, (char *)lt->def->vec, key, kb, NULL, 0);
1330
cp_key(0, tot, tot, (char *)lt->def->vec, key, kb, weights, 0);
1332
if(weights) MEM_freeN(weights);
1259
1334
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
1260
1335
Curve *cu= ob->data;
1268
1343
if(ob->ipoflag & OB_ACTION_KEY)
1269
1344
do_all_object_actions(ob);
1271
calc_ipo(key->ipo, bsystem_time(ob, 0, G.scene->r.cfra, 0.0));
1346
calc_ipo(key->ipo, bsystem_time(ob, G.scene->r.cfra, 0.0));
1272
1347
execute_ipo((ID *)key, key->ipo);
1275
1350
if(ob->type==OB_MESH) return do_mesh_key(ob, ob->data);
1276
1351
else if(ob->type==OB_CURVE) return do_curve_key( ob->data);
1277
1352
else if(ob->type==OB_SURF) return do_curve_key( ob->data);
1278
else if(ob->type==OB_LATTICE) return do_latt_key( ob->data);
1353
else if(ob->type==OB_LATTICE) return do_latt_key(ob, ob->data);