M13.15: rig puppet pins to nulls — Points Follow Nulls / Nulls Follow Points (Window ▸ Create Nulls From Paths, paths.* {pins?}) take selected pins, named pins, or every pin of a layer with no path: a null per Position / Advanced pin drives its Position (fromComp of the null's anchor, so parented nulls rig limbs), or rides on it (toComp of the pin's Position) to carry other layers; one undo step

This commit is contained in:
bflatastic
2026-10-04 00:19:25 +07:00
parent 6869cff51b
commit 6ec177de83
6 changed files with 203 additions and 10 deletions
+43
View File
@@ -269,6 +269,49 @@ fn puppet_select_all_takes_the_pin_kind_and_several_pins_record_together() {
assert!(s.execute("puppet.recordPin", json!({"layer": id, "pin": a, "pins": [st], "samples": samples})).is_err());
}
fn expr_of(s: &Session, layer: u64, uid: u64) -> String {
let l = layer_of(s, layer);
l.props.find(uid).and_then(|p| p.expr.as_ref()).map(|e| e.text.clone()).unwrap_or_default()
}
fn layer_of(s: &Session, id: u64) -> effectcraft_project::Layer {
s.active_comp().unwrap().layer(effectcraft_project::LayerId(id)).unwrap().clone()
}
#[test]
fn puppet_pins_rig_to_nulls_both_ways() {
let (mut s, id) = setup();
s.execute("puppet.addPin", json!({"layer": id, "position": [10, 30]})).unwrap();
s.execute("puppet.addPin", json!({"layer": id, "position": [90, 30]})).unwrap();
let bend = s.execute("puppet.addPin", json!({"layer": id, "kind": "bend", "position": [50, 30]})).unwrap()["pin"].clone();
// Only a Bend pin selected: nothing to rig.
assert!(s.execute("paths.pointsFollowNulls", json!({})).is_err());
// No pin selected and no path: every Position pin of the layer gets a null on it, and the
// pin's Position follows the null; one undo step.
s.execute("puppet.selectPins", json!({"layer": id, "pins": []})).unwrap();
let steps = s.history.undo.len();
let r = s.execute("paths.pointsFollowNulls", json!({"layer": id})).unwrap();
assert_eq!(s.history.undo.len(), steps + 1);
let nulls: Vec<u64> = r["nulls"].as_array().unwrap().iter().map(|v| v.as_u64().unwrap()).collect();
let pins: Vec<u64> = r["pins"].as_array().unwrap().iter().map(|v| v.as_u64().unwrap()).collect();
assert_eq!((nulls.len(), pins.len()), (2, 2));
let solid = layer_of(&s, id).name;
let null = layer_of(&s, nulls[0]);
assert_eq!(null.name, format!("{solid}: Puppet Pin 1"));
// Layer (10, 30) is comp (60, 50).
assert_eq!(null.props.prop("transform/position").unwrap().value.components()[..2], [60.0, 50.0]);
let e = expr_of(&s, id, pins[0]);
assert!(e.contains(&format!("thisComp.layer(\"{solid}: Puppet Pin 1\")")) && e.contains("fromComp(n.toComp(n.transform.anchorPoint))"), "{e}");
// Nulls Follow Points: a null riding on a pin, through the pin's Position.
let r = s.execute("paths.nullsFollowPoints", json!({"layer": id, "pins": ["Puppet Pin 2"]})).unwrap();
let rider = layer_of(&s, r["nulls"][0].as_u64().unwrap());
let e = rider.props.prop("transform/position").unwrap().expr.as_ref().unwrap().text.clone();
assert!(e.contains(&format!("thisComp.layer(\"{solid}\")")) && e.contains("(\"Puppet Pin 2\")(\"Position\")") && e.contains("toComp"), "{e}");
assert!(s.execute("paths.nullsFollowPoints", json!({"layer": id, "pins": [bend]})).is_err());
// Trace Path still needs a path.
assert!(s.execute("paths.tracePath", json!({"layer": id})).is_err());
}
#[test]
fn project_with_paint_and_puppet_round_trips() {
let (mut s, id) = setup();