[Bf-blender-cvs] [091100bfd75] master: Animation: Add function to remove all FCurves from an Action

Colin Basnett noreply at git.blender.org
Thu Jun 23 11:46:44 CEST 2022


Commit: 091100bfd757b886527b465aef19a88ba261d7ec
Author: Colin Basnett
Date:   Thu Jun 23 11:41:44 2022 +0200
Branches: master
https://developer.blender.org/rB091100bfd757b886527b465aef19a88ba261d7ec

Animation: Add function to remove all FCurves from an Action

Add a `BKE_action_fcurves_clear(action)` function, which removes all the
Action's FCurves, and expose it as `ActionFCurves.clear()` in RNA.

This is more ergonomic than calling `remove` on f-curves until the list
is empty.

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D14660

===================================================================

M	source/blender/blenkernel/BKE_action.h
M	source/blender/blenkernel/intern/action.c
M	source/blender/makesrna/intern/rna_action.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h
index d5487b3558a..79d0fe6e20a 100644
--- a/source/blender/blenkernel/BKE_action.h
+++ b/source/blender/blenkernel/BKE_action.h
@@ -92,6 +92,11 @@ bool action_has_motion(const struct bAction *act);
  */
 bool BKE_action_is_cyclic(const struct bAction *act);
 
+/**
+ * Remove all fcurves from the action.
+ */
+void BKE_action_fcurves_clear(struct bAction *act);
+
 /* Action Groups API ----------------- */
 
 /**
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 05b51e0c9fa..fee7582acb3 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -1983,3 +1983,16 @@ void BKE_pose_blend_read_expand(BlendExpander *expander, bPose *pose)
     BLO_expand(expander, chan->custom);
   }
 }
+
+void BKE_action_fcurves_clear(bAction *act)
+{
+  if (!act) {
+    return;
+  }
+  while (act->curves.first) {
+    FCurve *fcu = act->curves.first;
+    action_groups_remove_channel(act, fcu);
+    BKE_fcurve_free(fcu);
+  }
+  DEG_id_tag_update(&act->id, ID_RECALC_ANIMATION_NO_FLUSH);
+}
diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c
index a1266443631..ac90ec69784 100644
--- a/source/blender/makesrna/intern/rna_action.c
+++ b/source/blender/makesrna/intern/rna_action.c
@@ -168,6 +168,12 @@ static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, PointerR
   WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
 }
 
+static void rna_Action_fcurve_clear(bAction *act)
+{
+  BKE_action_fcurves_clear(act);
+  WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+}
+
 static TimeMarker *rna_Action_pose_markers_new(bAction *act, const char name[])
 {
   TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
@@ -788,6 +794,10 @@ static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
   parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "F-Curve to remove");
   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
   RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+
+  /* Action.fcurves.clear() */
+  func = RNA_def_function(srna, "clear", "rna_Action_fcurve_clear");
+  RNA_def_function_ui_description(func, "Remove all F-Curves");
 }
 
 static void rna_def_action_pose_markers(BlenderRNA *brna, PropertyRNA *cprop)



More information about the Bf-blender-cvs mailing list