M13.1: branching history, puppet pin recording, WebAssembly plug-in API, ScriptUI model and hosts, File ▸ Scripts, deterministic render test
- engine: History keeps undone lines as branches; edit.history.list/goto; History panel tree; MCP history tool - puppet.recordPin / puppet.recordOptions; viewer Cmd-drag records; Record Options form - effects::plugin (EffectPlugin trait, register_plugin, API v1); effectcraft-plugin (wasmi, sandboxed, fuel-limited); effect.plugins.load/list - ScriptUI: engine scriptui model + layout + scriptui.* commands; script crate scriptui.js and script-host threads (dialogs block show()) - File ▸ Scripts: install script / ScriptUI panel, sample scripts, window.scriptPanel - host test: bit-identical renders across runs and thread counts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ebcb8c95ce
commit
89c9b1b6ee
@@ -221,7 +221,21 @@ fn puppet_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
|
||||
}
|
||||
x = r.max.x + 12.0;
|
||||
}
|
||||
x + 4.0
|
||||
// Record Options… (⌘/Ctrl-drag a pin records its motion in real time).
|
||||
let label = "Record Options...";
|
||||
let w = 104.0;
|
||||
let r = Rect::from_min_size(pos2(x, cy - 10.0), vec2(w, 20.0));
|
||||
let resp = ui.interact(r, egui::Id::new("puppet-record-options"), egui::Sense::click()).on_hover_text("⌘/Ctrl-drag a pin to record its motion");
|
||||
p.rect_stroke(r, 3.0, egui::Stroke::new(1.0, if resp.hovered() { t.accent } else { t.field_border }), egui::StrokeKind::Inside);
|
||||
p.text(r.center(), Align2::CENTER_CENTER, label, Tokens::ui(11.5), t.text);
|
||||
app.auto.add("header.puppet.recordOptions", r, label);
|
||||
if resp.clicked() {
|
||||
let ctx = ui.ctx().clone();
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, "puppet.recordOptions", json!({})) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
r.max.x + 16.0
|
||||
}
|
||||
|
||||
fn ws_menu(app: &mut EffectcraftApp, ui: &mut egui::Ui) {
|
||||
|
||||
@@ -322,7 +322,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let searching = !query.is_empty();
|
||||
let mut y = list.min.y - scroll;
|
||||
let mut apply: Option<Apply> = None;
|
||||
let reg = effectcraft_engine::effects::registry();
|
||||
let reg = effectcraft_engine::effects::all();
|
||||
let keep = |e: &effectcraft_engine::effects::EffectSpec| depth_keeps(&view.depth, e) && (query.is_empty() || e.name.to_lowercase().contains(&query));
|
||||
let lookup = |id: &str| reg.iter().find(|e| e.id == id);
|
||||
|
||||
@@ -381,7 +381,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
effect_row(app, ui, &lp, list, &mut y, e, -16.0, &query, "effects.item", &mut apply);
|
||||
}
|
||||
} else {
|
||||
let mut cats: Vec<&str> = effectcraft_engine::effects::CATEGORIES.to_vec();
|
||||
let mut cats: Vec<&str> = effectcraft_engine::effects::categories();
|
||||
cats.retain(|c| reg.iter().any(|e| e.category == *c));
|
||||
for cat in cats {
|
||||
let items: Vec<_> = reg.iter().filter(|e| e.category == cat && keep(e)).collect();
|
||||
|
||||
@@ -136,6 +136,19 @@ pub fn open_form(app: &mut EffectcraftApp, id: &str, p: &Value) -> bool {
|
||||
1,
|
||||
)],
|
||||
),
|
||||
// Puppet tool ▸ Record Options.
|
||||
"puppet.recordOptions" if !has(p, &["speed", "smoothing", "useDraftDeformation", "showMesh"]) => {
|
||||
let o = &s.state.puppet;
|
||||
(
|
||||
"Puppet Record Options".into(),
|
||||
vec![
|
||||
Field::num("speed", "Speed (%)", o.record_speed),
|
||||
Field::num("smoothing", "Smoothing", o.record_smoothing),
|
||||
Field::bool("useDraftDeformation", "Use Draft Deformation", o.record_draft),
|
||||
Field::bool("showMesh", "Show Mesh", o.record_show_mesh),
|
||||
],
|
||||
)
|
||||
}
|
||||
"layer.setTransform" if !has(p, &["value"]) => {
|
||||
let prop = p.get("prop").and_then(Value::as_str).unwrap_or("position");
|
||||
let cur = layer.and_then(|l| l.transform()).and_then(|tr| tr.get(if prop == "anchorPoint" { "anchor" } else { prop })).map(|pr| pr.value_at(lt));
|
||||
|
||||
@@ -172,34 +172,43 @@ pub fn audio(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
pub fn history(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
// The branching history (EffectCraft's History panel): every state, branches indented under
|
||||
// the state they grew from; click any state to go there (`edit.history.goto`).
|
||||
let nodes = app.session.history_tree();
|
||||
let row_h = 22.0;
|
||||
let cur = nodes.iter().position(|n| n.current).unwrap_or(0);
|
||||
// Keep the current state in view.
|
||||
let visible = ((rect.height() - 12.0) / row_h).max(1.0) as usize;
|
||||
let first = (cur + 2).saturating_sub(visible).min(nodes.len().saturating_sub(visible));
|
||||
let mut y = rect.min.y + 6.0;
|
||||
let undo: Vec<String> = app.session.history.undo.iter().map(|u| u.0.clone()).collect();
|
||||
let redo: Vec<String> = app.session.history.redo.iter().rev().map(|u| u.0.clone()).collect();
|
||||
let n = undo.len();
|
||||
let mut jump: Option<i64> = None;
|
||||
for (i, label) in undo.iter().chain(redo.iter()).enumerate() {
|
||||
let r = Rect::from_min_size(pos2(rect.min.x, y), vec2(rect.width(), 22.0));
|
||||
y += 22.0;
|
||||
let current = i + 1 == n;
|
||||
let future = i >= n;
|
||||
let resp = ui.interact(r, egui::Id::new(("hist", i)), Sense::click());
|
||||
if current {
|
||||
let mut jump: Option<usize> = None;
|
||||
for n in nodes.iter().skip(first).take(visible + 1) {
|
||||
let r = Rect::from_min_size(pos2(rect.min.x, y), vec2(rect.width(), row_h));
|
||||
y += row_h;
|
||||
let resp = ui.interact(r, egui::Id::new(("hist", n.id.as_str())), Sense::click());
|
||||
if n.current {
|
||||
p.rect_filled(r, 0.0, t.row_selected);
|
||||
} else if resp.hovered() {
|
||||
p.rect_filled(r, 0.0, t.hover);
|
||||
}
|
||||
p.text(pos2(r.min.x + 12.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::ui(12.0), if future { t.text_faint } else { t.text });
|
||||
let x = r.min.x + 12.0 + n.depth as f32 * 14.0;
|
||||
if n.depth > 0 {
|
||||
// Branch marker.
|
||||
let c = pos2(x - 7.0, r.center().y);
|
||||
p.line_segment([pos2(c.x, r.min.y), c], egui::Stroke::new(1.0, t.text_faint));
|
||||
p.line_segment([c, pos2(c.x + 5.0, c.y)], egui::Stroke::new(1.0, t.text_faint));
|
||||
}
|
||||
let col = if !n.current && (n.future || !n.line) { t.text_faint } else { t.text };
|
||||
p.text(pos2(x, r.center().y), Align2::LEFT_CENTER, &n.label, Tokens::ui(12.0), col);
|
||||
app.auto.add(&format!("history.state.{}", n.index), r, &n.label);
|
||||
if resp.clicked() {
|
||||
jump = Some(i as i64 + 1 - n as i64);
|
||||
jump = Some(n.index);
|
||||
}
|
||||
}
|
||||
if let Some(d) = jump {
|
||||
for _ in 0..d.unsigned_abs() {
|
||||
if d < 0 {
|
||||
app.session.undo();
|
||||
} else {
|
||||
app.session.redo();
|
||||
}
|
||||
if let Some(i) = jump {
|
||||
let ctx = ui.ctx().clone();
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, "edit.history.goto", serde_json::json!({"index": i})) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,17 @@ enum Gesture {
|
||||
pin: u64,
|
||||
inv: Mat3,
|
||||
},
|
||||
/// 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
|
||||
/// current time runs along while recording.
|
||||
PuppetRecord {
|
||||
layer: LayerId,
|
||||
pin: u64,
|
||||
inv: Mat3,
|
||||
began: f64,
|
||||
cti: Tick,
|
||||
samples: Vec<(f64, [f64; 2])>,
|
||||
},
|
||||
/// Pen tool: pulling the tangents of the vertex just placed.
|
||||
Pen {
|
||||
layer: LayerId,
|
||||
@@ -861,7 +872,13 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
t if t.is_shape() => Some(Gesture::Create { tool: t, start: cpt }),
|
||||
t if t.puppet_kind().is_some() => pin_hits.iter().rev().find(|h| h.pos.distance(press) < 8.0).and_then(|h| {
|
||||
let l = comp.layer(h.layer)?;
|
||||
Some(Gesture::PuppetPin { layer: h.layer, pin: h.pin, inv: l2c(&ectx, l).0.inverse()? })
|
||||
let inv = l2c(&ectx, l).0.inverse()?;
|
||||
if mods.command {
|
||||
let lp = inv.apply(gv2(cpt[0], cpt[1]));
|
||||
let began = ui.input(|i| i.time);
|
||||
return Some(Gesture::PuppetRecord { layer: h.layer, pin: h.pin, inv, began, cti: time, samples: vec![(0.0, [lp.x, lp.y])] });
|
||||
}
|
||||
Some(Gesture::PuppetPin { layer: h.layer, pin: h.pin, inv })
|
||||
}),
|
||||
Tool::Orbit | Tool::PanCamera | Tool::Dolly => Some(Gesture::Camera { tool }),
|
||||
Tool::Selection if super::tracker::hit_at(&track_hits, press).is_some() => {
|
||||
@@ -1097,6 +1114,20 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
let _ = app.session.execute("mask.setVertex", params);
|
||||
}
|
||||
Gesture::PuppetRecord { layer, pin, inv, began, cti, mut samples } => {
|
||||
let lp = inv.apply(gv2(cpt[0], cpt[1]));
|
||||
let now = ui.input(|i| i.time) - began;
|
||||
if samples.last().is_none_or(|s| now > s.0) {
|
||||
samples.push((now, [lp.x, lp.y]));
|
||||
}
|
||||
// The current time runs with the recording (Record Options ▸ Speed).
|
||||
let speed = app.session.state.puppet.record_speed.max(1.0) / 100.0;
|
||||
app.session.set_time(cti + Tick::from_seconds_f64(now / speed));
|
||||
painter.circle_filled(pos, 6.0, Color32::from_rgb(0xe0, 0x30, 0x30));
|
||||
painter.text(pos + vec2(10.0, -10.0), Align2::LEFT_BOTTOM, "Recording", Tokens::ui(11.0), Color32::from_rgb(0xff, 0x60, 0x60));
|
||||
ui.data_mut(|dd| dd.insert_temp(gid, Gesture::PuppetRecord { layer, pin, inv, began, cti, samples }));
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
Gesture::PuppetPin { layer, pin, inv } => {
|
||||
let lp = inv.apply(gv2(cpt[0], cpt[1]));
|
||||
if let Err(e) = app.session.execute("puppet.movePin", json!({"layer": layer.0, "pin": pin, "position": [lp.x, lp.y], "merge": merge})) {
|
||||
@@ -1129,6 +1160,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if resp.drag_stopped() {
|
||||
if let (Some(g), Some(pos)) = (gesture, resp.interact_pointer_pos()) {
|
||||
match g {
|
||||
Gesture::PuppetRecord { layer, pin, cti, samples, .. } => {
|
||||
let pts: Vec<serde_json::Value> = samples.iter().map(|(t, p)| json!([t, p[0], p[1]])).collect();
|
||||
if let Err(e) = app.session.execute("puppet.recordPin", json!({"layer": layer.0, "pin": pin, "samples": pts, "start": cti.seconds()})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
Gesture::Create { tool, start } => {
|
||||
let end = map.to_comp(pos);
|
||||
create_shape(app, tool, start, end, mods.shift);
|
||||
|
||||
Reference in New Issue
Block a user