Blender
V5.3
source
blender
animrig
intern
action_runtime.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11
#include "
BKE_anim_data.hh
"
12
#include "
BKE_global.hh
"
13
#include "
BKE_lib_query.hh
"
14
#include "
BKE_main.hh
"
15
#include "
BKE_nla.hh
"
16
#include "
BKE_node.hh
"
17
18
#include "
BLI_listbase.hh
"
19
#include "
BLI_set.hh
"
20
21
#include "
ANIM_action.hh
"
22
#include "
ANIM_action_iterators.hh
"
23
24
#include "
action_runtime.hh
"
25
26
namespace
blender::animrig::internal
{
27
28
void
rebuild_slot_user_cache
(
Main
&bmain)
29
{
30
/* Loop over all Actions and clear their slots' user cache. */
31
for
(
bAction
&dna_action : bmain.
actions
) {
32
Action
&action = dna_action.wrap();
33
for
(
Slot
*slot : action.
slots
()) {
34
BLI_assert_msg
(slot->runtime,
"Slot::runtime should always be allocated"
);
35
slot->runtime->users.clear();
36
}
37
}
38
39
/* Mark all Slots as clear. This is a bit of a lie, because the code below still has to run.
40
* However, this is a necessity to make the `slot.users_add(*id)` call work without triggering
41
* an infinite recursion.
42
*
43
* The alternative would be to go around the `slot.users_add()` function and access the
44
* runtime directly, but this is IMO a bit cleaner. */
45
bmain.
is_action_slot_to_id_map_dirty
=
false
;
46
47
/* Visit any ID to see which Action+Slot it is using. Returns whether the ID
48
* was visited for the first time. */
49
Set<ID *>
visited_ids;
50
auto
visit_id = [&visited_ids](
ID
*
id
) ->
bool
{
51
BLI_assert
(
id
);
52
53
if
(!visited_ids.
add
(
id
)) {
54
return
false
;
55
}
56
57
foreach_action_slot_use
(*
id
, [&](
Action
&action,
slot_handle_t
slot_handle) {
58
Slot
*slot = action.
slot_for_handle
(slot_handle);
59
if
(!slot) {
60
return
true
;
61
}
62
slot->
users_add
(*
id
);
63
return
true
;
64
});
65
66
return
true
;
67
};
68
69
/* Loop over all IDs to cache their slot usage. */
70
ListBaseT<ID> *ids_of_idtype;
71
ID
*
id
;
72
FOREACH_MAIN_LISTBASE_BEGIN
(&bmain, ids_of_idtype) {
73
/* Check whether this ID type can be animated. If not, just skip all IDs of this type. */
74
id
= ids_of_idtype->first();
75
if
(!
id
|| !
id_type_can_have_animdata
(
GS
(
id
->name))) {
76
continue
;
77
}
78
79
FOREACH_MAIN_LISTBASE_ID_BEGIN
(ids_of_idtype,
id
) {
80
BLI_assert
(
id_can_have_animdata
(
id
));
81
82
/* Process the ID itself. */
83
if
(!visit_id(
id
)) {
84
continue
;
85
}
86
87
/* Process embedded IDs, as these are not listed in bmain, but still can
88
* have their own Action+Slot. Unfortunately there is no generic looper
89
* for embedded IDs. At this moment the only animatable embedded ID is a
90
* node tree. */
91
bNodeTree
*node_tree =
bke::node_tree_from_id
(
id
);
92
if
(node_tree) {
93
visit_id(&node_tree->
id
);
94
}
95
}
96
FOREACH_MAIN_LISTBASE_ID_END
;
97
}
98
FOREACH_MAIN_LISTBASE_END
;
99
}
100
101
}
// namespace blender::animrig::internal
ANIM_action.hh
Functions and classes to work with Actions.
ANIM_action_iterators.hh
Functionality to iterate an Action in various ways.
BKE_anim_data.hh
BKE_global.hh
BKE_lib_query.hh
BKE_main.hh
FOREACH_MAIN_LISTBASE_ID_END
#define FOREACH_MAIN_LISTBASE_ID_END
Definition
BKE_main.hh:703
FOREACH_MAIN_LISTBASE_ID_BEGIN
#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id)
Definition
BKE_main.hh:697
FOREACH_MAIN_LISTBASE_END
#define FOREACH_MAIN_LISTBASE_END
Definition
BKE_main.hh:715
FOREACH_MAIN_LISTBASE_BEGIN
#define FOREACH_MAIN_LISTBASE_BEGIN(_bmain, _lb)
Definition
BKE_main.hh:708
BKE_nla.hh
BKE_node.hh
BLI_listbase.hh
BLI_set.hh
action_runtime.hh
Internal C++ functions to deal with Actions, Slots, and their runtime data.
BLI_assert_msg
#define BLI_assert_msg(a, msg)
blender::Set
Definition
BLI_set.hh:106
blender::Set::add
bool add(const Key &key)
Definition
BLI_set.hh:248
blender::animrig::Action
Definition
ANIM_action.hh:88
blender::animrig::Action::slots
Span< const Slot * > slots() const
Definition
animrig/intern/action.cc:335
blender::animrig::Action::slot_for_handle
Slot * slot_for_handle(slot_handle_t handle)
Definition
animrig/intern/action.cc:352
blender::animrig::Slot
Definition
ANIM_action.hh:715
blender::animrig::Slot::users_add
void users_add(ID &animated_id)
Definition
animrig/intern/action.cc:1083
blender::animrig::internal
Definition
action_runtime.cc:26
blender::animrig::internal::rebuild_slot_user_cache
void rebuild_slot_user_cache(Main &bmain)
Definition
action_runtime.cc:28
blender::animrig::slot_handle_t
decltype(blender::ActionSlot::handle) slot_handle_t
Definition
ANIM_action_iterators.hh:30
blender::animrig::foreach_action_slot_use
bool foreach_action_slot_use(const ID &animated_id, FunctionRef< bool(Action &action, slot_handle_t slot_handle)> callback)
Definition
action_iterators.cc:94
blender::bke::id
Definition
AS_asset_library.hh:32
blender::bke::node_tree_from_id
bNodeTree * node_tree_from_id(ID *id)
Definition
node.cc:5337
blender::BLI_assert
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
blender::id_type_can_have_animdata
bool id_type_can_have_animdata(short id_type)
Definition
anim_data.cc:69
blender::id_can_have_animdata
bool id_can_have_animdata(const ID *id)
Definition
anim_data.cc:78
blender::GS
ID_Type GS(const char *name)
Definition
DNA_ID.h:410
blender::ID
Definition
DNA_ID.h:415
blender::Main
Definition
BKE_main.hh:243
blender::Main::is_action_slot_to_id_map_dirty
bool is_action_slot_to_id_map_dirty
Definition
BKE_main.hh:342
blender::Main::actions
ListBaseT< bAction > actions
Definition
BKE_main.hh:408
blender::bAction
Definition
DNA_action_types.h:1061
blender::bNodeTree
Definition
DNA_node_types.h:1891
blender::bNodeTree::id
ID id
Definition
DNA_node_types.h:1897
Generated on
for Blender by
doxygen
1.18.0