Blender V4.3
animrig/intern/nla.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "ANIM_nla.hh"
10
11#include "BKE_anim_data.hh"
12#include "BKE_lib_id.hh"
13#include "BKE_nla.hh"
14
15#include "BLI_string_utf8.h"
16
17namespace blender::animrig::nla {
18
19bool assign_action(NlaStrip &strip, Action &action, ID &animated_id)
20{
21 if (strip.act == &action) {
22 /* Already assigned, so just leave the slot as-is. */
23 return false;
24 }
25
26 unassign_action(strip, animated_id);
27
28 /* Assign the Action. */
29 strip.act = &action;
30 id_us_plus(&action.id);
31
32 /* Find a slot with the previously-used slot name. */
33 if (strip.action_slot_name[0]) {
34 Slot *slot = action.slot_find_by_name(strip.action_slot_name);
35 if (slot && assign_action_slot(strip, slot, animated_id) == ActionSlotAssignmentResult::OK) {
36 return true;
37 }
38 }
39
40 /* As a last resort, search for the ID name. */
41 Slot *slot = action.slot_find_by_name(animated_id.name);
42 if (slot && assign_action_slot(strip, slot, animated_id) == ActionSlotAssignmentResult::OK) {
43 return true;
44 }
45
46 return false;
47}
48
49void unassign_action(NlaStrip &strip, ID &animated_id)
50{
51 if (!strip.act) {
52 /* No Action was assigned, so nothing to do here. */
54 "When there is no Action assigned, the slot handle should also be set to "
55 "'unassigned'");
56 return;
57 }
58
59 /* Unassign any previously-assigned slot. */
61 assign_action_slot(strip, nullptr, animated_id);
62 }
63
64 /* Unassign the Action. */
65 id_us_min(&strip.act->id);
66 strip.act = nullptr;
67}
68
70 Slot *slot_to_assign,
71 ID &animated_id)
72{
73 BLI_assert(strip.act);
74
76 slot_to_assign, animated_id, strip.act, strip.action_slot_handle, strip.action_slot_name);
77}
78
80 const slot_handle_t slot_handle,
81 ID &animated_id)
82{
83 BLI_assert(strip.act);
84
85 Action &action = strip.act->wrap();
86 Slot *slot_to_assign = action.slot_for_handle(slot_handle);
87
88 return assign_action_slot(strip, slot_to_assign, animated_id);
89}
90
91} // namespace blender::animrig::nla
void id_us_plus(ID *id)
Definition lib_id.cc:351
void id_us_min(ID *id)
Definition lib_id.cc:359
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
Slot * slot_find_by_name(StringRefNull slot_name)
Slot * slot_for_handle(slot_handle_t handle)
static constexpr slot_handle_t unassigned
void unassign_action(NlaStrip &strip, ID &animated_id)
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)
ActionSlotAssignmentResult assign_action_slot(NlaStrip &strip, Slot *slot_to_assign, ID &animated_id)
ActionSlotAssignmentResult generic_assign_action_slot(Slot *slot_to_assign, ID &animated_id, bAction *&action_ptr_ref, slot_handle_t &slot_handle_ref, char *slot_name) ATTR_WARN_UNUSED_RESULT
decltype(::ActionSlot::handle) slot_handle_t
Definition DNA_ID.h:413
char name[66]
Definition DNA_ID.h:425
char action_slot_name[66]
int32_t action_slot_handle
bAction * act