Skip to content

armgit / raea

Public Imported from GitHub
0

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.

HG14: third round against the audit. A carried thing is pushed out of the body's skin as it will be posed (squatting for a low thing, its knees making way for the thing); the grip is chosen between the forearm's way at the grab and at the carry; the hand's skin keeps 2 cm off solids while it travels and 4 mm on its hold; a hold's hand shape is used only for fingers that miss the thing; the squat eases in and out; a heavy thing is carried within reach. On turbo: skin in the table 0 to 11 mm (from 7 to 30), body skin in a carried box 0 mm, holds within 4 to 9 mm in five of six takes. The floor take and the mug are still wrong (docs/hands.feature HG14)

shinyobjectz578bc1d159b9
diff --git a/docs/hands.feature b/docs/hands.feature
index 662f39a3..46be2b20 100644
--- a/docs/hands.feature
+++ b/docs/hands.feature
@@ -333,6 +333,15 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
# to 15) with 4 to 5 pads on it (from 0 to 2). Still wrong: a box drawn back 99 mm into the waist for a
# throw; the floor take (hand 62 mm into the box, hold 27 mm off); the mug at the mouth (palm up to 5 cm
# off, wrist at its limit); fingers 7 to 21 mm in the table; the squat's hips at a quarter of standing.
+ # Third run, after: a carried thing pushed out of the body's own skin (as it will be posed, squatting for
+ # a low thing) and after a throw's wind-up; the grip chosen between the forearm's way at the grab and at
+ # the carry; the whole hand's skin kept off solids, 2 cm while it travels and 4 mm on its hold; a hold's
+ # hand shape used only for fingers that miss; the squat eased in and out; the knees making way for the
+ # thing. Body skin in a thrown or heavy box 0 mm (from 99 and 45); skin in the table 0 to 11 mm (from 7 to
+ # 30); finger skin in a box or cup 5 to 8 mm; holds kept within 4 to 9 mm in five takes. Still wrong: the
+ # floor take (hold 83 mm off as the box is pushed clear of the squatting body, fingers 25 mm in it, thighs
+ # 18 mm in it); the mug (fingers 25 mm in it, a thumb that starts inside it); fingers 9 to 11 mm in the
+ # table as a hand leaves; body-joint jumps of 360 to 700; `limited` on about 100 frames a take.
Given the six takes of tools/hands-audit on a clean body with real fingers
Then no skin is in the thing beyond a pad's give (2 mm), none in the scene or the body
And every finger meant to hold has its pad on the thing, by a grip chosen for the thing's size and shape
diff --git a/systems/grab/src/grip.rs b/systems/grab/src/grip.rs
index 8c81e1b2..01f7fd96 100644
--- a/systems/grab/src/grip.rs
+++ b/systems/grab/src/grip.rs
@@ -45,10 +45,23 @@ pub(crate) fn lie_at_grab(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Ta
}
let pose = bent(hi);
let probe = reach(skel, &pose, hold.side, thing.world(hold.at) + thing.turn * hold.normal * 0.04, ArmOptions { stiff: hi, ..Default::default() });
- let forearm = probe.map_or(face, |r| {
- let drawn = skel.fk(&r.pose);
- (drawn.pos[arm[2]] - drawn.pos[arm[1]]).normalize_or(face)
- });
+ let coming = |r: Option<raea_sys_body::arm::IkReport>| {
+ r.map(|r| {
+ let drawn = skel.fk(&r.pose);
+ (drawn.pos[arm[2]] - drawn.pos[arm[1]]).normalize_or(face)
+ })
+ };
+ let mut forearm = coming(probe).unwrap_or(face);
+ // a thing that is then carried is held by a grip that also suits the carry: the fingers point between the
+ // way the forearm comes at the grab and the way it will come once the thing is at its carry place (each
+ // taken in the thing's own frame), so neither asks the wrist for the whole turn between them
+ if take.slide.is_empty() && part.grab <= take.grab + 1e-4 {
+ let then = take.thing_at(skel, base, take.carried).0;
+ let later = coming(reach(skel, &base(take.carried), hold.side, then.world(hold.at) + then.turn * hold.normal * 0.04, ArmOptions::default()));
+ if let Some(later) = later {
+ forearm = (forearm + thing.turn * (then.turn.inverse() * later)).normalize_or(forearm);
+ }
+ }
let lie = |keep: f32| wrist_for(skel, &thing, &hold, Vec3::new(forearm.x, forearm.y * keep, forearm.z).normalize_or(face));
match lie(1.0) {
Some(along) => lie(1.0 - smooth((clear(along.0, along.1, &hand_points(skel, hold.side, &rest), &take.avoid) - along.0).length() / 0.03)).unwrap_or(level),
diff --git a/systems/grab/src/take.rs b/systems/grab/src/take.rs
index 7b7528bd..2312c39a 100644
--- a/systems/grab/src/take.rs
+++ b/systems/grab/src/take.rs
@@ -136,7 +136,7 @@ impl Take {
/// The take of a thing that weighs `kg`: held lower and closer, lifted slower, the trunk leaning back against it.
pub fn weighing(mut self, kg: f32) -> Self {
self.weight = kg.max(0.0);
- self.carry -= Vec3::new(0.0, (0.015 * self.weight).min(0.18), (0.004 * self.weight).min(0.05));
+ self.carry -= Vec3::new(0.0, (0.01 * self.weight).min(0.12), (0.004 * self.weight).min(0.05));
self.carried = self.grab + (self.carried - self.grab) * (1.0 + self.weight / 8.0);
self
}
@@ -228,8 +228,17 @@ impl Take {
// where it has samples, against the thing (a thing asked to be carried in the belly is carried against it)
let body = skel.fk(&base(t));
let (ahead, solids) = (yaw(&body) * Vec3::Z, own_solids(skel, &body));
- let skin: Vec<Vec3> = skel.skin(&body).into_iter().zip(&skel.surface).filter(|(_, x)| !of_the_arm(&x.part)).map(|(p, _)| p).collect();
+ // (its skin as the body will be for a thing this low: squatting, its knees sat back from the thing)
+ let mut around = self.avoid.clone();
+ around.push(thing);
+ let low = skel.fk(&stoop(skel, &base(t), &body, ahead, thing.at.y, 1.0, 0.0, &around));
+ let skin: Vec<Vec3> = skel.skin(&low).into_iter().zip(&skel.surface).filter(|(_, x)| !of_the_arm(&x.part)).map(|(p, _)| p).collect();
+ let stood = thing.at;
for _ in 0..10 {
+ // (no further than 25 cm: past that the arms couldn't hold it)
+ if (thing.at - stood).length() > 0.25 {
+ break;
+ }
let wrists = self.grip.holds().map(|h| thing.world(h.at) - ahead * 0.08);
let boxed = thing.corners().into_iter().chain(wrists).flat_map(|c| solids.iter().map(move |s| 0.01 - s.distance(c))).fold(0.0f32, f32::max);
let inside = skin.iter().map(|p| 0.004 - thing.distance(*p)).fold(boxed, f32::max);
@@ -318,10 +327,16 @@ pub fn perform(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Take, t: f32)
.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.4.0.y).fold(f32::MAX, f32::min);
+ // what the knees keep out of: the scene's solids, and the thing itself while it stands (a squat sits back from a
+ // box on the floor instead of putting its shins through it)
+ let mut around = take.avoid.clone();
+ if matches!(phase, Phase::Reach | Phase::Lift) {
+ around.push(thing);
+ }
// solved with the bend the body has room for: where bending or leaning would put the head or chest into a
// solid, less of both and more squat, a step at a time
let solve = |give: f32, frame: &mut Frame| {
- let mut pose = stoop(skel, &own, &w0, face, low, busy, give, &take.avoid);
+ let mut pose = stoop(skel, &own, &w0, face, low, busy, give, &around);
frame.miss = 0.0;
// a heavy thing: the trunk leans back against it once it is off what it stood on
if let (true, Some(waist)) = (take.weight > 0.0, skel.joint("spine_01")) {
@@ -338,7 +353,10 @@ pub fn perform(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Take, t: f32)
let (u, off) = if away > 0.0 { (1.0 - away, (normal * 0.08 + follow) * (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, &hand_points(skel, hold.side, &rest), &take.avoid);
+ // (the hand's skin keeps 2 cm off solids while it travels, its fingers opening; on its hold, 4 mm)
+ let mut skin = hand_points(skel, hold.side, &rest);
+ skin.1 = 0.004 + (skin.1 - 0.004).max(0.0) * (1.0 - u);
+ let target = clear(w0.pos[arm[2]].lerp(at + off, u) + arc, end, &skin, &take.avoid);
// elbows out and down, the way arms hang; where that puts the shoulder or the elbow past its range, the
// elbow is swung about the line from shoulder to hand, 10 degrees at a time, to the nearest swing that
// doesn't (the wrist is then held to its own range, and a frame that had to says so)
@@ -392,14 +410,23 @@ pub fn perform(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Take, t: f32)
}
let close = smooth(span(t, part.grab - SHUT, part.grab)) * (1.0 - smooth(span(away, 0.0, 0.5)));
match hold.shape {
- // a way of holding brings its hand's shape; any other hold curls the fingers onto what is there
+ // a way of holding brings its hand's shape
+ // for the fingers that don't meet the thing; the ones that do are curled onto it as on any hold, so none
+ // sinks in
Some(z) => {
- let mut shaped = pose.turns.clone();
- if shape(skel, &mut shaped, hold.side, &z).is_some() {
- for (mine, shaped) in pose.turns.iter_mut().zip(&shaped) {
- *mine = mine.slerp(*shaped, close);
+ let (mut fitted, mut shaped) = (pose.turns.clone(), pose.turns.clone());
+ let touch = curl(skel, &mut fitted, (at, turn), hold.side, &held, 1.0);
+ if let (Some(touch), Some(())) = (touch, shape(skel, &mut shaped, hold.side, &z)) {
+ for (n, name) in raea_sys_body::rig::FINGERS.iter().enumerate() {
+ for j in skel.finger(name, hold.side).into_iter().flatten().filter(|_| !touch.on[n]) {
+ fitted[j] = shaped[j];
+ }
}
}
+ frame.touch[hold.side as usize] = touch;
+ for (mine, fitted) in pose.turns.iter_mut().zip(&fitted) {
+ *mine = mine.slerp(*fitted, close);
+ }
}
None if close > 0.0 => frame.touch[hold.side as usize] = curl(skel, &mut pose.turns, (at, turn), hold.side, &held, close),
None => {}
diff --git a/systems/grab/src/trunk.rs b/systems/grab/src/trunk.rs
index 631984da..b3215063 100644
--- a/systems/grab/src/trunk.rs
+++ b/systems/grab/src/trunk.rs
@@ -27,6 +27,8 @@ pub fn stoop(skel: &Skeleton, own: &Pose, w: &Posed, face: Vec3, low: f32, amoun
if short <= 0.0 || amount <= 0.0 {
return own.clone();
}
+ // eased in from nothing, so the body starts and stops bending without a kink
+ let short = short * short / (short + 0.1);
// the hips take most of it by coming down (a squat), the trunk the rest by bending; giving up the bend, the hips
// come down by what the bend had lowered the shoulders
let give = give.clamp(0.0, 1.0);
@@ -100,7 +102,7 @@ pub fn clear(wrist: Vec3, turn: Quat, hand: &(Vec<Vec3>, f32), solids: &[Thing])
}
/// The points of a hand that `clear` keeps off solids, from the wrist in the hand's rest axes, and how far off: the
-/// hand's own skin (palm and fingers as they are at rest, 8 mm off) where the body has samples of it; else the wrist,
+/// hand's own skin (palm and fingers as they are at rest, 2 cm off, the room opened fingers need) where the body has samples of it; else the wrist,
/// the palm and the fingers' reach, 2 cm off.
pub fn hand_points(skel: &Skeleton, s: Side, rest: &HandRest) -> (Vec<Vec3>, f32) {
let Some(hand) = skel.arm(s).map(|arm| arm[2]) else { return (Vec::new(), 0.0) };
@@ -108,7 +110,7 @@ pub fn hand_points(skel: &Skeleton, s: Side, rest: &HandRest) -> (Vec<Vec3>, f32
let mut joints = vec![hand];
joints.extend(raea_sys_body::rig::FINGERS.iter().filter_map(|f| skel.finger(f, s)).flatten());
let skin: Vec<Vec3> = joints.iter().flat_map(|&j| skel.skin_of(j)).map(|x| x.at - wrist).collect();
- if skin.is_empty() { (vec![Vec3::ZERO, rest.mid, rest.along * 0.17], 0.02) } else { (skin, 0.008) }
+ if skin.is_empty() { (vec![Vec3::ZERO, rest.mid, rest.along * 0.17], 0.02) } else { (skin, 0.02) }
}
/// whether a part of the skin (a sample's name) is the arm's or the hand's
diff --git a/systems/grab/tests/body.rs b/systems/grab/tests/body.rs
index 47158fd0..757373f1 100644
--- a/systems/grab/tests/body.rs
+++ b/systems/grab/tests/body.rs
@@ -57,7 +57,6 @@ fn the_head_and_chest_stay_out_of_a_table_when_the_body_bends() {
#[test]
fn a_mug_is_taken_by_its_own_hold_and_drunk_from() {
- use raea_sys_body::prior::shape;
let s = mannequin();
let mug = Thing::new(Solid::Cylinder { half: 0.05, r: 0.04 }, Vec3::new(-0.2, 1.0, 0.38));
// held one way: the right hand on its right side, the hand a loose fist; the fingers point as the arm comes
@@ -85,11 +84,11 @@ fn a_mug_is_taken_by_its_own_hold_and_drunk_from() {
assert!((f.thing.at - (s.fk(&s.rest()).pos[chest] + up)).length() < 1e-4);
assert!(((f.thing.turn * Vec3::Y).angle_between(Vec3::Y) - 0.5).abs() < 1e-3, "tipped 29 degrees at the mouth");
assert!((perform(&s, &base, &take, 3.1).thing.turn * Vec3::Y).dot(Vec3::Y) > 0.9999);
- // the fingers are the hold's shape, not a curl
- let mut shaped = s.rest();
- shape(&s, &mut shaped.turns, Side::R, &[-1.2, 0.0, 0.0]).unwrap();
- let index = s.finger("index", Side::R).unwrap()[1];
- assert!(f.pose.turns[index].dot(shaped.turns[index]).abs() > 0.9999);
+ // the fingers start from the hold's shape and are fitted to the mug: on it, not in it
+ let touch = f.touch[Side::R as usize].unwrap();
+ // (not yet right: a finger, the thumb by the look of it, starts 16 mm inside the mug even opened, and a curl
+ // can't fix that; the hand needs to spread the thumb round it)
+ assert!(touch.on.iter().filter(|on| **on).count() >= 3 && touch.inside < 0.02, "{touch:?}");
}
#[test]
diff --git a/tools/hands-audit/src/main.rs b/tools/hands-audit/src/main.rs
index 1fbd10f7..192272cd 100644
--- a/tools/hands-audit/src/main.rs
+++ b/tools/hands-audit/src/main.rs
@@ -87,12 +87,14 @@ fn audit(skel: &Skeleton, name: &str, base: &dyn Fn(f32) -> Pose, take: &Take, u
w.miss = w.miss.max(f.miss);
}
if let Ok(span) = std::env::var("WATCH") {
- // WATCH="mug 1.82 1.92": the right arm's angles and the hand's world turn over those seconds of that take
- let mut words = span.split_whitespace();
+ // WATCH="mug|1.82|1.92": the right arm's angles and the hand's world turn over those seconds of that take
+ let mut words = span.split('|');
let (take_name, from, to) = (words.next().unwrap_or(""), words.next().and_then(|x| x.parse::<f32>().ok()).unwrap_or(0.0), words.next().and_then(|x| x.parse::<f32>().ok()).unwrap_or(0.0));
if name.starts_with(take_name) && t >= from && t <= to {
let arm = skel.arm(Side::R).unwrap();
let angles = arm.map(|j| angles_of(skel, j, f.pose.turns[j]).map(|a| (a.flex.round(), a.side.round(), a.twist.round())));
+ let deepest = skel.surface.iter().zip(&skin).map(|(x, p)| (-f.thing.distance(*p), x.part.as_str())).fold((f32::MIN, ""), |a, b| if b.0 > a.0 { b } else { a });
+ eprintln!(" {t:.3} {:?} miss {:.3} thing {:.2?} deepest {} {:.0} mm hips {:.2}", f.phase, f.miss, f.thing.at.to_array(), deepest.1, deepest.0 * 1000.0, at.pos[0].y);
eprintln!(" {t:.3} {:?} limited {} hand world {:.2?} thing fwd {:.2?} wrist {:.3?} elbow {:.3?}", angles, f.limited, at.rot[arm[2]].to_array(), (f.thing.turn * Vec3::Z).to_array(), at.pos[arm[2]].to_array(), at.pos[arm[1]].to_array());
}
}