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.

HG7b, HG6d: walking up to the thing, a thing handed to another body, and an elbow out of the body's own trunk. A take works wherever the body stands and faces (a test with the body turned 120 degrees and moved 2 m). raea/character's placedPose stands a pose somewhere else; walkUp is the body's own motion for arriving at a take's standing place on a walk capture set down to end there. A hand-over is two takes: the giver's holds the thing out and leaves it as the taker's hand is on. 31 tests

shinyobjectz55a95b4d17d8
diff --git a/docs/hands.feature b/docs/hands.feature
index 4585104c..43208f97 100644
--- a/docs/hands.feature
+++ b/docs/hands.feature
@@ -66,7 +66,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 | examples/strip.rs | 90 | a take drawn as an SVG filmstrip |
- | sdk | sdk/character/src/take.ts | 120 | take(), fitPose(), handShape(): the calls made, typed |
+ | sdk | sdk/character/src/take.ts | 170 | take(), fitPose(), handShape(): the calls made, typed |
@done
Scenario: HG1. An arm reaches a target, and says what it cost
@@ -276,6 +276,29 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
# the thighs), which sdk/body's shape.ts knows and the Rust does not.
Then the limbs and the thing clear a table as the hands, head and chest do
+ @done
+ Scenario: HG7b. Walking up to the thing, and a thing handed to another body
+ # 11-14, built. A take works wherever the body stands and faces: a body turned 120 degrees and moved 2 m
+ # keeps its palm within 12 mm of the hold and carries the cup in front of where it faces. raea/character's
+ # `placedPose` stands a pose somewhere else; `walkUp(clip, fps, seconds, stand, to, yaw)` is the body's own
+ # motion for arriving: a walk capture played from its start and set down so it ends at a take's `stand`
+ # walking the way it faces, then eased into a stand over half a second; the take starts when it arrives.
+ # A hand-over needs nothing new: the giver's take holds the thing out on a path and leaves it at the
+ # moment the taker's take, on a body placed facing it, has its hand on. Seen on teal: walking up to the
+ # table and moving the cup; a second teal taking the cup from the first one's hand. Not right: the feet
+ # slide as the walk settles (the project's one walk capture doesn't stop), and the walk isn't chosen or
+ # steered (that is sdk/body's locomotion, which needs a library for the body).
+ Then a body can arrive where a take says to stand and take the thing, and give it to another body
+
+ @done
+ Scenario: HG6d. An elbow out of the body's own trunk
+ # 11-14, built. trunk.rs `torso`: the trunk as a capsule from the hips to the top of the chest, three
+ # fifths of the way out to a shoulder. An elbow swing that puts the elbow within 3 cm of it counts as far
+ # past its range. A cup well to the body's left taken with the right hand: the elbow is outside the trunk
+ # at every frame. Not done: the forearm and the hand against the thighs and the belly, and the thing
+ # against the body.
+ Then reaching across the body doesn't put the elbow through it
+
Rule: Next, in order
@needs:HG5
@@ -286,13 +309,11 @@ Feature: Procedural arms and hands: a character reaches for, takes, holds, carri
And one copy of the limits serves both the TypeScript and the Rust
@needs:HG5
- Scenario: HG7. The body walks to the thing
- # HG7a says where to stand; nothing walks there yet. sdk/body's locomotion plays a library retargeted to a
- # body, and only the MakeHuman test people have one: the Character SDK project's characters have a single
- # walk clip each, so this waits on their library (or on locomotion taking any body's).
- 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
+ Scenario: HG7. The walk is chosen and steered
+ # HG7a says where to stand and HG7b arrives there on one capture set down to fit.
+ Given a thing out of reach, anywhere
+ Then sdk/body's locomotion (its chooser, matching and foot holds) brings the body to the take's standing
+ place from wherever it is, with a stop that doesn't slide, on any body that has a library
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)
diff --git a/sdk/character/src/character.tsx b/sdk/character/src/character.tsx
index d9842ece..fd533d6e 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 } from "./take";
+export { take, 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 c4adda47..965f9fda 100644
--- a/sdk/character/src/take.ts
+++ b/sdk/character/src/take.ts
@@ -14,6 +14,7 @@
// 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";
+import { qmul, slerp } from "./character/vectors";
type Vec3 = [number, number, number];
@@ -121,3 +122,32 @@ export function handShape(skel: Skeleton, side: "L" | "R", z?: number[], from?:
const pose = from && { root: from.root, turns: skel.joints.map((_, i) => from.turns[i] ?? ([0, 0, 0, 1] as Quat)) };
return native("character.hand", { joints, side, z, pose });
}
+
+/** A pose turned about the vertical by `yaw` (about the origin, radians) and moved by `by`: the same body stood
+ * somewhere else, facing another way. take() works wherever the body is. */
+export function placedPose(p: Pose, yaw: number, by: Vec3 = [0, 0, 0]): Pose {
+ const c = Math.cos(yaw), s = Math.sin(yaw), [x, y, z] = p.root;
+ const turn: Quat = [0, Math.sin(yaw / 2), 0, Math.cos(yaw / 2)];
+ return { root: [c * x + s * z + by[0], y + by[1], c * z - s * x + by[2]], turns: [qmul(turn, p.turns[0] ?? [0, 0, 0, 1]), ...p.turns.slice(1)] };
+}
+
+/** The body's own motion for walking up to a place: a walk clip (poses carrying their own root motion, `fps` a
+ * second) played from its start for `seconds`, set down so it ends at `to` (x and z) walking the way `yaw` faces,
+ * then eased over `settle` seconds into `stand` there. Give take() `at` as its base, a take's `stand` as `to` and
+ * `yaw`, and start the take once it `arrives`. The feet slide a little while it settles: a clip that stops would
+ * not. */
+export function walkUp(clip: Pose[], fps: number, seconds: number, stand: Pose, to: Vec3, yaw: number, settle = 0.5): { at: (t: number) => Pose; arrives: number } {
+ const last = Math.min(clip.length - 1, Math.round(seconds * fps)), a = clip[Math.max(0, last - 4)].root, b = clip[last].root;
+ // the way the clip is walking as it ends, and the turn that makes that `yaw`
+ const by = yaw - Math.atan2(b[0] - a[0], b[2] - a[2]), end = placedPose(clip[last], by);
+ const shift: Vec3 = [to[0] - end.root[0], 0, to[2] - end.root[2]];
+ const there = placedPose({ root: [0, stand.root[1], 0], turns: stand.turns }, yaw, [to[0], 0, to[2]]);
+ const at = (t: number): Pose => {
+ const f = Math.max(0, Math.min(last, t * fps)), i = Math.floor(f), u = f - i, p = clip[i], q = clip[Math.min(last, i + 1)];
+ const walking = placedPose({ root: [p.root[0] + (q.root[0] - p.root[0]) * u, p.root[1] + (q.root[1] - p.root[1]) * u, p.root[2] + (q.root[2] - p.root[2]) * u], turns: p.turns.map((turn, j) => slerp(turn, q.turns[j] ?? turn, u)) }, by, shift);
+ const k = Math.max(0, Math.min(1, (t - last / fps) / settle)), e = k * k * (3 - 2 * k);
+ if (e <= 0) return walking;
+ return { root: [walking.root[0] + (there.root[0] - walking.root[0]) * e, walking.root[1] + (there.root[1] - walking.root[1]) * e, walking.root[2] + (there.root[2] - walking.root[2]) * e], turns: walking.turns.map((turn, j) => slerp(turn, there.turns[j] ?? turn, e)) };
+ };
+ return { at, arrives: last / fps + settle };
+}
diff --git a/systems/grab/src/lib.rs b/systems/grab/src/lib.rs
index 6565a95a..11e890be 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};
+pub use trunk::{clear, look, roomy, stand_for, stoop, torso};
diff --git a/systems/grab/src/take.rs b/systems/grab/src/take.rs
index 7ed09910..4f453a2b 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};
+use crate::trunk::{clear, look, 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};
@@ -362,6 +362,10 @@ pub fn perform(skel: &Skeleton, base: &dyn Fn(f32) -> Pose, take: &Take, t: f32)
if take.avoid.iter().any(|s| s.distance(elbow) < 0.04 || s.distance(elbow.lerp(wrist, 0.5)) < 0.03) {
past += 30.0;
}
+ // and so does one that puts the elbow into the body's own trunk
+ if torso(skel, &drawn).is_some_and(|body| body.distance(elbow) < 0.03) {
+ past += 30.0;
+ }
if best.as_ref().is_none_or(|b| past < b.0 - 0.01) {
best = Some((past, tried));
}
diff --git a/systems/grab/src/trunk.rs b/systems/grab/src/trunk.rs
index af749bdc..4f526d45 100644
--- a/systems/grab/src/trunk.rs
+++ b/systems/grab/src/trunk.rs
@@ -121,3 +121,13 @@ pub fn look(skel: &Skeleton, pose: &Pose, at: Vec3, weight: f32) -> Pose {
}
out
}
+
+/// The trunk as a solid, where a pose has it: a capsule from the hips to the top of the chest, as wide as the body
+/// (three fifths of the way out to a shoulder). What an elbow must not swing into.
+pub fn torso(skel: &Skeleton, at: &Posed) -> Option<Thing> {
+ let (chest, shoulder) = (skel.joint("spine_03")?, skel.arm(Side::L)?[0]);
+ let top = at.pos[chest] + at.rot[chest] * (skel.joints[chest].tail - skel.joints[chest].head);
+ let up = top - at.pos[0];
+ 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)) })
+}
diff --git a/systems/grab/tests/use.rs b/systems/grab/tests/use.rs
index 5dd7c5c6..a31b1396 100644
--- a/systems/grab/tests/use.rs
+++ b/systems/grab/tests/use.rs
@@ -115,3 +115,50 @@ fn the_forearms_the_knees_and_the_thing_keep_out_of_a_table() {
t += 1.0 / 30.0;
}
}
+
+#[test]
+fn a_body_turned_and_moved_takes_what_is_in_front_of_it() {
+ let s = mannequin();
+ // the body stands 2 m off, turned a third of the way round; the cup is where it was in front of it
+ let (turn, at) = (Quat::from_rotation_y(2.1), Vec3::new(2.0, 0.0, -1.0));
+ let mut stand = s.rest();
+ stand.root = turn * stand.root + at;
+ stand.turns[0] = turn * stand.turns[0];
+ let base = move |_: f32| stand.clone();
+ let cup = Thing { solid: Solid::Cylinder { half: 0.05, r: 0.035 }, at: turn * Vec3::new(-0.2, 1.0, 0.38) + at, turn };
+ let (there, facing) = stand_for(&cup, base(0.0).root);
+ // it already stands about where a take would have it stand, facing the cup
+ assert!((there - base(0.0).root).length() < 0.25, "{}", (there - base(0.0).root).length());
+ assert!(Quat::from_rotation_y(facing).angle_between(turn) < 0.6);
+ let grip = find_holds(&cup, base(0.0).root, HoldOptions::default());
+ let Grip::One(hold) = grip else { panic!("one hand") };
+ let mut take = Take::new(cup, grip, 0.0);
+ take.release = Some(Release::Put { at: 1.8, down: 2.4, place: turn * Vec3::new(0.05, 1.0, 0.4) + at });
+ let mut t = take.grab;
+ while t < 2.4 {
+ let f = perform(&s, &base, &take, t);
+ assert!(palm_off(&s, &f, &hold) < 0.012, "t {t}: the palm is {} m off", palm_off(&s, &f, &hold));
+ // carried, it is in front of the turned body and upright
+ assert!((f.thing.turn * Vec3::Y).dot(Vec3::Y) > 0.9999);
+ t += 1.0 / 30.0;
+ }
+ let carried = perform(&s, &base, &take, 1.5).thing.at - base(0.0).root;
+ assert!(carried.dot(turn * Vec3::Z) > 0.15, "in front of where it faces");
+}
+
+#[test]
+fn an_elbow_stays_out_of_the_trunk_when_a_hand_reaches_across() {
+ let s = mannequin();
+ // a cup well to the body's left, taken with the right hand
+ let cup = Thing::new(Solid::Cylinder { half: 0.05, r: 0.035 }, Vec3::new(0.22, 1.05, 0.3));
+ let take = Take::new(cup, find_holds(&cup, s.rest().root, HoldOptions::default()), 0.0);
+ let elbow = s.arm(Side::R).unwrap()[1];
+ let mut t = 0.0;
+ while t < 1.5 {
+ let f = perform(&s, &|_| s.rest(), &take, t);
+ let w = s.fk(&f.pose);
+ let body = torso(&s, &w).unwrap();
+ assert!(body.distance(w.pos[elbow]) > 0.0, "t {t}: the elbow is {} m into the trunk", -body.distance(w.pos[elbow]));
+ t += 1.0 / 30.0;
+ }
+}