Blender V5.3
blenkernel/intern/action.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10#include <cstddef>
11#include <cstdlib>
12#include <cstring>
13#include <optional>
14
15/* Allow using deprecated functionality for .blend file I/O. */
16#define DNA_DEPRECATED_ALLOW
17
18#include "DNA_ID.h"
19#include "DNA_action_types.h"
20#include "DNA_anim_types.h"
21#include "DNA_armature_types.h"
23#include "DNA_object_types.h"
24#include "DNA_scene_types.h"
25
26#include "BLI_assert.hh"
27#include "BLI_listbase.hh"
28#include "BLI_math_color_c.hh"
29#include "BLI_math_matrix_c.hh"
31#include "BLI_math_vector_c.hh"
32#include "BLI_session_uid.hh"
33#include "BLI_string.hh"
34#include "BLI_string_utf8.hh"
35#include "BLI_string_utils.hh"
36#include "BLI_utildefines.hh"
37
38#include "BLT_translation.hh"
39
40#include "BKE_action.hh"
41#include "BKE_anim_data.hh"
43#include "BKE_animsys.hh"
44#include "BKE_armature.hh"
45#include "BKE_asset.hh"
46#include "BKE_constraint.h"
47#include "BKE_deform.hh"
48#include "BKE_fcurve.hh"
49#include "BKE_idprop.hh"
50#include "BKE_idtype.hh"
51#include "BKE_lib_id.hh"
52#include "BKE_lib_query.hh"
53#include "BKE_main.hh"
54#include "BKE_object.hh"
55#include "BKE_object_types.hh"
56#include "BKE_pose.hh"
57#include "BKE_preview_image.hh"
58
59#include "DEG_depsgraph.hh"
61
62#include "BIK_api.h"
63
64#include "RNA_access.hh"
65#include "RNA_path.hh"
66
67#include "BLO_read_write.hh"
68
69#include "MEM_guardedalloc.h"
70
71#include "ANIM_action.hh"
72#include "ANIM_action_legacy.hh"
73#include "ANIM_armature.hh"
75#include "ANIM_bonecolor.hh"
76#include "ANIM_versioning.hh"
77
78#include "CLG_log.h"
79
80namespace blender {
81
82static CLG_LogRef LOG = {"anim.action"};
83
84/* *********************** NOTE ON POSE AND ACTION **********************
85 *
86 * - Pose is the local (object level) component of armature. The current
87 * object pose is saved in files, and (will be) is presorted for dependency
88 * - Actions have fewer (or other) channels, and write data to a Pose
89 * - Currently ob->pose data is controlled in BKE_pose_where_is only. The (recalc)
90 * event system takes care of calling that
91 * - The NLA system (here too) uses Poses as interpolation format for Actions
92 * - Therefore we assume poses to be static, and duplicates of poses have channels in
93 * same order, for quick interpolation reasons
94 *
95 * ****************************** (ton) ************************************ */
96
97/**************************** Action Datablock ******************************/
98
99/*********************** Armature Datablock ***********************/
100namespace bke {
101
102static void action_init_data(ID *action_id)
103{
104 BLI_assert(GS(action_id->name) == ID_AC);
105 bAction *action = reinterpret_cast<bAction *>(action_id);
106
107 INIT_DEFAULT_STRUCT_AFTER(action, id);
108}
109
120static void action_copy_data(Main * /*bmain*/,
121 std::optional<Library *> /*owner_library*/,
122 ID *id_dst,
123 const ID *id_src,
124 const int flag)
125{
126 bAction *dna_action_dst = reinterpret_cast<bAction *>(id_dst);
127 animrig::Action &action_dst = dna_action_dst->wrap();
128
129 const bAction *dna_action_src = reinterpret_cast<const bAction *>(id_src);
130 const animrig::Action &action_src = dna_action_src->wrap();
131
132 bActionGroup *group_dst, *group_src;
133 FCurve *fcurve_dst, *fcurve_src;
134
135 /* Duplicate the lists of groups and markers. */
136 BLI_duplicatelist(&action_dst.groups, &action_src.groups);
137 BKE_copy_time_markers(action_dst.markers, action_src.markers, flag);
138
139 /* Copy F-Curves, fixing up the links as we go. */
140 action_dst.curves.clear_no_delete();
141
142 for (fcurve_src = action_src.curves.first(); fcurve_src; fcurve_src = fcurve_src->next) {
143 /* Duplicate F-Curve. */
144
145 /* XXX TODO: pass sub-data flag?
146 * But surprisingly does not seem to be doing any ID reference-counting. */
147 fcurve_dst = BKE_fcurve_copy(fcurve_src);
148
149 BLI_addtail(&action_dst.curves, fcurve_dst);
150
151 /* Fix group links (kind of bad list-in-list search, but this is the most reliable way). */
152 for (group_dst = action_dst.groups.first(), group_src = action_src.groups.first();
153 group_dst && group_src;
154 group_dst = group_dst->next, group_src = group_src->next)
155 {
156 if (fcurve_src->grp == group_src) {
157 fcurve_dst->grp = group_dst;
158
159 if (group_dst->channels.first() == fcurve_src) {
160 group_dst->channels.first_ = fcurve_dst;
161 }
162 if (group_dst->channels.last() == fcurve_src) {
163 group_dst->channels.last_ = fcurve_dst;
164 }
165 break;
166 }
167 }
168 }
169
170 /* Copy all simple properties. */
171 action_dst.layer_array_num = action_src.layer_array_num;
172 action_dst.layer_active_index = action_src.layer_active_index;
173 action_dst.slot_array_num = action_src.slot_array_num;
174 action_dst.last_slot_handle = action_src.last_slot_handle;
175
176 /* Layers, and (recursively) Strips. */
178 __func__);
179 for (int i : action_src.layers().index_range()) {
180 action_dst.layer_array[i] = action_src.layer(i)->duplicate_with_shallow_strip_copies(__func__);
181 }
182
183 /* Strip data. */
185 action_src.strip_keyframe_data_array_num, __func__);
186 for (int i : action_src.strip_keyframe_data().index_range()) {
187 action_dst.strip_keyframe_data_array[i] = MEM_new<animrig::StripKeyframeData>(
188 __func__, *action_src.strip_keyframe_data()[i]);
189 }
190
191 /* Slots. */
192 action_dst.slot_array = MEM_new_array_zeroed<ActionSlot *>(action_src.slot_array_num, __func__);
193 for (int i : action_src.slots().index_range()) {
194 action_dst.slot_array[i] = MEM_new<animrig::Slot>(__func__, *action_src.slot(i));
195 }
196
197 if (flag & LIB_ID_COPY_NO_PREVIEW) {
198 action_dst.preview = nullptr;
199 }
200 else {
201 BKE_previewimg_id_copy(&action_dst.id, &action_src.id);
202 }
203}
204
206static void action_free_data(ID *id)
207{
208 animrig::Action &action = reinterpret_cast<bAction *>(id)->wrap();
209
210 /* Free keyframe data. */
211 for (animrig::StripKeyframeData *keyframe_data : action.strip_keyframe_data()) {
212 MEM_delete(keyframe_data);
213 }
214 MEM_SAFE_DELETE(action.strip_keyframe_data_array);
216
217 /* Free layers. */
218 for (animrig::Layer *layer : action.layers()) {
219 MEM_delete(layer);
220 }
221 MEM_SAFE_DELETE(action.layer_array);
222 action.layer_array_num = 0;
223
224 /* Free slots. */
225 for (animrig::Slot *slot : action.slots()) {
226 MEM_delete(slot);
227 }
228 MEM_SAFE_DELETE(action.slot_array);
229 action.slot_array_num = 0;
230
231 /* Free legacy F-Curves & groups. */
232 BKE_fcurves_free(&action.curves);
233 action.groups.free_no_destruct();
234
235 /* Free markers & preview. */
236 BKE_free_time_markers(action.markers, false);
237 BKE_previewimg_id_free(&action.id);
238
239 BLI_assert(action.is_empty());
240}
241
243{
244 animrig::Action &action = reinterpret_cast<bAction *>(id)->wrap();
245
246 /* When this function is called without the IDWALK_READONLY flag, calls to
247 * BKE_LIB_FOREACHID_PROCESS_... macros can change ID pointers. ID remapping is the main example
248 * of such use.
249 *
250 * Those ID pointer changes are not guaranteed to be valid, though. For example, the remapping
251 * can be used to replace one Mesh with another, but that neither means that the new Mesh is
252 * animated with the same Action, nor that the old Mesh is no longer animated by that Action. In
253 * other words, the best that can be done is to invalidate the cache.
254 *
255 * NOTE: early-returns by BKE_LIB_FOREACHID_PROCESS_... macros are forbidden in non-readonly
256 * cases (see #IDWALK_RET_STOP_ITER documentation). */
257
259
260 /* Note that `bmain` can be `nullptr`. An example is in
261 * `deg_eval_copy_on_write.cc`, function `deg_expand_eval_copy_datablock`. */
263
264 /* This function should not rebuild the slot user map, because that in turn loops over all IDs.
265 * It is really up to the caller to ensure things are clean when the slot user pointers should be
266 * reported.
267 *
268 * For things like ID remapping it's fine to skip the pointers when they're dirty. The next time
269 * somebody tries to actually use them, they will be rebuilt anyway. */
270 const bool slot_user_cache_is_known_clean = bmain && !bmain->is_action_slot_to_id_map_dirty;
271
272 if (slot_user_cache_is_known_clean) {
273 bool should_invalidate = false;
274 for (animrig::Slot *slot : action.slots()) {
275 for (ID *&slot_user : slot->runtime_users()) {
276 ID *const old_pointer = slot_user;
277 BKE_LIB_FOREACHID_PROCESS_ID(data, slot_user, idwalk_flags);
278 /* If slot_user changed, the cache should be invalidated. Not all pointer changes are
279 * semantically correct for our use. For example, when ID-remapping is used to replace
280 * MECube with MESuzanne. If MECube is animated by some slot before the remap, it will
281 * remain animated by that slot after the remap, even when all `object->data` pointers now
282 * reference MESuzanne instead. */
283 should_invalidate |= (slot_user != old_pointer);
284 }
285 }
286
287 if (should_invalidate) {
289 }
290
291#ifndef NDEBUG
293 const bool is_readonly = flag & IDWALK_READONLY;
294 if (is_readonly) {
295 BLI_assert_msg(!should_invalidate,
296 "pointers were changed while IDWALK_READONLY flag was set");
297 }
298#endif
299 }
300
301 /* Note that, even though `BKE_fcurve_foreach_id()` exists, it is not called here. That function
302 * is only relevant for drivers, but the F-Curves stored in an Action are always just animation
303 * data, not drivers. */
304
305 for (TimeMarker &marker : action.markers) {
309 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
310 }));
311 }
312}
313
314static void write_channelbag(BlendWriter *writer, animrig::Channelbag &channelbag)
315{
317 &channelbag, [](BlendStructWriter<ActionChannelbag> &struct_writer) {
318 ActionChannelbag &shallow_bag = struct_writer.shallow_data;
319 if (shallow_bag.group_array_num == 0) {
320 shallow_bag.group_array = nullptr;
321 }
322 if (shallow_bag.fcurve_array_num == 0) {
323 shallow_bag.fcurve_array = nullptr;
324 }
325 });
326
327 Span<bActionGroup *> groups = channelbag.channel_groups();
328 writer->write_pointer_array(groups.size(), groups.data());
329 for (const bActionGroup *group : groups) {
330 writer->write_struct(group);
331 }
332
333 Span<FCurve *> fcurves = channelbag.fcurves();
334 writer->write_pointer_array(fcurves.size(), fcurves.data());
335 for (FCurve *fcurve : fcurves) {
336 writer->write_struct(fcurve, [](BlendStructWriter<FCurve> &struct_writer) {
337 struct_writer.shallow_data.runtime = nullptr;
338 });
339 BKE_fcurve_blend_write_data(writer, fcurve);
340 }
341}
342
344 animrig::StripKeyframeData &strip_keyframe_data)
345{
346 writer->write_struct_cast<ActionStripKeyframeData>(&strip_keyframe_data);
347
348 auto channelbags = strip_keyframe_data.channelbags();
349 writer->write_pointer_array(channelbags.size(), channelbags.data());
350
351 for (animrig::Channelbag *channelbag : channelbags) {
352 write_channelbag(writer, *channelbag);
353 }
354}
355
357 BlendWriter *writer, Span<animrig::StripKeyframeData *> strip_keyframe_data_array)
358{
359 writer->write_pointer_array(strip_keyframe_data_array.size(), strip_keyframe_data_array.data());
360
361 for (animrig::StripKeyframeData *keyframe_data : strip_keyframe_data_array) {
362 write_strip_keyframe_data(writer, *keyframe_data);
363 }
364}
365
367{
368 writer->write_pointer_array(strips.size(), strips.data());
369
370 for (animrig::Strip *strip : strips) {
371 writer->write_struct_cast<ActionStrip>(strip);
372 }
373}
374
376{
377 writer->write_pointer_array(layers.size(), layers.data());
378
379 for (animrig::Layer *layer : layers) {
381 write_strips(writer, layer->strips());
382 }
383}
384
386{
387 writer->write_pointer_array(slots.size(), slots.data());
388 for (animrig::Slot *slot : slots) {
389 writer->write_struct_cast<ActionSlot>(slot, [](BlendStructWriter<ActionSlot> &struct_writer) {
390 struct_writer.shallow_data.runtime = nullptr;
391 });
392 }
393}
394
411 ListBaseT<bActionGroup> &listbase, const Span<bActionGroup *> channel_groups)
412{
413 if (channel_groups.is_empty()) {
414 listbase.clear_no_delete();
415 return;
416 }
417
418 /* Set the fcurve listbase pointers.
419 *
420 * Note that the fcurves' own prev/next pointers are hooked up by
421 * `action_blend_write_make_legacy_fcurves_listbase()`, so that they function
422 * properly as a list. */
423 for (bActionGroup *group : channel_groups) {
424 Span<FCurve *> fcurves = group->wrap().fcurves();
425 if (fcurves.is_empty()) {
426 group->channels = {nullptr, nullptr};
427 }
428 else {
429 group->channels = {fcurves.first(), fcurves.last()};
430 }
431 }
432
433 /* Determine the prev/next pointers on the elements. */
434 const int last_index = channel_groups.size() - 1;
435 for (int index : channel_groups.index_range()) {
436 channel_groups[index]->prev = (index > 0) ? channel_groups[index - 1] : nullptr;
437 channel_groups[index]->next = (index < last_index) ? channel_groups[index + 1] : nullptr;
438 }
439
440 listbase.first_ = channel_groups[0];
441 listbase.last_ = channel_groups[last_index];
442}
443
445 ListBaseT<bActionGroup> &listbase)
446{
447 for (bActionGroup &group : listbase.items_mutable()) {
448 group.prev = nullptr;
449 group.next = nullptr;
450 group.channels = {nullptr, nullptr};
451 }
452
453 listbase.clear_no_delete();
454}
455
470static void action_blend_write_make_legacy_fcurves_listbase(ListBaseT<FCurve> &listbase,
471 const Span<FCurve *> fcurves)
472{
473 if (fcurves.is_empty()) {
474 listbase.clear_no_delete();
475 return;
476 }
477
478 /* Determine the prev/next pointers on the elements. */
479 const int last_index = fcurves.size() - 1;
480 for (int index : fcurves.index_range()) {
481 fcurves[index]->prev = (index > 0) ? fcurves[index - 1] : nullptr;
482 fcurves[index]->next = (index < last_index) ? fcurves[index + 1] : nullptr;
483 }
484
485 listbase.first_ = fcurves[0];
486 listbase.last_ = fcurves[last_index];
487}
488
489static void action_blend_write_clear_legacy_fcurves_listbase(ListBaseT<FCurve> &listbase)
490{
491 for (FCurve &fcurve : listbase.items_mutable()) {
492 fcurve.prev = nullptr;
493 fcurve.next = nullptr;
494 }
495
496 listbase.clear_no_delete();
497}
498
499static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address)
500{
501 animrig::Action &action = reinterpret_cast<bAction *>(id)->wrap();
502
503 /* Create legacy data for Layered Actions: the F-Curves from the first Slot,
504 * bottom layer, first Keyframe strip. */
505 const bool do_write_forward_compat = !writer->is_undo() && action.slot_array_num > 0;
506 if (do_write_forward_compat) {
508 BLI_assert_msg(action.curves.is_empty(), "Layered Action should not have legacy data");
509 BLI_assert_msg(action.groups.is_empty(), "Layered Action should not have legacy data");
510
511 const animrig::Slot &first_slot = *action.slot(0);
512
513 /* The forward-compat animation data we write is for IDs of the type that
514 * the first slot is intended for. Therefore, the Action should have that
515 * `idroot` when loaded in old versions of Blender.
516 *
517 * Note that if there is no slot, this code will never run and therefore the
518 * action will be written with `idroot = 0`. Despite that, old
519 * pre-slotted-action files are still guaranteed to round-trip losslessly,
520 * because old actions (even when empty) are versioned to have one slot with
521 * `idtype` set to whatever the old action's `idroot` was. In other words,
522 * zero-slot actions can only be created via non-legacy features, and
523 * therefore represent animation data that wasn't purely from old files
524 * anyway. */
525 action.idroot = first_slot.idtype;
526
527 /* Note: channel group forward-compat data requires that fcurve
528 * forward-compat legacy data is also written, and vice-versa. Both have
529 * pointers to each other that won't resolve properly when loaded in older
530 * Blender versions if only one is written. */
531 animrig::Channelbag *bag = channelbag_for_action_slot(action, first_slot.handle);
532 if (bag) {
535 }
536 }
537
538 writer->write_id_struct(id_address, static_cast<const bAction *>(&action));
539 BKE_id_blend_write(writer, &action.id);
540
541 /* Write layered Action data. */
543 write_layers(writer, action.layers());
544 write_slots(writer, action.slots());
545
546 if (do_write_forward_compat) {
547 /* Set the idroot back to 'unspecified', as it always should be for layered
548 * Actions. */
549 action.idroot = 0;
550
551 /* The pointers to the first/last FCurve in the `action.curves` have already
552 * been written as part of the Action struct data, so they can be cleared
553 * here, such that the code writing legacy fcurves below does nothing (as
554 * expected). And to leave the Action in a consistent state (it shouldn't
555 * have F-Curves in both legacy and layered storage).
556 *
557 * Note that the FCurves themselves have been written as part of the layered
558 * animation writing code called above. Writing them again as part of the
559 * handling of the legacy `action.fcurves` ListBaseT would corrupt the
560 * blend-file by generating two `BHead` `DATA` blocks with the same old
561 * address for the same ID.
562 */
565 }
566
567 /* Write legacy F-Curves & Groups. */
569 for (bActionGroup &grp : action.groups) {
570 writer->write_struct(&grp);
571 }
572
574
575 BKE_previewimg_blend_write(writer, action.preview);
576}
577
578static void read_channelbag(BlendDataReader *reader, animrig::Channelbag &channelbag)
579{
581 reader, &channelbag.group_array, &channelbag.group_array_num);
582 for (int i = 0; i < channelbag.group_array_num; i++) {
583 BLO_read_struct(reader, bActionGroup, &channelbag.group_array[i]);
584 channelbag.group_array[i]->channelbag = &channelbag;
585
586 /* Clear the legacy channels #ListBase, since it will have been set for some
587 * groups for forward compatibility.
588 * See #action_blend_write_make_legacy_channel_groups_listbase. */
589 channelbag.group_array[i]->channels = {nullptr, nullptr};
590 }
591
593 reader, &channelbag.fcurve_array, &channelbag.fcurve_array_num);
594 for (int i = 0; i < channelbag.fcurve_array_num; i++) {
595 BLO_read_struct(reader, FCurve, &channelbag.fcurve_array[i]);
596 FCurve *fcurve = channelbag.fcurve_array[i];
597
598 /* Clear the prev/next pointers set by the forward compatibility code in
599 * action_blend_write(). */
600 fcurve->prev = nullptr;
601 fcurve->next = nullptr;
602
603 BKE_fcurve_blend_read_data(reader, fcurve);
604 }
605}
606
608 animrig::StripKeyframeData &strip_keyframe_data)
609{
611 reader, &strip_keyframe_data.channelbag_array, &strip_keyframe_data.channelbag_array_num);
612
613 for (int i = 0; i < strip_keyframe_data.channelbag_array_num; i++) {
614 BLO_read_struct(reader, ActionChannelbag, &strip_keyframe_data.channelbag_array[i]);
615 ActionChannelbag *channelbag = strip_keyframe_data.channelbag_array[i];
616 read_channelbag(reader, channelbag->wrap());
617 }
618}
619
621{
624
625 for (int i = 0; i < action.strip_keyframe_data_array_num; i++) {
627 ActionStripKeyframeData *keyframe_data = action.strip_keyframe_data_array[i];
628 read_strip_keyframe_data(reader, keyframe_data->wrap());
629 }
630}
631
632static void read_layers(BlendDataReader *reader, animrig::Action &action)
633{
635
636 for (int layer_idx = 0; layer_idx < action.layer_array_num; layer_idx++) {
637 BLO_read_struct(reader, ActionLayer, &action.layer_array[layer_idx]);
638 ActionLayer *layer = action.layer_array[layer_idx];
639
640 BLO_read_pointer_array_and_validate_size(reader, &layer->strip_array, &layer->strip_array_num);
641 for (int strip_idx = 0; strip_idx < layer->strip_array_num; strip_idx++) {
642 BLO_read_struct(reader, ActionStrip, &layer->strip_array[strip_idx]);
643
644 /* This if statement and the code in it is only for a transitional period
645 * while we land #126559 and for a while after, to prevent crashes for
646 * people that were already playing with slotted actions and have some
647 * blend files written with them. This code can be removed after a while.
648 * At the very least, if you're reading this and slotted actions are
649 * already in an official release of Blender then this code is no longer
650 * relevant and can be deleted. */
651 if (layer->strip_array[strip_idx] == nullptr) {
652 layer->strip_array[strip_idx] = &animrig::Strip::create(action,
654 }
655 }
656 }
657}
658
659static void read_slots(BlendDataReader *reader, animrig::Action &action)
660{
662
663 for (int i = 0; i < action.slot_array_num; i++) {
664 BLO_read_struct(reader, ActionSlot, &action.slot_array[i]);
665
666 /* NOTE: this is endianness-sensitive. */
667 /* In case of required endian switching, this code would have to undo the generic endian
668 * switching, as the ID type values are not numerically the same between little and big endian
669 * machines. Due to the way they are defined, they are always in the same byte order,
670 * regardless of hardware/platform endianness. */
671
672 action.slot_array[i]->wrap().blend_read_post();
673 }
674}
675
677{
678 animrig::Action &action = reinterpret_cast<bAction *>(id)->wrap();
679
680 /* NOTE: this is endianness-sensitive. */
681 /* In case of required endianness switching, this code would need to undo the generic endian
682 * switching (careful, only the two least significant bytes of the int32 must be swapped back
683 * here, since this value is actually an int16). */
684
685 read_strip_keyframe_data_array(reader, action);
686 read_layers(reader, action);
687 read_slots(reader, action);
688
690 /* Clear the forward-compatible storage (see action_blend_write_data()). */
691 action.curves.clear_no_delete();
692 action.groups.clear_no_delete();
693
694 /* Layered actions should always have `idroot == 0`, but when writing an
695 * action to a blend file `idroot` is typically set otherwise for forward
696 * compatibility reasons (see `action_blend_write()`). So we set it to zero
697 * here to put it back as it should be. */
698 action.idroot = 0;
699 }
700 else {
701 /* Read legacy data. */
702 BLO_read_struct_list(reader, FCurve, &action.curves);
703 BLO_read_struct_list(reader, bActionGroup, &action.groups);
704
706
707 for (bActionGroup &agrp : action.groups) {
708 BLO_read_struct(reader, FCurve, &agrp.channels.first_);
709 BLO_read_struct(reader, FCurve, &agrp.channels.last_);
710 }
711 }
712
713 BKE_time_markers_blend_read(reader, action.markers);
714
715 /* End of reading legacy data. */
716
717 BLO_read_struct(reader, PreviewImage, &action.preview);
718 BKE_previewimg_blend_read(reader, action.preview);
719}
720
722{
723 const bool is_single_frame = action && action->wrap().has_single_frame();
724 return bke::idprop::create("is_single_frame", int(is_single_frame)).release();
725}
726
727static void action_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data)
728{
729 bAction *action = static_cast<bAction *>(asset_ptr);
730 BLI_assert(GS(action->id.name) == ID_AC);
731
732 IDProperty *action_type = action_asset_type_property(action);
733 BKE_asset_metadata_idprop_ensure(asset_data, action_type);
734}
735
737 /*pre_save_fn*/ action_asset_metadata_ensure,
738 /*on_mark_asset_fn*/ action_asset_metadata_ensure,
739 /*on_clear_asset_fn*/ nullptr,
740};
741
742} // namespace bke
743
745 .id_code = bAction::id_type,
746 .id_filter = FILTER_ID_AC,
747
748 /* This value will be set dynamically in `BKE_idtype_init()` to only include
749 * animatable ID types (see `animrig::Slot::users()`). */
750 .dependencies_id_types = FILTER_ID_ALL,
751
752 .main_listbase_index = INDEX_ID_AC,
753 .struct_size = sizeof(bAction),
754 .name = "Action",
755 .name_plural = N_("actions"),
756 .translation_context = BLT_I18NCONTEXT_ID_ACTION,
758 .asset_type_info = &bke::AssetType_AC,
759
760 .init_data = bke::action_init_data,
761 .copy_data = bke::action_copy_data,
762 .free_data = bke::action_free_data,
763 .make_local = nullptr,
764 .foreach_id = bke::action_foreach_id,
765 .foreach_cache = nullptr,
766 .foreach_path = nullptr,
767 .foreach_working_space_color = nullptr,
768 .foreach_asset_weak_reference = nullptr,
769 .owner_pointer_get = nullptr,
770
771 .blend_write = bke::action_blend_write,
772 .blend_read_data = bke::action_blend_read_data,
773 .blend_read_after_liblink = nullptr,
774
775 .blend_read_undo_preserve = nullptr,
776
777 .lib_override_apply_post = nullptr,
778};
779
780/* ***************** Library data level operations on action ************** */
781
782bAction *BKE_action_add(Main *bmain, const char name[])
783{
784 bAction *act;
785
786 act = BKE_id_new<bAction>(bmain, name);
787
788 return act;
789}
790
791/* .................................. */
792
793/* *************** Action Groups *************** */
794
796{
797 /* Only do color copying if using a custom color (i.e. not default color). */
798 if (!grp->customCol) {
799 return;
800 }
801 if (grp->customCol > 0) {
802 /* Copy theme colors on-to group's custom color in case user tries to edit color. */
803 const bTheme *btheme = U.themes.first();
804 const ThemeWireColor *col_set = &btheme->tarm[(grp->customCol - 1)];
805
806 memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
807 }
808 else {
809 /* Init custom color with a generic/placeholder color set if
810 * no previous theme color was used that we can just keep using.
811 */
812 if (grp->cs.solid[0] == 0) {
813 /* define for setting colors in theme below */
814 rgba_uchar_args_set(grp->cs.solid, 0xff, 0x00, 0x00, 255);
815 rgba_uchar_args_set(grp->cs.select, 0x81, 0xe6, 0x14, 255);
816 rgba_uchar_args_set(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
817 }
818 }
819}
820
822{
823 BLI_assert_msg(pchanbone.pchan,
824 "cannot 'set action group colors from posebone' without a posebone");
827}
828
830{
831 const animrig::BoneColor &bone_color = color->wrap();
832
833 grp->customCol = int(bone_color.palette_index);
834
835 const ThemeWireColor *effective_color = bone_color.effective_color();
836 if (effective_color) {
837 /* The drawing code assumes that grp->cs always contains the effective
838 * color. This is why the effective color is always written to it, and why
839 * the above action_group_colors_sync() function exists: it needs to update
840 * grp->cs in case the theme changes. */
841 memcpy(&grp->cs, effective_color, sizeof(grp->cs));
842 }
843}
844
845/* *************** Pose channels *************** */
846
847/* -------------------------------------------------------------------- */
850
851const Bone *bPoseChannel::bone_get(const bArmature &armature) const
852{
853 if (this->runtime.bone_index == BONE_INDEX_UNKNOWN) {
854 /* This is a valid use case, as the nullptr is used to determine whether the bone exists. See
855 * BKE_pose_channels_clear_with_null_bone().
856 *
857 * In the future, this could be handled by another function (like `bool bone_exists(...)`)
858 * while this one can then return a reference instead of a pointer. Currently that is not yet
859 * done, to keep the introduction of this function semantically close to the bPoseChannel::bone
860 * pointer it replaces. */
861 return nullptr;
862 }
863 return armature.bone_get_indexed(this->runtime.bone_index);
864}
865
866const Bone *bPoseChannel::bone_get(const Object &owner) const
867{
868 BLI_assert(owner.type == OB_ARMATURE);
869 BLI_assert(GS(owner.data->name) == ID_AR);
870 bArmature *armature = id_cast<bArmature *>(owner.data);
871
872 /* Check that the Object's pose bone index generation counter is the same as the Armature's, and
873 * rebuild when necessary. */
875
876 return this->bone_get(*armature);
877}
878
879Bone *bPoseChannel::bone_get(bArmature &armature)
880{
881 const bPoseChannel *const_this = this;
882 const Bone *const_bone = const_this->bone_get(armature);
883 return const_cast<Bone *>(const_bone);
884}
885Bone *bPoseChannel::bone_get(Object &owner)
886{
887 const bPoseChannel *const_this = this;
888 const Bone *const_bone = const_this->bone_get(owner);
889 return const_cast<Bone *>(const_bone);
890}
891
893
898
900{
901 if (ELEM(nullptr, pose, name) || (name[0] == '\0')) {
902 return nullptr;
903 }
904
905 if (!pose->runtime->chanhash.is_empty()) {
906 bPoseChannel *const *found = pose->runtime->chanhash.lookup_ptr(name);
907 return found ? *found : nullptr;
908 }
909
910 return static_cast<bPoseChannel *>(
911 BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name)));
912}
913
915{
916 bPoseChannel *chan;
917
918 if (pose == nullptr) {
919 return nullptr;
920 }
921
923 name[0] != '\0',
924 "Bones have to have a name, otherwise the function below will always return a nullptr");
925 /* See if this channel exists */
926 chan = BKE_pose_channel_find_name(pose, name);
927 if (chan) {
928 return chan;
929 }
930
931 /* If not, create it and add it */
932 chan = MEM_new<bPoseChannel>("verifyPoseChannel");
933
935
936 STRNCPY_UTF8(chan->name, name);
937
938 copy_v3_fl(chan->custom_scale_xyz, 1.0f);
941 chan->custom_shape_wire_width = 1.0f;
942
943 /* init vars to prevent math errors */
944 unit_qt(chan->quat);
945 unit_axis_angle(chan->rotAxis, &chan->rotAngle);
946 chan->scale[0] = chan->scale[1] = chan->scale[2] = 1.0f;
947
948 copy_v3_fl(chan->scale_in, 1.0f);
949 copy_v3_fl(chan->scale_out, 1.0f);
950
951 chan->limitmin[0] = chan->limitmin[1] = chan->limitmin[2] = -M_PI;
952 chan->limitmax[0] = chan->limitmax[1] = chan->limitmax[2] = M_PI;
953 chan->stiffness[0] = chan->stiffness[1] = chan->stiffness[2] = 0.0f;
954 chan->ikrotweight = chan->iklinweight = 0.0f;
955 unit_m4(chan->constinv);
956
957 chan->protectflag = OB_LOCK_ROT4D; /* lock by components by default */
958
959 BLI_addtail(&pose->chanbase, chan);
960 if (!pose->runtime->chanhash.is_empty()) {
961 pose->runtime->chanhash.add_overwrite(chan->name, chan);
962 }
963
964 return chan;
965}
966
967#ifndef NDEBUG
969{
970 if (!pose->runtime->chanhash.is_empty()) {
971 bPoseChannel *pchan;
972 for (pchan = pose->chanbase.first(); pchan; pchan = pchan->next) {
973 bPoseChannel *const *found = pose->runtime->chanhash.lookup_ptr(pchan->name);
974 if (!found || *found != pchan) {
975 return false;
976 }
977 }
978 }
979
980 return true;
981}
982
983#endif
984
986{
987 const Bone *bone = pchan->bone_get(*arm);
988 return bone && ANIM_bone_in_visible_collection(arm, bone);
989}
990
991bPoseChannel *BKE_pose_channel_active(Object *ob, const bool check_bonecoll)
992{
993 if (!ob || !ob->data || ob->type != OB_ARMATURE) {
994 return nullptr;
995 }
996 bArmature *arm = id_cast<bArmature *>(ob->data);
997 if (ELEM(nullptr, ob->pose, arm)) {
998 return nullptr;
999 }
1000
1001 /* find active */
1002 for (bPoseChannel &pchan : ob->pose->chanbase) {
1003 const Bone *bone = pchan.bone_get(*ob);
1004 if (bone && bone == arm->act_bone) {
1005 if (!check_bonecoll || ANIM_bone_in_visible_collection(arm, bone)) {
1006 return &pchan;
1007 }
1008 }
1009 }
1010
1011 return nullptr;
1012}
1013
1018
1020{
1021 bArmature *arm = id_cast<bArmature *>((ob) ? ob->data : nullptr);
1022
1023 if (ELEM(nullptr, ob, ob->pose, arm)) {
1024 return nullptr;
1025 }
1026
1028 if (pchan && animrig::bone_is_selected(arm, {pchan, pchan->bone_get(*ob)})) {
1029 return pchan;
1030 }
1031
1032 for (bPoseChannel &pchan : ob->pose->chanbase) {
1033 Bone *bone = pchan.bone_get(*ob);
1034 if (bone != nullptr) {
1035 if (animrig::bone_is_selected(arm, {&pchan, bone})) {
1036 return &pchan;
1037 }
1038 }
1039 }
1040 return nullptr;
1041}
1042
1044{
1045 char name_flip[MAXBONENAME];
1046
1047 BLI_string_flip_side_name(name_flip, name, false, sizeof(name_flip));
1048
1049 if (!STREQ(name_flip, name)) {
1050 return BKE_pose_channel_find_name(pose, name_flip);
1051 }
1052
1053 return nullptr;
1054}
1055
1057{
1058 if (pose) {
1059 switch (pose->iksolver) {
1060 case IKSOLVER_STANDARD:
1061 return nullptr;
1062 case IKSOLVER_ITASC:
1063 return "bItasc";
1064 }
1065 }
1066 return nullptr;
1067}
1068
1070 const bPose *src,
1071 const int flag,
1072 const bool copy_constraints)
1073{
1074 bPose *outPose;
1075 ListBaseT<bConstraint> listb;
1076
1077 if (!src) {
1078 *dst = nullptr;
1079 return;
1080 }
1081
1082 outPose = MEM_new<bPose>("pose");
1083 outPose->runtime = MEM_new<bke::bPoseRuntime>(__func__);
1084
1085 BLI_duplicatelist(&outPose->chanbase, &src->chanbase);
1086
1087 /* Rebuild ghash here too, so that name lookups below won't be too bad...
1088 * BUT this will have the penalty that the ghash will be built twice
1089 * if BKE_pose_rebuild() gets called after this...
1090 */
1091 if (outPose->chanbase.first() != outPose->chanbase.last()) {
1093 }
1094
1095 outPose->iksolver = src->iksolver;
1096 if (src->ikparam) {
1097 outPose->ikparam = MEM_new<bItasc>(__func__, *src->ikparam);
1098 }
1099 outPose->avs = src->avs;
1100
1101 for (bPoseChannel &pchan : outPose->chanbase) {
1102 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
1103 id_us_plus(id_cast<ID *>(pchan.custom));
1104 }
1105
1106 if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) {
1108 }
1109
1110 /* warning, O(n2) here, if done without the hash, but these are rarely used features. */
1111 if (pchan.custom_tx) {
1112 pchan.custom_tx = BKE_pose_channel_find_name(outPose, pchan.custom_tx->name);
1113 }
1114 if (pchan.bbone_prev) {
1115 pchan.bbone_prev = BKE_pose_channel_find_name(outPose, pchan.bbone_prev->name);
1116 }
1117 if (pchan.bbone_next) {
1118 pchan.bbone_next = BKE_pose_channel_find_name(outPose, pchan.bbone_next->name);
1119 }
1120
1121 if (copy_constraints) {
1122 /* #BKE_constraints_copy nullptr's `listb` */
1123 BKE_constraints_copy_ex(&listb, &pchan.constraints, flag, true);
1124
1125 pchan.constraints = listb;
1126
1127 /* XXX: This is needed for motionpath drawing to work.
1128 * Dunno why it was setting to null before... */
1129 pchan.mpath = bke::motionpath::copy(pchan.mpath);
1130 }
1131
1132 if (pchan.prop) {
1133 pchan.prop = IDP_CopyProperty_ex(pchan.prop, flag);
1134 }
1135 if (pchan.system_properties) {
1137 }
1138
1139 pchan.draw_data = nullptr; /* Drawing cache, no need to copy. */
1140
1141 /* Runtime data, no need to copy. */
1143 }
1144
1145 /* for now, duplicate Bone Groups too when doing this */
1146 if (copy_constraints) {
1147 BLI_duplicatelist(&outPose->agroups, &src->agroups);
1148 }
1149
1150 *dst = outPose;
1151}
1152
1153void BKE_pose_copy_data(bPose **dst, const bPose *src, const bool copy_constraints)
1154{
1155 BKE_pose_copy_data_ex(dst, src, 0, copy_constraints);
1156}
1157
1159{
1160 if (itasc) {
1161 itasc->iksolver = IKSOLVER_ITASC;
1162 itasc->minstep = 0.01f;
1163 itasc->maxstep = 0.06f;
1164 itasc->numiter = 100;
1165 itasc->numstep = 4;
1166 itasc->precision = 0.005f;
1168 itasc->feedback = 20.0f;
1169 itasc->maxvel = 50.0f;
1170 itasc->solver = ITASC_SOLVER_SDLS;
1171 itasc->dampmax = 0.5;
1172 itasc->dampeps = 0.15;
1173 }
1174}
1176{
1177 if (pose->iksolver == IKSOLVER_ITASC) {
1178 pose->ikparam = MEM_new<bItasc>("itasc");
1179 BKE_pose_itasc_init(pose->ikparam);
1180 }
1181}
1182
1183/* only for real IK, not for auto-IK */
1184static bool pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan, int level)
1185{
1186 /* No need to check if constraint is active (has influence),
1187 * since all constraints with CONSTRAINT_IK_AUTO are active */
1188 for (bConstraint &con : pchan->constraints) {
1189 if (con.type == CONSTRAINT_TYPE_KINEMATIC) {
1190 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con.data);
1191 if ((data->rootbone == 0) || (data->rootbone > level)) {
1192 if ((data->flag & CONSTRAINT_IK_AUTO) == 0) {
1193 return true;
1194 }
1195 }
1196 }
1197 }
1198 for (Bone &bone : pchan->bone_get(*ob)->childbase) {
1199 pchan = BKE_pose_channel_find_name(ob->pose, bone.name);
1200 if (pchan && pose_channel_in_IK_chain(ob, pchan, level + 1)) {
1201 return true;
1202 }
1203 }
1204 return false;
1205}
1206
1208{
1209 return pose_channel_in_IK_chain(ob, pchan, 0);
1210}
1211
1212static bool transform_follows_custom_tx(const bArmature *arm, const bPoseChannel *pchan)
1213{
1214 if (arm->flag & ARM_NO_CUSTOM) {
1215 return false;
1216 }
1217
1218 if (!pchan->custom || !pchan->custom_tx) {
1219 return false;
1220 }
1221
1222 return pchan->flag & POSE_TRANSFORM_AT_CUSTOM_TX;
1223}
1224
1226 const bPoseChannel *pose_bone,
1227 float r_pose_orientation[3][3])
1228{
1229 if (!transform_follows_custom_tx(arm, pose_bone)) {
1230 copy_m3_m4(r_pose_orientation, pose_bone->pose_mat);
1231 return;
1232 }
1233
1234 BLI_assert(pose_bone->custom_tx);
1235
1236 const bPoseChannel *custom_tx_bone = pose_bone->custom_tx;
1237 copy_m3_m4(r_pose_orientation, custom_tx_bone->pose_mat);
1238}
1239
1241 const bPoseChannel *pose_bone,
1242 float r_pose_space_pivot[3])
1243{
1244 if (!transform_follows_custom_tx(arm, pose_bone)) {
1245 copy_v3_v3(r_pose_space_pivot, pose_bone->pose_mat[3]);
1246 return;
1247 }
1248
1249 copy_v3_v3(r_pose_space_pivot, pose_bone->custom_tx->pose_mat[3]);
1250}
1251
1253{
1254 if (pose->runtime->chanhash.is_empty()) {
1255 for (bPoseChannel &pchan : pose->chanbase) {
1256 pose->runtime->chanhash.add_overwrite(pchan.name, &pchan);
1257 }
1258 }
1259}
1260
1262{
1263 pose->runtime->chanhash.clear();
1264}
1265
1267{
1268 for (bPoseChannel &pchan : ob->pose->chanbase) {
1269 if (pchan.bbone_prev == unlinked_pchan) {
1270 pchan.bbone_prev = nullptr;
1271 }
1272 if (pchan.bbone_next == unlinked_pchan) {
1273 pchan.bbone_next = nullptr;
1274 }
1275 if (pchan.custom_tx == unlinked_pchan) {
1276 pchan.custom_tx = nullptr;
1277 }
1278 }
1279}
1280
1282 bool (*filter_fn)(const char *bone_name, void *user_data),
1283 void *user_data)
1284{
1285 /* Erase any associated pose channel, along with any references to them */
1286 if (ob->pose) {
1287 bPoseChannel *pchan, *pchan_next;
1288
1289 for (pchan = ob->pose->chanbase.first(); pchan; pchan = pchan_next) {
1290 pchan_next = pchan->next;
1291
1292 if (filter_fn(pchan->name, user_data)) {
1293 /* Bone itself is being removed */
1294 BKE_pose_channel_free(pchan);
1296 if (!ob->pose->runtime->chanhash.is_empty()) {
1297 ob->pose->runtime->chanhash.remove(pchan->name);
1298 }
1299 BLI_freelinkN(&ob->pose->chanbase, pchan);
1300 }
1301 else {
1302 /* Maybe something the bone references is being removed instead? */
1303 for (bConstraint &con : pchan->constraints) {
1304 ListBaseT<bConstraintTarget> targets = {nullptr, nullptr};
1305 if (BKE_constraint_targets_get(&con, &targets)) {
1306 for (bConstraintTarget &ct : targets) {
1307 if (ct.tar == ob) {
1308 if (ct.subtarget[0]) {
1309 if (filter_fn(ct.subtarget, user_data)) {
1310 con.flag |= CONSTRAINT_DISABLE;
1311 ct.subtarget[0] = 0;
1312 }
1313 }
1314 }
1315 }
1316
1317 BKE_constraint_targets_flush(&con, &targets, false);
1318 }
1319 }
1320
1321 if (pchan->bbone_prev) {
1322 if (filter_fn(pchan->bbone_prev->name, user_data)) {
1323 pchan->bbone_prev = nullptr;
1324 }
1325 }
1326 if (pchan->bbone_next) {
1327 if (filter_fn(pchan->bbone_next->name, user_data)) {
1328 pchan->bbone_next = nullptr;
1329 }
1330 }
1331
1332 if (pchan->custom_tx) {
1333 if (filter_fn(pchan->custom_tx->name, user_data)) {
1334 pchan->custom_tx = nullptr;
1335 }
1336 }
1337 }
1338 }
1339 }
1340}
1341
1342void BKE_pose_channel_free_ex(bPoseChannel *pchan, bool do_id_user)
1343{
1344 if (pchan->custom) {
1345 if (do_id_user) {
1346 id_us_min(&pchan->custom->id);
1347 }
1348 pchan->custom = nullptr;
1349 }
1350
1351 if (pchan->mpath) {
1353 pchan->mpath = nullptr;
1354 }
1355
1356 BKE_constraints_free_ex(&pchan->constraints, do_id_user);
1357
1358 if (pchan->prop) {
1359 IDP_FreeProperty_ex(pchan->prop, do_id_user);
1360 pchan->prop = nullptr;
1361 }
1362 if (pchan->system_properties) {
1363 IDP_FreeProperty_ex(pchan->system_properties, do_id_user);
1364 pchan->system_properties = nullptr;
1365 }
1366
1367 /* Cached data, for new draw manager rendering code. */
1368 MEM_SAFE_DELETE(pchan->draw_data);
1369
1370 /* Cached B-Bone shape and other data. */
1372}
1373
1378
1380{
1381 const SessionUID uid = runtime->session_uid;
1382 *runtime = bPoseChannel_Runtime{};
1383 runtime->session_uid = uid;
1384}
1385
1390
1392{
1393 runtime->bbone_segments = 0;
1394 MEM_SAFE_DELETE(runtime->bbone_rest_mats);
1395 MEM_SAFE_DELETE(runtime->bbone_pose_mats);
1396 MEM_SAFE_DELETE(runtime->bbone_deform_mats);
1397 MEM_SAFE_DELETE(runtime->bbone_dual_quats);
1398 MEM_SAFE_DELETE(runtime->bbone_segment_boundaries);
1399}
1400
1402{
1403 BKE_pose_channel_free_ex(pchan, true);
1404}
1405
1406void BKE_pose_channels_free_ex(bPose *pose, bool do_id_user)
1407{
1408 if (!pose->chanbase.is_empty()) {
1409 for (bPoseChannel &pchan : pose->chanbase) {
1410 BKE_pose_channel_free_ex(&pchan, do_id_user);
1411 }
1412
1413 pose->chanbase.free_no_destruct();
1414 }
1415
1417
1418 pose->runtime->chan_array.reinitialize(0);
1419}
1420
1425
1426void BKE_pose_free_data_ex(bPose *pose, bool do_id_user)
1427{
1428 /* free pose-channels */
1429 BKE_pose_channels_free_ex(pose, do_id_user);
1430
1431 /* free pose-groups */
1432 if (pose->agroups.first()) {
1433 pose->agroups.free_no_destruct();
1434 }
1435
1436 /* free IK solver state */
1438
1439 /* free IK solver param */
1440 if (pose->ikparam) {
1441 MEM_delete(pose->ikparam);
1442 }
1443
1444 MEM_delete(pose->runtime);
1445 pose->runtime = nullptr;
1446}
1447
1452
1453void BKE_pose_free_ex(bPose *pose, bool do_id_user)
1454{
1455 if (pose) {
1456 BKE_pose_free_data_ex(pose, do_id_user);
1457 /* free pose */
1458 MEM_delete(pose);
1459 }
1460}
1461
1463{
1464 BKE_pose_free_ex(pose, true);
1465}
1466
1468{
1469 /* copy transform locks */
1470 pchan->protectflag = pchan_from->protectflag;
1471
1472 /* copy rotation mode */
1473 pchan->rotmode = pchan_from->rotmode;
1474
1475 /* copy bone group */
1476 pchan->agrp_index = pchan_from->agrp_index;
1477
1478 /* IK (DOF) settings. */
1479 pchan->ikflag = pchan_from->ikflag;
1480 copy_v3_v3(pchan->limitmin, pchan_from->limitmin);
1481 copy_v3_v3(pchan->limitmax, pchan_from->limitmax);
1482 copy_v3_v3(pchan->stiffness, pchan_from->stiffness);
1483 pchan->ikstretch = pchan_from->ikstretch;
1484 pchan->ikrotweight = pchan_from->ikrotweight;
1485 pchan->iklinweight = pchan_from->iklinweight;
1486
1487 /* bbone settings (typically not animated) */
1488 pchan->bbone_next = pchan_from->bbone_next;
1489 pchan->bbone_prev = pchan_from->bbone_prev;
1490
1491 /* constraints */
1492 BKE_constraints_copy(&pchan->constraints, &pchan_from->constraints, true);
1493
1494 /* id-properties */
1495 if (pchan->prop) {
1496 /* Unlikely, but possible that it exists. */
1497 IDP_FreeProperty(pchan->prop);
1498 pchan->prop = nullptr;
1499 }
1500 if (pchan_from->prop) {
1501 pchan->prop = IDP_CopyProperty(pchan_from->prop);
1502 }
1503 if (pchan->system_properties) {
1504 /* Unlikely, but possible that it exists. */
1506 pchan->system_properties = nullptr;
1507 }
1508 if (pchan_from->system_properties) {
1510 }
1511
1512 /* custom shape */
1513 pchan->custom = pchan_from->custom;
1514 if (pchan->custom) {
1515 id_us_plus(&pchan->custom->id);
1516 }
1517 copy_v3_v3(pchan->custom_scale_xyz, pchan_from->custom_scale_xyz);
1521
1522 pchan->color.palette_index = pchan_from->color.palette_index;
1523 copy_v4_v4_uchar(pchan->color.custom.active, pchan_from->color.custom.active);
1524 copy_v4_v4_uchar(pchan->color.custom.select, pchan_from->color.custom.select);
1525 copy_v4_v4_uchar(pchan->color.custom.solid, pchan_from->color.custom.solid);
1526 pchan->color.custom.flag = pchan_from->color.custom.flag;
1527
1528 pchan->drawflag = pchan_from->drawflag;
1529}
1530
1532{
1533 bPose *pose = pose_ob.pose;
1535
1536 for (bPoseChannel &pchan : pose_ob.pose->chanbase) {
1537 pchan.constflag = ePchan_ConstFlag{};
1538
1539 for (bConstraint &con : pchan.constraints) {
1540 pchan.constflag |= PCHAN_HAS_CONST;
1541
1542 switch (con.type) {
1544 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con.data);
1545
1546 pchan.constflag |= PCHAN_HAS_IK;
1547
1548 if (data->tar == nullptr || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0))
1549 {
1551 }
1552
1553 bPoseChannel *chain_tip = (data->flag & CONSTRAINT_IK_TIP) ? &pchan : pchan.parent;
1554
1555 /* negative rootbone = recalc rootbone index. used in do_versions */
1556 if (data->rootbone < 0) {
1557 data->rootbone = 0;
1558
1559 /* TODO(Sybren): call the yet-to-be-written 'assert the bone indices are up to date'
1560 * function. This walk uses the armature bone hierarchy (via parbone->parent) rather
1561 * than the pose channel hierarchy, which is only safe when the pose is consistent
1562 * with the armature. The assert function will make that precondition explicit. */
1563 Bone *parbone = chain_tip->bone_get(pose_ob);
1564 while (parbone) {
1565 data->rootbone++;
1566 if ((parbone->flag & BONE_CONNECTED) == 0) {
1567 break;
1568 }
1569 parbone = parbone->parent;
1570 }
1571 }
1572
1573 /* Mark the pose bones in the IK chain as influenced by it. */
1574 {
1575 bPoseChannel *chain_bone = chain_tip;
1576 for (short index = 0; chain_bone && (data->rootbone == 0 || index < data->rootbone);
1577 index++)
1578 {
1579 chain_bone->constflag |= PCHAN_INFLUENCED_BY_IK;
1580 chain_bone = chain_bone->parent;
1581 }
1582 }
1583 break;
1584 }
1585
1588
1589 /* if we have a valid target, make sure that this will get updated on frame-change
1590 * (needed for when there is no anim-data for this pose)
1591 */
1592 if ((data->tar) && (data->tar->type == OB_CURVES_LEGACY)) {
1594 }
1595 break;
1596 }
1597
1600 break;
1601
1602 default:
1603 break;
1604 }
1605 }
1606 }
1607
1609}
1610
1615
1616/* ************************** Bone Groups ************************** */
1617
1619{
1620 bActionGroup *grp;
1621
1622 if (!name) {
1623 name = DATA_("Group");
1624 }
1625
1626 grp = MEM_new<bActionGroup>("PoseGroup");
1627 STRNCPY_UTF8(grp->name, name);
1628 BLI_addtail(&pose->agroups, grp);
1629 BLI_uniquename(&pose->agroups, grp, name, '.', offsetof(bActionGroup, name), sizeof(grp->name));
1630
1631 pose->active_group = pose->agroups.count();
1632
1633 return grp;
1634}
1635
1637{
1638 int idx = index;
1639
1640 if (idx < 1) {
1641 idx = BLI_findindex(&pose->agroups, grp) + 1;
1642 }
1643
1644 BLI_assert(idx > 0);
1645
1646 /* adjust group references (the trouble of using indices!):
1647 * - firstly, make sure nothing references it
1648 * - also, make sure that those after this item get corrected
1649 */
1650 for (bPoseChannel &pchan : pose->chanbase) {
1651 if (pchan.agrp_index == idx) {
1652 pchan.agrp_index = 0;
1653 }
1654 else if (pchan.agrp_index > idx) {
1655 pchan.agrp_index--;
1656 }
1657 }
1658
1659 /* now, remove it from the pose */
1660 BLI_freelinkN(&pose->agroups, grp);
1661 if (pose->active_group >= idx) {
1662 const bool has_groups = !pose->agroups.is_empty();
1663 pose->active_group--;
1664 if (pose->active_group == 0 && has_groups) {
1665 pose->active_group = 1;
1666 }
1667 else if (pose->active_group < 0 || !has_groups) {
1668 pose->active_group = 0;
1669 }
1670 }
1671}
1672
1674{
1675 bActionGroup *grp = nullptr;
1676
1677 /* get group to remove */
1678 grp = static_cast<bActionGroup *>(BLI_findlink(&pose->agroups, index - 1));
1679 if (grp) {
1681 }
1682}
1683
1684/* ************** Pose Management Tools ****************** */
1685
1686void BKE_pose_rest(Object &pose_ob, bool selected_bones_only)
1687{
1688 bPose *pose = pose_ob.pose;
1689 if (!pose) {
1690 return;
1691 }
1692
1693 memset(pose->stride_offset, 0, sizeof(pose->stride_offset));
1694 memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset));
1695
1696 for (bPoseChannel &pchan : pose->chanbase) {
1697 if (selected_bones_only && pchan.bone_get(pose_ob) != nullptr &&
1698 (pchan.flag & POSE_SELECTED) == 0)
1699 {
1700 continue;
1701 }
1702 zero_v3(pchan.loc);
1703 zero_v3(pchan.eul);
1704 unit_qt(pchan.quat);
1705 unit_axis_angle(pchan.rotAxis, &pchan.rotAngle);
1706 pchan.scale[0] = pchan.scale[1] = pchan.scale[2] = 1.0f;
1707
1708 pchan.roll1 = pchan.roll2 = 0.0f;
1709 pchan.curve_in_x = pchan.curve_in_z = 0.0f;
1710 pchan.curve_out_x = pchan.curve_out_z = 0.0f;
1711 pchan.ease1 = pchan.ease2 = 0.0f;
1712
1713 copy_v3_fl(pchan.scale_in, 1.0f);
1714 copy_v3_fl(pchan.scale_out, 1.0f);
1715 }
1716}
1717
1719{
1720 copy_m4_m4(pchanto->pose_mat, pchanfrom->pose_mat);
1721 copy_m4_m4(pchanto->chan_mat, pchanfrom->chan_mat);
1722
1723 /* used for local constraints */
1724 copy_v3_v3(pchanto->loc, pchanfrom->loc);
1725 copy_qt_qt(pchanto->quat, pchanfrom->quat);
1726 copy_v3_v3(pchanto->eul, pchanfrom->eul);
1727 copy_v3_v3(pchanto->scale, pchanfrom->scale);
1728
1729 copy_v3_v3(pchanto->pose_head, pchanfrom->pose_head);
1730 copy_v3_v3(pchanto->pose_tail, pchanfrom->pose_tail);
1731
1732 pchanto->roll1 = pchanfrom->roll1;
1733 pchanto->roll2 = pchanfrom->roll2;
1734 pchanto->curve_in_x = pchanfrom->curve_in_x;
1735 pchanto->curve_in_z = pchanfrom->curve_in_z;
1736 pchanto->curve_out_x = pchanfrom->curve_out_x;
1737 pchanto->curve_out_z = pchanfrom->curve_out_z;
1738 pchanto->ease1 = pchanfrom->ease1;
1739 pchanto->ease2 = pchanfrom->ease2;
1740
1741 copy_v3_v3(pchanto->scale_in, pchanfrom->scale_in);
1742 copy_v3_v3(pchanto->scale_out, pchanfrom->scale_out);
1743
1744 pchanto->rotmode = pchanfrom->rotmode;
1745 pchanto->flag = pchanfrom->flag;
1746 pchanto->protectflag = pchanfrom->protectflag;
1747}
1748
1750{
1751 if (to == nullptr || from == nullptr) {
1752 CLOG_ERROR(
1753 &LOG, "Pose copy error, pose to:%p from:%p", (void *)to, (void *)from); /* debug temp */
1754 return false;
1755 }
1756
1757 if (to == from) {
1758 CLOG_ERROR(&LOG, "source and target are the same");
1759 return false;
1760 }
1761
1762 for (bPoseChannel &pchanfrom : from->chanbase) {
1763 bPoseChannel *pchanto = BKE_pose_channel_find_name(to, pchanfrom.name);
1764 if (pchanto != nullptr) {
1765 BKE_pose_copy_pchan_result(pchanto, &pchanfrom);
1766 }
1767 }
1768 return true;
1769}
1770
1772{
1773 pose->flag |= POSE_RECALC;
1774 /* Depsgraph components depends on actual pose state,
1775 * if pose was changed depsgraph is to be updated as well.
1776 */
1778}
1779
1781 Object *workob,
1782 bPose *pose,
1783 bAction *act,
1784 const int32_t action_slot_handle,
1785 const char groupname[],
1786 const AnimationEvalContext *anim_eval_context)
1787{
1788 using namespace blender::animrig;
1789 BLI_assert(act);
1790
1791 bActionGroup *agrp = nullptr;
1792 if (groupname && groupname[0]) {
1793 /* Find the named channel group. */
1794 Action &action = act->wrap();
1795 Channelbag *cbag = channelbag_for_action_slot(action, action_slot_handle);
1796 agrp = cbag ? cbag->channel_group_find(groupname) : nullptr;
1797 }
1798
1799 /* clear workob */
1800 bke::ObjectRuntime workob_runtime;
1802 workob->runtime = &workob_runtime;
1803
1804 /* init workob */
1805 copy_m4_m4(workob->runtime->object_to_world.ptr(), ob->object_to_world().ptr());
1806 copy_m4_m4(workob->parentinv, ob->parentinv);
1807 copy_m4_m4(workob->constinv, ob->constinv);
1808 workob->parent = ob->parent;
1809
1810 workob->rotmode = ob->rotmode;
1811
1812 workob->trackflag = ob->trackflag;
1813 workob->upflag = ob->upflag;
1814
1815 workob->partype = ob->partype;
1816 workob->par1 = ob->par1;
1817 workob->par2 = ob->par2;
1818 workob->par3 = ob->par3;
1819
1820 workob->constraints.first_ = ob->constraints.first();
1821 workob->constraints.last_ = ob->constraints.last();
1822
1823 /* Need to set pose too, since this is used for both types of Action Constraint. */
1824 workob->pose = pose;
1825 if (pose) {
1826 /* This function is most likely to be used with a temporary pose with a single bone in there.
1827 * For such cases it makes no sense to create hash since it'll only waste CPU ticks on memory
1828 * allocation and also will make lookup slower.
1829 */
1830 if (pose->chanbase.first() != pose->chanbase.last()) {
1832 }
1835 }
1836 }
1837
1838 STRNCPY_UTF8(workob->parsubstr, ob->parsubstr);
1839
1840 /* we don't use real object name, otherwise RNA screws with the real thing */
1841 STRNCPY_UTF8(workob->id.name, "OB<ConstrWorkOb>");
1842
1843 /* If we're given a group to use, it's likely to be more efficient
1844 * (though a bit more dangerous). */
1845 if (agrp) {
1846 /* specifically evaluate this group only */
1847
1848 /* get RNA-pointer for the workob's ID */
1849 PointerRNA id_ptr = RNA_id_pointer_create(&workob->id);
1850
1851 /* execute action for this group only */
1852 animsys_evaluate_action_group(&id_ptr, act, agrp, anim_eval_context);
1853 }
1854 else {
1855 AnimData adt = {nullptr};
1856
1857 /* init animdata, and attach to workob */
1858 workob->adt = &adt;
1859
1860 adt.action = act;
1861 adt.slot_handle = action_slot_handle;
1862
1863 /* execute effects of Action on to workob (or its PoseChannels) */
1864 BKE_animsys_evaluate_animdata(&workob->id, &adt, anim_eval_context, ADT_RECALC_ANIM, false);
1865
1866 /* Ensure stack memory set here isn't accessed later, relates to !118847. */
1867 workob->adt = nullptr;
1868 }
1869 /* Ensure stack memory set here isn't accessed later, see !118847. */
1870 workob->runtime = nullptr;
1871}
1872
1874{
1875 if (pose == nullptr) {
1876 return;
1877 }
1878
1879 Set<SessionUID> used_uids;
1880
1881 for (bPoseChannel &pchan : pose->chanbase) {
1882 const SessionUID *session_uid = &pchan.runtime.session_uid;
1883 if (!session_uid->is_generated()) {
1884 printf("Pose channel %s does not have UID generated.\n", pchan.name);
1885 continue;
1886 }
1887
1888 if (!used_uids.add(*session_uid)) {
1889 printf("Pose channel %s has duplicate UID generated.\n", pchan.name);
1890 continue;
1891 }
1892 }
1893}
1894
1896{
1897#ifndef __GNUC__
1898 BLI_assert(pose != nullptr);
1899#endif
1900
1901 /* Write channels */
1902 for (bPoseChannel &chan : pose->chanbase) {
1903 /* Write ID Properties -- and copy this comment EXACTLY for easy finding
1904 * of library blocks that implement this. */
1905 if (chan.prop) {
1906 IDP_BlendWrite(writer, chan.prop);
1907 }
1908 if (chan.system_properties) {
1909 IDP_BlendWrite(writer, chan.system_properties);
1910 }
1911
1913
1914 bke::motionpath::blend_write(writer, chan.mpath);
1915
1916 writer->write_struct(&chan, [](BlendStructWriter<bPoseChannel> &struct_writer) {
1917 struct_writer.shallow_data.runtime = {};
1918 });
1919 }
1920
1921 /* Write groups */
1922 for (bActionGroup &grp : pose->agroups) {
1923 writer->write_struct(&grp);
1924 }
1925
1926 /* write IK param */
1927 if (pose->ikparam) {
1928 const char *structname = BKE_pose_ikparam_get_name(pose);
1929 if (structname) {
1930 writer->write_struct_by_name(structname, pose->ikparam);
1931 }
1932 }
1933
1934 /* Write this pose */
1935 writer->write_struct(pose, [](BlendStructWriter<bPose> &struct_writer) {
1936 struct_writer.shallow_data.runtime = nullptr;
1937 });
1938}
1939
1941{
1942 if (!pose) {
1943 return;
1944 }
1945
1946 BLO_read_struct_list(reader, bPoseChannel, &pose->chanbase);
1947 BLO_read_struct_list(reader, bActionGroup, &pose->agroups);
1948
1949 pose->runtime = MEM_new<bke::bPoseRuntime>(__func__);
1950
1951 for (bPoseChannel &pchan : pose->chanbase) {
1954
1955 BLO_read_struct(reader, bPoseChannel, &pchan.parent);
1956 BLO_read_struct(reader, bPoseChannel, &pchan.child);
1957 BLO_read_struct(reader, bPoseChannel, &pchan.custom_tx);
1958
1959 BLO_read_struct(reader, bPoseChannel, &pchan.bbone_prev);
1960 BLO_read_struct(reader, bPoseChannel, &pchan.bbone_next);
1961
1962 BKE_constraint_blend_read_data(reader, id_owner, &pchan.constraints);
1963
1964 BLO_read_struct(reader, IDProperty, &pchan.prop);
1965 IDP_BlendDataRead(reader, &pchan.prop);
1967 IDP_BlendDataRead(reader, &pchan.system_properties);
1968
1969 BLO_read_struct(reader, bMotionPath, &pchan.mpath);
1970 if (pchan.mpath) {
1972 }
1973
1974 pchan.iktree.clear_no_delete();
1975 pchan.siktree.clear_no_delete();
1976
1977 /* in case this value changes in future, clamp else we get undefined behavior */
1979
1980 pchan.draw_data = nullptr;
1981 }
1982 if (pose->ikparam != nullptr) {
1983 const char *structname = BKE_pose_ikparam_get_name(pose);
1984 if (structname) {
1985 pose->ikparam = static_cast<bItasc *>(
1986 BLO_read_struct_by_name_array(reader, structname, 1, pose->ikparam));
1987 }
1988 else {
1989 pose->ikparam = nullptr;
1990 }
1991 }
1992}
1993
1995{
1996 if (!pose || !ob->data) {
1997 return;
1998 }
1999
2000 bArmature *arm = id_cast<bArmature *>(ob->data);
2001
2002 /* Always rebuild to match library changes, except on Undo. */
2003 bool rebuild = false;
2004
2005 if (!BLO_read_lib_is_undo(reader)) {
2006 if (ob->id.lib != arm->id.lib) {
2007 rebuild = true;
2008 }
2009 }
2010
2011 for (bPoseChannel &pchan : pose->chanbase) {
2012 /* At some point in history, bones could have an armature object as custom shape, which caused
2013 * all kinds of wonderful issues. This is now avoided in RNA, but through the magic of linking
2014 * and editing the library file, the situation can still occur. Better to just reset the
2015 * pointer in those cases. */
2016 if (pchan.custom && pchan.custom->type == OB_ARMATURE) {
2017 pchan.custom = nullptr;
2018 }
2019
2020 /* An unnamed pose channel can never be matched to a bone, and the bone it belonged to has
2021 * been given a name by fix_empty_bone_names() on read. Rebuild so the stale channel is
2022 * dropped and a channel for the renamed bone is created. See #162046. */
2023 if (pchan.name[0] == '\0') {
2024 rebuild = true;
2025 }
2026 }
2027
2028 if (rebuild) {
2029 Main *bmain = BLO_read_lib_get_main(reader);
2032 BKE_pose_tag_recalc(bmain, pose);
2033 }
2034}
2035
2036} // namespace blender
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
C++ part of the BoneColor DNA struct.
Versioning of old animation data. Most animation versioning code lives in the versioning_xxx....
Blender kernel action and pose functionality.
support for deformation groups and hooks.
#define IDP_BlendDataRead(reader, prop)
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
General operations, lookup, etc. for blender objects.
#define M_PI
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define BLT_I18NCONTEXT_ID_ACTION
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
ID and Library types, which are fundamental for SDNA.
#define FILTER_ID_ALL
Definition DNA_ID.h:1241
#define FILTER_ID_AC
Definition DNA_ID.h:1199
#define MAXBONENAME
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define CLAMP(a, b, c)
#define BLI_assert(a)
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
Span< const Slot * > slots() const
const Layer * layer(int64_t index) const
const Slot * slot(int64_t index) const
Span< const Layer * > layers() const
Span< const StripKeyframeData * > strip_keyframe_data() const
const ThemeWireColor * effective_color() const
Definition bonecolor.cc:32
Span< const bActionGroup * > channel_groups() const
const bActionGroup * channel_group_find(StringRef name) const
Span< const FCurve * > fcurves() const
Layer * duplicate_with_shallow_strip_copies(StringRefNull allocation_name) const
static void users_invalidate(Main &bmain)
Span< const Channelbag * > channelbags() const
static Strip & create(Action &owning_action, const Strip::Type type)
#define offsetof(t, d)
#define layer
bool action_is_layered(const bAction &dna_action)
Definition versioning.cc:38
void assert_baklava_phase_1_invariants(const Action &action)
const animrig::Channelbag * channelbag_for_action_slot(const Action &action, slot_handle_t slot_handle)
const BoneColor & ANIM_bonecolor_posebone_get(bke::PChanBoneConst pchanbone)
Definition bonecolor.cc:90
bool bone_is_selected(const bArmature *armature, const Bone *bone)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
void blend_read_data(struct BlendDataReader *reader, struct bMotionPath *mpath)
struct bMotionPath * copy(const struct bMotionPath *mpath_src)
void free(struct bMotionPath *mpath)
void blend_write(struct BlendWriter *writer, struct bMotionPath *mpath)
static void write_strips(BlendWriter *writer, Span< animrig::Strip * > strips)
static void action_blend_read_data(BlendDataReader *reader, ID *id)
static void action_init_data(ID *action_id)
static void action_blend_write_clear_legacy_fcurves_listbase(ListBaseT< FCurve > &listbase)
static void read_layers(BlendDataReader *reader, animrig::Action &action)
static void write_layers(BlendWriter *writer, Span< animrig::Layer * > layers)
static void action_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
static void read_slots(BlendDataReader *reader, animrig::Action &action)
static void read_strip_keyframe_data_array(BlendDataReader *reader, animrig::Action &action)
static void read_strip_keyframe_data(BlendDataReader *reader, animrig::StripKeyframeData &strip_keyframe_data)
static void action_blend_write_make_legacy_fcurves_listbase(ListBaseT< FCurve > &listbase, const Span< FCurve * > fcurves)
static void write_slots(BlendWriter *writer, Span< animrig::Slot * > slots)
PChanBoneT< const bPoseChannel, const Bone > PChanBoneConst
Definition BKE_pose.hh:89
static IDProperty * action_asset_type_property(const bAction *action)
static void write_strip_keyframe_data(BlendWriter *writer, animrig::StripKeyframeData &strip_keyframe_data)
static void action_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data)
static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address)
static void write_strip_keyframe_data_array(BlendWriter *writer, Span< animrig::StripKeyframeData * > strip_keyframe_data_array)
static void action_free_data(ID *id)
static void read_channelbag(BlendDataReader *reader, animrig::Channelbag &channelbag)
static void action_blend_write_make_legacy_channel_groups_listbase(ListBaseT< bActionGroup > &listbase, const Span< bActionGroup * > channel_groups)
static void write_channelbag(BlendWriter *writer, animrig::Channelbag &channelbag)
static void action_blend_write_clear_legacy_channel_groups_listbase(ListBaseT< bActionGroup > &listbase)
static void action_foreach_id(ID *id, LibraryForeachIDData *data)
static AssetTypeInfo AssetType_AC
BLI_INLINE Texture * wrap(MTLTexture *texture)
BMesh Iterators.
bPoseChannel * BKE_pose_channel_ensure(bPose *pose, const char *name) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_constraints_copy_ex(ListBaseT< bConstraint > *dst, const ListBaseT< bConstraint > *src, int flag, bool do_extern)
void BKE_copy_time_markers(ListBaseT< TimeMarker > &markers_dst, const ListBaseT< TimeMarker > &markers_src, int flag)
Definition anim_sys.cc:3962
Main * BKE_lib_query_foreachid_process_main_get(const LibraryForeachIDData *data)
Definition lib_query.cc:138
bPoseChannel * BKE_pose_channel_active(Object *ob, bool check_bonecoll)
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1398
void BKE_previewimg_id_free(ID *id)
void BKE_pose_tag_recalc(Main *bmain, bPose *pose) ATTR_NONNULL(1
@ ADT_RECALC_ANIM
void BKE_time_markers_blend_read(BlendDataReader *reader, ListBaseT< TimeMarker > &markers)
Definition anim_sys.cc:3944
void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop)
Definition asset.cc:172
void void bool BKE_pose_copy_result(bPose *to, bPose *from)
@ POSE_CONSTRAINTS_NEED_UPDATE_FLAGS
@ POSE_CONSTRAINTS_TIMEDEPEND
void action_group_colors_set(bActionGroup *grp, const BoneColor *color)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BKE_previewimg_blend_read(BlendDataReader *reader, PreviewImage *prv)
void * BLO_read_struct_by_name_array(BlendDataReader *reader, StringRef struct_name, int64_t items_num, const void *old_address)
Definition readfile.cc:6521
void BKE_constraint_targets_flush(struct bConstraint *con, ListBaseT< bConstraintTarget > *targets, bool no_copy)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void BKE_pose_channel_free_bbone_cache(bPoseChannel_Runtime *runtime) ATTR_NONNULL(1)
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
void id_us_plus(ID *id)
Definition lib_id.cc:433
PointerRNA RNA_id_pointer_create(ID *id)
void BKE_pose_free_ex(bPose *pose, bool do_id_user)
void BKE_pose_free_data(bPose *pose) ATTR_NONNULL(1)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
void BKE_fcurves_free(ListBaseT< FCurve > *list)
void BKE_pose_channels_hash_free(bPose *pose) ATTR_NONNULL(1)
void BKE_previewimg_blend_write(BlendWriter *writer, const PreviewImage *prv)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void BKE_pose_free(bPose *pose)
static bool transform_follows_custom_tx(const bArmature *arm, const bPoseChannel *pchan)
MINLINE void rgba_uchar_args_set(unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1696
void BKE_pose_tag_update_constraint_flags(bPose *pose) ATTR_NONNULL(1)
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
void void BKE_pose_copy_pchan_result(bPoseChannel *pchanto, const bPoseChannel *pchanfrom) ATTR_NONNULL(1
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void BKE_fcurve_blend_read_data_listbase(BlendDataReader *reader, ListBaseT< FCurve > *fcurves)
void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, int index) ATTR_NONNULL(1)
bool ANIM_bone_in_visible_collection(const bArmature *armature, const Bone *bone)
void BKE_pose_channels_hash_ensure(bPose *pose) ATTR_NONNULL(1)
static void pose_channels_remove_internal_links(Object *ob, bPoseChannel *unlinked_pchan)
bAction * BKE_action_add(Main *bmain, const char name[])
void BKE_fcurve_blend_write_data(BlendWriter *writer, FCurve *fcu)
void BIK_clear_data(struct bPose *pose)
void BKE_fcurve_blend_read_data(BlendDataReader *reader, FCurve *fcu)
void BKE_pose_channel_runtime_reset(bPoseChannel_Runtime *runtime) ATTR_NONNULL(1)
void BKE_fcurve_blend_write_listbase(BlendWriter *writer, ListBaseT< FCurve > *fcurves)
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
Definition lib_query.cc:133
void BKE_pose_ensure_bone_indices(const Object &pose_object)
void BKE_pose_channel_transform_orientation(const bArmature *arm, const bPoseChannel *pose_bone, float r_pose_orientation[3][3])
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2890
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_COPY_NO_PREVIEW
@ LIB_ID_CREATE_NO_MAIN
void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup *agrp, const AnimationEvalContext *anim_eval_context)
Definition anim_sys.cc:654
void unit_axis_angle(float axis[3], float *angle)
void unit_qt(float q[4])
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, int32_t action_slot_handle, const char groupname[], const AnimationEvalContext *anim_eval_context) ATTR_NONNULL(1
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void BKE_pose_channel_free(bPoseChannel *pchan) ATTR_NONNULL(1)
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
void BKE_pose_channel_transform_location(const bArmature *arm, const bPoseChannel *pose_bone, float r_pose_space_pivot[3])
bPoseChannel * BKE_pose_channel_get_mirrored(const bPose *pose, const char *name) ATTR_WARN_UNUSED_RESULT
void BKE_pose_channels_free(bPose *pose) ATTR_NONNULL(1)
void BKE_pose_copy_data_ex(bPose **dst, const bPose *src, int flag, bool copy_constraints)
void copy_qt_qt(float q[4], const float a[4])
bool BKE_pose_channels_is_valid(const bPose *pose) ATTR_WARN_UNUSED_RESULT
BMesh const char void * data
void BKE_constraints_copy(ListBaseT< bConstraint > *dst, const ListBaseT< bConstraint > *src, bool do_extern)
void BKE_time_markers_blend_write(BlendWriter *writer, ListBaseT< TimeMarker > &markers)
Definition anim_sys.cc:3933
const char * BKE_pose_ikparam_get_name(bPose *pose) ATTR_WARN_UNUSED_RESULT
FCurve * BKE_fcurve_copy(const FCurve *fcu)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
void BKE_object_workob_clear(Object *workob)
Definition object.cc:1302
void void BKE_pose_blend_write(BlendWriter *writer, bPose *pose) ATTR_NONNULL(1
void BKE_pose_channel_free_ex(bPoseChannel *pchan, bool do_id_user) ATTR_NONNULL(1)
int BKE_constraint_targets_get(struct bConstraint *con, ListBaseT< bConstraintTarget > *r_targets)
void unit_m4(float m[4][4])
void BKE_pose_channels_remove(Object *ob, bool(*filter_fn)(const char *bone_name, void *user_data), void *user_data) ATTR_NONNULL(1
void BKE_pose_channel_session_uid_generate(bPoseChannel *pchan)
void BKE_pose_update_constraint_flags(Object &pose_ob)
SessionUID BLI_session_uid_generate()
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MINLINE void zero_v3(float r[3])
void BKE_constraint_blend_read_data(struct BlendDataReader *reader, struct ID *id_owner, ListBaseT< bConstraint > *lb)
@ ITASC_INITIAL_REITERATION
static bool pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan, int level)
void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_from)
void BKE_pose_channel_runtime_reset_on_copy(bPoseChannel_Runtime *runtime) ATTR_NONNULL(1)
void BKE_pose_remove_group_index(bPose *pose, int index) ATTR_NONNULL(1)
Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition readfile.cc:6853
void BKE_pose_copy_data(bPose **dst, const bPose *src, bool copy_constraints)
void BKE_animsys_evaluate_animdata(ID *id, AnimData *adt, const AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, bool flush_to_original)
Definition anim_sys.cc:3716
void BKE_previewimg_id_copy(ID *new_id, const ID *old_id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bool BKE_pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan)
MINLINE void copy_v3_fl(float r[3], float f)
void void void void BKE_pose_blend_read_after_liblink(BlendLibReader *reader, Object *ob, bPose *pose) ATTR_NONNULL(1
@ INDEX_ID_AC
Definition DNA_ID.h:1286
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
void void void BKE_pose_blend_read_data(BlendDataReader *reader, ID *id_owner, bPose *pose) ATTR_NONNULL(1
void BKE_pose_channels_free_ex(bPose *pose, bool do_id_user) ATTR_NONNULL(1)
@ POSE_TRANSFORM_AT_CUSTOM_TX
void BKE_free_time_markers(ListBaseT< TimeMarker > &markers, bool do_id_user)
Definition anim_sys.cc:3982
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
signed int int32_t
Definition BKE_text.h:78
static CLG_LogRef LOG
Definition logging.cpp:12
bool BLO_read_lib_is_undo(BlendLibReader *reader)
Definition readfile.cc:6848
void DEG_relations_tag_update(Main *bmain)
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
void BKE_pose_channel_runtime_free(bPoseChannel_Runtime *runtime) ATTR_NONNULL(1)
bool BKE_pose_is_bonecoll_visible(const bArmature *arm, const bPoseChannel *pchan) ATTR_WARN_UNUSED_RESULT
void void BKE_pose_free_data_ex(bPose *pose, bool do_id_user) ATTR_NONNULL(1)
void BKE_constraints_free_ex(ListBaseT< bConstraint > *list, bool do_id_user)
void action_group_colors_sync(bActionGroup *grp)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
LibraryForeachIDCallbackFlag
@ IDWALK_CB_LOOPBACK
@ IDWALK_CB_NEVER_SELF
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:968
void BKE_pose_rest(Object &pose_ob, bool selected_bones_only)
void BKE_constraint_blend_write(struct BlendWriter *writer, ListBaseT< bConstraint > *conlist)
bPoseChannel * BKE_pose_channel_active_or_first_selected(Object *ob) ATTR_WARN_UNUSED_RESULT
void id_us_min(ID *id)
Definition lib_id.cc:441
void BKE_pose_check_uids_unique_and_report(const bPose *pose)
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
@ IDP_TYPE_FILTER_ID
void BKE_pose_ikparam_init(bPose *pose) ATTR_NONNULL(1)
void BKE_pose_itasc_init(bItasc *itasc)
void action_group_colors_set_from_posebone(bActionGroup *grp, bke::PChanBoneConst pchanbone)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
size_t BLI_string_flip_side_name(char *name_dst, const char *name_src, bool strip_number, size_t name_dst_maxncpy) ATTR_NONNULL(1
bActionGroup * BKE_pose_add_group(bPose *pose, const char *name) ATTR_NONNULL(1)
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition BKE_idtype.hh:52
const NodeType * type
Definition graph/node.h:179
ustring name
Definition graph/node.h:178
unsigned char select[4]
unsigned char solid[4]
unsigned char active[4]
ThemeWireColor tarm[20]
struct bActionGroup ** group_array
struct ActionChannelbag ** channelbag_array
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
void write_pointer_array(int64_t num, const void *data)
void write_struct_by_name(const char *struct_name, const void *data, BlendStructWriterFn fn=nullptr)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
bool is_undo() const
struct Bone * parent
bActionGroup * grp
struct FCurve * prev
struct FCurve * next
char name[258]
Definition DNA_ID.h:433
struct Library * lib
Definition DNA_ID.h:421
bool is_action_slot_to_id_map_dirty
Definition BKE_main.hh:342
const c_style_mat & ptr() const
struct Object * parent
float parentinv[4][4]
bke::ObjectRuntime * runtime
eObject_Partype partype
ListBaseT< bConstraint > constraints
eObject_Axis upflag
struct AnimData * adt
eObject_Axis trackflag
struct bPose * pose
struct Object * camera
struct IDProperty * prop
struct bActionGroup * next
ListBaseT< FCurve > channels
struct ActionChannelbag * channelbag
struct ActionSlot ** slot_array
PreviewImage * preview
struct ActionStripKeyframeData ** strip_keyframe_data_array
ListBaseT< FCurve > curves
ListBaseT< bActionGroup > groups
ListBaseT< struct TimeMarker > markers
struct ActionLayer ** layer_array
ePose_IKSolverType iksolver
eItasc_Solver solver
struct bPoseChannel_BBoneSegmentBoundary * bbone_segment_boundaries
struct bPoseChannel_Runtime runtime
struct bPoseChannel * parent
ListBaseT< struct PoseTree > iktree
bPoseChannelDrawData * draw_data
struct bPoseChannel * child
ListBaseT< struct bConstraint > constraints
struct bPoseChannel * custom_tx
struct bPoseChannel * next
struct bPoseChannel * bbone_next
ePchan_ConstFlag constflag
ListBaseT< struct tSplineIK_Tree > siktree
struct bPoseChannel * bbone_prev
bke::bPoseRuntime * runtime
bAnimVizSettings avs
ePose_IKSolverType iksolver
ListBaseT< bPoseChannel > chanbase
ListBaseT< struct bActionGroup > agroups
PoseChannelT * pchan
Definition BKE_pose.hh:61
Map< StringRef, bPoseChannel * > chanhash
Definition BKE_pose.hh:36
#define N_(msgid)