From 9f4ad8014c91f74f01374aa7eb11fc3e4a6b9160 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 25 Apr 2014 02:52:27 +1200 Subject: [PATCH] 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. --- .../editors/transform/transform_generics.c | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 98f6d50bc36..0ff9f92db4e 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