Blender V5.3
blenkernel/intern/nla.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 <cstdlib>
14#include <cstring>
15
16#include "CLG_log.h"
17
18#include "MEM_guardedalloc.h"
19
20#include "BLI_ghash.hh"
21#include "BLI_listbase.hh"
22#include "BLI_string.hh"
23#include "BLI_string_utf8.hh"
24#include "BLI_string_utils.hh"
25#include "BLI_utildefines.hh"
26
27#include "BLT_translation.hh"
28
29#include "DNA_anim_types.h"
30#include "DNA_scene_types.h"
31#include "DNA_speaker_types.h"
32
33#include "BKE_action.hh"
34#include "BKE_anim_data.hh"
35#include "BKE_fcurve.hh"
36#include "BKE_global.hh"
37#include "BKE_lib_id.hh"
38#include "BKE_lib_query.hh"
39#include "BKE_main.hh"
40#include "BKE_nla.hh"
41#include "BKE_sound.hh"
42
43#include "BLO_read_write.hh"
44
45#include "RNA_access.hh"
46#include "RNA_prototypes.hh"
47
48#include "ANIM_nla.hh"
49
50#include "nla_private.h"
51
52namespace blender {
53
54static CLG_LogRef LOG = {"anim.nla"};
55
61static void nla_tweakmode_find_active(ListBaseT<NlaTrack> *nla_tracks,
62 NlaTrack **r_track_of_active_strip,
63 NlaStrip **r_active_strip);
64
65/* *************************************************** */
66/* Data Management */
67
68bke::NlaStripRuntime &NlaStrip::runtime_get()
69{
70 if (this->runtime == nullptr) {
71 this->runtime = MEM_new<bke::NlaStripRuntime>(__func__);
72 }
73 return *this->runtime;
74}
75
76/* Freeing ------------------------------------------- */
77
78void BKE_nlastrip_free(NlaStrip *strip, const bool do_id_user)
79{
80 NlaStrip *cs, *csn;
81
82 /* sanity checks */
83 if (strip == nullptr) {
84 return;
85 }
86
87 /* free child-strips */
88 for (cs = strip->strips.first(); cs; cs = csn) {
89 csn = cs->next;
90 BKE_nlastrip_remove_and_free(&strip->strips, cs, do_id_user);
91 }
92
93 /* remove reference to action */
94 if (strip->act != nullptr && do_id_user) {
95 id_us_min(&strip->act->id);
96 }
97
98 /* free own F-Curves */
100
101 /* free own F-Modifiers */
102 free_fmodifiers(&strip->modifiers);
103
104 /* free the strip runtime and itself */
105 MEM_delete(strip->runtime);
106 MEM_delete(strip);
107}
108
109void BKE_nlatrack_free(NlaTrack *nlt, const bool do_id_user)
110{
111 NlaStrip *strip, *stripn;
112
113 /* sanity checks */
114 if (nlt == nullptr) {
115 return;
116 }
117
118 /* free strips */
119 for (strip = nlt->strips.first(); strip; strip = stripn) {
120 stripn = strip->next;
121 BKE_nlastrip_remove_and_free(&nlt->strips, strip, do_id_user);
122 }
123
124 /* free NLA track itself now */
125 MEM_delete(nlt);
126}
127
128void BKE_nla_tracks_free(ListBaseT<NlaTrack> *tracks, bool do_id_user)
129{
130 NlaTrack *nlt, *nltn;
131
132 /* sanity checks */
133 if (ELEM(nullptr, tracks, tracks->first())) {
134 return;
135 }
136
137 /* free tracks one by one */
138 for (nlt = tracks->first(); nlt; nlt = nltn) {
139 nltn = nlt->next;
140 BKE_nlatrack_remove_and_free(tracks, nlt, do_id_user);
141 }
142
143 /* clear the list's pointers to be safe */
144 tracks->clear_no_delete();
145}
146
147/* Copying ------------------------------------------- */
148
150 NlaStrip *strip,
151 const bool use_same_action,
152 const int flag)
153{
154 NlaStrip *strip_d;
155 NlaStrip *cs_d;
156
157 const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
158
159 /* sanity check */
160 if (strip == nullptr) {
161 return nullptr;
162 }
163
164 /* make a copy */
165 strip_d = MEM_dupalloc(strip);
166 strip_d->next = strip_d->prev = nullptr;
167 strip_d->runtime = nullptr;
168
169 /* handle action */
170 if (strip_d->act) {
171 if (use_same_action) {
172 if (do_id_user) {
173 /* increase user-count of action */
174 id_us_plus(&strip_d->act->id);
175 }
176 }
177 else {
178 /* use a copy of the action instead (user count shouldn't have changed yet) */
179 BKE_id_copy_ex(bmain, &strip_d->act->id, reinterpret_cast<ID **>(&strip_d->act), flag);
180 }
181 }
182
183 /* copy F-Curves and modifiers */
184 BKE_fcurves_copy(&strip_d->fcurves, &strip->fcurves);
185 copy_fmodifiers(&strip_d->modifiers, &strip->modifiers);
186
187 /* make a copy of all the child-strips, one at a time */
188 strip_d->strips.clear_no_delete();
189
190 for (NlaStrip &cs : strip->strips) {
191 cs_d = BKE_nlastrip_copy(bmain, &cs, use_same_action, flag);
192 BLI_addtail(&strip_d->strips, cs_d);
193 }
194
195 /* return the strip */
196 return strip_d;
197}
198
200 NlaTrack *nlt,
201 const bool use_same_actions,
202 const int flag)
203{
204 NlaStrip *strip_d;
205 NlaTrack *nlt_d;
206
207 /* sanity check */
208 if (nlt == nullptr) {
209 return nullptr;
210 }
211
212 /* make a copy */
213 nlt_d = MEM_dupalloc(nlt);
214 nlt_d->next = nlt_d->prev = nullptr;
215
216 /* make a copy of all the strips, one at a time */
217 nlt_d->strips.clear_no_delete();
218
219 for (NlaStrip &strip : nlt->strips) {
220 strip_d = BKE_nlastrip_copy(bmain, &strip, use_same_actions, flag);
221 BLI_addtail(&nlt_d->strips, strip_d);
222 }
223
224 /* return the copy */
225 return nlt_d;
226}
227
229 ListBaseT<NlaTrack> *dst,
230 const ListBaseT<NlaTrack> *src,
231 const int flag)
232{
233 NlaTrack *nlt_d;
234
235 /* sanity checks */
236 if (ELEM(nullptr, dst, src)) {
237 return;
238 }
239
240 /* clear out the destination list first for precautions... */
241 dst->clear_no_delete();
242
243 /* copy each NLA-track, one at a time */
244 for (NlaTrack &nlt : *src) {
245 /* make a copy, and add the copy to the destination list */
246 /* XXX: we need to fix this sometime. */
247 nlt_d = BKE_nlatrack_copy(bmain, &nlt, true, flag);
248 BLI_addtail(dst, nlt_d);
249 }
250}
251
257 const ListBaseT<NlaStrip> *strips_source,
258 const ListBaseT<NlaStrip> *strips_dest)
259{
260 BLI_assert_msg(strips_source->count() == strips_dest->count(),
261 "Expecting the same number of source and destination strips");
262
263 NlaStrip *strip_dest = strips_dest->first();
264 for (const NlaStrip &strip_source : *strips_source) {
265 if (strip_dest == nullptr) {
266 /* The tracks are assumed to have an equal number of strips, but this is
267 * not the case. Not sure when this might happen, but it's better to not
268 * crash. */
269 break;
270 }
271 if (&strip_source == active_strip) {
272 return strip_dest;
273 }
274
275 const bool src_is_meta = strip_source.type == NLASTRIP_TYPE_META;
276 const bool dst_is_meta = strip_dest->type == NLASTRIP_TYPE_META;
277 BLI_assert_msg(src_is_meta == dst_is_meta,
278 "Expecting topology of source and destination strips to be equal");
279 if (src_is_meta && dst_is_meta) {
281 active_strip, &strip_source.strips, &strip_dest->strips);
282 if (found_in_meta != nullptr) {
283 return found_in_meta;
284 }
285 }
286
287 strip_dest = strip_dest->next;
288 }
289
290 return nullptr;
291}
292
293/* Set adt_dest->actstrip to the strip with the same index as
294 * adt_source->actstrip. Note that this always sets `adt_dest->actstrip`; sets
295 * to nullptr when `adt_source->actstrip` cannot be found. */
296static void update_active_strip(AnimData *adt_dest,
297 NlaTrack *track_dest,
298 const AnimData *adt_source,
299 const NlaTrack *track_source)
300{
301 BLI_assert(track_source->strips.count() == track_dest->strips.count());
302
304 adt_source->actstrip, &track_source->strips, &track_dest->strips);
305 adt_dest->actstrip = active_strip;
306}
307
308/* Set adt_dest->act_track to the track with the same index as adt_source->act_track. */
309static void update_active_track(AnimData *adt_dest, const AnimData *adt_source)
310{
311 adt_dest->act_track = nullptr;
312 adt_dest->actstrip = nullptr;
313 if (adt_source->act_track == nullptr && adt_source->actstrip == nullptr) {
314 return;
315 }
316
317 BLI_assert(adt_source->nla_tracks.count() == adt_dest->nla_tracks.count());
318
319 NlaTrack *track_dest = adt_dest->nla_tracks.first();
320 for (NlaTrack &track_source : adt_source->nla_tracks) {
321 if (&track_source == adt_source->act_track) {
322 adt_dest->act_track = track_dest;
323 }
324
325 /* Only search for the active strip if it hasn't been found yet. */
326 if (adt_dest->actstrip == nullptr && adt_source->actstrip != nullptr) {
327 update_active_strip(adt_dest, track_dest, adt_source, &track_source);
328 }
329
330 track_dest = track_dest->next;
331 }
332
333#ifndef NDEBUG
334 {
335 const bool source_has_actstrip = adt_source->actstrip != nullptr;
336 const bool dest_has_actstrip = adt_dest->actstrip != nullptr;
337 BLI_assert_msg(source_has_actstrip == dest_has_actstrip,
338 "Active strip did not copy correctly");
339 }
340#endif
341}
342
344 AnimData *adt_dest,
345 const AnimData *adt_source,
346 const int flag)
347{
348 adt_dest->act_track = nullptr;
349 adt_dest->actstrip = nullptr;
350
351 BKE_nla_tracks_copy(bmain, &adt_dest->nla_tracks, &adt_source->nla_tracks, flag);
352 update_active_track(adt_dest, adt_source);
353}
354
355/* Adding ------------------------------------------- */
356
358{
359 /* allocate new track */
360 NlaTrack *nlt = MEM_new<NlaTrack>("NlaTrack");
361
362 /* set settings requiring the track to not be part of the stack yet */
364
365 return nlt;
366}
367
368void BKE_nlatrack_insert_before(ListBaseT<NlaTrack> *nla_tracks,
369 NlaTrack *next,
370 NlaTrack *new_track,
371 bool is_liboverride)
372{
373
374 if (is_liboverride) {
375 /* Currently, all library override tracks are assumed to be grouped together at the start of
376 * the list. Non overridden must be placed after last library track. */
377 if (next != nullptr && (next->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
378 BKE_nlatrack_insert_after(nla_tracks, next, new_track, is_liboverride);
379 return;
380 }
381 }
382
383 BLI_insertlinkbefore(nla_tracks, next, new_track);
384 new_track->index = BLI_findindex(nla_tracks, new_track);
385
386 /* Must have unique name, but we need to seed this. */
387 STRNCPY_UTF8(new_track->name, "NlaTrack");
388
389 BLI_uniquename(nla_tracks,
390 new_track,
391 DATA_("NlaTrack"),
392 '.',
393 offsetof(NlaTrack, name),
394 sizeof(new_track->name));
395}
396
397void BKE_nlatrack_insert_after(ListBaseT<NlaTrack> *nla_tracks,
398 NlaTrack *prev,
399 NlaTrack *new_track,
400 const bool is_liboverride)
401{
402 BLI_assert(nla_tracks);
403 BLI_assert(new_track);
404
405 /* If nullptr, then caller intends to insert a new head. But, tracks are not allowed to be
406 * placed before library overrides. So it must inserted after the last override. */
407 if (prev == nullptr) {
408 NlaTrack *first_track = nla_tracks->first();
409 if (first_track != nullptr && (first_track->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
410 prev = first_track;
411 }
412 }
413
414 /* In liboverride case, we only add local tracks after all those coming from the linked data,
415 * so we need to find the first local track. */
416 if (is_liboverride && prev != nullptr && (prev->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
417 NlaTrack *first_local = prev->next;
418 for (; first_local != nullptr && (first_local->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0;
419 first_local = first_local->next)
420 {
421 }
422 prev = first_local != nullptr ? first_local->prev : prev;
423 }
424
425 /* Add track to stack, and make it the active one. */
426 BLI_insertlinkafter(nla_tracks, prev, new_track);
427 new_track->index = BLI_findindex(nla_tracks, new_track);
428
429 /* must have unique name, but we need to seed this */
430 BLI_uniquename(nla_tracks,
431 new_track,
432 DATA_("NlaTrack"),
433 '.',
434 offsetof(NlaTrack, name),
435 sizeof(new_track->name));
436}
437
438NlaTrack *BKE_nlatrack_new_before(ListBaseT<NlaTrack> *nla_tracks,
439 NlaTrack *next,
440 bool is_liboverride)
441{
442 NlaTrack *new_track = BKE_nlatrack_new();
443
444 BKE_nlatrack_insert_before(nla_tracks, next, new_track, is_liboverride);
445
446 return new_track;
447}
448
449NlaTrack *BKE_nlatrack_new_after(ListBaseT<NlaTrack> *nla_tracks,
450 NlaTrack *prev,
451 bool is_liboverride)
452{
453 NlaTrack *new_track = BKE_nlatrack_new();
454
455 BKE_nlatrack_insert_after(nla_tracks, prev, new_track, is_liboverride);
456
457 return new_track;
458}
459
460NlaTrack *BKE_nlatrack_new_head(ListBaseT<NlaTrack> *nla_tracks, bool is_liboverride)
461{
462 return BKE_nlatrack_new_before(nla_tracks, nla_tracks->first(), is_liboverride);
463}
464
465NlaTrack *BKE_nlatrack_new_tail(ListBaseT<NlaTrack> *nla_tracks, const bool is_liboverride)
466{
467 return BKE_nlatrack_new_after(nla_tracks, nla_tracks->last(), is_liboverride);
468}
469
471{
472 if (strip->actend <= strip->actstart) {
473 return 1.0f;
474 }
475 return strip->actend - strip->actstart;
476}
477
478void BKE_nla_clip_length_ensure_nonzero(const float *actstart, float *r_actend)
479{
480 if (*r_actend <= *actstart) {
481 *r_actend = *actstart + 1.0f;
482 }
483}
484
491static NlaStrip *nlastrip_new(bAction *act, ID &animated_id)
492{
493 using namespace blender::animrig;
494
495 NlaStrip *strip;
496
497 /* sanity checks */
498 if (act == nullptr) {
499 return nullptr;
500 }
501
502 /* allocate new strip */
503 strip = MEM_new<NlaStrip>("NlaStrip");
504
505 /* generic settings
506 * - selected flag to highlight this to the user
507 * - (XXX) disabled Auto-Blends, as this was often causing some unwanted effects
508 */
510
511 /* Disable sync for actions with a manual frame range, since it only syncs to range anyway. */
512 if (act->flag & ACT_FRAME_RANGE) {
514 }
515
516 /* Enable cyclic time for known cyclic actions. */
517 Action &action = act->wrap();
518 if (action.is_cyclic()) {
520 }
521
522 /* Assign the Action, and automatically choose a suitable slot. The caller can change the slot to
523 * something more specific later, if necessary. */
524 nla::assign_action(*strip, action, animated_id);
525
526 /* strip should be referenced as-is */
527 strip->scale = 1.0f;
528 strip->repeat = 1.0f;
529
530 return strip;
531}
532
538{
539 const float2 frame_range = strip->act->wrap().get_frame_range_of_slot(strip->action_slot_handle);
540 strip->actstart = frame_range[0];
541 strip->actend = frame_range[1];
543 strip->start = strip->actstart;
544 strip->end = strip->actend;
545}
546
548{
549 NlaStrip *strip = nlastrip_new(act, animated_id);
550 if (!strip) {
551 return nullptr;
552 }
554 return strip;
555}
556
558 animrig::slot_handle_t slot_handle,
559 ID &animated_id)
560{
561 using namespace blender::animrig;
562
563 NlaStrip *strip = BKE_nlastrip_new(act, animated_id);
564 if (!strip) {
565 return nullptr;
566 }
567
569 *strip, slot_handle, animated_id);
570
571 switch (result) {
573 break;
577 [[fallthrough]];
579 BKE_nlastrip_free(strip, true);
580 return nullptr;
581 }
582
584 return strip;
585}
586
587NlaStrip *BKE_nlastack_add_strip(const OwnedAnimData owned_adt, const bool is_liboverride)
588{
589 NlaStrip *strip;
590 NlaTrack *nlt;
591 AnimData *adt = &owned_adt.adt;
592
593 /* sanity checks */
594 if (ELEM(nullptr, adt, adt->action)) {
595 return nullptr;
596 }
597
598 /* create a new NLA strip */
599 strip = BKE_nlastrip_new_for_slot(adt->action, adt->slot_handle, owned_adt.owner_id);
600 if (strip == nullptr) {
601 return nullptr;
602 }
603
604 /* firstly try adding strip to last track, but if that fails, add to a new track */
605 if (BKE_nlatrack_add_strip(adt->nla_tracks.last(), strip, is_liboverride) == 0) {
606 /* trying to add to the last track failed (no track or no space),
607 * so add a new track to the stack, and add to that...
608 */
609 nlt = BKE_nlatrack_new_tail(&adt->nla_tracks, is_liboverride);
611 BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
612 STRNCPY_UTF8(nlt->name, adt->action->id.name + 2);
613 }
614
615 /* automatically name it too */
616 BKE_nlastrip_validate_name(adt, strip);
617
618 /* returns the strip added */
619 return strip;
620}
621
623{
624 NlaStrip *strip = MEM_new<NlaStrip>("NlaSoundStrip");
625
626/* if speaker has a sound, set the strip length to the length of the sound,
627 * otherwise default to length of 10 frames
628 */
629#ifdef WITH_AUDASPACE
630 if (speaker->sound) {
631 SoundInfo info;
632 if (BKE_sound_info_get(bmain, speaker->sound, &info)) {
633 strip->end = float(ceil(double(info.length) * scene->frames_per_second()));
634 }
635 }
636 else
637#endif
638 {
639 strip->end = 10.0f;
640 /* quiet compiler warnings */
641 UNUSED_VARS(bmain, scene, speaker);
642 }
643
644 /* general settings */
645 strip->type = NLASTRIP_TYPE_SOUND;
646
647 strip->flag = NLASTRIP_FLAG_SELECT;
648 strip->extendmode = NLASTRIP_EXTEND_NOTHING; /* nothing to extend... */
649
650 /* strip should be referenced as-is */
651 strip->scale = 1.0f;
652 strip->repeat = 1.0f;
653
654 /* return this strip */
655 return strip;
656}
657
670
671/* Removing ------------------------------------------ */
672
673void BKE_nlatrack_remove(ListBaseT<NlaTrack> *tracks, NlaTrack *nlt)
674{
675 BLI_assert(tracks);
676 BLI_remlink(tracks, nlt);
677}
678
679void BKE_nlatrack_remove_and_free(ListBaseT<NlaTrack> *tracks, NlaTrack *nlt, bool do_id_user)
680{
681 BKE_nlatrack_remove(tracks, nlt);
682 BKE_nlatrack_free(nlt, do_id_user);
683}
684
685bool BKE_nlatrack_is_enabled(const AnimData &adt, const NlaTrack &nlt)
686{
687 if (adt.flag & ADT_NLA_SOLO_TRACK) {
688 return (nlt.flag & NLATRACK_SOLO);
689 }
690
691 return !(nlt.flag & NLATRACK_MUTED);
692}
693
694/* *************************************************** */
695/* NLA Evaluation <-> Editing Stuff */
696
697/* Strip Mapping ------------------------------------- */
698
699/* non clipped mapping for strip-time <-> global time (for Action-Clips)
700 * invert = convert action-strip time to global time
701 */
702static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short mode)
703{
704 float scale;
705 // float repeat; // UNUSED
706
707 /* get number of repeats */
708 if (IS_EQF(strip->repeat, 0.0f)) {
709 strip->repeat = 1.0f;
710 }
711 // repeat = strip->repeat; /* UNUSED */
712
713 /* scaling */
714 if (IS_EQF(strip->scale, 0.0f)) {
715 strip->scale = 1.0f;
716 }
717
718 /* Scale must be positive - we've got a special flag for reversing. */
719 scale = fabsf(strip->scale);
720
721 /* length of referenced action */
722 const float actlength = BKE_nla_clip_length_get_nonzero(strip);
723
724 /* reversed = play strip backwards */
725 if (strip->flag & NLASTRIP_FLAG_REVERSE) {
726 /* FIXME: this won't work right with Graph Editor? */
727 if (mode == NLATIME_CONVERT_MAP) {
728 return strip->end - scale * (cframe - strip->actstart);
729 }
730 if (mode == NLATIME_CONVERT_UNMAP) {
731 return (strip->end + (strip->actstart * scale - cframe)) / scale;
732 }
733 /* if (mode == NLATIME_CONVERT_EVAL) */
734 if (IS_EQF(float(cframe), strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
735 /* This case prevents the motion snapping back to the first frame at the end of the strip
736 * by catching the case where repeats is a whole number, which means that the end of the
737 * strip could also be interpreted as the end of the start of a repeat. */
738 return strip->actstart;
739 }
740
741 /* - The `fmod(..., actlength * scale)` is needed to get the repeats working.
742 * - The `/ scale` is needed to ensure that scaling influences the timing within the repeat.
743 */
744 return strip->actend - fmodf(cframe - strip->start, actlength * scale) / scale;
745 }
746
747 if (mode == NLATIME_CONVERT_MAP) {
748 return strip->start + scale * (cframe - strip->actstart);
749 }
750 if (mode == NLATIME_CONVERT_UNMAP) {
751 return strip->actstart + (cframe - strip->start) / scale;
752 }
753 /* if (mode == NLATIME_CONVERT_EVAL) */
754 if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) {
755 /* This case prevents the motion snapping back to the first frame at the end of the strip
756 * by catching the case where repeats is a whole number, which means that the end of the
757 * strip could also be interpreted as the end of the start of a repeat. */
758 return strip->actend;
759 }
760
761 /* - The `fmod(..., actlength * scale)` is needed to get the repeats working.
762 * - The `/ scale` is needed to ensure that scaling influences the timing within the repeat.
763 */
764 return strip->actstart + fmodf(cframe - strip->start, actlength * scale) / scale;
765}
766
767/* non clipped mapping for strip-time <-> global time (for Transitions)
768 * invert = convert action-strip time to global time
769 */
770static float nlastrip_get_frame_transition(NlaStrip *strip, float cframe, short mode)
771{
772 float length;
773
774 /* length of strip */
775 length = strip->end - strip->start;
776
777 /* reversed = play strip backwards */
778 if (strip->flag & NLASTRIP_FLAG_REVERSE) {
779 if (mode == NLATIME_CONVERT_MAP) {
780 return strip->end - (length * cframe);
781 }
782
783 return (strip->end - cframe) / length;
784 }
785
786 if (mode == NLATIME_CONVERT_MAP) {
787 return (length * cframe) + strip->start;
788 }
789
790 return (cframe - strip->start) / length;
791}
792
793float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode)
794{
795 switch (strip->type) {
796 case NLASTRIP_TYPE_META: /* Meta - for now, does the same as transition
797 * (is really just an empty container). */
798 case NLASTRIP_TYPE_TRANSITION: /* transition */
799 return nlastrip_get_frame_transition(strip, cframe, mode);
800
801 case NLASTRIP_TYPE_CLIP: /* action-clip (default) */
802 default:
803 return nlastrip_get_frame_actionclip(strip, cframe, mode);
804 }
805}
806
807float BKE_nla_tweakedit_remap(AnimData *adt, const float cframe, const eNlaTime_ConvertModes mode)
808{
809 NlaStrip *strip;
810
811 /* Sanity checks:
812 * - Obviously we've got to have some starting data.
813 * - When not in tweak-mode, the active Action does not have any scaling applied :)
814 * - When in tweak-mode, if the no-mapping flag is set, do not map.
815 */
816 if ((adt == nullptr) || (adt->flag & ADT_NLA_EDIT_ON) == 0 || (adt->flag & ADT_NLA_EDIT_NOMAP)) {
817 return cframe;
818 }
819
820 /* if the active-strip info has been stored already, access this, otherwise look this up
821 * and store for (very probable) future usage
822 */
823 if (adt->act_track == nullptr) {
824 if (adt->actstrip) {
826 }
827 else {
829 }
830 }
831 if (adt->actstrip == nullptr) {
833 }
834 strip = adt->actstrip;
835
836 /* Sanity checks:
837 * - In rare cases, we may not be able to find this strip for some reason (internal error)
838 * - For now, if the user has defined a curve to control the time, this correction cannot be
839 * performed reliably.
840 */
841 if ((strip == nullptr) || (strip->flag & NLASTRIP_FLAG_USR_TIME)) {
842 return cframe;
843 }
844
845 /* perform the correction now... */
846 return nlastrip_get_frame(strip, cframe, mode);
847}
848
849/* *************************************************** */
850/* NLA API */
851
852/* List of Strips ------------------------------------ */
853/* (these functions are used for NLA-Tracks and also for nested/meta-strips) */
854
855bool BKE_nlastrips_has_space(ListBaseT<NlaStrip> *strips, float start, float end)
856{
857 /* sanity checks */
858 if ((strips == nullptr) || IS_EQF(start, end)) {
859 return false;
860 }
861 if (start > end) {
862 puts("BKE_nlastrips_has_space() error... start and end arguments swapped");
863 std::swap(start, end);
864 }
865
866 /* loop over NLA strips checking for any overlaps with this area... */
867 for (NlaStrip &strip : *strips) {
868 /* if start frame of strip is past the target end-frame, that means that
869 * we've gone past the window we need to check for, so things are fine
870 */
871 if (strip.start >= end) {
872 return true;
873 }
874
875 /* if the end of the strip is greater than either of the boundaries, the range
876 * must fall within the extents of the strip
877 */
878 if ((strip.end > start) || (strip.end > end)) {
879 return false;
880 }
881 }
882
883 /* if we are still here, we haven't encountered any overlapping strips */
884 return true;
885}
886
887void BKE_nlastrips_sort_strips(ListBaseT<NlaStrip> *strips)
888{
889 ListBaseT<NlaStrip> tmp = {nullptr, nullptr};
890 NlaStrip *strip, *stripn;
891
892 /* sanity checks */
893 if (ELEM(nullptr, strips, strips->first())) {
894 return;
895 }
896
897 /* we simply perform insertion sort on this list, since it is assumed that per track,
898 * there are only likely to be at most 5-10 strips
899 */
900 for (strip = strips->first(); strip; strip = stripn) {
901 short not_added = 1;
902
903 stripn = strip->next;
904
905 /* remove this strip from the list, and add it to the new list, searching from the end of
906 * the list, assuming that the lists are in order
907 */
908 BLI_remlink(strips, strip);
909
910 for (NlaStrip &sstrip : tmp.items_reversed()) {
911 /* check if add after */
912 if (sstrip.start <= strip->start) {
913 BLI_insertlinkafter(&tmp, &sstrip, strip);
914 not_added = 0;
915 break;
916 }
917 }
918
919 /* add before first? */
920 if (not_added) {
921 BLI_addhead(&tmp, strip);
922 }
923 }
924
925 /* reassign the start and end points of the strips */
926 strips->first_ = tmp.first();
927 strips->last_ = tmp.last();
928}
929
930void BKE_nlastrips_add_strip_unsafe(ListBaseT<NlaStrip> *strips, NlaStrip *strip)
931{
932 bool not_added = true;
933
934 /* sanity checks */
935 BLI_assert(!ELEM(nullptr, strips, strip));
936
937 /* find the right place to add the strip to the nominated track */
938 for (NlaStrip &ns : *strips) {
939 /* if current strip occurs after the new strip, add it before */
940 if (ns.start >= strip->start) {
941 BLI_insertlinkbefore(strips, &ns, strip);
942 not_added = false;
943 break;
944 }
945 }
946 if (not_added) {
947 /* just add to the end of the list of the strips then... */
948 BLI_addtail(strips, strip);
949 }
950}
951
952bool BKE_nlastrips_add_strip(ListBaseT<NlaStrip> *strips, NlaStrip *strip)
953{
954 if (ELEM(nullptr, strips, strip)) {
955 return false;
956 }
957
958 if (!BKE_nlastrips_has_space(strips, strip->start, strip->end)) {
959 return false;
960 }
961
962 BKE_nlastrips_add_strip_unsafe(strips, strip);
963 return true;
964}
965
966/* Meta-Strips ------------------------------------ */
967
968void BKE_nlastrips_make_metas(ListBaseT<NlaStrip> *strips, bool is_temp)
969{
970 NlaStrip *mstrip = nullptr;
971 NlaStrip *strip, *stripn;
972
973 /* sanity checks */
974 if (ELEM(nullptr, strips, strips->first())) {
975 return;
976 }
977
978 /* group all continuous chains of selected strips into meta-strips */
979 for (strip = strips->first(); strip; strip = stripn) {
980 stripn = strip->next;
981
982 if (strip->flag & NLASTRIP_FLAG_SELECT) {
983 /* if there is an existing meta-strip, add this strip to it, otherwise, create a new one */
984 if (mstrip == nullptr) {
985 /* add a new meta-strip, and add it before the current strip that it will replace... */
986 mstrip = MEM_new<NlaStrip>("Meta-NlaStrip");
987 mstrip->type = NLASTRIP_TYPE_META;
988 BLI_insertlinkbefore(strips, strip, mstrip);
989
990 /* set flags */
991 mstrip->flag = NLASTRIP_FLAG_SELECT;
992
993 /* set temp flag if appropriate (i.e. for transform-type editing) */
994 if (is_temp) {
995 mstrip->flag |= NLASTRIP_FLAG_TEMP_META;
996 }
997
998 /* set default repeat/scale values to prevent warnings */
999 mstrip->repeat = mstrip->scale = 1.0f;
1000
1001 /* make its start frame be set to the start frame of the current strip */
1002 mstrip->start = strip->start;
1003 }
1004
1005 /* remove the selected strips from the track, and add to the meta */
1006 BLI_remlink(strips, strip);
1007 BLI_addtail(&mstrip->strips, strip);
1008
1009 /* expand the meta's dimensions to include the newly added strip- i.e. its last frame */
1010 mstrip->end = strip->end;
1011 }
1012 else {
1013 /* current strip wasn't selected, so the end of 'island' of selected strips has been
1014 * reached, so stop adding strips to the current meta.
1015 */
1016 mstrip = nullptr;
1017 }
1018 }
1019}
1020
1021void BKE_nlastrips_clear_metastrip(ListBaseT<NlaStrip> *strips, NlaStrip *strip)
1022{
1023 NlaStrip *cs, *csn;
1024
1025 /* sanity check */
1026 if (ELEM(nullptr, strips, strip)) {
1027 return;
1028 }
1029
1030 /* move each one of the meta-strip's children before the meta-strip
1031 * in the list of strips after unlinking them from the meta-strip
1032 */
1033 for (cs = strip->strips.first(); cs; cs = csn) {
1034 csn = cs->next;
1035 BLI_remlink(&strip->strips, cs);
1036 BLI_insertlinkbefore(strips, strip, cs);
1037 }
1038
1039 /* free the meta-strip now */
1040 BKE_nlastrip_remove_and_free(strips, strip, true);
1041}
1042
1043void BKE_nlastrips_clear_metas(ListBaseT<NlaStrip> *strips, bool only_sel, bool only_temp)
1044{
1045 NlaStrip *strip, *stripn;
1046
1047 /* sanity checks */
1048 if (ELEM(nullptr, strips, strips->first())) {
1049 return;
1050 }
1051
1052 /* remove meta-strips fitting the criteria of the arguments */
1053 for (strip = strips->first(); strip; strip = stripn) {
1054 stripn = strip->next;
1055
1056 /* check if strip is a meta-strip */
1057 if (strip->type == NLASTRIP_TYPE_META) {
1058 /* if check if selection and 'temporary-only' considerations are met */
1059 if ((!only_sel) || (strip->flag & NLASTRIP_FLAG_SELECT)) {
1060 if ((!only_temp) || (strip->flag & NLASTRIP_FLAG_TEMP_META)) {
1061 BKE_nlastrips_clear_metastrip(strips, strip);
1062 }
1063 }
1064 }
1065 }
1066}
1067
1069{
1070 /* sanity checks */
1071 if (ELEM(nullptr, mstrip, strip)) {
1072 return false;
1073 }
1074
1075 /* firstly, check if the meta-strip has space for this */
1076 if (BKE_nlastrips_has_space(&mstrip->strips, strip->start, strip->end) == 0) {
1077 return false;
1078 }
1079
1080 /* check if this would need to be added to the ends of the meta,
1081 * and subsequently, if the neighboring strips allow us enough room
1082 */
1083 if (strip->start < mstrip->start) {
1084 /* check if strip to the left (if it exists) ends before the
1085 * start of the strip we're trying to add
1086 */
1087 if ((mstrip->prev == nullptr) || (mstrip->prev->end <= strip->start)) {
1088 /* add strip to start of meta's list, and expand dimensions */
1089 BLI_addhead(&mstrip->strips, strip);
1090 mstrip->start = strip->start;
1091
1092 return true;
1093 }
1094 /* failed... no room before */
1095 return false;
1096 }
1097 if (strip->end > mstrip->end) {
1098 /* check if strip to the right (if it exists) starts before the
1099 * end of the strip we're trying to add
1100 */
1101 if ((mstrip->next == nullptr) || (mstrip->next->start >= strip->end)) {
1102 /* add strip to end of meta's list, and expand dimensions */
1103 BLI_addtail(&mstrip->strips, strip);
1104 mstrip->end = strip->end;
1105
1106 return true;
1107 }
1108 /* failed... no room after */
1109 return false;
1110 }
1111
1112 /* just try to add to the meta-strip (no dimension changes needed) */
1113 return BKE_nlastrips_add_strip(&mstrip->strips, strip);
1114}
1115
1117{
1118 float oStart, oEnd, offset;
1119 float oLen, nLen;
1120 short scaleChanged = 0;
1121
1122 /* sanity checks
1123 * - strip must exist
1124 * - strip must be a meta-strip with some contents
1125 */
1126 if (ELEM(nullptr, mstrip, mstrip->strips.first())) {
1127 return;
1128 }
1129 if (mstrip->type != NLASTRIP_TYPE_META) {
1130 return;
1131 }
1132
1133 /* get the original start/end points, and calculate the start-frame offset
1134 * - these are simply the start/end frames of the child strips,
1135 * since we assume they weren't transformed yet
1136 */
1137 oStart = (mstrip->strips.first())->start;
1138 oEnd = (mstrip->strips.last())->end;
1139 offset = mstrip->start - oStart;
1140
1141 /* check if scale changed */
1142 oLen = oEnd - oStart;
1143 nLen = mstrip->end - mstrip->start;
1144 scaleChanged = !IS_EQF(oLen, nLen);
1145
1146 /* optimization:
1147 * don't flush if nothing changed yet
1148 * TODO: maybe we need a flag to say always flush?
1149 */
1150 if (IS_EQF(oStart, mstrip->start) && IS_EQF(oEnd, mstrip->end) && !scaleChanged) {
1151 return;
1152 }
1153
1154 /* for each child-strip, calculate new start/end points based on this new info */
1155 for (NlaStrip &strip : mstrip->strips) {
1156 if (scaleChanged) {
1157 float p1, p2;
1158
1159 if (oLen) {
1160 /* Compute positions of endpoints relative to old extents of strip. */
1161 p1 = (strip.start - oStart) / oLen;
1162 p2 = (strip.end - oStart) / oLen;
1163 }
1164 else {
1165 /* WORKAROUND: in theory, a strip should never be zero length. However,
1166 * zero-length strips are nevertheless showing up here (see issue #113552).
1167 * This is a stop-gap fix to handle that and prevent a divide by zero. A
1168 * proper fix will need to track down and fix the source(s) of these
1169 * zero-length strips. */
1170 p1 = 0.0f;
1171 p2 = 1.0f;
1172 }
1173
1174 /* Apply new strip endpoints using the proportions,
1175 * then wait for second pass to flush scale properly. */
1176 strip.start = (p1 * nLen) + mstrip->start;
1177 strip.end = (p2 * nLen) + mstrip->start;
1178
1179 /* Recompute the playback scale, given the new start & end frame of the strip. */
1180 const double action_len = strip.actend - strip.actstart;
1181 const double repeated_len = action_len * strip.repeat;
1182 const double strip_len = strip.end - strip.start;
1183 strip.scale = strip_len / repeated_len;
1184 }
1185 else {
1186 /* just apply the changes in offset to both ends of the strip */
1187 strip.start += offset;
1188 strip.end += offset;
1189 }
1190 }
1191
1192 /* apply a second pass over child strips, to finish up unfinished business */
1193 for (NlaStrip &strip : mstrip->strips) {
1194 /* only if scale changed, need to perform RNA updates */
1195 if (scaleChanged) {
1196 /* use RNA updates to compute scale properly */
1197 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, RNA_NlaStrip, &strip);
1198
1199 RNA_float_set(&ptr, "frame_start", strip.start);
1200 RNA_float_set(&ptr, "frame_end", strip.end);
1201 }
1202
1203 /* finally, make sure the strip's children (if it is a meta-itself), get updated */
1205 }
1206}
1207
1208/* NLA-Tracks ---------------------------------------- */
1209
1210NlaTrack *BKE_nlatrack_find_active(ListBaseT<NlaTrack> *tracks)
1211{
1212 /* sanity check */
1213 if (ELEM(nullptr, tracks, tracks->first())) {
1214 return nullptr;
1215 }
1216
1217 /* try to find the first active track */
1218 for (NlaTrack &nlt : *tracks) {
1219 if (nlt.flag & NLATRACK_ACTIVE) {
1220 return &nlt;
1221 }
1222 }
1223
1224 /* none found */
1225 return nullptr;
1226}
1227
1229{
1230 /* sanity check */
1231 if (adt == nullptr) {
1232 return nullptr;
1233 }
1234
1235 /* Since the track itself gets disabled, we want the first disabled... */
1236 for (NlaTrack &nlt : adt->nla_tracks) {
1237 if (nlt.flag & (NLATRACK_ACTIVE | NLATRACK_DISABLED)) {
1238 /* For good measure, make sure that strip actually exists there */
1239 if (BLI_findindex(&nlt.strips, adt->actstrip) != -1) {
1240 return &nlt;
1241 }
1242 if (G.debug & G_DEBUG) {
1243 printf("%s: Active strip (%p, %s) not in NLA track found (%p, %s)\n",
1244 __func__,
1245 adt->actstrip,
1246 (adt->actstrip) ? adt->actstrip->name : "<None>",
1247 &nlt,
1248 nlt.name);
1249 }
1250 }
1251 }
1252
1253 /* Not found! */
1254 return nullptr;
1255}
1256
1258{
1259 /* sanity check */
1260 if (ELEM(nullptr, adt, adt->nla_tracks.first())) {
1261 return;
1262 }
1263
1264 /* firstly, make sure 'solo' flag for all tracks is disabled */
1265 for (NlaTrack &nt : adt->nla_tracks) {
1266 if (&nt != nlt) {
1267 nt.flag &= ~NLATRACK_SOLO;
1268 }
1269 }
1270
1271 /* now, enable 'solo' for the given track if appropriate */
1272 if (nlt) {
1273 /* toggle solo status */
1274 nlt->flag ^= NLATRACK_SOLO;
1275
1276 /* set or clear solo-status on AnimData */
1277 if (nlt->flag & NLATRACK_SOLO) {
1278 adt->flag |= ADT_NLA_SOLO_TRACK;
1279 }
1280 else {
1281 adt->flag &= ~ADT_NLA_SOLO_TRACK;
1282 }
1283 }
1284 else {
1285 adt->flag &= ~ADT_NLA_SOLO_TRACK;
1286 }
1287}
1288
1289void BKE_nlatrack_set_active(ListBaseT<NlaTrack> *tracks, NlaTrack *nlt_a)
1290{
1291 /* sanity check */
1292 if (ELEM(nullptr, tracks, tracks->first())) {
1293 return;
1294 }
1295
1296 /* deactivate all the rest */
1297 for (NlaTrack &nlt : *tracks) {
1298 nlt.flag &= ~NLATRACK_ACTIVE;
1299 }
1300
1301 /* set the given one as the active one */
1302 if (nlt_a) {
1303 nlt_a->flag |= NLATRACK_ACTIVE;
1304 }
1305}
1306
1307bool BKE_nlatrack_has_space(NlaTrack *nlt, float start, float end)
1308{
1309 /* sanity checks
1310 * - track must exist
1311 * - track must be editable
1312 * - bounds cannot be equal (0-length is nasty)
1313 */
1314 if ((nlt == nullptr) || (nlt->flag & NLATRACK_PROTECTED) || IS_EQF(start, end)) {
1315 return false;
1316 }
1317
1318 if (start > end) {
1319 puts("BKE_nlatrack_has_space() error... start and end arguments swapped");
1320 std::swap(start, end);
1321 }
1322
1323 /* check if there's any space left in the track for a strip of the given length */
1324 return BKE_nlastrips_has_space(&nlt->strips, start, end);
1325}
1326
1327bool BKE_nlatrack_has_strips(ListBaseT<NlaTrack> *tracks)
1328{
1329 /* sanity checks */
1330 if (tracks->is_empty()) {
1331 return false;
1332 }
1333
1334 /* Check each track for NLA strips. */
1335 for (NlaTrack &track : *tracks) {
1336 if (track.strips.count() > 0) {
1337 return true;
1338 }
1339 }
1340
1341 /* none found */
1342 return false;
1343}
1344
1346{
1347 /* sanity checks */
1348 if (ELEM(nullptr, nlt, nlt->strips.first())) {
1349 return;
1350 }
1351
1352 /* sort the strips with a more generic function */
1354}
1355
1356bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip, const bool is_liboverride)
1357{
1358 /* sanity checks */
1359 if (ELEM(nullptr, nlt, strip)) {
1360 return false;
1361 }
1362
1363 /*
1364 * Do not allow adding strips if this track is locked, or not a local one in liboverride case.
1365 */
1366 if (nlt->flag & NLATRACK_PROTECTED ||
1367 (is_liboverride && (nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0))
1368 {
1369 return false;
1370 }
1371
1372 /* try to add the strip to the track using a more generic function */
1373 return BKE_nlastrips_add_strip(&nlt->strips, strip);
1374}
1375
1377{
1378 BLI_assert(track);
1379 BKE_nlastrip_remove(&track->strips, strip);
1380}
1381
1383{
1384 NlaStrip *strip;
1385
1386 /* initialize bounds */
1387 if (bounds) {
1388 bounds[0] = bounds[1] = 0.0f;
1389 }
1390 else {
1391 return false;
1392 }
1393
1394 /* sanity checks */
1395 if (ELEM(nullptr, nlt, nlt->strips.first())) {
1396 return false;
1397 }
1398
1399 /* lower bound is first strip's start frame */
1400 strip = nlt->strips.first();
1401 bounds[0] = strip->start;
1402
1403 /* upper bound is last strip's end frame */
1404 strip = nlt->strips.last();
1405 bounds[1] = strip->end;
1406
1407 /* done */
1408 return true;
1409}
1410
1412{
1413 return (ID_IS_OVERRIDE_LIBRARY(id) &&
1414 (nlt == nullptr || (nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0));
1415}
1416
1417/* NLA Strips -------------------------------------- */
1418
1419static NlaStrip *nlastrip_find_active(ListBaseT<NlaStrip> *strips)
1420{
1421 for (NlaStrip &strip : *strips) {
1422 if (strip.flag & NLASTRIP_FLAG_ACTIVE) {
1423 return &strip;
1424 }
1425
1426 if (strip.type != NLASTRIP_TYPE_META) {
1427 continue;
1428 }
1429
1430 NlaStrip *inner_active = nlastrip_find_active(&strip.strips);
1431 if (inner_active != nullptr) {
1432 return inner_active;
1433 }
1434 }
1435
1436 return nullptr;
1437}
1438
1440{
1441 float limit_prev = MINAFRAMEF;
1442
1443 /* Find the previous end frame, with a special case if the previous strip was a transition : */
1444 if (strip->prev) {
1445 if (strip->prev->type == NLASTRIP_TYPE_TRANSITION) {
1446 limit_prev = strip->prev->start + NLASTRIP_MIN_LEN_THRESH;
1447 }
1448 else {
1449 limit_prev = strip->prev->end;
1450 }
1451 }
1452
1453 return limit_prev;
1454}
1455
1457{
1458 float limit_next = MAXFRAMEF;
1459
1460 /* Find the next begin frame, with a special case if the next strip's a transition : */
1461 if (strip->next) {
1462 if (strip->next->type == NLASTRIP_TYPE_TRANSITION) {
1463 limit_next = strip->next->end - NLASTRIP_MIN_LEN_THRESH;
1464 }
1465 else {
1466 limit_next = strip->next->start;
1467 }
1468 }
1469
1470 return limit_next;
1471}
1472
1473NlaStrip *BKE_nlastrip_next_in_track(NlaStrip *strip, bool skip_transitions)
1474{
1475 NlaStrip *next = strip->next;
1476 while (next != nullptr) {
1477 if (skip_transitions && (next->type == NLASTRIP_TYPE_TRANSITION)) {
1478 next = next->next;
1479 }
1480 else {
1481 return next;
1482 }
1483 }
1484 return nullptr;
1485}
1486
1487NlaStrip *BKE_nlastrip_prev_in_track(NlaStrip *strip, bool skip_transitions)
1488{
1489 NlaStrip *prev = strip->prev;
1490 while (prev != nullptr) {
1491 if (skip_transitions && (prev->type == NLASTRIP_TYPE_TRANSITION)) {
1492 prev = prev->prev;
1493 }
1494 else {
1495 return prev;
1496 }
1497 }
1498 return nullptr;
1499}
1500
1502{
1503 if (nlt == nullptr) {
1504 return nullptr;
1505 }
1506
1507 return nlastrip_find_active(&nlt->strips);
1508}
1509
1510void BKE_nlastrip_remove(ListBaseT<NlaStrip> *strips, NlaStrip *strip)
1511{
1512 BLI_assert(strips);
1513 BLI_remlink(strips, strip);
1514}
1515
1516void BKE_nlastrip_remove_and_free(ListBaseT<NlaStrip> *strips,
1517 NlaStrip *strip,
1518 const bool do_id_user)
1519{
1520 BKE_nlastrip_remove(strips, strip);
1521 BKE_nlastrip_free(strip, do_id_user);
1522}
1523
1525{
1526 /* sanity checks */
1527 if (adt == nullptr) {
1528 return;
1529 }
1530
1531 /* Loop over tracks, deactivating. */
1532 for (NlaTrack &nlt : adt->nla_tracks) {
1533 for (NlaStrip &nls : nlt.strips) {
1534 if (&nls != strip) {
1536 }
1537 else {
1539 }
1540 }
1541 }
1542}
1543
1544static NlaStrip *nlastrip_find_by_name(ListBaseT<NlaStrip> *strips, const char *name)
1545{
1546 for (NlaStrip &strip : *strips) {
1547 if (STREQ(strip.name, name)) {
1548 return &strip;
1549 }
1550
1551 if (strip.type != NLASTRIP_TYPE_META) {
1552 continue;
1553 }
1554
1555 NlaStrip *inner_strip = nlastrip_find_by_name(&strip.strips, name);
1556 if (inner_strip != nullptr) {
1557 return inner_strip;
1558 }
1559 }
1560
1561 return nullptr;
1562}
1563
1565{
1566 return nlastrip_find_by_name(&nlt->strips, name);
1567}
1568
1569bool BKE_nlastrip_within_bounds(NlaStrip *strip, float min, float max)
1570{
1571 const float stripLen = (strip) ? strip->end - strip->start : 0.0f;
1572 const float boundsLen = fabsf(max - min);
1573
1574 /* sanity checks */
1575 if ((strip == nullptr) || IS_EQF(stripLen, 0.0f) || IS_EQF(boundsLen, 0.0f)) {
1576 return false;
1577 }
1578
1579 /* only ok if at least part of the strip is within the bounding window
1580 * - first 2 cases cover when the strip length is less than the bounding area
1581 * - second 2 cases cover when the strip length is greater than the bounding area
1582 */
1583 if ((stripLen < boundsLen) &&
1584 !(IN_RANGE(strip->start, min, max) || IN_RANGE(strip->end, min, max)))
1585 {
1586 return false;
1587 }
1588 if ((stripLen > boundsLen) &&
1589 !(IN_RANGE(min, strip->start, strip->end) || IN_RANGE(max, strip->start, strip->end)))
1590 {
1591 return false;
1592 }
1593
1594 /* should be ok! */
1595 return true;
1596}
1597
1598float BKE_nlastrip_distance_to_frame(const NlaStrip *strip, const float timeline_frame)
1599{
1600 if (timeline_frame < strip->start) {
1601 return strip->start - timeline_frame;
1602 }
1603 if (strip->end < timeline_frame) {
1604 return timeline_frame - strip->end;
1605 }
1606 return 0.0f;
1607}
1608
1609/* Ensure that strip doesn't overlap those around it after resizing
1610 * by offsetting those which follow. */
1612{
1613 /* next strips - do this first, since we're often just getting longer */
1614 if (strip->next) {
1615 NlaStrip *nls = strip->next;
1616 float offset = 0.0f;
1617
1618 if (nls->type == NLASTRIP_TYPE_TRANSITION) {
1619 /* transition strips should grow/shrink to accommodate the resized strip,
1620 * but if the strip's bounds now exceed the transition, we're forced to
1621 * offset everything to maintain the balance
1622 */
1623 if (strip->end <= nls->start) {
1624 /* grow the transition to fill the void */
1625 nls->start = strip->end;
1626 }
1627 else if (strip->end < nls->end) {
1628 /* shrink the transition to give the strip room */
1629 nls->start = strip->end;
1630 }
1631 else {
1632 /* Shrink transition down to 1 frame long (so that it can still be found),
1633 * then offset everything else by the remaining deficit to give the strip room. */
1634 nls->start = nls->end - 1.0f;
1635
1636 /* XXX: review whether preventing fractional values is good here... */
1637 offset = ceilf(strip->end - nls->start);
1638
1639 /* apply necessary offset to ensure that the strip has enough space */
1640 for (; nls; nls = nls->next) {
1641 nls->start += offset;
1642 nls->end += offset;
1643 }
1644 }
1645 }
1646 else if (strip->end > nls->start) {
1647 /* NOTE: need to ensure we don't have a fractional frame offset, even if that leaves a gap,
1648 * otherwise it will be very hard to get rid of later
1649 */
1650 offset = ceilf(strip->end - nls->start);
1651
1652 /* apply to times of all strips in this direction */
1653 for (; nls; nls = nls->next) {
1654 nls->start += offset;
1655 nls->end += offset;
1656 }
1657 }
1658 }
1659
1660 /* previous strips - same routine as before */
1661 /* NOTE: when strip bounds are recalculated, this is not considered! */
1662 if (strip->prev) {
1663 NlaStrip *nls = strip->prev;
1664 float offset = 0.0f;
1665
1666 if (nls->type == NLASTRIP_TYPE_TRANSITION) {
1667 /* transition strips should grow/shrink to accommodate the resized strip,
1668 * but if the strip's bounds now exceed the transition, we're forced to
1669 * offset everything to maintain the balance
1670 */
1671 if (strip->start >= nls->end) {
1672 /* grow the transition to fill the void */
1673 nls->end = strip->start;
1674 }
1675 else if (strip->start > nls->start) {
1676 /* shrink the transition to give the strip room */
1677 nls->end = strip->start;
1678 }
1679 else {
1680 /* Shrink transition down to 1 frame long (so that it can still be found),
1681 * then offset everything else by the remaining deficit to give the strip room. */
1682 nls->end = nls->start + 1.0f;
1683
1684 /* XXX: review whether preventing fractional values is good here... */
1685 offset = ceilf(nls->end - strip->start);
1686
1687 /* apply necessary offset to ensure that the strip has enough space */
1688 for (; nls; nls = nls->prev) {
1689 nls->start -= offset;
1690 nls->end -= offset;
1691 }
1692 }
1693 }
1694 else if (strip->start < nls->end) {
1695 /* NOTE: need to ensure we don't have a fractional frame offset, even if that leaves a gap,
1696 * otherwise it will be very hard to get rid of later
1697 */
1698 offset = ceilf(nls->end - strip->start);
1699
1700 /* apply to times of all strips in this direction */
1701 for (; nls; nls = nls->prev) {
1702 nls->start -= offset;
1703 nls->end -= offset;
1704 }
1705 }
1706 }
1707}
1708
1710{
1711 float prev_actstart;
1712
1713 if (strip == nullptr || strip->type != NLASTRIP_TYPE_CLIP) {
1714 return;
1715 }
1716
1717 prev_actstart = strip->actstart;
1718
1719 const float2 frame_range = strip->act->wrap().get_frame_range_of_slot(strip->action_slot_handle);
1720 strip->actstart = frame_range[0];
1721 strip->actend = frame_range[1];
1722
1724
1725 /* Set start such that key's do not visually move, to preserve the overall animation result. */
1726 strip->start += (strip->actstart - prev_actstart) * strip->scale;
1727
1729}
1731{
1732 float mapping;
1733
1734 /* sanity checks
1735 * - must have a strip
1736 * - can only be done for action clips
1737 */
1738 if ((strip == nullptr) || (strip->type != NLASTRIP_TYPE_CLIP)) {
1739 return;
1740 }
1741
1742 /* calculate new length factors */
1743 const float actlen = BKE_nla_clip_length_get_nonzero(strip);
1744
1745 mapping = strip->scale * strip->repeat;
1746
1747 /* adjust endpoint of strip in response to this */
1748 if (IS_EQF(mapping, 0.0f) == 0) {
1749 strip->end = (actlen * mapping) + strip->start;
1750 }
1751
1752 /* make sure we don't overlap our neighbors */
1754}
1755
1757{
1758
1759 /* check if values need to be re-calculated. */
1760 if (strip->blendin == 0 && strip->blendout == 0) {
1761 return;
1762 }
1763
1764 const double strip_len = strip->end - strip->start;
1765 double blend_in = strip->blendin;
1766 double blend_out = strip->blendout;
1767
1768 double blend_in_max = strip_len - blend_out;
1769
1770 CLAMP_MIN(blend_in_max, 0);
1771
1772 /* blend-out is limited to the length of the strip. */
1773 CLAMP(blend_in, 0, blend_in_max);
1774 CLAMP(blend_out, 0, strip_len - blend_in);
1775
1776 strip->blendin = blend_in;
1777 strip->blendout = blend_out;
1778}
1779
1780/* Animated Strips ------------------------------------------- */
1781
1783{
1784 /* sanity checks */
1785 if (ELEM(nullptr, nlt, nlt->strips.first())) {
1786 return false;
1787 }
1788
1789 /* check each strip for F-Curves only (don't care about whether the flags are set) */
1790 for (NlaStrip &strip : nlt->strips) {
1791 if (strip.fcurves.first()) {
1792 return true;
1793 }
1794 }
1795
1796 /* none found */
1797 return false;
1798}
1799
1800bool BKE_nlatracks_have_animated_strips(ListBaseT<NlaTrack> *tracks)
1801{
1802 /* sanity checks */
1803 if (ELEM(nullptr, tracks, tracks->first())) {
1804 return false;
1805 }
1806
1807 /* check each track, stopping on the first hit */
1808 for (NlaTrack &nlt : *tracks) {
1810 return true;
1811 }
1812 }
1813
1814 /* none found */
1815 return false;
1816}
1817
1819{
1820 FCurve *fcu;
1821
1822 /* sanity checks */
1823 if (strip == nullptr) {
1824 return;
1825 }
1826
1827 /* if controlling influence... */
1828 if (strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) {
1829 /* try to get F-Curve */
1830 fcu = BKE_fcurve_find(&strip->fcurves, "influence", 0);
1831
1832 /* add one if not found */
1833 if (fcu == nullptr) {
1834 /* make new F-Curve */
1835 fcu = BKE_fcurve_create();
1836 BLI_addtail(&strip->fcurves, fcu);
1837
1838 /* set default flags */
1840 fcu->auto_smoothing = U.auto_smoothing_new;
1841
1842 /* store path - make copy, and store that */
1843 fcu->rna_path_set("influence");
1844
1845 /* insert keyframe to ensure current value stays on first refresh */
1846 fcu->bezt = MEM_new_zeroed<BezTriple>("nlastrip influence bezt");
1847 fcu->totvert = 1;
1848
1849 fcu->bezt->vec[1][0] = strip->start;
1850 fcu->bezt->vec[1][1] = strip->influence;
1851
1852 /* Respect User Preferences for default interpolation and handles. */
1853 fcu->bezt->h1 = fcu->bezt->h2 = U.keyhandles_new;
1854 fcu->bezt->ipo = U.ipo_new;
1855 }
1856 }
1857
1858 /* if controlling time... */
1859 if (strip->flag & NLASTRIP_FLAG_USR_TIME) {
1860 /* try to get F-Curve */
1861 fcu = BKE_fcurve_find(&strip->fcurves, "strip_time", 0);
1862
1863 /* add one if not found */
1864 if (fcu == nullptr) {
1865 /* make new F-Curve */
1866 fcu = BKE_fcurve_create();
1867 BLI_addtail(&strip->fcurves, fcu);
1868
1869 /* set default flags */
1871 fcu->auto_smoothing = U.auto_smoothing_new;
1872
1873 /* store path - make copy, and store that */
1874 fcu->rna_path_set("strip_time");
1875
1876 /* TODO: insert a few keyframes to ensure default behavior? */
1877 }
1878 }
1879}
1880
1882{
1883 const StringRefNull rna_path = fcurve->rna_path();
1884 if (rna_path == "strip_time") {
1885 strip->flag &= ~NLASTRIP_FLAG_USR_TIME;
1886 }
1887 else if (rna_path == "influence") {
1889 }
1890 else {
1891 return false;
1892 }
1893
1894 BLI_remlink(&strip->fcurves, fcurve);
1895 BKE_fcurve_free(fcurve);
1896 return true;
1897}
1898
1900{
1901 /* sanity checks */
1902 if (ELEM(nullptr, ptr, prop)) {
1903 return false;
1904 }
1905
1906 /* 1) Must be NLA strip */
1907 if (ptr->type == RNA_NlaStrip) {
1908 /* 2) Must be one of the predefined properties */
1909 static PropertyRNA *prop_influence = nullptr;
1910 static PropertyRNA *prop_time = nullptr;
1911 static bool needs_init = true;
1912
1913 /* Init the properties on first use */
1914 if (needs_init) {
1915 prop_influence = RNA_struct_type_find_property(RNA_NlaStrip, "influence");
1916 prop_time = RNA_struct_type_find_property(RNA_NlaStrip, "strip_time");
1917
1918 needs_init = false;
1919 }
1920
1921 /* Check if match */
1922 if (ELEM(prop, prop_influence, prop_time)) {
1923 return true;
1924 }
1925 }
1926
1927 /* No criteria met */
1928 return false;
1929}
1930
1931/* Sanity Validation ------------------------------------ */
1932
1934{
1935 GHash *gh;
1936
1937 /* sanity checks */
1938 if (ELEM(nullptr, adt, strip)) {
1939 return;
1940 }
1941
1942 /* give strip a default name if none already */
1943 if (strip->name[0] == 0) {
1944 switch (strip->type) {
1945 case NLASTRIP_TYPE_CLIP: /* act-clip */
1946 STRNCPY_UTF8(strip->name, (strip->act) ? (strip->act->id.name + 2) : DATA_("<No Action>"));
1947 break;
1948 case NLASTRIP_TYPE_TRANSITION: /* transition */
1949 STRNCPY_UTF8(strip->name, DATA_("Transition"));
1950 break;
1951 case NLASTRIP_TYPE_META: /* meta */
1953 break;
1954 default:
1955 STRNCPY_UTF8(strip->name, DATA_("NLA Strip"));
1956 break;
1957 }
1958 }
1959
1960 /* build a hash-table of all the strips in the tracks
1961 * - this is easier than iterating over all the tracks+strips hierarchy every time
1962 * (and probably faster)
1963 */
1964 gh = BLI_ghash_str_new("nlastrip_validate_name gh");
1965
1966 for (NlaTrack &nlt : adt->nla_tracks) {
1967 for (NlaStrip &tstrip : nlt.strips) {
1968 /* don't add the strip of interest */
1969 if (&tstrip == strip) {
1970 continue;
1971 }
1972
1973 /* Use the name of the strip as the key, and the strip as the value,
1974 * since we're mostly interested in the keys. */
1975 BLI_ghash_insert(gh, tstrip.name, &tstrip);
1976 }
1977 }
1978
1979 /* If the hash-table has a match for this name, try other names...
1980 * - In an extreme case, it might not be able to find a name,
1981 * but then everything else in Blender would fail too :).
1982 */
1984 [&](const StringRefNull check_name) { return BLI_ghash_haskey(gh, check_name.c_str()); },
1985 DATA_("NlaStrip"),
1986 '.',
1987 strip->name,
1988 sizeof(strip->name));
1989
1990 /* free the hash... */
1991 BLI_ghash_free(gh, nullptr, nullptr);
1992}
1993
1994/* ---- */
1995
1996/* Get strips which overlap the given one at the start/end of its range
1997 * - strip: strip that we're finding overlaps for
1998 * - track: nla-track that the overlapping strips should be found from
1999 * - start, end: frames for the offending endpoints
2000 */
2002 NlaTrack *track,
2003 float **start,
2004 float **end)
2005{
2006 /* find strips that overlap over the start/end of the given strip,
2007 * but which don't cover the entire length
2008 */
2009 /* TODO: this scheme could get quite slow for doing this on many strips... */
2010 for (NlaStrip &nls : track->strips) {
2011 /* Check if strip overlaps (extends over or exactly on)
2012 * the entire range of the strip we're validating. */
2013 if ((nls.start <= strip->start) && (nls.end >= strip->end)) {
2014 *start = nullptr;
2015 *end = nullptr;
2016 return;
2017 }
2018
2019 /* check if strip doesn't even occur anywhere near... */
2020 if (nls.end < strip->start) {
2021 continue; /* skip checking this strip... not worthy of mention */
2022 }
2023 if (nls.start > strip->end) {
2024 return; /* the range we're after has already passed */
2025 }
2026
2027 /* if this strip is not part of an island of continuous strips, it can be used
2028 * - this check needs to be done for each end of the strip we try and use...
2029 */
2030 if ((nls.next == nullptr) || IS_EQF(nls.next->start, nls.end) == 0) {
2031 if ((nls.end > strip->start) && (nls.end < strip->end)) {
2032 *start = &nls.end;
2033 }
2034 }
2035 if ((nls.prev == nullptr) || IS_EQF(nls.prev->end, nls.start) == 0) {
2036 if ((nls.start < strip->end) && (nls.start > strip->start)) {
2037 *end = &nls.start;
2038 }
2039 }
2040 }
2041}
2042
2043/* Determine auto-blending for the given strip */
2045{
2046 float *ps = nullptr, *pe = nullptr;
2047 float *ns = nullptr, *ne = nullptr;
2048
2049 /* sanity checks */
2050 if (ELEM(nullptr, nls, nlt)) {
2051 return;
2052 }
2053 if ((nlt->prev == nullptr) && (nlt->next == nullptr)) {
2054 return;
2055 }
2056 if ((nls->flag & NLASTRIP_FLAG_AUTO_BLENDS) == 0) {
2057 return;
2058 }
2059
2060 /* get test ranges */
2061 if (nlt->prev) {
2062 nlastrip_get_endpoint_overlaps(nls, nlt->prev, &ps, &pe);
2063 }
2064 if (nlt->next) {
2065 nlastrip_get_endpoint_overlaps(nls, nlt->next, &ns, &ne);
2066 }
2067
2068 /* set overlaps for this strip
2069 * - don't use the values obtained though if the end in question
2070 * is directly followed/preceded by another strip, forming an
2071 * 'island' of continuous strips
2072 */
2073 if ((ps || ns) && ((nls->prev == nullptr) || IS_EQF(nls->prev->end, nls->start) == 0)) {
2074 /* start overlaps - pick the largest overlap */
2075 if (((ps && ns) && (*ps > *ns)) || (ps)) {
2076 nls->blendin = *ps - nls->start;
2077 }
2078 else {
2079 nls->blendin = *ns - nls->start;
2080 }
2081 }
2082 else { /* no overlap allowed/needed */
2083 nls->blendin = 0.0f;
2084 }
2085
2086 if ((pe || ne) && ((nls->next == nullptr) || IS_EQF(nls->next->start, nls->end) == 0)) {
2087 /* end overlaps - pick the largest overlap */
2088 if (((pe && ne) && (*pe > *ne)) || (pe)) {
2089 nls->blendout = nls->end - *pe;
2090 }
2091 else {
2092 nls->blendout = nls->end - *ne;
2093 }
2094 }
2095 else { /* no overlap allowed/needed */
2096 nls->blendout = 0.0f;
2097 }
2098}
2099
2105static bool nlastrip_validate_transition_start_end(ListBaseT<NlaStrip> *strips, NlaStrip *strip)
2106{
2107
2108 if (!(strip->type == NLASTRIP_TYPE_TRANSITION)) {
2109 return true;
2110 }
2111 if (strip->prev) {
2112 strip->start = strip->prev->end;
2113 }
2114 if (strip->next) {
2115 strip->end = strip->next->start;
2116 }
2117 if (strip->start >= strip->end || strip->prev == nullptr || strip->next == nullptr) {
2118 BKE_nlastrip_remove_and_free(strips, strip, true);
2119 return false;
2120 }
2121 return true;
2122}
2123
2125{
2126 /* sanity checks */
2127 if (ELEM(nullptr, adt, adt->nla_tracks.first())) {
2128 return;
2129 }
2130
2131 /* Adjust blending values for auto-blending,
2132 * and also do an initial pass to find the earliest strip. */
2133 for (NlaTrack &nlt : adt->nla_tracks) {
2134 for (NlaStrip &strip : nlt.strips.items_mutable()) {
2135
2137 printf(
2138 "While moving NLA strips, a transition strip could no longer be applied to the new "
2139 "positions and was removed.\n");
2140 continue;
2141 }
2142
2143 /* auto-blending first */
2146 }
2147 }
2148}
2149
2150/* Action Stashing -------------------------------------- */
2151
2152/* name of stashed tracks - the translation stuff is included here to save extra work */
2153#define STASH_TRACK_NAME DATA_("[Action Stash]")
2154
2156 bAction *act,
2157 const animrig::slot_handle_t slot_handle)
2158{
2159 for (NlaTrack &nlt : adt->nla_tracks) {
2160 if (strstr(nlt.name, STASH_TRACK_NAME)) {
2161 for (NlaStrip &strip : nlt.strips) {
2162 if (strip.act == act && strip.action_slot_handle == slot_handle) {
2163 return true;
2164 }
2165 }
2166 }
2167 }
2168
2169 return false;
2170}
2171
2172bool BKE_nla_action_stash(const OwnedAnimData owned_adt, const bool is_liboverride)
2173{
2174 NlaTrack *prev_track = nullptr;
2175 NlaTrack *nlt;
2176 NlaStrip *strip;
2177 AnimData *adt = &owned_adt.adt;
2178
2179 /* sanity check */
2180 if (ELEM(nullptr, adt, adt->action)) {
2181 CLOG_ERROR(&LOG, "Invalid argument - %p %p", adt, adt->action);
2182 return false;
2183 }
2184
2185 /* do not add if it is already stashed */
2186 if (BKE_nla_action_slot_is_stashed(adt, adt->action, adt->slot_handle)) {
2187 return false;
2188 }
2189
2190 /* create a new track, and add this immediately above the previous stashing track */
2191 for (prev_track = adt->nla_tracks.last(); prev_track; prev_track = prev_track->prev) {
2192 if (strstr(prev_track->name, STASH_TRACK_NAME)) {
2193 break;
2194 }
2195 }
2196
2197 nlt = BKE_nlatrack_new_after(&adt->nla_tracks, prev_track, is_liboverride);
2199 BLI_assert(nlt != nullptr);
2200
2201 /* We need to ensure that if there wasn't any previous instance,
2202 * it must go to be bottom of the stack. */
2203 if (prev_track == nullptr) {
2204 BLI_remlink(&adt->nla_tracks, nlt);
2205 BLI_addhead(&adt->nla_tracks, nlt);
2206 }
2207
2210 &adt->nla_tracks, nlt, STASH_TRACK_NAME, '.', offsetof(NlaTrack, name), sizeof(nlt->name));
2211
2212 /* add the action as a strip in this new track
2213 * NOTE: a new user is created here
2214 */
2215 strip = BKE_nlastrip_new_for_slot(adt->action, adt->slot_handle, owned_adt.owner_id);
2216 BLI_assert(strip != nullptr);
2217
2218 BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
2219 BKE_nlastrip_validate_name(adt, strip);
2220
2221 /* mark the stash track and strip so that they doesn't disturb the stack animation,
2222 * and are unlikely to draw attention to itself (or be accidentally bumped around)
2223 *
2224 * NOTE: this must be done *after* adding the strip to the track, or else
2225 * the strip locking will prevent the strip from getting added
2226 */
2229
2230 /* also mark the strip for auto syncing the length, so that the strips accurately
2231 * reflect the length of the action
2232 * XXX: we could do with some extra flags here to prevent repeats/scaling options from working!
2233 */
2235
2236 /* succeeded */
2237 return true;
2238}
2239
2240/* Core Tools ------------------------------------------- */
2241
2242void BKE_nla_action_pushdown(const OwnedAnimData owned_adt, const bool is_liboverride)
2243{
2244 NlaStrip *strip;
2245 AnimData *adt = &owned_adt.adt;
2246
2247 /* sanity checks */
2248 /* TODO: need to report the error for this */
2249 if (ELEM(nullptr, adt, adt->action)) {
2250 return;
2251 }
2252
2253 /* Add a new NLA strip to the track, which references the active action + slot. */
2254 strip = BKE_nlastack_add_strip(owned_adt, is_liboverride);
2255 if (strip == nullptr) {
2256 return;
2257 }
2258
2259 /* Clear reference to action now that we've pushed it onto the stack. */
2260 const bool unassign_ok = animrig::unassign_action(owned_adt.owner_id);
2261 BLI_assert_msg(unassign_ok,
2262 "Expecting un-assigning an action to always work when pushing down an NLA strip");
2263 UNUSED_VARS_NDEBUG(unassign_ok);
2264
2265 /* copy current "action blending" settings from adt to the strip,
2266 * as it was keyframed with these settings, so omitting them will
2267 * change the effect [#54233]. */
2268 strip->blendmode = adt->act_blendmode;
2269 strip->influence = adt->act_influence;
2270 strip->extendmode = adt->act_extendmode;
2271
2272 if (adt->act_influence < 1.0f) {
2273 /* enable "user-controlled" influence (which will insert a default keyframe)
2274 * so that the influence doesn't get lost on the new update
2275 *
2276 * NOTE: An alternative way would have been to instead hack the influence
2277 * to not get always get reset to full strength if NLASTRIP_FLAG_USR_INFLUENCE
2278 * is disabled but auto-blending isn't being used. However, that approach
2279 * is a bit hacky/hard to discover, and may cause backwards compatibility issues,
2280 * so it's better to just do it this way.
2281 */
2284 }
2285
2286 /* make strip the active one... */
2287 BKE_nlastrip_set_active(adt, strip);
2288}
2289
2290static void nla_tweakmode_find_active(ListBaseT<NlaTrack> *nla_tracks,
2291 NlaTrack **r_track_of_active_strip,
2292 NlaStrip **r_active_strip)
2293{
2294 NlaTrack *activeTrack = nullptr;
2295 NlaStrip *activeStrip = nullptr;
2296
2297 /* go over the tracks, finding the active one, and its active strip
2298 * - if we cannot find both, then there's nothing to do
2299 */
2300 for (NlaTrack &nlt : *nla_tracks) {
2301 /* check if active */
2302 if (nlt.flag & NLATRACK_ACTIVE) {
2303 /* store reference to this active track */
2304 activeTrack = &nlt;
2305
2306 /* now try to find active strip */
2307 activeStrip = BKE_nlastrip_find_active(&nlt);
2308 break;
2309 }
2310 }
2311
2312 /* There are situations where we may have multiple strips selected and we want to enter
2313 * tweak-mode on all of those at once. Usually in those cases,
2314 * it will usually just be a single strip per AnimData.
2315 * In such cases, compromise and take the last selected track and/or last selected strip,
2316 * #28468.
2317 */
2318 if (activeTrack == nullptr) {
2319 /* try last selected track for active strip */
2320 for (NlaTrack &nlt : nla_tracks->items_reversed()) {
2321 if (nlt.flag & NLATRACK_SELECTED) {
2322 /* assume this is the active track */
2323 activeTrack = &nlt;
2324
2325 /* try to find active strip */
2326 activeStrip = BKE_nlastrip_find_active(&nlt);
2327 break;
2328 }
2329 }
2330 }
2331 if ((activeTrack) && (activeStrip == nullptr)) {
2332 /* No active strip in active or last selected track;
2333 * compromise for first selected (assuming only single). */
2334 for (NlaStrip &strip : activeTrack->strips) {
2336 activeStrip = &strip;
2337 break;
2338 }
2339 }
2340 }
2341
2342 *r_track_of_active_strip = activeTrack;
2343 *r_active_strip = activeStrip;
2344}
2345
2347{
2348 NlaTrack *activeTrack = nullptr;
2349 NlaStrip *activeStrip = nullptr;
2350 AnimData &adt = owned_adt.adt;
2351
2352 /* verify that data is valid */
2353 if (ELEM(nullptr, adt.nla_tracks.first())) {
2354 return false;
2355 }
2356
2357 /* If block is already in tweak-mode, just leave, but we should report
2358 * that this block is in tweak-mode (as our return-code). */
2359 if (adt.flag & ADT_NLA_EDIT_ON) {
2360 return true;
2361 }
2362
2363 nla_tweakmode_find_active(&adt.nla_tracks, &activeTrack, &activeStrip);
2364
2365 if (ELEM(nullptr, activeTrack, activeStrip, activeStrip->act)) {
2366 if (G.debug & G_DEBUG) {
2367 printf("NLA tweak-mode enter - neither active requirement found\n");
2368 printf("\tactiveTrack = %p, activeStrip = %p\n",
2369 static_cast<void *>(activeTrack),
2370 static_cast<void *>(activeStrip));
2371 }
2372 return false;
2373 }
2374
2375 /* Go over all the tracks, tagging each strip that uses the same
2376 * action as the active strip, but leaving everything else alone.
2377 */
2378 for (NlaTrack &nlt : adt.nla_tracks) {
2379 for (NlaStrip &strip : nlt.strips) {
2380 if (strip.act == activeStrip->act) {
2382 }
2383 else {
2385 }
2386 }
2387 }
2388
2389 /* Untag tweaked track. This leads to non tweaked actions being drawn differently than the
2390 * tweaked action. */
2391 activeStrip->flag &= ~NLASTRIP_FLAG_TWEAKUSER;
2392
2393 /* go over all the tracks after AND INCLUDING the active one, tagging them as being disabled
2394 * - the active track needs to also be tagged, otherwise, it'll overlap with the tweaks going
2395 * on.
2396 */
2397 activeTrack->flag |= NLATRACK_DISABLED;
2398 if ((adt.flag & ADT_NLA_EVAL_UPPER_TRACKS) == 0) {
2399 for (NlaTrack *nlt = activeTrack->next; nlt; nlt = nlt->next) {
2400 nlt->flag |= NLATRACK_DISABLED;
2401 }
2402 }
2403
2404 /* Remember which Action + Slot was previously assigned. This will be stored in adt.tmpact and
2405 * related properties further down. This doesn't manipulate `adt.tmpact` quite yet, so that the
2406 * assignment of the tweaked NLA strip's Action can happen normally (we're not in tweak mode
2407 * yet). */
2408 bAction *prev_action = adt.action;
2409 const animrig::slot_handle_t prev_slot_handle = adt.slot_handle;
2410
2411 if (activeStrip->act) {
2412 animrig::Action &strip_action = activeStrip->act->wrap();
2413 animrig::Slot *strip_slot = strip_action.slot_for_handle(activeStrip->action_slot_handle);
2414 if (animrig::assign_action_and_slot(&strip_action, strip_slot, owned_adt.owner_id) !=
2416 {
2417 printf("NLA tweak-mode enter - could not assign slot %s\n",
2418 strip_slot ? strip_slot->identifier : "-unassigned-");
2419 /* There is one other reason this could fail: when already in NLA tweak mode. But since
2420 * we're here in the code, the ADT_NLA_EDIT_ON flag is not yet set, and thus that shouldn't
2421 * be the case.
2422 *
2423 * Because this ADT is not in tweak mode, it means that the Action assignment will have
2424 * succeeded (I know, too much coupling here, would be better to have another
2425 * SlotAssignmentResult value for this). */
2426 }
2427 }
2428 else {
2429 /* This is a strange situation to be in, as every *tweak-able* NLA strip should have an Action.
2430 */
2432 const bool unassign_ok = animrig::unassign_action(owned_adt);
2433 BLI_assert_msg(unassign_ok,
2434 "Expecting un-assigning the Action to work (while entering NLA tweak mode)");
2435 UNUSED_VARS_NDEBUG(unassign_ok);
2436 }
2437
2438 /* Actually set those properties that make this 'NLA Tweak Mode'. */
2440 prev_action, prev_slot_handle, owned_adt);
2443 "Expecting the Action+Slot of an NLA strip to be suitable for direct assignment as well");
2445 adt.act_track = activeTrack;
2446 adt.actstrip = activeStrip;
2447 adt.flag |= ADT_NLA_EDIT_ON;
2448
2449 return true;
2450}
2451
2453{
2454 return adt && (adt->flag & ADT_NLA_EDIT_ON);
2455}
2456
2458{
2459 NlaStrip *active_strip = adt->actstrip;
2460 if (!active_strip || !active_strip->act) {
2461 return;
2462 }
2463
2464 /* sync the length of the user-strip with the new state of the action
2465 * but only if the user has explicitly asked for this to happen
2466 * (see #34645 for things to be careful about)
2467 */
2468 if (active_strip->flag & NLASTRIP_FLAG_SYNC_LENGTH) {
2470 }
2471
2472 /* Sync strip extents of strips using the same Action as the tweaked strip. */
2473 for (NlaTrack &nlt : adt->nla_tracks) {
2474 for (NlaStrip &strip : nlt.strips) {
2475 if ((strip.flag & NLASTRIP_FLAG_SYNC_LENGTH) && active_strip->act == strip.act) {
2477 }
2478 }
2479 }
2480}
2481
2487{
2489
2490 adt->action = adt->tmpact;
2491 adt->slot_handle = adt->tmp_slot_handle;
2492
2493 adt->tmpact = nullptr;
2496
2497 adt->act_track = nullptr;
2498 adt->actstrip = nullptr;
2499}
2500
2502{
2503 if (!is_nla_in_tweakmode(adt)) {
2504 return;
2505 }
2506
2508}
2509
2511{
2512 if (!is_nla_in_tweakmode(&owned_adt.adt)) {
2513 return;
2514 }
2515
2516 if (owned_adt.adt.action) {
2517 /* When a strip has no slot assigned, it can still enter tweak mode. Inserting a key will then
2518 * create a slot. When exiting tweak mode, this slot has to be assigned to the strip.
2519 * At this moment in time, the adt->action is still the one being tweaked. */
2520 NlaStrip *active_strip = owned_adt.adt.actstrip;
2521 if (active_strip && active_strip->action_slot_handle != owned_adt.adt.slot_handle) {
2523 *active_strip, owned_adt.adt.slot_handle, owned_adt.owner_id);
2525 "When exiting tweak mode, syncing the tweaked Action slot should work");
2527 }
2528
2529 /* The Action will be replaced with adt->tmpact, and thus needs to be unassigned first. */
2530
2531 /* The high-level function animrig::unassign_action() will check whether NLA tweak mode is
2532 * enabled, and if so, refuse to work (and rightfully so). However, exiting tweak mode is not
2533 * just setting a flag (see BKE_animdata_action_editable(), it checks for the tmpact pointer as
2534 * well). Because of that, here we call the low-level generic assignment function, to
2535 * circumvent that check and unconditionally unassign the tweaked Action. */
2536 const bool unassign_ok = animrig::generic_assign_action(owned_adt.owner_id,
2537 nullptr,
2538 owned_adt.adt.action,
2539 owned_adt.adt.slot_handle,
2540 owned_adt.adt.last_slot_identifier);
2541 BLI_assert_msg(unassign_ok,
2542 "When exiting tweak mode, unassigning the tweaked Action should work");
2543 UNUSED_VARS_NDEBUG(unassign_ok);
2544 }
2545
2548
2549 /* nla_tweakmode_exit_nofollowptr() does not follow any pointers, and thus cannot update the slot
2550 * user map. So it has to be done here now. This is safe to do here, as slot->users_add()
2551 * gracefully handles duplicates. */
2552 if (owned_adt.adt.action && owned_adt.adt.slot_handle != animrig::Slot::unassigned) {
2553 animrig::Action &action = owned_adt.adt.action->wrap();
2554 animrig::Slot *slot = action.slot_for_handle(owned_adt.adt.slot_handle);
2555 if (slot) {
2556 slot->users_add(owned_adt.owner_id);
2557 }
2558 }
2559}
2560
2562{
2563 for (NlaTrack &nlt : adt->nla_tracks) {
2564 nlt.flag &= ~NLATRACK_DISABLED;
2565
2566 for (NlaStrip &strip : nlt.strips) {
2568 }
2569 }
2570 adt->flag &= ~ADT_NLA_EDIT_ON;
2571}
2572
2574{
2575 if (!adt) {
2576 adt = BKE_animdata_from_id(owner_id);
2577 }
2578 printf("\033[38;5;214mNLA state");
2579 if (owner_id) {
2580 printf(" for %s", owner_id->name);
2581 }
2582 printf("\033[0m\n");
2583
2584 if (!adt) {
2585 printf(" - ADT is nil!\n");
2586 return;
2587 }
2588
2589 printf(" - ADT flags:");
2590 if (adt->flag & ADT_NLA_SOLO_TRACK) {
2591 printf(" SOLO_TRACK");
2592 }
2593 if (adt->flag & ADT_NLA_EVAL_OFF) {
2594 printf(" EVAL_OFF");
2595 }
2596 if (adt->flag & ADT_NLA_EDIT_ON) {
2597 printf(" EDIT_ON");
2598 }
2599 if (adt->flag & ADT_NLA_EDIT_NOMAP) {
2600 printf(" EDIT_NOMAP");
2601 }
2602 if (adt->flag & ADT_NLA_SKEYS_COLLAPSED) {
2603 printf(" SKEYS_COLLAPSED");
2604 }
2605 if (adt->flag & ADT_NLA_EVAL_UPPER_TRACKS) {
2606 printf(" EVAL_UPPER_TRACKS");
2607 }
2610 {
2611 printf(" -");
2612 }
2613 printf("\n");
2614
2615 if (adt->nla_tracks.is_empty()) {
2616 printf(" - No tracks\n");
2617 return;
2618 }
2619 printf(" - Active track: %s (#%d)\n",
2620 adt->act_track ? adt->act_track->name : "-nil-",
2621 adt->act_track ? adt->act_track->index : 0);
2622 printf(" - Active strip: %s\n", adt->actstrip ? adt->actstrip->name : "-nil-");
2623
2624 for (NlaTrack &nlt : adt->nla_tracks) {
2625 printf(" - Track #%d %s: ", nlt.index, nlt.name);
2626 if (nlt.flag & NLATRACK_ACTIVE) {
2627 printf("ACTIVE ");
2628 }
2629 if (nlt.flag & NLATRACK_SELECTED) {
2630 printf("SELECTED ");
2631 }
2632 if (nlt.flag & NLATRACK_MUTED) {
2633 printf("MUTED ");
2634 }
2635 if (nlt.flag & NLATRACK_SOLO) {
2636 printf("SOLO ");
2637 }
2638 if (nlt.flag & NLATRACK_PROTECTED) {
2639 printf("PROTECTED ");
2640 }
2641 if (nlt.flag & NLATRACK_DISABLED) {
2642 printf("DISABLED ");
2643 }
2644 if (nlt.flag & NLATRACK_TEMPORARILY_ADDED) {
2645 printf("TEMPORARILY_ADDED ");
2646 }
2648 printf("OVERRIDELIBRARY_LOCAL ");
2649 }
2650 printf("\n");
2651
2652 for (NlaStrip &strip : nlt.strips) {
2653 printf(" - Strip %s: ", strip.name);
2654 if (strip.flag & NLASTRIP_FLAG_ACTIVE) {
2655 printf("ACTIVE ");
2656 }
2657 if (strip.flag & NLASTRIP_FLAG_SELECT) {
2658 printf("SELECT ");
2659 }
2660 if (strip.flag & NLASTRIP_FLAG_TWEAKUSER) {
2661 printf("TWEAKUSER ");
2662 }
2663 if (strip.flag & NLASTRIP_FLAG_USR_INFLUENCE) {
2664 printf("USR_INFLUENCE ");
2665 }
2666 if (strip.flag & NLASTRIP_FLAG_USR_TIME) {
2667 printf("USR_TIME ");
2668 }
2669 if (strip.flag & NLASTRIP_FLAG_USR_TIME_CYCLIC) {
2670 printf("USR_TIME_CYCLIC ");
2671 }
2672 if (strip.flag & NLASTRIP_FLAG_SYNC_LENGTH) {
2673 printf("SYNC_LENGTH ");
2674 }
2675 if (strip.flag & NLASTRIP_FLAG_AUTO_BLENDS) {
2676 printf("AUTO_BLENDS ");
2677 }
2678 if (strip.flag & NLASTRIP_FLAG_REVERSE) {
2679 printf("REVERSE ");
2680 }
2681 if (strip.flag & NLASTRIP_FLAG_MUTED) {
2682 printf("MUTED ");
2683 }
2685 printf("INVALID_LOCATION ");
2686 }
2687 if (strip.flag & NLASTRIP_FLAG_NO_TIME_MAP) {
2688 printf("NO_TIME_MAP ");
2689 }
2690 if (strip.flag & NLASTRIP_FLAG_TEMP_META) {
2691 printf("TEMP_META ");
2692 }
2693 if (strip.flag & NLASTRIP_FLAG_EDIT_TOUCHED) {
2694 printf("EDIT_TOUCHED ");
2695 }
2696 printf("\n");
2697 }
2698 }
2699}
2700
2701static void blend_write_nla_strips(BlendWriter *writer, ListBaseT<NlaStrip> *strips)
2702{
2703 writer->write_struct_list(strips);
2704 for (NlaStrip &strip : *strips) {
2705 /* write the strip's F-Curves and modifiers */
2706 BKE_fcurve_blend_write_listbase(writer, &strip.fcurves);
2707 BKE_fmodifiers_blend_write(writer, &strip.modifiers);
2708
2709 /* write the strip's children */
2710 blend_write_nla_strips(writer, &strip.strips);
2711 }
2712}
2713
2714static void blend_data_read_nla_strips(BlendDataReader *reader, ListBaseT<NlaStrip> *strips)
2715{
2716 for (NlaStrip &strip : *strips) {
2717 /* strip's child strips */
2718 BLO_read_struct_list(reader, NlaStrip, &strip.strips);
2719 blend_data_read_nla_strips(reader, &strip.strips);
2720
2721 /* strip's F-Curves */
2722 BLO_read_struct_list(reader, FCurve, &strip.fcurves);
2723 BKE_fcurve_blend_read_data_listbase(reader, &strip.fcurves);
2724
2725 /* strip's F-Modifiers */
2726 BLO_read_struct_list(reader, FModifier, &strip.modifiers);
2727 BKE_fmodifiers_blend_read_data(reader, &strip.modifiers, nullptr);
2728 }
2729}
2730
2731void BKE_nla_blend_write(BlendWriter *writer, ListBaseT<NlaTrack> *tracks)
2732{
2733 /* write all the tracks */
2734 for (NlaTrack &nlt : *tracks) {
2735 /* write the track first */
2736 writer->write_struct(&nlt);
2737
2738 /* write the track's strips */
2739 blend_write_nla_strips(writer, &nlt.strips);
2740 }
2741}
2742
2743void BKE_nla_blend_read_data(BlendDataReader *reader, ID *id_owner, ListBaseT<NlaTrack> *tracks)
2744{
2745 for (NlaTrack &nlt : *tracks) {
2746 /* If linking from a library, clear 'local' library override flag. */
2747 if (ID_IS_LINKED(id_owner)) {
2749 }
2750
2751 /* relink list of strips */
2752 BLO_read_struct_list(reader, NlaStrip, &nlt.strips);
2753
2754 /* relink strip data */
2755 blend_data_read_nla_strips(reader, &nlt.strips);
2756 }
2757}
2758
2760{
2761 /* TODO(Sybren): replace these two parameters with an OwnedAnimData struct. */
2762 BLI_assert(id);
2763 BLI_assert(adt);
2764
2765 /* The 'id' parameter is unused as it's not necessary here, but still can be useful when
2766 * debugging. And with the NLA complexity the way it is, debugging comfort is kinda nice. */
2768
2769 const bool is_tweak_mode = (adt->flag & ADT_NLA_EDIT_ON);
2770 const bool has_tracks = !adt->nla_tracks.is_empty();
2771
2772 if (!has_tracks) {
2773 if (is_tweak_mode) {
2774 /* No tracks, so it's impossible to actually be in tweak mode. */
2775 BKE_nla_tweakmode_exit({*id, *adt});
2776 }
2777 return;
2778 }
2779
2780 if (!is_tweak_mode) {
2781 /* Library-linked data should already have been cleared of NLA Tweak Mode flags, and the
2782 * overrides also didn't set tweak mode enabled. Assuming here that the override-added
2783 * tracks/strips are consistent with the override's tweak mode flag. */
2784 return;
2785 }
2786
2787 /* In tweak mode, with tracks, so ensure that the active track/strip pointers are correct. Since
2788 * these pointers may come from a library, but the override may have added other tracks and
2789 * strips (one of which is in tweak mode), always look up the current pointer values. */
2791 if (!adt->act_track || !adt->actstrip) {
2792 /* Could not find the active track/strip, so better to exit tweak mode. */
2793 BKE_nla_tweakmode_exit({*id, *adt});
2794 }
2795}
2796
2797static bool visit_strip(NlaStrip *strip, FunctionRef<bool(NlaStrip *)> callback)
2798{
2799 if (!callback(strip)) {
2800 return false;
2801 }
2802
2803 /* Recurse into sub-strips. */
2804 for (NlaStrip &sub_strip : strip->strips) {
2805 if (!visit_strip(&sub_strip, callback)) {
2806 return false;
2807 }
2808 }
2809 return true;
2810}
2811
2812namespace bke::nla {
2813
2814bool foreach_strip(ID *id, FunctionRef<bool(NlaStrip *)> callback)
2815{
2816 const AnimData *adt = BKE_animdata_from_id(id);
2817 if (!adt) {
2818 /* Having no NLA trivially means that we've looped through all the strips. */
2819 return true;
2820 }
2821 return foreach_strip_adt(*adt, callback);
2822}
2823
2824bool foreach_strip_adt(const AnimData &adt, FunctionRef<bool(NlaStrip *)> callback)
2825{
2826 for (NlaTrack &nlt : adt.nla_tracks) {
2827 for (NlaStrip &strip : nlt.strips) {
2828 if (!visit_strip(&strip, callback)) {
2829 return false;
2830 }
2831 }
2832 }
2833 return true;
2834}
2835
2836} // namespace bke::nla
2837} // namespace blender
Blender kernel action and pose functionality.
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define NLASTRIP_MIN_LEN_THRESH
Definition BKE_nla.hh:12
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLT_I18NCONTEXT_ID_ACTION
#define CTX_DATA_(context, msgid)
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define MAXFRAMEF
#define MINAFRAMEF
Read Blender memory allocation and freeing.
#define STASH_TRACK_NAME
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define IN_RANGE(a, b, c)
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define IS_EQF(a, b)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
btScalar max
constexpr const char * c_str() const
bool is_cyclic() const ATTR_WARN_UNUSED_RESULT
Slot * slot_for_handle(slot_handle_t handle)
void users_add(ID &animated_id)
static constexpr slot_handle_t unassigned
#define fmodf(x, y)
#define offsetof(t, d)
#define ceil
float length(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
ActionSlotAssignmentResult assign_action_slot_handle(NlaStrip &strip, slot_handle_t slot_handle, ID &animated_id)
bool assign_action(NlaStrip &strip, Action &action, ID &animated_id)
decltype(blender::ActionSlot::handle) slot_handle_t
ActionSlotAssignmentResult assign_tmpaction_and_slot_handle(bAction *action, slot_handle_t slot_handle, OwnedAnimData owned_adt)
bool generic_assign_action(ID &animated_id, bAction *action_to_assign, bAction *&action_ptr_ref, slot_handle_t &slot_handle_ref, char *slot_identifier)
ActionSlotAssignmentResult assign_action_and_slot(Action *action, Slot *slot_to_assign, ID &animated_id)
bool unassign_action(ID &animated_id)
bool foreach_strip(ID *id, FunctionRef< bool(NlaStrip *)> callback)
bool foreach_strip_adt(const AnimData &adt, FunctionRef< bool(NlaStrip *)> callback)
BMesh Iterators.
float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_nlastrips_add_strip_unsafe(ListBaseT< NlaStrip > *strips, NlaStrip *strip)
NlaTrack * BKE_nlatrack_new_head(ListBaseT< NlaTrack > *nla_tracks, bool is_liboverride)
@ NLATRACK_OVERRIDELIBRARY_LOCAL
@ NLATRACK_TEMPORARILY_ADDED
static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short mode)
static bool is_nla_in_tweakmode(AnimData *adt)
bool BKE_nlatrack_has_animated_strips(NlaTrack *nlt)
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
NlaStrip * BKE_nlastrip_find_by_name(NlaTrack *nlt, const char *name)
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BKE_nlastrip_recalculate_blend(NlaStrip *strip)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
void BKE_nlameta_flush_transforms(NlaStrip *mstrip)
void id_us_plus(ID *id)
Definition lib_id.cc:433
void BKE_nlatrack_free(NlaTrack *nlt, bool do_id_user)
NlaStrip * BKE_nla_add_soundstrip(Main *bmain, Scene *scene, Speaker *speaker)
@ NLASTRIP_FLAG_USR_INFLUENCE
@ NLASTRIP_FLAG_REVERSE
@ NLASTRIP_FLAG_USR_TIME
@ NLASTRIP_FLAG_NO_TIME_MAP
@ NLASTRIP_FLAG_USR_TIME_CYCLIC
@ NLASTRIP_FLAG_SELECT
@ NLASTRIP_FLAG_TWEAKUSER
@ NLASTRIP_FLAG_EDIT_TOUCHED
@ NLASTRIP_FLAG_ACTIVE
@ NLASTRIP_FLAG_MUTED
@ NLASTRIP_FLAG_SYNC_LENGTH
@ NLASTRIP_FLAG_INVALID_LOCATION
@ NLASTRIP_FLAG_AUTO_BLENDS
@ NLASTRIP_FLAG_TEMP_META
struct NlaTrack * BKE_nlatrack_new()
void BKE_fcurves_free(ListBaseT< FCurve > *list)
void BKE_nlatrack_set_active(ListBaseT< NlaTrack > *tracks, NlaTrack *nlt)
void BKE_nla_blend_read_data(BlendDataReader *reader, ID *id_owner, ListBaseT< NlaTrack > *tracks)
@ NLASTRIP_EXTEND_NOTHING
bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip, bool is_liboverride)
void copy_fmodifiers(ListBaseT< FModifier > *dst, const ListBaseT< FModifier > *src)
eNlaTime_ConvertModes
Definition BKE_nla.hh:555
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
@ NLATIME_CONVERT_MAP
Definition BKE_nla.hh:563
@ ADT_NLA_EVAL_UPPER_TRACKS
@ ADT_NLA_SKEYS_COLLAPSED
float BKE_nla_clip_length_get_nonzero(const NlaStrip *strip)
void BKE_fcurve_blend_read_data_listbase(BlendDataReader *reader, ListBaseT< FCurve > *fcurves)
void BKE_fcurve_foreach_id(FCurve *fcu, LibraryForeachIDData *data)
NlaTrack * BKE_nlatrack_find_active(ListBaseT< NlaTrack > *tracks)
NlaTrack * BKE_nlatrack_find_tweaked(AnimData *adt)
static NlaStrip * find_active_strip_from_listbase(const NlaStrip *active_strip, const ListBaseT< NlaStrip > *strips_source, const ListBaseT< NlaStrip > *strips_dest)
static NlaStrip * nlastrip_new(bAction *act, ID &animated_id)
bool BKE_sound_info_get(Main *main, bSound *sound, SoundInfo *sound_info)
static NlaStrip * nlastrip_find_by_name(ListBaseT< NlaStrip > *strips, const char *name)
void BKE_fcurve_blend_write_listbase(BlendWriter *writer, ListBaseT< FCurve > *fcurves)
void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip)
void BKE_fmodifiers_blend_write(BlendWriter *writer, ListBaseT< FModifier > *fmodifiers)
void BKE_nla_liboverride_post_process(ID *id, AnimData *adt)
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
void BKE_nlastrip_validate_fcurves(NlaStrip *strip)
NlaTrack * BKE_nlatrack_new_before(ListBaseT< NlaTrack > *nla_tracks, NlaTrack *next, bool is_liboverride)
static bool nlastrip_validate_transition_start_end(ListBaseT< NlaStrip > *strips, NlaStrip *strip)
void BKE_nla_tweakmode_exit(OwnedAnimData owned_adt)
Global G
Definition blender.cc:57
bool BKE_nlatrack_get_bounds(NlaTrack *nlt, float bounds[2])
static void nla_tweakmode_exit_nofollowptr(AnimData *adt)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
NlaStrip * BKE_nlastrip_new(bAction *act, ID &animated_id)
bool BKE_nlatrack_is_nonlocal_in_liboverride(const ID *id, const NlaTrack *nlt)
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
void BKE_nla_strip_foreach_id(NlaStrip *strip, LibraryForeachIDData *data)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
bool BKE_nlastrip_has_curves_for_property(const PointerRNA *ptr, const PropertyRNA *prop)
bool BKE_nlastrip_controlcurve_remove(NlaStrip *strip, FCurve *fcurve)
void BKE_nla_clip_length_ensure_nonzero(const float *actstart, float *r_actend)
VecBase< float, 2 > float2
void BKE_nla_validate_state(AnimData *adt)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool BKE_nlatrack_has_strips(ListBaseT< NlaTrack > *tracks)
void BKE_fcurves_copy(ListBaseT< FCurve > *dst, ListBaseT< FCurve > *src)
bool BKE_nlatrack_is_enabled(const AnimData &adt, const NlaTrack &nlt)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void BKE_nla_tracks_free(ListBaseT< NlaTrack > *tracks, bool do_id_user)
NlaStrip * BKE_nlastrip_find_active(NlaTrack *nlt)
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
NlaStrip * BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, bool use_same_action, int flag)
bool BKE_nlastrips_has_space(ListBaseT< NlaStrip > *strips, float start, float end)
@ NLASTRIP_TYPE_SOUND
@ NLASTRIP_TYPE_TRANSITION
void BKE_nla_action_pushdown(OwnedAnimData owned_adt, bool is_liboverride)
float BKE_nlastrip_compute_frame_to_next_strip(NlaStrip *strip)
NlaTrack * BKE_nlatrack_new_tail(ListBaseT< NlaTrack > *nla_tracks, const bool is_liboverride)
NlaTrack * BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, bool use_same_actions, int flag)
void BKE_nla_tracks_copy(Main *bmain, ListBaseT< NlaTrack > *dst, const ListBaseT< NlaTrack > *src, int flag)
void BKE_nla_tweakmode_clear_flags(AnimData *adt)
bool BKE_nla_action_slot_is_stashed(AnimData *adt, bAction *act, animrig::slot_handle_t slot_handle)
static bool visit_strip(NlaStrip *strip, FunctionRef< bool(NlaStrip *)> callback)
NlaStrip * BKE_nlastrip_next_in_track(NlaStrip *strip, bool skip_transitions)
void BKE_nlatrack_solo_toggle(AnimData *adt, NlaTrack *nlt)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
static void update_active_track(AnimData *adt_dest, const AnimData *adt_source)
void BKE_nlatrack_insert_before(ListBaseT< NlaTrack > *nla_tracks, NlaTrack *next, NlaTrack *new_track, bool is_liboverride)
void BKE_nlastrips_sort_strips(ListBaseT< NlaStrip > *strips)
bool BKE_nlastrip_within_bounds(NlaStrip *strip, float min, float max)
static void blend_write_nla_strips(BlendWriter *writer, ListBaseT< NlaStrip > *strips)
void BKE_nla_blend_write(BlendWriter *writer, ListBaseT< NlaTrack > *tracks)
void BKE_nlastrip_set_active(AnimData *adt, NlaStrip *strip)
void free_fmodifiers(ListBaseT< FModifier > *modifiers)
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:378
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
float BKE_nlastrip_compute_frame_from_previous_strip(NlaStrip *strip)
void BKE_nlastrip_recalculate_bounds_sync_action(NlaStrip *strip)
void BKE_nlastrips_clear_metas(ListBaseT< NlaStrip > *strips, bool only_sel, bool only_temp)
NlaStrip * BKE_nlastrip_prev_in_track(NlaStrip *strip, bool skip_transitions)
static void nla_tweakmode_exit_sync_strip_lengths(AnimData *adt)
void BKE_nla_tweakmode_exit_nofollowptr(AnimData *adt)
static void blend_data_read_nla_strips(BlendDataReader *reader, ListBaseT< NlaStrip > *strips)
void BKE_fcurve_free(FCurve *fcu)
NlaTrack * BKE_nlatrack_new_after(ListBaseT< NlaTrack > *nla_tracks, NlaTrack *prev, bool is_liboverride)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static void nla_tweakmode_find_active(ListBaseT< NlaTrack > *nla_tracks, NlaTrack **r_track_of_active_strip, NlaStrip **r_active_strip)
static void update_active_strip(AnimData *adt_dest, NlaTrack *track_dest, const AnimData *adt_source, const NlaTrack *track_source)
void BKE_nlastrip_recalculate_bounds(NlaStrip *strip)
static float nlastrip_get_frame_transition(NlaStrip *strip, float cframe, short mode)
void BKE_nlatrack_remove_strip(NlaTrack *track, NlaStrip *strip)
NlaStrip * BKE_nlastrip_new_for_slot(bAction *act, animrig::slot_handle_t slot_handle, ID &animated_id)
void BKE_fmodifiers_blend_read_data(BlendDataReader *reader, ListBaseT< FModifier > *fmodifiers, FCurve *curve)
bool BKE_nlastrips_add_strip(ListBaseT< NlaStrip > *strips, NlaStrip *strip)
void BKE_nlastrip_remove(ListBaseT< NlaStrip > *strips, NlaStrip *strip)
void BKE_nlatrack_remove_and_free(ListBaseT< NlaTrack > *tracks, NlaTrack *nlt, bool do_id_user)
static CLG_LogRef LOG
Definition logging.cpp:12
NlaStrip * BKE_nlastack_add_strip(OwnedAnimData owned_adt, const bool is_liboverride)
void BKE_nla_debug_print_flags(AnimData *adt, ID *owner_id)
void BKE_nlatrack_sort_strips(NlaTrack *nlt)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
static void nlastrip_set_initial_length(NlaStrip *strip)
void BKE_nlastrips_make_metas(ListBaseT< NlaStrip > *strips, bool is_temp)
static void BKE_nlastrip_validate_autoblends(NlaTrack *nlt, NlaStrip *nls)
FCurve * BKE_fcurve_find(ListBaseT< FCurve > *list, const char rna_path[], int array_index)
bool BKE_nlatrack_has_space(NlaTrack *nlt, float start, float end)
static NlaStrip * nlastrip_find_active(ListBaseT< NlaStrip > *strips)
bool BKE_nlameta_add_strip(NlaStrip *mstrip, NlaStrip *strip)
void id_us_min(ID *id)
Definition lib_id.cc:441
bool BKE_nla_action_stash(OwnedAnimData owned_adt, bool is_liboverride)
bool BLI_ghash_haskey(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:825
void BKE_nlastrips_clear_metastrip(ListBaseT< NlaStrip > *strips, NlaStrip *strip)
void BKE_nlastrip_remove_and_free(ListBaseT< NlaStrip > *strips, NlaStrip *strip, const bool do_id_user)
static void nlastrip_fix_resize_overlaps(NlaStrip *strip)
bool BKE_nla_tweakmode_enter(OwnedAnimData owned_adt)
void BKE_nlatrack_remove(ListBaseT< NlaTrack > *tracks, NlaTrack *nlt)
FCurve * BKE_fcurve_create()
static void nlastrip_get_endpoint_overlaps(NlaStrip *strip, NlaTrack *track, float **start, float **end)
float BKE_nlastrip_distance_to_frame(const NlaStrip *strip, float timeline_frame)
bool BKE_nlatracks_have_animated_strips(ListBaseT< NlaTrack > *tracks)
void BKE_nlastrip_free(NlaStrip *strip, bool do_id_user)
void BKE_nlatrack_insert_after(ListBaseT< NlaTrack > *nla_tracks, NlaTrack *prev, NlaTrack *new_track, bool is_liboverride)
void BKE_nla_tracks_copy_from_adt(Main *bmain, AnimData *adt_dest, const AnimData *adt_source, int flag)
#define floorf
#define fabsf
#define ceilf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
char tmp_last_slot_identifier[258]
eNlaStrip_Blend_Mode act_blendmode
char last_slot_identifier[258]
eNlaStrip_Extrapolate_Mode act_extendmode
eAnimData_Flag flag
ListBaseT< NlaTrack > nla_tracks
eBezTriple_Handle h2
eBezTriple_Interpolation ipo
eBezTriple_Handle h1
void write_struct_list(const ListBaseT< T > *list, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
eFCurve_Flags flag
eFCurve_Smoothing auto_smoothing
unsigned int totvert
char name[258]
Definition DNA_ID.h:433
struct NlaStrip * next
NlaStripRuntime * runtime
eNlaStrip_Blend_Mode blendmode
ListBaseT< FCurve > fcurves
ListBaseT< FModifier > modifiers
eNlaStrip_Extrapolate_Mode extendmode
eNlaStrip_Flag flag
ListBaseT< NlaStrip > strips
eNlaStrip_Type type
struct NlaStrip * prev
struct NlaTrack * prev
eNlaTrack_Flag flag
ListBaseT< NlaStrip > strips
struct NlaTrack * next
StructRNA * type
Definition RNA_types.hh:63
struct bSound * sound