Cleanup: keyframe API naming, high level keyframe API

- Split 'verify_fcurve' into two functions:

  ED_action_fcurve_ensure which adds the f-curve if needed.
  ED_action_fcurve_find which returns NULL when not found.

  Callers of ED_action_fcurve_find had unused 'group'
  argument which has been removed.

- Rename verify_adt_action to ED_id_action_ensure

  It had an argument to add data which was always true,
  remove this instead of splitting in into a separate function.
This commit is contained in:
2020-03-06 13:41:27 +11:00
parent 07d13be678
commit b15c658801
10 changed files with 70 additions and 57 deletions

View File

@@ -197,7 +197,7 @@ void AnimationImporter::add_fcurves_to_object(Main *bmain,
bAction *act;
if (!ob->adt || !ob->adt->action) {
act = verify_adt_action(bmain, (ID *)&ob->id, 1);
act = ED_id_action_ensure(bmain, (ID *)&ob->id);
}
else {
act = ob->adt->action;
@@ -941,7 +941,7 @@ void AnimationImporter::apply_matrix_curves(Object *ob,
}
}
Main *bmain = CTX_data_main(mContext);
verify_adt_action(bmain, (ID *)&ob->id, 1);
ED_id_action_ensure(bmain, (ID *)&ob->id);
ListBase *curves = &ob->adt->action->curves;
@@ -1006,7 +1006,7 @@ static ListBase &get_animation_curves(Main *bmain, Material *ma)
{
bAction *act;
if (!ma->adt || !ma->adt->action) {
act = verify_adt_action(bmain, (ID *)&ma->id, 1);
act = ED_id_action_ensure(bmain, (ID *)&ma->id);
}
else {
act = ma->adt->action;
@@ -1052,7 +1052,7 @@ void AnimationImporter::translate_Animations(
}
if (!ob->adt || !ob->adt->action) {
act = verify_adt_action(bmain, (ID *)&ob->id, 1);
act = ED_id_action_ensure(bmain, (ID *)&ob->id);
}
else {
act = ob->adt->action;
@@ -1115,7 +1115,7 @@ void AnimationImporter::translate_Animations(
if ((animType->light) != 0) {
Light *lamp = (Light *)ob->data;
if (!lamp->adt || !lamp->adt->action) {
act = verify_adt_action(bmain, (ID *)&lamp->id, 1);
act = ED_id_action_ensure(bmain, (ID *)&lamp->id);
}
else {
act = lamp->adt->action;
@@ -1153,7 +1153,7 @@ void AnimationImporter::translate_Animations(
Camera *cam = (Camera *)ob->data;
if (!cam->adt || !cam->adt->action) {
act = verify_adt_action(bmain, (ID *)&cam->id, 1);
act = ED_id_action_ensure(bmain, (ID *)&cam->id);
}
else {
act = cam->adt->action;
@@ -1209,7 +1209,7 @@ void AnimationImporter::translate_Animations(
Material *ma = BKE_object_material_get(ob, 1);
if (!ma->adt || !ma->adt->action) {
act = verify_adt_action(bmain, (ID *)&ma->id, 1);
act = ED_id_action_ensure(bmain, (ID *)&ma->id);
}
else {
act = ma->adt->action;
@@ -1390,7 +1390,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob,
}
}
Main *bmain = CTX_data_main(mContext);
verify_adt_action(bmain, (ID *)&ob->id, 1);
ED_id_action_ensure(bmain, (ID *)&ob->id);
/* add curves */
for (int i = 0; i < totcu; i++) {
@@ -1823,7 +1823,7 @@ Object *AnimationImporter::translate_animation_OLD(
#endif
}
Main *bmain = CTX_data_main(mContext);
verify_adt_action(bmain, (ID *)&ob->id, 1);
ED_id_action_ensure(bmain, (ID *)&ob->id);
ListBase *curves = &ob->adt->action->curves;
@@ -2129,7 +2129,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);
verify_adt_action((ID *)&job->id, 1);
ED_id_action_ensure((ID *)&job->id);
job->rotmode = ROT_MODE_QUAT;

View File

@@ -4432,8 +4432,8 @@ 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 = verify_adt_action(bmain, (ID *)key, 1);
FCurve *fcu = verify_fcurve(bmain, act, NULL, &ptr, rna_path, 0, 1);
bAction *act = ED_id_action_ensure(bmain, (ID *)key);
FCurve *fcu = ED_action_fcurve_ensure(bmain, act, NULL, &ptr, rna_path, 0);
/* set the special 'replace' flag if on a keyframe */
if (fcurve_frame_has_keyframe(fcu, cfra, 0)) {

View File

@@ -131,13 +131,13 @@ short ANIM_get_keyframing_flags(Scene *scene, short incl_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 *verify_adt_action(Main *bmain, ID *id, short add)
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 == NULL) && (add)) {
if (adt == NULL) {
adt = BKE_animdata_add_id(id);
}
if (adt == NULL) {
@@ -148,7 +148,7 @@ bAction *verify_adt_action(Main *bmain, ID *id, short add)
/* init action if none available yet */
/* TODO: need some wizardry to handle NLA stuff correct */
if ((adt->action == NULL) && (add)) {
if (adt->action == NULL) {
/* init action name from name of ID block */
char actname[sizeof(id->name) - 2];
BLI_snprintf(actname, sizeof(actname), "%sAction", id->name + 2);
@@ -172,21 +172,34 @@ bAction *verify_adt_action(Main *bmain, ID *id, short add)
return adt->action;
}
/* Get (or add relevant data to be able to do so) F-Curve from the Active Action,
/**
* Find the F-Curve from the Active Action,
* for the given Animation Data block. This assumes that all the destinations are valid.
*/
FCurve *verify_fcurve(Main *bmain,
bAction *act,
const char group[],
PointerRNA *ptr,
const char rna_path[],
const int array_index,
short add)
FCurve *ED_action_fcurve_find(struct bAction *act, const char rna_path[], const int array_index)
{
/* Sanity checks. */
if (ELEM(NULL, act, rna_path)) {
return NULL;
}
return list_find_fcurve(&act->curves, rna_path, array_index);
}
/**
* Get (or add relevant data to be able to do so) F-Curve from the Active Action,
* for the given Animation Data block. This assumes that all the destinations are valid.
*/
FCurve *ED_action_fcurve_ensure(struct Main *bmain,
struct bAction *act,
const char group[],
struct PointerRNA *ptr,
const char rna_path[],
const int array_index)
{
bActionGroup *agrp;
FCurve *fcu;
/* sanity checks */
/* Sanity checks. */
if (ELEM(NULL, act, rna_path)) {
return NULL;
}
@@ -197,7 +210,7 @@ FCurve *verify_fcurve(Main *bmain,
*/
fcu = list_find_fcurve(&act->curves, rna_path, array_index);
if ((fcu == NULL) && (add)) {
if (fcu == NULL) {
/* use default settings to make a F-Curve */
fcu = MEM_callocN(sizeof(FCurve), "FCurve");
@@ -1284,7 +1297,9 @@ static bool insert_keyframe_fcurve_value(Main *bmain,
* but still try to get the F-Curve if it exists...
*/
bool can_create_curve = (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) == 0;
FCurve *fcu = verify_fcurve(bmain, act, group, ptr, rna_path, array_index, can_create_curve);
FCurve *fcu = can_create_curve ?
ED_action_fcurve_ensure(bmain, act, group, ptr, rna_path, array_index) :
ED_action_fcurve_find(act, rna_path, array_index);
/* we may not have a F-Curve when we're replacing only... */
if (fcu) {
@@ -1361,7 +1376,7 @@ short insert_keyframe(Main *bmain,
/* if no action is provided, keyframe to the default one attached to this ID-block */
if (act == NULL) {
/* get action to add F-Curve+keyframe to */
act = verify_adt_action(bmain, id, 1);
act = ED_id_action_ensure(bmain, id);
if (act == NULL) {
BKE_reportf(reports,
@@ -1559,7 +1574,6 @@ short delete_keyframe(Main *bmain,
ReportList *reports,
ID *id,
bAction *act,
const char group[],
const char rna_path[],
int array_index,
float cfra,
@@ -1625,7 +1639,7 @@ short delete_keyframe(Main *bmain,
/* will only loop once unless the array index was -1 */
for (; array_index < array_index_max; array_index++) {
FCurve *fcu = verify_fcurve(bmain, act, group, &ptr, rna_path, array_index, 0);
FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
/* check if F-Curve exists and/or whether it can be edited */
if (fcu == NULL) {
@@ -1665,7 +1679,6 @@ static short clear_keyframe(Main *bmain,
ReportList *reports,
ID *id,
bAction *act,
const char group[],
const char rna_path[],
int array_index,
eInsertKeyFlags UNUSED(flag))
@@ -1727,7 +1740,7 @@ static short clear_keyframe(Main *bmain,
/* will only loop once unless the array index was -1 */
for (; array_index < array_index_max; array_index++) {
FCurve *fcu = verify_fcurve(bmain, act, group, &ptr, rna_path, array_index, 0);
FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
/* check if F-Curve exists and/or whether it can be edited */
if (fcu == NULL) {
@@ -2576,8 +2589,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op)
index = -1;
}
success = delete_keyframe(
bmain, op->reports, ptr.owner_id, NULL, NULL, path, index, cfra, 0);
success = delete_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, cfra, 0);
MEM_freeN(path);
}
else if (G.debug & G_DEBUG) {
@@ -2645,7 +2657,7 @@ static int clear_key_button_exec(bContext *C, wmOperator *op)
index = -1;
}
success += clear_keyframe(bmain, op->reports, ptr.owner_id, NULL, NULL, path, index, 0);
success += clear_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, 0);
MEM_freeN(path);
}
else if (G.debug & G_DEBUG) {

View File

@@ -1136,8 +1136,7 @@ int ANIM_apply_keyingset(
kflag2);
}
else if (mode == MODIFYKEY_MODE_DELETE) {
success += delete_keyframe(
bmain, reports, ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag2);
success += delete_keyframe(bmain, reports, ksp->id, act, ksp->rna_path, i, cfra, kflag2);
}
}

View File

@@ -513,8 +513,8 @@ static void gp_stroke_path_animation(bContext *C,
prop = RNA_struct_find_property(&ptr, "eval_time");
/* Ensure we have an F-Curve to add keyframes to */
act = verify_adt_action(bmain, (ID *)cu, true);
fcu = verify_fcurve(bmain, act, NULL, &ptr, "eval_time", 0, true);
act = ED_id_action_ensure(bmain, (ID *)cu);
fcu = ED_action_fcurve_ensure(bmain, act, NULL, &ptr, "eval_time", 0);
if (G.debug & G_DEBUG) {
printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time);

View File

@@ -65,18 +65,21 @@ short ANIM_get_keyframing_flags(struct Scene *scene, short incl_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.
*/
struct bAction *verify_adt_action(struct Main *bmain, struct ID *id, short add);
struct bAction *ED_id_action_ensure(struct Main *bmain, struct ID *id);
/* Get (or add relevant data to be able to do so) F-Curve from the given Action.
* This assumes that all the destinations are valid.
*/
struct FCurve *verify_fcurve(struct Main *bmain,
struct bAction *act,
const char group[],
struct PointerRNA *ptr,
const char rna_path[],
const int array_index,
short add);
struct FCurve *ED_action_fcurve_ensure(struct Main *bmain,
struct bAction *act,
const char group[],
struct PointerRNA *ptr,
const char rna_path[],
const int array_index);
struct FCurve *ED_action_fcurve_find(struct bAction *act,
const char rna_path[],
const int array_index);
/* -------- */
@@ -145,7 +148,6 @@ short delete_keyframe(struct Main *bmain,
struct ReportList *reports,
struct ID *id,
struct bAction *act,
const char group[],
const char rna_path[],
int array_index,
float cfra,

View File

@@ -1024,8 +1024,8 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op)
if (ELEM(NULL, cu->adt, cu->adt->action) ||
(list_find_fcurve(&cu->adt->action->curves, "eval_time", 0) == NULL)) {
/* create F-Curve for path animation */
act = verify_adt_action(bmain, &cu->id, 1);
fcu = verify_fcurve(bmain, act, NULL, NULL, "eval_time", 0, 1);
act = ED_id_action_ensure(bmain, &cu->id);
fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, "eval_time", 0);
/* standard vertical range - 1:1 = 100 frames */
standardRange = 100.0f;
@@ -1049,8 +1049,8 @@ 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 = verify_adt_action(bmain, &ob->id, 1);
fcu = verify_fcurve(bmain, act, NULL, NULL, path, 0, 1);
act = ED_id_action_ensure(bmain, &ob->id);
fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, path, 0);
/* standard vertical range - 0.0 to 1.0 */
standardRange = 1.0f;

View File

@@ -707,8 +707,8 @@ 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 = verify_adt_action(bmain, &cu->id, 1);
FCurve *fcu = verify_fcurve(bmain, act, NULL, NULL, "eval_time", 0, 1);
bAction *act = ED_id_action_ensure(bmain, &cu->id);
FCurve *fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, "eval_time", 0);
/* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {

View File

@@ -123,8 +123,8 @@ static FCurve *rna_Action_fcurve_new(bAction *act,
return NULL;
}
/* annoying, check if this exists */
if (verify_fcurve(bmain, act, group, NULL, data_path, index, 0)) {
/* Annoying, check if this exists. */
if (ED_action_fcurve_find(act, data_path, index)) {
BKE_reportf(reports,
RPT_ERROR,
"F-Curve '%s[%d]' already exists in action '%s'",
@@ -133,7 +133,7 @@ static FCurve *rna_Action_fcurve_new(bAction *act,
act->id.name + 2);
return NULL;
}
return verify_fcurve(bmain, act, group, NULL, data_path, index, 1);
return ED_action_fcurve_ensure(bmain, act, group, NULL, data_path, index);
}
static FCurve *rna_Action_fcurve_find(bAction *act,

View File

@@ -502,7 +502,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
BKE_reports_init(&reports, RPT_STORE);
result = delete_keyframe(
G.main, &reports, (ID *)self->ptr.owner_id, NULL, group_name, path_full, index, cfra, 0);
G.main, &reports, (ID *)self->ptr.owner_id, NULL, path_full, index, cfra, 0);
MEM_freeN((void *)path_full);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {