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 light steady: a frame held (raea render --hold FRAME:FRAMES) and whether its light holds still. Blotches tens of pixels wide that drift over lit floors and reflections, Solari's world cache lit by too few rays, are told from grain by size, and a run over --max fails with a picture of where

shinyobjectz12f8521003b6
diff --git a/apps/direction/src/pure.rs b/apps/direction/src/pure.rs
index 02514b89..0f529834 100644
--- a/apps/direction/src/pure.rs
+++ b/apps/direction/src/pure.rs
@@ -28,7 +28,7 @@ const LEVELS: f32 = 96.0;
const SHARE: f64 = 1e-4;
const LEAST: usize = 64;
/// The flags of the render the stills repeat (each takes a value, then the bare ones): what it draws and at what size
-const KEEP: [&str; 11] = ["--composition", "--w", "--h", "--fps", "--frames", "--words", "--perception", "--input", "--stage", "--props", "--scale"];
+const KEEP: [&str; 12] = ["--composition", "--w", "--h", "--fps", "--frames", "--words", "--perception", "--input", "--stage", "--props", "--scale", "--hold"];
const KEEP_BARE: [&str; 2] = ["--clay", "--lite"];
const BY: &str = "raea render (frame-pure)";
diff --git a/docs/manual/reference/cli/light.md b/docs/manual/reference/cli/light.md
index 385647af..cbdbc3bc 100644
--- a/docs/manual/reference/cli/light.md
+++ b/docs/manual/reference/cli/light.md
@@ -35,6 +35,19 @@ why another isn't). `"size"` is the live stage, 1920x1080 by default.
Any render takes the same switches: `RAEA_LIGHT=raster|solari|pathtracer` puts every 3D camera on that path,
whatever the composition asks, and `RAEA_LIGHT_SPP=N` draws each frame N times, the path tracer's accumulation started afresh on each frame.
+`raea light steady` asks one thing of one frame: does its light hold still? It draws frame `--frame` again and again
+(`raea render --hold`), so nothing in the scene or the camera moves, and measures what still changes. Grain is a
+pixel or two wide and new every frame. A blotch is tens of pixels wide and drifts over lit floors and reflections for a
+quarter of a second or more: on Solari, the world cache lit by too few rays. The two are told apart by size: the
+deviation in time of each 32-pixel square's mean luminance (`blotch`, percent of the mean) against each 8-pixel
+square's (`grain`). Grain alone gives a `spread` of 0.25, and blotches bring it toward 1. A run over `--max` fails,
+`DIR/held/steady.png` shows where (white is 6%), and `steady.json` holds the numbers.
+
+```sh
+raea light steady compositions/shots.tsx --composition court --frame 1188 -o out/steady/
+raea light steady out/steady/held/ # frames already held, measured again
+```
+
```sh
raea light check bench/light/scenes.json -o out/light/
raea light check bench/light/scenes.json -o out/light/ --scene kitchen --paths solari --spp 512 --fresh
@@ -45,7 +58,7 @@ raea light check bench/light/scenes.json -o out/light/ --scene kitchen --paths s
## Usage
```sh
-raea light check SCENES.json -o DIR [--scene NAME] [--paths raster,traced-ao,solari,gi] [--spp N] [--fresh] (each scene on each light path against its path-traced reference: distance in stops, the worst tile, a moving shot's flicker, a frame's cost; DIR/report.json)
+raea light check SCENES.json -o DIR [--scene NAME] [--paths raster,traced-ao,solari,gi] [--spp N] [--fresh] | raea light steady EDIT.tsx --frame N [--composition ID] [--frames 96] [--max 1.5] -o DIR | raea light steady DIR [--max 1.5] (steady: frame N held, and whether its light holds still) (each scene on each light path against its path-traced reference: distance in stops, the worst tile, a moving shot's flicker, a frame's cost; DIR/report.json)
```
Headless: it needs nothing running and opens no window. Takes up to 2 arguments besides its flags.
@@ -54,7 +67,11 @@ Headless: it needs nothing running and opens no window. Takes up to 2 arguments
| Flag | Takes | What it does |
| --- | --- | --- |
+| `--composition` | `ID` | `steady`: the composition of the file to hold. |
+| `--frame` | `N` | `steady`: the frame to hold. The scene and the camera stay as they are at it. |
+| `--frames` | `96` | `steady`: how many times the frame is drawn. The second half is measured, once the light has built. |
| `--fresh` | – | Make the references again, even where they're kept from an earlier check. |
+| `--max` | `1.5` | `steady`: the blotch, in percent, a run may show before it fails. The worst tile may show three times it. |
| `--paths` | `raster,traced-ao,solari,gi` | The light paths to measure, comma-separated (all four by default). |
| `--scene` | `NAME` | Check only the scene with this name. |
| `--spp` | `N` | How many times each reference frame is path-traced: its samples a pixel (256 by default). |
diff --git a/docs/manual/reference/cli/render.md b/docs/manual/reference/cli/render.md
index b743630e..64018b52 100644
--- a/docs/manual/reference/cli/render.md
+++ b/docs/manual/reference/cli/render.md
@@ -60,7 +60,7 @@ the reason in the manifest. A render of a file in a raea project also keeps its
## Usage
```sh
-raea render EDIT.tsx -o OUT.mp4|OUT.png|OUT.wav|DIR [--audio OUT.wav] [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--props JSON|P.json] [--scale S] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha [--alpha-codec prores|hevc|rle|png]] [--kbps N | --quality draft|high|master|0..1] [--clay] [--despite CHECK WHY] (also: --lite --comps)
+raea render EDIT.tsx -o OUT.mp4|OUT.png|OUT.wav|DIR [--audio OUT.wav] [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--props JSON|P.json] [--scale S] [--hold FRAME[:FRAMES]] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha [--alpha-codec prores|hevc|rle|png]] [--kbps N | --quality draft|high|master|0..1] [--clay] [--despite CHECK WHY] (also: --lite --comps)
raea render EDIT.tsx --review DIR [--frame N] (fixed cameras hero, front, right, top, iso, low in colour and clay: DIR/colour.png, clay.png, review.json)
raea render PAGE.html -o OUT.mp4|OUT.png|DIR [--at A,B] [--alpha] (an HTML composition)
raea render --bundle NAME.comp.js -o OUT.png|DIR [--dir DIR] [--frame N] (a bundle from raea bundle, as render_bundle draws it)
@@ -88,6 +88,7 @@ Headless: it needs nothing running and opens no window. Takes up to 1 argument b
| `--frame` | `N` | Render this one frame. |
| `--frames` | `N` | Length in frames for a file with no `<Composition>` or `config` (60 by default). |
| `--h` | `H` | Height in pixels for a file with no `<Composition>` or `config` (1920 by default). |
+| `--hold` | `FRAME` | Draws that frame of a `<Composition>` again and again, 96 times, or as many as `FRAME:FRAMES` says. The scene and the camera hold still, so what changes between the frames is the renderer's own. `raea light steady` measures it. |
| `--input` | `I.json\|inputs.rrl` | A game's input over time: a JSON timeline, or the step keys of an `inputs.rrl`, so a recorded play-through renders the same every time. |
| `--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. |
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index 8869d71c..e6af3ac1 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -376,7 +376,7 @@ pub fn run(args: &[String]) -> R<String> {
}
if args.first().map(String::as_str) != Some("render") || args.len() < 2 {
return Err(format!(
- "raea render EDIT.tsx -o OUT.mp4|OUT.png|OUT.wav|DIR [--audio OUT.wav] [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--props JSON|P.json] [--scale S] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha [--alpha-codec prores|hevc|rle|png]] [--kbps N | --quality draft|high|master|0..1] [--clay] [--despite CHECK WHY] (also: --lite --comps)\n raea render EDIT.tsx --review DIR [--frame N] (fixed cameras hero, front, right, top, iso, low in colour and clay: DIR/colour.png, clay.png, review.json)\n raea render PAGE.html -o OUT.mp4|OUT.png|DIR [--at A,B] [--alpha] (an HTML composition)\n raea render --bundle NAME.comp.js -o OUT.png|DIR [--dir DIR] [--frame N] (a bundle from raea bundle, as render_bundle draws it)
+ "raea render EDIT.tsx -o OUT.mp4|OUT.png|OUT.wav|DIR [--audio OUT.wav] [--frame N | --at A,B] [--composition ID] [--w W] [--h H] [--fps FPS] [--frames N] [--words W.json] [--perception P.json] [--input I.json|inputs.rrl] [--props JSON|P.json] [--scale S] [--hold FRAME[:FRAMES]] [--manifest render.json] [--layers] [--stage WxH] [--10bit] [--aov] [--alpha [--alpha-codec prores|hevc|rle|png]] [--kbps N | --quality draft|high|master|0..1] [--clay] [--despite CHECK WHY] (also: --lite --comps)\n raea render EDIT.tsx --review DIR [--frame N] (fixed cameras hero, front, right, top, iso, low in colour and clay: DIR/colour.png, clay.png, review.json)\n raea render PAGE.html -o OUT.mp4|OUT.png|DIR [--at A,B] [--alpha] (an HTML composition)\n raea render --bundle NAME.comp.js -o OUT.png|DIR [--dir DIR] [--frame N] (a bundle from raea bundle, as render_bundle draws it)
raea media probe|still|sheet|audio|loudness|motion|cuts|freezes|proxy|share|lod|trim|concat FILE ... | ffmpeg ARGS | ffprobe ARGS (media work, native: media help)
raea bundle EDIT.tsx --composition-bundle -o OUT.js [--portable DIR] (a composition for render_bundle, on the Mac or the iPhone)\n raea add PKG[@RANGE]... [--dev] | remove NAME... | install [--offline] [--in DIR] (npm packages for the project: raea.lock, node_modules)\n {} (foley, local)\n {} (an instrument's notes, local)\n raea setup-audio [--check] [sao|tokensynth] (install or check the local audio models)\n {} (the song's energy map: beats, sections, builds, drops, stops, hits, cuts per bar; also: --backend NAME)\n raea sounds [WORDS] | sounds get PACK/INSTRUMENT [--notes ..|--all] [-o DIR] (open sample libraries for a Sampler)\n {} (the clip's camera solved, for <Matchmove>)",
tools::sound::SAO_USAGE, tools::sound::TOKENSYNTH_USAGE, tools::song::USAGE, motion::track::USAGE
diff --git a/engine/light/src/lib.rs b/engine/light/src/lib.rs
index ced86219..93be1c7f 100644
--- a/engine/light/src/lib.rs
+++ b/engine/light/src/lib.rs
@@ -13,13 +13,14 @@
//! live stage, 1920x1080 by default) }.
pub mod metric;
+pub mod steady;
use raea_runtime_bundle::{flag, R};
use serde_json::{json, Value};
use std::path::{Path, PathBuf};
use std::time::Instant;
-pub const USAGE: &str = "raea light check SCENES.json -o DIR [--scene NAME] [--paths raster,traced-ao,solari,gi] [--spp N] [--fresh]";
+pub const USAGE: &str = "raea light check SCENES.json -o DIR [--scene NAME] [--paths raster,traced-ao,solari,gi] [--spp N] [--fresh] | raea light steady EDIT.tsx --frame N [--composition ID] [--frames 96] [--max 1.5] -o DIR | raea light steady DIR [--max 1.5] (steady: frame N held, and whether its light holds still)";
/// The light paths a check compares: RAEA_LIGHT's, and traced-ao, raster with systems/rt's traced occlusion in place
/// of SSAO (on a camera with <AmbientOcclusion>; on any other it draws as raster).
@@ -309,6 +310,9 @@ fn table(reports: &[Value]) -> String {
}
pub fn light(args: &[String]) -> R<String> {
+ if args.first().map(String::as_str) == Some("steady") {
+ return steady::steady(&args[1..]);
+ }
if args.first().map(String::as_str) != Some("check") || args.len() < 2 {
return Err(format!("usage: {USAGE}"));
}
diff --git a/engine/light/src/steady.rs b/engine/light/src/steady.rs
new file mode 100644
index 00000000..3cb42638
--- /dev/null
+++ b/engine/light/src/steady.rs
@@ -0,0 +1,168 @@
+//! `raea light steady EDIT.tsx --frame N -o DIR`: whether the light holds still. Frame N is
+//! drawn again and again (`raea render --hold`), so the scene and the camera don't move, and whatever still changes on
+//! screen is the renderer's own. Two things change: grain, a pixel or two wide and new every frame, which a denoiser
+//! and the eye average away; and blotches, patches tens of pixels wide that drift over lit floors and reflections for
+//! a quarter of a second or more, which nothing averages away. Solari's world cache makes them when its cells are
+//! lit by too few rays (MALL RAT, 11-24: "this noisy splotchy thing in the lights and reflections").
+//!
+//! The two are told apart by size. Each SMALL x SMALL and each LARGE x LARGE square's mean luminance is followed over
+//! the held frames, once the light has built: its deviation in time over its mean. Grain's falls by the square's side
+//! (LARGE / SMALL = 4 times less in the large squares); a blotch as wide as the large square keeps its deviation.
+//! `blotch` is the large squares' deviation (rms over the lit ones, percent), `worst` the worst TILE's, and `spread`
+//! the large squares' deviation over the small squares' (0.25 is grain alone, toward 1 is blotches). A run over
+//! `--max` fails, and DIR/steady.png shows where: each large square by its deviation, white at MAX_SHOWN percent.
+
+use crate::metric::{self, Luma};
+use raea_runtime_bundle::{flag, R};
+use serde_json::{json, Value};
+use std::path::{Path, PathBuf};
+
+use crate::USAGE;
+
+const SMALL: usize = 8;
+const LARGE: usize = 32;
+/// The large squares a side of the tile the worst is found among.
+const TILE: usize = 4;
+/// A square darker than this (linear) isn't lit enough for its deviation to show.
+const LIT: f64 = 0.004;
+/// The deviation steady.png draws as white, percent.
+const MAX_SHOWN: f64 = 6.0;
+/// What a run may show before it fails, percent, unless `--max` says: a held raster frame reads 0, Solari with a
+/// built cache under 1.
+const MAX: f64 = 1.5;
+
+/// Each square's mean and deviation in time over `frames`, side `k`: (w, h, [(mean, deviation / mean)]).
+fn squares(frames: &[Luma], k: usize) -> (usize, usize, Vec<(f64, f64)>) {
+ let first = frames[0].blocks(k);
+ let mut sums = vec![(0.0f64, 0.0f64); first.y.len()];
+ for f in frames {
+ for (s, &v) in sums.iter_mut().zip(&f.blocks(k).y) {
+ s.0 += v as f64;
+ s.1 += (v as f64) * (v as f64);
+ }
+ }
+ let n = frames.len() as f64;
+ let out = sums.into_iter().map(|(a, b)| { let m = a / n; (m, (b / n - m * m).max(0.0).sqrt() / m.max(LIT)) }).collect();
+ (first.w, first.h, out)
+}
+
+fn rms(v: impl Iterator<Item = f64>) -> f64 {
+ let (s, n) = v.fold((0.0, 0usize), |(s, n), x| (s + x * x, n + 1));
+ if n == 0 { 0.0 } else { (s / n as f64).sqrt() }
+}
+
+/// The measure of held frames (the module's doc), and steady.png's picture: the large squares' deviation.
+pub fn measure(frames: &[Luma]) -> R<(Value, image::GrayImage)> {
+ if frames.len() < 8 {
+ return Err(format!("{} held frames: 8 at least say whether the light holds still", frames.len()));
+ }
+ let (_, _, small) = squares(frames, SMALL);
+ let (w, h, large) = squares(frames, LARGE);
+ let lit = |s: &&(f64, f64)| s.0 > LIT;
+ let (blotch, grain) = (rms(large.iter().filter(lit).map(|s| s.1)), rms(small.iter().filter(lit).map(|s| s.1)));
+ let mut worst = (0.0f64, 0usize, 0usize);
+ for ty in 0..h.div_ceil(TILE) {
+ for tx in 0..w.div_ceil(TILE) {
+ let cells = (0..TILE * TILE).filter_map(|i| large.get((ty * TILE + i / TILE) * w + tx * TILE + i % TILE).filter(|_| tx * TILE + i % TILE < w)).filter(lit);
+ let v = rms(cells.map(|s| s.1));
+ if v > worst.0 {
+ worst = (v, tx * TILE * LARGE, ty * TILE * LARGE);
+ }
+ }
+ }
+ let map = image::GrayImage::from_fn(w as u32, h as u32, |x, y| {
+ let s = large[y as usize * w + x as usize];
+ image::Luma([if s.0 > LIT { (s.1 * 100.0 / MAX_SHOWN * 255.0).min(255.0) as u8 } else { 0 }])
+ });
+ let pct = |v: f64| (v * 1e4).round() / 100.0;
+ let report = json!({
+ "frames": frames.len(), "blotch": pct(blotch), "grain": pct(grain), "spread": ((blotch / grain.max(1e-9)) * 100.0).round() / 100.0,
+ "worst": pct(worst.0), "worst_at": [worst.1, worst.2], "lit": ((large.iter().filter(lit).count() as f64 / large.len().max(1) as f64) * 100.0).round() / 100.0,
+ });
+ Ok((report, map))
+}
+
+/// The PNG frames of a folder, in order.
+fn held(dir: &Path) -> R<Vec<PathBuf>> {
+ let mut v: Vec<PathBuf> = std::fs::read_dir(dir).map_err(|e| format!("{}: {e}", dir.display()))?.flatten().map(|e| e.path()).filter(|p| p.extension().is_some_and(|x| x == "png") && p.file_name().is_some_and(|n| n != "steady.png")).collect();
+ v.sort();
+ Ok(v)
+}
+
+pub fn steady(args: &[String]) -> R<String> {
+ let first = args.first().ok_or(format!("usage: {USAGE}"))?;
+ let max = flag(args, "--max").map(|m| m.parse::<f64>().map_err(|_| format!("--max takes a percent, not {m}"))).transpose()?.unwrap_or(MAX);
+ let dir = if Path::new(first).is_dir() {
+ PathBuf::from(first)
+ } else {
+ let frame = flag(args, "--frame").ok_or(format!("usage: {USAGE}"))?;
+ let n: usize = flag(args, "--frames").map(|n| n.parse().map_err(|_| format!("--frames takes a count, not {n}"))).transpose()?.unwrap_or(96);
+ let out = PathBuf::from(flag(args, "-o").ok_or(format!("usage: {USAGE}"))?).join("held");
+ let _ = std::fs::remove_dir_all(&out);
+ std::fs::create_dir_all(&out).map_err(|e| format!("{}: {e}", out.display()))?;
+ let mut cmd = std::process::Command::new(std::env::current_exe().map_err(|e| e.to_string())?);
+ cmd.args(["render", first, "--hold", &format!("{frame}:{n}"), "-o"]).arg(format!("{}/", out.display()));
+ if let Some(c) = flag(args, "--composition") {
+ cmd.args(["--composition", &c]);
+ }
+ let run = cmd.args(["--despite", "clips", "raea light steady measures light, not placement"]).output().map_err(|e| e.to_string())?;
+ if !run.status.success() {
+ let err = String::from_utf8_lossy(&run.stderr);
+ return Err(format!("the held render failed: {}", err.lines().rev().take(4).collect::<Vec<_>>().into_iter().rev().collect::<Vec<_>>().join(" | ")));
+ }
+ out
+ };
+ // the second half: the first is the light building from nothing, which a render's lead-in covers
+ let files = held(&dir)?;
+ let frames: Vec<Luma> = files[files.len() / 2..].iter().map(|p| metric::load(p)).collect::<R<_>>()?;
+ let (mut report, map) = measure(&frames)?;
+ let png = dir.join("steady.png");
+ map.save(&png).map_err(|e| format!("{}: {e}", png.display()))?;
+ let (blotch, worst) = (report["blotch"].as_f64().unwrap_or(0.0), report["worst"].as_f64().unwrap_or(0.0));
+ let ok = blotch <= max && worst <= max * 3.0;
+ report["max"] = json!(max);
+ report["steady"] = json!(ok);
+ std::fs::write(dir.join("steady.json"), serde_json::to_string_pretty(&report).unwrap_or_default()).map_err(|e| e.to_string())?;
+ let line = format!(
+ "blotch {blotch}% (max {max}), worst {worst}% at {},{} (max {}), grain {}%, spread {} over {} held frames; {}",
+ report["worst_at"][0], report["worst_at"][1], max * 3.0, report["grain"], report["spread"], report["frames"], png.display()
+ );
+ if ok { Ok(format!("STEADY {line}")) } else { Err(format!("the light doesn't hold still: {line}. On Solari this is the world cache lit by too few rays: bake it (cache.bake, then cache.load), or give it a longer history")) }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// Frames of a flat grey, each pixel moved by `grain` (new every frame and pixel) and each PATCH x PATCH patch by
+ /// `blotch` (new every frame, the same across the patch).
+ fn frames(grain: f32, blotch: f32) -> Vec<Luma> {
+ const PATCH: usize = 40;
+ let (w, h) = (320, 240);
+ let mut seed = 7u32;
+ let mut rnd = move || {
+ seed = seed.wrapping_mul(1664525).wrapping_add(1013904223);
+ (seed >> 8) as f32 / (1u32 << 24) as f32 * 2.0 - 1.0
+ };
+ (0..24)
+ .map(|_| {
+ let patches: Vec<f32> = (0..(w / PATCH + 1) * (h / PATCH + 1)).map(|_| rnd() * blotch).collect();
+ Luma { w, h, y: (0..w * h).map(|i| 0.3 * (1.0 + rnd() * grain + patches[(i / w / PATCH) * (w / PATCH + 1) + (i % w) / PATCH])).collect() }
+ })
+ .collect()
+ }
+
+ #[test]
+ fn grain_is_steady_and_blotches_are_not() {
+ let still = measure(&frames(0.0, 0.0)).unwrap().0;
+ assert_eq!(still["blotch"], 0.0);
+ // heavy grain, 30% a pixel: under 1% across a 32 px square, and a spread near 0.25
+ let grain = measure(&frames(0.3, 0.0)).unwrap().0;
+ assert!(grain["blotch"].as_f64().unwrap() < 1.0, "{grain}");
+ assert!(grain["spread"].as_f64().unwrap() < 0.35, "{grain}");
+ // patches moving 5%: the large squares keep it
+ let blotch = measure(&frames(0.05, 0.05)).unwrap().0;
+ assert!(blotch["blotch"].as_f64().unwrap() > 2.0, "{blotch}");
+ assert!(blotch["spread"].as_f64().unwrap() > 0.6, "{blotch}");
+ }
+}
diff --git a/runtime/bundle/src/entry.rs b/runtime/bundle/src/entry.rs
index 3cff6554..8bc4300a 100644
--- a/runtime/bundle/src/entry.rs
+++ b/runtime/bundle/src/entry.rs
@@ -5,7 +5,7 @@ pub fn entry(file: &str, o: &CompOpts) -> String {
let js = |v: &Option<Value>| v.as_ref().map(Value::to_string).unwrap_or("null".into());
let (words, perception, input) = (js(&o.words), js(&o.perception), js(&o.input));
let given = serde_json::to_string(&o.given).unwrap_or("[]".into());
- let props = format!("{} x{}", js(&o.props), o.scale.unwrap_or(1.0));
+ let props = format!("{} x{} hold {:?}", js(&o.props), o.scale.unwrap_or(1.0), o.hold);
// the composition's element made once, so a frame re-renders only what reads the frame (its clock, through
// useCurrentFrame), not every part (docs/control.feature FC1b). A frame is already pure (a still renders any
// frame alone), so a part drawing Math.random or Date in render without reading the frame breaks either way.
diff --git a/runtime/bundle/src/fresh.rs b/runtime/bundle/src/fresh.rs
index b24cb5cf..62f3104a 100644
--- a/runtime/bundle/src/fresh.rs
+++ b/runtime/bundle/src/fresh.rs
@@ -169,7 +169,7 @@ pub fn bundle_fresh(tsx: &Path, out_js: &Path, o: &CompOpts, portable: Option<&P
link_node_modules(&js, &work)?;
// the command line's props, where getInputProps() and a Composition read them (the entry imports it first)
let global = |v: Option<String>| v.unwrap_or("undefined".into());
- std::fs::write(work.join("props.ts"), format!("(globalThis as any).__raea_input_props = {};\n(globalThis as any).__raea_scale = {};\n", global(o.props.as_ref().map(Value::to_string)), global(o.scale.map(|s| s.to_string())))).map_err(|e| e.to_string())?;
+ std::fs::write(work.join("props.ts"), format!("(globalThis as any).__raea_input_props = {};\n(globalThis as any).__raea_scale = {};\n(globalThis as any).__raea_hold = {};\n", global(o.props.as_ref().map(Value::to_string)), global(o.scale.map(|s| s.to_string())), global(o.hold.map(|(n, m)| format!("[{n}, {m}]"))))).map_err(|e| e.to_string())?;
if o.lite {
// the game's code and the SDK's resolve "react" to the live view runtime (tsconfig paths cover the files under
// the work folder; packages in node_modules keep their own React)
diff --git a/runtime/bundle/src/lib.rs b/runtime/bundle/src/lib.rs
index 4d6bc2ee..871d1f77 100644
--- a/runtime/bundle/src/lib.rs
+++ b/runtime/bundle/src/lib.rs
@@ -139,6 +139,8 @@ pub struct CompOpts {
pub props: Option<Value>,
/// `--scale S`: a `<Composition>` laid out at its own size and drawn at S times it (MV5, #175)
pub scale: Option<f64>,
+ /// `--hold N:M`: frame N of a `<Composition>` drawn M times (96 unless given), a held camera on a still scene
+ pub hold: Option<(u32, u32)>,
/// live play's runtime instead of React (sdk/react/js/lite: each frame rendered and only what changed sent, no
/// reconciler): what a game plays on; renders keep React
pub lite: bool,
@@ -213,12 +215,13 @@ pub fn comp_opts(args: &[String]) -> R<CompOpts> {
perception: flag(args, "--perception").map(|p| json_file(&p)).transpose()?,
input: flag(args, "--input").map(|p| input_file(&p)).transpose()?,
props: flag(args, "--props").map(|p| props_arg(&p)).transpose()?,
+ hold: flag(args, "--hold").map(|h| { let (n, m) = h.split_once(':').unwrap_or((&h, "96")); n.parse().ok().zip(m.parse().ok().filter(|m| *m > 0)).ok_or(format!("--hold takes a frame, or FRAME:FRAMES (--hold 1308:96), not {h}")) }).transpose()?,
scale: n("--scale")?.map(|s| if s > 0.0 && s <= 8.0 { Ok(s) } else { Err(format!("--scale takes a number above 0, 8 at most (0.5 draws a half-size draft), not {s}")) }).transpose()?,
lite: args.iter().any(|a| a == "--lite"),
comps: args.iter().any(|a| a == "--comps"),
};
- if o.props.is_some() || o.scale.is_some() {
- *GIVEN.lock().unwrap() = Some(json!({"props": o.props, "scale": o.scale}));
+ if o.props.is_some() || o.scale.is_some() || o.hold.is_some() {
+ *GIVEN.lock().unwrap() = Some(json!({"props": o.props, "scale": o.scale, "hold": o.hold}));
}
Ok(o)
}
diff --git a/sdk/video/src/registry.tsx b/sdk/video/src/registry.tsx
index 037c4611..a9ac8a54 100644
--- a/sdk/video/src/registry.tsx
+++ b/sdk/video/src/registry.tsx
@@ -151,14 +151,17 @@ function validate(props: CompositionProps<any>, taken: readonly RegisteredCompos
const scale = (draft ?? 1) * ((globalThis as { __raea_scale?: number }).__raea_scale ?? 1);
const [w, h] = scale === 1 ? [props.width, props.height] : [Math.max(1, Math.round(props.width * scale)), Math.max(1, Math.round(props.height * scale))];
const controls = validControls(props.controls, defaultProps as Record<string, unknown>, fail);
- const cut = segments ? edited(props.component, segments) : props.component;
+ // --hold N:M: frame N drawn M times, so what still changes on screen is the renderer's own (raea light steady)
+ const hold = (globalThis as { __raea_hold?: [number, number] }).__raea_hold;
+ const Whole = segments ? edited(props.component, segments) : props.component;
+ const cut: ComponentType<any> = hold ? (p) => <Freeze frame={hold[0]}><Whole {...p} /></Freeze> : Whole;
return {
id: props.id,
component: w === props.width && h === props.height ? cut : scaled(cut, props.width, props.height, w, h),
width: w,
height: h,
fps: props.fps,
- durationInFrames: segments ? segments.reduce((n, [a, b]) => n + b - a, 0) : props.durationInFrames,
+ durationInFrames: hold ? hold[1] : segments ? segments.reduce((n, [a, b]) => n + b - a, 0) : props.durationInFrames,
defaultProps,
controls,
};