Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
HG6a: hands stay out of the scene's solids; HG7a: a low thing is taken by bending with the feet planted, and the take says where to stand; HG4a: the carry is against the body. body.rs: clear moves a wrist's place the least that keeps the hand 2 cm off every solid in a take's avoid list; stoop lowers the hips and bends the trunk for hands that must go low, by as much as the hands have got along their reach, with leg IK holding both ankles within 5 mm; stand_for gives the place a forearm off the thing's near face (character.take answers it as stand). The wrist's path arcs up and backs off a hold's surface when leaving. 16 tests: a box on the floor held within 2 cm with the hips over 30 cm down, no point of the hand in a table at any frame. Rendered on a psx person: a cup taken over a table's edge, a box lifted from the floor onto a table. Not right yet: the squat folds the head to the knees, and the body itself keeps out of nothing
shinyobjectz613645ffc6b1
diff --git a/docs/hands.feature b/docs/hands.featureindex 6c19e10e..81b82452 100644--- a/docs/hands.feature+++ b/docs/hands.feature@@ -130,25 +130,57 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri| raea-sys-grab | src/json.rs | 120 | a frame of a take asked for as JSON || sdk | sdk/character/src/take.ts | 80 | take(): the call made, typed |+ @done+ Scenario: HG6a. Hands stay out of the scene's solids+ # 11-14, built: body.rs `clear`, a take's `avoid` list. A wrist's place is moved the least that keeps the+ # wrist, the palm and the fingers' reach 2 cm clear of every solid named; the wrist's path arcs up 6 cm and+ # leaves a hold backing off its surface. With a table under a cup, no point of the hand is in the table at+ # any frame of the take, and keeping clear costs the hold under 6 mm. Seen on turbo: the hand comes over the+ # table's edge onto the cup and leaves it without passing through the top.+ Given a take with the solids round it named (a table, a shelf)+ Then no frame has the hand inside one, and the hold is still kept++ @done+ Scenario: HG7a. A low thing is taken by bending, the feet planted; and the body is told where to stand+ # 11-14, built: body.rs `stoop` and `stand_for`. For hands that must go lower than 0.7 of an arm below the+ # shoulders, the hips come down (to 0.5 m) and the trunk bends at the hips and along the spine (to 57+ # degrees), by as much as the hands have got along their reach, so the body rises again as the thing is+ # lifted. Leg IK keeps both ankles where they stood within 5 mm and the feet's turn. A box on the floor is+ # held within 2 cm; the hips come down over 30 cm and are back up with the box carried. `stand_for` gives+ # the place a forearm's length off the thing's near face, facing it; standing there both hands reach.+ # character.take answers it as `stand`. Seen on turbo: a box lifted from the floor onto a table. Not right+ # yet: the squat folds the head down to the knees, and the body itself keeps out of nothing (the head went+ # into the table that stood 38 cm in front).+ Given a thing lower than the arms reach, or out of reach+ Then the body bends and squats for a low one with its feet where they stand+ And for a far one the take says where to stand and which way to face++ @done+ Scenario: HG4a. The carry is against the body+ # 11-14: a two-handed thing rides 10 cm under the chest joint, 20 cm plus half its size in front, so the+ # elbows bend and the lift shows (it was carried at arm's length, hardly lifted).+ Then a carried box is held against the belly with the elbows bent+Rule: Next, in order@needs:HG5Scenario: HG6. The rig's real limits and the body's real shape# sdk/body has both in TypeScript (limits.ts: ranges checked against 26,288 captured frames; shape.ts,- # shell.ts: the skin). systems/grab has caps on the trunk's lean and finger ranges only.+ # shell.ts: the skin). systems/grab has caps on the trunk's lean and finger ranges, and HG6a for the hands.Given a solved armThen every joint is inside the range sdk/body's limits give, the elbow and wrist first- And the arm, the hand and the held thing stay out of the body and off a table's top, by the least move+ And the forearm, the elbow, the trunk, the head and the held thing stay out of the body and the scene's+ solids, by the least moveAnd one copy of the limits serves both the TypeScript and the Rust@needs:HG5- Scenario: HG7. The body goes to the thing- # A take starts only when the body is where it can reach (docs/character.md, principle 6). Today a thing- # out of reach is missed and reported.- Given a thing out of reach, on the floor, a table or a shelf- Then locomotion is asked to arrive where both holds are in reach, facing it- And a low thing is taken from a crouch or a bend chosen from the library's pick-low and lift captures,- with the hands' holds laid over it+ Scenario: HG7. The body walks to the thing+ # HG7a says where to stand; nothing walks there yet.+ Given a thing out of reach+ Then locomotion (sdk/body's) is asked to arrive at the take's standing place, facing it, and the take+ starts when it has+ And a low thing's bend is checked against the library's pick-low and lift captures, and takes its shape+ from them where they fit (the back straighter, the head up)@needs:HG5Scenario: HG8. Things with a way to be helddiff --git a/sdk/character/src/take.ts b/sdk/character/src/take.tsindex a5eb5d47..32266419 100644--- a/sdk/character/src/take.ts+++ b/sdk/character/src/take.ts@@ -10,7 +10,8 @@//// `base` is the body's own motion, its pose at any time (a clip, a walk, a stand): the take only moves what the hands// need and says how much (`moved`, degrees) and how far a wrist ended from its hold (`miss`, metres). A thing out of-// reach is missed and said so; walk the body to it first. Frame-pure: any frame can be asked for.+// reach is missed and said so: `stand` is where to walk the body to first. A low thing (on the floor) is taken by+// bending and squatting, the feet staying where they stand. Frame-pure: any frame can be asked for.import { native } from "@raea/app/native";import type { Pose, Quat, Skeleton } from "./character/core";@@ -40,6 +41,8 @@ export interface TakeSpec {hand?: "L" | "R";/** how far below the thing's middle the hands go, metres */lower?: number;+ /** the scene's solids the hands keep out of (a table's top, a shelf) */+ avoid?: TakeThing[];/** set down: moved to `place` from `at`, standing there from `down` */put?: { at: number; down: number; place: Vec3 };/** let go at `at` with a velocity, metres a second; it falls to `floor` (0) */@@ -55,6 +58,9 @@ export interface Taken {miss: number;/** the most any joint was turned from the body's own motion, degrees */moved: number;+ /** where the body would stand to take the thing, and the turn about the vertical that faces it: walk it there first+ * when the thing is out of reach */+ stand: { at: Vec3; yaw: number };}/** The body and the thing at `t` seconds of a take. */diff --git a/sdk/raea/src/native-calls.ts b/sdk/raea/src/native-calls.tsindex f0c863a8..d448e146 100644--- a/sdk/raea/src/native-calls.ts+++ b/sdk/raea/src/native-calls.ts@@ -37,7 +37,7 @@ export interface NativeCalls {/** an svg <text>'s getComputedTextLength and getStartPositionOfChar: its words laid out by usvg, as the page draws an svg, in its computed font (font-*, letter-spacing, word-spacing); x from the text's own (docs/layout-reads.feature LR7) */"canvas.svgText": { args: { text: string; style: Record<string, string> }; answer: { length: number; starts: number[] } };/** a frame of a character taking a thing with its hands (reach, grab, lift, carry, put down or throw): the pose to draw and where the thing is, with how far a wrist missed (metres) and how far the body was turned from its own motion (degrees) */- "character.take": { args: { joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; t: number; base: { t: number; root: [number, number, number]; turns: [number, number, number, number][] }[]; thing: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }; start: number; grab?: number; carried?: number; carry?: [number, number, number]; hand?: "L" | "R"; lower?: number; put?: { at: number; down: number; place: [number, number, number] }; throw?: { at: number; velocity: [number, number, number]; floor?: number } }; answer: { pose: { root: [number, number, number]; turns: [number, number, number, number][] }; thing: { at: [number, number, number]; turn: [number, number, number, number] }; phase: "Before" | "Reach" | "Lift" | "Carry" | "Release" | "After"; hands: 1 | 2; miss: number; moved: number } };+ "character.take": { args: { joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; t: number; base: { t: number; root: [number, number, number]; turns: [number, number, number, number][] }[]; thing: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }; start: number; grab?: number; carried?: number; carry?: [number, number, number]; hand?: "L" | "R"; lower?: number; avoid?: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }[]; put?: { at: number; down: number; place: [number, number, number] }; throw?: { at: number; velocity: [number, number, number]; floor?: number } }; answer: { pose: { root: [number, number, number]; turns: [number, number, number, number][] }; thing: { at: [number, number, number]; turn: [number, number, number, number] }; phase: "Before" | "Reach" | "Lift" | "Carry" | "Release" | "After"; hands: 1 | 2; miss: number; moved: number; stand: { at: [number, number, number]; yaw: number } } };/** raea's command line (render, play, guide, bundle, types; the media verbs: raea media, raea ffmpeg), run in process in cwd */"cli.raea": { args: { args: string[]; cwd: string }; answer: { exit: number; stdout: string; stderr: string } };/** a headless run ends with this exit code */diff --git a/systems/grab/src/body.rs b/systems/grab/src/body.rsnew file mode 100644index 00000000..2efefcc3--- /dev/null+++ b/systems/grab/src/body.rs@@ -0,0 +1,80 @@+//! What the rest of the body does for the hands. `stoop`: for a thing lower than the arms reach, the hips come down+//! and the trunk bends forward at the hips and along the spine, with both feet kept where they stand by leg IK, so a+//! thing on the floor is taken by bending and squatting. `clear`: a hand's place moved the least that keeps it out of+//! the scene's solids (a table's top). `stand_for`: where the body should stand to take a thing, for whatever walks+//! it there (a take starts only when the body is where it can reach: docs/character.md, principle 6).++use glam::{Quat, Vec3};++use crate::arm::{ArmOptions, two_bone};+use crate::hand::HandRest;+use crate::rig::{Pose, Posed, Side, Skeleton};+use crate::shape::Thing;++/// how far below the shoulders, in arm lengths, the hands go before the body bends for them+const EASY: f32 = 0.7;++/// The body bent and lowered for hands that must get down to `low` (a height, metres), by `amount` (0 to 1) of what+/// that needs. `own` drawn is `w`; `face` is the level way the body faces.+pub fn stoop(skel: &Skeleton, own: &Pose, w: &Posed, face: Vec3, low: f32, amount: f32) -> Pose {+ let (Some(l), Some(r)) = (skel.arm(Side::L), skel.arm(Side::R)) else { return own.clone() };+ let shoulders = (w.pos[l[0]].y + w.pos[r[0]].y) / 2.0;+ let arm = skel.offset(l[1]).length() + skel.offset(l[2]).length();+ let short = (shoulders - EASY * arm) - low;+ if short <= 0.0 || amount <= 0.0 {+ return own.clone();+ }+ // the hips take over half of it by coming down, the trunk the rest by bending+ let (drop, pitch) = ((short * 0.6).min(0.5) * amount, (short * 1.1).min(1.0) * amount);+ let left = Vec3::Y.cross(face);+ let mut pose = own.clone();+ // the hips go back a little as the trunk goes forward, as a body keeps its balance+ pose.root = own.root - Vec3::Y * drop - face * (0.12 * pitch);+ pose.turns[0] = (Quat::from_axis_angle(left, pitch * 0.4) * own.turns[0]).normalize();+ for name in ["spine_01", "spine_02", "spine_03"] {+ if let Some(i) = skel.joint(name) {+ pose.turns[i] = (own.turns[i] * Quat::from_rotation_x(pitch * 0.2)).normalize();+ }+ }+ // the feet stay where they stand, turned as they were, the knees going forward+ for s in Side::BOTH {+ let x = s.sx();+ let leg = [format!("thigh_{x}"), format!("calf_{x}"), format!("foot_{x}")].map(|n| skel.joint(&n));+ let [Some(a), Some(b), Some(c)] = leg else { continue };+ let pole = face + left * (0.25 * s.sign());+ pose = two_bone(skel, &pose, [a, b, c], w.pos[c], ArmOptions { pole: Some(pole), end: Some(w.rot[c]), soft: 0.0 }).pose;+ }+ pose+}++/// A wrist's place moved the least that keeps the hand (its wrist, palm and fingers' reach) clear of every solid.+pub fn clear(wrist: Vec3, turn: Quat, rest: &HandRest, solids: &[Thing]) -> Vec3 {+ const MARGIN: f32 = 0.02;+ let points = [Vec3::ZERO, rest.mid, rest.along * 0.17];+ let mut at = wrist;+ for _ in 0..4 {+ let mut worst: Option<(f32, Vec3)> = None;+ for solid in solids {+ for p in points {+ let p = at + turn * p;+ let d = solid.distance(p) - MARGIN;+ if d < worst.map_or(0.0, |w| w.0) {+ worst = Some((d, solid.normal(p)));+ }+ }+ }+ let Some((d, normal)) = worst else { break };+ at -= normal * d;+ }+ at+}++/// Where a body coming from `from` should stand to take a thing, and the turn about the vertical to face it.+pub fn stand_for(thing: &Thing, from: Vec3) -> (Vec3, f32) {+ let to = Vec3::new(from.x - thing.at.x, 0.0, from.z - thing.at.z).try_normalize().unwrap_or(Vec3::NEG_Z);+ let far = thing.solid.bound() + 0.1;+ // how far the thing comes toward the body, and a forearm's length off that+ let edge = thing.cast(thing.at + to * far, -to, far).map_or(thing.solid.bound(), |h| (h.at - thing.at).dot(to));+ let at = thing.at + to * (edge + 0.3);+ (Vec3::new(at.x, from.y, at.z), (-to.x).atan2(-to.z))+}diff --git a/systems/grab/src/json.rs b/systems/grab/src/json.rsindex 712ef3d2..d46ac0c1 100644--- a/systems/grab/src/json.rs+++ b/systems/grab/src/json.rs@@ -5,13 +5,14 @@use glam::{Quat, Vec3};use serde_json::{Value, json};+use crate::body::stand_for;use crate::hand::{Grip, HoldOptions, find_holds};use crate::rig::{Pose, Side, Skeleton};use crate::shape::{Solid, Thing};use crate::take::{Release, Take, perform};-pub const TAKE_ARGS: &str = "{ joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; t: number; base: { t: number; root: [number, number, number]; turns: [number, number, number, number][] }[]; thing: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }; start: number; grab?: number; carried?: number; carry?: [number, number, number]; hand?: \"L\" | \"R\"; lower?: number; put?: { at: number; down: number; place: [number, number, number] }; throw?: { at: number; velocity: [number, number, number]; floor?: number } }";-pub const TAKE_ANSWER: &str = "{ pose: { root: [number, number, number]; turns: [number, number, number, number][] }; thing: { at: [number, number, number]; turn: [number, number, number, number] }; phase: \"Before\" | \"Reach\" | \"Lift\" | \"Carry\" | \"Release\" | \"After\"; hands: 1 | 2; miss: number; moved: number }";+pub const TAKE_ARGS: &str = "{ joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; t: number; base: { t: number; root: [number, number, number]; turns: [number, number, number, number][] }[]; thing: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }; start: number; grab?: number; carried?: number; carry?: [number, number, number]; hand?: \"L\" | \"R\"; lower?: number; avoid?: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }[]; put?: { at: number; down: number; place: [number, number, number] }; throw?: { at: number; velocity: [number, number, number]; floor?: number } }";+pub const TAKE_ANSWER: &str = "{ pose: { root: [number, number, number]; turns: [number, number, number, number][] }; thing: { at: [number, number, number]; turn: [number, number, number, number] }; phase: \"Before\" | \"Reach\" | \"Lift\" | \"Carry\" | \"Release\" | \"After\"; hands: 1 | 2; miss: number; moved: number; stand: { at: [number, number, number]; yaw: number } }";fn num(v: &Value, what: &str) -> Result<f32, String> {v.as_f64().map(|n| n as f32).ok_or_else(|| format!("character.take: {what} isn't a number"))@@ -59,9 +60,11 @@ pub fn take_json(v: &Value) -> Result<Value, String> {// the body's own motion at a time: the pose given nearest itlet own = |t: f32| base.iter().min_by(|a, b| (a.0 - t).abs().total_cmp(&(b.0 - t).abs())).map(|b| b.1.clone()).unwrap_or_else(|| skel.rest());- let shape = &v["thing"];- let turn = if shape["turn"].is_null() { Quat::IDENTITY } else { quat(&shape["turn"], "thing.turn")? };- let thing = Thing { solid: solid(shape)?, at: vec3(&shape["at"], "thing.at")?, turn };+ let placed = |shape: &Value| -> Result<Thing, String> {+ let turn = if shape["turn"].is_null() { Quat::IDENTITY } else { quat(&shape["turn"], "a thing's turn")? };+ Ok(Thing { solid: solid(shape)?, at: vec3(&shape["at"], "a thing's at")?, turn })+ };+ let thing = placed(&v["thing"])?;let start = num(&v["start"], "start")?;let mut options = HoldOptions::default();if v["hand"] == "L" {@@ -83,6 +86,9 @@ pub fn take_json(v: &Value) -> Result<Value, String> {if !v["carry"].is_null() {take.carry = vec3(&v["carry"], "carry")?;}+ for solid in v["avoid"].as_array().into_iter().flatten() {+ take.avoid.push(placed(solid)?);+ }if let Some(p) = v.get("put").filter(|p| !p.is_null()) {take.release = Some(Release::Put { at: num(&p["at"], "put.at")?, down: num(&p["down"], "put.down")?, place: vec3(&p["place"], "put.place")? });} else if let Some(t) = v.get("throw").filter(|t| !t.is_null()) {@@ -91,6 +97,8 @@ pub fn take_json(v: &Value) -> Result<Value, String> {}let f = perform(&skel, &own, &take, num(&v["t"], "t")?);+ // where the body would stand to take it, for a scene that walks it there first+ let (stand, facing) = stand_for(&thing, own(start).root);let turns: Vec<[f32; 4]> = f.pose.turns.iter().map(|q| q.to_array()).collect();Ok(json!({"pose": { "root": f.pose.root.to_array(), "turns": turns },@@ -99,5 +107,6 @@ pub fn take_json(v: &Value) -> Result<Value, String> {"hands": if matches!(grip, Grip::One(_)) { 1 } else { 2 },"miss": f.miss,"moved": f.moved,+ "stand": { "at": stand.to_array(), "yaw": facing },}))}diff --git a/systems/grab/src/lib.rs b/systems/grab/src/lib.rsindex d84d37bc..c6235970 100644--- a/systems/grab/src/lib.rs+++ b/systems/grab/src/lib.rs@@ -6,10 +6,13 @@//! - `arm`: two-bone IK with a pole, a reach that leans the trunk, and the wrist's twist shared with the forearm.//! - `shape`: a thing as a signed distance: ray casts, normals, clearance.//! - `hand`: hold points found on the thing, the wrist that lays a palm on one, fingers curled onto the surface.+//! - `body`: the body bent and squatted for a low thing with its feet planted, hands kept out of the scene's solids,+//! and where to stand to take a thing.//! - `take`: reach, grab, lift, carry, put down or throw, as one timeline.//! - `json`: a take asked for as JSON, the engine's native call `character.take` (raea/character's `take`).pub mod arm;+pub mod body;pub mod hand;pub mod json;pub mod rig;@@ -18,6 +21,7 @@ pub mod take;pub use arm::{ArmOptions, IkReport, forearm_twist, reach, two_bone};pub use json::{TAKE_ANSWER, TAKE_ARGS, take_json};+pub use body::{clear, stand_for, stoop};pub use hand::{Grip, Hold, HoldOptions, Touch, curl, find_holds, wrist_for};pub use rig::{Pose, Posed, Side, Skeleton, mannequin};pub use shape::{Solid, Thing};diff --git a/systems/grab/src/take.rs b/systems/grab/src/take.rsindex 9fe04ff5..5a7781f7 100644--- a/systems/grab/src/take.rs+++ b/systems/grab/src/take.rs@@ -9,7 +9,8 @@use glam::{Quat, Vec3};use crate::arm::{ArmOptions, forearm_twist, reach};-use crate::hand::{Grip, Touch, curl, facing, wrist_for};+use crate::body::{clear, stoop};+use crate::hand::{Grip, Touch, curl, facing, hand_rest, wrist_for};use crate::rig::{Pose, Posed, Skeleton};use crate::shape::Thing;@@ -33,6 +34,8 @@ pub struct Take {/// where the thing's centre rides, from the chest: x to the body's left, y up, z the way it facespub carry: Vec3,pub release: Option<Release>,+ /// the scene's solids the hands keep out of (a table, a shelf)+ pub avoid: Vec<Thing>,}#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -83,10 +86,11 @@ impl Take {/// one-handed thing, off to its hand's side).pub fn new(thing: Thing, grip: Grip, start: f32) -> Self {let carry = match grip {- Grip::One(h) => Vec3::new(0.2 * h.side.sign(), -0.22, 0.3),- Grip::Two(..) => Vec3::new(0.0, -0.2, 0.32 + thing.solid.bound() * 0.3),+ Grip::One(h) => Vec3::new(0.2 * h.side.sign(), -0.18, 0.3),+ // against the belly, the elbows bent: nearer and higher the smaller it is+ Grip::Two(..) => Vec3::new(0.0, -0.1, 0.2 + thing.solid.bound() * 0.5),};- Take { thing, grip, start, grab: start + 0.6, carried: start + 1.1, carry, release: None }+ Take { thing, grip, start, grab: start + 0.6, carried: start + 1.1, carry, release: None, avoid: Vec::new() }}/// where the thing rides at a moment of the body's motion: off the chest, turned only with the body's facing, so@@ -144,13 +148,10 @@ pub fn perform(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Take, t: f32)let own = base(t);let (thing, phase) = take.thing_at(skel, base, t);let mut frame = Frame { pose: own.clone(), thing, phase, miss: 0.0, moved: 0.0, touch: [None, None] };- // how much the hands are the take's and not the body's own: none before, all from the grab, none again once away+ // how much the hands are the take's and not the body's own: none before, all from the start, none again once awaylet gone = take.let_go();- let weight = match gone {- Some(g) if t >= g => 1.0 - smooth(span(t, g, g + AWAY)),- _ => (t >= take.start) as u8 as f32,- };- if weight <= 0.0 {+ let away = gone.map_or(0.0, |g| smooth(span(t, g, g + AWAY)));+ if t < take.start || away >= 1.0 {return frame;}// while letting go the hands ease off the place the thing was let go at, not after a thing in flight@@ -160,31 +161,40 @@ pub fn perform(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Take, t: f32)};let w0 = skel.fk(&own);let face = yaw(&w0) * Vec3::Z;- let mut pose = own.clone();- for hold in take.grip.holds() {- let Some((at, turn)) = wrist_for(skel, &held, &hold, facing(&held, w0.pos[0]).lerp(face, 0.5).normalize_or(face)) else { continue };- let Some(arm) = skel.arm(hold.side) else { continue };- // the reach: the wrist leaves where the body has it and comes in onto the hold from off the surface- let u = smooth(span(t, take.start, take.grab));- let off = (held.turn * hold.normal) * 0.1 * (1.0 - u);- let target = w0.pos[arm[2]].lerp(at + off, u);- let end = w0.rot[arm[2]].slerp(turn, smooth(span(t, take.start, take.start + (take.grab - take.start) * 0.8)));+ // in: how far along the reach; the hands are fully on the thing from the grab until they let go+ let into = smooth(span(t, take.start, take.grab));+ let holds: Vec<_> = take.grip.holds().filter_map(|h| Some((h, wrist_for(skel, &held, &h, facing(&held, w0.pos[0]).lerp(face, 0.5).normalize_or(face))?))).collect();+ // a thing lower than the arms reach: the body bends and squats for it, as far as the hands have got+ let low = holds.iter().map(|h| h.1.0.y).fold(f32::MAX, f32::min);+ let mut pose = stoop(skel, &own, &w0, face, low, into * (1.0 - away));+ for (hold, (at, turn)) in holds {+ let (Some(arm), Some(rest)) = (skel.arm(hold.side), hand_rest(skel, hold.side)) else { continue };+ let normal = held.turn * hold.normal;+ // the wrist's path: from where the body has it, in onto the hold from off the surface and over what is in the+ // way; and when letting go, back off the surface and out to where the body has it+ let (u, off) = if away > 0.0 { (1.0 - away, normal * 0.08 * (away * 4.0).min(1.0)) } else { (into, normal * 0.1 * (1.0 - into)) };+ let arc = Vec3::Y * 0.06 * (std::f32::consts::PI * u).sin();+ let end = w0.rot[arm[2]].slerp(turn, smooth(span(u, 0.0, 0.8)));+ let target = clear(w0.pos[arm[2]].lerp(at + off, u) + arc, end, &rest, &take.avoid);// elbows out and down, the way arms hanglet pole = yaw(&w0) * Vec3::new(0.7 * hold.side.sign(), -1.0, -0.4);let Some(solved) = reach(skel, &pose, hold.side, target, ArmOptions { pole: Some(pole), end: Some(end), soft: 0.02 }) else { continue };pose = forearm_twist(skel, &solved.pose, hold.side, 0.7);- if t >= take.grab {- frame.miss = frame.miss.max(solved.miss);+ if t >= take.grab && away <= 0.0 {+ frame.miss = frame.miss.max((skel.fk(&pose).pos[arm[2]] - at).length());}// the fingers shut over the last moments of the reach, and open again as the hand leaves- let close = smooth(span(t, take.grab - SHUT, take.grab)) * weight;+ let close = smooth(span(t, take.grab - SHUT, take.grab)) * (1.0 - smooth(span(away, 0.0, 0.5)));if close > 0.0 {frame.touch[hold.side as usize] = curl(skel, &mut pose.turns, (at, turn), hold.side, &held, close);}}- if weight < 1.0 {+ if away > 0.0 {+ // the last of the way back is a blend of the joints, so the arm ends exactly as the body has it+ let w = 1.0 - smooth(span(away, 0.5, 1.0));+ pose.root = own.root.lerp(pose.root, w);for (mine, own) in pose.turns.iter_mut().zip(&own.turns) {- *mine = own.slerp(*mine, weight);+ *mine = own.slerp(*mine, w);}}frame.moved = pose.turns.iter().zip(&own.turns).map(|(a, b)| a.angle_between(*b).to_degrees()).fold(0.0, f32::max);diff --git a/systems/grab/tests/grab.rs b/systems/grab/tests/grab.rsindex f5a3c692..14d8fb8b 100644--- a/systems/grab/tests/grab.rs+++ b/systems/grab/tests/grab.rs@@ -216,6 +216,76 @@ fn a_box_is_taken_carried_and_thrown() {assert_eq!(f.pose, s.rest());}+#[test]+fn a_box_on_the_floor_is_taken_by_bending_with_the_feet_planted() {+ let s = mannequin();+ let thing = Thing::new(Solid::Box { half: Vec3::new(0.16, 0.1, 0.12) }, Vec3::new(0.0, 0.1, 0.38));+ let take = Take::new(thing, find_holds(&thing, s.rest().root, HoldOptions::default()), 0.0);+ let base = stand(&s);+ let rest = s.fk(&s.rest());+ let feet = ["foot_l", "foot_r"].map(|n| s.joint(n).unwrap());+ let (mut t, mut lowest) = (0.0, f32::MAX);+ while t < 2.0 {+ let f = perform(&s, &base, &take, t);+ let w = s.fk(&f.pose);+ for foot in feet {+ assert!((w.pos[foot] - rest.pos[foot]).length() < 5e-3, "t {t}: a foot moved");+ assert!(w.rot[foot].dot(rest.rot[foot]).abs() > 0.9999, "t {t}: a foot turned");+ }+ lowest = lowest.min(f.pose.root.y);+ if t >= take.grab {+ assert!(f.miss < 0.02, "t {t}: a wrist {} m off its hold on the floor", f.miss);+ }+ t += 1.0 / 30.0;+ }+ // the hips came down for it, and are back up with the box carried+ assert!(lowest < s.rest().root.y - 0.3, "the hips came down to {lowest}");+ assert!(perform(&s, &base, &take, 1.9).pose.root.y > s.rest().root.y - 0.02);+}++#[test]+fn hands_stay_out_of_a_table() {+ let s = mannequin();+ let top = 0.95;+ let table = Thing::new(Solid::Box { half: Vec3::new(0.6, top / 2.0, 0.34) }, Vec3::new(0.0, top / 2.0, 0.66));+ let cup = Thing::new(Solid::Cylinder { half: 0.05, r: 0.035 }, Vec3::new(-0.2, top + 0.05, 0.42));+ let mut take = Take::new(cup, find_holds(&cup, s.rest().root, HoldOptions::default()), 0.0);+ take.release = Some(Release::Put { at: 1.7, down: 2.3, place: Vec3::new(0.0, top + 0.05, 0.44) });+ take.avoid = vec![table];+ let base = stand(&s);+ let hand = s.arm(Side::R).unwrap()[2];+ let rest = hand_rest(&s, Side::R).unwrap();+ let mut t = 0.0;+ while t < 3.0 {+ let f = perform(&s, &base, &take, t);+ let w = s.fk(&f.pose);+ for p in [Vec3::ZERO, rest.mid, rest.along * 0.17] {+ let d = table.distance(w.pos[hand] + w.rot[hand] * p);+ assert!(d > 0.0, "t {t}: the hand is {} m into the table", -d);+ }+ if t >= take.grab && t < 2.3 {+ assert!(f.miss < 6e-3, "t {t}: keeping clear cost the hold {} m", f.miss);+ }+ t += 1.0 / 30.0;+ }+}++#[test]+fn the_body_is_told_where_to_stand() {+ let thing = Thing::new(Solid::Box { half: Vec3::new(0.16, 0.1, 0.12) }, Vec3::new(2.0, 1.0, 3.0));+ let (at, yaw) = stand_for(&thing, Vec3::new(2.0, 1.0, 0.0));+ // a forearm's length off the face nearest it, facing the thing+ assert!((at - Vec3::new(2.0, 1.0, 3.0 - 0.12 - 0.3)).length() < 2e-3, "{at}");+ assert!(yaw.abs() < 1e-3);+ // and standing there the thing is in reach of both hands+ let s = mannequin();+ let mut p = s.rest();+ p.root += at - Vec3::new(0.0, 1.0, 0.0);+ let here = move |_: f32| p.clone();+ let take = Take::new(thing, find_holds(&thing, at, HoldOptions::default()), 0.0);+ assert!(perform(&s, &here, &take, 1.0).miss < 5e-3);+}+#[test]fn a_cup_is_put_down_somewhere_else_upright_while_the_body_turns() {let s = mannequin();