Keep Essential Graphics instance keyframes in the comp so valueAtTime and numKeys see them (#1682)

This commit is contained in:
MarekSpodBiedry committed 2026-10-17 07:49:55 +02:00
1 parent 8f02f52a44
commit 36cc7d91f1
3 files changed
+69 -5

No files matched your search

+54 -1
View File
@@ -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());
}
+7 -3
View File
@@ -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<Keyframe>,
}
/// 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<Project> {
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;
}
+8 -1
View File
@@ -369,12 +369,19 @@ pub fn essential_overrides(ctx: &EvalCtx, layer: &Layer) -> Vec<effectcraft_proj
use effectcraft_project::essential;
let over = essential::overridden(layer);
let Some(g) = essential::group(layer).filter(|_| !over.is_empty()) else { return vec![] };
// Instance keys are in layer time, which is the nested comp's time unless Time Remap or
// Responsive Design - Time (a stretched precomp with protected regions) maps it.
let responsive = (layer.stretch - 100.0).abs() > 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