12#include <fmt/format.h>
44#include "RNA_prototypes.hh"
67 reports,
RPT_ERROR,
"Due to the setting 'Only Insert Needed' no keyframe was inserted.");
74 reports,
RPT_ERROR,
"Inserting key has been skipped because the ID cannot be edited.");
78 reports,
RPT_ERROR,
"Inserting key has been skipped because the ID cannot be keyed.");
99 result_counter.fill(0);
104 result_counter[int(
result)] += count;
109 for (
int i = 0; i < result_counter.size(); i++) {
110 result_counter[i] += other.result_counter[i];
116 return result_counter[int(
result)];
124 for (
int i = 1; i < result_counter.size(); i++) {
125 if (result_counter[i] > 0) {
136 reports,
RPT_WARNING,
"No keys have been inserted and no errors have been reported.");
143 errors.
append(fmt::format(
144 fmt::runtime(
RPT_(
"There were {:d} keying failures for unknown reasons.")), error_count));
149 errors.
append(fmt::format(
150 fmt::runtime(
RPT_(
"Could not create {:d} F-Curve(s). This can happen when only "
151 "inserting to available F-Curves.")),
158 fmt::format(fmt::runtime(
RPT_(
159 "{:d} F-Curve(s) are not keyframeable. They might be locked or sampled.")),
165 errors.
append(fmt::format(
167 "Due to the setting 'Only Insert Needed', {:d} keyframe(s) have not been inserted.")),
173 errors.
append(fmt::format(
174 fmt::runtime(
RPT_(
"Due to the NLA stack setup, {:d} keyframe(s) have not been inserted.")),
180 errors.
append(fmt::format(
181 fmt::runtime(
RPT_(
"Inserting keys on {:d} data-block(s) has been skipped because "
182 "they are not editable.")),
188 errors.
append(fmt::format(
189 fmt::runtime(
RPT_(
"Inserting keys on {:d} data-block(s) has been skipped because "
190 "they cannot be animated.")),
196 errors.
append(fmt::format(
197 fmt::runtime(
RPT_(
"Inserting keys on {:d} data-block(s) has been skipped because "
198 "the RNA path wasn't valid for them.")),
204 errors.
append(fmt::format(
205 fmt::runtime(
RPT_(
"Inserting keys on {:d} data-block(s) has been skipped because "
206 "there were no layers that could accept the keys.")),
212 errors.
append(fmt::format(
213 fmt::runtime(
RPT_(
"Inserting keys on {:d} data-block(s) has been skipped because "
214 "there were no strips that could accept the keys.")),
220 errors.
append(fmt::format(
221 fmt::runtime(
RPT_(
"Inserting keys on {:d} data-block(s) has been skipped because "
222 "of missing action slots.")),
231 if (errors.
size() == 1) {
232 BKE_report(reports, report_level, errors[0].c_str());
236 std::string error_message =
RPT_(
"Inserting keyframes failed:");
237 for (
const std::string &error : errors) {
238 error_message.append(fmt::format(
"\n- {}", error));
240 BKE_report(reports, report_level, error_message.c_str());
246 if (animated_struct->
type == RNA_PoseBone) {
248 return pose_channel->
name;
251 if (animated_struct->
type == RNA_Object) {
259 return "Object Transforms";
279 return U.keying_flag & flag;
312 if (adt.
action ==
nullptr) {
327 [&](
const IndexRange range,
const bool is_found) {
332 if (fcurve_frame_has_keyframe(fcu, frame)) {
338 std::logical_or<bool>());
372 switch (
GS(
id->name)) {
416 ListBaseT<NlaKeyframingContext> *nla_cache,
419 if (adt && adt->
action == act) {
421 nla_cache, id_ptr, adt, anim_eval_context);
424 return remapped_frame;
427 *r_nla_context =
nullptr;
434 const float fcurve_frame,
454 if (index < 0 || index >= values.
size()) {
480 if (adt->
action ==
nullptr) {
496 if (
ELEM(
nullptr,
id, adt)) {
508 "Could not delete keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
520 int array_index =
rna_path.index.value_or(0);
521 int array_index_max = array_index + 1;
529 if (array_index_max == array_index) {
534 Action &action = act->wrap();
545 for (; array_index < array_index_max; array_index++) {
547 if (fcurve ==
nullptr) {
551 modified_fcurves.
append(fcurve);
556 for (
FCurve *fcurve : modified_fcurves) {
564 return modified_fcurves.
size();
574 if (
ELEM(
nullptr,
id, adt)) {
586 "Could not clear keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
598 Action &action = act->wrap();
604 if (rna_path.index.has_value() && rna_path.index.value() != fcurve.array_index) {
613 for (
FCurve *fcu : fcurves) {
638 const std::optional<StringRefNull> channel_group,
666 "The animated ID should not be using another Action than the one passed to this function");
671 "The conditions that would cause this Slot assignment to fail (such as the ID not being "
672 "animatible) should have been caught and handled by higher-level functions.");
684 return std::make_pair(
layer, slot);
693 const std::optional<StringRefNull> channel_group,
703 int property_array_index = 0;
705 for (
float value : values) {
706 if (!keying_mask[property_array_index]) {
708 property_array_index++;
711 const KeyInsertData key_data = {{frame, value}, property_array_index};
724 property_array_index++;
726 return combined_result;
731 const std::optional<StringRefNull> channel_group,
733 const std::optional<float> scene_frame,
745 return combined_result;
750 if (adt ==
nullptr) {
752 return combined_result;
757 return combined_result;
763 return combined_result;
769 Action &action = dna_action->wrap();
776 ListBaseT<NlaKeyframingContext> nla_cache = {
nullptr,
nullptr};
792 struct_pointer,
rna_path.path.c_str(), &ptr, &prop);
793 if (!path_resolved) {
814 if (!rna_path_id_to_prop.has_value()) {
817 if (struct_pointer->
data !=
id) {
822 rna_path_id_to_prop =
rna_path.path;
838 bool at_least_one_would_succeed =
false;
839 for (
int i = 0; i < rna_values.
size(); i++) {
848 at_least_one_would_succeed =
true;
857 at_least_one_would_succeed =
true;
864 if (at_least_one_would_succeed) {
871 const std::optional<StringRefNull> this_rna_path_channel_group =
872 channel_group.has_value() ? channel_group :
880 this_rna_path_channel_group,
881 *rna_path_id_to_prop,
912 if (!
ELEM(adt->
action,
nullptr, dna_action)) {
917 return combined_result;
Functions and classes to work with Actions.
Functionality to iterate an Action in various ways.
Functions to work with AnimData.
Functions to modify FCurves.
Functions to insert, delete or modify keyframes.
Helper functions for animation to interact with the RNA system.
Functions to work with the visual keying system.
Blender kernel action and pose functionality.
#define ID_IS_LINKED(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
constexpr Span slice(int64_t start, int64_t size) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
void append(const T &value)
MutableSpan< T > as_mutable_span()
void layer_keystrip_ensure()
float2 get_frame_range() const ATTR_WARN_UNUSED_RESULT
bool is_cyclic() const ATTR_WARN_UNUSED_RESULT
Layer * get_layer_for_keyframing()
Slot * slot_for_handle(slot_handle_t handle)
void merge(const CombinedKeyingResult &other)
int get_count(const SingleKeyingResult result) const
void generate_reports(ReportList *reports, eReportType report_level=RPT_ERROR)
void add(SingleKeyingResult result, int count=1)
const T & data(const Action &owning_action) const
static constexpr int64_t not_found
constexpr int64_t find(char c, int64_t pos=0) const
bool action_fcurve_remove(Action &action, FCurve &fcu)
void assert_baklava_phase_1_invariants(const Action &action)
std::optional< StringRefNull > default_channel_group_for_path(const PointerRNA *animated_struct, StringRef prop_rna_path)
void animdata_fcurve_delete(AnimData *adt, FCurve *fcu)
KeyframeSettings get_keyframe_settings(bool from_userprefs)
Slot * assign_action_ensure_slot_for_keying(Action &action, ID &animated_id)
static bool object_frame_has_keyframe(Object *ob, const float frame)
bAction * id_action_ensure(Main *bmain, ID *id)
eFCurve_Flags fcurve_flags_for_property_type(PropertyType prop_type)
Vector< float > visualkey_get_values(PointerRNA *ptr, PropertyRNA *prop)
bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop)
void update_autoflags_fcurve_direct(FCurve *fcu, PropertyType prop_type)
Vector< float > get_property_values(PointerRNA *ptr, PropertyRNA *prop, bool visual_key)
Vector< float > get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
int clear_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &rna_path)
int delete_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &rna_path, float cfra)
Main Delete Key-Framing API call.
bool fcurve_delete_keyframe_at_time(FCurve *fcurve, float time)
bool id_frame_has_keyframe(ID *id, float frame)
static bool assigned_action_has_keyframe_at(AnimData &adt, const float frame)
SingleKeyingResult insert_vert_fcurve(FCurve *fcu, const float2 position, const KeyframeSettings &settings, eInsertKeyFlags flag)
Main Key-framing API call.
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
const FCurve * fcurve_find(Span< const FCurve * > fcurves, const FCurveDescriptor &fcurve_descriptor)
Action * get_action(ID &animated_id)
SingleKeyingResult insert_keyframe_direct(PointerRNA &ptr, PropertyRNA &prop, FCurve &fcu, float fcurve_frame, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag)
Secondary Insert Key-framing API call.
static SingleKeyingResult insert_key_layer(Main *bmain, Action &action, Layer &layer, const Slot &slot, const std::string &rna_path, PropertyRNA *prop, const std::optional< StringRefNull > channel_group, const KeyInsertData &key_data, const KeyframeSettings &key_settings, const eInsertKeyFlags insert_key_flags)
static CombinedKeyingResult insert_key_layered_action(Main *bmain, Action &action, Layer &layer, const Slot &slot, PropertyRNA *prop, const std::optional< StringRefNull > channel_group, const std::string &rna_path, const float frame, const Span< float > values, const eInsertKeyFlags insert_key_flags, const KeyframeSettings &key_settings, const BitSpan keying_mask)
static float nla_time_remap(float time, const AnimationEvalContext *anim_eval_context, PointerRNA *id_ptr, AnimData *adt, bAction *act, ListBaseT< NlaKeyframingContext > *nla_cache, NlaKeyframingContext **r_nla_context)
Span< FCurve * > fcurves_for_assigned_action(AnimData *adt)
bool is_keying_flag(const Scene *scene, eKeying_Flag flag)
static std::pair< Layer *, Slot * > prep_action_layer_for_keying(Action &action, ID &animated_id)
bool key_insertion_may_create_fcurve(eInsertKeyFlags insert_key_flags)
FCurve * fcurve_find_in_action(bAction *act, const FCurveDescriptor &fcurve_descriptor)
void foreach_fcurve_in_action_slot_editable(Action &action, slot_handle_t handle, FunctionRef< void(FCurve &fcurve)> callback)
static void deg_tag_after_keyframe_delete(Main *bmain, ID *id, AnimData *adt)
void generate_single_keying_result_report(const SingleKeyingResult result, ReportList *reports)
eInsertKeyFlags get_keyframing_flags(Scene *scene)
@ UNABLE_TO_INSERT_TO_NLA_STACK
@ FCURVE_NOT_KEYFRAMEABLE
CombinedKeyingResult insert_keyframes(Main *bmain, PointerRNA *struct_pointer, std::optional< StringRefNull > channel_group, const Span< RNAPath > rna_paths, std::optional< float > scene_frame, const AnimationEvalContext &anim_eval_context, eBezTriple_KeyframeType key_type, eInsertKeyFlags insert_key_flags)
Main key-frame insertion API.
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context, PointerRNA *prop_ptr, PropertyRNA *prop, const MutableSpan< float > values, int index, const AnimationEvalContext *anim_eval_context, bool *r_force_all, BitVector<> &r_values_mask)
bool BKE_fcurve_is_keyframable(const FCurve &fcu)
void BKE_animsys_free_nla_keyframing_context_cache(ListBaseT< NlaKeyframingContext > *cache)
PointerRNA RNA_id_pointer_create(ID *id)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
AnimData * BKE_animdata_ensure_id(ID *id)
PropertyType RNA_property_type(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
VecBase< float, 2 > float2
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
NlaKeyframingContext * BKE_animsys_get_nla_keyframing_context(ListBaseT< NlaKeyframingContext > *cache, PointerRNA *ptr, AnimData *adt, const AnimationEvalContext *anim_eval_context)
@ ID_RECALC_ANIMATION_NO_FLUSH
ID_Type GS(const char *name)
void DEG_relations_tag_update(Main *bmain)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
bool BKE_fcurve_is_empty(const FCurve *fcu)
@ MANUALKEY_FLAG_INSERTNEEDED
bool BKE_id_is_editable(const Main *bmain, const ID *id)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
struct ToolSettings * toolsettings
eBezTriple_KeyframeType keyframe_type