[Bf-blender-cvs] [9f4ad80] master: AutoSnap Bugfixes: NLA Editor - Nearest Second behaviour tweak

Joshua Leung noreply at git.blender.org
Thu Apr 24 17:14:56 CEST 2014


Commit: 9f4ad8014c91f74f01374aa7eb11fc3e4a6b9160
Author: Joshua Leung
Date:   Fri Apr 25 02:52:27 2014 +1200
https://developer.blender.org/rB9f4ad8014c91f74f01374aa7eb11fc3e4a6b9160

AutoSnap Bugfixes: NLA Editor - Nearest Second behaviour tweak

The previous behaviour for nearest second meant that transforming the strips often
caused their lengths to change (sometimes drastically), since strip lengths aren't
always uniformly x-seconds long. Now, it only snaps the start frame value, and adjusts
the end of the strip to follow.

This works well for most cases, apart from negatively scaling the strip, where it will
get "stuck" as a 0.001 frame long strip (and the viewport drawing will be a bit weird
during this time). Nevertheless, negative scaling of strips isn't something that's exactly
recommended.

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

M	source/blender/editors/transform/transform_generics.c

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

diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 98f6d50..0ff9f92 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -532,19 +532,37 @@ static void recalcData_nla(TransInfo *t)
 		/* handle auto-snapping */
 		switch (snla->autosnap) {
 			case SACTSNAP_FRAME: /* snap to nearest frame */
+			{
 				tdn->h1[0] = floorf(tdn->h1[0] + 0.5f);
 				tdn->h2[0] = floorf(tdn->h2[0] + 0.5f);
 				break;
-				
+			}
+			
 			case SACTSNAP_SECOND: /* snap to nearest second */
-				tdn->h1[0] = (float)(floor(((double)tdn->h1[0] / secf) + 0.5) * secf);
-				tdn->h2[0] = (float)(floor(((double)tdn->h2[0] / secf) + 0.5) * secf);
+			{
+				/* This case behaves differently from the rest, since lengths of strips
+				 * may not be multiples of a second. If we just naively resize adjust
+				 * the handles, things may not work correctly. Instead, we only snap
+				 * the first handle, and move the other to fit.
+				 *
+				 * FIXME: we do run into problems here when user attempts to negatively
+				 *        scale the strip, as it then just compresses down and refuses
+				 *        to expand out the other end.
+				 */
+				float h1_new = (float)(floor(((double)tdn->h1[0] / secf) + 0.5) * secf);
+				float delta  = h1_new - tdn->h1[0];
+				
+				tdn->h1[0] = h1_new;
+				tdn->h2[0] += delta;
 				break;
+			}
 			
 			case SACTSNAP_MARKER: /* snap to nearest marker */
+			{
 				tdn->h1[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, tdn->h1[0]);
 				tdn->h2[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, tdn->h2[0]);
 				break;
+			}
 		}
 		
 		/* Use RNA to write the values to ensure that constraints on these are obeyed




More information about the Bf-blender-cvs mailing list