Blender V5.0
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
30static void rna_FCurve_convert_to_samples(FCurve *fcu, ReportList *reports, int start, int end)
31{
32 /* XXX fcurve_store_samples uses end frame included,
33 * which is not consistent with usual behavior in Blender,
34 * nor python slices, etc. Let have public py API be consistent here at least. */
35 end--;
36 if (start > end) {
37 BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end + 1);
38 }
39 else if (fcu->fpt) {
40 BKE_report(reports, RPT_WARNING, "F-Curve already has sample points");
41 }
42 else if (!fcu->bezt) {
43 BKE_report(reports, RPT_WARNING, "F-Curve has no keyframes");
44 }
45 else {
46 fcurve_store_samples(fcu, nullptr, start, end, fcurve_samplingcb_evalcurve);
48 }
49}
50
51static void rna_FCurve_convert_to_keyframes(FCurve *fcu, ReportList *reports, int start, int end)
52{
53 if (start >= end) {
54 BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end);
55 }
56 else if (fcu->bezt) {
57 BKE_report(reports, RPT_WARNING, "F-Curve already has keyframes");
58 }
59 else if (!fcu->fpt) {
60 BKE_report(reports, RPT_WARNING, "F-Curve has no sample points");
61 }
62 else {
63 fcurve_samples_to_keyframes(fcu, start, end);
65 }
66}
67
68static void rna_FCurve_bake(FCurve *fcu,
69 ReportList *reports,
70 int start_frame,
71 int end_frame,
72 float step,
73 int remove_existing_as_int)
74{
75 using namespace blender::animrig;
76 if (start_frame >= end_frame) {
77 BKE_reportf(reports,
79 "Invalid frame range (%d - %d). Start Frame is larger than End Frame",
80 start_frame,
81 end_frame);
82 return;
83 }
84
85 const BakeCurveRemove remove_existing = BakeCurveRemove(remove_existing_as_int);
86 bake_fcurve(fcu, {start_frame, end_frame}, step, remove_existing);
88}
89
90#else
91
93 {int(blender::animrig::BakeCurveRemove::NONE), "NONE", 0, "None", "Keep all keys"},
95 "IN_RANGE",
96 0,
97 "In Range",
98 "Remove all keys within the defined range"},
100 "OUT_RANGE",
101 0,
102 "Outside Range",
103 "Remove all keys outside the defined range"},
104 {int(blender::animrig::BakeCurveRemove::ALL), "ALL", 0, "All", "Remove all existing keys"},
105 {0, nullptr, 0, nullptr, nullptr},
106};
107
109{
110 FunctionRNA *func;
111 PropertyRNA *parm;
112
113 func = RNA_def_function(srna, "convert_to_samples", "rna_FCurve_convert_to_samples");
115 func, "Convert current FCurve from keyframes to sample points, if necessary");
117 parm = RNA_def_int(
118 func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
120 parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
122
123 func = RNA_def_function(srna, "convert_to_keyframes", "rna_FCurve_convert_to_keyframes");
125 func,
126 "Convert current FCurve from sample points to keyframes (linear interpolation), "
127 "if necessary");
129 parm = RNA_def_int(
130 func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
132 parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
134
135 func = RNA_def_function(srna, "bake", "rna_FCurve_bake");
136 RNA_def_function_ui_description(func, "Place keys at even intervals on the existing curve.");
138 parm = RNA_def_int(func,
139 "start",
140 0,
141 MINAFRAME,
142 MAXFRAME,
143 "Start Frame",
144 "Frame at which to start baking",
145 MINAFRAME,
146 MAXFRAME);
148 parm = RNA_def_int(func,
149 "end",
150 0,
151 MINAFRAME,
152 MAXFRAME,
153 "End Frame",
154 "Frame at which to end baking (inclusive)",
155 MINAFRAME,
156 MAXFRAME);
158 parm = RNA_def_float(
159 func, "step", 1, 0.01, FLT_MAX, "Step", "At which interval to add keys", 1, 16);
160 RNA_def_enum(func,
161 "remove",
164 "Remove Options",
165 "Choose which keys should be automatically removed by the bake");
166}
167
169{
170 // FunctionRNA *func;
171 // PropertyRNA *parm;
172}
173
174#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
@ RPT_ERROR
Definition BKE_report.hh:39
@ RPT_WARNING
Definition BKE_report.hh:38
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define MINAFRAME
#define MAXFRAME
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ FUNC_USE_REPORTS
Definition RNA_types.hh:914
PropertyFlag
Definition RNA_types.hh:300
#define NC_ANIMATION
Definition WM_types.hh:388
#define NA_EDITED
Definition WM_types.hh:584
#define ND_ANIMCHAN
Definition WM_types.hh:496
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void bake_fcurve(FCurve *fcu, blender::int2 range, float step, BakeCurveRemove remove_existing)
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)