2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Joshua Leung (full recode)
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/blenkernel/intern/anim_sys.c
39 #include "MEM_guardedalloc.h"
41 #include "BLI_blenlib.h"
42 #include "BLI_dynstr.h"
43 #include "BLI_utildefines.h"
45 #include "DNA_anim_types.h"
46 #include "DNA_lamp_types.h"
47 #include "DNA_material_types.h"
48 #include "DNA_object_types.h"
49 #include "DNA_scene_types.h"
50 #include "DNA_texture_types.h"
51 #include "DNA_world_types.h"
53 #include "BKE_animsys.h"
54 #include "BKE_action.h"
55 #include "BKE_depsgraph.h"
56 #include "BKE_fcurve.h"
58 #include "BKE_global.h"
60 #include "BKE_library.h"
61 #include "BKE_report.h"
62 #include "BKE_utildefines.h"
64 #include "RNA_access.h"
66 #include "nla_private.h"
68 /* ***************************************** */
71 /* Getter/Setter -------------------------------------------- */
73 /* Check if ID can have AnimData */
74 short id_type_can_have_animdata (ID *id)
80 /* Only some ID-blocks have this info for now */
81 // TODO: finish adding this for the other blocktypes
82 switch (GS(id->name)) {
85 case ID_ME: case ID_MB: case ID_CU: case ID_AR: case ID_LT:
88 case ID_MA: case ID_TE: case ID_NT:
89 case ID_LA: case ID_CA: case ID_WO:
105 /* Get AnimData from the given ID-block. In order for this to work, we assume that
106 * the AnimData pointer is stored immediately after the given ID-block in the struct,
107 * as per IdAdtTemplate.
109 AnimData *BKE_animdata_from_id (ID *id)
111 /* only some ID-blocks have this info for now, so we cast the
112 * types that do to be of type IdAdtTemplate, and extract the
115 if (id_type_can_have_animdata(id)) {
116 IdAdtTemplate *iat= (IdAdtTemplate *)id;
123 /* Add AnimData to the given ID-block. In order for this to work, we assume that
124 * the AnimData pointer is stored immediately after the given ID-block in the struct,
125 * as per IdAdtTemplate. Also note that
127 AnimData *BKE_id_add_animdata (ID *id)
129 /* Only some ID-blocks have this info for now, so we cast the
130 * types that do to be of type IdAdtTemplate, and add the AnimData
131 * to it using the template
133 if (id_type_can_have_animdata(id)) {
134 IdAdtTemplate *iat= (IdAdtTemplate *)id;
136 /* check if there's already AnimData, in which case, don't add */
137 if (iat->adt == NULL) {
141 adt= iat->adt= MEM_callocN(sizeof(AnimData), "AnimData");
143 /* set default settings */
144 adt->act_influence= 1.0f;
153 /* Action Setter --------------------------------------- */
155 /* Called when user tries to change the active action of an AnimData block (via RNA, Outliner, etc.) */
156 short BKE_animdata_set_action (ReportList *reports, ID *id, bAction *act)
158 AnimData *adt = BKE_animdata_from_id(id);
161 /* animdata validity check */
163 BKE_report(reports, RPT_WARNING, "No AnimData to set action on");
167 /* active action is only editable when it is not a tweaking strip
168 * see rna_AnimData_action_editable() in rna_animation.c
170 if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) {
171 /* cannot remove, otherwise things turn to custard */
172 BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA");
176 /* manage usercount for current action */
178 id_us_min((ID*)adt->action);
180 /* assume that AnimData's action can in fact be edited... */
182 /* action must have same type as owner */
183 if (ELEM(act->idroot, 0, GS(id->name))) {
186 id_us_plus((ID*)adt->action);
191 BKE_reportf(reports, RPT_ERROR,
192 "Couldn't set Action '%s' onto ID '%s', as it doesn't have suitably rooted paths for this purpose",
193 act->id.name+2, id->name);
198 /* just clearing the action... */
206 /* Freeing -------------------------------------------- */
208 /* Free AnimData used by the nominated ID-block, and clear ID-block's AnimData pointer */
209 void BKE_free_animdata (ID *id)
211 /* Only some ID-blocks have this info for now, so we cast the
212 * types that do to be of type IdAdtTemplate
214 if (id_type_can_have_animdata(id)) {
215 IdAdtTemplate *iat= (IdAdtTemplate *)id;
216 AnimData *adt= iat->adt;
218 /* check if there's any AnimData to start with */
220 /* unlink action (don't free, as it's in its own list) */
222 adt->action->id.us--;
223 /* same goes for the temporarily displaced action */
225 adt->tmpact->id.us--;
228 free_nladata(&adt->nla_tracks);
230 /* free drivers - stored as a list of F-Curves */
231 free_fcurves(&adt->drivers);
236 /* free animdata now */
243 /* Freeing -------------------------------------------- */
245 /* Make a copy of the given AnimData - to be used when copying datablocks */
246 AnimData *BKE_copy_animdata (AnimData *adt, const short do_action)
250 /* sanity check before duplicating struct */
253 dadt= MEM_dupallocN(adt);
255 /* make a copy of action - at worst, user has to delete copies... */
257 dadt->action= copy_action(adt->action);
258 dadt->tmpact= copy_action(adt->tmpact);
261 id_us_plus((ID *)dadt->action);
262 id_us_plus((ID *)dadt->tmpact);
265 /* duplicate NLA data */
266 copy_nladata(&dadt->nla_tracks, &adt->nla_tracks);
268 /* duplicate drivers (F-Curves) */
269 copy_fcurves(&dadt->drivers, &adt->drivers);
271 /* don't copy overrides */
272 dadt->overrides.first= dadt->overrides.last= NULL;
278 int BKE_copy_animdata_id (ID *id_to, ID *id_from, const short do_action)
282 if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name)))
285 BKE_free_animdata(id_to);
287 adt = BKE_animdata_from_id(id_from);
289 IdAdtTemplate *iat = (IdAdtTemplate *)id_to;
290 iat->adt= BKE_copy_animdata(adt, do_action);
296 void BKE_copy_animdata_id_action(ID *id)
298 AnimData *adt= BKE_animdata_from_id(id);
301 id_us_min((ID *)adt->action);
302 adt->action= copy_action(adt->action);
305 id_us_min((ID *)adt->tmpact);
306 adt->tmpact= copy_action(adt->tmpact);
311 /* Make Local -------------------------------------------- */
313 static void make_local_strips(ListBase *strips)
317 for (strip=strips->first; strip; strip=strip->next) {
318 if (strip->act) make_local_action(strip->act);
319 if (strip->remap && strip->remap->target) make_local_action(strip->remap->target);
321 make_local_strips(&strip->strips);
325 /* Use local copy instead of linked copy of various ID-blocks */
326 void BKE_animdata_make_local(AnimData *adt)
330 /* Actions - Active and Temp */
331 if (adt->action) make_local_action(adt->action);
332 if (adt->tmpact) make_local_action(adt->tmpact);
334 if (adt->remap && adt->remap->target) make_local_action(adt->remap->target);
337 // TODO: need to remap the ID-targets too?
340 for (nlt=adt->nla_tracks.first; nlt; nlt=nlt->next)
341 make_local_strips(&nlt->strips);
345 /* When duplicating data (i.e. objects), drivers referring to the original data will
346 * get updated to point to the duplicated data (if drivers belong to the new data)
348 void BKE_relink_animdata (AnimData *adt)
355 if (adt->drivers.first) {
358 /* check each driver against all the base paths to see if any should go */
359 for (fcu= adt->drivers.first; fcu; fcu=fcu->next) {
360 ChannelDriver *driver= fcu->driver;
363 /* driver variables */
364 for (dvar= driver->variables.first; dvar; dvar=dvar->next) {
365 /* only change the used targets, since the others will need fixing manually anyway */
366 DRIVER_TARGETS_USED_LOOPER(dvar)
368 if (dtar->id && dtar->id->newid) {
369 dtar->id= dtar->id->newid;
372 DRIVER_TARGETS_LOOPER_END
378 /* Sub-ID Regrouping ------------------------------------------- */
380 /* helper heuristic for determining if a path is compatible with the basepath
381 * < path: (str) full RNA-path from some data (usually an F-Curve) to compare
382 * < basepath: (str) shorter path fragment to look for
383 * > returns (bool) whether there is a match
385 static short animpath_matches_basepath (const char path[], const char basepath[])
387 /* we need start of path to be basepath */
388 return (path && basepath) && (strstr(path, basepath) == path);
391 /* Move F-Curves in src action to dst action, setting up all the necessary groups
392 * for this to happen, but only if the F-Curves being moved have the appropriate
394 * - This is used when data moves from one datablock to another, causing the
395 * F-Curves to need to be moved over too
397 void action_move_fcurves_by_basepath (bAction *srcAct, bAction *dstAct, const char basepath[])
399 FCurve *fcu, *fcn=NULL;
402 if (ELEM3(NULL, srcAct, dstAct, basepath)) {
403 if (G.debug & G_DEBUG) {
404 printf("ERROR: action_partition_fcurves_by_basepath(%p, %p, %p) has insufficient info to work with\n",
405 (void *)srcAct, (void *)dstAct, (void *)basepath);
410 /* clear 'temp' flags on all groups in src, as we'll be needing them later
411 * to identify groups that we've managed to empty out here
413 action_groups_clear_tempflags(srcAct);
415 /* iterate over all src F-Curves, moving over the ones that need to be moved */
416 for (fcu = srcAct->curves.first; fcu; fcu = fcn) {
417 /* store next pointer in case we move stuff */
420 /* should F-Curve be moved over?
421 * - we only need the start of the path to match basepath
423 if (animpath_matches_basepath(fcu->rna_path, basepath)) {
424 bActionGroup *agrp = NULL;
428 /* make sure there will be a matching group on the other side for the migrants */
429 agrp = action_groups_find_named(dstAct, fcu->grp->name);
432 /* add a new one with a similar name (usually will be the same though) */
433 agrp = action_groups_add_new(dstAct, fcu->grp->name);
436 /* old groups should be tagged with 'temp' flags so they can be removed later
437 * if we remove everything from them
439 fcu->grp->flag |= AGRP_TEMP;
442 /* perform the migration now */
443 action_groups_remove_channel(srcAct, fcu);
446 action_groups_add_channel(dstAct, agrp, fcu);
448 BLI_addtail(&dstAct->curves, fcu);
452 /* cleanup groups (if present) */
453 if (srcAct->groups.first) {
454 bActionGroup *agrp, *grp=NULL;
456 for (agrp = srcAct->groups.first; agrp; agrp = grp) {
459 /* only tagged groups need to be considered - clearing these tags or removing them */
460 if (agrp->flag & AGRP_TEMP) {
461 /* if group is empty and tagged, then we can remove as this operation
462 * moved out all the channels that were formerly here
464 if (agrp->channels.first == NULL)
465 BLI_freelinkN(&srcAct->groups, agrp);
467 agrp->flag &= ~AGRP_TEMP;
473 /* Transfer the animation data from srcID to dstID where the srcID
474 * animation data is based off "basepath", creating new AnimData and
475 * associated data as necessary
477 void BKE_animdata_separate_by_basepath (ID *srcID, ID *dstID, ListBase *basepaths)
479 AnimData *srcAdt=NULL, *dstAdt=NULL;
483 if (ELEM(NULL, srcID, dstID)) {
484 if (G.debug & G_DEBUG)
485 printf("ERROR: no source or destination ID to separate AnimData with\n");
489 /* get animdata from src, and create for destination (if needed) */
490 srcAdt = BKE_animdata_from_id(srcID);
491 dstAdt = BKE_id_add_animdata(dstID);
493 if (ELEM(NULL, srcAdt, dstAdt)) {
494 if (G.debug & G_DEBUG)
495 printf("ERROR: no AnimData for this pair of ID's\n");
500 if (srcAdt->action) {
501 /* set up an action if necessary, and name it in a similar way so that it can be easily found again */
502 if (dstAdt->action == NULL) {
503 dstAdt->action = add_empty_action(srcAdt->action->id.name+2);
505 else if (dstAdt->action == srcAdt->action) {
506 printf("Argh! Source and Destination share animation! ('%s' and '%s' both use '%s') Making new empty action\n",
507 srcID->name, dstID->name, srcAdt->action->id.name);
509 // TODO: review this...
510 id_us_min(&dstAdt->action->id);
511 dstAdt->action = add_empty_action(dstAdt->action->id.name+2);
514 /* loop over base paths, trying to fix for each one... */
515 for (ld = basepaths->first; ld; ld = ld->next) {
516 const char *basepath = (const char *)ld->data;
517 action_move_fcurves_by_basepath(srcAdt->action, dstAdt->action, basepath);
522 if (srcAdt->drivers.first) {
523 FCurve *fcu, *fcn=NULL;
525 /* check each driver against all the base paths to see if any should go */
526 for (fcu = srcAdt->drivers.first; fcu; fcu = fcn) {
529 /* try each basepath in turn, but stop on the first one which works */
530 for (ld = basepaths->first; ld; ld = ld->next) {
531 const char *basepath = (const char *)ld->data;
533 if (animpath_matches_basepath(fcu->rna_path, basepath)) {
534 /* just need to change lists */
535 BLI_remlink(&srcAdt->drivers, fcu);
536 BLI_addtail(&dstAdt->drivers, fcu);
538 // TODO: add depsgraph flushing calls?
540 /* can stop now, as moved already */
548 /* Path Validation -------------------------------------------- */
550 /* Check if a given RNA Path is valid, by tracing it from the given ID, and seeing if we can resolve it */
551 static short check_rna_path_is_valid (ID *owner_id, const char *path)
553 PointerRNA id_ptr, ptr;
554 PropertyRNA *prop=NULL;
556 /* make initial RNA pointer to start resolving from */
557 RNA_id_pointer_create(owner_id, &id_ptr);
560 return RNA_path_resolve(&id_ptr, path, &ptr, &prop);
563 /* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate
564 * NOTE: we assume that oldName and newName have [" "] padding around them
566 static char *rna_path_rename_fix (ID *owner_id, const char *prefix, const char *oldName, const char *newName, char *oldpath, int verify_paths)
568 char *prefixPtr= strstr(oldpath, prefix);
569 char *oldNamePtr= strstr(oldpath, oldName);
570 int prefixLen= strlen(prefix);
571 int oldNameLen= strlen(oldName);
573 /* only start fixing the path if the prefix and oldName feature in the path,
574 * and prefix occurs immediately before oldName
576 if ( (prefixPtr && oldNamePtr) && (prefixPtr+prefixLen == oldNamePtr) ) {
577 /* if we haven't aren't able to resolve the path now, try again after fixing it */
578 if (!verify_paths || check_rna_path_is_valid(owner_id, oldpath) == 0) {
579 DynStr *ds= BLI_dynstr_new();
580 char *postfixPtr= oldNamePtr+oldNameLen;
581 char *newPath = NULL;
584 /* add the part of the string that goes up to the start of the prefix */
585 if (prefixPtr > oldpath) {
586 oldChar= prefixPtr[0];
588 BLI_dynstr_append(ds, oldpath);
589 prefixPtr[0]= oldChar;
593 BLI_dynstr_append(ds, prefix);
595 /* add the new name (complete with brackets) */
596 BLI_dynstr_append(ds, newName);
598 /* add the postfix */
599 BLI_dynstr_append(ds, postfixPtr);
601 /* create new path, and cleanup old data */
602 newPath= BLI_dynstr_get_cstring(ds);
605 /* check if the new path will solve our problems */
606 // TODO: will need to check whether this step really helps in practice
607 if (!verify_paths || check_rna_path_is_valid(owner_id, newPath)) {
608 /* free the old path, and return the new one, since we've solved the issues */
613 /* still couldn't resolve the path... so, might as well just leave it alone */
619 /* the old path doesn't need to be changed */
623 /* Check RNA-Paths for a list of F-Curves */
624 static void fcurves_path_rename_fix (ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *curves, int verify_paths)
628 /* we need to check every curve... */
629 for (fcu= curves->first; fcu; fcu= fcu->next) {
630 /* firstly, handle the F-Curve's own path */
632 fcu->rna_path= rna_path_rename_fix(owner_id, prefix, oldName, newName, fcu->rna_path, verify_paths);
636 /* Check RNA-Paths for a list of Drivers */
637 static void drivers_path_rename_fix(ID *owner_id, ID *ref_id, const char *prefix, const char *oldName, const char *newName,
638 const char *oldKey, const char *newKey, ListBase *curves, int verify_paths)
642 /* we need to check every curve - drivers are F-Curves too! */
643 for (fcu= curves->first; fcu; fcu= fcu->next) {
644 /* firstly, handle the F-Curve's own path */
646 fcu->rna_path= rna_path_rename_fix(owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths);
650 ChannelDriver *driver= fcu->driver;
653 /* driver variables */
654 for (dvar= driver->variables.first; dvar; dvar=dvar->next) {
655 /* only change the used targets, since the others will need fixing manually anyway */
656 DRIVER_TARGETS_USED_LOOPER(dvar)
658 /* rename RNA path */
659 if (dtar->rna_path && dtar->id)
660 dtar->rna_path= rna_path_rename_fix(dtar->id, prefix, oldKey, newKey, dtar->rna_path, verify_paths);
662 /* also fix the bone-name (if applicable) */
663 if (strstr(prefix, "bones")) {
664 if ( ((dtar->id) && (GS(dtar->id->name) == ID_OB) && (!ref_id || ((Object*)(dtar->id))->data == ref_id)) &&
665 (dtar->pchan_name[0]) && (strcmp(oldName, dtar->pchan_name)==0) )
667 BLI_strncpy(dtar->pchan_name, newName, sizeof(dtar->pchan_name));
671 DRIVER_TARGETS_LOOPER_END
677 /* Fix all RNA-Paths for Actions linked to NLA Strips */
678 static void nlastrips_path_rename_fix (ID *owner_id, const char *prefix, char *oldName, char *newName, ListBase *strips, int verify_paths)
682 /* recursively check strips, fixing only actions... */
683 for (strip= strips->first; strip; strip= strip->next) {
684 /* fix strip's action */
686 fcurves_path_rename_fix(owner_id, prefix, oldName, newName, &strip->act->curves, verify_paths);
687 /* ignore own F-Curves, since those are local... */
689 /* check sub-strips (if metas) */
690 nlastrips_path_rename_fix(owner_id, prefix, oldName, newName, &strip->strips, verify_paths);
694 /* Fix all RNA-Paths in the AnimData block used by the given ID block
695 * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
696 * i.e. pose.bones["Bone"]
698 void BKE_animdata_fix_paths_rename(ID *owner_id, AnimData *adt, ID *ref_id, const char *prefix, const char *oldName,
699 const char *newName, int oldSubscript, int newSubscript, int verify_paths)
704 /* if no AnimData, no need to proceed */
705 if (ELEM(NULL, owner_id, adt))
708 if ((oldName != NULL) && (newName != NULL)) {
709 /* pad the names with [" "] so that only exact matches are made */
710 oldN= BLI_sprintfN("[\"%s\"]", oldName);
711 newN= BLI_sprintfN("[\"%s\"]", newName);
714 oldN= BLI_sprintfN("[%d]", oldSubscript);
715 newN= BLI_sprintfN("[%d]", newSubscript);
718 /* Active action and temp action */
720 fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->action->curves, verify_paths);
722 fcurves_path_rename_fix(owner_id, prefix, oldN, newN, &adt->tmpact->curves, verify_paths);
724 /* Drivers - Drivers are really F-Curves */
725 drivers_path_rename_fix(owner_id, ref_id, prefix, oldName, newName, oldN, newN, &adt->drivers, verify_paths);
727 /* NLA Data - Animation Data for Strips */
728 for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next)
729 nlastrips_path_rename_fix(owner_id, prefix, oldN, newN, &nlt->strips, verify_paths);
731 /* free the temp names */
736 /* Whole Database Ops -------------------------------------------- */
738 /* apply the given callback function on all data in main database */
739 void BKE_animdata_main_cb (Main *mainptr, ID_AnimData_Edit_Callback func, void *user_data)
743 /* standard data version */
744 #define ANIMDATA_IDS_CB(first) \
745 for (id= first; id; id= id->next) { \
746 AnimData *adt= BKE_animdata_from_id(id); \
747 if (adt) func(id, adt, user_data); \
750 /* "embedded" nodetree cases (i.e. scene/material/texture->nodetree) */
751 #define ANIMDATA_NODETREE_IDS_CB(first, NtId_Type) \
752 for (id= first; id; id= id->next) { \
753 AnimData *adt= BKE_animdata_from_id(id); \
754 NtId_Type *ntp= (NtId_Type *)id; \
755 if (ntp->nodetree) { \
756 AnimData *adt2= BKE_animdata_from_id((ID *)ntp); \
757 if (adt2) func(id, adt2, user_data); \
759 if (adt) func(id, adt, user_data); \
763 ANIMDATA_IDS_CB(mainptr->nodetree.first);
766 ANIMDATA_NODETREE_IDS_CB(mainptr->tex.first, Tex);
769 ANIMDATA_IDS_CB(mainptr->lamp.first);
772 ANIMDATA_NODETREE_IDS_CB(mainptr->mat.first, Material);
775 ANIMDATA_IDS_CB(mainptr->camera.first);
778 ANIMDATA_IDS_CB(mainptr->key.first);
781 ANIMDATA_IDS_CB(mainptr->mball.first);
784 ANIMDATA_IDS_CB(mainptr->curve.first);
787 ANIMDATA_IDS_CB(mainptr->armature.first);
790 ANIMDATA_IDS_CB(mainptr->latt.first);
793 ANIMDATA_IDS_CB(mainptr->mesh.first);
796 ANIMDATA_IDS_CB(mainptr->particle.first);
799 ANIMDATA_IDS_CB(mainptr->speaker.first);
802 ANIMDATA_IDS_CB(mainptr->movieclip.first);
805 ANIMDATA_IDS_CB(mainptr->object.first);
808 ANIMDATA_IDS_CB(mainptr->world.first);
811 ANIMDATA_NODETREE_IDS_CB(mainptr->scene.first, Scene);
814 ANIMDATA_IDS_CB(mainptr->linestyle.first);
817 /* Fix all RNA-Paths throughout the database (directly access the Global.main version)
818 * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]>
819 * i.e. pose.bones["Bone"]
821 /* TODO: use BKE_animdata_main_cb for looping over all data */
822 void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const char *oldName, const char *newName)
824 Main *mainptr= G.main;
827 /* macro for less typing
828 * - whether animdata exists is checked for by the main renaming callback, though taking
829 * this outside of the function may make things slightly faster?
831 #define RENAMEFIX_ANIM_IDS(first) \
832 for (id= first; id; id= id->next) { \
833 AnimData *adt= BKE_animdata_from_id(id); \
834 BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1);\
837 /* another version of this macro for nodetrees */
838 #define RENAMEFIX_ANIM_NODETREE_IDS(first, NtId_Type) \
839 for (id= first; id; id= id->next) { \
840 AnimData *adt= BKE_animdata_from_id(id); \
841 NtId_Type *ntp= (NtId_Type *)id; \
842 if (ntp->nodetree) { \
843 AnimData *adt2= BKE_animdata_from_id((ID *)ntp); \
844 BKE_animdata_fix_paths_rename((ID *)ntp, adt2, ref_id, prefix, oldName, newName, 0, 0, 1);\
846 BKE_animdata_fix_paths_rename(id, adt, ref_id, prefix, oldName, newName, 0, 0, 1);\
850 RENAMEFIX_ANIM_IDS(mainptr->nodetree.first);
853 RENAMEFIX_ANIM_NODETREE_IDS(mainptr->tex.first, Tex);
856 RENAMEFIX_ANIM_IDS(mainptr->lamp.first);
859 RENAMEFIX_ANIM_NODETREE_IDS(mainptr->mat.first, Material);
862 RENAMEFIX_ANIM_IDS(mainptr->camera.first);
865 RENAMEFIX_ANIM_IDS(mainptr->key.first);
868 RENAMEFIX_ANIM_IDS(mainptr->mball.first);
871 RENAMEFIX_ANIM_IDS(mainptr->curve.first);
874 RENAMEFIX_ANIM_IDS(mainptr->armature.first);
877 RENAMEFIX_ANIM_IDS(mainptr->latt.first);
880 RENAMEFIX_ANIM_IDS(mainptr->mesh.first);
883 RENAMEFIX_ANIM_IDS(mainptr->particle.first);
886 RENAMEFIX_ANIM_IDS(mainptr->speaker.first);
889 RENAMEFIX_ANIM_IDS(mainptr->movieclip.first);
892 RENAMEFIX_ANIM_IDS(mainptr->object.first);
895 RENAMEFIX_ANIM_IDS(mainptr->world.first);
898 RENAMEFIX_ANIM_IDS(mainptr->linestyle.first);
901 RENAMEFIX_ANIM_NODETREE_IDS(mainptr->scene.first, Scene);
904 /* *********************************** */
907 /* Finding Tools --------------------------- */
909 /* Find the first path that matches the given criteria */
910 // TODO: do we want some method to perform partial matches too?
911 KS_Path *BKE_keyingset_find_path (KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, int UNUSED(group_mode))
916 if (ELEM3(NULL, ks, rna_path, id))
919 /* loop over paths in the current KeyingSet, finding the first one where all settings match
920 * (i.e. the first one where none of the checks fail and equal 0)
922 for (ksp= ks->paths.first; ksp; ksp= ksp->next) {
923 short eq_id=1, eq_path=1, eq_index=1, eq_group=1;
930 if ((ksp->rna_path==NULL) || strcmp(rna_path, ksp->rna_path))
933 /* index - need to compare whole-array setting too... */
934 if (ksp->array_index != array_index)
939 // FIXME: these checks need to be coded... for now, it's not too important though
942 /* if all aspects are ok, return */
943 if (eq_id && eq_path && eq_index && eq_group)
951 /* Defining Tools --------------------------- */
953 /* Used to create a new 'custom' KeyingSet for the user, that will be automatically added to the stack */
954 KeyingSet *BKE_keyingset_add (ListBase *list, const char idname[], const char name[], short flag, short keyingflag)
958 /* allocate new KeyingSet */
959 ks= MEM_callocN(sizeof(KeyingSet), "KeyingSet");
961 BLI_strncpy(ks->idname, idname ? idname : name ? name : "KeyingSet", sizeof(ks->idname));
963 BLI_strncpy(ks->name, name ? name : idname ? idname : "Keying Set", sizeof(ks->name));
966 ks->keyingflag= keyingflag;
968 /* add KeyingSet to list */
969 BLI_addtail(list, ks);
971 /* Make sure KeyingSet has a unique idname. */
972 BLI_uniquename(list, ks, "KeyingSet", '.', offsetof(KeyingSet, idname), sizeof(ks->idname));
974 /* Make sure KeyingSet has a unique label (this helps with identification). */
975 BLI_uniquename(list, ks, "Keying Set", '.', offsetof(KeyingSet, name), sizeof(ks->name));
977 /* return new KeyingSet for further editing */
981 /* Add a path to a KeyingSet. Nothing is returned for now...
982 * Checks are performed to ensure that destination is appropriate for the KeyingSet in question
984 KS_Path *BKE_keyingset_add_path (KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, short flag, short groupmode)
989 if (ELEM(NULL, ks, rna_path)) {
990 printf("ERROR: no Keying Set and/or RNA Path to add path with\n");
994 /* ID is required for all types of KeyingSets */
996 printf("ERROR: No ID provided for Keying Set Path\n");
1000 /* don't add if there is already a matching KS_Path in the KeyingSet */
1001 if (BKE_keyingset_find_path(ks, id, group_name, rna_path, array_index, groupmode)) {
1002 if (G.debug & G_DEBUG)
1003 printf("ERROR: destination already exists in Keying Set\n");
1007 /* allocate a new KeyingSet Path */
1008 ksp= MEM_callocN(sizeof(KS_Path), "KeyingSet Path");
1010 /* just store absolute info */
1013 BLI_strncpy(ksp->group, group_name, sizeof(ksp->group));
1015 ksp->group[0]= '\0';
1017 /* store additional info for relative paths (just in case user makes the set relative) */
1019 ksp->idtype= GS(id->name);
1021 /* just copy path info */
1022 // TODO: should array index be checked too?
1023 ksp->rna_path= BLI_strdupn(rna_path, strlen(rna_path));
1024 ksp->array_index= array_index;
1028 ksp->groupmode= groupmode;
1030 /* add KeyingSet path to KeyingSet */
1031 BLI_addtail(&ks->paths, ksp);
1033 /* return this path */
1037 /* Free the given Keying Set path */
1038 void BKE_keyingset_free_path (KeyingSet *ks, KS_Path *ksp)
1041 if (ELEM(NULL, ks, ksp))
1044 /* free RNA-path info */
1046 MEM_freeN(ksp->rna_path);
1048 /* free path itself */
1049 BLI_freelinkN(&ks->paths, ksp);
1052 /* Copy all KeyingSets in the given list */
1053 void BKE_keyingsets_copy (ListBase *newlist, ListBase *list)
1058 BLI_duplicatelist(newlist, list);
1060 for (ksn=newlist->first; ksn; ksn=ksn->next) {
1061 BLI_duplicatelist(&ksn->paths, &ksn->paths);
1063 for (kspn=ksn->paths.first; kspn; kspn=kspn->next)
1064 kspn->rna_path= MEM_dupallocN(kspn->rna_path);
1068 /* Freeing Tools --------------------------- */
1070 /* Free data for KeyingSet but not set itself */
1071 void BKE_keyingset_free (KeyingSet *ks)
1073 KS_Path *ksp, *kspn;
1079 /* free each path as we go to avoid looping twice */
1080 for (ksp= ks->paths.first; ksp; ksp= kspn) {
1082 BKE_keyingset_free_path(ks, ksp);
1086 /* Free all the KeyingSets in the given list */
1087 void BKE_keyingsets_free (ListBase *list)
1089 KeyingSet *ks, *ksn;
1095 /* loop over KeyingSets freeing them
1096 * - BKE_keyingset_free() doesn't free the set itself, but it frees its sub-data
1098 for (ks= list->first; ks; ks= ksn) {
1100 BKE_keyingset_free(ks);
1101 BLI_freelinkN(list, ks);
1105 /* ***************************************** */
1106 /* Evaluation Data-Setting Backend */
1108 /* Retrieve string to act as RNA-path, adjusted using mapping-table if provided
1109 * It returns whether the string needs to be freed (i.e. if it was a temp remapped one)
1110 * // FIXME: maybe it would be faster if we didn't have to alloc/free strings like this all the time, but for now it's safer
1112 * - remap: remapping table to use
1113 * - path: original path string (as stored in F-Curve data)
1114 * - dst: destination string to write data to
1116 static short animsys_remap_path (AnimMapper *UNUSED(remap), char *path, char **dst)
1118 /* is there a valid remapping table to use? */
1120 /* find a matching entry... to use to remap */
1124 /* nothing suitable found, so just set dst to look at path (i.e. no alloc/free needed) */
1130 /* less then 1.0 evaluates to false, use epsilon to avoid float error */
1131 #define ANIMSYS_FLOAT_AS_BOOL(value) ((value) > ((1.0f-FLT_EPSILON)))
1133 /* Write the given value to a setting using RNA, and return success */
1134 static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_index, float value)
1139 //printf("%p %s %i %f\n", ptr, path, array_index, value);
1141 /* get property to write to */
1142 if (RNA_path_resolve(ptr, path, &new_ptr, &prop)) {
1143 /* set value - only for animatable numerical values */
1144 if (RNA_property_animateable(&new_ptr, prop)) {
1145 int array_len= RNA_property_array_length(&new_ptr, prop);
1147 if (array_len && array_index >= array_len) {
1148 if (G.debug & G_DEBUG) {
1149 printf("Animato: Invalid array index. ID = '%s', '%s[%d]', array length is %d\n",
1150 (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name+2) : "<No ID>",
1151 path, array_index, array_len-1);
1157 switch (RNA_property_type(prop)) {
1160 RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value));
1162 RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value));
1166 RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value);
1168 RNA_property_int_set(&new_ptr, prop, (int)value);
1172 RNA_property_float_set_index(&new_ptr, prop, array_index, value);
1174 RNA_property_float_set(&new_ptr, prop, value);
1177 RNA_property_enum_set(&new_ptr, prop, (int)value);
1180 /* nothing can be done here... so it is unsuccessful? */
1184 /* RNA property update disabled for now - [#28525] [#28690] [#28774] [#28777] */
1186 /* buffer property update for later flushing */
1187 if (RNA_property_update_check(prop)) {
1188 short skip_updates_hack = 0;
1190 /* optimization hacks: skip property updates for those properties
1191 * for we know that which the updates in RNA were really just for
1192 * flushing property editing via UI/Py
1194 if (new_ptr.type == &RNA_PoseBone) {
1195 /* bone transforms - update pose (i.e. tag depsgraph) */
1196 skip_updates_hack = 1;
1199 if (skip_updates_hack == 0)
1200 RNA_property_update_cache_add(&new_ptr, prop);
1204 /* as long as we don't do property update, we still tag datablock
1205 * as having been updated. this flag does not cause any updates to
1206 * be run, it's for e.g. render engines to synchronize data */
1207 if (new_ptr.id.data) {
1208 ID *id= new_ptr.id.data;
1209 id->flag |= LIB_ID_RECALC;
1210 DAG_id_type_tag(G.main, GS(id->name));
1218 /* failed to get path */
1219 // XXX don't tag as failed yet though, as there are some legit situations (Action Constraint)
1220 // where some channels will not exist, but shouldn't lock up Action
1221 if (G.debug & G_DEBUG) {
1222 printf("Animato: Invalid path. ID = '%s', '%s[%d]'\n",
1223 (ptr && ptr->id.data) ? (((ID *)ptr->id.data)->name+2) : "<No ID>",
1230 /* Simple replacement based data-setting of the FCurve using RNA */
1231 static short animsys_execute_fcurve (PointerRNA *ptr, AnimMapper *remap, FCurve *fcu)
1237 /* get path, remapped as appropriate to work in its new environment */
1238 free_path= animsys_remap_path(remap, fcu->rna_path, &path);
1240 /* write value to setting */
1242 ok= animsys_write_rna_setting(ptr, path, fcu->array_index, fcu->curval);
1244 /* free temp path-info */
1248 /* return whether we were successful */
1252 /* Evaluate all the F-Curves in the given list
1253 * This performs a set of standard checks. If extra checks are required, separate code should be used
1255 static void animsys_evaluate_fcurves (PointerRNA *ptr, ListBase *list, AnimMapper *remap, float ctime)
1259 /* calculate then execute each curve */
1260 for (fcu= list->first; fcu; fcu= fcu->next) {
1261 /* check if this F-Curve doesn't belong to a muted group */
1262 if ((fcu->grp == NULL) || (fcu->grp->flag & AGRP_MUTED)==0) {
1263 /* check if this curve should be skipped */
1264 if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) {
1265 calculate_fcurve(fcu, ctime);
1266 animsys_execute_fcurve(ptr, remap, fcu);
1272 /* ***************************************** */
1273 /* Driver Evaluation */
1275 /* Evaluate Drivers */
1276 static void animsys_evaluate_drivers (PointerRNA *ptr, AnimData *adt, float ctime)
1280 /* drivers are stored as F-Curves, but we cannot use the standard code, as we need to check if
1281 * the depsgraph requested that this driver be evaluated...
1283 for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
1284 ChannelDriver *driver= fcu->driver;
1287 /* check if this driver's curve should be skipped */
1288 if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) {
1289 /* check if driver itself is tagged for recalculation */
1290 if ((driver) && !(driver->flag & DRIVER_FLAG_INVALID)/*&& (driver->flag & DRIVER_FLAG_RECALC)*/) { // XXX driver recalc flag is not set yet by depsgraph!
1291 /* evaluate this using values set already in other places */
1292 // NOTE: for 'layering' option later on, we should check if we should remove old value before adding new to only be done when drivers only changed
1293 calculate_fcurve(fcu, ctime);
1294 ok= animsys_execute_fcurve(ptr, NULL, fcu);
1296 /* clear recalc flag */
1297 driver->flag &= ~DRIVER_FLAG_RECALC;
1299 /* set error-flag if evaluation failed */
1301 driver->flag |= DRIVER_FLAG_INVALID;
1307 /* ***************************************** */
1308 /* Actions Evaluation */
1310 /* strictly not necessary for actual "evaluation", but it is a useful safety check
1311 * to reduce the amount of times that users end up having to "revive" wrongly-assigned
1314 static void action_idcode_patch_check (ID *id, bAction *act)
1319 if (ELEM(NULL, id, act))
1322 idcode = GS(id->name);
1324 /* the actual checks... hopefully not too much of a performance hit in the long run... */
1325 if (act->idroot == 0) {
1326 /* use the current root if not set already (i.e. newly created actions and actions from 2.50-2.57 builds)
1327 * - this has problems if there are 2 users, and the first one encountered is the invalid one
1328 * in which case, the user will need to manually fix this (?)
1330 act->idroot = idcode;
1332 else if (act->idroot != idcode) {
1333 /* only report this error if debug mode is enabled (to save performance everywhere else) */
1334 if (G.debug & G_DEBUG) {
1335 printf("AnimSys Safety Check Failed: Action '%s' is not meant to be used from ID-Blocks of type %d such as '%s'\n",
1336 act->id.name+2, idcode, id->name);
1341 /* ----------------------------------------- */
1343 /* Evaluate Action Group */
1344 void animsys_evaluate_action_group (PointerRNA *ptr, bAction *act, bActionGroup *agrp, AnimMapper *remap, float ctime)
1348 /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */
1349 if (ELEM(NULL, act, agrp)) return;
1350 if ((remap) && (remap->target != act)) remap= NULL;
1352 action_idcode_patch_check(ptr->id.data, act);
1354 /* if group is muted, don't evaluated any of the F-Curve */
1355 if (agrp->flag & AGRP_MUTED)
1358 /* calculate then execute each curve */
1359 for (fcu= agrp->channels.first; (fcu) && (fcu->grp == agrp); fcu= fcu->next) {
1360 /* check if this curve should be skipped */
1361 if ((fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) == 0) {
1362 calculate_fcurve(fcu, ctime);
1363 animsys_execute_fcurve(ptr, remap, fcu);
1368 /* Evaluate Action (F-Curve Bag) */
1369 void animsys_evaluate_action (PointerRNA *ptr, bAction *act, AnimMapper *remap, float ctime)
1371 /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */
1372 if (act == NULL) return;
1373 if ((remap) && (remap->target != act)) remap= NULL;
1375 action_idcode_patch_check(ptr->id.data, act);
1377 /* calculate then execute each curve */
1378 animsys_evaluate_fcurves(ptr, &act->curves, remap, ctime);
1381 /* ***************************************** */
1382 /* NLA System - Evaluation */
1384 /* calculate influence of strip based for given frame based on blendin/out values */
1385 static float nlastrip_get_influence (NlaStrip *strip, float cframe)
1387 /* sanity checks - normalize the blendin/out values? */
1388 strip->blendin= fabsf(strip->blendin);
1389 strip->blendout= fabsf(strip->blendout);
1391 /* result depends on where frame is in respect to blendin/out values */
1392 if (IS_EQ(strip->blendin, 0)==0 && (cframe <= (strip->start + strip->blendin))) {
1393 /* there is some blend-in */
1394 return fabsf(cframe - strip->start) / (strip->blendin);
1396 else if (IS_EQ(strip->blendout, 0)==0 && (cframe >= (strip->end - strip->blendout))) {
1397 /* there is some blend-out */
1398 return fabsf(strip->end - cframe) / (strip->blendout);
1401 /* in the middle of the strip, we should be full strength */
1406 /* evaluate the evaluation time and influence for the strip, storing the results in the strip */
1407 static void nlastrip_evaluate_controls (NlaStrip *strip, float ctime)
1409 /* firstly, analytically generate values for influence and time (if applicable) */
1410 if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0)
1411 strip->strip_time= nlastrip_get_frame(strip, ctime, NLATIME_CONVERT_EVAL);
1412 if ((strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) == 0)
1413 strip->influence= nlastrip_get_influence(strip, ctime);
1415 /* now strip's evaluate F-Curves for these settings (if applicable) */
1416 if (strip->fcurves.first) {
1417 PointerRNA strip_ptr;
1419 /* create RNA-pointer needed to set values */
1420 RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr);
1422 /* execute these settings as per normal */
1423 animsys_evaluate_fcurves(&strip_ptr, &strip->fcurves, NULL, ctime);
1426 /* if user can control the evaluation time (using F-Curves), consider the option which allows this time to be clamped
1427 * to lie within extents of the action-clip, so that a steady changing rate of progress through several cycles of the clip
1428 * can be achieved easily
1430 // NOTE: if we add any more of these special cases, we better group them up nicely...
1431 if ((strip->flag & NLASTRIP_FLAG_USR_TIME) && (strip->flag & NLASTRIP_FLAG_USR_TIME_CYCLIC))
1432 strip->strip_time= fmod(strip->strip_time - strip->actstart, strip->actend - strip->actstart);
1435 /* gets the strip active at the current time for a list of strips for evaluation purposes */
1436 NlaEvalStrip *nlastrips_ctime_get_strip (ListBase *list, ListBase *strips, short index, float ctime)
1438 NlaStrip *strip, *estrip=NULL;
1442 /* loop over strips, checking if they fall within the range */
1443 for (strip= strips->first; strip; strip= strip->next) {
1444 /* check if current time occurs within this strip */
1445 if (IN_RANGE_INCL(ctime, strip->start, strip->end)) {
1446 /* this strip is active, so try to use it */
1448 side= NES_TIME_WITHIN;
1452 /* if time occurred before current strip... */
1453 if (ctime < strip->start) {
1454 if (strip == strips->first) {
1455 /* before first strip - only try to use it if it extends backwards in time too */
1456 if (strip->extendmode == NLASTRIP_EXTEND_HOLD)
1459 /* side is 'before' regardless of whether there's a useful strip */
1460 side= NES_TIME_BEFORE;
1463 /* before next strip - previous strip has ended, but next hasn't begun,
1464 * so blending mode depends on whether strip is being held or not...
1465 * - only occurs when no transition strip added, otherwise the transition would have
1466 * been picked up above...
1470 if (strip->extendmode != NLASTRIP_EXTEND_NOTHING)
1472 side= NES_TIME_AFTER;
1477 /* if time occurred after current strip... */
1478 if (ctime > strip->end) {
1479 /* only if this is the last strip should we do anything, and only if that is being held */
1480 if (strip == strips->last) {
1481 if (strip->extendmode != NLASTRIP_EXTEND_NOTHING)
1484 side= NES_TIME_AFTER;
1488 /* otherwise, skip... as the 'before' case will catch it more elegantly! */
1492 /* check if a valid strip was found
1493 * - must not be muted (i.e. will have contribution
1495 if ((estrip == NULL) || (estrip->flag & NLASTRIP_FLAG_MUTED))
1498 /* if ctime was not within the boundaries of the strip, clamp! */
1500 case NES_TIME_BEFORE: /* extend first frame only */
1501 ctime= estrip->start;
1503 case NES_TIME_AFTER: /* extend last frame only */
1508 /* evaluate strip's evaluation controls
1509 * - skip if no influence (i.e. same effect as muting the strip)
1510 * - negative influence is not supported yet... how would that be defined?
1512 // TODO: this sounds a bit hacky having a few isolated F-Curves stuck on some data it operates on...
1513 nlastrip_evaluate_controls(estrip, ctime);
1514 if (estrip->influence <= 0.0f)
1517 /* check if strip has valid data to evaluate,
1518 * and/or perform any additional type-specific actions
1520 switch (estrip->type) {
1521 case NLASTRIP_TYPE_CLIP:
1522 /* clip must have some action to evaluate */
1523 if (estrip->act == NULL)
1526 case NLASTRIP_TYPE_TRANSITION:
1527 /* there must be strips to transition from and to (i.e. prev and next required) */
1528 if (ELEM(NULL, estrip->prev, estrip->next))
1531 /* evaluate controls for the relevant extents of the bordering strips... */
1532 nlastrip_evaluate_controls(estrip->prev, estrip->start);
1533 nlastrip_evaluate_controls(estrip->next, estrip->end);
1537 /* add to list of strips we need to evaluate */
1538 nes= MEM_callocN(sizeof(NlaEvalStrip), "NlaEvalStrip");
1541 nes->strip_mode= side;
1542 nes->track_index= index;
1543 nes->strip_time= estrip->strip_time;
1546 BLI_addtail(list, nes);
1551 /* ---------------------- */
1553 /* find an NlaEvalChannel that matches the given criteria
1554 * - ptr and prop are the RNA data to find a match for
1556 static NlaEvalChannel *nlaevalchan_find_match (ListBase *channels, PointerRNA *ptr, PropertyRNA *prop, int array_index)
1558 NlaEvalChannel *nec;
1561 if (channels == NULL)
1564 /* loop through existing channels, checking for a channel which affects the same property */
1565 for (nec= channels->first; nec; nec= nec->next) {
1566 /* - comparing the PointerRNA's is done by comparing the pointers
1567 * to the actual struct the property resides in, since that all the
1568 * other data stored in PointerRNA cannot allow us to definitively
1571 if ((nec->ptr.data == ptr->data) && (nec->prop == prop) && (nec->index == array_index))
1579 /* verify that an appropriate NlaEvalChannel for this F-Curve exists */
1580 static NlaEvalChannel *nlaevalchan_verify (PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes, FCurve *fcu, short *newChan)
1582 NlaEvalChannel *nec;
1583 NlaStrip *strip= nes->strip;
1587 /* short free_path=0; */
1590 if (channels == NULL)
1593 /* get RNA pointer+property info from F-Curve for more convenient handling */
1594 /* get path, remapped as appropriate to work in its new environment */
1595 /* free_path= */ /* UNUSED */ animsys_remap_path(strip->remap, fcu->rna_path, &path);
1597 /* a valid property must be available, and it must be animatable */
1598 if (RNA_path_resolve(ptr, path, &new_ptr, &prop) == 0) {
1599 if (G.debug & G_DEBUG) printf("NLA Strip Eval: Cannot resolve path\n");
1602 /* only ok if animatable */
1603 else if (RNA_property_animateable(&new_ptr, prop) == 0) {
1604 if (G.debug & G_DEBUG) printf("NLA Strip Eval: Property not animatable\n");
1608 /* try to find a match */
1609 nec= nlaevalchan_find_match(channels, &new_ptr, prop, fcu->array_index);
1611 /* allocate a new struct for this if none found */
1613 nec= MEM_callocN(sizeof(NlaEvalChannel), "NlaEvalChannel");
1615 BLI_addtail(channels, nec);
1619 nec->index= fcu->array_index;
1624 /* we can now return */
1628 /* accumulate (i.e. blend) the given value on to the channel it affects */
1629 static void nlaevalchan_accumulate (NlaEvalChannel *nec, NlaEvalStrip *nes, short newChan, float value)
1631 NlaStrip *strip= nes->strip;
1632 short blendmode= strip->blendmode;
1633 float inf= strip->influence;
1635 /* if channel is new, just store value regardless of blending factors, etc. */
1641 /* if this is being performed as part of transition evaluation, incorporate
1642 * an additional weighting factor for the influence
1644 if (nes->strip_mode == NES_TIME_TRANSITION_END)
1645 inf *= nes->strip_time;
1647 /* premultiply the value by the weighting factor */
1648 if (IS_EQ(inf, 0)) return;
1651 /* perform blending */
1652 switch (blendmode) {
1653 case NLASTRIP_MODE_ADD:
1654 /* simply add the scaled value on to the stack */
1655 nec->value += value;
1658 case NLASTRIP_MODE_SUBTRACT:
1659 /* simply subtract the scaled value from the stack */
1660 nec->value -= value;
1663 case NLASTRIP_MODE_MULTIPLY:
1664 /* multiply the scaled value with the stack */
1665 nec->value *= value;
1668 case NLASTRIP_MODE_REPLACE:
1669 default: // TODO: do we really want to blend by default? it seems more uses might prefer add...
1670 /* do linear interpolation
1671 * - the influence of the accumulated data (elsewhere, that is called dstweight)
1672 * is 1 - influence, since the strip's influence is srcweight
1674 nec->value= nec->value * (1.0f - inf) + value;
1679 /* accumulate the results of a temporary buffer with the results of the full-buffer */
1680 static void nlaevalchan_buffers_accumulate (ListBase *channels, ListBase *tmp_buffer, NlaEvalStrip *nes)
1682 NlaEvalChannel *nec, *necn, *necd;
1684 /* optimize - abort if no channels */
1685 if (tmp_buffer->first == NULL)
1688 /* accumulate results in tmp_channels buffer to the accumulation buffer */
1689 for (nec= tmp_buffer->first; nec; nec= necn) {
1690 /* get pointer to next channel in case we remove the current channel from the temp-buffer */
1693 /* try to find an existing matching channel for this setting in the accumulation buffer */
1694 necd= nlaevalchan_find_match(channels, &nec->ptr, nec->prop, nec->index);
1696 /* if there was a matching channel already in the buffer, accumulate to it,
1697 * otherwise, add the current channel to the buffer for efficiency
1700 nlaevalchan_accumulate(necd, nes, 0, nec->value);
1702 BLI_remlink(tmp_buffer, nec);
1703 BLI_addtail(channels, nec);
1707 /* free temp-channels that haven't been assimilated into the buffer */
1708 BLI_freelistN(tmp_buffer);
1711 /* ---------------------- */
1712 /* F-Modifier stack joining/separation utilities - should we generalise these for BLI_listbase.h interface? */
1714 /* Temporarily join two lists of modifiers together, storing the result in a third list */
1715 static void nlaeval_fmodifiers_join_stacks (ListBase *result, ListBase *list1, ListBase *list2)
1717 FModifier *fcm1, *fcm2;
1719 /* if list1 is invalid... */
1720 if (ELEM(NULL, list1, list1->first)) {
1721 if (list2 && list2->first) {
1722 result->first= list2->first;
1723 result->last= list2->last;
1726 /* if list 2 is invalid... */
1727 else if (ELEM(NULL, list2, list2->first)) {
1728 result->first= list1->first;
1729 result->last= list1->last;
1732 /* list1 should be added first, and list2 second, with the endpoints of these being the endpoints for result
1733 * - the original lists must be left unchanged though, as we need that fact for restoring
1735 result->first= list1->first;
1736 result->last= list2->last;
1746 /* Split two temporary lists of modifiers */
1747 static void nlaeval_fmodifiers_split_stacks (ListBase *list1, ListBase *list2)
1749 FModifier *fcm1, *fcm2;
1751 /* if list1/2 is invalid... just skip */
1752 if (ELEM(NULL, list1, list2))
1754 if (ELEM(NULL, list1->first, list2->first))
1761 /* clear their links */
1766 /* ---------------------- */
1768 /* evaluate action-clip strip */
1769 static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes)
1771 ListBase tmp_modifiers = {NULL, NULL};
1772 NlaStrip *strip= nes->strip;
1776 /* sanity checks for action */
1780 if (strip->act == NULL) {
1781 printf("NLA-Strip Eval Error: Strip '%s' has no Action\n", strip->name);
1785 action_idcode_patch_check(ptr->id.data, strip->act);
1787 /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
1788 nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers);
1790 /* evaluate strip's modifiers which modify time to evaluate the base curves at */
1791 evaltime= evaluate_time_fmodifiers(&tmp_modifiers, NULL, 0.0f, strip->strip_time);
1793 /* evaluate all the F-Curves in the action, saving the relevant pointers to data that will need to be used */
1794 for (fcu= strip->act->curves.first; fcu; fcu= fcu->next) {
1795 NlaEvalChannel *nec;
1799 /* check if this curve should be skipped */
1800 if (fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED))
1802 if ((fcu->grp) && (fcu->grp->flag & AGRP_MUTED))
1805 /* evaluate the F-Curve's value for the time given in the strip
1806 * NOTE: we use the modified time here, since strip's F-Curve Modifiers are applied on top of this
1808 value= evaluate_fcurve(fcu, evaltime);
1810 /* apply strip's F-Curve Modifiers on this value
1811 * NOTE: we apply the strip's original evaluation time not the modified one (as per standard F-Curve eval)
1813 evaluate_value_fmodifiers(&tmp_modifiers, fcu, &value, strip->strip_time);
1816 /* get an NLA evaluation channel to work with, and accumulate the evaluated value with the value(s)
1817 * stored in this channel if it has been used already
1819 nec= nlaevalchan_verify(ptr, channels, nes, fcu, &newChan);
1821 nlaevalchan_accumulate(nec, nes, newChan, value);
1824 /* unlink this strip's modifiers from the parent's modifiers again */
1825 nlaeval_fmodifiers_split_stacks(&strip->modifiers, modifiers);
1828 /* evaluate transition strip */
1829 static void nlastrip_evaluate_transition (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes)
1831 ListBase tmp_channels = {NULL, NULL};
1832 ListBase tmp_modifiers = {NULL, NULL};
1833 NlaEvalStrip tmp_nes;
1836 /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
1837 nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &nes->strip->modifiers, modifiers);
1839 /* get the two strips to operate on
1840 * - we use the endpoints of the strips directly flanking our strip
1841 * using these as the endpoints of the transition (destination and source)
1842 * - these should have already been determined to be valid...
1843 * - if this strip is being played in reverse, we need to swap these endpoints
1844 * otherwise they will be interpolated wrong
1846 if (nes->strip->flag & NLASTRIP_FLAG_REVERSE) {
1847 s1= nes->strip->next;
1848 s2= nes->strip->prev;
1851 s1= nes->strip->prev;
1852 s2= nes->strip->next;
1855 /* prepare template for 'evaluation strip'
1856 * - based on the transition strip's evaluation strip data
1857 * - strip_mode is NES_TIME_TRANSITION_* based on which endpoint
1858 * - strip_time is the 'normalised' (i.e. in-strip) time for evaluation,
1859 * which doubles up as an additional weighting factor for the strip influences
1860 * which allows us to appear to be 'interpolating' between the two extremes
1864 /* evaluate these strips into a temp-buffer (tmp_channels) */
1865 // FIXME: modifier evalation here needs some work...
1867 tmp_nes.strip_mode= NES_TIME_TRANSITION_START;
1869 nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, &tmp_nes);
1872 tmp_nes.strip_mode= NES_TIME_TRANSITION_END;
1874 nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, &tmp_nes);
1877 /* assumulate temp-buffer and full-buffer, using the 'real' strip */
1878 nlaevalchan_buffers_accumulate(channels, &tmp_channels, nes);
1880 /* unlink this strip's modifiers from the parent's modifiers again */
1881 nlaeval_fmodifiers_split_stacks(&nes->strip->modifiers, modifiers);
1884 /* evaluate meta-strip */
1885 static void nlastrip_evaluate_meta (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes)
1887 ListBase tmp_channels = {NULL, NULL};
1888 ListBase tmp_modifiers = {NULL, NULL};
1889 NlaStrip *strip= nes->strip;
1890 NlaEvalStrip *tmp_nes;
1893 /* meta-strip was calculated normally to have some time to be evaluated at
1894 * and here we 'look inside' the meta strip, treating it as a decorated window to
1895 * it's child strips, which get evaluated as if they were some tracks on a strip
1896 * (but with some extra modifiers to apply).
1898 * NOTE: keep this in sync with animsys_evaluate_nla()
1901 /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
1902 nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers);
1904 /* find the child-strip to evaluate */
1905 evaltime= (nes->strip_time * (strip->end - strip->start)) + strip->start;
1906 tmp_nes= nlastrips_ctime_get_strip(NULL, &strip->strips, -1, evaltime);
1907 if (tmp_nes == NULL)
1910 /* evaluate child-strip into tmp_channels buffer before accumulating
1911 * in the accumulation buffer
1913 nlastrip_evaluate(ptr, &tmp_channels, &tmp_modifiers, tmp_nes);
1915 /* assumulate temp-buffer and full-buffer, using the 'real' strip */
1916 nlaevalchan_buffers_accumulate(channels, &tmp_channels, nes);
1918 /* free temp eval-strip */
1921 /* unlink this strip's modifiers from the parent's modifiers again */
1922 nlaeval_fmodifiers_split_stacks(&strip->modifiers, modifiers);
1925 /* evaluates the given evaluation strip */
1926 void nlastrip_evaluate (PointerRNA *ptr, ListBase *channels, ListBase *modifiers, NlaEvalStrip *nes)
1928 NlaStrip *strip= nes->strip;
1930 /* to prevent potential infinite recursion problems (i.e. transition strip, beside meta strip containing a transition
1931 * several levels deep inside it), we tag the current strip as being evaluated, and clear this when we leave
1933 // TODO: be careful with this flag, since some edit tools may be running and have set this while animplayback was running
1934 if (strip->flag & NLASTRIP_FLAG_EDIT_TOUCHED)
1936 strip->flag |= NLASTRIP_FLAG_EDIT_TOUCHED;
1938 /* actions to take depend on the type of strip */
1939 switch (strip->type) {
1940 case NLASTRIP_TYPE_CLIP: /* action-clip */
1941 nlastrip_evaluate_actionclip(ptr, channels, modifiers, nes);
1943 case NLASTRIP_TYPE_TRANSITION: /* transition */
1944 nlastrip_evaluate_transition(ptr, channels, modifiers, nes);
1946 case NLASTRIP_TYPE_META: /* meta */
1947 nlastrip_evaluate_meta(ptr, channels, modifiers, nes);
1950 default: /* do nothing */
1954 /* clear temp recursion safe-check */
1955 strip->flag &= ~NLASTRIP_FLAG_EDIT_TOUCHED;
1958 /* write the accumulated settings to */
1959 void nladata_flush_channels (ListBase *channels)
1961 NlaEvalChannel *nec;
1964 if (channels == NULL)
1967 /* for each channel with accumulated values, write its value on the property it affects */
1968 for (nec= channels->first; nec; nec= nec->next) {
1969 PointerRNA *ptr= &nec->ptr;
1970 PropertyRNA *prop= nec->prop;
1971 int array_index= nec->index;
1972 float value= nec->value;
1974 /* write values - see animsys_write_rna_setting() to sync the code */
1975 switch (RNA_property_type(prop)) {
1977 if (RNA_property_array_length(ptr, prop))
1978 RNA_property_boolean_set_index(ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value));
1980 RNA_property_boolean_set(ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value));
1983 if (RNA_property_array_length(ptr, prop))
1984 RNA_property_int_set_index(ptr, prop, array_index, (int)value);
1986 RNA_property_int_set(ptr, prop, (int)value);
1989 if (RNA_property_array_length(ptr, prop))
1990 RNA_property_float_set_index(ptr, prop, array_index, value);
1992 RNA_property_float_set(ptr, prop, value);
1995 RNA_property_enum_set(ptr, prop, (int)value);
1998 // can't do anything with other types of property....
2004 /* ---------------------- */
2006 /* NLA Evaluation function - values are calculated and stored in temporary "NlaEvalChannels"
2007 * ! This is exported so that keyframing code can use this for make use of it for anim layers support
2008 * > echannels: (list<NlaEvalChannels>) evaluation channels with calculated values
2010 static void animsys_evaluate_nla (ListBase *echannels, PointerRNA *ptr, AnimData *adt, float ctime)
2013 short track_index=0;
2014 short has_strips = 0;
2016 ListBase estrips= {NULL, NULL};
2019 /* 1. get the stack of strips to evaluate at current time (influence calculated here) */
2020 for (nlt=adt->nla_tracks.first; nlt; nlt=nlt->next, track_index++) {
2021 /* stop here if tweaking is on and this strip is the tweaking track (it will be the first one that's 'disabled')... */
2022 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED))
2025 /* skip if we're only considering a track tagged 'solo' */
2026 if ((adt->flag & ADT_NLA_SOLO_TRACK) && (nlt->flag & NLATRACK_SOLO)==0)
2028 /* skip if track is muted */
2029 if (nlt->flag & NLATRACK_MUTED)
2032 /* if this track has strips (but maybe they won't be suitable), set has_strips
2033 * - used for mainly for still allowing normal action evaluation...
2035 if (nlt->strips.first)
2038 /* otherwise, get strip to evaluate for this channel */
2039 nes= nlastrips_ctime_get_strip(&estrips, &nlt->strips, track_index, ctime);
2040 if (nes) nes->track= nlt;
2043 /* add 'active' Action (may be tweaking track) as last strip to evaluate in NLA stack
2044 * - only do this if we're not exclusively evaluating the 'solo' NLA-track
2046 if ((adt->action) && !(adt->flag & ADT_NLA_SOLO_TRACK)) {
2047 /* if there are strips, evaluate action as per NLA rules */
2048 if ((has_strips) || (adt->actstrip)) {
2049 /* make dummy NLA strip, and add that to the stack */
2050 NlaStrip dummy_strip= {NULL};
2051 ListBase dummy_trackslist;
2053 dummy_trackslist.first= dummy_trackslist.last= &dummy_strip;
2055 if ((nlt) && !(adt->flag & ADT_NLA_EDIT_NOMAP)) {
2056 /* edit active action in-place according to its active strip, so copy the data */
2057 memcpy(&dummy_strip, adt->actstrip, sizeof(NlaStrip));
2058 dummy_strip.next = dummy_strip.prev = NULL;
2061 /* set settings of dummy NLA strip from AnimData settings */
2062 dummy_strip.act= adt->action;
2063 dummy_strip.remap= adt->remap;
2065 /* action range is calculated taking F-Modifiers into account (which making new strips doesn't do due to the troublesome nature of that) */
2066 calc_action_range(dummy_strip.act, &dummy_strip.actstart, &dummy_strip.actend, 1);
2067 dummy_strip.start = dummy_strip.actstart;
2068 dummy_strip.end = (IS_EQF(dummy_strip.actstart, dummy_strip.actend)) ? (dummy_strip.actstart + 1.0f): (dummy_strip.actend);
2070 dummy_strip.blendmode= adt->act_blendmode;
2071 dummy_strip.extendmode= adt->act_extendmode;
2072 dummy_strip.influence= adt->act_influence;
2075 /* add this to our list of evaluation strips */
2076 nlastrips_ctime_get_strip(&estrips, &dummy_trackslist, -1, ctime);
2079 /* special case - evaluate as if there isn't any NLA data */
2080 // TODO: this is really just a stop-gap measure...
2081 animsys_evaluate_action(ptr, adt->action, adt->remap, ctime);
2086 /* only continue if there are strips to evaluate */
2087 if (estrips.first == NULL)
2091 /* 2. for each strip, evaluate then accumulate on top of existing channels, but don't set values yet */
2092 for (nes= estrips.first; nes; nes= nes->next)
2093 nlastrip_evaluate(ptr, echannels, NULL, nes);
2095 /* 3. free temporary evaluation data that's not used elsewhere */
2096 BLI_freelistN(&estrips);
2099 /* NLA Evaluation function (mostly for use through do_animdata)
2100 * - All channels that will be affected are not cleared anymore. Instead, we just evaluate into
2101 * some temp channels, where values can be accumulated in one go.
2103 static void animsys_calculate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
2105 ListBase echannels= {NULL, NULL};
2107 // TODO: need to zero out all channels used, otherwise we have problems with threadsafety
2108 // and also when the user jumps between different times instead of moving sequentially...
2110 /* evaluate the NLA stack, obtaining a set of values to flush */
2111 animsys_evaluate_nla(&echannels, ptr, adt, ctime);
2113 /* flush effects of accumulating channels in NLA to the actual data they affect */
2114 nladata_flush_channels(&echannels);
2116 /* free temp data */
2117 BLI_freelistN(&echannels);
2120 /* ***************************************** */
2121 /* Overrides System - Public API */
2123 /* Clear all overides */
2125 /* Add or get existing Override for given setting */
2127 AnimOverride *BKE_animsys_validate_override (PointerRNA *UNUSED(ptr), char *UNUSED(path), int UNUSED(array_index))
2129 // FIXME: need to define how to get overrides
2134 /* -------------------- */
2136 /* Evaluate Overrides */
2137 static void animsys_evaluate_overrides (PointerRNA *ptr, AnimData *adt)
2141 /* for each override, simply execute... */
2142 for (aor= adt->overrides.first; aor; aor= aor->next)
2143 animsys_write_rna_setting(ptr, aor->rna_path, aor->array_index, aor->value);
2146 /* ***************************************** */
2147 /* Evaluation System - Public API */
2149 /* Overview of how this system works:
2150 * 1) Depsgraph sorts data as necessary, so that data is in an order that means
2151 * that all dependencies are resolved before dependants.
2152 * 2) All normal animation is evaluated, so that drivers have some basis values to
2154 * a. NLA stacks are done first, as the Active Actions act as 'tweaking' tracks
2155 * which modify the effects of the NLA-stacks
2156 * b. Active Action is evaluated as per normal, on top of the results of the NLA tracks
2158 * --------------< often in a separate phase... >------------------
2160 * 3) Drivers/expressions are evaluated on top of this, in an order where dependencies are
2162 * Note: it may be necessary to have some tools to handle the cases where some higher-level
2163 * drivers are added and cause some problematic dependencies that didn't exist in the local levels...
2165 * --------------< always executed >------------------
2167 * Maintenance of editability of settings (XXX):
2168 * In order to ensure that settings that are animated can still be manipulated in the UI without requiring
2169 * that keyframes are added to prevent these values from being overwritten, we use 'overrides'.
2171 * Unresolved things:
2172 * - Handling of multi-user settings (i.e. time-offset, group-instancing) -> big cache grids or nodal system? but stored where?
2173 * - Multiple-block dependencies (i.e. drivers for settings are in both local and higher levels) -> split into separate lists?
2176 * - Currently (as of September 2009), overrides we haven't needed to (fully) implement overrides.
2177 * However, the code for this is relatively harmless, so is left in the code for now.
2180 /* Evaluation loop for evaluation animation data
2182 * This assumes that the animation-data provided belongs to the ID block in question,
2183 * and that the flags for which parts of the anim-data settings need to be recalculated
2184 * have been set already by the depsgraph. Now, we use the recalc
2186 void BKE_animsys_evaluate_animdata (Scene *scene, ID *id, AnimData *adt, float ctime, short recalc)
2191 if (ELEM(NULL, id, adt))
2194 /* get pointer to ID-block for RNA to use */
2195 RNA_id_pointer_create(id, &id_ptr);
2197 /* recalculate keyframe data:
2198 * - NLA before Active Action, as Active Action behaves as 'tweaking track'
2199 * that overrides 'rough' work in NLA
2201 // TODO: need to double check that this all works correctly
2202 if ((recalc & ADT_RECALC_ANIM) || (adt->recalc & ADT_RECALC_ANIM)) {
2203 /* evaluate NLA data */
2204 if ((adt->nla_tracks.first) && !(adt->flag & ADT_NLA_EVAL_OFF)) {
2205 /* evaluate NLA-stack
2206 * - active action is evaluated as part of the NLA stack as the last item
2208 animsys_calculate_nla(&id_ptr, adt, ctime);
2210 /* evaluate Active Action only */
2211 else if (adt->action)
2212 animsys_evaluate_action(&id_ptr, adt->action, adt->remap, ctime);
2215 adt->recalc &= ~ADT_RECALC_ANIM;
2218 /* recalculate drivers
2219 * - Drivers need to be evaluated afterwards, as they can either override
2220 * or be layered on top of existing animation data.
2221 * - Drivers should be in the appropriate order to be evaluated without problems...
2223 if ((recalc & ADT_RECALC_DRIVERS)
2224 /* XXX for now, don't check yet, as depsgraph hasn't been updated */
2225 /* && (adt->recalc & ADT_RECALC_DRIVERS)*/)
2227 animsys_evaluate_drivers(&id_ptr, adt, ctime);
2230 /* always execute 'overrides'
2231 * - Overrides allow editing, by overwriting the value(s) set from animation-data, with the
2232 * value last set by the user (and not keyframed yet).
2233 * - Overrides are cleared upon frame change and/or keyframing
2234 * - It is best that we execute this everytime, so that no errors are likely to occur.
2236 animsys_evaluate_overrides(&id_ptr, adt);
2238 /* execute and clear all cached property update functions */
2240 Main *bmain = G.main; // xxx - to get passed in!
2241 RNA_property_update_cache_flush(bmain, scene);
2242 RNA_property_update_cache_free();
2245 /* clear recalc flag now */
2249 /* Evaluation of all ID-blocks with Animation Data blocks - Animation Data Only
2251 * This will evaluate only the animation info available in the animation data-blocks
2252 * encountered. In order to enforce the system by which some settings controlled by a
2253 * 'local' (i.e. belonging in the nearest ID-block that setting is related to, not a
2254 * standard 'root') block are overridden by a larger 'user'
2256 void BKE_animsys_evaluate_all_animation (Main *main, Scene *scene, float ctime)
2260 if (G.debug & G_DEBUG)
2261 printf("Evaluate all animation - %f\n", ctime);
2263 /* macros for less typing
2264 * - only evaluate animation data for id if it has users (and not just fake ones)
2265 * - whether animdata exists is checked for by the evaluation function, though taking
2266 * this outside of the function may make things slightly faster?
2268 #define EVAL_ANIM_IDS(first, aflag) \
2269 for (id= first; id; id= id->next) { \
2270 if (ID_REAL_USERS(id) > 0) { \
2271 AnimData *adt= BKE_animdata_from_id(id); \
2272 BKE_animsys_evaluate_animdata(scene, id, adt, ctime, aflag); \
2275 /* another macro for the "embedded" nodetree cases
2276 * - this is like EVAL_ANIM_IDS, but this handles the case "embedded nodetrees"
2277 * (i.e. scene/material/texture->nodetree) which we need a special exception
2278 * for, otherwise they'd get skipped
2279 * - ntp = "node tree parent" = datablock where node tree stuff resides
2281 #define EVAL_ANIM_NODETREE_IDS(first, NtId_Type, aflag) \
2282 for (id= first; id; id= id->next) { \
2283 if (ID_REAL_USERS(id) > 0) { \
2284 AnimData *adt= BKE_animdata_from_id(id); \
2285 NtId_Type *ntp= (NtId_Type *)id; \
2286 if (ntp->nodetree) { \
2287 AnimData *adt2= BKE_animdata_from_id((ID *)ntp->nodetree); \
2288 BKE_animsys_evaluate_animdata(scene, (ID *)ntp->nodetree, adt2, ctime, ADT_RECALC_ANIM); \
2290 BKE_animsys_evaluate_animdata(scene, id, adt, ctime, aflag); \
2295 * when there are no actions, don't go over database and loop over heaps of datablocks,
2296 * which should ultimately be empty, since it is not possible for now to have any animation
2297 * without some actions, and drivers wouldn't get affected by any state changes
2299 * however, if there are some curves, we will need to make sure that their 'ctime' property gets
2300 * set correctly, so this optimization must be skipped in that case...
2302 if ((main->action.first == NULL) && (main->curve.first == NULL)) {
2303 if (G.debug & G_DEBUG)
2304 printf("\tNo Actions, so no animation needs to be evaluated...\n");
2310 EVAL_ANIM_IDS(main->nodetree.first, ADT_RECALC_ANIM);
2313 EVAL_ANIM_NODETREE_IDS(main->tex.first, Tex, ADT_RECALC_ANIM);
2316 EVAL_ANIM_NODETREE_IDS(main->lamp.first, Lamp, ADT_RECALC_ANIM);
2319 EVAL_ANIM_NODETREE_IDS(main->mat.first, Material, ADT_RECALC_ANIM);
2322 EVAL_ANIM_IDS(main->camera.first, ADT_RECALC_ANIM);
2325 EVAL_ANIM_IDS(main->key.first, ADT_RECALC_ANIM);
2328 EVAL_ANIM_IDS(main->mball.first, ADT_RECALC_ANIM);
2331 EVAL_ANIM_IDS(main->curve.first, ADT_RECALC_ANIM);
2334 EVAL_ANIM_IDS(main->armature.first, ADT_RECALC_ANIM);
2337 EVAL_ANIM_IDS(main->latt.first, ADT_RECALC_ANIM);
2340 EVAL_ANIM_IDS(main->mesh.first, ADT_RECALC_ANIM);
2343 EVAL_ANIM_IDS(main->particle.first, ADT_RECALC_ANIM);
2346 EVAL_ANIM_IDS(main->speaker.first, ADT_RECALC_ANIM);
2349 EVAL_ANIM_IDS(main->movieclip.first, ADT_RECALC_ANIM);
2352 EVAL_ANIM_IDS(main->linestyle.first, ADT_RECALC_ANIM);
2355 /* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets
2356 * this tagged by Depsgraph on framechange. This optimization means that objects
2357 * linked from other (not-visible) scenes will not need their data calculated.
2359 EVAL_ANIM_IDS(main->object.first, 0);
2362 EVAL_ANIM_NODETREE_IDS(main->world.first, World, ADT_RECALC_ANIM);
2365 EVAL_ANIM_NODETREE_IDS(main->scene.first, Scene, ADT_RECALC_ANIM);
2368 /* ***************************************** */