Refactor: Move ED_id_action_ensure to animrig #116101
|
@ -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.
|
||||
|
|
|
@ -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) : "<None>");
|
||||
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
|
||||
|
|
|
@ -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 = 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 = id_action_ensure(bmain, id);
|
||||
if (action == nullptr) {
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <cstdio>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -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) : "<None>");
|
||||
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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ set(LIB
|
|||
bf_editor_util
|
||||
PRIVATE bf::intern::atomic
|
||||
PRIVATE bf::intern::guardedalloc
|
||||
PRIVATE bf::animrig
|
||||
)
|
||||
|
||||
if(WITH_AUDASPACE)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<FCurve *> curves;
|
||||
|
||||
for (auto blendshape_name : blendshapes) {
|
||||
|
|
Loading…
Reference in New Issue