Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lendenfeld <chris.lend@gmx.at>2022-03-18 22:07:16 +0300
committerChristoph Lendenfeld <chris.lend@gmx.at>2022-03-18 22:07:16 +0300
commit37b93b5df85c9e7acac989c86cf658bf8a0bc1e5 (patch)
tree46fd200a7d96537f0c97f2c4cdff0cefc713fcc9 /source/blender/editors/animation
parent63f9cb5a0b5930a67c6fa8db833293f21b57ff63 (diff)
Animation: Blend To Default Implementation
Add a new operator to the Graph Editor that blends selected keyframes to their default value. The operator can be accessed from Key>Slider Operators>Blend To Default Value Reviewed by: Sybren A. Stüvel Differential Revision: https://developer.blender.org/D9376 Ref: D9367
Diffstat (limited to 'source/blender/editors/animation')
-rw-r--r--source/blender/editors/animation/keyframes_general.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c
index 24ba62fc0f7..aec2b0f769a 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -382,6 +382,68 @@ void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
/* ---------------- */
+float get_default_rna_value(FCurve *fcu, PropertyRNA *prop, PointerRNA *ptr)
+{
+ const int len = RNA_property_array_length(ptr, prop);
+
+ float default_value = 0;
+ /* Find the default value of that property. */
+ switch (RNA_property_type(prop)) {
+ case PROP_BOOLEAN:
+ if (len) {
+ default_value = RNA_property_boolean_get_default_index(ptr, prop, fcu->array_index);
+ }
+ else {
+ default_value = RNA_property_boolean_get_default(ptr, prop);
+ }
+ break;
+ case PROP_INT:
+ if (len) {
+ default_value = RNA_property_int_get_default_index(ptr, prop, fcu->array_index);
+ }
+ else {
+ default_value = RNA_property_int_get_default(ptr, prop);
+ }
+ break;
+ case PROP_FLOAT:
+ if (len) {
+ default_value = RNA_property_float_get_default_index(ptr, prop, fcu->array_index);
+ }
+ else {
+ default_value = RNA_property_float_get_default(ptr, prop);
+ }
+ break;
+
+ default:
+ break;
+ }
+ return default_value;
+}
+
+/* This function blends the selected keyframes to the default value of the property the fcurve
+ * drives. */
+void blend_to_default_fcurve(PointerRNA *id_ptr, FCurve *fcu, const float factor)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+
+ /* Check if path is valid. */
+ if (!RNA_path_resolve_property(id_ptr, fcu->rna_path, &ptr, &prop)) {
+ return;
+ }
+
+ const float default_value = get_default_rna_value(fcu, prop, &ptr);
+
+ /* Blend selected keys to default */
+ for (int i = 0; i < fcu->totvert; i++) {
+ if (fcu->bezt[i].f2 & SELECT) {
+ fcu->bezt[i].vec[1][1] = interpf(default_value, fcu->bezt[i].vec[1][1], factor);
+ }
+ }
+}
+
+/* ---------------- */
+
void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
{
BezTriple left_bezt = fcurve_segment_start_get(fcu, segment->start_index);