feat(shell): Spring and Translation in Bone properties, members edited in place, swung bones on the stage (M7)

This commit is contained in:
Tanish Manku committed 2026-11-13 00:54:27 -07:00
1 parent 42a69a3b59
commit ef3406b80d
6 files changed
+134 -20

No files matched your search

+1 -1
View File
@@ -414,7 +414,7 @@ mod tests {
for tool in [Tool::Bone, Tool::Bind, Tool::Warp, Tool::Rect, Tool::Star, Tool::Text, Tool::Pencil, Tool::Brush, Tool::PaintBrush, Tool::Eraser, Tool::PaintBucket, Tool::InkBottle, Tool::Eyedropper, Tool::Pen] {
found.extend(check(&format!("{tool:?} tool"), |a, _| a.tool = tool));
}
for panel in ["select", "motion", "motionspan", "motionpath", "motionpoints", "motionedit", "motionpins", "motionpinsspan", "rawsub", "camera", "cameraview", "bones", "shapebones", "warp", "sound", "envelope", "prefs", "shortcuts", "palette", "about", "files", "licenses", "confirm", "recovery", "frames", "actions", "script", "scriptproblems", "testscript", "onion", "onionmenu", "editmultiple", "library", "librarymenu", "edittransform", "onionsymbol", "layerprops", "frameview", "layercolour", "timelinepolish", "convert", "mixed", "bitmap", "nineslice", "nineslicedit", "find", "explorer", "publish", "publishreport", "publishanim", "start", "drop", "droplibrary", "testmovie", "testmovieinside", "templates", "savetemplate", "droptimeline", "textfields", "testtext", "softmask", "pathtext", "gradient", "gradientbucket", "swatches", "swatchpanel", "brushlibrary", "brushcurve", "paintbrush"] {
for panel in ["select", "motion", "motionspan", "motionpath", "motionpoints", "motionedit", "motionpins", "motionpinsspan", "rawsub", "camera", "cameraview", "bones", "springbones", "shapebones", "warp", "sound", "envelope", "prefs", "shortcuts", "palette", "about", "files", "licenses", "confirm", "recovery", "frames", "actions", "script", "scriptproblems", "testscript", "onion", "onionmenu", "editmultiple", "library", "librarymenu", "edittransform", "onionsymbol", "layerprops", "frameview", "layercolour", "timelinepolish", "convert", "mixed", "bitmap", "nineslice", "nineslicedit", "find", "explorer", "publish", "publishreport", "publishanim", "start", "drop", "droplibrary", "testmovie", "testmovieinside", "templates", "savetemplate", "droptimeline", "textfields", "testtext", "softmask", "pathtext", "gradient", "gradientbucket", "swatches", "swatchpanel", "brushlibrary", "brushcurve", "paintbrush"] {
found.extend(check(panel, |a, _| a.open_panel(Some(panel))));
}
// Every panel in front where it docks, and floating (ADR 0075); the other workspaces.
+27
View File
@@ -2076,6 +2076,33 @@ impl App {
self.bone_sel = Some(anicraft_engine::doc::BoneId(b2));
self.tool = Tool::Select;
}
Some("springbones") => {
// A tail on springs (ADR 0084): a body that bobs up and back down over half a
// second, its three-piece tail swinging after it, mid-swing at frame 17; the tip's
// bone picked (its joint slides along X), so Properties shows Spring and
// Translation.
self.run("layer.new", json!({"name": "Critter"}));
let id = |v: Option<Value>, k: &str| v.and_then(|v| v[k].as_u64()).unwrap_or(0);
self.run("draw.rect", json!({"x": 260, "y": 300, "w": 190, "h": 110, "radius": 36, "fill": "#5f8dd3", "stroke": "#1b2a4a", "stroke_width": 3}));
let body = id(self.run("modify.convert_to_symbol", json!({"name": "Body"})), "instance");
self.run("draw.rect", json!({"x": 450, "y": 341, "w": 120, "h": 28, "radius": 14, "fill": "#ff9f43", "stroke": "#1b2a4a", "stroke_width": 3}));
let made = self.run("modify.convert_to_symbol", json!({"name": "Tail"}));
let (symbol, t1) = (id(made.clone(), "symbol"), id(made, "instance"));
let t2 = id(self.run("library.place", json!({"symbol": symbol, "x": 620, "y": 355})), "element");
let t3 = id(self.run("library.place", json!({"symbol": symbol, "x": 730, "y": 355})), "element");
let b1 = id(self.run("bone.add", json!({"from": body, "to": t1, "head": [452, 355], "tail": [562, 355]})), "bone");
let b2 = id(self.run("bone.add", json!({"from": t1, "to": t2, "tail": [672, 355]})), "bone");
let b3 = id(self.run("bone.add", json!({"from": t2, "to": t3, "tail": [782, 355]})), "bone");
self.run("bone.pose", json!({"dx": 0, "dy": -50, "frame": 6}));
self.run("bone.pose", json!({"dx": 0, "dy": 50, "frame": 12}));
for b in [b1, b2, b3] {
self.run("bone.set_spring", json!({"bone": b, "strength": 45, "damping": 30}));
}
self.run("bone.set_translation", json!({"bone": b3, "axis": "x", "min": -20, "max": 40}));
self.run("timeline.goto", json!({"frame": 16}));
self.tool = Tool::Select;
crate::bone_tool::select(self, self.s.layer, Some(anicraft_engine::doc::BoneId(b3)));
}
Some("shapebones") => {
// A tail with bones inside it (ADR 0071): four bones, curled at frame 1 and the
// other way at frame 24, the second bone picked with the Bind tool in hand.
+12 -4
View File
@@ -15,7 +15,7 @@ use crate::app::{App, Drag, Tool};
use crate::pathtools::Xf;
use crate::theme::{T, to_color32};
use anicraft_engine::doc::armature::{self, BoneAt};
use anicraft_engine::doc::{BoneId, Element, ElementId, ElementKind, Layer, LayerId, LayerKind, evaluate_layer_elements};
use anicraft_engine::doc::{BoneId, Element, ElementId, ElementKind, Layer, LayerId, LayerKind, evaluate_layer_elements, evaluate_shown};
use anicraft_engine::geom::Vec2;
use egui::{Color32, Key, Modifiers, Pos2, Stroke, pos2};
use serde_json::json;
@@ -46,8 +46,10 @@ pub fn shown(app: &App) -> Vec<Shown> {
.filter(|(i, l)| l.kind == LayerKind::Armature && l.visible && !tl.hidden_by_folder(*i))
.filter_map(|(_, l)| {
let arm = l.armature.as_deref()?;
let (_, els) = evaluate_layer_elements(l, app.s.frame)?;
let pose = armature::pose_at(l, app.s.frame).unwrap_or_default();
// As the stage draws the armature: swung by its springs (ADR 0084).
let fps = app.s.doc.stage.fps;
let (_, els) = evaluate_shown(l, app.s.frame, None, fps)?;
let pose = anicraft_engine::doc::spring::sprung_pose(l, app.s.frame, fps).unwrap_or_default();
Some(Shown { layer: l.id, color: to_color32(l.color), locked: l.locked || tl.locked_by_folder(l.id), bones: armature::bones_at(arm, &els, &pose) })
})
.collect()
@@ -126,12 +128,18 @@ fn item_at(app: &App, sp: Vec2, slop: f32, skip: Option<ElementId>, want: impl F
None
}
/// Selects bone `bone` on armature layer `layer` (its layer becomes the active one).
/// Selects bone `bone` on armature layer `layer` (its layer becomes the active one), and the
/// instance it moves, so Properties shows that instance's colour effect, blending and filters
/// to edit in place (ADR 0084).
pub fn select(app: &mut App, layer: LayerId, bone: Option<BoneId>) {
app.bone_sel = bone;
if bone.is_some() && app.s.layer != layer {
app.run("layer.select", json!({"layer": layer.0}));
}
let child = bone.and_then(|b| app.s.timeline().layer(layer).and_then(|l| l.armature.as_ref()).filter(|a| a.skin.is_none()).and_then(|a| a.bone(b)).map(|b| b.child));
if let Some(child) = child {
app.run("element.select", json!({"ids": [child.0], "layer": layer.0}));
}
}
/// A Bone tool drag starting at screen point `press`: a new bone from the instance there (or
+1 -1
View File
@@ -596,7 +596,7 @@ fn every_control_can_be_used_in_the_pseudo_locale() {
a.run("element.set_color_effect", serde_json::json!({"style": style}));
}));
}
for panel in ["sound", "camera", "shapebones", "warp", "motion", "motionpins", "actions", "script", "prefs", "envelope", "onionmenu", "editmultiple", "edittransform", "onionsymbol", "find", "explorer", "publish", "publishreport", "publishanim", "start", "testmovie", "testmovieinside", "templates", "savetemplate", "brushlibrary", "brushcurve"] {
for panel in ["sound", "camera", "springbones", "shapebones", "warp", "motion", "motionpins", "actions", "script", "prefs", "envelope", "onionmenu", "editmultiple", "edittransform", "onionsymbol", "find", "explorer", "publish", "publishreport", "publishanim", "start", "testmovie", "testmovieinside", "templates", "savetemplate", "brushlibrary", "brushcurve"] {
found.extend(click_everything(panel, |a, _| a.open_panel(Some(panel))));
}
// Test Movie in a window of its own (ADR 0062; egui stands in for the window system here).
+1 -1
View File
@@ -255,7 +255,7 @@ fn parse_args(args: impl IntoIterator<Item = String>) -> Result<Args, String> {
/// `--help` (the console's text, in English).
#[cfg(not(target_arch = "wasm32"))]
// i18n-exempt: the --help console text
const HELP: &str = "anicraft [file.anicraft|file.fla|file.xfl] [--version] [--screenshot out.png [--shot-width <px>]] [--renderer gl|wgpu|vulkan|dx12|metal] [--theme graphite|high-contrast] [--scale <percent>] [--lang <code>|auto|pseudo] [--open palette|shortcuts|lastscene|start|drop|droplibrary|select|selectzoom|about|files|confirm|transform|points|merge|rawparts|rawedit|rawsub|rawpoints|rawsnap|rulers|editguides|editgrid|symboledit|groups|combine|nineslice|nineslicedit|brush|brushing|polystar|paintinside|drawingedit|shapeenvelope|brushlibrary|brushcurve|paintbrush|eraser|erasing|eyedropper|pen|frames|span|bucket|tlzoom|tlwide|motion|motionspan|motionpath|motionpoints|motionedit|motionpins|motionpinsspan|hints|hintsend|camera|cameraview|layerdepth|layerdepthview|filters|strokes|prefs|licenses|zoom|recovery|plugins|actions|script|scriptproblems|testmovie|testmovieinside|testscript|textfields|testtext|softmask|pathtext|button|testhits|exporthtml|publish|publishreport|publishanim|sound|envelope|library|librarymenu|colour|layerprops|frameview|layercolour|timelinepolish|dock|animator|designer|gradient|gradientbucket|swatches|swatchpanel]\n\
const HELP: &str = "anicraft [file.anicraft|file.fla|file.xfl] [--version] [--screenshot out.png [--shot-width <px>]] [--renderer gl|wgpu|vulkan|dx12|metal] [--theme graphite|high-contrast] [--scale <percent>] [--lang <code>|auto|pseudo] [--open palette|shortcuts|lastscene|start|drop|droplibrary|select|selectzoom|about|files|confirm|transform|points|merge|rawparts|rawedit|rawsub|rawpoints|rawsnap|rulers|editguides|editgrid|symboledit|groups|combine|nineslice|nineslicedit|brush|brushing|polystar|paintinside|drawingedit|shapeenvelope|brushlibrary|brushcurve|paintbrush|eraser|erasing|eyedropper|pen|frames|span|bucket|tlzoom|tlwide|motion|motionspan|motionpath|motionpoints|motionedit|motionpins|motionpinsspan|hints|hintsend|camera|cameraview|bones|springbones|shapebones|layerdepth|layerdepthview|filters|strokes|prefs|licenses|zoom|recovery|plugins|actions|script|scriptproblems|testmovie|testmovieinside|testscript|textfields|testtext|softmask|pathtext|button|testhits|exporthtml|publish|publishreport|publishanim|sound|envelope|library|librarymenu|colour|layerprops|frameview|layercolour|timelinepolish|dock|animator|designer|gradient|gradientbucket|swatches|swatchpanel]\n\
--renderer the window's graphics (also ANICRAFT_RENDERER); default automatic, falling back to OpenGL\n\
--open shows a panel at start (handy with --screenshot for visual checks)\n\
--shot-width scales the screenshot down to this width (the user guide's pictures)\n\
+92 -13
View File
@@ -629,6 +629,22 @@ pub(crate) fn properties(app: &mut App, ui: &mut egui::Ui) {
}
}
/// The Blending row of a movie clip or button instance.
fn blend_row(app: &mut App, ui: &mut egui::Ui, current: anicraft_engine::doc::BlendMode, differs: bool) {
row_prose(ui, tr!("Blending"), |ui| {
egui::ComboBox::from_id_salt("prop_blend").selected_text(crate::i18n::t(current.label())).show_ui(ui, |ui| {
for mode in anicraft_engine::doc::BlendMode::ALL {
if ui.selectable_label(mode == current, crate::i18n::t(mode.label())).clicked() && (mode != current || differs) {
app.run("element.set_blend", json!({"mode": mode.key()}));
}
}
})
.response
.set_name(tr!("Blending"));
mixed(ui, differs);
});
}
/// A symbol type's name, as the Properties panel shows it.
pub(crate) fn symbol_kind_label(kind: SymbolKind) -> &'static str {
match kind {
@@ -771,6 +787,21 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E
let many = all.len() > 1;
// Which rows differ across the selection (ADR 0053): they say "mixed", and a change sets all.
let m = crate::mixed::of(&app.s.doc, all);
// Members of an armature (ADR 0084): their bones place them, so only the look is edited
// here, in place on every pose.
let tl = app.s.timeline();
let layers = app.s.selected_layers();
if !layers.is_empty() && layers.iter().all(|l| tl.layer(*l).is_some_and(|l| l.kind == anicraft_engine::doc::LayerKind::Armature)) {
colour_effect_rows(app, ui, &e.color, m.color);
if let ElementKind::Symbol { symbol, filters, blend, .. } = &e.kind
&& app.s.doc.symbol(*symbol).is_some_and(|x| x.kind != SymbolKind::Graphic)
{
filter_rows(app, ui, filters, m.filters);
blend_row(app, ui, *blend, m.blend);
}
ui.label(text(Type::Caption, tr!("Posed by its bone: drag it with the Selection tool. Colour effect, blending and filters apply on every pose of the armature.")));
return;
}
if let ElementKind::Symbol { symbol, events, .. } = &e.kind
&& app.s.doc.symbol(*symbol).is_some_and(|x| x.kind != SymbolKind::Graphic)
{
@@ -827,19 +858,7 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E
if let ElementKind::Symbol { symbol, blend, .. } = &e.kind
&& app.s.doc.symbol(*symbol).is_some_and(|x| x.kind != SymbolKind::Graphic)
{
let current = *blend;
row_prose(ui, tr!("Blending"), |ui| {
egui::ComboBox::from_id_salt("prop_blend").selected_text(crate::i18n::t(current.label())).show_ui(ui, |ui| {
for mode in anicraft_engine::doc::BlendMode::ALL {
if ui.selectable_label(mode == current, crate::i18n::t(mode.label())).clicked() && (mode != current || m.blend) {
app.run("element.set_blend", json!({"mode": mode.key()}));
}
}
})
.response
.set_name(tr!("Blending"));
mixed(ui, m.blend);
});
blend_row(app, ui, *blend, m.blend);
}
if let ElementKind::Symbol { symbol, loop_mode, first_frame, .. } = &e.kind
&& let Some(sym) = app.s.doc.symbol(*symbol).map(|s| (s.kind, s.timeline.frame_count()))
@@ -1738,6 +1757,66 @@ fn bone_props(app: &mut App, ui: &mut egui::Ui, id: anicraft_engine::doc::BoneId
}
});
}
// Joint translation (ADR 0084): the joint may slide along X and Y, within limits.
let slide = bone.allow_slide(pose.slide(id));
for (axis, limits, now) in [("x", bone.slide_x, slide.x), ("y", bone.slide_y, slide.y)] {
let (label, name, tip) = if axis == "x" {
(tr!("X translation"), tr!("Joint X translation"), tr!("Lets the joint slide along the x axis of what the bone starts on, so the bone can stretch away from it. Posing slides it only where turning can't reach"))
} else {
(tr!("Y translation"), tr!("Joint Y translation"), tr!("Lets the joint slide along the y axis of what the bone starts on, so the bone can stretch away from it. Posing slides it only where turning can't reach"))
};
let mut on = limits.is_some();
let free = anicraft_engine::doc::Limits { min: -anicraft_engine::doc::armature::MAX_SLIDE, max: anicraft_engine::doc::armature::MAX_SLIDE };
let mut constrain = limits.is_some_and(|l| l != free);
row_prose(ui, label, |ui| {
if crate::theme::checkbox(ui, &mut on, tr!("Enable")).named(name).on_hover_text(tip).changed() {
app.run("bone.set_translation", json!({"bone": id.0, "axis": axis, "enabled": on}));
}
if on && crate::theme::checkbox(ui, &mut constrain, tr!("Constrain")).on_hover_text(tr!("Limit how far the joint slides, in every pose")).changed() {
app.run("bone.set_translation", json!({"bone": id.0, "axis": axis, "constrain": constrain}));
}
});
if let Some(l) = limits {
let mut v = now;
row(ui, if axis == "x" { tr!("Slide X") } else { tr!("Slide Y") }, |ui| {
let r = ui.add(egui::DragValue::new(&mut v).suffix(" px").speed(0.5).range(l.min..=l.max).max_decimals(1)).named(if axis == "x" { tr!("Joint slide X") } else { tr!("Joint slide Y") });
if r.on_hover_text(tr!("How far the joint has slid at the playhead, from where it was drawn")).changed() {
live(app, tr_noop!("Pose Bone"), "bone.pose", json!({"bone": id.0, if axis == "x" { "slide_x" } else { "slide_y" }: v}));
}
});
if l != free {
row(ui, if axis == "x" { tr!("Limits X") } else { tr!("Limits Y") }, |ui| {
let (mut min, mut max) = (l.min, l.max);
let a = ui.add(egui::DragValue::new(&mut min).prefix("min ").suffix(" px").speed(0.5).range(-anicraft_engine::doc::armature::MAX_SLIDE..=max).max_decimals(0)).named(if axis == "x" { tr!("Joint X translation minimum") } else { tr!("Joint Y translation minimum") });
let b = ui.add(egui::DragValue::new(&mut max).prefix("max ").suffix(" px").speed(0.5).range(min..=anicraft_engine::doc::armature::MAX_SLIDE).max_decimals(0)).named(if axis == "x" { tr!("Joint X translation maximum") } else { tr!("Joint Y translation maximum") });
if a.changed() || b.changed() {
live(app, tr_noop!("Joint Translation"), "bone.set_translation", json!({"bone": id.0, "axis": axis, "min": min, "max": max}));
}
});
}
}
}
// Spring (ADR 0084): secondary motion as the bones it hangs from move.
let sp = bone.spring.unwrap_or(anicraft_engine::doc::armature::Spring { strength: 0.0, damping: 0.0 });
let (mut strength, mut damping) = (sp.strength * 100.0, sp.damping * 100.0);
row(ui, tr!("Spring"), |ui| {
let r = ui.add(egui::DragValue::new(&mut strength).speed(0.5).range(0.0..=100.0).max_decimals(0)).named(tr!("Spring strength"));
if r.on_hover_text(tr!("How stiff the bone's spring is, 0 to 100: 0 is no spring; a stiffer spring swings faster and lags less")).changed() {
live(app, tr_noop!("Bone Spring"), "bone.set_spring", json!({"bone": id.0, "strength": strength}));
}
});
row(ui, tr!("Damping"), |ui| {
let r = ui.add(egui::DragValue::new(&mut damping).speed(0.5).range(0.0..=100.0).max_decimals(0)).named(tr!("Spring damping"));
if r.on_hover_text(tr!("How quickly the spring's swing dies down, 0 to 100: 0 swings on, 100 absorbs it all")).changed() {
live(app, tr_noop!("Bone Spring"), "bone.set_spring", json!({"bone": id.0, "damping": damping}));
}
});
let mut springs = layer.armature.as_ref().is_some_and(|a| !a.springs_off);
row_prose(ui, tr!("Springs"), |ui| {
if crate::theme::checkbox(ui, &mut springs, tr!("Enable")).named(tr!("Enable springs")).on_hover_text(tr!("Turn off to see and pose the armature's keyed poses without the springs' swing; every export plays them on")).changed() {
app.run("bone.enable_springs", json!({"layer": layer.id.0, "enabled": springs}));
}
});
// A bone inside a shape (ADR 0071): how many of the shape's points it moves.
let skin = layer.armature.as_ref().and_then(|a| a.skin.as_ref()).map(|k| (k.points.iter().filter(|p| p.weight(id) > 0.0).count(), k.points.len()));
if let Some((mine, total)) = skin {