Merge pull request #289 from storytold/fix/227-shape-effect-points

Effects: effect points on shape layers start at the layer centre (#227)

# Conflicts:
#	crates/ui-egui/src/panels/puppet_tool.rs
#	crates/ui-egui/src/panels/viewer.rs
This commit is contained in:
Brandon Thomas
2026-10-09 09:32:13 -04:00
36 changed files with 684 additions and 154 deletions
+8 -4
View File
@@ -1183,13 +1183,15 @@ pub fn viewer_hook(
&& let Some(pos) = resp.interact_pointer_pos()
{
let c = map.to_comp(pos);
// Effect points and the keyer's input are in effect space.
let m = super::viewer::from_effect_space(ectx, &layer, l2c(ectx, &layer));
if pick.kind == "point" {
if let Some(lp) = fw::comp_to_layer(&l2c(ectx, &layer), c) {
if let Some(lp) = fw::comp_to_layer(&m, c) {
actions.push(("prop.set".into(), json!({"layer": pick.layer, "prop": pick.prop, "value": [lp[0], lp[1]]})));
}
} else if let Some(fx) = keyer {
// Ctrl/Cmd+click averages the 5 × 5 pixels around the point.
if let Some(lp) = fw::comp_to_layer(&l2c(ectx, &layer), c) {
if let Some(lp) = fw::comp_to_layer(&m, c) {
let average = ui.input(|i| i.modifiers.command);
actions.push((
"effect.pickColor".into(),
@@ -1215,6 +1217,8 @@ pub fn viewer_hook(
for layer in ectx.comp.layers.iter().filter(|l| selected.contains(&l.id) && l.is_active_at(ectx.time)) {
let Some(fx) = layer.effects() else { continue };
let m = l2c(ectx, layer);
// Masks are in layer space, effect points in effect space.
let fm = super::viewer::from_effect_space(ectx, layer, m);
for g in fx.groups().filter(|g| g.enabled && sel.iter().any(|(l, u)| *l == layer.id && *u == g.uid)) {
if matches!(&g.kind, GroupKind::Effect { effect } if effect == super::fx_editors::RESHAPE) {
super::fx_editors::reshape_overlay(app, ui, painter, map, ectx, layer, g, &m, &mut actions);
@@ -1224,7 +1228,7 @@ pub fn viewer_hook(
.iter()
.map(|pr| {
let v = ectx.value(layer, pr).as_vec2();
map.to_screen(fw::layer_to_comp(&m, v))
map.to_screen(fw::layer_to_comp(&fm, v))
})
.collect();
// Gradient Ramp and friends: a guide between start and end points.
@@ -1245,7 +1249,7 @@ pub fn viewer_hook(
}
if resp.dragged()
&& let Some(pos) = resp.interact_pointer_pos()
&& let Some(lp) = fw::comp_to_layer(&m, map.to_comp(pos))
&& let Some(lp) = fw::comp_to_layer(&fm, map.to_comp(pos))
{
let key = gesture_key(ui, id, resp.drag_started());
actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": pr.uid, "value": [lp[0], lp[1]], "merge": key})));
+2 -2
View File
@@ -113,8 +113,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// Canvas.
let area = Rect::from_min_max(pos2(rect.min.x, top.max.y), pos2(rect.max.x, canvas_bottom));
p.rect_filled(area, 0.0, t.pasteboard);
let (w, h) = effectcraft_engine::render::source_size(&app.session.project, &layer);
let (lw, lh) = if w == 0 { (comp.width as f64, comp.height as f64) } else { (w as f64, h as f64) };
// The layer's effect bounds, in effect space (where paint and Roto Brush strokes are).
let [lw, lh] = effectcraft_engine::render::effect_bounds(&app.session.project, &comp, &layer).0;
let zoom = ((area.width() - 40.0) as f64 / lw).min((area.height() - 40.0) as f64 / lh).max(0.01);
let origin = area.center() - vec2((lw * zoom / 2.0) as f32, (lh * zoom / 2.0) as f32);
let to_screen = |q: [f64; 2]| pos2(origin.x + (q[0] * zoom) as f32, origin.y + (q[1] * zoom) as f32);
+4 -4
View File
@@ -12,7 +12,7 @@ use effectcraft_engine::render::EvalCtx;
use effectcraft_engine::time::Tick;
use egui::{Color32, Pos2, Stroke};
use super::viewer::{ViewerMap, l2c};
use super::viewer::{ViewerMap, fx2c};
use crate::EffectcraftApp;
/// Deformed meshes of a layer's Puppet effect: (mesh uid, mesh, deformed vertices, pins).
@@ -89,7 +89,7 @@ pub fn overlay(app: &EffectcraftApp, ctx: &egui::Context, cid: ItemId, layer: &L
/// 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]))
};
@@ -106,7 +106,7 @@ pub fn reveal_pin(app: &mut EffectcraftApp, layer: LayerId, pin: u64) {
}
}
/// 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() {
@@ -148,7 +148,7 @@ pub fn draw(
selected: &[u64],
hover: Option<Pos2>,
) -> Vec<PinHit> {
let (m, _) = l2c(ectx, layer);
let m = fx2c(ectx, layer);
let scr = |q: [f64; 2]| {
let c = m.apply(gv2(q[0], q[1]));
map.to_screen([c.x, c.y])
+15 -3
View File
@@ -159,7 +159,7 @@ enum Gesture {
start: Pos2,
},
/// Puppet tool Record mode (⌘/Ctrl-drag a pin): the drag is sampled in real time (seconds
/// since it began, layer space) and becomes keyframes on release (`puppet.recordPin`); the
/// since it began, effect space) and becomes keyframes on release (`puppet.recordPin`); the
/// current time runs along while recording.
PuppetRecord {
layer: LayerId,
@@ -245,6 +245,18 @@ pub(crate) fn l2c(ctx: &EvalCtx, layer: &Layer) -> (Mat3, f64) {
}
}
/// `l2c` (layer → comp) applied from effect space instead: effect points and Puppet pins,
/// measured from the top-left of the layer's effect bounds (see `effect_bounds`).
pub(crate) fn from_effect_space(ctx: &EvalCtx, layer: &Layer, l2c: Mat3) -> Mat3 {
let o = ctx.effect_bounds(layer).1;
l2c * Mat3::translate(gv2(o[0], o[1]))
}
/// Effect space → comp (viewer) matrix through the current 3D view.
pub(crate) fn fx2c(ctx: &EvalCtx, layer: &Layer) -> Mat3 {
from_effect_space(ctx, layer, l2c(ctx, layer).0)
}
/// Layer → comp matrix and its bounds quad (in comp pixels).
pub(crate) fn layer_quad(ctx: &EvalCtx, layer: &Layer) -> Option<(Mat3, [[f64; 2]; 4], [f64; 4])> {
let b = effectcraft_engine::render::content_bounds(ctx, layer)?;
@@ -1150,7 +1162,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
PinPart::Center => {}
}
let l = comp.layer(h.layer)?;
let inv = l2c(&ectx, l).0.inverse()?;
let inv = fx2c(&ectx, l).inverse()?;
if mods.command {
let lp = inv.apply(gv2(cpt[0], cpt[1]));
let began = ui.input(|i| i.time);
@@ -1571,7 +1583,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// 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) = 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]));
match app.session.execute("puppet.addPin", json!({"layer": l.id.0, "kind": t.puppet_kind(), "position": [lp.x, lp.y]})) {