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
#26: a 3D still or --at list steps only its frames and their neighbours, not the whole timeline up to the last. scene_frames takes the wanted frames: when they and the frame either side of each are under half the timeline, each run of them is stepped in the one runtime and every frame between holds the stepped scene before it (never drawn; frames are pure); the clipping check reads the wanted frames alone. #26's 360-frame scene on this Mac, three runs each back to back, the raea on PATH (main before this) against this build: --at 30,150,270,330 steps React in 990-1048 ms before, 54-60 ms after (5.6-6.3 s to 2.2-2.5 s in all); --frame 330 in 912-988 ms before, 28-29 ms after. Pixels are identical to before, and bench/at-3d/check.sh checks them against the same four frames frozen in a 4-frame composition (which steps every frame), failing on the old raea and passing on this one. A full render still steps every frame for the rows and again while it draws; that's left open.
shinyobjectz089acda03ada
diff --git a/bench/at-3d/check.sh b/bench/at-3d/check.shnew file mode 100755index 00000000..ea4aa41c--- /dev/null+++ b/bench/at-3d/check.sh@@ -0,0 +1,24 @@+#!/bin/bash+# #26: a 3D composition's --at frames step only themselves and their neighbours, and draw as the whole timeline stepped+# draws them. scene.tsx (360 frames) is drawn at four frames with --at and must report the sparse stepping ("N of M+# frames stepped"); frozen.tsx draws the same four frames as a 4-frame composition (each the scene under <Freeze>, so+# its rows come from stepping every frame), and each pair must be pixel-identical. Exits 1 on a failure.+# bench/at-3d/check.sh (RAEA_BIN: the raea to run, default target/release/raea)+cd "$(dirname "$0")/../.." || exit 2+BIN=${RAEA_BIN:-$PWD/target/release/raea}+# pixel checks: no Content Credentials or TrustMark id in the frames+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-at-3d.XXXXXX")+trap 'rm -rf "$OUT"' EXIT+RAEA_STARTUP_TRACE=1 "$BIN" render bench/at-3d/scene.tsx --at 30,150,270,330 -o "$OUT/at" > "$OUT/at.log" 2>&1 || { echo "FAIL: the --at render failed"; tail -5 "$OUT/at.log"; exit 1; }+"$BIN" render bench/at-3d/frozen.tsx -o "$OUT/frozen" > "$OUT/frozen.log" 2>&1 || { echo "FAIL: the frozen render failed"; tail -5 "$OUT/frozen.log"; exit 1; }+status=0+stepped=$(grep -o "[0-9]* of [0-9]* frames stepped" "$OUT/at.log")+[ "$stepped" = "12 of 332 frames stepped" ] || { echo "FAIL: the --at render stepped '${stepped:-every frame}', not 12 of 332"; status=1; }+for k in 0 1 2 3; do+ f=$(printf 'frame-%05d.png' $k)+ d=$(magick compare -metric AE "$OUT/at/$f" "$OUT/frozen/$f" null: 2>&1 | cut -d' ' -f1)+ [ "$d" = 0 ] || { echo "FAIL: $f differs from the frozen render's in ${d:-?} pixels"; status=1; }+done+[ $status = 0 ] && echo "PASS: $stepped, the four frames pixel-identical to the frozen render's"+exit $statusdiff --git a/bench/at-3d/frozen.tsx b/bench/at-3d/frozen.tsxnew file mode 100644index 00000000..345cd52e--- /dev/null+++ b/bench/at-3d/frozen.tsx@@ -0,0 +1,16 @@+// The frames bench/at-3d/check.sh draws from scene.tsx with --at, as a 4-frame composition: each frame k is the scene+// frozen at F[k], so its 3D rows come from stepping frames 0..4, the whole composition, not the sparse path+import { AbsoluteFill, Composition, Freeze, registerRoot, useCurrentFrame } from "raea";+import { Scene } from "./scene3d";+const F = [30, 150, 270, 330];+function Frozen() {+ const k = useCurrentFrame();+ return (+ <AbsoluteFill>+ <Freeze frame={F[k]}>+ <Scene />+ </Freeze>+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="frozen" component={Frozen} width={1280} height={720} fps={60} durationInFrames={4} />);diff --git a/bench/at-3d/scene.tsx b/bench/at-3d/scene.tsxnew file mode 100644index 00000000..e397b3aa--- /dev/null+++ b/bench/at-3d/scene.tsx@@ -0,0 +1,4 @@+// #26's composition: scene3d.tsx's scene over 360 frames, which bench/at-3d/check.sh draws four of with --at+import { Composition, registerRoot } from "raea";+import { Scene } from "./scene3d";+registerRoot(() => <Composition id="steps" component={Scene} width={1280} height={720} fps={60} durationInFrames={360} />);diff --git a/bench/at-3d/scene3d.tsx b/bench/at-3d/scene3d.tsxnew file mode 100644index 00000000..431dc731--- /dev/null+++ b/bench/at-3d/scene3d.tsx@@ -0,0 +1,27 @@+import { AbsoluteFill, useCurrentFrame } from "raea";+import { Canvas3D, Entity, ShaderMesh, ToneMapping } from "raea/3d";+import { Camera3d } from "raea/camera";+import { Transform } from "raea/transform";+// #26's scene: 200 small spheres orbiting, each with a per-frame uniform (scene.tsx sets a 360-frame timeline)+const W = `fn shade(in: VertexOutput) -> vec4<f32> { return vec4<f32>(u_level(), 0.6, 0.3, 1.0); }`;+const N = 200;+export function Scene() {+ const f = useCurrentFrame();+ return (+ <AbsoluteFill style={{ background: "#000" }}>+ <Canvas3D>+ <Camera3d transform={Transform.fromXyz(0, 0, 12).lookingAt([0, 0, 0], [0, 1, 0])} />+ <ToneMapping mode="none" />+ {Array.from({ length: N }, (_, i) => {+ const a = (i / N) * Math.PI * 2 + f * 0.01;+ const r = 2 + (i % 10) * 0.4;+ return (+ <Entity key={i} transform={Transform.fromXyz(Math.cos(a) * r, Math.sin(a) * r, 0)}>+ <ShaderMesh name={`s${i}`} shape={{ primitive: "Sphere", radius: 0.12 }} wgsl={W} uniforms={{ level: ((f + i) % 60) / 60 }} />+ </Entity>+ );+ })}+ </Canvas3D>+ </AbsoluteFill>+ );+}diff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rsindex 4ae24aec..c77da7a1 100644--- a/runtime/export/src/fed.rs+++ b/runtime/export/src/fed.rs@@ -49,13 +49,15 @@ pub(crate) fn frames_hold_3d(js: &Path, dir: &Path, frames: &[i64]) -> R<bool> {/// each waited on the JS thread and back, took the Rome film's 8,064 frames 6 s on a quiet machine and 38 s at load/// 50, before its engine could open. RAEA_BAKE_WORKERS sets how many runtimes (4; one for short timelines).pub(crate) fn scene_frames_to(js: &Path, dir: &Path, upto: i64) -> R<Option<(Vec<(i64, Frame)>, u32, u32, f64)>> {- scene_frames(js, dir, upto, true)+ scene_frames(js, dir, upto, true, &[])}/// `whole`: the whole composition at least (scene_frames_to); else only frames 0..upto, as a still at frame f needs/// (a frame-0 still of 10 000 cubes over 121 frames stepped all 121, 69 s for 2 frames' 12 s; docs/control.feature-/// FC1a)-pub(crate) fn scene_frames(js: &Path, dir: &Path, upto: i64, whole: bool) -> R<Option<(Vec<(i64, Frame)>, u32, u32, f64)>> {+/// FC1a). `wanted`, the frames a still or an `--at` list draws: when they and their neighbours (what reads a frame+/// either side, as a shutter does) are under half of the frames, only those are stepped (frames are pure) and each+/// frame between holds the stepped one before it, never drawn (#26: four `--at` frames of 360 stepped all 360, 64 s)+pub(crate) fn scene_frames(js: &Path, dir: &Path, upto: i64, whole: bool, wanted: &[i64]) -> R<Option<(Vec<(i64, Frame)>, u32, u32, f64)>> {edit_dir(dir);let runtime = |js: &Path| {let mut app = App::new();@@ -69,6 +71,7 @@ pub(crate) fn scene_frames(js: &Path, dir: &Path, upto: i64, whole: bool) -> R<Olet fps = num(&conf, "fps").unwrap_or(30.0);let length = num(&conf, "frames").unwrap_or(60.0) as i64;let total = if whole || upto <= 0 { length.max(upto) } else { upto };+ let around: std::collections::BTreeSet<i64> = wanted.iter().filter(|f| **f >= 0).flat_map(|&f| f.saturating_sub(1).max(0)..=f + 1).collect();type Scenes = Vec<(i64, Vec<Node3>, Option<String>)>;let step = |app: &mut App, a: i64, b: i64| -> R<Scenes> {let mut out: Scenes = Vec::with_capacity((b - a).max(0) as usize);@@ -84,33 +87,48 @@ pub(crate) fn scene_frames(js: &Path, dir: &Path, upto: i64, whole: bool) -> R<O})?;Ok(out)};- let workers = std::env::var("RAEA_BAKE_WORKERS").ok().and_then(|v| v.parse::<i64>().ok()).unwrap_or(4).clamp(1, 16).min((total / 240).max(1));- let span = (total + workers - 1) / workers;- let ranges: Vec<(i64, i64)> = (0..workers).map(|k| (k * span, ((k + 1) * span).min(total))).filter(|(a, b)| a < b).collect();- let later: Vec<std::thread::JoinHandle<R<Scenes>>> = ranges- .iter()- .skip(1)- .map(|&(a, b)| {- let js = js.to_path_buf();- let dir = dir.to_path_buf();- std::thread::Builder::new()- .name("raea scene rows".into())- .spawn(move || {- edit_dir(&dir);- let mut app = runtime(&js);- settle(&mut app, Some(-1), 20.0)?;- step(&mut app, a, b)- })- .map_err(|e| e.to_string())- })- .collect::<Result<_, _>>()?;- let mut scenes = match ranges.first() {- Some(&(a, b)) => step(&mut app, a, b)?,- None => Vec::new(),+ let scenes = if !around.is_empty() && around.len() * 2 < total as usize {+ // each run of neighbouring frames stepped as one range, the runs one after another in the one runtime+ let mut runs: Vec<(i64, i64)> = Vec::new();+ for &f in &around {+ match runs.last_mut() { Some(r) if r.1 == f => r.1 = f + 1, _ => runs.push((f, f + 1)) }+ }+ let mut stepped: Scenes = Vec::new();+ for (a, b) in runs {+ stepped.extend(step(&mut app, a, b)?);+ }+ raea_runtime_react::startup_mark(&format!("the 3D's rows: {} of {total} frames stepped (the wanted ones and their neighbours)", stepped.len()));+ (0..total.max(stepped.last().map_or(0, |s| s.0 + 1))).map(|f| (f, stepped[stepped.partition_point(|s| s.0 <= f).saturating_sub(1)].clone())).map(|(f, (_, scene, clear))| (f, scene, clear)).collect()+ } else {+ let workers = std::env::var("RAEA_BAKE_WORKERS").ok().and_then(|v| v.parse::<i64>().ok()).unwrap_or(4).clamp(1, 16).min((total / 240).max(1));+ let span = (total + workers - 1) / workers;+ let ranges: Vec<(i64, i64)> = (0..workers).map(|k| (k * span, ((k + 1) * span).min(total))).filter(|(a, b)| a < b).collect();+ let later: Vec<std::thread::JoinHandle<R<Scenes>>> = ranges+ .iter()+ .skip(1)+ .map(|&(a, b)| {+ let js = js.to_path_buf();+ let dir = dir.to_path_buf();+ std::thread::Builder::new()+ .name("raea scene rows".into())+ .spawn(move || {+ edit_dir(&dir);+ let mut app = runtime(&js);+ settle(&mut app, Some(-1), 20.0)?;+ step(&mut app, a, b)+ })+ .map_err(|e| e.to_string())+ })+ .collect::<Result<_, _>>()?;+ let mut scenes = match ranges.first() {+ Some(&(a, b)) => step(&mut app, a, b)?,+ None => Vec::new(),+ };+ for t in later {+ scenes.extend(t.join().map_err(|_| "a scene-rows runtime panicked".to_string())??);+ }+ scenes};- for t in later {- scenes.extend(t.join().map_err(|_| "a scene-rows runtime panicked".to_string())??);- }let frames: Vec<(i64, Frame)> = scenes.into_iter().map(|(f, scene, clear)| (f, Frame { screens: Vec::new(), mix: None, page: None, sounds: Vec::new(), scene, clear, same: false })).collect();if frames.iter().all(|(_, f)| f.scene.is_empty()) {return Ok(None);diff --git a/runtime/export/src/run.rs b/runtime/export/src/run.rsindex 827dbd2c..65cbf86e 100644--- a/runtime/export/src/run.rs+++ b/runtime/export/src/run.rs@@ -71,10 +71,10 @@ pub(crate) fn scene_program_checked(js: &Path, dir: &Path, upto: i64, wanted: Op}}raea_runtime_react::startup_mark("the 3D's rows: stepping React through the frames");- // a still steps only up to its frame, and one past it (what reads ahead, as a shutter might, has it); anything- // else steps the whole composition+ // a still or an --at list steps only its frames and their neighbours (scene_frames), through one past the last+ // (what reads ahead, as a shutter might, has it); anything else steps the whole compositionlet got = match wanted {- Some(&[f]) if f >= 0 => scene_frames(js, dir, upto.max(f + 1) + 1, false)?,+ Some(w) if !w.is_empty() => scene_frames(js, dir, upto.max(w.iter().max().map_or(0, |f| f + 1)) + 1, false, w)?,_ => scene_frames_to(js, dir, upto)?,};let Some((frames, w, h, fps)) = got else { return Ok(None) };@@ -82,10 +82,10 @@ pub(crate) fn scene_program_checked(js: &Path, dir: &Path, upto: i64, wanted: Opraea_runtime_react::startup_mark(&format!("the 3D's rows: {} frames stepped", frames.len()));let p = program(&frames, w, h, fps);raea_runtime_react::startup_mark("the 3D's rows: program made");- // a still: its own frame (the frames are 0..upto in order)- let seen = match wanted {- Some(&[f]) if f >= 0 && (f as usize) < frames.len() => f as usize..f as usize + 1,- _ => 0..frames.len(),+ // a still or an --at list: its own frames (the rest are only stepped, or copies: scene_frames)+ let frames: Vec<(i64, Frame)> = match wanted.map(|w| w.iter().copied().collect::<std::collections::HashSet<i64>>()) {+ Some(w) => frames.into_iter().filter(|(f, _)| w.contains(f)).collect(),+ None => frames,};// 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 end@@ -96,7 +96,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[seen], w, h, fps)+ scene::told(&o.0, w, h, fps)}));Ok(Some(p))}