[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21212] branches/soc-2009-aligorith/source /blender: NLA SoC: NLA Mapping Cleanup

Joshua Leung aligorith at gmail.com
Sun Jun 28 09:32:00 CEST 2009


Revision: 21212
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21212
Author:   aligorith
Date:     2009-06-28 09:32:00 +0200 (Sun, 28 Jun 2009)

Log Message:
-----------
NLA SoC: NLA Mapping Cleanup 

While trying to fix the mapping conversions for repeat, I came across some limitations with the current (soon to be previous) mapping methods. 

Now the mapping conversions should work nicely for all places that use them.

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
    branches/soc-2009-aligorith/source/blender/blenkernel/nla_private.h
    branches/soc-2009-aligorith/source/blender/editors/animation/anim_draw.c
    branches/soc-2009-aligorith/source/blender/editors/space_action/action_edit.c
    branches/soc-2009-aligorith/source/blender/editors/space_action/action_select.c
    branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_edit.c
    branches/soc-2009-aligorith/source/blender/editors/space_graph/graph_select.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_edit.c
    branches/soc-2009-aligorith/source/blender/editors/space_view3d/drawarmature.c
    branches/soc-2009-aligorith/source/blender/editors/transform/transform.c
    branches/soc-2009-aligorith/source/blender/editors/transform/transform_conversions.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-06-28 07:26:16 UTC (rev 21211)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h	2009-06-28 07:32:00 UTC (rev 21212)
@@ -73,7 +73,22 @@
 short BKE_nla_tweakmode_enter(struct AnimData *adt);
 void BKE_nla_tweakmode_exit(struct AnimData *adt);
 
-float BKE_nla_tweakedit_remap(struct AnimData *adt, float cframe, short invert);
+/* ----------------------------- */
+/* Time Mapping */
 
+/* time mapping conversion modes */
+enum {
+		/* convert from global time to strip time - for evaluation */
+	NLATIME_CONVERT_EVAL = 0,
+		/* convert from global time to strip time - for editing corrections */
+		// XXX old 0 invert
+	NLATIME_CONVERT_UNMAP,
+		/* convert from strip time to global time */
+		// xxx old 1 invert
+	NLATIME_CONVERT_MAP,
+} eNlaTime_ConvertModes;
+
+float BKE_nla_tweakedit_remap(struct AnimData *adt, float cframe, short mode);
+
 #endif
 

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c	2009-06-28 07:26:16 UTC (rev 21211)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/anim_sys.c	2009-06-28 07:32:00 UTC (rev 21212)
@@ -604,7 +604,7 @@
 {
 	/* firstly, analytically generate values for influence and time (if applicable) */
 	if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0)
-		strip->strip_time= nlastrip_get_frame(strip, ctime, 0);
+		strip->strip_time= nlastrip_get_frame(strip, ctime, NLATIME_CONVERT_EVAL);
 	if ((strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) == 0)
 		strip->influence= nlastrip_get_influence(strip, ctime);
 	

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-06-28 07:26:16 UTC (rev 21211)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c	2009-06-28 07:32:00 UTC (rev 21212)
@@ -329,7 +329,7 @@
 /* non clipped mapping for strip-time <-> global time (for Action-Clips)
  *	invert = convert action-strip time to global time 
  */
-static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short invert)
+static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short mode)
 {
 	float actlength, repeat, scale;
 	
@@ -347,9 +347,20 @@
 	
 	/* reversed = play strip backwards */
 	if (strip->flag & NLASTRIP_FLAG_REVERSE) {
-		/* invert = convert action-strip time to global time */
-		if (invert)
-			return scale*(strip->actend - cframe) + strip->start; // FIXME: this doesn't work for multiple repeats yet
+		// FIXME: this won't work right with Graph Editor?
+		if (mode == NLATIME_CONVERT_MAP) {
+			return strip->end - scale*(cframe - strip->actstart);
+		}
+		else if (mode == NLATIME_CONVERT_UNMAP) {
+			int repeatsNum = (int)((cframe - strip->start) / (actlength * scale));
+			
+			/* this method doesn't clip the values to lie within the action range only 
+			 *	- the '(repeatsNum * actlength * scale)' compensates for the fmod(...)
+			 *	- the fmod(...) works in the same way as for eval 
+			 */
+			return strip->actend - (repeatsNum * actlength * scale) 
+					- (fmod(cframe - strip->start, actlength*scale) / scale);
+		}
 		else {
 			if (IS_EQ(cframe, strip->end) && IS_EQ(strip->repeat, ((int)strip->repeat))) {
 				/* this case prevents the motion snapping back to the first frame at the end of the strip 
@@ -367,10 +378,20 @@
 		}
 	}
 	else {
-		/* invert = convert action-strip time to global time */
-		if (invert)
-			return scale*(cframe - strip->actstart) + strip->start; // FIXME: this doesn't work for mutiple repeats yet
-		else {
+		if (mode == NLATIME_CONVERT_MAP) {
+			return strip->start + scale*(cframe - strip->actstart);
+		}
+		else if (mode == NLATIME_CONVERT_UNMAP) {
+			int repeatsNum = (int)((cframe - strip->start) / (actlength * scale));
+			
+			/* this method doesn't clip the values to lie within the action range only 
+			 *	- the '(repeatsNum * actlength * scale)' compensates for the fmod(...)
+			 *	- the fmod(...) works in the same way as for eval 
+			 */
+			return strip->actstart + (repeatsNum * actlength * scale) 
+					+ (fmod(cframe - strip->start, actlength*scale) / scale);
+		}
+		else /* if (mode == NLATIME_CONVERT_EVAL) */{
 			if (IS_EQ(cframe, strip->end) && IS_EQ(strip->repeat, ((int)strip->repeat))) {
 				/* this case prevents the motion snapping back to the first frame at the end of the strip 
 				 * by catching the case where repeats is a whole number, which means that the end of the strip
@@ -391,7 +412,7 @@
 /* non clipped mapping for strip-time <-> global time (for Transitions)
  *	invert = convert action-strip time to global time 
  */
-static float nlastrip_get_frame_transition (NlaStrip *strip, float cframe, short invert)
+static float nlastrip_get_frame_transition (NlaStrip *strip, float cframe, short mode)
 {
 	float length;
 	
@@ -400,15 +421,13 @@
 	
 	/* reversed = play strip backwards */
 	if (strip->flag & NLASTRIP_FLAG_REVERSE) {
-		/* invert = convert within-strip-time to global time */
-		if (invert)
+		if (mode == NLATIME_CONVERT_MAP)
 			return strip->end - (length * cframe);
 		else
 			return (strip->end - cframe) / length;
 	}
 	else {
-		/* invert = convert within-strip-time to global time */
-		if (invert)
+		if (mode == NLATIME_CONVERT_MAP)
 			return (length * cframe) + strip->start;
 		else
 			return (cframe - strip->start) / length;
@@ -416,31 +435,31 @@
 }
 
 /* non clipped mapping for strip-time <-> global time
- *	invert = convert action-strip time to global time 
+ * 	mode = eNlaTime_ConvertModes[] -> NLATIME_CONVERT_*
  *
  * only secure for 'internal' (i.e. within AnimSys evaluation) operations,
  * but should not be directly relied on for stuff which interacts with editors
  */
-float nlastrip_get_frame (NlaStrip *strip, float cframe, short invert)
+float nlastrip_get_frame (NlaStrip *strip, float cframe, short mode)
 {
 	switch (strip->type) {
 		case NLASTRIP_TYPE_TRANSITION: /* transition */
-			return nlastrip_get_frame_transition(strip, cframe, invert);
+			return nlastrip_get_frame_transition(strip, cframe, mode);
 		
 		case NLASTRIP_TYPE_CLIP: /* action-clip (default) */
 		default:
-			return nlastrip_get_frame_actionclip(strip, cframe, invert);
+			return nlastrip_get_frame_actionclip(strip, cframe, mode);
 	}	
 }
 
 
 /* Non clipped mapping for strip-time <-> global time
- *	invert = convert strip-time to global time 
+ *	mode = eNlaTime_ConvertModesp[] -> NLATIME_CONVERT_*
  *
  * Public API method - perform this mapping using the given AnimData block
  * and perform any necessary sanity checks on the value
  */
-float BKE_nla_tweakedit_remap (AnimData *adt, float cframe, short invert)
+float BKE_nla_tweakedit_remap (AnimData *adt, float cframe, short mode)
 {
 	NlaStrip *strip;
 	
@@ -469,7 +488,7 @@
 		return cframe;
 		
 	/* perform the correction now... */
-	return nlastrip_get_frame(strip, cframe, invert);
+	return nlastrip_get_frame(strip, cframe, mode);
 }
 
 /* *************************************************** */

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/nla_private.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/nla_private.h	2009-06-28 07:26:16 UTC (rev 21211)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/nla_private.h	2009-06-28 07:32:00 UTC (rev 21212)
@@ -73,6 +73,7 @@
 /* --------------- NLA Functions (not to be used as a proper API) ----------------------- */
 
 /* convert from strip time <-> global time */
-float nlastrip_get_frame(NlaStrip *strip, float cframe, short invert);
+float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode);
 
+
 #endif // NLA_PRIVATE

Modified: branches/soc-2009-aligorith/source/blender/editors/animation/anim_draw.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/animation/anim_draw.c	2009-06-28 07:26:16 UTC (rev 21211)
+++ branches/soc-2009-aligorith/source/blender/editors/animation/anim_draw.c	2009-06-28 07:32:00 UTC (rev 21212)
@@ -270,8 +270,8 @@
 		gla2DGetMap(di, &stored);
 		map= stored;
 		
-		map.xmin= BKE_nla_tweakedit_remap(adt, map.xmin, 0);
-		map.xmax= BKE_nla_tweakedit_remap(adt, map.xmax, 0);
+		map.xmin= BKE_nla_tweakedit_remap(adt, map.xmin, NLATIME_CONVERT_MAP);
+		map.xmax= BKE_nla_tweakedit_remap(adt, map.xmax, NLATIME_CONVERT_MAP);
 		
 		if (map.xmin == map.xmax) map.xmax += 1.0f;
 		gla2DSetMap(di, &map);
@@ -289,11 +289,11 @@
 	
 	/* adjust BezTriple handles only if allowed to */
 	if (only_keys == 0) {
-		bezt->vec[0][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], 0);
-		bezt->vec[2][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], 0);
+		bezt->vec[0][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_UNMAP);
+		bezt->vec[2][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_UNMAP);
 	}
 	
-	bezt->vec[1][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], 0);
+	bezt->vec[1][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_UNMAP);
 	
 	return 0;
 }
@@ -307,11 +307,11 @@
 	
 	/* adjust BezTriple handles only if allowed to */
 	if (only_keys == 0) {
-		bezt->vec[0][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], 1);
-		bezt->vec[2][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], 1);
+		bezt->vec[0][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_MAP);
+		bezt->vec[2][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_MAP);
 	}
 	
-	bezt->vec[1][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], 1);
+	bezt->vec[1][0]= BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_MAP);
 	
 	return 0;
 }

Modified: branches/soc-2009-aligorith/source/blender/editors/space_action/action_edit.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_action/action_edit.c	2009-06-28 07:26:16 UTC (rev 21211)
+++ branches/soc-2009-aligorith/source/blender/editors/space_action/action_edit.c	2009-06-28 07:32:00 UTC (rev 21212)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list