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
SG1: a 3D part whose shape or words change is spawned again; SG2: a text block keeps its own row
shinyobjectz83d8f8e30563
diff --git a/core/scene/src/kept.rs b/core/scene/src/kept.rsnew file mode 100644index 00000000..95e87039--- /dev/null+++ b/core/scene/src/kept.rs@@ -0,0 +1,202 @@+//! What a part's row keeps from the frame it was spawned in, and the guards that keep a later frame's change from being+//! lost (docs/stage-guards.feature SG1). The engine builds a part's mesh, its words' layout and its surface's maps once,+//! when its row is spawned; a later frame reaches only the columns it takes frame by frame (live_dynamic). So a live+//! scene spawns a part again when one of its kept columns changes (`respawns`), and a render's tracks are cut where a+//! part's kept inputs change (`split_kept`). A Sphere whose radius grows, a RichText whose words change and a Ribbon's+//! newest box each draw as their own frame has them, never as their first frame did. (11-21: every curve of the+//! mobile-ads essay broke into dashes, its counters read "0.0 MB" and its typed lines stopped half-typed.)++use std::hash::{Hash, Hasher};+use std::sync::Arc;++use serde_json::{Map, Value};++use crate::Item;++/// A row missing this many frames is dropped from the engine (its entity, mesh and surface freed) and forgotten: a game+/// that spawns entities with fresh names (`rock-${id}`) would otherwise keep every one it ever made, hidden. Coming back+/// later, it's a new row with the same values, so nothing drawn changes.+pub const LIVE_FORGET: u32 = 240;++/// The kinds a live frame keys column by column (live_dynamic); every other kind is diffed whole.+pub const LIVE_GROUPS: [&str; 5] = ["light", "mesh", "model", "panel", "decal"];++/// A <Model animations>'s keyed columns (its clips' times and weights) and a <Model morphs>'s (its targets' weights).+pub const MIX_COLS: [(&str, &str); 4] = [("mix0_t", "mix0_w"), ("mix1_t", "mix1_w"), ("mix2_t", "mix2_w"), ("mix3_t", "mix3_w")];+pub const GRAPH_COLS: [[&str; 2]; 16] = [["g0_w", "g0_t"], ["g1_w", "g1_t"], ["g2_w", "g2_t"], ["g3_w", "g3_t"], ["g4_w", "g4_t"], ["g5_w", "g5_t"], ["g6_w", "g6_t"], ["g7_w", "g7_t"], ["g8_w", "g8_t"], ["g9_w", "g9_t"], ["g10_w", "g10_t"], ["g11_w", "g11_t"], ["g12_w", "g12_t"], ["g13_w", "g13_t"], ["g14_w", "g14_t"], ["g15_w", "g15_t"]];+/// Up to 64 morph weights a model (Bevy takes 256; a MakeHuman face has 34 expression units).+pub const MORPH_COLS: [&str; 64] = ["morph0", "morph1", "morph2", "morph3", "morph4", "morph5", "morph6", "morph7", "morph8", "morph9", "morph10", "morph11", "morph12", "morph13", "morph14", "morph15", "morph16", "morph17", "morph18", "morph19", "morph20", "morph21", "morph22", "morph23", "morph24", "morph25", "morph26", "morph27", "morph28", "morph29", "morph30", "morph31", "morph32", "morph33", "morph34", "morph35", "morph36", "morph37", "morph38", "morph39", "morph40", "morph41", "morph42", "morph43", "morph44", "morph45", "morph46", "morph47", "morph48", "morph49", "morph50", "morph51", "morph52", "morph53", "morph54", "morph55", "morph56", "morph57", "morph58", "morph59", "morph60", "morph61", "morph62", "morph63"];++/// The columns a frame may change, per kind (what `rows_into` and `camera` key); everything else is the first frame's.+pub fn live_dynamic(kind: &str) -> &'static [&'static str] {+ match kind {+ "light" => &["lux", "lumens", "x", "y", "z", "dir_x", "dir_y", "dir_z", "rot_qx", "rot_qy", "rot_qz", "rot_qw", "inner", "outer", "frame_sets", "frame_set_i"],+ "mesh" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "rough", "metal", "emissive_k", "opacity", "sh_r", "sh_g", "sh_b", "rim_k", "spec_k", "outline_w", "pass", "inst"],+ "model" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "anim_t", "mix0_t", "mix0_w", "mix1_t", "mix1_w", "mix2_t", "mix2_w", "mix3_t", "mix3_w", "morph0", "morph1", "morph2", "morph3", "morph4", "morph5", "morph6", "morph7", "morph8", "morph9", "morph10", "morph11", "morph12", "morph13", "morph14", "morph15", "morph16", "morph17", "morph18", "morph19", "morph20", "morph21", "morph22", "morph23", "morph24", "morph25", "morph26", "morph27", "morph28", "morph29", "morph30", "morph31", "morph32", "morph33", "morph34", "morph35", "morph36", "morph37", "morph38", "morph39", "morph40", "morph41", "morph42", "morph43", "morph44", "morph45", "morph46", "morph47", "morph48", "morph49", "morph50", "morph51", "morph52", "morph53", "morph54", "morph55", "morph56", "morph57", "morph58", "morph59", "morph60", "morph61", "morph62", "morph63", "g0_w", "g0_t", "g1_w", "g1_t", "g2_w", "g2_t", "g3_w", "g3_t", "g4_w", "g4_t", "g5_w", "g5_t", "g6_w", "g6_t", "g7_w", "g7_t", "g8_w", "g8_t", "g9_w", "g9_t", "g10_w", "g10_t", "g11_w", "g11_t", "g12_w", "g12_t", "g13_w", "g13_t", "g14_w", "g14_t", "g15_w", "g15_t", "look", "glitch_explode", "glitch_scramble", "glitch_jitter", "glitch_snap", "glitch_smear_x", "glitch_smear_y", "glitch_smear_z", "glitch_seed", "cloth_frame", "screen_power", "pass", "inst"],+ "panel" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "screen_power", "screen_bright", "pass", "sheet_frame", "sheet_cols", "sheet_rows", "src"],+ "decal" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "opacity", "rough", "metal"],+ _ => &[],+ }+}++/// A camera column a render keys when it changes (raea-runtime-look camera.rs), which a live frame sends when it does:+/// its place and look, lens, roll (up_*), view window, ambient, sky and environment, aberration, depth of field, motion+/// blur, the paint look and its parts' rotations (*_qx..qw). The rest is the first frame's, as a render's is.+pub fn cam_keyed(k: &str) -> bool {+ // paint_cut: the paint look's worlds, each cut's centre, radius and style moving frame by frame (raea-runtime-look paint_cut_rows)+ ["lens_", "mb_", "up_", "view_", "paint_cut"].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_srcs" | "env_i" | "env_k" | "env_rot" | "sky_k" | "aberration" | "dof_aperture" | "paint_bands" | "paint_grain" | "paint_rag" | "paint_seed")+}++/// What a text block or a glyph takes frame by frame: its placement and whether it shows (text3d's sync_texts,+/// scene3d's sync_meshes; a glyph's colour and fade too, as col_* and opacity).+const PLACED: [&str; 16] = ["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "pass", "col_r", "col_g", "col_b", "opacity"];++/// A column a part's row keeps from its spawn, so that a change to it needs the part spawned again: not one the engine+/// takes frame by frame (live_dynamic, PLACED), nor its identity. A mesh's and a glyph's colour and a mesh's glow are+/// sent as columns once they change. A shader's uniforms ride in `three` and `shader`, which change on each frame an+/// animated uniform does: those stay with their own fix (frozen uniforms), not a part spawned every frame. A model is+/// spawned again only for a new file, never for its animation's columns.+pub fn kept_col(kind: &str, col: &str) -> bool {+ if matches!(col, "id" | "name") {+ return false;+ }+ match kind {+ "mesh" => !live_dynamic(kind).contains(&col) && !matches!(col, "color" | "emissive" | "three" | "shader"),+ "panel" | "decal" => !live_dynamic(kind).contains(&col),+ "model" => col == "src",+ "text" => !PLACED.contains(&col),+ "glyph" => matches!(col, "target" | "at" | "span" | "ch"),+ _ => false,+ }+}++/// Whether a row's kept columns differ from those its part was spawned with (`first`), so it must be spawned again.+pub fn respawns<T: PartialEq>(kind: &str, first: &std::collections::BTreeMap<String, T>, now: &std::collections::BTreeMap<String, T>) -> bool {+ let differs = |a: &std::collections::BTreeMap<String, T>, b: &std::collections::BTreeMap<String, T>| a.iter().any(|(k, v)| kept_col(kind, k) && b.get(k) != Some(v));+ differs(first, now) || differs(now, first)+}++/// A material's props that reach only columns taken frame by frame (colour, roughness, glow, fade, a toon surface's+/// keyed values) or the part's identity (its shader's source: surface_ident), so they never cut a track.+const MAT_LIVE: [&str; 14] = ["color", "roughness", "metalness", "emissive", "emissiveIntensity", "opacity", "shadowColor", "rimIntensity", "highlightIntensity", "outlineWidth", "uniforms", "shader", "vertexShader", "fragmentShader"];+/// A mesh's own props that its row keeps (meshes_rows): shadows, a page on it, its geometry's attributes, its layers.+const MESH_KEPT: [&str; 9] = ["shadow", "castShadow", "receiveShadow", "surface", "material", "driven", "attributes", "compressed", "layers"];+/// A RichText's props that its block keeps (texts_rows): its words, their runs, em, alignment, wrap and surface.+const TEXT_KEPT: [&str; 13] = ["text", "spans", "size", "align", "lineHeight", "maxWidth", "roughness", "metalness", "emissive", "emissiveIntensity", "unlit", "castShadow", "receiveShadow"];++fn hash_value(v: &Value, h: &mut impl Hasher) {+ match v {+ Value::Null => 0u8.hash(h),+ Value::Bool(b) => b.hash(h),+ Value::Number(n) => n.as_f64().unwrap_or(0.0).to_bits().hash(h),+ Value::String(s) => s.hash(h),+ Value::Array(a) => a.iter().for_each(|x| hash_value(x, h)),+ Value::Object(o) => o.iter().for_each(|(k, x)| {+ k.hash(h);+ hash_value(x, h);+ }),+ }+}++fn hash_props(m: &Map<String, Value>, h: &mut impl Hasher, take: impl Fn(&str) -> bool) {+ for (k, v) in m.iter().filter(|(k, _)| take(k)) {+ k.hash(h);+ hash_value(v, h);+ }+}++/// A part's kept inputs as one number: what its row takes from the frame it's spawned in (its shape, its material's+/// maps and modes, its words and their glyphs, a model's file). Two frames of a part with the same number make the+/// same kept columns.+pub fn spawn_sig(it: &Item) -> u64 {+ let mut h = std::collections::hash_map::DefaultHasher::new();+ it.kind.hash(&mut h);+ match it.kind {+ "mesh" => {+ it.shape.hash(&mut h);+ if let Some(m) = &it.material {+ m.kind.hash(&mut h);+ // a three.js shader's spec is its uniforms and its source, the one keyed and the other its identity+ if &*m.kind != "ThreeShaderMaterial" {+ hash_props(&m.props, &mut h, |k| !MAT_LIVE.contains(&k));+ }+ }+ hash_props(&it.props, &mut h, |k| MESH_KEPT.contains(&k));+ }+ "text" => {+ hash_props(&it.props, &mut h, |k| TEXT_KEPT.contains(&k));+ for g in it.props.get("glyphs").and_then(Value::as_array).into_iter().flatten() {+ for k in ["at", "span", "ch"] {+ hash_value(g.get(k).unwrap_or(&Value::Null), &mut h);+ }+ }+ }+ "model" => hash_value(it.props.get("src").unwrap_or(&Value::Null), &mut h),+ // a picture's size and cut, a decal's maps and fade (panels_rows, decals_rows)+ "panel" | "decal" => hash_props(&it.props, &mut h, |k| if it.kind == "panel" { ["width", "height", "shadow", "cutout"] } else { ["src", "normalMap", "fade", "unlit"] }.contains(&k)),+ _ => {}+ }+ h.finish()+}++/// Tracks cut where a part's kept inputs change: each run of frames with the same spawn_sig is a track of its own+/// (`ID~1`, `ID~2` after the first), so a render's row never holds one frame's shape or words over another frame's.+pub fn split_kept(tracks: Vec<(String, Vec<Option<Item>>)>) -> Vec<(String, Vec<Option<Item>>)> {+ let mut out = Vec::with_capacity(tracks.len());+ for (id, track) in tracks {+ // a part in one frame (every live frame's, a still's) has nothing to cut+ if track.iter().flatten().nth(1).is_none() {+ out.push((id, track));+ continue;+ }+ let n = track.len();+ let mut runs: Vec<(u64, Vec<Option<Item>>)> = Vec::new();+ for (i, slot) in track.into_iter().enumerate() {+ let Some(it) = slot else { continue };+ let s = spawn_sig(&it);+ if runs.last().is_none_or(|(r, _)| *r != s) {+ runs.push((s, vec![None; n]));+ }+ runs.last_mut().expect("a run was just pushed").1[i] = Some(it);+ }+ out.extend(runs.into_iter().enumerate().map(|(k, (_, t))| (if k == 0 { id.clone() } else { format!("{id}~{k}") }, t)));+ }+ out+}++/// A mesh's kept inputs as a live scene's row holds them, so a frame on the fast path can tell when one changed (then+/// the full path, which spawns the part again). Its props are held, not copied: held, they are never changed in place+/// (read3d's props_in_place takes only props nobody else holds), so the same Arc is the same props, and only a new+/// one is hashed.+#[derive(Clone)]+pub struct KeptInputs {+ sig: u64,+ props: Arc<Map<String, Value>>,+ mat: Option<Arc<Map<String, Value>>>,+ shape: Option<Arc<str>>,+}++impl KeptInputs {+ pub fn of(it: &Item) -> KeptInputs {+ KeptInputs { sig: spawn_sig(it), props: it.props.clone(), mat: it.material.as_ref().map(|m| m.props.clone()), shape: it.shape.clone() }+ }++ /// Whether `it` has the kept inputs these were taken from; when it has, its props are held from now on.+ pub fn same(&mut self, it: &Item) -> bool {+ let held = |a: &Option<Arc<Map<String, Value>>>, b: Option<&Arc<Map<String, Value>>>| match (a, b) {+ (Some(a), Some(b)) => Arc::ptr_eq(a, b),+ (None, None) => true,+ _ => false,+ };+ if Arc::ptr_eq(&self.props, &it.props) && held(&self.mat, it.material.as_ref().map(|m| &m.props)) && self.shape == it.shape {+ return true;+ }+ if spawn_sig(it) != self.sig {+ return false;+ }+ *self = KeptInputs::of(it);+ true+ }+}diff --git a/core/scene/src/lib.rs b/core/scene/src/lib.rsindex 4eee724d..776c9402 100644--- a/core/scene/src/lib.rs+++ b/core/scene/src/lib.rs@@ -7,9 +7,11 @@ use std::collections::BTreeMap;use bevy::math::Mat4;use serde_json::{Map, Value};+mod kept;mod media;mod parts;mod props;+pub use kept::*;pub use media::*;pub use parts::*;pub use props::*;diff --git a/docs/stage-guards.feature b/docs/stage-guards.featurenew file mode 100644index 00000000..b22ccf25--- /dev/null+++ b/docs/stage-guards.feature@@ -0,0 +1,215 @@+@spec+Feature: Stage guards: a 3D render an agent can't break+ Shane, 2026-11-21, on the mobile-ads essay's 3D cut (projects/mobile-ads, compositions/film2): "every aspect it was+ totally broken looking and text, cards, overlays, etc all were so incredibly broken we must have uncovered something+ bad". Then: "diagnose the 3D issues with text, glyphs, layouts, staging, blocking and why things are flipping back+ and forth on scale/size ... how to make sure an agent using raea cannot physically make them again".++ What the diagnosis found (11-21). The repros are in projects/mobile-ads: compositions/diag/kept-props.tsx,+ kept-props2.tsx, kept-props3.tsx, compositions/glyph-atlas-probe.tsx, and the measures tools/cam-diag.ts,+ tools/text-diag.ts and tools/at-diag.ts. Each repro renders in a second or two.+ 1. A 3D part's shape and a RichText's words, size and colour are made once, when the part's row is first spawned+ (engine/render/src/engine/spawn.rs, spawn_3d). A later frame's values reach the live row (apply_rows), but only+ placement, visibility, material and pictures are applied from it (runtime/scene3d sync.rs sync_meshes and+ sync_pictures; systems/text3d sync_texts).+ - kept-props.tsx: over 30 frames, a Sphere's radius, a Cuboid's half_size and a RichText's words hold their+ first frame's values. Growth by the transform's scale follows the frame, and so does a part remounted each+ frame.+ - kept-props2.tsx: a RichText's colour and size and a Text3D's letters hold too. A material's colour, an+ ImagePlane's picture and RichText's own enter reveal follow the frame.+ - In the film: every curve broke into dashes. stage.tsx's Ribbon is a chain of boxes whose newest box grows,+ and each box kept the length it was born with. A count read "0.0 MB" until its chunk ended, and typed code+ lines stopped wherever their first frame left them.+ 2. A RichText mounted where another unmounted takes over its row. It draws the old words at its own place, and its+ own glyph colours land on the old glyphs. In kept-props3.tsx, "FROM ITS STORE PAGE" drew as "FOUR OPENINGS"+ with one letter red. In the film this gave "A RENDE? ENGINE", "TALL · ?N APPS", "1.? MB" and a store card headed+ "…ENINGS". Every cut glyph traced so far came from this, not from the atlas.+ 3. There were two clocks. RichText's `at` is a frame of useCurrentFrame, so it counts in its composition's or+ Sequence's frames. The film's scenes took their own frame as a prop and passed scene frames. Rendered in+ 150-frame chunks, a reveal at scene frame 1013 never began, which is why the store quote never appeared+ (at-diag.ts). Rendered whole, every reveal came at once. 21 texts had an `at`.+ 4. The film was rendered in chunks, each in its own process, to get past 8 below. At each chunk's first frame,+ every frozen value snapped to that frame's value and then froze again. The network's red dot grew to full size+ in one frame at 1:10.06, the first frame of a chunk. Together with rows changing hands (2) and the camera (5),+ this is the "flipping back and forth on scale".+ 5. The camera path (stage.tsx camAt) is a Catmull-Rom through keys set at uneven times, with every segment+ running 0 to 1 regardless of its length. Of 155 keys in 13 paths, 51 see the camera's speed change 2x or more+ (up to 9.4x). The framing reverses 24 times within 2 s: in and then out, or one way and then the other+ (cam-diag.ts).+ 6. Type was set in the world. The placement wall's labels were 15–16 px tall at 1080 (text-diag.ts). Other labels+ lay on floors or on pages turned at an angle. The 2D type laid over the 3D didn't know where the parts were:+ words ran over the curves at 2:08, and a headline sat on the AppLovin card at 6:40. 45 entrances used an easing+ that overshoots full size.+ 7. The glyph atlas (bevy_rich_text3d 0.8) has its own fault. The glyph whose allocation doubles the atlas is drawn+ into the old bounds and stays cut (glyph-atlas-probe.tsx).+ 8. A 13,175-frame render in one process logged "Could not despawn entity" and grew from about 5 GB to 26 GB.++ None of this was caught:+ - raea check passed the film on loudness, freezes and flashes.+ - Its text checks read the 2D page only.+ - The contact check found one 1 cm touch.+ - `raea fingerprint things`, which finds camera lurches and empty frames, wasn't run.++ Each rule below makes one of these impossible to ship. Either the engine stops doing it, or the SDK refuses to write+ it, or the render fails with the part and the frame named.++ Background:+ Given the repros above, each a few seconds to render, and their measures+ And frame purity as control.feature and blitz-bevy H10 state it: a frame is the same however it is reached+ And the per-frame scene the contact check already reads (systems/contact: every part's kind, transform, shape and+ bounds; the camera)++ Rule: SG0. The bar first, before any fix++ Scenario: SG0. The repros become tests, and they fail today+ Given the plan+ | crate | file | lines | job |+ | raea-render (test) | engine/render/tests/frame_pure_3d.rs | 160 | each repro rendered as one sequence and frame by frame alone; frame N of both compared (SSIM, per part); fails while any part differs |+ | raea-render (test) | engine/render/tests/diag/*.tsx | 160 | kept-props, kept-props2, kept-props3, glyph-atlas-probe moved in from the project, with what each shows |+ Then the test fails on main today on radius, half_size, Text3D letters, RichText words, colour and size, the row+ taken over, and the atlas's cut glyph, and passes on transform scale, material colour, pictures and the reveal+ And every scenario below that the engine fixes turns one of its failures green++ Rule: The engine stops doing it++ Scenario: SG1. A part's shape and its type follow the frame+ The fix sits where rows are made, not in the engine: the engine keeps building a part once, at spawn, and a part+ whose kept columns change is spawned again. An mp4's 3D is made live frame by frame (raea-runtime-scene live.rs);+ a still's and RAEA_3D=program's rows are made from several frames at once (rows).+ Given the plan+ | crate | file | lines | job |+ | raea-core-scene | core/scene/src/kept.rs | 200 | kept_col: the columns a row keeps from its spawn, per kind; respawns; spawn_sig, a part's kept inputs as one number; split_kept; KeptInputs, the fast path's guard. The live column tables moved here from live.rs |+ | raea-runtime-scene | runtime/scene/src/live.rs | +25 | diff: a row whose kept columns changed is dropped with the rows under it and spawned again; a glyph's colour sent as col_r/g/b, as a mesh's is |+ | raea-runtime-scene | runtime/scene/src/fast.rs | +3 | the fast path takes the full path when a part's kept inputs changed |+ | raea-runtime-scene | runtime/scene/src/lib.rs | +1 | a render's mesh, model, panel, decal and text tracks cut where their kept inputs change |+ | raea-runtime-live | runtime/live/tests/stage_guards.rs | 160 | the tests: a shape spawned again, new words laid out again, a glyph's colour, a still's own shape and words |+ Then kept-props.tsx and kept-props2.tsx pass SG0+ And a Ribbon of 48 boxes drawn over 90 frames is solid in a sequence render, as it is frame by frame+ And a growing shape's cost is measured (one mesh a frame, cached): a 48-part curve drawn over 90 frames renders+ within 10% of the same frames alone+ # Status 11-21 (branch stage-guards): kept.rs, live.rs, fast.rs and the track cut are built, and+ # runtime/live/tests/stage_guards.rs passes (5 tests; live_emissive and live_sheet still pass). Left: SG0's+ # renders of the repros, and a shader's `three` and `shader` columns, whose uniforms change every frame+ # (frozen uniforms keep their own fix rather than a part spawned each frame).++ Scenario: SG2. A part never inherits another part's row+ The cause was live.rs: a text block kept the id its frame gave it (`text0` is the frame's first block), where a+ mesh, model, panel or decal has its identity's (its name, else what it draws). So a block mounted as another+ unmounted got the old one's row: the engine kept the old words and took the new glyphs' colours.+ Given the plan+ | crate | file | lines | job |+ | raea-runtime-scene | runtime/scene/src/live.rs | +3 | text blocks by identity, as the groups are; their glyphs follow their block's id |+ Then kept-props3.tsx passes: the new RichText draws its own words in its own colour, and the old one is gone+ And a part that unmounts while another mounts beside it changes nothing else's row+ # Status 11-21 (branch stage-guards): text blocks are rows by identity; a_new_text_never_takes_an_old_ones_row+ # passes. Fires, fog volumes, plates and the other kinds a live frame diffs whole still take their frame's id.++ Scenario: SG3. The atlas allocates before it draws+ Given bevy_rich_text3d 0.8 reads the atlas's size before it allocates a glyph (tess_glyph)+ When raea patches it ([patch] in Cargo.toml, a vendored copy, with the upstream issue filed)+ Then glyph-atlas-probe.tsx draws every glyph whole with no warm-up text+ And projects/mobile-ads components/stage.tsx Warm() comes out++ Scenario: SG4. A part that won't despawn fails the render+ # Status 11-21: a live scene now drops the rows under another first (a block's glyphs, a part's components), in a+ # respawn and when rows are forgotten, so a block no longer takes its glyphs' entities before their rows go.+ Then "Could not despawn entity" is an error naming the part and the frame, never a log line+ And a 13,000-frame 3D render's memory stays within 10% of its first minute's++ Rule: The SDK stops allowing it++ Scenario: SG5. One clock+ Given the plan+ | crate | file | lines | job |+ | @raea/render | sdk/render/src/3d/text.tsx | +12 | RichText refuses an `at` or `exitAt` outside its Sequence's frames |+ | @raea/render | sdk/render/src/3d/clock.ts | 40 | the same check for every part that takes a frame (Video's startFrom, Animate3d keys) |+ Then a reveal set after the composition ends is refused at its first frame: "RichText 'quote': at 1013 is after+ this composition's last frame (149). Give `at` in this Sequence's frames (useCurrentFrame), or put the scene+ in a <Sequence from>."+ And the 3D guide says a scene is a <Sequence>, never a frame passed down as a prop++ Scenario: SG6. Lines are lines+ Given the plan+ | crate | file | lines | job |+ | @raea/render | sdk/render/src/3d/line.tsx | 140 | Line3d: points, width, drawn up to p, round joins, one mesh (a swept outline); Tube for a round section |+ Then a curve is one part, solid at every frame, and the 3D guide's curve recipe uses it+ And SG12 flags a chain of more than 8 parts named `NAME-i` whose ends touch as "a line made of parts: Line3d"++ Scenario: SG7. A camera path that can't lurch+ Given the plan+ | crate | file | lines | job |+ | @raea/render | sdk/render/src/camera/path.ts | 160 | cameraPath(keys): keys timed in frames, a spline paced by time so speed carries smoothly across a key, `hold` keys where it stops, an ease only at the ends; pos, look and fov at any frame |+ Then cam-diag.ts on a path built with it finds no speed change over 1.5x across a key and no framing reversal+ within 2 s+ And the 3D guide's camera recipe uses it, and hand-written paths are left to the check (SG13)++ Scenario: SG8. Labels that read+ Given the plan+ | crate | file | lines | job |+ | @raea/render | sdk/render/src/3d/label.tsx | 120 | Label: type drawn in the page at a part's projected point, from the engine's own camera; sized in pixels of the frame (at least 22 at 1080); kept clear of the parts' projected boxes |+ Then type that points at a part is never at an angle, never tiny and never on top of the part+ And RichText stays for type that is itself part of the scene (a sign, a page in a book)++ Rule: The render fails when a frame would look broken+ Each check below reads the frame's scene (as systems/contact does) and the page's layout, runs in `raea render`+ and `raea check`, and reports the part, the frame and the fix, as P1 unless it says otherwise.++ Scenario: SG9. A frame looks the same however it is reached+ Given a render of more than 60 frames with 3D in it+ When raea render re-renders a sample alone: every 300th frame, each chunk's first, and the frame after any+ frame where more than 20 parts mount or unmount+ Then any part whose pixels differ beyond the encoder's noise is an error naming the part, the frame and the props+ that differ+ And this catches SG1–SG4 and any later fault of the same kind before a person sees it++ Scenario: SG10. 3D type that reads+ Then every RichText and Text3D is checked on every frame it shows:+ | measure | limit |+ | cap height on screen | at least 22 px at 1080 (scaled to the frame) |+ | its face against the line to camera | within 35° |+ | its box | inside the title-safe area |+ | parts in front of it | none covering it |+ | time held still on screen | its reading time (words ÷ 3 a second, plus 0.5 s) before it moves |+ | its reveal | finished before it unmounts |+ And on the film these flag the placement wall's labels (16 px), the floor labels (over 35°) and the store quote+ (a reveal that never starts)++ Scenario: SG11. 2D type stays off the parts+ Then a page text box that covers more than 10% of a 3D part's projected box is an error, unless one of them says+ allowOverlap+ And on the film this flags the words over the curves at 2:08 and the headline on the AppLovin card at 6:40++ Scenario: SG12. Nothing snaps+ Then a part whose projected size changes by more than 25% from one frame to the next, with no cut, is an error+ And so is a RichText whose words change without a remount, until SG1 lands+ And on the film this flags the red dot at 1:10.06 and every chunk's first frame in a curve's drawing++ Scenario: SG13. A camera that settles+ Then the camera's speed changing by more than 2x within 3 frames, or its framing reversing (in then out, one way+ then the other) within 1.5 s, is an error, and 1.5x is a warning+ And a camera still moving while type is up past the type's reading time is a warning+ And `raea fingerprint things`'s lurch check folds into this one, so it runs on every render++ Scenario: SG14. The frame is composed+ Then the part a shot is about (one a Label or pin points at, else the nearest named part) cut by the frame's edge+ for more than 10 frames is an error+ And under 8% of the frame showing any part, for more than 1 s, is an error+ And on the film these flag the AppLovin logo cut at 6:32, the dashboard cut at 0:40 and 7:00, and the empty frames+ at 3:40, 6:04 and 6:08++ Scenario: SG15. A broken render can't be posted+ Then `raea show` refuses a render whose record holds an open SG9–SG14 error, naming each, unless the agent passes+ `--despite CHECK "why"`, which the person sees on the item+ And the agent's hooks run SG10–SG14 on a composition's stills after each save (`raea check --quick`), so the+ fault shows before the first full render++ Rule: SG16. The 3D guide says it first+ Scenario: SG16. The guide's 3D rules, before any recipe+ Then sdk/guides (3d.md and craft/floor.md) and the raea skill say, before any recipe:+ | rule |+ | type goes in the page over the scene; a Label points at a part; RichText only for type in the world |+ | a scene is a <Sequence>; SDK parts read useCurrentFrame, never a frame passed down as a prop |+ | a curve is a Line3d; a camera is a cameraPath |+ | grow a part by its transform's scale until SG1 lands; remount it when its words change |+ | render frame-pure: SG9 runs on every render; a chunked render is a workaround, never the plan |+ And each rule names the check that enforces itdiff --git a/runtime/live/tests/stage_guards.rs b/runtime/live/tests/stage_guards.rsnew file mode 100644index 00000000..3251c5eb--- /dev/null+++ b/runtime/live/tests/stage_guards.rs@@ -0,0 +1,142 @@+//! Stage guards (docs/stage-guards.feature SG1, SG2, SG4): a 3D part draws as its own frame has it, however that frame+//! is reached. The mobile-ads essay (11-21) showed each fault in an mp4, whose 3D is made live frame by frame+//! (raea-runtime-scene live.rs), and in a still, whose rows are made from the frames around it (rows):+//! - a part's shape and a RichText's words held their first frame's (its curves broke into dashes, its counters read+//! "0.0 MB", its typed lines stopped half-typed);+//! - a RichText mounted as another went took that one's row, and drew its words in its own colours ("A RENDE? ENGINE");+//! - a glyph's colour held its first frame's.+//!+//! Tested here: raea-runtime-scene is at its 2,000-line limit. RAEA_LIVE3D_CHECK holds every frame the fast path makes+//! against the full path's.+use raea_core_program::eval::Tup;+use raea_core_program::ir::{Program, V};+use raea_runtime_react::scene::{LiveScene, Node3, Shot};+use serde_json::{Value, json};++fn check_on() {+ static ON: std::sync::Once = std::sync::Once::new();+ // SAFETY: every test calls this before it reads the environment, and the Once holds the others until it's set+ ON.call_once(|| unsafe { std::env::set_var("RAEA_LIVE3D_CHECK", "1") });+}++fn node(kind: &str, props: Value, kids: Vec<Node3>) -> Node3 {+ Node3 { kind: kind.into(), props: std::sync::Arc::new(props.as_object().unwrap().clone()), shape: None, at: None, kids: kids.into() }+}++/// A mesh with its shape and its own name ("" for none).+fn mesh(name: &str, shape: &str, color: &str) -> Node3 {+ let props = if name.is_empty() { json!({}) } else { json!({ "name": name }) };+ let mut m = node("Mesh", props, vec![node("MeshStandardMaterial", json!({ "color": color }), vec![])]);+ m.shape = Some(shape.into());+ m+}++/// A RichText of `words` in one colour, as raea/3d's RichText hands it on: its block and a glyph per letter.+fn words(name: &str, words: &str, color: &str) -> Node3 {+ let glyphs: Vec<Value> = words.char_indices().map(|(at, ch)| json!({ "at": at, "span": 0, "ch": ch.to_string(), "p": [0, 0, 0], "r": [0, 0, 0], "s": [1, 1, 1], "c": color, "o": 1 })).collect();+ let mut props = json!({ "text": words, "spans": [{ "t": words }], "size": 0.5, "glyphs": glyphs });+ if !name.is_empty() {+ props["name"] = json!(name);+ }+ node("RichText", props, vec![])+}++fn s(v: Option<&V>) -> String {+ match v {+ Some(V::S(s)) => s.clone(),+ _ => String::new(),+ }+}++/// The rows a frame spawns whole (those with the columns only a spawn reads), by kind.+fn spawned<'a>(set: &'a [Tup], kind: &str, col: &str) -> Vec<&'a Tup> {+ set.iter().filter(|t| t.kind == kind && t.vals.contains_key(col)).collect()+}++/// A Sphere whose radius changes, named so it keeps its row: dropped and spawned again with the new shape, on the fast+/// path's frames as on the full path's. The same shape again changes nothing.+#[test]+fn a_shape_that_changes_is_spawned_again() {+ check_on();+ let mut ls = LiveScene::default();+ ls.open(Shot { scene: &[mesh("a", "sphere(0.5)", "#ff0000")], clear: None }, 64, 64, 30.0);+ let id = |set: &[Tup]| spawned(set, "mesh", "shape").first().map(|t| (t.id.clone(), s(t.vals.get("shape"))));+ let (set, gone) = ls.frame(Shot { scene: &[mesh("a", "sphere(0.5)", "#ff0000")], clear: None });+ assert!(gone.is_empty() && id(&set).is_none(), "the same shape: nothing spawned or dropped");+ let (set, gone) = ls.frame(Shot { scene: &[mesh("a", "sphere(1)", "#ff0000")], clear: None });+ let (row, shape) = id(&set).expect("the new radius spawns the sphere again");+ assert_eq!(shape, "sphere(1)");+ assert_eq!(gone, vec![("mesh".to_string(), row.clone())], "its old row dropped first, under the same id");+ // a colour change alone is a column, never a new spawn+ let (set, gone) = ls.frame(Shot { scene: &[mesh("a", "sphere(1)", "#0000ff")], clear: None });+ assert!(gone.is_empty() && id(&set).is_none());+ assert!(set.iter().any(|t| t.id == row && t.vals.contains_key("col_b")));+}++/// A named RichText whose words change (a counter): its block and every glyph dropped, glyphs first (SG4: the block's+/// entity takes theirs with it), and spawned again with the new words, one glyph a letter.+#[test]+fn new_words_are_laid_out_again() {+ check_on();+ let mut ls = LiveScene::default();+ ls.open(Shot { scene: &[words("count", "0.0 MB", "#ffffff")], clear: None }, 64, 64, 30.0);+ let (set, gone) = ls.frame(Shot { scene: &[words("count", "12.5 MB", "#ffffff")], clear: None });+ let block = spawned(&set, "text", "spans");+ assert_eq!(block.len(), 1, "the block spawned again");+ assert!(s(block[0].vals.get("spans")).contains("12.5 MB"));+ let chars: String = spawned(&set, "glyph", "ch").iter().map(|t| s(t.vals.get("ch"))).collect();+ assert_eq!(chars, "12.5 MB", "a glyph a letter of the new words");+ assert_eq!(gone.len(), 7, "the old block and its six glyphs: {gone:?}");+ assert_eq!(gone.last().map(|(k, _)| k.as_str()), Some("text"), "glyphs dropped before their block: {gone:?}");+}++/// kept-props3.tsx: "FOUR OPENINGS" unmounts as "FROM ITS STORE PAGE" mounts, neither named. The new block is a row of+/// its own with its own words and colour; the old one's row is hidden, never handed on.+#[test]+fn a_new_text_never_takes_an_old_ones_row() {+ check_on();+ let mut ls = LiveScene::default();+ ls.open(Shot { scene: &[words("", "FOUR OPENINGS", "#ffffff")], clear: None }, 64, 64, 30.0);+ let (set, _) = ls.frame(Shot { scene: &[words("", "FOUR OPENINGS", "#ffffff")], clear: None });+ let old: Vec<String> = set.iter().map(|t| t.id.clone()).collect();+ let (set, _) = ls.frame(Shot { scene: &[words("", "FROM ITS STORE PAGE", "#ff3b30")], clear: None });+ let block = spawned(&set, "text", "spans");+ assert_eq!(block.len(), 1);+ assert!(s(block[0].vals.get("spans")).contains("FROM ITS STORE PAGE"));+ assert!(!old.contains(&block[0].id), "a row of its own, not the old block's");+ let glyphs = spawned(&set, "glyph", "ch");+ assert_eq!(glyphs.iter().map(|t| s(t.vals.get("ch"))).collect::<String>(), "FROM ITS STORE PAGE");+ assert!(glyphs.iter().all(|t| s(t.vals.get("target")) == block[0].id && s(t.vals.get("color")) == "#ff3b30"));+ // the old block hidden, its glyphs with it+ assert!(set.iter().any(|t| t.kind == "text" && t.id != block[0].id && t.vals.get("visible") == Some(&V::N(0.0))));+}++/// A RichText's colour that changes (kept-props2.tsx): sent to its glyphs as col_r/g/b, as a mesh's is.+#[test]+fn a_glyph_colour_follows_the_frame() {+ check_on();+ let mut ls = LiveScene::default();+ ls.open(Shot { scene: &[words("tag", "AB", "#ffffff")], clear: None }, 64, 64, 30.0);+ let (set, gone) = ls.frame(Shot { scene: &[words("tag", "AB", "#ff0000")], clear: None });+ assert!(gone.is_empty(), "a colour spawns nothing again");+ let glyphs: Vec<&Tup> = set.iter().filter(|t| t.kind == "glyph").collect();+ assert_eq!(glyphs.len(), 2);+ assert!(glyphs.iter().all(|t| t.vals.get("col_r") == Some(&V::N(1.0)) && t.vals.get("col_g") == Some(&V::N(0.0))), "{glyphs:?}");+}++/// The rows of a still, or of RAEA_3D=program, are made from several frames (a still's neighbours): a part whose shape+/// or words change between them is a row per run, each shown in its own frames, never the first frame's held over.+#[test]+fn a_still_draws_its_own_frames_shape_and_words() {+ let frames = [vec![mesh("a", "sphere(0.5)", "#ff0000"), words("count", "0.0 MB", "#ffffff")], vec![mesh("a", "sphere(1)", "#ff0000"), words("count", "12.5 MB", "#ffffff")]];+ let all: Vec<_> = frames.iter().map(|f| raea_runtime_scene::items_of(f)).collect();+ let mut p = Program::default();+ raea_runtime_scene::rows(&all, &mut p);+ let of = |kind: &str, col: &str| -> Vec<String> { p.spawns.iter().filter(|(k, _)| k == kind).flat_map(|(_, rows)| rows.iter().map(|r| s(r.get(col)))).collect() };+ let mut shapes = of("mesh", "shape");+ shapes.sort();+ assert_eq!(shapes, vec!["sphere(0.5)", "sphere(1)"]);+ let spans = of("text", "spans");+ assert_eq!(spans.len(), 2);+ assert!(spans[0].contains("0.0 MB") && spans[1].contains("12.5 MB"));+}diff --git a/runtime/scene/src/fast.rs b/runtime/scene/src/fast.rsindex ec3ae6f0..27a2dce3 100644--- a/runtime/scene/src/fast.rs+++ b/runtime/scene/src/fast.rs@@ -57,7 +57,8 @@ impl LiveScene {if it.kind == "mesh" && it.shape.is_none() {continue;}- if !self.rows.contains_key(id) {+ // a part whose kept inputs changed (its shape, a map, a picture's size): the full path, which spawns it again (SG1)+ if !self.rows.get_mut(id).is_some_and(|r| matches!(it.kind, "directional" | "point" | "spot" | "rect") || r.kept.as_mut().is_some_and(|k| k.same(it))) {return None;}// a panel showing another picture (`current` kept the last): the full path, which sends the new srcdiff --git a/runtime/scene/src/lib.rs b/runtime/scene/src/lib.rsindex a434679d..df73de9e 100644--- a/runtime/scene/src/lib.rs+++ b/runtime/scene/src/lib.rs@@ -20,8 +20,8 @@ use parts::*;mod models;use models::*;mod live;-pub use live::{LIVE_GROUPS, LiveScene, Shot, cam_keyed, live_dynamic};-use live::*;+pub use live::{LiveScene, Shot};+pub use raea_core_scene::{LIVE_GROUPS, cam_keyed, live_dynamic};mod fast;/// Gaussian splats' rows (<Splat>).@@ -286,10 +286,11 @@ impl Tracks {fn of(all: &[Vec<Item>]) -> Tracks {Tracks {lights: tracks_of(all, &["directional", "point", "spot", "rect"]),- meshes: tracks_of(all, &["mesh"]),- models: tracks_of(all, &["model"]),- panels: tracks_of(all, &["panel"]),- decals: tracks_of(all, &["decal"]),+ // cut where a part's shape, words, file or size change (SG1): a row keeps its first frame's+ meshes: split_kept(tracks_of(all, &["mesh"])),+ models: split_kept(tracks_of(all, &["model"])),+ panels: split_kept(tracks_of(all, &["panel"])),+ decals: split_kept(tracks_of(all, &["decal"])),fogs: tracks_of(all, &["fogvolume"]),fires: tracks_of(all, &["fire"]),grasses: tracks_of(all, &["grass"]),@@ -299,7 +300,7 @@ impl Tracks {plates: tracks_of(all, &["plate"]),meshseqs: tracks_of(all, &["meshseq"]),entities: tracks_of(all, &["entity"]),- texts: tracks_of(all, &["text"]),+ texts: split_kept(tracks_of(all, &["text"])),}}}diff --git a/runtime/scene/src/live.rs b/runtime/scene/src/live.rsindex 48757606..3b4e0460 100644--- a/runtime/scene/src/live.rs+++ b/runtime/scene/src/live.rs@@ -20,8 +20,10 @@ pub struct LiveScene {/// per row id: its kind, its first values, what was last sent, whether its colour has changed (a render keys/// col_r/g/b on every frame once it does), and the frames it has been missingpub(crate) rows: std::collections::HashMap<String, LiveRow>,- /// rows made per group (lights, meshes, models, panels, decals): the next one's number- pub(crate) made: [usize; 5],+ /// rows made per group (lights, meshes, models, panels, decals, texts): the next one's number+ pub(crate) made: [usize; 6],+ /// row id -> a part's kept inputs this frame (not a light's), for its row (the fast path's SG1 guard)+ pub(crate) kept_now: std::collections::HashMap<String, KeptInputs>,pub(crate) cam: BTreeMap<String, V>,/// frame 0 was stepped when play opened (live.rs), and nothing sincepub warm: bool,@@ -42,42 +44,7 @@ pub(crate) struct LiveRow {pub(crate) missing: u32,/// seen this frame (frame_fast's mark)pub(crate) seen: bool,-}--/// A row missing this many frames is dropped from the engine (its entity, mesh and surface freed) and forgotten: a game-/// that spawns entities with fresh names (`rock-${id}`) would otherwise keep every one it ever made, hidden. Coming back-/// later, it's a new row with the same values, so nothing drawn changes.-pub(crate) const LIVE_FORGET: u32 = 240;--/// The kinds a live frame keys column by column (live_dynamic); every other kind is diffed whole.-pub const LIVE_GROUPS: [&str; 5] = ["light", "mesh", "model", "panel", "decal"];--/// A <Model animations>'s keyed columns (its clips' times and weights) and a <Model morphs>'s (its targets' weights).-pub(crate) const MIX_COLS: [(&str, &str); 4] = [("mix0_t", "mix0_w"), ("mix1_t", "mix1_w"), ("mix2_t", "mix2_w"), ("mix3_t", "mix3_w")];-pub(crate) const GRAPH_COLS: [[&str; 2]; 16] = [["g0_w", "g0_t"], ["g1_w", "g1_t"], ["g2_w", "g2_t"], ["g3_w", "g3_t"], ["g4_w", "g4_t"], ["g5_w", "g5_t"], ["g6_w", "g6_t"], ["g7_w", "g7_t"], ["g8_w", "g8_t"], ["g9_w", "g9_t"], ["g10_w", "g10_t"], ["g11_w", "g11_t"], ["g12_w", "g12_t"], ["g13_w", "g13_t"], ["g14_w", "g14_t"], ["g15_w", "g15_t"]];-/// Up to 64 morph weights a model (Bevy takes 256; a MakeHuman face has 34 expression units).-pub(crate) const MORPH_COLS: [&str; 64] = ["morph0", "morph1", "morph2", "morph3", "morph4", "morph5", "morph6", "morph7", "morph8", "morph9", "morph10", "morph11", "morph12", "morph13", "morph14", "morph15", "morph16", "morph17", "morph18", "morph19", "morph20", "morph21", "morph22", "morph23", "morph24", "morph25", "morph26", "morph27", "morph28", "morph29", "morph30", "morph31", "morph32", "morph33", "morph34", "morph35", "morph36", "morph37", "morph38", "morph39", "morph40", "morph41", "morph42", "morph43", "morph44", "morph45", "morph46", "morph47", "morph48", "morph49", "morph50", "morph51", "morph52", "morph53", "morph54", "morph55", "morph56", "morph57", "morph58", "morph59", "morph60", "morph61", "morph62", "morph63"];--/// The columns a frame may change, per kind (what `rows_into` and `camera` key); everything else is the first frame's.-pub fn live_dynamic(kind: &str) -> &'static [&'static str] {- match kind {- "light" => &["lux", "lumens", "x", "y", "z", "dir_x", "dir_y", "dir_z", "rot_qx", "rot_qy", "rot_qz", "rot_qw", "inner", "outer", "frame_sets", "frame_set_i"],- "mesh" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "rough", "metal", "emissive_k", "opacity", "sh_r", "sh_g", "sh_b", "rim_k", "spec_k", "outline_w", "pass", "inst"],- "model" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "anim_t", "mix0_t", "mix0_w", "mix1_t", "mix1_w", "mix2_t", "mix2_w", "mix3_t", "mix3_w", "morph0", "morph1", "morph2", "morph3", "morph4", "morph5", "morph6", "morph7", "morph8", "morph9", "morph10", "morph11", "morph12", "morph13", "morph14", "morph15", "morph16", "morph17", "morph18", "morph19", "morph20", "morph21", "morph22", "morph23", "morph24", "morph25", "morph26", "morph27", "morph28", "morph29", "morph30", "morph31", "morph32", "morph33", "morph34", "morph35", "morph36", "morph37", "morph38", "morph39", "morph40", "morph41", "morph42", "morph43", "morph44", "morph45", "morph46", "morph47", "morph48", "morph49", "morph50", "morph51", "morph52", "morph53", "morph54", "morph55", "morph56", "morph57", "morph58", "morph59", "morph60", "morph61", "morph62", "morph63", "g0_w", "g0_t", "g1_w", "g1_t", "g2_w", "g2_t", "g3_w", "g3_t", "g4_w", "g4_t", "g5_w", "g5_t", "g6_w", "g6_t", "g7_w", "g7_t", "g8_w", "g8_t", "g9_w", "g9_t", "g10_w", "g10_t", "g11_w", "g11_t", "g12_w", "g12_t", "g13_w", "g13_t", "g14_w", "g14_t", "g15_w", "g15_t", "look", "glitch_explode", "glitch_scramble", "glitch_jitter", "glitch_snap", "glitch_smear_x", "glitch_smear_y", "glitch_smear_z", "glitch_seed", "cloth_frame", "screen_power", "pass", "inst"],- "panel" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "screen_power", "screen_bright", "pass", "sheet_frame", "sheet_cols", "sheet_rows", "src"],- "decal" => &["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x", "scale_y", "scale_z", "visible", "col_r", "col_g", "col_b", "opacity", "rough", "metal"],- _ => &[],- }-}--/// A camera column a render keys when it changes (raea-runtime-look camera.rs), which a live frame sends when it does:-/// its place and look, lens, roll (up_*), view window, ambient, sky and environment, aberration, depth of field, motion-/// blur, the paint look and its parts' rotations (*_qx..qw). The rest is the first frame's, as a render's is.-pub fn cam_keyed(k: &str) -> bool {- // paint_cut: the paint look's worlds, each cut's centre, radius and style moving frame by frame (raea-runtime-look paint_cut_rows)- ["lens_", "mb_", "up_", "view_", "paint_cut"].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_srcs" | "env_i" | "env_k" | "env_rot" | "sky_k" | "aberration" | "dof_aperture" | "paint_bands" | "paint_grain" | "paint_rag" | "paint_seed")+ pub(crate) kept: Option<KeptInputs>,}impl LiveScene {@@ -144,6 +111,7 @@ impl LiveScene {pub(crate) fn current(&mut self, f: Shot) -> (BTreeMap<String, V>, Vec<(String, String, BTreeMap<String, V>)>) {let all = vec![items_of(f.scene)];self.light_sig = scene_sig(&all[0]);+ self.kept_now.clear();// the camera's own spawns (its fog, sky...) in the frame's program with the restlet mut p = Program::default();let cam = self.camera_row(&all, f.clear, &mut p);@@ -161,7 +129,8 @@ impl LiveScene {let kind = track[0].as_ref().map(|i| i.kind).unwrap_or("directional");local.insert(if kind == "directional" { format!("sun{li}") } else { format!("{kind}{li}") }, key);}- for (prefix, group) in [("mesh", &tr.meshes), ("model", &tr.models), ("plane", &tr.panels), ("decal", &tr.decals)] {+ // a text block too (SG2: by its frame's place, a block mounted as another went took that one's row and words)+ for (prefix, group) in [("mesh", &tr.meshes), ("model", &tr.models), ("plane", &tr.panels), ("decal", &tr.decals), ("text", &tr.texts)] {for (k, (key, _)) in group.iter().enumerate() {local.insert(format!("{prefix}{k}"), key);}@@ -178,6 +147,7 @@ impl LiveScene {"model" => 2,"panel" => 3,"decal" => 4,+ "text" => 5,"camera" => continue,_ => {others.extend(rows.into_iter().map(|r| (kind.clone(), r)));@@ -198,6 +168,9 @@ impl LiveScene {}};live_id.insert(lid.clone(), id.clone());+ if let Some(it) = [("mesh", &tr.meshes), ("model", &tr.models), ("plane", &tr.panels), ("decal", &tr.decals)].into_iter().find_map(|(p, g)| g.get(lid.strip_prefix(p)?.parse::<usize>().ok()?)?.1[0].as_ref()) {+ self.kept_now.insert(id.clone(), KeptInputs::of(it));+ }row.insert("id".into(), V::S(id.clone()));// a light's colour, shadows and shafts as a table, so a frame's replaces the last whole (as_table)if kind == "light" {@@ -222,7 +195,7 @@ impl LiveScene {for (kind, mut row) in others {let Some(V::S(mut id)) = row.get("id").cloned() else { continue };if let Some(V::S(t)) = row.get("target").cloned() {- let Some(to) = (if t.starts_with("ent") || t.starts_with("text") || t == "cam" || kept.contains(&t) { Some(t.clone()) } else { live_id.get(&t).cloned() }) else { continue };+ let Some(to) = (if t.starts_with("ent") || t == "cam" || kept.contains(&t) { Some(t.clone()) } else { live_id.get(&t).cloned() }) else { continue };id = id.replacen(&t, &to, 1);row.insert("id".into(), V::S(id.clone()));row.insert("target".into(), V::S(to));@@ -243,7 +216,8 @@ impl LiveScene {p.spawns.push(("camera".into(), std::iter::once(cam).chain(more).collect()));for (kind, id, row) in rows {let first = row.clone();- self.rows.insert(id, LiveRow { kind: kind.clone(), first, sent: row.clone(), recoloured: false, missing: 0, seen: false });+ let kept = self.kept_now.remove(&id);+ self.rows.insert(id, LiveRow { kind: kind.clone(), first, sent: row.clone(), recoloured: false, missing: 0, seen: false, kept });p.spawns.push((kind, vec![row]));}p@@ -282,15 +256,23 @@ impl LiveScene {// the camera: whatever of it a render keys, and the ambient light (0 once there's none)out.extend(Self::camera_diff(&mut self.cam, &cam));let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();+ let mut dropped = Vec::new();for (kind, id, row) in rows {seen.insert(id.clone());+ // a kept column changed (its shape, its words, a map): dropped with the rows under it and spawned again with+ // this frame's values, which the engine would otherwise never read (SG1)+ if self.rows.get(&id).is_some_and(|r| respawns(&kind, &r.first, &row)) {+ self.drop_with_under(&id, &mut dropped);+ }+ let kept = self.kept_now.remove(&id);let Some(r) = self.rows.get_mut(&id) else {// first seen: its whole row, spawned with these values- self.rows.insert(id.clone(), LiveRow { kind: kind.clone(), first: row.clone(), sent: row.clone(), recoloured: false, missing: 0, seen: false });+ self.rows.insert(id.clone(), LiveRow { kind: kind.clone(), first: row.clone(), sent: row.clone(), recoloured: false, missing: 0, seen: false, kept });out.push(raea_core_program::eval::Tup { kind, id, vals: row.into_iter().filter(|(k, _)| k != "id").collect() });continue;};r.missing = 0;+ r.kept = kept;let mut want: BTreeMap<String, V> = BTreeMap::new();if !LIVE_GROUPS.contains(&kind.as_str()) {// a kind the groups don't key column by column: every column it has, sent when it changes@@ -303,7 +285,8 @@ impl LiveScene {want.insert(k.to_string(), v.clone());}}- if kind == "mesh" {+ // a glyph's too: its `color` is read only at spawn+ if matches!(kind.as_str(), "mesh" | "glyph") {// a colour other than its first: keyed from now on, as a render keys it once a part's colour changesif row.get("color") != r.first.get("color") {r.recoloured = true;@@ -316,6 +299,8 @@ impl LiveScene {}}}+ }+ if kind == "mesh" {// the emissive colour the frame it differs from what was sent (none is black), with its strength (0 once black:// #106, a video kept the first frame's); else the strength only where the sent colour glows (a render's column)let black = || V::S("#000000".into());@@ -376,12 +361,25 @@ impl LiveScene {out.push(raea_core_program::eval::Tup { kind: r.kind.clone(), id: id.clone(), vals });}}+ // the rows under another first (a glyph, a component): a block's entity takes its glyphs' with it (SG4)+ gone.sort_by_key(|(_, id)| !self.rows.get(id).is_some_and(|r| r.first.contains_key("target")));for (_, id) in &gone {self.rows.remove(id);self.ids.retain(|_, v| v != id);self.panel_srcs.retain(|k, _| self.ids.contains_key(k));}- (out, gone)+ dropped.extend(gone);+ (out, dropped)+ }++ /// A row dropped with the rows under it (its glyphs, its components), those under it first (SG4)+ fn drop_with_under(&mut self, id: &str, gone: &mut Vec<(String, String)>) {+ let under: Vec<String> = self.rows.iter().filter(|(_, r)| matches!(r.first.get("target"), Some(V::S(t)) if t == id)).map(|(u, _)| u.clone()).collect();+ for u in under.iter().map(String::as_str).chain([id]) {+ if let Some(r) = self.rows.remove(u) {+ gone.push((r.kind, u.to_string()));+ }+ }}}