Blender V5.3
animation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "DNA_anim_types.h"
12#include "DNA_scene_types.h"
13#include "DNA_sequence_types.h"
14
15#include "BKE_fcurve.hh"
16
17#include "BLI_listbase.hh"
18
19#include "DEG_depsgraph.hh"
20
21#include "SEQ_animation.hh"
22
23namespace blender::seq {
24
26{
27 return scene->adt != nullptr && scene->adt->action != nullptr &&
28 scene->adt->action->wrap().has_keyframes(scene->adt->slot_handle);
29}
30
32{
33 return scene->adt != nullptr && !scene->adt->drivers.is_empty();
34}
35
36bool fcurve_matches(const Strip &strip, const FCurve &fcurve)
37{
39 fcurve, "sequence_editor.strips_all[", strip.name + 2);
40}
41
42void offset_animdata(const Scene *scene, Strip *strip, float ofs)
43{
44 if (!animation_keyframes_exist(scene) || ofs == 0.0f) {
45 return;
46 }
47
49 scene->adt->action, scene->adt->slot_handle, [&](const FCurve &fcurve) {
50 return fcurve_matches(*strip, fcurve);
51 });
52
53 for (FCurve *fcu : fcurves) {
54 uint i;
55 if (fcu->bezt) {
56 for (i = 0; i < fcu->totvert; i++) {
57 BezTriple *bezt = &fcu->bezt[i];
58 bezt->vec[0][0] += ofs;
59 bezt->vec[1][0] += ofs;
60 bezt->vec[2][0] += ofs;
61 }
62 }
63 if (fcu->fpt) {
64 for (i = 0; i < fcu->totvert; i++) {
65 FPoint *fpt = &fcu->fpt[i];
66 fpt->vec[0] += ofs;
67 }
68 }
69 }
70
72}
73
74void free_animdata(Scene *scene, Strip *strip)
75{
76 if (!animation_keyframes_exist(scene)) {
77 return;
78 }
79
81 scene->adt->action, scene->adt->slot_handle, [&](const FCurve &fcurve) {
82 return fcurve_matches(*strip, fcurve);
83 });
84
85 animrig::Action &action = scene->adt->action->wrap();
86 for (FCurve *fcu : fcurves) {
87 action_fcurve_remove(action, *fcu);
88 }
89}
90
92{
93 if (animation_keyframes_exist(scene)) {
94 animrig::Action &action = scene->adt->action->wrap();
95
97
99 action, scene->adt->slot_handle))
100 {
101 animrig::channelbag_fcurves_move(backup->channelbag, *channelbag);
102 }
103 }
104
105 if (animation_drivers_exist(scene)) {
106 BLI_movelisttolist(&backup->drivers, &scene->adt->drivers);
107 }
108}
109
111{
112 if (!backup->channelbag.fcurves().is_empty()) {
113 BLI_assert(scene->adt != nullptr && scene->adt->action != nullptr);
114
115 animrig::Action &action = scene->adt->action->wrap();
116
118
120 scene->adt->slot_handle);
121 /* The channel bag should exist if we got here, because otherwise the
122 * backup channel bag would have been empty. */
123 BLI_assert(channelbag != nullptr);
124
125 animrig::channelbag_fcurves_move(*channelbag, backup->channelbag);
126 }
127
128 if (!backup->drivers.is_empty()) {
129 BLI_assert(scene->adt != nullptr);
130 BLI_movelisttolist(&scene->adt->drivers, &backup->drivers);
131 }
132}
133
138 animrig::Action &dst,
139 const animrig::slot_handle_t dst_slot_handle,
140 AnimationBackup *src)
141{
142 if (strip->type == STRIP_TYPE_META) {
143 for (Strip &meta_child : strip->seqbase) {
144 strip_animation_duplicate(&meta_child, dst, dst_slot_handle, src);
145 }
146 }
147
149 src->channelbag.fcurves(),
150 [&](const FCurve &fcurve) { return fcurve_matches(*strip, fcurve); });
151
152 for (const FCurve *fcu : fcurves) {
153 FCurve *fcu_copy = BKE_fcurve_copy(fcu);
154
155 /* Handling groups properly requires more work, so we ignore them for now.
156 *
157 * Note that when legacy actions are deprecated, then we can handle channel
158 * groups way more easily because we know they're stored in the
159 * already-duplicated channelbag in `src`, and we therefore don't have to
160 * worry that they might have already been freed. */
161 fcu_copy->grp = nullptr;
162
163 animrig::action_fcurve_attach(dst, dst_slot_handle, *fcu_copy, std::nullopt);
164 }
165}
166
171{
172 if (strip->type == STRIP_TYPE_META) {
173 for (Strip &meta_child : strip->seqbase) {
174 strip_drivers_duplicate(&meta_child, dst, src);
175 }
176 }
177
179 src->drivers, [&](const FCurve &fcurve) { return fcurve_matches(*strip, fcurve); });
180
181 for (const FCurve *fcu : fcurves) {
182 FCurve *fcu_cpy = BKE_fcurve_copy(fcu);
183 BLI_addtail(&dst->drivers, fcu_cpy);
184 }
185}
186
188{
189 BLI_assert(scene != nullptr);
190
191 if (!backup->channelbag.fcurves().is_empty()) {
192 BLI_assert(scene->adt != nullptr);
193 BLI_assert(scene->adt->action != nullptr);
194 strip_animation_duplicate(strip, scene->adt->action->wrap(), scene->adt->slot_handle, backup);
195 }
196
197 if (!backup->drivers.is_empty()) {
198 BLI_assert(scene->adt != nullptr);
199 strip_drivers_duplicate(strip, scene->adt, backup);
200 }
201}
202
203} // namespace blender::seq
Span< const FCurve * > fcurves() const
void action_fcurve_attach(Action &action, slot_handle_t action_slot, FCurve &fcurve_to_attach, std::optional< StringRefNull > group_name)
bool action_fcurve_remove(Action &action, FCurve &fcu)
void assert_baklava_phase_1_invariants(const Action &action)
bool fcurve_matches_collection_path(const FCurve &fcurve, StringRefNull collection_rna_path, StringRefNull data_name)
decltype(blender::ActionSlot::handle) slot_handle_t
void channelbag_fcurves_move(Channelbag &channelbag_dst, Channelbag &channelbag_src)
Vector< FCurve * > fcurves_in_action_slot_filtered(bAction *act, slot_handle_t slot_handle, FunctionRef< bool(const FCurve &fcurve)> predicate)
const animrig::Channelbag * channelbag_for_action_slot(const Action &action, slot_handle_t slot_handle)
Vector< FCurve * > fcurves_in_span_filtered(Span< FCurve * > fcurves, FunctionRef< bool(const FCurve &fcurve)> predicate)
Vector< FCurve * > fcurves_in_listbase_filtered(ListBaseT< FCurve > fcurves, FunctionRef< bool(const FCurve &fcurve)> predicate)
static void strip_drivers_duplicate(Strip *strip, AnimData *dst, AnimationBackup *src)
Definition animation.cc:170
static void strip_animation_duplicate(Strip *strip, animrig::Action &dst, const animrig::slot_handle_t dst_slot_handle, AnimationBackup *src)
Definition animation.cc:137
bool animation_keyframes_exist(const Scene *scene)
Definition animation.cc:25
void animation_duplicate_backup_to_scene(Scene *scene, Strip *strip, AnimationBackup *backup)
Definition animation.cc:187
void offset_animdata(const Scene *scene, Strip *strip, float ofs)
Definition animation.cc:42
bool animation_drivers_exist(Scene *scene)
Definition animation.cc:31
void free_animdata(Scene *scene, Strip *strip)
Definition animation.cc:74
void animation_backup_original(Scene *scene, AnimationBackup *backup)
Definition animation.cc:91
void animation_restore_original(Scene *scene, AnimationBackup *backup)
Definition animation.cc:110
bool fcurve_matches(const Strip &strip, const FCurve &fcurve)
Definition animation.cc:36
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned int uint
Definition BKE_text.h:55
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:32
void DEG_id_tag_update(ID *id, unsigned int flags)
FCurve * BKE_fcurve_copy(const FCurve *fcu)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
ListBaseT< FCurve > drivers
bActionGroup * grp
struct AnimData * adt
animrig::Channelbag channelbag
ListBaseT< FCurve > drivers