EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge pull request #289 from storytold/fix/227-shape-effect-points
Brandon Thomase12bf5ca7d5b
diff --cc crates/ui-egui/src/panels/puppet_tool.rsindex 361a914fd,6c3d8266c..8299f3a34--- a/crates/ui-egui/src/panels/puppet_tool.rs+++ b/crates/ui-egui/src/panels/puppet_tool.rs@@@ -82,31 -82,7 +82,31 @@@ pub fn overlay(app: &EffectcraftApp, ctSome(overlay)}+/// The layer a Puppet tool press at comp point `cpt` works on, of the selected `layers` with a+/// Puppet effect (stack order): the one whose mesh, as deformed now, is under it (pins go on the+/// deformed shape, also where it reaches past the layer's own bounds), else the one whose art is+/// (a new mesh there). Never a layer without a Puppet effect: the tools stay on the layers being+/// rigged, as in After Effects (#284).+pub fn target(ectx: &EvalCtx, layers: &[(&Layer, Overlay)], cpt: [f64; 2], on_art: impl Fn(&Layer) -> bool) -> Option<LayerId> {+ let on_mesh = |l: &Layer, ov: &Overlay| {- let Some(inv) = l2c(ectx, l).0.inverse() else { return false };++ let Some(inv) = fx2c(ectx, l).inverse() else { return false };+ let p = inv.apply(gv2(cpt[0], cpt[1]));+ ov.iter().any(|(_, mesh, def, _)| puppet::contains(mesh, def, [p.x, p.y]))+ };+ layers.iter().find(|(l, ov)| on_mesh(l, ov)).or_else(|| layers.iter().find(|(l, _)| on_art(l))).map(|(l, _)| l.id)+}++/// Keep a pin's keyframed Position in view in the Timeline after placing, moving or recording the+/// pin in the viewer (#273).+pub fn reveal_pin(app: &mut EffectcraftApp, layer: LayerId, pin: u64) {+ let comp = app.session.active_comp();+ let pos = comp.and_then(|c| c.layer(layer)?.props.find_group(pin)?.get("position")).filter(|p| p.is_animated()).map(|p| p.uid);+ if let Some(pos) = pos {+ super::timeline::keep_in_view(app, layer, pos);+ }+}+- /// Where a pin sits now (layer space): its Position, or (Bend / Starch / Overlap pins) its rest+ /// Where a pin sits now (effect space): its Position, or (Bend / Starch / Overlap pins) its rest/// point carried along by the deformation.pub fn pin_position(mesh: &Mesh, def: &[[f64; 2]], p: &Pin) -> [f64; 2] {if p.kind.moves() {diff --cc crates/ui-egui/src/panels/viewer.rsindex 837cfb98d,9249d5c0a..4d92340e5--- a/crates/ui-egui/src/panels/viewer.rs+++ b/crates/ui-egui/src/panels/viewer.rs@@@ -1570,17 -1561,13 +1582,17 @@@ pub fn show(app: &mut EffectcraftApp, uif let Some((h, _)) = super::puppet_tool::hit(&pin_hits, pos) {// Click selects the pin; Shift-click adds or removes it.let _ = app.session.execute("puppet.selectPins", json!({"layer": h.layer.0, "pins": [h.pin], "toggle": mods.shift}));- } else if let Some(l) = pick(app, &ectx, cpt, false).and_then(|l| comp.layer(l))+ } else if let Some(l) = puppet_layer(app, cpt).and_then(|l| comp.layer(l))- && let Some(inv) = l2c(&ectx, l).0.inverse()+ && let Some(inv) = fx2c(&ectx, l).inverse(){let lp = inv.apply(gv2(cpt[0], cpt[1]));- let r = app.session.execute("puppet.addPin", json!({"layer": l.id.0, "kind": t.puppet_kind(), "position": [lp.x, lp.y]}));- if let Err(e) = r {- app.ui.status = e.to_string();+ match app.session.execute("puppet.addPin", json!({"layer": l.id.0, "kind": t.puppet_kind(), "position": [lp.x, lp.y]})) {+ Ok(r) => {+ if let Some(pin) = r["pin"].as_u64() {+ super::puppet_tool::reveal_pin(app, l.id, pin);+ }+ }+ Err(e) => app.ui.status = e.to_string(),}}}