Blender V4.3
rna_fcurve_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdio>
10#include <cstdlib>
11#include <cstring>
12#include <ctime>
13
14#include "BLI_utildefines.h"
15
16#include "RNA_define.hh"
17
18#include "DNA_anim_types.h"
19#include "DNA_scene_types.h"
20
21#include "ANIM_fcurve.hh"
22
23#include "rna_internal.hh" /* own include */
24
25#ifdef RNA_RUNTIME
26
27# include <stddef.h>
28
29# include "BKE_fcurve.hh"
30
31static void rna_FCurve_convert_to_samples(FCurve *fcu, ReportList *reports, int start, int end)
32{
33 /* XXX fcurve_store_samples uses end frame included,
34 * which is not consistent with usual behavior in Blender,
35 * nor python slices, etc. Let have public py API be consistent here at least. */
36 end--;
37 if (start > end) {
38 BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end + 1);
39 }
40 else if (fcu->fpt) {
41 BKE_report(reports, RPT_WARNING, "F-Curve already has sample points");
42 }
43 else if (!fcu->bezt) {
44 BKE_report(reports, RPT_WARNING, "F-Curve has no keyframes");
45 }
46 else {
47 fcurve_store_samples(fcu, nullptr, start, end, fcurve_samplingcb_evalcurve);
49 }
50}
51
52static void rna_FCurve_convert_to_keyframes(FCurve *fcu, ReportList *reports, int start, int end)
53{
54 if (start >= end) {
55 BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end);
56 }
57 else if (fcu->bezt) {
58 BKE_report(reports, RPT_WARNING, "F-Curve already has keyframes");
59 }
60 else if (!fcu->fpt) {
61 BKE_report(reports, RPT_WARNING, "F-Curve has no sample points");
62 }
63 else {
64 fcurve_samples_to_keyframes(fcu, start, end);
66 }
67}
68
69static void rna_FCurve_bake(FCurve *fcu,
70 ReportList *reports,
71 int start_frame,
72 int end_frame,
73 float step,
74 int remove_existing_as_int)
75{
76 using namespace blender::animrig;
77 if (start_frame >= end_frame) {
78 BKE_reportf(reports,
80 "Invalid frame range (%d - %d). Start Frame is larger than End Frame",
81 start_frame,
82 end_frame);
83 return;
84 }
85
86 const BakeCurveRemove remove_existing = BakeCurveRemove(remove_existing_as_int);
87 bake_fcurve(fcu, {start_frame, end_frame}, step, remove_existing);
89}
90
91#else
92
94 {int(blender::animrig::BakeCurveRemove::NONE), "NONE", 0, "None", "Keep all keys"},
96 "IN_RANGE",
97 0,
98 "In Range",
99 "Remove all keys within the defined range"},
101 "OUT_RANGE",
102 0,
103 "Outside Range",
104 "Remove all keys outside the defined range"},
105 {int(blender::animrig::BakeCurveRemove::ALL), "ALL", 0, "All", "Remove all existing keys"},
106 {0, nullptr, 0, nullptr, nullptr},
107};
108
110{
111 FunctionRNA *func;
112 PropertyRNA *parm;
113
114 func = RNA_def_function(srna, "convert_to_samples", "rna_FCurve_convert_to_samples");
116 func, "Convert current FCurve from keyframes to sample points, if necessary");
118 parm = RNA_def_int(
119 func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
121 parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
123
124 func = RNA_def_function(srna, "convert_to_keyframes", "rna_FCurve_convert_to_keyframes");
126 func,
127 "Convert current FCurve from sample points to keyframes (linear interpolation), "
128 "if necessary");
130 parm = RNA_def_int(
131 func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
133 parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
135
136 func = RNA_def_function(srna, "bake", "rna_FCurve_bake");
137 RNA_def_function_ui_description(func, "Place keys at even intervals on the existing curve.");
139 parm = RNA_def_int(func,
140 "start",
141 0,
142 MINAFRAME,
143 MAXFRAME,
144 "Start Frame",
145 "Frame at which to start baking",
146 MINAFRAME,
147 MAXFRAME);
149 parm = RNA_def_int(func,
150 "end",
151 0,
152 MINAFRAME,
153 MAXFRAME,
154 "End Frame",
155 "Frame at which to end baking (inclusive)",
156 MINAFRAME,
157 MAXFRAME);
159 parm = RNA_def_float(
160 func, "step", 1, 0.01, FLT_MAX, "Step", "At which interval to add keys", 1, 16);
162 RNA_def_enum(func,
163 "remove",
166 "Remove Options",
167 "Choose which keys should be automatically removed by the bake");
169}
170
172{
173 // FunctionRNA *func;
174 // PropertyRNA *parm;
175}
176
177#endif
Functions to modify FCurves.
void fcurve_samples_to_keyframes(FCurve *fcu, int start, int end)
void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
#define MINAFRAME
#define MAXFRAME
@ PARM_PYFUNC_OPTIONAL
Definition RNA_types.hh:407
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
PropertyFlag
Definition RNA_types.hh:201
#define NC_ANIMATION
Definition WM_types.hh:355
#define NA_EDITED
Definition WM_types.hh:550
#define ND_ANIMCHAN
Definition WM_types.hh:463
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void bake_fcurve(FCurve *fcu, blender::int2 range, float step, BakeCurveRemove remove_existing)
T step(const T &edge, const T &value)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_function_flag(FunctionRNA *func, int flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_api_fcurves(StructRNA *srna)
void RNA_api_drivers(StructRNA *)
static const EnumPropertyItem channel_bake_remove_options[]
#define FLT_MAX
Definition stdcycles.h:14
FPoint * fpt
BezTriple * bezt
void WM_main_add_notifier(uint type, void *reference)