mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-02 20:20:57 -05:00
Skip muted 3D Orientation keys when rotating a layer (#4279)
* Respect muted keys when evaluating 3D Orientation (#4270) * Format the automatic Orientation ease fallback
This commit is contained in:
1 parent
5d6d457187
commit
1f51eaadc7
2 files changed
+38
-8
No files matched your search
@@ -570,17 +570,25 @@ fn evaluate_active<K: Borrow<Keyframe>>(keys: &[K], t: Tick, spatial: bool) -> O
|
||||
/// keys ([`effectcraft_geom::orientation_slerp`]) instead of blending each angle. Speeds are
|
||||
/// degrees per second along that arc. Values other than 3D vectors evaluate as [`evaluate`].
|
||||
pub fn evaluate_orientation(keys: &[Keyframe], t: Tick) -> Option<Value> {
|
||||
let first = keys.first()?;
|
||||
if !keys.iter().any(|k| k.muted) {
|
||||
return evaluate_orientation_active(keys, t);
|
||||
}
|
||||
let active: Vec<_> = keys.iter().filter(|k| !k.muted).collect();
|
||||
evaluate_orientation_active(&active, t)
|
||||
}
|
||||
|
||||
fn evaluate_orientation_active<K: Borrow<Keyframe>>(keys: &[K], t: Tick) -> Option<Value> {
|
||||
let first = keys.first()?.borrow();
|
||||
if keys.len() == 1 || t <= first.time {
|
||||
return Some(first.value.clone());
|
||||
}
|
||||
let last = keys.last()?;
|
||||
let last = keys.last()?.borrow();
|
||||
if t >= last.time {
|
||||
return Some(last.value.clone());
|
||||
}
|
||||
let i = keys.partition_point(|k| k.time <= t).checked_sub(1)?;
|
||||
let (a, b) = (keys.get(i)?, keys.get(i + 1)?);
|
||||
let (Value::Vec3(va), Value::Vec3(vb)) = (&a.value, &b.value) else { return Some(segment_value(keys, i, t, false)) };
|
||||
let i = keys.partition_point(|k| k.borrow().time <= t).checked_sub(1)?;
|
||||
let (a, b) = (keys.get(i)?.borrow(), keys.get(i + 1)?.borrow());
|
||||
let (Value::Vec3(va), Value::Vec3(vb)) = (&a.value, &b.value) else { return Some(segment_value_of(keys, i, t, false)) };
|
||||
if a.out_interp == Interp::Hold {
|
||||
return Some(a.value.clone());
|
||||
}
|
||||
@@ -601,14 +609,16 @@ pub fn evaluate_orientation(keys: &[Keyframe], t: Tick) -> Option<Value> {
|
||||
let side = |j: usize, out: bool| -> Ease {
|
||||
// A linear side keeps the segment's average speed at the same influence as in
|
||||
// `segment_value` (and a missing key, unreachable here, is treated as one).
|
||||
let Some(k) = keys.get(j) else { return Ease { speed: arc / dur, influence: LINEAR_SIDE_INFLUENCE } };
|
||||
let Some(k) = keys.get(j).map(Borrow::borrow) else { return Ease { speed: arc / dur, influence: LINEAR_SIDE_INFLUENCE } };
|
||||
let linear = if out { lin_out } else { lin_in };
|
||||
if linear {
|
||||
return Ease { speed: arc / dur, influence: LINEAR_SIDE_INFLUENCE };
|
||||
}
|
||||
if k.auto_bezier && j > 0 && j + 1 < keys.len() {
|
||||
let span = (secs(keys[j + 1].time) - secs(keys[j - 1].time)).max(1e-12);
|
||||
let (Value::Vec3(p), Value::Vec3(n)) = (&keys[j - 1].value, &keys[j + 1].value) else { return Ease { speed: arc / dur, influence: 1.0 / 6.0 } };
|
||||
let span = (secs(keys[j + 1].borrow().time) - secs(keys[j - 1].borrow().time)).max(1e-12);
|
||||
let (Value::Vec3(p), Value::Vec3(n)) = (&keys[j - 1].borrow().value, &keys[j + 1].borrow().value) else {
|
||||
return Ease { speed: arc / dur, influence: 1.0 / 6.0 };
|
||||
};
|
||||
return Ease { speed: effectcraft_geom::orientation_arc_deg((*p).into(), (*n).into()) / span, influence: 1.0 / 6.0 };
|
||||
}
|
||||
let list = if out { &k.out_ease } else { &k.in_ease };
|
||||
|
||||
@@ -127,6 +127,26 @@ fn keyed_orientation_matches_after_effects() {
|
||||
assert_eq!(evaluate_orientation(&[], s(0.5)), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orientation_uses_only_unmuted_keys_for_rotations_and_auto_ease() {
|
||||
let mut keys: Vec<_> = [15.0, 0.0, 90.0, 20.0, 80.0, 60.0]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, angle)| {
|
||||
let mut k = Keyframe::new(s(i as f64), Value::Vec3([0.0, angle, 0.0])).eased();
|
||||
k.auto_bezier = true;
|
||||
k.muted = matches!(i, 0 | 2 | 5);
|
||||
k
|
||||
})
|
||||
.collect();
|
||||
let active: Vec<_> = keys.iter().filter(|k| !k.muted).cloned().collect();
|
||||
for t in [0.0, 1.5, 2.0, 2.5, 3.5, 5.0] {
|
||||
assert_eq!(evaluate_orientation(&keys, s(t)), evaluate_orientation(&active, s(t)), "at {t}");
|
||||
}
|
||||
keys.iter_mut().for_each(|k| k.muted = true);
|
||||
assert_eq!(evaluate_orientation(&keys, s(2.0)), None);
|
||||
}
|
||||
|
||||
/// M13.15: agents set gradients as plain JSON, not only the tagged form `get` returns.
|
||||
#[test]
|
||||
fn gradients_coerce_from_plain_json() {
|
||||
|
||||
Reference in new issue
Block a user