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:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(¶ms);
|
||||
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(¶ms);
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)))
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
//! Headless checks for the Object Matte tool in the Composition viewer: the hover preview, a
|
||||
//! click (point prompt), a drag (box prompt) re-prompting the same effect, Shift adding another,
|
||||
//! one undo step each (egui_kittest, UI logic only).
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::effects::flatten_params;
|
||||
use effectcraft_engine::effects::object_matte as om;
|
||||
use effectcraft_engine::keyframe::Value;
|
||||
use effectcraft_engine::project::{GroupKind, LayerId, PropGroup};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use effectcraft_ui_egui::state::Tool;
|
||||
use egui::{Event, Modifiers, Pos2, Rect, pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
fn harness() -> Harness<'static, EffectcraftApp> {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Matte", "width": 640, "height": 360, "duration": 4})).unwrap();
|
||||
s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080", "width": 640, "height": 360})).unwrap();
|
||||
s.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap();
|
||||
s.execute("edit.deselectAll", json!({})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(move |_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> Rect {
|
||||
let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}"));
|
||||
Rect::from_min_size(pos2(e.rect[0], e.rect[1]), vec2(e.rect[2], e.rect[3]))
|
||||
}
|
||||
|
||||
/// Comp pixel → screen point.
|
||||
fn screen(h: &Harness<'_, EffectcraftApp>, p: [f32; 2]) -> Pos2 {
|
||||
let c = rect(h, "viewer.comp");
|
||||
let z = c.width() / 640.0;
|
||||
c.min + vec2(p[0] * z, p[1] * z)
|
||||
}
|
||||
|
||||
fn press(h: &mut Harness<'_, EffectcraftApp>, p: Pos2, pressed: bool, modifiers: Modifiers) {
|
||||
h.input_mut().events.push(Event::ModifiersChanged(modifiers));
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers });
|
||||
h.step();
|
||||
}
|
||||
|
||||
fn click(h: &mut Harness<'_, EffectcraftApp>, p: Pos2, modifiers: Modifiers) {
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
h.step();
|
||||
press(h, p, true, modifiers);
|
||||
press(h, p, false, modifiers);
|
||||
h.input_mut().events.push(Event::ModifiersChanged(Modifiers::NONE));
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn drag(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) -> Option<Rect> {
|
||||
h.input_mut().events.push(Event::PointerMoved(from));
|
||||
press(h, from, true, Modifiers::NONE);
|
||||
let mut drawn = None;
|
||||
for i in 1..=8 {
|
||||
h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (i as f32 / 8.0)));
|
||||
h.step();
|
||||
drawn = h.state().auto.find("viewer.objectMatte.box").map(|e| Rect::from_min_size(pos2(e.rect[0], e.rect[1]), vec2(e.rect[2], e.rect[3])));
|
||||
}
|
||||
press(h, to, false, Modifiers::NONE);
|
||||
h.run_steps(2);
|
||||
drawn
|
||||
}
|
||||
|
||||
fn box_layer(h: &Harness<'_, EffectcraftApp>) -> LayerId {
|
||||
h.state().session.active_comp().unwrap().layers.iter().find(|l| l.name == "Box").unwrap().id
|
||||
}
|
||||
|
||||
/// The Box layer's Object Matte effects.
|
||||
fn mattes(h: &Harness<'_, EffectcraftApp>) -> Vec<PropGroup> {
|
||||
let comp = h.state().session.active_comp().unwrap();
|
||||
let l = comp.layer(box_layer(h)).unwrap();
|
||||
l.effects().unwrap().groups().filter(|g| matches!(&g.kind, GroupKind::Effect { effect } if effect == om::ID)).cloned().collect()
|
||||
}
|
||||
|
||||
fn v2(g: &PropGroup, id: &str) -> [f64; 2] {
|
||||
flatten_params(g, &mut |p| p.value.clone()).get(id).map(Value::as_vec2).unwrap()
|
||||
}
|
||||
|
||||
fn near(a: [f64; 2], b: [f64; 2]) -> bool {
|
||||
(a[0] - b[0]).abs() < 1.5 && (a[1] - b[1]).abs() < 1.5
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_matte_tool_prompts_with_a_click_and_a_box() {
|
||||
let mut h = harness();
|
||||
assert_eq!(Tool::from_name("objectMatte"), Some(Tool::ObjectMatte));
|
||||
assert!(Tool::SLOTS.iter().any(|s| s.contains(&Tool::RotoBrush) && s.contains(&Tool::ObjectMatte)));
|
||||
h.state_mut().ui.tool = Tool::ObjectMatte;
|
||||
h.run_steps(2);
|
||||
// Hover: a crosshair at the pointer and the outline of the layer that would get the matte.
|
||||
let center = screen(&h, [320.0, 180.0]);
|
||||
h.input_mut().events.push(Event::PointerMoved(center));
|
||||
h.run_steps(2);
|
||||
assert!(rect(&h, "viewer.objectMatte.crosshair").contains(center));
|
||||
let target = h.state().auto.find("viewer.objectMatte.target").expect("no target outline");
|
||||
assert_eq!(target.label, "Box");
|
||||
assert!(mattes(&h).is_empty(), "hovering must not apply anything");
|
||||
let undo0 = h.state().session.history.undo.len();
|
||||
|
||||
// Click: a point prompt in layer pixels on the layer under the pointer, selected.
|
||||
click(&mut h, center, Modifiers::NONE);
|
||||
let m = mattes(&h);
|
||||
assert_eq!(m.len(), 1);
|
||||
assert!(near(v2(&m[0], "objectPoint"), [40.0, 40.0]), "{:?}", v2(&m[0], "objectPoint"));
|
||||
let uid = m[0].uid;
|
||||
let st = &h.state().session.state;
|
||||
assert!(st.selected_props.contains(&(box_layer(&h), uid)), "the new effect is selected");
|
||||
assert_eq!(h.state().session.history.undo.len(), undo0 + 1);
|
||||
|
||||
// Drag: a box (drawn while dragging) re-prompts the same effect; its centre is the point.
|
||||
// (It starts clear of the selected effect's point controls, which take drags of their own.)
|
||||
let (a, b) = (screen(&h, [286.0, 150.0]), screen(&h, [356.0, 214.0]));
|
||||
let drawn = drag(&mut h, a, b).expect("no box drawn while dragging");
|
||||
assert!(drawn.width() > 20.0);
|
||||
let m = mattes(&h);
|
||||
assert_eq!(m.len(), 1);
|
||||
assert_eq!(m[0].uid, uid);
|
||||
let ps = flatten_params(&m[0], &mut |p| p.value.clone());
|
||||
assert_eq!(ps.get("useBox"), Some(&Value::Bool(true)));
|
||||
assert!(near(v2(&m[0], "boxTopLeft"), [6.0, 10.0]), "{:?}", v2(&m[0], "boxTopLeft"));
|
||||
assert!(near(v2(&m[0], "boxBottomRight"), [76.0, 74.0]), "{:?}", v2(&m[0], "boxBottomRight"));
|
||||
assert!(near(v2(&m[0], "objectPoint"), [41.0, 42.0]), "{:?}", v2(&m[0], "objectPoint"));
|
||||
assert_eq!(h.state().session.history.undo.len(), undo0 + 2);
|
||||
|
||||
// Shift-click adds a second Object Matte.
|
||||
let p = screen(&h, [310.0, 170.0]);
|
||||
click(&mut h, p, Modifiers::SHIFT);
|
||||
let m = mattes(&h);
|
||||
assert_eq!(m.len(), 2);
|
||||
assert_eq!(m[1].name, "Object Matte 2");
|
||||
assert!(near(v2(&m[1], "objectPoint"), [30.0, 30.0]));
|
||||
|
||||
// Undo takes the prompts back one at a time.
|
||||
h.state_mut().session.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(mattes(&h).len(), 1);
|
||||
h.state_mut().session.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(flatten_params(&mattes(&h)[0], &mut |p| p.value.clone()).get("useBox"), Some(&Value::Bool(false)));
|
||||
}
|
||||
|
||||
/// Effect Controls: the Object Matte's Track and Freeze buttons run the background job and its
|
||||
/// status line shows where it is; the UI keeps drawing frames while it runs and finishes the
|
||||
/// job itself (a Freeze writes its mattes without any other job running).
|
||||
#[test]
|
||||
fn object_matte_effect_controls_track_and_freeze() {
|
||||
let mut h = harness();
|
||||
h.state_mut().show_panel(PanelKind::EffectControls);
|
||||
h.state_mut().ui.tool = Tool::ObjectMatte;
|
||||
h.run_steps(2);
|
||||
let center = screen(&h, [320.0, 180.0]);
|
||||
click(&mut h, center, Modifiers::NONE);
|
||||
let uid = mattes(&h)[0].uid;
|
||||
h.run_steps(2);
|
||||
let status = |h: &Harness<'_, EffectcraftApp>| h.state().auto.find(&format!("effectControls.objectMatte.{uid}.status")).map(|e| e.label.clone());
|
||||
assert!(status(&h).is_some(), "no Object Matte status line");
|
||||
// Freeze: a background job (the frames keep coming), then the effect is frozen.
|
||||
let b = rect(&h, &format!("effectControls.objectMatte.{uid}.freeze"));
|
||||
// Let any automatic tracking finish first (one job at a time).
|
||||
let frozen = |h: &Harness<'_, EffectcraftApp>| om::is_frozen(&flatten_params(&mattes(h)[0], &mut |p| p.value.clone()));
|
||||
let t = std::time::Instant::now();
|
||||
while h.state().session.is_roto_running() {
|
||||
assert!(t.elapsed().as_secs() < 120);
|
||||
h.step();
|
||||
}
|
||||
click(&mut h, b.center(), Modifiers::NONE);
|
||||
let t = std::time::Instant::now();
|
||||
while !frozen(&h) {
|
||||
assert!(
|
||||
t.elapsed().as_secs() < 20,
|
||||
"never frozen: {:?} / {} / running {} / {:?}",
|
||||
status(&h),
|
||||
h.state().ui.status,
|
||||
h.state().session.is_roto_running(),
|
||||
h.state().session.roto_progress()
|
||||
);
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(2);
|
||||
assert!(status(&h).is_some_and(|s| s.starts_with("Frozen")), "{:?}", status(&h));
|
||||
assert_eq!(h.state().auto.find(&format!("effectControls.objectMatte.{uid}.freeze")).map(|e| e.label.as_str()), Some("Unfreeze"));
|
||||
}
|
||||
Reference in New Issue
Block a user