Animato/2.5 - Graph Editor (i.e. the new 'IPO Editor')
[blender.git] / source / blender / blenkernel / intern / ipo.c
1 /* ipo.c
2  * 
3  * $Id$
4  *
5  * ***** BEGIN GPL LICENSE BLOCK *****
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *
21  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22  * All rights reserved.
23  *
24  * The Original Code is: all of this file.
25  *
26  * Contributor(s): 2008,2009 Joshua Leung (IPO System cleanup, Animation System Recode)
27  *
28  * ***** END GPL LICENSE BLOCK *****
29  */
30
31 /* NOTE:
32  *
33  * This file is no longer used to provide tools for the depreceated IPO system. Instead, it
34  * is only used to house the conversion code to the new system.
35  *
36  * -- Joshua Leung, Jan 2009
37  */
38  
39 #include <math.h>
40 #include <stdio.h>
41 #include <string.h>
42
43 #ifdef HAVE_CONFIG_H
44 #include <config.h>
45 #endif
46
47 #include "MEM_guardedalloc.h"
48
49 #include "DNA_anim_types.h"
50 #include "DNA_action_types.h"
51 #include "DNA_armature_types.h"
52 #include "DNA_constraint_types.h"
53 #include "DNA_curve_types.h"
54 #include "DNA_camera_types.h"
55 #include "DNA_lamp_types.h"
56 #include "DNA_ipo_types.h"
57 #include "DNA_key_types.h"
58 #include "DNA_material_types.h"
59 #include "DNA_mesh_types.h"
60 #include "DNA_object_types.h"
61 #include "DNA_object_force.h"
62 #include "DNA_particle_types.h"
63 #include "DNA_sequence_types.h"
64 #include "DNA_scene_types.h"
65 #include "DNA_sound_types.h"
66 #include "DNA_texture_types.h"
67 #include "DNA_view3d_types.h"
68 #include "DNA_world_types.h"
69
70 #include "BLI_blenlib.h"
71 #include "BLI_arithb.h"
72 #include "BLI_dynstr.h"
73
74 #include "BKE_utildefines.h"
75
76 #include "BKE_animsys.h"
77 #include "BKE_action.h"
78 #include "BKE_blender.h"
79 #include "BKE_curve.h"
80 #include "BKE_constraint.h"
81 #include "BKE_fcurve.h"
82 #include "BKE_global.h"
83 #include "BKE_ipo.h"
84 #include "BKE_library.h"
85 #include "BKE_main.h"
86 #include "BKE_mesh.h"
87 #include "BKE_object.h"
88
89
90
91 /* *************************************************** */
92 /* Old-Data Freeing Tools */
93
94 /* Free data from old IPO-Blocks (those which haven't been converted), but not IPO block itself */
95 // XXX this shouldn't be necessary anymore, but may occur while not all data is converted yet
96 void free_ipo (Ipo *ipo)
97 {
98         IpoCurve *icu, *icn;
99         int n= 0;
100         
101         for (icu= ipo->curve.first; icu; icu= icn) {
102                 icn= icu->next;
103                 n++;
104                 
105                 if (icu->bezt) MEM_freeN(icu->bezt);
106                 if (icu->bp) MEM_freeN(icu->bp);
107                 if (icu->driver) MEM_freeN(icu->driver);
108                 
109                 BLI_freelinkN(&ipo->curve, icu);
110         }
111         
112         printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s' \n", n, ipo->id.name+2);
113 }
114
115 /* *************************************************** */
116 /* ADRCODE to RNA-Path Conversion Code */
117
118 /* Object types */
119 static char *ob_adrcodes_to_paths (int adrcode, int *array_index)
120 {
121         /* set array index like this in-case nothing sets it correctly  */
122         *array_index= 0;
123         
124         /* result depends on adrcode */
125         switch (adrcode) {
126                 case OB_LOC_X:
127                         *array_index= 0; return "location";
128                 case OB_LOC_Y:
129                         *array_index= 1; return "location";
130                 case OB_LOC_Z:
131                         *array_index= 2; return "location";
132                 case OB_DLOC_X:
133                         *array_index= 0; return "delta_location";
134                 case OB_DLOC_Y:
135                         *array_index= 1; return "delta_location";
136                 case OB_DLOC_Z:
137                         *array_index= 2; return "delta_location";
138                 
139                 case OB_ROT_X:
140                         *array_index= 0; return "rotation";
141                 case OB_ROT_Y:
142                         *array_index= 1; return "rotation";
143                 case OB_ROT_Z:
144                         *array_index= 2; return "rotation";
145                 case OB_DROT_X:
146                         *array_index= 0; return "delta_rotation";
147                 case OB_DROT_Y:
148                         *array_index= 1; return "delta_rotation";
149                 case OB_DROT_Z:
150                         *array_index= 2; return "delta_rotation";
151                         
152                 case OB_SIZE_X:
153                         *array_index= 0; return "scale";
154                 case OB_SIZE_Y:
155                         *array_index= 1; return "scale";
156                 case OB_SIZE_Z:
157                         *array_index= 2; return "scale";
158                 case OB_DSIZE_X:
159                         *array_index= 0; return "delta_scale";
160                 case OB_DSIZE_Y:
161                         *array_index= 1; return "delta_scale";
162                 case OB_DSIZE_Z:
163                         *array_index= 2; return "delta_scale";
164         
165 #if 0   
166                 case OB_LAY:    // XXX EVIL BITFLAG ALERT! this one will need special attention...
167                 //      poin= &(ob->lay); *type= IPO_INT_BIT; break;
168                         return NULL;
169                         
170                 case OB_COL_R:  
171                         poin= &(ob->col[0]); break;
172                 case OB_COL_G:
173                         poin= &(ob->col[1]); break;
174                 case OB_COL_B:
175                         poin= &(ob->col[2]); break;
176                 case OB_COL_A:
177                         poin= &(ob->col[3]); break;
178                         
179                 case OB_PD_FSTR:
180                         if (ob->pd) poin= &(ob->pd->f_strength);
181                         break;
182                 case OB_PD_FFALL:
183                         if (ob->pd) poin= &(ob->pd->f_power);
184                         break;
185                 case OB_PD_SDAMP:
186                         if (ob->pd) poin= &(ob->pd->pdef_damp);
187                         break;
188                 case OB_PD_RDAMP:
189                         if (ob->pd) poin= &(ob->pd->pdef_rdamp);
190                         break;
191                 case OB_PD_PERM:
192                         if (ob->pd) poin= &(ob->pd->pdef_perm);
193                         break;
194                 case OB_PD_FMAXD:
195                         if (ob->pd) poin= &(ob->pd->maxdist);
196                         break;
197 #endif
198         }
199         
200         return NULL;
201 }
202
203 /* PoseChannel types 
204  * NOTE: pchan name comes from 'actname' added earlier... 
205  */
206 static char *pchan_adrcodes_to_paths (int adrcode, int *array_index)
207 {
208         /* set array index like this in-case nothing sets it correctly  */
209         *array_index= 0;
210         
211         /* result depends on adrcode */
212         switch (adrcode) {
213                 case AC_QUAT_W:
214                         *array_index= 0; return "rotation";
215                 case AC_QUAT_X:
216                         *array_index= 1; return "rotation";
217                 case AC_QUAT_Y:
218                         *array_index= 2; return "rotation";
219                 case AC_QUAT_Z:
220                         *array_index= 3; return "rotation";
221                         
222 #if 0 // XXX these were not 'official' channels (i.e. not in bf-releases)... these will need separate wrapping to work...
223                 case AC_EUL_X:
224                         *array_index= 0; return "rotation";
225                 case AC_EUL_Y:
226                         *array_index= 1; return "rotation";
227                 case AC_EUL_Z:
228                         *array_index= 2; return "rotation";
229 #endif 
230                 case -1: // XXX special case for rotation drivers... until eulers are added...
231                         *array_index= 0; return "rotation";
232                         
233                 case AC_LOC_X:
234                         *array_index= 0; return "location";
235                 case AC_LOC_Y:
236                         *array_index= 1; return "location";
237                 case AC_LOC_Z:
238                         *array_index= 2; return "location";
239                 
240                 case AC_SIZE_X:
241                         *array_index= 0; return "scale";
242                 case AC_SIZE_Y:
243                         *array_index= 1; return "scale";
244                 case AC_SIZE_Z:
245                         *array_index= 2; return "scale";
246         }
247         
248         /* for debugging only */
249         printf("ERROR: unmatched PoseChannel setting (code %d) \n", adrcode);
250         return NULL;
251 }
252
253 /* ShapeKey types 
254  * NOTE: as we don't have access to the keyblock where the data comes from (for now), 
255  *              we'll just use numerical indicies for now... 
256  */
257 static char *shapekey_adrcodes_to_paths (int adrcode, int *array_index)
258 {
259         static char buf[128];
260         
261         /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
262         // XXX adrcode 0 was dummy 'speed' curve 
263         sprintf(buf, "keys[%d].value", adrcode-1); // XXX this doesn't seem too safe...
264         return buf;
265 }
266
267 /* Texture types */
268 static char *texture_adrcodes_to_paths (int adrcode, int *array_index)
269 {
270         /* set array index like this in-case nothing sets it correctly  */
271         *array_index= 0;
272         
273         /* result depends on adrcode */
274         switch (adrcode) {
275                 case TE_NSIZE:
276                         return "noise_size";
277                 case TE_TURB:
278                         return "turbulence";
279                         
280                 case TE_NDEPTH: // XXX texture RNA undefined
281                         //poin= &(tex->noisedepth); *type= IPO_SHORT; break;
282                         break;
283                 case TE_NTYPE: // XXX texture RNA undefined
284                         //poin= &(tex->noisetype); *type= IPO_SHORT; break;
285                         break;
286                         
287                 case TE_N_BAS1:
288                         return "noise_basis";
289                 case TE_N_BAS2:
290                         return "noise_basis"; // XXX this is not yet defined in RNA...
291                 
292                         /* voronoi */
293                 case TE_VNW1:
294                         *array_index= 0; return "feature_weights";
295                 case TE_VNW2:
296                         *array_index= 1; return "feature_weights";
297                 case TE_VNW3:
298                         *array_index= 2; return "feature_weights";
299                 case TE_VNW4:
300                         *array_index= 3; return "feature_weights";
301                 case TE_VNMEXP:
302                         return "minkovsky_exponent";
303                 case TE_VN_DISTM:
304                         return "distance_metric";
305                 case TE_VN_COLT:
306                         return "color_type";
307                 
308                         /* distorted noise / voronoi */
309                 case TE_ISCA:
310                         return "noise_intensity";
311                         
312                         /* distorted noise */
313                 case TE_DISTA:
314                         return "distortion_amount";
315                 
316                         /* musgrave */
317                 case TE_MG_TYP: // XXX texture RNA undefined
318                 //      poin= &(tex->stype); *type= IPO_SHORT; break;
319                         break;
320                 case TE_MGH:
321                         return "highest_dimension";
322                 case TE_MG_LAC:
323                         return "lacunarity";
324                 case TE_MG_OCT:
325                         return "octaves";
326                 case TE_MG_OFF:
327                         return "offset";
328                 case TE_MG_GAIN:
329                         return "gain";
330                         
331                 case TE_COL_R:
332                         *array_index= 0; return "rgb_factor";
333                 case TE_COL_G:
334                         *array_index= 1; return "rgb_factor";
335                 case TE_COL_B:
336                         *array_index= 2; return "rgb_factor";
337                         
338                 case TE_BRIGHT:
339                         return "brightness";
340                 case TE_CONTRA:
341                         return "constrast";
342         }
343         
344         return NULL;
345 }
346
347 /* Material Types */
348 static char *material_adrcodes_to_paths (int adrcode, int *array_index)
349 {
350         /* set array index like this in-case nothing sets it correctly  */
351         *array_index= 0;
352         
353         /* result depends on adrcode */
354         switch (adrcode) {
355                 case MA_COL_R:
356                         *array_index= 0; return "diffuse_color";
357                 case MA_COL_G:
358                         *array_index= 1; return "diffuse_color";
359                 case MA_COL_B:
360                         *array_index= 2; return "diffuse_color";
361                         
362                 case MA_SPEC_R:
363                         *array_index= 0; return "specular_color";
364                 case MA_SPEC_G:
365                         *array_index= 1; return "specular_color";
366                 case MA_SPEC_B:
367                         *array_index= 2; return "specular_color";
368                         
369                 case MA_MIR_R:
370                         *array_index= 0; return "mirror_color";
371                 case MA_MIR_G:
372                         *array_index= 1; return "mirror_color";
373                 case MA_MIR_B:
374                         *array_index= 2; return "mirror_color";
375                         
376                 case MA_ALPHA:
377                         return "alpha";
378                         
379                 case MA_REF:
380                         return "diffuse_reflection";
381                         
382                 // XXX add other types...
383         }
384         
385         return NULL;
386         
387 #if 0
388         case MA_EMIT:
389                 poin= &(ma->emit); break;
390         case MA_AMB:
391                 poin= &(ma->amb); break;
392         case MA_SPEC:
393                 poin= &(ma->spec); break;
394         case MA_HARD:
395                 poin= &(ma->har); *type= IPO_SHORT; break;
396         case MA_SPTR:
397                 poin= &(ma->spectra); break;
398         case MA_IOR:
399                 poin= &(ma->ang); break;
400         case MA_MODE:
401                 poin= &(ma->mode); *type= IPO_INT_BIT; break; // evil... dumping bitflags directly to user!
402         case MA_HASIZE:
403                 poin= &(ma->hasize); break;
404         case MA_TRANSLU:
405                 poin= &(ma->translucency); break;
406         case MA_RAYM:
407                 poin= &(ma->ray_mirror); break;
408         case MA_FRESMIR:
409                 poin= &(ma->fresnel_mir); break;
410         case MA_FRESMIRI:
411                 poin= &(ma->fresnel_mir_i); break;
412         case MA_FRESTRA:
413                 poin= &(ma->fresnel_tra); break;
414         case MA_FRESTRAI:
415                 poin= &(ma->fresnel_tra_i); break;
416         case MA_ADD:
417                 poin= &(ma->add); break;
418         
419         if (poin == NULL) {
420                 if (icu->adrcode & MA_MAP1) mtex= ma->mtex[0];
421                 else if (icu->adrcode & MA_MAP2) mtex= ma->mtex[1];
422                 else if (icu->adrcode & MA_MAP3) mtex= ma->mtex[2];
423                 else if (icu->adrcode & MA_MAP4) mtex= ma->mtex[3];
424                 else if (icu->adrcode & MA_MAP5) mtex= ma->mtex[4];
425                 else if (icu->adrcode & MA_MAP6) mtex= ma->mtex[5];
426                 else if (icu->adrcode & MA_MAP7) mtex= ma->mtex[6];
427                 else if (icu->adrcode & MA_MAP8) mtex= ma->mtex[7];
428                 else if (icu->adrcode & MA_MAP9) mtex= ma->mtex[8];
429                 else if (icu->adrcode & MA_MAP10) mtex= ma->mtex[9];
430                 else if (icu->adrcode & MA_MAP12) mtex= ma->mtex[11];
431                 else if (icu->adrcode & MA_MAP11) mtex= ma->mtex[10];
432                 else if (icu->adrcode & MA_MAP13) mtex= ma->mtex[12];
433                 else if (icu->adrcode & MA_MAP14) mtex= ma->mtex[13];
434                 else if (icu->adrcode & MA_MAP15) mtex= ma->mtex[14];
435                 else if (icu->adrcode & MA_MAP16) mtex= ma->mtex[15];
436                 else if (icu->adrcode & MA_MAP17) mtex= ma->mtex[16];
437                 else if (icu->adrcode & MA_MAP18) mtex= ma->mtex[17];
438                 
439                 if (mtex)
440                         poin= give_mtex_poin(mtex, (icu->adrcode & (MA_MAP1-1)));
441         }
442 #endif
443         
444 }
445
446 /* Camera Types */
447 static char *camera_adrcodes_to_paths (int adrcode, int *array_index)
448 {
449         /* set array index like this in-case nothing sets it correctly  */
450         *array_index= 0;
451         
452         /* result depends on adrcode */
453         switch (adrcode) {
454                 case CAM_LENS:
455 #if 0 // XXX this cannot be resolved easily... perhaps we assume camera is perspective (works for most cases...
456                         if (ca->type == CAM_ORTHO)
457                                 return "ortho_scale";
458                         else
459                                 return "lens"; 
460 #endif // XXX this cannot be resolved easily
461                         break;
462                         
463                 case CAM_STA:
464                         return "clip_start";
465                 case CAM_END:
466                         return "clip_end";
467                         
468 #if 0 // XXX these are not defined in RNA
469                 case CAM_YF_APERT:
470                         poin= &(ca->YF_aperture); break;
471                 case CAM_YF_FDIST:
472                         poin= &(ca->YF_dofdist); break;
473 #endif // XXX these are not defined in RNA
474                         
475                 case CAM_SHIFT_X:
476                         return "shift_x";
477                 case CAM_SHIFT_Y:
478                         return "shift_y";
479         }
480         
481         /* unrecognised adrcode, or not-yet-handled ones! */
482         return NULL;
483 }
484
485 /* ------- */
486
487 /* Allocate memory for RNA-path for some property given a blocktype, adrcode, and 'root' parts of path
488  *      Input:
489  *              - blocktype, adrcode    - determines setting to get
490  *              - actname, constname    - used to build path
491  *      Output:
492  *              - array_index                   - index in property's array (if applicable) to use
493  *              - return                                - the allocated path...
494  */
495 char *get_rna_access (int blocktype, int adrcode, char actname[], char constname[], int *array_index)
496 {
497         DynStr *path= BLI_dynstr_new();
498         char *propname=NULL, *rpath=NULL;
499         char buf[512];
500         int dummy_index= 0;
501         
502         /* get property name based on blocktype */
503         switch (blocktype) {
504                 case ID_OB: /* object */
505                         propname= ob_adrcodes_to_paths(adrcode, &dummy_index);
506                         break;
507                 
508                 case ID_PO: /* pose channel */
509                         propname= pchan_adrcodes_to_paths(adrcode, &dummy_index);
510                         break;
511                         
512                 case ID_KE: /* shapekeys */
513                         propname= shapekey_adrcodes_to_paths(adrcode, &dummy_index);
514                         break;
515                         
516                 case ID_TE: /* texture */
517                         propname= texture_adrcodes_to_paths(adrcode, &dummy_index);
518                         break;
519                         
520                 case ID_MA: /* material */
521                         propname= material_adrcodes_to_paths(adrcode, &dummy_index);
522                         break;
523                         
524                 case ID_CA: /* camera */
525                         propname= camera_adrcodes_to_paths(adrcode, &dummy_index);
526                         break;
527                         
528                 /* XXX problematic blocktypes */
529                 case ID_CU: /* curve */
530                         propname= "speed"; // XXX this was a 'dummy curve' that didn't really correspond to any real var...
531                         break;
532                         
533                 case ID_SEQ: /* sequencer strip */
534                         //SEQ_FAC1:
535                         //      poin= &(seq->facf0); // XXX this doesn't seem to be included anywhere in sequencer RNA...
536                         break;
537                         
538                 /* special hacks */
539                 case -1:
540                         /* special case for rotdiff drivers... we don't need a property for this... */
541                         break;
542                         
543                 // TODO... add other blocktypes...
544                 default:
545                         printf("IPO2ANIMATO WARNING: No path for blocktype %d, adrcode %d yet \n", blocktype, adrcode);
546                         break;
547         }
548         
549         /* check if any property found 
550          *      - blocktype < 0 is special case for a specific type of driver, where we don't need a property name...
551          */
552         if ((propname == NULL) && (blocktype > 0)) {
553                 /* nothing was found, so exit */
554                 if (array_index) 
555                         *array_index= 0;
556                         
557                 BLI_dynstr_free(path);
558                 
559                 return NULL;
560         }
561         else {
562                 if (array_index)
563                         *array_index= dummy_index;
564         }
565         
566         /* append preceeding bits to path */
567         if ((actname && actname[0]) && (constname && constname[0])) {
568                 /* Constraint in Pose-Channel */
569                 sprintf(buf, "pose.pose_channels[\"%s\"].constraints[\"%s\"]", actname, constname);
570         }
571         else if (actname && actname[0]) {
572                 /* Pose-Channel */
573                 sprintf(buf, "pose.pose_channels[\"%s\"]", actname);
574         }
575         else if (constname && constname[0]) {
576                 /* Constraint in Object */
577                 sprintf(buf, "constraints[\"%s\"]", constname);
578         }
579         else
580                 strcpy(buf, ""); /* empty string */
581         BLI_dynstr_append(path, buf);
582         
583         /* append property to path (only if applicable) */
584         if (blocktype > 0) {
585                 /* need to add dot before property if there was anything precceding this */
586                 if (buf[0])
587                         BLI_dynstr_append(path, ".");
588                 
589                 /* now write name of property */
590                 BLI_dynstr_append(path, propname);
591         }
592         
593         /* convert to normal MEM_malloc'd string */
594         rpath= BLI_dynstr_get_cstring(path);
595         BLI_dynstr_free(path);
596         
597         /* return path... */
598         return rpath;
599 }
600
601 /* *************************************************** */
602 /* Conversion Utilities */
603
604 /* Convert IpoDriver to ChannelDriver - will free the old data (i.e. the old driver) */
605 static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
606 {
607         ChannelDriver *cdriver;
608         
609         /* allocate memory for new driver */
610         cdriver= MEM_callocN(sizeof(ChannelDriver), "ChannelDriver");
611         
612         /* if 'pydriver', just copy data across */
613         if (idriver->type == IPO_DRIVER_TYPE_PYTHON) {
614                 /* PyDriver only requires the expression to be copied */
615                 cdriver->type = DRIVER_TYPE_PYTHON;
616                 strcpy(cdriver->expression, idriver->name); // XXX is this safe? 
617         }
618         else {
619                 /* what to store depends on the 'blocktype' (ID_OB or ID_PO - object or posechannel) */
620                 if (idriver->blocktype == ID_AR) {
621                         /* ID_PO */
622                         if (idriver->adrcode == OB_ROT_DIFF) {
623                                 /* Rotational Difference is a special type of driver now... */
624                                 cdriver->type= DRIVER_TYPE_ROTDIFF;
625                                 
626                                 /* driver must use bones from same armature... */
627                                 cdriver->id= cdriver->id2= (ID *)idriver->ob;
628                                 
629                                 /* paths for the two targets get the pointers to the relevant Pose-Channels 
630                                  *      - return pointers to Pose-Channels not rotation channels, as calculation code is picky
631                                  *      - old bone names were stored in same var, in idriver->name
632                                  *
633                                  *      - we use several hacks here - blocktype == -1 specifies that no property needs to be found, and
634                                  *        providing a name for 'actname' will automatically imply Pose-Channel with name 'actname'
635                                  */
636                                 cdriver->rna_path= get_rna_access(-1, -1, idriver->name, NULL, NULL);
637                                 cdriver->rna_path2= get_rna_access(-1, -1, idriver->name+DRIVER_NAME_OFFS, NULL, NULL);
638                         }
639                         else {
640                                 /* 'standard' driver */
641                                 cdriver->type= DRIVER_TYPE_CHANNEL;
642                                 cdriver->id= (ID *)idriver->ob;
643                                 
644                                 switch (idriver->adrcode) {
645                                         case OB_LOC_X:  /* x,y,z location are quite straightforward */
646                                                 cdriver->rna_path= get_rna_access(ID_PO, AC_LOC_X, idriver->name, NULL, &cdriver->array_index);
647                                                 break;
648                                         case OB_LOC_Y:
649                                                 cdriver->rna_path= get_rna_access(ID_PO, AC_LOC_Y, idriver->name, NULL, &cdriver->array_index);
650                                                 break;
651                                         case OB_LOC_Z:
652                                                 cdriver->rna_path= get_rna_access(ID_PO, AC_LOC_Z, idriver->name, NULL, &cdriver->array_index);
653                                                 break;
654                                                 
655                                         case OB_SIZE_X: /* x,y,z scaling are also quite straightforward */
656                                                 cdriver->rna_path= get_rna_access(ID_PO, AC_SIZE_X, idriver->name, NULL, &cdriver->array_index);
657                                                 break;
658                                         case OB_SIZE_Y:
659                                                 cdriver->rna_path= get_rna_access(ID_PO, AC_SIZE_Y, idriver->name, NULL, &cdriver->array_index);
660                                                 break;
661                                         case OB_SIZE_Z:
662                                                 cdriver->rna_path= get_rna_access(ID_PO, AC_SIZE_Z, idriver->name, NULL, &cdriver->array_index);
663                                                 break;  
664                                                 
665                                         case OB_ROT_X:  /* rotation - we need to be careful with this... XXX (another reason why we need eulers) */     
666                                         case OB_ROT_Y:
667                                         case OB_ROT_Z:
668                                         {
669                                                 // XXX this is not yet a 1:1 map, since we'd need euler rotations to make this work nicely (unless we make some hacks)
670                                                 // XXX -1 here is a special hack...
671                                                 cdriver->rna_path= get_rna_access(ID_PO, -1, idriver->name, NULL, NULL);
672                                                 cdriver->array_index= idriver->adrcode - OB_ROT_X;
673                                         }
674                                                 break;
675                                 }
676                         }
677                 }
678                 else {
679                         /* ID_OB */
680                         cdriver->type= DRIVER_TYPE_CHANNEL;
681                         cdriver->id= (ID *)idriver->ob;
682                         cdriver->rna_path= get_rna_access(ID_OB, idriver->adrcode, idriver->name, NULL, &cdriver->array_index);
683                 }
684         }
685         
686         /* free old driver */
687         MEM_freeN(idriver);
688         
689         /* return the new one */
690         return cdriver;
691 }
692
693 /* Convert IPO-Curve to F-Curve (including Driver data), and free any of the old data that 
694  * is not relevant, BUT do not free the IPO-Curve itself...
695  *      actname: name of Action-Channel (if applicable) that IPO-Curve's IPO-block belonged to
696  *      constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to
697  */
698 static FCurve *icu_to_fcu (IpoCurve *icu, char *actname, char *constname)
699 {
700         FCurve *fcu;
701         int i= 0;
702         
703         /* allocate memory for a new F-Curve */
704         fcu= MEM_callocN(sizeof(FCurve), "FCurve");
705         
706         /* convert driver - will free the old one... */
707         if (icu->driver) {
708                 fcu->driver= idriver_to_cdriver(icu->driver);
709                 icu->driver= NULL;
710         }
711         
712         /* convert keyframes 
713          *      - beztriples and bpoints are mutually exclusive, so we won't have both at the same time
714          *      - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet)
715          */
716         // XXX we need to cope with the nasty old 'bitflag' curves... that will be a task for later
717         // XXX we also need to correct values for object-rotation curves
718         fcu->totvert= icu->totvert;
719         
720         if (icu->bezt) {
721                 BezTriple *dst, *src;
722                 
723                 /* allocate new array for keyframes/beztriples */
724                 fcu->bezt= MEM_callocN(sizeof(BezTriple)*fcu->totvert, "BezTriples");
725                 
726                 /* loop through copying all BezTriples individually, as we need to modify a few things */
727                 for (dst=fcu->bezt, src=icu->bezt; i < fcu->totvert; i++, dst++, src++) {
728                         /* firstly, copy BezTriple data */
729                         *dst= *src;
730                         
731                         /* now copy interpolation from curve (if not already set) */
732                         if (icu->ipo != IPO_MIXED)
733                                 dst->ipo= icu->ipo;
734                                 
735                         /* correct values for object rotation curves - they were degrees/10 */
736                         // XXX for now, just make them into radians as RNA sets/reads directly in that form
737                         if ((icu->blocktype == ID_OB) && ELEM3(icu->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) {
738                                 const float fac= M_PI / 18.0f; //10.0f * M_PI/180.0f;
739                                 
740                                 dst->vec[0][1] *= fac;
741                                 dst->vec[1][1] *= fac;
742                                 dst->vec[2][1] *= fac;
743                         }
744                 }
745                 
746                 /* free this data now */
747                 MEM_freeN(icu->bezt);
748         }
749         else if (icu->bp) {
750                 /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */
751                 //BPoint *bp;
752                 //FPoint *fpt;
753         }
754         
755         /* get rna-path
756          *      - we will need to set the 'disabled' flag if no path is able to be made (for now)
757          */
758         fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, &fcu->array_index);
759         if (fcu->rna_path == NULL)
760                 fcu->flag |= FCURVE_DISABLED;
761         
762         /* copy flags */
763         if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE;
764         if (icu->flag & IPO_SELECT) fcu->flag |= FCURVE_SELECTED;
765         if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
766         if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
767         if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
768         if (icu->flag & IPO_AUTO_HORIZ) fcu->flag |= FCURVE_AUTO_HANDLES;
769         
770         /* set extrapolation */
771         switch (icu->extrap) {
772                 case IPO_HORIZ: /* constant extrapolation */
773                 case IPO_DIR: /* linear extrapolation */
774                 {
775                         /* just copy, as the new defines match the old ones... */
776                         fcu->extend= icu->extrap;
777                 }
778                         break;
779                         
780                 case IPO_CYCL: /* cyclic extrapolation */
781                 case IPO_CYCLX: /* cyclic extrapolation + offset */
782                 {
783                         /* Add a new FModifier (Cyclic) instead of setting extend value 
784                          * as that's the new equivilant of that option. 
785                          */
786                         FModifier *fcm= fcurve_add_modifier(fcu, FMODIFIER_TYPE_CYCLES);
787                         FMod_Cycles *data= (FMod_Cycles *)fcm->data;
788                         
789                         /* if 'offset' one is in use, set appropriate settings */
790                         if (icu->extrap == IPO_CYCLX)
791                                 data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET;
792                         else
793                                 data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC;
794                 }
795                         break;
796         }
797         
798         /* return new F-Curve */
799         return fcu;
800 }
801
802 /* Convert IPO-block (i.e. all its IpoCurves) for some ID to the new system
803  * This assumes that AnimData has been added already. Separation of drivers
804  * from animation data is accomplished here too...
805  */
806 static void ipo_to_animdata (ID *id, Ipo *ipo, char *actname, char *constname)
807 {
808         AnimData *adt= BKE_animdata_from_id(id);
809         //bActionGroup *grp;
810         IpoCurve *icu, *icn;
811         FCurve *fcu;
812         
813         /* sanity check */
814         if ELEM(NULL, id, ipo)
815                 return;
816         if (adt == NULL) {
817                 printf("ERROR ipo_to_animdata(): adt invalid \n");
818                 return;
819         }
820         
821         printf("ipo to animdata - ID:%s, IPO:%s, actname:%s constname:%s  curves:%d \n", 
822                 id->name+2, ipo->id.name+2, (actname)?actname:"<None>", (constname)?constname:"<None>", 
823                 BLI_countlist(&ipo->curve));
824         
825         /* validate actname and constname 
826          *      - clear actname if it was one of the generic <builtin> ones (i.e. 'Object', or 'Shapes')
827          *      - actname can then be used to assign F-Curves in Action to Action Groups 
828          *        (i.e. thus keeping the benefits that used to be provided by Action Channels for grouping
829          *              F-Curves for bones). This may be added later... for now let's just dump without them...
830          */
831         if (actname) {
832                 printf("actname != 0 \n");
833                 if ((GS(id->name) == ID_OB) && (strcmp(actname, "Object") == 0))
834                         actname= NULL;
835                 else if ((GS(id->name) == ID_OB) && (strcmp(actname, "Shape") == 0))
836                         actname= NULL;
837         }
838         
839         /* loop over IPO-Curves, freeing as we progress */
840         for (icu= ipo->curve.first; icu; icu= icn) {
841                 /* get link to next (for later) */
842                 icn= icu->next;
843                 
844                 /* convert IPO-Curve to F-Curve 
845                  * NOTE: this frees any of the old data stored in the IPO-Curve that isn't needed anymore...
846                  */
847                 // XXX we need to cope with the nasty old 'bitflag' curves... that will be a task for later
848                 //              we will need to create a few new curves when doing so, and will need to sift through the keyframes to add relevant data
849                 fcu= icu_to_fcu(icu, actname, constname);
850                 
851                 /* conversion path depends on whether it's a driver or not */
852                 if (fcu->driver == NULL) {
853                         /* try to get action */
854                         if (adt->action == NULL) {
855                                 adt->action= add_empty_action("ConvertedAction"); // XXX we need a better name for this...
856                                 printf("added new action \n");
857                         }
858                                 
859                         /* add F-Curve to action */
860                         BLI_addtail(&adt->action->curves, fcu);
861                 }
862                 else {
863                         /* add F-Curve to AnimData's drivers */
864                         BLI_addtail(&adt->drivers, fcu);
865                 }
866                 
867                 /* free this IpoCurve now that it's been converted */
868                 BLI_freelinkN(&ipo->curve, icu);
869         }
870 }
871
872 /* Convert Action-block to new system 
873  * NOTE: we need to be careful here, as same data-structs are used for new system too!
874  */
875 static void action_to_animdata (ID *id, bAction *act)
876 {
877         AnimData *adt= BKE_animdata_from_id(id);
878         bActionChannel *achan, *achann;
879         bConstraintChannel *conchan, *conchann;
880         
881         /* only continue if there are Action Channels (indicating unconverted data) */
882         if (ELEM(NULL, adt, act->chanbase.first))
883                 return;
884                 
885         /* get rid of all Action Groups */
886         // XXX this is risky if there's some old, some new data in the Action...
887         if (act->groups.first) 
888                 BLI_freelistN(&act->groups);
889                 
890         /* check if we need to set this Action as the AnimData's action */
891         if (adt->action == NULL) {
892                 /* set this Action as AnimData's Action */
893                 printf("act_to_adt - set adt action to act \n");
894                 adt->action= act;
895         }
896                 
897         /* loop through Action-Channels, converting data, freeing as we go */
898         for (achan= act->chanbase.first; achan; achan= achann) {
899                 /* get pointer to next Action Channel */
900                 achann= achan->next;
901                 
902                 /* convert Action Channel's IPO data */
903                 if (achan->ipo) {
904                         ipo_to_animdata(id, achan->ipo, achan->name, NULL);
905                         achan->ipo->id.us--;
906                         achan->ipo= NULL;
907                 }
908                 
909                 /* convert constraint channel IPO-data */
910                 for (conchan= achan->constraintChannels.first; conchan; conchan= conchann) {
911                         /* get pointer to next Constraint Channel */
912                         conchann= conchan->next;
913                         
914                         /* convert Constraint Channel's IPO data */
915                         if (conchan->ipo) {
916                                 ipo_to_animdata(id, conchan->ipo, achan->name, conchan->name);
917                                 conchan->ipo->id.us--;
918                                 conchan->ipo= NULL;
919                         }
920                         
921                         /* free Constraint Channel */
922                         BLI_freelinkN(&achan->constraintChannels, conchan);
923                 }
924                 
925                 /* free Action Channel */
926                 BLI_freelinkN(&act->chanbase, achan);
927         }
928 }
929
930 /* *************************************************** */
931 /* External API - Only Called from do_versions() */
932
933 /* Called from do_versions() in readfile.c to convert the old 'IPO/adrcode' system
934  * to the new 'Animato/RNA' system.
935  *
936  * The basic method used here, is to loop over datablocks which have IPO-data, and 
937  * add those IPO's to new AnimData blocks as Actions. 
938  * Action/NLA data only works well for Objects, so these only need to be checked for there.
939  *  
940  * Data that has been converted should be freed immediately, which means that it is immediately
941  * clear which datablocks have yet to be converted, and also prevent freeing errors when we exit.
942  */
943 // XXX currently done after all file reading... 
944 void do_versions_ipos_to_animato(Main *main)
945 {
946         ID *id;
947         AnimData *adt;
948         
949         if (main == NULL) {
950                 printf("Argh! Main is NULL in do_versions_ipos_to_animato() \n");
951                 return;
952         }
953                 
954         /* only convert if version is right */
955         // XXX???
956         if (main->versionfile >= 250) {
957                 printf("WARNING: Animation data too new to convert (Version %d) \n", main->versionfile);
958                 return;
959         }
960         else
961                 printf("INFO: Converting to Animato... \n"); // xxx debug
962                 
963         
964         /* objects */
965         for (id= main->object.first; id; id= id->next) {
966                 Object *ob= (Object *)id;
967                 bPoseChannel *pchan;
968                 bConstraint *con;
969                 bConstraintChannel *conchan, *conchann;
970                 
971                 printf("\tconverting ob %s \n", id->name+2);
972                 
973                 /* check if object has any animation data */
974                 if ((ob->ipo) || (ob->action) || (ob->nlastrips.first)) {
975                         /* Add AnimData block */
976                         adt= BKE_id_add_animdata(id);
977                         
978                         /* IPO first */
979                         if (ob->ipo) {
980                                 ipo_to_animdata(id, ob->ipo, NULL, NULL);
981                                 ob->ipo->id.us--;
982                                 ob->ipo= NULL;
983                         }
984                         
985                         /* now Action */
986                         if (ob->action) {
987                                 action_to_animdata(id, ob->action);
988                                 
989                                 /* only decrease usercount if this Action isn't now being used by AnimData */
990                                 if (ob->action != adt->action) {
991                                         ob->action->id.us--;
992                                         ob->action= NULL;
993                                 }
994                         }
995                         
996                         /* finally NLA */
997                         // XXX todo... for now, new NLA code not hooked up yet, so keep old stuff (but not for too long!)
998                 }
999                 
1000                 /* check PoseChannels for constraints with local data */
1001                 if (ob->pose) {
1002                         for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1003                                 for (con= pchan->constraints.first; con; con= con->next) {
1004                                         /* if constraint has own IPO, convert add these to Object 
1005                                          * (NOTE: they're most likely to be drivers too) 
1006                                          */
1007                                         if (con->ipo) {
1008                                                 /* although this was the constraint's local IPO, we still need to provide pchan + con 
1009                                                  * so that drivers can be added properly...
1010                                                  */
1011                                                 ipo_to_animdata(id, con->ipo, pchan->name, con->name);
1012                                                 con->ipo->id.us--;
1013                                                 con->ipo= NULL;
1014                                         }
1015                                          
1016                                         /* check for Action Constraint */
1017                                         // XXX do we really want to do this here?
1018                                 }
1019                         }
1020                 }
1021                 
1022                 /* check constraints for local IPO's */
1023                 for (con= ob->constraints.first; con; con= con->next) {
1024                         /* if constraint has own IPO, convert add these to Object 
1025                          * (NOTE: they're most likely to be drivers too) 
1026                          */
1027                         if (con->ipo) {
1028                                 /* although this was the constraint's local IPO, we still need to provide con 
1029                                  * so that drivers can be added properly...
1030                                  */
1031                                 ipo_to_animdata(id, con->ipo, NULL, con->name);
1032                                 con->ipo->id.us--;
1033                                 con->ipo= NULL;
1034                         }
1035                          
1036                         /* check for Action Constraint */
1037                         // XXX do we really want to do this here?
1038                 }
1039                 
1040                 /* check constraint channels - we need to remove them anyway... */
1041                 for (conchan= ob->constraintChannels.first; conchan; conchan= conchann) {
1042                         /* get pointer to next Constraint Channel */
1043                         conchann= conchan->next;
1044                         
1045                         /* convert Constraint Channel's IPO data */
1046                         if (conchan->ipo) {
1047                                 ipo_to_animdata(id, conchan->ipo, NULL, conchan->name);
1048                                 conchan->ipo->id.us--;
1049                                 conchan->ipo= NULL;
1050                         }
1051                         
1052                         /* free Constraint Channel */
1053                         BLI_freelinkN(&ob->constraintChannels, conchan);
1054                 }
1055         }
1056         
1057         /* shapekeys */
1058         for (id= main->key.first; id; id= id->next) {
1059                 Key *key= (Key *)id;
1060                 
1061                 printf("\tconverting key %s \n", id->name+2);
1062                 
1063                 /* we're only interested in the IPO 
1064                  * NOTE: for later, it might be good to port these over to Object instead, as many of these
1065                  * are likely to be drivers, but it's hard to trace that from here, so move this to Ob loop?
1066                  */
1067                 if (key->ipo) {
1068                         /* Add AnimData block */
1069                         adt= BKE_id_add_animdata(id);
1070                         
1071                         /* Convert Shapekey data... */
1072                         ipo_to_animdata(id, key->ipo, NULL, NULL);
1073                         key->ipo->id.us--;
1074                         key->ipo= NULL;
1075                 }
1076         }
1077         
1078         /* materials */
1079         for (id= main->mat.first; id; id= id->next) {
1080                 Material *ma= (Material *)id;
1081                 
1082                 printf("\tconverting material %s \n", id->name+2);
1083                 
1084                 /* we're only interested in the IPO */
1085                 if (ma->ipo) {
1086                         /* Add AnimData block */
1087                         adt= BKE_id_add_animdata(id);
1088                         
1089                         /* Convert Material data... */
1090                         ipo_to_animdata(id, ma->ipo, NULL, NULL);
1091                         ma->ipo->id.us--;
1092                         ma->ipo= NULL;
1093                 }
1094         }
1095         
1096         /* textures */
1097         for (id= main->tex.first; id; id= id->next) {
1098                 Tex *te= (Tex *)id;
1099                 
1100                 printf("\tconverting texture %s \n", id->name+2);
1101                 
1102                 /* we're only interested in the IPO */
1103                 if (te->ipo) {
1104                         /* Add AnimData block */
1105                         adt= BKE_id_add_animdata(id);
1106                         
1107                         /* Convert Texture data... */
1108                         ipo_to_animdata(id, te->ipo, NULL, NULL);
1109                         te->ipo->id.us--;
1110                         te->ipo= NULL;
1111                 }
1112         }
1113         
1114         /* cameras */
1115         for (id= main->camera.first; id; id= id->next) {
1116                 Camera *ca= (Camera *)id;
1117                 
1118                 printf("\tconverting camera %s \n", id->name+2);
1119                 
1120                 /* we're only interested in the IPO */
1121                 if (ca->ipo) {
1122                         /* Add AnimData block */
1123                         adt= BKE_id_add_animdata(id);
1124                         
1125                         /* Convert Camera data... */
1126                         ipo_to_animdata(id, ca->ipo, NULL, NULL);
1127                         ca->ipo->id.us--;
1128                         ca->ipo= NULL;
1129                 }
1130         }
1131         
1132         // XXX add other types too...
1133         
1134         printf("INFO: animato convert done \n"); // xxx debug
1135 }
1136
1137
1138
1139 #if 0 // XXX old animation system
1140
1141 /* ***************************** IPO - DataAPI ********************************* */
1142
1143 // !!!!!!!!!!!!!!!!!!!!!!!!!!!! FIXME - BAD CRUFT WARNING !!!!!!!!!!!!!!!!!!!!!!!
1144
1145 /* These functions here should be replaced eventually by the Data API, as this is 
1146  * inflexible duplication...
1147  */
1148
1149 /* --------------------- Get Pointer API ----------------------------- */ 
1150
1151 /* get texture-slot/mapping channel */
1152 void *give_mtex_poin (MTex *mtex, int adrcode)
1153 {
1154         void *poin= NULL;
1155         
1156         switch (adrcode) {
1157         case MAP_OFS_X:
1158                 poin= &(mtex->ofs[0]); break;
1159         case MAP_OFS_Y:
1160                 poin= &(mtex->ofs[1]); break;
1161         case MAP_OFS_Z:
1162                 poin= &(mtex->ofs[2]); break;
1163         case MAP_SIZE_X:
1164                 poin= &(mtex->size[0]); break;
1165         case MAP_SIZE_Y:
1166                 poin= &(mtex->size[1]); break;
1167         case MAP_SIZE_Z:
1168                 poin= &(mtex->size[2]); break;
1169         case MAP_R:
1170                 poin= &(mtex->r); break;
1171         case MAP_G:
1172                 poin= &(mtex->g); break;
1173         case MAP_B:
1174                 poin= &(mtex->b); break;
1175         case MAP_DVAR:
1176                 poin= &(mtex->def_var); break;
1177         case MAP_COLF:
1178                 poin= &(mtex->colfac); break;
1179         case MAP_NORF:
1180                 poin= &(mtex->norfac); break;
1181         case MAP_VARF:
1182                 poin= &(mtex->varfac); break;
1183         case MAP_DISP:
1184                 poin= &(mtex->dispfac); break;
1185         }
1186         
1187         /* return pointer */
1188         return poin;
1189 }
1190
1191 /* GS reads the memory pointed at in a specific ordering. There are,
1192  * however two definitions for it. I have jotted them down here, both,
1193  * but I think the first one is actually used. The thing is that
1194  * big-endian systems might read this the wrong way round. OTOH, we
1195  * constructed the IDs that are read out with this macro explicitly as
1196  * well. I expect we'll sort it out soon... */
1197
1198 /* from blendef: */
1199 #define GS(a)   (*((short *)(a)))
1200
1201 /* from misc_util: flip the bytes from x  */
1202 /*  #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
1203
1204
1205 /* general function to get pointer to source/destination data  */
1206 void *get_ipo_poin (ID *id, IpoCurve *icu, int *type)
1207 {
1208         void *poin= NULL;
1209         MTex *mtex= NULL;
1210
1211         /* most channels will have float data, but those with other types will override this */
1212         *type= IPO_FLOAT;
1213
1214         /* data is divided into 'blocktypes' based on ID-codes */
1215         switch (GS(id->name)) {
1216                 case ID_WO: /* world channels -----------------------------  */
1217                 {
1218                         World *wo= (World *)id;
1219                         
1220                         switch (icu->adrcode) {
1221                         case WO_HOR_R:
1222                                 poin= &(wo->horr); break;
1223                         case WO_HOR_G:
1224                                 poin= &(wo->horg); break;
1225                         case WO_HOR_B:
1226                                 poin= &(wo->horb); break;
1227                         case WO_ZEN_R:
1228                                 poin= &(wo->zenr); break;
1229                         case WO_ZEN_G:
1230                                 poin= &(wo->zeng); break;
1231                         case WO_ZEN_B:
1232                                 poin= &(wo->zenb); break;
1233                         
1234                         case WO_EXPOS:
1235                                 poin= &(wo->exposure); break;
1236                         
1237                         case WO_MISI:
1238                                 poin= &(wo->misi); break;
1239                         case WO_MISTDI:
1240                                 poin= &(wo->mistdist); break;
1241                         case WO_MISTSTA:
1242                                 poin= &(wo->miststa); break;
1243                         case WO_MISTHI:
1244                                 poin= &(wo->misthi); break;
1245                         
1246                         case WO_STAR_R:
1247                                 poin= &(wo->starr); break;
1248                         case WO_STAR_G:
1249                                 poin= &(wo->starg); break;
1250                         case WO_STAR_B:
1251                                 poin= &(wo->starb); break;
1252                         
1253                         case WO_STARDIST:
1254                                 poin= &(wo->stardist); break;
1255                         case WO_STARSIZE:
1256                                 poin= &(wo->starsize); break;
1257                         }
1258                         
1259                         if (poin == NULL) {
1260                                 if (icu->adrcode & MA_MAP1) mtex= wo->mtex[0];
1261                                 else if (icu->adrcode & MA_MAP2) mtex= wo->mtex[1];
1262                                 else if (icu->adrcode & MA_MAP3) mtex= wo->mtex[2];
1263                                 else if (icu->adrcode & MA_MAP4) mtex= wo->mtex[3];
1264                                 else if (icu->adrcode & MA_MAP5) mtex= wo->mtex[4];
1265                                 else if (icu->adrcode & MA_MAP6) mtex= wo->mtex[5];
1266                                 else if (icu->adrcode & MA_MAP7) mtex= wo->mtex[6];
1267                                 else if (icu->adrcode & MA_MAP8) mtex= wo->mtex[7];
1268                                 else if (icu->adrcode & MA_MAP9) mtex= wo->mtex[8];
1269                                 else if (icu->adrcode & MA_MAP10) mtex= wo->mtex[9];
1270                                 else if (icu->adrcode & MA_MAP11) mtex= wo->mtex[10];
1271                                 else if (icu->adrcode & MA_MAP12) mtex= wo->mtex[11];
1272                                 else if (icu->adrcode & MA_MAP13) mtex= wo->mtex[12];
1273                                 else if (icu->adrcode & MA_MAP14) mtex= wo->mtex[13];
1274                                 else if (icu->adrcode & MA_MAP15) mtex= wo->mtex[14];
1275                                 else if (icu->adrcode & MA_MAP16) mtex= wo->mtex[15];
1276                                 else if (icu->adrcode & MA_MAP17) mtex= wo->mtex[16];
1277                                 else if (icu->adrcode & MA_MAP18) mtex= wo->mtex[17];
1278                                 
1279                                 if (mtex)
1280                                         poin= give_mtex_poin(mtex, (icu->adrcode & (MA_MAP1-1)));
1281                         }
1282                 }
1283                         break;
1284                 case ID_LA: /* lamp channels -----------------------------  */
1285                 {
1286                         Lamp *la= (Lamp *)id;
1287                         
1288                         switch (icu->adrcode) {
1289                         case LA_ENERGY:
1290                                 poin= &(la->energy); break;             
1291                         case LA_COL_R:
1292                                 poin= &(la->r); break;
1293                         case LA_COL_G:
1294                                 poin= &(la->g); break;
1295                         case LA_COL_B:
1296                                 poin= &(la->b); break;
1297                         case LA_DIST:
1298                                 poin= &(la->dist); break;               
1299                         case LA_SPOTSI:
1300                                 poin= &(la->spotsize); break;
1301                         case LA_SPOTBL:
1302                                 poin= &(la->spotblend); break;
1303                         case LA_QUAD1:
1304                                 poin= &(la->att1); break;
1305                         case LA_QUAD2:
1306                                 poin= &(la->att2); break;
1307                         case LA_HALOINT:
1308                                 poin= &(la->haint); break;
1309                         }
1310                         
1311                         if (poin == NULL) {
1312                                 if (icu->adrcode & MA_MAP1) mtex= la->mtex[0];
1313                                 else if (icu->adrcode & MA_MAP2) mtex= la->mtex[1];
1314                                 else if (icu->adrcode & MA_MAP3) mtex= la->mtex[2];
1315                                 else if (icu->adrcode & MA_MAP4) mtex= la->mtex[3];
1316                                 else if (icu->adrcode & MA_MAP5) mtex= la->mtex[4];
1317                                 else if (icu->adrcode & MA_MAP6) mtex= la->mtex[5];
1318                                 else if (icu->adrcode & MA_MAP7) mtex= la->mtex[6];
1319                                 else if (icu->adrcode & MA_MAP8) mtex= la->mtex[7];
1320                                 else if (icu->adrcode & MA_MAP9) mtex= la->mtex[8];
1321                                 else if (icu->adrcode & MA_MAP10) mtex= la->mtex[9];
1322                                 else if (icu->adrcode & MA_MAP11) mtex= la->mtex[10];
1323                                 else if (icu->adrcode & MA_MAP12) mtex= la->mtex[11];
1324                                 else if (icu->adrcode & MA_MAP13) mtex= la->mtex[12];
1325                                 else if (icu->adrcode & MA_MAP14) mtex= la->mtex[13];
1326                                 else if (icu->adrcode & MA_MAP15) mtex= la->mtex[14];
1327                                 else if (icu->adrcode & MA_MAP16) mtex= la->mtex[15];
1328                                 else if (icu->adrcode & MA_MAP17) mtex= la->mtex[16];
1329                                 else if (icu->adrcode & MA_MAP18) mtex= la->mtex[17];
1330                                 
1331                                 if (mtex)
1332                                         poin= give_mtex_poin(mtex, (icu->adrcode & (MA_MAP1-1)));
1333                         }
1334                 }
1335                         break;
1336                 case ID_SO: /* sound channels -----------------------------  */
1337                 {
1338                         bSound *snd= (bSound *)id;
1339                         
1340                         switch (icu->adrcode) {
1341                         case SND_VOLUME:
1342                                 poin= &(snd->volume); break;
1343                         case SND_PITCH:
1344                                 poin= &(snd->pitch); break;
1345                         case SND_PANNING:
1346                                 poin= &(snd->panning); break;
1347                         case SND_ATTEN:
1348                                 poin= &(snd->attenuation); break;
1349                         }
1350                 }
1351                         break;
1352                 case ID_PA: /* particle channels -----------------------------  */
1353                 {
1354                         ParticleSettings *part= (ParticleSettings *)id;
1355                         
1356                         switch (icu->adrcode) {
1357                         case PART_EMIT_FREQ:
1358                         case PART_EMIT_LIFE:
1359                         case PART_EMIT_VEL:
1360                         case PART_EMIT_AVE:
1361                         case PART_EMIT_SIZE:
1362                                 poin= NULL; 
1363                                 break;
1364                         
1365                         case PART_CLUMP:
1366                                 poin= &(part->clumpfac); break;
1367                         case PART_AVE:
1368                                 poin= &(part->avefac); break;
1369                         case PART_SIZE:
1370                                 poin= &(part->size); break;
1371                         case PART_DRAG:
1372                                 poin= &(part->dragfac); break;
1373                         case PART_BROWN:
1374                                 poin= &(part->brownfac); break;
1375                         case PART_DAMP:
1376                                 poin= &(part->dampfac); break;
1377                         case PART_LENGTH:
1378                                 poin= &(part->length); break;
1379                         case PART_GRAV_X:
1380                                 poin= &(part->acc[0]); break;
1381                         case PART_GRAV_Y:
1382                                 poin= &(part->acc[1]); break;
1383                         case PART_GRAV_Z:
1384                                 poin= &(part->acc[2]); break;
1385                         case PART_KINK_AMP:
1386                                 poin= &(part->kink_amp); break;
1387                         case PART_KINK_FREQ:
1388                                 poin= &(part->kink_freq); break;
1389                         case PART_KINK_SHAPE:
1390                                 poin= &(part->kink_shape); break;
1391                         case PART_BB_TILT:
1392                                 poin= &(part->bb_tilt); break;
1393                                 
1394                         case PART_PD_FSTR:
1395                                 if (part->pd) poin= &(part->pd->f_strength);
1396                                 break;
1397                         case PART_PD_FFALL:
1398                                 if (part->pd) poin= &(part->pd->f_power);
1399                                 break;
1400                         case PART_PD_FMAXD:
1401                                 if (part->pd) poin= &(part->pd->maxdist);
1402                                 break;
1403                         case PART_PD2_FSTR:
1404                                 if (part->pd2) poin= &(part->pd2->f_strength);
1405                                 break;
1406                         case PART_PD2_FFALL:
1407                                 if (part->pd2) poin= &(part->pd2->f_power);
1408                                 break;
1409                         case PART_PD2_FMAXD:
1410                                 if (part->pd2) poin= &(part->pd2->maxdist);
1411                                 break;
1412                         }
1413                 }
1414                         break;
1415         }
1416
1417         /* return pointer */
1418         return poin;
1419 }
1420
1421
1422 #endif // XXX old animation system