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.

HG16: in progress: a SOMA body's twist joints set on any pose (raea-sys-body with_twists, native call character.twists, raea/character withTwists), so a clip or a solver that turns the named joints only draws with the limbs' twist spread. The body library's captures, moved to SOMA joint for joint, play on SOMA's body through it

shinyobjectz1dee5992e53b
diff --git a/runtime/calls/src/lib.rs b/runtime/calls/src/lib.rs
index 236e1846..8f510505 100644
--- a/runtime/calls/src/lib.rs
+++ b/runtime/calls/src/lib.rs
@@ -179,6 +179,7 @@ pub fn call(name: &str, v: &Value) -> R<Value> {
"character.hand" => raea_sys_grab::hand_json(v),
"character.soma" => raea_sys_grab::soma_json(v),
"character.turns" => raea_sys_grab::turns_json(v),
+ "character.twists" => raea_sys_grab::twists_json(v),
"fonts.families" => Ok(families().into()),
"fonts.google" => {
let family = s(v, "family")?;
@@ -232,6 +233,7 @@ pub fn register() {
("character.hand", raea_sys_grab::HAND_ARGS, raea_sys_grab::HAND_ANSWER, "a hand shaped by a few numbers of a model of real hand poses (none: the average relaxed hand; the first opens it, positive, and closes it), on a pose; and that hand read back: its numbers and how odd it is (0: the average hand)"),
("character.soma", raea_sys_grab::SOMA_ARGS, raea_sys_grab::SOMA_ANSWER, "the pose that has a body's bones pointing as a SOMA body's do (SOMA: the 78-joint skeleton of NVIDIA's motion models and datasets), from SOMA's joint names and where each joint is"),
("character.turns", raea_sys_grab::TURNS_ARGS, raea_sys_grab::TURNS_ANSWER, "a SOMA body's pose from a motion given as turns (each named joint's world turn from SOMA's T-pose, as Kimodo writes them, and where the hips are), with the body's twist joints set"),
+ ("character.twists", raea_sys_grab::TWISTS_ARGS, raea_sys_grab::TURNS_ANSWER, "a SOMA body's pose with its twist joints set from its limbs' turns: for a pose from a clip or a solver, which turn the named joints only"),
("fonts.families", "{}", "string[]", "the system's font families by name, sorted, as fontique (bevy_text's FontCx) lists them"),
("fonts.google", "{ family: string }", "{ family: string }", "a Google Fonts family the page loads (its Latin faces, every weight and style, fetched once through raea's URL cache), as a stylesheet link loads it in Chrome (raea/text loadFont)"),
("fonts.atlases", "{ font: string; size: number; text: string }", "{ width: number; height: number; src: string }[]", "bevy_text's glyph atlases for a text in a font file at a size px, each page a PNG data: URL, as Bevy's FontAtlasSet holds them"),
diff --git a/sdk/character/src/character.tsx b/sdk/character/src/character.tsx
index 406e7c3d..d981efd3 100644
--- a/sdk/character/src/character.tsx
+++ b/sdk/character/src/character.tsx
@@ -21,5 +21,5 @@ export type { Quat, Joint, Skeleton, Pose, Posed, Side, Finger, HandShape, Closi
export { take, fetch, fitPose, handShape, placedPose, walkUp } from "./take";
export type { TakeThing, TakeSpec, Taken, Mark } from "./take";
// motion on SOMA's skeleton (NVIDIA's motion models and datasets) played on a raea body
-export { readSomaUsda, somaPose, turnsPose } from "./soma";
+export { readSomaUsda, somaPose, turnsPose, withTwists } from "./soma";
export type { SomaClip, TurnsClip } from "./soma";
diff --git a/sdk/character/src/soma.ts b/sdk/character/src/soma.ts
index 220845c4..e698c2f1 100644
--- a/sdk/character/src/soma.ts
+++ b/sdk/character/src/soma.ts
@@ -81,3 +81,10 @@ export function turnsPose(skel: Skeleton & { tpose?: Record<string, Quat> }, cli
const joints = skel.joints.map((j) => ({ name: j.name, parent: j.parent, head: j.head, tail: j.tail }));
return native("character.turns", { joints, tpose: skel.tpose ?? {}, names: clip.names, turns: clip.turns[f], root: clip.root[f] }).pose;
}
+
+/** A SOMA body's pose with its twist joints set from its limbs' turns (the native call character.twists): for a
+ * pose from a clip or a solver, which turn the named joints only. A body without twist joints comes back as it is. */
+export function withTwists(skel: Skeleton, pose: Pose): Pose {
+ const joints = skel.joints.map((j) => ({ name: j.name, parent: j.parent, head: j.head, tail: j.tail }));
+ return native("character.twists", { joints, pose }).pose;
+}
diff --git a/sdk/raea/src/native-calls.ts b/sdk/raea/src/native-calls.ts
index 60ebd973..205f7745 100644
--- a/sdk/raea/src/native-calls.ts
+++ b/sdk/raea/src/native-calls.ts
@@ -46,6 +46,8 @@ export interface NativeCalls {
"character.take": { args: { joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; t: number; base: { t: number; root: [number, number, number]; turns: [number, number, number, number][] }[]; thing: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }; start: number; grab?: number; carried?: number; carry?: [number, number, number]; hand?: "L" | "R"; lower?: number; holds?: { side: "L" | "R"; at: [number, number, number]; normal: [number, number, number]; along?: [number, number, number]; shape?: number[] }[]; path?: { t: number; carry: [number, number, number]; tilt?: [number, number, number, number] }[]; weight?: number; pass?: number; slide?: { t: number; at: [number, number, number]; turn?: [number, number, number, number] }[]; leave?: number; avoid?: { ball?: number; box?: [number, number, number]; capsule?: [number, number]; cylinder?: [number, number]; at: [number, number, number]; turn?: [number, number, number, number] }[]; put?: { at: number; down: number; place: [number, number, number] }; throw?: { at: number; velocity: [number, number, number]; floor?: number } }; answer: { pose: { root: [number, number, number]; turns: [number, number, number, number][] }; thing: { at: [number, number, number]; turn: [number, number, number, number] }; phase: "Before" | "Reach" | "Lift" | "Carry" | "Release" | "After"; hands: 1 | 2; miss: number; moved: number; limited: boolean; stand: { at: [number, number, number]; yaw: number }; reach: { ok: boolean; move: number } } };
/** a SOMA body's pose from a motion given as turns (each named joint's world turn from SOMA's T-pose, as Kimodo writes them, and where the hips are), with the body's twist joints set */
"character.turns": { args: { joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; tpose?: Record<string, [number, number, number, number]>; names: string[]; turns: [number, number, number, number][]; root: [number, number, number] }; answer: { pose: { root: [number, number, number]; turns: [number, number, number, number][] } } };
+ /** a SOMA body's pose with its twist joints set from its limbs' turns: for a pose from a clip or a solver, which turn the named joints only */
+ "character.twists": { args: { joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; pose: { root: [number, number, number]; turns: [number, number, number, number][] } }; answer: { pose: { root: [number, number, number]; turns: [number, number, number, number][] } } };
/** raea's command line (render, play, guide, bundle, types; the media verbs: raea media, raea ffmpeg), run in process in cwd */
"cli.raea": { args: { args: string[]; cwd: string }; answer: { exit: number; stdout: string; stderr: string } };
/** a headless run ends with this exit code */
diff --git a/systems/body/src/json.rs b/systems/body/src/json.rs
index 4cbf7d54..12559be5 100644
--- a/systems/body/src/json.rs
+++ b/systems/body/src/json.rs
@@ -8,7 +8,7 @@ use crate::fit::{Mark, fit};
use crate::prior::{coefficients, oddness, shape};
use crate::rig::{Pose, Side, Skeleton};
use crate::soma::from_soma;
-use crate::turns::from_turns;
+use crate::turns::{from_turns, with_twists};
pub fn num(v: &Value, what: &str) -> Result<f32, String> {
v.as_f64().map(|n| n as f32).ok_or_else(|| format!("character.take: {what} isn't a number"))
@@ -117,6 +117,19 @@ pub fn turns_json(v: &Value) -> Result<Value, String> {
Ok(json!({ "pose": posed(&from_turns(&skel, &tpose, &names, &turns, vec3(&v["root"], "root")?)) }))
}
+pub const TWISTS_ARGS: &str = "{ joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; pose: { root: [number, number, number]; turns: [number, number, number, number][] } }";
+
+/// `character.twists`: a SOMA body's pose with its twist joints set from its limbs' turns (turns.rs).
+pub fn twists_json(v: &Value) -> Result<Value, String> {
+ let skel = Skeleton::from_value(v)?;
+ let mut pose = skel.rest();
+ pose.root = vec3(&v["pose"]["root"], "pose.root")?;
+ for (slot, turn) in pose.turns.iter_mut().zip(v["pose"]["turns"].as_array().into_iter().flatten()) {
+ *slot = quat(turn, "the pose's turn")?;
+ }
+ Ok(json!({ "pose": posed(&with_twists(&skel, &pose)) }))
+}
+
/// a pose as the calls answer it: the root's place and every joint's turn
pub fn posed(pose: &Pose) -> Value {
let turns: Vec<[f32; 4]> = pose.turns.iter().map(|q| q.to_array()).collect();
diff --git a/systems/body/src/lib.rs b/systems/body/src/lib.rs
index 7dd48473..98ef5042 100644
--- a/systems/body/src/lib.rs
+++ b/systems/body/src/lib.rs
@@ -23,9 +23,9 @@ pub mod turns;
pub use arm::{ArmOptions, IkReport, forearm_twist, reach, settle_hinge, twist_joints, two_bone};
pub use soma::{from_soma, raea_joint};
-pub use turns::{from_turns, set_twists};
+pub use turns::{from_turns, set_twists, with_twists};
pub use fit::{Mark, fit, marks_of};
-pub use json::{FIT_ANSWER, FIT_ARGS, HAND_ANSWER, HAND_ARGS, SOMA_ANSWER, SOMA_ARGS, TURNS_ANSWER, TURNS_ARGS, fit_json, hand_json, soma_json, turns_json};
+pub use json::{FIT_ANSWER, FIT_ARGS, HAND_ANSWER, HAND_ARGS, SOMA_ANSWER, SOMA_ARGS, TURNS_ANSWER, TURNS_ARGS, TWISTS_ARGS, fit_json, hand_json, soma_json, turns_json, twists_json};
pub use limits::{Angles, angles_of, clamp_turn, violations};
pub use shape::{Hit, Solid, Thing};
pub use rig::{HandRest, Pose, Posed, Sample, Side, Skeleton, hand_rest, mannequin};
diff --git a/systems/body/src/turns.rs b/systems/body/src/turns.rs
index 402bc59f..bef29693 100644
--- a/systems/body/src/turns.rs
+++ b/systems/body/src/turns.rs
@@ -57,6 +57,18 @@ pub fn from_turns(skel: &Skeleton, tpose: &HashMap<String, Quat>, names: &[Strin
};
}
set_twists(skel, &mut world);
- let turns = skel.joints.iter().enumerate().map(|(i, j)| j.parent.map_or(world[i], |p| (world[p].inverse() * world[i]).normalize())).collect();
- Pose { root, turns }
+ Pose { root, turns: locals(skel, &world) }
+}
+
+/// each joint's turn against its parent, from every joint's world turn
+fn locals(skel: &Skeleton, world: &[Quat]) -> Vec<Quat> {
+ skel.joints.iter().enumerate().map(|(i, j)| j.parent.map_or(world[i], |p| (world[p].inverse() * world[i]).normalize())).collect()
+}
+
+/// A pose of a SOMA body with its twist joints set from the joints at each limb segment's ends: for a pose that
+/// came from a clip or a solver, which turn the named joints only.
+pub fn with_twists(skel: &Skeleton, pose: &Pose) -> Pose {
+ let mut world = skel.fk(pose).rot;
+ set_twists(skel, &mut world);
+ Pose { root: pose.root, turns: locals(skel, &world) }
}
diff --git a/systems/grab/src/lib.rs b/systems/grab/src/lib.rs
index c9bbb6c6..6eabc9f0 100644
--- a/systems/grab/src/lib.rs
+++ b/systems/grab/src/lib.rs
@@ -22,6 +22,6 @@ pub mod trunk;
pub use hand::{Grip, Hold, HoldOptions, Touch, curl, find_holds, wrist_for};
pub use interact::pick;
pub use json::{TAKE_ANSWER, TAKE_ARGS, take_json};
-pub use raea_sys_body::json::{FIT_ANSWER, FIT_ARGS, HAND_ANSWER, HAND_ARGS, SOMA_ANSWER, SOMA_ARGS, TURNS_ANSWER, TURNS_ARGS, fit_json, hand_json, soma_json, turns_json};
+pub use raea_sys_body::json::{FIT_ANSWER, FIT_ARGS, HAND_ANSWER, HAND_ARGS, SOMA_ANSWER, SOMA_ARGS, TURNS_ANSWER, TURNS_ARGS, TWISTS_ARGS, fit_json, hand_json, soma_json, turns_json, twists_json};
pub use take::{Frame, Key, Phase, Release, Take, perform};
pub use trunk::{clear, give_for, hand_points, look, own_solids, room, spread_for, stand_for, stoop, torso};