Merge pull request #792 from vangel76/gap-object-matte

# Conflicts:
#	crates/ui-egui/src/i18n/ui.rs
#	docs/gaps.md
#	docs/target-app-parity.md
This commit is contained in:
Brandon Thomas
2026-10-13 04:30:49 -04:00
29 changed files with 2031 additions and 74 deletions
+4
View File
@@ -627,6 +627,7 @@ const JAPANESE: &[(&str, &str)] = &[
("Project", "プロジェクト"),
("Total Offset", "合計オフセット"),
("Per Layer", "レイヤーごと"),
("Track", "トラック"),
];
const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
@@ -1352,6 +1353,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
("Stored, but not used by EffectCraft yet", "已保存,但 EffectCraft 尚未使用"),
("Total Offset", "总偏移"),
("Per Layer", "每个图层"),
("Track", "跟踪"),
];
const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
@@ -2072,6 +2074,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
("Stored, but not used by EffectCraft yet", "已儲存,但 EffectCraft 尚未使用"),
("Total Offset", "總偏移"),
("Per Layer", "每個圖層"),
("Track", "追蹤"),
];
/// Ukrainian (uk): original translations of the same interface rows as the Chinese catalogs.
@@ -2539,6 +2542,7 @@ const UKRAINIAN: &[(&str, &str)] = &[
("⌘/Ctrl-drag a pin to record its motion", "Перетягніть опорну точку з ⌘/Ctrl, щоб записати її рух"),
("▣ {}", "▣ {}"),
("⚠ {} is used by:", "⚠ {} використовується в:"),
("Track", "Відстежити"),
// Strings a panel used to hand to a helper as a bare literal: the helper draws them (the
// viewer's toolbar tooltips and popup items, the solid dialog's checkbox), so the lookup has
// to reach the catalog from inside the helper. Kept at the end so the catalogs stay parallel.
+10
View File
@@ -35,6 +35,8 @@ pub enum Icon {
Eraser,
RotoBrush,
RefineEdge,
/// Object Matte: a selection box's corners around a solid object, with a click point.
ObjectMatte,
/// Puppet Position Pin: a pushpin. The other pin tools add a badge at the lower right.
Puppet,
PuppetAdvanced,
@@ -348,6 +350,14 @@ pub fn paint(painter: &Painter, rect: Rect, icon: Icon, color: Color32) {
pen.line(&[(8.0, 14.0), (9.5, 12.5)]);
pen.line(&[(11.0, 14.0), (12.5, 12.5)]);
}
ObjectMatte => {
// Corner brackets of a box around a filled object, and the click on it.
for (x, y, dx, dy) in [(2.0, 2.0, 1.0, 1.0), (14.0, 2.0, -1.0, 1.0), (14.0, 14.0, -1.0, -1.0), (2.0, 14.0, 1.0, -1.0)] {
pen.line(&[(x, y + 3.0 * dy), (x, y), (x + 3.0 * dx, y)]);
}
pen.dot(8.0, 8.0, 2.2);
pen.circle(8.0, 8.0, 4.4);
}
Puppet => pen.pushpin(8.0),
PuppetAdvanced => {
// Rotation ring with its square scale handle.
+6
View File
@@ -1635,6 +1635,12 @@ impl EffectcraftApp {
self.session.poll_roto(true);
ctx.request_repaint_after(std::time::Duration::from_millis(100));
}
// Roto Brush propagation and Object Matte tracking / Freeze: finish jobs (a Freeze writes
// its mattes) and start queued ones in the background.
if self.session.roto_job.is_some() || !self.session.roto_pending.is_empty() {
self.session.poll_roto(true);
ctx.request_repaint_after(std::time::Duration::from_millis(100));
}
// 3D Camera Tracker: likewise (tracking, then solving).
if self.session.camera_job.is_some() || !self.session.camera_pending.is_empty() {
self.session.poll_camera(true);
+40 -1
View File
@@ -805,6 +805,44 @@ fn roto_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, l
p.text(pos2(r.min.x + 24.0, r.min.y + 38.0), Align2::LEFT_CENTER, status, Tokens::ui(11.5), t.text_dim);
}
/// Object Matte: Freeze / Unfreeze and Track / Stop buttons (the background job that computes
/// the matte over the tracked frames) and its status.
fn object_matte_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, layer: &Layer, g: &PropGroup, r: Rect, actions: &mut Actions) {
use effectcraft_engine::effects::object_matte as om;
let t = app.tokens;
let params = effectcraft_engine::effects::flatten_params(g, &mut |pr| pr.value.clone());
let frozen = om::is_frozen(&params);
let mine = app.session.roto_target().is_some_and(|(_, l, u, _)| l == layer.id && u == g.uid);
let running = mine && app.session.is_roto_running();
let busy = app.session.is_roto_running();
let b1 = Rect::from_min_size(pos2(r.min.x + 24.0, r.min.y + 4.0), vec2(84.0, 22.0));
let b2 = Rect::from_min_size(pos2(b1.max.x + 8.0, b1.min.y), vec2(84.0, 22.0));
let label = if frozen { "Unfreeze" } else { "Freeze" };
if widgets::text_button(ui, b1, crate::i18n::tr(label), frozen, &t, egui::Id::new(("om-freeze-ec", g.uid))).clicked() && !busy {
let id = if frozen { "objectMatte.unfreeze" } else { "objectMatte.freeze" };
actions.push((id.into(), json!({"layer": layer.id.0, "effect": g.uid})));
}
app.auto.add(&format!("effectControls.objectMatte.{}.freeze", g.uid), b1, label);
let (l2, id2) = if running { ("Stop", "roto.cancel") } else { ("Track", "objectMatte.propagate") };
if widgets::text_button(ui, b2, crate::i18n::tr(l2), false, &t, egui::Id::new(("om-track-ec", g.uid))).clicked() && !frozen && (running || !busy) {
actions.push((id2.into(), json!({"layer": layer.id.0, "effect": g.uid})));
}
app.auto.add(&format!("effectControls.objectMatte.{}.track", g.uid), b2, l2);
let base = om::reference_frame(&params);
let status = match app.session.roto_progress() {
Some(pr) if running => pr.banner(),
_ if frozen => format!("Frozen from reference frame {base}"),
_ if app.session.roto_pending.iter().any(|(_, l, u)| *l == layer.id && *u == g.uid) => "Waiting to track".to_string(),
_ => format!("Reference frame {base}: Track computes the matte ahead of playback"),
};
p.text(pos2(r.min.x + 24.0, r.min.y + 38.0), Align2::LEFT_CENTER, &status, Tokens::ui(11.5), t.text_dim);
app.auto.add(
&format!("effectControls.objectMatte.{}.status", g.uid),
Rect::from_min_size(pos2(r.min.x + 24.0, r.min.y + 30.0), vec2(r.width() - 24.0, 16.0)),
&status,
);
}
// ---------------------------------------------------------------------------------------------
// Curves / Levels editors
@@ -815,7 +853,7 @@ fn editor_height(effect: &str, g: &PropGroup, width: f32) -> f32 {
"ec.color.curves" => 34.0 + curves_size(width) + 26.0,
effectcraft_engine::effects::warp_stab::ID => 50.0,
effectcraft_engine::effects::camera_tracker::ID => super::camera_tracker_ui::EDITOR_HEIGHT,
effectcraft_engine::effects::roto::ID => 50.0,
effectcraft_engine::effects::roto::ID | effectcraft_engine::effects::object_matte::ID => 50.0,
"ec.color.levels" | "ec.color.levelsic" => 34.0 + 80.0 + 58.0,
"ec.color.autolevels" | "ec.color.autocontrast" | "ec.color.autocolor" => 24.0 + 80.0 + 12.0,
_ => 0.0,
@@ -1290,6 +1328,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
effectcraft_engine::effects::warp_stab::ID => warp_editor(app, ui, &bp, &layer, g, er, &mut actions),
effectcraft_engine::effects::camera_tracker::ID => super::camera_tracker_ui::editor(app, ui, &bp, &layer, g, er, &mut actions),
effectcraft_engine::effects::roto::ID => roto_editor(app, ui, &bp, &layer, g, er, &mut actions),
effectcraft_engine::effects::object_matte::ID => object_matte_editor(app, ui, &bp, &layer, g, er, &mut actions),
"ec.color.levels" | "ec.color.levelsic" => levels_editor(app, ui, &bp, &layer, g, effect, &ectx, er, &mut actions),
super::fx_editors::GLOW | super::fx_editors::RESHAPE | super::fx_editors::EXTRACTOR => {
super::fx_editors::header_editor(app, ui, &bp, &layer, g, effect, &ectx, er, &mut actions)
+1
View File
@@ -30,6 +30,7 @@ pub mod learn;
pub mod markers_ui;
pub mod media_panels;
pub mod misc;
pub mod object_matte_tool;
pub mod paint_panels;
pub mod panel_kit;
pub mod path_vr_panels;
@@ -0,0 +1,128 @@
//! The Object Matte tool in the Composition viewer (After Effects 26.2's Object Matte, from its
//! public description): click an object to isolate it, or drag a box around it. The layer under
//! the pointer gets an Object Matte effect (`objectMatte.apply`), or its Object Matte is
//! re-prompted (the selected one, else its last); Shift adds another. Every prompt is one undo
//! step, and the effect is selected so its point controls show in the viewer.
//!
//! While hovering, a crosshair and the outline of the layer that would get the matte preview the
//! click: segmenting on every pointer move would be far too slow for a hover preview (a model
//! pass or a graph cut per move), so the matte itself appears once the prompt is set.
use effectcraft_engine::geom::vec2 as gv2;
use effectcraft_engine::project::Layer;
use effectcraft_engine::render::EvalCtx;
use egui::{Color32, Pos2, Rect, Stroke, StrokeKind};
use serde_json::json;
use super::viewer::{ViewerMap, fx2c, layers_at};
use crate::EffectcraftApp;
/// Drags shorter than this (screen points) are clicks: a point prompt, no box.
pub const MIN_BOX: f32 = 4.0;
/// Whether Object Matte can work on `layer` (footage, solid or composition layers with pixels).
fn eligible(layer: &Layer) -> bool {
layer.has_video() && !layer.switches.adjustment && layer.effects().is_some()
}
/// The layer a prompt at comp point `cpt` goes to: a selected one under it, else the topmost.
pub fn target<'a>(app: &EffectcraftApp, ectx: &EvalCtx<'a>, cpt: [f64; 2]) -> Option<&'a Layer> {
let hits: Vec<&Layer> = layers_at(ectx, cpt).filter(|l| eligible(l)).collect();
let selected = &app.session.state.selected_layers;
hits.iter().find(|l| selected.contains(&l.id)).or(hits.first()).copied()
}
/// The layer's effect-space rectangle (its pixels) on screen.
fn outline(ectx: &EvalCtx, map: &ViewerMap, layer: &Layer) -> [Pos2; 4] {
let [w, h] = ectx.effect_bounds(layer).0;
let m = fx2c(ectx, layer);
[[0.0, 0.0], [w, 0.0], [w, h], [0.0, h]].map(|p| {
let c = m.apply(gv2(p[0], p[1]));
map.to_screen([c.x, c.y])
})
}
/// Hover preview at `hp` (screen): the outline of the layer that would get the matte and a
/// crosshair where the object point would go.
pub fn hover(app: &mut EffectcraftApp, painter: &egui::Painter, map: &ViewerMap, ectx: &EvalCtx, hp: Pos2) {
let accent = app.tokens.accent;
let cpt = map.to_comp(hp);
if let Some(layer) = target(app, ectx, cpt) {
let q = outline(ectx, map, layer);
let mut pts = q.to_vec();
pts.push(q[0]);
painter.add(egui::Shape::line(pts, Stroke::new(1.5, accent)));
let r = Rect::from_points(&q);
app.auto.add("viewer.objectMatte.target", r, &layer.name);
}
let (gap, arm) = (4.0, 11.0);
for (dx, dy) in [(1.0, 0.0), (-1.0, 0.0), (0.0, 1.0), (0.0, -1.0)] {
let d = egui::vec2(dx, dy);
for (w, c) in [(3.0, Color32::from_black_alpha(160)), (1.5, Color32::WHITE)] {
painter.line_segment([hp + d * gap, hp + d * arm], Stroke::new(w, c));
}
}
painter.circle_stroke(hp, 2.0, Stroke::new(1.5, accent));
app.auto.add("viewer.objectMatte.crosshair", Rect::from_center_size(hp, egui::vec2(2.0 * arm, 2.0 * arm)), "Object Matte point");
}
/// The box being dragged (screen `a`–`b`).
pub fn draw_box(app: &mut EffectcraftApp, painter: &egui::Painter, a: Pos2, b: Pos2) {
let r = Rect::from_two_pos(a, b);
let accent = app.tokens.accent;
painter.rect_stroke(r, 0.0, Stroke::new(2.5, Color32::from_black_alpha(140)), StrokeKind::Middle);
painter.rect_stroke(r, 0.0, Stroke::new(1.5, accent), StrokeKind::Middle);
painter.circle_filled(r.center(), 2.5, accent);
app.auto.add("viewer.objectMatte.box", r, "Object Matte box");
}
/// Set the prompt from a click at `a` (screen), or a box dragged from `a` to `b`: on the
/// target layer's Object Matte (re-prompted), or a new one with `add` or when it has none.
pub fn apply(app: &mut EffectcraftApp, ectx: &EvalCtx, map: &ViewerMap, a: Pos2, b: Option<Pos2>, add: bool) {
let boxed = b.filter(|b| (b.x - a.x).abs() >= MIN_BOX && (b.y - a.y).abs() >= MIN_BOX);
let center = boxed.map_or(a, |b| Rect::from_two_pos(a, b).center());
let Some(layer) = target(app, ectx, map.to_comp(center)) else {
app.ui.status = "Object Matte: click an object on a footage, solid or composition layer".into();
return;
};
let Some(inv) = fx2c(ectx, layer).inverse() else { return };
let to_layer = |p: Pos2| {
let c = map.to_comp(p);
let l = inv.apply(gv2(c[0], c[1]));
[l.x, l.y]
};
let point = to_layer(center);
let mut q = json!({"layer": layer.id.0, "point": point});
if let Some(b) = boxed {
// The box in layer pixels: the bounds of its corners (the layer may be turned).
let r = Rect::from_two_pos(a, b);
let c = [r.left_top(), r.right_top(), r.right_bottom(), r.left_bottom()].map(to_layer);
let (x0, x1) = c.iter().map(|p| p[0]).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), v| (lo.min(v), hi.max(v)));
let (y0, y1) = c.iter().map(|p| p[1]).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), v| (lo.min(v), hi.max(v)));
q["box"] = json!([x0, y0, x1, y1]);
}
if !add && let Some(uid) = existing(app, layer) {
q["effect"] = json!(uid);
}
let lid = layer.id;
match app.session.execute("objectMatte.apply", q) {
Ok(r) => {
if let Some(uid) = r["effect"].as_u64() {
let _ = app.session.execute("prop.select", json!({"layer": lid.0, "prop": uid}));
}
}
Err(e) => app.ui.status = e.to_string(),
}
}
/// The Object Matte a prompt on `layer` re-prompts: the selected one, else the layer's last.
fn existing(app: &EffectcraftApp, layer: &Layer) -> Option<u64> {
let fx = layer.effects()?;
let om: Vec<u64> = fx.groups().filter(|g| is_object_matte(g)).map(|g| g.uid).collect();
let sel = app.session.state.selected_props.iter().rev().find(|(l, u)| *l == layer.id && om.contains(u)).map(|(_, u)| *u);
sel.or(om.last().copied())
}
fn is_object_matte(g: &effectcraft_engine::project::PropGroup) -> bool {
matches!(&g.kind, effectcraft_engine::project::GroupKind::Effect { effect } if effect == effectcraft_engine::effects::object_matte::ID)
}
+17 -1
View File
@@ -168,6 +168,10 @@ enum Gesture {
PinMarquee {
start: Pos2,
},
/// Object Matte tool: a box around the object (screen point where the drag began).
ObjectMatteBox {
start: Pos2,
},
/// Puppet tool Record mode (⌘/Ctrl-drag a pin): the drag is sampled in real time (seconds
/// since it began, effect space) and becomes keyframes on release (`puppet.recordPin`); the
/// current time runs along while recording.
@@ -1313,6 +1317,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
t if t.is_shape() => egui::CursorIcon::Crosshair,
_ if app.ui.viewer.roi_draw => egui::CursorIcon::Crosshair,
Tool::ObjectMatte => {
// The tool draws its own crosshair (and the layer it would matte) while no box
// is being dragged.
if ui.data(|d| d.get_temp::<Gesture>(egui::Id::new("viewer-gesture"))).is_none() {
super::object_matte_tool::hover(app, &painter, &map, &ectx, hp);
}
egui::CursorIcon::None
}
t if t.puppet_kind().is_some() => match super::puppet_tool::hit(&pin_hits, hp) {
Some((_, super::puppet_tool::PinPart::Ring)) => egui::CursorIcon::Alias,
Some((_, super::puppet_tool::PinPart::Scale)) => egui::CursorIcon::ResizeNwSe,
@@ -1443,6 +1455,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// From where the button went down: by the time the pointer has moved far enough to
// count as a drag it has already left the press point, and the shape is drawn there.
t if t.is_shape() => Some(Gesture::Create { tool: t, start: map.to_comp(press) }),
Tool::ObjectMatte => Some(Gesture::ObjectMatteBox { start: press }),
t if t.puppet_kind().is_some() && super::puppet_tool::hit(&pin_hits, press).is_none() => {
// Off the pins: Alt or a press outside the art drags a marquee that selects pins.
(mods.alt || puppet_layer(app, cpt).is_none()).then_some(Gesture::PinMarquee { start: press })
@@ -1766,6 +1779,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
q["merge"] = json!(merge);
let _ = app.session.execute("track.setPoint", q);
}
Gesture::ObjectMatteBox { start } => super::object_matte_tool::draw_box(app, &painter, start, pos),
Gesture::Marquee { start } | Gesture::PinMarquee { start } => {
let r = Rect::from_two_pos(start, pos);
painter.rect_filled(r, 0.0, t.accent.gamma_multiply(0.12));
@@ -1806,6 +1820,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
}
Gesture::PuppetPin { layer, pin, .. } => super::puppet_tool::reveal_pin(app, layer, pin),
Gesture::ObjectMatteBox { start } => super::object_matte_tool::apply(app, &ectx, &map, start, Some(pos), mods.shift),
Gesture::Create { tool, start } => {
let end = map.to_comp(pos);
create_shape(app, tool, start, end, mods);
@@ -1909,6 +1924,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// Clicking away from the free-transform box ends it.
ov::end_free_transform(&ctx);
}
Tool::ObjectMatte => super::object_matte_tool::apply(app, &ectx, &map, pos, None, mods.shift),
t if t.puppet_kind().is_some() => {
if let Some((h, _)) = super::puppet_tool::hit(&pin_hits, pos) {
// Click selects the pin; Shift-click adds or removes it.
@@ -2270,7 +2286,7 @@ pub(crate) fn selectable_layers(comp: &Comp, time: Tick) -> impl Iterator<Item =
}
/// Selectable layers under a comp point, front to back.
fn layers_at<'a, 'b>(ectx: &'b EvalCtx<'a>, cpt: [f64; 2]) -> impl Iterator<Item = &'a Layer> + 'b {
pub(crate) fn layers_at<'a, 'b>(ectx: &'b EvalCtx<'a>, cpt: [f64; 2]) -> impl Iterator<Item = &'a Layer> + 'b {
selectable_layers(ectx.comp, ectx.time).filter(move |l| layer_quad(ectx, l).is_some_and(|(_, q, _)| point_in_quad(cpt, &q)))
}
+8 -3
View File
@@ -35,6 +35,8 @@ pub enum Tool {
Eraser,
RotoBrush,
RefineEdge,
/// Object Matte: click an object (or drag a box around it) in the Composition viewer.
ObjectMatte,
Puppet,
PuppetStarch,
PuppetBend,
@@ -59,10 +61,10 @@ impl Tool {
&[Tool::Brush],
&[Tool::Clone],
&[Tool::Eraser],
&[Tool::RotoBrush, Tool::RefineEdge],
&[Tool::RotoBrush, Tool::RefineEdge, Tool::ObjectMatte],
&[Tool::Puppet, Tool::PuppetStarch, Tool::PuppetBend, Tool::PuppetAdvanced, Tool::PuppetOverlap],
];
pub const ALL: [Tool; 30] = [
pub const ALL: [Tool; 31] = [
Tool::Selection,
Tool::Hand,
Tool::Zoom,
@@ -88,6 +90,7 @@ impl Tool {
Tool::Eraser,
Tool::RotoBrush,
Tool::RefineEdge,
Tool::ObjectMatte,
Tool::Puppet,
Tool::PuppetStarch,
Tool::PuppetBend,
@@ -121,6 +124,7 @@ impl Tool {
Tool::Eraser => "Eraser Tool",
Tool::RotoBrush => "Roto Brush Tool",
Tool::RefineEdge => "Refine Edge Tool",
Tool::ObjectMatte => "Object Matte Tool",
Tool::Puppet => "Puppet Position Pin Tool",
Tool::PuppetStarch => "Puppet Starch Pin Tool",
Tool::PuppetBend => "Puppet Bend Pin Tool",
@@ -142,7 +146,7 @@ impl Tool {
Tool::Pen | Tool::PenAdd | Tool::PenDelete | Tool::PenConvert | Tool::MaskFeather => Some("G"),
Tool::Type | Tool::TypeVertical => Some("Cmd+T"),
Tool::Brush | Tool::Clone | Tool::Eraser => Some("Cmd+B"),
Tool::RotoBrush | Tool::RefineEdge => Some("Alt+W"),
Tool::RotoBrush | Tool::RefineEdge | Tool::ObjectMatte => Some("Alt+W"),
Tool::Puppet | Tool::PuppetStarch | Tool::PuppetBend | Tool::PuppetAdvanced | Tool::PuppetOverlap => Some("Cmd+P"),
}
}
@@ -173,6 +177,7 @@ impl Tool {
Tool::Eraser => Icon::Eraser,
Tool::RotoBrush => Icon::RotoBrush,
Tool::RefineEdge => Icon::RefineEdge,
Tool::ObjectMatte => Icon::ObjectMatte,
Tool::Puppet => Icon::Puppet,
Tool::PuppetStarch => Icon::PuppetStarch,
Tool::PuppetBend => Icon::PuppetBend,