Refactor: Move fcurve functions to animrig
No functional changes. Moving the following two functions to animrig `ED_action_fcurve_ensure` `ED_action_fcurve_find` Pull Request: https://projects.blender.org/blender/blender/pulls/114445
This commit is contained in:
committed by
Christoph Lendenfeld
parent
ba37c59e13
commit
0f5e7c7469
@@ -8,11 +8,31 @@
|
||||
* \brief Functions to modify FCurves.
|
||||
*/
|
||||
|
||||
#include "RNA_types.hh"
|
||||
|
||||
struct AnimData;
|
||||
struct FCurve;
|
||||
struct bAction;
|
||||
|
||||
namespace blender::animrig {
|
||||
|
||||
/**
|
||||
* 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(Main *bmain,
|
||||
bAction *act,
|
||||
const char group[],
|
||||
PointerRNA *ptr,
|
||||
const char rna_path[],
|
||||
int array_index);
|
||||
|
||||
/**
|
||||
* Find the F-Curve from the Active Action,
|
||||
* for the given Animation Data block. This assumes that all the destinations are valid.
|
||||
*/
|
||||
FCurve *ED_action_fcurve_find(bAction *act, const char rna_path[], int array_index);
|
||||
|
||||
bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra);
|
||||
|
||||
} // namespace blender::animrig
|
||||
|
||||
@@ -7,12 +7,95 @@
|
||||
*/
|
||||
|
||||
#include "ANIM_fcurve.hh"
|
||||
#include "BKE_action.h"
|
||||
#include "BKE_fcurve.h"
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_string.h"
|
||||
#include "DEG_depsgraph_build.hh"
|
||||
#include "DNA_anim_types.h"
|
||||
#include "ED_anim_api.hh"
|
||||
#include "RNA_prototypes.h"
|
||||
|
||||
namespace blender::animrig {
|
||||
|
||||
FCurve *ED_action_fcurve_find(bAction *act, const char rna_path[], const int array_index)
|
||||
{
|
||||
/* Sanity checks. */
|
||||
if (ELEM(nullptr, act, rna_path)) {
|
||||
return nullptr;
|
||||
}
|
||||
return BKE_fcurve_find(&act->curves, rna_path, array_index);
|
||||
}
|
||||
|
||||
FCurve *ED_action_fcurve_ensure(Main *bmain,
|
||||
bAction *act,
|
||||
const char group[],
|
||||
PointerRNA *ptr,
|
||||
const char rna_path[],
|
||||
const int array_index)
|
||||
{
|
||||
bActionGroup *agrp;
|
||||
FCurve *fcu;
|
||||
|
||||
/* Sanity checks. */
|
||||
if (ELEM(nullptr, act, rna_path)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* try to find f-curve matching for this setting
|
||||
* - add if not found and allowed to add one
|
||||
* TODO: add auto-grouping support? how this works will need to be resolved
|
||||
*/
|
||||
fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
|
||||
|
||||
if (fcu == nullptr) {
|
||||
/* use default settings to make a F-Curve */
|
||||
fcu = BKE_fcurve_create();
|
||||
|
||||
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
|
||||
fcu->auto_smoothing = U.auto_smoothing_new;
|
||||
if (BLI_listbase_is_empty(&act->curves)) {
|
||||
fcu->flag |= FCURVE_ACTIVE; /* first one added active */
|
||||
}
|
||||
|
||||
/* store path - make copy, and store that */
|
||||
fcu->rna_path = BLI_strdup(rna_path);
|
||||
fcu->array_index = array_index;
|
||||
|
||||
/* if a group name has been provided, try to add or find a group, then add F-Curve to it */
|
||||
if (group) {
|
||||
/* try to find group */
|
||||
agrp = BKE_action_group_find_name(act, group);
|
||||
|
||||
/* no matching groups, so add one */
|
||||
if (agrp == nullptr) {
|
||||
agrp = action_groups_add_new(act, group);
|
||||
|
||||
/* sync bone group colors if applicable */
|
||||
if (ptr && (ptr->type == &RNA_PoseBone)) {
|
||||
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
|
||||
action_group_colors_set_from_posebone(agrp, pchan);
|
||||
}
|
||||
}
|
||||
|
||||
/* add F-Curve to group */
|
||||
action_groups_add_channel(act, agrp, fcu);
|
||||
}
|
||||
else {
|
||||
/* just add F-Curve to end of Action's list */
|
||||
BLI_addtail(&act->curves, fcu);
|
||||
}
|
||||
|
||||
/* New f-curve was added, meaning it's possible that it affects
|
||||
* dependency graph component which wasn't previously animated.
|
||||
*/
|
||||
DEG_relations_tag_update(bmain);
|
||||
}
|
||||
|
||||
/* return the F-Curve */
|
||||
return fcu;
|
||||
}
|
||||
|
||||
/**
|
||||
* \note caller needs to run #BKE_nla_tweakedit_remap to get NLA relative frame.
|
||||
* caller should also check #BKE_fcurve_is_protected before keying.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "ANIM_fcurve.hh"
|
||||
#include "ANIM_keyframing.hh"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
@@ -5094,7 +5095,8 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi
|
||||
/* find or create new F-Curve */
|
||||
/* XXX is the group name for this ok? */
|
||||
bAction *act = ED_id_action_ensure(bmain, (ID *)key);
|
||||
FCurve *fcu = ED_action_fcurve_ensure(bmain, act, nullptr, &ptr, rna_path, 0);
|
||||
FCurve *fcu = blender::animrig::ED_action_fcurve_ensure(
|
||||
bmain, act, nullptr, &ptr, rna_path, 0);
|
||||
|
||||
/* set the special 'replace' flag if on a keyframe */
|
||||
if (fcurve_frame_has_keyframe(fcu, remapped_frame)) {
|
||||
|
||||
@@ -155,84 +155,6 @@ bAction *ED_id_action_ensure(Main *bmain, ID *id)
|
||||
return adt->action;
|
||||
}
|
||||
|
||||
FCurve *ED_action_fcurve_find(bAction *act, const char rna_path[], const int array_index)
|
||||
{
|
||||
/* Sanity checks. */
|
||||
if (ELEM(nullptr, act, rna_path)) {
|
||||
return nullptr;
|
||||
}
|
||||
return BKE_fcurve_find(&act->curves, rna_path, array_index);
|
||||
}
|
||||
|
||||
FCurve *ED_action_fcurve_ensure(Main *bmain,
|
||||
bAction *act,
|
||||
const char group[],
|
||||
PointerRNA *ptr,
|
||||
const char rna_path[],
|
||||
const int array_index)
|
||||
{
|
||||
bActionGroup *agrp;
|
||||
FCurve *fcu;
|
||||
|
||||
/* Sanity checks. */
|
||||
if (ELEM(nullptr, act, rna_path)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* try to find f-curve matching for this setting
|
||||
* - add if not found and allowed to add one
|
||||
* TODO: add auto-grouping support? how this works will need to be resolved
|
||||
*/
|
||||
fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
|
||||
|
||||
if (fcu == nullptr) {
|
||||
/* use default settings to make a F-Curve */
|
||||
fcu = BKE_fcurve_create();
|
||||
|
||||
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
|
||||
fcu->auto_smoothing = U.auto_smoothing_new;
|
||||
if (BLI_listbase_is_empty(&act->curves)) {
|
||||
fcu->flag |= FCURVE_ACTIVE; /* first one added active */
|
||||
}
|
||||
|
||||
/* store path - make copy, and store that */
|
||||
fcu->rna_path = BLI_strdup(rna_path);
|
||||
fcu->array_index = array_index;
|
||||
|
||||
/* if a group name has been provided, try to add or find a group, then add F-Curve to it */
|
||||
if (group) {
|
||||
/* try to find group */
|
||||
agrp = BKE_action_group_find_name(act, group);
|
||||
|
||||
/* no matching groups, so add one */
|
||||
if (agrp == nullptr) {
|
||||
agrp = action_groups_add_new(act, group);
|
||||
|
||||
/* sync bone group colors if applicable */
|
||||
if (ptr && (ptr->type == &RNA_PoseBone)) {
|
||||
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
|
||||
action_group_colors_set_from_posebone(agrp, pchan);
|
||||
}
|
||||
}
|
||||
|
||||
/* add F-Curve to group */
|
||||
action_groups_add_channel(act, agrp, fcu);
|
||||
}
|
||||
else {
|
||||
/* just add F-Curve to end of Action's list */
|
||||
BLI_addtail(&act->curves, fcu);
|
||||
}
|
||||
|
||||
/* New f-curve was added, meaning it's possible that it affects
|
||||
* dependency graph component which wasn't previously animated.
|
||||
*/
|
||||
DEG_relations_tag_update(bmain);
|
||||
}
|
||||
|
||||
/* return the F-Curve */
|
||||
return fcu;
|
||||
}
|
||||
|
||||
/** Helper for #update_autoflags_fcurve(). */
|
||||
void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop)
|
||||
{
|
||||
|
||||
@@ -66,7 +66,9 @@
|
||||
#include "UI_resources.hh"
|
||||
#include "UI_view2d.hh"
|
||||
|
||||
#include "ANIM_fcurve.hh"
|
||||
#include "ANIM_keyframing.hh"
|
||||
|
||||
#include "ED_clip.hh"
|
||||
#include "ED_gpencil_legacy.hh"
|
||||
#include "ED_keyframing.hh"
|
||||
@@ -523,7 +525,7 @@ static void gpencil_stroke_path_animation(bContext *C,
|
||||
|
||||
/* Ensure we have an F-Curve to add keyframes to */
|
||||
act = ED_id_action_ensure(bmain, (ID *)cu);
|
||||
fcu = ED_action_fcurve_ensure(bmain, act, nullptr, &ptr, "eval_time", 0);
|
||||
fcu = blender::animrig::ED_action_fcurve_ensure(bmain, act, nullptr, &ptr, "eval_time", 0);
|
||||
|
||||
if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) {
|
||||
float cfra;
|
||||
|
||||
@@ -54,23 +54,6 @@ eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, bool use_autokey_mode);
|
||||
*/
|
||||
bAction *ED_id_action_ensure(Main *bmain, ID *id);
|
||||
|
||||
/**
|
||||
* 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(Main *bmain,
|
||||
bAction *act,
|
||||
const char group[],
|
||||
PointerRNA *ptr,
|
||||
const char rna_path[],
|
||||
int array_index);
|
||||
|
||||
/**
|
||||
* Find the F-Curve from the Active Action,
|
||||
* for the given Animation Data block. This assumes that all the destinations are valid.
|
||||
*/
|
||||
FCurve *ED_action_fcurve_find(bAction *act, const char rna_path[], int array_index);
|
||||
|
||||
/* -------- */
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,8 @@
|
||||
#include "ED_object.hh"
|
||||
#include "ED_screen.hh"
|
||||
|
||||
#include "ANIM_fcurve.hh"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
#include "UI_resources.hh"
|
||||
|
||||
@@ -1071,7 +1073,8 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* create F-Curve for path animation */
|
||||
act = ED_id_action_ensure(bmain, &cu->id);
|
||||
fcu = ED_action_fcurve_ensure(bmain, act, nullptr, nullptr, "eval_time", 0);
|
||||
fcu = blender::animrig::ED_action_fcurve_ensure(
|
||||
bmain, act, nullptr, nullptr, "eval_time", 0);
|
||||
|
||||
/* standard vertical range - 1:1 = 100 frames */
|
||||
standardRange = 100.0f;
|
||||
@@ -1095,7 +1098,7 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op)
|
||||
|
||||
/* create F-Curve for constraint */
|
||||
act = ED_id_action_ensure(bmain, &ob->id);
|
||||
fcu = ED_action_fcurve_ensure(bmain, act, nullptr, nullptr, path, 0);
|
||||
fcu = blender::animrig::ED_action_fcurve_ensure(bmain, act, nullptr, nullptr, path, 0);
|
||||
|
||||
/* standard vertical range - 0.0 to 1.0 */
|
||||
standardRange = 1.0f;
|
||||
|
||||
@@ -103,6 +103,8 @@
|
||||
#include "ED_screen.hh"
|
||||
#include "ED_view3d.hh"
|
||||
|
||||
#include "ANIM_fcurve.hh"
|
||||
|
||||
#include "MOD_nodes.hh"
|
||||
|
||||
#include "object_intern.h"
|
||||
@@ -560,7 +562,8 @@ bool ED_object_parent_set(ReportList *reports,
|
||||
if (partype == PAR_FOLLOW) {
|
||||
/* get or create F-Curve */
|
||||
bAction *act = ED_id_action_ensure(bmain, &cu->id);
|
||||
FCurve *fcu = ED_action_fcurve_ensure(bmain, act, nullptr, nullptr, "eval_time", 0);
|
||||
FCurve *fcu = blender::animrig::ED_action_fcurve_ensure(
|
||||
bmain, act, nullptr, nullptr, "eval_time", 0);
|
||||
|
||||
/* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
|
||||
if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
# include "DEG_depsgraph.hh"
|
||||
|
||||
# include "ED_keyframing.hh"
|
||||
# include "ANIM_fcurve.hh"
|
||||
|
||||
# include "WM_api.hh"
|
||||
|
||||
@@ -112,7 +112,7 @@ static FCurve *rna_Action_fcurve_new(bAction *act,
|
||||
}
|
||||
|
||||
/* Annoying, check if this exists. */
|
||||
if (ED_action_fcurve_find(act, data_path, index)) {
|
||||
if (blender::animrig::ED_action_fcurve_find(act, data_path, index)) {
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
"F-Curve '%s[%d]' already exists in action '%s'",
|
||||
@@ -121,7 +121,7 @@ static FCurve *rna_Action_fcurve_new(bAction *act,
|
||||
act->id.name + 2);
|
||||
return nullptr;
|
||||
}
|
||||
return ED_action_fcurve_ensure(bmain, act, group, nullptr, data_path, index);
|
||||
return blender::animrig::ED_action_fcurve_ensure(bmain, act, group, nullptr, data_path, index);
|
||||
}
|
||||
|
||||
static FCurve *rna_Action_fcurve_find(bAction *act,
|
||||
|
||||
Reference in New Issue
Block a user