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
SG11: page words over a 3D part are an error; SG4a: a long film renders whole with its end checks
shinyobjectz35ce4cfdb378
diff --git a/docs/manual/reference/cli/render.md b/docs/manual/reference/cli/render.mdindex 5771261e..822d4efd 100644--- a/docs/manual/reference/cli/render.md+++ b/docs/manual/reference/cli/render.md@@ -42,8 +42,8 @@ size, each video's source and time), the sounds heard and what the render found.[`raea world`](world.md), which measures the output against it when a check asks.A render checks what it draws: 3D parts passing into each other (the clipping check), how its 3D is staged (3D type-too small or turned to read, parts that snap, a camera that lurches, frames with almost nothing on screen; `raea scene-stage` runs these without drawing) and its pictures' exposure (clipping to white, crushing to black). A video with 3D+too small or turned to read, page type over a part, parts that snap, a camera that lurches, frames with almost nothing+on screen; `raea scene stage` runs these without drawing, all but the page's) and its pictures' exposure (clipping to white, crushing to black). A video with 3Din it, longer than 60 frames, is also checked for frame purity: every 300th frame, its last, and the frame after eachchange of more than 20 parts are rendered again on their own and held to the video's. A patch that differs is an errornaming the frame and the parts under it, with both pictures kept beside the video (`OUT.frame-pure/`), since a partdiff --git a/docs/stage-guards.feature b/docs/stage-guards.featureindex a37f2d2b..ceb8d0a0 100644--- a/docs/stage-guards.feature+++ b/docs/stage-guards.feature@@ -152,8 +152,28 @@ Feature: Stage guards: a 3D render an agent can't break# already gone, despawned with another part it hung from"); the store test covers it.Scenario: SG4a. A long render's memory stays flat+ Given the plan+ | crate | file | lines | job |+ | raea-runtime-export | runtime/export/src/program.rs | +5 | program_of: a frame's program with its 3D left out, for the sound alone |+ | raea-runtime-export | runtime/export/src/fed.rs | +22 | a live render's sound step leaves the 3D out; stills_live, one look at the wanted frames with frames_hold_3d |+ | raea-runtime-export | runtime/export/src/render.rs | +12 | a still past frame 3,600 made live (LIVE_PAST); stills keep their scenes for the end checks |+ | raea-sys-stage | systems/stage/src/manifest.rs | +8 | the remounts counted as the frames go, not all at once |+ | raea-core-scene | core/scene/src/lib.rs | +30 | spans_of: each part over the frames it's in; tracks_of built on it |+ | raea-sys-contact | systems/contact/src/lib.rs | 0 | the clipping check over spans |Then a 13,000-frame 3D render's memory stays within 10% of its first minute's- # Status 11-21: not measured yet (SG4's leak fixed; the bar is the proof).+ # Status 11-21 (branch stage-guards-8): the film (13,175 frames, 7:19) renders whole with every end check on, at+ # a 9.4 to 13.6 GB peak. Before, memguard killed it past 24 GB (28 to 33 GB) after its last frame. Four causes,+ # each measured: the sound step at a live render's end built the 3D's rows again from every frame's kept scene+ # (28 GB; it takes the sound's rows alone now); the clipping check held a slot for every part on every frame+ # (each part over the frames it's in now); the remounts' counts were all kept at once (counted as they go now);+ # and SG9's 64 stills, reached by rows, built a scene for every frame up to each (over 30 GB, killed). A still+ # past frame 3,600 makes its 3D live now, as a game's does, unless a compute in it carries state from frame to+ # frame: raea check --quick on the film went from 10.4 GB and 39 s to 0.8 GB and 9 s. Live stills at frames 300,+ # 6000 and 13000 match the film's frames exactly, and the two routes' stills at 3293, 6587 and 13174 match each+ # other in pixels and findings, since a still's end checks now run on its kept scene once its page is laid+ # out, on either route (the live route ran none before: a game's stills were never staged). Not met: memory+ # still grows with the frames (about 2 GB at the first minute, 5.7 GB at the last frame), because each frame's+ # scene is kept for the end checks. Flat needs the checks to run over a window as the frames come.Rule: The SDK stops allowing it@@ -256,12 +276,14 @@ Feature: Stage guards: a 3D render an agent can't break# frame-pure, so both routes hand the engine the same props: what differs is the engine's state, and the# error names the parts instead). RAEA_FRAME_PURE=0 skips it. Measured before building, alone (`--frame N`)# against the sequence on four real scenes of 91-180 frames: three match exactly (SSIM 1.0); one under Solari- # GI differs in SSIM (0.97-0.99, the GI's history) with no patch past the bar after frame 0.+ # GI differs in SSIM (0.97-0.99, the GI's history) with no patch past the bar after frame 0. On the whole film+ # (13,175 frames), its 64 stills past frame 3,600 made live (SG4a): none differs. The positive control is still+ # caught and six real scenes are clean on that route.Given the plan| crate | file | lines | job |- | raea-app-direction | apps/direction/src/pure.rs | 230 | the sample, the stills and the alone frame, the patch, the parts under it, the findings |+ | raea-app-direction | apps/direction/src/pure.rs | 234 | the sample, the stills and the alone frame, the patch, the parts under it, the findings || raea-app-direction | apps/direction/src/rendered.rs | +2 | a video render's end runs it beside the text rules |- | raea-runtime-export | runtime/export/src/scene.rs | +40 | the manifest's `parts` (stills) and `remounts` (longer renders) |+ | raea-sys-stage | systems/stage/src/manifest.rs | +40 | the manifest's `parts` (stills) and `remounts` (longer renders) || raea-runtime-export | runtime/export/src/lib.rs | +4 | write_manifest takes them || raea-sys-stage | systems/stage/src/framing.rs | +12 | on_screen: each part's box on screen, named |@@ -298,9 +320,26 @@ Feature: Stage guards: a 3D render an agent can't break# front of the words.Scenario: SG11. 2D type stays off the parts+ Given the plan+ | crate | file | lines | job |+ | raea-sys-stage | systems/stage/src/page.rs | 157 | each run of page words over a part's box on screen past 10%, the parts under them named |+ | raea-sys-stage | systems/stage/src/manifest.rs | 97 | each frame's page (words, videos, pictures) read from the manifest's frames; the parts and remounts written into it (moved from raea-runtime-export, at its 2,000 lines) |+ | raea-sys-stage | systems/stage/src/lib.rs | +14 | check_with and told take each frame's page |+ | raea-sys-stage | systems/stage/src/framing.rs | +16 | the backdrop rule shared; the page's words and videos fill the frame (SG14) |+ | raea-runtime-export | runtime/export/src/run.rs | +5 | a still's end checks wait for its page |Then a page text box that covers more than 10% of a 3D part's projected box is an error, unless one of them saysallowOverlapAnd on the film this flags the words over the curves at 2:08 and the headline on the AppLovin card at 6:40+ # Status 11-21 (branch stage-guards-8): page.rs. Words in the page (the manifest's text: its ink's box, opacity+ # 0.1 or more) over more than 10% of a 3D part's box on screen (inside the frame), for a quarter second or more+ # or on a still alone, are a `type-over-part` error: one for each run of the words, naming the parts under them+ # with their shares. A backdrop (framing's slab rule) and a part with allowOverlap are left out. On the film,+ # 31 errors: the caption over the curves from 2:08.02 to 2:16.04 (16 parts: the week's label at 53%, the curves+ # at 28%), the words over the brand cards from 6:33 to 6:37 (the first card at 61%) and 'social winners often+ # don't' over the hero and the network's logo from 6:38 to 6:41. Some are words over a wall of small parts (54 ad tiles+ # under '185 ads · 11 games' at 5:01, a chart's points at 1:03), which the rule as written counts: a wall of+ # tiles isn't a backdrop by the slab rule. Left: page text can't say allowOverlap (the manifest has a text's+ # words and box, not its props), and `raea scene stage` doesn't know the page, since it draws none.Scenario: SG12. Nothing snapsGiven the plan@@ -349,7 +388,10 @@ Feature: Stage guards: a 3D render an agent can't break# Status 11-21 (branch stage-guards-6): framing.rs says both, as warnings for now: the page's own 2D (a headline# over an empty 3D) isn't known to them until SG11. Coverage leaves out a slab over 12 m (a floor, a wall: a frame# of floor and fog is empty), and a part wholly behind the camera. On film2: empty frames at 1:59, 3:07 and 3:41- # (the notes' 3:40), and 21 subject cuts. Left: errors once SG11 knows the page, and the subject a Label points at.+ # (the notes' 3:40), and 21 subject cuts. Branch stage-guards-8: the page's words and videos fill the frame too+ # (the manifest's, as SG11 reads them), so a headline over an empty 3D isn't an empty frame. Still warnings: the+ # page's pictures (img, svg, a CSS background) aren't in the manifest, so one over an empty 3D would be a false+ # error. Left: those pictures in the manifest, then errors; the subject a Label points at.@doneScenario: SG15. A broken render can't be posteddiff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rsindex 52a61d5b..528e0343 100644--- a/runtime/export/src/fed.rs+++ b/runtime/export/src/fed.rs@@ -23,22 +23,37 @@ pub(crate) struct FrameLog {/// Whether any of `frames` shows 3D: each rendered on its own in one runtime (frames are pure, so a frame stepped/// alone is the frame a whole pass would have stepped), stopping at the first that does.pub(crate) fn frames_hold_3d(js: &Path, dir: &Path, frames: &[i64]) -> R<bool> {+ Ok(looked(js, dir, frames, true)?.0)+}++/// Whether stills at `frames` can make their 3D live, at each still (SG4a): one of them holds 3D, and none holds a+/// compute that carries GPU state from frame to frame (its rows step every frame before the still instead).+pub(crate) fn stills_live(js: &Path, dir: &Path, frames: &[i64]) -> R<bool> {+ let (held, carries) = looked(js, dir, frames, false)?;+ Ok(held && !carries)+}++/// Each of `frames` stepped alone: whether one holds 3D and whether one holds a compute that carries state (`first`:+/// done at the first that holds 3D).+fn looked(js: &Path, dir: &Path, frames: &[i64], first: bool) -> R<(bool, bool)> {edit_dir(dir);let mut app = App::new();app.add_plugins(MinimalPlugins).add_plugins(ReactPlugin::new(js.to_path_buf()));app.insert_resource(raea_runtime_react::OneBatch::default());settle(&mut app, Some(-1), 20.0)?.ok_or("the composition's settings didn't arrive")?;- let mut held = false;+ let (mut held, mut carries) = (false, false);for &f in frames {raea_runtime_bake::step_frames(&mut app, f, f + 1, |app, _| {- held |= !scene_of(app.world_mut()).is_empty();+ let scene = scene_of(app.world_mut());+ held |= !scene.is_empty();+ carries |= raea_runtime_scene::carries_state(&scene);Ok(())})?;- if held {+ if held && first {break;}}- Ok(held)+ Ok((held, carries))}/// The frames `scene_program_to` reads its rows from, with the composition's size and rate. Stepped as a bake steps@@ -276,7 +291,8 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, totOk(page.clone())},|| {- let p = program(&frames.borrow(), w, h, fps);+ // its sound's rows alone: the 3D was drawn as the frames came (SG4a)+ let p = program_of(&frames.borrow(), w, h, fps, false);sound_lint(&p, fps);let st = streamer.borrow_mut().take().ok_or("the sound was asked for twice")?;let t_bounce = std::time::Instant::now();@@ -310,7 +326,7 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, totlet n = frames.borrow().len();// 3D parts passing through each other on screen: on stderr, and in the manifest for the legacy app's checkslet found = FED_CLIPPING.lock().unwrap().take().and_then(|t| t.join().ok());- let clipping = found.unwrap_or_else(|| scene::told(&frames.borrow(), w, h, fps));+ let clipping = found.unwrap_or_else(|| scene::told(&frames.borrow(), cx.manifest.as_deref(), w, h, fps));write_manifest(cx, (w, h, fps, total), clipping, |cx| heard(&frames.borrow(), ¬es.borrow(), cx, fps))?;let ms = t0.elapsed().as_secs_f64() * 1e3 / n.max(1) as f64;Ok(format!("APPLIED {n} frames rendered to {} ({ms:.1} ms a frame, pages handed to raea-render on the GPU)", out.display()))diff --git a/runtime/export/src/program.rs b/runtime/export/src/program.rsindex 640e3c8d..56319e0b 100644--- a/runtime/export/src/program.rs+++ b/runtime/export/src/program.rs@@ -6,6 +6,14 @@ use super::*;/// TypeScript-only editing, phase 5: raea-render's IR is the contract; rrl the language, which this once went through, is/// retired). A column that changes frame by frame is keyed (linear) and its row holds the first frame's value.pub(crate) fn program(frames: &[(i64, Frame)], w: u32, h: u32, fps: f64) -> raea_core_program::ir::Program {+ let has3d = frames.iter().any(|(_, f)| !f.scene.is_empty());+ program_of(frames, w, h, fps, has3d)+}++/// program, its 3D's rows made only when `has3d`: false for a step that reads only its sound (the sound lint at a+/// live render's end). That render drew its 3D as the frames came; building the 3D's rows again from every+/// frame's kept scene asked for 28 GB at the end of a 13,175-frame film and got it killed (stage-guards SG4a).+pub(crate) fn program_of(frames: &[(i64, Frame)], w: u32, h: u32, fps: f64, has3d: bool) -> raea_core_program::ir::Program {use raea_core_program::ir::V;let mut p = raea_core_program::ir::Program { fps, width: w, height: h, frames: frames.len() as i64, ..Default::default() };let row = |id: &str, cols: Vec<(&str, V)>| -> BTreeMap<String, V> {@@ -14,7 +22,6 @@ pub(crate) fn program(frames: &[(i64, Frame)], w: u32, h: u32, fps: f64) -> raear};// --alpha: nothing under the pages, so what the composition leaves empty stays transparent- let has3d = frames.iter().any(|(_, f)| !f.scene.is_empty());// with no holder background: black under 2D pages, and for 3D no `bg`, so the camera clears to Bevy's ClearColor// resource (srgb 43, 44, 47 unless a <BevyResource type="bevy_camera::clear_color::ClearColor"> sets it), as a Bevy// scene does (docs/control conventions C17)diff --git a/runtime/export/src/render.rs b/runtime/export/src/render.rsindex 2cde0f04..6bb11b4b 100644--- a/runtime/export/src/render.rs+++ b/runtime/export/src/render.rs@@ -190,6 +190,9 @@ fn with_exposure(said: String, out: &Path, manifest: Option<&Path>) -> String {}}+/// A still past this frame takes the live route (render_bundle): the rows to reach it would hold that many scenes.+const LIVE_PAST: i64 = 3600;+/// A bundled composition rendered by the engine, in this process (the Mac or the iPhone): React on JavaScriptCore inside Bevy steps/// its Clock; each frame's page goes through Blitz, its <Video> decoded natively, its 3D as rows; the frames become one/// raea-render program drawn by raea-render into `out` (.mp4, .png for one frame, a folder of PNGs). `dir` is where relative media resolves. `wanted`: the frames (all when None).@@ -208,6 +211,13 @@ pub fn render_bundle(js: &Path, dir: &Path, out: &Path, wanted: Option<Vec<i64>>}if stills && how != "files" {let upto = wanted.as_ref().and_then(|w| w.iter().max()).map_or(0, |f| f + 1);+ // a still far into a 3D piece: its 3D made live at the still, as a game's is. The rows made beforehand hold a+ // scene for every frame up to it: raea check --quick's three stills of a 13,175-frame film took 10.4 GB that+ // way and 0.8 GB live, the same pixels as the film's (SG4a)+ if how != "program" && upto > LIVE_PAST && raea_runtime_view::gpuview::paint_device().is_some() && wanted.as_deref().is_some_and(|w| crate::fed::stills_live(js, dir, w).unwrap_or(false)) {+ raea_runtime_react::startup_mark("stills past the rows' reach: the 3D made live at each");+ return render_bundle_with(js, dir, out, wanted, false, None, true);+ }if let Some(scene) = scene_program_checked(js, dir, upto, wanted.as_deref())? {return render_bundle_with(js, dir, out, wanted, false, Some(scene), false);}@@ -311,11 +321,14 @@ pub(crate) fn render_bundle_with(js: &Path, dir: &Path, out: &Path, wanted: Optiif folder {std::fs::create_dir_all(out).map_err(|e| format!("{}: {e}", out.display()))?;}+ // each still's scene, for the end checks once the page is known (made live or from rows alike)+ let mut kept: Vec<(i64, Frame)> = Vec::new();for (i, &f) in wanted.iter().enumerate() {let px = raea_gpu_device::check::frame_caught(f, || { // a panic drawing it an error naming it (#33)engine_before(&app, &mut cx, f);app.world().resource::<ReactOutbox>().send(json!({"t": "event", "name": "raea-frame", "value": f}));settle_with(&mut app, Some(f), 20.0, &mut |w, q| layout_answer(w, pg, &mut cx, f, fps, q))?;+ kept.push((f, Frame { screens: Vec::new(), mix: None, page: None, sounds: Vec::new(), scene: scene_of(app.world_mut()), clear: None, same: false }));cx.now = f;pg.at_frame(f, fps);let mut px = bevy_over_3d(app.world_mut(), pg, &mut cx, fps)?;@@ -338,7 +351,8 @@ pub(crate) fn render_bundle_with(js: &Path, dir: &Path, out: &Path, wanted: Optiif folder { write_aov(out, i, cx.scene3d.as_mut())?; }}// with --manifest, its file as a 2D render writes it (it wrote none, and an older one stayed looking current, #28)- let clipping = FED_CLIPPING.lock().unwrap().take().and_then(|t| t.join().ok()).unwrap_or_default();+ drop(FED_CLIPPING.lock().unwrap().take());+ let clipping = scene::told(&kept, cx.manifest.as_deref(), w, h, fps);write_manifest(&mut cx, (w, h, fps, total), clipping, |_| json!([]))?;return Ok(if folder {format!("APPLIED {} frames rendered to {} (bevy_ui, the page over its 3D)", wanted.len(), out.display())@@ -393,7 +407,7 @@ pub(crate) fn render_bundle_with(js: &Path, dir: &Path, out: &Path, wanted: Optilet react_ms = t0.elapsed().as_secs_f64() * 1e3 / wanted.len().max(1) as f64;drop(app);// 3D parts passing through each other on screen: on stderr, and in the manifest for the legacy app's checks- let clipping = scene::told(&frames, w, h, fps);+ let clipping = scene::told(&frames, cx.manifest.as_deref(), w, h, fps);write_manifest(&mut cx, (w, h, fps, total), clipping, |cx| heard(&frames, &tones, cx, fps))?;let ext = out_ext(out);diff --git a/runtime/export/src/run.rs b/runtime/export/src/run.rsindex ec26f1de..2ddfc1ec 100644--- a/runtime/export/src/run.rs+++ b/runtime/export/src/run.rs@@ -97,6 +97,11 @@ pub(crate) fn scene_program_checked(js: &Path, dir: &Path, upto: i64, wanted: OpSome(w) => frames.into_iter().filter(|(f, _)| w.contains(f)).collect(),None => frames,};+ // stills: their end checks run once their page is laid out (render_bundle_with keeps each still's scene), so+ // the page's words are known to them (SG11)+ if wanted.is_some_and(|w| !w.is_empty()) {+ return Ok(Some(p));+ }// the clipping check on a thread of its own while the engine opens and the frames render (3 s over the Rome// film's 8,064 frames, which the render waited for before its engine opened); the render joins it at its endstruct Prepassed(Vec<(i64, Frame)>);@@ -106,7 +111,7 @@ pub(crate) fn scene_program_checked(js: &Path, dir: &Path, upto: i64, wanted: Oplet owned = Prepassed(frames);*FED_CLIPPING.lock().unwrap() = Some(std::thread::spawn(move || {let o = owned;- scene::told(&o.0, w, h, fps)+ scene::told(&o.0, None, w, h, fps)}));Ok(Some(p))}diff --git a/runtime/export/src/scene.rs b/runtime/export/src/scene.rsindex 1e6b59aa..5e1858e3 100644--- a/runtime/export/src/scene.rs+++ b/runtime/export/src/scene.rs@@ -15,55 +15,23 @@ pub fn all_items(frames: &[(i64, Frame)]) -> Vec<Vec<raea_core_scene::Item>> {}/// raea_sys_contact::told on a render's frames, the parts that clip where the camera sees them (RAEA_CLIP_CHECK=0 skips-/// it), and raea_sys_stage::told, the staging (RAEA_STAGE_CHECK=0), each said on stderr.-pub(crate) fn told(frames: &[(i64, Frame)], w: u32, h: u32, fps: f64) -> Vec<raea_core_facts::Finding> {+/// it), and raea_sys_stage::told, the staging (RAEA_STAGE_CHECK=0), each said on stderr. `page` is the manifest's+/// frames (each one's words in the page, which the staging holds off the parts: SG11), None where they aren't known.+pub(crate) fn told(frames: &[(i64, Frame)], page: Option<&[serde_json::Value]>, w: u32, h: u32, fps: f64) -> Vec<raea_core_facts::Finding> {if frames.iter().all(|(_, f)| f.scene.is_empty()) {return Vec::new();}let (nums, all): (Vec<i64>, _) = (frames.iter().map(|(f, _)| *f).collect(), all_items(frames));- *SEEN.lock().unwrap() = seen(&all, &nums, w, h);+ *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) };- found.extend(raea_sys_stage::told(&all, &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, fps));found}-/// A render of at most this many frames is stills (`--frame`, `--at`): its manifest names each frame's parts on screen-const STILLS: usize = 16;-/// More than this many parts mounting or unmounting between two frames is a remount-const REMOUNT: usize = 20;--/// What the manifest says of a render's parts (render.rs's write_manifest takes it): for stills, each frame's parts on-/// screen and their boxes (`parts`); for a longer render, the frames where more than REMOUNT parts mount or unmount-/// (`remounts`). SG9 re-renders the frame after each remount alone and names the parts under a patch that differs.+/// What the manifest says of a render's parts (raea_sys_stage::seen; write_manifest takes it): for stills each+/// frame's parts on screen, for a longer render where they remount.pub(crate) static SEEN: std::sync::Mutex<Option<serde_json::Value>> = std::sync::Mutex::new(None);-fn seen(all: &[Vec<raea_core_scene::Item>], nums: &[i64], w: u32, h: u32) -> Option<serde_json::Value> {- if all.len() <= STILLS {- let parts: Vec<_> = all.iter().zip(nums).map(|(its, f)| serde_json::json!({"frame": f, "parts": raea_sys_stage::on_screen(its, w, h)})).collect();- return Some(serde_json::json!({"parts": parts}));- }- let counts: Vec<_> = all.iter().map(|its| counted(its)).collect();- let remounts: Vec<i64> = (1..counts.len()).filter(|&k| changed(&counts[k], &counts[k - 1]) > REMOUNT).map(|k| nums[k]).collect();- Some(serde_json::json!({"remounts": remounts}))-}--type Counted<'a> = std::collections::HashMap<(&'a str, &'a str, u64), i64>;--/// A frame's parts as a count by what they are: kind, name, what they draw.-fn counted(its: &[raea_core_scene::Item]) -> Counted<'_> {- let mut m = Counted::new();- for it in its {- *m.entry((it.kind, raea_core_scene::base_ident(it), raea_core_scene::spawn_sig(it))).or_default() += 1;- }- m-}--/// How many parts mount or unmount from one frame's count to the next's.-fn changed(a: &Counted, b: &Counted) -> usize {- let off = |x: &Counted, y: &Counted| x.iter().map(|(k, n)| (n - y.get(k).copied().unwrap_or(0)).max(0) as usize).sum::<usize>();- off(a, b) + off(b, a)-}-/// `--frame N`, 0 when it isn't given (scene lint and render --review).pub fn frame_of(args: &[String]) -> Result<i64, String> {match flag(args, "--frame") {diff --git a/systems/stage/src/framing.rs b/systems/stage/src/framing.rsindex e8b2395d..3ef7846c 100644--- a/systems/stage/src/framing.rs+++ b/systems/stage/src/framing.rs@@ -28,7 +28,7 @@ const GX: usize = 48;const GY: usize = 27;/// A part's box in its own space: a shape's, a block of words' (estimated), a picture's; None when it isn't known.-fn own_box(it: &raea_core_scene::Item, boxes: &mut HashMap<String, Option<(Vec3, Vec3)>>) -> Option<(Vec3, Vec3)> {+pub(crate) fn own_box(it: &raea_core_scene::Item, boxes: &mut HashMap<String, Option<(Vec3, Vec3)>>) -> Option<(Vec3, Vec3)> {match it.kind {"mesh" => {let shape = it.shape.as_deref()?;@@ -55,6 +55,13 @@ fn own_box(it: &raea_core_scene::Item, boxes: &mut HashMap<String, Option<(Vec3,}}+/// A slab wider than BACKDROP_M in the world, its thinnest side under SLAB of its widest: a floor, a set's wall, a sky+/// plane, the backdrop a frame's parts stand in front of, not one of them.+pub(crate) fn backdrop(it: &raea_core_scene::Item, lo: Vec3, hi: Vec3) -> bool {+ let ext = (hi - lo) * it.world.to_scale_rotation_translation().0.abs();+ ext.max_element() > BACKDROP_M && ext.min_element() < SLAB * ext.max_element()+}+/// 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])> {@@ -67,7 +74,18 @@ pub fn on_screen(its: &[raea_core_scene::Item], w: u32, h: u32) -> Vec<(String,its.iter().filter_map(|it| Some((called(it), seen(it, &mut boxes)?))).collect()}-pub(crate) fn check(st: &Stage) -> Vec<Finding> {+/// The coverage grid's cells under a box on screen ([x0, y0, x1, y1] px, clipped to the w x h frame), set.+fn mark(grid: &mut [bool], b: [f32; 4], w: f32, h: f32) {+ let (x0, y0) = ((b[0].max(0.0) / w * GX as f32) as usize, (b[1].max(0.0) / h * GY as f32) as usize);+ let (x1, y1) = (((b[2].min(w) / w * GX as f32).ceil() as usize).min(GX), ((b[3].min(h) / h * GY as f32).ceil() as usize).min(GY));+ for y in y0..y1 {+ for x in x0..x1 {+ grid[y * GX + x] = true;+ }+ }+}++pub(crate) fn check(st: &Stage, page: &[crate::Page]) -> Vec<Finding> {let n = st.all.len();let mut boxes = HashMap::new();// each frame: the share covered, whether it can be judged (no part of unknown size in view, no footage or 2D@@ -97,8 +115,7 @@ pub(crate) fn check(st: &Stage) -> Vec<Finding> {continue;};// a floor or wall round the camera is backdrop before it is a part behind it- let ext = (hi - lo) * it.world.to_scale_rotation_translation().0.abs();- if ext.max_element() > BACKDROP_M && ext.min_element() < SLAB * ext.max_element() {+ if backdrop(it, lo, hi) {continue;}let Some(b) = v.bounds(corners(&it.world, lo, hi)) else {@@ -109,13 +126,7 @@ pub(crate) fn check(st: &Stage) -> Vec<Finding> {let inside = v.share(b);let whole = ((b[2] - b[0]) * (b[3] - b[1]) / (st.w * st.h)).max(1e-9);if inside > 0.0 {- let (x0, y0) = ((b[0].max(0.0) / st.w * GX as f32) as usize, (b[1].max(0.0) / st.h * GY as f32) as usize);- let (x1, y1) = (((b[2].min(st.w) / st.w * GX as f32).ceil() as usize).min(GX), ((b[3].min(st.h) / st.h * GY as f32).ceil() as usize).min(GY));- for y in y0..y1 {- for x in x0..x1 {- grid[y * GX + x] = true;- }- }+ mark(&mut grid, b, st.w, st.h);}// 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) {@@ -123,6 +134,10 @@ pub(crate) fn check(st: &Stage) -> Vec<Finding> {best = Some((called(it), inside, 1.0 - inside / whole, fits && scale_of(it) > 0.0));}}+ // the page's words and videos fill the frame too: a headline over an empty 3D isn't an empty frame+ for b in page.get(k).into_iter().flat_map(|p| p.words.iter().map(|w| w.bx).chain(p.videos.iter().copied()).chain(p.pictures.iter().copied())) {+ mark(&mut grid, b, st.w, st.h);+ }covered[k] = grid.iter().filter(|c| **c).count() as f32 / (GX * GY) as f32;judged[k] = sure;subject[k] = best.map(|(name, _, out, fits)| (name, out, fits));@@ -174,6 +189,17 @@ mod tests {assert!(!run(framed).iter().any(|f| f.check == "frame-empty"));}+ #[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();+ let n: Vec<i64> = (0..120).collect();+ let headline = crate::Page { words: vec![crate::Words { text: "The rule".into(), bx: [360.0, 380.0, 1560.0, 700.0], allow_overlap: false }], videos: Vec::new(), pictures: Vec::new() };+ let f = crate::check_with(&fs, &n, &vec![headline; 120], 1920, 1080, 30.0, "test");+ assert!(!f.iter().any(|f| f.check == "frame-empty"), "{f:?}");+ let clip = crate::Page { words: Vec::new(), videos: Vec::new(), pictures: vec![[656.0, 0.0, 1264.0, 1080.0]] };+ assert!(!crate::check_with(&fs, &n, &vec![clip; 120], 1920, 1080, 30.0, "test").iter().any(|f| f.check == "frame-empty"));+ }+#[test]fn a_floor_filling_the_frame_is_no_content() {let mut floor = item("mesh", json!({"name": "floor"}), Mat4::from_translation(Vec3::new(0.0, -1.0, 0.0)));diff --git a/systems/stage/src/lib.rs b/systems/stage/src/lib.rsindex 5ef7288b..4d392823 100644--- a/systems/stage/src/lib.rs+++ b/systems/stage/src/lib.rs@@ -10,22 +10,27 @@ use raea_core_scene::{Item, base_ident};use serde_json::Value;mod framing;+mod manifest;mod motion;+mod page;mod text;mod view;pub use framing::on_screen;+pub use manifest::{pages, seen};+pub use page::{Page, Words};pub use view::View;/// Who says these findings, in a render.pub const BY: &str = "raea render";-/// The checks on a render's frames, said on stderr and kept with its findings (RAEA_STAGE_CHECK=0 skips them).-pub fn told(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec<Finding> {+/// The checks on a render's frames, said on stderr and kept with its findings (RAEA_STAGE_CHECK=0 skips them). `page` is+/// what each frame's page draws over its 3D (SG11, SG14), none when it isn't known.+pub fn told(all: &[Vec<Item>], frames: &[i64], page: &[Page], w: u32, h: u32, fps: f64) -> Vec<Finding> {if std::env::var("RAEA_STAGE_CHECK").as_deref() == Ok("0") || all.iter().all(|its| its.is_empty()) {return Vec::new();}let t = std::time::Instant::now();- let found = check(all, frames, w, h, fps, BY);+ let found = check_with(all, frames, page, w, h, fps, BY);for f in &found {eprintln!("raea: {}", f.line());}@@ -38,11 +43,18 @@ pub fn told(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec</// Every stage check on the frames (`all[k]` is frame `frames[k]`'s parts), worst first.pub fn check(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64, by: &str) -> Vec<Finding> {+ check_with(all, frames, &[], w, h, fps, by)+}++/// check, with what each frame's page draws (`page[k]`, frame `frames[k]`'s): its words held off the parts (SG11),+/// and its words and videos filling the frame (SG14).+pub fn check_with(all: &[Vec<Item>], frames: &[i64], page: &[Page], w: u32, h: u32, fps: f64, by: &str) -> Vec<Finding> {let st = Stage::new(all, frames, w, h, fps, by);let mut out = text::check(&st);out.extend(motion::camera(&st));out.extend(motion::snaps(&st));- out.extend(framing::check(&st));+ out.extend(framing::check(&st, page));+ out.extend(page::check(&st, page));raea_core_facts::finding::ranked(merged(out))}diff --git a/systems/stage/src/manifest.rs b/systems/stage/src/manifest.rsnew file mode 100644index 00000000..6cbb9791--- /dev/null+++ b/systems/stage/src/manifest.rs@@ -0,0 +1,97 @@+//! The render manifest and the stage checks: each frame's page read from it (what SG11 and SG14 hold the parts to),+//! and what the checks write into it of the parts (what SG9 names and samples).++use std::collections::HashMap;++use raea_core_scene::{Item, base_ident, spawn_sig};+use serde_json::{Value, json};++use crate::{Page, Words};++/// A render of at most this many frames is stills (`--frame`, `--at`): its manifest names each frame's parts on screen+const STILLS: usize = 16;+/// More than this many parts mounting or unmounting between two frames is a remount+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> {+ 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 shows+ let shown = |e: &Value, key: &str| {+ let b: Vec<f32> = e.get(key)?.as_array()?.iter().filter_map(|v| Some(v.as_f64()? as f32)).collect();+ let [x, y, bw, bh]: [f32; 4] = b.try_into().ok()?;+ (bw > 0.0 && bh > 0.0 && e["opacity"].as_f64().unwrap_or(1.0) >= 0.1).then_some([x, y, x + bw, y + bh])+ };+ fn list<'a>(e: Option<&&'a Value>, key: &str) -> impl Iterator<Item = &'a Value> {+ e.and_then(|e| e[key].as_array()).into_iter().flatten()+ }+ let words = |t: &Value| {+ let text = Some(t["text"].as_str()?.trim()).filter(|s| !s.is_empty())?.into();+ Some(Words { text, bx: shown(t, "ink").or_else(|| shown(t, "box"))?, allow_overlap: t["allowOverlap"] == true })+ };+ nums.iter()+ .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(),+ })+ .collect()+}++/// What the manifest says of a render's parts: for stills, each frame's parts on screen and their boxes (`parts`); for+/// a longer render, the frames where more than REMOUNT parts mount or unmount (`remounts`). SG9 re-renders the frame+/// after each remount alone and names the parts under a patch that differs.+pub fn seen(all: &[Vec<Item>], nums: &[i64], w: u32, h: u32) -> Value {+ if all.len() <= STILLS {+ let parts: Vec<_> = all.iter().zip(nums).map(|(its, f)| json!({"frame": f, "parts": crate::on_screen(its, w, h)})).collect();+ return json!({"parts": parts});+ }+ // each frame's count against the one before, one count held at a time (a film's 13,175 at once were a GB)+ let (mut before, mut remounts) = (None, Vec::new());+ for (its, f) in all.iter().zip(nums) {+ let now = counted(its);+ if before.as_ref().is_some_and(|b| changed(&now, b) > REMOUNT) {+ remounts.push(*f);+ }+ before = Some(now);+ }+ json!({"remounts": remounts})+}++type Counted<'a> = HashMap<(&'a str, &'a str, u64), i64>;++/// A frame's parts as a count by what they are: kind, name, what they draw.+fn counted(its: &[Item]) -> Counted<'_> {+ let mut m = Counted::new();+ for it in its {+ *m.entry((it.kind, base_ident(it), spawn_sig(it))).or_default() += 1;+ }+ m+}++/// How many parts mount or unmount from one frame's count to the next's.+fn changed(a: &Counted, b: &Counted) -> usize {+ let off = |x: &Counted, y: &Counted| x.iter().map(|(k, n)| (n - y.get(k).copied().unwrap_or(0)).max(0) as usize).sum::<usize>();+ off(a, b) + off(b, a)+}++#[cfg(test)]+mod tests {+ use serde_json::json;++ #[test]+ fn a_frames_page_is_its_words_videos_and_pictures() {+ let frames = vec![json!({"frame": 7, "text": [+ {"text": "Hello", "box": [0, 0, 400, 40], "ink": [10, 0, 100, 40], "opacity": 1.0},+ {"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]);+ 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());+ }+}diff --git a/systems/stage/src/page.rs b/systems/stage/src/page.rsnew file mode 100644index 00000000..2f3cf80c--- /dev/null+++ b/systems/stage/src/page.rs@@ -0,0 +1,157 @@+//! SG11, page type stays off the parts: words drawn in the page over more than SHARE of a 3D part's box on screen, for+//! SECS or more, are an error (the essay's words over its curves, a headline over the card it names). A caption sliding+//! past a part is not one; a part that says allowOverlap, or a backdrop (a floor, a set's wall: framing's rule), is+//! not a part words can cover, and words in an element that says data-allow-overlap may cover any.++use std::collections::HashMap;++use raea_core_facts::{Finding, Level};+use serde_json::Value;++use super::{Stage, called, runs};+use crate::framing::{backdrop, own_box};+use crate::view::corners;++/// Words in the page on one frame: what they say, their box on screen ([x0, y0, x1, y1] in px), and whether they+/// may sit on a part (an element they're in says data-allow-overlap).+#[derive(Clone, Debug)]+pub struct Words {+ pub text: String,+ pub bx: [f32; 4],+ pub allow_overlap: bool,+}++/// What the page draws over one frame's 3D, as its manifest has it: its words, its videos' boxes and its pictures'+/// (an img, an svg, a background image or colour): SG14 counts all three as filling the frame.+#[derive(Clone, Debug, Default)]+pub struct Page {+ pub words: Vec<Words>,+ pub videos: Vec<[f32; 4]>,+ pub pictures: Vec<[f32; 4]>,+}++/// Over this share of a part's box on screen (the part inside the frame)+const SHARE: f32 = 0.10;+/// for this long or more, seconds+const SECS: f64 = 0.25;++/// What the words say in a finding, cut short.+fn short(t: &str) -> String {+ let mut s: String = t.chars().take(40).collect();+ if t.chars().count() > 40 {+ s.push('…');+ }+ s+}++pub(crate) fn check(st: &Stage, page: &[Page]) -> Vec<Finding> {+ let mut boxes = HashMap::new();+ // each words' frames over a part past SHARE, and on each the parts it covers with their shares+ let mut over: HashMap<String, HashMap<usize, Vec<(String, f32)>>> = HashMap::new();+ for (k, its) in st.all.iter().enumerate() {+ let (Some(v), Some(words)) = (st.views[k], page.get(k).map(|p| &p.words).filter(|w| !w.is_empty())) else { continue };+ for it in its {+ if it.props.get("allowOverlap").and_then(Value::as_bool) == Some(true) {+ continue;+ }+ let Some((lo, hi)) = own_box(it, &mut boxes).filter(|(lo, hi)| !backdrop(it, *lo, *hi)) else { continue };+ let Some(b) = v.bounds(corners(&it.world, lo, hi)) else { continue };+ let b = [b[0].max(0.0), b[1].max(0.0), b[2].min(st.w), b[3].min(st.h)];+ let area = (b[2] - b[0]) * (b[3] - b[1]);+ if !(area > 1.0) {+ continue;+ }+ for wd in words.iter().filter(|w| !w.allow_overlap) {+ let o = (wd.bx[2].min(b[2]) - wd.bx[0].max(b[0])).max(0.0) * (wd.bx[3].min(b[3]) - wd.bx[1].max(b[1])).max(0.0);+ if o / area > SHARE {+ over.entry(wd.text.clone()).or_default().entry(k).or_default().push((called(it), o / area));+ }+ }+ }+ }+ let mut out = Vec::new();+ for (text, at) in over {+ for (a, b) in runs(st, st.all.len(), |k| at.contains_key(&k)) {+ if st.secs(a, b) < SECS && !st.alone(a) {+ continue;+ }+ // the parts it covers over the run, the most covered first: one fault, however many parts are under it+ let mut most: Vec<(String, f32)> = Vec::new();+ for (name, share) in (a..=b).filter_map(|k| at.get(&k)).flatten() {+ match most.iter_mut().find(|m| m.0 == *name) {+ Some(m) => m.1 = m.1.max(*share),+ None => most.push((name.clone(), *share)),+ }+ }+ most.sort_by(|x, y| y.1.total_cmp(&x.1));+ let named: Vec<String> = most.iter().take(3).map(|(n, s)| format!("'{n}' ({:.0}%)", s * 100.0)).collect();+ let more = if most.len() > 3 { format!(" and {} more", most.len() - 3) } else { String::new() };+ let says = format!("'{}' in the page covers {}{more} from {} to {}", short(&text), named.join(", "), st.at(a), st.at(b));+ out.push(st.finding("type-over-part", Level::Error, a, b, says).fix("move the words off it, or beside it with a Label (raea/camera) that points at it; give the part allowOverlap when the words belong on it"));+ }+ }+ out+}++#[cfg(test)]+mod tests {+ use bevy::math::{Mat4, Vec3};+ use raea_core_scene::Item;+ use serde_json::json;++ use super::{Page, Words};+ use crate::test_items::{cam, item};++ fn card(name: &str, extra: serde_json::Value) -> Item {+ let mut props = json!({"name": name});+ props.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone());+ let mut it = item("mesh", props, Mat4::from_translation(Vec3::ZERO));+ it.shape = Some("box(2, 1, 0.1)".into());+ it+ }++ fn run(part: Item, words: [f32; 4], n: usize) -> Vec<raea_core_facts::Finding> {+ let all: Vec<Vec<Item>> = (0..n).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), part.clone()]).collect();+ let frames: Vec<i64> = (0..n as i64).collect();+ let page: Vec<Page> = (0..n).map(|_| Page { words: vec![Words { text: "Install now".into(), bx: words, allow_overlap: false }], videos: Vec::new(), pictures: Vec::new() }).collect();+ crate::check_with(&all, &frames, &page, 1920, 1080, 30.0, "test").into_iter().filter(|f| f.check == "type-over-part").collect()+ }++ #[test]+ fn a_headline_over_the_card_it_names_is_an_error() {+ // the card fills the middle of the frame; the headline sits across its centre for a second+ let f = run(card("card", json!({})), [760.0, 500.0, 1160.0, 580.0], 30);+ assert_eq!(f.len(), 1, "{f:?}");+ assert!(f[0].says.contains("'Install now' in the page covers 'card' ("), "{}", f[0].says);+ }++ #[test]+ fn words_over_several_parts_are_one_error_naming_them() {+ let mut left = card("left", json!({}));+ left.world = Mat4::from_translation(Vec3::new(-0.6, 0.0, 0.0));+ let mut right = card("right", json!({}));+ right.world = Mat4::from_translation(Vec3::new(0.6, 0.0, 0.0));+ let all: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), left.clone(), right.clone()]).collect();+ let frames: Vec<i64> = (0..30).collect();+ let page: Vec<Page> = (0..30).map(|_| Page { words: vec![Words { text: "Install now".into(), bx: [560.0, 500.0, 1360.0, 580.0], allow_overlap: false }], videos: Vec::new(), pictures: Vec::new() }).collect();+ let f: Vec<_> = crate::check_with(&all, &frames, &page, 1920, 1080, 30.0, "test").into_iter().filter(|f| f.check == "type-over-part").collect();+ assert_eq!(f.len(), 1, "{f:?}");+ assert!(f[0].says.contains("'left'") && f[0].says.contains("'right'"), "{}", f[0].says);+ }++ #[test]+ fn words_that_say_allow_overlap_may_cover_a_part() {+ let all: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), card("card", json!({}))]).collect();+ let frames: Vec<i64> = (0..30).collect();+ let page: Vec<Page> = (0..30).map(|_| Page { words: vec![Words { text: "on the card".into(), bx: [760.0, 500.0, 1160.0, 580.0], allow_overlap: true }], ..Page::default() }).collect();+ assert!(!crate::check_with(&all, &frames, &page, 1920, 1080, 30.0, "test").iter().any(|f| f.check == "type-over-part"));+ }++ #[test]+ fn words_beside_it_brief_or_allowed_are_not() {+ assert!(run(card("card", json!({})), [40.0, 40.0, 400.0, 100.0], 30).is_empty());+ // over it for 4 frames (under a quarter second): a caption passing+ assert!(run(card("card", json!({})), [760.0, 500.0, 1160.0, 580.0], 4).is_empty());+ assert!(run(card("card", json!({"allowOverlap": true})), [760.0, 500.0, 1160.0, 580.0], 30).is_empty());+ }+}