From 10e23fd1046a0fd1f2e2f7cac7fc897cc0ea99be Mon Sep 17 00:00:00 2001 From: Wayde Moss Date: Fri, 5 Feb 2021 16:45:34 -0500 Subject: NLA: Refactor Transition, Use Snapshot Blend Func The function `nlastrip_evaluate_transition()` has been slightly modified to use `nlasnapshot_blend()` instead of it's own special blending function `nlaeval_snapshot_mix_and_free()`. No user functional changes Reviewed By: sybren, #animation_rigging Differential Revision: https://developer.blender.org/D10221 --- source/blender/blenkernel/intern/anim_sys.c | 65 +++++++---------------------- 1 file changed, 14 insertions(+), 51 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 19684cbc788..da4c43e12a4 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -1657,55 +1657,6 @@ static bool nla_combine_quaternion_get_inverted_strip_values(const float lower_v return true; } -/* Blend the specified snapshots into the target, and free the input snapshots. */ -static void nlaeval_snapshot_mix_and_free(NlaEvalData *nlaeval, - NlaEvalSnapshot *out, - NlaEvalSnapshot *in1, - NlaEvalSnapshot *in2, - float alpha) -{ - BLI_assert(in1->base == out && in2->base == out); - - nlaeval_snapshot_ensure_size(out, nlaeval->num_channels); - - for (int i = 0; i < nlaeval->num_channels; i++) { - NlaEvalChannelSnapshot *c_in1 = nlaeval_snapshot_get(in1, i); - NlaEvalChannelSnapshot *c_in2 = nlaeval_snapshot_get(in2, i); - - if (c_in1 || c_in2) { - NlaEvalChannelSnapshot *c_out = out->channels[i]; - - /* Steal the entry from one of the input snapshots. */ - if (c_out == NULL) { - if (c_in1 != NULL) { - c_out = c_in1; - in1->channels[i] = NULL; - } - else { - c_out = c_in2; - in2->channels[i] = NULL; - } - } - - if (c_in1 == NULL) { - c_in1 = nlaeval_snapshot_find_channel(in1->base, c_out->channel); - } - if (c_in2 == NULL) { - c_in2 = nlaeval_snapshot_find_channel(in2->base, c_out->channel); - } - - out->channels[i] = c_out; - - for (int j = 0; j < c_out->length; j++) { - c_out->values[j] = c_in1->values[j] * (1.0f - alpha) + c_in2->values[j] * alpha; - } - } - } - - nlaeval_snapshot_free_data(in1); - nlaeval_snapshot_free_data(in2); -} - /* ---------------------- */ /* F-Modifier stack joining/separation utilities - * should we generalize these for BLI_listbase.h interface? */ @@ -1910,8 +1861,13 @@ static void nlastrip_evaluate_transition(PointerRNA *ptr, nlastrip_evaluate( ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot2, anim_eval_context, flush_to_original); - /* accumulate temp-buffer and full-buffer, using the 'real' strip */ - nlaeval_snapshot_mix_and_free(channels, snapshot, &snapshot1, &snapshot2, nes->strip_time); + /** Replace \a snapshot2 NULL channels with base or default values so all channels blend. */ + nlasnapshot_ensure_channels(channels, &snapshot2); + nlasnapshot_blend( + channels, &snapshot1, &snapshot2, NLASTRIP_MODE_REPLACE, nes->strip_time, snapshot); + + nlaeval_snapshot_free_data(&snapshot1); + nlaeval_snapshot_free_data(&snapshot2); /* unlink this strip's modifiers from the parent's modifiers again */ nlaeval_fmodifiers_split_stacks(&nes->strip->modifiers, modifiers); @@ -2515,6 +2471,13 @@ static void animsys_calculate_nla(PointerRNA *ptr, /* ---------------------- */ +void nlasnapshot_ensure_channels(NlaEvalData *eval_data, NlaEvalSnapshot *snapshot) +{ + LISTBASE_FOREACH (NlaEvalChannel *, nec, &eval_data->channels) { + nlaeval_snapshot_ensure_channel(snapshot, nec); + } +} + /** Blends the \a lower_snapshot with the \a upper_snapshot into \a r_blended_snapshot according * to the given \a upper_blendmode and \a upper_influence. */ void nlasnapshot_blend(NlaEvalData *eval_data, -- cgit v1.2.3