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.

HG6e: the carried thing and the hands on it out of the body. own_solids: the trunk and both thighs as capsules where the pose has them; a carried thing is moved the way the body faces until none of its corners, nor the wrists behind its holds, is in them. The stick-figure filmstrip example is gone (the renders on a character replaced it, and the crate was at its size limit). 32 tests

shinyobjectze24d71b3b952
diff --git a/docs/hands.feature b/docs/hands.feature
index 43208f97..66f678c7 100644
--- a/docs/hands.feature
+++ b/docs/hands.feature
@@ -65,7 +65,7 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
| raea-sys-grab | src/json.rs | 190 | character.take, character.fit, character.hand |
| raea-sys-grab | tests/grab.rs | 470 | the hands' measures, on the stand-in body |
| raea-sys-grab | tests/body.rs | 150 | limits, the body out of solids, the hand prior |
- | raea-sys-grab | examples/strip.rs | 90 | a take drawn as an SVG filmstrip |
+ | raea-sys-grab | tests/use.rs | 230 | passing, sliding, wind-up, a turned body, keeping out of solids |
| sdk | sdk/character/src/take.ts | 170 | take(), fitPose(), handShape(): the calls made, typed |
@done
@@ -111,7 +111,6 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
# way and is set down within 0.1 mm of its place; a thrown box flies, lands on the floor and stays; the
# body is back on its own motion 0.4 s after letting go. A frame asked for twice, in any order, is the same
# frame; no joint of the body turns over 6 degrees in a 60th of a second, no finger joint over 20.
- # `cargo run -p raea-sys-grab --example strip -- out.svg` draws a take as a filmstrip of stick figures.
Given the body's own motion as a pose at any time, a thing, and its holds
When a frame of the take is asked for
Then the hands leave the body's motion, come onto the holds from off the surface, and close
@@ -299,6 +298,16 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
# against the body.
Then reaching across the body doesn't put the elbow through it
+ @done
+ Scenario: HG6e. The carried thing and the hands on it out of the body
+ # 11-14, built. trunk.rs `own_solids`: the trunk and both thighs as capsules where the pose has them. A
+ # carried thing is moved the way the body faces until none of its corners, nor a point a hand's length
+ # behind each hold (the wrist), is within 1 cm of them. A deep box asked to be carried inside the belly:
+ # no corner and no wrist is in the body at any frame, the nearest of them is within 4 cm of it, the holds
+ # are kept within 1 cm; a carry that was clear is unchanged. Not done: the forearm against the thighs in
+ # a squat, and the fingers against the body.
+ Then a thing is carried against the body, never in it
+
Rule: Next, in order
@needs:HG5
diff --git a/systems/grab/examples/strip.rs b/systems/grab/examples/strip.rs
deleted file mode 100644
index f5716ffd..00000000
--- a/systems/grab/examples/strip.rs
+++ /dev/null
@@ -1,77 +0,0 @@
-//! A filmstrip of a take, as an SVG of stick figures, to judge the motion by eye with no engine: the stand-in body
-//! takes a box with both hands and throws it (top rows), and moves a cup with one (bottom rows). Each take is drawn
-//! from the front quarter and from the side.
-//! cargo run -p raea-sys-grab --example strip -- out.svg
-
-use std::fmt::Write;
-
-use glam::{Quat, Vec3};
-use raea_sys_body::*;
-use raea_sys_grab::*;
-
-/// a point of the body's frame on the page: turned about the vertical by `yaw`, y up
-fn project(p: Vec3, yaw: f32, ox: f32, oy: f32) -> (f32, f32) {
- let q = Quat::from_rotation_y(yaw) * p;
- (ox + q.x * 150.0, oy - q.y * 150.0)
-}
-
-fn draw(svg: &mut String, s: &Skeleton, f: &Frame, yaw: f32, ox: f32, oy: f32) {
- let w = s.fk(&f.pose);
- let line = |svg: &mut String, a: Vec3, b: Vec3, colour: &str, width: f32| {
- let ((x1, y1), (x2, y2)) = (project(a, yaw, ox, oy), project(b, yaw, ox, oy));
- let _ = writeln!(svg, r#"<line x1="{x1:.1}" y1="{y1:.1}" x2="{x2:.1}" y2="{y2:.1}" stroke="{colour}" stroke-width="{width}" stroke-linecap="round"/>"#);
- };
- // the thing: its box, or the box round it, by its own axes
- let half = match f.thing.solid {
- Solid::Ball { r } => Vec3::splat(r),
- Solid::Box { half } => half,
- Solid::Capsule { half, r } => Vec3::new(r, half + r, r),
- Solid::Cylinder { half, r } => Vec3::new(r, half, r),
- };
- let corner = |i: usize| f.thing.world(Vec3::new(if i & 1 == 0 { -half.x } else { half.x }, if i & 2 == 0 { -half.y } else { half.y }, if i & 4 == 0 { -half.z } else { half.z }));
- for i in 0..8 {
- for bit in [1, 2, 4] {
- if i & bit == 0 {
- line(svg, corner(i), corner(i | bit), "#c2410c", 1.5);
- }
- }
- }
- for (i, j) in s.joints.iter().enumerate() {
- let Some(p) = j.parent else { continue };
- let finger = i >= s.joint("thumb_01_l").unwrap_or(usize::MAX);
- let colour = if j.name.ends_with("_l") { "#1d4ed8" } else if j.name.ends_with("_r") { "#15803d" } else { "#111827" };
- line(svg, w.pos[p], w.pos[i], colour, if finger { 1.0 } else { 2.5 });
- if finger || j.name.starts_with("hand") || j.name == "head" {
- line(svg, w.pos[i], w.pos[i] + w.rot[i] * (j.tail - j.head), colour, if finger { 1.0 } else { 2.5 });
- }
- }
-}
-
-fn main() {
- let out = std::env::args().nth(1).unwrap_or_else(|| "strip.svg".into());
- let s = mannequin();
- let stand = |_: f32| s.rest();
-
- let crate_ = Thing::new(Solid::Box { half: Vec3::new(0.16, 0.1, 0.12) }, Vec3::new(0.0, 1.05, 0.42));
- let mut throw = Take::new(crate_, find_holds(&crate_, s.rest().root, HoldOptions::default()), 0.2);
- throw.release = Some(Release::Throw { at: 1.9, velocity: Vec3::new(0.0, 1.5, 2.5), floor: 0.0 });
-
- let cup = Thing::new(Solid::Cylinder { half: 0.05, r: 0.035 }, Vec3::new(-0.2, 1.0, 0.38));
- let mut put = Take::new(cup, find_holds(&cup, s.rest().root, HoldOptions::default()), 0.2);
- put.release = Some(Release::Put { at: 1.7, down: 2.3, place: Vec3::new(0.05, 1.0, 0.4) });
-
- let times = [0.0, 0.45, 0.65, 0.8, 1.05, 1.3, 1.6, 1.9, 2.05, 2.3, 2.7];
- let (cell, row) = (190.0, 310.0);
- let mut svg = format!(r##"<svg xmlns="http://www.w3.org/2000/svg" width="{}" height="{}" font-family="monospace" font-size="11"><rect width="100%" height="100%" fill="#fafaf9"/>"##, cell * times.len() as f32, row * 4.0);
- for (r, (take, yaw, name)) in [(&throw, -0.6, "box, front quarter"), (&throw, -1.5708, "box, side"), (&put, -0.6, "cup, front quarter"), (&put, -1.5708, "cup, side")].into_iter().enumerate() {
- for (c, t) in times.iter().enumerate() {
- let f = perform(&s, &stand, take, *t);
- let (ox, oy) = (cell * (c as f32 + 0.5), row * (r as f32 + 1.0) - 14.0);
- draw(&mut svg, &s, &f, yaw, ox, oy);
- let _ = writeln!(svg, r##"<text x="{:.0}" y="{:.0}" fill="#44403c">{name} t={t:.2} {:?}</text><text x="{:.0}" y="{:.0}" fill="#78716c">miss {:.1} mm, moved {:.0} deg</text>"##, ox - cell / 2.0 + 6.0, oy - row + 30.0, f.phase, ox - cell / 2.0 + 6.0, oy - row + 44.0, f.miss * 1000.0, f.moved);
- }
- }
- svg.push_str("</svg>");
- std::fs::write(&out, svg).expect("the strip written");
- println!("{out}");
-}
diff --git a/systems/grab/src/lib.rs b/systems/grab/src/lib.rs
index 11e890be..d8b0bcb6 100644
--- a/systems/grab/src/lib.rs
+++ b/systems/grab/src/lib.rs
@@ -24,4 +24,4 @@ pub use interact::pick;
pub use json::{FIT_ANSWER, FIT_ARGS, HAND_ANSWER, HAND_ARGS, TAKE_ANSWER, TAKE_ARGS, fit_json, hand_json, take_json};
pub use shape::{Solid, Thing};
pub use take::{Frame, Key, Phase, Release, Take, perform};
-pub use trunk::{clear, look, roomy, stand_for, stoop, torso};
+pub use trunk::{clear, look, own_solids, roomy, stand_for, stoop, torso};
diff --git a/systems/grab/src/take.rs b/systems/grab/src/take.rs
index 4f453a2b..1f6bf233 100644
--- a/systems/grab/src/take.rs
+++ b/systems/grab/src/take.rs
@@ -9,7 +9,7 @@
use glam::{Quat, Vec3};
use raea_sys_body::arm::{ArmOptions, forearm_twist, reach};
-use crate::trunk::{clear, look, roomy, stoop, torso};
+use crate::trunk::{clear, look, own_solids, roomy, stoop, torso};
use raea_sys_body::limits::clamp_turn;
use raea_sys_body::prior::shape;
use crate::hand::{Grip, Hold, Touch, curl, facing, wrist_for};
@@ -217,6 +217,19 @@ impl Take {
let mut thing = self.thing.moved(self.thing.at.lerp(ride.at, u) + Vec3::Y * 0.04 * rise, self.thing.turn.slerp(ride.turn, u));
let deep = thing.corners().iter().flat_map(|c| self.avoid.iter().map(|s| 0.01 - s.distance(*c))).fold(0.0f32, f32::max);
thing.at.y += deep * (rise * 4.0).min(1.0);
+ // and out of the body's own trunk and thighs, the way it faces, by how deep its corners would be in
+ // them (a thing asked to be carried inside the belly is carried against it)
+ let body = skel.fk(&base(t));
+ let (ahead, solids) = (yaw(&body) * Vec3::Z, own_solids(skel, &body));
+ for _ in 0..10 {
+ // its corners, and where the wrists that hold it are: a hand's length behind each hold
+ let wrists = self.grip.holds().map(|h| thing.world(h.at) - ahead * 0.08);
+ let inside = thing.corners().into_iter().chain(wrists).flat_map(|c| solids.iter().map(move |s| 0.01 - s.distance(c))).fold(0.0f32, f32::max);
+ if inside <= 0.0 {
+ break;
+ }
+ thing.at += ahead * (inside + 0.005) * u;
+ }
// a throw is wound up: drawn back against the throw over its last moments, and brought through
if let Some(Release::Throw { at, velocity, .. }) = self.release {
let wind = (std::f32::consts::PI * span(t, at - WIND, at)).sin() * (velocity.length() / 3.0).min(1.0);
diff --git a/systems/grab/src/trunk.rs b/systems/grab/src/trunk.rs
index 4f526d45..9eb969f2 100644
--- a/systems/grab/src/trunk.rs
+++ b/systems/grab/src/trunk.rs
@@ -131,3 +131,17 @@ pub fn torso(skel: &Skeleton, at: &Posed) -> Option<Thing> {
let wide = 0.6 * (skel.joints[shoulder].head.x - skel.joints[chest].head.x).abs();
Some(Thing { solid: crate::shape::Solid::Capsule { half: up.length() / 2.0, r: wide }, at: at.pos[0] + up / 2.0, turn: Quat::from_rotation_arc(Vec3::Y, up.normalize_or(Vec3::Y)) })
}
+
+/// The body's own solids where a pose has them: the trunk and both thighs (each a capsule along its bone, a little
+/// under half as wide as the trunk). What a carried thing, and the hands on it, must not pass through.
+pub fn own_solids(skel: &Skeleton, at: &Posed) -> Vec<Thing> {
+ let Some(trunk) = torso(skel, at) else { return Vec::new() };
+ let crate::shape::Solid::Capsule { r, .. } = trunk.solid else { return vec![trunk] };
+ let mut out = vec![trunk];
+ for s in Side::BOTH {
+ let (Some(thigh), Some(calf)) = (skel.joint(&format!("thigh_{}", s.sx())), skel.joint(&format!("calf_{}", s.sx()))) else { continue };
+ let bone = at.pos[calf] - at.pos[thigh];
+ out.push(Thing { solid: crate::shape::Solid::Capsule { half: bone.length() / 2.0, r: r * 0.75 }, at: at.pos[thigh] + bone / 2.0, turn: Quat::from_rotation_arc(Vec3::Y, bone.normalize_or(Vec3::NEG_Y)) });
+ }
+ out
+}
diff --git a/systems/grab/tests/use.rs b/systems/grab/tests/use.rs
index a31b1396..0011e074 100644
--- a/systems/grab/tests/use.rs
+++ b/systems/grab/tests/use.rs
@@ -162,3 +162,42 @@ fn an_elbow_stays_out_of_the_trunk_when_a_hand_reaches_across() {
t += 1.0 / 30.0;
}
}
+
+#[test]
+fn a_carried_thing_and_the_hands_on_it_stay_out_of_the_body() {
+ let s = mannequin();
+ let rest = s.fk(&s.rest());
+ let body = own_solids(&s, &rest);
+ assert_eq!(body.len(), 3);
+ // a deep box, and a carry place asked for inside the belly
+ let thing = Thing::new(Solid::Box { half: Vec3::new(0.16, 0.12, 0.2) }, Vec3::new(0.0, 1.05, 0.5));
+ let grip = find_holds(&thing, s.rest().root, HoldOptions::default());
+ let mut take = Take::new(thing, grip, 0.0);
+ take.carry = Vec3::new(0.0, -0.25, 0.08);
+ let hands = Side::BOTH.map(|side| s.arm(side).unwrap()[2]);
+ let mut t = take.carried;
+ while t < 2.5 {
+ let f = perform(&s, &|_| s.rest(), &take, t);
+ for corner in f.thing.corners() {
+ for solid in &body {
+ assert!(solid.distance(corner) > 0.0, "t {t}: a corner of the box is {} m into the body", -solid.distance(corner));
+ }
+ }
+ // and so are the wrists that hold it
+ let w = s.fk(&f.pose);
+ for hand in hands {
+ assert!(body.iter().all(|solid| solid.distance(w.pos[hand]) > 0.0), "t {t}: a wrist is in the body");
+ }
+ assert!(f.miss < 0.01);
+ t += 1.0 / 15.0;
+ }
+ // it was moved the least: the box or a wrist is against the body (the trunk or a thigh), not out at arm's length
+ let f = perform(&s, &|_| s.rest(), &take, 2.0);
+ let w = s.fk(&f.pose);
+ let near = f.thing.corners().into_iter().chain(hands.map(|h| w.pos[h])).flat_map(|p| body.iter().map(move |solid| solid.distance(p))).fold(f32::MAX, f32::min);
+ assert!(near < 0.04, "the nearest of the box and the wrists is {near} m off the body");
+ // a take whose carry is clear of the body is as it was
+ let usual = Take::new(thing, grip, 0.0);
+ let chest = s.joint("spine_03").unwrap();
+ assert!((perform(&s, &|_| s.rest(), &usual, 2.0).thing.at - (rest.pos[chest] + usual.carry)).length() < 1e-4);
+}