1813
/* returns and creates */
1814
IpoCurve *verify_ipocurve(ID *from, short blocktype, char *actname, char *constname, int adrcode)
1987
/* returns and creates
1988
* Make sure functions check for NULL or they will crash!
1990
IpoCurve *verify_ipocurve(ID *from, short blocktype, char *actname, char *constname, char *bonename, int adrcode)
1817
1993
IpoCurve *icu= NULL;
1819
1995
/* return 0 if lib */
1820
1996
/* creates ipo too */
1821
ipo= verify_ipo(from, blocktype, actname, constname);
1997
ipo= verify_ipo(from, blocktype, actname, constname, bonename);
1823
if(ipo && ipo->id.lib==NULL) {
1999
if(ipo && ipo->id.lib==NULL && from->lib==NULL) {
1825
2001
for(icu= ipo->curve.first; icu; icu= icu->next) {
1826
2002
if(icu->adrcode==adrcode) break;
1828
2004
if(icu==NULL) {
1829
2005
icu= MEM_callocN(sizeof(IpoCurve), "ipocurve");
1831
2007
icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
2008
if(ipo->curve.first==NULL) icu->flag |= IPO_ACTIVE; /* first one added active */
1832
2010
icu->blocktype= blocktype;
1833
2011
icu->adrcode= adrcode;
1835
2013
set_icu_vars(icu);
1837
2015
BLI_addtail( &(ipo->curve), icu);
2017
switch (GS(from->name)) {
2019
Sequence *seq= (Sequence *)from;
2021
update_seq_icu_rects(seq);
1844
void insert_vert_ipo(IpoCurve *icu, float x, float y)
1846
BezTriple *bezt, beztr, *newbezt;
2032
/* threshold for inserting keyframes - threshold here should be good enough for now, but should become userpref */
2033
#define BEZT_INSERT_THRESH 0.00001
2035
/* Binary search algorithm for finding where to insert BezTriple. (for use by insert_bezt_icu)
2036
* Returns the index to insert at (data already at that index will be offset if replace is 0)
2038
static int binarysearch_bezt_index (BezTriple array[], BezTriple *item, int arraylen, short *replace)
2040
int start=0, end=arraylen;
2041
int loopbreaker= 0, maxloop= arraylen * 2;
2042
const float frame= (item)? item->vec[1][0] : 0.0f;
2044
/* initialise replace-flag first */
2047
/* sneaky optimisations (don't go through searching process if...):
2048
* - keyframe to be added is to be added out of current bounds
2049
* - keyframe to be added would replace one of the existing ones on bounds
2051
if ((arraylen <= 0) || ELEM(NULL, array, item)) {
2052
printf("Warning: binarysearch_bezt_index encountered invalid array \n");
2056
/* check whether to add before/after/on */
2059
/* 'First' Keyframe (when only one keyframe, this case is used) */
2060
framenum= array[0].vec[1][0];
2061
if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH)) {
2065
else if (frame < framenum)
2068
/* 'Last' Keyframe */
2069
framenum= array[(arraylen-1)].vec[1][0];
2070
if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH)) {
2072
return (arraylen - 1);
2074
else if (frame > framenum)
2079
/* most of the time, this loop is just to find where to put it
2080
* 'loopbreaker' is just here to prevent infinite loops
2082
for (loopbreaker=0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) {
2083
/* compute and get midpoint */
2084
int mid = (start + end) / 2;
2085
float midfra= array[mid].vec[1][0];
2087
/* check if exactly equal to midpoint */
2088
if (IS_EQT(frame, midfra, BEZT_INSERT_THRESH)) {
2093
/* repeat in upper/lower half */
2096
else if (frame < midfra)
2100
/* print error if loop-limit exceeded */
2101
if (loopbreaker == (maxloop-1)) {
2102
printf("Error: binarysearch_bezt_index was taking too long \n");
2104
// include debug info
2105
printf("\tround = %d: start = %d, end = %d, arraylen = %d \n", loopbreaker, start, end, arraylen);
2108
/* not found, so return where to place it */
2112
/* This function adds a given BezTriple to an IPO-Curve. It will allocate
2113
* memory for the array if needed, and will insert the BezTriple into a
2114
* suitable place in chronological order.
2116
* NOTE: any recalculate of the IPO-Curve that needs to be done will need to
2117
* be done by the caller.
2119
int insert_bezt_icu (IpoCurve *icu, BezTriple *bezt)
2124
if (icu->bezt == NULL) {
2125
icu->bezt= MEM_callocN(sizeof(BezTriple), "beztriple");
2126
*(icu->bezt)= *bezt;
2131
i = binarysearch_bezt_index(icu->bezt, bezt, icu->totvert, &replace);
2134
/* sanity check: 'i' may in rare cases exceed arraylen */
2135
if ((i >= 0) && (i < icu->totvert))
2136
*(icu->bezt + i) = *bezt;
2140
newb= MEM_callocN((icu->totvert+1)*sizeof(BezTriple), "beztriple");
2142
/* add the beztriples that should occur before the beztriple to be pasted (originally in ei->icu) */
2144
memcpy(newb, icu->bezt, i*sizeof(BezTriple));
2146
/* add beztriple to paste at index i */
2149
/* add the beztriples that occur after the beztriple to be pasted (originally in icu) */
2150
if (i < icu->totvert)
2151
memcpy(newb+i+1, icu->bezt+i, (icu->totvert-i)*sizeof(BezTriple));
2153
/* replace (+ free) old with new */
2154
MEM_freeN(icu->bezt);
2161
/* we need to return the index, so that some tools which do post-processing can
2162
* detect where we added the BezTriple in the array
2167
/* This function is a wrapper for insert_bezt_icu, and should be used when
2168
* adding a new keyframe to a curve, when the keyframe doesn't exist anywhere
2171
* 'fast' - is only for the python API where importing BVH's would take an extreamly long time.
2173
void insert_vert_icu (IpoCurve *icu, float x, float y, short fast)
2178
/* set all three points, for nicer start position */
1849
2179
memset(&beztr, 0, sizeof(BezTriple));
1850
beztr.vec[0][0]= x; // set all three points, for nicer start position
1851
2181
beztr.vec[0][1]= y;
1852
2182
beztr.vec[1][0]= x;
1853
2183
beztr.vec[1][1]= y;
1983
void insertkey(ID *id, int blocktype, char *actname, char *constname, int adrcode)
1991
icu= verify_ipocurve(id, blocktype, actname, constname, adrcode);
2320
#define KEYNEEDED_DONTADD 0
2321
#define KEYNEEDED_JUSTADD 1
2322
#define KEYNEEDED_DELPREV 2
2323
#define KEYNEEDED_DELNEXT 3
2325
static int new_key_needed(IpoCurve *icu, float cFrame, float nValue)
2327
/* This function determines whether a new keyframe is needed */
2328
/* Cases where keyframes should not be added:
2329
* 1. Keyframe to be added bewteen two keyframes with similar values
2330
* 2. Keyframe to be added on frame where two keyframes are already situated
2331
* 3. Keyframe lies at point that intersects the linear line between two keyframes
2334
BezTriple *bezt=NULL, *prev=NULL;
2336
float valA = 0.0f, valB = 0.0f;
2338
/* safety checking */
2339
if (!icu) return KEYNEEDED_JUSTADD;
2340
totCount= icu->totvert;
2341
if (totCount==0) return KEYNEEDED_JUSTADD;
2343
/* loop through checking if any are the same */
2345
for (i=0; i<totCount; i++) {
2346
float prevPosi=0.0f, prevVal=0.0f;
2347
float beztPosi=0.0f, beztVal=0.0f;
2349
/* get current time+value */
2350
beztPosi= bezt->vec[1][0];
2351
beztVal= bezt->vec[1][1];
2354
/* there is a keyframe before the one currently being examined */
2356
/* get previous time+value */
2357
prevPosi= prev->vec[1][0];
2358
prevVal= prev->vec[1][1];
2360
/* keyframe to be added at point where there are already two similar points? */
2361
if (IS_EQ(prevPosi, cFrame) && IS_EQ(beztPosi, cFrame) && IS_EQ(beztPosi, prevPosi)) {
2362
return KEYNEEDED_DONTADD;
2365
/* keyframe between prev+current points ? */
2366
if ((prevPosi <= cFrame) && (cFrame <= beztPosi)) {
2367
/* is the value of keyframe to be added the same as keyframes on either side ? */
2368
if (IS_EQ(prevVal, nValue) && IS_EQ(beztVal, nValue) && IS_EQ(prevVal, beztVal)) {
2369
return KEYNEEDED_DONTADD;
2374
/* get real value of curve at that point */
2375
realVal= eval_icu(icu, cFrame);
2377
/* compare whether it's the same as proposed */
2378
if (IS_EQ(realVal, nValue))
2379
return KEYNEEDED_DONTADD;
2381
return KEYNEEDED_JUSTADD;
2385
/* new keyframe before prev beztriple? */
2386
if (cFrame < prevPosi) {
2387
/* A new keyframe will be added. However, whether the previous beztriple
2388
* stays around or not depends on whether the values of previous/current
2389
* beztriples and new keyframe are the same.
2391
if (IS_EQ(prevVal, nValue) && IS_EQ(beztVal, nValue) && IS_EQ(prevVal, beztVal))
2392
return KEYNEEDED_DELNEXT;
2394
return KEYNEEDED_JUSTADD;
2398
/* just add a keyframe if there's only one keyframe
2399
* and the new one occurs before the exisiting one does.
2401
if ((cFrame < beztPosi) && (totCount==1))
2402
return KEYNEEDED_JUSTADD;
2405
/* continue. frame to do not yet passed (or other conditions not met) */
2406
if (i < (totCount-1)) {
2414
/* Frame in which to add a new-keyframe occurs after all other keys
2415
* -> If there are at least two existing keyframes, then if the values of the
2416
* last two keyframes and the new-keyframe match, the last existing keyframe
2417
* gets deleted as it is no longer required.
2418
* -> Otherwise, a keyframe is just added. 1.0 is added so that fake-2nd-to-last
2419
* keyframe is not equal to last keyframe.
2421
bezt= (icu->bezt + (icu->totvert - 1));
2422
valA= bezt->vec[1][1];
2425
valB= prev->vec[1][1];
2427
valB= bezt->vec[1][1] + 1.0f;
2429
if (IS_EQ(valA, nValue) && IS_EQ(valA, valB))
2430
return KEYNEEDED_DELPREV;
2432
return KEYNEEDED_JUSTADD;
2435
/* a duplicate of insertkey that does not check for routing to insertmatrixkey
2436
to avoid recursion problems */
2437
static void insertkey_nonrecurs(ID *id, int blocktype, char *actname, char *constname, int adrcode)
2447
icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
2451
poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
2454
curval= read_ipo_poin(poin, vartype);
2456
cfra= frame_to_float(CFRA);
2458
/* if action is mapped in NLA, it returns a correction */
2459
if(actname && actname[0] && GS(id->name)==ID_OB)
2460
cfra= get_action_frame((Object *)id, cfra);
2462
if( GS(id->name)==ID_OB ) {
2464
if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
2465
/* actually frametofloat calc again! */
2466
cfra-= give_timeoffset(ob)*G.scene->r.framelen;
2470
insert_vert_icu(icu, cfra, curval, 0);
2476
int insertmatrixkey(ID *id, int blocktype, char *actname, char *constname, int adrcode)
2479
/* branch on adrcode and blocktype, generating the proper matrix-based
2480
values to send to insertfloatkey */
2481
if (GS(id->name)==ID_OB) {
2482
Object *ob= (Object *)id;
2484
if ( blocktype==ID_OB ){ //working with an object
2485
if ((ob)&&!(ob->parent)) {
2486
if ((adrcode==OB_ROT_X)||(adrcode==OB_ROT_Y)||(adrcode==OB_ROT_Z)) { //get a rotation
2499
Mat4ToEul(ob->obmat, eul);
2500
insertfloatkey(id, ID_OB, actname, NULL, adrcode, eul[matindex]*(5.72958));
2502
} else if ((adrcode==OB_LOC_X)||(adrcode==OB_LOC_Y)||(adrcode==OB_LOC_Z)) {//get a translation
2514
insertfloatkey(id, ID_OB, actname, NULL, adrcode, ob->obmat[3][matindex]);
2518
} else if ( blocktype==ID_PO) { //working with a pose channel
2519
bPoseChannel *pchan= get_pose_channel(ob->pose, actname);
2521
if ((adrcode==AC_LOC_X)||(adrcode==AC_LOC_Y)||(adrcode==AC_LOC_Z)) {
2533
if (!(pchan->bone->parent)||((pchan->bone->parent)&&!(pchan->bone->flag&BONE_CONNECTED))) { /* don't use for non-connected child bones */
2534
float delta_mat[4][4];
2535
armature_mat_pose_to_delta(delta_mat, pchan->pose_mat, pchan->bone->arm_mat);
2536
insertfloatkey(id, ID_PO, pchan->name, NULL, adrcode, delta_mat[3][matindex]);
2539
} else if ((adrcode==AC_QUAT_W)||(adrcode==AC_QUAT_X)||(adrcode==AC_QUAT_Y)||(adrcode==AC_QUAT_Z)) {
2540
float tmat[4][4], trimat[3][3], localQuat[4];
2557
/* it should be reasonable to assume that we are keyframing on the active object, although it is not
2558
* strictly required for this particular space conversion, arg1 must not be null for this to work
2560
Mat4CpyMat4(tmat, pchan->pose_mat);
2561
constraint_mat_convertspace(OBACT, pchan, tmat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL);
2563
Mat3CpyMat4(trimat, tmat);
2564
Mat3ToQuat_is_ok(trimat, localQuat);
2565
insertfloatkey(id, ID_PO, pchan->name, NULL, adrcode, localQuat[matindex]);
2572
/* failed to set a matrix key -- use traditional, but the non-recursing version */
2573
insertkey_nonrecurs(id,blocktype,actname,constname,adrcode);
2577
static int match_adr_constraint(ID * id, int blocktype, char *actname, int adrcode)
2578
{ /* This function matches constraint blocks with adrcodes to see if the
2579
visual keying method should be used. For example, an object looking to key
2580
location and having a CopyLoc constraint would return true. */
2585
bConstraint *conref=NULL, *con=NULL;
2587
/*Retrieve constraint list*/
2588
if( GS(id->name)==ID_OB )
2591
if (blocktype==ID_PO) {
2592
bPoseChannel *pchan= get_pose_channel(ob->pose, actname);
2593
conref=pchan->constraints.first;
2594
} else if (blocktype==ID_OB) {
2595
conref=ob->constraints.first;
2599
/*Set search type: 1 is for translation contraints, 2 is for rotation*/
2600
if ((adrcode==OB_LOC_X)||(adrcode==OB_LOC_Y)||(adrcode==OB_LOC_Z)||(adrcode==AC_LOC_X)||(adrcode==AC_LOC_Y)||(adrcode==AC_LOC_Z)) {
2602
} else if ((adrcode==OB_ROT_X)||(adrcode==OB_ROT_Y)||(adrcode==OB_ROT_Z)||(adrcode==AC_QUAT_W)||(adrcode==AC_QUAT_X)||(adrcode==AC_QUAT_Y)||(adrcode==AC_QUAT_Z)) {
2607
for (con=conref; (con)&&(foundmatch==0); con=con->next) {
2608
switch (con->type) {
2609
/* match constraint types to which kinds of keying they would affect */
2610
case CONSTRAINT_TYPE_CHILDOF:
2613
case CONSTRAINT_TYPE_TRACKTO:
2614
if (searchtype==2) foundmatch=1;
2616
case CONSTRAINT_TYPE_FOLLOWPATH:
2619
case CONSTRAINT_TYPE_ROTLIMIT:
2620
if (searchtype==2) foundmatch=1;
2622
case CONSTRAINT_TYPE_LOCLIMIT:
2623
if (searchtype==1) foundmatch=1;
2625
case CONSTRAINT_TYPE_ROTLIKE:
2626
if (searchtype==2) foundmatch=1;
2628
case CONSTRAINT_TYPE_LOCLIKE:
2629
if (searchtype==1) foundmatch=1;
2631
case CONSTRAINT_TYPE_LOCKTRACK:
2632
if (searchtype==2) foundmatch=1;
2634
case CONSTRAINT_TYPE_DISTLIMIT:
2635
if (searchtype==1) foundmatch=1;
2637
case CONSTRAINT_TYPE_MINMAX:
2638
if (searchtype==1) foundmatch=1;
2640
case CONSTRAINT_TYPE_TRANSFORM:
2655
void insertkey(ID *id, int blocktype, char *actname, char *constname, int adrcode, short fast)
2664
if ((IS_AUTOKEY_FLAG(AUTOMATKEY))&&(match_adr_constraint(id, blocktype, actname, adrcode))) {
2665
matset=insertmatrixkey(id, blocktype, actname, constname, adrcode);
2668
icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
2672
poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
2675
curval= read_ipo_poin(poin, vartype);
2677
cfra= frame_to_float(CFRA);
2679
/* if action is mapped in NLA, it returns a correction */
2680
if(actname && actname[0] && GS(id->name)==ID_OB)
2681
cfra= get_action_frame((Object *)id, cfra);
2683
if( GS(id->name)==ID_OB ) {
2685
if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
2686
/* actually frametofloat calc again! */
2687
cfra-= give_timeoffset(ob)*G.scene->r.framelen;
2691
insert_vert_icu(icu, cfra, curval, fast);
2699
/* This function is a 'smarter' version of the insert key code.
2700
* It uses an auxilliary function to check whether a keyframe is really needed */
2701
void insertkey_smarter(ID *id, int blocktype, char *actname, char *constname, int adrcode)
2710
icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
1995
poin= get_context_ipo_poin(id, blocktype, actname, icu, &vartype);
2714
poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
1998
2717
curval= read_ipo_poin(poin, vartype);
2209
2952
map= texchannel_to_adrcode(ma->texact);
2211
2954
if(event==0 || event==10) {
2212
insertkey(id, ID_MA, NULL, NULL, MA_COL_R);
2213
insertkey(id, ID_MA, NULL, NULL, MA_COL_G);
2214
insertkey(id, ID_MA, NULL, NULL, MA_COL_B);
2955
insertkey(id, ID_MA, NULL, NULL, MA_COL_R, 0);
2956
insertkey(id, ID_MA, NULL, NULL, MA_COL_G, 0);
2957
insertkey(id, ID_MA, NULL, NULL, MA_COL_B, 0);
2216
2959
if(event==1 || event==10) {
2217
insertkey(id, ID_MA, NULL, NULL, MA_ALPHA);
2960
insertkey(id, ID_MA, NULL, NULL, MA_ALPHA, 0);
2219
2962
if(event==2 || event==10) {
2220
insertkey(id, ID_MA, NULL, NULL, MA_HASIZE);
2963
insertkey(id, ID_MA, NULL, NULL, MA_HASIZE, 0);
2222
2965
if(event==3 || event==10) {
2223
insertkey(id, ID_MA, NULL, NULL, MA_MODE);
2966
insertkey(id, ID_MA, NULL, NULL, MA_MODE, 0);
2225
2968
if(event==10) {
2226
insertkey(id, ID_MA, NULL, NULL, MA_SPEC_R);
2227
insertkey(id, ID_MA, NULL, NULL, MA_SPEC_G);
2228
insertkey(id, ID_MA, NULL, NULL, MA_SPEC_B);
2229
insertkey(id, ID_MA, NULL, NULL, MA_REF);
2230
insertkey(id, ID_MA, NULL, NULL, MA_EMIT);
2231
insertkey(id, ID_MA, NULL, NULL, MA_AMB);
2232
insertkey(id, ID_MA, NULL, NULL, MA_SPEC);
2233
insertkey(id, ID_MA, NULL, NULL, MA_HARD);
2234
insertkey(id, ID_MA, NULL, NULL, MA_MODE);
2235
insertkey(id, ID_MA, NULL, NULL, MA_TRANSLU);
2236
insertkey(id, ID_MA, NULL, NULL, MA_ADD);
2969
insertkey(id, ID_MA, NULL, NULL, MA_SPEC_R, 0);
2970
insertkey(id, ID_MA, NULL, NULL, MA_SPEC_G, 0);
2971
insertkey(id, ID_MA, NULL, NULL, MA_SPEC_B, 0);
2972
insertkey(id, ID_MA, NULL, NULL, MA_REF, 0);
2973
insertkey(id, ID_MA, NULL, NULL, MA_EMIT, 0);
2974
insertkey(id, ID_MA, NULL, NULL, MA_AMB, 0);
2975
insertkey(id, ID_MA, NULL, NULL, MA_SPEC, 0);
2976
insertkey(id, ID_MA, NULL, NULL, MA_HARD, 0);
2977
insertkey(id, ID_MA, NULL, NULL, MA_MODE, 0);
2978
insertkey(id, ID_MA, NULL, NULL, MA_TRANSLU, 0);
2979
insertkey(id, ID_MA, NULL, NULL, MA_ADD, 0);
2238
2981
if(event==14) {
2239
insertkey(id, ID_MA, NULL, NULL, MA_RAYM);
2240
insertkey(id, ID_MA, NULL, NULL, MA_FRESMIR);
2241
insertkey(id, ID_MA, NULL, NULL, MA_FRESMIRI);
2242
insertkey(id, ID_MA, NULL, NULL, MA_FRESTRA);
2243
insertkey(id, ID_MA, NULL, NULL, MA_FRESTRAI);
2982
insertkey(id, ID_MA, NULL, NULL, MA_RAYM, 0);
2983
insertkey(id, ID_MA, NULL, NULL, MA_FRESMIR, 0);
2984
insertkey(id, ID_MA, NULL, NULL, MA_FRESMIRI, 0);
2985
insertkey(id, ID_MA, NULL, NULL, MA_FRESTRA, 0);
2986
insertkey(id, ID_MA, NULL, NULL, MA_FRESTRAI, 0);
2245
2988
if(event==12 || event==11) {
2246
insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_X);
2247
insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Y);
2248
insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Z);
2989
insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_X, 0);
2990
insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Y, 0);
2991
insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Z, 0);
2250
2993
if(event==13 || event==11) {
2251
insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_X);
2252
insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Y);
2253
insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Z);
2994
insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_X, 0);
2995
insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Y, 0);
2996
insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Z, 0);
2255
2998
if(event==11) {
2256
insertkey(id, ID_MA, NULL, NULL, map+MAP_R);
2257
insertkey(id, ID_MA, NULL, NULL, map+MAP_G);
2258
insertkey(id, ID_MA, NULL, NULL, map+MAP_B);
2259
insertkey(id, ID_MA, NULL, NULL, map+MAP_DVAR);
2260
insertkey(id, ID_MA, NULL, NULL, map+MAP_COLF);
2261
insertkey(id, ID_MA, NULL, NULL, map+MAP_NORF);
2262
insertkey(id, ID_MA, NULL, NULL, map+MAP_VARF);
2263
insertkey(id, ID_MA, NULL, NULL, map+MAP_DISP);
2999
insertkey(id, ID_MA, NULL, NULL, map+MAP_R, 0);
3000
insertkey(id, ID_MA, NULL, NULL, map+MAP_G, 0);
3001
insertkey(id, ID_MA, NULL, NULL, map+MAP_B, 0);
3002
insertkey(id, ID_MA, NULL, NULL, map+MAP_DVAR, 0);
3003
insertkey(id, ID_MA, NULL, NULL, map+MAP_COLF, 0);
3004
insertkey(id, ID_MA, NULL, NULL, map+MAP_NORF, 0);
3005
insertkey(id, ID_MA, NULL, NULL, map+MAP_VARF, 0);
3006
insertkey(id, ID_MA, NULL, NULL, map+MAP_DISP, 0);
2274
3017
map= texchannel_to_adrcode(wo->texact);
2277
insertkey(id, ID_WO, NULL, NULL, WO_ZEN_R);
2278
insertkey(id, ID_WO, NULL, NULL, WO_ZEN_G);
2279
insertkey(id, ID_WO, NULL, NULL, WO_ZEN_B);
3020
insertkey(id, ID_WO, NULL, NULL, WO_ZEN_R, 0);
3021
insertkey(id, ID_WO, NULL, NULL, WO_ZEN_G, 0);
3022
insertkey(id, ID_WO, NULL, NULL, WO_ZEN_B, 0);
2282
insertkey(id, ID_WO, NULL, NULL, WO_HOR_R);
2283
insertkey(id, ID_WO, NULL, NULL, WO_HOR_G);
2284
insertkey(id, ID_WO, NULL, NULL, WO_HOR_B);
3025
insertkey(id, ID_WO, NULL, NULL, WO_HOR_R, 0);
3026
insertkey(id, ID_WO, NULL, NULL, WO_HOR_G, 0);
3027
insertkey(id, ID_WO, NULL, NULL, WO_HOR_B, 0);
2287
insertkey(id, ID_WO, NULL, NULL, WO_MISI);
2288
insertkey(id, ID_WO, NULL, NULL, WO_MISTDI);
2289
insertkey(id, ID_WO, NULL, NULL, WO_MISTSTA);
2290
insertkey(id, ID_WO, NULL, NULL, WO_MISTHI);
3030
insertkey(id, ID_WO, NULL, NULL, WO_MISI, 0);
3031
insertkey(id, ID_WO, NULL, NULL, WO_MISTDI, 0);
3032
insertkey(id, ID_WO, NULL, NULL, WO_MISTSTA, 0);
3033
insertkey(id, ID_WO, NULL, NULL, WO_MISTHI, 0);
2293
insertkey(id, ID_WO, NULL, NULL, WO_STAR_R);
2294
insertkey(id, ID_WO, NULL, NULL, WO_STAR_G);
2295
insertkey(id, ID_WO, NULL, NULL, WO_STAR_B);
2296
insertkey(id, ID_WO, NULL, NULL, WO_STARDIST);
2297
insertkey(id, ID_WO, NULL, NULL, WO_STARSIZE);
3036
insertkey(id, ID_WO, NULL, NULL, WO_STAR_R, 0);
3037
insertkey(id, ID_WO, NULL, NULL, WO_STAR_G, 0);
3038
insertkey(id, ID_WO, NULL, NULL, WO_STAR_B, 0);
3039
insertkey(id, ID_WO, NULL, NULL, WO_STARDIST, 0);
3040
insertkey(id, ID_WO, NULL, NULL, WO_STARSIZE, 0);
2299
3042
if(event==12) {
2300
insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_X);
2301
insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Y);
2302
insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Z);
3043
insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_X, 0);
3044
insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Y, 0);
3045
insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Z, 0);
2304
3047
if(event==13) {
2305
insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_X);
2306
insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Y);
2307
insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Z);
3048
insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_X, 0);
3049
insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Y, 0);
3050
insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Z, 0);
2345
3088
id= G.buts->lockpoin;
2346
3089
te= G.buts->lockpoin;
2348
event= pupmenu("Insert Key %t|Cloud%x0|Mable%x1|Stucci%x2|Wood%x3|Magic%x4|Blend%x5|Musgrave%x6|Voronoi%x7|Distnoise%x8|ColourFilter%x9");
3091
event= pupmenu("Insert Key %t|Clouds%x0|Marble%x1|Stucci%x2|Wood%x3|Magic%x4|Blend%x5|Musgrave%x6|Voronoi%x7|DistortedNoise%x8|ColorFilter%x9");
2349
3092
if(event== -1) return;
2352
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2353
insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH);
2354
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2355
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2356
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
3095
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
3096
insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH, 0);
3097
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
3098
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
3099
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
2359
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2360
insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH);
2361
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2362
insertkey(id, ID_TE, NULL, NULL, TE_TURB);
2363
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2364
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
2365
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2);
3102
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
3103
insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH, 0);
3104
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
3105
insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
3106
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
3107
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
3108
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2, 0);
2368
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2369
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2370
insertkey(id, ID_TE, NULL, NULL, TE_TURB);
2371
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2372
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
3111
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
3112
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
3113
insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
3114
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
3115
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
2375
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2376
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2377
insertkey(id, ID_TE, NULL, NULL, TE_TURB);
2378
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2379
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
2380
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2);
3118
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
3119
insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
3120
insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
3121
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
3122
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
3123
insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2, 0);
2383
insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH);
2384
insertkey(id, ID_TE, NULL, NULL, TE_TURB);
3126
insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH, 0);
3127
insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
2387
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
3130
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
2390
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2391
insertkey(id, ID_TE, NULL, NULL, TE_MGH);
2392
insertkey(id, ID_TE, NULL, NULL, TE_MG_LAC);
2393
insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT);
2394
insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF);
2395
insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN);
3133
insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
3134
insertkey(id, ID_TE, NULL, NULL, TE_MGH, 0);
3135
insertkey(id, ID_TE, NULL, NULL, TE_MG_LAC, 0);
3136
insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT, 0);
3137
insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF, 0);
3138
insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN, 0);
2398
insertkey(id, ID_TE, NULL, NULL, TE_VNW1);
2399
insertkey(id, ID_TE, NULL, NULL, TE_VNW2);
2400
insertkey(id, ID_TE, NULL, NULL, TE_VNW3);
2401
insertkey(id, ID_TE, NULL, NULL, TE_VNW4);
2402
insertkey(id, ID_TE, NULL, NULL, TE_VNMEXP);
2403
insertkey(id, ID_TE, NULL, NULL, TE_VN_DISTM);
2404
insertkey(id, ID_TE, NULL, NULL, TE_VN_COLT);
2405
insertkey(id, ID_TE, NULL, NULL, TE_ISCA);
2406
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
3141
insertkey(id, ID_TE, NULL, NULL, TE_VNW1, 0);
3142
insertkey(id, ID_TE, NULL, NULL, TE_VNW2, 0);
3143
insertkey(id, ID_TE, NULL, NULL, TE_VNW3, 0);
3144
insertkey(id, ID_TE, NULL, NULL, TE_VNW4, 0);
3145
insertkey(id, ID_TE, NULL, NULL, TE_VNMEXP, 0);
3146
insertkey(id, ID_TE, NULL, NULL, TE_VN_DISTM, 0);
3147
insertkey(id, ID_TE, NULL, NULL, TE_VN_COLT, 0);
3148
insertkey(id, ID_TE, NULL, NULL, TE_ISCA, 0);
3149
insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
2409
insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT);
2410
insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF);
2411
insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN);
2412
insertkey(id, ID_TE, NULL, NULL, TE_DISTA);
3152
insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT, 0);
3153
insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF, 0);
3154
insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN, 0);
3155
insertkey(id, ID_TE, NULL, NULL, TE_DISTA, 0);
2415
insertkey(id, ID_TE, NULL, NULL, TE_COL_R);
2416
insertkey(id, ID_TE, NULL, NULL, TE_COL_G);
2417
insertkey(id, ID_TE, NULL, NULL, TE_COL_B);
2418
insertkey(id, ID_TE, NULL, NULL, TE_BRIGHT);
2419
insertkey(id, ID_TE, NULL, NULL, TE_CONTRA);
3158
insertkey(id, ID_TE, NULL, NULL, TE_COL_R, 0);
3159
insertkey(id, ID_TE, NULL, NULL, TE_COL_G, 0);
3160
insertkey(id, ID_TE, NULL, NULL, TE_COL_B, 0);
3161
insertkey(id, ID_TE, NULL, NULL, TE_BRIGHT, 0);
3162
insertkey(id, ID_TE, NULL, NULL, TE_CONTRA, 0);
2424
3167
else if(G.buts->mainb==CONTEXT_OBJECT) {
2426
if(ob && ob->type==OB_MESH) {
2427
3170
id= (ID *) (ob);
2429
event= pupmenu("Insert Key %t|Surface Damping%x0|Random Damping%x1|Permeability%x2|Force Strength%x3|Force Falloff%x4");
2430
if(event== -1) return;
3172
if(ob->type==OB_MESH)
3173
event= pupmenu("Insert Key %t|Surface Damping%x0|Random Damping%x1|Permeability%x2|Force Strength%x3|Force Falloff%x4");
3175
event= pupmenu("Insert Key %t|Force Strength%x3|Force Falloff%x4");
3176
if(event == -1) return;
2433
insertkey(id, ID_OB, NULL, NULL, OB_PD_SDAMP);
3179
insertkey(id, ID_OB, NULL, NULL, OB_PD_SDAMP, 0);
2436
insertkey(id, ID_OB, NULL, NULL, OB_PD_RDAMP);
3182
insertkey(id, ID_OB, NULL, NULL, OB_PD_RDAMP, 0);
2439
insertkey(id, ID_OB, NULL, NULL, OB_PD_PERM);
3185
insertkey(id, ID_OB, NULL, NULL, OB_PD_PERM, 0);
2442
insertkey(id, ID_OB, NULL, NULL, OB_PD_FSTR);
3188
insertkey(id, ID_OB, NULL, NULL, OB_PD_FSTR, 0);
2445
insertkey(id, ID_OB, NULL, NULL, OB_PD_FFALL);
3191
insertkey(id, ID_OB, NULL, NULL, OB_PD_FFALL, 0);
3194
insertkey(id, ID_OB, NULL, NULL, OB_PD_FMAXD, 0);
2541
3301
if (ob && (ob->flag & OB_POSEMODE)){
2542
3302
bPoseChannel *pchan;
3303
short recalc_bonepaths= 0;
2544
3305
if (ob->action && ob->action->id.lib) {
2545
3306
error ("Can't key libactions");
2549
set_pose_keys(ob); // sets pchan->flag to POSE_KEY if bone selected
2551
3311
for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
2552
if (pchan->flag & POSE_KEY){
3312
if (pchan->flag & POSE_KEY) {
3313
/* insert relevant keyframes */
2553
3314
if(event==0 || event==3 ||event==4) {
2554
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X);
2555
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y);
2556
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z);
3315
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0);
3316
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0);
3317
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0);
2558
if(event==1 || event==3 ||event==4) {
2559
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X);
2560
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y);
2561
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z);
2562
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W);
3319
if(event==1 || event==3 || event==4) {
3320
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0);
3321
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0);
3322
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0);
3323
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0);
2564
3325
if(event==2 || event==4) {
2565
insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X);
2566
insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y);
2567
insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z);
3326
insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X, 0);
3327
insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y, 0);
3328
insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z, 0);
2569
3330
if (event==9 && ob->action) {
2570
3331
bActionChannel *achan;
2572
3333
for (achan = ob->action->chanbase.first; achan; achan=achan->next){
2573
3334
if (achan->ipo && !strcmp (achan->name, pchan->name)){
2574
3335
for (icu = achan->ipo->curve.first; icu; icu=icu->next){
2575
insertkey(id, ID_PO, achan->name, NULL, icu->adrcode);
3336
insertkey(id, ID_PO, achan->name, NULL, icu->adrcode, 0);
2581
3342
if(event==11 || event==13) {
2582
float obSpaceBoneMat[4][4];
2584
bone2objectspace(obSpaceBoneMat, pchan->pose_mat, pchan->bone->arm_mat);
2585
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, obSpaceBoneMat[3][0]);
2586
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, obSpaceBoneMat[3][1]);
2587
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, obSpaceBoneMat[3][2]);
3344
/* check one to make sure we're not trying to set visual loc keys on
3345
bones inside of a chain, which only leads to tears. */
3346
matok= insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_X);
3347
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y);
3348
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z);
3351
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0);
3352
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0);
3353
insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0);
2589
3356
if(event==12 || event==13) {
2590
float obSpaceBoneMat[4][4];
2593
bone2objectspace(obSpaceBoneMat, pchan->pose_mat, pchan->bone->arm_mat);
2594
Mat4ToQuat(obSpaceBoneMat, localQuat);
2595
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, localQuat[0]);
2596
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, localQuat[1]);
2597
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, localQuat[2]);
2598
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, localQuat[2]);
3358
/* check one to make sure we're not trying to set visual rot keys on
3359
bones inside of a chain, which only leads to tears. */
3360
matok= insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W);
3361
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X);
3362
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y);
3363
insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z);
3366
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0);
3367
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0);
3368
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0);
3369
insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0);
3372
if (event==15 && ob->action) {
3373
bActionChannel *achan;
3375
for (achan = ob->action->chanbase.first; achan; achan=achan->next){
3376
if (achan->ipo && !strcmp (achan->name, pchan->name)){
3377
for (icu = achan->ipo->curve.first; icu; icu=icu->next){
3378
insertkey_smarter(id, ID_PO, achan->name, NULL, icu->adrcode);
3385
/* clear unkeyed flag (it doesn't matter if it's set or not) */
3387
pchan->bone->flag &= ~BONE_UNKEYED;
3389
/* check if bone has a path */
3391
recalc_bonepaths = 1;
3395
/* recalculate ipo handles, etc. */
2603
3397
remake_action_ipos(ob->action);
3399
/* recalculate bone-paths on adding new keyframe? */
3400
// TODO: currently, there is no setting to turn this on/off globally
3401
if (recalc_bonepaths)
3402
pose_recalculate_paths(ob);
2605
3405
allqueue(REDRAWIPO, 0);
2606
3406
allqueue(REDRAWACTION, 0);
2607
3407
allqueue(REDRAWNLA, 0);
2610
3410
base= FIRSTBASE;
2612
if TESTBASELIB(base) {
3412
if (TESTBASELIB(base)) {
2613
3413
char *actname= NULL;
2615
3415
id= (ID *)(base->object);
2617
if(ob->ipoflag & OB_ACTION_OB)
3417
if(base->object->ipoflag & OB_ACTION_OB)
2618
3418
actname= "Object";
2620
3420
/* all curves in ipo deselect */
2621
if(base->object->ipo) {
2622
icu= base->object->ipo->curve.first;
3421
if(base->object->ipo || base->object->action) {
3422
if (base->object->ipo) {
3423
icu= base->object->ipo->curve.first;
3426
bActionChannel *achan;
3427
achan= get_action_channel(base->object->action, actname);
3429
if (achan && achan->ipo)
3430
icu= achan->ipo->curve.first;
2624
3436
icu->flag &= ~IPO_SELECT;
2625
if(event==9) insertkey(id, ID_OB, actname, NULL, icu->adrcode);
3440
insertkey(id, ID_OB, actname, NULL, icu->adrcode, 0);
3443
insertkey_smarter(id, ID_OB, actname, NULL, icu->adrcode);
2626
3446
icu= icu->next;
2630
3450
if(event==0 || event==3 ||event==4) {
2631
insertkey(id, ID_OB, actname, NULL, OB_LOC_X);
2632
insertkey(id, ID_OB, actname, NULL, OB_LOC_Y);
2633
insertkey(id, ID_OB, actname, NULL, OB_LOC_Z);
3451
insertkey(id, ID_OB, actname, NULL, OB_LOC_X, 0);
3452
insertkey(id, ID_OB, actname, NULL, OB_LOC_Y, 0);
3453
insertkey(id, ID_OB, actname, NULL, OB_LOC_Z, 0);
2635
3455
if(event==1 || event==3 ||event==4) {
2636
insertkey(id, ID_OB, actname, NULL, OB_ROT_X);
2637
insertkey(id, ID_OB, actname, NULL, OB_ROT_Y);
2638
insertkey(id, ID_OB, actname, NULL, OB_ROT_Z);
3456
insertkey(id, ID_OB, actname, NULL, OB_ROT_X, 0);
3457
insertkey(id, ID_OB, actname, NULL, OB_ROT_Y, 0);
3458
insertkey(id, ID_OB, actname, NULL, OB_ROT_Z, 0);
2640
3460
if(event==2 || event==4) {
2641
insertkey(id, ID_OB, actname, NULL, OB_SIZE_X);
2642
insertkey(id, ID_OB, actname, NULL, OB_SIZE_Y);
2643
insertkey(id, ID_OB, actname, NULL, OB_SIZE_Z);
3461
insertkey(id, ID_OB, actname, NULL, OB_SIZE_X, 0);
3462
insertkey(id, ID_OB, actname, NULL, OB_SIZE_Y, 0);
3463
insertkey(id, ID_OB, actname, NULL, OB_SIZE_Z, 0);
2646
3466
/* remove localview */
2647
3467
tlay= base->object->lay;
2648
3468
base->object->lay &= 0xFFFFFF;
2649
insertkey(id, ID_OB, actname, NULL, OB_LAY);
3469
insertkey(id, ID_OB, actname, NULL, OB_LAY, 0);
2650
3470
base->object->lay= tlay;
2652
3472
if(event==11 || event==13) {
2653
insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_X, ob->obmat[3][0]);
2654
insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Y, ob->obmat[3][1]);
2655
insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Z, ob->obmat[3][2]);
3473
insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_X);
3474
insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Y);
3475
insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Z);
2657
3477
if(event==12 || event==13) {
2661
Mat3CpyMat4(rotMat, ob->obmat);
2662
Mat3ToEul(rotMat, eul);
2663
insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_X, eul[0]*(5.72958));
2664
insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Y, eul[1]*(5.72958));
2665
insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Z, eul[2]*(5.72958));
3478
insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_X);
3479
insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Y);
3480
insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Z);
2667
3482
base->object->recalc |= OB_RECALC_OB;
2842
3661
deselectall_editipo();
3665
void clean_ipo(void)
3671
ok= fbutton(&G.scene->toolsettings->clean_thresh,
3672
0.0000001f, 1.0, 0.001, 0.1,
3676
get_status_editipo();
3678
ei= G.sipo->editipo;
3679
for(b=0; b<G.sipo->totipo; b++, ei++) {
3680
if (ISPOIN3(ei, flag & IPO_VISIBLE, icu, icu->bezt)) {
3683
if(G.sipo->showkey) ok= 1;
3684
else if(totipo_vert && (ei->flag & IPO_EDIT)) ok= 2;
3685
else if(totipo_vert==0 && (ei->flag & IPO_SELECT)) ok= 3;
3688
/* only clean if ok */
3689
clean_ipo_curve(ei->icu);
3694
editipo_changed(G.sipo, 1);
3695
BIF_undo_push("Clean IPO");
3698
void clean_ipo_curve(IpoCurve *icu)
3700
BezTriple *old_bezts, *bezt, *beztn;
3705
/* check if any points */
3706
if (icu == NULL || icu->totvert <= 1)
3709
/* get threshold for match-testing */
3710
thresh= G.scene->toolsettings->clean_thresh;
3712
/* make a copy of the old BezTriples, and clear IPO curve */
3713
old_bezts = icu->bezt;
3714
totCount = icu->totvert;
3718
/* now insert first keyframe, as it should be ok */
3720
insert_vert_icu(icu, bezt->vec[1][0], bezt->vec[1][1], 0);
3722
/* Loop through BezTriples, comparing them. Skip any that do
3723
* not fit the criteria for "ok" points.
3725
for (i=1; i<totCount; i++) {
3726
float prev[2], cur[2], next[2];
3728
/* get BezTriples and their values */
3729
if (i < (totCount - 1)) {
3730
beztn = (old_bezts + (i+1));
3731
next[0]= beztn->vec[1][0]; next[1]= beztn->vec[1][1];
3735
next[0] = next[1] = 0.0f;
3737
lastb= (icu->bezt + (icu->totvert - 1));
3738
bezt= (old_bezts + i);
3740
/* get references for quicker access */
3741
prev[0] = lastb->vec[1][0]; prev[1] = lastb->vec[1][1];
3742
cur[0] = bezt->vec[1][0]; cur[1] = bezt->vec[1][1];
3744
/* check if current bezt occurs at same time as last ok */
3745
if (IS_EQT(cur[0], prev[0], thresh)) {
3746
/* If there is a next beztriple, and if occurs at the same time, only insert
3747
* if there is a considerable distance between the points, and also if the
3748
* current is further away than the next one is to the previous.
3750
if (beztn && (IS_EQT(cur[0], next[0], thresh)) &&
3751
(IS_EQT(next[1], prev[1], thresh)==0))
3753
/* only add if current is further away from previous */
3754
if (cur[1] > next[1]) {
3755
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
3756
/* add new keyframe */
3757
insert_vert_icu(icu, cur[0], cur[1], 0);
3762
/* only add if values are a considerable distance apart */
3763
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
3764
/* add new keyframe */
3765
insert_vert_icu(icu, cur[0], cur[1], 0);
3770
/* checks required are dependent on whether this is last keyframe or not */
3772
/* does current have same value as previous and next? */
3773
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
3774
/* add new keyframe*/
3775
insert_vert_icu(icu, cur[0], cur[1], 0);
3777
else if (IS_EQT(cur[1], next[1], thresh) == 0) {
3778
/* add new keyframe */
3779
insert_vert_icu(icu, cur[0], cur[1], 0);
3783
/* add if value doesn't equal that of previous */
3784
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
3785
/* add new keyframe */
3786
insert_vert_icu(icu, cur[0], cur[1], 0);
3792
/* now free the memory used by the old BezTriples */
3794
MEM_freeN(old_bezts);
3798
/* temp struct used for smooth_ipo */
3799
typedef struct tSmooth_Bezt {
3800
float *h1, *h2, *h3; /* bezt->vec[0,1,2][1] */
3803
void smooth_ipo(void)
3809
get_status_editipo();
3811
ei= G.sipo->editipo;
3812
for(b=0; b<G.sipo->totipo; b++, ei++) {
3813
if (ISPOIN3(ei, flag & IPO_VISIBLE, icu, icu->bezt)) {
3815
if(G.sipo->showkey) ok= 1;
3816
else if(totipo_vert && (ei->flag & IPO_EDIT)) ok= 2;
3817
else if(totipo_vert==0 && (ei->flag & IPO_SELECT)) ok= 3;
3820
IpoCurve *icu= ei->icu;
3822
int i, x, totSel = 0;
3824
/* check if enough points */
3825
if (icu->totvert >= 3) {
3826
/* first loop through - count how many verts are selected, and fix up handles */
3828
for (i=0; i < icu->totvert; i++, bezt++) {
3829
if (BEZSELECTED(bezt)) {
3830
/* line point's handles up with point's vertical position */
3831
bezt->vec[0][1]= bezt->vec[2][1]= bezt->vec[1][1];
3832
if ((bezt->h1==HD_AUTO) || (bezt->h1==HD_VECT)) bezt->h1= HD_ALIGN;
3833
if ((bezt->h2==HD_AUTO) || (bezt->h2==HD_VECT)) bezt->h2= HD_ALIGN;
3835
/* add value to total */
3840
/* if any points were selected, allocate tSmooth_Bezt points to work on */
3842
tSmooth_Bezt *tarray, *tsb;
3844
/* allocate memory in one go */
3845
tsb= tarray= MEM_callocN(totSel*sizeof(tSmooth_Bezt), "tSmooth_Bezt Array");
3847
/* populate tarray with data of selected points */
3849
for (i=0, x=0; (i < icu->totvert) && (x < totSel); i++, bezt++) {
3850
if (BEZSELECTED(bezt)) {
3851
/* tsb simply needs pointer to vec, and index */
3852
tsb->h1 = &bezt->vec[0][1];
3853
tsb->h2 = &bezt->vec[1][1];
3854
tsb->h3 = &bezt->vec[2][1];
3856
/* advance to the next tsb to populate */
3864
/* calculate the new smoothed ipo's with weighted averages:
3865
* - this is done with two passes
3866
* - uses 5 points for each operation (which stores in the relevant handles)
3867
* - previous: w/a ratio = 3:5:2:1:1
3868
* - next: w/a ratio = 1:1:2:5:3
3871
/* round 1: calculate previous and next */
3873
for (i=0; i < totSel; i++, tsb++) {
3874
/* don't touch end points (otherwise, curves slowly explode) */
3875
if (ELEM(i, 0, (totSel-1)) == 0) {
3876
tSmooth_Bezt *tP1 = tsb - 1;
3877
tSmooth_Bezt *tP2 = (i-2 > 0) ? (tsb - 2) : (NULL);
3878
tSmooth_Bezt *tN1 = tsb + 1;
3879
tSmooth_Bezt *tN2 = (i+2 < totSel) ? (tsb + 2) : (NULL);
3881
float p1 = *tP1->h2;
3882
float p2 = (tP2) ? (*tP2->h2) : (*tP1->h2);
3883
float c1 = *tsb->h2;
3884
float n1 = *tN1->h2;
3885
float n2 = (tN2) ? (*tN2->h2) : (*tN1->h2);
3887
/* calculate previous and next */
3888
*tsb->h1= (3*p2 + 5*p1 + 2*c1 + n1 + n2) / 12;
3889
*tsb->h3= (p2 + p1 + 2*c1 + 5*n1 + 3*n2) / 12;
3893
/* round 2: calculate new values and reset handles */
3895
for (i=0; i < totSel; i++, tsb++) {
3896
/* calculate new position by averaging handles */
3897
*tsb->h2 = (*tsb->h1 + *tsb->h3) / 2;
3899
/* reset handles now */
3900
*tsb->h1 = *tsb->h2;
3901
*tsb->h3 = *tsb->h2;
3904
/* free memory required for tarray */
3909
/* recalculate handles */
3910
calchandles_ipocurve(icu);
3915
editipo_changed(G.sipo, 1);
3916
BIF_undo_push("Smooth IPO");
2845
3919
void join_ipo_menu(void)
3260
if(G.sipo->showkey) return;
3262
if(totipocopybuf==0) return;
3263
if(G.sipo->ipo==0) return;
3264
if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
4452
if (G.sipo->showkey) return;
4454
if (totipocopybuf==0) return;
4455
if (G.sipo->ipo==0) return;
4456
if (G.sipo->ipo && G.sipo->ipo->id.lib) return;
3266
4458
get_status_editipo();
4460
if (totipo_vis==0) {
3269
4461
error("No visible channels");
3271
else if(totipo_vis!=totipocopybuf && totipo_sel!=totipocopybuf) {
4464
else if (totipo_vis!=totipocopybuf && totipo_sel!=totipocopybuf) {
3272
4465
error("Incompatible paste");
3275
/* prevent problems: splines visible that are not selected */
3276
if(totipo_vis==totipo_sel) totipo_vis= 0;
3278
icu= ipocopybuf.first;
3281
ei= G.sipo->editipo;
3282
for(a=0; a<G.sipo->totipo; a++, ei++) {
3283
if(ei->flag & IPO_VISIBLE) {
3285
if(totipo_vis==totipocopybuf) ok= 1;
3286
if(totipo_sel==totipocopybuf && (ei->flag & IPO_SELECT)) ok= 1;
4469
icu= ipocopybuf.first;
4471
for (a=0, ei=G.sipo->editipo; a<G.sipo->totipo; a++, ei++) {
4472
if (ei->flag & IPO_VISIBLE) {
4473
/* don't attempt pasting if no valid buffer-curve to paste from anymore */
4474
if (icu == 0) return;
3290
ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, ei->adrcode);
3291
if(ei->icu==NULL) return;
3293
if(ei->icu->bezt) MEM_freeN(ei->icu->bezt);
3294
ei->icu->bezt= NULL;
3295
if(ei->icu->driver) MEM_freeN(ei->icu->driver);
3296
ei->icu->driver= NULL;
3298
ei->icu->totvert= icu->totvert;
3299
ei->icu->flag= ei->flag= icu->flag;
3300
ei->icu->extrap= icu->extrap;
3301
ei->icu->ipo= icu->ipo;
3304
ei->icu->bezt= MEM_dupallocN(icu->bezt);
3306
ei->icu->driver= MEM_dupallocN(icu->driver);
4476
/* if in editmode, paste keyframes */
4477
if (ei->flag & IPO_EDIT) {
4480
short offsetInit= 0;
4483
/* make sure an ipo-curve exists (it may not, as this is an editipo) */
4484
ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei->adrcode);
4485
if (ei->icu == NULL) return;
4487
/* Copy selected beztriples from source icu onto this edit-icu,
4488
* with all added keyframes being offsetted by the difference between
4489
* the first source keyframe and the current frame.
4491
for (i=0, bezt=icu->bezt; i < icu->totvert; i++, bezt++) {
4492
/* skip if not selected */
4493
if (BEZSELECTED(bezt) == 0) continue;
4495
/* initialise offset (if not already done) */
4496
if (offsetInit==0) {
4497
offset= CFRA - bezt->vec[1][0];
4500
/* temporarily apply offset to src beztriple while copying */
4501
bezt->vec[0][0] += offset;
4502
bezt->vec[1][0] += offset;
4503
bezt->vec[2][0] += offset;
4505
/* insert the keyframe */
4506
insert_bezt_icu(ei->icu, bezt);
4508
/* un-apply offset from src beztriple after copying */
4509
bezt->vec[0][0] -= offset;
4510
bezt->vec[1][0] -= offset;
4511
bezt->vec[2][0] -= offset;
4514
/* recalculate handles of curve that data was pasted into */
4515
calchandles_ipocurve(ei->icu);
4517
/* advance to next copy/paste buffer ipo-curve */
4521
/* otherwise paste entire curve data */
4524
/* make sure an ipo-curve exists (it may not, as this is an editipo) */
4525
ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei->adrcode);
4526
if (ei->icu==NULL) return;
4528
/* clear exisiting dynamic memory (keyframes, driver) */
4529
if (ei->icu->bezt) MEM_freeN(ei->icu->bezt);
4530
ei->icu->bezt= NULL;
4531
if (ei->icu->driver) MEM_freeN(ei->icu->driver);
4532
ei->icu->driver= NULL;
4534
ei->icu->totvert= icu->totvert;
4535
ei->icu->flag= ei->flag= icu->flag;
4536
ei->icu->extrap= icu->extrap;
4537
ei->icu->ipo= icu->ipo;
4539
/* make a copy of the source icu's data */
4541
ei->icu->bezt= MEM_dupallocN(icu->bezt);
4543
ei->icu->driver= MEM_dupallocN(icu->driver);
4545
/* advance to next copy/paste buffer ipo-curve */
3313
editipo_changed(G.sipo, 1);
3314
BIF_undo_push("Paste Ipo curves");
4551
editipo_changed(G.sipo, 1);
4552
BIF_undo_push("Paste Ipo curves");
3318
4555
/* *********************** */
3824
5090
/* **************************************************** */
3827
void remake_ipo_transverts(TransVert *transmain, float *dvec, int tot)
5091
/* IPO TRANSFORM TOOLS
5093
* Only the helper functions are stored here these days. They are here as
5094
* there are heaps of ugly globals which the IPO editor relies on.
5095
* However, the actual transforms go through the transform system these days.
5098
/* Helper function for make_ipo_transdata, which is reponsible for associating
5099
* source data with transform data
5101
static void bezt_to_transdata (TransData *td, TransData2D *td2d, float *loc, float *cent, short selected, short onlytime)
5103
/* New location from td gets dumped onto the old-location of td2d, which then
5104
* gets copied to the actual data at td2d->loc2d (bezt->vec[n])
5106
* Due to NLA scaling, we apply NLA scaling to some of the verts here,
5107
* and then that scaling will be undone after transform is done.
5110
if (NLA_IPO_SCALED) {
5111
td2d->loc[0] = get_action_frame_inv(OBACT, loc[0]);
5112
td2d->loc[1] = loc[1];
5113
td2d->loc[2] = 0.0f;
5116
/*td->flag = 0;*/ /* can be set beforehand, else make sure its set to 0 */
5117
td->loc = td2d->loc;
5118
td->center[0] = get_action_frame_inv(OBACT, cent[0]);
5119
td->center[1] = cent[1];
5120
td->center[2] = 0.0f;
5122
VECCOPY(td->iloc, td->loc);
5125
td2d->loc[0] = loc[0];
5126
td2d->loc[1] = loc[1];
5127
td2d->loc[2] = 0.0f;
5130
/*td->flag = 0;*/ /* can be set beforehand, else make sure its set to 0 */
5131
td->loc = td2d->loc;
5132
VECCOPY(td->center, cent);
5133
VECCOPY(td->iloc, td->loc);
5136
memset(td->axismtx, 0, sizeof(td->axismtx));
5137
td->axismtx[2][2] = 1.0f;
5139
td->ext= NULL; td->tdi= NULL; td->val= NULL;
5142
td->flag |= TD_SELECTED;
5149
td->flag |= TD_TIMEONLY;
5155
/* This function is called by createTransIpoData and remake_ipo_transdata to
5156
* create the TransData and TransData2D arrays for transform. The costly counting
5157
* stage is only performed for createTransIpoData case, and is indicated by t->total==-1;
5159
void make_ipo_transdata (TransInfo *t)
5161
TransData *td = NULL;
5162
TransData2D *td2d = NULL;
3831
5165
BezTriple *bezt;
5168
/* countsel and propmode are used for proportional edit, which is not yet available */
5169
int count=0/*, countsel=0*/;
5170
/*int propmode = t->flag & T_PROP_EDIT;*/
5172
/* count data and allocate memory (if needed) */
5173
if (t->total == 0) {
5174
/* count data first */
5175
if (totipo_vertsel) {
5176
/* we're probably in editmode, so only selected verts */
5177
count= totipo_vertsel;
5179
else if (totipo_edit==0 && totipo_sel!=0) {
5180
/* we're not in editmode, so entire curves get moved */
5181
ei= G.sipo->editipo;
5182
for (a=0; a<G.sipo->totipo; a++, ei++) {
5183
if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
5184
if (ei->icu->bezt && ei->icu->ipo==IPO_BEZ)
5185
count+= 3*ei->icu->totvert;
5187
count+= ei->icu->totvert;
5190
if (count==0) return;
5193
/* this case should not happen */
5197
/* memory allocation */
5198
/*t->total= (propmode)? count: countsel;*/
5200
t->data= MEM_callocN(t->total*sizeof(TransData), "TransData (IPO Editor)");
5201
/* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */
5202
t->data2d= MEM_callocN(t->total*sizeof(TransData2D), "TransData2D (IPO Editor)");
5209
if (totipo_vertsel) {
5210
/* we're probably in editmode, so only selected verts */
5211
ei= G.sipo->editipo;
5212
for (a=0; a<G.sipo->totipo; a++, ei++) {
5213
/* only consider those curves that are visible and are being edited/used for showkeys */
5214
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
5215
if ( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
5216
if (ei->icu->bezt) {
5217
short onlytime= (ei->disptype==IPO_DISPBITS) ? 1 : (G.sipo->showkey) ? 1 : 0;
5218
bezt= ei->icu->bezt;
5220
for (b=0; b < ei->icu->totvert; b++, bezt++) {
5221
TransDataCurveHandleFlags *hdata = NULL;
5222
/* only include handles if selected, and interpolaton mode uses beztriples */
5223
if (ei->icu->ipo==IPO_BEZ) {
5224
if (bezt->f1 & SELECT) {
5225
hdata = initTransDataCurveHandes(td, bezt);
5226
bezt_to_transdata(td++, td2d++, bezt->vec[0], bezt->vec[1], 1, onlytime);
5228
if (bezt->f3 & SELECT) {
5230
hdata = initTransDataCurveHandes(td, bezt);
5232
bezt_to_transdata(td++, td2d++, bezt->vec[2], bezt->vec[1], 1, onlytime);
5236
/* only include main vert if selected */
5237
if (bezt->f2 & SELECT) {
5239
if ((bezt->f1&SELECT)==0 && (bezt->f3&SELECT)==0) {
5241
hdata = initTransDataCurveHandes(td, bezt);
5245
bezt_to_transdata(td++, td2d++, bezt->vec[1], bezt->vec[1], 1, onlytime);
5248
/* Sets handles based on the selection */
5249
testhandles_ipocurve(ei->icu);
5255
else if (totipo_edit==0 && totipo_sel!=0) {
5256
/* we're not in editmode, so entire curves get moved */
5257
ei= G.sipo->editipo;
5258
for (a=0; a<G.sipo->totipo; a++, ei++) {
5259
/* only include curves that are visible and selected */
5260
if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
5261
if (ei->icu->bezt) {
5262
short onlytime= (ei->disptype==IPO_DISPBITS) ? 1 : (G.sipo->showkey) ? 1 : 0;
5263
bezt= ei->icu->bezt;
5264
b= ei->icu->totvert;
5266
for (b=0; b < ei->icu->totvert; b++, bezt++) {
5267
/* only include handles if interpolation mode is bezier not bpoint */
5268
if (ei->icu->ipo==IPO_BEZ) {
5269
bezt_to_transdata(td++, td2d++, bezt->vec[0], bezt->vec[1], 1, onlytime);
5270
bezt_to_transdata(td++, td2d++, bezt->vec[2], bezt->vec[1], 1, onlytime);
5273
/* always include the main handle */
5274
bezt_to_transdata(td++, td2d++, bezt->vec[1], bezt->vec[1], 1, onlytime);
5282
/* ------------------------ */
5284
/* struct for use in re-sorting BezTriples during IPO transform */
5285
typedef struct BeztMap {
5287
int oldIndex; /* index of bezt in icu->bezt array before sorting */
5288
int newIndex; /* index of bezt in icu->bezt array after sorting */
5289
short swapHs; /* swap order of handles (-1=clear; 0=not checked, 1=swap) */
5293
/* This function converts an IpoCurve's BezTriple array to a BeztMap array
5294
* NOTE: this allocates memory that will need to get freed later
5296
static BeztMap *bezt_to_beztmaps (BezTriple *bezts, int totvert)
5298
BezTriple *bezt= bezts;
5299
BeztMap *bezm, *bezms;
5302
/* allocate memory for this array */
5303
if (totvert==0 || bezts==NULL)
5305
bezm= bezms= MEM_callocN(sizeof(BeztMap)*totvert, "BeztMaps");
5307
/* assign beztriples to beztmaps */
5308
for (i=0; i < totvert; i++, bezm++, bezt++) {
5317
/* This function copies the code of sort_time_ipocurve, but acts on BeztMap structs instead */
5318
static void sort_time_beztmaps (BeztMap *bezms, int totvert)
5323
/* keep repeating the process until nothing is out of place anymore */
5330
/* is current bezm out of order (i.e. occurs later than next)? */
5332
if (bezm->bezt->vec[1][0] > (bezm+1)->bezt->vec[1][0]) {
5334
(bezm+1)->newIndex--;
5336
SWAP(BeztMap, *bezm, *(bezm+1));
5342
/* do we need to check if the handles need to be swapped?
5343
* optimisation: this only needs to be performed in the first loop
5345
if (bezm->swapHs == 0) {
5346
if ( (bezm->bezt->vec[0][0] > bezm->bezt->vec[1][0]) &&
5347
(bezm->bezt->vec[2][0] < bezm->bezt->vec[1][0]) )
5349
/* handles need to be swapped */
5353
/* handles need to be cleared */
5363
/* This function firstly adjusts the pointers that the transdata has to each BezTriple*/
5364
static void beztmap_to_data (TransInfo *t, EditIpo *ei, BeztMap *bezms, int totvert)
5366
BezTriple *bezts = ei->icu->bezt;
5372
/* dynamically allocate an array of chars to mark whether an TransData's
5373
* pointers have been fixed already, so that we don't override ones that are
5376
adjusted= MEM_callocN(t->total, "beztmap_adjusted_map");
5378
/* for each beztmap item, find if it is used anywhere */
5380
for (i= 0; i < totvert; i++, bezm++) {
5381
/* loop through transdata, testing if we have a hit
5382
* for the handles (vec[0]/vec[2]), we must also check if they need to be swapped...
5385
for (j= 0; j < t->total; j++, td++) {
5386
/* skip item if already marked */
5387
if (adjusted[j] != 0) continue;
5389
if (totipo_vertsel) {
5390
/* only selected verts */
5391
if (ei->icu->ipo==IPO_BEZ) {
5392
if (bezm->bezt->f1 & SELECT) {
5393
if (td->loc2d == bezm->bezt->vec[0]) {
5394
if (bezm->swapHs == 1)
5395
td->loc2d= (bezts + bezm->newIndex)->vec[2];
5397
td->loc2d= (bezts + bezm->newIndex)->vec[0];
5401
if (bezm->bezt->f3 & SELECT) {
5402
if (td->loc2d == bezm->bezt->vec[2]) {
5403
if (bezm->swapHs == 1)
5404
td->loc2d= (bezts + bezm->newIndex)->vec[0];
5406
td->loc2d= (bezts + bezm->newIndex)->vec[2];
5411
if (bezm->bezt->f2 & SELECT) {
5412
if (td->loc2d == bezm->bezt->vec[1]) {
5413
td->loc2d= (bezts + bezm->newIndex)->vec[1];
5420
if (ei->icu->ipo==IPO_BEZ) {
5421
if (td->loc2d == bezm->bezt->vec[0]) {
5422
if (bezm->swapHs == 1)
5423
td->loc2d= (bezts + bezm->newIndex)->vec[2];
5425
td->loc2d= (bezts + bezm->newIndex)->vec[0];
5429
if (td->loc2d == bezm->bezt->vec[2]) {
5430
if (bezm->swapHs == 1)
5431
td->loc2d= (bezts + bezm->newIndex)->vec[0];
5433
td->loc2d= (bezts + bezm->newIndex)->vec[2];
5437
if (td->loc2d == bezm->bezt->vec[1]) {
5438
td->loc2d= (bezts + bezm->newIndex)->vec[1];
5446
/* free temp memory used for 'adjusted' array */
5447
MEM_freeN(adjusted);
5450
/* This function is called by recalcData during the Transform loop to recalculate
5451
* the handles of curves and sort the keyframes so that the curves draw correctly.
5452
* It is only called if some keyframes have moved out of order.
5454
void remake_ipo_transdata (TransInfo *t)
5459
/* sort and reassign verts */
3834
5460
ei= G.sipo->editipo;
3835
for(a=0; a<G.sipo->totipo; a++, ei++) {
5461
for (a=0; a<G.sipo->totipo; a++, ei++) {
3837
5462
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
5463
if (ei->icu->bezt) {
5466
/* adjust transform-data pointers */
5467
bezm= bezt_to_beztmaps(ei->icu->bezt, ei->icu->totvert);
5468
sort_time_beztmaps(bezm, ei->icu->totvert);
5469
beztmap_to_data(t, ei, bezm, ei->icu->totvert);
5471
/* re-sort actual beztriples (perhaps this could be done using the beztmaps to save time?) */
3840
5472
sort_time_ipocurve(ei->icu);
5474
/* free mapping stuff */
5477
/* make sure handles are all set correctly */
5478
testhandles_ipocurve(ei->icu);
3845
ei= G.sipo->editipo;
3847
for(a=0; a<G.sipo->totipo; a++, ei++) {
3849
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
3850
if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
3852
bezt= ei->icu->bezt;
3853
b= ei->icu->totvert;
3855
if(ei->icu->ipo==IPO_BEZ) {
3857
tv->loc= bezt->vec[0];
3861
tv->loc= bezt->vec[2];
3866
tv->loc= bezt->vec[1];
3872
testhandles_ipocurve(ei->icu);
3878
if(G.sipo->showkey) make_ipokey();
3883
for(a=0; a<tot; a++, tv++) {
3884
tv->oldloc[0]= tv->loc[0]-dvec[0];
3885
tv->oldloc[1]= tv->loc[1]-dvec[1];
5483
/* remake ipokeys */
5484
if (G.sipo->showkey) make_ipokey();
3889
void transform_ipo(int mode)
5487
/* This function acts as the entrypoint for transforms in the IPO editor (as for
5488
* the Action and NLA editors). The actual transform loop is not here anymore.
5490
void transform_ipo (int mode)
3893
TransVert *transmain = NULL, *tv;
3894
float xref=1.0, yref=1.0, dx, dy, dvec[2], min[3], max[3], vec[2], div, cent[2], size[2], sizefac;
3895
int tot=0, a, b, firsttime=1, afbreek=0, midtog= 0, dosort, proj = 0;
3896
unsigned short event = 0;
3897
short mval[2], val, xo, yo, xn, yn, xc, yc;
3900
if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
3901
if(G.sipo->editipo==0) return;
3902
if(mode=='r') return; /* from gesture */
3904
INIT_MINMAX(min, max);
3906
/* which vertices are involved */
5493
short context = (U.flag & USER_DRAGIMMEDIATE)?CTX_TWEAK:CTX_NONE;
5495
/* data-validation */
5496
if (G.sipo->ipo && G.sipo->ipo->id.lib) return;
5497
if (G.sipo->editipo==0) return;
5499
/* convert ascii-based mode to transform system constants (mode) */
5502
tmode= TFM_TRANSLATION;
5505
tmode= TFM_ROTATION;
5515
/* the transform system method involved depends on the selection */
3907
5516
get_status_editipo();
3908
if(totipo_vertsel) {
3909
tot= totipo_vertsel;
3910
tv=transmain= MEM_callocN(tot*sizeof(TransVert), "transmain");
3912
ei= G.sipo->editipo;
3913
for(a=0; a<G.sipo->totipo; a++, ei++) {
3915
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
3916
if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
3920
bezt= ei->icu->bezt;
3921
b= ei->icu->totvert;
3923
if(ei->icu->ipo==IPO_BEZ) {
3925
tv->loc= bezt->vec[0];
3926
VECCOPY(tv->oldloc, tv->loc);
3927
if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3929
/* we take the middle vertex */
3930
DO_MINMAX2(bezt->vec[1], min, max);
3935
tv->loc= bezt->vec[2];
3936
VECCOPY(tv->oldloc, tv->loc);
3937
if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3939
/* we take the middle vertex */
3940
DO_MINMAX2(bezt->vec[1], min, max);
3946
tv->loc= bezt->vec[1];
3947
VECCOPY(tv->oldloc, tv->loc);
3948
if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3949
DO_MINMAX2(bezt->vec[1], min, max);
3960
else if(totipo_edit==0 && totipo_sel!=0) {
3962
ei= G.sipo->editipo;
3963
for(a=0; a<G.sipo->totipo; a++, ei++) {
3964
if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
3965
if(ei->icu->bezt && ei->icu->ipo==IPO_BEZ) tot+= 3*ei->icu->totvert;
3966
else tot+= ei->icu->totvert;
3971
tv=transmain= MEM_callocN(tot*sizeof(TransVert), "transmain");
3973
ei= G.sipo->editipo;
3974
for(a=0; a<G.sipo->totipo; a++, ei++) {
3975
if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
3978
bezt= ei->icu->bezt;
3979
b= ei->icu->totvert;
3981
if(ei->icu->ipo==IPO_BEZ) {
3982
tv->loc= bezt->vec[0];
3983
VECCOPY(tv->oldloc, tv->loc);
3984
if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3987
tv->loc= bezt->vec[2];
3988
VECCOPY(tv->oldloc, tv->loc);
3989
if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3992
tv->loc= bezt->vec[1];
3993
VECCOPY(tv->oldloc, tv->loc);
3994
if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3996
DO_MINMAX2(bezt->vec[1], min, max);
4009
if(totipo_edit==0) move_keys(OBACT);
5517
if (totipo_vertsel) {
5518
/* we're probably in editmode, so only selected verts - transform system */
5519
initTransform(tmode, context);
5522
else if (totipo_edit==0 && totipo_sel!=0) {
5523
/* we're not in editmode, so entire curves get moved - transform system*/
5524
initTransform(tmode, context);
5528
/* shapekey mode? special transform code */
4013
cent[0]= (float)((min[0]+max[0])/2.0);
4014
cent[1]= (float)((min[1]+max[1])/2.0);
4016
if(G.sipo->showkey) {
4021
ipoco_to_areaco(G.v2d, cent, mval);
4025
getmouseco_areawin(mval);
4028
dvec[0]= dvec[1]= 0.0;
4030
sizefac= (float)(sqrt( (float)((yc-yn)*(yc-yn)+(xn-xc)*(xn-xc)) ));
4031
if(sizefac<2.0) sizefac= 2.0;
4034
getmouseco_areawin(mval);
4035
if(mval[0]!=xo || mval[1]!=yo || firsttime) {
4039
dx= (float)(mval[0]- xo);
4040
dy= (float)(mval[1]- yo);
4042
div= (float)(G.v2d->mask.xmax-G.v2d->mask.xmin);
4043
dvec[0]+= (G.v2d->cur.xmax-G.v2d->cur.xmin)*(dx)/div;
4045
div= (float)(G.v2d->mask.ymax-G.v2d->mask.ymin);
4046
dvec[1]+= (G.v2d->cur.ymax-G.v2d->cur.ymin)*(dy)/div;
4048
if(midtog) dvec[proj]= 0.0;
4050
/* vec is reused below: remake_ipo_transverts */
4054
apply_keyb_grid(vec, 0.0, (float)1.0, (float)0.1, U.flag & USER_AUTOGRABGRID);
4055
apply_keyb_grid(vec+1, 0.0, (float)1.0, (float)0.1, 0);
4058
for(a=0; a<tot; a++, tv++) {
4059
tv->loc[0]= tv->oldloc[0]+vec[0];
4061
if(tv->flag==0) tv->loc[1]= tv->oldloc[1]+vec[1];
4064
sprintf(str, "X: %.3f Y: %.3f ", vec[0], vec[1]);
4067
else if(mode=='s') {
4069
size[0]=size[1]=(float)( (sqrt( (float)((yc-mval[1])*(yc-mval[1])+(mval[0]-xc)*(mval[0]-xc)) ))/sizefac);
4071
if(midtog) size[proj]= 1.0;
4075
apply_keyb_grid(size, 0.0, (float)0.2, (float)0.1, U.flag & USER_AUTOSIZEGRID);
4076
apply_keyb_grid(size+1, 0.0, (float)0.2, (float)0.1, U.flag & USER_AUTOSIZEGRID);
4080
for(a=0; a<tot; a++, tv++) {
4081
tv->loc[0]= size[0]*(tv->oldloc[0]-cent[0])+ cent[0];
4082
if(tv->flag==0) tv->loc[1]= size[1]*(tv->oldloc[1]-cent[1])+ cent[1];
4085
sprintf(str, "scaleX: %.3f scaleY: %.3f ", size[0], size[1]);
4094
ei= G.sipo->editipo;
4095
for(a=0; a<G.sipo->totipo; a++, ei++) {
4096
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
4098
/* watch it: if the time is wrong: do not correct handles */
4099
if (test_time_ipocurve(ei->icu) ) dosort++;
4100
else testhandles_ipocurve(ei->icu);
4105
if(mode=='g') remake_ipo_transverts(transmain, vec, tot);
4106
else remake_ipo_transverts(transmain, 0, tot);
4108
if(G.sipo->showkey) update_ipokey_val();
4110
calc_ipo(G.sipo->ipo, (float)CFRA);
4112
/* update realtime */
4114
if(G.sipo->blocktype==ID_MA || G.sipo->blocktype==ID_TE) {
4115
do_ipo(G.sipo->ipo);
4116
force_draw_plus(SPACE_BUTS, 0);
4118
else if(G.sipo->blocktype==ID_CA) {
4119
do_ipo(G.sipo->ipo);
4120
force_draw_plus(SPACE_VIEW3D, 0);
4122
else if(G.sipo->blocktype==ID_KE) {
4125
ob->shapeflag &= ~OB_SHAPE_TEMPLOCK;
4126
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
4128
force_draw_plus(SPACE_VIEW3D, 0);
4130
else if(G.sipo->blocktype==ID_PO) {
4132
if(ob && ob->pose) {
4133
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
4135
force_draw_plus(SPACE_VIEW3D, 0);
4137
else if(G.sipo->blocktype==ID_OB) {
4138
Base *base= FIRSTBASE;
4141
if(base->object->ipo==G.sipo->ipo) {
4142
do_ob_ipo(base->object);
4143
base->object->recalc |= OB_RECALC_OB;
4147
DAG_scene_flush_update(G.scene, screen_view3d_layers());
4148
force_draw_plus(SPACE_VIEW3D, 0);
4157
else BIF_wait_for_statechange();
4160
event= extern_qread(&val);
4171
if(G.sipo->showkey==0) {
4174
if( abs(mval[0]-xn) > abs(mval[1]-yn)) proj= 1;
4182
if(event==XKEY) xref= -xref;
4183
else if(G.sipo->showkey==0) yref= -yref;
4192
if(G.qual & LR_CTRLKEY) {
4193
if(event==LEFTARROWKEY) {dvec[0]-= 1.0; firsttime= 1;}
4194
else if(event==RIGHTARROWKEY) {dvec[0]+= 1.0; firsttime= 1;}
4195
else if(event==UPARROWKEY) {dvec[1]+= 1.0; firsttime= 1;}
4196
else if(event==DOWNARROWKEY) {dvec[1]-= 1.0; firsttime= 1;}
4198
else arrows_move_cursor(event);
4200
else arrows_move_cursor(event);
4207
if(event==ESCKEY || event==RIGHTMOUSE) {
4209
for(a=0; a<tot; a++, tv++) {
4210
tv->loc[0]= tv->oldloc[0];
4211
tv->loc[1]= tv->oldloc[1];
4215
ei= G.sipo->editipo;
4216
for(a=0; a<G.sipo->totipo; a++, ei++) {
4217
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
4218
if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
4219
if( test_time_ipocurve(ei->icu)) {
4227
if(dosort) remake_ipo_transverts(transmain, 0, tot);
4229
ei= G.sipo->editipo;
4230
for(a=0; a<G.sipo->totipo; a++, ei++) {
4231
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
4232
if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
4233
testhandles_ipocurve(ei->icu);
4237
calc_ipo(G.sipo->ipo, (float)CFRA);
4239
else BIF_undo_push("Transform Ipo");
4241
5535
editipo_changed(G.sipo, 1);
4243
MEM_freeN(transmain);
5538
/**************************************************/
4246
5540
void filter_sampledata(float *data, int sfra, int efra)