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
Live play cuts from one <Environment> panorama to another, lit and with its sky, as a render does (part of #38). bevy/environment cuts from venice_sunset to museum_of_ethnography at frame 30. A render's camera row lists both panoramas at load (env_srcs) and keys which one each frame shows (env_i), and the engine bakes both lights up front. A live frame's row names only its own panorama, and env_srcs wasn't a column live frames send, so live play kept the first panorama for good: frames 30-59 of the case showed Venice in live play and in the parked live render route.
shinyobjectzba97a973c044
diff --git a/bench/live-3d/check.sh b/bench/live-3d/check.shindex a933543c..70d3829d 100755--- a/bench/live-3d/check.sh+++ b/bench/live-3d/check.sh@@ -5,7 +5,10 @@# also held against its full rows), and the two must be identical. They caught what live frames sent otherwise than# a render keys it: a spot's cone (spotlight), a zero scale's NaN rotation and a bulb's f32 place# (spherical_area_lights, lighting), a colour as rounded floats against its hex (screenshake), a rotation's sign-# (shapes); atmospheric_fog keeps the camera's own spawns, the at-3d scene a ShaderMesh's uniforms. Exits 1 on a failure.+# (shapes); atmospheric_fog keeps the camera's own spawns, the at-3d scene a ShaderMesh's uniforms; bevy/environment+# cuts from one panorama to another at frame 30, which live play never made or lit before that frame (#38), and+# material-field-0 animates a material field past the row columns, which a render drew wrong after frame 0 (#38).+# Exits 1 on a failure.# bench/live-3d/check.sh (RAEA_BIN: the raea to run, default target/release/raea)cd "$(dirname "$0")/../.." || exit 2BIN=${RAEA_BIN:-$PWD/target/release/raea}@@ -14,7 +17,8 @@ OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-live-3d.XXXXXX")trap 'rm -rf "$OUT"' EXITstatus=0for f in bench/at-3d/scene.tsx sdk/raea/bench/bevy-parity/3d/spotlight.tsx sdk/raea/bench/bevy-parity/3d/spherical_area_lights.tsx \- sdk/raea/bench/bevy-parity/3d/atmospheric_fog.tsx examples/games/screenshake.tsx examples/games/shapes.tsx examples/games/lighting.tsx; do+ sdk/raea/bench/bevy-parity/3d/atmospheric_fog.tsx examples/games/screenshake.tsx examples/games/shapes.tsx examples/games/lighting.tsx \+ sdk/raea/bench/bevy/environment/edit.tsx sdk/raea/bench/bevy-ts/cases/material-field-0.tsx; don=$(basename "$f" .tsx)RAEA_3D=program "$BIN" render "$f" -o "$OUT/$n.program.txt" > "$OUT/$n.program.log" 2>&1 || { echo "FAIL $f: the programmed render failed"; tail -3 "$OUT/$n.program.log"; status=1; continue; }RAEA_3D=live RAEA_LIVE3D_CHECK=1 "$BIN" render "$f" -o "$OUT/$n.live.txt" > "$OUT/$n.live.log" 2>&1 || { echo "FAIL $f: the live render failed: $(grep -o 'RAEA_LIVE3D_CHECK.\{0,160\}' "$OUT/$n.live.log" | head -1)"; status=1; continue; }diff --git a/engine/render/src/engine.rs b/engine/render/src/engine.rsindex c715db23..389e63d1 100644--- a/engine/render/src/engine.rs+++ b/engine/render/src/engine.rs@@ -261,11 +261,9 @@ impl Engine {}// a camera's frame looks, as the timeline's are each frame (relational), so a live game's look turns on tooself.app.world_mut().resource_mut::<FrameRows>().parse_looks();- // a glTF model loaded and set up before the frame that shows it draws- if spawned {- scene3d::await_models(&mut self.app)?;- }- Ok(())+ // a glTF model, and a panorama a live frame showed first (#38), set up before the frame that shows it draws+ if spawned { scene3d::await_models(&mut self.app)?; }+ environment::live_rows(&mut self.app, rows, &self.dir)}/// A live scene's rows dropped, by kind and id: their entities go (and the meshes and surfaces only they held).diff --git a/runtime/look/src/camera.rs b/runtime/look/src/camera.rsindex 59eeed0d..f1890ac1 100644--- a/runtime/look/src/camera.rs+++ b/runtime/look/src/camera.rs@@ -6,6 +6,28 @@ use super::*;/// A frame without depth of field: an f-stop so large no circle of confusion reaches a pixelpub const NO_DOF: f64 = 1.0e6;+/// A live frame's camera row (runtime/scene's LiveScene) with its <Environment>'s panoramas as every one shown so far:+/// a frame names only its own, so the row lists those `sent` last, then this frame's if it's new, with env_i pointing+/// into the list, as a render's row lists them all at load; the engine bakes one it hasn't seen when the row brings it+/// (raea-sys-environment's live_rows, #38).+pub fn env_shown(sent: Option<&V>, cam: &mut BTreeMap<String, V>) {+ let Some(V::S(now)) = cam.get("env_srcs").cloned() else { return };+ let mut list: Vec<String> = match sent {+ Some(V::S(s)) => serde_json::from_str(s).unwrap_or_default(),+ _ => Vec::new(),+ };+ let mine: Vec<String> = serde_json::from_str(&now).unwrap_or_default();+ let i = cam.get("env_i").map(V::num).unwrap_or(-1.0);+ if let Some(src) = mine.get(i.max(0.0) as usize).filter(|_| i > -0.5) {+ let at = list.iter().position(|s| s == src).unwrap_or_else(|| {+ list.push(src.clone());+ list.len() - 1+ });+ cam.insert("env_i".into(), V::N(at as f64));+ }+ cam.insert("env_srcs".into(), V::S(serde_json::to_string(&list).unwrap_or_default()));+}+pub fn camera(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String, V>) {let cams: Vec<Option<Item>> = all.iter().map(|its| its.iter().find(|i| i.kind == "camera").cloned()).collect();let id = "cam";diff --git a/runtime/scene/src/live.rs b/runtime/scene/src/live.rsindex 0a9b4a6a..7262d71e 100644--- a/runtime/scene/src/live.rs+++ b/runtime/scene/src/live.rs@@ -70,7 +70,7 @@ pub(crate) fn live_dynamic(kind: &str) -> &'static [&'static str] {pub(crate) fn cam_keyed(k: &str) -> bool {["lens_", "mb_", "up_", "view_"].iter().any(|p| k.starts_with(p))|| ["_qx", "_qy", "_qz", "_qw"].iter().any(|q| k.ends_with(q))- || matches!(k, "x" | "y" | "z" | "look_x" | "look_y" | "look_z" | "fov" | "focus" | "ortho" | "ambient" | "skybox_k" | "env_i" | "env_k" | "env_rot" | "sky_k" | "aberration" | "dof_aperture" | "paint_bands" | "paint_grain" | "paint_rag" | "paint_seed")+ || matches!(k, "x" | "y" | "z" | "look_x" | "look_y" | "look_z" | "fov" | "focus" | "ortho" | "ambient" | "skybox_k" | "env_srcs" | "env_i" | "env_k" | "env_rot" | "sky_k" | "aberration" | "dof_aperture" | "paint_bands" | "paint_grain" | "paint_rag" | "paint_seed")}impl LiveScene {@@ -90,6 +90,8 @@ impl LiveScene {cam.insert("bg".into(), V::S(bg));}camera(all, p, &mut cam);+ // an <Environment>'s panoramas: every one shown so far, as a render's row lists them all (#38)+ env_shown(self.cam.get("env_srcs"), &mut cam);if !all[0].iter().any(|i| i.kind == "camera") {// no camera this frame: a render holds the one before (filled)for k in ["x", "y", "z", "look_x", "look_y", "look_z", "fov", "focus"] {diff --git a/systems/environment/src/lib.rs b/systems/environment/src/lib.rsindex 9ae5a1e1..10c2ab2e 100644--- a/systems/environment/src/lib.rs+++ b/systems/environment/src/lib.rs@@ -301,18 +301,13 @@ pub fn environment(world: &mut World, e: Entity, vals: &BTreeMap<String, V>, ins}let widest = eqs.iter().map(|q| q.w).max().unwrap_or(1024) as u32;let size = (widest / 4).max(64).next_power_of_two().min(2048);- let maps: Vec<Handle<Image>> = eqs.iter().map(|q| {- let img = cubemap(q, size);- world.resource_mut::<Assets<Image>>().add(img)- }).collect();- // each panorama's light, filtered once by its own bake- let mut lights = Vec::new();- let mut bakes = Vec::new();- for m in &maps {- let (diffuse_map, specular_map) = filter_targets(&mut world.resource_mut::<Assets<Image>>(), size);- let light = EnvironmentMapLight { diffuse_map, specular_map, intensity: 0.0, ..default() };- bakes.push(world.spawn((EnvBake, GeneratedEnvironmentMapLight { environment_map: m.clone(), intensity: 0.0, ..default() }, light.clone())).id());+ // each panorama's cubemap and its light, filtered once by its own bake+ let (mut maps, mut lights, mut bakes) = (Vec::new(), Vec::new(), Vec::new());+ for q in &eqs {+ let (m, light, bake) = panorama(world, q, size);+ maps.push(m);lights.push(light);+ bakes.push(bake);}let i = num(vals, "env_i", 0.0).round().max(0.0) as usize;let rot = Quat::from_rotation_y(num(vals, "env_rot", 0.0));@@ -328,6 +323,74 @@ pub fn environment(world: &mut World, e: Entity, vals: &BTreeMap<String, V>, insOk(())}+/// A panorama made a cubemap of `size` and its light, with the bake that filters that light once.+fn panorama(world: &mut World, q: &Equirect, size: u32) -> (Handle<Image>, EnvironmentMapLight, Entity) {+ let map = world.resource_mut::<Assets<Image>>().add(cubemap(q, size));+ let (diffuse_map, specular_map) = filter_targets(&mut world.resource_mut::<Assets<Image>>(), size);+ let light = EnvironmentMapLight { diffuse_map, specular_map, intensity: 0.0, ..default() };+ let bake = world.spawn((EnvBake, GeneratedEnvironmentMapLight { environment_map: map.clone(), intensity: 0.0, ..default() }, light.clone())).id();+ (map, light, bake)+}++/// A live camera's panoramas as they come (#38): live play's camera row lists those its frames have shown so far+/// (runtime/scene's LiveScene), so one first seen mid-play is made and baked when the row brings it, beside the ones+/// before it at their face size, as a render's are all made at load (environment). A camera with none yet gets its+/// whole environment then.+fn grow(world: &mut World, e: Entity, vals: &BTreeMap<String, V>, inserted: &[Tup], dir: &Path) -> Result<(), String> {+ let Some(V::S(list)) = vals.get("env_srcs") else { return Ok(()) };+ let srcs: Vec<String> = serde_json::from_str(list).map_err(|e| format!("camera: env_srcs: {e}"))?;+ let Some((have, first)) = world.get::<EnvMaps>(e).map(|m| (m.0.len(), m.0[0].clone())) else {+ return environment(world, e, vals, inserted, dir);+ };+ if srcs.len() <= have || preview() {+ return Ok(());+ }+ let size = world.resource::<Assets<Image>>().get(&first).map_or(512, |i| i.width());+ for s in &srcs[have..] {+ let path = resolve_src(inserted, s, dir).map_err(|e| format!("Environment: {e}"))?;+ let q = equirect(&path).map_err(|e| format!("Environment: {e}"))?;+ let (map, _, bake) = panorama(world, &q, size);+ let mut m = world.get_mut::<EnvMaps>(e).ok_or("camera: its environment went")?;+ m.0.push(map);+ m.1.push(bake);+ }+ Ok(())+}++/// A live frame's camera rows (an Engine's set_rows): a panorama first shown now (runtime/scene's LiveScene sends+/// env_srcs when its list grows) made and baked beside the ones before it (grow), and its light filtered before the+/// frame draws, as one at load is (#38), by updates that draw nothing and step no time (the frame's own sets its step).+pub fn live_rows(app: &mut App, rows: &[Tup], dir: &Path) -> Result<(), String> {+ for t in rows {+ if t.kind != "camera" || !t.vals.contains_key("env_srcs") {+ continue;+ }+ let world = app.world_mut();+ let Some(e) = raea_sys_frame::store::find(world, &t.kind, &t.id) else { continue };+ let Some(row) = world.resource::<FrameRows>().vals(e).map(|v| v.into_owned()) else { continue };+ grow(world, e, &row, &[], dir)?;+ }+ let baking = |w: &mut World| w.query_filtered::<(), (With<EnvBake>, With<GeneratedEnvironmentMapLight>)>().iter(w).next().is_some();+ if !baking(app.world_mut()) {+ return Ok(());+ }+ let was = app.world_mut().remove_resource::<bevy::time::TimeUpdateStrategy>();+ app.world_mut().insert_resource(bevy::time::TimeUpdateStrategy::ManualDuration(std::time::Duration::ZERO));+ for _ in 0..8 {+ app.update();+ if !baking(app.world_mut()) {+ break;+ }+ }+ match was {+ Some(w) => app.world_mut().insert_resource(w),+ None => {+ app.world_mut().remove_resource::<bevy::time::TimeUpdateStrategy>();+ }+ }+ Ok(())+}+/// Each frame's panorama, light, turn and sky: the camera's light points at the targets of the panorama's bake, so/// switching the source switches the light that frame.pub fn sync_environment(frame: Res<FrameRows>, mut q: Query<(Entity, &EnvMaps, &mut EnvironmentMapLight, Option<&mut Skybox>), Without<EnvBake>>, bakes: Query<&EnvironmentMapLight, With<EnvBake>>) {