Blender V5.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
8
9#include <cstdlib>
10#include <cstring>
11#include <ctime>
12
13#include "RNA_define.hh"
14
15#include "DNA_scene_types.h"
16
17#include "ANIM_fcurve.hh"
18
19#include "rna_internal.hh" /* own include */
20
21#ifdef RNA_RUNTIME
22
23# include <cstddef>
24
25# include "BKE_fcurve.hh"
26# include "BKE_report.hh"
27
28# include "WM_api.hh"
29
30namespace blender {
31
32static void rna_FCurve_convert_to_samples(FCurve *fcu, ReportList *reports, int start, int end)
33{
34 /* XXX fcurve_store_samples uses end frame included,
35 * which is not consistent with usual behavior in Blender,
36 * nor python slices, etc. Let have public py API be consistent here at least. */
37 end--;
38 if (start > end) {
39 BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end + 1);
40 }
41 else if (fcu->fpt) {
42 BKE_report(reports, RPT_WARNING, "F-Curve already has sample points");
43 }
44 else if (!fcu->bezt) {
45 BKE_report(reports, RPT_WARNING, "F-Curve has no keyframes");
46 }
47 else {
48 fcurve_store_samples(fcu, nullptr, start, end, fcurve_samplingcb_evalcurve);
50 }
51}
52
53static void rna_FCurve_convert_to_keyframes(FCurve *fcu, ReportList *reports, int start, int end)
54{
55 if (start >= end) {
56 BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end);
57 }
58 else if (fcu->bezt) {
59 BKE_report(reports, RPT_WARNING, "F-Curve already has keyframes");
60 }
61 else if (!fcu->fpt) {
62 BKE_report(reports, RPT_WARNING, "F-Curve has no sample points");
63 }
64 else {
65 fcurve_samples_to_keyframes(fcu, start, end);
67 }
68}
69
70static void rna_FCurve_bake(FCurve *fcu,
71 ReportList *reports,
72 int start_frame,
73 int end_frame,
74 float step,
75 int remove_existing_as_int)
76{
77 using namespace animrig;
78 if (start_frame >= end_frame) {
79 BKE_reportf(reports,
81 "Invalid frame range (%d - %d). Start Frame is larger than End Frame",
82 start_frame,
83 end_frame);
84 return;
85 }
86
87 const BakeCurveRemove remove_existing = BakeCurveRemove(remove_existing_as_int);
88 bake_fcurve(fcu, {start_frame, end_frame}, step, remove_existing);
90}
91
92} // namespace blender
93
94#else
95
96namespace blender {
97
99 {int(animrig::BakeCurveRemove::NONE), "NONE", 0, "None", "Keep all keys"},
101 "IN_RANGE",
102 0,
103 "In Range",
104 "Remove all keys within the defined range"},
106 "OUT_RANGE",
107 0,
108 "Outside Range",
109 "Remove all keys outside the defined range"},
110 {int(animrig::BakeCurveRemove::ALL), "ALL", 0, "All", "Remove all existing keys"},
111 {0, nullptr, 0, nullptr, nullptr},
112};
113
115{
116 FunctionRNA *func;
117 PropertyRNA *parm;
118
119 func = RNA_def_function(srna, "convert_to_samples", "rna_FCurve_convert_to_samples");
121 func, "Convert current FCurve from keyframes to sample points, if necessary");
123 parm = RNA_def_int(
124 func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
126 parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
128
129 func = RNA_def_function(srna, "convert_to_keyframes", "rna_FCurve_convert_to_keyframes");
131 func,
132 "Convert current FCurve from sample points to keyframes (linear interpolation), "
133 "if necessary");
135 parm = RNA_def_int(
136 func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
138 parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
140
141 func = RNA_def_function(srna, "bake", "rna_FCurve_bake");
142 RNA_def_function_ui_description(func, "Place keys at even intervals on the existing curve.");
144 parm = RNA_def_int(func,
145 "start",
146 0,
147 MINAFRAME,
148 MAXFRAME,
149 "Start Frame",
150 "Frame at which to start baking",
151 MINAFRAME,
152 MAXFRAME);
154 parm = RNA_def_int(func,
155 "end",
156 0,
157 MINAFRAME,
158 MAXFRAME,
159 "End Frame",
160 "Frame at which to end baking (inclusive)",
161 MINAFRAME,
162 MAXFRAME);
164 parm = RNA_def_float(
165 func, "step", 1, 0.01, FLT_MAX, "Step", "At which interval to add keys", 1, 16);
166 RNA_def_enum(func,
167 "remove",
170 "Remove Options",
171 "Choose which keys should be automatically removed by the bake");
172}
173
175{
176 // FunctionRNA *func;
177 // PropertyRNA *parm;
178}
179
180} // namespace blender
181
182#endif
Functions to modify FCurves.
#define MINAFRAME
#define MAXFRAME
#define NC_ANIMATION
Definition WM_types.hh:401
#define NA_EDITED
Definition WM_types.hh:634
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define FLT_MAX
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void bake_fcurve(FCurve *fcu, int2 range, float step, BakeCurveRemove remove_existing)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
@ RPT_WARNING
Definition BKE_report.hh:40
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static const EnumPropertyItem channel_bake_remove_options[]
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
void RNA_api_fcurves(StructRNA *srna)
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 BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
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)
@ PARM_REQUIRED
Definition RNA_types.hh:631
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)
void RNA_api_drivers(StructRNA *)
void fcurve_samples_to_keyframes(FCurve *fcu, int start, int end)