From 4966e26cd3645f92a725b8838180e688b99c874c Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Thu, 18 Apr 2024 14:38:55 +0200 Subject: [PATCH 1/2] implement rna function --- .../blender/makesrna/intern/rna_fcurve_api.cc | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/source/blender/makesrna/intern/rna_fcurve_api.cc b/source/blender/makesrna/intern/rna_fcurve_api.cc index 37b722b75cb..f0fdfe691b0 100644 --- a/source/blender/makesrna/intern/rna_fcurve_api.cc +++ b/source/blender/makesrna/intern/rna_fcurve_api.cc @@ -17,6 +17,7 @@ #include "DNA_anim_types.h" #include "DNA_scene_types.h" +#include "ED_keyframes_edit.hh" #include "rna_internal.hh" /* own include */ @@ -64,8 +65,41 @@ static void rna_FCurve_convert_to_keyframes(FCurve *fcu, ReportList *reports, in } } +static void rna_FCurve_bake(FCurve *fcu, + ReportList *reports, + int start_frame, + int end_frame, + float step, + int remove_option) +{ + if (start_frame >= end_frame) { + BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start_frame, end_frame); + return; + } + + const BakeCurveRemove remove_existing = BakeCurveRemove(remove_option); + bake_fcurve(fcu, {start_frame, end_frame}, step, remove_existing); + WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, nullptr); +} + #else +static const EnumPropertyItem channel_bake_remove_options[] = { + {int(BakeCurveRemove::REMOVE_NONE), "NONE", 0, "None", "Keep all keys"}, + {int(BakeCurveRemove::REMOVE_IN_RANGE), + "IN_RANGE", + 0, + "In Range", + "Remove all keys within the defined range"}, + {int(BakeCurveRemove::REMOVE_OUT_RANGE), + "OUT_RANGE", + 0, + "Outside Range", + "Remove all keys outside the defined range"}, + {int(BakeCurveRemove::REMOVE_ALL), "ALL", 0, "All", "Remove all existing keys"}, + {0, nullptr, 0, nullptr, nullptr}, +}; + void RNA_api_fcurves(StructRNA *srna) { FunctionRNA *func; @@ -92,6 +126,40 @@ void RNA_api_fcurves(StructRNA *srna) RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME); RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); + + func = RNA_def_function(srna, "bake", "rna_FCurve_bake"); + RNA_def_function_ui_description(func, "Place keys at even intervals on the existing curve."); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm = RNA_def_int(func, + "start", + 0, + MINAFRAME, + MAXFRAME, + "Start Frame", + "Frame at which to start baking", + MINAFRAME, + MAXFRAME); + RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); + parm = RNA_def_int(func, + "end", + 0, + MINAFRAME, + MAXFRAME, + "End Frame", + "Frame at which to end baking (inclusive)", + MINAFRAME, + MAXFRAME); + RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); + parm = RNA_def_float( + func, "step", 1, 0.01, FLT_MAX, "Step", "At which interval to add keys", 1, 16); + RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_PYFUNC_OPTIONAL); + RNA_def_enum(func, + "remove", + channel_bake_remove_options, + int(BakeCurveRemove::REMOVE_IN_RANGE), + "Remove Options", + "Choose which keys should be automatically removed by the bake"); + RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_PYFUNC_OPTIONAL); } void RNA_api_drivers(StructRNA * /*srna*/) -- 2.30.2 From ad666b78bf376c502211cf44ef1fde51848e3c37 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 23 Apr 2024 12:42:51 +0200 Subject: [PATCH 2/2] review comments --- source/blender/makesrna/intern/rna_fcurve_api.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/blender/makesrna/intern/rna_fcurve_api.cc b/source/blender/makesrna/intern/rna_fcurve_api.cc index f0fdfe691b0..8db31045bc8 100644 --- a/source/blender/makesrna/intern/rna_fcurve_api.cc +++ b/source/blender/makesrna/intern/rna_fcurve_api.cc @@ -70,14 +70,18 @@ static void rna_FCurve_bake(FCurve *fcu, int start_frame, int end_frame, float step, - int remove_option) + int remove_existing_as_int) { if (start_frame >= end_frame) { - BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start_frame, end_frame); + BKE_reportf(reports, + RPT_ERROR, + "Invalid frame range (%d - %d). End Frame is larger than Start Frame", + start_frame, + end_frame); return; } - const BakeCurveRemove remove_existing = BakeCurveRemove(remove_option); + const BakeCurveRemove remove_existing = BakeCurveRemove(remove_existing_as_int); bake_fcurve(fcu, {start_frame, end_frame}, step, remove_existing); WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, nullptr); } -- 2.30.2