Files
shaneandshinyobjectz 036a2ddb5e raea scene faults: a 3D scene's faults judged as a viewer sees them, motion held to what a body does (#272)
* raea scene faults: a 3D scene's faults judged as a viewer would see them, motion held to what a body does, both learning from verdicts and fixes

The scene judge (raea-sys-notice, docs/notice.feature): each lint finding asked of every camera of the shot (in
frame, facing it, not hidden, how many pixels) and scored by a small logistic model over those features and the
words of the parts' names. It learns from verdicts (--real/--fine) and from fixes (a finding gone while its parts
remain); verdicts all one way teach only words, and a held-out check is part of train. 22 verdicts on 18 findings
from 2 projects: 19 right held out, against 16 for the prior. --seed plants faults to measure it; --ask rings the
likeliest on its frame and asks a vision model, given the scene's own words, only whether it's meant. Renders
judge their own frames at the end (runtime/endchecks faults.rs, RAEA_FAULTS_CHECK=0 skips it).

Motion (raea-sys-motionfaults): knees buckling, feet skating, joints past their limits, jolts, fingers bent or
twisted, bones through what the hand holds, and a hand that hasn't closed on it (grip). Lines set from 107 clean
ACCAD takes; 1,039 of 1,051 planted faults caught. --clip reads a clip, --motion a composition's characters with
their hands tested against the scene's triangles; it caught gambit's ladder thumb (68a505a) before its fix and is
silent after. Fixes and looks become verdicts and examples, and a critic (critic.rs) fitted to them by train says
which findings matter; a verdict on a finding's own key at its size outranks it.

The contact lint's touching test made exact-faster (lint/touching.rs, same findings, 30.6 to 8.5 s on a room),
lint_but_clips for a render's end, and core/zfight keeps a fight's patches for where it shows.

* docs/notice.feature: the judge on six gambit interiors it had never seen

41 verdicts from looks at ringed renders (3 real, 38 fine). The judge as it stood called nearly all of them faults;
refitted with each shop left out and then judged, 34 of 41 right. Floats by size and the hidden-seam clip are what it
still misses; three feature changes tried in a replay of the fit and not kept.

* docs/notice.feature: motion checks on gambit's fp labs, and the shin roll they misread

The fp character's shins read 136-165 degrees past their range (twist near 180, its foot taking the roll back);
rendered, nothing shows. Left unverdicted, since a line on limit:calf at that size would hide real broken knees;
next is reading a joint's roll with its child's.

* raea scene faults --motion: a roll its child takes back is no limit

A solve that rolls a shin half a turn and undoes it at the foot read as the shin 136-165 degrees past its range on
every crouching step of gambit's fp character, though nothing shows. Before the limit check, a roll of 15 degrees or
more about a joint's own bone moves to its child when the two are then less past their ranges together (legs.rs
settled; raea-sys-body limits::over). It moves no joint's place; a roll nothing takes back stays. Tested both ways.
Limit findings on the takedown 34 -> 17, the sneak 21 -> 6, the crowd's walkers unchanged.

* raea scene faults train: the judge held out a whole shot at a time

Besides each finding held out, train now fits without each shot and judges it (labels::shots keeps the shot with
each verdict): how it does on a scene it hasn't seen. On the 63 verdicts from 3 projects and 13 shots: 51 right
(the prior 18), where a replay had put it at 50.

* raea scene faults --motion: a roll moves only where it moves nothing else, and a change of checks is no fix

The roll fix (xos) moved a hand's roll onto one finger: that moves the other fingers, and a finger has no limits to
show it, so 77 of the crowd's wrists vanished, and the fix-to-verdict path kept every finding the change hid as a
real fix. Now a roll moves only when the joint's other children sit on its bone's line (a shin's twist joints), to a
child with limits of its own (tested on a hand); and a fix is read only between runs of the same checks
(motionfaults CHECKS, kept in motion.last). The false rows are removed from the critic's examples. Limit findings:
takedown 34 -> 14, sneak 21 -> 6, crowd unchanged, every hand finding kept; two runs each, 0 fixes.

* Fold scene faults' copies into what they copied (the dupes gate: 307/64 groups back to 293/57): one sigmoid in raea-core-ease (splat, notice, motionfaults), solid() in raea-sys-body's JSON readers (grab, motionfaults), the scene's hand stretches onto motionfaults' stretches() and its seeded Rng, one bounds() for least and most, lint_with(clips) in place of lint_but_clips, raea_runtime_bundle::flags for a repeated flag, held_out() for both held-out passes, a fault that stands in one place, the views and their frame numbers in one pass

* flag is the first of flags (raea-runtime-bundle back to 2000 lines, the size gate): one way to read a flag's values

---------

Co-authored-by: shinyobjectz <[email protected]>
2026-11-29 16:40:52 -08:00

154 lines
8.9 KiB
Rust

//! Poses fitted to points and hands shaped by number, asked for as JSON: the engine's native calls character.fit and
//! character.hand (raea/character's fitPose and handShape); and the readers the hands' calls share.
use glam::{Quat, Vec3};
use serde_json::{Value, json};
use crate::fit::{Mark, fit};
use crate::prior::{coefficients, oddness, shape};
use crate::rig::{Pose, Side, Skeleton};
use crate::shape::Solid;
use crate::soma::from_soma;
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"))
}
/// A held thing's shape: a ball's radius, a box's half sizes, or a capsule's or cylinder's [half length, radius].
pub fn solid(v: &Value) -> Result<Solid, String> {
if !v["ball"].is_null() {
return Ok(Solid::Ball { r: num(&v["ball"], "thing.ball")? });
}
if !v["box"].is_null() {
return Ok(Solid::Box { half: vec3(&v["box"], "thing.box")? });
}
// a capsule or a cylinder: half its length along its own y, then its radius
let rod = ["capsule", "cylinder"].into_iter().find(|k| !v[*k].is_null()).ok_or("character.take: the thing needs a shape: ball, box, capsule or cylinder")?;
let a = v[rod].as_array().filter(|a| a.len() == 2).ok_or_else(|| format!("character.take: thing.{rod} isn't [half its length, radius]"))?;
let (half, r) = (num(&a[0], rod)?, num(&a[1], rod)?);
Ok(if rod == "capsule" { Solid::Capsule { half, r } } else { Solid::Cylinder { half, r } })
}
pub fn vec3(v: &Value, what: &str) -> Result<Vec3, String> {
let a = v.as_array().filter(|a| a.len() == 3).ok_or_else(|| format!("character.take: {what} isn't [x, y, z]"))?;
Ok(Vec3::new(num(&a[0], what)?, num(&a[1], what)?, num(&a[2], what)?))
}
pub fn quat(v: &Value, what: &str) -> Result<Quat, String> {
let a = v.as_array().filter(|a| a.len() == 4).ok_or_else(|| format!("character.take: {what} isn't [x, y, z, w]"))?;
Ok(Quat::from_xyzw(num(&a[0], what)?, num(&a[1], what)?, num(&a[2], what)?, num(&a[3], what)?).normalize())
}
pub const FIT_ARGS: &str = "{ joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; marks: { joint: string; offset?: [number, number, number]; at: [number, number, number]; weight?: number }[]; from?: { root: [number, number, number]; turns: [number, number, number, number][] }; passes?: number }";
pub const FIT_ANSWER: &str = "{ pose: { root: [number, number, number]; turns: [number, number, number, number][] }; miss: number }";
/// `character.fit`: a pose fitted to points of the body seen somewhere (fit.rs).
pub fn fit_json(v: &Value) -> Result<Value, String> {
let skel = Skeleton::from_value(v)?;
let mut from = skel.rest();
if !v["from"].is_null() {
from.root = vec3(&v["from"]["root"], "from.root")?;
for (slot, turn) in from.turns.iter_mut().zip(v["from"]["turns"].as_array().into_iter().flatten()) {
*slot = quat(turn, "from's turn")?;
}
}
let mut marks = Vec::new();
for m in v["marks"].as_array().ok_or("character.fit: no marks")? {
let name = m["joint"].as_str().ok_or("character.fit: a mark names no joint")?;
let joint = skel.joint(name).ok_or_else(|| format!("character.fit: the body has no joint {name}"))?;
let offset = if m["offset"].is_null() { Vec3::ZERO } else { vec3(&m["offset"], "a mark's offset")? };
let weight = if m["weight"].is_null() { 1.0 } else { num(&m["weight"], "a mark's weight")? };
marks.push(Mark { joint, offset, at: vec3(&m["at"], "a mark's at")?, weight });
}
let passes = v["passes"].as_u64().unwrap_or(8) as usize;
let (pose, miss) = fit(&skel, &from, &marks, passes);
Ok(json!({ "pose": posed(&pose), "miss": miss }))
}
pub const HAND_ARGS: &str = "{ joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; side: \"L\" | \"R\"; z?: number[]; pose?: { root: [number, number, number]; turns: [number, number, number, number][] } }";
pub const HAND_ANSWER: &str = "{ pose: { root: [number, number, number]; turns: [number, number, number, number][] }; z: number[]; odd: number }";
/// `character.hand`: a hand shaped by the hand prior's coefficients (prior.rs) on a pose, and that hand read back:
/// its coefficients and how odd it is.
pub fn hand_json(v: &Value) -> Result<Value, String> {
let skel = Skeleton::from_value(v)?;
let side = if v["side"] == "L" { Side::L } else { Side::R };
let mut pose = skel.rest();
if !v["pose"].is_null() {
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")?;
}
}
if let Some(z) = v["z"].as_array() {
let z = z.iter().map(|n| num(n, "a number of z")).collect::<Result<Vec<f32>, String>>()?;
shape(&skel, &mut pose.turns, side, &z).ok_or("character.hand: the body has no hand on that side")?;
}
let (z, _) = coefficients(&skel, &pose, side).ok_or("character.hand: the body has no hand on that side")?;
let odd = oddness(&skel, &pose, side).unwrap_or(0.0);
Ok(json!({ "pose": posed(&pose), "z": z, "odd": odd }))
}
pub const SOMA_ARGS: &str = "{ joints: { name: string; parent: number; head: [number, number, number]; tail: [number, number, number] }[]; names: string[]; at: [number, number, number][]; eyes?: [number, number, number] }";
pub const SOMA_ANSWER: &str = "{ pose: { root: [number, number, number]; turns: [number, number, number, number][] } }";
/// `character.soma`: the pose that has the body's bones pointing as a SOMA body's do (soma.rs).
pub fn soma_json(v: &Value) -> Result<Value, String> {
let skel = Skeleton::from_value(v)?;
let mut names = Vec::new();
for name in v["names"].as_array().ok_or("character.soma: no names")? {
names.push(name.as_str().ok_or("character.soma: a name isn't text")?.to_string());
}
let mut at = Vec::with_capacity(names.len());
for p in v["at"].as_array().ok_or("character.soma: no places")? {
at.push(vec3(p, "a SOMA joint's place")?);
}
if at.len() != names.len() {
return Err(format!("character.soma: {} names for {} places", names.len(), at.len()));
}
let eyes = if v["eyes"].is_null() { None } else { Some(vec3(&v["eyes"], "eyes")?) };
let pose = from_soma(&skel, &names, &at, eyes).ok_or("character.soma: the body or the SOMA joints lack the hips or a leg")?;
Ok(json!({ "pose": posed(&pose) }))
}
pub const TURNS_ARGS: &str = "{ 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] }";
pub const TURNS_ANSWER: &str = "{ pose: { root: [number, number, number]; turns: [number, number, number, number][] } }";
/// `character.turns`: a SOMA body's pose from a motion's turns, its twist joints set (turns.rs).
pub fn turns_json(v: &Value) -> Result<Value, String> {
let skel = Skeleton::from_value(v)?;
let mut tpose = std::collections::HashMap::new();
for (name, turn) in v["tpose"].as_object().into_iter().flatten() {
tpose.insert(name.clone(), quat(turn, "a joint's turn to the T-pose")?);
}
let names: Vec<String> = v["names"].as_array().ok_or("character.turns: no names")?.iter().filter_map(|n| n.as_str().map(String::from)).collect();
let mut turns = Vec::with_capacity(names.len());
for turn in v["turns"].as_array().ok_or("character.turns: no turns")? {
turns.push(quat(turn, "a joint's turn")?);
}
if turns.len() != names.len() {
return Err(format!("character.turns: {} names for {} turns", names.len(), turns.len()));
}
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();
json!({ "root": pose.root.to_array(), "turns": turns })
}