From 36cc7d91f10e6892db02568335abf469bc62309c Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Sat, 17 Oct 2026 07:46:15 +0200 Subject: [PATCH 1/5] Keep Essential Graphics instance keyframes in the comp so valueAtTime and numKeys see them (#1682) --- crates/engine/src/tests_essential_more.rs | 55 ++++++++++++++++++++++- crates/project/src/essential.rs | 10 +++-- crates/render/src/lib.rs | 9 +++- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/tests_essential_more.rs b/crates/engine/src/tests_essential_more.rs index a8d8dc808..22b03e8e4 100644 --- a/crates/engine/src/tests_essential_more.rs +++ b/crates/engine/src/tests_essential_more.rs @@ -64,7 +64,7 @@ fn font_and_scale_controls_override_per_instance() { let mut v = vec![]; g.walk("", &mut |_, p| { if let Some(c) = essential::control_of(&p.match_id) { - v.push(essential::Override { control: c, value: p.value.clone() }); + v.push(essential::Override { control: c, value: p.value.clone(), keys: vec![] }); } }); v @@ -102,3 +102,56 @@ fn open_in_essential_graphics_sets_the_primary_comp() { ); assert_eq!(s.execute("essential.list", json!({})).unwrap()["name"], "A"); } + +#[test] +fn instance_keyframes_reach_the_comp_so_expressions_can_look_ahead() { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "frameRate": 30, "duration": 2})).unwrap(); + let inner = s.active_comp_id().unwrap(); + let text = s.execute("layer.newText", json!({"text": "Hi"})).unwrap()["layer"].as_u64().unwrap(); + let ctl = s.execute("essential.addProperty", json!({"layer": text, "path": "transform/opacity"})).unwrap()["controls"][0].as_u64().unwrap(); + let keys = vec![ + effectcraft_keyframe::Keyframe::new(effectcraft_time::Tick::ZERO, KV::Scalar(0.0)), + effectcraft_keyframe::Keyframe::new(effectcraft_time::Tick::from_seconds_f64(1.0), KV::Scalar(100.0)), + ]; + let over = [essential::Override { control: ctl, value: KV::Scalar(25.0), keys: keys.clone() }]; + let p = essential::with_overrides(&s.project, inner, &over).unwrap(); + let pr = p.comp(inner).unwrap().layer(effectcraft_project::LayerId(text)).unwrap().props.prop("transform/opacity").unwrap(); + assert_eq!(pr.keys, keys); + assert_eq!(pr.value, KV::Scalar(25.0)); +} + +#[test] +fn keys_set_on_an_instance_are_passed_to_the_nested_comp_render() { + use effectcraft_project::LayerId; + use effectcraft_time::Tick; + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "frameRate": 30, "duration": 2})).unwrap(); + let inner = s.active_comp_id().unwrap(); + let solid = s.execute("layer.newSolid", json!({"name": "BG", "color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("essential.addProperty", json!({"layer": solid, "path": "transform/opacity"})).unwrap(); + s.execute("comp.new", json!({"name": "Scene", "width": 32, "height": 32, "frameRate": 30, "duration": 2})).unwrap(); + let scene = s.active_comp_id().unwrap(); + let inst = s.execute("layer.addItem", json!({"item": inner.0, "time": 0.0})).unwrap()["layer"].as_u64().unwrap(); + let path = s.execute("essential.instance", json!({"layer": inst})).unwrap()["controls"][0]["path"].as_str().unwrap().to_string(); + s.execute("prop.addKey", json!({"layer": inst, "path": path, "time": 0.0, "value": 0.0})).unwrap(); + s.execute("prop.addKey", json!({"layer": inst, "path": path, "time": 1.0, "value": 100.0})).unwrap(); + // At 0.25 s the nested comp's opacity carries the instance's keys, so it reads the instance's + // value half a second ahead too (valueAtTime), not only the current one. + let nested_opacity = |s: &Session| { + let comp = s.project.comp(scene).unwrap(); + let layer = comp.layer(LayerId(inst)).unwrap(); + let ctx = effectcraft_render::EvalCtx::new(&s.project, scene, comp, Tick::from_seconds_f64(0.25)); + let over = effectcraft_render::essential_overrides(&ctx, layer); + let p = essential::with_overrides(&s.project, inner, &over).unwrap(); + p.comp(inner).unwrap().layer(LayerId(solid)).unwrap().props.prop("transform/opacity").unwrap().clone() + }; + let pr = nested_opacity(&s); + let ahead = s.project.comp(scene).unwrap().layer(LayerId(inst)).unwrap().props.prop(&path).unwrap().value_at(Tick::from_seconds_f64(0.75)); + assert_eq!(pr.keys.len(), 2); + assert_eq!(pr.value_at(Tick::from_seconds_f64(0.75)), ahead); + assert_ne!(pr.value_at(Tick::from_seconds_f64(0.75)), pr.value_at(Tick::from_seconds_f64(0.25))); + // With Time Remap the instance's layer time is not the nested comp's time: only the value. + s.execute("layer.enableTimeRemap", json!({"layers": [inst]})).unwrap(); + assert!(nested_opacity(&s).keys.is_empty()); +} diff --git a/crates/project/src/essential.rs b/crates/project/src/essential.rs index 3d851f902..5cc21de31 100644 --- a/crates/project/src/essential.rs +++ b/crates/project/src/essential.rs @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize}; use crate::props::{GroupKind, Node, ParamUi, PropGroup, Property, Uid}; -use crate::{ItemId, ItemKind, Layer, LayerId, LayerSource, Project, Value}; +use crate::{ItemId, ItemKind, Keyframe, Layer, LayerId, LayerSource, Project, Value}; /// Match id of the Essential Properties group on precomp layers. pub const GROUP: &str = "essential"; @@ -652,10 +652,14 @@ pub fn sync_project(before: &Project, after: &mut Project) { pub struct Override { pub control: u64, pub value: Value, + /// The instance property's keyframes, already in the nested comp's time. Empty when the + /// property is not keyed (or its keys can't be mapped); expressions in the comp then see + /// only `value`. + pub keys: Vec, } /// The project as an instance of `comp` renders it: each overridden control's source property -/// set to the instance value (keyframes dropped; its expression, if any, still applies) and +/// set to the instance value and keyframes (its expression, if any, still applies) and /// replaced media swapped in. `None` when nothing applies. pub fn with_overrides(project: &Project, comp: ItemId, overrides: &[Override]) -> Option { let eg = project.comp(comp)?.essential.clone()?; @@ -683,7 +687,7 @@ pub fn with_overrides(project: &Project, comp: ItemId, overrides: &[Override]) - EgKind::Property { .. } => { for (layer, prop) in ctl.kind.targets() { if let Some(pr) = c.layer_mut(layer).and_then(|l| l.props.find_mut(prop)) { - pr.keys.clear(); + pr.keys = o.keys.clone(); pr.value = o.value.clone(); any = true; } diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index cfefd02db..b94cdac2f 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -369,12 +369,19 @@ pub fn essential_overrides(ctx: &EvalCtx, layer: &Layer) -> Vec 1e-9 + && matches!(layer.source, LayerSource::Comp { item } if ctx.project.comp(item).is_some_and(|nc| !eval::protected_regions(nc).is_empty())); + let same_time = layer.props.get("timeRemap").is_none() && !responsive; let mut out = vec![]; g.walk("", &mut |_, p| { if over.contains(&p.uid) && let Some(control) = essential::control_of(&p.match_id) { - out.push(essential::Override { control, value: ctx.value(layer, p) }); + // An expression on the instance property replaces its keys. + let keys = if same_time && !p.has_expression() { p.keys.clone() } else { vec![] }; + out.push(essential::Override { control, value: ctx.value(layer, p), keys }); } }); out From c6e91da8bbfd9e5862c00616108aee0e0b6ef7f5 Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:39:52 +0200 Subject: [PATCH 2/5] Map Essential Graphics instance keys into each target layer's time (#1682) --- crates/engine/src/tests_essential_more.rs | 100 ++++++++++++++++++++++ crates/project/src/essential.rs | 37 ++++++-- 2 files changed, 132 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/tests_essential_more.rs b/crates/engine/src/tests_essential_more.rs index 22b03e8e4..32f8ac4a6 100644 --- a/crates/engine/src/tests_essential_more.rs +++ b/crates/engine/src/tests_essential_more.rs @@ -155,3 +155,103 @@ fn keys_set_on_an_instance_are_passed_to_the_nested_comp_render() { s.execute("layer.enableTimeRemap", json!({"layers": [inst]})).unwrap(); assert!(nested_opacity(&s).keys.is_empty()); } + +/// Inner comp with two opacity-exposed solids (the second linked to the first's control), an +/// instance of it in Scene keyed 0 -> 100 over 0..1 s. `timing` sets each solid's start (s) and +/// stretch (%). Returns the pieces the checks below need. +fn keyed_instance(timing: [(f64, f64); 2]) -> (Session, effectcraft_project::ItemId, effectcraft_project::ItemId, [u64; 2], u64) { + use effectcraft_project::LayerId; + use effectcraft_time::Tick; + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "frameRate": 30, "duration": 4})).unwrap(); + let inner = s.active_comp_id().unwrap(); + let a = s.execute("layer.newSolid", json!({"name": "A", "color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap(); + let ctl = s.execute("essential.addProperty", json!({"layer": a, "path": "transform/opacity"})).unwrap()["controls"][0].as_u64().unwrap(); + let b = s.execute("layer.newSolid", json!({"name": "B", "color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("essential.linkProperty", json!({"control": ctl, "layer": b, "path": "transform/opacity"})).unwrap(); + for (id, (start, stretch)) in [a, b].into_iter().zip(timing) { + let l = std::sync::Arc::make_mut(&mut s.project).comp_mut(inner).unwrap().layer_mut(LayerId(id)).unwrap(); + l.start_time = Tick::from_seconds_f64(start); + l.stretch = stretch; + } + s.execute("comp.new", json!({"name": "Scene", "width": 32, "height": 32, "frameRate": 30, "duration": 4})).unwrap(); + let scene = s.active_comp_id().unwrap(); + let inst = s.execute("layer.addItem", json!({"item": inner.0, "time": 0.0})).unwrap()["layer"].as_u64().unwrap(); + let path = s.execute("essential.instance", json!({"layer": inst})).unwrap()["controls"][0]["path"].as_str().unwrap().to_string(); + s.execute("prop.addKey", json!({"layer": inst, "path": path, "time": 0.0, "value": 0.0})).unwrap(); + s.execute("prop.addKey", json!({"layer": inst, "path": path, "time": 1.0, "value": 100.0})).unwrap(); + (s, scene, inner, [a, b], inst) +} + +/// Opacity of `solid` inside Inner as the instance renders it at nested time `t`, and the +/// overridden property itself (its keys are what `numKeys` / `valueAtTime` read). +fn rendered( + s: &Session, + scene: effectcraft_project::ItemId, + inner: effectcraft_project::ItemId, + inst: u64, + solid: u64, + t: f64, +) -> (f64, effectcraft_project::Property) { + use effectcraft_project::LayerId; + use effectcraft_time::Tick; + let comp = s.project.comp(scene).unwrap(); + let layer = comp.layer(LayerId(inst)).unwrap(); + let ctx = effectcraft_render::EvalCtx::new(&s.project, scene, comp, Tick::from_seconds_f64(t)); + let over = effectcraft_render::essential_overrides(&ctx, layer); + let p = essential::with_overrides(&s.project, inner, &over).unwrap(); + let ic = p.comp(inner).unwrap(); + let il = ic.layer(LayerId(solid)).unwrap(); + let pr = il.props.prop("transform/opacity").unwrap().clone(); + let ictx = effectcraft_render::EvalCtx::new(&p, inner, ic, Tick::from_seconds_f64(t)); + (ictx.value(il, &pr).as_f64(), pr) +} + +#[test] +fn instance_keys_follow_a_nested_layer_that_starts_late() { + use effectcraft_time::Tick; + let (s, scene, inner, [a, _], inst) = keyed_instance([(0.5, 100.0), (0.0, 100.0)]); + // The instance reads 75 at 0.75 s; the layer starting at 0.5 s must too, not 25. + let (v, pr) = rendered(&s, scene, inner, inst, a, 0.75); + assert!((v - 75.0).abs() < 1e-6, "rendered {v}"); + assert_eq!(pr.keys.len(), 2); + // Layer time: the 0 s and 1 s keys sit at -0.5 s and 0.5 s. + assert_eq!(pr.keys[0].time, Tick::from_seconds_f64(-0.5)); + assert_eq!(pr.keys[1].time, Tick::from_seconds_f64(0.5)); + // What valueAtTime reads: layer time 0.5 s is the end key, -0.5 s the start key. + assert_eq!(pr.value_at(Tick::from_seconds_f64(0.5)), KV::Scalar(100.0)); + assert_eq!(pr.value_at(Tick::from_seconds_f64(-0.5)), KV::Scalar(0.0)); +} + +#[test] +fn instance_keys_follow_a_stretched_nested_layer() { + use effectcraft_time::Tick; + let (s, scene, inner, [a, _], inst) = keyed_instance([(0.0, 200.0), (0.0, 100.0)]); + // Stretched to 200 %: nested time 0.5 s is layer time 0.25 s. + let (v, pr) = rendered(&s, scene, inner, inst, a, 0.5); + assert!((v - 50.0).abs() < 1e-6, "rendered {v}"); + assert_eq!(pr.keys.len(), 2); + assert_eq!(pr.keys[1].time, Tick::from_seconds_f64(0.5)); + assert_eq!(pr.value_at(Tick::from_seconds_f64(0.5)), KV::Scalar(100.0)); + // Offset and stretch together: starts at 0.25 s, 50 %: nested 0.5 s is layer time 0.5 s. + let (s, scene, inner, [a, _], inst) = keyed_instance([(0.25, 50.0), (0.0, 100.0)]); + let (v, pr) = rendered(&s, scene, inner, inst, a, 0.5); + assert!((v - 50.0).abs() < 1e-6, "rendered {v}"); + assert_eq!(pr.keys[0].time, Tick::from_seconds_f64(-0.5)); + assert_eq!(pr.keys[1].time, Tick::from_seconds_f64(1.5)); +} + +#[test] +fn one_control_with_targets_of_different_timing_stays_in_step() { + let (s, scene, inner, [a, b], inst) = keyed_instance([(0.5, 100.0), (0.0, 200.0)]); + for t in [0.2, 0.6, 0.75, 0.9] { + let (va, pa) = rendered(&s, scene, inner, inst, a, t); + let (vb, pb) = rendered(&s, scene, inner, inst, b, t); + let want = t * 100.0; + assert!((va - want).abs() < 1e-6, "A at {t}: {va}"); + assert!((vb - want).abs() < 1e-6, "B at {t}: {vb}"); + // Each target carries the keys in its own time. + assert_ne!(pa.keys[0].time, pb.keys[0].time); + assert_ne!(pa.keys[1].time, pb.keys[1].time); + } +} diff --git a/crates/project/src/essential.rs b/crates/project/src/essential.rs index 5cc21de31..021c1a8fc 100644 --- a/crates/project/src/essential.rs +++ b/crates/project/src/essential.rs @@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize}; use crate::props::{GroupKind, Node, ParamUi, PropGroup, Property, Uid}; use crate::{ItemId, ItemKind, Keyframe, Layer, LayerId, LayerSource, Project, Value}; +use effectcraft_time::Tick; /// Match id of the Essential Properties group on precomp layers. pub const GROUP: &str = "essential"; @@ -647,14 +648,35 @@ pub fn sync_project(before: &Project, after: &mut Project) { after.next_id = after.next_id.max(next); } +/// Keys given in comp time, in the time of a layer that starts at `start` and is stretched to +/// `stretch` percent. Empty when the stretch is not a usable factor. +fn keys_in_layer_time(keys: &[Keyframe], start: Tick, stretch: f64) -> Vec { + if stretch.is_finite() && stretch > 0.0 { keys.iter().map(|k| key_in_layer_time(k, start, stretch)).collect() } else { vec![] } +} + +/// A key given in comp time, moved into the layer time of a layer that starts at `start` and is +/// stretched to `stretch` percent (the inverse of `Layer::comp_time`). Ease speeds are per +/// second, so they scale with the time axis; influences are fractions of the segment and stay. +fn key_in_layer_time(k: &Keyframe, start: Tick, stretch: f64) -> Keyframe { + let d = k.time - start; + let mut k = k.clone(); + k.time = if (stretch - 100.0).abs() < 1e-9 { d } else { Tick((d.0 as f64 * 100.0 / stretch) as i64) }; + if (stretch - 100.0).abs() >= 1e-9 { + for e in k.in_ease.iter_mut().chain(k.out_ease.iter_mut()) { + e.speed *= stretch / 100.0; + } + } + k +} + /// One instance override: the control and the value it takes in this instance. #[derive(Clone, Debug, PartialEq)] pub struct Override { pub control: u64, pub value: Value, - /// The instance property's keyframes, already in the nested comp's time. Empty when the - /// property is not keyed (or its keys can't be mapped); expressions in the comp then see - /// only `value`. + /// The instance property's keyframes, in the nested comp's time (`with_overrides` moves them + /// into each target layer's time). Empty when the property is not keyed (or its keys can't + /// be mapped); expressions in the comp then see only `value`. pub keys: Vec, } @@ -686,8 +708,13 @@ pub fn with_overrides(project: &Project, comp: ItemId, overrides: &[Override]) - } EgKind::Property { .. } => { for (layer, prop) in ctl.kind.targets() { - if let Some(pr) = c.layer_mut(layer).and_then(|l| l.props.find_mut(prop)) { - pr.keys = o.keys.clone(); + if let Some(l) = c.layer_mut(layer) { + let (start, stretch) = (l.start_time, l.stretch); + let Some(pr) = l.props.find_mut(prop) else { continue }; + // The keys are in nested comp time; the property reads them in this + // layer's own time (start offset, stretch). Without a usable mapping + // only the value is set. + pr.keys = keys_in_layer_time(&o.keys, start, stretch); pr.value = o.value.clone(); any = true; } From 102dd8be6c77a28848010e9adefd13ea537e9fa2 Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:42:21 +0200 Subject: [PATCH 3/5] Give the multi-target Essential Graphics test distinct key times; group the Tick import --- crates/engine/src/tests_essential_more.rs | 2 +- crates/project/src/essential.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests_essential_more.rs b/crates/engine/src/tests_essential_more.rs index 32f8ac4a6..720c87e91 100644 --- a/crates/engine/src/tests_essential_more.rs +++ b/crates/engine/src/tests_essential_more.rs @@ -243,7 +243,7 @@ fn instance_keys_follow_a_stretched_nested_layer() { #[test] fn one_control_with_targets_of_different_timing_stays_in_step() { - let (s, scene, inner, [a, b], inst) = keyed_instance([(0.5, 100.0), (0.0, 200.0)]); + let (s, scene, inner, [a, b], inst) = keyed_instance([(0.5, 100.0), (0.25, 200.0)]); for t in [0.2, 0.6, 0.75, 0.9] { let (va, pa) = rendered(&s, scene, inner, inst, a, t); let (vb, pb) = rendered(&s, scene, inner, inst, b, t); diff --git a/crates/project/src/essential.rs b/crates/project/src/essential.rs index 021c1a8fc..cc3b12209 100644 --- a/crates/project/src/essential.rs +++ b/crates/project/src/essential.rs @@ -12,11 +12,11 @@ //! [`sync_project`] keeps the groups in step with the controls (and refreshes the values of //! controls that are not overridden), [`with_overrides`] builds the project an instance renders. +use effectcraft_time::Tick; use serde::{Deserialize, Serialize}; use crate::props::{GroupKind, Node, ParamUi, PropGroup, Property, Uid}; use crate::{ItemId, ItemKind, Keyframe, Layer, LayerId, LayerSource, Project, Value}; -use effectcraft_time::Tick; /// Match id of the Essential Properties group on precomp layers. pub const GROUP: &str = "essential"; From 25cf11493aec2e3ba7811e5a7b5c63e2d99a659e Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Sun, 1 Nov 2026 07:39:48 +0100 Subject: [PATCH 4/5] Keep Essential Graphics instance keys out of nested comps that preserve their frame rate (#1682) --- crates/engine/src/tests/essential_more.rs | 10 ++++++++++ crates/render/src/fx_host.rs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests/essential_more.rs b/crates/engine/src/tests/essential_more.rs index a417d39ff..b3de8359c 100644 --- a/crates/engine/src/tests/essential_more.rs +++ b/crates/engine/src/tests/essential_more.rs @@ -252,6 +252,16 @@ fn one_control_with_targets_of_different_timing_stays_in_step() { } } +#[test] +fn instance_keys_stay_out_of_a_nested_comp_that_preserves_its_frame_rate() { + let (mut s, scene, inner, [a, _], inst) = keyed_instance([(0.0, 100.0), (0.0, 100.0)]); + std::sync::Arc::make_mut(&mut s.project).comp_mut(inner).unwrap().preserve_frame_rate = true; + // The nested time is floored to the nested comp's frames, so only the instance's value goes in. + let (v, pr) = rendered(&s, scene, inner, inst, a, 0.25); + assert!((v - 25.0).abs() < 1e-6, "rendered {v}"); + assert!(pr.keys.is_empty()); +} + /// #1747: through a collapsed precomp, a Text override and a Font override of the same Source /// Text both apply: the Font merges into the overridden text, as `essential::with_overrides` /// does on the flattened path, instead of one entry replacing the other. diff --git a/crates/render/src/fx_host.rs b/crates/render/src/fx_host.rs index 655c01980..c5983ceca 100644 --- a/crates/render/src/fx_host.rs +++ b/crates/render/src/fx_host.rs @@ -184,7 +184,7 @@ fn effect_param<'a>(layer: &'a Layer, effect_index: usize, id: &str) -> Option<& /// Whether an instance's keys are in the nested comp's time, so they can go into the comp as they /// are: not with Time Remap, Responsive Design - Time (a stretched precomp with protected -/// regions). +/// regions) or a nested comp that preserves its frame rate (its time is floored to its own frames). fn keys_in_nested_time(ctx: &EvalCtx, layer: &Layer) -> bool { if layer.props.get("timeRemap").is_some() { return false; @@ -192,7 +192,7 @@ fn keys_in_nested_time(ctx: &EvalCtx, layer: &Layer) -> bool { let LayerSource::Comp { item } = layer.source else { return true }; let Some(nc) = ctx.project.comp(item) else { return true }; let responsive = (layer.stretch - 100.0).abs() > 1e-9 && !super::eval::protected_regions(nc).is_empty(); - !responsive + !responsive && !nc.preserve_frame_rate } /// The Essential Properties overrides of a precomp layer, evaluated at the context time. From 6c3b49d88ba946dd4fb7d60712cbae724549fd74 Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:54:09 +0100 Subject: [PATCH 5/5] Keep Essential Graphics instance keys out of frame-blended layers and collapsed parent overrides (#1682) --- crates/engine/src/tests/essential_more.rs | 47 +++++++++++++++++++++++ crates/render/src/fx_host.rs | 15 +++++--- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/tests/essential_more.rs b/crates/engine/src/tests/essential_more.rs index b3de8359c..c87d36eec 100644 --- a/crates/engine/src/tests/essential_more.rs +++ b/crates/engine/src/tests/essential_more.rs @@ -291,3 +291,50 @@ fn collapsed_instance_merges_text_and_font_overrides() { o => panic!("{o:?}"), } } + +#[test] +fn instance_keys_stay_out_of_a_layer_that_blends_frames() { + let (mut s, scene, inner, [a, _], inst) = keyed_instance([(0.0, 100.0), (0.0, 100.0)]); + { + let comp = std::sync::Arc::make_mut(&mut s.project).comp_mut(scene).unwrap(); + comp.enable_frame_blending = true; + comp.layer_mut(effectcraft_project::LayerId(inst)).unwrap().switches.frame_blend = effectcraft_project::FrameBlend::FrameMix; + } + // Frame Mix renders the nested comp at two other times, so only the instance's current value goes in. + let (v, pr) = rendered(&s, scene, inner, inst, a, 0.25); + assert!((v - 25.0).abs() < 1e-6, "rendered {v}"); + assert!(pr.keys.is_empty()); +} + +/// An override from a collapsed parent reaches the nested instance as a value only: the keys the +/// nested instance property carries itself must not be copied onto its own target. +#[test] +fn collapsed_parent_override_replaces_the_nested_instance_keys() { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "frameRate": 30, "duration": 4})).unwrap(); + let a = s.execute("layer.newSolid", json!({"name": "A", "color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("essential.addProperty", json!({"layer": a, "path": "transform/opacity"})).unwrap(); + s.execute("comp.new", json!({"name": "Mid", "width": 32, "height": 32, "frameRate": 30, "duration": 4})).unwrap(); + let mid = s.active_comp_id().unwrap(); + let inner = s.project.find_by_name("Inner").unwrap().id; + let nested = s.execute("layer.addItem", json!({"item": inner.0, "time": 0.0})).unwrap()["layer"].as_u64().unwrap(); + let path = s.execute("essential.instance", json!({"layer": nested})).unwrap()["controls"][0]["path"].as_str().unwrap().to_string(); + s.execute("prop.addKey", json!({"layer": nested, "path": path, "time": 0.0, "value": 0.0})).unwrap(); + s.execute("prop.addKey", json!({"layer": nested, "path": path, "time": 1.0, "value": 100.0})).unwrap(); + let ctl = s.execute("essential.addProperty", json!({"layer": nested, "path": path})).unwrap()["controls"][0].as_u64().unwrap(); + s.execute("comp.new", json!({"name": "Top", "width": 32, "height": 32, "frameRate": 30, "duration": 4})).unwrap(); + let top = s.active_comp_id().unwrap(); + let inst = s.execute("layer.addItem", json!({"item": mid.0, "time": 0.0})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.setSwitch", json!({"layers": [inst], "switch": "collapse", "value": true})).unwrap(); + s.execute("essential.set", json!({"layer": inst, "control": ctl, "value": 80.0})).unwrap(); + let r = effectcraft_render::Renderer::new(&s.project, &*s.footage, crate::render::RenderOpts::default()); + let ctx = effectcraft_render::EvalCtx::new(&s.project, top, s.project.comp(top).unwrap(), Tick::from_seconds_f64(0.25)); + let layer = ctx.comp.layer(effectcraft_project::LayerId(inst)).unwrap(); + let collapsed = r.collapsed(&ctx, layer).expect("the instance collapses"); + let (_, nctx) = r.collapse_into(&ctx, layer, &collapsed, 1.0).expect("a nested context"); + let nl = nctx.comp.layer(effectcraft_project::LayerId(nested)).unwrap(); + let over = effectcraft_render::essential_overrides(&nctx, nl); + assert_eq!(over.len(), 1); + assert!((over[0].value.as_f64() - 80.0).abs() < 1e-6, "value {:?}", over[0].value); + assert!(over[0].keys.is_empty(), "the nested instance's own keys are stale"); +} diff --git a/crates/render/src/fx_host.rs b/crates/render/src/fx_host.rs index c5983ceca..f15f91c93 100644 --- a/crates/render/src/fx_host.rs +++ b/crates/render/src/fx_host.rs @@ -1,4 +1,5 @@ -use super::{Arc, Buf, EffectHost, EvalCtx, ItemKind, Layer, LayerPixels, LayerSource, Params, Renderer, Tick, three_d}; +use super::frames::frame_blend_mode; +use super::{Arc, Buf, EffectHost, EvalCtx, FrameBlend, ItemKind, Layer, LayerPixels, LayerSource, Params, Renderer, Tick, three_d}; /// Layer parameters and audio for effects (see [`effectcraft_effects::EffectHost`]). What it /// hands out is in effect space (see [`effect_bounds`]): the other layer's for its pixels, the @@ -184,9 +185,11 @@ fn effect_param<'a>(layer: &'a Layer, effect_index: usize, id: &str) -> Option<& /// Whether an instance's keys are in the nested comp's time, so they can go into the comp as they /// are: not with Time Remap, Responsive Design - Time (a stretched precomp with protected -/// regions) or a nested comp that preserves its frame rate (its time is floored to its own frames). +/// regions), a nested comp that preserves its frame rate (its time is floored to its own frames) +/// or a layer with Frame Blending (it renders the nested comp at two other times and mixes them, +/// so keys would pull the next frame's value in early). fn keys_in_nested_time(ctx: &EvalCtx, layer: &Layer) -> bool { - if layer.props.get("timeRemap").is_some() { + if layer.props.get("timeRemap").is_some() || frame_blend_mode(ctx, layer) != FrameBlend::Off { return false; } let LayerSource::Comp { item } = layer.source else { return true }; @@ -206,8 +209,10 @@ pub fn essential_overrides(ctx: &EvalCtx, layer: &Layer) -> Vec