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.
This commit is contained in:
Joshua Leung 2014-04-25 02:52:27 +12:00
parent 8b24d0a2e9
commit 9f4ad8014c
1 changed files with 21 additions and 3 deletions

View File

@ -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