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
A still of a 3D composition no plugin carries state for draws only its own frame, not every frame before it (#77). Every engine installs the plugin clock (some plugin is always registered), so catch_up rendered each frame before a still in full: render graph, shadow views and submit, about 90 ms a frame in a film, and --at 2448 took 226 s. The engine now steps through those frames only when the rows hold something a plugin carries from frame to frame (raea_runtime_plugins::steps): a component or resource of a type from outside Bevy's own scene and render crates and raea's (a rigid body, a particle effect, Bevy's animation, time or states; a short type name, which could be anyone's), a driven mesh, or a row kind not known to be frame-pure. Keyed component rows land on their frame however it is reached. The film's --at 2448: 226 s -> 20 s, pixel-identical; a physics still at frame 100 (avian) still steps all 100 frames. bench/at-cost checks that a frame-pure still steps none.
shinyobjectz4b8157f98c3c
diff --git a/bench/at-cost/check.sh b/bench/at-cost/check.shindex 504acd8d..eb584ca4 100755--- a/bench/at-cost/check.sh+++ b/bench/at-cost/check.sh@@ -1,10 +1,13 @@#!/bin/bash# A still late in a long 3D composition costs about what one early in it does (#77). A still at --at F stepped React# only near F, but held every frame before it as copies, keyed each changing column on all of them and evaluated and-# kept every one in the timeline: a film's --at 2448 took 234 s and 7.1 GB against 9 s and 3.1 GB at --at 30.-# 200 turning cubes over 3618 frames are drawn at --at 30 and --at 2448. The peak memory at 2448 must stay under 1.6x-# the one at 30 (the #60 build: 2.3x), and the 2448 still must match the same scene drawn at frame 30 with its clock-# moved on 2418 frames (within 1 level, as frames are pure), so the shortcut changes no pixel. Exits 1 on a failure.+# kept every one in the timeline; and the engine drew every frame before F (catch_up: the plugin clock, installed in+# every build, though nothing in the scene was a plugin's): a film's --at 2448 took 234 s and 7.1 GB against 9 s and+# 3.1 GB at --at 30. 200 turning cubes over 3618 frames, with Bevy's own components on them, are drawn at --at 30 and+# --at 2448. The peak memory at 2448 must stay under 1.6x the one at 30 (the #60 build: 2.3x); the engine must step no+# frame to reach 2448 (RAEA_PLUGIN_TRACE; was 2447); and the 2448 still must match the same scene drawn at frame 30+# with its clock moved on 2418 frames (within 1 level, as frames are pure), so the shortcut changes no pixel. A scene+# a plugin steps is still stepped: runtime/plugins' only_rows_... test. Exits 1 on a failure.# bench/at-cost/check.sh (RAEA_BIN: the raea to run, default target/release/raea)cd "$(dirname "$0")/../.." || exit 2BIN=${RAEA_BIN:-$PWD/target/release/raea}@@ -19,12 +22,14 @@ import { Cuboid, Mesh3d } from "raea/mesh";import { DirectionalLight } from "raea/light";import { Transform, Quat } from "raea/transform";import { Camera3d } from "raea/camera";+import { BevyComponent } from "raea/3d";function Shot() {const f = useCurrentFrame() + $2;const parts = Array.from({ length: 200 }, (_, i) => (<Mesh3d key={i} transform={Transform.fromXyz((i % 20) - 10, Math.floor(i / 20) - 5, -8).withRotation(Quat.fromEuler("XYZ", 0, f * 0.01 + i, 0))}><Cuboid half_size={[0.3, 0.3, 0.3]} /><StandardMaterial base_color="#ff7a1a" />+ {i === 0 ? <BevyComponent type="bevy_light::NotShadowCaster" value={{}} /> : null}</Mesh3d>));return (@@ -49,6 +54,9 @@ early=$(peak early "$OUT/late.tsx" 30) && late=$(peak late "$OUT/late.tsx" 2448)ratio=$(echo "scale=2; $late / $early" | bc)if (( late * 10 < early * 16 )); then echo "ok --at 2448 peaks at ${ratio}x --at 30 ($((late >> 20)) MB, $((early >> 20)) MB)"else echo "FAIL --at 2448 peaks at ${ratio}x --at 30 ($((late >> 20)) MB against $((early >> 20)) MB), wanted under 1.6x"; status=1; fi+steps=$(RAEA_PLUGIN_TRACE=1 "$BIN" render "$OUT/late.tsx" --at 2448 -o "$OUT/trace" 2>&1 | grep -c "^plugin clock: .* step$")+if (( steps == 0 )); then echo "ok --at 2448 draws no frame before it"+else echo "FAIL --at 2448 drew $steps frames before it, wanted none (the scene has nothing a plugin carries)"; status=1; fimax=$(magick "$OUT/late/frame-00000.png" "$OUT/moved/frame-00000.png" -compose difference -composite -format "%[fx:int(maxima*255+0.5)]" info:)if (( max <= 1 )); then echo "ok frame 2448 matches the scene moved on to it at frame 30 (largest difference $max)"else echo "FAIL frame 2448 differs from the scene moved on to it at frame 30 by up to $max levels"; status=1; fidiff --git a/engine/render/src/engine.rs b/engine/render/src/engine.rsindex c0c7c656..6024b9d4 100644--- a/engine/render/src/engine.rs+++ b/engine/render/src/engine.rs@@ -276,9 +276,10 @@ impl Engine {}/// The registered Bevy plugins' frame clock: the frames before f stepped through (one update each, their readbacks- /// dropped), from a new App made from the load when f is before the last frame stepped. Nothing without plugins.+ /// dropped), from a new App made from the load when f is before the last frame stepped. Nothing without plugins, or+ /// when the load's rows give them nothing to step (plugins::steps: a frame-pure edit's still draws only its frame).fn catch_up(&mut self, f: i64) -> Result<(), String> {- if !plugins::active(self.app.world()) {+ if !plugins::active(self.app.world()) || self.replay.is_none() {return Ok(());}if f < self.app.world().resource::<plugins::PluginClock>().stepped {diff --git a/engine/render/src/engine/load.rs b/engine/render/src/engine/load.rsindex a96b3801..72680013 100644--- a/engine/render/src/engine/load.rs+++ b/engine/render/src/engine/load.rs@@ -13,9 +13,8 @@ impl Engine {if (prog.width, prog.height) != self.size() {return Err("the edit's size changed: make a new Engine".into());}- if plugins::active(self.app.world()) {- self.replay = Some((prog.clone(), inserted.to_vec()));- }+ // kept (and the frames before a frame stepped through: catch_up) only when the rows need steps (#77)+ self.replay = (plugins::active(self.app.world()) && plugins::steps(inserted)).then(|| (prog.clone(), inserted.to_vec()));let world = self.app.world_mut();let g = world.resource::<Gen>().0;world.insert_resource(Gen(if g == 255 { 1 } else { g + 1 }));diff --git a/runtime/plugins/src/lib.rs b/runtime/plugins/src/lib.rsindex 95149294..cc197c6c 100644--- a/runtime/plugins/src/lib.rs+++ b/runtime/plugins/src/lib.rs@@ -205,6 +205,23 @@ pub fn active(world: &World) -> bool {world.contains_resource::<PluginClock>()}+/// Whether an edit's rows give a plugin anything to carry from frame to frame: a driven mesh, a kind not known to be+/// frame-pure (a compute's buffers), or a component or resource row of a type from outside Bevy's own+/// scene and render crates and raea's (a plugin's: a rigid body, a particle effect; Bevy's animation, time or states).+/// Keyed rows land on their frame however it's reached, so without one a frame is the same however it was reached,+/// and a still at frame F needn't draw the F frames before it: a film's --at 2448 drew all of them, 217 s (#77).+pub fn steps(inserted: &[Tup]) -> bool {+ const PURE: &[&str] = &["camera", "light", "mesh", "model", "panel", "image", "audio", "master", "media", "text", "glyph", "decal", "fogvolume", "plate", "screenpage", "shape2d", "splat", "meshseq", "surface_shader", "entity"];+ const BEVY: &[&str] = &["bevy_camera", "bevy_ecs", "bevy_light", "bevy_mesh", "bevy_pbr", "bevy_post_process", "bevy_core_pipeline", "bevy_anti_alias", "bevy_render", "bevy_transform", "bevy_color", "bevy_image", "bevy_sprite", "bevy_text", "bevy_ui", "bevy_solari", "bevy_window"];+ // a short name could be anyone's: it steps+ let pure_type = |ty: &str| ["material:", "own:", "three:", "raea_"].iter().any(|p| ty.starts_with(p)) || (ty.contains("::") && BEVY.contains(&ty.split("::").next().unwrap_or("")));+ inserted.iter().any(|t| match t.kind.as_str() {+ "component" | "resource" => !s(&t.vals, "type").is_some_and(|ty| pure_type(&ty)),+ "mesh" => t.vals.get("driven").is_some_and(V::truthy),+ k => !PURE.contains(&k),+ })+}+/// Before an update: Time advances one frame when this update draws the frame after the last stepped, else not at all.pub fn arm(world: &mut World) {let f = world.resource::<Clock>().0;diff --git a/runtime/plugins/src/tests.rs b/runtime/plugins/src/tests.rsindex 5b2e2d50..b384606c 100644--- a/runtime/plugins/src/tests.rs+++ b/runtime/plugins/src/tests.rs@@ -131,3 +131,17 @@ fn a_material_row_sets_only_its_fields() {let err = insert_reflect(w, e, "material:bevy_pbr::pbr_material::StandardMaterial", &json!({"no_such": 1.0})).unwrap_err();assert!(err.contains("no field no_such"), "{err}");}++#[test]+fn only_rows_a_plugin_carries_from_frame_to_frame_need_the_frames_before_a_still_stepped() {+ let row = |kind: &str, vals: &[(&str, V)]| Tup { kind: kind.into(), id: "r".into(), vals: vals.iter().map(|(k, v)| (k.to_string(), v.clone())).collect() };+ let ty = |t: &str| row("component", &[("type", V::S(t.into()))]);+ // a film's rows: parts, lights, a camera and Bevy's own components (#77)+ let film = vec![row("camera", &[]), row("light", &[]), row("mesh", &[]), row("model", &[]), row("panel", &[]), row("entity", &[]), ty("bevy_light::NotShadowCaster"), ty("bevy_post_process::bloom::settings::Bloom"), ty("material:bevy_pbr::pbr_material::StandardMaterial"), ty("three:uniforms")];+ assert!(!steps(&film));+ for more in [ty("avian3d::dynamics::rigid_body::RigidBody"), ty("bevy_hanabi::ParticleEffect"), ty("bevy_animation::AnimationPlayer"), ty("RigidBody"), row("mesh", &[("driven", V::N(1.0))]), row("compute", &[])] {+ let mut rows = film.clone();+ rows.push(more.clone());+ assert!(steps(&rows), "{more:?} needs its frames stepped");+ }+}