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 grip chosen by the thing's shape for a rod lying down (taken over the top, the fingers round it across its length); raea/character's fetch takes a thing as asked when it is in reach and otherwise walks the body to the take's standing place first and puts the take off until it arrives. 35 tests. fetch is not rendered yet

shinyobjectzd37f835bfd09
diff --git a/docs/hands.feature b/docs/hands.feature
index 71a53bbe..42e7b6c6 100644
--- a/docs/hands.feature
+++ b/docs/hands.feature
@@ -68,7 +68,7 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
| 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 | 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 |
+ | sdk | sdk/character/src/take.ts | 190 | take(), fitPose(), handShape(): the calls made, typed |
@done
Scenario: HG1. An arm reaches a target, and says what it cost
@@ -358,6 +358,11 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
# that exposed: at the mouth the mug tips up to 50 degrees where 29 was asked, and its rim goes 14 mm into
# the face; a carried cup tips up to 2 degrees where the wrist is limited; the mug take has a joint jump of
# 1,378 as the elbow swings out. The floor take is unchanged (hold 69 mm off).
+ # Also since: a grip chosen by the thing's shape for one more case, a rod lying down (taken over the top,
+ # the fingers round it across its length; stood on end it is taken by its side), with three of five
+ # fingers on it on the stand-in body; and raea/character's `fetch`, which takes a thing as asked when it
+ # is in reach and otherwise walks the body to the take's standing place first (walkUp) and puts every
+ # time of the take off until it arrives. `fetch` is written and type-checked by use only: not rendered.
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/sdk/character/src/character.tsx b/sdk/character/src/character.tsx
index fd533d6e..a23a156b 100644
--- a/sdk/character/src/character.tsx
+++ b/sdk/character/src/character.tsx
@@ -18,5 +18,5 @@ export type { Quat, Joint, Skeleton, Pose, Posed, Side, Finger, HandShape, Closi
// a character takes a thing with its hands, with no capture of the action (docs/hands.feature)
-export { take, fitPose, handShape, placedPose, walkUp } from "./take";
+export { take, fetch, fitPose, handShape, placedPose, walkUp } from "./take";
export type { TakeThing, TakeSpec, Taken, Mark } from "./take";
diff --git a/sdk/character/src/take.ts b/sdk/character/src/take.ts
index e2f1e454..c9d38afd 100644
--- a/sdk/character/src/take.ts
+++ b/sdk/character/src/take.ts
@@ -154,3 +154,20 @@ export function walkUp(clip: Pose[], fps: number, seconds: number, stand: Pose,
};
return { at, arrives: last / fps + settle };
}
+
+/** Fetching: the body takes a thing, walking up to it first when it is out of reach. `stand` is the body's standing
+ * pose where it is; `walk` a walk clip (poses carrying their own root motion) and its rate. When the thing is in
+ * reach the take runs as given; when it is not, the body walks to where the take says to stand (walkUp), and every
+ * time of the take is put off until it arrives. The answer is the take's, with `arrives` (0 when it didn't walk). */
+export function fetch(skel: Skeleton, stand: Pose, walk: { clip: Pose[]; fps: number; seconds?: number }, spec: TakeSpec, t: number): Taken & { arrives: number } {
+ const first = take(skel, () => stand, spec, spec.start);
+ if (first.reach.ok) return { ...take(skel, () => stand, spec, t), arrives: 0 };
+ const up = walkUp(walk.clip, walk.fps, walk.seconds ?? Math.max(1, first.reach.move / 1.2), { root: [0, stand.root[1], 0], turns: stand.turns }, first.stand.at, first.stand.yaw);
+ const later = (x: number | undefined) => (x === undefined ? undefined : x + up.arrives);
+ const put = spec.put && { ...spec.put, at: spec.put.at + up.arrives, down: spec.put.down + up.arrives };
+ const thrown = spec.throw && { ...spec.throw, at: spec.throw.at + up.arrives };
+ const path = spec.path?.map((k) => ({ ...k, t: k.t + up.arrives }));
+ const slide = spec.slide?.map((k) => ({ ...k, t: k.t + up.arrives }));
+ const moved: TakeSpec = { ...spec, start: spec.start + up.arrives, grab: later(spec.grab), carried: later(spec.carried), pass: later(spec.pass), leave: later(spec.leave), put, throw: thrown, path, slide };
+ return { ...take(skel, up.at, moved, t), arrives: up.arrives };
+}
diff --git a/systems/grab/src/hand.rs b/systems/grab/src/hand.rs
index 749399d2..37f77daa 100644
--- a/systems/grab/src/hand.rs
+++ b/systems/grab/src/hand.rs
@@ -7,7 +7,7 @@
use glam::{Mat3, Quat, Vec3};
use raea_sys_body::rig::{Side, Skeleton, hand_rest};
-use raea_sys_body::shape::Thing;
+use raea_sys_body::shape::{Solid, Thing};
/// where one hand holds a thing, in the thing's own frame
#[derive(Clone, Copy, Debug)]
@@ -71,6 +71,19 @@ pub fn facing(thing: &Thing, holder: Vec3) -> Vec3 {
/// The holds a holder standing at `holder` takes on a thing: one on its left and one on its right, or one hand's.
pub fn find_holds(thing: &Thing, holder: Vec3, o: HoldOptions) -> Grip {
+ // a rod lying down (a capsule or cylinder longer than it is wide, its length near level, thin enough for one
+ // hand) is taken over the top, the fingers round it across its length: not by its ends
+ if let Solid::Capsule { half, r } | Solid::Cylinder { half, r } = thing.solid {
+ let length = thing.turn * Vec3::Y;
+ if half > r * 1.5 && 2.0 * r <= o.span && length.y.abs() < 0.5 {
+ let across = Vec3::Y.cross(length).normalize_or(Vec3::X);
+ // the fingers point away from the holder, across the rod
+ let away = if across.dot(facing(thing, holder)) >= 0.0 { across } else { -across };
+ let top = thing.cast(thing.at + Vec3::Y * (thing.solid.bound() + 0.1), Vec3::NEG_Y, thing.solid.bound() + 0.1).map_or(thing.at + Vec3::Y * r, |h| h.at);
+ let turn = thing.turn.inverse();
+ return Grip::One(Hold { side: o.hand, at: thing.local(top), normal: turn * Vec3::Y, along: Some(turn * away), shape: None });
+ }
+ }
// the body's left is its up crossed with its facing (y up, facing +z, x left)
let left = Vec3::Y.cross(facing(thing, holder));
let far = thing.solid.bound() + 0.1;
diff --git a/systems/grab/tests/use.rs b/systems/grab/tests/use.rs
index 0011e074..5ac843bd 100644
--- a/systems/grab/tests/use.rs
+++ b/systems/grab/tests/use.rs
@@ -201,3 +201,25 @@ fn a_carried_thing_and_the_hands_on_it_stay_out_of_the_body() {
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);
}
+
+#[test]
+fn a_rod_lying_down_is_taken_over_the_top() {
+ let s = mannequin();
+ // a rod 30 cm long and 3 cm thick, lying across in front of the body
+ let rod = Thing { solid: Solid::Capsule { half: 0.135, r: 0.015 }, at: Vec3::new(0.0, 1.0, 0.4), turn: Quat::from_rotation_z(std::f32::consts::FRAC_PI_2) };
+ let Grip::One(hold) = find_holds(&rod, s.rest().root, HoldOptions::default()) else { panic!("one hand") };
+ // on its top, the fingers pointing away from the body across it
+ assert!((rod.world(hold.at) - Vec3::new(0.0, 1.015, 0.4)).length() < 2e-3);
+ assert!((rod.turn * hold.normal).dot(Vec3::Y) > 0.99 && (rod.turn * hold.along.unwrap()).dot(Vec3::Z) > 0.99);
+ // taken, the fingers are round it: on it, not in it
+ let take = Take::new(rod, Grip::One(hold), 0.0);
+ let f = perform(&s, &|_| s.rest(), &take, 1.5);
+ let touch = f.touch[Side::R as usize].unwrap();
+ // (three of five on this body: the index and middle close past so thin a rod without meeting it, not yet right)
+ assert!(touch.on.iter().filter(|on| **on).count() >= 3 && touch.inside < 0.004, "{touch:?}");
+ assert!(palm_off(&s, &f, &hold) < 0.006);
+ // stood on end it is taken by its side, as a bottle is
+ let stood = Thing { turn: Quat::IDENTITY, ..rod };
+ let Grip::One(side) = find_holds(&stood, s.rest().root, HoldOptions::default()) else { panic!("one hand") };
+ assert!(side.along.is_none() && side.normal.y.abs() < 0.01);
+}