Fix #110108: NLA absolute snapping #111984

Merged
Christoph Lendenfeld merged 9 commits from ChrisLend/blender:fix_nla_marker_snap into main 2023-09-15 09:52:48 +02:00

View File

@ -660,9 +660,28 @@ static void snap_transform_data(TransInfo *t, TransDataContainer *tc)
if (t->modifiers & MOD_SNAP_INVERT) {
invert_snap(snap_mode);
}
TransData *td = tc->data;
for (int i = 0; i < tc->data_len; i++, td++) {
transform_snap_anim_flush_data(t, td, snap_mode, td->loc);
float offset = 0;
float smallest_snap_delta = FLT_MAX;
/* In order to move the strip in a block and not each end individually,
* find the minimal snap offset first and then shift the whole strip by that amount. */
for (int i = 0; i < tc->data_len; i++) {
TransData td = tc->data[i];
float snap_value;
transform_snap_anim_flush_data(t, &td, snap_mode, &snap_value);
/* The snap_delta measures how far from the unsnapped position the value has moved. */

Minor: first line in comment is a little long.

/* In order to move the strip in a block and not each end individually,
 * find the minimal snap offset and shift the whole strip by that amount. */

Might read better.

Minor: first line in comment is a little long. ``` /* In order to move the strip in a block and not each end individually, * find the minimal snap offset and shift the whole strip by that amount. */ ``` Might read better.
const float snap_delta = *td.loc - snap_value;
if (fabs(snap_delta) < fabs(smallest_snap_delta)) {
offset = snap_value - td.iloc[0];
smallest_snap_delta = snap_delta;
}
}
for (int i = 0; i < tc->data_len; i++) {
TransData td = tc->data[i];
*td.loc = td.iloc[0] + offset;
Review

is there a reason we update *td.loc in it's own loop? Couldn't that be done at the bottom of the other loop?

is there a reason we update `*td.loc` in it's own loop? Couldn't that be done at the bottom of the other loop?

I need to first find the smallest snap delta of all points, then I can apply that offset to all points.
That gives me the behavior of snapping the whole block to the closest snapping point of either side.

I renamed the variables and added a comment to make that clearer

I need to first find the smallest snap delta of all points, then I can apply that offset to all points. That gives me the behavior of snapping the whole block to the closest snapping point of either side. I renamed the variables and added a comment to make that clearer
}
}