61 if (!ancestor->done) {
108 scale.reinitialize(3);
128 FPoint &fpt = fcurves[
y * 4 +
x]->fpt[key_index];
130 fpt.
vec[1] = matrix[
x][
y];
140 FPoint &fpt = fcurves[
y * 4 +
x]->fpt[key_index];
141 mat[
x][
y] = fpt.
vec[1];
154 if (added_ids.
add(transformable->owner_id())) {
155 ids.
append(transformable->owner_id());
168 if (added_ids.
add(transformable.owner_id())) {
169 ids.
append(transformable.owner_id());
178 switch (transformable.
type()) {
198 transformable_relations[i].transformable = &transformable;
199 transformable_relations[i].done =
false;
211 if (!ELEM(type, DEG_OB_COMP_TRANSFORM, DEG_OB_COMP_BONE)) {
215 if (dependent_deg_id == deg_identifier) {
224 dependent->
ancestors.append(transformable_relation);
225 if (dependent->
done) {
231 dependent->
done =
true;
235 for (TransformableRelations &relation : transformable_relations) {
237 relation.done =
false;
239 return transformable_relations;
246 depsgraph, transformables);
250 bool inserted_any =
false;
252 if (relations.done || !relations.all_ancestors_done()) {
255 sorted_transformables.
append(relations.transformable);
257 relations.done =
true;
268 return sorted_transformables;
283 bool has_key_on_frame =
false;
291 paste_fcu.
fcurve = &fcurve;
299 paste_fcu.
fcurve, {range.min, range.max - 1}, 1, ar::BakeCurveRemove::IN_RANGE);
330 return key.
vec[1][1] == key.
vec[0][1] && key.
vec[1][1] == key.
vec[2][1];
333 constexpr float threshold = 0.0001f;
334 const float reference_value = fcurve.
bezt[0].
vec[1][1];
335 for (
int i = 0; i < fcurve.
totvert; i++) {
336 if (
fabsf(reference_value - fcurve.
bezt[i].
vec[1][1]) > threshold) {
343 if (
fabsf(reference_value - fcurve.
bezt[i].
vec[0][1]) > threshold) {
346 if (
fabsf(reference_value - fcurve.
bezt[i].
vec[2][1]) > threshold) {
363 if (!paste_fcurve.created_on_paste) {
367 BLI_assert(paste_fcurve.fcurve->bezt !=
nullptr);
368 values[paste_fcurve.fcurve->array_index] = paste_fcurve.fcurve->bezt[0].vec[1][1];
370 paste_fcurve.fcurve =
nullptr;
379 if (paste_fcurve.fcurve) {
388 const int paste_index)
398 &reference_rotation);
400 for (
const int i : t_fcus.
location.index_range()) {
411 for (
const int i : t_fcus.
rotation.index_range()) {
422 for (
const int i : t_fcus.
scale.index_range()) {
451 bf::PartialWriteContext copybuffer{bmain};
453 copybuffer.id_create(
ID_AC,
456 {(bf::PartialWriteContext::IDAddOperations::SET_FAKE_USER |
457 bf::PartialWriteContext::IDAddOperations::SET_CLIPBOARD_MARK)}));
462 ar::Action &action = dna_action->wrap();
463 action.layer_keystrip_ensure();
464 ar::StripKeyframeData &strip_data = action.layer(0)->strip(0)->data<ar::StripKeyframeData>(
466 ar::Slot &slot = action.slot_add();
467 ar::Channelbag &channelbag = strip_data.channelbag_for_slot_ensure(slot);
473 for (
const int transformable_index : transformables.
index_range()) {
475 if (!added_names.
add(transformable.
name())) {
483 fcurve->rna_path_set(transformable.
name());
485 const int vert_count = range.
size();
493 channelbag.fcurve_append(*fcurve);
497 world_space_data[transformable_index] = std::move(fcurves);
500 if (added_names.
size() != transformables.
size()) {
503 "Found duplicate names in selection. Not all selected were saved into clipboard.");
510 for (
int frame = range.
min; frame < range.
max; frame++) {
511 const int key_index = frame - range.
min;
513 for (
const int transformable_index : transformables.
index_range()) {
514 if (world_space_data[transformable_index].size() == 0) {
520 matrix_to_fcurves(world_matrix, world_space_data[transformable_index], frame, key_index);
529 copybuffer.write_as_copypaste_buffer(filepath, reports);
530 if (added_names.
size() == transformables.
size()) {
531 const char *transformable_type_name = transformables[0].type() ==
537 "Copied %d %s across %d frames to the clipboard",
538 int(added_names.
size()),
539 transformable_type_name,
550 const bool from_single = clipboard_data.
size() == 1;
551 const bool to_single = transformables.
size() == 1;
552 if (from_single && to_single) {
553 paste_map.
add(&transformables[0], *clipboard_data.
keys().begin());
558 if (from_single && !to_single) {
561 paste_map.
add(&transformable, source_name);
570 paste_map.
add(&transformable, transformable.name());
588 bAction *paste_dna_action = ar::id_action_ensure(&bmain, owner_id);
599 ar::assert_baklava_phase_1_invariants(paste_dna_action->wrap());
600 ar::Channelbag &channelbag = ar::action_channelbag_ensure(*paste_dna_action, *owner_id);
605 transform_fcurves.
rotation.reinitialize(3);
608 transform_fcurves.
rotation.reinitialize(4);
618 FCurve *rotation_mode_fcurve =
nullptr;
620 for (
FCurve *fcurve : channelbag.fcurves()) {
622 if (fcurve_path == loc_path) {
623 transform_fcurves.
location[fcurve->array_index].fcurve = fcurve;
625 else if (fcurve_path == rot_path) {
626 transform_fcurves.
rotation[fcurve->array_index].fcurve = fcurve;
628 else if (fcurve_path == scale_path) {
629 transform_fcurves.
scale[fcurve->array_index].fcurve = fcurve;
631 else if (fcurve_path == rotation_mode_path) {
633 rotation_mode_fcurve = fcurve;
639 bmain, *transformable, transform_fcurves.
location, channelbag, loc_path, range);
641 bmain, *transformable, transform_fcurves.
rotation, channelbag, rot_path, range);
643 bmain, *transformable, transform_fcurves.
scale, channelbag, scale_path, range);
644 if (rotation_mode_fcurve && rotation_mode_fcurve->
bezt) {
650 rotation_mode_fcurve, {range.
min, range.
max - 1}, 1, ar::BakeCurveRemove::IN_RANGE);
651 bool has_key_on_frame;
653 rotation_mode_fcurve->
bezt, range.
min, rotation_mode_fcurve->
totvert, &has_key_on_frame);
655 for (
int frame = range.
min; frame < range.
max; frame++) {
657 &rotation_mode_fcurve->
bezt[range_start_index + frame - range.
min], current_mode);
662 return fcurve_buffer;
669 if (clipboard_bmain.
actions.is_empty()) {
675 ar::Action &clipboard_action = clipboard_dna_action->wrap();
676 if (clipboard_action.strip_keyframe_data().is_empty() ||
677 clipboard_action.strip_keyframe_data()[0]->channelbags().is_empty())
683 return clipboard_dna_action;
696 ar::Action &clipboard_action = clipboard_dna_action.wrap();
697 BLI_assert(clipboard_action.strip_keyframe_data_array_num == 1 &&
698 clipboard_action.strip_keyframe_data()[0]->channelbag_array_num == 1);
699 ar::Channelbag &channelbag = *clipboard_action.strip_keyframe_data()[0]->channelbags()[0];
701 for (
FCurve *fcurve : channelbag.fcurves()) {
705 fcurves[fcurve->array_index] = fcurve;
709 for (
FCurve *fcurve : fcurves) {
710 if (fcurve ==
nullptr) {
719 if (paste_map.
size() == 0) {
727 pasteables.
append(anim_transformable);
740 if (sorted_transformables.
size() != pasteables.
size()) {
742 &reports,
RPT_ERROR,
"Failed to figure out pasting order. Potential dependency cycle");
747 Bounds<int> range = {int(clipboard_action.frame_start), int(clipboard_action.frame_end)};
749 const int paste_length = range.
size();
750 const int start_frame = scene.
r.
cfra;
751 range = {start_frame, start_frame + paste_length};
756 bmain, sorted_transformables, range);
762 for (
const int i : sorted_transformables.
index_range()) {
769 for (
int frame = range.
min; frame < range.
max; frame++) {
772 const int key_index = frame - range.
min;
776 "Only transformables with matching matrix data should iterated here");
780 transform_fcurves, local_matrix, previous_rotation, key_index);
789 for (
const int i : sorted_transformables.
index_range()) {
802 transform_fcurves.
scale,
809 const char *transformable_type_name = transformables[0].type() ==
813 if (sorted_transformables.
size() == clipboard_data.
size()) {
816 "Pasted all %d %s over %d frames",
817 int(sorted_transformables.
size()),
818 transformable_type_name,
821 else if (clipboard_data.
size() == 1) {
824 "Pasted the same animation to %d %s over %d frames",
825 int(sorted_transformables.
size()),
826 transformable_type_name,
832 "Pasted %d/%d %s over %d frames",
833 int(sorted_transformables.
size()),
834 int(clipboard_data.
size()),
835 transformable_type_name,
859 "Use the range provided in the operator properties"},
864 "Use the playback range of the scene"},
865 {0,
nullptr, 0,
nullptr,
nullptr},
877 switch (range_mode) {
912 ot->
name =
"Copy World Space Range";
913 ot->
idname =
"ANIM_OT_world_space_copy";
914 ot->
description =
"Copy animation from selected elements to the clipboard";
926 "Determines which range should be copied");
936 switch (transformable.type()) {
947 if (!
object->constraints.is_empty()) {
966 "Selection contains constraints. Perfect world space match cannot be guaranteed");
973 if (!clipboard_bmain) {
979 if (!clipboard_dna_action) {
989 *clipboard_dna_action,
1012 "Paste data to the same frames they were copied from"},
1016 "Start at Current Frame",
1017 "Paste data starting at current frame"},
1018 {0,
nullptr, 0,
nullptr,
nullptr},
1023 ot->
name =
"Paste World Space";
1024 ot->
idname =
"ANIM_OT_world_space_paste";
1025 ot->
description =
"Paste the animation from the clipboard to selected elements";
1037 "Paste time offset of keys");
Functions and classes to work with Actions.
Functions to work with AnimData.
Helper functions for animation to interact with the RNA system.
Blender kernel action and pose functionality.
#define BLI_path_join(...)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
IndexRange index_range() const
void reinitialize(const int64_t new_size)
constexpr IndexRange()=default
const Value * lookup_ptr(const Key &key) const
ValueIterator values() const &
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
Value lookup_default(const Key &key, const Value &default_value) const
KeyIterator keys() const &
Value & lookup_or_add(const Key &key, const Value &value)
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
void append(const T &value)
IndexRange index_range() const
void reserve(const int64_t min_capacity)
bool fcurve_remove(FCurve &fcurve_to_remove)
FCurve & fcurve_ensure(Main *bmain, const FCurveDescriptor &fcurve_descriptor)
float3x3 scale(float3x3 mat, float2 scale)
static Rotation set_keys_to_transform(TransformFCurves &t_fcus, const float4x4 &matrix, const Rotation &reference_rotation, const int paste_index)
const EnumPropertyItem rna_enum_copy_range_items[]
static bool world_space_paste_poll(bContext *C)
static DegComponentIdentifier transformable_to_deg_identifier(const AnimTransformable &transformable)
static void clean_baked_fcurves(AnimTransformable &transformable, AnimTransformable::PropertyType property_type, MutableSpan< PasteFCurve > fcurves, blender::animrig::Channelbag &channelbag)
static Array< TransformFCurves > build_fcurves_for_paste(Main &bmain, const Span< AnimTransformable * > transformables, const Bounds< int > range)
static void matrix_to_fcurves(const float4x4 &matrix, Span< FCurve * > fcurves, const int frame, const int key_index)
constexpr const char * clipboard_name
Map< StringRefNull, Array< FCurve * > > ClipboardData
static float4x4 fcurves_to_matrix(const Span< const FCurve * > fcurves, const int key_index)
static Vector< ID * > get_unique_ids(const Span< AnimTransformable * > transformables)
static Vector< AnimTransformable * > depsgraph_sorted_transformables(const Depsgraph *depsgraph, const MutableSpan< AnimTransformable * > transformables)
static void copy_world_space(Main &bmain, Scene &scene, ViewLayer &view_layer, ReportList &reports, const Span< AnimTransformable > transformables, const Bounds< int > range)
static wmOperatorStatus world_space_paste_exec(bContext *C, wmOperator *op)
Map< AnimTransformable *, StringRefNull > PasteMap
static wmOperatorStatus world_space_copy_exec(bContext *C, wmOperator *op)
static PasteMap generate_paste_mapping(const MutableSpan< AnimTransformable > transformables, const ClipboardData &clipboard_data)
static bAction * read_action_from_clipboard(Main &clipboard_bmain, ReportList &reports)
static bool has_constraints(const Span< AnimTransformable > transformables)
static void ensure_baked_fcurves(Main &bmain, const AnimTransformable &transformable, MutableSpan< PasteFCurve > fcus, blender::animrig::Channelbag &channelbag, const StringRefNull rna_path, const Bounds< int > range)
void ANIM_OT_world_space_paste(wmOperatorType *ot)
static Array< TransformableRelations > build_transformable_relations(const Depsgraph *depsgraph, const MutableSpan< AnimTransformable * > transformables)
static bool world_space_copy_poll(bContext *C)
void ANIM_OT_world_space_copy(wmOperatorType *ot)
static void recalculate_handles(MutableSpan< PasteFCurve > fcurves)
static void paste_world_space(Main &bmain, Scene &scene, ViewLayer &view_layer, ReportList &reports, bAction &clipboard_dna_action, const MutableSpan< AnimTransformable > transformables, const AnimationPasteOffset offset)
static bool is_fcurve_flat(FCurve &fcurve)
const EnumPropertyItem rna_enum_animation_paste_offset_items[]
Array< float, 4 > TransformFloats
Vector< ed::AnimTransformable > selected_transformables_from_context(bContext &C)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
int RNA_enum_get(PointerRNA *ptr, const char *name)
Main * BKE_copybuffer_read(Main &reference_bmain, const char *libname, ReportList *reports, uint64_t id_types_mask)
void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void DEG_graph_free(Depsgraph *graph)
bool ED_operator_posemode(bContext *C)
void DEG_graph_id_tag_update(Main *bmain, Depsgraph *depsgraph, ID *id, unsigned int flags)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
int RNA_int_get(PointerRNA *ptr, const char *name)
MatBase< float, 4, 4 > float4x4
ViewLayer * CTX_data_view_layer(const bContext *C)
ScenePlaybackRange BKE_scene_get_playback_range(const Scene *scene)
AnimData * BKE_animdata_from_id(const ID *id)
void BKE_fcurve_handles_recalc(FCurve &fcu)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
void DEG_graph_build_from_ids(Depsgraph *graph, Span< ID * > ids)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BKE_main_free(Main *bmain)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
bool ED_operator_objectmode(bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Main * CTX_data_main(const bContext *C)
void DEG_foreach_dependent_component(const Depsgraph *depsgraph, const ID *start_id, eDepsObjectComponentType start_component_type, StringRef start_component_name, DEGForeachNamedIDComponentCallback callback)
void DEG_evaluate_on_framechange(Depsgraph *graph, float frame, DepsgraphEvaluateSyncWriteback sync_writeback=DEG_EVALUATE_SYNC_WRITEBACK_NO)
Scene * CTX_data_scene(const bContext *C)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
VecBase< float, 3 > float3
@ FCURVE_EXTRAPOLATE_CONSTANT
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
void mat4_decompose(float loc[3], float quat[4], float size[3], const float wmat[4][4])
FCurve * BKE_fcurve_create()
eBezTriple_Interpolation ipo
ListBaseT< FModifier > modifiers
ListBaseT< bAction > actions
const c_style_mat & ptr() const
static MatBase identity()
ListBaseT< struct bConstraint > constraints
Rotation converted_to_mode(eRotationModes mode, const Rotation *reference_euler=nullptr) const
bool operator==(const DegComponentIdentifier &other) const
eDepsObjectComponentType type
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports