ANM-5: sampleImage, data footage (JSON/CSV/TSV) with footage().sourceData, thisProject, error list, Expression Language menu
sampleImage renders the sampled layer through the evaluating renderer's footage source (EvalCtx::footage), cached per thread and frame. File > Import reads .json/.csv/.tsv as data footage kept in the project. expr.errors collects failing expressions for the error bar; expr.languageMenu lists the categorised Expression Language menu. Marker keys expose protectedRegion and cue points; colorDepth, timeToFeetAndFrames, comp.activeCamera. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
abd39f5fd8
commit
6d0d7de922
+77
-1
@@ -183,7 +183,8 @@ mod tests {
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let comp = s.project.comp(cid).unwrap();
|
||||
let layer = comp.layer(effectcraft_engine::project::LayerId(l)).unwrap();
|
||||
let ctx = effectcraft_engine::render::EvalCtx { project: &s.project, comp_id: cid, comp, time: Default::default(), expr: s.expr.as_deref() };
|
||||
let ctx =
|
||||
effectcraft_engine::render::EvalCtx { project: &s.project, comp_id: cid, comp, time: Default::default(), expr: s.expr.as_deref(), footage: None };
|
||||
ctx.value(layer, layer.props.prop(path).unwrap())
|
||||
}
|
||||
|
||||
@@ -221,6 +222,81 @@ mod tests {
|
||||
assert_eq!(value(&s, a, "transform/rotation").as_f64(), 12.0);
|
||||
}
|
||||
|
||||
/// The expression error bar's list: evaluation errors and syntax errors, with the layer and
|
||||
/// property they belong to.
|
||||
#[test]
|
||||
fn expression_errors_are_collected() {
|
||||
let mut s = super::session();
|
||||
s.execute("comp.new", json!({"name": "C", "width": 100, "height": 100, "frameRate": 30, "duration": 2})).unwrap();
|
||||
let a = s.execute("layer.newSolid", json!({"name": "Box", "color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/opacity", "expression": "50"})).unwrap();
|
||||
assert_eq!(s.execute("expr.errors", json!({})).unwrap()["count"], 0);
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/rotation", "expression": "thisComp.layer(\"Nope\").rotation"})).unwrap();
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/opacity", "expression": "1 +* ("})).unwrap();
|
||||
let r = s.execute("expr.errors", json!({})).unwrap();
|
||||
assert_eq!(r["count"], 2, "{r}");
|
||||
let errs = r["errors"].as_array().unwrap();
|
||||
let rot = errs.iter().find(|e| e["path"] == "transform/rotation").unwrap();
|
||||
assert!(rot["message"].as_str().unwrap().contains("Nope"), "{rot}");
|
||||
assert_eq!(rot["layerIndex"], 1);
|
||||
assert_eq!(rot["layerName"], "Box");
|
||||
assert_eq!(rot["disabled"], false);
|
||||
let op = errs.iter().find(|e| e["path"] == "transform/opacity").unwrap();
|
||||
assert_eq!(op["disabled"], true);
|
||||
assert!(r["text"][0].as_str().unwrap().contains("of layer 1 ('Box') in comp 'C'"), "{r}");
|
||||
// A user-disabled (but valid) expression is not an error.
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/rotation", "expression": "45"})).unwrap();
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/rotation", "enabled": false})).unwrap();
|
||||
assert_eq!(s.execute("expr.errors", json!({})).unwrap()["count"], 1);
|
||||
// The Expression Language menu is categorised.
|
||||
let m = s.execute("expr.languageMenu", json!({})).unwrap();
|
||||
assert!(m.as_array().unwrap().iter().any(|c| c["category"] == "Footage" && c["items"].as_array().unwrap().iter().any(|i| i["text"] == "sourceData")));
|
||||
}
|
||||
|
||||
/// File ▸ Import of JSON/CSV data files as data footage, read by expressions.
|
||||
#[test]
|
||||
fn imported_data_files_drive_expressions() {
|
||||
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../target/test-out/host-data");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::fs::write(dir.join("levels.csv"), "label,value\nlow,10\nhigh,90\n").unwrap();
|
||||
std::fs::write(dir.join("cfg.json"), r#"{"angle": 33}"#).unwrap();
|
||||
std::fs::write(dir.join("broken.json"), "{nope").unwrap();
|
||||
let mut s = super::session();
|
||||
s.execute("comp.new", json!({"name": "C", "width": 100, "height": 100, "frameRate": 30, "duration": 2})).unwrap();
|
||||
let paths: Vec<String> = ["levels.csv", "cfg.json", "broken.json"].iter().map(|n| dir.join(n).to_string_lossy().to_string()).collect();
|
||||
let r = s.execute("file.import", json!({"paths": paths})).unwrap();
|
||||
assert_eq!(r["items"].as_array().unwrap().len(), 2, "{r}");
|
||||
assert_eq!(r["errors"].as_array().unwrap().len(), 1, "{r}");
|
||||
let csv = r["items"][0].as_u64().unwrap();
|
||||
assert_eq!(s.project.item(effectcraft_engine::project::ItemId(csv)).unwrap().type_name(), "Data");
|
||||
assert!(s.execute("layer.addItem", json!({"item": csv})).is_err(), "data files are not layers");
|
||||
let a = s.execute("layer.newSolid", json!({"color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/opacity", "expression": "footage(\"levels.csv\").sourceData[1].value"})).unwrap();
|
||||
s.execute("prop.setExpression", json!({"layer": a, "path": "transform/rotation", "expression": "footage(\"cfg.json\").sourceData.angle"})).unwrap();
|
||||
assert_eq!(value(&s, a, "transform/opacity").as_f64(), 90.0);
|
||||
assert_eq!(value(&s, a, "transform/rotation").as_f64(), 33.0);
|
||||
}
|
||||
|
||||
/// sampleImage through the renderer: a box's Fill colour follows the solid under it.
|
||||
#[test]
|
||||
fn sample_image_drives_a_colour() {
|
||||
let mut s = super::session();
|
||||
s.execute("comp.new", json!({"name": "C", "width": 100, "height": 100, "frameRate": 30, "duration": 2})).unwrap();
|
||||
s.execute("layer.newSolid", json!({"name": "Bg", "color": "#00ff00"})).unwrap();
|
||||
let a = s.execute("layer.newSolid", json!({"name": "Fg", "color": "#ffffff", "width": 20, "height": 20})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("effect.apply", json!({"layer": a, "effect": "Fill"})).unwrap();
|
||||
s.execute(
|
||||
"prop.setExpression",
|
||||
json!({"layer": a, "path": "effects/#1/color", "expression": "thisComp.layer(\"Bg\").sampleImage(thisComp.layer(\"Bg\").fromComp(toComp(anchorPoint)))"}),
|
||||
)
|
||||
.unwrap();
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let img = s.render(cid, s.time(), effectcraft_engine::render::RenderOpts::default());
|
||||
let px = img.get(50, 50);
|
||||
assert!(px[1] > 0.99 && px[0] < 0.01, "the box is filled with the sampled green: {px:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expression_syntax_errors_disable_the_expression() {
|
||||
let mut s = super::session();
|
||||
|
||||
Reference in New Issue
Block a user