Blender  V2.93
anim_sys.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
17  * All rights reserved.
18  */
19 
24 #include <float.h>
25 #include <math.h>
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include "MEM_guardedalloc.h"
31 
32 #include "BLI_alloca.h"
33 #include "BLI_blenlib.h"
34 #include "BLI_dynstr.h"
35 #include "BLI_listbase.h"
36 #include "BLI_math_rotation.h"
37 #include "BLI_math_vector.h"
38 #include "BLI_string_utils.h"
39 #include "BLI_utildefines.h"
40 
41 #include "BLT_translation.h"
42 
43 #include "DNA_anim_types.h"
44 #include "DNA_light_types.h"
45 #include "DNA_material_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_screen_types.h"
49 #include "DNA_space_types.h"
50 #include "DNA_texture_types.h"
51 #include "DNA_world_types.h"
52 
53 #include "BKE_action.h"
54 #include "BKE_anim_data.h"
55 #include "BKE_animsys.h"
56 #include "BKE_context.h"
57 #include "BKE_fcurve.h"
58 #include "BKE_global.h"
59 #include "BKE_lib_id.h"
60 #include "BKE_lib_query.h"
61 #include "BKE_main.h"
62 #include "BKE_material.h"
63 #include "BKE_nla.h"
64 #include "BKE_node.h"
65 #include "BKE_report.h"
66 #include "BKE_texture.h"
67 
68 #include "DEG_depsgraph.h"
69 #include "DEG_depsgraph_query.h"
70 
71 #include "RNA_access.h"
72 
73 #include "BLO_read_write.h"
74 
75 #include "nla_private.h"
76 
77 #include "atomic_ops.h"
78 
79 #include "CLG_log.h"
80 
81 static CLG_LogRef LOG = {"bke.anim_sys"};
82 
83 /* *********************************** */
84 /* KeyingSet API */
85 
86 /* Finding Tools --------------------------- */
87 
88 /* Find the first path that matches the given criteria */
89 /* TODO: do we want some method to perform partial matches too? */
91  ID *id,
92  const char group_name[],
93  const char rna_path[],
94  int array_index,
95  int UNUSED(group_mode))
96 {
97  KS_Path *ksp;
98 
99  /* sanity checks */
100  if (ELEM(NULL, ks, rna_path, id)) {
101  return NULL;
102  }
103 
104  /* loop over paths in the current KeyingSet, finding the first one where all settings match
105  * (i.e. the first one where none of the checks fail and equal 0)
106  */
107  for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
108  short eq_id = 1, eq_path = 1, eq_index = 1, eq_group = 1;
109 
110  /* id */
111  if (id != ksp->id) {
112  eq_id = 0;
113  }
114 
115  /* path */
116  if ((ksp->rna_path == NULL) || !STREQ(rna_path, ksp->rna_path)) {
117  eq_path = 0;
118  }
119 
120  /* index - need to compare whole-array setting too... */
121  if (ksp->array_index != array_index) {
122  eq_index = 0;
123  }
124 
125  /* group */
126  if (group_name) {
127  /* FIXME: these checks need to be coded... for now, it's not too important though */
128  }
129 
130  /* if all aspects are ok, return */
131  if (eq_id && eq_path && eq_index && eq_group) {
132  return ksp;
133  }
134  }
135 
136  /* none found */
137  return NULL;
138 }
139 
140 /* Defining Tools --------------------------- */
141 
142 /* Used to create a new 'custom' KeyingSet for the user,
143  * that will be automatically added to the stack */
145  ListBase *list, const char idname[], const char name[], short flag, short keyingflag)
146 {
147  KeyingSet *ks;
148 
149  /* allocate new KeyingSet */
150  ks = MEM_callocN(sizeof(KeyingSet), "KeyingSet");
151 
152  BLI_strncpy(
153  ks->idname, (idname) ? idname : (name) ? name : DATA_("KeyingSet"), sizeof(ks->idname));
154  BLI_strncpy(ks->name, (name) ? name : (idname) ? idname : DATA_("Keying Set"), sizeof(ks->name));
155 
156  ks->flag = flag;
157  ks->keyingflag = keyingflag;
158  /* NOTE: assume that if one is set one way, the other should be too, so that it'll work */
159  ks->keyingoverride = keyingflag;
160 
161  /* add KeyingSet to list */
162  BLI_addtail(list, ks);
163 
164  /* Make sure KeyingSet has a unique idname */
166  list, ks, DATA_("KeyingSet"), '.', offsetof(KeyingSet, idname), sizeof(ks->idname));
167 
168  /* Make sure KeyingSet has a unique label (this helps with identification) */
169  BLI_uniquename(list, ks, DATA_("Keying Set"), '.', offsetof(KeyingSet, name), sizeof(ks->name));
170 
171  /* return new KeyingSet for further editing */
172  return ks;
173 }
174 
175 /* Add a path to a KeyingSet. Nothing is returned for now...
176  * Checks are performed to ensure that destination is appropriate for the KeyingSet in question
177  */
179  ID *id,
180  const char group_name[],
181  const char rna_path[],
182  int array_index,
183  short flag,
184  short groupmode)
185 {
186  KS_Path *ksp;
187 
188  /* sanity checks */
189  if (ELEM(NULL, ks, rna_path)) {
190  CLOG_ERROR(&LOG, "no Keying Set and/or RNA Path to add path with");
191  return NULL;
192  }
193 
194  /* ID is required for all types of KeyingSets */
195  if (id == NULL) {
196  CLOG_ERROR(&LOG, "No ID provided for Keying Set Path");
197  return NULL;
198  }
199 
200  /* don't add if there is already a matching KS_Path in the KeyingSet */
201  if (BKE_keyingset_find_path(ks, id, group_name, rna_path, array_index, groupmode)) {
202  if (G.debug & G_DEBUG) {
203  CLOG_ERROR(&LOG, "destination already exists in Keying Set");
204  }
205  return NULL;
206  }
207 
208  /* allocate a new KeyingSet Path */
209  ksp = MEM_callocN(sizeof(KS_Path), "KeyingSet Path");
210 
211  /* just store absolute info */
212  ksp->id = id;
213  if (group_name) {
214  BLI_strncpy(ksp->group, group_name, sizeof(ksp->group));
215  }
216  else {
217  ksp->group[0] = '\0';
218  }
219 
220  /* store additional info for relative paths (just in case user makes the set relative) */
221  if (id) {
222  ksp->idtype = GS(id->name);
223  }
224 
225  /* just copy path info */
226  /* TODO: should array index be checked too? */
227  ksp->rna_path = BLI_strdup(rna_path);
228  ksp->array_index = array_index;
229 
230  /* store flags */
231  ksp->flag = flag;
232  ksp->groupmode = groupmode;
233 
234  /* add KeyingSet path to KeyingSet */
235  BLI_addtail(&ks->paths, ksp);
236 
237  /* return this path */
238  return ksp;
239 }
240 
241 /* Free the given Keying Set path */
243 {
244  /* sanity check */
245  if (ELEM(NULL, ks, ksp)) {
246  return;
247  }
248 
249  /* free RNA-path info */
250  if (ksp->rna_path) {
251  MEM_freeN(ksp->rna_path);
252  }
253 
254  /* free path itself */
255  BLI_freelinkN(&ks->paths, ksp);
256 }
257 
258 /* Copy all KeyingSets in the given list */
259 void BKE_keyingsets_copy(ListBase *newlist, const ListBase *list)
260 {
261  KeyingSet *ksn;
262  KS_Path *kspn;
263 
264  BLI_duplicatelist(newlist, list);
265 
266  for (ksn = newlist->first; ksn; ksn = ksn->next) {
267  BLI_duplicatelist(&ksn->paths, &ksn->paths);
268 
269  for (kspn = ksn->paths.first; kspn; kspn = kspn->next) {
270  kspn->rna_path = MEM_dupallocN(kspn->rna_path);
271  }
272  }
273 }
274 
276 {
277  for (KeyingSet *ksn = keyingsets->first; ksn; ksn = ksn->next) {
278  for (KS_Path *kspn = ksn->paths.first; kspn; kspn = kspn->next) {
280  }
281  }
282 }
283 
284 /* Freeing Tools --------------------------- */
285 
286 /* Free data for KeyingSet but not set itself */
288 {
289  KS_Path *ksp, *kspn;
290 
291  /* sanity check */
292  if (ks == NULL) {
293  return;
294  }
295 
296  /* free each path as we go to avoid looping twice */
297  for (ksp = ks->paths.first; ksp; ksp = kspn) {
298  kspn = ksp->next;
299  BKE_keyingset_free_path(ks, ksp);
300  }
301 }
302 
303 /* Free all the KeyingSets in the given list */
305 {
306  KeyingSet *ks, *ksn;
307 
308  /* sanity check */
309  if (list == NULL) {
310  return;
311  }
312 
313  /* loop over KeyingSets freeing them
314  * - BKE_keyingset_free() doesn't free the set itself, but it frees its sub-data
315  */
316  for (ks = list->first; ks; ks = ksn) {
317  ksn = ks->next;
318  BKE_keyingset_free(ks);
319  BLI_freelinkN(list, ks);
320  }
321 }
322 
324 {
325  LISTBASE_FOREACH (KeyingSet *, ks, list) {
326  /* KeyingSet */
327  BLO_write_struct(writer, KeyingSet, ks);
328 
329  /* Paths */
330  LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) {
331  /* Path */
332  BLO_write_struct(writer, KS_Path, ksp);
333 
334  if (ksp->rna_path) {
335  BLO_write_string(writer, ksp->rna_path);
336  }
337  }
338  }
339 }
340 
342 {
343  LISTBASE_FOREACH (KeyingSet *, ks, list) {
344  /* paths */
345  BLO_read_list(reader, &ks->paths);
346 
347  LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) {
348  /* rna path */
349  BLO_read_data_address(reader, &ksp->rna_path);
350  }
351  }
352 }
353 
355 {
356  LISTBASE_FOREACH (KeyingSet *, ks, list) {
357  LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) {
358  BLO_read_id_address(reader, id->lib, &ksp->id);
359  }
360  }
361 }
362 
364 {
365  LISTBASE_FOREACH (KeyingSet *, ks, list) {
366  LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) {
367  BLO_expand(expander, ksp->id);
368  }
369  }
370 }
371 
372 /* ***************************************** */
373 /* Evaluation Data-Setting Backend */
374 
375 static bool is_fcurve_evaluatable(FCurve *fcu)
376 {
377  if (fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) {
378  return false;
379  }
380  if (fcu->grp != NULL && (fcu->grp->flag & AGRP_MUTED)) {
381  return false;
382  }
383  if (BKE_fcurve_is_empty(fcu)) {
384  return false;
385  }
386  return true;
387 }
388 
390  /* typically 'fcu->rna_path', 'fcu->array_index' */
391  const char *rna_path,
392  const int array_index,
393  PathResolvedRNA *r_result)
394 {
395  if (rna_path == NULL) {
396  return false;
397  }
398 
399  const char *path = rna_path;
400  if (!RNA_path_resolve_property(ptr, path, &r_result->ptr, &r_result->prop)) {
401  /* failed to get path */
402  /* XXX don't tag as failed yet though, as there are some legit situations (Action Constraint)
403  * where some channels will not exist, but shouldn't lock up Action */
404  if (G.debug & G_DEBUG) {
405  CLOG_WARN(&LOG,
406  "Animato: Invalid path. ID = '%s', '%s[%d]'",
407  (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>",
408  path,
409  array_index);
410  }
411  return false;
412  }
413 
414  if (ptr->owner_id != NULL && !RNA_property_animateable(&r_result->ptr, r_result->prop)) {
415  return false;
416  }
417 
418  int array_len = RNA_property_array_length(&r_result->ptr, r_result->prop);
419  if (array_len && array_index >= array_len) {
420  if (G.debug & G_DEBUG) {
421  CLOG_WARN(&LOG,
422  "Animato: Invalid array index. ID = '%s', '%s[%d]', array length is %d",
423  (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>",
424  path,
425  array_index,
426  array_len - 1);
427  }
428  return false;
429  }
430 
431  r_result->prop_index = array_len ? array_index : -1;
432  return true;
433 }
434 
435 /* less than 1.0 evaluates to false, use epsilon to avoid float error */
436 #define ANIMSYS_FLOAT_AS_BOOL(value) ((value) > ((1.0f - FLT_EPSILON)))
437 
438 bool BKE_animsys_read_from_rna_path(PathResolvedRNA *anim_rna, float *r_value)
439 {
440  PropertyRNA *prop = anim_rna->prop;
441  PointerRNA *ptr = &anim_rna->ptr;
442  int array_index = anim_rna->prop_index;
443  float orig_value;
444 
445  /* caller must ensure this is animatable */
447 
448  switch (RNA_property_type(prop)) {
449  case PROP_BOOLEAN: {
450  if (array_index != -1) {
451  const int orig_value_coerce = RNA_property_boolean_get_index(ptr, prop, array_index);
452  orig_value = (float)orig_value_coerce;
453  }
454  else {
455  const int orig_value_coerce = RNA_property_boolean_get(ptr, prop);
456  orig_value = (float)orig_value_coerce;
457  }
458  break;
459  }
460  case PROP_INT: {
461  if (array_index != -1) {
462  const int orig_value_coerce = RNA_property_int_get_index(ptr, prop, array_index);
463  orig_value = (float)orig_value_coerce;
464  }
465  else {
466  const int orig_value_coerce = RNA_property_int_get(ptr, prop);
467  orig_value = (float)orig_value_coerce;
468  }
469  break;
470  }
471  case PROP_FLOAT: {
472  if (array_index != -1) {
473  const float orig_value_coerce = RNA_property_float_get_index(ptr, prop, array_index);
474  orig_value = (float)orig_value_coerce;
475  }
476  else {
477  const float orig_value_coerce = RNA_property_float_get(ptr, prop);
478  orig_value = (float)orig_value_coerce;
479  }
480  break;
481  }
482  case PROP_ENUM: {
483  const int orig_value_coerce = RNA_property_enum_get(ptr, prop);
484  orig_value = (float)orig_value_coerce;
485  break;
486  }
487  default:
488  /* nothing can be done here... so it is unsuccessful? */
489  return false;
490  }
491 
492  if (r_value != NULL) {
493  *r_value = orig_value;
494  }
495 
496  /* successful */
497  return true;
498 }
499 
500 /* Write the given value to a setting using RNA, and return success */
501 bool BKE_animsys_write_to_rna_path(PathResolvedRNA *anim_rna, const float value)
502 {
503  PropertyRNA *prop = anim_rna->prop;
504  PointerRNA *ptr = &anim_rna->ptr;
505  int array_index = anim_rna->prop_index;
506 
507  /* caller must ensure this is animatable */
509 
510  /* Check whether value is new. Otherwise we skip all the updates. */
511  float old_value;
512  if (!BKE_animsys_read_from_rna_path(anim_rna, &old_value)) {
513  return false;
514  }
515  if (old_value == value) {
516  return true;
517  }
518 
519  switch (RNA_property_type(prop)) {
520  case PROP_BOOLEAN: {
521  const int value_coerce = ANIMSYS_FLOAT_AS_BOOL(value);
522  if (array_index != -1) {
523  RNA_property_boolean_set_index(ptr, prop, array_index, value_coerce);
524  }
525  else {
526  RNA_property_boolean_set(ptr, prop, value_coerce);
527  }
528  break;
529  }
530  case PROP_INT: {
531  int value_coerce = (int)value;
532  RNA_property_int_clamp(ptr, prop, &value_coerce);
533  if (array_index != -1) {
534  RNA_property_int_set_index(ptr, prop, array_index, value_coerce);
535  }
536  else {
537  RNA_property_int_set(ptr, prop, value_coerce);
538  }
539  break;
540  }
541  case PROP_FLOAT: {
542  float value_coerce = value;
543  RNA_property_float_clamp(ptr, prop, &value_coerce);
544  if (array_index != -1) {
545  RNA_property_float_set_index(ptr, prop, array_index, value_coerce);
546  }
547  else {
548  RNA_property_float_set(ptr, prop, value_coerce);
549  }
550  break;
551  }
552  case PROP_ENUM: {
553  const int value_coerce = (int)value;
554  RNA_property_enum_set(ptr, prop, value_coerce);
555  break;
556  }
557  default:
558  /* nothing can be done here... so it is unsuccessful? */
559  return false;
560  }
561 
562  /* successful */
563  return true;
564 }
565 
567 {
568  *ptr_orig = *ptr;
569  /* NOTE: nlastrip_evaluate_controls() creates PointerRNA with ID of NULL. Technically, this is
570  * not a valid pointer, but there are exceptions in various places of this file which handles
571  * such pointers.
572  * We do special trickery here as well, to quickly go from evaluated to original NlaStrip. */
573  if (ptr->owner_id == NULL) {
574  if (ptr->type != &RNA_NlaStrip) {
575  return false;
576  }
577  NlaStrip *strip = ((NlaStrip *)ptr_orig->data);
578  if (strip->orig_strip == NULL) {
579  return false;
580  }
581  ptr_orig->data = strip->orig_strip;
582  }
583  else {
584  ptr_orig->owner_id = ptr_orig->owner_id->orig_id;
585  ptr_orig->data = ptr_orig->owner_id;
586  }
587  return true;
588 }
589 
591  const char *rna_path,
592  int array_index,
593  float value)
594 {
595  PointerRNA ptr_orig;
596  if (!animsys_construct_orig_pointer_rna(ptr, &ptr_orig)) {
597  return;
598  }
599  PathResolvedRNA orig_anim_rna;
600  /* TODO(sergey): Should be possible to cache resolved path in dependency graph somehow. */
601  if (BKE_animsys_rna_path_resolve(&ptr_orig, rna_path, array_index, &orig_anim_rna)) {
602  BKE_animsys_write_to_rna_path(&orig_anim_rna, value);
603  }
604 }
605 
612  ListBase *list,
613  const AnimationEvalContext *anim_eval_context,
614  bool flush_to_original)
615 {
616  /* Calculate then execute each curve. */
617  LISTBASE_FOREACH (FCurve *, fcu, list) {
618 
619  if (!is_fcurve_evaluatable(fcu)) {
620  continue;
621  }
622 
623  PathResolvedRNA anim_rna;
624  if (BKE_animsys_rna_path_resolve(ptr, fcu->rna_path, fcu->array_index, &anim_rna)) {
625  const float curval = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
626  BKE_animsys_write_to_rna_path(&anim_rna, curval);
627  if (flush_to_original) {
628  animsys_write_orig_anim_rna(ptr, fcu->rna_path, fcu->array_index, curval);
629  }
630  }
631  }
632 }
633 
634 /* ***************************************** */
635 /* Driver Evaluation */
636 
638  float eval_time)
639 {
640  AnimationEvalContext ctx = {
641  .depsgraph = depsgraph,
642  .eval_time = eval_time,
643  };
644  return ctx;
645 }
646 
648  const AnimationEvalContext *anim_eval_context, float eval_time)
649 {
650  return BKE_animsys_eval_context_construct(anim_eval_context->depsgraph, eval_time);
651 }
652 
653 /* Evaluate Drivers */
655  AnimData *adt,
656  const AnimationEvalContext *anim_eval_context)
657 {
658  FCurve *fcu;
659 
660  /* drivers are stored as F-Curves, but we cannot use the standard code, as we need to check if
661  * the depsgraph requested that this driver be evaluated...
662  */
663  for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
664  ChannelDriver *driver = fcu->driver;
665  bool ok = false;
666 
667  /* check if this driver's curve should be skipped */
668  if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) {
669  /* check if driver itself is tagged for recalculation */
670  /* XXX driver recalc flag is not set yet by depsgraph! */
671  if ((driver) && !(driver->flag & DRIVER_FLAG_INVALID)) {
672  /* evaluate this using values set already in other places
673  * NOTE: for 'layering' option later on, we should check if we should remove old value
674  * before adding new to only be done when drivers only changed. */
675  PathResolvedRNA anim_rna;
676  if (BKE_animsys_rna_path_resolve(ptr, fcu->rna_path, fcu->array_index, &anim_rna)) {
677  const float curval = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
678  ok = BKE_animsys_write_to_rna_path(&anim_rna, curval);
679  }
680 
681  /* set error-flag if evaluation failed */
682  if (ok == 0) {
683  driver->flag |= DRIVER_FLAG_INVALID;
684  }
685  }
686  }
687  }
688 }
689 
690 /* ***************************************** */
691 /* Actions Evaluation */
692 
693 /* strictly not necessary for actual "evaluation", but it is a useful safety check
694  * to reduce the amount of times that users end up having to "revive" wrongly-assigned
695  * actions
696  */
697 static void action_idcode_patch_check(ID *id, bAction *act)
698 {
699  int idcode = 0;
700 
701  /* just in case */
702  if (ELEM(NULL, id, act)) {
703  return;
704  }
705 
706  idcode = GS(id->name);
707 
708  /* the actual checks... hopefully not too much of a performance hit in the long run... */
709  if (act->idroot == 0) {
710  /* use the current root if not set already
711  * (i.e. newly created actions and actions from 2.50-2.57 builds).
712  * - this has problems if there are 2 users, and the first one encountered is the invalid one
713  * in which case, the user will need to manually fix this (?)
714  */
715  act->idroot = idcode;
716  }
717  else if (act->idroot != idcode) {
718  /* only report this error if debug mode is enabled (to save performance everywhere else) */
719  if (G.debug & G_DEBUG) {
720  printf(
721  "AnimSys Safety Check Failed: Action '%s' is not meant to be used from ID-Blocks of "
722  "type %d such as '%s'\n",
723  act->id.name + 2,
724  idcode,
725  id->name);
726  }
727  }
728 }
729 
730 /* ----------------------------------------- */
731 
732 /* Evaluate Action Group */
734  bAction *act,
735  bActionGroup *agrp,
736  const AnimationEvalContext *anim_eval_context)
737 {
738  FCurve *fcu;
739 
740  /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */
741  if (ELEM(NULL, act, agrp)) {
742  return;
743  }
744 
746 
747  /* if group is muted, don't evaluated any of the F-Curve */
748  if (agrp->flag & AGRP_MUTED) {
749  return;
750  }
751 
752  /* calculate then execute each curve */
753  for (fcu = agrp->channels.first; (fcu) && (fcu->grp == agrp); fcu = fcu->next) {
754  /* check if this curve should be skipped */
755  if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0 && !BKE_fcurve_is_empty(fcu)) {
756  PathResolvedRNA anim_rna;
757  if (BKE_animsys_rna_path_resolve(ptr, fcu->rna_path, fcu->array_index, &anim_rna)) {
758  const float curval = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
759  BKE_animsys_write_to_rna_path(&anim_rna, curval);
760  }
761  }
762  }
763 }
764 
765 /* Evaluate Action (F-Curve Bag) */
767  bAction *act,
768  const AnimationEvalContext *anim_eval_context,
769  const bool flush_to_original)
770 {
771  /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */
772  if (act == NULL) {
773  return;
774  }
775 
777 
778  /* calculate then execute each curve */
779  animsys_evaluate_fcurves(ptr, &act->curves, anim_eval_context, flush_to_original);
780 }
781 
782 /* ***************************************** */
783 /* NLA System - Evaluation */
784 
785 /* calculate influence of strip based for given frame based on blendin/out values */
786 static float nlastrip_get_influence(NlaStrip *strip, float cframe)
787 {
788  /* sanity checks - normalize the blendin/out values? */
789  strip->blendin = fabsf(strip->blendin);
790  strip->blendout = fabsf(strip->blendout);
791 
792  /* result depends on where frame is in respect to blendin/out values */
793  if (IS_EQF(strip->blendin, 0.0f) == false && (cframe <= (strip->start + strip->blendin))) {
794  /* there is some blend-in */
795  return fabsf(cframe - strip->start) / (strip->blendin);
796  }
797  if (IS_EQF(strip->blendout, 0.0f) == false && (cframe >= (strip->end - strip->blendout))) {
798  /* there is some blend-out */
799  return fabsf(strip->end - cframe) / (strip->blendout);
800  }
801 
802  /* in the middle of the strip, we should be full strength */
803  return 1.0f;
804 }
805 
806 /* evaluate the evaluation time and influence for the strip, storing the results in the strip */
808  const AnimationEvalContext *anim_eval_context,
809  const bool flush_to_original)
810 {
811  /* now strip's evaluate F-Curves for these settings (if applicable) */
812  if (strip->fcurves.first) {
813  PointerRNA strip_ptr;
814 
815  /* create RNA-pointer needed to set values */
816  RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr);
817 
818  /* execute these settings as per normal */
819  animsys_evaluate_fcurves(&strip_ptr, &strip->fcurves, anim_eval_context, flush_to_original);
820  }
821 
822  /* analytically generate values for influence and time (if applicable)
823  * - we do this after the F-Curves have been evaluated to override the effects of those
824  * in case the override has been turned off.
825  */
826  if ((strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) == 0) {
827  strip->influence = nlastrip_get_influence(strip, anim_eval_context->eval_time);
828  }
829 
830  /* Bypass evaluation time computation if time mapping is disabled. */
831  if ((strip->flag & NLASTRIP_FLAG_NO_TIME_MAP) != 0) {
832  strip->strip_time = anim_eval_context->eval_time;
833  return;
834  }
835 
836  if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0) {
838  strip, anim_eval_context->eval_time, NLATIME_CONVERT_EVAL);
839  }
840 
841  /* if user can control the evaluation time (using F-Curves), consider the option which allows
842  * this time to be clamped to lie within extents of the action-clip, so that a steady changing
843  * rate of progress through several cycles of the clip can be achieved easily.
844  */
845  /* NOTE: if we add any more of these special cases, we better group them up nicely... */
846  if ((strip->flag & NLASTRIP_FLAG_USR_TIME) && (strip->flag & NLASTRIP_FLAG_USR_TIME_CYCLIC)) {
847  strip->strip_time = fmod(strip->strip_time - strip->actstart, strip->actend - strip->actstart);
848  }
849 }
850 
851 /* gets the strip active at the current time for a list of strips for evaluation purposes */
853  ListBase *strips,
854  short index,
855  const AnimationEvalContext *anim_eval_context,
856  const bool flush_to_original)
857 {
858  NlaStrip *strip, *estrip = NULL;
859  NlaEvalStrip *nes;
860  short side = 0;
861  float ctime = anim_eval_context->eval_time;
862 
863  /* loop over strips, checking if they fall within the range */
864  for (strip = strips->first; strip; strip = strip->next) {
865  /* check if current time occurs within this strip */
866  if (IN_RANGE_INCL(ctime, strip->start, strip->end) ||
867  (strip->flag & NLASTRIP_FLAG_NO_TIME_MAP)) {
868  /* this strip is active, so try to use it */
869  estrip = strip;
870  side = NES_TIME_WITHIN;
871  break;
872  }
873 
874  /* if time occurred before current strip... */
875  if (ctime < strip->start) {
876  if (strip == strips->first) {
877  /* before first strip - only try to use it if it extends backwards in time too */
878  if (strip->extendmode == NLASTRIP_EXTEND_HOLD) {
879  estrip = strip;
880  }
881 
882  /* side is 'before' regardless of whether there's a useful strip */
883  side = NES_TIME_BEFORE;
884  }
885  else {
886  /* before next strip - previous strip has ended, but next hasn't begun,
887  * so blending mode depends on whether strip is being held or not...
888  * - only occurs when no transition strip added, otherwise the transition would have
889  * been picked up above...
890  */
891  strip = strip->prev;
892 
893  if (strip->extendmode != NLASTRIP_EXTEND_NOTHING) {
894  estrip = strip;
895  }
896  side = NES_TIME_AFTER;
897  }
898  break;
899  }
900 
901  /* if time occurred after current strip... */
902  if (ctime > strip->end) {
903  /* only if this is the last strip should we do anything, and only if that is being held */
904  if (strip == strips->last) {
905  if (strip->extendmode != NLASTRIP_EXTEND_NOTHING) {
906  estrip = strip;
907  }
908 
909  side = NES_TIME_AFTER;
910  break;
911  }
912 
913  /* otherwise, skip... as the 'before' case will catch it more elegantly! */
914  }
915  }
916 
917  /* check if a valid strip was found
918  * - must not be muted (i.e. will have contribution
919  */
920  if ((estrip == NULL) || (estrip->flag & NLASTRIP_FLAG_MUTED)) {
921  return NULL;
922  }
923 
924  /* if ctime was not within the boundaries of the strip, clamp! */
925  switch (side) {
926  case NES_TIME_BEFORE: /* extend first frame only */
927  ctime = estrip->start;
928  break;
929  case NES_TIME_AFTER: /* extend last frame only */
930  ctime = estrip->end;
931  break;
932  }
933 
934  /* evaluate strip's evaluation controls
935  * - skip if no influence (i.e. same effect as muting the strip)
936  * - negative influence is not supported yet... how would that be defined?
937  */
938  /* TODO: this sounds a bit hacky having a few isolated F-Curves
939  * stuck on some data it operates on... */
941  anim_eval_context, ctime);
942  nlastrip_evaluate_controls(estrip, &clamped_eval_context, flush_to_original);
943  if (estrip->influence <= 0.0f) {
944  return NULL;
945  }
946 
947  /* check if strip has valid data to evaluate,
948  * and/or perform any additional type-specific actions
949  */
950  switch (estrip->type) {
951  case NLASTRIP_TYPE_CLIP:
952  /* clip must have some action to evaluate */
953  if (estrip->act == NULL) {
954  return NULL;
955  }
956  break;
958  /* there must be strips to transition from and to (i.e. prev and next required) */
959  if (ELEM(NULL, estrip->prev, estrip->next)) {
960  return NULL;
961  }
962 
963  /* evaluate controls for the relevant extents of the bordering strips... */
965  anim_eval_context, estrip->start);
967  anim_eval_context, estrip->end);
968  nlastrip_evaluate_controls(estrip->prev, &start_eval_context, flush_to_original);
969  nlastrip_evaluate_controls(estrip->next, &end_eval_context, flush_to_original);
970  break;
971  }
972 
973  /* add to list of strips we need to evaluate */
974  nes = MEM_callocN(sizeof(NlaEvalStrip), "NlaEvalStrip");
975 
976  nes->strip = estrip;
977  nes->strip_mode = side;
978  nes->track_index = index;
979  nes->strip_time = estrip->strip_time;
980 
981  if (list) {
982  BLI_addtail(list, nes);
983  }
984 
985  return nes;
986 }
987 
989  ListBase *dst_list,
990  NlaStrip *single_strip,
991  const AnimationEvalContext *anim_eval_context,
992  const bool flush_to_original)
993 {
994  ListBase single_tracks_list;
995  single_tracks_list.first = single_tracks_list.last = single_strip;
996 
998  dst_list, &single_tracks_list, -1, anim_eval_context, flush_to_original);
999 }
1000 
1001 /* ---------------------- */
1002 
1003 /* Initialize a valid mask, allocating memory if necessary. */
1004 static void nlavalidmask_init(NlaValidMask *mask, int bits)
1005 {
1006  if (BLI_BITMAP_SIZE(bits) > sizeof(mask->buffer)) {
1007  mask->ptr = BLI_BITMAP_NEW(bits, "NlaValidMask");
1008  }
1009  else {
1010  mask->ptr = mask->buffer;
1011  }
1012 }
1013 
1014 /* Free allocated memory for the mask. */
1016 {
1017  if (mask->ptr != mask->buffer) {
1018  MEM_freeN(mask->ptr);
1019  }
1020 }
1021 
1022 /* ---------------------- */
1023 
1024 /* Hashing functions for NlaEvalChannelKey. */
1025 static uint nlaevalchan_keyhash(const void *ptr)
1026 {
1027  const NlaEvalChannelKey *key = ptr;
1029  return hash ^ BLI_ghashutil_ptrhash(key->prop);
1030 }
1031 
1032 static bool nlaevalchan_keycmp(const void *a, const void *b)
1033 {
1034  const NlaEvalChannelKey *A = a;
1035  const NlaEvalChannelKey *B = b;
1036 
1037  return ((A->ptr.data != B->ptr.data) || (A->prop != B->prop));
1038 }
1039 
1040 /* ---------------------- */
1041 
1042 /* Allocate a new blending value snapshot for the channel. */
1044 {
1045  int length = nec->base_snapshot.length;
1046 
1047  size_t byte_size = sizeof(NlaEvalChannelSnapshot) + sizeof(float) * length;
1048  NlaEvalChannelSnapshot *nec_snapshot = MEM_callocN(byte_size, "NlaEvalChannelSnapshot");
1049 
1050  nec_snapshot->channel = nec;
1051  nec_snapshot->length = length;
1052  nlavalidmask_init(&nec_snapshot->blend_domain, length);
1053 
1054  return nec_snapshot;
1055 }
1056 
1057 /* Free a channel's blending value snapshot. */
1059 {
1060  BLI_assert(!nec_snapshot->is_base);
1061 
1062  nlavalidmask_free(&nec_snapshot->blend_domain);
1063  MEM_freeN(nec_snapshot);
1064 }
1065 
1066 /* Copy all data in the snapshot. */
1068  const NlaEvalChannelSnapshot *src)
1069 {
1070  BLI_assert(dst->channel == src->channel);
1071 
1072  memcpy(dst->values, src->values, sizeof(float) * dst->length);
1073 }
1074 
1075 /* ---------------------- */
1076 
1077 /* Initialize a blending state snapshot structure. */
1079  NlaEvalData *nlaeval,
1080  NlaEvalSnapshot *base)
1081 {
1082  snapshot->base = base;
1083  snapshot->size = MAX2(16, nlaeval->num_channels);
1084  snapshot->channels = MEM_callocN(sizeof(*snapshot->channels) * snapshot->size,
1085  "NlaEvalSnapshot::channels");
1086 }
1087 
1088 /* Retrieve the individual channel snapshot. */
1090 {
1091  return (index < snapshot->size) ? snapshot->channels[index] : NULL;
1092 }
1093 
1094 /* Ensure at least this number of slots exists. */
1096 {
1097  if (size > snapshot->size) {
1098  snapshot->size *= 2;
1099  CLAMP_MIN(snapshot->size, size);
1100  CLAMP_MIN(snapshot->size, 16);
1101 
1102  size_t byte_size = sizeof(*snapshot->channels) * snapshot->size;
1103  snapshot->channels = MEM_recallocN_id(
1104  snapshot->channels, byte_size, "NlaEvalSnapshot::channels");
1105  }
1106 }
1107 
1108 /* Retrieve the address of a slot in the blending state snapshot for this channel (may realloc). */
1110  NlaEvalChannel *nec)
1111 {
1113  return &snapshot->channels[nec->index];
1114 }
1115 
1116 /* Retrieve the blending snapshot for the specified channel, with fallback to base. */
1118  NlaEvalChannel *nec)
1119 {
1120  while (snapshot != NULL) {
1121  NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_get(snapshot, nec->index);
1122  if (nec_snapshot != NULL) {
1123  return nec_snapshot;
1124  }
1125  snapshot = snapshot->base;
1126  }
1127 
1128  return &nec->base_snapshot;
1129 }
1130 
1131 /* Retrieve or create the channel value snapshot, copying from the other snapshot
1132  * (or default values) */
1134  NlaEvalChannel *nec)
1135 {
1136  NlaEvalChannelSnapshot **slot = nlaeval_snapshot_ensure_slot(snapshot, nec);
1137 
1138  if (*slot == NULL) {
1139  NlaEvalChannelSnapshot *base_snapshot, *nec_snapshot;
1140 
1141  nec_snapshot = nlaevalchan_snapshot_new(nec);
1142  base_snapshot = nlaeval_snapshot_find_channel(snapshot->base, nec);
1143 
1144  nlaevalchan_snapshot_copy(nec_snapshot, base_snapshot);
1145 
1146  *slot = nec_snapshot;
1147  }
1148 
1149  return *slot;
1150 }
1151 
1152 /* Free all memory owned by this blending snapshot structure. */
1154 {
1155  if (snapshot->channels != NULL) {
1156  for (int i = 0; i < snapshot->size; i++) {
1157  NlaEvalChannelSnapshot *nec_snapshot = snapshot->channels[i];
1158  if (nec_snapshot != NULL) {
1159  nlaevalchan_snapshot_free(nec_snapshot);
1160  }
1161  }
1162 
1163  MEM_freeN(snapshot->channels);
1164  }
1165 
1166  snapshot->base = NULL;
1167  snapshot->size = 0;
1168  snapshot->channels = NULL;
1169 }
1170 
1171 /* ---------------------- */
1172 
1173 /* Free memory owned by this evaluation channel. */
1175 {
1176  nlavalidmask_free(&nec->domain);
1177 }
1178 
1179 /* Initialize a full NLA evaluation state structure. */
1180 static void nlaeval_init(NlaEvalData *nlaeval)
1181 {
1182  memset(nlaeval, 0, sizeof(*nlaeval));
1183 
1184  nlaeval->path_hash = BLI_ghash_str_new("NlaEvalData::path_hash");
1185  nlaeval->key_hash = BLI_ghash_new(
1186  nlaevalchan_keyhash, nlaevalchan_keycmp, "NlaEvalData::key_hash");
1187 }
1188 
1189 static void nlaeval_free(NlaEvalData *nlaeval)
1190 {
1191  /* Delete base snapshot - its channels are part of NlaEvalChannel and shouldn't be freed. */
1193 
1194  /* Delete result snapshot. */
1196 
1197  /* Delete channels. */
1198  LISTBASE_FOREACH (NlaEvalChannel *, nec, &nlaeval->channels) {
1199  nlaevalchan_free_data(nec);
1200  }
1201 
1202  BLI_freelistN(&nlaeval->channels);
1203  BLI_ghash_free(nlaeval->path_hash, NULL, NULL);
1204  BLI_ghash_free(nlaeval->key_hash, NULL, NULL);
1205 }
1206 
1207 /* ---------------------- */
1208 
1209 static int nlaevalchan_validate_index(const NlaEvalChannel *nec, int index)
1210 {
1211  if (nec->is_array) {
1212  if (index >= 0 && index < nec->base_snapshot.length) {
1213  return index;
1214  }
1215 
1216  return -1;
1217  }
1218  return 0;
1219 }
1220 
1221 static bool nlaevalchan_validate_index_ex(const NlaEvalChannel *nec, const int array_index)
1222 {
1225  const int index = nlaevalchan_validate_index(nec, array_index);
1226 
1227  if (index < 0) {
1228  if (G.debug & G_DEBUG) {
1229  ID *id = nec->key.ptr.owner_id;
1230  CLOG_WARN(&LOG,
1231  "Animation: Invalid array index. ID = '%s', '%s[%d]', array length is %d",
1232  id ? (id->name + 2) : "<No ID>",
1233  nec->rna_path,
1234  array_index,
1235  nec->base_snapshot.length);
1236  }
1237 
1238  return false;
1239  }
1240  return true;
1241 }
1242 
1243 /* Initialize default values for NlaEvalChannel from the property data. */
1244 static void nlaevalchan_get_default_values(NlaEvalChannel *nec, float *r_values)
1245 {
1246  PointerRNA *ptr = &nec->key.ptr;
1247  PropertyRNA *prop = nec->key.prop;
1248  int length = nec->base_snapshot.length;
1249 
1250  /* Use unit quaternion for quaternion properties. */
1251  if (nec->mix_mode == NEC_MIX_QUATERNION) {
1252  unit_qt(r_values);
1253  return;
1254  }
1255  /* Use all zero for Axis-Angle properties. */
1256  if (nec->mix_mode == NEC_MIX_AXIS_ANGLE) {
1257  zero_v4(r_values);
1258  return;
1259  }
1260 
1261  /* NOTE: while this doesn't work for all RNA properties as default values aren't in fact
1262  * set properly for most of them, at least the common ones (which also happen to get used
1263  * in NLA strips a lot, e.g. scale) are set correctly.
1264  */
1265  if (RNA_property_array_check(prop)) {
1267  bool *tmp_bool;
1268  int *tmp_int;
1269 
1270  switch (RNA_property_type(prop)) {
1271  case PROP_BOOLEAN:
1272  tmp_bool = MEM_malloc_arrayN(sizeof(*tmp_bool), length, __func__);
1274  for (int i = 0; i < length; i++) {
1275  r_values[i] = (float)tmp_bool[i];
1276  }
1277  MEM_freeN(tmp_bool);
1278  break;
1279  case PROP_INT:
1280  tmp_int = MEM_malloc_arrayN(sizeof(*tmp_int), length, __func__);
1281  RNA_property_int_get_default_array(ptr, prop, tmp_int);
1282  for (int i = 0; i < length; i++) {
1283  r_values[i] = (float)tmp_int[i];
1284  }
1285  MEM_freeN(tmp_int);
1286  break;
1287  case PROP_FLOAT:
1288  RNA_property_float_get_default_array(ptr, prop, r_values);
1289  break;
1290  default:
1291  memset(r_values, 0, sizeof(float) * length);
1292  }
1293  }
1294  else {
1295  BLI_assert(length == 1);
1296 
1297  switch (RNA_property_type(prop)) {
1298  case PROP_BOOLEAN:
1299  *r_values = (float)RNA_property_boolean_get_default(ptr, prop);
1300  break;
1301  case PROP_INT:
1302  *r_values = (float)RNA_property_int_get_default(ptr, prop);
1303  break;
1304  case PROP_FLOAT:
1305  *r_values = RNA_property_float_get_default(ptr, prop);
1306  break;
1307  case PROP_ENUM:
1308  *r_values = (float)RNA_property_enum_get_default(ptr, prop);
1309  break;
1310  default:
1311  *r_values = 0.0f;
1312  }
1313  }
1314 
1315  /* Ensure multiplicative properties aren't reset to 0. */
1316  if (nec->mix_mode == NEC_MIX_MULTIPLY) {
1317  for (int i = 0; i < length; i++) {
1318  if (r_values[i] == 0.0f) {
1319  r_values[i] = 1.0f;
1320  }
1321  }
1322  }
1323 }
1324 
1326 {
1327  PropertySubType subtype = RNA_property_subtype(key->prop);
1328 
1329  if (subtype == PROP_QUATERNION && length == 4) {
1330  return NEC_MIX_QUATERNION;
1331  }
1332  if (subtype == PROP_AXISANGLE && length == 4) {
1333  return NEC_MIX_AXIS_ANGLE;
1334  }
1336  return NEC_MIX_MULTIPLY;
1337  }
1338  return NEC_MIX_ADD;
1339 }
1340 
1341 /* Verify that an appropriate NlaEvalChannel for this property exists. */
1343  const char *path,
1344  NlaEvalChannelKey *key)
1345 {
1346  /* Look it up in the key hash. */
1347  NlaEvalChannel **p_key_nec;
1348  NlaEvalChannelKey **p_key;
1349  bool found_key = BLI_ghash_ensure_p_ex(
1350  nlaeval->key_hash, key, (void ***)&p_key, (void ***)&p_key_nec);
1351 
1352  if (found_key) {
1353  return *p_key_nec;
1354  }
1355 
1356  /* Create the channel. */
1357  bool is_array = RNA_property_array_check(key->prop);
1358  int length = is_array ? RNA_property_array_length(&key->ptr, key->prop) : 1;
1359 
1360  NlaEvalChannel *nec = MEM_callocN(sizeof(NlaEvalChannel) + sizeof(float) * length,
1361  "NlaEvalChannel");
1362 
1363  /* Initialize the channel. */
1364  nec->rna_path = path;
1365  nec->key = *key;
1366 
1367  nec->owner = nlaeval;
1368  nec->index = nlaeval->num_channels++;
1369  nec->is_array = is_array;
1370 
1372 
1374 
1375  nec->base_snapshot.channel = nec;
1376  nec->base_snapshot.length = length;
1377  nec->base_snapshot.is_base = true;
1378 
1380 
1381  /* Store channel in data structures. */
1382  BLI_addtail(&nlaeval->channels, nec);
1383 
1384  *nlaeval_snapshot_ensure_slot(&nlaeval->base_snapshot, nec) = &nec->base_snapshot;
1385 
1386  *p_key_nec = nec;
1387  *p_key = &nec->key;
1388 
1389  return nec;
1390 }
1391 
1392 /* Verify that an appropriate NlaEvalChannel for this path exists. */
1393 static NlaEvalChannel *nlaevalchan_verify(PointerRNA *ptr, NlaEvalData *nlaeval, const char *path)
1394 {
1395  if (path == NULL) {
1396  return NULL;
1397  }
1398 
1399  /* Lookup the path in the path based hash. */
1400  NlaEvalChannel **p_path_nec;
1401  bool found_path = BLI_ghash_ensure_p(nlaeval->path_hash, (void *)path, (void ***)&p_path_nec);
1402 
1403  if (found_path) {
1404  return *p_path_nec;
1405  }
1406 
1407  /* Cache NULL result for now. */
1408  *p_path_nec = NULL;
1409 
1410  /* Resolve the property and look it up in the key hash. */
1411  NlaEvalChannelKey key;
1412 
1413  if (!RNA_path_resolve_property(ptr, path, &key.ptr, &key.prop)) {
1414  /* Report failure to resolve the path. */
1415  if (G.debug & G_DEBUG) {
1416  CLOG_WARN(&LOG,
1417  "Animato: Invalid path. ID = '%s', '%s'",
1418  (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>",
1419  path);
1420  }
1421 
1422  return NULL;
1423  }
1424 
1425  /* Check that the property can be animated. */
1426  if (ptr->owner_id != NULL && !RNA_property_animateable(&key.ptr, key.prop)) {
1427  return NULL;
1428  }
1429 
1430  NlaEvalChannel *nec = nlaevalchan_verify_key(nlaeval, path, &key);
1431 
1432  if (nec->rna_path == NULL) {
1433  nec->rna_path = path;
1434  }
1435 
1436  return *p_path_nec = nec;
1437 }
1438 
1439 /* ---------------------- */
1440 
1441 /* Blend the lower nla stack value and upper strip value of a channel according to mode and
1442  * influence. */
1443 static float nla_blend_value(const int blendmode,
1444  const float lower_value,
1445  const float strip_value,
1446  const float influence)
1447 {
1448  /* Optimization: no need to try applying if there is no influence. */
1449  if (IS_EQF(influence, 0.0f)) {
1450  return lower_value;
1451  }
1452 
1453  /* Perform blending. */
1454  switch (blendmode) {
1455  case NLASTRIP_MODE_ADD:
1456  /* Simply add the scaled value on to the stack. */
1457  return lower_value + (strip_value * influence);
1458 
1460  /* Simply subtract the scaled value from the stack. */
1461  return lower_value - (strip_value * influence);
1462 
1464  /* Multiply the scaled value with the stack. */
1465  return influence * (lower_value * strip_value) + (1 - influence) * lower_value;
1466 
1467  case NLASTRIP_MODE_COMBINE:
1468  BLI_assert(!"combine mode");
1470 
1471  default:
1472  /* TODO: Do we really want to blend by default? it seems more uses might prefer add... */
1473  /* Do linear interpolation. The influence of the accumulated data (elsewhere, that is called
1474  * dstweight) is 1 - influence, since the strip's influence is srcweight.
1475  */
1476  return lower_value * (1.0f - influence) + (strip_value * influence);
1477  }
1478 }
1479 
1480 /* Blend the lower nla stack value and upper strip value of a channel according to mode and
1481  * influence. */
1482 static float nla_combine_value(const int mix_mode,
1483  float base_value,
1484  const float lower_value,
1485  const float strip_value,
1486  const float influence)
1487 {
1488  /* Optimization: No need to try applying if there is no influence. */
1489  if (IS_EQF(influence, 0.0f)) {
1490  return lower_value;
1491  }
1492 
1493  /* Perform blending */
1494  switch (mix_mode) {
1495  case NEC_MIX_ADD:
1496  case NEC_MIX_AXIS_ANGLE:
1497  return lower_value + (strip_value - base_value) * influence;
1498 
1499  case NEC_MIX_MULTIPLY:
1500  if (IS_EQF(base_value, 0.0f)) {
1501  base_value = 1.0f;
1502  }
1503  return lower_value * powf(strip_value / base_value, influence);
1504 
1505  default:
1506  BLI_assert(!"invalid mix mode");
1507  return lower_value;
1508  }
1509 }
1510 
1512 static bool nla_blend_get_inverted_strip_value(const int blendmode,
1513  const float lower_value,
1514  const float blended_value,
1515  const float influence,
1516  float *r_strip_value)
1517 {
1519  if (IS_EQF(influence, 0.0f)) {
1520  return false;
1521  }
1522 
1523  switch (blendmode) {
1524  case NLASTRIP_MODE_ADD:
1525  *r_strip_value = (blended_value - lower_value) / influence;
1526  return true;
1527 
1529  *r_strip_value = (lower_value - blended_value) / influence;
1530  return true;
1531 
1533  if (IS_EQF(lower_value, 0.0f)) {
1534  /* Resolve 0/0 to 1. */
1535  if (IS_EQF(blended_value, 0.0f)) {
1536  *r_strip_value = 1.0f;
1537  return true;
1538  }
1539  /* Division by zero. */
1540  return false;
1541  }
1542 
1553  *r_strip_value = ((blended_value - lower_value) / (influence * lower_value)) + 1.0f;
1554  return true;
1555 
1556  case NLASTRIP_MODE_COMBINE:
1557  BLI_assert(!"combine mode");
1559 
1560  default:
1561 
1570  *r_strip_value = (blended_value - lower_value * (1.0f - influence)) / influence;
1571  return true;
1572  }
1573 }
1574 
1576 static bool nla_combine_get_inverted_strip_value(const int mix_mode,
1577  float base_value,
1578  const float lower_value,
1579  const float blended_value,
1580  const float influence,
1581  float *r_strip_value)
1582 {
1583  /* No solution if strip had no influence. */
1584  if (IS_EQF(influence, 0.0f)) {
1585  return false;
1586  }
1587 
1588  switch (mix_mode) {
1589  case NEC_MIX_ADD:
1590  case NEC_MIX_AXIS_ANGLE:
1591  *r_strip_value = base_value + (blended_value - lower_value) / influence;
1592  return true;
1593 
1594  case NEC_MIX_MULTIPLY:
1595  if (IS_EQF(base_value, 0.0f)) {
1596  base_value = 1.0f;
1597  }
1598  /* Division by zero. */
1599  if (IS_EQF(lower_value, 0.0f)) {
1600  /* Resolve 0/0 to 1. */
1601  if (IS_EQF(blended_value, 0.0f)) {
1602  *r_strip_value = base_value;
1603  return true;
1604  }
1605  /* Division by zero. */
1606  return false;
1607  }
1608 
1609  *r_strip_value = base_value * powf(blended_value / lower_value, 1.0f / influence);
1610  return true;
1611 
1612  default:
1613  BLI_assert(!"invalid mix mode");
1614  return false;
1615  }
1616 }
1617 
1622 static void nla_combine_quaternion(const float lower_values[4],
1623  const float strip_values[4],
1624  const float influence,
1625  float r_blended_value[4])
1626 {
1627  float tmp_lower[4], tmp_strip_values[4];
1628 
1629  normalize_qt_qt(tmp_lower, lower_values);
1630  normalize_qt_qt(tmp_strip_values, strip_values);
1631 
1632  pow_qt_fl_normalized(tmp_strip_values, influence);
1633  mul_qt_qtqt(r_blended_value, tmp_lower, tmp_strip_values);
1634 }
1635 
1637 static bool nla_combine_quaternion_get_inverted_strip_values(const float lower_values[4],
1638  const float blended_values[4],
1639  const float influence,
1640  float r_strip_values[4])
1641 {
1642  /* blended_value = lower_values @ r_strip_values^infl
1643  * inv(lower_values) @ blended_value = r_strip_values^infl
1644  * (inv(lower_values) @ blended_value) ^ (1/inf) = r_strip_values
1645  *
1646  * Returns: r_strip_values = (inv(lower_values) @ blended_value) ^ (1/inf) */
1647  if (IS_EQF(influence, 0.0f)) {
1648  return false;
1649  }
1650  float tmp_lower[4], tmp_blended[4];
1651 
1652  normalize_qt_qt(tmp_lower, lower_values);
1653  normalize_qt_qt(tmp_blended, blended_values);
1654  invert_qt_normalized(tmp_lower);
1655 
1656  mul_qt_qtqt(r_strip_values, tmp_lower, tmp_blended);
1657  pow_qt_fl_normalized(r_strip_values, 1.0f / influence);
1658 
1659  return true;
1660 }
1661 
1662 /* ---------------------- */
1663 /* F-Modifier stack joining/separation utilities -
1664  * should we generalize these for BLI_listbase.h interface? */
1665 
1666 /* Temporarily join two lists of modifiers together, storing the result in a third list */
1668 {
1669  FModifier *fcm1, *fcm2;
1670 
1671  /* if list1 is invalid... */
1672  if (ELEM(NULL, list1, list1->first)) {
1673  if (list2 && list2->first) {
1674  result->first = list2->first;
1675  result->last = list2->last;
1676  }
1677  }
1678  /* if list 2 is invalid... */
1679  else if (ELEM(NULL, list2, list2->first)) {
1680  result->first = list1->first;
1681  result->last = list1->last;
1682  }
1683  else {
1684  /* list1 should be added first, and list2 second,
1685  * with the endpoints of these being the endpoints for result
1686  * - the original lists must be left unchanged though, as we need that fact for restoring.
1687  */
1688  result->first = list1->first;
1689  result->last = list2->last;
1690 
1691  fcm1 = list1->last;
1692  fcm2 = list2->first;
1693 
1694  fcm1->next = fcm2;
1695  fcm2->prev = fcm1;
1696  }
1697 }
1698 
1699 /* Split two temporary lists of modifiers */
1701 {
1702  FModifier *fcm1, *fcm2;
1703 
1704  /* if list1/2 is invalid... just skip */
1705  if (ELEM(NULL, list1, list2)) {
1706  return;
1707  }
1708  if (ELEM(NULL, list1->first, list2->first)) {
1709  return;
1710  }
1711 
1712  /* get endpoints */
1713  fcm1 = list1->last;
1714  fcm2 = list2->first;
1715 
1716  /* clear their links */
1717  fcm1->next = NULL;
1718  fcm2->prev = NULL;
1719 }
1720 
1721 /* ---------------------- */
1722 
1725  NlaEvalData *channels,
1726  ListBase *modifiers,
1727  bAction *action,
1728  const float evaltime,
1729  NlaEvalSnapshot *r_snapshot)
1730 {
1731  FCurve *fcu;
1732 
1734 
1735  /* Evaluate modifiers which modify time to evaluate the base curves at. */
1736  FModifiersStackStorage storage;
1737  storage.modifier_count = BLI_listbase_count(modifiers);
1739  storage.buffer = alloca(storage.modifier_count * storage.size_per_modifier);
1740 
1741  const float modified_evaltime = evaluate_time_fmodifiers(
1742  &storage, modifiers, NULL, 0.0f, evaltime);
1743 
1744  for (fcu = action->curves.first; fcu; fcu = fcu->next) {
1745  if (!is_fcurve_evaluatable(fcu)) {
1746  continue;
1747  }
1748 
1749  NlaEvalChannel *nec = nlaevalchan_verify(ptr, channels, fcu->rna_path);
1750 
1751  /* Invalid path or property cannot be animated. */
1752  if (nec == NULL) {
1753  continue;
1754  }
1755 
1756  if (!nlaevalchan_validate_index_ex(nec, fcu->array_index)) {
1757  continue;
1758  }
1759 
1761 
1762  float value = evaluate_fcurve(fcu, modified_evaltime);
1763  evaluate_value_fmodifiers(&storage, modifiers, fcu, &value, evaltime);
1764  necs->values[fcu->array_index] = value;
1765 
1766  if (nec->mix_mode == NEC_MIX_QUATERNION) {
1767  BLI_bitmap_set_all(necs->blend_domain.ptr, true, 4);
1768  }
1769  else {
1771  }
1772  }
1773 }
1774 
1775 /* evaluate action-clip strip */
1777  NlaEvalData *channels,
1778  ListBase *modifiers,
1779  NlaEvalStrip *nes,
1780  NlaEvalSnapshot *snapshot)
1781 {
1782 
1783  NlaStrip *strip = nes->strip;
1784 
1785  /* sanity checks for action */
1786  if (strip == NULL) {
1787  return;
1788  }
1789 
1790  if (strip->act == NULL) {
1791  CLOG_ERROR(&LOG, "NLA-Strip Eval Error: Strip '%s' has no Action", strip->name);
1792  return;
1793  }
1794 
1795  ListBase tmp_modifiers = {NULL, NULL};
1796 
1797  /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
1798  nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers);
1799 
1800  NlaEvalSnapshot strip_snapshot;
1801  nlaeval_snapshot_init(&strip_snapshot, channels, NULL);
1802 
1804  ptr, channels, &tmp_modifiers, strip->act, strip->strip_time, &strip_snapshot);
1806  channels, snapshot, &strip_snapshot, strip->blendmode, strip->influence, snapshot);
1807 
1808  nlaeval_snapshot_free_data(&strip_snapshot);
1809 
1810  /* unlink this strip's modifiers from the parent's modifiers again */
1811  nlaeval_fmodifiers_split_stacks(&strip->modifiers, modifiers);
1812 }
1813 
1814 /* evaluate transition strip */
1816  NlaEvalData *channels,
1817  ListBase *modifiers,
1818  NlaEvalStrip *nes,
1819  NlaEvalSnapshot *snapshot,
1820  const AnimationEvalContext *anim_eval_context,
1821  const bool flush_to_original)
1822 {
1823  ListBase tmp_modifiers = {NULL, NULL};
1824  NlaEvalSnapshot snapshot1, snapshot2;
1825  NlaEvalStrip tmp_nes;
1826  NlaStrip *s1, *s2;
1827 
1828  /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
1829  nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &nes->strip->modifiers, modifiers);
1830 
1831  /* get the two strips to operate on
1832  * - we use the endpoints of the strips directly flanking our strip
1833  * using these as the endpoints of the transition (destination and source)
1834  * - these should have already been determined to be valid...
1835  * - if this strip is being played in reverse, we need to swap these endpoints
1836  * otherwise they will be interpolated wrong
1837  */
1838  if (nes->strip->flag & NLASTRIP_FLAG_REVERSE) {
1839  s1 = nes->strip->next;
1840  s2 = nes->strip->prev;
1841  }
1842  else {
1843  s1 = nes->strip->prev;
1844  s2 = nes->strip->next;
1845  }
1846 
1847  /* prepare template for 'evaluation strip'
1848  * - based on the transition strip's evaluation strip data
1849  * - strip_mode is NES_TIME_TRANSITION_* based on which endpoint
1850  * - strip_time is the 'normalized' (i.e. in-strip) time for evaluation,
1851  * which doubles up as an additional weighting factor for the strip influences
1852  * which allows us to appear to be 'interpolating' between the two extremes
1853  */
1854  tmp_nes = *nes;
1855 
1856  /* evaluate these strips into a temp-buffer (tmp_channels) */
1857  /* FIXME: modifier evaluation here needs some work... */
1858  /* first strip */
1860  tmp_nes.strip = s1;
1861  tmp_nes.strip_time = s1->strip_time;
1862  nlaeval_snapshot_init(&snapshot1, channels, snapshot);
1864  ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot1, anim_eval_context, flush_to_original);
1865 
1866  /* second strip */
1868  tmp_nes.strip = s2;
1869  tmp_nes.strip_time = s2->strip_time;
1870  nlaeval_snapshot_init(&snapshot2, channels, snapshot);
1872  ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot2, anim_eval_context, flush_to_original);
1873 
1875  nlasnapshot_ensure_channels(channels, &snapshot2);
1879  channels, &snapshot1, &snapshot2, NLASTRIP_MODE_REPLACE, nes->strip_time, snapshot);
1880 
1881  nlaeval_snapshot_free_data(&snapshot1);
1882  nlaeval_snapshot_free_data(&snapshot2);
1883 
1884  /* unlink this strip's modifiers from the parent's modifiers again */
1885  nlaeval_fmodifiers_split_stacks(&nes->strip->modifiers, modifiers);
1886 }
1887 
1888 /* evaluate meta-strip */
1890  NlaEvalData *channels,
1891  ListBase *modifiers,
1892  NlaEvalStrip *nes,
1893  NlaEvalSnapshot *snapshot,
1894  const AnimationEvalContext *anim_eval_context,
1895  const bool flush_to_original)
1896 {
1897  ListBase tmp_modifiers = {NULL, NULL};
1898  NlaStrip *strip = nes->strip;
1899  NlaEvalStrip *tmp_nes;
1900  float evaltime;
1901 
1902  /* meta-strip was calculated normally to have some time to be evaluated at
1903  * and here we 'look inside' the meta strip, treating it as a decorated window to
1904  * its child strips, which get evaluated as if they were some tracks on a strip
1905  * (but with some extra modifiers to apply).
1906  *
1907  * NOTE: keep this in sync with animsys_evaluate_nla()
1908  */
1909 
1910  /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
1911  nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers);
1912 
1913  /* find the child-strip to evaluate */
1914  evaltime = (nes->strip_time * (strip->end - strip->start)) + strip->start;
1915  AnimationEvalContext child_context = BKE_animsys_eval_context_construct_at(anim_eval_context,
1916  evaltime);
1917  tmp_nes = nlastrips_ctime_get_strip(NULL, &strip->strips, -1, &child_context, flush_to_original);
1918 
1919  /* directly evaluate child strip into accumulation buffer...
1920  * - there's no need to use a temporary buffer (as it causes issues [T40082])
1921  */
1922  if (tmp_nes) {
1924  ptr, channels, &tmp_modifiers, tmp_nes, snapshot, &child_context, flush_to_original);
1925 
1926  /* free temp eval-strip */
1927  MEM_freeN(tmp_nes);
1928  }
1929 
1930  /* unlink this strip's modifiers from the parent's modifiers again */
1931  nlaeval_fmodifiers_split_stacks(&strip->modifiers, modifiers);
1932 }
1933 
1934 /* evaluates the given evaluation strip */
1936  NlaEvalData *channels,
1937  ListBase *modifiers,
1938  NlaEvalStrip *nes,
1939  NlaEvalSnapshot *snapshot,
1940  const AnimationEvalContext *anim_eval_context,
1941  const bool flush_to_original)
1942 {
1943  NlaStrip *strip = nes->strip;
1944 
1945  /* To prevent potential infinite recursion problems
1946  * (i.e. transition strip, beside meta strip containing a transition
1947  * several levels deep inside it),
1948  * we tag the current strip as being evaluated, and clear this when we leave.
1949  */
1950  /* TODO: be careful with this flag, since some edit tools may be running and have
1951  * set this while animation playback was running. */
1952  if (strip->flag & NLASTRIP_FLAG_EDIT_TOUCHED) {
1953  return;
1954  }
1955  strip->flag |= NLASTRIP_FLAG_EDIT_TOUCHED;
1956 
1957  /* actions to take depend on the type of strip */
1958  switch (strip->type) {
1959  case NLASTRIP_TYPE_CLIP: /* action-clip */
1960  nlastrip_evaluate_actionclip(ptr, channels, modifiers, nes, snapshot);
1961  break;
1962  case NLASTRIP_TYPE_TRANSITION: /* transition */
1964  ptr, channels, modifiers, nes, snapshot, anim_eval_context, flush_to_original);
1965  break;
1966  case NLASTRIP_TYPE_META: /* meta */
1968  ptr, channels, modifiers, nes, snapshot, anim_eval_context, flush_to_original);
1969  break;
1970 
1971  default: /* do nothing */
1972  break;
1973  }
1974 
1975  /* clear temp recursion safe-check */
1976  strip->flag &= ~NLASTRIP_FLAG_EDIT_TOUCHED;
1977 }
1978 
1979 /* write the accumulated settings to */
1981  NlaEvalData *channels,
1982  NlaEvalSnapshot *snapshot,
1983  const bool flush_to_original)
1984 {
1985  /* sanity checks */
1986  if (channels == NULL) {
1987  return;
1988  }
1989 
1990  /* for each channel with accumulated values, write its value on the property it affects */
1991  LISTBASE_FOREACH (NlaEvalChannel *, nec, &channels->channels) {
2001  NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_find_channel(snapshot, nec);
2002 
2003  PathResolvedRNA rna = {nec->key.ptr, nec->key.prop, -1};
2004 
2005  for (int i = 0; i < nec_snapshot->length; i++) {
2006  if (BLI_BITMAP_TEST(nec->domain.ptr, i)) {
2007  float value = nec_snapshot->values[i];
2008  if (nec->is_array) {
2009  rna.prop_index = i;
2010  }
2011  BKE_animsys_write_to_rna_path(&rna, value);
2012  if (flush_to_original) {
2013  animsys_write_orig_anim_rna(ptr, nec->rna_path, rna.prop_index, value);
2014  }
2015  }
2016  }
2017  }
2018 }
2019 
2020 /* ---------------------- */
2021 
2023  NlaEvalData *channels,
2024  bAction *act,
2025  GSet *touched_actions)
2026 {
2027  if (!BLI_gset_add(touched_actions, act)) {
2028  return;
2029  }
2030 
2031  LISTBASE_FOREACH (FCurve *, fcu, &act->curves) {
2032  /* check if this curve should be skipped */
2033  if (!is_fcurve_evaluatable(fcu)) {
2034  continue;
2035  }
2036 
2037  NlaEvalChannel *nec = nlaevalchan_verify(ptr, channels, fcu->rna_path);
2038 
2039  if (nec != NULL) {
2040  /* For quaternion properties, enable all sub-channels. */
2041  if (nec->mix_mode == NEC_MIX_QUATERNION) {
2042  BLI_bitmap_set_all(nec->domain.ptr, true, 4);
2043  continue;
2044  }
2045 
2046  int idx = nlaevalchan_validate_index(nec, fcu->array_index);
2047 
2048  if (idx >= 0) {
2049  BLI_BITMAP_ENABLE(nec->domain.ptr, idx);
2050  }
2051  }
2052  }
2053 }
2054 
2056  NlaEvalData *channels,
2057  ListBase *strips,
2058  GSet *touched_actions)
2059 {
2060  LISTBASE_FOREACH (NlaStrip *, strip, strips) {
2061  /* check strip's action */
2062  if (strip->act) {
2063  nla_eval_domain_action(ptr, channels, strip->act, touched_actions);
2064  }
2065 
2066  /* check sub-strips (if metas) */
2067  nla_eval_domain_strips(ptr, channels, &strip->strips, touched_actions);
2068  }
2069 }
2070 
2076 {
2077  GSet *touched_actions = BLI_gset_ptr_new(__func__);
2078 
2079  if (adt->action) {
2080  nla_eval_domain_action(ptr, channels, adt->action, touched_actions);
2081  }
2082 
2083  /* NLA Data - Animation Data for Strips */
2084  LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
2085  /* solo and muting are mutually exclusive... */
2086  if (adt->flag & ADT_NLA_SOLO_TRACK) {
2087  /* skip if there is a solo track, but this isn't it */
2088  if ((nlt->flag & NLATRACK_SOLO) == 0) {
2089  continue;
2090  }
2091  /* else - mute doesn't matter */
2092  }
2093  else {
2094  /* no solo tracks - skip track if muted */
2095  if (nlt->flag & NLATRACK_MUTED) {
2096  continue;
2097  }
2098  }
2099 
2100  nla_eval_domain_strips(ptr, channels, &nlt->strips, touched_actions);
2101  }
2102 
2103  BLI_gset_free(touched_actions, NULL);
2104 }
2105 
2106 /* ---------------------- */
2107 
2112 static void animsys_create_tweak_strip(const AnimData *adt,
2113  const bool keyframing_to_strip,
2114  NlaStrip *r_tweak_strip)
2115 
2116 {
2117  /* Copy active strip so we can modify how it evaluates without affecting user data. */
2118  memcpy(r_tweak_strip, adt->actstrip, sizeof(NlaStrip));
2119  r_tweak_strip->next = r_tweak_strip->prev = NULL;
2120 
2121  /* If tweaked strip is syncing action length, then evaluate using action length. */
2122  if (r_tweak_strip->flag & NLASTRIP_FLAG_SYNC_LENGTH) {
2124  }
2125 
2126  /* Strips with a user-defined time curve don't get properly remapped for editing
2127  * at the moment, so mapping them just for display may be confusing. */
2128  const bool is_inplace_tweak = !(adt->flag & ADT_NLA_EDIT_NOMAP) &&
2130 
2131  if (!is_inplace_tweak) {
2132  /* Use Hold due to no proper remapping yet (the note above). */
2133  r_tweak_strip->extendmode = NLASTRIP_EXTEND_HOLD;
2134 
2135  /* Disable range. */
2136  r_tweak_strip->flag |= NLASTRIP_FLAG_NO_TIME_MAP;
2137  }
2138 
2140  if (keyframing_to_strip) {
2141  r_tweak_strip->extendmode = (is_inplace_tweak &&
2142  !(r_tweak_strip->flag & NLASTRIP_FLAG_SYNC_LENGTH)) ?
2145  }
2146 }
2147 
2150  const bool keyframing_to_strip,
2151  NlaStrip *r_action_strip)
2152 {
2153  memset(r_action_strip, 0, sizeof(NlaStrip));
2154 
2155  bAction *action = adt->action;
2156 
2157  if ((adt->flag & ADT_NLA_EDIT_ON)) {
2158  action = adt->tmpact;
2159  }
2160 
2161  /* Set settings of dummy NLA strip from AnimData settings. */
2162  r_action_strip->act = action;
2163 
2164  /* Action range is calculated taking F-Modifiers into account
2165  * (which making new strips doesn't do due to the troublesome nature of that). */
2166  calc_action_range(r_action_strip->act, &r_action_strip->actstart, &r_action_strip->actend, 1);
2167  r_action_strip->start = r_action_strip->actstart;
2168  r_action_strip->end = (IS_EQF(r_action_strip->actstart, r_action_strip->actend)) ?
2169  (r_action_strip->actstart + 1.0f) :
2170  (r_action_strip->actend);
2171 
2172  r_action_strip->blendmode = adt->act_blendmode;
2173  r_action_strip->extendmode = adt->act_extendmode;
2174  r_action_strip->influence = adt->act_influence;
2175 
2176  /* NOTE: must set this, or else the default setting overrides,
2177  * and this setting doesn't work. */
2178  r_action_strip->flag |= NLASTRIP_FLAG_USR_INFLUENCE;
2179 
2180  /* Unless extendmode is Nothing (might be useful for flattening NLA evaluation), disable range.
2181  * Extendmode Nothing and Hold will behave as normal. Hold Forward will behave just like Hold.
2182  */
2183  if (r_action_strip->extendmode != NLASTRIP_EXTEND_NOTHING) {
2184  r_action_strip->flag |= NLASTRIP_FLAG_NO_TIME_MAP;
2185  }
2186 
2187  const bool tweaking = (adt->flag & ADT_NLA_EDIT_ON) != 0;
2188  const bool soloing = (adt->flag & ADT_NLA_SOLO_TRACK) != 0;
2189  const bool actionstrip_evaluated = r_action_strip->act && !soloing && !tweaking;
2190  if (!actionstrip_evaluated) {
2191  r_action_strip->flag |= NLASTRIP_FLAG_MUTED;
2192  }
2193 
2195  if (keyframing_to_strip) {
2196  r_action_strip->extendmode = NLASTRIP_EXTEND_HOLD;
2197  }
2198 }
2199 
2200 static bool is_nlatrack_evaluatable(const AnimData *adt, const NlaTrack *nlt)
2201 {
2202  /* Skip disabled tracks unless it contains the tweaked strip. */
2203  const bool contains_tweak_strip = (adt->flag & ADT_NLA_EDIT_ON) && adt->act_track &&
2204  (nlt->index == adt->act_track->index);
2205  if ((nlt->flag & NLATRACK_DISABLED) && !contains_tweak_strip) {
2206  return false;
2207  }
2208 
2209  /* Solo and muting are mutually exclusive. */
2210  if (adt->flag & ADT_NLA_SOLO_TRACK) {
2211  /* Skip if there is a solo track, but this isn't it. */
2212  if ((nlt->flag & NLATRACK_SOLO) == 0) {
2213  return false;
2214  }
2215  }
2216  else {
2217  /* Skip track if muted. */
2218  if (nlt->flag & NLATRACK_MUTED) {
2219  return false;
2220  }
2221  }
2222 
2223  return true;
2224 }
2225 
2231  const bool any_strip_evaluated)
2232 {
2233  if (adt->action == NULL) {
2234  return false;
2235  }
2236 
2237  if (any_strip_evaluated) {
2238  return false;
2239  }
2240 
2242  if ((adt->flag & (ADT_NLA_SOLO_TRACK | ADT_NLA_EDIT_ON)) != 0) {
2243  return false;
2244  }
2245 
2247  return true;
2248 }
2249 
2259 {
2260  NlaTrack *nlt;
2261 
2262  if (adt == NULL) {
2263  return NULL;
2264  }
2265 
2266  /* Since the track itself gets disabled, we want the first disabled. */
2267  for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
2268  if (nlt->flag & NLATRACK_DISABLED) {
2269  return nlt;
2270  }
2271  }
2272 
2273  return NULL;
2274 }
2275 
2281  PointerRNA *ptr,
2282  const AnimData *adt,
2283  const AnimationEvalContext *anim_eval_context,
2284  const bool flush_to_original)
2285 {
2286  NlaTrack *nlt;
2287  short track_index = 0;
2288  bool has_strips = false;
2289  ListBase estrips = {NULL, NULL};
2290  NlaEvalStrip *nes;
2291 
2292  NlaStrip tweak_strip;
2293 
2294  NlaTrack *tweaked_track = nlatrack_find_tweaked(adt);
2295 
2296  /* Get the stack of strips to evaluate at current time (influence calculated here). */
2297  for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next, track_index++) {
2298 
2299  if (!is_nlatrack_evaluatable(adt, nlt)) {
2300  continue;
2301  }
2302 
2303  if (nlt->strips.first) {
2304  has_strips = true;
2305  }
2306 
2308  if (nlt == tweaked_track) {
2310  animsys_create_tweak_strip(adt, false, &tweak_strip);
2312  &estrips, &tweak_strip, anim_eval_context, flush_to_original);
2313  }
2314  else {
2316  &estrips, &nlt->strips, track_index, anim_eval_context, flush_to_original);
2317  }
2318  if (nes) {
2319  nes->track = nlt;
2320  }
2321  }
2322 
2323  if (is_action_track_evaluated_without_nla(adt, has_strips)) {
2324  BLI_freelistN(&estrips);
2325  return false;
2326  }
2327 
2328  NlaStrip action_strip = {0};
2329  animsys_create_action_track_strip(adt, false, &action_strip);
2330  nlastrips_ctime_get_strip_single(&estrips, &action_strip, anim_eval_context, flush_to_original);
2331 
2332  /* Per strip, evaluate and accumulate on top of existing channels. */
2333  for (nes = estrips.first; nes; nes = nes->next) {
2335  echannels,
2336  NULL,
2337  nes,
2338  &echannels->eval_snapshot,
2339  anim_eval_context,
2340  flush_to_original);
2341  }
2342 
2343  /* Free temporary evaluation data that's not used elsewhere. */
2344  BLI_freelistN(&estrips);
2345  return true;
2346 }
2347 
2350  const AnimData *adt,
2351  const AnimationEvalContext *anim_eval_context,
2352  NlaKeyframingContext *r_context)
2353 {
2354  if (!r_context) {
2355  return;
2356  }
2357 
2358  /* Early out. If NLA track is soloing and tweaked action isn't it, then don't allow keyframe
2359  * insertion. */
2360  if (adt->flag & ADT_NLA_SOLO_TRACK) {
2361  if (!(adt->act_track && (adt->act_track->flag & NLATRACK_SOLO))) {
2362  r_context->eval_strip = NULL;
2363  return;
2364  }
2365  }
2366 
2367  NlaTrack *nlt;
2368  short track_index = 0;
2369  bool has_strips = false;
2370 
2371  ListBase lower_estrips = {NULL, NULL};
2372  NlaEvalStrip *nes;
2373 
2374  NlaTrack *tweaked_track = nlatrack_find_tweaked(adt);
2375 
2376  /* Get the lower stack of strips to evaluate at current time (influence calculated here). */
2377  for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next, track_index++) {
2378 
2379  if (!is_nlatrack_evaluatable(adt, nlt)) {
2380  continue;
2381  }
2382 
2383  /* Tweaked strip effect should not be stored in any snapshot. */
2384  if (nlt == tweaked_track) {
2385  break;
2386  }
2387 
2388  if (nlt->strips.first) {
2389  has_strips = true;
2390  }
2391 
2392  /* Get strip to evaluate for this channel. */
2394  &lower_estrips, &nlt->strips, track_index, anim_eval_context, false);
2395  if (nes) {
2396  nes->track = nlt;
2397  }
2398  }
2399 
2404  if (is_action_track_evaluated_without_nla(adt, has_strips)) {
2405  BLI_freelistN(&lower_estrips);
2406  return;
2407  }
2408 
2409  /* Write r_context->eval_strip. */
2410  if (adt->flag & ADT_NLA_EDIT_ON) {
2411 
2412  NlaStrip *tweak_strip = &r_context->strip;
2413  animsys_create_tweak_strip(adt, true, tweak_strip);
2415  NULL, tweak_strip, anim_eval_context, false);
2416  }
2417  else {
2418 
2419  NlaStrip *action_strip = &r_context->strip;
2420  animsys_create_action_track_strip(adt, true, action_strip);
2422  NULL, action_strip, anim_eval_context, false);
2423  }
2424 
2425  /* If NULL, then keyframing will fail. No need to do any more processing. */
2426  if (!r_context->eval_strip) {
2427  BLI_freelistN(&lower_estrips);
2428  return;
2429  }
2430 
2431  /* If tweak strip is full REPLACE, then lower strips not needed. */
2432  if (r_context->strip.blendmode == NLASTRIP_MODE_REPLACE &&
2433  IS_EQF(r_context->strip.influence, 1.0f)) {
2434  BLI_freelistN(&lower_estrips);
2435  return;
2436  }
2437 
2438  /* For each strip, evaluate then accumulate on top of existing channels. */
2439  for (nes = lower_estrips.first; nes; nes = nes->next) {
2441  &r_context->lower_eval_data,
2442  NULL,
2443  nes,
2444  &r_context->lower_eval_data.eval_snapshot,
2445  anim_eval_context,
2446  false);
2447  }
2448 
2449  /* Free temporary evaluation data that's not used elsewhere. */
2450  BLI_freelistN(&lower_estrips);
2451 }
2452 
2453 /* NLA Evaluation function (mostly for use through do_animdata)
2454  * - All channels that will be affected are not cleared anymore. Instead, we just evaluate into
2455  * some temp channels, where values can be accumulated in one go.
2456  */
2458  AnimData *adt,
2459  const AnimationEvalContext *anim_eval_context,
2460  const bool flush_to_original)
2461 {
2462  NlaEvalData echannels;
2463 
2464  nlaeval_init(&echannels);
2465 
2466  /* evaluate the NLA stack, obtaining a set of values to flush */
2467  if (animsys_evaluate_nla_for_flush(&echannels, ptr, adt, anim_eval_context, flush_to_original)) {
2468  /* reset any channels touched by currently inactive actions to default value */
2469  animsys_evaluate_nla_domain(ptr, &echannels, adt);
2470 
2471  /* flush effects of accumulating channels in NLA to the actual data they affect */
2472  nladata_flush_channels(ptr, &echannels, &echannels.eval_snapshot, flush_to_original);
2473  }
2474  else {
2475  /* special case - evaluate as if there isn't any NLA data */
2476  /* TODO: this is really just a stop-gap measure... */
2477  if (G.debug & G_DEBUG) {
2478  CLOG_WARN(&LOG, "NLA Eval: Stopgap for active action on NLA Stack - no strips case");
2479  }
2480 
2481  animsys_evaluate_action(ptr, adt->action, anim_eval_context, flush_to_original);
2482  }
2483 
2484  /* free temp data */
2485  nlaeval_free(&echannels);
2486 }
2487 
2488 /* ---------------------- */
2489 
2491 {
2492  for (int i = 0; i < snapshot->size; i++) {
2493  NlaEvalChannelSnapshot *necs = nlaeval_snapshot_get(snapshot, i);
2494  if (necs == NULL) {
2495  continue;
2496  }
2497 
2498  BLI_bitmap_set_all(necs->blend_domain.ptr, true, necs->length);
2499  }
2500 }
2501 
2503 {
2504  LISTBASE_FOREACH (NlaEvalChannel *, nec, &eval_data->channels) {
2505  nlaeval_snapshot_ensure_channel(snapshot, nec);
2506  }
2507 }
2508 
2518  NlaEvalSnapshot *lower_snapshot,
2519  NlaEvalSnapshot *upper_snapshot,
2520  const short upper_blendmode,
2521  const float upper_influence,
2522  NlaEvalSnapshot *r_blended_snapshot)
2523 {
2524  nlaeval_snapshot_ensure_size(r_blended_snapshot, eval_data->num_channels);
2525 
2526  const bool zero_upper_influence = IS_EQF(upper_influence, 0.0f);
2527 
2528  LISTBASE_FOREACH (NlaEvalChannel *, nec, &eval_data->channels) {
2529  const int length = nec->base_snapshot.length;
2530 
2531  NlaEvalChannelSnapshot *upper_necs = nlaeval_snapshot_get(upper_snapshot, nec->index);
2532  NlaEvalChannelSnapshot *lower_necs = nlaeval_snapshot_get(lower_snapshot, nec->index);
2533  if (upper_necs == NULL && lower_necs == NULL) {
2534  continue;
2535  }
2536 
2538  if (lower_necs == NULL) {
2539  lower_necs = nlaeval_snapshot_find_channel(lower_snapshot->base, nec);
2540  }
2541 
2542  NlaEvalChannelSnapshot *result_necs = nlaeval_snapshot_ensure_channel(r_blended_snapshot, nec);
2543 
2547  memcpy(result_necs->values, lower_necs->values, length * sizeof(float));
2548  if (upper_necs == NULL || zero_upper_influence) {
2549  continue;
2550  }
2551 
2552  if (upper_blendmode == NLASTRIP_MODE_COMBINE) {
2553  const int mix_mode = nec->mix_mode;
2554  if (mix_mode == NEC_MIX_QUATERNION) {
2555  if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, 0)) {
2556  continue;
2557  }
2558 
2560  lower_necs->values, upper_necs->values, upper_influence, result_necs->values);
2561  }
2562  else {
2563  for (int j = 0; j < length; j++) {
2564  if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, j)) {
2565  continue;
2566  }
2567 
2568  result_necs->values[j] = nla_combine_value(mix_mode,
2569  nec->base_snapshot.values[j],
2570  lower_necs->values[j],
2571  upper_necs->values[j],
2572  upper_influence);
2573  }
2574  }
2575  }
2576  else {
2577  for (int j = 0; j < length; j++) {
2578  if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, j)) {
2579  continue;
2580  }
2581 
2582  result_necs->values[j] = nla_blend_value(
2583  upper_blendmode, lower_necs->values[j], upper_necs->values[j], upper_influence);
2584  }
2585  }
2586  }
2587 }
2588 
2589 /* ---------------------- */
2590 
2601  struct ListBase *cache,
2602  struct PointerRNA *ptr,
2603  struct AnimData *adt,
2604  const AnimationEvalContext *anim_eval_context)
2605 {
2606  /* No remapping needed if NLA is off or no action. */
2607  if ((adt == NULL) || (adt->action == NULL) || (adt->nla_tracks.first == NULL) ||
2608  (adt->flag & ADT_NLA_EVAL_OFF)) {
2609  return NULL;
2610  }
2611 
2612  /* No remapping if editing an ordinary Replace action with full influence. */
2613  if (!(adt->flag & ADT_NLA_EDIT_ON) &&
2614  (adt->act_blendmode == NLASTRIP_MODE_REPLACE && adt->act_influence == 1.0f)) {
2615  return NULL;
2616  }
2617 
2618  /* Try to find a cached context. */
2619  NlaKeyframingContext *ctx = BLI_findptr(cache, adt, offsetof(NlaKeyframingContext, adt));
2620 
2621  if (ctx == NULL) {
2622  /* Allocate and evaluate a new context. */
2623  ctx = MEM_callocN(sizeof(*ctx), "NlaKeyframingContext");
2624  ctx->adt = adt;
2625 
2627  animsys_evaluate_nla_for_keyframing(ptr, adt, anim_eval_context, ctx);
2628 
2629  BLI_assert(ELEM(ctx->strip.act, NULL, adt->action));
2630  BLI_addtail(cache, ctx);
2631  }
2632 
2633  return ctx;
2634 }
2635 
2649  struct PointerRNA *prop_ptr,
2650  struct PropertyRNA *prop,
2651  float *values,
2652  int count,
2653  int index,
2654  bool *r_force_all)
2655 {
2656  if (r_force_all != NULL) {
2657  *r_force_all = false;
2658  }
2659 
2660  /* No context means no correction. */
2661  if (context == NULL || context->strip.act == NULL) {
2662  return true;
2663  }
2664 
2665  /* If the strip is not evaluated, it is the same as zero influence. */
2666  if (context->eval_strip == NULL) {
2667  return false;
2668  }
2669 
2670  /* Full influence Replace strips also require no correction. */
2671  int blend_mode = context->strip.blendmode;
2672  float influence = context->strip.influence;
2673 
2674  if (blend_mode == NLASTRIP_MODE_REPLACE && influence == 1.0f) {
2675  return true;
2676  }
2677 
2678  /* Zero influence is division by zero. */
2679  if (influence <= 0.0f) {
2680  return false;
2681  }
2682 
2683  /* Find the evaluation channel for the NLA stack below current strip. */
2684  NlaEvalChannelKey key = {
2685  .ptr = *prop_ptr,
2686  .prop = prop,
2687  };
2694  NlaEvalData *const lower_eval_data = &context->lower_eval_data;
2695  NlaEvalChannel *const lower_nec = nlaevalchan_verify_key(lower_eval_data, NULL, &key);
2696 
2697  if ((lower_nec->base_snapshot.length != count)) {
2698  BLI_assert(!"invalid value count");
2699  return false;
2700  }
2701 
2702  /* Invert the blending operation to compute the desired strip values. */
2703  NlaEvalChannelSnapshot *const lower_nec_snapshot = nlaeval_snapshot_find_channel(
2704  &lower_eval_data->eval_snapshot, lower_nec);
2705 
2706  float *lower_values = lower_nec_snapshot->values;
2707 
2708  if (blend_mode == NLASTRIP_MODE_COMBINE) {
2709  /* Quaternion combine handles all sub-channels as a unit. */
2710  if (lower_nec->mix_mode == NEC_MIX_QUATERNION) {
2711  if (r_force_all == NULL) {
2712  return false;
2713  }
2714 
2715  *r_force_all = true;
2716 
2718  lower_values, values, influence, values)) {
2719  return false;
2720  }
2721  }
2722  else {
2723  float *base_values = lower_nec->base_snapshot.values;
2724 
2725  for (int i = 0; i < count; i++) {
2726  if (ELEM(index, i, -1)) {
2728  base_values[i],
2729  lower_values[i],
2730  values[i],
2731  influence,
2732  &values[i])) {
2733  return false;
2734  }
2735  }
2736  }
2737  }
2738  }
2739  else {
2740  for (int i = 0; i < count; i++) {
2741  if (ELEM(index, i, -1)) {
2743  blend_mode, lower_values[i], values[i], influence, &values[i])) {
2744  return false;
2745  }
2746  }
2747  }
2748  }
2749 
2750  return true;
2751 }
2752 
2757 {
2758  LISTBASE_FOREACH (NlaKeyframingContext *, ctx, cache) {
2759  MEM_SAFE_FREE(ctx->eval_strip);
2760  nlaeval_free(&ctx->lower_eval_data);
2761  }
2762 
2763  BLI_freelistN(cache);
2764 }
2765 
2766 /* ***************************************** */
2767 /* Overrides System - Public API */
2768 
2769 /* Evaluate Overrides */
2771 {
2772  AnimOverride *aor;
2773 
2774  /* for each override, simply execute... */
2775  for (aor = adt->overrides.first; aor; aor = aor->next) {
2776  PathResolvedRNA anim_rna;
2777  if (BKE_animsys_rna_path_resolve(ptr, aor->rna_path, aor->array_index, &anim_rna)) {
2778  BKE_animsys_write_to_rna_path(&anim_rna, aor->value);
2779  }
2780  }
2781 }
2782 
2783 /* ***************************************** */
2784 /* Evaluation System - Public API */
2785 
2786 /* Overview of how this system works:
2787  * 1) Depsgraph sorts data as necessary, so that data is in an order that means
2788  * that all dependencies are resolved before dependents.
2789  * 2) All normal animation is evaluated, so that drivers have some basis values to
2790  * work with
2791  * a. NLA stacks are done first, as the Active Actions act as 'tweaking' tracks
2792  * which modify the effects of the NLA-stacks
2793  * b. Active Action is evaluated as per normal, on top of the results of the NLA tracks
2794  *
2795  * --------------< often in a separate phase... >------------------
2796  *
2797  * 3) Drivers/expressions are evaluated on top of this, in an order where dependencies are
2798  * resolved nicely.
2799  * Note: it may be necessary to have some tools to handle the cases where some higher-level
2800  * drivers are added and cause some problematic dependencies that
2801  * didn't exist in the local levels...
2802  *
2803  * --------------< always executed >------------------
2804  *
2805  * Maintenance of editability of settings (XXX):
2806  * - In order to ensure that settings that are animated can still be manipulated in the UI without
2807  * requiring that keyframes are added to prevent these values from being overwritten,
2808  * we use 'overrides'.
2809  *
2810  * Unresolved things:
2811  * - Handling of multi-user settings (i.e. time-offset, group-instancing) -> big cache grids
2812  * or nodal system? but stored where?
2813  * - Multiple-block dependencies
2814  * (i.e. drivers for settings are in both local and higher levels) -> split into separate lists?
2815  *
2816  * Current Status:
2817  * - Currently (as of September 2009), overrides we haven't needed to (fully) implement overrides.
2818  * However, the code for this is relatively harmless, so is left in the code for now.
2819  */
2820 
2821 /* Evaluation loop for evaluation animation data
2822  *
2823  * This assumes that the animation-data provided belongs to the ID block in question,
2824  * and that the flags for which parts of the anim-data settings need to be recalculated
2825  * have been set already by the depsgraph. Now, we use the recalc
2826  */
2828  AnimData *adt,
2829  const AnimationEvalContext *anim_eval_context,
2830  eAnimData_Recalc recalc,
2831  const bool flush_to_original)
2832 {
2833  PointerRNA id_ptr;
2834 
2835  /* sanity checks */
2836  if (ELEM(NULL, id, adt)) {
2837  return;
2838  }
2839 
2840  /* get pointer to ID-block for RNA to use */
2841  RNA_id_pointer_create(id, &id_ptr);
2842 
2843  /* recalculate keyframe data:
2844  * - NLA before Active Action, as Active Action behaves as 'tweaking track'
2845  * that overrides 'rough' work in NLA
2846  */
2847  /* TODO: need to double check that this all works correctly */
2848  if (recalc & ADT_RECALC_ANIM) {
2849  /* evaluate NLA data */
2850  if ((adt->nla_tracks.first) && !(adt->flag & ADT_NLA_EVAL_OFF)) {
2851  /* evaluate NLA-stack
2852  * - active action is evaluated as part of the NLA stack as the last item
2853  */
2854  animsys_calculate_nla(&id_ptr, adt, anim_eval_context, flush_to_original);
2855  }
2856  /* evaluate Active Action only */
2857  else if (adt->action) {
2858  animsys_evaluate_action(&id_ptr, adt->action, anim_eval_context, flush_to_original);
2859  }
2860  }
2861 
2862  /* recalculate drivers
2863  * - Drivers need to be evaluated afterwards, as they can either override
2864  * or be layered on top of existing animation data.
2865  * - Drivers should be in the appropriate order to be evaluated without problems...
2866  */
2867  if (recalc & ADT_RECALC_DRIVERS) {
2868  animsys_evaluate_drivers(&id_ptr, adt, anim_eval_context);
2869  }
2870 
2871  /* always execute 'overrides'
2872  * - Overrides allow editing, by overwriting the value(s) set from animation-data, with the
2873  * value last set by the user (and not keyframed yet).
2874  * - Overrides are cleared upon frame change and/or keyframing
2875  * - It is best that we execute this every time, so that no errors are likely to occur.
2876  */
2877  animsys_evaluate_overrides(&id_ptr, adt);
2878 }
2879 
2880 /* Evaluation of all ID-blocks with Animation Data blocks - Animation Data Only
2881  *
2882  * This will evaluate only the animation info available in the animation data-blocks
2883  * encountered. In order to enforce the system by which some settings controlled by a
2884  * 'local' (i.e. belonging in the nearest ID-block that setting is related to, not a
2885  * standard 'root') block are overridden by a larger 'user'
2886  */
2888 {
2889  ID *id;
2890 
2891  if (G.debug & G_DEBUG) {
2892  printf("Evaluate all animation - %f\n", ctime);
2893  }
2894 
2895  const bool flush_to_original = DEG_is_active(depsgraph);
2897  ctime);
2898 
2899  /* macros for less typing
2900  * - only evaluate animation data for id if it has users (and not just fake ones)
2901  * - whether animdata exists is checked for by the evaluation function, though taking
2902  * this outside of the function may make things slightly faster?
2903  */
2904 #define EVAL_ANIM_IDS(first, aflag) \
2905  for (id = first; id; id = id->next) { \
2906  if (ID_REAL_USERS(id) > 0) { \
2907  AnimData *adt = BKE_animdata_from_id(id); \
2908  BKE_animsys_evaluate_animdata(id, adt, &anim_eval_context, aflag, flush_to_original); \
2909  } \
2910  } \
2911  (void)0
2912 
2913  /* another macro for the "embedded" nodetree cases
2914  * - this is like EVAL_ANIM_IDS, but this handles the case "embedded nodetrees"
2915  * (i.e. scene/material/texture->nodetree) which we need a special exception
2916  * for, otherwise they'd get skipped
2917  * - 'ntp' stands for "node tree parent" = data-block where node tree stuff resides
2918  */
2919 #define EVAL_ANIM_NODETREE_IDS(first, NtId_Type, aflag) \
2920  for (id = first; id; id = id->next) { \
2921  if (ID_REAL_USERS(id) > 0) { \
2922  AnimData *adt = BKE_animdata_from_id(id); \
2923  NtId_Type *ntp = (NtId_Type *)id; \
2924  if (ntp->nodetree) { \
2925  AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \
2926  BKE_animsys_evaluate_animdata( \
2927  &ntp->nodetree->id, adt2, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original); \
2928  } \
2929  BKE_animsys_evaluate_animdata(id, adt, &anim_eval_context, aflag, flush_to_original); \
2930  } \
2931  } \
2932  (void)0
2933 
2934  /* optimization:
2935  * when there are no actions, don't go over database and loop over heaps of data-blocks,
2936  * which should ultimately be empty, since it is not possible for now to have any animation
2937  * without some actions, and drivers wouldn't get affected by any state changes
2938  *
2939  * however, if there are some curves, we will need to make sure that their 'ctime' property gets
2940  * set correctly, so this optimization must be skipped in that case...
2941  */
2942  if (BLI_listbase_is_empty(&main->actions) && BLI_listbase_is_empty(&main->curves)) {
2943  if (G.debug & G_DEBUG) {
2944  printf("\tNo Actions, so no animation needs to be evaluated...\n");
2945  }
2946 
2947  return;
2948  }
2949 
2950  /* nodes */
2951  EVAL_ANIM_IDS(main->nodetrees.first, ADT_RECALC_ANIM);
2952 
2953  /* textures */
2954  EVAL_ANIM_NODETREE_IDS(main->textures.first, Tex, ADT_RECALC_ANIM);
2955 
2956  /* lights */
2958 
2959  /* materials */
2961 
2962  /* cameras */
2963  EVAL_ANIM_IDS(main->cameras.first, ADT_RECALC_ANIM);
2964 
2965  /* shapekeys */
2966  EVAL_ANIM_IDS(main->shapekeys.first, ADT_RECALC_ANIM);
2967 
2968  /* metaballs */
2969  EVAL_ANIM_IDS(main->metaballs.first, ADT_RECALC_ANIM);
2970 
2971  /* curves */
2972  EVAL_ANIM_IDS(main->curves.first, ADT_RECALC_ANIM);
2973 
2974  /* armatures */
2975  EVAL_ANIM_IDS(main->armatures.first, ADT_RECALC_ANIM);
2976 
2977  /* lattices */
2978  EVAL_ANIM_IDS(main->lattices.first, ADT_RECALC_ANIM);
2979 
2980  /* meshes */
2981  EVAL_ANIM_IDS(main->meshes.first, ADT_RECALC_ANIM);
2982 
2983  /* particles */
2984  EVAL_ANIM_IDS(main->particles.first, ADT_RECALC_ANIM);
2985 
2986  /* speakers */
2987  EVAL_ANIM_IDS(main->speakers.first, ADT_RECALC_ANIM);
2988 
2989  /* movie clips */
2990  EVAL_ANIM_IDS(main->movieclips.first, ADT_RECALC_ANIM);
2991 
2992  /* linestyles */
2993  EVAL_ANIM_IDS(main->linestyles.first, ADT_RECALC_ANIM);
2994 
2995  /* grease pencil */
2996  EVAL_ANIM_IDS(main->gpencils.first, ADT_RECALC_ANIM);
2997 
2998  /* palettes */
2999  EVAL_ANIM_IDS(main->palettes.first, ADT_RECALC_ANIM);
3000 
3001  /* cache files */
3002  EVAL_ANIM_IDS(main->cachefiles.first, ADT_RECALC_ANIM);
3003 
3004  /* hairs */
3005  EVAL_ANIM_IDS(main->hairs.first, ADT_RECALC_ANIM);
3006 
3007  /* pointclouds */
3008  EVAL_ANIM_IDS(main->pointclouds.first, ADT_RECALC_ANIM);
3009 
3010  /* volumes */
3011  EVAL_ANIM_IDS(main->volumes.first, ADT_RECALC_ANIM);
3012 
3013  /* simulations */
3014  EVAL_ANIM_IDS(main->simulations.first, ADT_RECALC_ANIM);
3015 
3016  /* objects */
3017  /* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets
3018  * this tagged by Depsgraph on framechange. This optimization means that objects
3019  * linked from other (not-visible) scenes will not need their data calculated.
3020  */
3021  EVAL_ANIM_IDS(main->objects.first, 0);
3022 
3023  /* masks */
3024  EVAL_ANIM_IDS(main->masks.first, ADT_RECALC_ANIM);
3025 
3026  /* worlds */
3028 
3029  /* scenes */
3031 }
3032 
3033 /* ***************************************** */
3034 
3035 /* ************** */
3036 /* Evaluation API */
3037 
3039 {
3040  float ctime = DEG_get_ctime(depsgraph);
3041  AnimData *adt = BKE_animdata_from_id(id);
3042  /* XXX: this is only needed for flushing RNA updates,
3043  * which should get handled as part of the dependency graph instead. */
3044  DEG_debug_print_eval_time(depsgraph, __func__, id->name, id, ctime);
3045  const bool flush_to_original = DEG_is_active(depsgraph);
3046 
3048  ctime);
3049  BKE_animsys_evaluate_animdata(id, adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
3050 }
3051 
3053 {
3054  AnimData *adt = BKE_animdata_from_id(id);
3055 
3056  /* Runtime driver map to avoid O(n^2) lookups in BKE_animsys_eval_driver.
3057  * Ideally the depsgraph could pass a pointer to the COW driver directly,
3058  * but this is difficult in the current design. */
3059  if (adt && adt->drivers.first) {
3060  BLI_assert(!adt->driver_array);
3061 
3062  int num_drivers = BLI_listbase_count(&adt->drivers);
3063  adt->driver_array = MEM_mallocN(sizeof(FCurve *) * num_drivers, "adt->driver_array");
3064 
3065  int driver_index = 0;
3066  LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
3067  adt->driver_array[driver_index++] = fcu;
3068  }
3069  }
3070 }
3071 
3072 void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, int driver_index, FCurve *fcu_orig)
3073 {
3074  BLI_assert(fcu_orig != NULL);
3075 
3076  /* TODO(sergey): De-duplicate with BKE animsys. */
3077  PointerRNA id_ptr;
3078  bool ok = false;
3079 
3080  /* Lookup driver, accelerated with driver array map. */
3081  const AnimData *adt = BKE_animdata_from_id(id);
3082  FCurve *fcu;
3083 
3084  if (adt->driver_array) {
3085  fcu = adt->driver_array[driver_index];
3086  }
3087  else {
3088  fcu = BLI_findlink(&adt->drivers, driver_index);
3089  }
3090 
3092  depsgraph, __func__, id->name, id, "fcu", fcu->rna_path, fcu, fcu->array_index);
3093 
3094  RNA_id_pointer_create(id, &id_ptr);
3095 
3096  /* check if this driver's curve should be skipped */
3097  if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) {
3098  /* check if driver itself is tagged for recalculation */
3099  /* XXX driver recalc flag is not set yet by depsgraph! */
3100  ChannelDriver *driver_orig = fcu_orig->driver;
3101  if ((driver_orig) && !(driver_orig->flag & DRIVER_FLAG_INVALID)) {
3102  /* evaluate this using values set already in other places
3103  * NOTE: for 'layering' option later on, we should check if we should remove old value before
3104  * adding new to only be done when drivers only changed */
3105  // printf("\told val = %f\n", fcu->curval);
3106 
3107  PathResolvedRNA anim_rna;
3108  if (BKE_animsys_rna_path_resolve(&id_ptr, fcu->rna_path, fcu->array_index, &anim_rna)) {
3109  /* Evaluate driver, and write results to COW-domain destination */
3110  const float ctime = DEG_get_ctime(depsgraph);
3111  const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(
3112  depsgraph, ctime);
3113  const float curval = calculate_fcurve(&anim_rna, fcu, &anim_eval_context);
3114  ok = BKE_animsys_write_to_rna_path(&anim_rna, curval);
3115 
3116  /* Flush results & status codes to original data for UI (T59984) */
3117  if (ok && DEG_is_active(depsgraph)) {
3118  animsys_write_orig_anim_rna(&id_ptr, fcu->rna_path, fcu->array_index, curval);
3119 
3120  /* curval is displayed in the UI, and flag contains error-status codes */
3121  fcu_orig->curval = fcu->curval;
3122  driver_orig->curval = fcu->driver->curval;
3123  driver_orig->flag = fcu->driver->flag;
3124 
3125  DriverVar *dvar_orig = driver_orig->variables.first;
3126  DriverVar *dvar = fcu->driver->variables.first;
3127  for (; dvar_orig && dvar; dvar_orig = dvar_orig->next, dvar = dvar->next) {
3128  DriverTarget *dtar_orig = &dvar_orig->targets[0];
3129  DriverTarget *dtar = &dvar->targets[0];
3130  for (int i = 0; i < MAX_DRIVER_TARGETS; i++, dtar_orig++, dtar++) {
3131  dtar_orig->flag = dtar->flag;
3132  }
3133 
3134  dvar_orig->curval = dvar->curval;
3135  dvar_orig->flag = dvar->flag;
3136  }
3137  }
3138  }
3139 
3140  /* set error-flag if evaluation failed */
3141  if (ok == 0) {
3142  CLOG_WARN(&LOG, "invalid driver - %s[%d]", fcu->rna_path, fcu->array_index);
3143  driver_orig->flag |= DRIVER_FLAG_INVALID;
3144  }
3145  }
3146  }
3147 }
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
void calc_action_range(const struct bAction *act, float *start, float *end, short incl_modifiers)
struct AnimData * BKE_animdata_from_id(struct ID *id)
Definition: anim_data.c:96
eAnimData_Recalc
Definition: BKE_animsys.h:236
@ ADT_RECALC_ANIM
Definition: BKE_animsys.h:238
@ ADT_RECALC_DRIVERS
Definition: BKE_animsys.h:237
float evaluate_fcurve(struct FCurve *fcu, float evaltime)
Definition: fcurve.c:2186
float calculate_fcurve(struct PathResolvedRNA *anim_rna, struct FCurve *fcu, const struct AnimationEvalContext *anim_eval_context)
bool BKE_fcurve_is_empty(struct FCurve *fcu)
Definition: fcurve.c:2250
void evaluate_value_fmodifiers(FModifiersStackStorage *storage, ListBase *modifiers, struct FCurve *fcu, float *cvalue, float evaltime)
Definition: fmodifier.c:1518
float evaluate_time_fmodifiers(FModifiersStackStorage *storage, ListBase *modifiers, struct FCurve *fcu, float cvalue, float evaltime)
Definition: fmodifier.c:1457
uint evaluate_fmodifiers_storage_size_per_modifier(ListBase *modifiers)
Definition: fmodifier.c:1376
@ G_DEBUG
Definition: BKE_global.h:133
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:47
#define BKE_LIB_FOREACHID_PROCESS_ID(_data, _id, _cb_flag)
General operations, lookup, etc. for materials.
@ NLATIME_CONVERT_EVAL
Definition: BKE_nla.h:150
void BKE_nlastrip_recalculate_bounds_sync_action(struct NlaStrip *strip)
Definition: nla.c:1389
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:63
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition: BLI_bitmap.h:78
#define BLI_BITMAP_SIZE(_tot)
Definition: BLI_bitmap.h:47
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
Definition: BLI_bitmap.h:73
#define BLI_BITMAP_NEW(_tot, _alloc_string)
Definition: BLI_bitmap.h:50
void BLI_bitmap_set_all(BLI_bitmap *bitmap, bool set, size_t bits)
Definition: bitmap.c:33
#define ATTR_FALLTHROUGH
A dynamically sized string ADT.
struct GSet GSet
Definition: BLI_ghash.h:189
unsigned int BLI_ghashutil_ptrhash(const void *key)
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GSet * BLI_gset_ptr_new(const char *info)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:718
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1253
bool BLI_ghash_ensure_p(GHash *gh, void *key, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:851
bool BLI_gset_add(GSet *gs, void *key)
Definition: BLI_ghash.c:1160
bool BLI_ghash_ensure_p_ex(GHash *gh, const void *key, void ***r_key, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:873
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:281
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void invert_qt_normalized(float q[4])
void unit_qt(float q[4])
Definition: math_rotation.c:46
float normalize_qt_qt(float r[4], const float q[4])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
Definition: math_rotation.c:65
void pow_qt_fl_normalized(float q[4], const float f)
MINLINE void zero_v4(float r[4])
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t len)
Definition: string_utils.c:381
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNUSED(x)
#define MAX2(a, b)
#define ELEM(...)
#define IS_EQF(a, b)
#define IN_RANGE_INCL(a, b, c)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5654
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
Definition: writefile.c:1401
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_expand(expander, id)
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition: CLG_log.h:204
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:203
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
bool DEG_is_active(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:331
void DEG_debug_print_eval_time(struct Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address, float time)
void DEG_debug_print_eval_subdata_index(struct Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address, const char *subdata_comment, const char *subdata_name, const void *subdata_address, const int subdata_index)
float DEG_get_ctime(const Depsgraph *graph)
@ AGRP_MUTED
#define MAX_DRIVER_TARGETS
@ NLASTRIP_FLAG_USR_INFLUENCE
@ NLASTRIP_FLAG_USR_TIME
@ NLASTRIP_FLAG_REVERSE
@ NLASTRIP_FLAG_MUTED
@ NLASTRIP_FLAG_USR_TIME_CYCLIC
@ NLASTRIP_FLAG_NO_TIME_MAP
@ NLASTRIP_FLAG_EDIT_TOUCHED
@ NLASTRIP_FLAG_SYNC_LENGTH
@ ADT_NLA_SOLO_TRACK
@ ADT_NLA_EVAL_OFF
@ ADT_NLA_EDIT_NOMAP
@ ADT_NLA_EDIT_ON
@ NLASTRIP_EXTEND_NOTHING
@ NLASTRIP_EXTEND_HOLD
@ NLASTRIP_MODE_REPLACE
@ NLASTRIP_MODE_ADD
@ NLASTRIP_MODE_SUBTRACT
@ NLASTRIP_MODE_COMBINE
@ NLASTRIP_MODE_MULTIPLY
@ DRIVER_FLAG_INVALID
@ NLASTRIP_TYPE_META
@ NLASTRIP_TYPE_TRANSITION
@ NLASTRIP_TYPE_CLIP
@ FCURVE_DISABLED
@ FCURVE_MUTED
@ NLATRACK_SOLO
@ NLATRACK_MUTED
@ NLATRACK_DISABLED
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
StructRNA RNA_NlaStrip
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_PROPORTIONAL
Definition: RNA_types.h:209
PropertySubType
Definition: RNA_types.h:112
@ PROP_AXISANGLE
Definition: RNA_types.h:147
@ PROP_QUATERNION
Definition: RNA_types.h:146
static void nlaeval_init(NlaEvalData *nlaeval)
Definition: anim_sys.c:1180
void BKE_animsys_free_nla_keyframing_context_cache(struct ListBase *cache)
Definition: anim_sys.c:2756
static float nla_combine_value(const int mix_mode, float base_value, const float lower_value, const float strip_value, const float influence)
Definition: anim_sys.c:1482
static void animsys_evaluate_fcurves(PointerRNA *ptr, ListBase *list, const AnimationEvalContext *anim_eval_context, bool flush_to_original)
Definition: anim_sys.c:611
void nlasnapshot_enable_all_blend_domain(NlaEvalSnapshot *snapshot)
Definition: anim_sys.c:2490
void BKE_animsys_evaluate_animdata(ID *id, AnimData *adt, const AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, const bool flush_to_original)
Definition: anim_sys.c:2827
static void animsys_write_orig_anim_rna(PointerRNA *ptr, const char *rna_path, int array_index, float value)
Definition: anim_sys.c:590
static void nlastrip_evaluate_meta(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:1889
bool BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context, struct PointerRNA *prop_ptr, struct PropertyRNA *prop, float *values, int count, int index, bool *r_force_all)
Definition: anim_sys.c:2648
static bool is_action_track_evaluated_without_nla(const AnimData *adt, const bool any_strip_evaluated)
Definition: anim_sys.c:2230
static NlaEvalChannelSnapshot * nlaeval_snapshot_find_channel(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec)
Definition: anim_sys.c:1117
static NlaTrack * nlatrack_find_tweaked(const AnimData *adt)
Definition: anim_sys.c:2258
void BKE_animsys_evaluate_all_animation(Main *main, Depsgraph *depsgraph, float ctime)
Definition: anim_sys.c:2887
void BKE_keyingsets_copy(ListBase *newlist, const ListBase *list)
Definition: anim_sys.c:259
static bool is_nlatrack_evaluatable(const AnimData *adt, const NlaTrack *nlt)
Definition: anim_sys.c:2200
static void nlaevalchan_free_data(NlaEvalChannel *nec)
Definition: anim_sys.c:1174
static void nlavalidmask_free(NlaValidMask *mask)
Definition: anim_sys.c:1015
void nlasnapshot_ensure_channels(NlaEvalData *eval_data, NlaEvalSnapshot *snapshot)
Definition: anim_sys.c:2502
static void animsys_create_action_track_strip(const AnimData *adt, const bool keyframing_to_strip, NlaStrip *r_action_strip)
Definition: anim_sys.c:2149
static void nlavalidmask_init(NlaValidMask *mask, int bits)
Definition: anim_sys.c:1004
static float nla_blend_value(const int blendmode, const float lower_value, const float strip_value, const float influence)
Definition: anim_sys.c:1443
bool BKE_animsys_rna_path_resolve(PointerRNA *ptr, const char *rna_path, const int array_index, PathResolvedRNA *r_result)
Definition: anim_sys.c:389
static NlaEvalChannelSnapshot * nlaeval_snapshot_get(NlaEvalSnapshot *snapshot, int index)
Definition: anim_sys.c:1089
static NlaEvalChannel * nlaevalchan_verify(PointerRNA *ptr, NlaEvalData *nlaeval, const char *path)
Definition: anim_sys.c:1393
AnimationEvalContext BKE_animsys_eval_context_construct(struct Depsgraph *depsgraph, float eval_time)
Definition: anim_sys.c:637
static NlaEvalStrip * nlastrips_ctime_get_strip_single(ListBase *dst_list, NlaStrip *single_strip, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:988
static void nlaeval_fmodifiers_join_stacks(ListBase *result, ListBase *list1, ListBase *list2)
Definition: anim_sys.c:1667
void BKE_keyingset_free_path(KeyingSet *ks, KS_Path *ksp)
Definition: anim_sys.c:242
void nlasnapshot_blend(NlaEvalData *eval_data, NlaEvalSnapshot *lower_snapshot, NlaEvalSnapshot *upper_snapshot, const short upper_blendmode, const float upper_influence, NlaEvalSnapshot *r_blended_snapshot)
Definition: anim_sys.c:2517
static uint nlaevalchan_keyhash(const void *ptr)
Definition: anim_sys.c:1025
void BKE_keyingsets_blend_read_expand(BlendExpander *expander, ListBase *list)
Definition: anim_sys.c:363
void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id)
Definition: anim_sys.c:3038
static bool nla_combine_get_inverted_strip_value(const int mix_mode, float base_value, const float lower_value, const float blended_value, const float influence, float *r_strip_value)
Definition: anim_sys.c:1576
static NlaEvalChannel * nlaevalchan_verify_key(NlaEvalData *nlaeval, const char *path, NlaEvalChannelKey *key)
Definition: anim_sys.c:1342
static void nlaevalchan_get_default_values(NlaEvalChannel *nec, float *r_values)
Definition: anim_sys.c:1244
#define EVAL_ANIM_IDS(first, aflag)
static bool nlaevalchan_validate_index_ex(const NlaEvalChannel *nec, const int array_index)
Definition: anim_sys.c:1221
static void animsys_evaluate_overrides(PointerRNA *ptr, AnimData *adt)
Definition: anim_sys.c:2770
static void nlaevalchan_snapshot_copy(NlaEvalChannelSnapshot *dst, const NlaEvalChannelSnapshot *src)
Definition: anim_sys.c:1067
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))
Definition: anim_sys.c:90
void BKE_keyingsets_blend_write(BlendWriter *writer, ListBase *list)
Definition: anim_sys.c:323
static void animsys_calculate_nla(PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:2457
bool BKE_animsys_read_from_rna_path(PathResolvedRNA *anim_rna, float *r_value)
Definition: anim_sys.c:438
static bool is_fcurve_evaluatable(FCurve *fcu)
Definition: anim_sys.c:375
void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup *agrp, const AnimationEvalContext *anim_eval_context)
Definition: anim_sys.c:733
static void nlastrip_evaluate_transition(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:1815
NlaKeyframingContext * BKE_animsys_get_nla_keyframing_context(struct ListBase *cache, struct PointerRNA *ptr, struct AnimData *adt, const AnimationEvalContext *anim_eval_context)
Definition: anim_sys.c:2600
void animsys_evaluate_action(PointerRNA *ptr, bAction *act, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:766
void nlastrip_evaluate(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:1935
static int nlaevalchan_validate_index(const NlaEvalChannel *nec, int index)
Definition: anim_sys.c:1209
static void nla_eval_domain_action(PointerRNA *ptr, NlaEvalData *channels, bAction *act, GSet *touched_actions)
Definition: anim_sys.c:2022
static bool nla_blend_get_inverted_strip_value(const int blendmode, const float lower_value, const float blended_value, const float influence, float *r_strip_value)
Definition: anim_sys.c:1512
NlaEvalStrip * nlastrips_ctime_get_strip(ListBase *list, ListBase *strips, short index, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:852
static void nlastrip_evaluate_actionclip(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot)
Definition: anim_sys.c:1776
static void nlaeval_snapshot_ensure_size(NlaEvalSnapshot *snapshot, int size)
Definition: anim_sys.c:1095
void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBase *list)
Definition: anim_sys.c:341
#define ANIMSYS_FLOAT_AS_BOOL(value)
Definition: anim_sys.c:436
void BKE_keyingset_free(KeyingSet *ks)
Definition: anim_sys.c:287
#define EVAL_ANIM_NODETREE_IDS(first, NtId_Type, aflag)
static void nla_combine_quaternion(const float lower_values[4], const float strip_values[4], const float influence, float r_blended_value[4])
Definition: anim_sys.c:1622
void BKE_animsys_update_driver_array(ID *id)
Definition: anim_sys.c:3052
KeyingSet * BKE_keyingset_add(ListBase *list, const char idname[], const char name[], short flag, short keyingflag)
Definition: anim_sys.c:144
static NlaEvalChannelSnapshot * nlaeval_snapshot_ensure_channel(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec)
Definition: anim_sys.c:1133
static bool nla_combine_quaternion_get_inverted_strip_values(const float lower_values[4], const float blended_values[4], const float influence, float r_strip_values[4])
Definition: anim_sys.c:1637
static void nlaeval_snapshot_init(NlaEvalSnapshot *snapshot, NlaEvalData *nlaeval, NlaEvalSnapshot *base)
Definition: anim_sys.c:1078
static void nlaeval_snapshot_free_data(NlaEvalSnapshot *snapshot)
Definition: anim_sys.c:1153
static void nlaeval_free(NlaEvalData *nlaeval)
Definition: anim_sys.c:1189
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)
Definition: anim_sys.c:178
static NlaEvalChannelSnapshot ** nlaeval_snapshot_ensure_slot(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec)
Definition: anim_sys.c:1109
static CLG_LogRef LOG
Definition: anim_sys.c:81
static float nlastrip_get_influence(NlaStrip *strip, float cframe)
Definition: anim_sys.c:786
static bool animsys_evaluate_nla_for_flush(NlaEvalData *echannels, PointerRNA *ptr, const AnimData *adt, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:2280
static bool nlaevalchan_keycmp(const void *a, const void *b)
Definition: anim_sys.c:1032
static void nlasnapshot_from_action(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, bAction *action, const float evaltime, NlaEvalSnapshot *r_snapshot)
Definition: anim_sys.c:1724
void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, int driver_index, FCurve *fcu_orig)
Definition: anim_sys.c:3072
void BKE_keyingsets_foreach_id(LibraryForeachIDData *data, const ListBase *keyingsets)
Definition: anim_sys.c:275
static void animsys_create_tweak_strip(const AnimData *adt, const bool keyframing_to_strip, NlaStrip *r_tweak_strip)
Definition: anim_sys.c:2112
static void nlaevalchan_snapshot_free(NlaEvalChannelSnapshot *nec_snapshot)
Definition: anim_sys.c:1058
void nladata_flush_channels(PointerRNA *ptr, NlaEvalData *channels, NlaEvalSnapshot *snapshot, const bool flush_to_original)
Definition: anim_sys.c:1980
static void action_idcode_patch_check(ID *id, bAction *act)
Definition: anim_sys.c:697
static void nlaeval_fmodifiers_split_stacks(ListBase *list1, ListBase *list2)
Definition: anim_sys.c:1700
static char nlaevalchan_detect_mix_mode(NlaEvalChannelKey *key, int length)
Definition: anim_sys.c:1325
static NlaEvalChannelSnapshot * nlaevalchan_snapshot_new(NlaEvalChannel *nec)
Definition: anim_sys.c:1043
static bool animsys_construct_orig_pointer_rna(const PointerRNA *ptr, PointerRNA *ptr_orig)
Definition: anim_sys.c:566
static void animsys_evaluate_drivers(PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context)
Definition: anim_sys.c:654
static void animsys_evaluate_nla_domain(PointerRNA *ptr, NlaEvalData *channels, AnimData *adt)
Definition: anim_sys.c:2075
static void animsys_evaluate_nla_for_keyframing(PointerRNA *ptr, const AnimData *adt, const AnimationEvalContext *anim_eval_context, NlaKeyframingContext *r_context)
Definition: anim_sys.c:2349
static void nla_eval_domain_strips(PointerRNA *ptr, NlaEvalData *channels, ListBase *strips, GSet *touched_actions)
Definition: anim_sys.c:2055
static void nlastrip_evaluate_controls(NlaStrip *strip, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition: anim_sys.c:807
AnimationEvalContext BKE_animsys_eval_context_construct_at(const AnimationEvalContext *anim_eval_context, float eval_time)
Definition: anim_sys.c:647
bool BKE_animsys_write_to_rna_path(PathResolvedRNA *anim_rna, const float value)
Definition: anim_sys.c:501
void BKE_keyingsets_free(ListBase *list)
Definition: anim_sys.c:304
void BKE_keyingsets_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *list)
Definition: anim_sys.c:354
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
#define A
float evaltime
Definition: bpy_driver.c:181
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
const Depsgraph * depsgraph
int count
#define GS(x)
Definition: iris.c:241
#define powf(x, y)
#define fabsf(x)
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:48
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_recallocN_id)(void *vmemh, size_t len, const char *str)
Definition: mallocn.c:44
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
#define B
int main(int argc, char **argv)
Definition: msgfmt.c:457
static unsigned a[3]
Definition: RandGen.cpp:92
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode)
Definition: nla.c:562
struct NlaEvalChannelSnapshot NlaEvalChannelSnapshot
@ NEC_MIX_AXIS_ANGLE
Definition: nla_private.h:97
@ NEC_MIX_ADD
Definition: nla_private.h:94
@ NEC_MIX_MULTIPLY
Definition: nla_private.h:95
@ NEC_MIX_QUATERNION
Definition: nla_private.h:96
@ NES_TIME_TRANSITION_END
Definition: nla_private.h:60
@ NES_TIME_TRANSITION_START
Definition: nla_private.h:59
@ NES_TIME_AFTER
Definition: nla_private.h:56
@ NES_TIME_BEFORE
Definition: nla_private.h:54
@ NES_TIME_WITHIN
Definition: nla_private.h:55
#define hash
Definition: noise.c:169
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2941
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3249
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
Definition: rna_access.c:2530
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:2627
bool RNA_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:1223
bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2168
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
int RNA_property_int_clamp(PointerRNA *ptr, PropertyRNA *prop, int *value)
Definition: rna_access.c:1542
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
Definition: rna_access.c:1525
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2759
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
Definition: rna_access.c:3190
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:3108
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1155
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:3562
bool RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:2557
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2331
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition: rna_access.c:2568
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
Definition: rna_access.c:2830
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2607
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3592
int RNA_property_flag(PropertyRNA *prop)
Definition: rna_access.c:1192
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2358
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:2856
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1218
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
Definition: rna_access.c:2886
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
Definition: rna_access.c:2964
PropertySubType RNA_property_subtype(PropertyRNA *prop)
Definition: rna_access.c:1160
bool RNA_path_resolve_property(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_access.c:5434
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2453
float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3216
struct SELECTID_Context context
Definition: select_engine.c:47
bAction * action
short act_blendmode
NlaStrip * actstrip
ListBase overrides
float act_influence
FCurve ** driver_array
NlaTrack * act_track
bAction * tmpact
short act_extendmode
ListBase drivers
ListBase nla_tracks
struct AnimOverride * next
struct Depsgraph * depsgraph
Definition: BKE_animsys.h:57
ListBase variables
struct DriverVar * next
DriverTarget targets[8]
struct FCurve * next
bActionGroup * grp
float curval
char * rna_path
ChannelDriver * driver
int array_index
short flag
struct FModifier * next
struct FModifier * prev
Definition: DNA_ID.h:273
struct Library * lib
Definition: DNA_ID.h:277
struct ID * orig_id
Definition: DNA_ID.h:324
char name[66]
Definition: DNA_ID.h:283
struct KS_Path * next
short flag
char group[64]
int array_index
short groupmode
char * rna_path
char name[64]
char idname[64]
struct KeyingSet * next
ListBase paths
short keyingflag
short keyingoverride
ID id
Definition: DNA_ID.h:349
void * last
Definition: DNA_listBase.h:47
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct PropertyRNA * prop
Definition: nla_private.h:69
struct PointerRNA ptr
Definition: nla_private.h:68
NlaValidMask blend_domain
Definition: nla_private.h:83
struct NlaEvalChannel * channel
Definition: nla_private.h:80
struct NlaEvalData * owner
Definition: nla_private.h:104
NlaEvalChannelSnapshot base_snapshot
Definition: nla_private.h:118
const char * rna_path
Definition: nla_private.h:107
NlaEvalChannelKey key
Definition: nla_private.h:108
NlaValidMask domain
Definition: nla_private.h:115
NlaEvalSnapshot eval_snapshot
Definition: nla_private.h:144
GHash * path_hash
Definition: nla_private.h:136
NlaEvalSnapshot base_snapshot
Definition: nla_private.h:141
ListBase channels
Definition: nla_private.h:133
GHash * key_hash
Definition: nla_private.h:137
int num_channels
Definition: nla_private.h:140
struct NlaEvalSnapshot * base
Definition: nla_private.h:125
NlaEvalChannelSnapshot ** channels
Definition: nla_private.h:128
struct NlaEvalStrip * next
Definition: nla_private.h:40
NlaStrip * strip
Definition: nla_private.h:43
short track_index
Definition: nla_private.h:45
NlaTrack * track
Definition: nla_private.h:42
short strip_mode
Definition: nla_private.h:46
float strip_time
Definition: nla_private.h:48
struct AnimData * adt
Definition: nla_private.h:152
NlaEvalData lower_eval_data
Definition: nla_private.h:159
NlaEvalStrip * eval_strip
Definition: nla_private.h:156
float actstart
struct NlaStrip * next
short blendmode
float blendout
ListBase fcurves
char name[64]
float influence
ListBase strips
float actend
ListBase modifiers
struct NlaStrip * prev
float blendin
struct NlaStrip * orig_strip
short extendmode
bAction * act
float strip_time
ListBase strips
struct NlaTrack * next
BLI_bitmap * ptr
Definition: nla_private.h:74
struct PropertyRNA * prop
Definition: RNA_types.h:65
struct PointerRNA ptr
Definition: RNA_types.h:64
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
ListBase curves
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
#define G(x, y, z)
PointerRNA * ptr
Definition: wm_files.c:3157