Blender V5.3
anim_sys.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <cmath>
11#include <cstddef>
12#include <cstdio>
13#include <cstring>
14
15#include "MEM_guardedalloc.h"
16
17#include "BLI_bit_vector.hh"
18#include "BLI_listbase.hh"
20#include "BLI_math_matrix_c.hh"
22#include "BLI_math_vector_c.hh"
24#include "BLI_set.hh"
25#include "BLI_string.hh"
26#include "BLI_string_utf8.hh"
27#include "BLI_string_utils.hh"
28#include "BLI_utildefines.hh"
29
30#include "BLT_translation.hh"
31
32#include "DNA_anim_enums.h"
33#include "DNA_anim_types.h"
34#include "DNA_light_types.h"
35#include "DNA_material_types.h"
36#include "DNA_scene_types.h"
37#include "DNA_screen_types.h"
38#include "DNA_space_types.h"
39#include "DNA_texture_types.h"
40#include "DNA_world_types.h"
41
42#include "BKE_action.hh"
43#include "BKE_anim_data.hh"
44#include "BKE_animsys.hh"
45#include "BKE_armature.hh"
46#include "BKE_context.hh"
47#include "BKE_fcurve.hh"
48#include "BKE_global.hh"
49#include "BKE_idprop.hh"
50#include "BKE_idtype.hh"
51#include "BKE_lib_id.hh"
52#include "BKE_lib_query.hh"
53#include "BKE_main.hh"
54#include "BKE_material.hh"
55#include "BKE_nla.hh"
56#include "BKE_node.hh"
57#include "BKE_texture.h"
58
59#include "ANIM_action.hh"
60#include "ANIM_evaluation.hh"
61
62#include "DEG_depsgraph.hh"
64
65#include "RNA_access.hh"
66#include "RNA_path.hh"
67#include "RNA_prototypes.hh"
68
69#include "BLO_read_write.hh"
70
71#include "nla_private.h"
72
73#include "CLG_log.h"
74
75namespace blender {
76
77static CLG_LogRef LOG_ANIM_DRIVER = {"anim.driver"};
78static CLG_LogRef LOG_ANIM_FCURVE = {"anim.fcurve"};
79static CLG_LogRef LOG_ANIM_KEYINGSET = {"anim.keyingset"};
80static CLG_LogRef LOG_ANIM_NLA = {"anim.nla"};
81
82/* *********************************** */
83/* KeyingSet API */
84
85/* Finding Tools --------------------------- */
86
88 ID *id,
89 const char group_name[],
90 const char rna_path[],
91 int array_index,
92 int /*group_mode*/)
93{
94 /* sanity checks */
95 if (ELEM(nullptr, ks, rna_path, id)) {
96 return nullptr;
97 }
98
99 /* loop over paths in the current KeyingSet, finding the first one where all settings match
100 * (i.e. the first one where none of the checks fail and equal 0)
101 */
102 for (KS_Path &ksp : ks->paths) {
103 short eq_id = 1, eq_path = 1, eq_index = 1, eq_group = 1;
104
105 /* id */
106 if (id != ksp.id) {
107 eq_id = 0;
108 }
109
110 /* path */
111 if ((ksp.rna_path == nullptr) || !STREQ(rna_path, ksp.rna_path)) {
112 eq_path = 0;
113 }
114
115 /* index - need to compare whole-array setting too... */
116 if (ksp.array_index != array_index) {
117 eq_index = 0;
118 }
119
120 /* group */
121 if (group_name) {
122 /* FIXME: these checks need to be coded... for now, it's not too important though */
123 }
124
125 /* if all aspects are ok, return */
126 if (eq_id && eq_path && eq_index && eq_group) {
127 return &ksp;
128 }
129 }
130
131 /* none found */
132 return nullptr;
133}
134
135/* Defining Tools --------------------------- */
136
137KeyingSet *BKE_keyingset_add(ListBaseT<KeyingSet> *list,
138 const char idname[],
139 const char name[],
140 eKS_Settings flag,
141 eInsertKeyFlags keyingflag)
142{
143 KeyingSet *ks;
144
145 /* allocate new KeyingSet */
146 ks = MEM_new<KeyingSet>("KeyingSet");
147
148 STRNCPY_UTF8(ks->idname, (idname) ? idname : (name) ? name : DATA_("KeyingSet"));
149 STRNCPY_UTF8(ks->name, (name) ? name : (idname) ? idname : DATA_("Keying Set"));
150
151 ks->flag = flag;
152 ks->keyingflag = keyingflag;
153 /* NOTE: assume that if one is set one way, the other should be too, so that it'll work */
154 ks->keyingoverride = keyingflag;
155
156 /* add KeyingSet to list */
157 BLI_addtail(list, ks);
158
159 /* Make sure KeyingSet has a unique idname */
161 list, ks, DATA_("KeyingSet"), '.', offsetof(KeyingSet, idname), sizeof(ks->idname));
162
163 /* Make sure KeyingSet has a unique label (this helps with identification) */
164 BLI_uniquename(list, ks, DATA_("Keying Set"), '.', offsetof(KeyingSet, name), sizeof(ks->name));
165
166 /* return new KeyingSet for further editing */
167 return ks;
168}
169
171 ID *id,
172 const char group_name[],
173 const char rna_path[],
174 int array_index,
175 eKSP_Settings flag,
176 eKSP_Grouping groupmode)
177{
178 KS_Path *ksp;
179
180 /* sanity checks */
181 if (ELEM(nullptr, ks, rna_path)) {
182 CLOG_ERROR(&LOG_ANIM_KEYINGSET, "no Keying Set and/or RNA Path to add path with");
183 return nullptr;
184 }
185
186 /* ID is required for all types of KeyingSets */
187 if (id == nullptr) {
188 CLOG_ERROR(&LOG_ANIM_KEYINGSET, "No ID provided for Keying Set Path");
189 return nullptr;
190 }
191
192 /* don't add if there is already a matching KS_Path in the KeyingSet */
193 if (BKE_keyingset_find_path(ks, id, group_name, rna_path, array_index, groupmode)) {
194 if (G.debug & G_DEBUG) {
195 CLOG_ERROR(&LOG_ANIM_KEYINGSET, "destination already exists in Keying Set");
196 }
197 return nullptr;
198 }
199
200 /* allocate a new KeyingSet Path */
201 ksp = MEM_new<KS_Path>("KeyingSet Path");
202
203 /* just store absolute info */
204 ksp->id = id;
205 if (group_name) {
206 STRNCPY(ksp->group, group_name);
207 }
208 else {
209 ksp->group[0] = '\0';
210 }
211
212 /* store additional info for relative paths (just in case user makes the set relative) */
213 if (id) {
214 ksp->idtype = id->id_type();
215 }
216
217 /* just copy path info */
218 /* TODO: should array index be checked too? */
220 ksp->array_index = array_index;
221
222 /* store flags */
223 ksp->flag = flag;
224 ksp->groupmode = groupmode;
225
226 /* add KeyingSet path to KeyingSet */
227 BLI_addtail(&ks->paths, ksp);
228
229 /* return this path */
230 return ksp;
231}
232
234{
235 /* sanity check */
236 if (ELEM(nullptr, ks, ksp)) {
237 return;
238 }
239
240 /* free RNA-path info */
241 if (ksp->rna_path) {
242 MEM_delete(ksp->rna_path);
243 }
244
245 /* free path itself */
246 BLI_freelinkN(&ks->paths, ksp);
247}
248
249void BKE_keyingsets_copy(ListBaseT<KeyingSet> *newlist, const ListBaseT<KeyingSet> *list)
250{
251 BLI_duplicatelist(newlist, list);
252
253 for (KeyingSet &ksn : *newlist) {
254 BLI_duplicatelist(&ksn.paths, &ksn.paths);
255
256 for (KS_Path &kspn : ksn.paths) {
257 kspn.rna_path = MEM_dupalloc(kspn.rna_path);
258 }
259 }
260}
261
262void BKE_keyingsets_foreach_id(LibraryForeachIDData *data, const ListBaseT<KeyingSet> *keyingsets)
263{
264 for (KeyingSet &ksn : *keyingsets) {
265 for (KS_Path &kspn : ksn.paths) {
267 }
268 }
269}
270
271/* Freeing Tools --------------------------- */
272
274{
275 KS_Path *ksp, *kspn;
276
277 /* sanity check */
278 if (ks == nullptr) {
279 return;
280 }
281
282 /* free each path as we go to avoid looping twice */
283 for (ksp = ks->paths.first(); ksp; ksp = kspn) {
284 kspn = ksp->next;
286 }
287}
288
289void BKE_keyingsets_free(ListBaseT<KeyingSet> *list)
290{
291 KeyingSet *ks, *ksn;
292
293 /* sanity check */
294 if (list == nullptr) {
295 return;
296 }
297
298 /* loop over KeyingSets freeing them
299 * - BKE_keyingset_free_paths() doesn't free the set itself, but it frees its sub-data
300 */
301 for (ks = list->first(); ks; ks = ksn) {
302 ksn = ks->next;
304 BLI_freelinkN(list, ks);
305 }
306}
307
308void BKE_keyingsets_blend_write(BlendWriter *writer, ListBaseT<KeyingSet> *list)
309{
310 for (KeyingSet &ks : *list) {
311 /* KeyingSet */
312 writer->write_struct(&ks);
313
314 /* Paths */
315 for (KS_Path &ksp : ks.paths) {
316 /* Path */
317 writer->write_struct(&ksp);
318
319 if (ksp.rna_path) {
320 writer->write_string(ksp.rna_path);
321 }
322 }
323 }
324}
325
326void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBaseT<KeyingSet> *list)
327{
328 for (KeyingSet &ks : *list) {
329 /* paths */
330 BLO_read_struct_list(reader, KS_Path, &ks.paths);
331
332 for (KS_Path &ksp : ks.paths) {
333 /* rna path */
334 BLO_read_string(reader, &ksp.rna_path);
335 }
336 }
337}
338
339/* ***************************************** */
340/* Evaluation Data-Setting Backend */
341
342static bool is_fcurve_evaluatable(const FCurve *fcu)
343{
344 if (fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) {
345 return false;
346 }
347 if (fcu->grp != nullptr && (fcu->grp->flag & AGRP_MUTED)) {
348 return false;
349 }
350 if (BKE_fcurve_is_empty(fcu)) {
351 return false;
352 }
353 return true;
354}
355
357 PointerRNA *ptr, /* typically 'fcu->rna_path()', 'fcu->array_index' */
359 const int array_index,
360 PathResolvedRNA *r_result)
361{
362 if (!RNA_path_resolve_property(ptr, rna_path, &r_result->ptr, &r_result->prop)) {
363 /* failed to get path */
364 /* XXX don't tag as failed yet though, as there are some legit situations (Action Constraint)
365 * where some channels will not exist, but shouldn't lock up Action */
366 if (G.debug & G_DEBUG) {
368 "Invalid path. ID = '%s', '%s[%d]'",
369 (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>",
371 array_index);
372 }
373 return false;
374 }
375
376 if (ptr->owner_id != nullptr && !RNA_property_animateable(&r_result->ptr, r_result->prop)) {
377 return false;
378 }
379
380 int array_len = RNA_property_array_length(&r_result->ptr, r_result->prop);
381 if (array_len && array_index >= array_len) {
382 if (G.debug & G_DEBUG) {
384 "Invalid array index. ID = '%s', '%s[%d]', array length is %d",
385 (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>",
387 array_index,
388 array_len - 1);
389 }
390 return false;
391 }
392
393 r_result->prop_index = array_len ? array_index : -1;
394 return true;
395}
396
397/* less than 1.0 evaluates to false, use epsilon to avoid float error */
398#define ANIMSYS_FLOAT_AS_BOOL(value) ((value) > (1.0f - FLT_EPSILON))
399
400bool BKE_animsys_read_from_rna_path(PathResolvedRNA *anim_rna, float *r_value)
401{
402 PropertyRNA *prop = anim_rna->prop;
403 PointerRNA *ptr = &anim_rna->ptr;
404 int array_index = anim_rna->prop_index;
405 float orig_value;
406
407 /* caller must ensure this is animatable */
408 BLI_assert(RNA_property_animateable(ptr, prop) || ptr->owner_id == nullptr);
409
410 switch (RNA_property_type(prop)) {
411 case PROP_BOOLEAN: {
412 if (array_index != -1) {
413 const int orig_value_coerce = RNA_property_boolean_get_index(ptr, prop, array_index);
414 orig_value = float(orig_value_coerce);
415 }
416 else {
417 const int orig_value_coerce = RNA_property_boolean_get(ptr, prop);
418 orig_value = float(orig_value_coerce);
419 }
420 break;
421 }
422 case PROP_INT: {
423 if (array_index != -1) {
424 const int orig_value_coerce = RNA_property_int_get_index(ptr, prop, array_index);
425 orig_value = float(orig_value_coerce);
426 }
427 else {
428 const int orig_value_coerce = RNA_property_int_get(ptr, prop);
429 orig_value = float(orig_value_coerce);
430 }
431 break;
432 }
433 case PROP_FLOAT: {
434 if (array_index != -1) {
435 const float orig_value_coerce = RNA_property_float_get_index(ptr, prop, array_index);
436 orig_value = float(orig_value_coerce);
437 }
438 else {
439 const float orig_value_coerce = RNA_property_float_get(ptr, prop);
440 orig_value = float(orig_value_coerce);
441 }
442 break;
443 }
444 case PROP_ENUM: {
445 const int orig_value_coerce = RNA_property_enum_get(ptr, prop);
446 orig_value = float(orig_value_coerce);
447 break;
448 }
449 default: /* nothing can be done here... so it is unsuccessful? */
450 return false;
451 }
452
453 if (r_value != nullptr) {
454 *r_value = orig_value;
455 }
456
457 /* successful */
458 return true;
459}
460
462 const float value,
463 const bool force_write)
464{
465 PropertyRNA *prop = anim_rna->prop;
466 PointerRNA *ptr = &anim_rna->ptr;
467 int array_index = anim_rna->prop_index;
468
469 /* caller must ensure this is animatable */
470 BLI_assert(RNA_property_animateable(ptr, prop) || ptr->owner_id == nullptr);
471
472 if (!force_write) {
473 /* Check whether value is new. Otherwise we skip all the updates. */
474 float old_value;
475 if (!BKE_animsys_read_from_rna_path(anim_rna, &old_value)) {
476 return false;
477 }
478 if (old_value == value) {
479 return true;
480 }
481 }
482
483 switch (RNA_property_type(prop)) {
484 case PROP_BOOLEAN: {
485 const int value_coerce = ANIMSYS_FLOAT_AS_BOOL(value);
486 if (array_index != -1) {
487 RNA_property_boolean_set_index(ptr, prop, array_index, value_coerce);
488 }
489 else {
490 RNA_property_boolean_set(ptr, prop, value_coerce);
491 }
492 break;
493 }
494 case PROP_INT: {
495 int value_coerce = int(value);
496 RNA_property_int_clamp(ptr, prop, &value_coerce);
497 if (array_index != -1) {
498 RNA_property_int_set_index(ptr, prop, array_index, value_coerce);
499 }
500 else {
501 RNA_property_int_set(ptr, prop, value_coerce);
502 }
503 break;
504 }
505 case PROP_FLOAT: {
506 float value_coerce = value;
507 RNA_property_float_clamp(ptr, prop, &value_coerce);
508 if (array_index != -1) {
509 RNA_property_float_set_index(ptr, prop, array_index, value_coerce);
510 }
511 else {
512 RNA_property_float_set(ptr, prop, value_coerce);
513 }
514 break;
515 }
516 case PROP_ENUM: {
517 const int value_coerce = int(value);
518 RNA_property_enum_set(ptr, prop, value_coerce);
519 break;
520 }
521 default: /* nothing can be done here... so it is unsuccessful? */
522 return false;
523 }
524
525 /* successful */
526 return true;
527}
528
530{
531 *ptr_orig = *ptr;
532 /* NOTE: nlastrip_evaluate_controls() creates PointerRNA with ID of nullptr. Technically, this is
533 * not a valid pointer, but there are exceptions in various places of this file which handles
534 * such pointers.
535 * We do special trickery here as well, to quickly go from evaluated to original NlaStrip. */
536 if (ptr->owner_id == nullptr) {
537 if (ptr->type != RNA_NlaStrip) {
538 return false;
539 }
540 NlaStrip *strip = (static_cast<NlaStrip *>(ptr_orig->data));
541 if (strip->orig_strip == nullptr) {
542 return false;
543 }
544 ptr_orig->data = strip->orig_strip;
545 }
546 else {
547 ptr_orig->owner_id = ptr_orig->owner_id->orig_id;
548 ptr_orig->data = ptr_orig->owner_id;
549 }
550 return true;
551}
552
555 int array_index,
556 float value)
557{
558 PointerRNA ptr_orig;
559 if (!animsys_construct_orig_pointer_rna(ptr, &ptr_orig)) {
560 return;
561 }
562 PathResolvedRNA orig_anim_rna;
563 /* TODO(sergey): Should be possible to cache resolved path in dependency graph somehow. */
564 if (BKE_animsys_rna_path_resolve(&ptr_orig, rna_path, array_index, &orig_anim_rna)) {
565 BKE_animsys_write_to_rna_path(&orig_anim_rna, value);
566 }
567}
568
575 const Span<FCurve *> fcurves,
576 const AnimationEvalContext *anim_eval_context,
577 bool flush_to_original)
578{
579 /* Calculate then execute each curve. */
580 for (FCurve *fcu : fcurves) {
581
582 if (!is_fcurve_evaluatable(fcu)) {
583 continue;
584 }
585
586 const ParsedRNAPathRef rna_path = fcu->rna_path_parsed();
587
588 PathResolvedRNA anim_rna;
589 if (BKE_animsys_rna_path_resolve(ptr, rna_path, fcu->array_index, &anim_rna)) {
590 const float curval = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
591 BKE_animsys_write_to_rna_path(&anim_rna, curval);
592 if (flush_to_original) {
593 animsys_write_orig_anim_rna(ptr, rna_path, fcu->array_index, curval);
594 }
595 }
596 }
597}
598
599/* ***************************************** */
600/* Driver Evaluation */
601
602AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time)
603{
605 ctx.depsgraph = depsgraph;
606 ctx.eval_time = eval_time;
607 return ctx;
608}
609
611 const AnimationEvalContext *anim_eval_context, float eval_time)
612{
613 return BKE_animsys_eval_context_construct(anim_eval_context->depsgraph, eval_time);
614}
615
616/* Evaluate Drivers */
618 AnimData *adt,
619 const AnimationEvalContext *anim_eval_context)
620{
621 /* drivers are stored as F-Curves, but we cannot use the standard code, as we need to check if
622 * the depsgraph requested that this driver be evaluated...
623 */
624 for (FCurve &fcu : adt->drivers) {
625 ChannelDriver *driver = fcu.driver;
626 bool ok = false;
627
628 /* check if this driver's curve should be skipped */
629 if ((fcu.flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) {
630 /* check if driver itself is tagged for recalculation */
631 /* XXX driver recalc flag is not set yet by depsgraph! */
632 if ((driver) && !(driver->flag & DRIVER_FLAG_INVALID)) {
633 /* evaluate this using values set already in other places
634 * NOTE: for 'layering' option later on, we should check if we should remove old value
635 * before adding new to only be done when drivers only changed. */
636 PathResolvedRNA anim_rna;
637 if (BKE_animsys_rna_path_resolve(ptr, fcu.rna_path_parsed(), fcu.array_index, &anim_rna)) {
638 const float curval = calculate_fcurve(&anim_rna, &fcu, anim_eval_context);
639 ok = BKE_animsys_write_to_rna_path(&anim_rna, curval);
640 }
641
642 /* set error-flag if evaluation failed */
643 if (ok == 0) {
644 driver->flag |= DRIVER_FLAG_INVALID;
645 }
646 }
647 }
648 }
649}
650
651/* ***************************************** */
652/* Actions Evaluation */
653
655 bAction *act,
656 bActionGroup *agrp,
657 const AnimationEvalContext *anim_eval_context)
658{
659 /* check if mapper is appropriate for use here (we set to nullptr if it's inappropriate) */
660 if (ELEM(nullptr, act, agrp)) {
661 return;
662 }
663
664 /* if group is muted, don't evaluated any of the F-Curve */
665 if (agrp->flag & AGRP_MUTED) {
666 return;
667 }
668
669 const auto visit_fcurve = [&](FCurve *fcu) {
670 /* check if this curve should be skipped */
671 if ((fcu->flag & FCURVE_MUTED) == 0 && !BKE_fcurve_is_empty(fcu)) {
672 PathResolvedRNA anim_rna;
673 if (BKE_animsys_rna_path_resolve(ptr, fcu->rna_path_parsed(), fcu->array_index, &anim_rna)) {
674 const float curval = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
675 BKE_animsys_write_to_rna_path(&anim_rna, curval);
676 }
677 }
678 };
679
680 animrig::ChannelGroup channel_group = agrp->wrap();
681 for (FCurve *fcurve : channel_group.fcurves()) {
682 visit_fcurve(fcurve);
683 }
684}
685
687 bAction *act,
688 const int32_t action_slot_handle,
689 const AnimationEvalContext *anim_eval_context,
690 const bool flush_to_original)
691{
692 /* check if mapper is appropriate for use here (we set to nullptr if it's inappropriate) */
693 if (act == nullptr) {
694 return;
695 }
696
697 animrig::Action &action = act->wrap();
698
699 /* TODO: check the slot to see if its IDtype is suitable for the animated ID. */
700
701 /* Note that this is _only_ for evaluation of actions linked by NLA strips. As in, legacy code
702 * paths that I (Sybren) tried to keep as much intact as possible when adding support for slotted
703 * Actions. This code will go away when we implement layered Actions. */
704 const Span<FCurve *> fcurves = animrig::fcurves_for_action_slot(action, action_slot_handle);
705 animsys_evaluate_fcurves(ptr, fcurves, anim_eval_context, flush_to_original);
706}
707
708/* ***************************************** */
709/* NLA System - Evaluation */
710
711/* calculate influence of strip based for given frame based on blendin/out values */
712static float nlastrip_get_influence(NlaStrip *strip, float cframe)
713{
714 /* sanity checks - normalize the blendin/out values? */
715 strip->blendin = fabsf(strip->blendin);
716 strip->blendout = fabsf(strip->blendout);
717
718 /* result depends on where frame is in respect to blendin/out values */
719 if (IS_EQF(strip->blendin, 0.0f) == false && (cframe <= (strip->start + strip->blendin))) {
720 /* there is some blend-in */
721 return fabsf(cframe - strip->start) / (strip->blendin);
722 }
723 if (IS_EQF(strip->blendout, 0.0f) == false && (cframe >= (strip->end - strip->blendout))) {
724 /* there is some blend-out */
725 return fabsf(strip->end - cframe) / (strip->blendout);
726 }
727
728 /* in the middle of the strip, we should be full strength */
729 return 1.0f;
730}
731
732/* evaluate the evaluation time and influence for the strip, storing the results in the strip */
734 const AnimationEvalContext *anim_eval_context,
735 const bool flush_to_original)
736{
737 /* now strip's evaluate F-Curves for these settings (if applicable) */
738 if (strip->fcurves.first()) {
739
740 /* create RNA-pointer needed to set values */
741 PointerRNA strip_ptr = RNA_pointer_create_discrete(nullptr, RNA_NlaStrip, strip);
742
743 /* execute these settings as per normal */
745 animsys_evaluate_fcurves(&strip_ptr, strip_fcurves, anim_eval_context, flush_to_original);
746 }
747
748 /* analytically generate values for influence and time (if applicable)
749 * - we do this after the F-Curves have been evaluated to override the effects of those
750 * in case the override has been turned off.
751 */
752 if ((strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) == 0) {
753 strip->influence = nlastrip_get_influence(strip, anim_eval_context->eval_time);
754 }
755
756 /* Bypass evaluation time computation if time mapping is disabled. */
757 if ((strip->flag & NLASTRIP_FLAG_NO_TIME_MAP) != 0) {
758 strip->strip_time = anim_eval_context->eval_time;
759 return;
760 }
761
762 if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0) {
764 strip, anim_eval_context->eval_time, NLATIME_CONVERT_EVAL);
765 }
766
767 /* if user can control the evaluation time (using F-Curves), consider the option which allows
768 * this time to be clamped to lie within extents of the action-clip, so that a steady changing
769 * rate of progress through several cycles of the clip can be achieved easily.
770 */
771 /* NOTE: if we add any more of these special cases, we better group them up nicely... */
772 if ((strip->flag & NLASTRIP_FLAG_USR_TIME) && (strip->flag & NLASTRIP_FLAG_USR_TIME_CYCLIC)) {
773 strip->strip_time = fmod(strip->strip_time - strip->actstart, strip->actend - strip->actstart);
774 }
775}
776
778 ListBaseT<NlaStrip> *strips,
779 short index,
780 const AnimationEvalContext *anim_eval_context,
781 const bool flush_to_original)
782{
783 NlaStrip *estrip = nullptr;
784 NlaEvalStrip *nes;
785 short side = 0;
786 float ctime = anim_eval_context->eval_time;
787
788 /* loop over strips, checking if they fall within the range */
789 for (NlaStrip &strip : *strips) {
790 /* Check if current time occurs within this strip. */
791
792 /* This block leads to the Action Track and non-time-remapped tweak strip evaluation to respect
793 * the extrapolation modes. If in_range, these two tracks will always output NES_TIME_WITHIN so
794 * fcurve extrapolation isn't clamped to the keyframe bounds. */
795 bool in_range = IN_RANGE_INCL(ctime, strip.start, strip.end);
796 if (strip.flag & NLASTRIP_FLAG_NO_TIME_MAP) {
797 switch (strip.extendmode) {
799 in_range = true;
800 break;
802 in_range = ctime >= strip.start;
803 break;
805 break;
806 }
807 }
808
809 if (in_range) {
810 /* this strip is active, so try to use it */
811 estrip = &strip;
812 side = NES_TIME_WITHIN;
813 break;
814 }
815
816 /* if time occurred before current strip... */
817 if (ctime < strip.start) {
818 if (&strip == strips->first()) {
819 /* before first strip - only try to use it if it extends backwards in time too */
820 if (strip.extendmode == NLASTRIP_EXTEND_HOLD) {
821 estrip = &strip;
822 }
823
824 /* side is 'before' regardless of whether there's a useful strip */
825 side = NES_TIME_BEFORE;
826 }
827 else {
828 /* before next strip - previous strip has ended, but next hasn't begun,
829 * so blending mode depends on whether strip is being held or not...
830 * - only occurs when no transition strip added, otherwise the transition would have
831 * been picked up above...
832 */
833 if (strip.prev->extendmode != NLASTRIP_EXTEND_NOTHING) {
834 estrip = strip.prev;
835 }
836 side = NES_TIME_AFTER;
837 }
838 break;
839 }
840
841 /* if time occurred after current strip... */
842 if (ctime > strip.end) {
843 /* only if this is the last strip should we do anything, and only if that is being held */
844 if (&strip == strips->last()) {
845 if (strip.extendmode != NLASTRIP_EXTEND_NOTHING) {
846 estrip = &strip;
847 }
848
849 side = NES_TIME_AFTER;
850 break;
851 }
852
853 /* otherwise, skip... as the 'before' case will catch it more elegantly! */
854 }
855 }
856
857 /* check if a valid strip was found
858 * - must not be muted (i.e. will have contribution)
859 */
860 if ((estrip == nullptr) || (estrip->flag & NLASTRIP_FLAG_MUTED)) {
861 return nullptr;
862 }
863
864 /* if ctime was not within the boundaries of the strip, clamp! */
865 switch (side) {
866 case NES_TIME_BEFORE: /* extend first frame only */
867 ctime = estrip->start;
868 break;
869 case NES_TIME_AFTER: /* extend last frame only */
870 ctime = estrip->end;
871 break;
872 }
873
874 /* evaluate strip's evaluation controls
875 * - skip if no influence (i.e. same effect as muting the strip)
876 * - negative influence is not supported yet... how would that be defined?
877 */
878 /* TODO: this sounds a bit hacky having a few isolated F-Curves
879 * stuck on some data it operates on... */
881 anim_eval_context, ctime);
882 nlastrip_evaluate_controls(estrip, &clamped_eval_context, flush_to_original);
883 if (estrip->influence <= 0.0f) {
884 return nullptr;
885 }
886
887 /* check if strip has valid data to evaluate,
888 * and/or perform any additional type-specific actions
889 */
890 switch (estrip->type) {
891 case NLASTRIP_TYPE_CLIP: /* clip must have some action to evaluate */
892 if (estrip->act == nullptr) {
893 return nullptr;
894 }
895 break;
896 /* There must be strips to transition from and to (i.e. `prev` and `next` required). */
898 if (ELEM(nullptr, estrip->prev, estrip->next)) {
899 return nullptr;
900 }
901
902 /* evaluate controls for the relevant extents of the bordering strips... */
904 anim_eval_context, estrip->start);
906 anim_eval_context, estrip->end);
907 nlastrip_evaluate_controls(estrip->prev, &start_eval_context, flush_to_original);
908 nlastrip_evaluate_controls(estrip->next, &end_eval_context, flush_to_original);
909 break;
910 }
913 break;
914 }
915
916 /* add to list of strips we need to evaluate */
917 nes = MEM_new_zeroed<NlaEvalStrip>("NlaEvalStrip");
918
919 nes->strip = estrip;
920 nes->strip_mode = side;
921 nes->track_index = index;
922 nes->strip_time = estrip->strip_time;
923
924 if (list) {
925 BLI_addtail(list, nes);
926 }
927
928 return nes;
929}
930
932 ListBaseT<NlaEvalStrip> *dst_list,
933 NlaStrip *single_strip,
934 const AnimationEvalContext *anim_eval_context,
935 const bool flush_to_original)
936{
937 ListBaseT<NlaStrip> single_tracks_list;
938 single_tracks_list.first_ = single_tracks_list.last_ = single_strip;
939
941 dst_list, &single_tracks_list, -1, anim_eval_context, flush_to_original);
942}
943
944/* ---------------------- */
945
946/* Initialize a valid mask, allocating memory if necessary. */
948{
949 if (BLI_BITMAP_SIZE(bits) > sizeof(mask->buffer)) {
950 mask->ptr = BLI_BITMAP_NEW(bits, "NlaValidMask");
951 }
952 else {
953 mask->ptr = mask->buffer;
954 }
955}
956
957/* Free allocated memory for the mask. */
959{
960 if (mask->ptr != mask->buffer) {
961 MEM_delete(mask->ptr);
962 }
963}
964
965/* ---------------------- */
966
967/* Allocate a new blending value snapshot for the channel. */
969{
970 int length = nec->base_snapshot.length;
971
972 size_t byte_size = sizeof(NlaEvalChannelSnapshot) + sizeof(float) * length;
973 NlaEvalChannelSnapshot *nec_snapshot = static_cast<NlaEvalChannelSnapshot *>(
974 MEM_new_zeroed(byte_size, "NlaEvalChannelSnapshot"));
975
976 nec_snapshot->channel = nec;
977 nec_snapshot->length = length;
978 nlavalidmask_init(&nec_snapshot->blend_domain, length);
979 nlavalidmask_init(&nec_snapshot->remap_domain, length);
980
981 return nec_snapshot;
982}
983
984/* Free a channel's blending value snapshot. */
986{
987 BLI_assert(!nec_snapshot->is_base);
988
989 nlavalidmask_free(&nec_snapshot->blend_domain);
990 nlavalidmask_free(&nec_snapshot->remap_domain);
991 MEM_delete(nec_snapshot);
992}
993
994/* Copy all data in the snapshot. */
996 const NlaEvalChannelSnapshot *src)
997{
998 BLI_assert(dst->channel == src->channel);
999
1000 memcpy(dst->values, src->values, sizeof(float) * dst->length);
1001}
1002
1003/* ---------------------- */
1004
1005/* Initialize a blending state snapshot structure. */
1007 NlaEvalData *nlaeval,
1008 NlaEvalSnapshot *base)
1009{
1010 snapshot->base = base;
1011 snapshot->size = std::max(16, nlaeval->num_channels);
1013 "NlaEvalSnapshot::channels");
1014}
1015
1016/* Retrieve the individual channel snapshot. */
1018{
1019 return (index < snapshot->size) ? snapshot->channels[index] : nullptr;
1020}
1021
1022/* Ensure at least this number of slots exists. */
1023static void nlaeval_snapshot_ensure_size(NlaEvalSnapshot *snapshot, int size)
1024{
1025 if (size > snapshot->size) {
1026 snapshot->size *= 2;
1027 CLAMP_MIN(snapshot->size, size);
1028 CLAMP_MIN(snapshot->size, 16);
1029
1030 size_t byte_size = sizeof(*snapshot->channels) * snapshot->size;
1031 snapshot->channels = static_cast<NlaEvalChannelSnapshot **>(
1032 MEM_realloc_zeroed_id(snapshot->channels, byte_size, "NlaEvalSnapshot::channels"));
1033 }
1034}
1035
1036/* Retrieve the address of a slot in the blending state snapshot for this channel (may realloc). */
1038 NlaEvalChannel *nec)
1039{
1041 return &snapshot->channels[nec->index];
1042}
1043
1044/* Retrieve the blending snapshot for the specified channel, with fallback to base. */
1046 NlaEvalChannel *nec)
1047{
1048 while (snapshot != nullptr) {
1049 NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_get(snapshot, nec->index);
1050 if (nec_snapshot != nullptr) {
1051 return nec_snapshot;
1052 }
1053 snapshot = snapshot->base;
1054 }
1055
1056 return &nec->base_snapshot;
1057}
1058
1059/* Retrieve or create the channel value snapshot, copying from the other snapshot
1060 * (or default values) */
1062 NlaEvalChannel *nec)
1063{
1065
1066 if (*slot == nullptr) {
1067 NlaEvalChannelSnapshot *base_snapshot, *nec_snapshot;
1068
1069 nec_snapshot = nlaevalchan_snapshot_new(nec);
1070 base_snapshot = nlaeval_snapshot_find_channel(snapshot->base, nec);
1071
1072 nlaevalchan_snapshot_copy(nec_snapshot, base_snapshot);
1073
1074 *slot = nec_snapshot;
1075 }
1076
1077 return *slot;
1078}
1079
1080/* Free all memory owned by this blending snapshot structure. */
1082{
1083 if (snapshot->channels != nullptr) {
1084 for (int i = 0; i < snapshot->size; i++) {
1085 NlaEvalChannelSnapshot *nec_snapshot = snapshot->channels[i];
1086 if (nec_snapshot != nullptr) {
1087 nlaevalchan_snapshot_free(nec_snapshot);
1088 }
1089 }
1090
1091 MEM_delete(snapshot->channels);
1092 }
1093
1094 snapshot->base = nullptr;
1095 snapshot->size = 0;
1096 snapshot->channels = nullptr;
1097}
1098
1099/* ---------------------- */
1100
1101/* Free memory owned by this evaluation channel. */
1103{
1105 nec->key.~NlaEvalChannelKey();
1106 /* The channel is allocated as raw memory with extra space for the values of its base snapshot,
1107 * see #nlaevalchan_verify_key. */
1108 MEM_delete_void(static_cast<void *>(nec));
1109}
1110
1111/* Initialize a full NLA evaluation state structure. */
1112static void nlaeval_init(NlaEvalData *nlaeval)
1113{
1114 memset(nlaeval, 0, sizeof(*nlaeval));
1115
1116 nlaeval->path_hash = BLI_ghash_str_new("NlaEvalData::path_hash");
1117 nlaeval->key_hash = MEM_new<Map<NlaEvalChannelKey, NlaEvalChannel *>>("NlaEvalData::key_hash");
1118}
1119
1120static void nlaeval_free(NlaEvalData *nlaeval)
1121{
1122 /* Delete base snapshot - its channels are part of NlaEvalChannel and shouldn't be freed. */
1123 MEM_SAFE_DELETE(nlaeval->base_snapshot.channels);
1124
1125 /* Delete result snapshot. */
1127
1128 /* Delete channels. */
1129 for (NlaEvalChannel &nec : nlaeval->channels.items_mutable()) {
1130 nlaevalchan_free(&nec);
1131 }
1132 nlaeval->channels.clear_no_delete();
1133 BLI_ghash_free(nlaeval->path_hash, nullptr, nullptr);
1134 MEM_delete(nlaeval->key_hash);
1135}
1136
1137/* ---------------------- */
1138
1140{
1141 if (nec->is_array) {
1142 if (index >= 0 && index < nec->base_snapshot.length) {
1143 return index;
1144 }
1145
1146 return -1;
1147 }
1148 return 0;
1149}
1150
1151static bool nlaevalchan_validate_index_ex(const NlaEvalChannel *nec, const int array_index)
1152{
1153 /* Although array_index comes from fcurve, that doesn't necessarily mean the property has that
1154 * many elements. */
1155 const int index = nlaevalchan_validate_index(nec, array_index);
1156
1157 if (index < 0) {
1158 if (G.debug & G_DEBUG) {
1159 ID *id = nec->key.ptr.owner_id;
1161 "Animation: Invalid array index. ID = '%s', '%s[%d]', array length is %d",
1162 id ? (id->name + 2) : "<No ID>",
1163 nec->rna_path,
1164 array_index,
1165 nec->base_snapshot.length);
1166 }
1167
1168 return false;
1169 }
1170 return true;
1171}
1172
1173/* Initialize default values for NlaEvalChannel from the property data. */
1174static void nlaevalchan_get_default_values(NlaEvalChannel *nec, float *r_values)
1175{
1176 PointerRNA *ptr = &nec->key.ptr;
1177 PropertyRNA *prop = nec->key.prop;
1178 int length = nec->base_snapshot.length;
1179
1180 /* Use unit quaternion for quaternion properties. */
1181 if (nec->mix_mode == NEC_MIX_QUATERNION) {
1182 unit_qt(r_values);
1183 return;
1184 }
1185 /* Use all zero for Axis-Angle properties. */
1186 if (nec->mix_mode == NEC_MIX_AXIS_ANGLE) {
1187 zero_v4(r_values);
1188 return;
1189 }
1190
1191 /* NOTE: while this doesn't work for all RNA properties as default values aren't in fact
1192 * set properly for most of them, at least the common ones (which also happen to get used
1193 * in NLA strips a lot, e.g. scale) are set correctly.
1194 */
1195 if (RNA_property_array_check(prop)) {
1197 bool *tmp_bool;
1198 int *tmp_int;
1199
1200 switch (RNA_property_type(prop)) {
1201 case PROP_BOOLEAN:
1202 tmp_bool = MEM_new_array_uninitialized<bool>(size_t(length), __func__);
1203 RNA_property_boolean_get_default_array(ptr, prop, tmp_bool);
1204 for (int i = 0; i < length; i++) {
1205 r_values[i] = float(tmp_bool[i]);
1206 }
1207 MEM_delete(tmp_bool);
1208 break;
1209 case PROP_INT:
1210 tmp_int = MEM_new_array_uninitialized<int>(size_t(length), __func__);
1211 RNA_property_int_get_default_array(ptr, prop, tmp_int);
1212 for (int i = 0; i < length; i++) {
1213 r_values[i] = float(tmp_int[i]);
1214 }
1215 MEM_delete(tmp_int);
1216 break;
1217 case PROP_FLOAT:
1218 RNA_property_float_get_default_array(ptr, prop, r_values);
1219 break;
1220 default:
1221 memset(r_values, 0, sizeof(float) * length);
1222 }
1223 }
1224 else {
1225 BLI_assert(length == 1);
1226
1227 switch (RNA_property_type(prop)) {
1228 case PROP_BOOLEAN:
1229 *r_values = float(RNA_property_boolean_get_default(ptr, prop));
1230 break;
1231 case PROP_INT:
1232 *r_values = float(RNA_property_int_get_default(ptr, prop));
1233 break;
1234 case PROP_FLOAT:
1235 *r_values = RNA_property_float_get_default(ptr, prop);
1236 break;
1237 case PROP_ENUM:
1238 *r_values = float(RNA_property_enum_get_default(ptr, prop));
1239 break;
1240 default:
1241 *r_values = 0.0f;
1242 }
1243 }
1244
1245 /* Ensure multiplicative properties aren't reset to 0. */
1246 if (nec->mix_mode == NEC_MIX_MULTIPLY) {
1247 for (int i = 0; i < length; i++) {
1248 if (r_values[i] == 0.0f) {
1249 r_values[i] = 1.0f;
1250 }
1251 }
1252 }
1253}
1254
1256{
1258
1259 if (subtype == PROP_QUATERNION && length == 4) {
1260 return NEC_MIX_QUATERNION;
1261 }
1262 if (subtype == PROP_AXISANGLE && length == 4) {
1263 return NEC_MIX_AXIS_ANGLE;
1264 }
1266 return NEC_MIX_MULTIPLY;
1267 }
1268 return NEC_MIX_ADD;
1269}
1270
1271/* Verify that an appropriate NlaEvalChannel for this property exists. */
1273 const char *path,
1274 NlaEvalChannelKey *key)
1275{
1276 return nlaeval->key_hash->lookup_or_add_cb(*key, [&]() {
1277 /* Create the channel. */
1278 bool is_array = RNA_property_array_check(key->prop);
1279 int length = is_array ? RNA_property_array_length(&key->ptr, key->prop) : 1;
1280
1281 NlaEvalChannel *nec = static_cast<NlaEvalChannel *>(
1282 MEM_new_zeroed(sizeof(NlaEvalChannel) + sizeof(float) * length, "NlaEvalChannel"));
1283
1284 /* Initialize the channel. */
1285 nec->rna_path = path;
1286 new (&nec->key) NlaEvalChannelKey(*key);
1287
1288 nec->owner = nlaeval;
1289 nec->index = nlaeval->num_channels++;
1290 nec->is_array = is_array;
1291
1293
1295
1296 nec->base_snapshot.channel = nec;
1298 nec->base_snapshot.is_base = true;
1299
1301
1302 /* Store channel in data structures. */
1303 BLI_addtail(&nlaeval->channels, nec);
1304
1306
1307 return nec;
1308 });
1309}
1310
1311/* Verify that an appropriate NlaEvalChannel for this path exists. */
1312static NlaEvalChannel *nlaevalchan_verify(PointerRNA *ptr, NlaEvalData *nlaeval, const char *path)
1313{
1314 if (path == nullptr) {
1315 return nullptr;
1316 }
1317
1318 /* Lookup the path in the path based hash. */
1319 NlaEvalChannel **p_path_nec;
1320 bool found_path = BLI_ghash_ensure_p(nlaeval->path_hash, (void *)path, (void ***)&p_path_nec);
1321
1322 if (found_path) {
1323 return *p_path_nec;
1324 }
1325
1326 /* Cache nullptr result for now. */
1327 *p_path_nec = nullptr;
1328
1329 /* Resolve the property and look it up in the key hash. */
1330 NlaEvalChannelKey key{};
1331
1332 if (!RNA_path_resolve_property(ptr, path, &key.ptr, &key.prop)) {
1333 /* Report failure to resolve the path. */
1334 if (G.debug & G_DEBUG) {
1336 "Invalid path. ID = '%s', '%s'",
1337 (ptr->owner_id) ? (ptr->owner_id->name + 2) : "<No ID>",
1338 path);
1339 }
1340
1341 return nullptr;
1342 }
1343
1344 /* Check that the property can be animated. */
1345 if (ptr->owner_id != nullptr && !RNA_property_animateable(&key.ptr, key.prop)) {
1346 return nullptr;
1347 }
1348
1349 NlaEvalChannel *nec = nlaevalchan_verify_key(nlaeval, path, &key);
1350
1351 if (nec->rna_path == nullptr) {
1352 nec->rna_path = path;
1353 }
1354
1355 return *p_path_nec = nec;
1356}
1357
1358/* ---------------------- */
1359
1361static bool nla_blend_get_inverted_lower_value(const int blendmode,
1362 const float strip_value,
1363 const float blended_value,
1364 const float influence,
1365 float *r_lower_value)
1366{
1367 if (IS_EQF(influence, 0.0f)) {
1368 *r_lower_value = blended_value;
1369 return true;
1370 }
1371
1372 switch (blendmode) {
1373 case NLASTRIP_MODE_ADD: /* Simply subtract the scaled value on to the stack. */
1374 *r_lower_value = blended_value - (strip_value * influence);
1375 return true;
1376
1377 case NLASTRIP_MODE_SUBTRACT: /* Simply add the scaled value from the stack. */
1378 *r_lower_value = blended_value + (strip_value * influence);
1379 return true;
1380
1382 /* Check for division by zero. */
1383 const float denominator = (influence * strip_value + (1.0f - influence));
1384 if (IS_EQF(denominator, 0.0f)) {
1385 /* For 0/0, any r_lower_value is a solution. We'll just choose 1.
1386 *
1387 * Any r_lower_value is a solution. In this case, ideally we would insert redundant
1388 * keyframes, those that don't change the fcurve's shape. Otherwise, we're likely messing
1389 * up interpolation for the animator, requiring further cleanup on their part.
1390 */
1391 if (IS_EQF(blended_value, 0.0f)) {
1392 /* When denominator==0:
1393 *
1394 * denominator = (inf * strip_value + (1.0f - inf))
1395 * 0 = inf * strip_value + (1-inf)
1396 * -inf * strip_value = 1 - inf
1397 * -strip_value = (1 - inf) / inf
1398 * strip_value = (inf - 1) / inf
1399 * strip_value = 1 - (1/inf)
1400 *
1401 * For blending, nla_blend_value(), this results in:
1402 *
1403 * blended_value = inf * (lower_value * strip_value) + (1 - inf) * lower_value;
1404 * = inf * (lower_value * (1 - (1/inf))) + ...
1405 * = inf * (1 - (1/inf)) * lower_value + ...
1406 * = (inf - (inf/inf)) * lower_value + ...
1407 * = -(inf - 1) * lower_value + (1 - inf) * lower_value;
1408 * blended_value = 0
1409 *
1410 * Effectively, blended_value will equal 0 no matter what lower_value is. Put another
1411 * way, when (blended_value==0 and denominator==0), then lower_value can be any value and
1412 * blending will give us back blended_value=0. We have infinite solutions for this case.
1413 */
1414 *r_lower_value = 1;
1415 return true;
1416 }
1417 /* No solution for division by zero. */
1418 return false;
1419 }
1420 /* Math:
1421 * blended_value = inf * (lower_value * strip_value) + (1 - inf) * lower_value
1422 * = lower_value * (inf * strip_value + (1-inf))
1423 * lower_value = blended_value / (inf * strip_value + (1-inf))
1424 * lower_value = blended_value / denominator
1425 */
1426 *r_lower_value = blended_value / denominator;
1427 return true;
1428 }
1430 BLI_assert_msg(0, "Use nla_combine_get_inverted_lower_value()");
1431 return false;
1432
1434
1435 /* No solution if lower strip has 0 influence. */
1436 if (IS_EQF(influence, 1.0f)) {
1437 return false;
1438 }
1439
1440 /* Math:
1441 *
1442 * blended_value = lower_value * (1.0f - inf) + (strip_value * inf)
1443 * blended_value - (strip_value * inf) = lower_value * (1.0f - inf)
1444 * blended_value - (strip_value * inf) / (1.0f - inf) = lower_value
1445 *
1446 * lower_value = blended_value - (strip_value * inf) / (1.0f - inf)
1447 */
1448 *r_lower_value = (blended_value - (strip_value * influence)) / (1.0f - influence);
1449 return true;
1450 }
1451
1452 BLI_assert_msg(0, "invalid blend mode");
1453 return false;
1454}
1455
1457static bool nla_combine_get_inverted_lower_value(const int mix_mode,
1458 float base_value,
1459 const float strip_value,
1460 const float blended_value,
1461 const float influence,
1462 float *r_lower_value)
1463{
1464 if (IS_EQF(influence, 0.0f)) {
1465 *r_lower_value = blended_value;
1466 return true;
1467 }
1468
1469 /* Perform blending. */
1470 switch (mix_mode) {
1471 case NEC_MIX_ADD:
1472 case NEC_MIX_AXIS_ANGLE:
1473 *r_lower_value = blended_value - (strip_value - base_value) * influence;
1474 return true;
1475 case NEC_MIX_MULTIPLY: /* Division by zero. */
1476 if (IS_EQF(strip_value, 0.0f)) {
1477 /* Resolve 0/0 to 1.
1478 *
1479 * Any r_lower_value is a solution. In this case, ideally we would insert redundant
1480 * keyframes, those that don't change the fcurve's shape. Otherwise, we're likely messing
1481 * up interpolation for the animator, requiring further cleanup on their part.
1482 */
1483 if (IS_EQF(blended_value, 0.0f)) {
1484 /* For blending, nla_combine_value(), when `strip_value == 0`:
1485 * \code{.cc}
1486 * blended_value = lower_value * powf(strip_value / base_value, infl);
1487 * blended_value = lower_value * powf(0, infl);
1488 * blended_value = lower_value * 0;
1489 * blended_value = 0;
1490 * \endcode
1491 *
1492 * Effectively, blended_value will equal 0 no matter what lower_value is. Put another
1493 * way, when (blended_value==0 and strip_value==0), then lower_value can be any value and
1494 * blending will give us back blended_value=0. We have infinite solutions for this case.
1495 */
1496 *r_lower_value = 1.0f;
1497 return true;
1498 }
1499 /* No solution. */
1500 return false;
1501 }
1502
1503 if (IS_EQF(base_value, 0.0f)) {
1504 base_value = 1.0f;
1505 }
1506
1507 *r_lower_value = blended_value / powf(strip_value / base_value, influence);
1508 return true;
1509
1510 case NEC_MIX_QUATERNION:
1511 BLI_assert_msg(0, "Use nla_combine_quaternion_get_inverted_lower_values()");
1512 return false;
1513 }
1514
1515 BLI_assert_msg(0, "Mixmode not implemented");
1516 return false;
1517}
1518
1519static void nla_combine_quaternion_get_inverted_lower_values(const float strip_values[4],
1520 const float blended_values[4],
1521 const float influence,
1522 float r_lower_value[4])
1523{
1524 if (IS_EQF(influence, 0.0f)) {
1525 normalize_qt_qt(r_lower_value, blended_values);
1526 return;
1527 }
1528
1529 /* blended_value = lower_values @ strip_values^infl
1530 * blended_value @ inv(strip_values^inf) = lower_values
1531 *
1532 * Returns: lower_values = blended_value @ inv(strip_values^inf) */
1533 float tmp_strip_values[4], tmp_blended[4];
1534
1535 normalize_qt_qt(tmp_strip_values, strip_values);
1536 normalize_qt_qt(tmp_blended, blended_values);
1537
1538 pow_qt_fl_normalized(tmp_strip_values, influence);
1539 invert_qt_normalized(tmp_strip_values);
1540
1541 mul_qt_qtqt(r_lower_value, tmp_blended, tmp_strip_values);
1542}
1543
1544/* Blend the lower nla stack value and upper strip value of a channel according to mode and
1545 * influence. */
1546static float nla_blend_value(const int blendmode,
1547 const float lower_value,
1548 const float strip_value,
1549 const float influence)
1550{
1551 /* Optimization: no need to try applying if there is no influence. */
1552 if (IS_EQF(influence, 0.0f)) {
1553 return lower_value;
1554 }
1555
1556 /* Perform blending. */
1557 switch (blendmode) {
1558 case NLASTRIP_MODE_ADD: /* Simply add the scaled value on to the stack. */
1559 return lower_value + (strip_value * influence);
1560
1561 case NLASTRIP_MODE_SUBTRACT: /* Simply subtract the scaled value from the stack. */
1562 return lower_value - (strip_value * influence);
1563
1564 case NLASTRIP_MODE_MULTIPLY: /* Multiply the scaled value with the stack. */
1565 return influence * (lower_value * strip_value) + (1 - influence) * lower_value;
1566
1568 BLI_assert_msg(0, "combine mode");
1570
1571 default: /* TODO: Do we really want to blend by default? it seems more uses might prefer add...
1572 */
1573 /* Do linear interpolation. The influence of the accumulated data
1574 * (elsewhere, that is called `dstwegiht`) is 1 - influence,
1575 * since the strip's influence is `srcweight`. */
1576 return lower_value * (1.0f - influence) + (strip_value * influence);
1577 }
1578}
1579
1580/* Blend the lower nla stack value and upper strip value of a channel according to mode and
1581 * influence. */
1582static float nla_combine_value(const int mix_mode,
1583 float base_value,
1584 const float lower_value,
1585 const float strip_value,
1586 const float influence)
1587{
1588 /* Optimization: No need to try applying if there is no influence. */
1589 if (IS_EQF(influence, 0.0f)) {
1590 return lower_value;
1591 }
1592
1593 /* Perform blending */
1594 switch (mix_mode) {
1595 case NEC_MIX_ADD:
1596 case NEC_MIX_AXIS_ANGLE:
1597 return lower_value + (strip_value - base_value) * influence;
1598
1599 case NEC_MIX_MULTIPLY:
1600 if (IS_EQF(base_value, 0.0f)) {
1601 base_value = 1.0f;
1602 }
1603 return lower_value * powf(strip_value / base_value, influence);
1604
1605 default:
1606 BLI_assert_msg(0, "invalid mix mode");
1607 return lower_value;
1608 }
1609}
1610
1612static bool nla_blend_get_inverted_strip_value(const int blendmode,
1613 const float lower_value,
1614 const float blended_value,
1615 const float influence,
1616 float *r_strip_value)
1617{
1619 if (IS_EQF(influence, 0.0f)) {
1620 return false;
1621 }
1622
1623 switch (blendmode) {
1624 case NLASTRIP_MODE_ADD:
1625 *r_strip_value = (blended_value - lower_value) / influence;
1626 return true;
1627
1629 *r_strip_value = (lower_value - blended_value) / influence;
1630 return true;
1631
1633 if (IS_EQF(lower_value, 0.0f)) {
1634 /* Resolve 0/0 to 1. */
1635 if (IS_EQF(blended_value, 0.0f)) {
1636 *r_strip_value = 1.0f;
1637 return true;
1638 }
1639 /* Division by zero. */
1640 return false;
1641 }
1642
1643 /* Math:
1644 *
1645 * blended_value = inf * (lower_value * strip_value) + (1 - inf) * lower_value
1646 * blended_value - (1 - inf) * lower_value = inf * (lower_value * strip_value)
1647 * (blended_value - (1 - inf) * lower_value) / (inf * lower_value) = strip_value
1648 * (blended_value - lower_value + inf * lower_value) / (inf * lower_value) = strip_value
1649 * ((blended_value - lower_value) / (inf * lower_value)) + 1 = strip_value
1650 *
1651 * strip_value = ((blended_value - lower_value) / (inf * lower_value)) + 1
1652 */
1653 *r_strip_value = ((blended_value - lower_value) / (influence * lower_value)) + 1.0f;
1654 return true;
1655
1657 BLI_assert_msg(0, "combine mode");
1659
1660 default:
1661
1662 /* Math:
1663 *
1664 * blended_value = lower_value * (1.0f - inf) + (strip_value * inf)
1665 * blended_value - lower_value * (1.0f - inf) = (strip_value * inf)
1666 * (blended_value - lower_value * (1.0f - inf)) / inf = strip_value
1667 *
1668 * strip_value = (blended_value - lower_value * (1.0f - inf)) / inf
1669 */
1670 *r_strip_value = (blended_value - lower_value * (1.0f - influence)) / influence;
1671 return true;
1672 }
1673}
1674
1676static bool nla_combine_get_inverted_strip_value(const int mix_mode,
1677 float base_value,
1678 const float lower_value,
1679 const float blended_value,
1680 const float influence,
1681 float *r_strip_value)
1682{
1683 /* No solution if strip had no influence. */
1684 if (IS_EQF(influence, 0.0f)) {
1685 return false;
1686 }
1687
1688 switch (mix_mode) {
1689 case NEC_MIX_ADD:
1690 case NEC_MIX_AXIS_ANGLE:
1691 *r_strip_value = base_value + (blended_value - lower_value) / influence;
1692 return true;
1693
1694 case NEC_MIX_MULTIPLY:
1695 if (IS_EQF(base_value, 0.0f)) {
1696 base_value = 1.0f;
1697 }
1698 /* Division by zero. */
1699 if (IS_EQF(lower_value, 0.0f)) {
1700 /* Resolve 0/0 to 1. */
1701 if (IS_EQF(blended_value, 0.0f)) {
1702 *r_strip_value = base_value;
1703 return true;
1704 }
1705 /* Division by zero. */
1706 return false;
1707 }
1708
1709 *r_strip_value = base_value * powf(blended_value / lower_value, 1.0f / influence);
1710 return true;
1711
1712 default:
1713 BLI_assert_msg(0, "invalid mix mode");
1714 return false;
1715 }
1716}
1717
1722static void nla_combine_quaternion(const float lower_values[4],
1723 const float strip_values[4],
1724 const float influence,
1725 float r_blended_value[4])
1726{
1727 float tmp_lower[4], tmp_strip_values[4];
1728
1729 normalize_qt_qt(tmp_lower, lower_values);
1730 normalize_qt_qt(tmp_strip_values, strip_values);
1731
1732 pow_qt_fl_normalized(tmp_strip_values, influence);
1733 mul_qt_qtqt(r_blended_value, tmp_lower, tmp_strip_values);
1734}
1735
1737static bool nla_combine_quaternion_get_inverted_strip_values(const float lower_values[4],
1738 const float blended_values[4],
1739 const float influence,
1740 float r_strip_values[4])
1741{
1742 /* blended_value = lower_values @ r_strip_values^infl
1743 * inv(lower_values) @ blended_value = r_strip_values^infl
1744 * (inv(lower_values) @ blended_value) ^ (1/inf) = r_strip_values
1745 *
1746 * Returns: r_strip_values = (inv(lower_values) @ blended_value) ^ (1/inf) */
1747 if (IS_EQF(influence, 0.0f)) {
1748 return false;
1749 }
1750 float tmp_lower[4], tmp_blended[4];
1751
1752 normalize_qt_qt(tmp_lower, lower_values);
1753 normalize_qt_qt(tmp_blended, blended_values);
1754 invert_qt_normalized(tmp_lower);
1755
1756 mul_qt_qtqt(r_strip_values, tmp_lower, tmp_blended);
1757 pow_qt_fl_normalized(r_strip_values, 1.0f / influence);
1758
1759 return true;
1760}
1761
1762/* ---------------------- */
1763
1764/* Assert necs and necs->channel is nonNull. */
1766{
1767 UNUSED_VARS_NDEBUG(necs);
1768 BLI_assert(necs != nullptr && necs->channel != nullptr);
1769}
1770
1771/* Assert that the channels given can be blended or combined together. */
1773 const NlaEvalChannelSnapshot *lower_necs,
1774 const NlaEvalChannelSnapshot *upper_necs,
1775 const NlaEvalChannelSnapshot *blended_necs)
1776{
1777 UNUSED_VARS_NDEBUG(lower_necs, upper_necs, blended_necs);
1778 BLI_assert(!ELEM(nullptr, lower_necs, blended_necs));
1779 BLI_assert(upper_necs == nullptr || lower_necs->length == upper_necs->length);
1780 BLI_assert(lower_necs->length == blended_necs->length);
1781}
1782
1791 NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_or_lower_necs)
1792{
1793 for (int j = 0; j < 4; j++) {
1794 if (!BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, j)) {
1795 BLI_bitmap_set_all(upper_or_lower_necs->remap_domain.ptr, false, 4);
1796 return true;
1797 }
1798 }
1799
1800 return false;
1801}
1802
1803/* Assert that the channels given can be blended or combined together as a quaternion. */
1805 NlaEvalChannelSnapshot *lower_necs,
1806 NlaEvalChannelSnapshot *upper_necs,
1807 NlaEvalChannelSnapshot *blended_necs)
1808{
1809 nlaevalchan_assert_blendOrcombine_compatible(lower_necs, upper_necs, blended_necs);
1810 BLI_assert(lower_necs->length == 4);
1811}
1812
1814{
1815 memcpy(dst->values, src->values, src->length * sizeof(float));
1816}
1817
1823 const NlaEvalChannelSnapshot *lower_necs,
1824 const NlaEvalChannelSnapshot *upper_necs,
1825 const float upper_influence,
1826 NlaEvalChannelSnapshot *r_blended_necs)
1827{
1828 const bool has_influence = !IS_EQF(upper_influence, 0.0f);
1829 if (upper_necs != nullptr && has_influence) {
1830 return false;
1831 }
1832
1833 nlaevalchan_copy_values(r_blended_necs, lower_necs);
1834 return true;
1835}
1836
1846 NlaEvalChannelSnapshot *upper_necs,
1847 const float upper_influence,
1848 NlaEvalChannelSnapshot *r_lower_necs)
1849{
1850 const bool has_influence = !IS_EQF(upper_influence, 0.0f);
1851 if (upper_necs != nullptr && has_influence) {
1852 return false;
1853 }
1854
1855 nlaevalchan_copy_values(r_lower_necs, blended_necs);
1856
1857 /* Must copy remap domain to handle case where some blended values are out of domain. */
1859 r_lower_necs->remap_domain.ptr, blended_necs->remap_domain.ptr, r_lower_necs->length);
1860
1861 return true;
1862}
1863
1871 NlaEvalChannelSnapshot *upper_necs,
1872 const int upper_blendmode,
1873 const float upper_influence,
1874 NlaEvalChannelSnapshot *r_blended_necs)
1875{
1876 nlaevalchan_assert_blendOrcombine_compatible(lower_necs, upper_necs, r_blended_necs);
1878 lower_necs, upper_necs, upper_influence, r_blended_necs))
1879 {
1880 return;
1881 }
1882
1883 const int length = lower_necs->length;
1884 for (int j = 0; j < length; j++) {
1885 if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, j)) {
1886 r_blended_necs->values[j] = lower_necs->values[j];
1887 continue;
1888 }
1889
1890 r_blended_necs->values[j] = nla_blend_value(
1891 upper_blendmode, lower_necs->values[j], upper_necs->values[j], upper_influence);
1892 }
1893}
1894
1902 NlaEvalChannelSnapshot *upper_necs,
1903 const float upper_influence,
1904 NlaEvalChannelSnapshot *r_blended_necs)
1905{
1906 nlaevalchan_assert_blendOrcombine_compatible(lower_necs, upper_necs, r_blended_necs);
1908 lower_necs, upper_necs, upper_influence, r_blended_necs))
1909 {
1910 return;
1911 }
1912
1913 /* Assumes every base is the same. */
1914 float *base_values = lower_necs->channel->base_snapshot.values;
1915 const int length = lower_necs->length;
1916 const char mix_mode = lower_necs->channel->mix_mode;
1917
1918 for (int j = 0; j < length; j++) {
1919 if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, j)) {
1920 r_blended_necs->values[j] = lower_necs->values[j];
1921 continue;
1922 }
1923
1924 r_blended_necs->values[j] = nla_combine_value(
1925 mix_mode, base_values[j], lower_necs->values[j], upper_necs->values[j], upper_influence);
1926 }
1927}
1928
1936 NlaEvalChannelSnapshot *upper_necs,
1937 const float upper_influence,
1938 NlaEvalChannelSnapshot *r_blended_necs)
1939{
1940 nlaevalchan_assert_blendOrcombine_compatible_quaternion(lower_necs, upper_necs, r_blended_necs);
1942 lower_necs, upper_necs, upper_influence, r_blended_necs))
1943 {
1944 return;
1945 }
1946
1948 if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, 0)) {
1949 nlaevalchan_copy_values(r_blended_necs, lower_necs);
1950 return;
1951 }
1952
1954 lower_necs->values, upper_necs->values, upper_influence, r_blended_necs->values);
1955}
1956
1970 NlaEvalChannelSnapshot *upper_necs,
1971 const int upper_blendmode,
1972 const float upper_influence,
1973 NlaEvalChannelSnapshot *r_blended_necs)
1974{
1975 nlaevalchan_assert_nonNull(r_blended_necs);
1976
1977 switch (upper_blendmode) {
1978 case NLASTRIP_MODE_COMBINE: {
1979 switch (r_blended_necs->channel->mix_mode) {
1980 case NEC_MIX_QUATERNION: {
1981 nlaevalchan_combine_quaternion(lower_necs, upper_necs, upper_influence, r_blended_necs);
1982 return;
1983 }
1984 case NEC_MIX_ADD:
1985 case NEC_MIX_AXIS_ANGLE:
1986 case NEC_MIX_MULTIPLY: {
1987 nlaevalchan_combine_value(lower_necs, upper_necs, upper_influence, r_blended_necs);
1988 return;
1989 }
1990 default:
1991 BLI_assert_msg(0, "Mix mode should've been handled");
1992 }
1993 return;
1994 }
1995 case NLASTRIP_MODE_ADD:
1998 case NLASTRIP_MODE_REPLACE: {
2000 lower_necs, upper_necs, upper_blendmode, upper_influence, r_blended_necs);
2001 return;
2002 }
2003 default:
2004 BLI_assert_msg(0, "Blend mode should've been handled");
2005 }
2006}
2007
2016 NlaEvalChannelSnapshot *lower_necs,
2017 NlaEvalChannelSnapshot *blended_necs,
2018 const int upper_blendmode,
2019 const float upper_influence,
2020 NlaEvalChannelSnapshot *r_upper_necs)
2021{
2022 nlaevalchan_assert_nonNull(r_upper_necs);
2023 nlaevalchan_assert_blendOrcombine_compatible(lower_necs, r_upper_necs, blended_necs);
2024
2025 const int length = lower_necs->length;
2026 for (int j = 0; j < length; j++) {
2027 if (!BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, j)) {
2028 BLI_BITMAP_DISABLE(r_upper_necs->remap_domain.ptr, j);
2029 continue;
2030 }
2031
2032 const bool success = nla_blend_get_inverted_strip_value(upper_blendmode,
2033 lower_necs->values[j],
2034 blended_necs->values[j],
2035 upper_influence,
2036 &r_upper_necs->values[j]);
2037 BLI_BITMAP_SET(r_upper_necs->remap_domain.ptr, j, success);
2038 }
2039}
2040
2049 NlaEvalChannelSnapshot *lower_necs,
2050 NlaEvalChannelSnapshot *blended_necs,
2051 const float upper_influence,
2052 NlaEvalChannelSnapshot *r_upper_necs)
2053{
2054 nlaevalchan_assert_nonNull(r_upper_necs);
2055 nlaevalchan_assert_blendOrcombine_compatible(lower_necs, r_upper_necs, blended_necs);
2056
2057 /* Assumes every channel's base is the same. */
2058 float *base_values = lower_necs->channel->base_snapshot.values;
2059 const int length = lower_necs->length;
2060 const char mix_mode = lower_necs->channel->mix_mode;
2061
2062 for (int j = 0; j < length; j++) {
2063 if (!BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, j)) {
2064 BLI_BITMAP_DISABLE(r_upper_necs->remap_domain.ptr, j);
2065 continue;
2066 }
2067
2068 const bool success = nla_combine_get_inverted_strip_value(mix_mode,
2069 base_values[j],
2070 lower_necs->values[j],
2071 blended_necs->values[j],
2072 upper_influence,
2073 &r_upper_necs->values[j]);
2074
2075 BLI_BITMAP_SET(r_upper_necs->remap_domain.ptr, j, success);
2076 }
2077}
2078
2087 NlaEvalChannelSnapshot *lower_necs,
2088 NlaEvalChannelSnapshot *blended_necs,
2089 const float upper_influence,
2090 NlaEvalChannelSnapshot *r_upper_necs)
2091{
2092 nlaevalchan_assert_nonNull(r_upper_necs);
2093 nlaevalchan_assert_blendOrcombine_compatible_quaternion(lower_necs, r_upper_necs, blended_necs);
2094
2095 if (nlaevalchan_combine_quaternion_handle_undefined_blend_values(blended_necs, r_upper_necs)) {
2096 return;
2097 }
2098
2100 lower_necs->values, blended_necs->values, upper_influence, r_upper_necs->values);
2101
2102 BLI_bitmap_set_all(r_upper_necs->remap_domain.ptr, success, 4);
2103}
2104
2119 NlaEvalChannelSnapshot *lower_necs,
2120 NlaEvalChannelSnapshot *blended_necs,
2121 const int upper_blendmode,
2122 const float upper_influence,
2123 NlaEvalChannelSnapshot *r_upper_necs)
2124{
2125 nlaevalchan_assert_nonNull(r_upper_necs);
2126
2127 if (IS_EQF(upper_influence, 0.0f)) {
2128 BLI_bitmap_set_all(r_upper_necs->remap_domain.ptr, false, r_upper_necs->length);
2129 return;
2130 }
2131
2132 switch (upper_blendmode) {
2133 case NLASTRIP_MODE_COMBINE: {
2134 switch (r_upper_necs->channel->mix_mode) {
2135 case NEC_MIX_QUATERNION: {
2137 lower_necs, blended_necs, upper_influence, r_upper_necs);
2138 return;
2139 }
2140 case NEC_MIX_ADD:
2141 case NEC_MIX_AXIS_ANGLE:
2142 case NEC_MIX_MULTIPLY: {
2144 lower_necs, blended_necs, upper_influence, r_upper_necs);
2145 return;
2146 }
2147 default:
2148 BLI_assert_msg(0, "Mix mode should've been handled");
2149 }
2150 return;
2151 }
2152 case NLASTRIP_MODE_ADD:
2155 case NLASTRIP_MODE_REPLACE: {
2157 lower_necs, blended_necs, upper_blendmode, upper_influence, r_upper_necs);
2158 return;
2159 }
2160 default:
2161 BLI_assert_msg(0, "Blend mode should've been handled");
2162 }
2163}
2164
2166 NlaEvalChannelSnapshot *blended_necs,
2167 NlaEvalChannelSnapshot *upper_necs,
2168 const int upper_blendmode,
2169 const float upper_influence,
2170 NlaEvalChannelSnapshot *r_lower_necs)
2171{
2172 nlaevalchan_assert_blendOrcombine_compatible(r_lower_necs, upper_necs, blended_necs);
2173
2175 blended_necs, upper_necs, upper_influence, r_lower_necs))
2176 {
2177 return;
2178 }
2179
2180 const int length = r_lower_necs->length;
2181
2182 for (int j = 0; j < length; j++) {
2183 if (!BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, j)) {
2184 BLI_BITMAP_DISABLE(r_lower_necs->remap_domain.ptr, j);
2185 continue;
2186 }
2187
2188 /* If upper value was not blended, then the blended value was directly copied from the lower
2189 * value. */
2190 if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, j)) {
2191 r_lower_necs->values[j] = blended_necs->values[j];
2192 BLI_BITMAP_ENABLE(r_lower_necs->remap_domain.ptr, j);
2193 continue;
2194 }
2195
2196 const bool success = nla_blend_get_inverted_lower_value(upper_blendmode,
2197 upper_necs->values[j],
2198 blended_necs->values[j],
2199 upper_influence,
2200 &r_lower_necs->values[j]);
2201
2202 BLI_BITMAP_SET(r_lower_necs->remap_domain.ptr, j, success);
2203 }
2204}
2205
2207 NlaEvalChannelSnapshot *blended_necs,
2208 NlaEvalChannelSnapshot *upper_necs,
2209 const float upper_influence,
2210 NlaEvalChannelSnapshot *r_lower_necs)
2211{
2212 nlaevalchan_assert_blendOrcombine_compatible(r_lower_necs, upper_necs, blended_necs);
2213
2215 blended_necs, upper_necs, upper_influence, r_lower_necs))
2216 {
2217 return;
2218 }
2219
2220 float *base_values = r_lower_necs->channel->base_snapshot.values;
2221 const int mix_mode = r_lower_necs->channel->mix_mode;
2222 const int length = r_lower_necs->length;
2223
2224 for (int j = 0; j < length; j++) {
2225 if (!BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, j)) {
2226 BLI_BITMAP_DISABLE(r_lower_necs->remap_domain.ptr, j);
2227 continue;
2228 }
2229
2230 /* If upper value was not blended, then the blended value was directly copied from the lower
2231 * value. */
2232 if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, j)) {
2233 r_lower_necs->values[j] = blended_necs->values[j];
2234 BLI_BITMAP_ENABLE(r_lower_necs->remap_domain.ptr, j);
2235 continue;
2236 }
2237
2238 const bool success = nla_combine_get_inverted_lower_value(mix_mode,
2239 base_values[j],
2240 upper_necs->values[j],
2241 blended_necs->values[j],
2242 upper_influence,
2243 &r_lower_necs->values[j]);
2244
2245 BLI_BITMAP_SET(r_lower_necs->remap_domain.ptr, j, success);
2246 }
2247}
2248
2250 NlaEvalChannelSnapshot *blended_necs,
2251 NlaEvalChannelSnapshot *upper_necs,
2252 const float upper_influence,
2253 NlaEvalChannelSnapshot *r_lower_necs)
2254{
2255 nlaevalchan_assert_blendOrcombine_compatible_quaternion(r_lower_necs, upper_necs, blended_necs);
2256
2257 if (nlaevalchan_combine_quaternion_handle_undefined_blend_values(blended_necs, r_lower_necs)) {
2258 return;
2259 }
2260
2262 blended_necs, upper_necs, upper_influence, r_lower_necs))
2263 {
2264 return;
2265 }
2266
2267 /* If upper value was not blended, then the blended value was directly copied from the lower
2268 * value. */
2269 if (!BLI_BITMAP_TEST_BOOL(upper_necs->blend_domain.ptr, 0)) {
2270 memcpy(r_lower_necs->values, blended_necs->values, 4 * sizeof(float));
2271 BLI_bitmap_set_all(r_lower_necs->remap_domain.ptr, true, 4);
2272 return;
2273 }
2274
2276 upper_necs->values, blended_necs->values, upper_influence, r_lower_necs->values);
2277
2278 BLI_bitmap_set_all(r_lower_necs->remap_domain.ptr, true, 4);
2279}
2280
2295 NlaEvalChannelSnapshot *blended_necs,
2296 NlaEvalChannelSnapshot *upper_necs,
2297 const int upper_blendmode,
2298 const float upper_influence,
2299 NlaEvalChannelSnapshot *r_lower_necs)
2300
2301{
2302 nlaevalchan_assert_nonNull(r_lower_necs);
2303
2304 switch (upper_blendmode) {
2305 case NLASTRIP_MODE_COMBINE: {
2306 switch (r_lower_necs->channel->mix_mode) {
2307 case NEC_MIX_QUATERNION: {
2309 blended_necs, upper_necs, upper_influence, r_lower_necs);
2310 return;
2311 }
2312 case NEC_MIX_ADD:
2313 case NEC_MIX_AXIS_ANGLE:
2314 case NEC_MIX_MULTIPLY: {
2316 blended_necs, upper_necs, upper_influence, r_lower_necs);
2317 return;
2318 }
2319 }
2320 BLI_assert_msg(0, "Mix mode should've been handled");
2321 return;
2322 }
2323 case NLASTRIP_MODE_ADD:
2326 case NLASTRIP_MODE_REPLACE: {
2328 blended_necs, upper_necs, upper_blendmode, upper_influence, r_lower_necs);
2329 return;
2330 }
2331 }
2332
2333 BLI_assert_msg(0, "Blend mode should've been handled");
2334}
2335
2336/* ---------------------- */
2337/* F-Modifier stack joining/separation utilities -
2338 * should we generalize these for BLI_listbase.hh interface? */
2339
2340/* Temporarily join two lists of modifiers together, storing the result in a third list */
2341static void nlaeval_fmodifiers_join_stacks(ListBaseT<FModifier> *result,
2342 ListBaseT<FModifier> *list1,
2343 ListBaseT<FModifier> *list2)
2344{
2345 FModifier *fcm1, *fcm2;
2346
2347 /* if list1 is invalid... */
2348 if (ELEM(nullptr, list1, list1->first())) {
2349 if (list2 && list2->first()) {
2350 result->first_ = list2->first();
2351 result->last_ = list2->last();
2352 }
2353 }
2354 /* if list 2 is invalid... */
2355 else if (ELEM(nullptr, list2, list2->first())) {
2356 result->first_ = list1->first();
2357 result->last_ = list1->last();
2358 }
2359 else {
2360 /* list1 should be added first, and list2 second,
2361 * with the endpoints of these being the endpoints for result
2362 * - the original lists must be left unchanged though, as we need that fact for restoring.
2363 */
2364 result->first_ = list1->first();
2365 result->last_ = list2->last();
2366
2367 fcm1 = list1->last();
2368 fcm2 = list2->first();
2369
2370 fcm1->next = fcm2;
2371 fcm2->prev = fcm1;
2372 }
2373}
2374
2375/* Split two temporary lists of modifiers */
2376static void nlaeval_fmodifiers_split_stacks(ListBaseT<FModifier> *list1,
2377 ListBaseT<FModifier> *list2)
2378{
2379 FModifier *fcm1, *fcm2;
2380
2381 /* if list1/2 is invalid... just skip */
2382 if (ELEM(nullptr, list1, list2)) {
2383 return;
2384 }
2385 if (ELEM(nullptr, list1->first(), list2->first())) {
2386 return;
2387 }
2388
2389 /* get endpoints */
2390 fcm1 = list1->last();
2391 fcm2 = list2->first();
2392
2393 /* clear their links */
2394 fcm1->next = nullptr;
2395 fcm2->prev = nullptr;
2396}
2397
2398/* ---------------------- */
2399
2402 NlaEvalData *channels,
2403 ListBaseT<FModifier> *modifiers,
2404 bAction *action,
2405 const animrig::slot_handle_t slot_handle,
2406 const float evaltime,
2407 NlaEvalSnapshot *r_snapshot)
2408{
2409 /* Evaluate modifiers which modify time to evaluate the base curves at. */
2411 storage.modifier_count = modifiers->count();
2412 storage.size_per_modifier = evaluate_fmodifiers_storage_size_per_modifier(modifiers);
2413 storage.buffer = alloca(storage.modifier_count * storage.size_per_modifier);
2414
2415 const float modified_evaltime = evaluate_time_fmodifiers(
2416 &storage, modifiers, nullptr, 0.0f, evaltime);
2417
2418 for (const FCurve *fcu : animrig::fcurves_for_action_slot(action->wrap(), slot_handle)) {
2419 if (!is_fcurve_evaluatable(fcu)) {
2420 continue;
2421 }
2422
2423 NlaEvalChannel *nec = nlaevalchan_verify(ptr, channels, fcu->rna_path().c_str());
2424
2425 /* Invalid path or property cannot be animated. */
2426 if (nec == nullptr) {
2427 continue;
2428 }
2429
2430 if (!nlaevalchan_validate_index_ex(nec, fcu->array_index)) {
2431 continue;
2432 }
2433
2435
2436 float value = evaluate_fcurve(fcu, modified_evaltime);
2437 evaluate_value_fmodifiers(&storage, modifiers, fcu, &value, evaltime);
2438 necs->values[fcu->array_index] = value;
2439
2440 if (nec->mix_mode == NEC_MIX_QUATERNION) {
2441 BLI_bitmap_set_all(necs->blend_domain.ptr, true, 4);
2442 }
2443 else {
2444 BLI_BITMAP_ENABLE(necs->blend_domain.ptr, fcu->array_index);
2445 }
2446 }
2447}
2448
2449/* evaluate action-clip strip */
2450static void nlastrip_evaluate_actionclip(const int evaluation_mode,
2451 PointerRNA *ptr,
2452 NlaEvalData *channels,
2453 ListBaseT<FModifier> *modifiers,
2454 NlaEvalStrip *nes,
2455 NlaEvalSnapshot *snapshot)
2456{
2457
2458 NlaStrip *strip = nes->strip;
2459
2460 /* sanity checks for action */
2461 if (strip == nullptr) {
2462 return;
2463 }
2464
2465 if (strip->act == nullptr) {
2466 CLOG_ERROR(&LOG_ANIM_NLA, "NLA-Strip Eval Error: Strip '%s' has no Action", strip->name);
2467 return;
2468 }
2469
2470 ListBaseT<FModifier> tmp_modifiers = {nullptr, nullptr};
2471
2472 /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
2473 nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers);
2474
2475 switch (evaluation_mode) {
2476 case STRIP_EVAL_BLEND: {
2477
2478 NlaEvalSnapshot strip_snapshot;
2479 nlaeval_snapshot_init(&strip_snapshot, channels, nullptr);
2480
2482 channels,
2483 &tmp_modifiers,
2484 strip->act,
2485 strip->action_slot_handle,
2486 strip->strip_time,
2487 &strip_snapshot);
2489 channels, snapshot, &strip_snapshot, strip->blendmode, strip->influence, snapshot);
2490
2491 nlaeval_snapshot_free_data(&strip_snapshot);
2492
2493 break;
2494 }
2496
2497 NlaEvalSnapshot strip_snapshot;
2498 nlaeval_snapshot_init(&strip_snapshot, channels, nullptr);
2499
2501 channels,
2502 &tmp_modifiers,
2503 strip->act,
2504 strip->action_slot_handle,
2505 strip->strip_time,
2506 &strip_snapshot);
2508 channels, snapshot, &strip_snapshot, strip->blendmode, strip->influence, snapshot);
2509
2510 nlaeval_snapshot_free_data(&strip_snapshot);
2511
2512 break;
2513 }
2514 case STRIP_EVAL_NOBLEND: {
2516 channels,
2517 &tmp_modifiers,
2518 strip->act,
2519 strip->action_slot_handle,
2520 strip->strip_time,
2521 snapshot);
2522 break;
2523 }
2524 }
2525
2526 /* unlink this strip's modifiers from the parent's modifiers again */
2527 nlaeval_fmodifiers_split_stacks(&strip->modifiers, modifiers);
2528}
2529
2530/* evaluate transition strip */
2531static void nlastrip_evaluate_transition(const int evaluation_mode,
2532 PointerRNA *ptr,
2533 NlaEvalData *channels,
2534 ListBaseT<FModifier> *modifiers,
2535 NlaEvalStrip *nes,
2536 NlaEvalSnapshot *snapshot,
2537 const AnimationEvalContext *anim_eval_context,
2538 const bool flush_to_original)
2539{
2540 ListBaseT<FModifier> tmp_modifiers = {nullptr, nullptr};
2541 NlaEvalSnapshot snapshot1, snapshot2;
2542 NlaEvalStrip tmp_nes;
2543 NlaStrip *s1, *s2;
2544
2545 /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
2546 nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &nes->strip->modifiers, modifiers);
2547
2548 /* get the two strips to operate on
2549 * - we use the endpoints of the strips directly flanking our strip
2550 * using these as the endpoints of the transition (destination and source)
2551 * - these should have already been determined to be valid...
2552 * - if this strip is being played in reverse, we need to swap these endpoints
2553 * otherwise they will be interpolated wrong
2554 */
2555 if (nes->strip->flag & NLASTRIP_FLAG_REVERSE) {
2556 s1 = nes->strip->next;
2557 s2 = nes->strip->prev;
2558 }
2559 else {
2560 s1 = nes->strip->prev;
2561 s2 = nes->strip->next;
2562 }
2563
2564 switch (evaluation_mode) {
2565 case STRIP_EVAL_BLEND: {
2566
2567 /* prepare template for 'evaluation strip'
2568 * - based on the transition strip's evaluation strip data
2569 * - strip_mode is NES_TIME_TRANSITION_* based on which endpoint
2570 * - strip_time is the 'normalized' (i.e. in-strip) time for evaluation,
2571 * which doubles up as an additional weighting factor for the strip influences
2572 * which allows us to appear to be 'interpolating' between the two extremes
2573 */
2574 tmp_nes = *nes;
2575
2576 /* evaluate these strips into a temp-buffer (tmp_channels) */
2577 /* FIXME: modifier evaluation here needs some work... */
2578 /* first strip */
2580 tmp_nes.strip = s1;
2581 tmp_nes.strip_time = s1->strip_time;
2582 nlaeval_snapshot_init(&snapshot1, channels, snapshot);
2584 channels,
2585 &tmp_modifiers,
2586 &tmp_nes,
2587 &snapshot1,
2588 anim_eval_context,
2589 flush_to_original);
2590
2591 /* second strip */
2593 tmp_nes.strip = s2;
2594 tmp_nes.strip_time = s2->strip_time;
2595 nlaeval_snapshot_init(&snapshot2, channels, snapshot);
2597 channels,
2598 &tmp_modifiers,
2599 &tmp_nes,
2600 &snapshot2,
2601 anim_eval_context,
2602 flush_to_original);
2603
2607 nlasnapshot_ensure_channels(channels, &snapshot2);
2611 channels, &snapshot1, &snapshot2, NLASTRIP_MODE_REPLACE, nes->strip_time, snapshot);
2612
2613 nlaeval_snapshot_free_data(&snapshot1);
2614 nlaeval_snapshot_free_data(&snapshot2);
2615
2616 break;
2617 }
2619 /* No support for remapping values through a transition. Mark all channel values affected by
2620 * transition as non-remappable. */
2621 tmp_nes = *nes;
2622
2623 /* Process first strip. */
2624 tmp_nes.strip = s1;
2625 tmp_nes.strip_time = s1->strip_time;
2626 nlaeval_snapshot_init(&snapshot1, channels, snapshot);
2628 ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot1, anim_eval_context);
2629
2630 /* Remove channel values affected by transition from the remap domain. */
2631 for (NlaEvalChannel &nec : channels->channels) {
2632 NlaEvalChannelSnapshot *necs = nlaeval_snapshot_get(&snapshot1, nec.index);
2633 if (necs == nullptr) {
2634 continue;
2635 }
2636 NlaEvalChannelSnapshot *output_necs = nlaeval_snapshot_ensure_channel(snapshot, &nec);
2637 for (int i = 0; i < necs->length; i++) {
2638 if (BLI_BITMAP_TEST_BOOL(necs->blend_domain.ptr, i)) {
2639 BLI_BITMAP_DISABLE(output_necs->remap_domain.ptr, i);
2640 }
2641 }
2642 }
2643
2644 nlaeval_snapshot_free_data(&snapshot1);
2645
2646 /* Process second strip. */
2647 tmp_nes.strip = s2;
2648 tmp_nes.strip_time = s2->strip_time;
2649 nlaeval_snapshot_init(&snapshot2, channels, snapshot);
2651 ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot2, anim_eval_context);
2652
2653 /* Remove channel values affected by transition from the remap domain. */
2654 for (NlaEvalChannel &nec : channels->channels) {
2655 NlaEvalChannelSnapshot *necs = nlaeval_snapshot_get(&snapshot2, nec.index);
2656 if (necs == nullptr) {
2657 continue;
2658 }
2659 NlaEvalChannelSnapshot *output_necs = nlaeval_snapshot_ensure_channel(snapshot, &nec);
2660 for (int i = 0; i < necs->length; i++) {
2661 if (BLI_BITMAP_TEST_BOOL(necs->blend_domain.ptr, i)) {
2662 BLI_BITMAP_DISABLE(output_necs->remap_domain.ptr, i);
2663 }
2664 }
2665 }
2666
2667 nlaeval_snapshot_free_data(&snapshot2);
2668
2669 break;
2670 }
2671 case STRIP_EVAL_NOBLEND: {
2672 BLI_assert_msg(false,
2673 "This case shouldn't occur. "
2674 "Transitions assumed to not reference other transitions.");
2675 break;
2676 }
2677 }
2678
2679 /* unlink this strip's modifiers from the parent's modifiers again */
2681}
2682
2683/* evaluate meta-strip */
2684static void nlastrip_evaluate_meta(const int evaluation_mode,
2685 PointerRNA *ptr,
2686 NlaEvalData *channels,
2687 ListBaseT<FModifier> *modifiers,
2688 NlaEvalStrip *nes,
2689 NlaEvalSnapshot *snapshot,
2690 const AnimationEvalContext *anim_eval_context,
2691 const bool flush_to_original)
2692{
2693 ListBaseT<FModifier> tmp_modifiers = {nullptr, nullptr};
2694 NlaStrip *strip = nes->strip;
2695 NlaEvalStrip *tmp_nes;
2696 float evaltime;
2697
2698 /* meta-strip was calculated normally to have some time to be evaluated at
2699 * and here we 'look inside' the meta strip, treating it as a decorated window to
2700 * its child strips, which get evaluated as if they were some tracks on a strip
2701 * (but with some extra modifiers to apply).
2702 *
2703 * NOTE: keep this in sync with animsys_evaluate_nla()
2704 */
2705
2706 /* join this strip's modifiers to the parent's modifiers (own modifiers first) */
2707 nlaeval_fmodifiers_join_stacks(&tmp_modifiers, &strip->modifiers, modifiers);
2708
2709 /* find the child-strip to evaluate */
2710 evaltime = (nes->strip_time * (strip->end - strip->start)) + strip->start;
2711 AnimationEvalContext child_context = BKE_animsys_eval_context_construct_at(anim_eval_context,
2712 evaltime);
2713 tmp_nes = nlastrips_ctime_get_strip(
2714 nullptr, &strip->strips, -1, &child_context, flush_to_original);
2715
2716 /* Assert currently supported modes. If new mode added, then assertion marks potentially missed
2717 * area.
2718 *
2719 * NOTE: In the future if support is ever added to meta-strips to support nested tracks, then
2720 * STRIP_EVAL_BLEND and STRIP_EVAL_BLEND_GET_INVERTED_LOWER_SNAPSHOT cases are no longer
2721 * equivalent. The output of nlastrips_ctime_get_strip() may return a list of strips. The only
2722 * case difference should be the evaluation order.
2723 */
2724 BLI_assert(ELEM(evaluation_mode,
2728
2729 /* directly evaluate child strip into accumulation buffer...
2730 * - there's no need to use a temporary buffer (as it causes issues [#40082])
2731 */
2732 if (tmp_nes) {
2733 nlastrip_evaluate(evaluation_mode,
2734 ptr,
2735 channels,
2736 &tmp_modifiers,
2737 tmp_nes,
2738 snapshot,
2739 &child_context,
2740 flush_to_original);
2741
2742 /* free temp eval-strip */
2743 MEM_delete(tmp_nes);
2744 }
2745
2746 /* unlink this strip's modifiers from the parent's modifiers again */
2747 nlaeval_fmodifiers_split_stacks(&strip->modifiers, modifiers);
2748}
2749
2750void nlastrip_evaluate(const int evaluation_mode,
2751 PointerRNA *ptr,
2752 NlaEvalData *channels,
2753 ListBaseT<FModifier> *modifiers,
2754 NlaEvalStrip *nes,
2755 NlaEvalSnapshot *snapshot,
2756 const AnimationEvalContext *anim_eval_context,
2757 const bool flush_to_original)
2758{
2759 NlaStrip *strip = nes->strip;
2760
2761 /* To prevent potential infinite recursion problems
2762 * (i.e. transition strip, beside meta strip containing a transition
2763 * several levels deep inside it),
2764 * we tag the current strip as being evaluated, and clear this when we leave.
2765 */
2766 /* TODO: be careful with this flag, since some edit tools may be running and have
2767 * set this while animation playback was running. */
2768 if (strip->flag & NLASTRIP_FLAG_EDIT_TOUCHED) {
2769 return;
2770 }
2772
2773 /* actions to take depend on the type of strip */
2774 switch (strip->type) {
2775 case NLASTRIP_TYPE_CLIP: /* action-clip */
2776 nlastrip_evaluate_actionclip(evaluation_mode, ptr, channels, modifiers, nes, snapshot);
2777 break;
2778 case NLASTRIP_TYPE_TRANSITION: /* transition */
2779 nlastrip_evaluate_transition(evaluation_mode,
2780 ptr,
2781 channels,
2782 modifiers,
2783 nes,
2784 snapshot,
2785 anim_eval_context,
2786 flush_to_original);
2787 break;
2788 case NLASTRIP_TYPE_META: /* meta */
2789 nlastrip_evaluate_meta(evaluation_mode,
2790 ptr,
2791 channels,
2792 modifiers,
2793 nes,
2794 snapshot,
2795 anim_eval_context,
2796 flush_to_original);
2797 break;
2798
2799 default: /* do nothing */
2800 break;
2801 }
2802
2803 /* clear temp recursion safe-check */
2805}
2806
2808 NlaEvalData *channels,
2809 ListBaseT<FModifier> *modifiers,
2810 NlaEvalStrip *nes,
2811 NlaEvalSnapshot *snapshot,
2812 const AnimationEvalContext *anim_eval_context,
2813 const bool flush_to_original)
2814{
2816 ptr,
2817 channels,
2818 modifiers,
2819 nes,
2820 snapshot,
2821 anim_eval_context,
2822 flush_to_original);
2823}
2824
2826 PointerRNA *ptr,
2827 NlaEvalData *channels,
2828 ListBaseT<FModifier> *modifiers,
2829 NlaEvalStrip *nes,
2830 NlaEvalSnapshot *snapshot,
2831 const AnimationEvalContext *anim_eval_context)
2832{
2834 ptr,
2835 channels,
2836 modifiers,
2837 nes,
2838 snapshot,
2839 anim_eval_context,
2840 false);
2841}
2842
2844 NlaEvalData *channels,
2845 ListBaseT<FModifier> *modifiers,
2846 NlaEvalStrip *nes,
2847 NlaEvalSnapshot *snapshot,
2848 const AnimationEvalContext *anim_eval_context)
2849{
2851 STRIP_EVAL_NOBLEND, ptr, channels, modifiers, nes, snapshot, anim_eval_context, false);
2852}
2853
2855 NlaEvalData *channels,
2856 NlaEvalSnapshot *snapshot,
2857 const bool flush_to_original)
2858{
2859 /* sanity checks */
2860 if (channels == nullptr) {
2861 return;
2862 }
2863
2864 /* for each channel with accumulated values, write its value on the property it affects */
2865 for (NlaEvalChannel &nec : channels->channels) {
2875 NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_find_channel(snapshot, &nec);
2876
2877 PathResolvedRNA rna = {nec.key.ptr, nec.key.prop, -1};
2878
2879 for (int i = 0; i < nec_snapshot->length; i++) {
2880 if (BLI_BITMAP_TEST(nec.domain.ptr, i)) {
2881 float value = nec_snapshot->values[i];
2882 if (nec.is_array) {
2883 rna.prop_index = i;
2884 }
2886 if (flush_to_original) {
2888 {
2889 animsys_write_orig_anim_rna(ptr, *rna_path, rna.prop_index, value);
2890 }
2891 }
2892 }
2893 }
2894 }
2895}
2896
2897/* ---------------------- */
2898
2899using ActionAndSlot = std::pair<bAction *, animrig::slot_handle_t>;
2901
2903 NlaEvalData *channels,
2904 bAction *act,
2905 const animrig::slot_handle_t slot_handle,
2906 ActionAndSlotSet &touched_actions)
2907{
2908 const ActionAndSlot action_and_slot(act, slot_handle);
2909 if (!touched_actions.add(action_and_slot)) {
2910 return;
2911 }
2912
2913 for (const FCurve *fcu : animrig::fcurves_for_action_slot(act->wrap(), slot_handle)) {
2914 /* check if this curve should be skipped */
2915 if (!is_fcurve_evaluatable(fcu)) {
2916 continue;
2917 }
2918
2919 NlaEvalChannel *nec = nlaevalchan_verify(ptr, channels, fcu->rna_path().c_str());
2920
2921 if (nec != nullptr) {
2922 /* For quaternion properties, enable all sub-channels. */
2923 if (nec->mix_mode == NEC_MIX_QUATERNION) {
2924 BLI_bitmap_set_all(nec->domain.ptr, true, 4);
2925 continue;
2926 }
2927
2928 int idx = nlaevalchan_validate_index(nec, fcu->array_index);
2929
2930 if (idx >= 0) {
2931 BLI_BITMAP_ENABLE(nec->domain.ptr, idx);
2932 }
2933 }
2934 }
2935}
2936
2938 NlaEvalData *channels,
2939 ListBaseT<NlaStrip> *strips,
2940 ActionAndSlotSet &touched_actions)
2941{
2942 for (NlaStrip &strip : *strips) {
2943 /* Check strip's action. */
2944 if (strip.act) {
2945 nla_eval_domain_action(ptr, channels, strip.act, strip.action_slot_handle, touched_actions);
2946 }
2947
2948 /* Check sub-strips (if meta-strips). */
2949 nla_eval_domain_strips(ptr, channels, &strip.strips, touched_actions);
2950 }
2951}
2952
2958{
2959 ActionAndSlotSet touched_actions;
2960
2961 /* Include domain of Action Track. */
2962 if ((adt->flag & ADT_NLA_EDIT_ON) == 0) {
2963 if (adt->action) {
2964 nla_eval_domain_action(ptr, channels, adt->action, adt->slot_handle, touched_actions);
2965 }
2966 }
2967 else if (adt->tmpact && (adt->flag & ADT_NLA_EVAL_UPPER_TRACKS)) {
2968 nla_eval_domain_action(ptr, channels, adt->tmpact, adt->tmp_slot_handle, touched_actions);
2969 }
2970
2971 /* NLA Data - Animation Data for Strips */
2972 for (NlaTrack &nlt : adt->nla_tracks) {
2973 if (!BKE_nlatrack_is_enabled(*adt, nlt)) {
2974 continue;
2975 }
2976 nla_eval_domain_strips(ptr, channels, &nlt.strips, touched_actions);
2977 }
2978}
2979
2980/* ---------------------- */
2981
2987 const bool keyframing_to_strip,
2988 NlaStrip *r_tweak_strip)
2989
2990{
2991 /* Copy active strip so we can modify how it evaluates without affecting user data. */
2992 memcpy(r_tweak_strip, adt->actstrip, sizeof(NlaStrip));
2993 r_tweak_strip->next = r_tweak_strip->prev = nullptr;
2994
2995 /* If tweaked strip is syncing action length, then evaluate using action length. */
2996 if (r_tweak_strip->flag & NLASTRIP_FLAG_SYNC_LENGTH) {
2998 }
2999
3000 /* Strips with a user-defined time curve don't get properly remapped for editing
3001 * at the moment, so mapping them just for display may be confusing. */
3002 const bool is_inplace_tweak = !(adt->flag & ADT_NLA_EDIT_NOMAP) &&
3004
3005 if (!is_inplace_tweak) {
3006 /* Use Hold due to no proper remapping yet (the note above). */
3007 r_tweak_strip->extendmode = NLASTRIP_EXTEND_HOLD;
3008
3009 /* Disable range. */
3010 r_tweak_strip->flag |= NLASTRIP_FLAG_NO_TIME_MAP;
3011 }
3012
3013 if (keyframing_to_strip) {
3014 /* Since keying cannot happen when there is no NLA influence, this is a workaround to get keys
3015 * onto the strip in tweak mode while keyframing. */
3016 r_tweak_strip->extendmode = NLASTRIP_EXTEND_HOLD;
3017 }
3018}
3019
3022 const bool keyframing_to_strip,
3023 NlaStrip *r_action_strip)
3024{
3025 using namespace blender::animrig;
3026
3027 *r_action_strip = NlaStrip{};
3028
3029 /* Set settings of dummy NLA strip from AnimData settings. */
3030 bAction *action = adt->action;
3031 slot_handle_t slot_handle = adt->slot_handle;
3032
3033 if (adt->flag & ADT_NLA_EDIT_ON) {
3034 action = adt->tmpact;
3035 slot_handle = adt->tmp_slot_handle;
3036 }
3037
3038 r_action_strip->act = action;
3039 r_action_strip->action_slot_handle = slot_handle;
3040
3041 /* Action range is calculated taking F-Modifiers into account
3042 * (which making new strips doesn't do due to the troublesome nature of that). */
3043 const float2 frame_range = action ? action->wrap().get_frame_range_of_keys(true) :
3044 float2{0.0f, 0.0f};
3045 r_action_strip->actstart = frame_range[0];
3046 r_action_strip->actend = frame_range[1];
3047
3048 BKE_nla_clip_length_ensure_nonzero(&r_action_strip->actstart, &r_action_strip->actend);
3049 r_action_strip->start = r_action_strip->actstart;
3050 r_action_strip->end = r_action_strip->actend;
3051
3052 r_action_strip->blendmode = adt->act_blendmode;
3053 r_action_strip->extendmode = adt->act_extendmode;
3054 r_action_strip->influence = adt->act_influence;
3055
3056 /* Must set NLASTRIP_FLAG_USR_INFLUENCE, or else the default setting overrides, and influence
3057 * doesn't work.
3058 */
3060
3061 const bool tweaking = (adt->flag & ADT_NLA_EDIT_ON) != 0;
3062 const bool soloing = (adt->flag & ADT_NLA_SOLO_TRACK) != 0;
3063 const bool eval_upper = !tweaking || (adt->flag & ADT_NLA_EVAL_UPPER_TRACKS) != 0;
3064 const bool actionstrip_evaluated = r_action_strip->act && !soloing && eval_upper;
3065 if (!actionstrip_evaluated) {
3066 r_action_strip->flag |= NLASTRIP_FLAG_MUTED;
3067 }
3068
3070 if (keyframing_to_strip) {
3071 r_action_strip->extendmode = NLASTRIP_EXTEND_HOLD;
3072 }
3073}
3074
3075static bool is_nlatrack_evaluatable(const AnimData *adt, const NlaTrack *nlt)
3076{
3077 /* Skip disabled tracks unless it contains the tweaked strip. */
3078 const bool contains_tweak_strip = (adt->flag & ADT_NLA_EDIT_ON) && adt->act_track &&
3079 (nlt->index == adt->act_track->index);
3080 if ((nlt->flag & NLATRACK_DISABLED) && !contains_tweak_strip) {
3081 return false;
3082 }
3083
3084 return BKE_nlatrack_is_enabled(*adt, *nlt);
3085}
3086
3092 const bool any_strip_evaluated)
3093{
3094 if (adt->action == nullptr) {
3095 return false;
3096 }
3097
3098 if (any_strip_evaluated) {
3099 return false;
3100 }
3101
3103 if ((adt->flag & (ADT_NLA_SOLO_TRACK | ADT_NLA_EDIT_ON)) != 0) {
3104 return false;
3105 }
3106
3108 return true;
3109}
3110
3120{
3121 if (adt == nullptr) {
3122 return nullptr;
3123 }
3124
3125 /* Since the track itself gets disabled, we want the first disabled. */
3126 for (NlaTrack &nlt : adt->nla_tracks) {
3127 if (nlt.flag & NLATRACK_DISABLED) {
3128 return &nlt;
3129 }
3130 }
3131
3132 return nullptr;
3133}
3134
3140 PointerRNA *ptr,
3141 const AnimData *adt,
3142 const AnimationEvalContext *anim_eval_context,
3143 const bool flush_to_original)
3144{
3145 NlaTrack *nlt;
3146 short track_index = 0;
3147 bool has_strips = false;
3148 ListBaseT<NlaEvalStrip> estrips = {nullptr, nullptr};
3149 NlaEvalStrip *nes;
3150
3151 NlaStrip tweak_strip;
3152
3153 NlaTrack *tweaked_track = nlatrack_find_tweaked(adt);
3154
3155 /* Get the stack of strips to evaluate at current time (influence calculated here). */
3156 for (nlt = adt->nla_tracks.first(); nlt; nlt = nlt->next, track_index++) {
3157
3158 if (!is_nlatrack_evaluatable(adt, nlt)) {
3159 continue;
3160 }
3161
3162 if (nlt->strips.first()) {
3163 has_strips = true;
3164 }
3165
3167 if (nlt == tweaked_track) {
3169 animsys_create_tweak_strip(adt, false, &tweak_strip);
3171 &estrips, &tweak_strip, anim_eval_context, flush_to_original);
3172 }
3173 else {
3175 &estrips, &nlt->strips, track_index, anim_eval_context, flush_to_original);
3176 }
3177 if (nes) {
3178 nes->track = nlt;
3179 }
3180 }
3181
3182 if (is_action_track_evaluated_without_nla(adt, has_strips)) {
3183 estrips.free_no_destruct();
3184 return false;
3185 }
3186
3187 NlaStrip action_strip = {nullptr};
3188 animsys_create_action_track_strip(adt, false, &action_strip);
3189 nlastrips_ctime_get_strip_single(&estrips, &action_strip, anim_eval_context, flush_to_original);
3190
3191 /* Per strip, evaluate and accumulate on top of existing channels. */
3192 for (NlaEvalStrip &nes : estrips) {
3194 echannels,
3195 nullptr,
3196 &nes,
3197 &echannels->eval_snapshot,
3198 anim_eval_context,
3199 flush_to_original);
3200 }
3201
3202 /* Free temporary evaluation data that's not used elsewhere. */
3203 estrips.free_no_destruct();
3204 return true;
3205}
3206
3209 const AnimData *adt,
3210 const AnimationEvalContext *anim_eval_context,
3211 NlaKeyframingContext *r_context)
3212{
3213 if (!r_context) {
3214 return;
3215 }
3216
3217 /* Early out. If NLA track is soloing and tweaked action isn't it, then don't allow keyframe
3218 * insertion. */
3219 if (adt->flag & ADT_NLA_SOLO_TRACK) {
3220 if (!(adt->act_track && (adt->act_track->flag & NLATRACK_SOLO))) {
3221 r_context->eval_strip = nullptr;
3222 return;
3223 }
3224 }
3225
3226 NlaTrack *nlt;
3227 short track_index = 0;
3228 bool has_strips = false;
3229
3230 ListBaseT<NlaEvalStrip> *upper_estrips = &r_context->upper_estrips;
3231 ListBaseT<NlaEvalStrip> lower_estrips = {nullptr, nullptr};
3232 NlaEvalStrip *nes;
3233
3234 NlaTrack *tweaked_track = nlatrack_find_tweaked(adt);
3235
3236 /* Get the lower stack of strips to evaluate at current time (influence calculated here). */
3237 for (nlt = adt->nla_tracks.first(); nlt; nlt = nlt->next, track_index++) {
3238
3239 if (!is_nlatrack_evaluatable(adt, nlt)) {
3240 continue;
3241 }
3242
3243 /* Tweaked strip effect should not be stored in any snapshot. */
3244 if (nlt == tweaked_track) {
3245 break;
3246 }
3247
3248 if (nlt->strips.first()) {
3249 has_strips = true;
3250 }
3251
3252 /* Get strip to evaluate for this channel. */
3254 &lower_estrips, &nlt->strips, track_index, anim_eval_context, false);
3255 if (nes) {
3256 nes->track = nlt;
3257 }
3258 }
3259
3260 /* Get the upper stack of strips to evaluate at current time (influence calculated here).
3261 * Var nlt exists only if tweak strip exists. */
3262 if (nlt) {
3263
3264 /* Skip tweaked strip. */
3265 nlt = nlt->next;
3266 track_index++;
3267
3268 for (; nlt; nlt = nlt->next, track_index++) {
3269
3270 if (!is_nlatrack_evaluatable(adt, nlt)) {
3271 continue;
3272 }
3273
3274 if (nlt->strips.first()) {
3275 has_strips = true;
3276 }
3277
3278 /* Get strip to evaluate for this channel. */
3280 upper_estrips, &nlt->strips, track_index, anim_eval_context, false);
3281 }
3282 }
3283
3284 /* NOTE: Although we early out, we can still keyframe to the non-pushed action since the
3285 * keyframe remap function detects (r_context->strip.act == nullptr) and will keyframe without
3286 * remapping. */
3287 if (is_action_track_evaluated_without_nla(adt, has_strips)) {
3288 lower_estrips.free_no_destruct();
3289 return;
3290 }
3291
3292 /* Write r_context->eval_strip. */
3293 if (adt->flag & ADT_NLA_EDIT_ON) {
3294 /* Append action_track_strip to upper estrips. */
3295 NlaStrip *action_strip = &r_context->action_track_strip;
3296 animsys_create_action_track_strip(adt, false, action_strip);
3297 nlastrips_ctime_get_strip_single(upper_estrips, action_strip, anim_eval_context, false);
3298
3299 NlaStrip *tweak_strip = &r_context->strip;
3300 animsys_create_tweak_strip(adt, true, tweak_strip);
3302 nullptr, tweak_strip, anim_eval_context, false);
3303 }
3304 else {
3305
3306 NlaStrip *action_strip = &r_context->strip;
3307 animsys_create_action_track_strip(adt, true, action_strip);
3309 nullptr, action_strip, anim_eval_context, false);
3310 }
3311
3312 /* If nullptr, then keyframing will fail. No need to do any more processing. */
3313 if (!r_context->eval_strip) {
3314 lower_estrips.free_no_destruct();
3315 return;
3316 }
3317
3318 /* If tweak strip is full REPLACE, then lower strips not needed. */
3319 if (r_context->strip.blendmode == NLASTRIP_MODE_REPLACE &&
3320 IS_EQF(r_context->strip.influence, 1.0f))
3321 {
3322 lower_estrips.free_no_destruct();
3323 return;
3324 }
3325
3326 /* For each strip, evaluate then accumulate on top of existing channels. */
3327 for (NlaEvalStrip &nes : lower_estrips) {
3329 &r_context->lower_eval_data,
3330 nullptr,
3331 &nes,
3332 &r_context->lower_eval_data.eval_snapshot,
3333 anim_eval_context,
3334 false);
3335 }
3336
3337 /* Free temporary evaluation data that's not used elsewhere. */
3338 lower_estrips.free_no_destruct();
3339}
3340
3349 AnimData *adt,
3350 const AnimationEvalContext *anim_eval_context,
3351 const bool flush_to_original)
3352{
3353 NlaEvalData echannels;
3354
3355 nlaeval_init(&echannels);
3356
3357 /* evaluate the NLA stack, obtaining a set of values to flush */
3358 const bool did_evaluate_something = animsys_evaluate_nla_for_flush(
3359 &echannels, ptr, adt, anim_eval_context, flush_to_original);
3360 if (did_evaluate_something) {
3361 /* reset any channels touched by currently inactive actions to default value */
3362 animsys_evaluate_nla_domain(ptr, &echannels, adt);
3363
3364 /* flush effects of accumulating channels in NLA to the actual data they affect */
3365 nladata_flush_channels(ptr, &echannels, &echannels.eval_snapshot, flush_to_original);
3366 }
3367
3368 /* free temp data */
3369 nlaeval_free(&echannels);
3370
3371 return did_evaluate_something;
3372}
3373
3374/* ---------------------- */
3375
3377{
3378 for (int i = 0; i < snapshot->size; i++) {
3379 NlaEvalChannelSnapshot *necs = nlaeval_snapshot_get(snapshot, i);
3380 if (necs == nullptr) {
3381 continue;
3382 }
3383
3384 BLI_bitmap_set_all(necs->blend_domain.ptr, true, necs->length);
3385 }
3386}
3387
3389{
3390 for (NlaEvalChannel &nec : eval_data->channels) {
3391 nlaeval_snapshot_ensure_channel(snapshot, &nec);
3392 }
3393}
3394
3396 NlaEvalSnapshot *lower_snapshot,
3397 NlaEvalSnapshot *upper_snapshot,
3398 const short upper_blendmode,
3399 const float upper_influence,
3400 NlaEvalSnapshot *r_blended_snapshot)
3401{
3402 nlaeval_snapshot_ensure_size(r_blended_snapshot, eval_data->num_channels);
3403
3404 for (NlaEvalChannel &nec : eval_data->channels) {
3405 NlaEvalChannelSnapshot *upper_necs = nlaeval_snapshot_get(upper_snapshot, nec.index);
3406 NlaEvalChannelSnapshot *lower_necs = nlaeval_snapshot_get(lower_snapshot, nec.index);
3407 if (upper_necs == nullptr && lower_necs == nullptr) {
3408 continue;
3409 }
3410
3412 if (lower_necs == nullptr) {
3413 lower_necs = nlaeval_snapshot_find_channel(lower_snapshot->base, &nec);
3414 }
3415
3416 NlaEvalChannelSnapshot *result_necs = nlaeval_snapshot_ensure_channel(r_blended_snapshot,
3417 &nec);
3419 lower_necs, upper_necs, upper_blendmode, upper_influence, result_necs);
3420 }
3421}
3422
3424 NlaEvalSnapshot *lower_snapshot,
3425 NlaEvalSnapshot *blended_snapshot,
3426 const short upper_blendmode,
3427 const float upper_influence,
3428 NlaEvalSnapshot *r_upper_snapshot)
3429{
3430 nlaeval_snapshot_ensure_size(r_upper_snapshot, eval_data->num_channels);
3431
3432 for (NlaEvalChannel &nec : eval_data->channels) {
3433 NlaEvalChannelSnapshot *blended_necs = nlaeval_snapshot_get(blended_snapshot, nec.index);
3434 if (blended_necs == nullptr) {
3435 /* We assume the caller only wants a subset of channels to be inverted,
3436 * those that exist within `blended_snapshot`. */
3437 continue;
3438 }
3439
3440 NlaEvalChannelSnapshot *lower_necs = nlaeval_snapshot_get(lower_snapshot, nec.index);
3441 if (lower_necs == nullptr) {
3442 lower_necs = nlaeval_snapshot_find_channel(lower_snapshot->base, &nec);
3443 }
3444
3445 NlaEvalChannelSnapshot *result_necs = nlaeval_snapshot_ensure_channel(r_upper_snapshot, &nec);
3447 lower_necs, blended_necs, upper_blendmode, upper_influence, result_necs);
3448 }
3449}
3450
3452 NlaEvalSnapshot *blended_snapshot,
3453 NlaEvalSnapshot *upper_snapshot,
3454 const short upper_blendmode,
3455 const float upper_influence,
3456 NlaEvalSnapshot *r_lower_snapshot)
3457{
3458 nlaeval_snapshot_ensure_size(r_lower_snapshot, eval_data->num_channels);
3459
3460 for (NlaEvalChannel &nec : eval_data->channels) {
3461 NlaEvalChannelSnapshot *blended_necs = nlaeval_snapshot_get(blended_snapshot, nec.index);
3462 if (blended_necs == nullptr) {
3463 /* We assume the caller only wants a subset of channels to be inverted, those that exist
3464 * within \a blended_snapshot. */
3465 continue;
3466 }
3467
3468 NlaEvalChannelSnapshot *upper_necs = nlaeval_snapshot_get(upper_snapshot, nec.index);
3469 NlaEvalChannelSnapshot *result_necs = nlaeval_snapshot_ensure_channel(r_lower_snapshot, &nec);
3470
3472 blended_necs, upper_necs, upper_blendmode, upper_influence, result_necs);
3473 }
3474}
3475
3476/* ---------------------- */
3477
3479 ListBaseT<NlaKeyframingContext> *cache,
3480 PointerRNA *ptr,
3481 AnimData *adt,
3482 const AnimationEvalContext *anim_eval_context)
3483{
3484 /* The PointerRNA needs to point to an ID because animsys_evaluate_nla_for_keyframing uses
3485 * F-Curve paths to resolve properties. Since F-Curve paths are always relative to the ID this
3486 * would fail if the PointerRNA was e.g. a bone. */
3488
3489 /* No remapping needed if NLA is off or no action. */
3490 if ((adt == nullptr) || (adt->action == nullptr) || (adt->nla_tracks.first() == nullptr) ||
3491 (adt->flag & ADT_NLA_EVAL_OFF))
3492 {
3493 return nullptr;
3494 }
3495
3496 /* No remapping if editing an ordinary Replace action with full influence and upper tracks not
3497 * evaluated. */
3498 if (!(adt->flag & ADT_NLA_EDIT_ON) &&
3499 (adt->act_blendmode == NLASTRIP_MODE_REPLACE && adt->act_influence == 1.0f) &&
3500 (adt->flag & ADT_NLA_EVAL_UPPER_TRACKS) == 0)
3501 {
3502 return nullptr;
3503 }
3504
3505 /* Try to find a cached context. */
3506 NlaKeyframingContext *ctx = static_cast<NlaKeyframingContext *>(
3507 BLI_findptr(cache, adt, offsetof(NlaKeyframingContext, adt)));
3508
3509 if (ctx == nullptr) {
3510 /* Allocate and evaluate a new context. */
3511 ctx = MEM_new<NlaKeyframingContext>("NlaKeyframingContext");
3512 ctx->adt = adt;
3513
3515 animsys_evaluate_nla_for_keyframing(ptr, adt, anim_eval_context, ctx);
3516
3517 BLI_assert(ELEM(ctx->strip.act, nullptr, adt->action));
3518 BLI_addtail(cache, ctx);
3519 }
3520
3521 return ctx;
3522}
3523
3525 PointerRNA *prop_ptr,
3526 PropertyRNA *prop,
3527 const MutableSpan<float> values,
3528 int index,
3529 const AnimationEvalContext *anim_eval_context,
3530 bool *r_force_all,
3531 BitVector<> &r_values_mask)
3532{
3533 const int count = values.size();
3534 r_values_mask.fill(false);
3535
3536 if (r_force_all != nullptr) {
3537 *r_force_all = false;
3538 }
3539
3540 BitVector remap_domain(count, false);
3541 for (int i = 0; i < count; i++) {
3542 if (!ELEM(index, i, -1)) {
3543 continue;
3544 }
3545
3546 remap_domain[i].set();
3547 }
3548
3549 /* No context means no correction. */
3550 if (context == nullptr || context->strip.act == nullptr) {
3551 r_values_mask = remap_domain;
3552 return;
3553 }
3554
3555 /* If the strip is not evaluated, it is the same as zero influence. */
3556 if (context->eval_strip == nullptr) {
3557 return;
3558 }
3559
3560 /* Full influence Replace strips also require no correction if there are no upper tracks
3561 * evaluating. */
3562 int blend_mode = context->strip.blendmode;
3563 float influence = context->strip.influence;
3564
3565 if (blend_mode == NLASTRIP_MODE_REPLACE && influence == 1.0f &&
3566 context->upper_estrips.is_empty())
3567 {
3568 r_values_mask = remap_domain;
3569 return;
3570 }
3571
3572 /* Zero influence is division by zero. */
3573 if (influence <= 0.0f) {
3574 return;
3575 }
3576
3578 NlaEvalData *eval_data = &context->lower_eval_data;
3579 NlaEvalSnapshot blended_snapshot;
3580 nlaeval_snapshot_init(&blended_snapshot, eval_data, nullptr);
3581
3582 NlaEvalChannelKey key{};
3583 key.ptr = *prop_ptr;
3584 key.prop = prop;
3585
3586 NlaEvalChannel *nec = nlaevalchan_verify_key(eval_data, nullptr, &key);
3587 BLI_assert(nec);
3588 if (nec->base_snapshot.length != count) {
3589 BLI_assert_msg(0, "invalid value count");
3590 nlaeval_snapshot_free_data(&blended_snapshot);
3591 return;
3592 }
3593
3594 NlaEvalChannelSnapshot *blended_necs = nlaeval_snapshot_ensure_channel(&blended_snapshot, nec);
3595 std::copy(values.begin(), values.end(), blended_necs->values);
3596
3597 /* Force all channels to be remapped for quaternions in a Combine or Replace strip, otherwise it
3598 * will always fail. See nlaevalchan_combine_quaternion_handle_undefined_blend_values().
3599 */
3600 const bool can_force_all = r_force_all != nullptr;
3601 if (blended_necs->channel->mix_mode == NEC_MIX_QUATERNION &&
3602 ELEM(blend_mode, NLASTRIP_MODE_COMBINE, NLASTRIP_MODE_REPLACE) && can_force_all)
3603 {
3604
3605 *r_force_all = true;
3606 index = -1;
3607 remap_domain.fill(true);
3608 }
3609
3610 for (const int i : remap_domain.index_range()) {
3611 BLI_BITMAP_SET(blended_necs->remap_domain.ptr, i, remap_domain[i]);
3612 }
3613
3614 /* Need to send id_ptr instead of prop_ptr so fcurve RNA paths resolve properly. */
3615 PointerRNA id_ptr = RNA_id_pointer_create(prop_ptr->owner_id);
3616
3617 /* Per iteration, remove effect of upper strip which gives output of nla stack below it. */
3618 for (NlaEvalStrip &nes : context->upper_estrips.items_reversed()) {
3619 /* This will disable blended_necs->remap_domain bits if an upper strip is not invertible
3620 * (full replace, multiply zero, or transition). Then there is no remap solution. */
3622 &id_ptr, eval_data, nullptr, &nes, &blended_snapshot, anim_eval_context);
3623 }
3624
3627 &context->lower_eval_data.eval_snapshot,
3628 &blended_snapshot,
3629 blend_mode,
3630 influence,
3631 &blended_snapshot);
3632
3633 /* Write results into \a values for successfully remapped values. */
3634 for (int i = 0; i < count; i++) {
3635 if (!BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, i)) {
3636 continue;
3637 }
3638 values[i] = blended_necs->values[i];
3639 }
3640
3641 for (int i = 0; i < blended_necs->length; i++) {
3642 r_values_mask[i].set(BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, i));
3643 }
3644
3645 nlaeval_snapshot_free_data(&blended_snapshot);
3646}
3647
3648void BKE_animsys_free_nla_keyframing_context_cache(ListBaseT<NlaKeyframingContext> *cache)
3649{
3650 for (NlaKeyframingContext &ctx : *cache) {
3651 MEM_SAFE_DELETE(ctx.eval_strip);
3652 ctx.upper_estrips.free_no_destruct();
3653 nlaeval_free(&ctx.lower_eval_data);
3654 }
3655
3656 cache->free_no_destruct();
3657}
3658
3659/* ***************************************** */
3660/* Overrides System - Public API */
3661
3662/* Evaluate Overrides */
3664{
3665 /* for each override, simply execute... */
3666 for (AnimOverride &aor : adt->overrides) {
3667 PathResolvedRNA anim_rna;
3668 const std::optional<ParsedRNAPath<>> rna_path = ParsedRNAPath<>::from_string(aor.rna_path);
3669 if (!rna_path) {
3670 continue;
3671 }
3672 if (BKE_animsys_rna_path_resolve(ptr, *rna_path, aor.array_index, &anim_rna)) {
3673 BKE_animsys_write_to_rna_path(&anim_rna, aor.value);
3674 }
3675 }
3676}
3677
3678/* ***************************************** */
3679/* Evaluation System - Public API */
3680
3681/* Overview of how this system works:
3682 * 1) Depsgraph sorts data as necessary, so that data is in an order that means
3683 * that all dependencies are resolved before dependents.
3684 * 2) All normal animation is evaluated, so that drivers have some basis values to
3685 * work with
3686 * a. NLA stacks are done first, as the Active Actions act as 'tweaking' tracks
3687 * which modify the effects of the NLA-stacks
3688 * b. Active Action is evaluated as per normal, on top of the results of the NLA tracks
3689 *
3690 * --------------< often in a separate phase... >------------------
3691 *
3692 * 3) Drivers/expressions are evaluated on top of this, in an order where dependencies are
3693 * resolved nicely.
3694 * NOTE: it may be necessary to have some tools to handle the cases where some higher-level
3695 * drivers are added and cause some problematic dependencies that
3696 * didn't exist in the local levels...
3697 *
3698 * --------------< always executed >------------------
3699 *
3700 * Maintenance of editability of settings (XXX):
3701 * - In order to ensure that settings that are animated can still be manipulated in the UI without
3702 * requiring that keyframes are added to prevent these values from being overwritten,
3703 * we use 'overrides'.
3704 *
3705 * Unresolved things:
3706 * - Handling of multi-user settings (i.e. time-offset, group-instancing) -> big cache grids
3707 * or nodal system? but stored where?
3708 * - Multiple-block dependencies
3709 * (i.e. drivers for settings are in both local and higher levels) -> split into separate lists?
3710 *
3711 * Current Status:
3712 * - Currently (as of September 2009), overrides we haven't needed to (fully) implement overrides.
3713 * However, the code for this is relatively harmless, so is left in the code for now.
3714 */
3715
3717 AnimData *adt,
3718 const AnimationEvalContext *anim_eval_context,
3719 eAnimData_Recalc recalc,
3720 const bool flush_to_original)
3721{
3722
3723 /* sanity checks */
3724 if (ELEM(nullptr, id, adt)) {
3725 return;
3726 }
3727
3728 /* get pointer to ID-block for RNA to use */
3729 PointerRNA id_ptr = RNA_id_pointer_create(id);
3730
3731 /* recalculate keyframe data:
3732 * - NLA before Active Action, as Active Action behaves as 'tweaking track'
3733 * that overrides 'rough' work in NLA
3734 */
3735 /* TODO: need to double check that this all works correctly */
3736 if (recalc & ADT_RECALC_ANIM) {
3737 /* evaluate NLA data */
3738 bool did_nla_evaluate_anything = false;
3739 if ((adt->nla_tracks.first()) && !(adt->flag & ADT_NLA_EVAL_OFF)) {
3740 /* evaluate NLA-stack
3741 * - active action is evaluated as part of the NLA stack as the last item
3742 */
3743 did_nla_evaluate_anything = animsys_calculate_nla(
3744 &id_ptr, adt, anim_eval_context, flush_to_original);
3745 }
3746
3747 if (!did_nla_evaluate_anything && adt->action) {
3748 animrig::Action &action = adt->action->wrap();
3750 id_ptr, action, adt->slot_handle, *anim_eval_context, flush_to_original);
3751 }
3752 }
3753
3754 /* recalculate drivers
3755 * - Drivers need to be evaluated afterwards, as they can either override
3756 * or be layered on top of existing animation data.
3757 * - Drivers should be in the appropriate order to be evaluated without problems...
3758 */
3759 if (recalc & ADT_RECALC_DRIVERS) {
3760 animsys_evaluate_drivers(&id_ptr, adt, anim_eval_context);
3761 }
3762
3763 /* always execute 'overrides'
3764 * - Overrides allow editing, by overwriting the value(s) set from animation-data, with the
3765 * value last set by the user (and not keyframed yet).
3766 * - Overrides are cleared upon frame change and/or keyframing
3767 * - It is best that we execute this every time, so that no errors are likely to occur.
3768 */
3769 animsys_evaluate_overrides(&id_ptr, adt);
3770}
3771
3772/* ***************************************** */
3773
3774/* ************** */
3775/* Evaluation API */
3776
3777void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id)
3778{
3779 float ctime = DEG_get_ctime(depsgraph);
3780 AnimData *adt = BKE_animdata_from_id(id);
3781 /* XXX: this is only needed for flushing RNA updates,
3782 * which should get handled as part of the dependency graph instead. */
3783 DEG_debug_print_eval_time(depsgraph, __func__, id->name, id, ctime);
3784 const bool flush_to_original = DEG_is_active(depsgraph);
3785
3786 const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
3787 ctime);
3788 BKE_animsys_evaluate_animdata(id, adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
3789}
3790
3792{
3793 AnimData *adt = BKE_animdata_from_id(id);
3794
3795 /* Runtime driver map to avoid O(n^2) lookups in BKE_animsys_eval_driver.
3796 * Ideally the depsgraph could pass a pointer to the evaluated driver directly,
3797 * but this is difficult in the current design. */
3798 if (adt && adt->drivers.first()) {
3799 BLI_assert(!adt->driver_array);
3800
3801 int num_drivers = adt->drivers.count();
3802 adt->driver_array = MEM_new_array_uninitialized<FCurve *>(size_t(num_drivers),
3803 "adt->driver_array");
3804
3805 int driver_index = 0;
3806 for (FCurve &fcu : adt->drivers) {
3807 adt->driver_array[driver_index++] = &fcu;
3808 }
3809 }
3810}
3811
3812void BKE_animsys_eval_driver_unshare(Depsgraph *depsgraph, ID *id_eval)
3813{
3814 BLI_assert(DEG_is_evaluated(id_eval));
3815
3816 AnimData *adt = BKE_animdata_from_id(id_eval);
3817 PointerRNA id_ptr = RNA_id_pointer_create(id_eval);
3818 const bool is_active_depsgraph = DEG_is_active(depsgraph);
3819
3820 for (FCurve &fcu : adt->drivers) {
3821 /* Resolve the driver RNA path. */
3822 PathResolvedRNA anim_rna;
3823 const ParsedRNAPathRef rna_path = fcu.rna_path_parsed();
3824 if (!BKE_animsys_rna_path_resolve(&id_ptr, rna_path, fcu.array_index, &anim_rna)) {
3825 continue;
3826 }
3827
3828 /* Write the current value back to RNA. */
3829 float curval;
3830 if (!BKE_animsys_read_from_rna_path(&anim_rna, &curval)) {
3831 continue;
3832 }
3833 if (!BKE_animsys_write_to_rna_path(&anim_rna, curval, /*force_write=*/true)) {
3834 continue;
3835 }
3836
3837 if (is_active_depsgraph) {
3838 /* Also un-share the original data, as the driver evaluation will write here too. */
3839 animsys_write_orig_anim_rna(&id_ptr, rna_path, fcu.array_index, curval);
3840 }
3841 }
3842}
3843
3844void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, int driver_index, FCurve *fcu_orig)
3845{
3846 BLI_assert(fcu_orig != nullptr);
3847
3848 /* TODO(sergey): De-duplicate with BKE animsys. */
3849 bool ok = false;
3850
3851 /* Lookup driver, accelerated with driver array map. */
3852 const AnimData *adt = BKE_animdata_from_id(id);
3853 FCurve *fcu;
3854
3855 if (adt->driver_array) {
3856 fcu = adt->driver_array[driver_index];
3857 }
3858 else {
3859 fcu = static_cast<FCurve *>(BLI_findlink(&adt->drivers, driver_index));
3860 }
3861
3862 if (!fcu) {
3863 /* Trying to evaluate a driver that does no longer exist. Potentially missing a call to
3864 * DEG_relations_tag_update. */
3866 return;
3867 }
3868
3870 depsgraph, __func__, id->name, id, "fcu", fcu->rna_path().c_str(), fcu, fcu->array_index);
3871
3872 PointerRNA id_ptr = RNA_id_pointer_create(id);
3873
3874 /* check if this driver's curve should be skipped */
3875 if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) {
3876 /* check if driver itself is tagged for recalculation */
3877 /* XXX driver recalc flag is not set yet by depsgraph! */
3878 ChannelDriver *driver_orig = fcu_orig->driver;
3879 if ((driver_orig) && !(driver_orig->flag & DRIVER_FLAG_INVALID)) {
3880 /* evaluate this using values set already in other places
3881 * NOTE: for 'layering' option later on, we should check if we should remove old value before
3882 * adding new to only be done when drivers only changed */
3883 // printf("\told val = %f\n", fcu->curval);
3884
3885 PathResolvedRNA anim_rna;
3886 const ParsedRNAPathRef rna_path = fcu->rna_path_parsed();
3887 if (BKE_animsys_rna_path_resolve(&id_ptr, rna_path, fcu->array_index, &anim_rna)) {
3888 /* Evaluate driver, and write results to copy-on-eval-domain destination */
3889 const float ctime = DEG_get_ctime(depsgraph);
3891 depsgraph, ctime);
3892 const float curval = calculate_fcurve(&anim_rna, fcu, &anim_eval_context);
3893 ok = BKE_animsys_write_to_rna_path(&anim_rna, curval);
3894
3895 /* Flush results & status codes to original data for UI (#59984) */
3896 if (ok && DEG_is_active(depsgraph)) {
3897 animsys_write_orig_anim_rna(&id_ptr, rna_path, fcu->array_index, curval);
3898
3899 /* curval is displayed in the UI, and flag contains error-status codes */
3900 fcu_orig->runtime->curval = fcu->runtime->curval;
3901 driver_orig->curval = fcu->driver->curval;
3902 driver_orig->flag = fcu->driver->flag;
3903
3904 DriverVar *dvar_orig = driver_orig->variables.first();
3905 DriverVar *dvar = fcu->driver->variables.first();
3906 for (; dvar_orig && dvar; dvar_orig = dvar_orig->next, dvar = dvar->next) {
3907 DriverTarget *dtar_orig = &dvar_orig->targets[0];
3908 DriverTarget *dtar = &dvar->targets[0];
3909 for (int i = 0; i < MAX_DRIVER_TARGETS; i++, dtar_orig++, dtar++) {
3910 dtar_orig->flag = dtar->flag;
3911 }
3912
3913 dvar_orig->curval = dvar->curval;
3914 dvar_orig->flag = dvar->flag;
3915 }
3916 }
3917 }
3918
3919 /* set error-flag if evaluation failed */
3920 if (ok == 0) {
3922 "Invalid driver on %s '%s' - %s[%d]",
3923 BKE_idtype_idcode_to_name(id->id_type()),
3924 id->name + 2,
3925 fcu->rna_path().c_str(),
3926 fcu->array_index);
3927 driver_orig->flag |= DRIVER_FLAG_INVALID;
3928 }
3929 }
3930 }
3931}
3932
3933void BKE_time_markers_blend_write(BlendWriter *writer, ListBaseT<TimeMarker> &markers)
3934{
3935 for (TimeMarker &marker : markers) {
3936 writer->write_struct(&marker);
3937
3938 if (marker.prop != nullptr) {
3939 IDP_BlendWrite(writer, marker.prop);
3940 }
3941 }
3942}
3943
3944void BKE_time_markers_blend_read(BlendDataReader *reader, ListBaseT<TimeMarker> &markers)
3945{
3946 BLO_read_struct_list(reader, TimeMarker, &markers);
3947 for (TimeMarker &marker : markers) {
3948 BLO_read_struct(reader, IDProperty, &marker.prop);
3949 IDP_BlendDataRead(reader, &marker.prop);
3950 }
3951}
3952
3953TimeMarker *BKE_copy_time_marker(const TimeMarker &marker_src, const int flag)
3954{
3955 TimeMarker *marker_dst = MEM_dupalloc(&marker_src);
3956 if (marker_dst->prop != nullptr) {
3957 marker_dst->prop = IDP_CopyProperty_ex(marker_dst->prop, flag);
3958 }
3959 return marker_dst;
3960}
3961
3962void BKE_copy_time_markers(ListBaseT<TimeMarker> &markers_dst,
3963 const ListBaseT<TimeMarker> &markers_src,
3964 const int flag)
3965{
3966 BLI_duplicatelist(&markers_dst, &markers_src);
3967 for (TimeMarker &marker : markers_dst) {
3968 if (marker.prop != nullptr) {
3969 marker.prop = IDP_CopyProperty_ex(marker.prop, flag);
3970 }
3971 }
3972}
3973
3974void BKE_free_time_marker(TimeMarker &marker, const bool do_id_user)
3975{
3976 if (marker.prop != nullptr) {
3977 IDP_FreeProperty_ex(marker.prop, do_id_user);
3978 }
3979 MEM_delete(&marker);
3980}
3981
3982void BKE_free_time_markers(ListBaseT<TimeMarker> &markers, const bool do_id_user)
3983{
3984 for (TimeMarker &marker : markers.items_mutable()) {
3985 BKE_free_time_marker(marker, do_id_user);
3986 }
3987 markers.clear_no_delete();
3988}
3989
3990} // namespace blender
Functions and classes to work with Actions.
Layered Action evaluation.
Blender kernel action and pose functionality.
#define IDP_BlendDataRead(reader, prop)
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
General operations, lookup, etc. for materials.
#define ATTR_FALLTHROUGH
#define BLI_BITMAP_NEW(_num, _alloc_string)
Definition BLI_bitmap.hh:39
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition BLI_bitmap.hh:63
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition BLI_bitmap.hh:80
#define BLI_BITMAP_DISABLE(_bitmap, _index)
Definition BLI_bitmap.hh:87
#define BLI_BITMAP_SIZE(_num)
Definition BLI_bitmap.hh:34
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
Definition BLI_bitmap.hh:73
#define BLI_BITMAP_SET(_bitmap, _index, _set)
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define MAX_DRIVER_TARGETS
Read Blender memory allocation and freeing.
#define ANIMSYS_FLOAT_AS_BOOL(value)
Definition anim_sys.cc:398
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define IS_EQF(a, b)
#define BLI_assert_msg(a, msg)
#define IN_RANGE_INCL(a, b, c)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr T * end() const
Definition BLI_span.hh:554
constexpr T * begin() const
Definition BLI_span.hh:550
static std::optional< ParsedRNAPath > from_string(StringRefNull path)
Definition rna_path.cc:194
bool add(const Key &key)
Definition BLI_set.hh:248
void fill(const bool value)
IndexRange index_range() const
#define powf(x, y)
#define offsetof(t, d)
#define storage(slot, qualifiers)
float length(VecOp< float, D >) RET
ccl_device_inline float2 fmod(const float2 a, const float b)
void evaluate_and_apply_action(PointerRNA &animated_id_ptr, Action &action, slot_handle_t slot_handle, const AnimationEvalContext &anim_eval_context, bool flush_to_original)
Definition evaluation.cc:83
decltype(blender::ActionSlot::handle) slot_handle_t
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
std::string to_string(const Span< Item > items)
Definition rna_path.cc:246
BMesh Iterators.
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode)
static void nlaevalchan_blend_value_get_inverted_lower_evalchan(NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_necs, const int upper_blendmode, const float upper_influence, NlaEvalChannelSnapshot *r_lower_necs)
Definition anim_sys.cc:2165
void * BLI_findptr(const ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:710
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
static bool nlaevalchan_validate_index_ex(const NlaEvalChannel *nec, const int array_index)
Definition anim_sys.cc:1151
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:326
static void nlaeval_init(NlaEvalData *nlaeval)
Definition anim_sys.cc:1112
void BKE_copy_time_markers(ListBaseT< TimeMarker > &markers_dst, const ListBaseT< TimeMarker > &markers_src, int flag)
Definition anim_sys.cc:3962
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1398
void BKE_animsys_eval_driver_unshare(Depsgraph *depsgraph, ID *id)
Definition anim_sys.cc:3812
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
char * STRNCPY(char(&dst)[N], const char *src)
@ NEC_MIX_MULTIPLY
@ NEC_MIX_AXIS_ANGLE
@ NEC_MIX_QUATERNION
@ DRIVER_FLAG_INVALID
static void animsys_evaluate_nla_domain(PointerRNA *ptr, NlaEvalData *channels, AnimData *adt)
Definition anim_sys.cc:2957
@ ADT_RECALC_DRIVERS
@ ADT_RECALC_ANIM
void BKE_time_markers_blend_read(BlendDataReader *reader, ListBaseT< TimeMarker > &markers)
Definition anim_sys.cc:3944
static void nlaevalchan_blendOrcombine(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *upper_necs, const int upper_blendmode, const float upper_influence, NlaEvalChannelSnapshot *r_blended_necs)
Definition anim_sys.cc:1969
static bool nla_blend_get_inverted_lower_value(const int blendmode, const float strip_value, const float blended_value, const float influence, float *r_lower_value)
Definition anim_sys.cc:1361
TimeMarker * BKE_copy_time_marker(const TimeMarker &marker_src, int flag)
Definition anim_sys.cc:3953
static void nlaeval_fmodifiers_join_stacks(ListBaseT< FModifier > *result, ListBaseT< FModifier > *list1, ListBaseT< FModifier > *list2)
Definition anim_sys.cc:2341
void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context, PointerRNA *prop_ptr, PropertyRNA *prop, const MutableSpan< float > values, int index, const AnimationEvalContext *anim_eval_context, bool *r_force_all, BitVector<> &r_values_mask)
Definition anim_sys.cc:3524
static void animsys_evaluate_nla_for_keyframing(PointerRNA *ptr, const AnimData *adt, const AnimationEvalContext *anim_eval_context, NlaKeyframingContext *r_context)
Definition anim_sys.cc:3208
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
static void nlaevalchan_assert_blendOrcombine_compatible(const NlaEvalChannelSnapshot *lower_necs, const NlaEvalChannelSnapshot *upper_necs, const NlaEvalChannelSnapshot *blended_necs)
Definition anim_sys.cc:1772
static NlaEvalChannelSnapshot * nlaeval_snapshot_ensure_channel(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec)
Definition anim_sys.cc:1061
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void nlaeval_fmodifiers_split_stacks(ListBaseT< FModifier > *list1, ListBaseT< FModifier > *list2)
Definition anim_sys.cc:2376
void nladata_flush_channels(PointerRNA *ptr, NlaEvalData *channels, NlaEvalSnapshot *snapshot, const bool flush_to_original)
Definition anim_sys.cc:2854
float calculate_fcurve(PathResolvedRNA *anim_rna, FCurve *fcu, const AnimationEvalContext *anim_eval_context)
AnimationEvalContext BKE_animsys_eval_context_construct_at(const AnimationEvalContext *anim_eval_context, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:610
void BKE_animsys_free_nla_keyframing_context_cache(ListBaseT< NlaKeyframingContext > *cache)
Definition anim_sys.cc:3648
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
void BKE_keyingsets_copy(ListBaseT< KeyingSet > *newlist, const ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:249
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.cc:3395
static void nlaevalchan_blendOrCombine_get_inverted_lower_evalchan(NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_necs, const int upper_blendmode, const float upper_influence, NlaEvalChannelSnapshot *r_lower_necs)
Definition anim_sys.cc:2294
PointerRNA RNA_id_pointer_create(ID *id)
static void nlavalidmask_init(NlaValidMask *mask, int bits)
Definition anim_sys.cc:947
static void nlavalidmask_free(NlaValidMask *mask)
Definition anim_sys.cc:958
@ NLASTRIP_FLAG_USR_INFLUENCE
@ NLASTRIP_FLAG_REVERSE
@ NLASTRIP_FLAG_USR_TIME
@ NLASTRIP_FLAG_NO_TIME_MAP
@ NLASTRIP_FLAG_USR_TIME_CYCLIC
@ NLASTRIP_FLAG_EDIT_TOUCHED
@ NLASTRIP_FLAG_MUTED
@ NLASTRIP_FLAG_SYNC_LENGTH
static float nlastrip_get_influence(NlaStrip *strip, float cframe)
Definition anim_sys.cc:712
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
void nlasnapshot_blend_strip(PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:2807
void animsys_evaluate_action(PointerRNA *ptr, bAction *act, int32_t action_slot_handle, const AnimationEvalContext *anim_eval_context, bool flush_to_original)
Definition anim_sys.cc:686
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
static void animsys_evaluate_drivers(PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context)
Definition anim_sys.cc:617
static void nlaeval_snapshot_ensure_size(NlaEvalSnapshot *snapshot, int size)
Definition anim_sys.cc:1023
KeyingSet * BKE_keyingset_add(ListBaseT< KeyingSet > *list, const char idname[], const char name[], eKS_Settings flag, eInsertKeyFlags keyingflag)
Definition anim_sys.cc:137
uint evaluate_fmodifiers_storage_size_per_modifier(const ListBaseT< FModifier > *modifiers)
static void nlaevalchan_copy_values(NlaEvalChannelSnapshot *dst, const NlaEvalChannelSnapshot *src)
Definition anim_sys.cc:1813
@ NLASTRIP_EXTEND_NOTHING
@ NLASTRIP_EXTEND_HOLD_FORWARD
@ NLASTRIP_EXTEND_HOLD
void nlasnapshot_blend_get_inverted_upper_snapshot(NlaEvalData *eval_data, NlaEvalSnapshot *lower_snapshot, NlaEvalSnapshot *blended_snapshot, const short upper_blendmode, const float upper_influence, NlaEvalSnapshot *r_upper_snapshot)
Definition anim_sys.cc:3423
static bool nlaevalchan_combine_quaternion_handle_undefined_blend_values(NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_or_lower_necs)
Definition anim_sys.cc:1790
void nlastrip_evaluate(const int evaluation_mode, PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:2750
static void nlaevalchan_assert_blendOrcombine_compatible_quaternion(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *upper_necs, NlaEvalChannelSnapshot *blended_necs)
Definition anim_sys.cc:1804
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
static char nlaevalchan_detect_mix_mode(NlaEvalChannelKey *key, int length)
Definition anim_sys.cc:1255
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1696
@ NLATIME_CONVERT_EVAL
Definition BKE_nla.hh:557
void BKE_keyingset_free_path(KeyingSet *ks, KS_Path *ksp)
Definition anim_sys.cc:233
void DEG_debug_print_eval_time(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address, float time)
@ ADT_NLA_EVAL_UPPER_TRACKS
void nlasnapshot_blend_strip_get_inverted_lower_snapshot(PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context)
Definition anim_sys.cc:2825
void BKE_keyingset_free_paths(KeyingSet *ks)
Definition anim_sys.cc:273
static bool is_fcurve_evaluatable(const FCurve *fcu)
Definition anim_sys.cc:342
static void nlaevalchan_snapshot_free(NlaEvalChannelSnapshot *nec_snapshot)
Definition anim_sys.cc:985
static void nlaevalchan_combine_value(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *upper_necs, const float upper_influence, NlaEvalChannelSnapshot *r_blended_necs)
Definition anim_sys.cc:1901
static void nlaevalchan_blend_value(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *upper_necs, const int upper_blendmode, const float upper_influence, NlaEvalChannelSnapshot *r_blended_necs)
Definition anim_sys.cc:1870
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
bool RNA_property_animateable(const PointerRNA *ptr, PropertyRNA *prop_orig)
Span< rna_path::Item > ParsedRNAPathRef
Definition RNA_path.hh:113
static void nlastrip_evaluate_actionclip(const int evaluation_mode, PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot)
Definition anim_sys.cc:2450
void MEM_delete_void(void *vmemh)
static void nlaevalchan_combine_quaternion_get_inverted_lower_evalchan(NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_necs, const float upper_influence, NlaEvalChannelSnapshot *r_lower_necs)
Definition anim_sys.cc:2249
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:602
Vector< T * > listbase_to_vector(ListBase &list)
static NlaEvalChannelSnapshot ** nlaeval_snapshot_ensure_slot(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec)
Definition anim_sys.cc:1037
static NlaEvalChannel * nlaevalchan_verify_key(NlaEvalData *nlaeval, const char *path, NlaEvalChannelKey *key)
Definition anim_sys.cc:1272
void nlasnapshot_blend_get_inverted_lower_snapshot(NlaEvalData *eval_data, NlaEvalSnapshot *blended_snapshot, NlaEvalSnapshot *upper_snapshot, const short upper_blendmode, const float upper_influence, NlaEvalSnapshot *r_lower_snapshot)
Definition anim_sys.cc:3451
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_array_check(PropertyRNA *prop)
Global G
Definition blender.cc:57
void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup *agrp, const AnimationEvalContext *anim_eval_context)
Definition anim_sys.cc:654
MINLINE void zero_v4(float r[4])
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void BKE_keyingsets_foreach_id(LibraryForeachIDData *data, const ListBaseT< KeyingSet > *keyingsets)
Definition anim_sys.cc:262
void unit_qt(float q[4])
PropertyType RNA_property_type(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
static void nlaevalchan_combine_value_get_inverted_lower_evalchan(NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_necs, const float upper_influence, NlaEvalChannelSnapshot *r_lower_necs)
Definition anim_sys.cc:2206
static bool nlaevalchan_blendOrcombine_try_copy_from_lower(const NlaEvalChannelSnapshot *lower_necs, const NlaEvalChannelSnapshot *upper_necs, const float upper_influence, NlaEvalChannelSnapshot *r_blended_necs)
Definition anim_sys.cc:1822
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
void nlasnapshot_ensure_channels(NlaEvalData *eval_data, NlaEvalSnapshot *snapshot)
Definition anim_sys.cc:3388
static void animsys_create_tweak_strip(const AnimData *adt, const bool keyframing_to_strip, NlaStrip *r_tweak_strip)
Definition anim_sys.cc:2986
void BKE_nla_clip_length_ensure_nonzero(const float *actstart, float *r_actend)
int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop)
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool BKE_nlatrack_is_enabled(const AnimData &adt, const NlaTrack &nlt)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
void evaluate_value_fmodifiers(FModifiersStackStorage *storage, const ListBaseT< FModifier > *modifiers, const FCurve *fcu, float *cvalue, float evaltime)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
static bool animsys_calculate_nla(PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:3348
void BKE_keyingsets_blend_write(BlendWriter *writer, ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:308
BMesh const char void * data
bool BLI_ghash_ensure_p(GHash *gh, void *key, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:756
static void nlaevalchan_snapshot_copy(NlaEvalChannelSnapshot *dst, const NlaEvalChannelSnapshot *src)
Definition anim_sys.cc:995
void BKE_time_markers_blend_write(BlendWriter *writer, ListBaseT< TimeMarker > &markers)
Definition anim_sys.cc:3933
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
@ NLASTRIP_TYPE_SOUND
@ NLASTRIP_TYPE_TRANSITION
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.cc:3139
static CLG_LogRef LOG_ANIM_KEYINGSET
Definition anim_sys.cc:79
static CLG_LogRef LOG_ANIM_FCURVE
Definition anim_sys.cc:78
@ NLASTRIP_MODE_MULTIPLY
@ NLASTRIP_MODE_REPLACE
@ NLASTRIP_MODE_SUBTRACT
@ NLASTRIP_MODE_COMBINE
static bool nla_combine_get_inverted_lower_value(const int mix_mode, float base_value, const float strip_value, const float blended_value, const float influence, float *r_lower_value)
Definition anim_sys.cc:1457
static bool is_action_track_evaluated_without_nla(const AnimData *adt, const bool any_strip_evaluated)
Definition anim_sys.cc:3091
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.cc:1722
static void nlasnapshot_from_action(PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, bAction *action, const animrig::slot_handle_t slot_handle, const float evaltime, NlaEvalSnapshot *r_snapshot)
Definition anim_sys.cc:2401
int RNA_property_flag(PropertyRNA *prop)
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
static void nlaevalchan_combine_value_get_inverted_upper_evalchan(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *blended_necs, const float upper_influence, NlaEvalChannelSnapshot *r_upper_necs)
Definition anim_sys.cc:2048
void nlasnapshot_enable_all_blend_domain(NlaEvalSnapshot *snapshot)
Definition anim_sys.cc:3376
void invert_qt_normalized(float q[4])
static bool animsys_construct_orig_pointer_rna(const PointerRNA *ptr, PointerRNA *ptr_orig)
Definition anim_sys.cc:529
static void nlaevalchan_free(NlaEvalChannel *nec)
Definition anim_sys.cc:1102
std::pair< bAction *, animrig::slot_handle_t > ActionAndSlot
Definition anim_sys.cc:2899
static NlaEvalChannelSnapshot * nlaeval_snapshot_find_channel(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec)
Definition anim_sys.cc:1045
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static void nla_eval_domain_strips(PointerRNA *ptr, NlaEvalData *channels, ListBaseT< NlaStrip > *strips, ActionAndSlotSet &touched_actions)
Definition anim_sys.cc:2937
void BKE_free_time_marker(TimeMarker &marker, bool do_id_user)
Definition anim_sys.cc:3974
static void nlaevalchan_get_default_values(NlaEvalChannel *nec, float *r_values)
Definition anim_sys.cc:1174
static void nlaeval_snapshot_free_data(NlaEvalSnapshot *snapshot)
Definition anim_sys.cc:1081
static void animsys_write_orig_anim_rna(PointerRNA *ptr, const ParsedRNAPathRef rna_path, int array_index, float value)
Definition anim_sys.cc:553
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.cc:1582
bool BKE_animsys_read_from_rna_path(PathResolvedRNA *anim_rna, float *r_value)
Definition anim_sys.cc:400
void BKE_nlastrip_recalculate_bounds_sync_action(NlaStrip *strip)
static void nlaevalchan_blend_value_get_inverted_upper_evalchan(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *blended_necs, const int upper_blendmode, const float upper_influence, NlaEvalChannelSnapshot *r_upper_necs)
Definition anim_sys.cc:2015
void BKE_animsys_update_driver_array(ID *id)
Definition anim_sys.cc:3791
bool RNA_struct_is_ID(const StructRNA *type)
static void nlaeval_snapshot_init(NlaEvalSnapshot *snapshot, NlaEvalData *nlaeval, NlaEvalSnapshot *base)
Definition anim_sys.cc:1006
static void animsys_evaluate_fcurves(PointerRNA *ptr, const Span< FCurve * > fcurves, const AnimationEvalContext *anim_eval_context, bool flush_to_original)
Definition anim_sys.cc:574
static NlaTrack * nlatrack_find_tweaked(const AnimData *adt)
Definition anim_sys.cc:3119
static void nlaevalchan_combine_quaternion(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *upper_necs, const float upper_influence, NlaEvalChannelSnapshot *r_blended_necs)
Definition anim_sys.cc:1935
void BKE_animsys_evaluate_animdata(ID *id, AnimData *adt, const AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, bool flush_to_original)
Definition anim_sys.cc:3716
@ NES_TIME_TRANSITION_START
Definition nla_private.h:51
@ NES_TIME_WITHIN
Definition nla_private.h:47
@ NES_TIME_AFTER
Definition nla_private.h:48
@ NES_TIME_TRANSITION_END
Definition nla_private.h:52
@ NES_TIME_BEFORE
Definition nla_private.h:46
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
static CLG_LogRef LOG_ANIM_DRIVER
Definition anim_sys.cc:77
bool BKE_animsys_write_to_rna_path(PathResolvedRNA *anim_rna, float value, bool force_write=false)
Definition anim_sys.cc:461
float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static void nlastrip_evaluate_meta(const int evaluation_mode, PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:2684
NlaEvalStrip * nlastrips_ctime_get_strip(ListBaseT< NlaEvalStrip > *list, ListBaseT< NlaStrip > *strips, short index, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:777
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
static void nlaevalchan_blendOrcombine_get_inverted_upper_evalchan(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *blended_necs, const int upper_blendmode, const float upper_influence, NlaEvalChannelSnapshot *r_upper_necs)
Definition anim_sys.cc:2118
static NlaEvalChannelSnapshot * nlaevalchan_snapshot_new(NlaEvalChannel *nec)
Definition anim_sys.cc:968
@ STRIP_EVAL_BLEND_GET_INVERTED_LOWER_SNAPSHOT
@ STRIP_EVAL_BLEND
@ STRIP_EVAL_NOBLEND
void BKE_free_time_markers(ListBaseT< TimeMarker > &markers, bool do_id_user)
Definition anim_sys.cc:3982
NlaKeyframingContext * BKE_animsys_get_nla_keyframing_context(ListBaseT< NlaKeyframingContext > *cache, PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context)
Definition anim_sys.cc:3478
static void animsys_create_action_track_strip(const AnimData *adt, const bool keyframing_to_strip, NlaStrip *r_action_strip)
Definition anim_sys.cc:3021
static NlaEvalChannelSnapshot * nlaeval_snapshot_get(NlaEvalSnapshot *snapshot, int index)
Definition anim_sys.cc:1017
void BLI_bitmap_set_all(BLI_bitmap *bitmap, bool set, size_t bits)
Definition bitmap.cc:19
@ PROP_PROPORTIONAL
Definition RNA_types.hh:419
static void nla_eval_domain_action(PointerRNA *ptr, NlaEvalData *channels, bAction *act, const animrig::slot_handle_t slot_handle, ActionAndSlotSet &touched_actions)
Definition anim_sys.cc:2902
int RNA_property_int_get_default(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
signed int int32_t
Definition BKE_text.h:78
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
int RNA_property_int_clamp(PointerRNA *ptr, PropertyRNA *prop, int *value)
static void nlastrip_evaluate_controls(NlaStrip *strip, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:733
bool BKE_animsys_rna_path_resolve(PointerRNA *ptr, ParsedRNAPathRef rna_path, int array_index, PathResolvedRNA *r_result)
Definition anim_sys.cc:356
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
static void nlaevalchan_assert_nonNull(const NlaEvalChannelSnapshot *necs)
Definition anim_sys.cc:1765
KS_Path * BKE_keyingset_find_path(KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, int group_mode)
Definition anim_sys.cc:87
void BKE_keyingsets_free(ListBaseT< KeyingSet > *list)
Definition anim_sys.cc:289
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
bool BKE_fcurve_is_empty(const FCurve *fcu)
static void nlaeval_free(NlaEvalData *nlaeval)
Definition anim_sys.cc:1120
static void animsys_evaluate_overrides(PointerRNA *ptr, AnimData *adt)
Definition anim_sys.cc:3663
Set< ActionAndSlot > ActionAndSlotSet
Definition anim_sys.cc:2900
void nlasnapshot_blend_strip_no_blend(PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context)
Definition anim_sys.cc:2843
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:968
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
static int nlaevalchan_validate_index(const NlaEvalChannel *nec, int index)
Definition anim_sys.cc:1139
@ PROP_QUATERNION
Definition RNA_types.hh:324
@ PROP_AXISANGLE
Definition RNA_types.hh:325
bool DEG_is_evaluated(const T *id)
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.cc:1737
static void nla_combine_quaternion_get_inverted_lower_values(const float strip_values[4], const float blended_values[4], const float influence, float r_lower_value[4])
Definition anim_sys.cc:1519
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
static void nlastrip_evaluate_transition(const int evaluation_mode, PointerRNA *ptr, NlaEvalData *channels, ListBaseT< FModifier > *modifiers, NlaEvalStrip *nes, NlaEvalSnapshot *snapshot, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:2531
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.cc:1676
void *(*) MEM_realloc_zeroed_id(void *vmemh, size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
KS_Path * BKE_keyingset_add_path(KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, eKSP_Settings flag, eKSP_Grouping groupmode)
Definition anim_sys.cc:170
static void nlaevalchan_combine_quaternion_get_inverted_upper_evalchan(NlaEvalChannelSnapshot *lower_necs, NlaEvalChannelSnapshot *blended_necs, const float upper_influence, NlaEvalChannelSnapshot *r_upper_necs)
Definition anim_sys.cc:2086
float DEG_get_ctime(const Depsgraph *graph)
bool RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop)
void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, int driver_index, FCurve *fcu_orig)
Definition anim_sys.cc:3844
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
static bool is_nlatrack_evaluatable(const AnimData *adt, const NlaTrack *nlt)
Definition anim_sys.cc:3075
static CLG_LogRef LOG_ANIM_NLA
Definition anim_sys.cc:80
void DEG_debug_print_eval_subdata_index(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, int subdata_index)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:6653
float evaluate_time_fmodifiers(FModifiersStackStorage *storage, const ListBaseT< FModifier > *modifiers, const FCurve *fcu, float cvalue, float evaltime)
void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id)
Definition anim_sys.cc:3777
static bool nlaevalchan_blendOrcombine_try_copy_to_lower(NlaEvalChannelSnapshot *blended_necs, NlaEvalChannelSnapshot *upper_necs, const float upper_influence, NlaEvalChannelSnapshot *r_lower_necs)
Definition anim_sys.cc:1845
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
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.cc:1612
float evaluate_fcurve(const FCurve *fcu, float evaltime)
void BLI_bitmap_copy_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits)
Definition bitmap.cc:32
void pow_qt_fl_normalized(float q[4], float fac)
static float nla_blend_value(const int blendmode, const float lower_value, const float strip_value, const float influence)
Definition anim_sys.cc:1546
float normalize_qt_qt(float r[4], const float q[4])
static NlaEvalChannel * nlaevalchan_verify(PointerRNA *ptr, NlaEvalData *nlaeval, const char *path)
Definition anim_sys.cc:1312
static NlaEvalStrip * nlastrips_ctime_get_strip_single(ListBaseT< NlaEvalStrip > *dst_list, NlaStrip *single_strip, const AnimationEvalContext *anim_eval_context, const bool flush_to_original)
Definition anim_sys.cc:931
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eNlaStrip_Blend_Mode act_blendmode
eNlaStrip_Extrapolate_Mode act_extendmode
eAnimData_Flag flag
ListBaseT< AnimOverride > overrides
ListBaseT< FCurve > drivers
ListBaseT< NlaTrack > nla_tracks
void write_string(const char *data)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
ListBaseT< DriverVar > variables
eDriverTarget_Flag flag
struct DriverVar * next
eDriverVar_Flags flag
DriverTarget targets[8]
bActionGroup * grp
eFCurve_Flags flag
ChannelDriver * driver
bke::FCurveRuntime * runtime
struct FModifier * prev
struct FModifier * next
char name[258]
Definition DNA_ID.h:433
struct ID * orig_id
Definition DNA_ID.h:502
eKSP_Grouping groupmode
struct KS_Path * next
eKSP_Settings flag
struct KeyingSet * next
eInsertKeyFlags keyingoverride
ListBaseT< KS_Path > paths
eInsertKeyFlags keyingflag
struct PropertyRNA * prop
Definition nla_private.h:61
struct PointerRNA ptr
Definition nla_private.h:60
struct NlaEvalChannel * channel
Definition nla_private.h:82
NlaEvalChannelKey key
NlaEvalChannelSnapshot base_snapshot
struct NlaEvalData * owner
NlaEvalSnapshot base_snapshot
Map< NlaEvalChannelKey, NlaEvalChannel * > * key_hash
NlaEvalSnapshot eval_snapshot
ListBaseT< NlaEvalChannel > channels
struct NlaEvalSnapshot * base
NlaEvalChannelSnapshot ** channels
ListBaseT< NlaEvalStrip > upper_estrips
struct NlaStrip * next
eNlaStrip_Blend_Mode blendmode
ListBaseT< FCurve > fcurves
ListBaseT< FModifier > modifiers
eNlaStrip_Extrapolate_Mode extendmode
struct NlaStrip * orig_strip
eNlaStrip_Flag flag
ListBaseT< NlaStrip > strips
eNlaStrip_Type type
struct NlaStrip * prev
eNlaTrack_Flag flag
ListBaseT< NlaStrip > strips
struct NlaTrack * next
StructRNA * type
Definition RNA_types.hh:63
struct IDProperty * prop