Blender V5.3
BKE_fcurve.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
12#include "BLI_span.hh"
13#include "BLI_string_ref.hh"
14
15#include "DNA_curve_types.h"
16#include "DNA_listBase.h"
17
18#include "RNA_path.hh"
19
20namespace blender {
21
22struct ChannelDriver;
23struct FCM_EnvelopeData;
24struct FCurve;
25struct FModifier;
26struct FCurvePathCache;
27
28struct AnimData;
30struct BezTriple;
31struct BlendDataReader;
32struct BlendWriter;
34struct PathResolvedRNA;
35struct PointerRNA;
36struct PropertyRNA;
37struct StructRNA;
38struct bAction;
39struct bContext;
40
41namespace bke {
42
45 float curval = 0;
46
48 std::optional<ParsedRNAPath<>> parsed_rna_path;
49};
50
51} // namespace bke
52
53/* ************** F-Curve Modifiers *************** */
54
67 /* Admin/identity. */
69 short type;
71 short size;
73 short acttype;
77 char name[64];
79 char struct_name[64];
82
83 /* data management function pointers - special handling */
85 void (*free_data)(FModifier *fcm);
87 void (*copy_data)(FModifier *fcm, const FModifier *src);
92 void (*new_data)(void *mdata);
94 void (*verify_data)(FModifier *fcm);
95
96 /* evaluation */
99 const FCurve *fcu, const FModifier *fcm, float cvalue, float evaltime, void *storage);
102 const FCurve *fcu, const FModifier *fcm, float *cvalue, float evaltime, void *storage);
103};
104
105/* Values which describe the behavior of a FModifier Type */
107 /* modifier only modifies values outside of data range */
109 /* modifier leaves data-points alone, but adjusts the interpolation between and around them */
111 /* modifier only modifies the values of points (but times stay the same) */
113 /* modifier generates a curve regardless of what came before */
115};
116
117/* Flags for the requirements of a FModifier Type */
119 /* modifier requires original data-points (kind of beats the purpose of a modifier stack?) */
121 /* modifier doesn't require on any preceding data (i.e. it will generate a curve).
122 * Use in conjunction with FMI_TYPE_GENRATE_CURVE
123 */
125 /* refer to modifier instance */
127};
128
129/* Function Prototypes for FModifierTypeInfo's */
130
135const FModifierTypeInfo *fmodifier_get_typeinfo(const FModifier *fcm);
140const FModifierTypeInfo *get_fmodifier_typeinfo(int type);
141
142/* ---------------------- */
143
147FModifier *add_fmodifier(ListBaseT<FModifier> *modifiers, int type, FCurve *owner_fcu);
151FModifier *copy_fmodifier(const FModifier *src);
155void copy_fmodifiers(ListBaseT<FModifier> *dst, const ListBaseT<FModifier> *src);
159bool remove_fmodifier(ListBaseT<FModifier> *modifiers, FModifier *fcm);
163void free_fmodifiers(ListBaseT<FModifier> *modifiers);
164
168FModifier *find_active_fmodifier(ListBaseT<FModifier> *modifiers);
172void set_active_fmodifier(ListBaseT<FModifier> *modifiers, FModifier *fcm);
173
180bool list_has_suitable_fmodifier(const ListBaseT<FModifier> *modifiers, int mtype, short acttype);
181
187
188uint evaluate_fmodifiers_storage_size_per_modifier(const ListBaseT<FModifier> *modifiers);
203 const ListBaseT<FModifier> *modifiers,
204 const FCurve *fcu,
205 float cvalue,
206 float evaltime);
212 const ListBaseT<FModifier> *modifiers,
213 const FCurve *fcu,
214 float *cvalue,
215 float evaltime);
216
221void fcurve_bake_modifiers(FCurve *fcu, int start, int end);
222
224 float frame,
225 int arraylen,
226 bool *r_exists);
227
228/* ************** F-Curves API ******************** */
229
230/* threshold for binary-searching keyframes - threshold here should be good enough for now,
231 * but should become userpref */
232#define BEZT_BINARYSEARCH_THRESH 0.01f /* was 0.00001, but giving errors */
233
234/* -------- Data Management -------- */
235FCurve *BKE_fcurve_create();
239void BKE_fcurve_free(FCurve *fcu);
243FCurve *BKE_fcurve_copy(const FCurve *fcu);
247void BKE_fcurves_free(ListBaseT<FCurve> *list);
251void BKE_fcurves_copy(ListBaseT<FCurve> *dst, ListBaseT<FCurve> *src);
252
253/* Set fcurve modifier name and ensure uniqueness.
254 * Pass new name string when it's been edited otherwise pass empty string. */
255void BKE_fmodifier_name_set(FModifier *fcm, const char *name);
256
260void BKE_fmodifier_ensure_flag(ListBaseT<FModifier> *modifiers);
268void BKE_fcurve_foreach_id(FCurve *fcu, LibraryForeachIDData *data);
269
280FCurve *BKE_fcurve_find(ListBaseT<FCurve> *list, const char rna_path[], int array_index);
281
285FCurve *BKE_fcurve_iter_step(FCurve *fcu_iter, const char rna_path[]);
286
302FCurve *id_data_find_fcurve(
303 ID *id, void *data, StructRNA *type, const char *prop_name, int index, bool *r_driven);
304
323FCurve *BKE_animadata_fcurve_find_by_rna_path(AnimData *animdata,
324 const char *rna_path,
325 const int rna_index,
326 bAction **r_action,
327 bool *r_driven);
328
332FCurve *BKE_fcurve_find_by_rna(PointerRNA *ptr,
333 PropertyRNA *prop,
334 int rnaindex,
335 AnimData **r_adt,
336 bAction **r_action,
337 bool *r_driven,
338 bool *r_special);
346FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *C,
347 const PointerRNA *ptr,
348 PropertyRNA *prop,
349 int rnaindex,
350 AnimData **r_animdata,
351 bAction **r_action,
352 bool *r_driven,
353 bool *r_special);
354
359int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[],
360 float frame,
361 int arraylen,
362 bool *r_replace);
363
368bool BKE_fcurve_calc_range(const FCurve *fcu, float *r_min, float *r_max, bool selected_keys_only);
369
381bool BKE_fcurve_calc_bounds(const FCurve *fcu,
382 bool selected_keys_only,
383 bool include_handles,
384 const float frame_range[2],
385 rctf *r_bounds);
386
397
402void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt);
407
412void BKE_fcurve_keyframe_move_time_with_handles(BezTriple *keyframe, const float new_time);
413void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value);
414
415/* .............. */
416
423
428bool BKE_fcurve_is_keyframable(const FCurve &fcu);
429bool BKE_fcurve_is_protected(const FCurve &fcu);
430
435
440
445bool BKE_fcurve_is_cyclic(const FCurve &fcu);
446
447/* Type of infinite cycle for a curve. */
450 /* The cycle repeats identically to the base range. */
452 /* The cycle accumulates the change between start and end keys. */
454};
455
460
469bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt,
470 BezTriple *prev,
471 BezTriple *next,
472 float *r_pdelta);
473
485void BKE_fcurve_bezt_resize(FCurve &fcu, int new_totvert);
486
496BezTriple *BKE_bezier_array_merge(
497 const BezTriple *a, int size_a, const BezTriple *b, int size_b, int *r_merged_size);
498
502void BKE_fcurve_delete_key(FCurve *fcu, int index);
503
511void BKE_fcurve_delete_keys(FCurve &fcu, uint2 index_range);
512
516bool BKE_fcurve_delete_keys_selected(FCurve &fcu);
517
521void BKE_fcurve_delete_keys_all(FCurve &fcu);
522
531void BKE_fcurve_merge_duplicate_keys(FCurve *fcu, const int sel_flag, const bool use_handle);
532
546void BKE_fcurve_deduplicate_keys(FCurve *fcu);
547
548/* -------- Curve Sanity -------- */
549
556void BKE_fcurve_handles_recalc(FCurve &fcu);
565void BKE_fcurve_handles_recalc_ex(FCurve &fcu, eBezTriple_Flag handle_sel_flag);
566
567enum class HandleSide {
568 LEFT,
569 RIGHT,
570};
571
581void BKE_fcurve_update_handle_flag_from_opposite(BezTriple &key, HandleSide source_side);
582
593void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, bool use_handle);
598void sort_time_fcurve(FCurve &fcu);
602bool test_time_fcurve(FCurve &fcu);
603
612void BKE_fcurve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2]);
613
614/* -------- Evaluation -------- */
615
619float evaluate_fcurve(const FCurve *fcu, float evaltime);
624float evaluate_fcurve_only_curve(const FCurve *fcu, float evaltime);
628float evaluate_fcurve_unmodified(const FCurve *fcu, float evaltime);
629float evaluate_fcurve_driver(PathResolvedRNA *anim_rna,
630 FCurve *fcu,
631 ChannelDriver *driver_orig,
632 const AnimationEvalContext *anim_eval_context);
636bool BKE_fcurve_is_empty(const FCurve *fcu);
641float calculate_fcurve(PathResolvedRNA *anim_rna,
642 FCurve *fcu,
643 const AnimationEvalContext *anim_eval_context);
644
645/* ************* F-Curve Samples API ******************** */
646
647/* -------- Defines -------- */
648
655typedef float (*FcuSampleFunc)(FCurve *fcu, void *data, float evaltime);
656
657/* ----- Sampling Callbacks ------ */
658
663float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime);
664
665/* -------- Main Methods -------- */
666
671void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb);
672
676void fcurve_samples_to_keyframes(FCurve *fcu, int start, int end);
677
678/* ************* F-Curve .blend file API ******************** */
679
680void BKE_fmodifiers_blend_write(BlendWriter *writer, ListBaseT<FModifier> *fmodifiers);
682 ListBaseT<FModifier> *fmodifiers,
683 FCurve *curve);
684
691void BKE_fcurve_blend_write_listbase(BlendWriter *writer, ListBaseT<FCurve> *fcurves);
693void BKE_fcurve_blend_read_data_listbase(BlendDataReader *reader, ListBaseT<FCurve> *fcurves);
694
695} // namespace blender
These structs are the foundation for all linked lists in the library system.
#define C
Definition RandGen.cpp:29
#define storage(slot, qualifiers)
#define index(i)
BMesh Iterators.
bool BKE_fcurve_calc_range(const FCurve *fcu, float *r_min, float *r_max, bool selected_keys_only)
void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value)
@ FMI_TYPE_GENERATE_CURVE
@ FMI_TYPE_EXTRAPOLATION
@ FMI_TYPE_REPLACE_VALUES
@ FMI_TYPE_INTERPOLATION
bool BKE_fcurve_delete_keys_selected(FCurve &fcu)
void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, bool use_handle)
BezTriple * BKE_bezier_array_merge(const BezTriple *a, int size_a, const BezTriple *b, int size_b, int *r_merged_size)
unsigned int uint
Definition BKE_text.h:55
float(*) FcuSampleFunc(FCurve *fcu, void *data, float evaltime)
float calculate_fcurve(PathResolvedRNA *anim_rna, FCurve *fcu, const AnimationEvalContext *anim_eval_context)
FCurve * BKE_fcurve_iter_step(FCurve *fcu_iter, const char rna_path[])
bool BKE_fcurve_is_keyframable(const FCurve &fcu)
void BKE_fcurves_free(ListBaseT< FCurve > *list)
uint evaluate_fmodifiers_storage_size_per_modifier(const ListBaseT< FModifier > *modifiers)
void BKE_fcurve_delete_keys(FCurve &fcu, uint2 index_range)
void BKE_fcurve_update_handle_flag_from_opposite(BezTriple &key, HandleSide source_side)
@ FCU_CYCLE_OFFSET
@ FCU_CYCLE_NONE
@ FCU_CYCLE_PERFECT
void BKE_fmodifier_ensure_flag(ListBaseT< FModifier > *modifiers)
void BKE_fmodifier_name_set(FModifier *fcm, const char *name)
void copy_fmodifiers(ListBaseT< FModifier > *dst, const ListBaseT< FModifier > *src)
bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt, BezTriple *prev, BezTriple *next, float *r_pdelta)
void BKE_fcurve_delete_key(FCurve *fcu, int index)
FCurve * BKE_fcurve_find_by_rna(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, AnimData **r_adt, bAction **r_action, bool *r_driven, bool *r_special)
void BKE_fcurve_handles_recalc_ex(FCurve &fcu, eBezTriple_Flag handle_sel_flag)
void BKE_fcurve_blend_read_data_listbase(BlendDataReader *reader, ListBaseT< FCurve > *fcurves)
void BKE_fcurve_foreach_id(FCurve *fcu, LibraryForeachIDData *data)
const FModifierTypeInfo * fmodifier_get_typeinfo(const FModifier *fcm)
FModifier * add_fmodifier(ListBaseT< FModifier > *modifiers, int type, FCurve *owner_fcu)
float evaluate_fcurve_unmodified(const FCurve *fcu, float evaltime)
void BKE_fcurve_blend_write_data(BlendWriter *writer, FCurve *fcu)
void BKE_fcurve_blend_read_data(BlendDataReader *reader, FCurve *fcu)
void BKE_fcurve_blend_write_listbase(BlendWriter *writer, ListBaseT< FCurve > *fcurves)
bool list_has_suitable_fmodifier(const ListBaseT< FModifier > *modifiers, int mtype, short acttype)
bool remove_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
void BKE_fmodifiers_blend_write(BlendWriter *writer, ListBaseT< FModifier > *fmodifiers)
void BKE_fcurve_merge_duplicate_keys(FCurve *fcu, const int sel_flag, const bool use_handle)
void BKE_fcurve_keyframe_move_time_with_handles(BezTriple *keyframe, const float new_time)
bool BKE_fcurve_is_protected(const FCurve &fcu)
void BKE_fcurves_copy(ListBaseT< FCurve > *dst, ListBaseT< FCurve > *src)
void evaluate_value_fmodifiers(FModifiersStackStorage *storage, const ListBaseT< FModifier > *modifiers, const FCurve *fcu, float *cvalue, float evaltime)
void BKE_fcurve_handles_recalc(FCurve &fcu)
bool BKE_fcurve_calc_bounds(const FCurve *fcu, bool selected_keys_only, bool include_handles, const float frame_range[2], rctf *r_bounds)
BMesh const char void * data
void BKE_fcurve_deselect_all_keys(FCurve &fcu)
FCurve * BKE_animadata_fcurve_find_by_rna_path(AnimData *animdata, const char *rna_path, const int rna_index, bAction **r_action, bool *r_driven)
FCurve * BKE_fcurve_copy(const FCurve *fcu)
FModifier * find_active_fmodifier(ListBaseT< FModifier > *modifiers)
eFCU_Cycle_Type BKE_fcurve_get_cycle_type(const FCurve &fcu)
float evaluate_fcurve_driver(PathResolvedRNA *anim_rna, FCurve *fcu, ChannelDriver *driver_orig, const AnimationEvalContext *anim_eval_context)
void free_fmodifiers(ListBaseT< FModifier > *modifiers)
bool BKE_fcurve_is_cyclic(const FCurve &fcu)
void BKE_fcurve_free(FCurve *fcu)
void BKE_fcurve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2])
Array< float > BKE_fcurves_calc_keyed_frames_ex(Span< FCurve * > fcurve_array, float interval)
float evaluate_fcurve_only_curve(const FCurve *fcu, float evaltime)
void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt)
int BKE_fcurve_active_keyframe_index(const FCurve *fcu)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void fcurve_bake_modifiers(FCurve *fcu, int start, int end)
FModifier * copy_fmodifier(const FModifier *src)
Array< float > BKE_fcurves_calc_keyed_frames(Span< FCurve * > fcurve_array)
bool BKE_fcurve_are_keyframes_usable(const FCurve &fcu)
int BKE_fcm_envelope_find_index(FCM_EnvelopeData *array, float frame, int arraylen, bool *r_exists)
FCurve * id_data_find_fcurve(ID *id, void *data, StructRNA *type, const char *prop_name, int index, bool *r_driven)
void BKE_fmodifiers_blend_read_data(BlendDataReader *reader, ListBaseT< FModifier > *fmodifiers, FCurve *curve)
void BKE_fcurve_delete_keys_all(FCurve &fcu)
bool test_time_fcurve(FCurve &fcu)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
void BKE_fcurve_bezt_resize(FCurve &fcu, int new_totvert)
bool BKE_fcurve_is_empty(const FCurve *fcu)
void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
void BKE_fcurve_deduplicate_keys(FCurve *fcu)
FCurve * BKE_fcurve_find_by_rna_context_ui(bContext *C, const PointerRNA *ptr, PropertyRNA *prop, int rnaindex, AnimData **r_animdata, bAction **r_action, bool *r_driven, bool *r_special)
FCurve * BKE_fcurve_find(ListBaseT< FCurve > *list, const char rna_path[], int array_index)
float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime)
bool BKE_fcurve_has_selected_control_points(const FCurve &fcu)
void set_active_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
eFMI_Requirement_Flags
@ FMI_REQUIRES_ORIGINAL_DATA
@ FMI_REQUIRES_NOTHING
@ FMI_REQUIRES_RUNTIME_CHECK
const FModifierTypeInfo * get_fmodifier_typeinfo(int type)
float evaluate_time_fmodifiers(FModifiersStackStorage *storage, const ListBaseT< FModifier > *modifiers, const FCurve *fcu, float cvalue, float evaltime)
void fcurve_samples_to_keyframes(FCurve *fcu, int start, int end)
FCurve * BKE_fcurve_create()
void sort_time_fcurve(FCurve &fcu)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void(*) free_data(FModifier *fcm)
Definition BKE_fcurve.hh:85
float(*) evaluate_modifier_time(const FCurve *fcu, const FModifier *fcm, float cvalue, float evaltime, void *storage)
Definition BKE_fcurve.hh:98
void(*) evaluate_modifier(const FCurve *fcu, const FModifier *fcm, float *cvalue, float evaltime, void *storage)
void(*) new_data(void *mdata)
Definition BKE_fcurve.hh:92
void(*) copy_data(FModifier *fcm, const FModifier *src)
Definition BKE_fcurve.hh:87
void(*) verify_data(FModifier *fcm)
Definition BKE_fcurve.hh:94
std::optional< ParsedRNAPath<> > parsed_rna_path
Definition BKE_fcurve.hh:48