mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 00:55:43 +00:00
Disk cache: follow 3D model sources in the comp's reach
The reach walk followed comp, footage and solid sources but not
LayerSource::Model. An expression reading a model layer's source
(thisComp.layer("Model").source.name) left the model item out of the
comp's content key, so renaming the model kept the key and the old
frames on disk were served. Every source item is followed now
(LayerSource::item), which also counts the model when no expression
reads it (Advanced 3D draws it).
The same omission is fixed in the RAM preview's content walk
(frames.rs) and in the layer key's walk of referenced layers
(cache/dependencies.rs).
This commit is contained in:
1 parent
e1b59f3760
commit
8d4c37a38c
7 files changed
+85
-6
No files matched your search
@@ -626,3 +626,35 @@ fn stereo_rig_expressions_follow_the_master_camera() {
|
||||
assert!(close(v3(&s, "transform/position"), [300.0 - d, 180.0, -800.0]), "{:?}", v3(&s, "transform/position"));
|
||||
assert!(close(v3(&s, "transform/poi"), [300.0, 180.0, 0.0]), "{:?}", v3(&s, "transform/poi"));
|
||||
}
|
||||
|
||||
/// A text layer showing a 3D model's name (`thisComp.layer("Model").source.name`): renaming the
|
||||
/// model gives the comp a new disk key and the text shows the new name (expressions on).
|
||||
#[test]
|
||||
fn renaming_a_model_a_text_expression_reads_changes_the_key_and_the_text() {
|
||||
use effectcraft_engine::Session;
|
||||
let mut s = super::session();
|
||||
let cid = effectcraft_project::ItemId(
|
||||
s.execute("comp.new", json!({"name": "M", "width": 160, "height": 60, "frameRate": 30, "duration": 1})).unwrap()["comp"].as_u64().unwrap(),
|
||||
);
|
||||
let model = s
|
||||
.edit("add model", None, |p, _| {
|
||||
let f = effectcraft_project::Footage { kind: effectcraft_project::FootageKind::Model, ..Default::default() };
|
||||
let model = p.add_item("chair.glb", Default::default(), None, effectcraft_project::ItemKind::Footage(f));
|
||||
let comp = p.comp(cid).cloned().unwrap();
|
||||
let mut l = effectcraft_project::build::layer(p, &comp, "Model", effectcraft_project::LayerSource::Model { item: model }, (16, 16), None);
|
||||
// (not drawn: no model file; an expression still reads its source)
|
||||
l.switches.video = false;
|
||||
p.comp_mut(cid).unwrap().layers.push(l);
|
||||
Ok(model)
|
||||
})
|
||||
.unwrap();
|
||||
let text = s.execute("layer.newText", json!({"comp": cid.0, "text": "x"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("prop.setExpression", json!({"comp": cid.0, "layer": text, "path": "text/sourceText", "expression": "thisComp.layer(\"Model\").source.name"}))
|
||||
.unwrap();
|
||||
let key = effectcraft_engine::render::disk_cache::comp_content_key(&s.project, cid);
|
||||
let shown = |s: &mut Session| s.execute("prop.get", json!({"comp": cid.0, "layer": text, "path": "text/sourceText"})).unwrap()["evaluated"].to_string();
|
||||
assert!(shown(&mut s).contains("chair.glb"), "{}", shown(&mut s));
|
||||
s.execute("project.rename", json!({"item": model.0, "name": "table.glb"})).unwrap();
|
||||
assert_ne!(effectcraft_engine::render::disk_cache::comp_content_key(&s.project, cid), key, "the comp's frames on disk hold the old name");
|
||||
assert!(shown(&mut s).contains("table.glb"), "the text shows the new name: {}", shown(&mut s));
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use crate::{Comp, ItemId, ItemKind, LayerId, LayerSource, Node, Project, PropGroup, Value};
|
||||
use crate::{Comp, ItemId, ItemKind, LayerId, Node, Project, PropGroup, Value};
|
||||
|
||||
/// What an expression's text can reach outside its own comp and the layers it can read.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -351,7 +351,9 @@ impl Project {
|
||||
let Some(c) = self.comp(id) else { continue };
|
||||
let quiet = quiet(id, c);
|
||||
for l in c.layers.iter().filter(|l| !quiet.contains(&l.id)) {
|
||||
if let LayerSource::Comp { item } | LayerSource::Footage { item } | LayerSource::Solid { item } = l.source {
|
||||
// Every source item: a 3D model's too (it is drawn, and `layer.source` reads its
|
||||
// name and size).
|
||||
if let Some(item) = l.source.item() {
|
||||
stack.push(item);
|
||||
}
|
||||
stack.extend(self.media_replacements(l)?);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::{Expression, Solid, build};
|
||||
use crate::{Expression, LayerSource, Solid, build};
|
||||
use effectcraft_time::{FrameRate, Tick};
|
||||
|
||||
fn names(comps: &[&str], footage: &[&str]) -> ExprReach {
|
||||
@@ -175,3 +175,24 @@ fn nested_comps_bring_their_expressions_reach() {
|
||||
set_expr(&mut f.p, f.third, "comp(\"Main\").width");
|
||||
assert!(reach(&f.p, f.main).items.unwrap().contains(&f.main));
|
||||
}
|
||||
|
||||
/// A 3D model layer's item is reached like any other source: it is drawn, and an expression
|
||||
/// reads its name and size through `layer.source` (a renamed model left the comp's disk key and
|
||||
/// its old frames in place).
|
||||
#[test]
|
||||
fn model_sources_are_reached() {
|
||||
let mut f = fixture();
|
||||
let model = f.p.add_item(
|
||||
"chair.glb",
|
||||
effectcraft_color::Label::None,
|
||||
None,
|
||||
ItemKind::Footage(crate::Footage { kind: crate::FootageKind::Model, ..Default::default() }),
|
||||
);
|
||||
let comp = f.p.comp(f.main).unwrap().clone();
|
||||
let l = build::layer(&mut f.p, &comp, "Model", LayerSource::Model { item: model }, (64, 64), None);
|
||||
f.p.comp_mut(f.main).unwrap().layers.push(l);
|
||||
assert!(reach(&f.p, f.main).items.unwrap().contains(&model), "drawn");
|
||||
set_expr(&mut f.p, f.main, "thisComp.layer(\"Model\").source.name.length");
|
||||
let r = reach(&f.p, f.main);
|
||||
assert!(r.expressions && r.items.unwrap().contains(&model), "read by an expression");
|
||||
}
|
||||
+1
-1
@@ -156,7 +156,7 @@ impl Dependencies<'_> {
|
||||
layer.layer_time(ctx.time).0.hash(self.h);
|
||||
}
|
||||
match layer.source {
|
||||
LayerSource::Solid { item } | LayerSource::Footage { item } | LayerSource::Comp { item } => {
|
||||
LayerSource::Solid { item } | LayerSource::Footage { item } | LayerSource::Comp { item } | LayerSource::Model { item } => {
|
||||
let item = match layer.source {
|
||||
LayerSource::Footage { .. } => ctx.media_item(layer, item),
|
||||
_ => item,
|
||||
|
||||
@@ -1745,6 +1745,28 @@ mod tests {
|
||||
assert_ne!(comp_content_key(&p, cid), key, "a hidden clip");
|
||||
}
|
||||
|
||||
/// An expression that reads a 3D model layer's source (`thisComp.layer("Model").source.name`)
|
||||
/// gives a new key when the model item is renamed: the frames on disk hold the old name.
|
||||
#[test]
|
||||
fn renaming_a_model_an_expression_reads_changes_the_disk_key() {
|
||||
use effectcraft_project::{Comp, Expression, Footage, FootageKind, ItemKind, LayerSource, Project, Solid, build};
|
||||
use effectcraft_time::{FrameRate, Tick};
|
||||
let mut p = Project::default();
|
||||
let comp = Comp::new(64, 64, FrameRate::FPS_30, Tick::from_seconds_f64(2.0));
|
||||
let cid = p.add_item("Main", Default::default(), None, ItemKind::Comp(comp.clone().into()));
|
||||
let model = p.add_item("chair.glb", Default::default(), None, ItemKind::Footage(Footage { kind: FootageKind::Model, ..Default::default() }));
|
||||
let sid = p.add_item("Solid", Default::default(), None, ItemKind::Solid(Solid { color: [1.0, 0.0, 0.0], width: 64, height: 64, pixel_aspect: 1.0 }));
|
||||
let mut m = build::layer(&mut p, &comp, "Model", LayerSource::Model { item: model }, (64, 64), None);
|
||||
m.switches.video = false;
|
||||
let mut s = build::layer(&mut p, &comp, "Reader", LayerSource::Solid { item: sid }, (64, 64), None);
|
||||
s.props.prop_mut("transform/opacity").unwrap().expr =
|
||||
Some(Expression { text: "thisComp.layer(\"Model\").source.name.length * 10".into(), enabled: true });
|
||||
p.comp_mut(cid).unwrap().layers.extend([s, m]);
|
||||
let key = comp_content_key(&p, cid);
|
||||
p.item_mut(model).unwrap().name = "table.glb".into();
|
||||
assert_ne!(comp_content_key(&p, cid), key, "the expression reads the model's name");
|
||||
}
|
||||
|
||||
/// A burst of layer writes never crowds out frames: every frame of a fully cached comp is
|
||||
/// on disk afterwards (the blue bar came back with gaps).
|
||||
#[test]
|
||||
|
||||
@@ -35,7 +35,7 @@ use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use effectcraft_engine::project::{Comp, Heard, ItemId, ItemKind, LayerSource, Node, Project, PropGroup};
|
||||
use effectcraft_engine::project::{Comp, Heard, ItemId, ItemKind, Node, Project, PropGroup};
|
||||
use effectcraft_engine::render::disk_cache::{self, DiskCache};
|
||||
use effectcraft_engine::render::reads::{ReadFiles, ReadLog};
|
||||
use effectcraft_engine::render::{CancellableFootage, ExprHost, FootageSource, LayerCache, RenderOpts, Renderer};
|
||||
@@ -434,7 +434,8 @@ fn comp_content_with<'a>(
|
||||
let Some(ItemKind::Comp(c)) = item(id).map(|i| &i.kind) else { continue };
|
||||
let c = version(id, c);
|
||||
for l in &c.layers {
|
||||
if let LayerSource::Comp { item } | LayerSource::Footage { item } | LayerSource::Solid { item } = l.source {
|
||||
// (a 3D model's item too)
|
||||
if let Some(item) = l.source.item() {
|
||||
stack.push(item);
|
||||
}
|
||||
expressions = expressions || (everything && has_expression(&l.props));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use effectcraft_engine::project::LayerSource;
|
||||
|
||||
#[test]
|
||||
fn render_scales_are_the_factors_the_thousandths_stand_for() {
|
||||
|
||||
Reference in new issue
Block a user