#How do I use Interpolation::CubicSpline?
10 messages ยท Page 1 of 1 (latest)
I have tried having less/more/equal keyframe_stamps than keyframes and I tried using >=4 control points as well.
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?
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?
it mostly comes from https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
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
it's described a bit here: https://docs.rs/bevy/latest/bevy/animation/struct.VariableCurve.html#structfield.keyframes