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: a carried thing is pushed out of the body's own skin (after a throw's wind-up, which drew a box 99 mm into the waist); the grip of a low thing is found with the squat the body will have there; the whole hand's skin, not three points, keeps off the scene's solids. On turbo's skin: body skin in a thrown box 99 to 0 mm, in a 14 kg box 45 to 0; finger skin in the table 7-21 to 0-13 mm. Not fixed: the floor take, and the 14 kg box's hold now 41 mm off

shinyobjectzc135130ccb61
diff --git a/systems/grab/src/grip.rs b/systems/grab/src/grip.rs
index 53afdbd5..8c81e1b2 100644
--- a/systems/grab/src/grip.rs
+++ b/systems/grab/src/grip.rs
@@ -9,7 +9,7 @@ use raea_sys_body::shape::Thing;
use crate::hand::{facing, wrist_for};
use crate::take::{Part, Release, Take, smooth, span, yaw};
-use crate::trunk::{clear, stoop};
+use crate::trunk::{clear, hand_points, roomy, stoop};
/// how far past their ranges an arm's shoulder and elbow are in a pose, degrees
pub(crate) fn past_range(skel: &Skeleton, arm: [usize; 3], pose: &Pose) -> f32 {
@@ -33,15 +33,25 @@ pub(crate) fn lie_at_grab(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Ta
let (at, turn) = if hold.along.is_some() {
level
} else {
- let pose = stoop(skel, &own, &w, face, level.0.y, 1.0, 0.0, &take.avoid);
- let probe = reach(skel, &pose, hold.side, thing.world(hold.at) + thing.turn * hold.normal * 0.04, ArmOptions::default());
+ // the body as it will be at the grab: bent for a low thing, with the give its head and chest need there
+ let bent = |give: f32| stoop(skel, &own, &w, face, level.0.y, 1.0, give, &take.avoid);
+ let (mut lo, mut hi) = (0.0f32, if roomy(skel, &bent(0.0), &take.avoid) { 0.0 } else { 1.0 });
+ for _ in 0..6 {
+ if hi <= 0.0 {
+ break;
+ }
+ let mid = (lo + hi) / 2.0;
+ if roomy(skel, &bent(mid), &take.avoid) { hi = mid } else { lo = mid }
+ }
+ 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 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, &rest, &take.avoid) - along.0).length() / 0.03)).unwrap_or(level),
+ 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),
None => level,
}
};
diff --git a/systems/grab/src/lib.rs b/systems/grab/src/lib.rs
index 18845868..7800117f 100644
--- a/systems/grab/src/lib.rs
+++ b/systems/grab/src/lib.rs
@@ -23,4 +23,4 @@ pub use hand::{Grip, Hold, HoldOptions, Touch, curl, find_holds, wrist_for};
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 take::{Frame, Key, Phase, Release, Take, perform};
-pub use trunk::{clear, look, own_solids, roomy, stand_for, stoop, torso};
+pub use trunk::{clear, hand_points, look, own_solids, roomy, stand_for, stoop, torso};
diff --git a/systems/grab/src/take.rs b/systems/grab/src/take.rs
index 651c469f..7b7528bd 100644
--- a/systems/grab/src/take.rs
+++ b/systems/grab/src/take.rs
@@ -10,7 +10,7 @@ use glam::{Quat, Vec3};
use raea_sys_body::arm::{ArmOptions, forearm_twist, reach};
use crate::grip::{lie_at_grab, past_range, swivel};
-use crate::trunk::{clear, look, own_solids, roomy, stoop, torso};
+use crate::trunk::{clear, hand_points, look, of_the_arm, 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};
@@ -218,24 +218,26 @@ 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)
+ // 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);
+ thing.at -= velocity.normalize_or_zero() * 0.18 * wind;
+ }
+ // and out of the body, the way it faces, by how deep it would be in it: its corners and the wrists that
+ // hold it (a hand's length behind each hold) against the trunk and thighs, and the body's own skin,
+ // 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();
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);
+ 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);
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);
- thing.at -= velocity.normalize_or_zero() * 0.18 * wind;
- }
thing
};
match self.release {
@@ -336,7 +338,7 @@ 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, &rest, &take.avoid);
+ let target = clear(w0.pos[arm[2]].lerp(at + off, u) + arc, end, &hand_points(skel, hold.side, &rest), &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)
diff --git a/systems/grab/src/trunk.rs b/systems/grab/src/trunk.rs
index c3e0f70c..631984da 100644
--- a/systems/grab/src/trunk.rs
+++ b/systems/grab/src/trunk.rs
@@ -79,16 +79,15 @@ pub fn roomy(skel: &Skeleton, pose: &Pose, solids: &[Thing]) -> bool {
}
/// 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];
+pub fn clear(wrist: Vec3, turn: Quat, hand: &(Vec<Vec3>, f32), solids: &[Thing]) -> Vec3 {
+ let (points, margin) = hand;
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;
+ 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)));
}
@@ -100,6 +99,23 @@ pub fn clear(wrist: Vec3, turn: Quat, rest: &HandRest, solids: &[Thing]) -> Vec3
at
}
+/// 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,
+/// 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) };
+ let wrist = skel.joints[hand].head;
+ 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) }
+}
+
+/// whether a part of the skin (a sample's name) is the arm's or the hand's
+pub fn of_the_arm(part: &str) -> bool {
+ part == "palm" || part.ends_with("Arm") || ["thumb", "index", "middle", "ring", "pinky"].iter().any(|f| part.starts_with(f))
+}
+
/// 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);