5 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22 * All rights reserved.
24 * The Original Code is: all of this file.
26 * Contributor(s): 2008,2009 Joshua Leung (IPO System cleanup, Animation System Recode)
28 * ***** END GPL LICENSE BLOCK *****
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.
36 * -- Joshua Leung, Jan 2009
44 #include "MEM_guardedalloc.h"
46 #include "DNA_anim_types.h"
47 #include "DNA_constraint_types.h"
48 #include "DNA_camera_types.h"
49 #include "DNA_lamp_types.h"
50 #include "DNA_ipo_types.h"
51 #include "DNA_key_types.h"
52 #include "DNA_material_types.h"
53 #include "DNA_nla_types.h"
54 #include "DNA_sequence_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_world_types.h"
57 #include "DNA_object_types.h"
59 #include "BLI_math.h" /* windows needs for M_PI */
60 #include "BLI_blenlib.h"
61 #include "BLI_dynstr.h"
63 #include "BKE_utildefines.h"
65 #include "BKE_animsys.h"
66 #include "BKE_action.h"
67 #include "BKE_fcurve.h"
68 #include "BKE_global.h"
71 #include "BKE_sequencer.h"
74 /* *************************************************** */
75 /* Old-Data Freeing Tools */
77 /* Free data from old IPO-Blocks (those which haven't been converted), but not IPO block itself */
78 // XXX this shouldn't be necessary anymore, but may occur while not all data is converted yet
79 void free_ipo (Ipo *ipo)
84 for (icu= ipo->curve.first; icu; icu= icn) {
88 if (icu->bezt) MEM_freeN(icu->bezt);
89 if (icu->bp) MEM_freeN(icu->bp);
90 if (icu->driver) MEM_freeN(icu->driver);
92 BLI_freelinkN(&ipo->curve, icu);
96 printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s' \n", n, ipo->id.name+2);
99 /* *************************************************** */
100 /* ADRCODE to RNA-Path Conversion Code - Special (Bitflags) */
102 /* Mapping Table for bitflag <-> RNA path */
103 typedef struct AdrBit2Path {
109 /* ----------------- */
110 /* Mapping Tables to use bits <-> RNA paths */
113 static AdrBit2Path ob_layer_bits[]= {
114 {(1<<0), "layer", 0},
115 {(1<<1), "layer", 1},
116 {(1<<2), "layer", 2},
117 {(1<<3), "layer", 3},
118 {(1<<4), "layer", 4},
119 {(1<<5), "layer", 5},
120 {(1<<6), "layer", 6},
121 {(1<<7), "layer", 7},
122 {(1<<8), "layer", 8},
123 {(1<<9), "layer", 9},
124 {(1<<10), "layer", 10},
125 {(1<<11), "layer", 11},
126 {(1<<12), "layer", 12},
127 {(1<<13), "layer", 13},
128 {(1<<14), "layer", 14},
129 {(1<<15), "layer", 15},
130 {(1<<16), "layer", 16},
131 {(1<<17), "layer", 17},
132 {(1<<18), "layer", 18},
133 {(1<<19), "layer", 19},
134 {(1<<20), "layer", 20}
138 static AdrBit2Path ma_mode_bits[]= {
139 // {MA_TRACEBLE, "traceable", 0},
140 // {MA_SHADOW, "shadow", 0},
141 // {MA_SHLESS, "shadeless", 0},
143 {MA_RAYTRANSP, "transparency", 0},
144 {MA_RAYMIRROR, "raytrace_mirror.enabled", 0},
145 // {MA_HALO, "type", MA_TYPE_HALO}
148 /* ----------------- */
150 /* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */
151 #define RET_ABP(items) \
153 *tot= sizeof(items)/sizeof(AdrBit2Path); \
157 /* This function checks if a Blocktype+Adrcode combo, returning a mapping table */
158 static AdrBit2Path *adrcode_bitmaps_to_paths (int blocktype, int adrcode, int *tot)
161 if ((blocktype == ID_OB) && (adrcode == OB_LAY))
162 RET_ABP(ob_layer_bits)
163 else if ((blocktype == ID_MA) && (adrcode == MA_MODE))
164 RET_ABP(ma_mode_bits)
165 // XXX TODO: add other types...
171 /* *************************************************** */
172 /* ADRCODE to RNA-Path Conversion Code - Standard */
175 static char *ob_adrcodes_to_paths (int adrcode, int *array_index)
177 /* set array index like this in-case nothing sets it correctly */
180 /* result depends on adrcode */
183 *array_index= 0; return "location";
185 *array_index= 1; return "location";
187 *array_index= 2; return "location";
189 *array_index= 0; return "delta_location";
191 *array_index= 1; return "delta_location";
193 *array_index= 2; return "delta_location";
196 *array_index= 0; return "rotation_euler";
198 *array_index= 1; return "rotation_euler";
200 *array_index= 2; return "rotation_euler";
202 *array_index= 0; return "delta_rotation_euler";
204 *array_index= 1; return "delta_rotation_euler";
206 *array_index= 2; return "delta_rotation_euler";
209 *array_index= 0; return "scale";
211 *array_index= 1; return "scale";
213 *array_index= 2; return "scale";
215 *array_index= 0; return "delta_scale";
217 *array_index= 1; return "delta_scale";
219 *array_index= 2; return "delta_scale";
221 *array_index= 0; return "color";
223 *array_index= 1; return "color";
225 *array_index= 2; return "color";
227 *array_index= 3; return "color";
230 if (ob->pd) poin= &(ob->pd->f_strength);
233 if (ob->pd) poin= &(ob->pd->f_power);
236 if (ob->pd) poin= &(ob->pd->pdef_damp);
239 if (ob->pd) poin= &(ob->pd->pdef_rdamp);
242 if (ob->pd) poin= &(ob->pd->pdef_perm);
245 if (ob->pd) poin= &(ob->pd->maxdist);
254 * NOTE: pchan name comes from 'actname' added earlier...
256 static char *pchan_adrcodes_to_paths (int adrcode, int *array_index)
258 /* set array index like this in-case nothing sets it correctly */
261 /* result depends on adrcode */
264 *array_index= 0; return "rotation_quaternion";
266 *array_index= 1; return "rotation_quaternion";
268 *array_index= 2; return "rotation_quaternion";
270 *array_index= 3; return "rotation_quaternion";
273 *array_index= 0; return "rotation_euler";
275 *array_index= 1; return "rotation_euler";
277 *array_index= 2; return "rotation_euler";
280 *array_index= 0; return "location";
282 *array_index= 1; return "location";
284 *array_index= 2; return "location";
287 *array_index= 0; return "scale";
289 *array_index= 1; return "scale";
291 *array_index= 2; return "scale";
294 /* for debugging only */
295 printf("ERROR: unmatched PoseChannel setting (code %d) \n", adrcode);
299 /* Constraint types */
300 static char *constraint_adrcodes_to_paths (int adrcode, int *array_index)
302 /* set array index like this in-case nothing sets it correctly */
305 /* result depends on adrcode */
309 case CO_HEADTAIL: // XXX this needs to be wrapped in RNA.. probably then this path will be invalid
310 return "data.head_tail";
317 * NOTE: as we don't have access to the keyblock where the data comes from (for now),
318 * we'll just use numerical indicies for now...
320 static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
322 static char buf[128];
324 /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
325 // XXX adrcode 0 was dummy 'speed' curve
327 sprintf(buf, "speed");
329 sprintf(buf, "keys[%d].value", adrcode);
333 /* MTex (Texture Slot) types */
334 static char *mtex_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
336 char *base=NULL, *prop=NULL;
337 static char buf[128];
339 /* base part of path */
340 if (adrcode & MA_MAP1) base= "textures[0]";
341 else if (adrcode & MA_MAP2) base= "textures[1]";
342 else if (adrcode & MA_MAP3) base= "textures[2]";
343 else if (adrcode & MA_MAP4) base= "textures[3]";
344 else if (adrcode & MA_MAP5) base= "textures[4]";
345 else if (adrcode & MA_MAP6) base= "textures[5]";
346 else if (adrcode & MA_MAP7) base= "textures[6]";
347 else if (adrcode & MA_MAP8) base= "textures[7]";
348 else if (adrcode & MA_MAP9) base= "textures[8]";
349 else if (adrcode & MA_MAP10) base= "textures[9]";
350 else if (adrcode & MA_MAP11) base= "textures[10]";
351 else if (adrcode & MA_MAP12) base= "textures[11]";
352 else if (adrcode & MA_MAP13) base= "textures[12]";
353 else if (adrcode & MA_MAP14) base= "textures[13]";
354 else if (adrcode & MA_MAP15) base= "textures[14]";
355 else if (adrcode & MA_MAP16) base= "textures[15]";
356 else if (adrcode & MA_MAP17) base= "textures[16]";
357 else if (adrcode & MA_MAP18) base= "textures[17]";
359 /* property identifier for path */
360 adrcode= (adrcode & (MA_MAP1-1));
362 #if 0 // XXX these are not wrapped in RNA yet!
364 poin= &(mtex->ofs[0]); break;
366 poin= &(mtex->ofs[1]); break;
368 poin= &(mtex->ofs[2]); break;
370 poin= &(mtex->size[0]); break;
372 poin= &(mtex->size[1]); break;
374 poin= &(mtex->size[2]); break;
376 poin= &(mtex->r); break;
378 poin= &(mtex->g); break;
380 poin= &(mtex->b); break;
382 poin= &(mtex->def_var); break;
384 poin= &(mtex->colfac); break;
386 poin= &(mtex->norfac); break;
388 poin= &(mtex->varfac); break;
391 prop= "warp_factor"; break;
394 /* only build and return path if there's a property */
396 BLI_snprintf(buf, 128, "%s.%s", base, prop);
404 static char *texture_adrcodes_to_paths (int adrcode, int *array_index)
406 /* set array index like this in-case nothing sets it correctly */
409 /* result depends on adrcode */
416 case TE_NDEPTH: // XXX texture RNA undefined
417 //poin= &(tex->noisedepth); *type= IPO_SHORT; break;
419 case TE_NTYPE: // XXX texture RNA undefined
420 //poin= &(tex->noisetype); *type= IPO_SHORT; break;
424 return "noise_basis";
426 return "noise_basis"; // XXX this is not yet defined in RNA...
430 *array_index= 0; return "feature_weights";
432 *array_index= 1; return "feature_weights";
434 *array_index= 2; return "feature_weights";
436 *array_index= 3; return "feature_weights";
438 return "minkovsky_exponent";
440 return "distance_metric";
444 /* distorted noise / voronoi */
446 return "noise_intensity";
448 /* distorted noise */
450 return "distortion_amount";
453 case TE_MG_TYP: // XXX texture RNA undefined
454 // poin= &(tex->stype); *type= IPO_SHORT; break;
457 return "highest_dimension";
468 *array_index= 0; return "rgb_factor";
470 *array_index= 1; return "rgb_factor";
472 *array_index= 2; return "rgb_factor";
484 static char *material_adrcodes_to_paths (int adrcode, int *array_index)
486 /* set array index like this in-case nothing sets it correctly */
489 /* result depends on adrcode */
492 *array_index= 0; return "diffuse_color";
494 *array_index= 1; return "diffuse_color";
496 *array_index= 2; return "diffuse_color";
499 *array_index= 0; return "specular_color";
501 *array_index= 1; return "specular_color";
503 *array_index= 2; return "specular_color";
506 *array_index= 0; return "mirror_color";
508 *array_index= 1; return "mirror_color";
510 *array_index= 2; return "mirror_color";
516 return "diffuse_reflection";
525 return "specular_reflection";
528 return "specular_hardness";
531 return "specular_opacity";
540 return "translucency";
543 return "raytrace_mirror.reflect";
546 return "raytrace_mirror.fresnel";
549 return "raytrace_mirror.fresnel_fac";
552 return "raytrace_transparency.fresnel";
555 return "raytrace_transparency.fresnel_fac";
560 default: /* for now, we assume that the others were MTex channels */
561 return mtex_adrcodes_to_paths(adrcode, array_index);
568 static char *camera_adrcodes_to_paths (int adrcode, int *array_index)
570 /* set array index like this in-case nothing sets it correctly */
573 /* result depends on adrcode */
576 #if 0 // XXX this cannot be resolved easily... perhaps we assume camera is perspective (works for most cases...
577 if (ca->type == CAM_ORTHO)
578 return "ortho_scale";
581 #else // XXX lazy hack for now...
583 #endif // XXX this cannot be resolved easily
590 #if 0 // XXX these are not defined in RNA
592 poin= &(ca->YF_aperture); break;
594 poin= &(ca->YF_dofdist); break;
595 #endif // XXX these are not defined in RNA
603 /* unrecognised adrcode, or not-yet-handled ones! */
608 static char *lamp_adrcodes_to_paths (int adrcode, int *array_index)
610 /* set array index like this in-case nothing sets it correctly */
613 /* result depends on adrcode */
619 *array_index= 0; return "color";
621 *array_index= 1; return "color";
623 *array_index= 2; return "color";
634 return "linear_attenuation";
636 return "quadratic_attenuation";
639 return "halo_intensity";
641 default: /* for now, we assume that the others were MTex channels */
642 return mtex_adrcodes_to_paths(adrcode, array_index);
645 /* unrecognised adrcode, or not-yet-handled ones! */
650 static char *sound_adrcodes_to_paths (int adrcode, int *array_index)
652 /* set array index like this in-case nothing sets it correctly */
655 /* result depends on adrcode */
661 /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */
665 return "attenuation";
668 /* unrecognised adrcode, or not-yet-handled ones! */
673 static char *world_adrcodes_to_paths (int adrcode, int *array_index)
675 /* set array index like this in-case nothing sets it correctly */
678 /* result depends on adrcode */
681 *array_index= 0; return "horizon_color";
683 *array_index= 1; return "horizon_color";
685 *array_index= 2; return "horizon_color";
687 *array_index= 0; return "zenith_color";
689 *array_index= 1; return "zenith_color";
691 *array_index= 2; return "zenith_color";
697 return "mist.intensity";
703 return "mist.height";
705 /* Star Color is unused -- recommend removal */
707 *array_index= 0; return "stars.color";
709 *array_index= 1; return "stars.color";
711 *array_index= 2; return "stars.color"; */
714 return "stars.min_distance";
718 default: /* for now, we assume that the others were MTex channels */
719 return mtex_adrcodes_to_paths(adrcode, array_index);
726 static char *particle_adrcodes_to_paths (int adrcode, int *array_index)
728 /* set array index like this in-case nothing sets it correctly */
731 /* result depends on adrcode */
734 return "settings.clump_factor";
736 return "settings.angular_velocity_factor";
738 return "settings.particle_size";
740 return "settings.drag_factor";
742 return "settings.brownian_factor";
744 return "settings.damp_factor";
746 return "settings.length";
748 *array_index= 0; return "settings.acceleration";
750 *array_index= 1; return "settings.acceleration";
752 *array_index= 2; return "settings.acceleration";
754 return "settings.kink_amplitude";
756 return "settings.kink_frequency";
757 case PART_KINK_SHAPE:
758 return "settings.kink_shape";
760 return "settings.billboard_tilt";
762 /* PartDeflect needs to be sorted out properly in rna_object_force;
763 If anyone else works on this, but is unfamiliar, these particular
764 settings reference the particles of the system themselves
765 being used as forces -- it will use the same rna structure
766 as the similar object forces */
768 if (part->pd) poin= &(part->pd->f_strength);
771 if (part->pd) poin= &(part->pd->f_power);
774 if (part->pd) poin= &(part->pd->maxdist);
777 if (part->pd2) poin= &(part->pd2->f_strength);
780 if (part->pd2) poin= &(part->pd2->f_power);
783 if (part->pd2) poin= &(part->pd2->maxdist);
793 /* Allocate memory for RNA-path for some property given a blocktype, adrcode, and 'root' parts of path
795 * - blocktype, adrcode - determines setting to get
796 * - actname, constname,seq - used to build path
798 * - array_index - index in property's array (if applicable) to use
799 * - return - the allocated path...
801 static char *get_rna_access (int blocktype, int adrcode, char actname[], char constname[], Sequence * seq, int *array_index)
803 DynStr *path= BLI_dynstr_new();
804 char *propname=NULL, *rpath=NULL;
808 /* hack: if constname is set, we can only be dealing with an Constraint curve */
812 /* get property name based on blocktype */
814 case ID_OB: /* object */
815 propname= ob_adrcodes_to_paths(adrcode, &dummy_index);
818 case ID_PO: /* pose channel */
819 propname= pchan_adrcodes_to_paths(adrcode, &dummy_index);
822 case ID_KE: /* shapekeys */
823 propname= shapekey_adrcodes_to_paths(adrcode, &dummy_index);
826 case ID_CO: /* constraint */
827 propname= constraint_adrcodes_to_paths(adrcode, &dummy_index);
830 case ID_TE: /* texture */
831 propname= texture_adrcodes_to_paths(adrcode, &dummy_index);
834 case ID_MA: /* material */
835 propname= material_adrcodes_to_paths(adrcode, &dummy_index);
838 case ID_CA: /* camera */
839 propname= camera_adrcodes_to_paths(adrcode, &dummy_index);
842 case ID_LA: /* lamp */
843 propname= lamp_adrcodes_to_paths(adrcode, &dummy_index);
846 case ID_SO: /* sound */
847 propname= sound_adrcodes_to_paths(adrcode, &dummy_index);
850 case ID_WO: /* world */
851 propname= world_adrcodes_to_paths(adrcode, &dummy_index);
854 case ID_PA: /* particle */
855 propname= particle_adrcodes_to_paths(adrcode, &dummy_index);
858 case ID_CU: /* curve */
859 /* this used to be a 'dummy' curve which got evaluated on the fly...
860 * now we've got real var for this!
862 propname= "eval_time";
865 /* XXX problematic blocktypes */
866 case ID_SEQ: /* sequencer strip */
870 propname= "effect_fader";
873 propname= "speed_fader";
875 case SEQ_FAC_OPACITY:
876 propname= "blend_opacity";
879 // poin= &(seq->facf0); // XXX this doesn't seem to be included anywhere in sequencer RNA...
884 /* special case for rotdiff drivers... we don't need a property for this... */
887 // TODO... add other blocktypes...
889 printf("IPO2ANIMATO WARNING: No path for blocktype %d, adrcode %d yet \n", blocktype, adrcode);
893 /* check if any property found
894 * - blocktype < 0 is special case for a specific type of driver, where we don't need a property name...
896 if ((propname == NULL) && (blocktype > 0)) {
897 /* nothing was found, so exit */
901 BLI_dynstr_free(path);
907 *array_index= dummy_index;
910 /* append preceding bits to path */
911 if ((actname && actname[0]) && (constname && constname[0])) {
912 /* Constraint in Pose-Channel */
913 sprintf(buf, "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
915 else if (actname && actname[0]) {
917 sprintf(buf, "pose.bones[\"%s\"]", actname);
919 else if (constname && constname[0]) {
920 /* Constraint in Object */
921 sprintf(buf, "constraints[\"%s\"]", constname);
924 /* Sequence names in Scene */
925 sprintf(buf, "sequence_editor.sequences_all[\"%s\"]",
929 strcpy(buf, ""); /* empty string */
930 BLI_dynstr_append(path, buf);
932 /* need to add dot before property if there was anything precceding this */
934 BLI_dynstr_append(path, ".");
936 /* now write name of property */
937 BLI_dynstr_append(path, propname);
939 /* if there was no array index pointer provided, add it to the path */
940 if (array_index == NULL) {
941 sprintf(buf, "[\"%d\"]", dummy_index);
942 BLI_dynstr_append(path, buf);
945 /* convert to normal MEM_malloc'd string */
946 rpath= BLI_dynstr_get_cstring(path);
947 BLI_dynstr_free(path);
953 /* *************************************************** */
954 /* Conversion Utilities */
956 /* Convert adrcodes to driver target transform channel types */
957 static short adrcode_to_dtar_transchan (short adrcode)
961 return DTAR_TRANSCHAN_LOCX;
963 return DTAR_TRANSCHAN_LOCY;
965 return DTAR_TRANSCHAN_LOCZ;
968 return DTAR_TRANSCHAN_ROTX;
970 return DTAR_TRANSCHAN_ROTY;
972 return DTAR_TRANSCHAN_ROTZ;
975 return DTAR_TRANSCHAN_SCALEX;
977 return DTAR_TRANSCHAN_SCALEX;
979 return DTAR_TRANSCHAN_SCALEX;
986 /* Convert IpoDriver to ChannelDriver - will free the old data (i.e. the old driver) */
987 static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
989 ChannelDriver *cdriver;
991 /* allocate memory for new driver */
992 cdriver= MEM_callocN(sizeof(ChannelDriver), "ChannelDriver");
994 /* if 'pydriver', just copy data across */
995 if (idriver->type == IPO_DRIVER_TYPE_PYTHON) {
996 /* PyDriver only requires the expression to be copied */
997 // FIXME: expression will be useless due to API changes, but at least not totally lost
998 cdriver->type = DRIVER_TYPE_PYTHON;
999 if (idriver->name[0])
1000 BLI_strncpy(cdriver->expression, idriver->name, sizeof(cdriver->expression));
1003 DriverVar *dvar = NULL;
1004 DriverTarget *dtar = NULL;
1006 /* this should be ok for all types here... */
1007 cdriver->type= DRIVER_TYPE_AVERAGE;
1009 /* what to store depends on the 'blocktype' - object or posechannel */
1010 if (idriver->blocktype == ID_AR) { /* PoseChannel */
1011 if (idriver->adrcode == OB_ROT_DIFF) {
1012 /* Rotational Difference requires a special type of variable */
1013 dvar= driver_add_new_variable(cdriver);
1014 driver_change_variable_type(dvar, DVAR_TYPE_ROT_DIFF);
1016 /* first bone target */
1017 dtar= &dvar->targets[0];
1018 dtar->id= (ID *)idriver->ob;
1019 if (idriver->name[0])
1020 BLI_strncpy(dtar->pchan_name, idriver->name, 32);
1022 /* second bone target (name was stored in same var as the first one) */
1023 dtar= &dvar->targets[1];
1024 dtar->id= (ID *)idriver->ob;
1025 if (idriver->name[0]) // xxx... for safety
1026 BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, 32);
1029 /* only a single variable, of type 'transform channel' */
1030 dvar= driver_add_new_variable(cdriver);
1031 driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);
1033 /* only requires a single target */
1034 dtar= &dvar->targets[0];
1035 dtar->id= (ID *)idriver->ob;
1036 if (idriver->name[0])
1037 BLI_strncpy(dtar->pchan_name, idriver->name, 32);
1038 dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
1039 dtar->flag |= DTAR_FLAG_LOCALSPACE; /* old drivers took local space */
1043 /* only a single variable, of type 'transform channel' */
1044 dvar= driver_add_new_variable(cdriver);
1045 driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);
1047 /* only requires single target */
1048 dtar= &dvar->targets[0];
1049 dtar->id= (ID *)idriver->ob;
1050 dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
1054 /* return the new one */
1058 /* Add F-Curve to the correct list
1059 * - grpname is needed to be used as group name where relevant, and is usually derived from actname
1061 static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, char *grpname, int muteipo)
1063 /* If we're adding to an action, we will have groups to write to... */
1064 if (groups && grpname) {
1065 /* wrap the pointers given into a dummy action that we pass to the API func
1066 * and extract the resultant lists...
1069 bActionGroup *agrp= NULL;
1071 /* init the temp action */
1072 memset(&tmp_act, 0, sizeof(bAction)); // XXX only enable this line if we get errors
1073 tmp_act.groups.first= groups->first;
1074 tmp_act.groups.last= groups->last;
1075 tmp_act.curves.first= list->first;
1076 tmp_act.curves.last= list->last;
1077 /* ... xxx, the other vars don't need to be filled in */
1079 /* get the group to use */
1080 agrp= action_groups_find_named(&tmp_act, grpname);
1082 /* no matching group, so add one */
1084 /* Add a new group, and make it active */
1085 agrp= MEM_callocN(sizeof(bActionGroup), "bActionGroup");
1087 agrp->flag = AGRP_SELECTED;
1088 if (muteipo) agrp->flag |= AGRP_MUTED;
1090 strncpy(agrp->name, grpname, sizeof(agrp->name));
1092 BLI_addtail(&tmp_act.groups, agrp);
1093 BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
1097 /* add F-Curve to group */
1098 /* WARNING: this func should only need to look at the stuff we initialised, if not, things may crash */
1099 action_groups_add_channel(&tmp_act, agrp, fcu);
1101 if (agrp->flag & AGRP_MUTED) /* flush down */
1102 fcu->flag |= FCURVE_MUTED;
1104 /* set the output lists based on the ones in the temp action */
1105 groups->first= tmp_act.groups.first;
1106 groups->last= tmp_act.groups.last;
1107 list->first= tmp_act.curves.first;
1108 list->last= tmp_act.curves.last;
1111 /* simply add the F-Curve to the end of the given list */
1112 BLI_addtail(list, fcu);
1116 /* Convert IPO-Curve to F-Curve (including Driver data), and free any of the old data that
1117 * is not relevant, BUT do not free the IPO-Curve itself...
1118 * actname: name of Action-Channel (if applicable) that IPO-Curve's IPO-block belonged to
1119 * constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to
1120 * seq: sequencer-strip (if applicable) that IPO-Curve's IPO-block belonged to
1122 static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *icu, char *actname, char *constname, Sequence * seq, int muteipo)
1126 unsigned int i=0, totbits;
1128 /* allocate memory for a new F-Curve */
1129 fcu= MEM_callocN(sizeof(FCurve), "FCurve");
1131 /* convert driver */
1133 fcu->driver= idriver_to_cdriver(icu->driver);
1136 if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE;
1137 if (icu->flag & IPO_SELECT) fcu->flag |= FCURVE_SELECTED;
1138 if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
1139 if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
1140 if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
1141 if (icu->flag & IPO_AUTO_HORIZ) fcu->flag |= FCURVE_AUTO_HANDLES;
1143 /* set extrapolation */
1144 switch (icu->extrap) {
1145 case IPO_HORIZ: /* constant extrapolation */
1146 case IPO_DIR: /* linear extrapolation */
1148 /* just copy, as the new defines match the old ones... */
1149 fcu->extend= icu->extrap;
1153 case IPO_CYCL: /* cyclic extrapolation */
1154 case IPO_CYCLX: /* cyclic extrapolation + offset */
1156 /* Add a new FModifier (Cyclic) instead of setting extend value
1157 * as that's the new equivilant of that option.
1159 FModifier *fcm= add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES);
1160 FMod_Cycles *data= (FMod_Cycles *)fcm->data;
1162 /* if 'offset' one is in use, set appropriate settings */
1163 if (icu->extrap == IPO_CYCLX)
1164 data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET;
1166 data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC;
1173 /* get adrcode <-> bitflags mapping to handle nasty bitflag curves? */
1174 abp= adrcode_bitmaps_to_paths(icu->blocktype, icu->adrcode, &totbits);
1175 if (abp && totbits) {
1179 if (G.f & G_DEBUG) printf("\tconvert bitflag ipocurve, totbits = %d \n", totbits);
1181 /* add the 'only int values' flag */
1182 fcu->flag |= (FCURVE_INT_VALUES|FCURVE_DISCRETE_VALUES);
1184 /* for each bit we have to remap + check for:
1185 * 1) we need to make copy the existing F-Curve data (fcu -> fcurve),
1186 * except for the last one which will use the original
1187 * 2) copy the relevant path info across
1188 * 3) filter the keyframes for the flag of interest
1190 for (b=0; b < totbits; b++, abp++) {
1191 /* make a copy of existing base-data if not the last curve */
1192 if (b < (totbits-1))
1193 fcurve= copy_fcurve(fcu);
1198 fcurve->rna_path= BLI_strdupn(abp->path, strlen(abp->path));
1199 fcurve->array_index= abp->array_index;
1201 /* convert keyframes
1202 * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time
1203 * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet)
1205 fcurve->totvert= icu->totvert;
1208 BezTriple *dst, *src;
1210 /* allocate new array for keyframes/beztriples */
1211 fcurve->bezt= MEM_callocN(sizeof(BezTriple)*fcurve->totvert, "BezTriples");
1213 /* loop through copying all BezTriples individually, as we need to modify a few things */
1214 for (dst=fcurve->bezt, src=icu->bezt; i < fcurve->totvert; i++, dst++, src++) {
1215 /* firstly, copy BezTriple data */
1218 /* interpolation can only be constant... */
1219 dst->ipo= BEZT_IPO_CONST;
1221 /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
1222 dst->hide= BEZT_KEYTYPE_KEYFRAME;
1224 /* correct values, by checking if the flag of interest is set */
1225 if ( ((int)(dst->vec[1][1])) & (abp->bit) )
1226 dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 1.0f;
1228 dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 0.0f;
1232 /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */
1237 /* add new F-Curve to list */
1238 fcurve_add_to_list(groups, list, fcurve, actname, muteipo);
1243 * - we will need to set the 'disabled' flag if no path is able to be made (for now)
1245 fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, seq, &fcu->array_index);
1246 if (fcu->rna_path == NULL)
1247 fcu->flag |= FCURVE_DISABLED;
1249 /* convert keyframes
1250 * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time
1251 * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet)
1253 fcu->totvert= icu->totvert;
1256 BezTriple *dst, *src;
1258 /* allocate new array for keyframes/beztriples */
1259 fcu->bezt= MEM_callocN(sizeof(BezTriple)*fcu->totvert, "BezTriples");
1261 /* loop through copying all BezTriples individually, as we need to modify a few things */
1262 for (dst=fcu->bezt, src=icu->bezt; i < fcu->totvert; i++, dst++, src++) {
1263 /* firstly, copy BezTriple data */
1266 /* now copy interpolation from curve (if not already set) */
1267 if (icu->ipo != IPO_MIXED)
1270 /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
1271 dst->hide= BEZT_KEYTYPE_KEYFRAME;
1273 /* correct values for euler rotation curves
1274 * - they were degrees/10
1275 * - we need radians for RNA to do the right thing
1277 if ( ((icu->blocktype == ID_OB) && ELEM3(icu->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) ||
1278 ((icu->blocktype == ID_PO) && ELEM3(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z)) )
1280 const float fac= (float)M_PI / 18.0f; //10.0f * M_PI/180.0f;
1282 dst->vec[0][1] *= fac;
1283 dst->vec[1][1] *= fac;
1284 dst->vec[2][1] *= fac;
1287 /* correct values for path speed curves
1288 * - their values were 0-1
1289 * - we now need as 'frames'
1291 if ( (id) && (icu->blocktype == GS(id->name)) &&
1292 (fcu->rna_path && strcmp(fcu->rna_path, "eval_time")==0) )
1294 Curve *cu = (Curve *)id;
1296 dst->vec[0][1] *= cu->pathlen;
1297 dst->vec[1][1] *= cu->pathlen;
1298 dst->vec[2][1] *= cu->pathlen;
1301 /* correct times for rotation drivers
1302 * - need to go from degrees to radians...
1303 * - there's only really 1 target to worry about
1304 * - were also degrees/10
1306 if (fcu->driver && fcu->driver->variables.first) {
1307 DriverVar *dvar= fcu->driver->variables.first;
1308 DriverTarget *dtar= &dvar->targets[0];
1310 if (ELEM3(dtar->transChan, DTAR_TRANSCHAN_ROTX, DTAR_TRANSCHAN_ROTY, DTAR_TRANSCHAN_ROTZ)) {
1311 const float fac= (float)M_PI / 18.0f;
1313 dst->vec[0][0] *= fac;
1314 dst->vec[1][0] *= fac;
1315 dst->vec[2][0] *= fac;
1319 /* correct values for sequencer curves,
1320 that were not locked to frame */
1323 (seq->flag & SEQ_IPO_FRAME_LOCKED) == 0) {
1324 double mul= (seq->enddisp-seq->startdisp)/100.0f;
1325 double offset= seq->startdisp;
1327 dst->vec[0][0] *= mul;
1328 dst->vec[0][0] += offset;
1330 dst->vec[1][0] *= mul;
1331 dst->vec[1][0] += offset;
1333 dst->vec[2][0] *= mul;
1334 dst->vec[2][0] += offset;
1339 /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */
1344 /* add new F-Curve to list */
1345 fcurve_add_to_list(groups, list, fcu, actname, muteipo);
1349 /* ------------------------- */
1351 /* Convert IPO-block (i.e. all its IpoCurves) to the new system.
1352 * This does not assume that any ID or AnimData uses it, but does assume that
1353 * it is given two lists, which it will perform driver/animation-data separation.
1355 static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], Sequence * seq, ListBase *animgroups, ListBase *anim, ListBase *drivers)
1360 if (ELEM3(NULL, ipo, anim, drivers))
1363 if (G.f & G_DEBUG) printf("ipo_to_animato \n");
1365 /* validate actname and constname
1366 * - clear actname if it was one of the generic <builtin> ones (i.e. 'Object', or 'Shapes')
1367 * - actname can then be used to assign F-Curves in Action to Action Groups
1368 * (i.e. thus keeping the benefits that used to be provided by Action Channels for grouping
1369 * F-Curves for bones). This may be added later... for now let's just dump without them...
1372 if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Object") == 0))
1374 else if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Shape") == 0))
1378 /* loop over IPO-Curves, freeing as we progress */
1379 for (icu= ipo->curve.first; icu; icu= icu->next) {
1380 /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves),
1381 * we figure out the best place to put the channel, then tell the curve-converter to just dump there
1384 /* Blender 2.4x allowed empty drivers, but we don't now, since they cause more trouble than they're worth */
1385 if ((icu->driver->ob) || (icu->driver->type == IPO_DRIVER_TYPE_PYTHON)) {
1386 icu_to_fcurves(id, NULL, drivers, icu, actname, constname, seq, ipo->muteipo);
1389 MEM_freeN(icu->driver);
1394 icu_to_fcurves(id, animgroups, anim, icu, actname, constname, seq, ipo->muteipo);
1397 /* if this IPO block doesn't have any users after this one, free... */
1399 if ( (ipo->id.us == 0) || ((ipo->id.us == 1) && (ipo->id.flag & LIB_FAKEUSER)) )
1403 for (icu= ipo->curve.first; icu; icu= icn) {
1408 MEM_freeN(icu->driver);
1410 /* free old data of curve now that it's no longer needed for converting any more curves */
1411 if (icu->bezt) MEM_freeN(icu->bezt);
1412 if (icu->bp) MEM_freeN(icu->bezt);
1414 /* free this IPO-Curve */
1415 BLI_freelinkN(&ipo->curve, icu);
1420 /* Convert Action-block to new system, separating animation and drivers
1421 * New curves may not be converted directly into the given Action (i.e. for Actions linked
1422 * to Objects, where ob->ipo and ob->action need to be combined).
1423 * NOTE: we need to be careful here, as same data-structs are used for new system too!
1425 static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase *curves, ListBase *drivers)
1427 bActionChannel *achan, *achann;
1428 bConstraintChannel *conchan, *conchann;
1430 /* only continue if there are Action Channels (indicating unconverted data) */
1431 if (act->chanbase.first == NULL)
1434 /* get rid of all Action Groups */
1435 // XXX this is risky if there's some old + some new data in the Action...
1436 if (act->groups.first)
1437 BLI_freelistN(&act->groups);
1439 /* loop through Action-Channels, converting data, freeing as we go */
1440 for (achan= act->chanbase.first; achan; achan= achann) {
1441 /* get pointer to next Action Channel */
1442 achann= achan->next;
1444 /* convert Action Channel's IPO data */
1446 ipo_to_animato(id, achan->ipo, achan->name, NULL, NULL, groups, curves, drivers);
1447 achan->ipo->id.us--;
1451 /* convert constraint channel IPO-data */
1452 for (conchan= achan->constraintChannels.first; conchan; conchan= conchann) {
1453 /* get pointer to next Constraint Channel */
1454 conchann= conchan->next;
1456 /* convert Constraint Channel's IPO data */
1458 ipo_to_animato(id, conchan->ipo, achan->name, conchan->name, NULL, groups, curves, drivers);
1459 conchan->ipo->id.us--;
1463 /* free Constraint Channel */
1464 BLI_freelinkN(&achan->constraintChannels, conchan);
1467 /* free Action Channel */
1468 BLI_freelinkN(&act->chanbase, achan);
1473 /* ------------------------- */
1475 /* Convert IPO-block (i.e. all its IpoCurves) for some ID to the new system
1476 * This assumes that AnimData has been added already. Separation of drivers
1477 * from animation data is accomplished here too...
1479 static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], Sequence * seq)
1481 AnimData *adt= BKE_animdata_from_id(id);
1482 ListBase anim = {NULL, NULL};
1483 ListBase drivers = {NULL, NULL};
1486 if ELEM(NULL, id, ipo)
1489 printf("ERROR ipo_to_animdata(): adt invalid \n");
1493 if (G.f & G_DEBUG) {
1494 printf("ipo to animdata - ID:%s, IPO:%s, actname:%s constname:%s seqname:%s curves:%d \n",
1495 id->name+2, ipo->id.name+2, (actname)?actname:"<None>", (constname)?constname:"<None>", (seq)?(seq->name+2):"<None>",
1496 BLI_countlist(&ipo->curve));
1499 /* Convert curves to animato system (separated into separate lists of F-Curves for animation and drivers),
1500 * and the try to put these lists in the right places, but do not free the lists here
1502 // XXX there shouldn't be any need for the groups, so don't supply pointer for that now...
1503 ipo_to_animato(id, ipo, actname, constname, seq, NULL, &anim, &drivers);
1505 /* deal with animation first */
1507 if (G.f & G_DEBUG) printf("\thas anim \n");
1508 /* try to get action */
1509 if (adt->action == NULL) {
1510 adt->action= add_empty_action("ConvData_Action"); // XXX we need a better name for this
1511 if (G.f & G_DEBUG) printf("\t\tadded new action \n");
1514 /* add F-Curves to action */
1515 addlisttolist(&adt->action->curves, &anim);
1518 /* deal with drivers */
1519 if (drivers.first) {
1520 if (G.f & G_DEBUG) printf("\thas drivers \n");
1521 /* add drivers to end of driver stack */
1522 addlisttolist(&adt->drivers, &drivers);
1526 /* Convert Action-block to new system
1527 * NOTE: we need to be careful here, as same data-structs are used for new system too!
1529 static void action_to_animdata (ID *id, bAction *act)
1531 AnimData *adt= BKE_animdata_from_id(id);
1533 /* only continue if there are Action Channels (indicating unconverted data) */
1534 if (ELEM(NULL, adt, act->chanbase.first))
1537 /* check if we need to set this Action as the AnimData's action */
1538 if (adt->action == NULL) {
1539 /* set this Action as AnimData's Action */
1540 if (G.f & G_DEBUG) printf("act_to_adt - set adt action to act \n");
1544 /* convert Action data */
1545 action_to_animato(id, act, &adt->action->groups, &adt->action->curves, &adt->drivers);
1548 /* ------------------------- */
1551 // - NLA group duplicators info
1552 // - NLA curve/stride modifiers...
1554 /* Convert NLA-Strip to new system */
1555 static void nlastrips_to_animdata (ID *id, ListBase *strips)
1557 AnimData *adt= BKE_animdata_from_id(id);
1558 NlaTrack *nlt = NULL;
1560 bActionStrip *as, *asn;
1562 /* for each one of the original strips, convert to a new strip and free the old... */
1563 for (as= strips->first; as; as= asn) {
1566 /* this old strip is only worth something if it had an action... */
1568 /* convert Action data (if not yet converted), storing the results in the same Action */
1569 action_to_animato(id, as->act, &as->act->groups, &as->act->curves, &adt->drivers);
1571 /* create a new-style NLA-strip which references this Action, then copy over relevant settings */
1573 /* init a new strip, and assign the action to it
1574 * - no need to muck around with the user-counts, since this is just
1575 * passing over the ref to the new owner, not creating an additional ref
1577 strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip");
1578 strip->act= as->act;
1581 strip->start= as->start;
1582 strip->end= as->end;
1583 strip->actstart= as->actstart;
1584 strip->actend= as->actend;
1587 strip->repeat= as->repeat;
1588 strip->scale= as->scale;
1589 if (as->flag & ACTSTRIP_LOCK_ACTION) strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH;
1592 strip->blendin= as->blendin;
1593 strip->blendout= as->blendout;
1594 strip->blendmode= (as->mode==ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_REPLACE;
1595 if (as->flag & ACTSTRIP_AUTO_BLENDS) strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS;
1597 /* assorted setting flags */
1598 if (as->flag & ACTSTRIP_SELECT) strip->flag |= NLASTRIP_FLAG_SELECT;
1599 if (as->flag & ACTSTRIP_ACTIVE) strip->flag |= NLASTRIP_FLAG_ACTIVE;
1601 if (as->flag & ACTSTRIP_MUTE) strip->flag |= NLASTRIP_FLAG_MUTED;
1602 if (as->flag & ACTSTRIP_REVERSE) strip->flag |= NLASTRIP_FLAG_REVERSE;
1604 /* by default, we now always extrapolate, while in the past this was optional */
1605 if ((as->flag & ACTSTRIP_HOLDLASTFRAME)==0)
1606 strip->extendmode= NLASTRIP_EXTEND_NOTHING;
1609 /* try to add this strip to the current NLA-Track (i.e. the 'last' one on the stack atm) */
1610 if (BKE_nlatrack_add_strip(nlt, strip) == 0) {
1611 /* trying to add to the current failed (no space),
1612 * so add a new track to the stack, and add to that...
1614 nlt= add_nlatrack(adt, NULL);
1615 BKE_nlatrack_add_strip(nlt, strip);
1620 // FIXME: for now, we just free them...
1621 if (as->modifiers.first)
1622 BLI_freelistN(&as->modifiers);
1624 /* free the old strip */
1625 BLI_freelinkN(strips, as);
1629 /* *************************************************** */
1630 /* External API - Only Called from do_versions() */
1632 /* Called from do_versions() in readfile.c to convert the old 'IPO/adrcode' system
1633 * to the new 'Animato/RNA' system.
1635 * The basic method used here, is to loop over datablocks which have IPO-data, and
1636 * add those IPO's to new AnimData blocks as Actions.
1637 * Action/NLA data only works well for Objects, so these only need to be checked for there.
1639 * Data that has been converted should be freed immediately, which means that it is immediately
1640 * clear which datablocks have yet to be converted, and also prevent freeing errors when we exit.
1642 // XXX currently done after all file reading...
1643 void do_versions_ipos_to_animato(Main *main)
1645 ListBase drivers = {NULL, NULL};
1650 printf("Argh! Main is NULL in do_versions_ipos_to_animato() \n");
1654 /* only convert if version is right */
1655 if (main->versionfile >= 250) {
1656 printf("WARNING: Animation data too new to convert (Version %d) \n", main->versionfile);
1659 else if (G.f & G_DEBUG)
1660 printf("INFO: Converting to Animato... \n");
1662 /* ----------- Animation Attached to Data -------------- */
1665 for (id= main->object.first; id; id= id->next) {
1666 Object *ob= (Object *)id;
1667 bPoseChannel *pchan;
1669 bConstraintChannel *conchan, *conchann;
1671 if (G.f & G_DEBUG) printf("\tconverting ob %s \n", id->name+2);
1673 /* check if object has any animation data */
1674 if (ob->nlastrips.first) {
1675 /* Add AnimData block */
1676 adt= BKE_id_add_animdata(id);
1678 /* IPO first to take into any non-NLA'd Object Animation */
1680 ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
1686 /* Action is skipped since it'll be used by some strip in the NLA anyway,
1687 * causing errors with evaluation in the new evaluation pipeline
1690 ob->action->id.us--;
1695 nlastrips_to_animdata(id, &ob->nlastrips);
1697 else if ((ob->ipo) || (ob->action)) {
1698 /* Add AnimData block */
1699 adt= BKE_id_add_animdata(id);
1701 /* Action first - so that Action name get conserved */
1703 action_to_animdata(id, ob->action);
1705 /* only decrease usercount if this Action isn't now being used by AnimData */
1706 if (ob->action != adt->action) {
1707 ob->action->id.us--;
1714 ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
1720 /* check PoseChannels for constraints with local data */
1722 /* Verify if there's AnimData block */
1723 BKE_id_add_animdata(id);
1725 for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1726 for (con= pchan->constraints.first; con; con= con->next) {
1727 /* if constraint has own IPO, convert add these to Object
1728 * (NOTE: they're most likely to be drivers too)
1731 /* although this was the constraint's local IPO, we still need to provide pchan + con
1732 * so that drivers can be added properly...
1734 ipo_to_animdata(id, con->ipo, pchan->name, con->name, NULL);
1742 /* check constraints for local IPO's */
1743 for (con= ob->constraints.first; con; con= con->next) {
1744 /* if constraint has own IPO, convert add these to Object
1745 * (NOTE: they're most likely to be drivers too)
1748 /* Verify if there's AnimData block, just in case */
1749 BKE_id_add_animdata(id);
1751 /* although this was the constraint's local IPO, we still need to provide con
1752 * so that drivers can be added properly...
1754 ipo_to_animdata(id, con->ipo, NULL, con->name, NULL);
1759 /* check for Action Constraint */
1760 // XXX do we really want to do this here?
1763 /* check constraint channels - we need to remove them anyway... */
1764 if (ob->constraintChannels.first) {
1765 /* Verify if there's AnimData block */
1766 BKE_id_add_animdata(id);
1768 for (conchan= ob->constraintChannels.first; conchan; conchan= conchann) {
1769 /* get pointer to next Constraint Channel */
1770 conchann= conchan->next;
1772 /* convert Constraint Channel's IPO data */
1774 ipo_to_animdata(id, conchan->ipo, NULL, conchan->name, NULL);
1775 conchan->ipo->id.us--;
1779 /* free Constraint Channel */
1780 BLI_freelinkN(&ob->constraintChannels, conchan);
1786 for (id= main->key.first; id; id= id->next) {
1787 Key *key= (Key *)id;
1789 if (G.f & G_DEBUG) printf("\tconverting key %s \n", id->name+2);
1791 /* we're only interested in the IPO
1792 * NOTE: for later, it might be good to port these over to Object instead, as many of these
1793 * are likely to be drivers, but it's hard to trace that from here, so move this to Ob loop?
1796 /* Add AnimData block */
1797 adt= BKE_id_add_animdata(id);
1799 /* Convert Shapekey data... */
1800 ipo_to_animdata(id, key->ipo, NULL, NULL, NULL);
1807 for (id= main->mat.first; id; id= id->next) {
1808 Material *ma= (Material *)id;
1810 if (G.f & G_DEBUG) printf("\tconverting material %s \n", id->name+2);
1812 /* we're only interested in the IPO */
1814 /* Add AnimData block */
1815 adt= BKE_id_add_animdata(id);
1817 /* Convert Material data... */
1818 ipo_to_animdata(id, ma->ipo, NULL, NULL, NULL);
1825 for (id= main->world.first; id; id= id->next) {
1826 World *wo= (World *)id;
1828 if (G.f & G_DEBUG) printf("\tconverting world %s \n", id->name+2);
1830 /* we're only interested in the IPO */
1832 /* Add AnimData block */
1833 adt= BKE_id_add_animdata(id);
1835 /* Convert World data... */
1836 ipo_to_animdata(id, wo->ipo, NULL, NULL, NULL);
1842 /* sequence strips */
1843 for (id= main->scene.first; id; id= id->next) {
1844 Scene *scene = (Scene *)id;
1845 Editing * ed = scene->ed;
1846 if (ed && ed->seqbasep) {
1849 adt= BKE_id_add_animdata(id);
1851 SEQ_BEGIN(ed, seq) {
1852 IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL;
1853 short adrcode = SEQ_FAC1;
1856 printf("\tconverting sequence strip %s \n", seq->name+2);
1858 if (ELEM(NULL, seq->ipo, icu)) {
1859 seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE;
1863 /* patch adrcode, so that we can map
1864 to different DNA variables later
1873 adrcode = SEQ_FAC_OPACITY;
1876 adrcode = SEQ_FAC_SPEED;
1879 icu->adrcode = adrcode;
1882 ipo_to_animdata((ID *)scene, seq->ipo, NULL, NULL, seq);
1892 for (id= main->tex.first; id; id= id->next) {
1895 if (G.f & G_DEBUG) printf("\tconverting texture %s \n", id->name+2);
1897 /* we're only interested in the IPO */
1899 /* Add AnimData block */
1900 adt= BKE_id_add_animdata(id);
1902 /* Convert Texture data... */
1903 ipo_to_animdata(id, te->ipo, NULL, NULL, NULL);
1910 for (id= main->camera.first; id; id= id->next) {
1911 Camera *ca= (Camera *)id;
1913 if (G.f & G_DEBUG) printf("\tconverting camera %s \n", id->name+2);
1915 /* we're only interested in the IPO */
1917 /* Add AnimData block */
1918 adt= BKE_id_add_animdata(id);
1920 /* Convert Camera data... */
1921 ipo_to_animdata(id, ca->ipo, NULL, NULL, NULL);
1928 for (id= main->lamp.first; id; id= id->next) {
1929 Lamp *la= (Lamp *)id;
1931 if (G.f & G_DEBUG) printf("\tconverting lamp %s \n", id->name+2);
1933 /* we're only interested in the IPO */
1935 /* Add AnimData block */
1936 adt= BKE_id_add_animdata(id);
1938 /* Convert Lamp data... */
1939 ipo_to_animdata(id, la->ipo, NULL, NULL, NULL);
1946 for (id= main->curve.first; id; id= id->next) {
1947 Curve *cu= (Curve *)id;
1949 if (G.f & G_DEBUG) printf("\tconverting curve %s \n", id->name+2);
1951 /* we're only interested in the IPO */
1953 /* Add AnimData block */
1954 adt= BKE_id_add_animdata(id);
1956 /* Convert Curve data... */
1957 ipo_to_animdata(id, cu->ipo, NULL, NULL, NULL);
1963 /* --------- Unconverted Animation Data ------------------ */
1964 /* For Animation data which may not be directly connected (i.e. not linked) to any other
1965 * data, we need to perform a separate pass to make sure that they are converted to standalone
1966 * Actions which may then be able to be reused. This does mean that we will be going over data that's
1967 * already been converted, but there are no problems with that.
1969 * The most common case for this will be Action Constraints, or IPO's with Fake-Users.
1970 * We collect all drivers that were found into a temporary collection, and free them in one go, as they're
1971 * impossible to resolve.
1975 for (id= main->action.first; id; id= id->next) {
1976 bAction *act= (bAction *)id;
1978 if (G.f & G_DEBUG) printf("\tconverting action %s \n", id->name+2);
1980 /* be careful! some of the actions we encounter will be converted ones... */
1981 action_to_animato(NULL, act, &act->groups, &act->curves, &drivers);
1985 for (id= main->ipo.first; id; id= id->next) {
1986 Ipo *ipo= (Ipo *)id;
1988 if (G.f & G_DEBUG) printf("\tconverting ipo %s \n", id->name+2);
1990 /* most likely this IPO has already been processed, so check if any curves left to convert */
1991 if (ipo->curve.first) {
1994 /* add a new action for this, and convert all data into that action */
1995 new_act= add_empty_action("ConvIPO_Action"); // XXX need a better name...
1996 ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers);
1999 /* clear fake-users, and set user-count to zero to make sure it is cleared on file-save */
2001 ipo->id.flag &= ~LIB_FAKEUSER;
2004 /* free unused drivers from actions + ipos */
2005 free_fcurves(&drivers);
2008 printf("INFO: Animato convert done \n");