From 3e1f1b90d57361affc3822ad19b5ea3a83408071 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 12 Dec 2023 16:35:43 +0100 Subject: [PATCH 1/2] move code --- source/blender/animrig/ANIM_animdata.hh | 10 +++++ source/blender/animrig/intern/animdata.cc | 45 +++++++++++++++++++ source/blender/animrig/intern/keyframing.cc | 4 +- .../animation/anim_channels_defines.cc | 3 +- .../blender/editors/animation/keyframing.cc | 41 ----------------- .../editors/gpencil_legacy/gpencil_convert.cc | 3 +- .../blender/editors/include/ED_keyframing.hh | 8 ---- .../editors/object/object_constraint.cc | 5 ++- .../editors/object/object_relations.cc | 3 +- .../editors/space_sequencer/CMakeLists.txt | 1 + .../space_sequencer/sequencer_clipboard.cc | 6 ++- .../blender/io/collada/AnimationImporter.cpp | 21 ++++----- .../blender/io/usd/intern/usd_skel_convert.cc | 5 ++- 13 files changed, 85 insertions(+), 70 deletions(-) diff --git a/source/blender/animrig/ANIM_animdata.hh b/source/blender/animrig/ANIM_animdata.hh index 5132a058dd1..fe9eb4e3da1 100644 --- a/source/blender/animrig/ANIM_animdata.hh +++ b/source/blender/animrig/ANIM_animdata.hh @@ -8,12 +8,22 @@ * \brief Functions to work with AnimData. */ +struct ID; +struct Main; + struct bAnimContext; struct AnimData; struct FCurve; +struct bAction; namespace blender::animrig { +/** + * Get (or add relevant data to be able to do so) the Active Action for the given + * Animation Data block, given an ID block where the Animation Data should reside. + */ +bAction *id_action_ensure(Main *bmain, ID *id); + /** * Delete the F-Curve from the given AnimData block (if possible), * as appropriate according to animation context. diff --git a/source/blender/animrig/intern/animdata.cc b/source/blender/animrig/intern/animdata.cc index 0277f667e3c..869f16c9188 100644 --- a/source/blender/animrig/intern/animdata.cc +++ b/source/blender/animrig/intern/animdata.cc @@ -8,9 +8,13 @@ #include "ANIM_animdata.hh" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_fcurve.h" #include "BKE_lib_id.h" #include "BLI_listbase.h" +#include "BLI_string.h" +#include "DEG_depsgraph.hh" +#include "DEG_depsgraph_build.hh" #include "DNA_anim_types.h" #include "ED_anim_api.hh" @@ -20,6 +24,47 @@ namespace blender::animrig { /** \name Public F-Curves API * \{ */ +bAction *id_action_ensure(Main *bmain, ID *id) +{ + AnimData *adt; + + /* init animdata if none available yet */ + adt = BKE_animdata_from_id(id); + if (adt == nullptr) { + adt = BKE_animdata_ensure_id(id); + } + if (adt == nullptr) { + /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */ + printf("ERROR: Couldn't add AnimData (ID = %s)\n", (id) ? (id->name) : ""); + return nullptr; + } + + /* init action if none available yet */ + /* TODO: need some wizardry to handle NLA stuff correct */ + if (adt->action == nullptr) { + /* init action name from name of ID block */ + char actname[sizeof(id->name) - 2]; + SNPRINTF(actname, "%sAction", id->name + 2); + + /* create action */ + adt->action = BKE_action_add(bmain, actname); + + /* set ID-type from ID-block that this is going to be assigned to + * so that users can't accidentally break actions by assigning them + * to the wrong places + */ + BKE_animdata_action_ensure_idroot(id, adt->action); + + /* Tag depsgraph to be rebuilt to include time dependency. */ + DEG_relations_tag_update(bmain); + } + + DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH); + + /* return the action */ + return adt->action; +} + void animdata_fcurve_delete(bAnimContext *ac, AnimData *adt, FCurve *fcu) { /* - If no AnimData, we've got nowhere to remove the F-Curve from diff --git a/source/blender/animrig/intern/keyframing.cc b/source/blender/animrig/intern/keyframing.cc index e60e6677593..fb0051416fb 100644 --- a/source/blender/animrig/intern/keyframing.cc +++ b/source/blender/animrig/intern/keyframing.cc @@ -536,7 +536,7 @@ int insert_keyframe(Main *bmain, /* If no action is provided, keyframe to the default one attached to this ID-block. */ if (act == nullptr) { - act = ED_id_action_ensure(bmain, id); + act = blender::animrig::id_action_ensure(bmain, id); if (act == nullptr) { BKE_reportf(reports, RPT_ERROR, @@ -936,7 +936,7 @@ void insert_key_rna(PointerRNA *rna_pointer, ReportList *reports) { ID *id = rna_pointer->owner_id; - bAction *action = ED_id_action_ensure(bmain, id); + bAction *action = blender::animrig::id_action_ensure(bmain, id); if (action == nullptr) { BKE_reportf(reports, RPT_ERROR, diff --git a/source/blender/editors/animation/anim_channels_defines.cc b/source/blender/editors/animation/anim_channels_defines.cc index 2f998e2eff8..fce48984450 100644 --- a/source/blender/editors/animation/anim_channels_defines.cc +++ b/source/blender/editors/animation/anim_channels_defines.cc @@ -9,6 +9,7 @@ #include #include "ANIM_action.hh" +#include "ANIM_animdata.hh" #include "ANIM_keyframing.hh" #include "MEM_guardedalloc.h" @@ -5094,7 +5095,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) { /* find or create new F-Curve */ /* XXX is the group name for this ok? */ - bAction *act = ED_id_action_ensure(bmain, (ID *)key); + bAction *act = blender::animrig::id_action_ensure(bmain, (ID *)key); FCurve *fcu = blender::animrig::action_fcurve_ensure(bmain, act, nullptr, &ptr, rna_path, 0); /* set the special 'replace' flag if on a keyframe */ diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index 5898fe868ff..e57fb634720 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -115,47 +115,6 @@ eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, const bool use_autokey_m /* ******************************************* */ /* Animation Data Validation */ -bAction *ED_id_action_ensure(Main *bmain, ID *id) -{ - AnimData *adt; - - /* init animdata if none available yet */ - adt = BKE_animdata_from_id(id); - if (adt == nullptr) { - adt = BKE_animdata_ensure_id(id); - } - if (adt == nullptr) { - /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */ - printf("ERROR: Couldn't add AnimData (ID = %s)\n", (id) ? (id->name) : ""); - return nullptr; - } - - /* init action if none available yet */ - /* TODO: need some wizardry to handle NLA stuff correct */ - if (adt->action == nullptr) { - /* init action name from name of ID block */ - char actname[sizeof(id->name) - 2]; - SNPRINTF(actname, "%sAction", id->name + 2); - - /* create action */ - adt->action = BKE_action_add(bmain, actname); - - /* set ID-type from ID-block that this is going to be assigned to - * so that users can't accidentally break actions by assigning them - * to the wrong places - */ - BKE_animdata_action_ensure_idroot(id, adt->action); - - /* Tag depsgraph to be rebuilt to include time dependency. */ - DEG_relations_tag_update(bmain); - } - - DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH); - - /* return the action */ - return adt->action; -} - void update_autoflags_fcurve(FCurve *fcu, bContext *C, ReportList *reports, PointerRNA *ptr) { PointerRNA tmp_ptr; diff --git a/source/blender/editors/gpencil_legacy/gpencil_convert.cc b/source/blender/editors/gpencil_legacy/gpencil_convert.cc index 0ab37ed1f95..9bd48342df4 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_convert.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_convert.cc @@ -67,6 +67,7 @@ #include "UI_view2d.hh" #include "ANIM_action.hh" +#include "ANIM_animdata.hh" #include "ANIM_keyframing.hh" #include "ED_clip.hh" @@ -524,7 +525,7 @@ static void gpencil_stroke_path_animation(bContext *C, prop = RNA_struct_find_property(&ptr, "eval_time"); /* Ensure we have an F-Curve to add keyframes to */ - act = ED_id_action_ensure(bmain, (ID *)cu); + act = blender::animrig::id_action_ensure(bmain, (ID *)cu); fcu = blender::animrig::action_fcurve_ensure(bmain, act, nullptr, &ptr, "eval_time", 0); if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) { diff --git a/source/blender/editors/include/ED_keyframing.hh b/source/blender/editors/include/ED_keyframing.hh index 623063d6318..53173aed5e9 100644 --- a/source/blender/editors/include/ED_keyframing.hh +++ b/source/blender/editors/include/ED_keyframing.hh @@ -48,14 +48,6 @@ eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, bool use_autokey_mode); /* -------- */ -/** - * Get (or add relevant data to be able to do so) the Active Action for the given - * Animation Data block, given an ID block where the Animation Data should reside. - */ -bAction *ED_id_action_ensure(Main *bmain, ID *id); - -/* -------- */ - /** * \brief Lesser Key-framing API call. * diff --git a/source/blender/editors/object/object_constraint.cc b/source/blender/editors/object/object_constraint.cc index df6cec1460e..774342791c8 100644 --- a/source/blender/editors/object/object_constraint.cc +++ b/source/blender/editors/object/object_constraint.cc @@ -61,6 +61,7 @@ #include "ED_screen.hh" #include "ANIM_action.hh" +#include "ANIM_animdata.hh" #include "UI_interface.hh" #include "UI_resources.hh" @@ -1072,7 +1073,7 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op) (BKE_fcurve_find(&cu->adt->action->curves, "eval_time", 0) == nullptr)) { /* create F-Curve for path animation */ - act = ED_id_action_ensure(bmain, &cu->id); + act = blender::animrig::id_action_ensure(bmain, &cu->id); fcu = blender::animrig::action_fcurve_ensure(bmain, act, nullptr, nullptr, "eval_time", 0); /* standard vertical range - 1:1 = 100 frames */ @@ -1096,7 +1097,7 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op) path = RNA_path_from_ID_to_property(&ptr, prop); /* create F-Curve for constraint */ - act = ED_id_action_ensure(bmain, &ob->id); + act = blender::animrig::id_action_ensure(bmain, &ob->id); fcu = blender::animrig::action_fcurve_ensure(bmain, act, nullptr, nullptr, path, 0); /* standard vertical range - 0.0 to 1.0 */ diff --git a/source/blender/editors/object/object_relations.cc b/source/blender/editors/object/object_relations.cc index b62023cf44a..9d5c2851310 100644 --- a/source/blender/editors/object/object_relations.cc +++ b/source/blender/editors/object/object_relations.cc @@ -106,6 +106,7 @@ #include "ED_view3d.hh" #include "ANIM_action.hh" +#include "ANIM_animdata.hh" #include "MOD_nodes.hh" @@ -563,7 +564,7 @@ bool ED_object_parent_set(ReportList *reports, /* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */ if (partype == PAR_FOLLOW) { /* get or create F-Curve */ - bAction *act = ED_id_action_ensure(bmain, &cu->id); + bAction *act = blender::animrig::id_action_ensure(bmain, &cu->id); FCurve *fcu = blender::animrig::action_fcurve_ensure( bmain, act, nullptr, nullptr, "eval_time", 0); diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt index e5602bb28b9..f6656599d85 100644 --- a/source/blender/editors/space_sequencer/CMakeLists.txt +++ b/source/blender/editors/space_sequencer/CMakeLists.txt @@ -57,6 +57,7 @@ set(LIB bf_editor_util PRIVATE bf::intern::atomic PRIVATE bf::intern::guardedalloc + PRIVATE bf::animrig ) if(WITH_AUDASPACE) diff --git a/source/blender/editors/space_sequencer/sequencer_clipboard.cc b/source/blender/editors/space_sequencer/sequencer_clipboard.cc index 46e7a53439c..292ab18b8d9 100644 --- a/source/blender/editors/space_sequencer/sequencer_clipboard.cc +++ b/source/blender/editors/space_sequencer/sequencer_clipboard.cc @@ -51,6 +51,8 @@ #include "DEG_depsgraph.hh" #include "DEG_depsgraph_build.hh" +#include "ANIM_animdata.hh" + #include "WM_api.hh" #include "WM_types.hh" @@ -175,7 +177,7 @@ static bool sequencer_write_copy_paste_file(Main *bmain_src, if (!BLI_listbase_is_empty(&fcurves_dst) || !BLI_listbase_is_empty(&drivers_dst)) { BLI_assert(scene_dst->adt == nullptr); - bAction *act_dst = ED_id_action_ensure(bmain_src, &scene_dst->id); + bAction *act_dst = blender::animrig::id_action_ensure(bmain_src, &scene_dst->id); BLI_movelisttolist(&act_dst->curves, &fcurves_dst); BLI_movelisttolist(&scene_dst->adt->drivers, &drivers_dst); } @@ -250,7 +252,7 @@ static bool sequencer_paste_animation(Main *bmain_dst, Scene *scene_dst, Scene * } else { /* get action to add F-Curve+keyframe to */ - act_dst = ED_id_action_ensure(bmain_dst, &scene_dst->id); + act_dst = blender::animrig::id_action_ensure(bmain_dst, &scene_dst->id); } LISTBASE_FOREACH (FCurve *, fcu, &scene_src->adt->action->curves) { diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp index 700cefe58cb..ce4db271f64 100644 --- a/source/blender/io/collada/AnimationImporter.cpp +++ b/source/blender/io/collada/AnimationImporter.cpp @@ -15,6 +15,7 @@ #include "ED_keyframing.hh" +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" #include "BLI_listbase.h" @@ -188,7 +189,7 @@ void AnimationImporter::add_fcurves_to_object(Main *bmain, bAction *act; if (!ob->adt || !ob->adt->action) { - act = ED_id_action_ensure(bmain, (ID *)&ob->id); + act = blender::animrig::id_action_ensure(bmain, (ID *)&ob->id); } else { act = ob->adt->action; @@ -920,7 +921,7 @@ void AnimationImporter::apply_matrix_curves(Object *ob, } } Main *bmain = CTX_data_main(mContext); - ED_id_action_ensure(bmain, (ID *)&ob->id); + blender::animrig::id_action_ensure(bmain, (ID *)&ob->id); ListBase *curves = &ob->adt->action->curves; @@ -983,7 +984,7 @@ static ListBase &get_animation_curves(Main *bmain, Material *ma) { bAction *act; if (!ma->adt || !ma->adt->action) { - act = ED_id_action_ensure(bmain, (ID *)&ma->id); + act = blender::animrig::id_action_ensure(bmain, (ID *)&ma->id); } else { act = ma->adt->action; @@ -1029,7 +1030,7 @@ void AnimationImporter::translate_Animations( } if (!ob->adt || !ob->adt->action) { - act = ED_id_action_ensure(bmain, (ID *)&ob->id); + act = blender::animrig::id_action_ensure(bmain, (ID *)&ob->id); } else { act = ob->adt->action; @@ -1091,7 +1092,7 @@ void AnimationImporter::translate_Animations( if ((animType->light) != 0) { Light *lamp = (Light *)ob->data; if (!lamp->adt || !lamp->adt->action) { - act = ED_id_action_ensure(bmain, (ID *)&lamp->id); + act = blender::animrig::id_action_ensure(bmain, (ID *)&lamp->id); } else { act = lamp->adt->action; @@ -1129,7 +1130,7 @@ void AnimationImporter::translate_Animations( Camera *cam = (Camera *)ob->data; if (!cam->adt || !cam->adt->action) { - act = ED_id_action_ensure(bmain, (ID *)&cam->id); + act = blender::animrig::id_action_ensure(bmain, (ID *)&cam->id); } else { act = cam->adt->action; @@ -1185,7 +1186,7 @@ void AnimationImporter::translate_Animations( Material *ma = BKE_object_material_get(ob, 1); if (!ma->adt || !ma->adt->action) { - act = ED_id_action_ensure(bmain, (ID *)&ma->id); + act = blender::animrig::id_action_ensure(bmain, (ID *)&ma->id); } else { act = ma->adt->action; @@ -1366,7 +1367,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, } } Main *bmain = CTX_data_main(mContext); - ED_id_action_ensure(bmain, (ID *)&ob->id); + blender::animrig::id_action_ensure(bmain, (ID *)&ob->id); /* add curves */ for (int i = 0; i < totcu; i++) { @@ -1793,7 +1794,7 @@ Object *AnimationImporter::translate_animation_OLD( #endif } Main *bmain = CTX_data_main(mContext); - ED_id_action_ensure(bmain, (ID *)&ob->id); + blender::animrig::id_action_ensure(bmain, (ID *)&ob->id); ListBase *curves = &ob->adt->action->curves; @@ -2097,7 +2098,7 @@ Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, mul_v3_fl(job->scale, 0.5f); DEG_id_tag_update(&job->id, ID_RECALC_TRANSFORM); - ED_id_action_ensure((ID *)&job->id); + blender::animrig::id_action_ensure((ID *)&job->id); job->rotmode = ROT_MODE_QUAT; diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc index c423f828e3b..c3e6b0ef035 100644 --- a/source/blender/io/usd/intern/usd_skel_convert.cc +++ b/source/blender/io/usd/intern/usd_skel_convert.cc @@ -41,6 +41,7 @@ #include "ED_keyframing.hh" #include "ED_mesh.hh" +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" #include "WM_api.hh" @@ -141,7 +142,7 @@ void import_skeleton_curves(Main *bmain, const size_t num_samples = samples.size(); /* Create the action on the armature. */ - bAction *act = ED_id_action_ensure(bmain, (ID *)&arm_obj->id); + bAction *act = blender::animrig::id_action_ensure(bmain, (ID *)&arm_obj->id); /* Create the curves. */ @@ -590,7 +591,7 @@ void import_blendshapes(Main *bmain, const size_t num_samples = times.size(); /* Create the animation and curves. */ - bAction *act = ED_id_action_ensure(bmain, (ID *)&key->id); + bAction *act = blender::animrig::id_action_ensure(bmain, (ID *)&key->id); std::vector curves; for (auto blendshape_name : blendshapes) { -- 2.30.2 From 0e5d57aecda49b98b5eefa3f5dc3db50a21772a1 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 12 Dec 2023 16:47:22 +0100 Subject: [PATCH 2/2] remove unneeded namespace --- source/blender/animrig/intern/keyframing.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/animrig/intern/keyframing.cc b/source/blender/animrig/intern/keyframing.cc index fb0051416fb..de86f61d97f 100644 --- a/source/blender/animrig/intern/keyframing.cc +++ b/source/blender/animrig/intern/keyframing.cc @@ -536,7 +536,7 @@ int insert_keyframe(Main *bmain, /* If no action is provided, keyframe to the default one attached to this ID-block. */ if (act == nullptr) { - act = blender::animrig::id_action_ensure(bmain, id); + act = id_action_ensure(bmain, id); if (act == nullptr) { BKE_reportf(reports, RPT_ERROR, @@ -936,7 +936,7 @@ void insert_key_rna(PointerRNA *rna_pointer, ReportList *reports) { ID *id = rna_pointer->owner_id; - bAction *action = blender::animrig::id_action_ensure(bmain, id); + bAction *action = id_action_ensure(bmain, id); if (action == nullptr) { BKE_reportf(reports, RPT_ERROR, -- 2.30.2