#How do I use Interpolation::CubicSpline?

10 messages ยท Page 1 of 1 (latest)

cold aspen
#

I want to do a simple Transform animation, I have tried several combinations of keyframe_timestamps and keyframes but they all panic index out of bounds. Settings to Interpolation::Linear works as expected. What could I be doing wrong with the Interpolation::CubicSpline?

#

I have tried having less/more/equal keyframe_stamps than keyframes and I tried using >=4 control points as well.

hybrid sapphire
#

I confirm this is a bug. I used the animated_transform.rs example off the main branch and changed one from Linear into CubicSpline and it crashed with an index out of bounds.

Do you want to submit an issue for this?

hybrid sapphire
#

Hey @modest veldt, we're getting some strange behavior with cubic spline animation. I'm looking at the code here:

            (Interpolation::CubicSpline, Keyframes::Scale(keyframes)) => {
                let Some(ref mut transform) = self.transform else {
                    return;
                };

                let value_start = keyframes[step_start * 3 + 1];
                let tangent_out_start = keyframes[step_start * 3 + 2];
                let tangent_in_end = keyframes[(step_start + 1) * 3];
                let value_end = keyframes[(step_start + 1) * 3 + 1];
                let result = cubic_spline_interpolation(
                    value_start,
                    tangent_out_start,
                    tangent_in_end,
                    value_end,
                    lerp,
                    duration,
                );
                transform.scale = transform.scale.lerp(result, weight);
            }

Am I right that the expected vectors are like this: [???, start0, tangent_out_start0, tangent_in_end0, end0 | start1, tangent_out1, tangent_in1, end1, ...]?

Also are the timestamps expected to be fewer than the number of vectors?

modest veldt
#

For each timestamp stored in the animation sampler, there are three associated keyframe values: in-tangent, property value, and out-tangent.

#

The first in-tangent ๐‘Ž1 and last out-tangent ๐‘๐‘› SHOULD be zeros as they are not used in the spline calculations.

#

so it's [0, value-1, out-tangent-1, in-tangent-2, value-2, out-tangent-2, ..., in-tangent-n, value-n, 0]

#

with n being the number of timestamps