mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 00:55:43 +00:00
Merge remote-tracking branch 'origin/keyframe-spans-3324' into cache-defaults-3298
This commit is contained in:
commit
b5d5b67ee0
3 files changed
+457
-27
No files matched your search
+135
-27
@@ -222,6 +222,102 @@ const READS_OTHER_FRAMES: &[&str] = &[
|
||||
"ec.paint.paint",
|
||||
];
|
||||
|
||||
/// Does the effect group `g` read its own parameters at times its frame doesn't show, past the
|
||||
/// comp's shutter (`EffectHost::params_at`, `param_at`)? Write-on lays a dab at every Brush
|
||||
/// Spacing from the layer's start with the Brush Position of its time, Radio Waves keeps the
|
||||
/// parameters each wave was born with for its lifespan, and Transform samples past the comp's
|
||||
/// shutter with its own Shutter Angle (up to 720°) or on a stretched layer (`unit_stretch`
|
||||
/// false: it samples in layer time). A key change of theirs then reaches frames far from the key. The time effects and simulations ([`reads_other_frames`])
|
||||
/// read them too, and reach every frame anyway.
|
||||
// ponytail: hand-kept list of the effects that call `params_at`/`param_at` beyond the comp's
|
||||
// shutter; a new one must be added here.
|
||||
fn reads_own_params_elsewhen(g: &PropGroup, unit_stretch: bool) -> bool {
|
||||
let GroupKind::Effect { effect } = &g.kind else { return false };
|
||||
match effect.as_str() {
|
||||
"ec.generate.writeon" | "ec.generate.radiowaves" => true,
|
||||
// (the comp's shutter at 100% stretch is within `Comp::shutter_margin`)
|
||||
"ec.distort.transform" => !unit_stretch || !g.get("useCompositionShutterAngle").is_some_and(|p| p.keys.is_empty() && p.value.as_bool()),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// `a` and `b` have the same header: every field but the children.
|
||||
fn same_head(a: &PropGroup, b: &PropGroup) -> bool {
|
||||
// Every field (no `..`: a new field must be considered here).
|
||||
let PropGroup { uid, match_id, name, kind, enabled, label, children: _ } = a;
|
||||
*uid == b.uid && *match_id == b.match_id && *name == b.name && *kind == b.kind && *enabled == b.enabled && *label == b.label
|
||||
}
|
||||
|
||||
/// Groups nested deeper than this in a layer's property tree count as changed everywhere.
|
||||
const MAX_PROP_DEPTH: usize = 64;
|
||||
|
||||
/// Where a group sits in a layer's property tree, for its audio-only children ([`audio_only`]).
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum Level {
|
||||
Root,
|
||||
/// The root's Effects group.
|
||||
Effects,
|
||||
Inner,
|
||||
}
|
||||
|
||||
/// The pairs of properties that differ between `a` and `b` (groups at `level` of two layers'
|
||||
/// trees, `depth` deep), when all else is the same: the same headers, children and kinds, and
|
||||
/// every difference a property whose value at a time reaches only the frames around that time.
|
||||
/// `None` for any other difference: one in a header, a group added, removed or reordered, or a
|
||||
/// property that is read at other times (inside an effect that reads its own parameters
|
||||
/// elsewhen, [`reads_own_params_elsewhen`]; in the Essential Properties; in the audio something
|
||||
/// draws). Audio-only nodes count only when `heard`, as in [`same_picture_props`]. `unit_stretch`:
|
||||
/// the layer plays at 100%, so layer time and comp time advance alike.
|
||||
fn changed_props<'a>(
|
||||
a: &'a PropGroup,
|
||||
b: &'a PropGroup,
|
||||
level: Level,
|
||||
heard: bool,
|
||||
unit_stretch: bool,
|
||||
depth: usize,
|
||||
out: &mut Vec<(&'a Property, &'a Property)>,
|
||||
) -> Option<()> {
|
||||
if depth > MAX_PROP_DEPTH || !same_head(a, b) {
|
||||
return None;
|
||||
}
|
||||
let audio = |n: &Node| match level {
|
||||
Level::Root => audio_only(n, true),
|
||||
Level::Effects => audio_only(n, false),
|
||||
Level::Inner => false,
|
||||
};
|
||||
let mut x = a.children.iter().filter(|n| heard || !audio(n));
|
||||
let mut y = b.children.iter().filter(|n| heard || !audio(n));
|
||||
loop {
|
||||
let (m, n) = match (x.next(), y.next()) {
|
||||
(None, None) => return Some(()),
|
||||
(Some(m), Some(n)) => (m, n),
|
||||
_ => return None,
|
||||
};
|
||||
if m == n {
|
||||
continue;
|
||||
}
|
||||
// Waveform and spectrum effects draw a stretch of the audio they hear; audio effects
|
||||
// (delay, reverb) carry it on.
|
||||
if audio(m) || audio(n) {
|
||||
return None;
|
||||
}
|
||||
match (m, n) {
|
||||
(Node::Group(g), Node::Group(h)) => {
|
||||
// (the Essential Properties override the nested comp's controls, which reach its
|
||||
// layers by paths this walk doesn't follow: time effects and motion blur there,
|
||||
// mirrored masters; conservatively, their whole span)
|
||||
if matches!(g.kind, GroupKind::Essential { .. }) || reads_own_params_elsewhen(g, unit_stretch) || reads_own_params_elsewhen(h, unit_stretch) {
|
||||
return None;
|
||||
}
|
||||
let level = if level == Level::Root && g.match_id == "effects" { Level::Effects } else { Level::Inner };
|
||||
changed_props(g, h, level, heard, unit_stretch, depth.saturating_add(1), out)?;
|
||||
}
|
||||
(Node::Prop(p), Node::Prop(q)) => out.push((p, q)),
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Switches {
|
||||
/// These switches with Audio, Lock and Shy at their defaults.
|
||||
pub fn pixels(&self) -> Switches {
|
||||
@@ -246,11 +342,6 @@ fn audio_only(n: &Node, root: bool) -> bool {
|
||||
/// `a` and `b` are equal but for their audio-only nodes ([`audio_only`]: the root's Audio group,
|
||||
/// the effects in its Effects group that are audio effects).
|
||||
fn same_picture_props(a: &PropGroup, b: &PropGroup) -> bool {
|
||||
fn head(a: &PropGroup, b: &PropGroup) -> bool {
|
||||
// Every field (no `..`: a new field must be considered here).
|
||||
let PropGroup { uid, match_id, name, kind, enabled, label, children: _ } = a;
|
||||
*uid == b.uid && *match_id == b.match_id && *name == b.name && *kind == b.kind && *enabled == b.enabled && *label == b.label
|
||||
}
|
||||
fn children(a: &PropGroup, b: &PropGroup, root: bool) -> bool {
|
||||
let mut x = a.children.iter().filter(|n| !audio_only(n, root));
|
||||
let mut y = b.children.iter().filter(|n| !audio_only(n, root));
|
||||
@@ -258,7 +349,7 @@ fn same_picture_props(a: &PropGroup, b: &PropGroup) -> bool {
|
||||
match (x.next(), y.next()) {
|
||||
(None, None) => return true,
|
||||
(Some(Node::Group(g)), Some(Node::Group(h))) if root && g.match_id == "effects" && h.match_id == "effects" => {
|
||||
if !(head(g, h) && children(g, h, false)) {
|
||||
if !(same_head(g, h) && children(g, h, false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -267,7 +358,7 @@ fn same_picture_props(a: &PropGroup, b: &PropGroup) -> bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
head(a, b) && children(a, b, true)
|
||||
same_head(a, b) && children(a, b, true)
|
||||
}
|
||||
|
||||
/// `g` (a layer's property tree) without its audio-only nodes ([`same_picture_props`]).
|
||||
@@ -343,16 +434,20 @@ impl Layer {
|
||||
}
|
||||
|
||||
/// The comp-time spans where `self` draws differently than `o` when the two differ only in
|
||||
/// the keyframes of Transform properties (a key's value, ease or interpolation moved in the
|
||||
/// Timeline or Graph Editor): from two keys before the first changed key to two after the
|
||||
/// last (auto-Bezier and continuous tangents reach the neighbouring segments), to the
|
||||
/// layer's in or out point past the first or last key (values hold there). `None` for any
|
||||
/// other difference, a static value, an expression on the layer (it can read the keyed
|
||||
/// property at other times), roving or muted keys, a time remap or a time effect (it reads other
|
||||
/// times): those reach the layer's whole span.
|
||||
/// the keyframes of their properties (a key's value, ease or interpolation moved in the
|
||||
/// Timeline or Graph Editor), anywhere in the property tree: Transform, effects, masks, shape
|
||||
/// contents, text animators, layer styles… Per changed property, from two keys before the
|
||||
/// first changed key to two after the last (auto-Bezier and continuous tangents reach the
|
||||
/// neighbouring segments), to the layer's in or out point past the first or last key (values
|
||||
/// hold there). A keyed value at a time comes from the keys around it, whatever its kind (a
|
||||
/// path, a gradient, Source Text's hold keys, an orientation). `None` for any other
|
||||
/// difference: the tree's structure (a group or effect added, removed or reordered, a
|
||||
/// group's header), a static value, an expression on the layer (it can read the keyed
|
||||
/// property at other times), roving or muted keys, a time remap or a time effect (it reads
|
||||
/// other times), a property read at other times (an effect reading its own parameters
|
||||
/// elsewhen, the Essential Properties, audio something draws, see [`changed_props`]; Position
|
||||
/// under Auto-Orient Along Path; a model's animation clip): those reach the layer's whole span.
|
||||
pub fn keyframe_spans(&self, o: &Layer, with_markers: bool, heard: bool) -> Option<Vec<(Tick, Tick)>> {
|
||||
let transform = |l: &Layer| l.props.group("transform").cloned();
|
||||
let (t1, t0) = (transform(self)?, transform(o)?);
|
||||
let reads_time = |l: &Layer| {
|
||||
l.props.get("timeRemap").is_some()
|
||||
|| l.props.group("effects").is_some_and(|e| {
|
||||
@@ -367,22 +462,35 @@ impl Layer {
|
||||
if reads_time(self) || reads_time(o) || has_expr(self) || has_expr(o) {
|
||||
return None;
|
||||
}
|
||||
// Everything but the Transform group draws the same.
|
||||
let rest = |l: &Layer| {
|
||||
// Everything but the property tree's contents draws the same.
|
||||
let shell = |l: &Layer| {
|
||||
let mut l = l.clone();
|
||||
l.props.children.retain(|n| !matches!(n, Node::Group(g) if g.match_id == "transform"));
|
||||
l.props.children.clear();
|
||||
l
|
||||
};
|
||||
let head = |g: &PropGroup| PropGroup { children: vec![], ..g.clone() };
|
||||
if !rest(self).same_pixels_with(&rest(o), with_markers, heard) || head(&t1) != head(&t0) || t1.children.len() != t0.children.len() {
|
||||
if !shell(self).same_pixels_with(&shell(o), with_markers, heard) {
|
||||
return None;
|
||||
}
|
||||
// Properties read at other times by the renderer: Position under Auto-Orient Along Path
|
||||
// (where the layer holds still it keeps the direction of the last motion, any distance
|
||||
// back) and a model's animation clip (it plays from the key that chose it).
|
||||
fn at<'a>(l: &'a Layer, group: &str, m: &str) -> Option<&'a Property> {
|
||||
l.props.sub(group).and_then(|g| g.get(m))
|
||||
}
|
||||
let along = self.auto_orient == AutoOrient::AlongPath || o.auto_orient == AutoOrient::AlongPath;
|
||||
if (along && ["position", "positionX", "positionY", "positionZ"].iter().any(|m| at(self, "transform", m) != at(o, "transform", m)))
|
||||
|| at(self, "geometryOptions", "animation") != at(o, "geometryOptions", "animation")
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let unit_stretch = (self.effective_stretch() - 100.0).abs() < 1e-9;
|
||||
let mut pairs = Vec::new();
|
||||
changed_props(&self.props, &o.props, Level::Root, heard, unit_stretch, 0, &mut pairs)?;
|
||||
// (a reversed layer plays its first keys last)
|
||||
let reversed = self.effective_stretch() < 0.0;
|
||||
let (early, late) = if reversed { (self.out_point, self.in_point) } else { (self.in_point, self.out_point) };
|
||||
let mut spans = Vec::new();
|
||||
for (n1, n0) in t1.children.iter().zip(&t0.children) {
|
||||
if n1 == n0 {
|
||||
continue;
|
||||
}
|
||||
let (Node::Prop(p1), Node::Prop(p0)) = (n1, n0) else { return None };
|
||||
for (p1, p0) in pairs {
|
||||
let bare = |p: &Property| Property { keys: vec![], value: Value::Scalar(0.0), ..p.clone() };
|
||||
// (muted keys are skipped: the keys around an edit that play can be any distance away)
|
||||
if bare(p1) != bare(p0) || p1.keys.is_empty() || p0.keys.is_empty() || p1.keys.iter().chain(&p0.keys).any(|k| k.roving || k.muted) {
|
||||
@@ -405,7 +513,7 @@ impl Layer {
|
||||
let ahead = if upto >= keys.len() { None } else { keys.get(upto.saturating_add(1).min(keys.len().saturating_sub(1))) };
|
||||
hi = hi.zip(ahead).map(|(a, k)| a.max(k.time));
|
||||
}
|
||||
let (x, y) = (lo.map_or(self.in_point, |t| self.comp_time(t)), hi.map_or(self.out_point, |t| self.comp_time(t)));
|
||||
let (x, y) = (lo.map_or(early, |t| self.comp_time(t)), hi.map_or(late, |t| self.comp_time(t)));
|
||||
let (x, y) = (x.min(y).max(self.in_point), x.max(y).min(self.out_point));
|
||||
if x <= y {
|
||||
spans.push((x, y));
|
||||
|
||||
@@ -523,3 +523,275 @@ fn an_item_inside_a_non_folder_moves_to_the_top_level_when_a_project_is_opened()
|
||||
// Nothing to repair in a sound project.
|
||||
assert!(Project::from_json_repaired(&q.to_json()).expect("opens").1.is_empty());
|
||||
}
|
||||
|
||||
/// #3324: a layer of [`project_with_layer`] with `add` applied and three keys (at 1, 2 and 3 s)
|
||||
/// with `values` on the property at `path`, and that layer with the middle key's value `mid`.
|
||||
fn middle_key_edit(add: impl FnOnce(&mut Ids, &mut crate::Layer), path: &str, values: [Value; 3], mid: Value) -> (crate::Layer, crate::Layer) {
|
||||
let (mut p, cid) = project_with_layer();
|
||||
let mut l = p.comp(cid).unwrap().layers[0].clone();
|
||||
add(&mut Ids(&mut p.next_id), &mut l);
|
||||
l.props.prop_mut(path).unwrap_or_else(|| panic!("{path}")).keys =
|
||||
values.into_iter().zip([1.0, 2.0, 3.0]).map(|(v, s)| Keyframe::new(Tick::from_seconds_f64(s), v)).collect();
|
||||
let mut edited = l.clone();
|
||||
edited.props.prop_mut(path).unwrap().keys[1].value = mid;
|
||||
(l, edited)
|
||||
}
|
||||
|
||||
/// The span of a middle-key edit: from the first key to the last (1 to 3 s).
|
||||
fn first_to_last_key() -> Option<Vec<(Tick, Tick)>> {
|
||||
Some(vec![(Tick::from_seconds_f64(1.0), Tick::from_seconds_f64(3.0))])
|
||||
}
|
||||
|
||||
/// An effect instance as `effects::instantiate` builds it: `params` under its group, or under a
|
||||
/// `master` group (Exposure's `master/exposure`).
|
||||
fn effect(ids: &mut Ids, id: &str, params: Vec<crate::Property>) -> crate::PropGroup {
|
||||
let mut fx = ids.group(id, id);
|
||||
fx.kind = crate::GroupKind::Effect { effect: id.into() };
|
||||
for p in params {
|
||||
fx.children.push(p.into());
|
||||
}
|
||||
fx
|
||||
}
|
||||
|
||||
fn exposure(ids: &mut Ids) -> crate::PropGroup {
|
||||
let master = ids.group("master", "Master").with(ids.prop("exposure", "Exposure", Value::Scalar(0.0)));
|
||||
let mut fx = effect(ids, "ec.color.exposure", vec![]);
|
||||
fx.children.push(master.into());
|
||||
fx
|
||||
}
|
||||
|
||||
fn add_effect(l: &mut crate::Layer, fx: crate::PropGroup) {
|
||||
l.props.sub_mut("effects").unwrap().children.push(fx.into());
|
||||
}
|
||||
|
||||
fn scalars(v: [f64; 3]) -> [Value; 3] {
|
||||
v.map(Value::Scalar)
|
||||
}
|
||||
|
||||
/// A key edit on an effect parameter (inside the effect's Master group) keeps the frames
|
||||
/// outside its keys, as a Transform key edit does (#3324).
|
||||
#[test]
|
||||
fn an_effect_key_edit_reaches_only_its_keys() {
|
||||
let (a, b) = middle_key_edit(|ids, l| add_effect(l, exposure(ids)), "effects/#1/master/exposure", scalars([0.0, 1.0, 0.0]), Value::Scalar(2.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
assert_eq!(a.keyframe_spans(&b, true, false), first_to_last_key());
|
||||
}
|
||||
|
||||
/// A key edit on a mask's path (a shape value) keeps the frames outside its keys (#3324).
|
||||
#[test]
|
||||
fn a_mask_path_key_edit_reaches_only_its_keys() {
|
||||
let path = |w: f64| Value::Path(ShapePath::rect([0.0, 0.0], w, 10.0));
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| {
|
||||
let m = build::mask(ids, "Mask 1", ShapePath::rect([0.0, 0.0], 10.0, 10.0), MaskMode::Add, [255, 0, 0]);
|
||||
l.props.sub_mut("masks").unwrap().children.push(m.into());
|
||||
},
|
||||
"masks/mask#1/path",
|
||||
[path(10.0), path(20.0), path(10.0)],
|
||||
path(40.0),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
}
|
||||
|
||||
/// A key edit on a shape's path inside a shape group keeps the frames outside its keys (#3324).
|
||||
#[test]
|
||||
fn a_shape_path_key_edit_reaches_only_its_keys() {
|
||||
let path = |w: f64| Value::Path(ShapePath::ellipse([0.0, 0.0], w, 10.0));
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| {
|
||||
let shape = build::shape_path(ids, ShapePath::ellipse([0.0, 0.0], 10.0, 10.0));
|
||||
let fill = build::shape_fill(ids, [1.0, 0.0, 0.0, 1.0]);
|
||||
let group = build::shape_group(ids, "Group 1", vec![shape, fill]);
|
||||
l.props.children.push(build::contents(ids).with(group).into());
|
||||
},
|
||||
"contents/group#1/contents/path#1/path",
|
||||
[path(10.0), path(20.0), path(10.0)],
|
||||
path(40.0),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
}
|
||||
|
||||
/// A key edit on a text animator's property keeps the frames outside its keys, and so does one
|
||||
/// on Source Text (hold keys) (#3324).
|
||||
#[test]
|
||||
fn text_key_edits_reach_only_their_keys() {
|
||||
let text = |ids: &mut Ids, l: &mut crate::Layer| {
|
||||
let mut t = build::text(ids, effectcraft_keyframe::TextDoc::plain("Hello"));
|
||||
let opacity = build::text_anim_prop(ids, "opacity").unwrap();
|
||||
let animator = build::text_animator(ids, "Animator 1", vec![opacity]);
|
||||
t.sub_mut("animators").unwrap().children.push(animator.into());
|
||||
l.props.children.push(t.into());
|
||||
};
|
||||
let (a, b) = middle_key_edit(text, "text/animators/animator#1/properties/opacity", scalars([100.0, 0.0, 100.0]), Value::Scalar(50.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
let doc = |s: &str| Value::Text(Box::new(effectcraft_keyframe::TextDoc::plain(s)));
|
||||
let (a, b) = middle_key_edit(text, "text/sourceText", [doc("a"), doc("b"), doc("c")], doc("B"));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
}
|
||||
|
||||
/// An expression anywhere on the layer can read the keyed property at other times: an effect key
|
||||
/// edit then reaches the layer's whole span (#3324).
|
||||
#[test]
|
||||
fn an_expression_elsewhere_on_the_layer_keeps_the_whole_span() {
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| {
|
||||
add_effect(l, exposure(ids));
|
||||
l.props.prop_mut("transform/rotation").unwrap().expr = Some(crate::Expression { text: "time * 10".into(), enabled: true });
|
||||
},
|
||||
"effects/#1/master/exposure",
|
||||
scalars([0.0, 1.0, 0.0]),
|
||||
Value::Scalar(2.0),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
}
|
||||
|
||||
/// A change of the tree's structure reaches the layer's whole span: an effect added (even beside
|
||||
/// a key edit), and a group header (an effect switched off) (#3324).
|
||||
#[test]
|
||||
fn an_effect_added_or_switched_off_keeps_the_whole_span() {
|
||||
let (a, b) = middle_key_edit(|ids, l| add_effect(l, exposure(ids)), "effects/#1/master/exposure", scalars([0.0, 1.0, 0.0]), Value::Scalar(2.0));
|
||||
let mut added = a.clone();
|
||||
add_effect(&mut added, effect(&mut Ids(&mut 10_000), "ec.channel.invert", vec![]));
|
||||
assert_eq!(added.keyframe_spans(&a, true, false), None);
|
||||
let mut both = b.clone();
|
||||
add_effect(&mut both, effect(&mut Ids(&mut 10_000), "ec.channel.invert", vec![]));
|
||||
assert_eq!(both.keyframe_spans(&a, true, false), None);
|
||||
let mut off = b.clone();
|
||||
off.props.group_mut("effects/#1").unwrap().enabled = false;
|
||||
assert_eq!(off.keyframe_spans(&a, true, false), None);
|
||||
}
|
||||
|
||||
/// Effects that read their own parameters at other times (Write-on's dabs since the layer's
|
||||
/// start, Radio Waves' birth values, Transform's own shutter) reach the layer's whole span with a
|
||||
/// key edit of theirs, not with one of another effect on the layer (#3324).
|
||||
#[test]
|
||||
fn effects_reading_their_parameters_elsewhen_keep_the_whole_span() {
|
||||
let v2 = |x: f64| Value::Vec2([x, 0.0]);
|
||||
let write_on = |ids: &mut Ids| {
|
||||
let p = ids.prop("brushPosition", "Brush Position", v2(0.0));
|
||||
effect(ids, "ec.generate.writeon", vec![p])
|
||||
};
|
||||
let (a, b) = middle_key_edit(|ids, l| add_effect(l, write_on(ids)), "effects/#1/brushPosition", [v2(0.0), v2(5.0), v2(0.0)], v2(9.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
let radio = |ids: &mut Ids| {
|
||||
let p = ids.prop("producePoint", "Producer Point", v2(0.0));
|
||||
effect(ids, "ec.generate.radiowaves", vec![p])
|
||||
};
|
||||
let (a, b) = middle_key_edit(|ids, l| add_effect(l, radio(ids)), "effects/#1/producePoint", [v2(0.0), v2(5.0), v2(0.0)], v2(9.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
// Transform: its own Shutter Angle reaches past the comp's shutter, the comp's doesn't unless
|
||||
// the layer is stretched (Transform samples its shutter in layer time).
|
||||
for (comp_shutter, stretch, want) in [(false, 100.0, None), (true, 100.0, first_to_last_key()), (true, 200.0, None)] {
|
||||
let transform = |ids: &mut Ids, l: &mut crate::Layer| {
|
||||
let shutter = ids.prop("useCompositionShutterAngle", "Use Composition's Shutter Angle", Value::Bool(comp_shutter));
|
||||
let rotation = ids.prop("rotation", "Rotation", Value::Scalar(0.0));
|
||||
add_effect(l, effect(ids, "ec.distort.transform", vec![shutter, rotation]));
|
||||
l.stretch = stretch;
|
||||
};
|
||||
let (a, b) = middle_key_edit(transform, "effects/#1/rotation", scalars([0.0, 10.0, 0.0]), Value::Scalar(20.0));
|
||||
let want = want.map(|_| vec![(a.comp_time(Tick::from_seconds_f64(1.0)), a.comp_time(Tick::from_seconds_f64(3.0)))]);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), want, "comp shutter {comp_shutter}, stretch {stretch}");
|
||||
}
|
||||
// Another effect's key edit beside a Write-on.
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| {
|
||||
add_effect(l, write_on(ids));
|
||||
add_effect(l, exposure(ids));
|
||||
},
|
||||
"effects/#2/master/exposure",
|
||||
scalars([0.0, 1.0, 0.0]),
|
||||
Value::Scalar(2.0),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
}
|
||||
|
||||
/// The Essential Properties feed a nested comp, and audio something draws (a waveform reads a
|
||||
/// stretch of it): a key edit there reaches the layer's whole span. Audio nothing draws doesn't
|
||||
/// count at all (#3324).
|
||||
#[test]
|
||||
fn essential_properties_and_heard_audio_keep_the_whole_span() {
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| {
|
||||
let mut g = ids.group("essentialProperties", "Essential Properties").with(ids.prop("control1", "Size", Value::Scalar(0.0)));
|
||||
g.kind = crate::GroupKind::Essential { overridden: vec![] };
|
||||
l.props.children.push(g.into());
|
||||
},
|
||||
"essentialProperties/control1",
|
||||
scalars([0.0, 1.0, 0.0]),
|
||||
Value::Scalar(2.0),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| l.props.children.push(build::audio(ids).into()),
|
||||
"audio/levels",
|
||||
[Value::Vec2([0.0; 2]), Value::Vec2([-6.0; 2]), Value::Vec2([0.0; 2])],
|
||||
Value::Vec2([-12.0; 2]),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, true), None, "heard");
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), Some(vec![]), "not heard: the picture is the same");
|
||||
}
|
||||
|
||||
/// A property tree nested deeper than the walk goes counts as changed everywhere (#3324).
|
||||
#[test]
|
||||
fn a_deeply_nested_key_edit_keeps_the_whole_span() {
|
||||
// 100 groups around a property keyed at 1, 2 and 3 s with `mid` in the middle (the same uids
|
||||
// each time).
|
||||
let deep = |mid: f64| {
|
||||
let mut n = 50_000;
|
||||
let ids = &mut Ids(&mut n);
|
||||
let mut x = ids.prop("x", "X", Value::Scalar(0.0));
|
||||
x.keys = [0.0, mid, 0.0].into_iter().zip([1.0, 2.0, 3.0]).map(|(v, s)| Keyframe::new(Tick::from_seconds_f64(s), Value::Scalar(v))).collect();
|
||||
let mut g = ids.group("g", "G").with(x);
|
||||
for _ in 0..100 {
|
||||
g = ids.group("g", "G").with(g);
|
||||
}
|
||||
g
|
||||
};
|
||||
let (p, cid) = project_with_layer();
|
||||
let (mut a, mut b) = (p.comp(cid).unwrap().layers[0].clone(), p.comp(cid).unwrap().layers[0].clone());
|
||||
a.props.children.push(deep(1.0).into());
|
||||
b.props.children.push(deep(2.0).into());
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
// (a Transform key edit beside the same deep tree keeps its span)
|
||||
let (a, b) = middle_key_edit(|_, l| l.props.children.push(deep(1.0).into()), "transform/opacity", scalars([100.0, 0.0, 100.0]), Value::Scalar(50.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key());
|
||||
}
|
||||
|
||||
/// On a reversed layer (negative stretch) the first keys play last: an edit of the first key
|
||||
/// reaches from the next keys' time to the out point, not from the in point (#3324).
|
||||
#[test]
|
||||
fn a_first_key_edit_on_a_reversed_layer_reaches_the_out_point() {
|
||||
// (a layer from 0 to 10 s reversed: start 10 s, so layer time t shows at 10 - t)
|
||||
let reversed = |_: &mut Ids, l: &mut crate::Layer| (l.stretch, l.start_time) = (-100.0, Tick::from_seconds_f64(10.0));
|
||||
let (a, _) = middle_key_edit(reversed, "transform/opacity", scalars([100.0, 0.0, 100.0]), Value::Scalar(0.0));
|
||||
let mut b = a.clone();
|
||||
b.props.prop_mut("transform/opacity").unwrap().keys[0].value = Value::Scalar(50.0);
|
||||
let spans = b.keyframe_spans(&a, true, false).unwrap();
|
||||
let (s, e) = spans[0];
|
||||
assert_eq!(spans.len(), 1);
|
||||
// Keys at layer 1, 2, 3 s show at 9, 8, 7 s; the first key's edit reaches 7 s (its second key
|
||||
// after) through the out point.
|
||||
assert_eq!((s, e), (Tick::from_seconds_f64(7.0), a.out_point), "{spans:?}");
|
||||
}
|
||||
|
||||
/// The renderer reads some properties at other times: Position under Auto-Orient Along Path (a
|
||||
/// still layer keeps its last direction of travel) and a model's animation clip (it plays from the
|
||||
/// key that chose it). Their key edits reach the layer's whole span (#3324).
|
||||
#[test]
|
||||
fn properties_the_renderer_reads_elsewhen_keep_the_whole_span() {
|
||||
let v3 = |x: f64| Value::Vec3([x, 0.0, 0.0]);
|
||||
let (a, b) = middle_key_edit(|_, l| l.auto_orient = crate::AutoOrient::AlongPath, "transform/position", [v3(0.0), v3(5.0), v3(9.0)], v3(2.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
let (a, b) = middle_key_edit(|_, _| {}, "transform/position", [v3(0.0), v3(5.0), v3(9.0)], v3(2.0));
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), first_to_last_key(), "without Auto-Orient");
|
||||
let (a, b) = middle_key_edit(
|
||||
|ids, l| {
|
||||
let g = ids.group("geometryOptions", "Geometry Options").with(ids.prop("animation", "Animation", Value::Enum(0)));
|
||||
l.props.children.push(g.into());
|
||||
},
|
||||
"geometryOptions/animation",
|
||||
[Value::Enum(0), Value::Enum(1), Value::Enum(1)],
|
||||
Value::Enum(0),
|
||||
);
|
||||
assert_eq!(b.keyframe_spans(&a, true, false), None);
|
||||
}
|
||||
@@ -2233,6 +2233,56 @@ fn a_keyframe_edit_reaches_only_the_keys_around_it() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A key edit of an effect parameter re-renders only around the keys it changed, as a Transform
|
||||
/// key edit does (#3324): Exposure keyed at frames 30, 60 and 90, its middle key changed. Write-on
|
||||
/// reads its Brush Position at every earlier time (a dab per Brush Spacing since the layer's
|
||||
/// start), so its middle key edit reaches every frame after it. Every frame kept renders as
|
||||
/// before.
|
||||
#[test]
|
||||
fn an_effect_key_edit_reaches_only_the_frames_that_read_it() {
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::project::{LayerId, Value};
|
||||
use effectcraft_engine::render::render_frame;
|
||||
use serde_json::{Value as Json, json};
|
||||
let v2 = |x: f64, y: f64| (json!([x, y]), Value::Vec2([x, y]));
|
||||
let edits = [
|
||||
("Exposure", "master/exposure", [json!(0.0), json!(1.0), json!(0.0)], Value::Scalar(3.0)),
|
||||
("Write-on", "brushPosition", [v2(2.0, 2.0).0, v2(14.0, 14.0).0, v2(2.0, 14.0).0], v2(14.0, 2.0).1),
|
||||
];
|
||||
for (effect, param, values, mid) in edits {
|
||||
let mut s = Session::default();
|
||||
let cid =
|
||||
ItemId(s.execute("comp.new", json!({"name": "A", "width": 16, "height": 16, "duration": 4, "frameRate": 30})).unwrap()["comp"].as_u64().unwrap());
|
||||
let l = s.execute("layer.newSolid", json!({"color": "#808080", "width": 16, "height": 16})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("effect.apply", json!({"layers": [l], "effect": effect})).unwrap();
|
||||
let path = format!("effects/#1/{param}");
|
||||
let fr = s.project.comp(cid).unwrap().frame_rate;
|
||||
for (f, v) in [30, 60, 90].into_iter().zip(values) {
|
||||
let add: Json = json!({"layer": l, "path": path, "time": fr.tick_of(f).seconds(), "value": v});
|
||||
s.execute("prop.addKey", add).unwrap();
|
||||
}
|
||||
let p0 = s.project.clone();
|
||||
let f = Frames::default();
|
||||
let k = |content: u64, frame: i64| FrameKey { content, comp: cid.0, ..key(0, frame, 0) };
|
||||
let id0 = f.content_of(&p0, 1, cid);
|
||||
(0..120).for_each(|i| insert(&f, k(id0, i)));
|
||||
let mut p1 = p0.clone();
|
||||
Arc::make_mut(&mut p1).comp_mut(cid).unwrap().layer_mut(LayerId(l)).unwrap().props.prop_mut(&path).unwrap().keys[1].value = mid;
|
||||
let kept = f.cached_frames(&k(f.content_of(&p1, 2, cid), 0));
|
||||
let same = |i: i64| render_frame(&p0, cid, fr.tick_of(i), 1.0).data == render_frame(&p1, cid, fr.tick_of(i), 1.0).data;
|
||||
assert!(!same(60), "{effect}: the edit shows");
|
||||
assert!(![45, 60, 75].iter().any(|i| kept.contains(i)), "{effect}: {kept:?}");
|
||||
if effect == "Exposure" {
|
||||
assert!((0..=27).chain(93..120).all(|i| kept.contains(&i)), "{effect}: the frames outside the keys stay: {kept:?}");
|
||||
} else {
|
||||
assert!(!same(110) && !kept.contains(&110), "{effect}: the stroke drawn by frame 110 passes the edited key: {kept:?}");
|
||||
}
|
||||
for i in kept {
|
||||
assert!(same(i), "{effect}: kept frame {i} renders differently after the edit");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Music's Audio Levels keep every frame, in RAM and on disk, while the project's expressions
|
||||
/// can't read audio (a wiggle); an expression naming the music's Audio Levels re-renders its layer.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user