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.

raea check --quick looks at a quarter in, the middle and the end of the composition's real length, and says which frames (#86). It read the length from the source's first durationInFrames={N} and took 90 for anything else, so a durationInFrames={DUR} of 300 frames was sampled at 22, 45 and 89, and text only in its second half went unseen (all 0 texts, exit 0) by the after-save hook too. Now render.json carries the composition's length (length, written by every render whatever frames it drew), the quick check renders frame 0 first to read it, then the three stills, and its report says ok looked at frames 75, 150 and 299 of 300. The reporter's one-text file with DUR: main, all 0 texts; now all 1 texts and its safe-area error, as with a literal 300. The extra render of frame 0 costs about half a second (the literal file 0.85 s to 1.40 s). frames_come_from_the_render replaces the source-reading test; the manual's check and render references say both

shinyobjectz6f7a3f447816
diff --git a/apps/check/src/quick.rs b/apps/check/src/quick.rs
index f1bc8dc0..3187928a 100644
--- a/apps/check/src/quick.rs
+++ b/apps/check/src/quick.rs
@@ -1,41 +1,42 @@
//! `raea check EDIT.tsx --quick` (docs/skills.feature SK10). The quick check renders three stills of a composition (a
-//! quarter in, the middle, the last frame) with their manifest, about a second, and runs the full check's text rules
+//! quarter in, the middle, the last frame, of the length frame 0's render reports) with their manifest, and runs the text rules
//! and the person's text taste on it: clipped and cramped text, safe areas, sizes. Every agent's after-save hook runs
//! it (hook.rs): after a .tsx that registers a root is saved, its findings go back to the agent; a clean check says
//! nothing.
use super::*;
use std::path::Path;
-/// The composition's length in frames, read from its source (the first `durationInFrames={N}`), 90 without one.
-fn frames(src: &str) -> u64 {
- src.split("durationInFrames={").nth(1).and_then(|r| r.split('}').next()).and_then(|n| n.trim().parse().ok()).unwrap_or(90)
+/// The stills' frames: a quarter in, the middle and the last of the length a render reports (render.json's `length`,
+/// the composition's own however it's written; #86 read its source's `durationInFrames={N}` and took 90 for a name).
+fn samples(m: &Value) -> Option<[u64; 3]> {
+ let n = m["length"].as_u64()?.max(1);
+ Some([n / 4, n / 2, n - 1])
}
/// `raea check EDIT.tsx --quick [--shape S] [--platform P] [-o check.json]`: (report, P0 or P1 found). `tastes` are the
/// person's, evaluated by the raea CLI when --taste names them.
pub fn quick(args: &[String], tastes: Vec<raea_core_brief::Taste>) -> R<(String, bool)> {
let file = args.iter().find(|a| a.ends_with(".tsx")).ok_or("raea check --quick takes a composition: EDIT.tsx")?;
- let src = std::fs::read_to_string(file).map_err(|e| format!("{file}: {e}"))?;
- let n = frames(&src).max(1);
- let at = format!("{},{},{}", n / 4, n / 2, n - 1);
let tmp = std::env::temp_dir().join(format!("raea-quick-{}", std::process::id()));
std::fs::create_dir_all(&tmp).map_err(|e| format!("{}: {e}", tmp.display()))?;
let manifest = tmp.join("render.json");
let me = std::env::current_exe().map_err(|e| e.to_string())?;
// the stills are part of this check, which keeps the one entry in the project's record (DR3)
- let out = std::process::Command::new(me).arg("render").arg(file).args(["--at", &at, "-o"]).arg(format!("{}/", tmp.display())).arg("--manifest").arg(&manifest).env("RAEA_RECORD", "off").output().map_err(|e| e.to_string())?;
+ let render = |at: &str| std::process::Command::new(&me).arg("render").arg(file).args(["--at", at, "-o"]).arg(format!("{}/", tmp.display())).arg("--manifest").arg(&manifest).env("RAEA_RECORD", "off").output().map_err(|e| e.to_string());
+ // frame 0 first, for the length (its manifest's), then the three stills
+ let mut out = render("0")?;
+ let at = std::fs::read_to_string(&manifest).ok().and_then(|t| samples(&serde_json::from_str(&t).ok()?));
+ if let Some(at) = at {
+ let _ = std::fs::remove_file(&manifest);
+ out = render(&at.map(|f| f.to_string()).join(","))?;
+ }
// rendered when its manifest was written: a render whose stills clip exits 1 (DR3), and those findings are read here
- let result = if manifest.is_file() {
- on_manifest(file, &manifest, args, tastes)
+ let result = if let (Some(at), true) = (at, manifest.is_file()) {
+ on_manifest(file, &manifest, args, tastes, at)
} else {
// a render that fails is the finding: the agent sees why
let (err, out) = (String::from_utf8_lossy(&out.stderr), String::from_utf8_lossy(&out.stdout));
- let mut why = Vec::new();
- for line in err.lines().chain(out.lines()) {
- if line.contains("REFUSED") || line.contains("rror") {
- why.push(line);
- }
- }
+ let why: Vec<&str> = err.lines().chain(out.lines()).filter(|l| l.contains("REFUSED") || l.contains("rror")).collect();
let f = raea_core_facts::Finding::new("render", raea_core_facts::Level::Error, why.join("\n"), "raea check --quick");
Ok((format!("raea check {file}: it doesn't render\n{}\nraea check: {}", f.line(), raea_core_facts::finding::count(&[f])), true))
};
@@ -46,10 +47,10 @@ pub fn quick(args: &[String], tastes: Vec<raea_core_brief::Taste>) -> R<(String,
/// `raea check --quick`'s half (docs/skills.feature SK10): the text rules and the person's text taste on the manifest
/// of a few stills (`raea render EDIT.tsx --at ... --manifest`), no video. What it can't see (contrast, freezes,
/// sound, blotching) waits for the full check on the export.
-fn on_manifest(file: &str, manifest: &Path, args: &[String], tastes: Vec<raea_core_brief::Taste>) -> R<(String, bool)> {
+fn on_manifest(file: &str, manifest: &Path, args: &[String], tastes: Vec<raea_core_brief::Taste>, [a, b, c]: [u64; 3]) -> R<(String, bool)> {
let at = manifest.display();
let m: Value = serde_json::from_str(&std::fs::read_to_string(manifest).map_err(|e| format!("{at}: {e}"))?).map_err(|e| format!("{at}: {e}"))?;
- let (mut issues, mut passed) = (Vec::new(), Vec::new());
+ let (mut issues, mut passed) = (Vec::new(), vec![format!("looked at frames {a}, {b} and {c} of {}", c + 1)]);
let runs = text_runs(&m);
let (w, h) = (m["width"].as_f64().unwrap_or(1080.0), m["height"].as_f64().unwrap_or(1920.0));
text_rules(&runs, None, w, h, flag(args, "--shape"), flag(args, "--platform"), &mut issues, &mut passed);
@@ -61,9 +62,14 @@ fn on_manifest(file: &str, manifest: &Path, args: &[String], tastes: Vec<raea_co
#[cfg(test)]
mod tests {
+ use serde_json::json;
+ /// the length is the render's, so a `durationInFrames={DUR}` (#86: 300 frames, read as 90) is sampled to its end
#[test]
- fn frames_come_from_the_source() {
- assert_eq!(super::frames("<Composition durationInFrames={240} fps={30} />"), 240);
- assert_eq!(super::frames("no composition"), 90);
+ fn frames_come_from_the_render() {
+ assert_eq!(super::samples(&json!({"length": 240})), Some([60, 120, 239]));
+ assert_eq!(super::samples(&json!({"length": 300})), Some([75, 150, 299]));
+ assert_eq!(super::samples(&json!({"length": 1})), Some([0, 0, 0]));
+ // a render that reported no length: no stills to look at, so the frame-0 render's failure is the finding
+ assert_eq!(super::samples(&json!({"width": 640})), None);
}
}
diff --git a/docs/manual/reference/cli/check.md b/docs/manual/reference/cli/check.md
index f9272f9b..8033af27 100644
--- a/docs/manual/reference/cli/check.md
+++ b/docs/manual/reference/cli/check.md
@@ -7,6 +7,8 @@ sources: ["apps/check/src/lib.rs", "apps/check/src/quick.rs", "apps/direction/sr
`raea check` has two speeds. On a composition with `--quick`, it renders three stills and measures the text:
clipped, cramped, inside the safe areas, large enough to read, and what the stills' render found (3D parts clipping).
+The stills are a quarter in, the middle and the last frame of the length a render of frame 0 reports, however
+`durationInFrames` is written, and the report names them (`ok looked at frames 75, 150 and 299 of 300`).
That takes about a second, so run it after every save. On an exported video, it measures everything the floor asks
of a finished piece. Each finding is an error, a warn or a note (raea's one finding, as `raea scene lint` and a
render's manifest have it), says on which frames and how to fix it, and the command exits 1 while an error stands.
diff --git a/docs/manual/reference/cli/render.md b/docs/manual/reference/cli/render.md
index 07162663..20865d85 100644
--- a/docs/manual/reference/cli/render.md
+++ b/docs/manual/reference/cli/render.md
@@ -83,7 +83,7 @@ Headless: it needs nothing running and opens no window. Takes up to 1 argument b
| `--kbps` | `N` | A fixed video bitrate in kbit/s, in place of the default that follows size and frame rate. |
| `--layers` | – | Write `NAME.layers` beside the export: which layer (a 3D part, an element, its text, an image or a video, by where its JSX is written) each pixel of each frame shows, for raea's player to select layers by clicking. The manifest (`--manifest`, or `NAME.render.json` beside it) names it. The export cache is skipped. |
| `--lite` | – | Draw with raea's live view runtime instead of React, as a live game does. Used by the app when it opens a game. |
-| `--manifest` | `render.json` | Write the render's manifest to this file instead of beside the output: every frame's element boxes as drawn, what the render found and the sounds heard, which `raea check` and `raea world` read. |
+| `--manifest` | `render.json` | Write the render's manifest to this file instead of beside the output: the composition's length in frames (`length`, whichever frames were rendered), every frame's element boxes as drawn, what the render found and the sounds heard, which `raea check` and `raea world` read. |
| `--perception` | `P.json` | The perception the composition's Clock reads (faces, boxes, one for every frame or by frame), when it isn't the `perception.json` beside it. |
| `--quality` | `draft\|high\|master\|0..1` | Constant-quality encoding: `draft` for previews, `high` for most deliveries, `master` for type and hard edges, or a number from 0 to 1. On Windows and Linux (OpenH264) it scales the bitrate instead, and once a frame fits at OpenH264's finest quantiser (12), a higher setting writes the same file. |
| `--review` | `DIR` | Render a 3D scene from six fixed cameras (hero, front, right, top, iso, low), in colour and in clay, to `DIR/colour.png`, `DIR/clay.png` and `DIR/review.json`. |
diff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rs
index c0d3ca32..2cc84fff 100644
--- a/runtime/export/src/fed.rs
+++ b/runtime/export/src/fed.rs
@@ -308,7 +308,7 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, tot
// 3D parts passing through each other on screen: on stderr, and in the manifest for the legacy app's checks
let 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));
- write_manifest(cx, (w, h, fps), clipping, |cx| heard(&frames.borrow(), &notes.borrow(), cx, fps))?;
+ write_manifest(cx, (w, h, fps, total), clipping, |cx| heard(&frames.borrow(), &notes.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/lib.rs b/runtime/export/src/lib.rs
index b7f0954e..fbb87284 100644
--- a/runtime/export/src/lib.rs
+++ b/runtime/export/src/lib.rs
@@ -67,11 +67,12 @@ pub(crate) struct Sound {
/// `render --manifest PATH` (the CLI's; render_bundle keeps its signature for the iPhone): where render.json goes.
static MANIFEST: std::sync::Mutex<Option<PathBuf>> = std::sync::Mutex::new(None);
-/// The manifest, its folder made first (2D stills write it before their frames): boxes as drawn, findings, sounds.
-fn write_manifest(cx: &mut Ctx, (w, h, fps): (u32, u32, f64), found: Vec<raea_core_facts::Finding>, heard: impl FnOnce(&Ctx) -> Value) -> R<()> {
+/// The manifest, its folder made first (2D stills write it before their frames): the composition's length in frames
+/// (whatever was rendered of it; raea check --quick samples by it, #86), boxes as drawn, findings, sounds.
+fn write_manifest(cx: &mut Ctx, (w, h, fps, length): (u32, u32, f64, i64), found: Vec<raea_core_facts::Finding>, heard: impl FnOnce(&Ctx) -> Value) -> R<()> {
let (Some(path), Some(frames)) = (MANIFEST.lock().unwrap().clone(), cx.manifest.take()) else { return Ok(()) };
path.parent().map_or(Ok(()), std::fs::create_dir_all).map_err(|e| format!("{}: {e}", path.display()))?;
- std::fs::write(&path, json!({"width": w, "height": h, "fps": fps, "frames": frames, "findings": raea_core_facts::finding::ranked(found), "sounds": heard(cx), "not_applied": not_applied::seen(), "layers": raea_sys_layers::finish(fps)}).to_string()).map_err(|e| format!("{}: {e}", path.display()))
+ std::fs::write(&path, json!({"width": w, "height": h, "fps": fps, "length": length, "frames": frames, "findings": raea_core_facts::finding::ranked(found), "sounds": heard(cx), "not_applied": not_applied::seen(), "layers": raea_sys_layers::finish(fps)}).to_string()).map_err(|e| format!("{}: {e}", path.display()))
}
/// `render --stage WxH`: a responsive composition (one that lays out from useVideoConfig) laid out at a stage's size, as
diff --git a/runtime/export/src/render.rs b/runtime/export/src/render.rs
index 15610100..0965daaa 100644
--- a/runtime/export/src/render.rs
+++ b/runtime/export/src/render.rs
@@ -302,7 +302,7 @@ pub(crate) fn render_bundle_with(js: &Path, dir: &Path, out: &Path, wanted: Opti
}
// 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();
- write_manifest(&mut cx, (w, h, fps), clipping, |_| json!([]))?;
+ 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())
} else {
@@ -357,7 +357,7 @@ pub(crate) fn render_bundle_with(js: &Path, dir: &Path, out: &Path, wanted: Opti
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);
- write_manifest(&mut cx, (w, h, fps), clipping, |cx| heard(&frames, &tones, cx, fps))?;
+ write_manifest(&mut cx, (w, h, fps, total), clipping, |cx| heard(&frames, &tones, cx, fps))?;
let ext = out_ext(out);
// raea-render's IR built directly from the frames and drawn by raea-render (checked equal to the retired rrl's compile of the same