Refactor: Pass Keyframe settings as arguments #115898

Merged
Christoph Lendenfeld merged 6 commits from ChrisLend/blender:refactor_insert_vert_arguments into main 2023-12-08 13:09:19 +01:00
11 changed files with 149 additions and 123 deletions

View File

@ -15,11 +15,25 @@ struct FCurve;
namespace blender::animrig {
/* This is used to pass in the settings for a keyframe into a function. */
struct KeyframeSettings {
eBezTriple_KeyframeType keyframe_type;
eBezTriple_Handle handle;
eBezTriple_Interpolation interpolation;
};
/**
* Helper function to generate the KeyframeSettings struct.
*
* \param from_userprefs if true read the user preferences for the settings, else return static
* defaults.
*/
KeyframeSettings get_keyframe_settings(bool from_userprefs);
/** Initialize the given BezTriple with default values. */
void initialize_bezt(BezTriple *beztr,
float2 position,
eBezTriple_KeyframeType keyframe_type,
eInsertKeyFlags flag,
const KeyframeSettings &settings,
eFCurve_Flags fcu_flags);
/**
@ -63,7 +77,7 @@ int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
*/
int insert_vert_fcurve(FCurve *fcu,
const float2 position,
eBezTriple_KeyframeType keyframe_type,
const KeyframeSettings &settings,
eInsertKeyFlags flag);
} // namespace blender::animrig

View File

@ -19,6 +19,20 @@
namespace blender::animrig {
KeyframeSettings get_keyframe_settings(const bool from_userprefs)
{
KeyframeSettings settings = {};
settings.keyframe_type = BEZT_KEYTYPE_KEYFRAME;
settings.handle = HD_AUTO_ANIM;
settings.interpolation = BEZT_IPO_BEZ;
if (from_userprefs) {
settings.interpolation = eBezTriple_Interpolation(U.ipo_new);
settings.handle = eBezTriple_Handle(U.keyhandles_new);
}
return settings;
}
bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
{
bool found;
@ -201,8 +215,7 @@ static void subdivide_nonauto_handles(const FCurve *fcu,
void initialize_bezt(BezTriple *beztr,
const float2 position,
const eBezTriple_KeyframeType keyframe_type,
const eInsertKeyFlags flag,
const KeyframeSettings &settings,
const eFCurve_Flags fcu_flags)
{
/* Set all three points, for nicer start position.
@ -216,21 +229,8 @@ void initialize_bezt(BezTriple *beztr,
beztr->vec[2][1] = position.y;
beztr->f1 = beztr->f2 = beztr->f3 = SELECT;
/* Set default handle types and interpolation mode. */
if (flag & INSERTKEY_NO_USERPREF) {
/* For Py-API, we want scripts to have predictable behavior,
* hence the option to not depend on the userpref defaults.
*/
beztr->h1 = beztr->h2 = HD_AUTO_ANIM;
beztr->ipo = BEZT_IPO_BEZ;
}
else {
/* For UI usage - defaults should come from the user-preferences and/or tool-settings. */
beztr->h1 = beztr->h2 = U.keyhandles_new; /* Use default handle type here. */
/* Use default interpolation mode, with exceptions for int/discrete values. */
beztr->ipo = U.ipo_new;
}
beztr->h1 = beztr->h2 = settings.handle;
beztr->ipo = settings.interpolation;
/* Interpolation type used is constrained by the type of values the curve can take. */
if (fcu_flags & FCURVE_DISCRETE_VALUES) {
@ -242,7 +242,7 @@ void initialize_bezt(BezTriple *beztr,
/* Set keyframe type value (supplied), which should come from the scene
* settings in most cases. */
BEZKEYTYPE(beztr) = keyframe_type;
BEZKEYTYPE(beztr) = settings.keyframe_type;
/* Set default values for "easing" interpolation mode settings.
* NOTE: Even if these modes aren't currently used, if users switch
@ -262,11 +262,11 @@ void initialize_bezt(BezTriple *beztr,
int insert_vert_fcurve(FCurve *fcu,
const float2 position,
eBezTriple_KeyframeType keyframe_type,
const KeyframeSettings &settings,
eInsertKeyFlags flag)
{
BezTriple beztr = {{{0}}};
initialize_bezt(&beztr, position, keyframe_type, flag, eFCurve_Flags(fcu->flag));
initialize_bezt(&beztr, position, settings, eFCurve_Flags(fcu->flag));
uint oldTot = fcu->totvert;
int a;

View File

@ -310,19 +310,22 @@ static bool insert_keyframe_value(
}
}
KeyframeSettings settings = get_keyframe_settings((flag & INSERTKEY_NO_USERPREF) == 0);
settings.keyframe_type = keytype;
if (flag & INSERTKEY_NEEDED) {
if (!new_key_needed(fcu, cfra, curval)) {
return false;
}
if (insert_vert_fcurve(fcu, {cfra, curval}, keytype, flag) < 0) {
if (insert_vert_fcurve(fcu, {cfra, curval}, settings, flag) < 0) {
return false;
}
return true;
}
return insert_vert_fcurve(fcu, {cfra, curval}, keytype, flag) >= 0;
return insert_vert_fcurve(fcu, {cfra, curval}, settings, flag) >= 0;
}
bool insert_keyframe_direct(ReportList *reports,

View File

@ -32,9 +32,10 @@ TEST(evaluate_fcurve, OnKeys)
{
FCurve *fcu = BKE_fcurve_create();
insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {3.0f, 19.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
const KeyframeSettings settings = get_keyframe_settings(false);
insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS);

About this block & similar blocks below: since settings is only used by the block of code directly following it, personally I'd remove the newline under the get_keyframe_settings() call. No strong feelings either way, do with this as you please, I just wanted to voice a minor personal preference ;-)

About this block & similar blocks below: since `settings` is only used by the block of code directly following it, personally I'd remove the newline under the `get_keyframe_settings()` call. No strong feelings either way, do with this as you please, I just wanted to voice a minor personal preference ;-)
insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {3.0f, 19.0f}, settings, INSERTKEY_NOFLAGS);
EXPECT_NEAR(evaluate_fcurve(fcu, 1.0f), 7.0f, EPSILON); /* hits 'on or before first' function */
EXPECT_NEAR(evaluate_fcurve(fcu, 2.0f), 13.0f, EPSILON); /* hits 'between' function */
@ -55,10 +56,9 @@ TEST(evaluate_fcurve, InterpolationConstant)
{
FCurve *fcu = BKE_fcurve_create();
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
const KeyframeSettings settings = get_keyframe_settings(false);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS), 1);
fcu->bezt[0].ipo = BEZT_IPO_CONST;
fcu->bezt[1].ipo = BEZT_IPO_CONST;
@ -73,10 +73,9 @@ TEST(evaluate_fcurve, InterpolationLinear)
{
FCurve *fcu = BKE_fcurve_create();
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
const KeyframeSettings settings = get_keyframe_settings(false);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS), 1);
fcu->bezt[0].ipo = BEZT_IPO_LIN;
fcu->bezt[1].ipo = BEZT_IPO_LIN;
@ -92,10 +91,9 @@ TEST(evaluate_fcurve, InterpolationBezier)
{
FCurve *fcu = BKE_fcurve_create();
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
const KeyframeSettings settings = get_keyframe_settings(false);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS), 1);
EXPECT_EQ(fcu->bezt[0].ipo, BEZT_IPO_BEZ);
EXPECT_EQ(fcu->bezt[1].ipo, BEZT_IPO_BEZ);
@ -127,10 +125,9 @@ TEST(evaluate_fcurve, InterpolationBounce)
{
FCurve *fcu = BKE_fcurve_create();
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
const KeyframeSettings settings = get_keyframe_settings(false);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS), 1);
fcu->bezt[0].ipo = BEZT_IPO_BOUNCE;
fcu->bezt[1].ipo = BEZT_IPO_BOUNCE;
@ -149,10 +146,9 @@ TEST(evaluate_fcurve, ExtrapolationLinearKeys)
{
FCurve *fcu = BKE_fcurve_create();
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
const KeyframeSettings settings = get_keyframe_settings(false);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS), 1);
fcu->bezt[0].ipo = BEZT_IPO_LIN;
fcu->bezt[1].ipo = BEZT_IPO_LIN;
@ -180,10 +176,9 @@ TEST(evaluate_fcurve, ExtrapolationBezierKeys)
{
FCurve *fcu = BKE_fcurve_create();
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
const KeyframeSettings settings = get_keyframe_settings(false);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {2.0f, 13.0f}, settings, INSERTKEY_NOFLAGS), 1);
fcu->bezt[0].vec[0][0] = 0.71855f; /* left handle X */
fcu->bezt[0].vec[0][1] = 6.22482f; /* left handle Y */
@ -218,11 +213,10 @@ TEST(fcurve_subdivide, BKE_fcurve_bezt_subdivide_handles)
{
FCurve *fcu = BKE_fcurve_create();
const KeyframeSettings settings = get_keyframe_settings(false);
/* Insert two keyframes and set handles to something non-default. */
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 0.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {13.0f, 2.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 0.0f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {13.0f, 2.0f}, settings, INSERTKEY_NOFLAGS), 1);
fcu->bezt[0].h1 = fcu->bezt[0].h2 = HD_FREE;
fcu->bezt[0].vec[0][0] = -5.0f;
@ -286,15 +280,13 @@ TEST(fcurve_active_keyframe, ActiveKeyframe)
/* There should be no active keyframe with no points. */
EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE);
const KeyframeSettings settings = get_keyframe_settings(false);
/* Check that adding new points sets the active index. */
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.5f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
0);
EXPECT_EQ(insert_vert_fcurve(fcu, {1.0f, 7.5f}, settings, INSERTKEY_NOFLAGS), 0);
EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), 0);
EXPECT_EQ(insert_vert_fcurve(fcu, {8.0f, 15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
1);
EXPECT_EQ(insert_vert_fcurve(fcu, {8.0f, 15.0f}, settings, INSERTKEY_NOFLAGS), 1);
EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), 1);
EXPECT_EQ(insert_vert_fcurve(fcu, {14.0f, 8.2f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF),
2);
EXPECT_EQ(insert_vert_fcurve(fcu, {14.0f, 8.2f}, settings, INSERTKEY_NOFLAGS), 2);
EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), 2);
/* Check clearing the index. */
@ -342,9 +334,10 @@ TEST(BKE_fcurve, BKE_fcurve_keyframe_move_value_with_handles)
{
FCurve *fcu = BKE_fcurve_create();
insert_vert_fcurve(fcu, {1.0f, 7.5f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
const KeyframeSettings settings = get_keyframe_settings(false);
insert_vert_fcurve(fcu, {1.0f, 7.5f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, settings, INSERTKEY_NOFLAGS);
EXPECT_FLOAT_EQ(fcu->bezt[1].vec[0][0], 5.2671194f);
EXPECT_FLOAT_EQ(fcu->bezt[1].vec[0][1], 15.0f);
@ -373,9 +366,10 @@ TEST(BKE_fcurve, BKE_fcurve_keyframe_move_time_with_handles)
{
FCurve *fcu = BKE_fcurve_create();
insert_vert_fcurve(fcu, {1.0f, 7.5f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
const KeyframeSettings settings = get_keyframe_settings(false);
insert_vert_fcurve(fcu, {1.0f, 7.5f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, settings, INSERTKEY_NOFLAGS);
EXPECT_FLOAT_EQ(fcu->bezt[1].vec[0][0], 5.2671194f);
EXPECT_FLOAT_EQ(fcu->bezt[1].vec[0][1], 15.0f);
@ -404,11 +398,12 @@ TEST(BKE_fcurve, BKE_fcurve_calc_range)
{
FCurve *fcu = BKE_fcurve_create();
insert_vert_fcurve(fcu, {1.0f, 7.5f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {4.0f, -15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {18.2f, -20.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
const KeyframeSettings settings = get_keyframe_settings(false);
insert_vert_fcurve(fcu, {1.0f, 7.5f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {4.0f, -15.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {18.2f, -20.0f}, settings, INSERTKEY_NOFLAGS);
for (int i = 0; i < fcu->totvert; i++) {
fcu->bezt[i].f1 &= ~SELECT;
@ -456,11 +451,12 @@ TEST(BKE_fcurve, BKE_fcurve_calc_bounds)
{
FCurve *fcu = BKE_fcurve_create();
insert_vert_fcurve(fcu, {1.0f, 7.5f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {4.0f, -15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
insert_vert_fcurve(fcu, {18.2f, -20.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NO_USERPREF);
const KeyframeSettings settings = get_keyframe_settings(false);
insert_vert_fcurve(fcu, {1.0f, 7.5f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {4.0f, -15.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {8.0f, 15.0f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {14.0f, 8.2f}, settings, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {18.2f, -20.0f}, settings, INSERTKEY_NOFLAGS);
for (int i = 0; i < fcu->totvert; i++) {
fcu->bezt[i].f1 &= ~SELECT;

View File

@ -95,6 +95,7 @@ FCurve *alloc_driver_fcurve(const char rna_path[],
const int array_index,
eDriverFCurveCreationMode creation_mode)
{
using namespace blender::animrig;
FCurve *fcu = BKE_fcurve_create();
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
@ -124,10 +125,9 @@ FCurve *alloc_driver_fcurve(const char rna_path[],
* - These are configured to 0,0 and 1,1 to give a 1-1 mapping
* which can be easily tweaked from there.
*/
blender::animrig::insert_vert_fcurve(
fcu, {0.0f, 0.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_FAST | INSERTKEY_NO_USERPREF);
blender::animrig::insert_vert_fcurve(
fcu, {1.0f, 1.0f}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_FAST | INSERTKEY_NO_USERPREF);
const KeyframeSettings settings = get_keyframe_settings(false);
insert_vert_fcurve(fcu, {0.0f, 0.0f}, settings, INSERTKEY_FAST);
insert_vert_fcurve(fcu, {1.0f, 1.0f}, settings, INSERTKEY_FAST);
fcu->extend = FCURVE_EXTRAPOLATE_LINEAR;
BKE_fcurve_handles_recalc(fcu);
}

View File

@ -1223,6 +1223,7 @@ void sample_fcurve_segment(FCurve *fcu,
void bake_fcurve_segments(FCurve *fcu)
{
using namespace blender::animrig;
BezTriple *bezt, *start = nullptr, *end = nullptr;
TempFrameValCache *value_cache, *fp;
int sfra, range;
@ -1232,6 +1233,9 @@ void bake_fcurve_segments(FCurve *fcu)
return;
}
KeyframeSettings settings = get_keyframe_settings(true);
settings.keyframe_type = BEZT_KEYTYPE_BREAKDOWN;
/* Find selected keyframes... once pair has been found, add keyframes. */
for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
/* check if selected, and which end this is */
@ -1272,7 +1276,7 @@ void bake_fcurve_segments(FCurve *fcu)
/* add keyframes with these, tagging as 'breakdowns' */
for (n = 1, fp = value_cache; n < range && fp; n++, fp++) {
blender::animrig::insert_vert_fcurve(
fcu, {fp->frame, fp->val}, BEZT_KEYTYPE_BREAKDOWN, eInsertKeyFlags(1));
fcu, {fp->frame, fp->val}, settings, eInsertKeyFlags(1));
}
/* free temp cache */

View File

@ -1734,15 +1734,15 @@ static void propagate_curve_values(ListBase /*tPChanFCurveLink*/ *pflinks,
const float source_frame,
ListBase /*FrameLink*/ *target_frames)
{
using namespace blender::animrig;
const KeyframeSettings settings = get_keyframe_settings(true);
LISTBASE_FOREACH (tPChanFCurveLink *, pfl, pflinks) {
LISTBASE_FOREACH (LinkData *, ld, &pfl->fcurves) {
FCurve *fcu = (FCurve *)ld->data;
const float current_fcu_value = evaluate_fcurve(fcu, source_frame);
LISTBASE_FOREACH (FrameLink *, target_frame, target_frames) {
blender::animrig::insert_vert_fcurve(fcu,
{target_frame->frame, current_fcu_value},
BEZT_KEYTYPE_KEYFRAME,
INSERTKEY_NEEDED);
insert_vert_fcurve(
fcu, {target_frame->frame, current_fcu_value}, settings, INSERTKEY_NEEDED);
}
}
}

View File

@ -824,6 +824,7 @@ static void insert_fcurve_key(bAnimContext *ac,
const AnimationEvalContext anim_eval_context,
eInsertKeyFlags flag)
{
using namespace blender::animrig;
FCurve *fcu = (FCurve *)ale->key_data;
ReportList *reports = ac->reports;
@ -840,16 +841,16 @@ static void insert_fcurve_key(bAnimContext *ac,
* (TODO: add the full-blown PointerRNA relative parsing case here...)
*/
if (ale->id && !ale->owner) {
blender::animrig::insert_keyframe(ac->bmain,
reports,
ale->id,
nullptr,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,
&anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
insert_keyframe(ac->bmain,
reports,
ale->id,
nullptr,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,
&anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
}
else {
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
@ -861,8 +862,9 @@ static void insert_fcurve_key(bAnimContext *ac,
}
const float curval = evaluate_fcurve(fcu, cfra);
blender::animrig::insert_vert_fcurve(
fcu, {cfra, curval}, eBezTriple_KeyframeType(ts->keyframe_type), eInsertKeyFlags(0));
KeyframeSettings settings = get_keyframe_settings(true);
settings.keyframe_type = eBezTriple_KeyframeType(ts->keyframe_type);
insert_vert_fcurve(fcu, {cfra, curval}, settings, eInsertKeyFlags(0));
}
ale->update |= ANIM_UPDATE_DEFAULT;

View File

@ -107,6 +107,7 @@ static const EnumPropertyItem prop_graphkeys_insertkey_types[] = {
/* This function is responsible for snapping keyframes to frame-times. */
static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
{
using namespace blender::animrig;
ListBase anim_data = {nullptr, nullptr};
int filter;
size_t num_items;
@ -147,6 +148,8 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
/* Init key-framing flag. */
flag = ANIM_get_keyframing_flags(scene, true);
KeyframeSettings settings = get_keyframe_settings(true);
settings.keyframe_type = eBezTriple_KeyframeType(ts->keyframe_type);
/* Insert keyframes. */
if (mode & GRAPHKEYS_INSERTKEY_CURSOR) {
@ -181,8 +184,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
}
/* Insert keyframe directly into the F-Curve. */
blender::animrig::insert_vert_fcurve(
fcu, {x, y}, eBezTriple_KeyframeType(ts->keyframe_type), eInsertKeyFlags(0));
insert_vert_fcurve(fcu, {x, y}, settings, eInsertKeyFlags(0));
ale->update |= ANIM_UPDATE_DEFAULT;
}
@ -206,16 +208,16 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
* up adding the keyframes on a new F-Curve in the action data instead.
*/
if (ale->id && !ale->owner && !fcu->driver) {
blender::animrig::insert_keyframe(ac->bmain,
reports,
ale->id,
nullptr,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,
&anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
insert_keyframe(ac->bmain,
reports,
ale->id,
nullptr,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,
&anim_eval_context,
eBezTriple_KeyframeType(ts->keyframe_type),
flag);
}
else {
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
@ -230,8 +232,7 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
}
const float curval = evaluate_fcurve_only_curve(fcu, cfra);
blender::animrig::insert_vert_fcurve(
fcu, {cfra, curval}, eBezTriple_KeyframeType(ts->keyframe_type), eInsertKeyFlags(0));
insert_vert_fcurve(fcu, {cfra, curval}, settings, eInsertKeyFlags(0));
}
ale->update |= ANIM_UPDATE_DEFAULT;
@ -293,6 +294,7 @@ void GRAPH_OT_keyframe_insert(wmOperatorType *ot)
static int graphkeys_click_insert_exec(bContext *C, wmOperator *op)
{
using namespace blender::animrig;
bAnimContext ac;
bAnimListElem *ale;
AnimData *adt;
@ -346,9 +348,11 @@ static int graphkeys_click_insert_exec(bContext *C, wmOperator *op)
val = val * scale - offset;
KeyframeSettings settings = get_keyframe_settings(true);
settings.keyframe_type = eBezTriple_KeyframeType(ts->keyframe_type);
/* Insert keyframe on the specified frame + value. */
blender::animrig::insert_vert_fcurve(
fcu, {frame, val}, eBezTriple_KeyframeType(ts->keyframe_type), eInsertKeyFlags(0));
insert_vert_fcurve(fcu, {frame, val}, settings, eInsertKeyFlags(0));
ale->update |= ANIM_UPDATE_DEPS;

View File

@ -301,10 +301,13 @@ FCurve *BCAnimationCurve::get_edit_fcurve()
void BCAnimationCurve::clean_handles()
{
using namespace blender::animrig;
if (fcurve == nullptr) {
fcurve = get_edit_fcurve();
}
const KeyframeSettings settings = get_keyframe_settings(true);
/* Keep old bezt data for copy). */
BezTriple *old_bezts = fcurve->bezt;
int totvert = fcurve->totvert;
@ -315,8 +318,7 @@ void BCAnimationCurve::clean_handles()
BezTriple *bezt = &old_bezts[i];
float x = bezt->vec[1][0];
float y = bezt->vec[1][1];
blender::animrig::insert_vert_fcurve(
fcurve, {x, y}, (eBezTriple_KeyframeType)BEZKEYTYPE(bezt), INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcurve, {x, y}, settings, INSERTKEY_NOFLAGS);
BezTriple *lastb = fcurve->bezt + (fcurve->totvert - 1);
lastb->f1 = lastb->f2 = lastb->f3 = 0;
}
@ -379,10 +381,11 @@ void BCAnimationCurve::adjust_range(const int frame_index)
void BCAnimationCurve::add_value(const float val, const int frame_index)
{
using namespace blender::animrig;
const KeyframeSettings settings = get_keyframe_settings(true);
FCurve *fcu = get_edit_fcurve();
fcu->auto_smoothing = U.auto_smoothing_new;
blender::animrig::insert_vert_fcurve(
fcu, {(float)frame_index, val}, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_NOFLAGS);
insert_vert_fcurve(fcu, {(float)frame_index, val}, settings, INSERTKEY_NOFLAGS);
if (fcu->totvert == 1) {
init_range(val);

View File

@ -1055,10 +1055,10 @@ static void rna_FModifierStepped_frame_end_set(PointerRNA *ptr, float value)
static BezTriple *rna_FKeyframe_points_insert(
ID *id, FCurve *fcu, Main *bmain, float frame, float value, int keyframe_type, int flag)
{
int index = blender::animrig::insert_vert_fcurve(fcu,
{frame, value},
eBezTriple_KeyframeType(keyframe_type),
eInsertKeyFlags(flag) | INSERTKEY_NO_USERPREF);
using namespace blender::animrig;
KeyframeSettings settings = get_keyframe_settings(false);
settings.keyframe_type = eBezTriple_KeyframeType(keyframe_type);
int index = insert_vert_fcurve(fcu, {frame, value}, settings, eInsertKeyFlags(flag));
if ((fcu->bezt) && (index >= 0)) {
rna_tag_animation_update(bmain, id);