Reduce Project and Remove Unused Footage keep the media an Essential Graphics override shows (#4129) (#4164)

This commit is contained in:
Anubhav-Rai authored and GitHub committed 2026-11-28 07:55:33 +01:00
1 parent 988a7a7685
commit ffc0ad89da
3 files changed
+55 -13

No files matched your search

+8 -2
View File
@@ -287,6 +287,12 @@ fn new_comp_from_selection(s: &mut Session, p: &Value) -> Result<Value> {
// ---------------------------------------------------------------- dependencies
/// The items a comp's layers use directly: their sources and the media their Essential Properties
/// swap in.
fn layer_items(c: &Comp) -> impl Iterator<Item = ItemId> {
c.layers.iter().flat_map(|l| l.source.item().into_iter().chain(effectcraft_project::essential::instance_media(l)))
}
/// Items used (transitively) by `roots`.
fn used_items(proj: &Project, roots: &[ItemId]) -> BTreeSet<ItemId> {
let mut seen = BTreeSet::new();
@@ -296,7 +302,7 @@ fn used_items(proj: &Project, roots: &[ItemId]) -> BTreeSet<ItemId> {
continue;
}
if let Some(c) = proj.comp(i) {
stack.extend(c.layers.iter().filter_map(|l| l.source.item()));
stack.extend(layer_items(c));
}
// Parent folders stay so the structure is kept.
if let Some(parent) = proj.item(i).and_then(|x| x.parent) {
@@ -307,7 +313,7 @@ fn used_items(proj: &Project, roots: &[ItemId]) -> BTreeSet<ItemId> {
}
fn referenced_sources(proj: &Project) -> BTreeSet<ItemId> {
proj.comps().flat_map(|(_, c)| c.layers.iter().filter_map(|l| l.source.item())).collect()
proj.comps().flat_map(|(_, c)| layer_items(c)).collect()
}
fn remove_unused(s: &mut Session, _: &Value) -> Result<Value> {
+29
View File
@@ -367,6 +367,35 @@ fn media_replacement_swaps_footage_per_instance() {
assert!(center(&s, main)[0] > 0.99);
}
/// #4129: media only an instance's override names is in use, so cleaning the project keeps it.
#[test]
fn cleaning_the_project_keeps_replacement_media() {
for command in ["file.reduceProject", "file.removeUnusedFootage"] {
let mut s = Session::default();
let foot = |s: &mut Session| ItemId(s.execute("file.importPlaceholder", json!({})).unwrap()["item"].as_u64().unwrap());
let (default, replacement, unused) = (foot(&mut s), foot(&mut s), foot(&mut s));
s.execute("comp.new", json!({"name": "Slot", "width": 16, "height": 16, "frameRate": 30, "duration": 1})).unwrap();
let slot = s.active_comp_id().unwrap();
let clip = s.execute("layer.addItem", json!({"item": default.0})).unwrap()["layer"].as_u64().unwrap();
let media = s.execute("essential.addMedia", json!({"layer": clip})).unwrap()["control"].as_u64().unwrap();
s.execute("comp.new", json!({"name": "Main", "width": 16, "height": 16, "frameRate": 30, "duration": 1})).unwrap();
let main = s.active_comp_id().unwrap();
let instance = s.execute("layer.addItem", json!({"item": slot.0})).unwrap()["layer"].as_u64().unwrap();
s.execute("essential.set", json!({"layer": instance, "control": media, "item": replacement.0})).unwrap();
s.state.project_selection = vec![main];
s.execute(command, json!({})).unwrap();
for (what, item, kept) in [("default", default, true), ("replacement", replacement, true), ("unused", unused, false)] {
assert_eq!(s.project.item(item).is_some(), kept, "{command}: {what}");
}
// Reverted, nothing uses the replacement any more.
s.execute("essential.revert", json!({"layer": instance})).unwrap();
s.state.project_selection = vec![main];
s.execute(command, json!({})).unwrap();
assert!(s.project.item(replacement).is_none(), "{command}: reverted");
assert!(s.project.item(default).is_some(), "{command}: default");
}
}
/// #1747: a collapsed precomp with an Essential Property override must keep drawing its nested
/// layers past the precomp's frame instead of falling back to a flattened, clipped frame.
#[test]
+18 -11
View File
@@ -843,6 +843,23 @@ fn offset_layer(l: &mut Layer, o: u64) {
group(&mut l.props, o, false);
}
/// The items the media controls of an instance layer show: its replacement media, or the source
/// comp's own media where it overrides nothing.
pub fn instance_media(layer: &Layer) -> Vec<ItemId> {
let mut out = vec![];
if let Some(g) = group(layer) {
g.walk("", &mut |_, p| {
if matches!(p.ui, ParamUi::Hidden)
&& control_of(&p.match_id).is_some()
&& let Value::Scalar(x) = p.value
{
out.push(ItemId(x as u64));
}
});
}
out
}
/// The items `comp` needs (itself, nested comps, footage, solids), transitively.
pub fn dependencies(project: &Project, comp: ItemId) -> Vec<ItemId> {
let mut out = vec![];
@@ -858,17 +875,7 @@ pub fn dependencies(project: &Project, comp: ItemId) -> Vec<ItemId> {
if let Some(i) = l.source.item() {
stack.push(i);
}
// Media replacement candidates referenced by instances inside.
if let Some(g) = group(l) {
g.walk("", &mut |_, p| {
if matches!(p.ui, ParamUi::Hidden)
&& control_of(&p.match_id).is_some()
&& let Value::Scalar(x) = p.value
{
stack.push(ItemId(x as u64));
}
});
}
stack.extend(instance_media(l));
}
}
}