Blender V4.3
keyframes_general.cc File Reference
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
#include "DNA_anim_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "BKE_action.hh"
#include "BKE_curve.hh"
#include "BKE_fcurve.hh"
#include "BKE_main.hh"
#include "BKE_scene.hh"
#include "RNA_access.hh"
#include "RNA_enum_types.hh"
#include "RNA_path.hh"
#include "ED_keyframes_edit.hh"
#include "ANIM_animdata.hh"
#include "ANIM_fcurve.hh"

Go to the source code of this file.

Classes

struct  ButterworthCoefficients
 
struct  tSmooth_Bezt
 
struct  tAnimCopybufItem
 

Functions

bool duplicate_fcurve_keys (FCurve *fcu)
 
Various Tools
void clean_fcurve (bAnimContext *ac, bAnimListElem *ale, float thresh, bool cleardefault, const bool only_selected_keys)
 
static bool find_fcurve_segment (FCurve *fcu, const int start_index, int *r_segment_start_idx, int *r_segment_len)
 
ListBase find_fcurve_segments (FCurve *fcu)
 
static const BezTriplefcurve_segment_start_get (FCurve *fcu, int index)
 
static const BezTriplefcurve_segment_end_get (FCurve *fcu, int index)
 
void blend_to_neighbor_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
float get_default_rna_value (const FCurve *fcu, PropertyRNA *prop, PointerRNA *ptr)
 
void blend_to_default_fcurve (PointerRNA *id_ptr, FCurve *fcu, const float factor)
 
void scale_average_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
ButterworthCoefficientsED_anim_allocate_butterworth_coefficients (const int filter_order)
 
void ED_anim_free_butterworth_coefficients (ButterworthCoefficients *bw_coeff)
 
void ED_anim_calculate_butterworth_coefficients (const float cutoff_frequency, const float sampling_frequency, ButterworthCoefficients *bw_coeff)
 
static double butterworth_filter_value (double x, double *w0, double *w1, double *w2, ButterworthCoefficients *bw_coeff)
 
static float butterworth_calculate_blend_value (float *samples, float *filtered_values, const int start_index, const int end_index, const int sample_index, const int blend_in_out)
 
void butterworth_smooth_fcurve_segment (FCurve *fcu, FCurveSegment *segment, float *samples, const int sample_count, const float factor, const int blend_in_out, const int sample_rate, ButterworthCoefficients *bw_coeff)
 
void ED_ANIM_get_1d_gauss_kernel (const float sigma, const int kernel_size, double *r_kernel)
 
void smooth_fcurve_segment (FCurve *fcu, FCurveSegment *segment, float *samples, const float factor, const int kernel_size, double *kernel)
 
static float ease_sigmoid_function (const float x, const float width, const float shift)
 
void ease_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor, const float width)
 
void blend_offset_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
static float s_curve (float x, float slope, float width, float height, float xshift, float yshift)
 
void blend_to_ease_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
bool match_slope_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
void shear_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor, tShearDirection direction)
 
void push_pull_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
void time_offset_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float frame_offset)
 
void scale_from_fcurve_segment_neighbor (FCurve *fcu, FCurveSegment *segment, const float factor, const FCurveSegmentAnchor anchor)
 
void breakdown_fcurve_segment (FCurve *fcu, FCurveSegment *segment, const float factor)
 
FCurve Decimate
static bool prepare_for_decimate (FCurve *fcu, int i)
 
static void decimate_fcurve_segment (FCurve *fcu, int bezt_segment_start_idx, int bezt_segment_len, float remove_ratio, float error_sq_max)
 
bool decimate_fcurve (bAnimListElem *ale, float remove_ratio, float error_sq_max)
 
FCurve Smooth
void smooth_fcurve (FCurve *fcu)
 

Copy/Paste Tools

  • The copy/paste buffer currently stores a set of temporary F-Curves containing only the keyframes that were selected in each of the original F-Curves.
  • All pasted frames are offset by the same amount. This is calculated as the difference in the times of the current frame and the first keyframe (i.e. the earliest one in all channels).
  • The earliest frame is calculated per copy operation.
static ListBase animcopybuf = {nullptr, nullptr}
 
static float animcopy_firstframe = 999999999.0f
 
static float animcopy_lastframe = -999999999.0f
 
static float animcopy_cfra = 0.0
 
const EnumPropertyItem rna_enum_keyframe_paste_offset_items []
 
const EnumPropertyItem rna_enum_keyframe_paste_offset_value_items []
 
const EnumPropertyItem rna_enum_keyframe_paste_merge_items []
 
void ANIM_fcurves_copybuf_free ()
 
short copy_animedit_keys (bAnimContext *ac, ListBase *anim_data)
 
static void flip_names (tAnimCopybufItem *aci, char **r_name)
 
static tAnimCopybufItempastebuf_match_path_full (const FCurve *fcu, const short from_single, const short to_simple, bool flip)
 
static tAnimCopybufItempastebuf_match_path_property (Main *bmain, const FCurve *fcu, const short from_single, const short)
 
static tAnimCopybufItempastebuf_match_index_only (const FCurve *fcu, const short from_single, const short)
 
static void do_curve_mirror_flippping (tAnimCopybufItem *aci, BezTriple *bezt)
 
static void paste_animedit_keys_fcurve (FCurve *fcu, tAnimCopybufItem *aci, float offset[2], const eKeyMergeMode merge_mode, bool flip)
 
static float paste_get_y_offset (bAnimContext *ac, tAnimCopybufItem *aci, bAnimListElem *ale, const eKeyPasteValueOffset value_offset_mode)
 
eKeyPasteError paste_animedit_keys (bAnimContext *ac, ListBase *anim_data, const eKeyPasteOffset offset_mode, const eKeyPasteValueOffset value_offset_mode, const eKeyMergeMode merge_mode, bool flip)
 

Function Documentation

◆ ANIM_fcurves_copybuf_free()

◆ blend_offset_fcurve_segment()

void blend_offset_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
float factor )

Shift the FCurve segment up/down so that it aligns with the key before/after the segment.

Parameters
factorblend factor from -1.0 to 1.0. The sign determines whether the segment is aligned with the key before or after the segment.

Definition at line 706 of file keyframes_general.cc.

References FCurve::bezt, BKE_fcurve_keyframe_move_value_with_handles(), fabs(), fcurve_segment_end_get(), fcurve_segment_start_get(), and BezTriple::vec.

Referenced by blend_offset_graph_keys().

◆ blend_to_default_fcurve()

void blend_to_default_fcurve ( PointerRNA * id_ptr,
FCurve * fcu,
float factor )

Blends the selected keyframes to the default value of the property the F-curve drives.

Definition at line 374 of file keyframes_general.cc.

References FCurve::bezt, BKE_fcurve_keyframe_move_value_with_handles(), BezTriple::f2, get_default_rna_value(), interpf(), ptr, FCurve::rna_path, RNA_path_resolve_property(), SELECT, FCurve::totvert, and BezTriple::vec.

Referenced by blend_to_default_graph_keys().

◆ blend_to_ease_fcurve_segment()

void blend_to_ease_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor )

◆ blend_to_neighbor_fcurve_segment()

void blend_to_neighbor_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor )

◆ breakdown_fcurve_segment()

void breakdown_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor )

◆ butterworth_calculate_blend_value()

static float butterworth_calculate_blend_value ( float * samples,
float * filtered_values,
const int start_index,
const int end_index,
const int sample_index,
const int blend_in_out )
static

Definition at line 472 of file keyframes_general.cc.

References clamp_f(), and interpf().

Referenced by butterworth_smooth_fcurve_segment().

◆ butterworth_filter_value()

static double butterworth_filter_value ( double x,
double * w0,
double * w1,
double * w2,
ButterworthCoefficients * bw_coeff )
static

◆ butterworth_smooth_fcurve_segment()

void butterworth_smooth_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
float * samples,
int sample_count,
float factor,
int blend_in_out,
int sample_rate,
ButterworthCoefficients * bw_coeff )
Parameters
samplesAre expected to start at the first frame of the segment with a buffer of size segment->filter_order at the left.

Definition at line 517 of file keyframes_general.cc.

References FCurve::bezt, BKE_fcurve_keyframe_move_value_with_handles(), butterworth_calculate_blend_value(), butterworth_filter_value(), double(), ButterworthCoefficients::filter_order, float, int, interpf(), MEM_callocN, MEM_freeN(), min_ff(), min_ii(), and BezTriple::vec.

Referenced by btw_smooth_graph_keys(), and btw_smooth_modal_update().

◆ clean_fcurve()

◆ copy_animedit_keys()

◆ decimate_fcurve()

◆ decimate_fcurve_segment()

static void decimate_fcurve_segment ( FCurve * fcu,
int bezt_segment_start_idx,
int bezt_segment_len,
float remove_ratio,
float error_sq_max )
static

◆ do_curve_mirror_flippping()

static void do_curve_mirror_flippping ( tAnimCopybufItem * aci,
BezTriple * bezt )
static

◆ duplicate_fcurve_keys()

bool duplicate_fcurve_keys ( FCurve * fcu)

◆ ease_fcurve_segment()

void ease_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
float factor,
float width )

Snap the keys on the given FCurve segment to an S-Curve. By modifying the factor the part of the S-Curve that the keys are snapped to is moved on the x-axis.

Definition at line 669 of file keyframes_general.cc.

References FCurve::bezt, BKE_fcurve_keyframe_move_value_with_handles(), blend, ease_sigmoid_function(), fcurve_segment_end_get(), fcurve_segment_start_get(), IS_EQF, and BezTriple::vec.

Referenced by ease_graph_keys().

◆ ease_sigmoid_function()

static float ease_sigmoid_function ( const float x,
const float width,
const float shift )
static

Definition at line 661 of file keyframes_general.cc.

References pow2f(), and sqrt().

Referenced by ease_fcurve_segment().

◆ ED_anim_allocate_butterworth_coefficients()

◆ ED_anim_calculate_butterworth_coefficients()

void ED_anim_calculate_butterworth_coefficients ( const float cutoff_frequency,
const float sampling_frequency,
ButterworthCoefficients * bw_coeff )

◆ ED_anim_free_butterworth_coefficients()

void ED_anim_free_butterworth_coefficients ( ButterworthCoefficients * bw_coeff)

◆ ED_ANIM_get_1d_gauss_kernel()

void ED_ANIM_get_1d_gauss_kernel ( const float sigma,
int kernel_size,
double * r_kernel )

Get a 1D gauss kernel. Since the kernel is symmetrical, only calculates the positive side.

Parameters
sigmaThe shape of the gauss distribution.
kernel_sizeHow long the kernel array is.

Definition at line 609 of file keyframes_general.cc.

References BLI_assert, double(), exp(), and sum().

Referenced by gaussian_smooth_allocate_operator_data(), and gaussian_smooth_exec().

◆ fcurve_segment_end_get()

◆ fcurve_segment_start_get()

◆ find_fcurve_segment()

static bool find_fcurve_segment ( FCurve * fcu,
const int start_index,
int * r_segment_start_idx,
int * r_segment_len )
static

Find the first segment of consecutive selected curve points, starting from start_index. Keys that have BEZT_FLAG_IGNORE_TAG set are treated as unselected.

Parameters
r_segment_start_idxreturns the start index of the segment.
r_segment_lenreturns the number of curve points in the segment.
Returns
whether such a segment was found or not.

Definition at line 245 of file keyframes_general.cc.

References FCurve::bezt, BEZT_FLAG_IGNORE_TAG, BezTriple::f2, point_is_selected(), SELECT, and FCurve::totvert.

Referenced by find_fcurve_segments().

◆ find_fcurve_segments()

ListBase find_fcurve_segments ( FCurve * fcu)

Return a list of FCurveSegment with a start index and a length. A segment is a continuous selection of keyframes. Keys that have BEZT_FLAG_IGNORE_TAG set are treated as unselected. The caller is responsible for freeing the memory.

Definition at line 278 of file keyframes_general.cc.

References FCurve::bezt, BLI_addtail(), find_fcurve_segment(), MEM_callocN, and FCurveSegment::start_index.

Referenced by apply_fcu_segment_function(), btw_smooth_allocate_operator_data(), btw_smooth_graph_keys(), decimate_fcurve(), ease_graph_keys(), gaussian_smooth_allocate_operator_data(), gaussian_smooth_graph_keys(), match_slope_graph_keys(), scale_from_neighbor_graph_keys(), and shear_graph_keys().

◆ flip_names()

◆ get_default_rna_value()

◆ match_slope_fcurve_segment()

bool match_slope_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor )

◆ paste_animedit_keys()

◆ paste_animedit_keys_fcurve()

◆ paste_get_y_offset()

◆ pastebuf_match_index_only()

static tAnimCopybufItem * pastebuf_match_index_only ( const FCurve * fcu,
const short from_single,
const short  )
static

◆ pastebuf_match_path_full()

static tAnimCopybufItem * pastebuf_match_path_full ( const FCurve * fcu,
const short from_single,
const short to_simple,
bool flip )
static

◆ pastebuf_match_path_property()

◆ prepare_for_decimate()

◆ push_pull_fcurve_segment()

void push_pull_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor )

◆ s_curve()

static float s_curve ( float x,
float slope,
float width,
float height,
float xshift,
float yshift )
static

Definition at line 731 of file keyframes_general.cc.

References pow(), and y.

Referenced by blend_to_ease_fcurve_segment().

◆ scale_average_fcurve_segment()

void scale_average_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor )

◆ scale_from_fcurve_segment_neighbor()

void scale_from_fcurve_segment_neighbor ( FCurve * fcu,
FCurveSegment * segment,
const float factor,
const FCurveSegmentAnchor anchor )

◆ shear_fcurve_segment()

void shear_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float factor,
tShearDirection direction )

◆ smooth_fcurve()

void smooth_fcurve ( FCurve * fcu)

◆ smooth_fcurve_segment()

void smooth_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
float * samples,
const float factor,
const int kernel_size,
double * kernel )

◆ time_offset_fcurve_segment()

void time_offset_fcurve_segment ( FCurve * fcu,
FCurveSegment * segment,
const float frame_offset )

Variable Documentation

◆ animcopy_cfra

float animcopy_cfra = 0.0
static

Definition at line 1241 of file keyframes_general.cc.

Referenced by copy_animedit_keys(), and paste_animedit_keys().

◆ animcopy_firstframe

float animcopy_firstframe = 999999999.0f
static

◆ animcopy_lastframe

float animcopy_lastframe = -999999999.0f
static

◆ animcopybuf

◆ rna_enum_keyframe_paste_merge_items

const EnumPropertyItem rna_enum_keyframe_paste_merge_items[]
Initial value:
= {
{KEYFRAME_PASTE_MERGE_MIX, "MIX", 0, "Mix", "Overlay existing with new keys"},
{KEYFRAME_PASTE_MERGE_OVER, "OVER_ALL", 0, "Overwrite All", "Replace all keys"},
"OVER_RANGE",
0,
"Overwrite Range",
"Overwrite keys in pasted range"},
"OVER_RANGE_ALL",
0,
"Overwrite Entire Range",
"Overwrite keys in pasted range, using the range of all copied keys"},
{0, nullptr, 0, nullptr, nullptr},
}
@ KEYFRAME_PASTE_MERGE_OVER_RANGE_ALL
@ KEYFRAME_PASTE_MERGE_OVER_RANGE
@ KEYFRAME_PASTE_MERGE_OVER
@ KEYFRAME_PASTE_MERGE_MIX

Definition at line 1699 of file keyframes_general.cc.

Referenced by ACTION_OT_paste(), and GRAPH_OT_paste().

◆ rna_enum_keyframe_paste_offset_items

const EnumPropertyItem rna_enum_keyframe_paste_offset_items[]
Initial value:
= {
"START",
0,
"Frame Start",
"Paste keys starting at current frame"},
{KEYFRAME_PASTE_OFFSET_CFRA_END, "END", 0, "Frame End", "Paste keys ending at current frame"},
"RELATIVE",
0,
"Frame Relative",
"Paste keys relative to the current frame when copying"},
{KEYFRAME_PASTE_OFFSET_NONE, "NONE", 0, "No Offset", "Paste keys from original time"},
{0, nullptr, 0, nullptr, nullptr},
}
@ KEYFRAME_PASTE_OFFSET_NONE
@ KEYFRAME_PASTE_OFFSET_CFRA_END
@ KEYFRAME_PASTE_OFFSET_CFRA_RELATIVE
@ KEYFRAME_PASTE_OFFSET_CFRA_START

Definition at line 1654 of file keyframes_general.cc.

Referenced by ACTION_OT_paste(), and GRAPH_OT_paste().

◆ rna_enum_keyframe_paste_offset_value_items

const EnumPropertyItem rna_enum_keyframe_paste_offset_value_items[]
Initial value:
= {
"LEFT_KEY",
0,
"Left Key",
"Paste keys with the first key matching the key left of the cursor"},
"RIGHT_KEY",
0,
"Right Key",
"Paste keys with the last key matching the key right of the cursor"},
"CURRENT_FRAME",
0,
"Current Frame Value",
"Paste keys relative to the value of the curve under the cursor"},
"CURSOR_VALUE",
0,
"Cursor Value",
"Paste keys relative to the Y-Position of the cursor"},
"NONE",
0,
"No Offset",
"Paste keys with the same value as they were copied"},
{0, nullptr, 0, nullptr, nullptr},
}
@ KEYFRAME_PASTE_VALUE_OFFSET_RIGHT_KEY
@ KEYFRAME_PASTE_VALUE_OFFSET_NONE
@ KEYFRAME_PASTE_VALUE_OFFSET_CURSOR
@ KEYFRAME_PASTE_VALUE_OFFSET_CFRA
@ KEYFRAME_PASTE_VALUE_OFFSET_LEFT_KEY

Definition at line 1670 of file keyframes_general.cc.

Referenced by GRAPH_OT_paste().