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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
SG14: frame-empty is an error; a room's walls and models fill the frame, the page's background doesn't
shinyobjectz0c9fc255f228
diff --git a/docs/stage-guards.feature b/docs/stage-guards.featureindex 2a466727..f9daacb6 100644--- a/docs/stage-guards.feature+++ b/docs/stage-guards.feature@@ -416,8 +416,9 @@ Feature: Stage guards: a 3D render an agent can't breakScenario: SG14. The frame is composedGiven the plan- | crate | file | lines | job |- | raea-sys-stage | systems/stage/src/framing.rs | 182 | the share of the frame any part covers (a grid of their boxes), and the shot's subject cut by the edge |+ | crate | file | lines | job |+ | raea-sys-stage | systems/stage/src/framing.rs | 314 | the share of the frame any part covers (a grid of their boxes), and the shot's subject cut by the edge |+ | raea-sys-stage | systems/stage/src/manifest.rs | +17 | a CSS background over half the frame is the page's ground, not shown |Then the part a shot is about (one a Label or pin points at, else the nearest named part) cut by the frame's edgefor more than 10 frames is an errorAnd under 8% of the frame showing any part, for more than 1 s, is an error@@ -437,6 +438,22 @@ Feature: Stage guards: a 3D render an agent can't break# nobuild's Solari dummy buffer was sized for its 64-byte vertex; at 48 the GPU refused that frame), 1:05 and# 1:09-1:12 read empty too: a dark sphere half in frame, then a canyon's walls filling it, backdrop by the same# rule. Left: the subject a Label points at; a room's inside as content.+ # Branch stage-guards-17: frame-empty is an error. Three causes of false and missed empties, each measured. A+ # room's walls were backdrop by the slab rule: a standing slab (its thin side within 45 degrees of level) fills+ # the frame now, though it is never the shot's subject; a floor, water or a ceiling still doesn't. A model's size+ # wasn't known: its file's box (read once a render) adds coverage now but never judges a frame, since raea poses+ # a person's joints off its rest box (two character sheets read empty when it did), and a room model round the+ # camera leaves the frame unjudged, as a mesh across the camera's plane does. And the page's ground counted as+ # shown: since stage-guards-9 a frame with a background colour read as full, so the film's two full-frame cream+ # fills hid all five of its empty stretches, the blank frame at 6:04 among them; a CSS background (a colour or a+ # gradient) over half the frame is ground now, an <img> or svg still shown. A frame pass or a set of copies+ # (<Instances>) leaves a frame unjudged, as grass does, and fire is of unknown size, as a model is. raea scene+ # stage over the 29 clean scenes, Stay and the film: Stay's 8 empty stretches are gone, the film's 5 stay (1:59,+ # 3:07, 3:41, 5:54 and 6:03-6:07: the notes' 3:40, 6:04 and 6:08), no clean scene has one, and every other+ # check's findings are the same. Rendered whole with their pages known: the film fails on four (3:07, 3:41, 5:54+ # and 6:03-6:07; 1:59 holds a caption that fills it), 439 errors where it had 435, and Stay (approved) on none,+ # its findings otherwise the same as before (its three meant errors, three warnings). Left: the subject a Label+ # points at; subject-cut stays a warning (33, on Stay and four clean scenes).@doneScenario: SG15. A broken render can't be posteddiff --git a/runtime/export/src/scene.rs b/runtime/export/src/scene.rsindex 3a0274e1..0035ef90 100644--- a/runtime/export/src/scene.rs+++ b/runtime/export/src/scene.rs@@ -38,7 +38,7 @@ fn checked(frames: Vec<(i64, Vec<raea_core_scene::Item>)>, page: Option<&[serde_*SEEN.lock().unwrap() = Some(raea_sys_stage::seen(&all, &nums, w, h));let mut found = if std::env::var("RAEA_CLIP_CHECK").as_deref() == Ok("0") { Vec::new() } else { raea_sys_contact::told(&all, &nums, w, h, fps) };mark("end checks: clipping");- found.extend(raea_sys_stage::told(&all, &nums, &page.map_or_else(Vec::new, |p| raea_sys_stage::pages(p, &nums)), w, h, fps));+ found.extend(raea_sys_stage::told(&all, &nums, &page.map_or_else(Vec::new, |p| raea_sys_stage::pages(p, &nums, w, h)), w, h, fps));mark("end checks: staging");// the clipping check's solids, kept for the process, aren't needed again by a renderraea_sys_contact::forget();diff --git a/sdk/guides/craft/bevy.md b/sdk/guides/craft/bevy.mdindex 54305131..f055997b 100644--- a/sdk/guides/craft/bevy.md+++ b/sdk/guides/craft/bevy.md@@ -107,8 +107,9 @@ the rest come from `raea`.gives them their reading time first. `raea render` fails on a speed that changes over 2x within 3 frames(`camera-lurch`) and on a dolly in and back out (`camera-reverse`): SG13.11. **Render and look.** Before a render, `raea scene stage edit.tsx` steps every frame without drawing and runs the- checks above, and the render runs them again at its end, beside clipping: it warns when almost nothing is on screen- for a second (`frame-empty`) or the shot's part is cut by the edge (`subject-cut`), SG14. Render stills where things- happen (`raea render edit.tsx --at A,B,C -o stills/`) and look at them. A 3D frame that renders black usually has no- light or a camera inside or behind the subject. `raea show` refuses a render that still holds an error, naming each:- fix it, or say why it goes anyway with `--despite CHECK "why"`, which the person reads (SG15).+ checks above, and the render runs them again at its end, beside clipping: it fails when almost nothing is on screen+ for a second (`frame-empty`: the page's background colour or gradient isn't something on screen; a room's walls, or+ words in the page, are) and warns when the shot's part is cut by the edge (`subject-cut`), SG14. Render stills+ where things happen (`raea render edit.tsx --at A,B,C -o stills/`) and look at them. A 3D frame that renders black+ usually has no light or a camera inside or behind the subject. `raea show` refuses a render that still holds an+ error, naming each: fix it, or say why it goes anyway with `--despite CHECK "why"`, which the person reads (SG15).diff --git a/systems/stage/src/framing.rs b/systems/stage/src/framing.rsindex 3ef7846c..62ae8f6f 100644--- a/systems/stage/src/framing.rs+++ b/systems/stage/src/framing.rs@@ -32,15 +32,7 @@ pub(crate) fn own_box(it: &raea_core_scene::Item, boxes: &mut HashMap<String, Opmatch it.kind {"mesh" => {let shape = it.shape.as_deref()?;- *boxes.entry(shape.to_string()).or_insert_with(|| {- let t = raea_core_shape::cached(shape).ok()?;- let (mut lo, mut hi) = (Vec3::splat(f32::MAX), Vec3::splat(f32::MIN));- for p in &t.positions {- lo = lo.min(Vec3::from(*p));- hi = hi.max(Vec3::from(*p));- }- (lo.x <= hi.x).then_some((lo, hi))- })+ *boxes.entry(shape.to_string()).or_insert_with(|| span(raea_core_shape::cached(shape).ok()?.positions.iter().copied()))}"text" => {let words = it.props.get("text").and_then(serde_json::Value::as_str).unwrap_or("");@@ -62,6 +54,46 @@ pub(crate) fn backdrop(it: &raea_core_scene::Item, lo: Vec3, hi: Vec3) -> bool {ext.max_element() > BACKDROP_M && ext.min_element() < SLAB * ext.max_element()}+/// A model's box in its own space, from its file's triangles (each file read once a render); None for one whose file+/// animates or can't be read. Coverage only, never sure: raea may pose its joints (a person walks off its rest box), and+/// a box is mostly air round a tree, so it never makes a frame judged, nor judges words over it (SG11); but a frame+/// its box fills isn't empty (Stay's pool room of wall models read empty with their origins out of view: SG14).+fn model_box(it: &raea_core_scene::Item, boxes: &mut HashMap<String, Option<(Vec3, Vec3)>>) -> Option<(Vec3, Vec3)> {+ let src = raea_core_scene::src_path(it.props.get("src").and_then(serde_json::Value::as_str)?);+ *boxes.entry(format!("model:{src}")).or_insert_with(|| {+ let (groups, moves) = raea_core_scene::gltf_tris(&src).ok()?;+ if moves {+ return None;+ }+ let mut points = Vec::new();+ for (_, tris) in &groups {+ points.extend(tris.iter().flatten().copied());+ }+ span(points)+ })+}++/// The box round some points, None for none.+fn span<P: Into<Vec3>>(points: impl IntoIterator<Item = P>) -> Option<(Vec3, Vec3)> {+ let (mut lo, mut hi) = (Vec3::splat(f32::MAX), Vec3::splat(f32::MIN));+ for p in points {+ let p = p.into();+ lo = lo.min(p);+ hi = hi.max(p);+ }+ (lo.x <= hi.x).then_some((lo, hi))+}++/// A backdrop slab standing up, its thin side facing within 45 degrees of level: a wall, not a floor, water or a+/// ceiling. A frame of floor and fog is empty; one of a room's walls or a canyon's is not (Stay's pool room and canyon+/// read empty when every slab was backdrop: SG14).+fn standing(it: &raea_core_scene::Item, lo: Vec3, hi: Vec3) -> bool {+ let (scale, turn, _) = it.world.to_scale_rotation_translation();+ let ext = (hi - lo) * scale.abs();+ let thin = if ext.x <= ext.y && ext.x <= ext.z { Vec3::X } else if ext.y <= ext.z { Vec3::Y } else { Vec3::Z };+ (turn * thin).y.abs() < std::f32::consts::FRAC_1_SQRT_2+}+/// Each part of known size that shows in a frame: its name as the checks call it, and its box on screen, [x0, y0, x1,/// y1] in px (SG9 names the parts under a patch that differs between a frame rendered in sequence and alone).pub fn on_screen(its: &[raea_core_scene::Item], w: u32, h: u32) -> Vec<(String, [f32; 4])> {@@ -99,23 +131,36 @@ pub(crate) fn check(st: &Stage, page: &[crate::Page]) -> Vec<Finding> {let mut sure = true;let mut best: Option<(String, f32, f32, bool)> = None;for it in its {- if matches!(it.kind, "plate" | "sprite" | "shape2d" | "grass" | "splat" | "meshseq") {+ // drawn where the boxes can't say: footage, 2D, a field, a shader over the frame, a set of copies (<Instances>)+ if matches!(it.kind, "plate" | "sprite" | "shape2d" | "grass" | "splat" | "meshseq" | "frame_pass") || it.at.is_some() {sure = false;continue;}let Some((lo, hi)) = own_box(it, &mut boxes) else {// a model or other part of unknown size: judged only when its origin is well out of view- if matches!(it.kind, "model" | "entity") {+ if matches!(it.kind, "model" | "entity" | "fire") {if let Some([x, y, _]) = v.project(super::origin(it)) {if x > -0.5 * st.w && x < 1.5 * st.w && y > -0.5 * st.h && y < 1.5 * st.h {sure = false;}}}+ // its file's box fills what it shows, a floor's or terrain's left out as a slab mesh's is; across the+ // camera's plane (a room model round it: Stay's pool) it may fill the view+ let model = (it.kind == "model").then(|| model_box(it, &mut boxes)).flatten();+ if let Some((lo, hi)) = model.filter(|(lo, hi)| !backdrop(it, *lo, *hi) || standing(it, *lo, *hi)) {+ match v.bounds(corners(&it.world, lo, hi)) {+ Some(b) if v.share(b) > 0.0 => mark(&mut grid, b, st.w, st.h),+ Some(_) => {}+ None => sure &= corners(&it.world, lo, hi).into_iter().all(|p| v.project(p).is_none()),+ }+ }continue;};- // a floor or wall round the camera is backdrop before it is a part behind it- if backdrop(it, lo, hi) {+ // a floor, water or a ceiling round the camera is backdrop before it is a part behind it; a wall (a slab+ // standing up: a room's, a canyon's) is what the frame shows, so it fills the frame, but is never its subject+ let wall = backdrop(it, lo, hi) && standing(it, lo, hi);+ if backdrop(it, lo, hi) && !wall {continue;}let Some(b) = v.bounds(corners(&it.world, lo, hi)) else {@@ -128,6 +173,10 @@ pub(crate) fn check(st: &Stage, page: &[crate::Page]) -> Vec<Finding> {if inside > 0.0 {mark(&mut grid, b, st.w, st.h);}+ // a wall fills the frame but isn't its subject+ if wall {+ continue;+ }// the subject: the named part showing most, when it could fit in the frameif it.props.get("name").is_some() && inside > 0.0 && best.as_ref().is_none_or(|s| inside > s.1) {let fits = b[2] - b[0] < 0.9 * st.w && b[3] - b[1] < 0.9 * st.h;@@ -149,7 +198,7 @@ pub(crate) fn check(st: &Stage, page: &[crate::Page]) -> Vec<Finding> {if st.secs(a, b) >= EMPTY_SECS && t0 > FADE_SECS && t1 < total - FADE_SECS {let least = covered[a..=b].iter().copied().fold(1.0, f32::min);let says = format!("almost nothing is on screen from {} to {} ({:.0}% of the frame shows any part)", st.at(a), st.at(b), least * 100.0);- out.push(st.finding("frame-empty", Level::Warn, a, b, says).fix("aim the camera at what the shot is about, or bring it into the frame"));+ out.push(st.finding("frame-empty", Level::Error, a, b, says).fix("aim the camera at what the shot is about, or bring it into the frame"));}}for (a, b) in runs(st, n, |k| subject[k].as_ref().is_some_and(|(_, out, fits)| *fits && *out > CUT_LO && *out < CUT_HI)) {@@ -189,6 +238,18 @@ mod tests {assert!(!run(framed).iter().any(|f| f.check == "frame-empty"));}+ #[test]+ fn copies_or_a_shader_over_the_frame_leave_it_unjudged() {+ // the empty stretch of the test above, with a forest of copies or a frame pass in it: either may fill the frame+ let aimed = |extra: Item| (0..120).map(|i| vec![cam([0.0, 0.0, 6.0], if (30..90).contains(&i) { [0.0, 40.0, 0.0] } else { [0.0; 3] }), cube("dash", [0.0; 3]), extra.clone()]).collect::<Vec<_>>();+ let mut forest = cube("forest", [0.0, 30.0, 0.0]);+ forest.at = Some("[0,0,0, 0,0,0, 1,1,1]".into());+ assert!(!run(aimed(forest)).iter().any(|f| f.check == "frame-empty"));+ assert!(!run(aimed(item("frame_pass", json!({}), Mat4::IDENTITY))).iter().any(|f| f.check == "frame-empty"));+ let f = run(aimed(item("fog", json!({}), Mat4::IDENTITY)));+ assert!(f.iter().any(|f| f.check == "frame-empty" && f.level == Level::Error), "{f:?}");+ }+#[test]fn words_or_a_video_in_the_page_fill_the_frame() {let fs: Vec<Vec<Item>> = (0..120).map(|i| vec![cam([0.0, 0.0, 6.0], if (30..90).contains(&i) { [0.0, 40.0, 0.0] } else { [0.0; 3] }), cube("dash", [0.0; 3])]).collect();@@ -211,6 +272,41 @@ mod tests {assert!(run(fs).iter().any(|f| f.check == "frame-empty"));}+ #[test]+ fn a_rooms_wall_filling_the_frame_is_what_it_shows() {+ // the same floor and crate, and a 30 m wall standing 8 m off along the look away: the room's inside, not empty+ let mut floor = item("mesh", json!({"name": "floor"}), Mat4::from_translation(Vec3::new(0.0, -1.0, 0.0)));+ floor.shape = Some("box(100, 0.1, 100)".into());+ let mut wall = item("mesh", json!({"name": "wall"}), Mat4::from_translation(Vec3::new(8.0, 3.0, 6.0)));+ wall.shape = Some("box(0.2, 10, 30)".into());+ let mut crate_ = cube("crate", [-5.0, 0.0, 0.0]);+ crate_.shape = Some("box(4, 4, 4)".into());+ let fs: Vec<Vec<Item>> = (0..120).map(|i| vec![cam([0.0, 1.0, 6.0], if (30..90).contains(&i) { [40.0, 1.0, 6.0] } else { [-5.0, 0.0, 0.0] }), floor.clone(), wall.clone(), crate_.clone()]).collect();+ let f = run(fs);+ assert!(!f.iter().any(|f| f.check == "frame-empty"), "{f:?}");+ // a wall is never the shot's subject: looking at it alone cuts nothing+ assert!(!f.iter().any(|f| f.check == "subject-cut" && f.says.contains("wall")), "{f:?}");+ }++ #[test]+ fn a_model_filling_the_frame_is_sized_from_its_file() {+ // a cabinet scaled 20x (25 m wide, 18 m tall), the camera 6 m off its face near the top: its origin (its base)+ // is far below the frame, so before its file was read the frame was judged empty+ let cabinet = |src: &str| item("model", json!({"name": "cabinet", "src": src}), Mat4::from_scale(Vec3::splat(20.0)));+ // the middle two seconds of four; before and after, the camera turns round to a 6 m crate behind it+ let mut crate_ = cube("crate", [0.0, 16.0, 25.0]);+ crate_.shape = Some("box(6, 6, 6)".into());+ let look = |i: usize| if (30..90).contains(&i) { [0.0, 16.0, 0.0] } else { [0.0, 16.0, 25.0] };+ let shot = |src: &str| (0..120).map(|i| vec![cam([0.0, 16.0, 15.0], look(i)), cabinet(src), crate_.clone()]).collect::<Vec<_>>();+ let f = run(shot("../../sdk/react/bench/games/room3d/media/cabinet.glb"));+ assert!(!f.iter().any(|f| f.check == "frame-empty"), "{f:?}");+ assert!(run(shot("../../sdk/react/bench/games/room3d/media/no-such.glb")).iter().any(|f| f.check == "frame-empty"));+ // the camera inside it (a room model round the camera), looking away from its origin: not an empty frame+ let inside = |src: &str| (0..120).map(|i| vec![cam([0.0, 9.0, 4.0], if (30..90).contains(&i) { [0.0, 9.0, 9.0] } else { [0.0, 16.0, 25.0] }), cabinet(src), crate_.clone()]).collect::<Vec<_>>();+ let f = run(inside("../../sdk/react/bench/games/room3d/media/cabinet.glb"));+ assert!(!f.iter().any(|f| f.check == "frame-empty"), "{f:?}");+ }+#[test]fn parts_on_screen_are_named_with_their_boxes() {let its = vec![cam([0.0, 0.0, 6.0], [0.0; 3]), cube("dash", [0.0; 3]), cube("gone", [0.0, 0.0, 20.0])];diff --git a/systems/stage/src/manifest.rs b/systems/stage/src/manifest.rsindex 6cbb9791..180168d8 100644--- a/systems/stage/src/manifest.rs+++ b/systems/stage/src/manifest.rs@@ -14,8 +14,11 @@ const STILLS: usize = 16;const REMOUNT: usize = 20;/// What each frame (`nums`) of the manifest's frames draws in its page: its words (what they say, their ink's box,-/// whether they may sit on a part), its videos' boxes and its pictures', the nearly invisible left out.-pub fn pages(frames: &[Value], nums: &[i64]) -> Vec<Page> {+/// whether they may sit on a part), its videos' boxes and its pictures', the nearly invisible left out, and a CSS+/// background (a colour or a gradient) over half the w x h frame or more: the page's ground, under the 3D or alone, not+/// something shown (an <img> or an svg is). The film's blank cream frame at 6:04 read as full while its background+/// counted (SG14).+pub fn pages(frames: &[Value], nums: &[i64], w: u32, h: u32) -> Vec<Page> {let by: HashMap<i64, &Value> = frames.iter().filter_map(|e| Some((e["frame"].as_i64()?, e))).collect();// an entry's box as [x0, y0, x1, y1], when it showslet shown = |e: &Value, key: &str| {@@ -34,7 +37,7 @@ pub fn pages(frames: &[Value], nums: &[i64]) -> Vec<Page> {.map(|f| Page {words: list(by.get(f), "text").filter_map(words).collect(),videos: list(by.get(f), "videos").filter_map(|v| shown(v, "box")).collect(),- pictures: list(by.get(f), "pictures").filter_map(|v| shown(v, "box")).collect(),+ pictures: list(by.get(f), "pictures").filter_map(|v| shown(v, "box").filter(|b| !matches!(v["kind"].as_str(), Some("fill" | "background")) || (b[2] - b[0]) * (b[3] - b[1]) < 0.5 * (w * h) as f32)).collect(),}).collect()}@@ -87,11 +90,25 @@ mod tests {{"text": "faded", "box": [0, 50, 400, 40], "opacity": 0.05},{"text": "on it", "box": [0, 100, 400, 40], "allowOverlap": true}], "videos": [{"box": [0, 0, 1920, 1080], "opacity": 1.0}], "pictures": [{"box": [5, 5, 10, 10]}]})];- let p = super::pages(&frames, &[7, 8]);+ let p = super::pages(&frames, &[7, 8], 1920, 1080);assert_eq!(p.len(), 2);assert_eq!(p[0].words.len(), 2, "{:?}", p[0].words);assert_eq!((p[0].words[0].bx, p[0].words[1].allow_overlap), ([10.0, 0.0, 110.0, 40.0], true));assert_eq!((p[0].videos.len(), p[0].pictures[0]), (1, [5.0, 5.0, 15.0, 15.0]));assert!(p[1].words.is_empty() && p[1].videos.is_empty());}++ #[test]+ fn the_pages_background_fill_is_ground_not_shown() {+ // the film's 6:04: its cream background, twice, full frame, and a gradient; a lower third's bar and a photo stay+ let frames = vec![json!({"frame": 1, "pictures": [+ {"kind": "fill", "box": [0, 0, 1920, 1080], "opacity": 1.0},+ {"kind": "fill", "box": [0, 0, 1920, 1080], "opacity": 1.0},+ {"kind": "fill", "box": [52, 862, 645, 44], "opacity": 1.0},+ {"kind": "background", "box": [0, 0, 1920, 1080], "opacity": 1.0},+ {"kind": "img", "box": [0, 0, 1920, 1080], "opacity": 1.0}+ ]})];+ let p = super::pages(&frames, &[1], 1920, 1080);+ assert_eq!(p[0].pictures, vec![[52.0, 862.0, 697.0, 906.0], [0.0, 0.0, 1920.0, 1080.0]]);+ }}