[Bf-blender-cvs] [b6b2199] gooseberry: Squeakycleanlinator tool for Hwoozeberry.

Antony Riakiotakis noreply at git.blender.org
Wed May 20 15:30:42 CEST 2015


Commit: b6b219996df20a2b63d932032d8b6ea1c0a14fd1
Author: Antony Riakiotakis
Date:   Wed May 20 15:30:33 2015 +0200
Branches: gooseberry
https://developer.blender.org/rBb6b219996df20a2b63d932032d8b6ea1c0a14fd1

Squeakycleanlinator tool for Hwoozeberry.

Basically it's a clean tool, but also removes a channel if the only
remaining keyframe has the default value only and is not used by
drivers or generative modifiers.

It's supposed to help with performance of the heavy scenes in
gooseberry.

Field test in gooseberry for now, masterification later.

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

M	release/scripts/startup/bl_ui/space_dopesheet.py
M	release/scripts/startup/bl_ui/space_graph.py
M	source/blender/editors/animation/keyframes_general.c
M	source/blender/editors/include/ED_keyframes_edit.h
M	source/blender/editors/space_action/action_edit.c
M	source/blender/editors/space_graph/graph_edit.c

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

diff --git a/release/scripts/startup/bl_ui/space_dopesheet.py b/release/scripts/startup/bl_ui/space_dopesheet.py
index 0b7502b..7fd9719 100644
--- a/release/scripts/startup/bl_ui/space_dopesheet.py
+++ b/release/scripts/startup/bl_ui/space_dopesheet.py
@@ -339,6 +339,7 @@ class DOPESHEET_MT_key(Menu):
 
         layout.separator()
         layout.operator("action.clean")
+        layout.operator("action.clean", text="Clean Channels").channels = True
         layout.operator("action.sample")
 
         layout.separator()
@@ -421,6 +422,8 @@ class DOPESHEET_MT_delete(Menu):
         layout.separator()
 
         layout.operator("action.clean")
+        layout.operator("action.clean", text="Clean Channels").channels = True
+
 
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/release/scripts/startup/bl_ui/space_graph.py b/release/scripts/startup/bl_ui/space_graph.py
index 2f5381e..104fd14 100644
--- a/release/scripts/startup/bl_ui/space_graph.py
+++ b/release/scripts/startup/bl_ui/space_graph.py
@@ -258,6 +258,7 @@ class GRAPH_MT_key(Menu):
 
         layout.separator()
         layout.operator("graph.clean")
+        layout.operator("graph.clean", text="Clean Channels").channels = True
         layout.operator("graph.smooth")
         layout.operator("graph.sample")
         layout.operator("graph.bake")
@@ -293,6 +294,7 @@ class GRAPH_MT_delete(Menu):
         layout.separator()
 
         layout.operator("graph.clean")
+        layout.operator("graph.clean", text="Clean Channels").channels = True
 
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c
index b3dc002..19e32b5 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -179,17 +179,22 @@ void duplicate_fcurve_keys(FCurve *fcu)
 /* **************************************************** */
 /* Various Tools */
 
-/* Basic F-Curve 'cleanup' function that removes 'double points' and unnecessary keyframes on linear-segments only */
-void clean_fcurve(FCurve *fcu, float thresh)
+/* Basic F-Curve 'cleanup' function that removes 'double points' and unnecessary keyframes on linear-segments only
+ * optionally clears up curve if one keyframe with default value remains */
+void clean_fcurve(struct bAnimContext *ac, bAnimListElem *ale, float thresh, bool cleardefault)
 {
+	FCurve *fcu = (FCurve *)ale->key_data;
 	BezTriple *old_bezts, *bezt, *beztn;
 	BezTriple *lastb;
 	int totCount, i;
 	
 	/* check if any points  */
-	if ((fcu == NULL) || (fcu->bezt == NULL) || (fcu->totvert <= 1))
+	if ((fcu == NULL) || (fcu->bezt == NULL) || (fcu->totvert == 0) ||
+	    (!cleardefault && fcu->totvert == 1))
+	{
 		return;
-	
+	}
+
 	/* make a copy of the old BezTriples, and clear F-Curve */
 	old_bezts = fcu->bezt;
 	totCount = fcu->totvert;
@@ -284,6 +289,34 @@ void clean_fcurve(FCurve *fcu, float thresh)
 	/* now free the memory used by the old BezTriples */
 	if (old_bezts)
 		MEM_freeN(old_bezts);
+
+	/* final step, if there is just one key in fcurve, check if it's
+	 * the default value and if is, remove fcurve completely. */
+	if (cleardefault && fcu->totvert == 1) {
+		float default_value = 0.0f;
+		PointerRNA id_ptr, ptr;
+		PropertyRNA *prop;
+		RNA_id_pointer_create(ale->id, &id_ptr);
+
+		/* get property to read from, and get value as appropriate */
+		if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
+			if (RNA_property_type(prop) == PROP_FLOAT)
+				default_value = RNA_property_float_get_default_index(&ptr, prop, fcu->array_index);
+		}
+
+		if (fcu->bezt->vec[1][1] == default_value) {
+			clear_fcurve_keys(fcu);
+
+			/* check if curve is really unused and if it is, return signal for deletion */
+			if ((list_has_suitable_fmodifier(&fcu->modifiers, 0, FMI_TYPE_GENERATE_CURVE) == 0) &&
+			    (fcu->driver == NULL))
+			{
+				AnimData *adt = ale->adt;
+				ANIM_fcurve_delete_from_animdata(ac, adt, fcu);
+				ale->key_data = NULL;
+			}
+		}
+	}
 }
 
 /* ---------------- */
diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h
index adf82ac..92375cb 100644
--- a/source/blender/editors/include/ED_keyframes_edit.h
+++ b/source/blender/editors/include/ED_keyframes_edit.h
@@ -261,7 +261,7 @@ bool delete_fcurve_keys(struct FCurve *fcu);
 void clear_fcurve_keys(struct FCurve *fcu);
 void duplicate_fcurve_keys(struct FCurve *fcu);
 
-void clean_fcurve(struct FCurve *fcu, float thresh);
+void clean_fcurve(struct bAnimContext *ac, struct bAnimListElem *ale, float thresh, bool cleardefault);
 void smooth_fcurve(struct FCurve *fcu);
 void sample_fcurve(struct FCurve *fcu);
 
diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c
index 90c3842..a28b4c1 100644
--- a/source/blender/editors/space_action/action_edit.c
+++ b/source/blender/editors/space_action/action_edit.c
@@ -898,7 +898,7 @@ void ACTION_OT_delete(wmOperatorType *ot)
 
 /* ******************** Clean Keyframes Operator ************************* */
 
-static void clean_action_keys(bAnimContext *ac, float thresh)
+static void clean_action_keys(bAnimContext *ac, float thresh, bool clean_chan)
 {	
 	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
@@ -910,7 +910,7 @@ static void clean_action_keys(bAnimContext *ac, float thresh)
 	
 	/* loop through filtered data and clean curves */
 	for (ale = anim_data.first; ale; ale = ale->next) {
-		clean_fcurve((FCurve *)ale->key_data, thresh);
+		clean_fcurve(ac, ale, thresh, clean_chan);
 
 		ale->update |= ANIM_UPDATE_DEFAULT;
 	}
@@ -925,6 +925,7 @@ static int actkeys_clean_exec(bContext *C, wmOperator *op)
 {
 	bAnimContext ac;
 	float thresh;
+	bool clean_chan;
 	
 	/* get editor data */
 	if (ANIM_animdata_get_context(C, &ac) == 0)
@@ -937,9 +938,10 @@ static int actkeys_clean_exec(bContext *C, wmOperator *op)
 		
 	/* get cleaning threshold */
 	thresh = RNA_float_get(op->ptr, "threshold");
+	clean_chan = RNA_boolean_get(op->ptr, "channels");
 	
 	/* clean keyframes */
-	clean_action_keys(&ac, thresh);
+	clean_action_keys(&ac, thresh, clean_chan);
 	
 	/* set notifier that keyframes have changed */
 	WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
@@ -964,6 +966,7 @@ void ACTION_OT_clean(wmOperatorType *ot)
 	
 	/* properties */
 	ot->prop = RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
+	RNA_def_boolean(ot->srna, "channels", false, "Channels", "");
 }
 
 /* ******************** Sample Keyframes Operator *********************** */
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index c3e5b37..74adfdc 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -983,7 +983,7 @@ void GRAPH_OT_delete(wmOperatorType *ot)
 
 /* ******************** Clean Keyframes Operator ************************* */
 
-static void clean_graph_keys(bAnimContext *ac, float thresh)
+static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan)
 {	
 	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
@@ -995,7 +995,7 @@ static void clean_graph_keys(bAnimContext *ac, float thresh)
 	
 	/* loop through filtered data and clean curves */
 	for (ale = anim_data.first; ale; ale = ale->next) {
-		clean_fcurve((FCurve *)ale->key_data, thresh);
+		clean_fcurve(ac, ale, thresh, clean_chan);
 
 		ale->update |= ANIM_UPDATE_DEFAULT;
 	}
@@ -1010,6 +1010,7 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op)
 {
 	bAnimContext ac;
 	float thresh;
+	bool clean_chan;
 	
 	/* get editor data */
 	if (ANIM_animdata_get_context(C, &ac) == 0)
@@ -1017,9 +1018,9 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op)
 		
 	/* get cleaning threshold */
 	thresh = RNA_float_get(op->ptr, "threshold");
-	
+	clean_chan = RNA_boolean_get(op->ptr, "channels");
 	/* clean keyframes */
-	clean_graph_keys(&ac, thresh);
+	clean_graph_keys(&ac, thresh, clean_chan);
 	
 	/* set notifier that keyframes have changed */
 	WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
@@ -1044,6 +1045,7 @@ void GRAPH_OT_clean(wmOperatorType *ot)
 	
 	/* properties */
 	ot->prop = RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
+	RNA_def_boolean(ot->srna, "channels", false, "Channels", "");
 }
 
 /* ******************** Bake F-Curve Operator *********************** */




More information about the Bf-blender-cvs mailing list