Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

Bones are picked from a list and edited where they are

Indicode BVa764c8925e74
diff --git a/crates/app/src/editor/bones.rs b/crates/app/src/editor/bones.rs
index 4940910..6e7cf3e 100644
--- a/crates/app/src/editor/bones.rs
+++ b/crates/app/src/editor/bones.rs
@@ -5,7 +5,7 @@ use anyhow::{Context, Result, bail};
use egui::{Color32, Pos2, RichText, Vec2};
use klad_core::doc::Kind;
use klad_core::ops::{BoneSpec, Op, WeightsSpec};
-use klad_core::rig::{Bone, CELL, Pose, Weights, tips, weights_for};
+use klad_core::rig::{Bone, CELL, Pose, Weights, moved, subtree, tips, weights_for};
use std::collections::BTreeMap;
use std::path::PathBuf;
@@ -17,10 +17,30 @@ pub(super) enum Mode {
Pose,
}
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(super) enum Grip {
+ Head,
+ Tail,
+ Whole,
+}
+
+#[derive(Clone, Debug, PartialEq)]
+pub(super) enum Dragging {
+ New(Option<String>),
+ Bone(String, Grip),
+}
+
+#[derive(Clone, Debug)]
+pub(super) struct Drag {
+ pub from: Vec2,
+ pub to: Vec2,
+ pub what: Dragging,
+}
+
pub(super) struct BoneTool {
pub mode: Mode,
pub selected: Option<String>,
- pub drag: Option<(Vec2, Vec2, Option<String>)>,
+ pub drag: Option<Drag>,
pub dabs: Vec<[f32; 4]>,
pub radius: f32,
pub strength: f32,
@@ -48,6 +68,8 @@ impl Default for BoneTool {
}
const NEAR: f32 = 10.0;
+const CLICK: f32 = 5.0;
+const JOINED: f32 = 0.5;
type Later = Box<dyn FnOnce(&mut Editor) -> Result<()>>;
@@ -102,15 +124,87 @@ impl Editor {
}
fn shown_pose(&self) -> Pose {
- Pose {
- angles: self.bones.pose.clone(),
- ..Pose::default()
+ match self.bones.mode {
+ Mode::Draw => Pose::default(),
+ _ => Pose {
+ angles: self.bones.pose.clone(),
+ ..Pose::default()
+ },
}
}
+ fn zoom(&self) -> f32 {
+ self.view.map_or(1.0, |v| v.zoom)
+ }
+
+ pub(super) fn pick_bone(&mut self, name: Option<String>) {
+ self.bones.name = name.clone().unwrap_or_default();
+ self.bones.selected = name;
+ self.bones.heat = None;
+ }
+
+ fn grip_at(&self, c: Vec2) -> Option<(String, String, Grip)> {
+ let bones = self.rig_bones();
+ let reach = NEAR / self.zoom();
+ let at = |p: [f32; 2]| (Vec2::new(p[0], p[1]) - c).length();
+ let picked = self.bones.selected.as_deref();
+ let joint = |b: &Bone| {
+ b.parent
+ .as_ref()
+ .and_then(|p| bones.iter().find(|o| &o.name == p))
+ .filter(|p| (p.tail[0] - b.head[0]).hypot(p.tail[1] - b.head[1]) <= JOINED)
+ .map(|p| p.name.clone())
+ };
+ bones
+ .iter()
+ .flat_map(|b| {
+ [
+ (Grip::Tail, at(b.tail)),
+ (Grip::Head, at(b.head)),
+ (Grip::Whole, near_segment(c, b.head, b.tail)),
+ ]
+ .into_iter()
+ .filter(move |(_, d)| *d <= reach)
+ .map(move |(g, d)| ((g == Grip::Whole, picked != Some(b.name.as_str()), d), b, g))
+ })
+ .min_by(|a, b| a.0.partial_cmp(&b.0).unwrap_or(std::cmp::Ordering::Equal))
+ .map(|(_, b, g)| match (g, joint(b)) {
+ (Grip::Head, Some(parent)) => (b.name.clone(), parent, Grip::Tail),
+ _ => (b.name.clone(), b.name.clone(), g),
+ })
+ }
+
+ fn drag_spec(&self, drag: &Drag) -> Option<BoneSpec> {
+ let Dragging::Bone(name, grip) = &drag.what else {
+ return None;
+ };
+ let bone = self.rig_bones().into_iter().find(|b| &b.name == name)?;
+ let d = drag.to - drag.from;
+ let by = |p: [f32; 2]| [p[0] + d.x, p[1] + d.y];
+ Some(BoneSpec {
+ layer: self.rig_owner()?,
+ moved: Some(name.clone()),
+ head: (*grip == Grip::Head).then(|| by(bone.head)),
+ tail: (*grip == Grip::Tail).then(|| by(bone.tail)),
+ by: (*grip == Grip::Whole).then_some([d.x, d.y]),
+ ..BoneSpec::default()
+ })
+ }
+
+ fn drawn_bones(&self) -> Vec<Bone> {
+ let bones = self.rig_bones();
+ self.bones
+ .drag
+ .as_ref()
+ .filter(|d| (d.to - d.from).length() * self.zoom() >= CLICK)
+ .and_then(|d| self.drag_spec(d))
+ .and_then(|s| moved(&bones, s.moved.as_deref()?, s.head, s.tail, s.by).ok())
+ .unwrap_or(bones)
+ }
+
fn bone_at(&self, c: Vec2) -> Option<String> {
let bones = self.rig_bones();
- let zoom = self.view.map_or(1.0, |v| v.zoom);
+ let zoom = self.zoom();
let shown = tips(&bones, &self.shown_pose());
bones
.iter()
@@ -123,16 +217,40 @@ impl Editor {
pub(super) fn bone_down(&mut self, c: Vec2) {
match self.bones.mode {
- Mode::Draw => {
+ Mode::Draw if self.modifiers.alt => {
let bones = self.rig_bones();
- let zoom = self.view.map_or(1.0, |v| v.zoom);
- let parent = bones
+ let reach = NEAR / self.zoom();
+ let from_tail = bones
.iter()
- .filter(|b| (Vec2::new(b.tail[0], b.tail[1]) - c).length() <= NEAR / zoom)
- .map(|b| (b.name.clone(), Vec2::new(b.tail[0], b.tail[1])))
- .next();
- let start = parent.as_ref().map_or(c, |p| p.1);
- self.bones.drag = Some((start, c, parent.map(|p| p.0)));
+ .find(|b| (Vec2::new(b.tail[0], b.tail[1]) - c).length() <= reach)
+ .map(|b| (b.name.clone(), Vec2::new(b.tail[0], b.tail[1])));
+ let (parent, from) = match from_tail {
+ Some((name, tail)) => (Some(name), tail),
+ None => (self.bone_at(c), c),
+ };
+ self.bones.drag = Some(Drag {
+ from,
+ to: c,
+ what: Dragging::New(parent),
+ });
+ }
+ Mode::Draw => {
+ let what = match self.grip_at(c) {
+ Some((picked, moving, grip)) => {
+ if self.bones.selected.as_ref() != Some(&picked) {
+ self.pick_bone(Some(picked));
+ }
+ Dragging::Bone(moving, grip)
+ }
+ None => Dragging::New(None),
+ };
+ self.bones.drag = Some(Drag { from: c, to: c, what });
+ }
+ Mode::Weights if self.modifiers.command => {
+ let found = self.bone_at(c);
+ if found.is_some() {
+ self.pick_bone(found);
+ }
}
Mode::Weights => {
self.bones.dabs.clear();
@@ -140,8 +258,8 @@ impl Editor {
}
Mode::Pose => {
self.bones.turning = self.bone_at(c);
- if let Some(b) = &self.bones.turning {
- self.bones.selected = Some(b.clone());
+ if let Some(b) = self.bones.turning.clone() {
+ self.pick_bone(Some(b));
}
}
}
@@ -163,7 +281,7 @@ impl Editor {
match self.bones.mode {
Mode::Draw => {
if let Some(drag) = self.bones.drag.as_mut() {
- drag.1 = c;
+ drag.to = c;
}
}
Mode::Weights => {
@@ -193,14 +311,23 @@ impl Editor {
pub(super) fn bone_up(&mut self) -> Result<()> {
match self.bones.mode {
Mode::Draw => {
- let Some((a, b, parent)) = self.bones.drag.take() else {
+ let Some(drag) = self.bones.drag.take() else {
return Ok(());
};
- if (b - a).length() < 6.0 {
- self.bones.selected = self.bone_at(b);
- self.bones.name = self.bones.selected.clone().unwrap_or_default();
- return Ok(());
- }
+ let short = (drag.to - drag.from).length() * self.zoom() < CLICK;
+ let parent = match (&drag.what, short) {
+ (Dragging::Bone(..), true) => return Ok(()),
+ (Dragging::Bone(..), false) => {
+ let spec = self.drag_spec(&drag).context("that bone is gone")?;
+ return self.apply(vec![Op::Bone(spec)]);
+ }
+ (Dragging::New(_), true) => {
+ self.pick_bone(self.bone_at(drag.to));
+ return Ok(());
+ }
+ (Dragging::New(parent), false) => parent.clone(),
+ };
+ let (a, b) = (drag.from, drag.to);
let owner = self
.rig_owner()
.context("pick the layer or group the bones go on first")?;
@@ -212,17 +339,12 @@ impl Editor {
self.apply(vec![Op::Bone(BoneSpec {
layer: owner,
add: Some(name.clone()),
- rm: None,
- rename: None,
- to_name: None,
- moved: None,
- reparent: None,
parent,
head: Some([a.x, a.y]),
tail: Some([b.x, b.y]),
+ ..BoneSpec::default()
})])?;
- self.bones.name = name.clone();
- self.bones.selected = Some(name);
+ self.pick_bone(Some(name));
}
Mode::Weights => {
let dabs = std::mem::take(&mut self.bones.dabs);
@@ -233,7 +355,7 @@ impl Editor {
.bones
.selected
.clone()
- .context("pick a bone to paint its weights: click it in draw mode")?;
+ .context("pick a bone to paint its weights: cmd click it, or pick it in the skeleton list")?;
self.paint_weights(WeightsSpec {
layer: self.rig_owner().context("no skeleton here")?,
frame: self.scene.frame,
@@ -263,15 +385,7 @@ impl Editor {
pub(super) fn bone_edit(&mut self, edit: impl FnOnce(&mut BoneSpec)) -> Result<()> {
let mut spec = BoneSpec {
layer: self.rig_owner().context("no skeleton here")?,
- add: None,
- rm: None,
- rename: None,
- to_name: None,
- moved: None,
- reparent: None,
- parent: None,
- head: None,
- tail: None,
+ ..BoneSpec::default()
};
edit(&mut spec);
self.apply(vec![Op::Bone(spec)])
@@ -308,12 +422,12 @@ impl Editor {
(
Mode::Draw,
"draw",
- "drag to draw a bone; start on a bone's end to make it its child; click a bone to pick it",
+ "drag on empty canvas to draw a bone; drag a bone's end or middle to move it; alt drag from a bone's end for a child",
),
(
Mode::Weights,
"weights",
- "paint the picked bone's weight; alt removes it",
+ "paint the picked bone's weight; alt removes it; cmd click a bone to pick it",
),
(Mode::Pose, "pose", "drag a bone's end to turn it, its children follow"),
]
@@ -340,6 +454,10 @@ impl Editor {
}
});
ui.separator();
+ if let Some(later) = self.skeleton_list(ui) {
+ run = Some(later);
+ }
+ ui.separator();
match self.bones.mode {
Mode::Draw => {
if let Some(picked) = self.bones.selected.clone() {
@@ -355,18 +473,21 @@ impl Editor {
s.rename = Some(picked);
s.to_name = Some(to.clone());
})?;
- e.bones.selected = Some(to);
+ e.pick_bone(Some(to));
Ok(())
}));
+ } else if let Some(later) = self.parent_menu(ui, &picked) {
+ run = Some(later);
} else if ui.button("remove").hint("the picked bone and its children").clicked() {
run = Some(Box::new(move |e| {
e.bone_edit(|s| s.rm = Some(picked))?;
- e.bones.selected = None;
+ e.pick_bone(None);
Ok(())
}));
}
+ ui.label(RichText::new("drag its ends or middle; alt drag: a child").color(theme::WEAK));
} else {
- ui.label(RichText::new("drag on the canvas to draw a bone").color(theme::WEAK));
+ ui.label(RichText::new("drag to draw a bone; click one to pick it").color(theme::WEAK));
}
}
Mode::Weights => {
@@ -417,7 +538,7 @@ impl Editor {
self.bones
.selected
.as_deref()
- .map_or("click a bone in draw mode first".to_string(), |b| {
+ .map_or("pick a bone: cmd click it, or pick it in the list".to_string(), |b| {
format!("painting {b}")
}),
)
@@ -443,6 +564,135 @@ impl Editor {
Ok(())
}
+ fn skeleton_list(&mut self, ui: &mut egui::Ui) -> Option<Later> {
+ let bones = self.rig_bones();
+ let doc = &self.scene.bundle.doc;
+ if bones.is_empty() {
+ let owners: Vec<(String, String)> = doc
+ .all_layers()
+ .into_iter()
+ .filter(|l| !l.bones.is_empty())
+ .map(|l| (l.id.clone(), l.name.clone()))
+ .collect();
+ if owners.is_empty() {
+ ui.label(RichText::new("no skeleton yet").color(theme::WEAK));
+ return None;
+ }
+ let here = self
+ .scene
+ .active_layer()
+ .map_or("this layer".to_string(), |l| l.name.clone());
+ ui.label(RichText::new(format!("{here} has no bones; skeletons are on")).color(theme::WEAK));
+ return owners.into_iter().fold(None, |run, (id, name)| {
+ let clicked = ui
+ .button(format!("{} {name}", theme::icon::TURN))
+ .hint(format!("make {name} the active layer to see and edit its bones"))
+ .clicked();
+ run.or_else(|| {
+ clicked.then(|| -> Later {
+ Box::new(move |e| {
+ let Some(klad_core::doc::Loc::Layer(path)) = e.scene.bundle.doc.locate(&id) else {
+ bail!("that layer is gone");
+ };
+ e.pick_bone(None);
+ e.activate(path)
+ })
+ })
+ })
+ });
+ }
+ let owner = self
+ .rig_owner()
+ .and_then(|o| doc.layer(&o).map(|l| l.name.clone()))
+ .unwrap_or_default();
+ let picked = self
+ .bones
+ .selected
+ .clone()
+ .filter(|p| bones.iter().any(|b| &b.name == p));
+ let depth = |b: &Bone| {
+ std::iter::successors(b.parent.clone(), |p| {
+ bones.iter().find(|o| &o.name == p).and_then(|o| o.parent.clone())
+ })
+ .count()
+ };
+ let mut chosen = None;
+ ui.menu_button(
+ format!("{} {}", theme::icon::TURN, picked.as_deref().unwrap_or("pick a bone")),
+ |ui| {
+ ui.label(
+ RichText::new(format!("the bones of {owner}"))
+ .color(theme::WEAK)
+ .small(),
+ );
+ bones.iter().for_each(|b| {
+ ui.horizontal(|ui| {
+ ui.add_space(14.0 * depth(b) as f32);
+ if ui
+ .selectable_label(picked.as_ref() == Some(&b.name), &b.name)
+ .hint(match &b.parent {
+ Some(p) => format!("pick {}, a child of {p}", b.name),
+ None => format!("pick {}, a root bone", b.name),
+ })
+ .clicked()
+ {
+ chosen = Some(b.name.clone());
+ ui.close();
+ }
+ });
+ });
+ },
+ )
+ .response
+ .hint(format!("the skeleton of {owner}, each bone under its parent: pick one"));
+ chosen.map(|name| -> Later {
+ Box::new(move |e| {
+ e.pick_bone(Some(name));
+ Ok(())
+ })
+ })
+ }
+
+ fn parent_menu(&mut self, ui: &mut egui::Ui, picked: &str) -> Option<Later> {
+ let bones = self.rig_bones();
+ let current = bones.iter().find(|b| b.name == picked)?.parent.clone();
+ let below = subtree(&bones, picked);
+ let mut chosen: Option<Option<String>> = None;
+ let label = ui.label("parent");
+ egui::ComboBox::from_id_salt("bones.parent")
+ .selected_text(current.as_deref().unwrap_or("none"))
+ .show_ui(ui, |ui| {
+ std::iter::once(None)
+ .chain(
+ bones
+ .iter()
+ .filter(|b| !below.contains(&b.name))
+ .map(|b| Some(b.name.clone())),
+ )
+ .for_each(|p| {
+ if ui
+ .selectable_label(p == current, p.as_deref().unwrap_or("none"))
+ .clicked()
+ && p != current
+ {
+ chosen = Some(p);
+ }
+ });
+ })
+ .response
+ .labelled_by(label.id)
+ .hint("the bone this one hangs from; none makes it a root");
+ let name = picked.to_string();
+ chosen.map(|parent| -> Later {
+ Box::new(move |e| {
+ e.bone_edit(|s| {
+ s.reparent = Some(name);
+ s.parent = parent;
+ })
+ })
+ })
+ }
+
fn heat_texture(&mut self, bone: &str) -> Option<egui::TextureHandle> {
let rev = self.scene.bundle.doc.rev;
if let Some((b, r, t)) = &self.bones.heat
@@ -494,8 +744,9 @@ impl Editor {
Color32::WHITE,
);
}
- let bones = self.rig_bones();
+ let bones = self.drawn_bones();
let shown = tips(&bones, &self.shown_pose());
+ let editing = self.bones.mode == Mode::Draw;
bones.iter().zip(shown).for_each(|(b, (h, t))| {
let (a, z) = (place(Vec2::new(h[0], h[1])), place(Vec2::new(t[0], t[1])));
let picked = self.bones.selected.as_ref() == Some(&b.name);
@@ -508,6 +759,12 @@ impl Editor {
painter.line_segment([a, z], egui::Stroke::new(3.0, colour));
painter.circle_filled(a, 4.5, colour);
painter.circle_stroke(z, 4.0, egui::Stroke::new(1.5, colour));
+ if picked && editing {
+ [a, z].into_iter().for_each(|p| {
+ painter.circle_filled(p, 6.5, Color32::WHITE);
+ painter.circle_stroke(p, 6.5, egui::Stroke::new(2.0, theme::ACCENT));
+ });
+ }
painter.text(
a + (z - a) * 0.5 + egui::vec2(6.0, -6.0),
egui::Align2::LEFT_BOTTOM,
@@ -516,8 +773,27 @@ impl Editor {
colour,
);
});
- if let Some((a, b, _)) = self.bones.drag {
- painter.line_segment([place(a), place(b)], egui::Stroke::new(2.0, theme::ACCENT));
+ if let Some(Drag {
+ from,
+ to,
+ what: Dragging::New(_),
+ }) = &self.bones.drag
+ {
+ painter.line_segment([place(*from), place(*to)], egui::Stroke::new(2.0, theme::ACCENT));
+ }
+ if editing
+ && self.bones.drag.is_none()
+ && let Some(p) = hover
+ {
+ let cursor = match (self.modifiers.alt, self.grip_at(p)) {
+ (true, _) => None,
+ (false, Some((_, _, Grip::Whole))) => Some(egui::CursorIcon::Move),
+ (false, Some(_)) => Some(egui::CursorIcon::Grab),
+ (false, None) => None,
+ };
+ if let Some(c) = cursor {
+ self.ctx.set_cursor_icon(c);
+ }
}
if self.bones.mode == Mode::Weights
&& let Some(p) = hover
diff --git a/crates/app/src/editor/ui_tests.rs b/crates/app/src/editor/ui_tests.rs
index 760c611..fd5645a 100644
--- a/crates/app/src/editor/ui_tests.rs
+++ b/crates/app/src/editor/ui_tests.rs
@@ -2542,9 +2542,17 @@ fn bones_are_drawn_weighted_and_posed_on_the_canvas() {
canvas_at(&h, 170.0, 120.0),
canvas_at(&h, 300.0, 200.0),
);
+ let canvas = h.state().canvas_rect;
drag(&mut h, a, b);
h.run_steps(2);
+ assert_eq!(
+ h.state().canvas_rect,
+ canvas,
+ "picking a bone keeps the canvas where it is"
+ );
+ h.event(egui::Event::ModifiersChanged(Modifiers::ALT));
drag(&mut h, b, c);
+ h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
h.run_steps(2);
let bones = |h: &Harness<'static, Editor>| h.state().scene.bundle.doc.layer("l6").unwrap().bones.clone();
let made = bones(&h);
@@ -2552,9 +2560,12 @@ fn bones_are_drawn_weighted_and_posed_on_the_canvas() {
assert_eq!(
made[1].parent.as_deref(),
Some("bone 1"),
- "a bone started on a tail is its child"
+ "a bone alt dragged from a tail is its child"
+ );
+ assert!(
+ (made[1].tail[0] - 300.0).abs() < 2.0 && (made[1].tail[1] - 200.0).abs() < 2.0,
+ "{made:?}"
);
- assert!((made[1].tail[0] - 300.0).abs() < 2.0 && (made[1].tail[1] - 200.0).abs() < 2.0);
h.state_mut().bones.name = "shin".into();
h.state_mut()
.bone_edit(|s| {
@@ -2582,6 +2593,123 @@ fn bones_are_drawn_weighted_and_posed_on_the_canvas() {
let _ = std::fs::remove_dir_all(&path);
}
+#[test]
+fn bones_are_picked_from_the_list_and_the_canvas_and_edited_in_place() {
+ let path = sample("bone-edit");
+ Bundle::open(&path)
+ .unwrap()
+ .apply(
+ &parse_lines(
+ r#"{"op":"bone","layer":"l6","add":"thigh","head":[100,60],"tail":[100,160]}
+{"op":"bone","layer":"l6","add":"shin","parent":"thigh","head":[100,160],"tail":[100,260]}
+{"op":"bone","layer":"l6","add":"tail","head":[300,100],"tail":[400,100]}"#,
+ )
+ .unwrap(),
+ )
+ .unwrap();
+ let mut h = harness(editor(&path), vec2(1440.0, 1000.0));
+ let bones = |h: &Harness<'static, Editor>| h.state().scene.bundle.doc.layer("l6").unwrap().bones.clone();
+ let bone = |h: &Harness<'static, Editor>, name: &str| bones(h).into_iter().find(|b| b.name == name).unwrap();
+ activate(&mut h, "colour");
+ h.key_press(Key::J);
+ h.run_steps(2);
+ assert!(
+ h.query_by_label_contains("colour has no bones").is_some(),
+ "a layer without bones says where the skeletons are"
+ );
+ h.get_by_label(&format!("{} lines", theme::icon::TURN)).click();
+ h.run_steps(3);
+ assert_eq!(h.state().scene.active_layer().unwrap().name, "lines");
+ h.get_by_label_contains("pick a bone").click();
+ h.run_steps(2);
+ h.get_by_label("shin").click();
+ h.run_steps(2);
+ assert_eq!(
+ h.state().bones.selected.as_deref(),
+ Some("shin"),
+ "picked from the list"
+ );
+ h.get_by_label("weights").click();
+ h.run_steps(2);
+ let tail = canvas_at(&h, 350.0, 100.0);
+ h.event(egui::Event::ModifiersChanged(Modifiers::COMMAND));
+ h.hover_at(tail);
+ h.run_steps(1);
+ [true, false].into_iter().for_each(|pressed| {
+ h.event(egui::Event::PointerButton {
+ pos: tail,
+ button: egui::PointerButton::Primary,
+ pressed,
+ modifiers: Modifiers::COMMAND,
+ });
+ h.run_steps(1);
+ });
+ h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
+ h.run_steps(2);
+ assert_eq!(
+ h.state().bones.selected.as_deref(),
+ Some("tail"),
+ "cmd click picks in weights mode"
+ );
+ assert!(
+ h.state()
+ .scene
+ .bundle
+ .read_weights("l6")
+ .map_or(true, |w| !w.maps.contains_key("tail")),
+ "a cmd click paints no weight"
+ );
+ h.get_by_label("draw").click();
+ h.run_steps(2);
+ let (knee, there) = (canvas_at(&h, 100.0, 160.0), canvas_at(&h, 140.0, 170.0));
+ drag(&mut h, knee, there);
+ h.run_steps(2);
+ let (thigh, shin) = (bone(&h, "thigh"), bone(&h, "shin"));
+ assert!(
+ (thigh.tail[0] - 140.0).abs() < 1.5 && (thigh.tail[1] - 170.0).abs() < 1.5,
+ "{thigh:?}"
+ );
+ assert_eq!(shin.head, thigh.tail, "the knee moves the shin's head along");
+ assert_eq!(shin.tail, [100.0, 260.0]);
+ assert_eq!(
+ h.state().bones.selected.as_deref(),
+ Some("thigh"),
+ "pressing a bone picks it"
+ );
+ let (middle, along) = (canvas_at(&h, 350.0, 100.0), canvas_at(&h, 350.0, 140.0));
+ drag(&mut h, middle, along);
+ h.run_steps(2);
+ let moved = bone(&h, "tail");
+ assert!(
+ (moved.head[1] - 140.0).abs() < 1.5 && (moved.tail[1] - 140.0).abs() < 1.5,
+ "{moved:?}"
+ );
+ h.event(egui::Event::ModifiersChanged(Modifiers::ALT));
+ let (foot, toe) = (canvas_at(&h, 100.0, 260.0), canvas_at(&h, 160.0, 280.0));
+ drag(&mut h, foot, toe);
+ h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
+ h.run_steps(2);
+ let foot = bones(&h).last().unwrap().clone();
+ assert_eq!(
+ foot.parent.as_deref(),
+ Some("shin"),
+ "alt drag from a tail makes a child"
+ );
+ assert_eq!(foot.head, [100.0, 260.0]);
+ h.state_mut().pick_bone(Some("tail".into()));
+ h.run_steps(2);
+ h.get_by_label("parent").click();
+ h.run_steps(2);
+ h.get_by_label("thigh").click();
+ h.run_steps(2);
+ assert_eq!(
+ bone(&h, "tail").parent.as_deref(),
+ Some("thigh"),
+ "the parent menu reparents"
+ );
+ let _ = std::fs::remove_dir_all(&path);
+}
+
#[test]
fn a_layer_is_keyed_from_the_inspector_and_eases_between_its_keys() {
let path = sample("keyed-layer");
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
index a863545..43ba68b 100644
--- a/crates/cli/src/main.rs
+++ b/crates/cli/src/main.rs
@@ -1163,7 +1163,7 @@ enum Command {
},
#[command(
about = "Add, remove, rename, move or reparent a bone of a layer's or group's skeleton",
- long_about = "Bones go on a paint layer or a group (a group's skeleton poses every paint layer in it together). A bone has a name, an optional parent, a head and a tail in canvas px; a child usually starts where its parent ends. Removing a bone removes its children.\n\n klad bone art.klad body --add hip --head 400,500 --tail 400,420\n klad bone art.klad body --add thigh --parent hip --head 400,500 --tail 410,620\n klad bone art.klad body --rename thigh --as femur\n klad bone art.klad body --move femur --tail 420,630\n klad bone art.klad body --reparent femur --parent pelvis\n klad bone art.klad body --rm femur\n\nAlso a bone op: {\"op\":\"bone\",\"layer\":\"body\",\"add\":\"thigh\",\"parent\":\"hip\",\"head\":[400,500],\"tail\":[410,620]}."
+ long_about = "Bones go on a paint layer or a group (a group's skeleton poses every paint layer in it together). A bone has a name, an optional parent, a head and a tail in canvas px; a child usually starts where its parent ends. Removing a bone removes its children. Moving a tail takes the heads of the children that start there along; --by moves a bone with all its children.\n\n klad bone art.klad body --add hip --head 400,500 --tail 400,420\n klad bone art.klad body --add thigh --parent hip --head 400,500 --tail 410,620\n klad bone art.klad body --rename thigh --as femur\n klad bone art.klad body --move femur --tail 420,630\n klad bone art.klad body --move femur --by 12,-4\n klad bone art.klad body --reparent femur --parent pelvis\n klad bone art.klad body --rm femur\n\nAlso a bone op: {\"op\":\"bone\",\"layer\":\"body\",\"add\":\"thigh\",\"parent\":\"hip\",\"head\":[400,500],\"tail\":[410,620]}."
)]
Bone {
bundle: PathBuf,
@@ -1186,6 +1186,8 @@ enum Command {
head: Option<[f32; 2]>,
#[arg(long, value_parser = parse_pair, allow_hyphen_values = true)]
tail: Option<[f32; 2]>,
+ #[arg(long, value_parser = parse_pair, allow_hyphen_values = true, help = "dx,dy in px: with --move, the bone and its children")]
+ by: Option<[f32; 2]>,
#[command(flatten)]
flags: EditFlags,
},
@@ -2797,6 +2799,7 @@ fn run() -> Result<()> {
parent,
head,
tail,
+ by,
flags,
} => {
let spec = BoneSpec {
@@ -2810,6 +2813,7 @@ fn run() -> Result<()> {
parent,
head,
tail,
+ by,
};
agent::edit(&bundle, &[Op::Bone(spec)], &output(&flags, 0))?;
}
diff --git a/crates/cli/src/rig.rs b/crates/cli/src/rig.rs
index e65b323..1093605 100644
--- a/crates/cli/src/rig.rs
+++ b/crates/cli/src/rig.rs
@@ -398,6 +398,22 @@ mod tests {
bundle.read_weights("l1").unwrap().maps.contains_key("fore"),
"undo restores the weights file"
);
+ edit(&dir, r#"{"op":"bone","layer":"l1","move":"fore","tail":[470,230]}"#).unwrap();
+ let bones = Bundle::open(&dir).unwrap().doc.layer("l1").unwrap().bones.clone();
+ assert_eq!(
+ bones[2].head,
+ [470.0, 230.0],
+ "the hand starts where the forearm now ends"
+ );
+ edit(&dir, r#"{"op":"bone","layer":"l1","move":"upper","by":[0,-20]}"#).unwrap();
+ let lifted = Bundle::open(&dir).unwrap().doc.layer("l1").unwrap().bones.clone();
+ assert!(
+ lifted
+ .iter()
+ .zip(&bones)
+ .all(|(a, b)| a.head == [b.head[0], b.head[1] - 20.0] && a.tail == [b.tail[0], b.tail[1] - 20.0]),
+ "by moves a bone with its children: {lifted:?}"
+ );
edit(&dir, r#"{"op":"bone","layer":"l1","rm":"upper"}"#).unwrap();
assert!(
Bundle::open(&dir).unwrap().doc.layer("l1").unwrap().bones.is_empty(),
diff --git a/crates/core/src/ops.rs b/crates/core/src/ops.rs
index 1c8263b..68d5591 100644
--- a/crates/core/src/ops.rs
+++ b/crates/core/src/ops.rs
@@ -622,7 +622,7 @@ pub struct GrassSpec {
pub part: Option<String>,
}
-#[derive(Clone, Debug, PartialEq, Deserialize)]
+#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BoneSpec {
pub layer: String,
@@ -644,6 +644,8 @@ pub struct BoneSpec {
pub head: Option<[f32; 2]>,
#[serde(default)]
pub tail: Option<[f32; 2]>,
+ #[serde(default)]
+ pub by: Option<[f32; 2]>,
}
#[derive(Clone, Debug, PartialEq, Deserialize)]
@@ -1705,13 +1707,8 @@ fn bone(doc: &mut Document, spec: &BoneSpec, out: &mut Applied) -> Result<()> {
out.renamed_bones.push((id.clone(), name.clone(), to.clone()));
}
(None, None, None, Some(name), None) => {
- let at = find(&bones, name)?;
- if let Some(h) = spec.head {
- bones[at].head = h;
- }
- if let Some(t) = spec.tail {
- bones[at].tail = t;
- }
+ find(&bones, name)?;
+ bones = crate::rig::moved(&bones, name, spec.head, spec.tail, spec.by)?;
}
(None, None, None, None, Some(name)) => {
let at = find(&bones, name)?;
diff --git a/crates/core/src/rig.rs b/crates/core/src/rig.rs
index b8bb6db..3f8e130 100644
--- a/crates/core/src/rig.rs
+++ b/crates/core/src/rig.rs
@@ -93,6 +93,58 @@ pub fn check(bones: &[Bone]) -> Result<()> {
})
}
+pub fn subtree(bones: &[Bone], name: &str) -> Vec<String> {
+ let mut found = vec![name.to_string()];
+ bones.iter().for_each(|b| {
+ if b.parent.as_ref().is_some_and(|p| found.contains(p)) && !found.contains(&b.name) {
+ found.push(b.name.clone());
+ }
+ });
+ found
+}
+
+const JOINED: f32 = 0.5;
+
+pub fn moved(
+ bones: &[Bone],
+ name: &str,
+ head: Option<[f32; 2]>,
+ tail: Option<[f32; 2]>,
+ by: Option<[f32; 2]>,
+) -> Result<Vec<Bone>> {
+ let at = bones
+ .iter()
+ .position(|b| b.name == name)
+ .ok_or_else(|| anyhow!("no bone {name}"))?;
+ let mut out = bones.to_vec();
+ match (head, tail, by) {
+ (None, None, Some([dx, dy])) => {
+ let moving = subtree(bones, name);
+ out.iter_mut().filter(|b| moving.contains(&b.name)).for_each(|b| {
+ b.head = [b.head[0] + dx, b.head[1] + dy];
+ b.tail = [b.tail[0] + dx, b.tail[1] + dy];
+ });
+ }
+ (None, None, None) => bail!("say where: head, tail or by"),
+ (_, _, Some(_)) => bail!("by moves the whole bone; give it without head or tail"),
+ (head, tail, None) => {
+ let old = bones[at].tail;
+ if let Some(h) = head {
+ out[at].head = h;
+ }
+ if let Some(t) = tail {
+ out[at].tail = t;
+ out.iter_mut()
+ .filter(|b| {
+ b.parent.as_deref() == Some(name) && (b.head[0] - old[0]).hypot(b.head[1] - old[1]) <= JOINED
+ })
+ .for_each(|b| b.head = t);
+ }
+ }
+ }
+ Ok(out)
+}
+
type Mat = [f32; 6];
fn mul(a: Mat, b: Mat) -> Mat {
@@ -588,6 +640,31 @@ mod tests {
]
}
+ #[test]
+ fn a_moved_tail_takes_the_joined_children_along_and_by_moves_the_family() {
+ let mut bones = leg();
+ bones.push(Bone {
+ name: "spur".into(),
+ parent: Some("thigh".into()),
+ head: [120.0, 150.0],
+ tail: [140.0, 150.0],
+ });
+ let bent = moved(&bones, "thigh", None, Some([130.0, 190.0]), None).unwrap();
+ assert_eq!(bent[0].tail, [130.0, 190.0]);
+ assert_eq!(bent[1].head, [130.0, 190.0], "the shin starts where the thigh ends");
+ assert_eq!(bent[1].tail, [100.0, 300.0]);
+ assert_eq!(bent[2].head, [120.0, 150.0], "a child that starts elsewhere stays");
+ let shifted = moved(&bones, "thigh", None, None, Some([5.0, -10.0])).unwrap();
+ assert!(shifted.iter().all(|b| {
+ let was = bones.iter().find(|o| o.name == b.name).unwrap();
+ b.head == [was.head[0] + 5.0, was.head[1] - 10.0] && b.tail == [was.tail[0] + 5.0, was.tail[1] - 10.0]
+ }));
+ let shin = moved(&bones, "shin", None, None, Some([5.0, 0.0])).unwrap();
+ assert_eq!(shin[0], bones[0], "moving a child leaves its parent");
+ assert!(moved(&bones, "shin", Some([0.0, 0.0]), None, Some([1.0, 1.0])).is_err());
+ assert_eq!(subtree(&bones, "thigh"), ["thigh", "shin", "spur"]);
+ }
+
#[test]
fn automatic_weights_add_up_and_fall_off_across_the_joint() {
let bones = leg();
diff --git a/docs/DESIGN.md b/docs/DESIGN.md
index afa873c..89c9b5b 100644
--- a/docs/DESIGN.md
+++ b/docs/DESIGN.md
@@ -1,4 +1,4 @@
-_Last updated: 2026-11-06 15:37_
+_Last updated: 2026-11-06 16:56_
# klad: design
@@ -246,7 +246,7 @@ Every layer has `blend`, `opacity`, `visible`, `locked`, optional `mask`, `clip`
- **Fonts (M5, S5.26).** klad ships about fifty open families for game art in `fonts/` (sans, serif, mono, display, handwriting, pixel; OFL-1.1 or Apache-2.0, unchanged from the Google Fonts repository at a pinned commit, listed with their licences in the notices; `fonts/update.py` fetches them again). `klad_render::fonts` finds that folder next to the binary (also `../Resources/fonts` in a Mac app and the repository's `fonts/` for development builds; `KLAD_FONTS` overrides), and keeps families downloaded on request in a per-user folder (`~/Library/Application Support/klad/fonts`, `$XDG_DATA_HOME/klad/fonts`, `%APPDATA%\klad\fonts`). `fonts/catalogue.json` lists every open family on Google Fonts (about 1,900) with its group and folder at the same commit, so `klad fonts --search` works offline and a download (`klad fonts --get`, or naming a family anywhere a font is taken) fetches exactly that commit's files with `curl`. Choosing a font anywhere (the CLI's `font=`, `klad font`, the editor's picker) copies the file and its licence into the bundle; the node keeps the file name. This replaces M5 choice 3 (no fonts with the app). The editor's frame and plane caches fold `klad_render::RENDER_VERSION` into their keys, so pictures cached before a renderer change are not shown again. A light layer is no kind of its own: a paint layer set to `add` with a soft glow (a shortcut button for it only confused the layers pane).
- **Foliage (M5, S5.27).** `foliage` is a shape op (CLI only, principle 7): each closed shape becomes a clump built from leaf strokes on a jittered grid, each coloured from the clump lit as a round form (a normal from its bounding ellipse, mixed with the normal of an optional `mass` shape so clumps turn with the whole crown, a key light or a lamp, the underside darker) and stepped into three value families between `shade`, `color` and `lit` (OKLab; by default darker and cooler, lighter and warmer), with more variety in the light; then leaves along the outline, kept more where the outline faces the light or the sky, a few in `glow` on the shadow edge. Strokes are sorted dark to light so lit leaves land on top. It puts how foliage is painted (light families on the clump, the big mass before the texture, a broken silhouette) into one op, so an agent does not scatter leaves like confetti.
- **No agent inside the editor (M8).** A first version ran a model in an Agent pane with the user's Claude API key; it was removed on 2026-11-06 in favour of an MCP server that any agent client can use (planned). Agents work on a drawing through the `klad` CLI, and the person reaches them through notes, the selection and the shared history.
-- **Rigs (M6).** A paint layer or a group gets `bones` (format 9): each a name, an optional parent that comes before it, a head and a tail in canvas px. A group's skeleton poses every paint layer in it together, so a character's lines, colour and shading layers stay in step. Each bone has a weight map in `weights/<owner>.weights` (zstd: a JSON header with the grid size and bone names, then one byte per cell per bone, cells of 4 px), written by `Bundle::apply` with the edit and kept in its history step; weights are normalised across bones when read (bilinear between cells), and a place no bone weighs follows the nearest bone. Automatic weights are 1/(d + 0.15 L + 1)^3 by distance to each bone segment (L its length), so joints blend over a short stretch; `set` paints soft dabs (smoothstep falloff towards a value), `part` gives a named part's cells to one bone at 1 and the others 0, `smooth` blurs every map once. A pose (`pose` on a cel: its rest drawing's id, an angle per bone in degrees from rest, a root move) is linear blend skinning: each bone's rest matrix (head, angle) and posed matrix (its parent's posed matrix times the rest offset times its turn) give a skin matrix, and every stroke sample moves by the weighted sum; stroke sizes scale by the mean local stretch (the Jacobian's determinant, square-rooted); polygon fills move their points; flood fills are warped through a 4 px triangle mesh over their coverage (each posed triangle rasterised, sampling the rest coverage by barycentric position). The rest pose returns the marks untouched. `pose` (computed by the CLI, `cli/src/rig.rs`) makes or re-poses a drawing at `to` on every paint layer under the skeleton from the rest drawing shown at `from` (a posed drawing's own rest when `from` shows one). In-betweens of two poses of one rest drawing (or a pose and its rest) mix the angles and root by t instead of matching strokes (`rig::posed_pair`), and keep the mixed pose. The editor's bone tool (J) draws bones (from a bone's end makes a child), picks, renames and removes them, paints weights in its own process (`klad_core::rig::weights_for`) over a tint of the picked bone's map, and turns bones in pose mode, committing the pose through `klad pose` as a job; the drawing is not deformed live while turning, only the skeleton.
+- **Rigs (M6).** A paint layer or a group gets `bones` (format 9): each a name, an optional parent that comes before it, a head and a tail in canvas px. A group's skeleton poses every paint layer in it together, so a character's lines, colour and shading layers stay in step. Each bone has a weight map in `weights/<owner>.weights` (zstd: a JSON header with the grid size and bone names, then one byte per cell per bone, cells of 4 px), written by `Bundle::apply` with the edit and kept in its history step; weights are normalised across bones when read (bilinear between cells), and a place no bone weighs follows the nearest bone. Automatic weights are 1/(d + 0.15 L + 1)^3 by distance to each bone segment (L its length), so joints blend over a short stretch; `set` paints soft dabs (smoothstep falloff towards a value), `part` gives a named part's cells to one bone at 1 and the others 0, `smooth` blurs every map once. A pose (`pose` on a cel: its rest drawing's id, an angle per bone in degrees from rest, a root move) is linear blend skinning: each bone's rest matrix (head, angle) and posed matrix (its parent's posed matrix times the rest offset times its turn) give a skin matrix, and every stroke sample moves by the weighted sum; stroke sizes scale by the mean local stretch (the Jacobian's determinant, square-rooted); polygon fills move their points; flood fills are warped through a 4 px triangle mesh over their coverage (each posed triangle rasterised, sampling the rest coverage by barycentric position). The rest pose returns the marks untouched. `pose` (computed by the CLI, `cli/src/rig.rs`) makes or re-poses a drawing at `to` on every paint layer under the skeleton from the rest drawing shown at `from` (a posed drawing's own rest when `from` shows one). In-betweens of two poses of one rest drawing (or a pose and its rest) mix the angles and root by t instead of matching strokes (`rig::posed_pair`), and keep the mixed pose. A bone `move` with a `tail` takes along the heads of the children that start at the old tail (within half a pixel), and `by` moves a bone with all its children (`rig::moved`, which the editor also draws while dragging). The editor's bone tool (J) has three modes (draw, weights, pose) and in every mode a skeleton list in its options (each bone under its parent; picking one highlights it on the canvas); with no skeleton on the active layer the options name the layers and groups that have one, each a button that makes it active. Picking on the canvas is a click in draw and pose mode and cmd click (ctrl outside macOS) in weights mode. In draw mode a drag on empty canvas draws a root bone, a press on a bone picks it and drags what is under the pointer (the picked bone shows handles at both ends): an end moves that end, the middle moves the bone and its children, and the head of a child that starts at its parent's tail is that joint, so dragging it moves the parent's tail; alt drag from a tail draws a child (from a bone's middle, a child starting there); the options rename, reparent (a parent menu without the bone's own children) and remove. Draw mode shows the skeleton at rest. Weights are painted in the editor's own process (`klad_core::rig::weights_for`) over a tint of the picked bone's map, and pose mode turns bones, committing the pose through `klad pose` as a job; the drawing is not deformed live while turning, only the skeleton.
- **Keys (M6, S6.5).** Layers, groups and vector nodes keep `keys`: per property (`x`, `y`, `rotate`, `sx`, `sy`, `opacity`) a sorted list of frame, value and ease (linear, in, out, in-out, step, or a cubic curve x1,y1,x2,y2 solved by bisection). A segment follows its first key's ease; values hold before the first key and after the last. Layers and groups composite with their keyed opacity and, when moved, with their keyed transform about the canvas centre (drawn whole, not tile by tile, while moved); nodes take keyed transforms and opacity when rasterised (`nodes_at`). The editor's frame and plane caches hash the keyed values; its vector raster cache does not follow node keys yet, so keyed shapes move in `klad render` and the exports, not in the editor.
- **Godot scenes (M6, S6.6, S6.7).** `export --godot-scene` flattens each visible top-level layer (with its fog; the background with the first) into a texture on a `Parallax2D` with `scroll_scale` 1/(1 + depth), the factor the editor's depth preview (hold D) uses. `export --godot-rig` writes per skeleton: each part of the rest drawing (named parts of each paint layer's rest drawing, the loose marks as one) replayed alone, trimmed, on a `Polygon2D` with a 16 px triangle mesh over its pixels (one cell of margin), UVs, and per-vertex weights sampled from the maps; a `Skeleton2D` with a `Bone2D` per bone at rest (local position and angle against the parent, `rest`, `length`); and an `AnimationPlayer` with one animation per clip (or one for the timeline) whose value tracks hold each bone's rest angle plus its pose at the frame each posed drawing starts (stepped, so drawings hold as in klad); frames that are not poses of the rest drawing are listed for the frames export. Re-exports keep their uids. `samples/rig` builds a figure with all of it.
- **Paint over (M5, S5.29).** `paintover` (`cli/src/paintover.rs`, resolved before the shape ops, alone in its batch) flattens the source (the `from` layers, or every visible layer below the target's top-level layer with the background) into OKLab, then follows Hertzmann's painterly method: for each brush size, biggest first, the source is blurred to that size, a grid at half the size finds cells whose mean difference from the painting so far (an estimate made by stamping discs of each stroke's colour) exceeds `threshold`, and a stroke starts at each such cell's worst pixel in a seeded random order. A stroke walks in steps of half its size across the luminance gradient (Sobel), turning towards it by `curve` times how sure the gradient is (weak gradients keep the stroke's direction; with none, a smooth seeded field of mostly level angles), and stops past its minimum length when the source there is closer to the painting than to the stroke's colour, at a colour change over twice the threshold, at the edge of the region or at its maximum length. `focus` keeps the last size to a shape grown by three of those sizes. Each stroke becomes a stroke op with a press-in and lift-off pressure, its size a little varied, its colour broken by `vary` from a hash of its seed, in the part `part`. `like <cel>` carries a paint-over to another drawing: every source paint layer's two drawings are paired as in-betweens pair them; each stroke rides the topmost source mark under its centre (a stroke within half its size, a polygon fill, a flood fill's coverage) with `tween::carry` along that mark's line (still marks: it stays; marks gone: it fades to opacity 0); it keeps its seed and is recoloured from the new source at its start, faded when it would now cross an edge; new strokes, in `<part> added`, only go where the source changed (its colour or alpha, grown by the biggest size) or where carried strokes left a gap. `--frames a-b` repeats that drawing to drawing, making a drawing on the target wherever a source layer starts one (a link where they link). `samples/paintover` paints over the lemons and carries a paint-over through the creature's walk; frame to frame its background changes by 0.03 of 255 on average.
@@ -415,7 +415,7 @@ An error is one line on stderr (`error: reading a.klad/doc.json: No such file or
| `klad export <bundle> --godot [dir] [--store] [--scale s]` | the sheet, a `SpriteFrames` `.tres` and an `AnimatedSprite2D` `.tscn` (see Exports) |
| `klad hash <bundle> [--frame n] [--all]` | pixel hash for the parity check; `--all` one line per frame |
| `klad open [bundle]` | the editor; without a bundle, the start window: New, Open (the platform's open panel or a pasted path), Recent with thumbnails |
-| `klad bone <bundle> <layer> --add n [--parent p] --head x,y --tail x,y`, `--rm n`, `--rename n --as m`, `--move n [--head] [--tail]`, `--reparent n [--parent p]`; `klad bones <bundle> [--json]` | skeletons (see Rigs) |
+| `klad bone <bundle> <layer> --add n [--parent p] --head x,y --tail x,y`, `--rm n`, `--rename n --as m`, `--move n [--head] [--tail]` or `--move n --by dx,dy`, `--reparent n [--parent p]`; `klad bones <bundle> [--json]` | skeletons (see Rigs) |
| `klad weights <bundle> <layer> --auto \| --bone b --set 'x,y,r,w ...' \| --bone b --part p [--value v] \| --smooth` | how much each bone moves the drawing |
| `klad pose <bundle> <layer> [--from f] --to f --bone name=deg ... [--root x,y] [--hold n]` | a posed drawing from the rest drawing |
| `klad key <bundle> <id> --frame f prop=value ... [--ease e] [--rm]`; `klad keys <bundle> [id] [--json]` | animate layers, groups and shapes (see Keys) |
diff --git a/docs/cli.md b/docs/cli.md
index 9c92471..5abb09a 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -2107,12 +2107,13 @@ Options:
## klad bone
```text
-Bones go on a paint layer or a group (a group's skeleton poses every paint layer in it together). A bone has a name, an optional parent, a head and a tail in canvas px; a child usually starts where its parent ends. Removing a bone removes its children.
+Bones go on a paint layer or a group (a group's skeleton poses every paint layer in it together). A bone has a name, an optional parent, a head and a tail in canvas px; a child usually starts where its parent ends. Removing a bone removes its children. Moving a tail takes the heads of the children that start there along; --by moves a bone with all its children.
klad bone art.klad body --add hip --head 400,500 --tail 400,420
klad bone art.klad body --add thigh --parent hip --head 400,500 --tail 410,620
klad bone art.klad body --rename thigh --as femur
klad bone art.klad body --move femur --tail 420,630
+ klad bone art.klad body --move femur --by 12,-4
klad bone art.klad body --reparent femur --parent pelvis
klad bone art.klad body --rm femur
@@ -2155,6 +2156,9 @@ Options:
--tail <TAIL>
+ --by <BY>
+ dx,dy in px: with --move, the bone and its children
+
--render
Render a preview after the edit and print its path
diff --git a/docs/skill/SKILL.md b/docs/skill/SKILL.md
index 75b28c7..28e94a2 100644
--- a/docs/skill/SKILL.md
+++ b/docs/skill/SKILL.md
@@ -232,6 +232,7 @@ klad export art.klad --godot-rig game/art --godot-scene game/art
```
- Angles are degrees from the rest pose, positive turning clockwise on screen; a child follows its parent. Pose from the rest drawing (`--from` its frame); posing a frame again re-poses it.
+- Fix a skeleton in place: `--move upper --tail 570,350` moves an end (children that start at that tail come along), `--move upper --by 10,0` moves a bone with all its children, `--reparent hand --parent fore` changes a parent. The user does the same in the bone tool: the skeleton list picks a bone, its ends and middle drag, alt drag from an end draws a child.
- Automatic weights bend joints over a short stretch; hold rigid things (head, hands, props) with `--part`, or a stiff limb with dabs at 1. Look at `--overlay weights:<bone>` before posing.
- Keys move whole layers, groups and shapes (`x`, `y`, `rotate`, `sx`, `sy`, `scale`, `opacity`) between frames with an ease (`linear`, `in`, `out`, `in-out`, `step`, or a curve `x1,y1,x2,y2`); a segment follows its first key's ease. A lantern that floats, a glow that pulses, a far plane that drifts: no drawing per frame.
- Godot: `--godot` exports frames (always works), `--godot-rig` a Skeleton2D with Polygon2D parts and an AnimationPlayer per clip (only frames that are poses of the rest drawing; the others are listed), `--godot-scene` one Parallax2D per top-level layer scrolling by its depth. `samples/rig` builds all of it.