Viewer: a straight motion path has Bezier handles to curve it (#290)
The Position motion path drew a key's spatial handles only where its tangent wasn't zero, and auto-Bezier keys have none at the path's ends, so a two-key path (the usual start) had no handles to pull it into a curve. Auto-Bezier keys now show a handle on such a side too, pointing where the path leaves the key, a third of the way to the next key; dragging it makes the key Bezier with that tangent. Linear keys still show none. Keyframe Interpolation > Spatial Bezier copied those zero tangents, so the keys stayed straight with no handles (and read back as Linear); it now gives them the same handles. The path keeps its shape and timing. The handles come from the new keyframe::spatial_handles. Tests: spatial_bezier_gives_a_straight_path_handles (engine), a_straight_motion_path_has_handles_to_curve_it (ui_viewer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5b05a5ae80
commit
ed5ad56eb5
@@ -299,6 +299,37 @@ pub fn spatial_tangents(keys: &[Keyframe], i: usize) -> ([f64; 3], [f64; 3]) {
|
||||
if key.spatial_auto { auto_spatial(keys, i) } else { (key.spatial_in, key.spatial_out) }
|
||||
}
|
||||
|
||||
/// Spatial tangents of key `i` as motion-path handles: [`spatial_tangents`], with a side that
|
||||
/// has none but a neighbour (the ends of an auto-Bezier path, a straight two-key path) pointing
|
||||
/// where the path leaves the key, toward the segment's next control point, a third of the way to
|
||||
/// the neighbouring key. After Effects shows Bezier handles there to drag the path into a curve.
|
||||
pub fn spatial_handles(keys: &[Keyframe], i: usize) -> ([f64; 3], [f64; 3]) {
|
||||
let (mut tin, mut tout) = spatial_tangents(keys, i);
|
||||
let Some(p) = keys.get(i).map(|k| v3(&k.value)) else { return (tin, tout) };
|
||||
// Toward key `j`'s control point on this segment (its in side when `j` follows `i`).
|
||||
let toward = |j: usize, after: bool| -> Option<[f64; 3]> {
|
||||
let q = v3(&keys.get(j)?.value);
|
||||
let (jin, jout) = spatial_tangents(keys, j);
|
||||
let t = if after { jin } else { jout };
|
||||
let d = [q[0] + t[0] - p[0], q[1] + t[1] - p[1], q[2] + t[2] - p[2]];
|
||||
let dl = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt();
|
||||
let len = ((q[0] - p[0]).powi(2) + (q[1] - p[1]).powi(2) + (q[2] - p[2]).powi(2)).sqrt() / 3.0;
|
||||
(dl > 1e-9).then(|| d.map(|v| v * len / dl))
|
||||
};
|
||||
let none = |t: [f64; 3]| t == [0.0; 3];
|
||||
if none(tout)
|
||||
&& let Some(v) = toward(i + 1, true)
|
||||
{
|
||||
tout = v;
|
||||
}
|
||||
if none(tin)
|
||||
&& let Some(v) = i.checked_sub(1).and_then(|j| toward(j, false))
|
||||
{
|
||||
tin = v;
|
||||
}
|
||||
(tin, tout)
|
||||
}
|
||||
|
||||
/// Effective temporal ease of key `i` for dimension `d` (auto-Bezier keys get the neighbour slope).
|
||||
fn effective_ease(keys: &[Keyframe], i: usize, d: usize, spatial: bool, out: bool) -> Ease {
|
||||
let k = &keys[i];
|
||||
|
||||
Reference in New Issue
Block a user