[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60999] trunk/blender: Project Pampa request: FCurves normalized display

Sergey Sharybin sergey.vfx at gmail.com
Tue Oct 29 19:10:52 CET 2013


Revision: 60999
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60999
Author:   nazgul
Date:     2013-10-29 18:10:52 +0000 (Tue, 29 Oct 2013)
Log Message:
-----------
Project Pampa request: FCurves normalized display

Added two options to a header of FCurve editor:

- Normalize which makes it so every individual
  curve is fit into -1..1 space.

- Auto-normalize, which probably is to be called
  "Lock" which "locks" curve normalization scale.
  This is useful to prevent curves from jumping
  around when tweaking it.

It's debatable whether it need to be a button to
normalize curves n purpose only, and it's fully
depends on animator's workflow.

Here during Project Pampa we've got Francesco
who get used to auto-renormalization and Hjalti
who prefers locked behavior.

Docs are to be ready soon by Francesco.
Thanks Brecht for the review!

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_graph.py
    trunk/blender/source/blender/blenkernel/BKE_global.h
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/space_graph/graph_draw.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_select.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_graph.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_graph.py	2013-10-29 18:10:48 UTC (rev 60998)
+++ trunk/blender/release/scripts/startup/bl_ui/space_graph.py	2013-10-29 18:10:52 UTC (rev 60999)
@@ -46,6 +46,11 @@
 
         dopesheet_filter(layout, context)
 
+        layout.prop(st, "use_normalization", text="Normalize")
+        row = layout.row()
+        row.active = st.use_normalization
+        row.prop(st, "use_auto_normalization", text="Auto")
+
         layout.prop(st, "auto_snap", text="")
         layout.prop(st, "pivot_point", text="", icon_only=True)
 

Modified: trunk/blender/source/blender/blenkernel/BKE_global.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_global.h	2013-10-29 18:10:48 UTC (rev 60998)
+++ trunk/blender/source/blender/blenkernel/BKE_global.h	2013-10-29 18:10:52 UTC (rev 60999)
@@ -192,6 +192,7 @@
 #define G_TRANSFORM_OBJ         1
 #define G_TRANSFORM_EDIT        2
 #define G_TRANSFORM_SEQ         4
+#define G_TRANSFORM_FCURVES     8
 
 /* G.special1 */
 

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c	2013-10-29 18:10:48 UTC (rev 60998)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c	2013-10-29 18:10:52 UTC (rev 60999)
@@ -33,6 +33,7 @@
 #include "DNA_anim_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
 
 #include "BLI_math.h"
@@ -359,9 +360,68 @@
 /* *************************************************** */
 /* UNITS CONVERSION MAPPING (required for drawing and editing keyframes) */
 
+/* Get flags used for normalization in ANIM_unit_mapping_get_factor. */
+short ANIM_get_normalization_flags(bAnimContext *ac)
+{
+	if (ac->sl->spacetype == SPACE_IPO) {
+		SpaceIpo *sipo = (SpaceIpo *) ac->sl;
+		bool use_normalization = (sipo->flag & SIPO_NORMALIZE) != 0;
+		bool freeze_normalization = (sipo->flag & SIPO_NORMALIZE_FREEZE) != 0;
+		return use_normalization
+		    ? (ANIM_UNITCONV_NORMALIZE |  (freeze_normalization ? ANIM_UNITCONV_NORMALIZE_FREEZE : 0))
+		    : 0;
+	}
+
+	return 0;
+}
+
+static float normalzation_factor_get(FCurve *fcu, short flag)
+{
+	float factor;
+
+	if (flag & ANIM_UNITCONV_RESTORE) {
+		return 1.0f / fcu->prev_norm_factor;
+	}
+
+	if (flag & ANIM_UNITCONV_NORMALIZE_FREEZE) {
+		return fcu->prev_norm_factor;
+	}
+
+	if (G.moving & G_TRANSFORM_FCURVES) {
+		return fcu->prev_norm_factor;
+	}
+
+	fcu->prev_norm_factor = 1.0f;
+	if (fcu->bezt) {
+		BezTriple *bezt;
+		int i;
+		float max_coord = -FLT_MAX;
+
+		if (fcu->totvert < 1) {
+			return 1.0f;
+		}
+
+		for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
+			max_coord = max_ff(max_coord, fabsf(bezt->vec[0][1]));
+			max_coord = max_ff(max_coord, fabsf(bezt->vec[1][1]));
+			max_coord = max_ff(max_coord, fabsf(bezt->vec[2][1]));
+		}
+
+		if (max_coord > FLT_EPSILON) {
+			factor = 1.0f / max_coord;
+		}
+	}
+	fcu->prev_norm_factor = factor;
+	return factor;
+}
+
 /* Get unit conversion factor for given ID + F-Curve */
-float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short restore)
+float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag)
 {
+	if (flag & ANIM_UNITCONV_NORMALIZE) {
+		return normalzation_factor_get(fcu, flag);
+	}
+
 	/* sanity checks */
 	if (id && fcu && fcu->rna_path) {
 		PointerRNA ptr, id_ptr;
@@ -374,7 +434,7 @@
 			if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
 				/* if the radians flag is not set, default to using degrees which need conversions */
 				if ((scene) && (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS) == 0) {
-					if (restore)
+					if (flag & ANIM_UNITCONV_RESTORE)
 						return DEG2RADF(1.0f);  /* degrees to radians */
 					else
 						return RAD2DEGF(1.0f);  /* radians to degrees */

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h	2013-10-29 18:10:48 UTC (rev 60998)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h	2013-10-29 18:10:52 UTC (rev 60999)
@@ -559,10 +559,19 @@
 	/* only touch selected vertices */
 	ANIM_UNITCONV_SELVERTS  = (1 << 3),
 	ANIM_UNITCONV_SKIPKNOTS  = (1 << 4),
+	/* Scale FCurve i a way it fits to -1..1 space */
+	ANIM_UNITCONV_NORMALIZE  = (1 << 5),
+	/* Only whennormalization is used: use scale factor from previous run,
+	 * prevents curves from jumping all over the place when tweaking them.
+	 */
+	ANIM_UNITCONV_NORMALIZE_FREEZE  = (1 << 6),
 } eAnimUnitConv_Flags;
 
+/* Normalizatin flags from Space Graph passing to ANIM_unit_mapping_get_factor */
+short ANIM_get_normalization_flags(bAnimContext *ac);
+
 /* Get unit conversion factor for given ID + F-Curve */
-float ANIM_unit_mapping_get_factor(struct Scene *scene, struct ID *id, struct FCurve *fcu, short restore);
+float ANIM_unit_mapping_get_factor(struct Scene *scene, struct ID *id, struct FCurve *fcu, short flag);
 
 /* ------------- Utility macros ----------------------- */
 

Modified: trunk/blender/source/blender/editors/space_graph/graph_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_draw.c	2013-10-29 18:10:48 UTC (rev 60998)
+++ trunk/blender/source/blender/editors/space_graph/graph_draw.c	2013-10-29 18:10:52 UTC (rev 60999)
@@ -490,6 +490,7 @@
 	float stime, etime;
 	float unitFac;
 	float dx, dy;
+	short mapping_flag = ANIM_get_normalization_flags(ac);
 
 	/* when opening a blend file on a different sized screen or while dragging the toolbar this can happen
 	 * best just bail out in this case */
@@ -503,7 +504,7 @@
 	fcu->driver = NULL;
 	
 	/* compute unit correction factor */
-	unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0);
+	unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
 	
 	/* Note about sampling frequency:
 	 *  Ideally, this is chosen such that we have 1-2 pixels = 1 segment
@@ -551,10 +552,11 @@
 	float fac, v[2];
 	int b = fcu->totvert - 1;
 	float unit_scale;
+	short mapping_flag = ANIM_get_normalization_flags(ac);
 
 	/* apply unit mapping */
 	glPushMatrix();
-	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0);
+	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
 	glScalef(1.0f, unit_scale, 1.0f);
 
 	glBegin(GL_LINE_STRIP);
@@ -632,10 +634,11 @@
 	int b = fcu->totvert - 1;
 	int resol;
 	float unit_scale;
+	short mapping_flag = ANIM_get_normalization_flags(ac);
 
 	/* apply unit mapping */
 	glPushMatrix();
-	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0);
+	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
 	glScalef(1.0f, unit_scale, 1.0f);
 
 	glBegin(GL_LINE_STRIP);
@@ -788,7 +791,8 @@
 {
 	ChannelDriver *driver = fcu->driver;
 	View2D *v2d = &ac->ar->v2d;
-	float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, false);
+	short mapping_flag = ANIM_get_normalization_flags(ac);
+	float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
 	
 	/* for now, only show when debugging driver... */
 	//if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0)
@@ -1019,7 +1023,8 @@
 				}
 			}
 			else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
-				float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0);
+				short mapping_flag = ANIM_get_normalization_flags(ac);
+				float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag);
 
 				glPushMatrix();
 				glScalef(1.0f, unit_scale, 1.0f);

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c	2013-10-29 18:10:48 UTC (rev 60998)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c	2013-10-29 18:10:52 UTC (rev 60999)
@@ -116,6 +116,8 @@
 			
 			/* get range */
 			if (calc_fcurve_bounds(fcu, &txmin, &txmax, &tymin, &tymax, do_sel_only, include_handles)) {
+				short mapping_flag = ANIM_get_normalization_flags(ac);
+
 				/* apply NLA scaling */
 				if (adt) {
 					txmin = BKE_nla_tweakedit_remap(adt, txmin, NLATIME_CONVERT_MAP);
@@ -123,7 +125,7 @@
 				}
 				
 				/* apply unit corrections */
-				unitFac = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0);
+				unitFac = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag);
 				tymin *= unitFac;
 				tymax *= unitFac;
 				
@@ -330,12 +332,14 @@
 		FPoint *fpt;
 		float unitFac;
 		int cfra;
-		
+		SpaceIpo *sipo = (SpaceIpo *) ac->sl;
+		short mapping_flag = ANIM_get_normalization_flags(ac);
+
 		/* disable driver so that it don't muck up the sampling process */
 		fcu->driver = NULL;
 		
 		/* calculate unit-mapping factor */
-		unitFac = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0);
+		unitFac = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag);
 		
 		/* create samples, but store them in a new curve 
 		 *	- we cannot use fcurve_store_samples() as that will only overwrite the original curve 
@@ -578,6 +582,8 @@
 	 * keyframes if these will be visible after doing so...
 	 */
 	if (fcurve_is_keyframable(fcu)) {
+		short mapping_flag = ANIM_get_normalization_flags(&ac);
+
 		/* get frame and value from props */
 		frame = RNA_float_get(op->ptr, "frame");
 		val = RNA_float_get(op->ptr, "value");
@@ -587,7 +593,7 @@
 		frame = BKE_nla_tweakedit_remap(adt, frame, NLATIME_CONVERT_UNMAP);
 		
 		/* apply inverse unit-mapping to value to get correct value for F-Curves */
-		val *= ANIM_unit_mapping_get_factor(ac.scene, ale->id, fcu, 1);
+		val *= ANIM_unit_mapping_get_factor(ac.scene, ale->id, fcu, mapping_flag | ANIM_UNITCONV_RESTORE);
 		
 		/* insert keyframe on the specified frame + value */
 		insert_vert_fcurve(fcu, frame, val, 0);
@@ -1787,8 +1793,9 @@
 	
 	for (ale = anim_data.first; ale; ale = ale->next) {
 		AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
+		short mapping_flag = ANIM_get_normalization_flags(&ac);
 		KeyframeEditData current_ked;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list