14#include "RNA_prototypes.hh"
41 for (
FCurve *existing_fcurve : fcurves_) {
43 "An FCurve with that index was already inserted");
44 if (existing_fcurve->array_index > fcurve.
array_index) {
49 fcurves_.insert(insert_index, &fcurve);
64 for (
FCurve *fcurve : fcurves_) {
65 if (fcurve->array_index == array_index) {
77 BLI_assert(fcurve.rna_path().endswith(
"rotation_mode"));
86 changes.
append({0, key_rotation_mode});
89 if (changes.
last().second == key_rotation_mode) {
92 changes.
append({key.
vec[1][0], key_rotation_mode});
106 float get_next_frame()
const
109 for (
const int i : fcurves_.index_range()) {
110 const FCurve *fcurve = fcurves_[i];
111 if (key_indices_[i] > fcurve->
totvert - 1) {
114 const float key_frame = fcurve->
bezt[key_indices_[i]].
vec[1][0];
115 if (key_frame >= range_.max) {
118 if (key_frame < next_frame) {
119 next_frame = key_frame;
133 if (!fcurves[i] || !fcurves[i]->bezt) {
136 fcurves_.append(fcurves[i]);
142 const FCurve *fcurve = fcurves_[i];
143 const int index = BKE_fcurve_bezt_binarysearch_index(
144 fcurve->bezt, range.min, fcurve->totvert, &frame_has_key);
145 key_indices_[i] = index;
151 for (
const int i : fcurves_.index_range()) {
152 const FCurve *fcurve = fcurves_[i];
153 if (key_indices_[i] > fcurve->
totvert - 1) {
157 const float key_frame = fcurve->
bezt[key_indices_[i]].
vec[1][0];
158 if (key_frame < range_.max) {
167 float next_frame = get_next_frame();
174 for (
const int i : fcurves_.index_range()) {
175 const FCurve *fcurve = fcurves_[i];
176 if (key_indices_[i] > fcurve->
totvert - 1) {
179 const float key_frame = fcurve->
bezt[key_indices_[i]].
vec[1][0];
180 if (key_frame <= next_frame) {
193 float next_frame = get_next_frame();
211 for (
const int i : fcurves_.index_range()) {
212 const FCurve *fcurve = fcurves_[i];
213 if (key_indices_[i] > fcurve->
totvert - 1) {
216 if (key && fcurve->
bezt[key_indices_[i]].
vec[1][0] >= key->
vec[1][0]) {
219 key = &fcurve->
bezt[key_indices_[i]];
249 const bool ensure_range_start_key)
257 for (
const FCurve *fcurve : evaluation_buffer) {
268 if (ensure_range_start_key && key_iterator.
get_frame() > range.
min) {
272 for (
const int i : insertion_buffer.
index_range()) {
273 FCurve *fcurve = insertion_buffer[i];
274 BLI_assert_msg(fcurve,
"For insertion all FCurves are expected to be created before");
281 const float frame = key_iterator.
get_frame();
285 for (
const FCurve *fcurve : evaluation_buffer) {
292 &previous_conversion);
293 for (
const int i : insertion_buffer.
index_range()) {
294 FCurve *fcurve = insertion_buffer[i];
295 BLI_assert_msg(fcurve,
"For insertion all FCurves are expected to be created before");
298 previous_conversion = std::move(converted_rotation);
309 if (!rotation_fcurves) {
316 rotation_fcurves->
clear();
323 const Span<std::pair<float, eRotationModes>> ranges,
326 const int insertion_buffer_count = to_mode >
ROT_MODE_QUAT ? 3 : 4;
329 for (
const int i : insertion_buffer.
index_range()) {
344 insertion_buffer[i] = fcurve;
347 bool modified_keys =
false;
348 for (
const int i : ranges.index_range()) {
349 const std::pair<float, eRotationModes> &rotation_mode_range = ranges[i];
354 if (!rotation_fcurves) {
358 const int evaluation_buffer_count = from_mode >
ROT_MODE_QUAT ? 3 : 4;
360 for (
const int buffer_index : evaluation_buffer.
index_range()) {
365 if (i + 1 < ranges.size()) {
366 range.
max = ranges[i + 1].first;
370 evaluation_buffer, insertion_buffer, from_mode, to_mode, range, transformable, i > 0);
372 modified_keys =
true;
375 if (!modified_keys) {
378 for (
FCurve *fcurve : insertion_buffer) {
389 for (
FCurve *fcurve : insertion_buffer) {
402 bool modified_keys =
false;
404 for (
const auto &item : channelbag_fcurve_map.
items()) {
409 FCurve *rotation_mode_fcurve =
nullptr;
411 BLI_assert(rotation_mode_buffer->fcurves().size() == 1);
412 rotation_mode_fcurve = rotation_mode_buffer->fcurves()[0];
423 *channelbag, fcu_map, to_mode, rotation_mode_ranges, transformable);
425 if (rotation_mode_fcurve && rotation_mode_fcurve->
bezt) {
427 rotation_mode_fcurve->
bezt[i].
vec[1][1] = to_mode;
433 return modified_keys;
438 const int start_of_propname =
rna_path.rfind(
".") + 1;
439 return rna_path.substr(start_of_propname,
rna_path.size()) ==
"rotation_mode";
448 for (
FCurve *fcurve : channelbag->fcurves()) {
471 const SortedFCurveBuffer *fcurve_buffer = rna_fcurve_map.lookup_ptr(rotation_rna_path);
472 if (!fcurve_buffer) {
476 if (!fcurve || !fcurve->bezt) {
479 const int2 range = {int(fcurve->bezt[0].vec[1][0]),
480 int(fcurve->bezt[fcurve->totvert - 1].vec[1][0])};
499 bool converted_actions =
false;
503 if (!BKE_id_is_editable(bmain, &action.id)) {
506 if (!data_map.
contains({&action, slot_handle})) {
507 ChannelbagFCurveMap fcurve_map = build_rotation_fcurve_map(action, slot_handle);
508 data_map.add({&action, slot_handle}, fcurve_map);
510 ChannelbagFCurveMap &channelbag_fcurve_map = data_map.
lookup({&action, slot_handle});
519 if (converted_actions) {
520 transformable.set_rotation_mode(to_mode);
521 ID *
id = transformable.owner_id();
526 ed::Rotation
rotation = transformable.get_rotation();
527 transformable.set_rotation_mode(to_mode);
528 transformable.set_rotation(
rotation.converted_to_mode(to_mode));
Functions and classes to work with Actions.
Functionality to iterate an Action in various ways.
Functions to modify FCurves.
Helper functions for animation to interact with the RNA system.
Object is a sort of wrapper for general info.
#define BLI_assert_msg(a, msg)
IndexRange index_range() const
void reinitialize(const int64_t new_size)
constexpr IndexRange()=default
animrig::KeyframeSettings get_keyframe_settings() const
KeyframeIterator(Span< const FCurve * > fcurves, const Bounds< float > range)
const Value * lookup_ptr(const Key &key) const
ValueIterator values() const &
const Value & lookup(const Key &key) const
bool remove(const Key &key)
bool contains(const Key &key) const
ItemIterator items() const &
Value & lookup_or_add(const Key &key, const Value &value)
void insert_fcurve(FCurve &fcurve)
Span< FCurve * > fcurves() const
FCurve * get_fcurve_by_array_index(int array_index) const
constexpr IndexRange index_range() const
void append(const T &value)
const T & last(const int64_t n=0) const
IndexRange index_range() const
bool fcurve_assign_to_channel_group(FCurve &fcurve, bActionGroup &to_group)
bool fcurve_remove(FCurve &fcurve_to_remove)
void fcurve_append(FCurve &fcurve)
bActionGroup & channel_group_ensure(StringRefNull name)
decltype(blender::ActionSlot::handle) slot_handle_t
bool foreach_action_slot_use(const ID &animated_id, FunctionRef< bool(Action &action, slot_handle_t slot_handle)> callback)
FCurve * create_fcurve_for_channel(const FCurveDescriptor &fcurve_descriptor)
bool is_rotation_path(ParsedRNAPathRef rna_path)
Vector< animrig::Channelbag * > channelbags_for_action_slot(Action &action, slot_handle_t slot_handle)
void bake_fcurve(FCurve *fcu, int2 range, float step, BakeCurveRemove remove_existing)
SingleKeyingResult insert_vert_fcurve(FCurve *fcu, const float2 position, const KeyframeSettings &settings, eInsertKeyFlags flag)
Main Key-framing API call.
constexpr StringRefNull rotation
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void convert_rotation_mode_range(const Span< const FCurve * > evaluation_buffer, const Span< FCurve * > insertion_buffer, const eRotationModes from_mode, const eRotationModes to_mode, const Bounds< float > range, const ed::AnimTransformable &transformable, const bool ensure_range_start_key)
static void remove_rotation_fcurves(const ed::AnimTransformable &transformable, RNAFCurveMap &fcu_map, animrig::Channelbag &channelbag, const eRotationModes rotation_mode)
void convert_to_rotation_mode(bContext &C, ed::AnimTransformable &transformable, const eRotationModes to_mode, const bool bake)
ChannelbagFCurveMap build_rotation_fcurve_map(animrig::Action &action, const animrig::slot_handle_t slot_handle)
VecBase< int32_t, 2 > int2
void BKE_fcurve_handles_recalc(FCurve &fcu)
void DEG_id_tag_update(ID *id, unsigned int flags)
bool convert_rotation_keys(const ed::AnimTransformable &transformable, ChannelbagFCurveMap &channelbag_fcurve_map, const eRotationModes to_mode)
Map< std::string, SortedFCurveBuffer > RNAFCurveMap
static Vector< std::pair< float, eRotationModes > > get_rotation_mode_ranges(const FCurve &fcurve)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
Map< animrig::Channelbag *, RNAFCurveMap > ChannelbagFCurveMap
void BKE_fcurve_free(FCurve *fcu)
void bake_rotation_fcurves(const ChannelbagFCurveMap &channelbag_fcurve_map, const ed::AnimTransformable &transformable)
Main * CTX_data_main(const bContext *C)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
static bool is_rotation_mode_path(const StringRefNull rna_path)
static bool convert_rotation_mode_channelbag(animrig::Channelbag &channelbag, RNAFCurveMap &fcu_map, const eRotationModes to_mode, const Span< std::pair< float, eRotationModes > > ranges, const ed::AnimTransformable &transformable)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
eBezTriple_Interpolation ipo
eBezTriple_Interpolation interpolation
eBezTriple_KeyframeType keyframe_type
Rotation converted_to_mode(eRotationModes mode, const Rotation *reference_euler=nullptr) const