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