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 3D: a mesh's emissive colour is sent the frame it changes, with its strength (#106)
shinyobjectz5d320bc96ee6
diff --git a/runtime/live/tests/live_emissive.rs b/runtime/live/tests/live_emissive.rsnew file mode 100644index 00000000..eb77d125--- /dev/null+++ b/runtime/live/tests/live_emissive.rs@@ -0,0 +1,36 @@+//! A mesh's emissive in live 3D (an mp4 render draws a video's 3D live: raea-runtime-scene live.rs) follows its colour,+//! not only its strength. Tested here: raea-runtime-scene is at its 2,000-line limit.+use raea_core_program::ir::V;+use raea_runtime_react::scene::{LiveScene, Node3, Shot};++fn ball(emissive: &str, k: f64) -> Vec<Node3> {+ let node = |kind: &str, props: serde_json::Value, kids: Vec<Node3>| Node3 { kind: kind.into(), props: std::sync::Arc::new(props.as_object().unwrap().clone()), shape: None, at: None, kids: kids.into() };+ let mat = node("MeshStandardMaterial", serde_json::json!({"color": "#000000", "emissive": emissive, "emissive_nits": k}), vec![]);+ let mut mesh = node("Mesh", serde_json::json!({"name": "ball"}), vec![mat]);+ mesh.shape = Some("sphere(1)".into());+ vec![mesh]+}++/// A ball dark on its first frame glows blue from a later one, turns orange, and goes dark again: each change sends+/// the colour with its strength, on the fast path as on the full one (RAEA_LIVE3D_CHECK holds each fast frame against+/// the full path's). #106: a video kept the first frame's colour, so one that started black stayed black.+#[test]+fn a_live_mesh_sends_its_emissive_colour_when_it_changes() {+ // SAFETY: this binary's only test, so no other thread reads the environment+ unsafe { std::env::set_var("RAEA_LIVE3D_CHECK", "1") };+ let mut ls = LiveScene::default();+ ls.open(Shot { scene: &ball("#000000", 0.0), clear: None }, 64, 64, 30.0);+ let mut frame = |scene: Vec<Node3>| ls.frame(Shot { scene: &scene, clear: None }).0;+ let mesh = |set: &[raea_core_program::eval::Tup]| set.iter().find(|t| t.kind == "mesh").map(|t| (t.vals.get("emissive").cloned(), t.vals.get("emissive_k").map(V::num)));+ // still dark: no emissive sent (the first frame after open sends a mesh's visible column, as the full path always has)+ assert_eq!(mesh(&frame(ball("#000000", 0.0))).filter(|(e, k)| e.is_some() || k.is_some()), None);+ // from dark to blue: the colour and its strength+ assert_eq!(mesh(&frame(ball("#3399ff", 2.0))), Some((Some(V::S("#3399ff".into())), Some(2.0))));+ // the same again: nothing+ assert!(frame(ball("#3399ff", 2.0)).is_empty());+ // another hue at the same strength: the colour alone+ assert_eq!(mesh(&frame(ball("#ff8800", 2.0))), Some((Some(V::S("#ff8800".into())), None)));+ // dark again: black at no strength+ assert_eq!(mesh(&frame(ball("#000000", 2.0))), Some((Some(V::S("#000000".into())), Some(0.0))));+ assert!(frame(ball("#000000", 0.0)).is_empty());+}diff --git a/runtime/scene/src/fast.rs b/runtime/scene/src/fast.rsindex 44c0c210..01e8f7e1 100644--- a/runtime/scene/src/fast.rs+++ b/runtime/scene/src/fast.rs@@ -9,8 +9,8 @@ const PLACE: [&str; 10] = ["x", "y", "z", "q_x", "q_y", "q_z", "q_w", "scale_x",impl LiveScene {/// `diff(current(f))` for a frame whose parts are all known, without the rows: each known part's changing values worked out into a fixed array and held- /// against what was sent in place, as diff holds a row (the same rules: recoloured meshes keyed, the emissive strength- /// only where the first frame glows, opacity once seen-through, visible and scale back to 1, lights without visible),+ /// against what was sent in place, as diff holds a row (the same rules: recoloured meshes keyed, the emissive colour when it+ /// changes and its strength where the sent colour glows, opacity once seen-through, visible and scale back to 1, lights without visible),/// so a frame allocates only for what it changes. None, with nothing changed, when a part is new.pub(crate) fn frame_fast(&mut self, f: Shot) -> Option<(Vec<raea_core_program::eval::Tup>, Vec<(String, String)>)> {if self.rows.is_empty() {@@ -64,6 +64,8 @@ impl LiveScene {if it.kind == "panel" && self.panel_srcs.get(key.as_str()).map(|s| &**s) != it.props.get("src").and_then(Value::as_str) { return None }// an <Instances> placed elsewhere (`current` sent its list): the full path, which sends the new one (#85)if let Some(at) = &it.at && self.panel_srcs.get(key.as_str()).is_none_or(|s| !std::sync::Arc::ptr_eq(s, at) && s != at) { return None }+ // a mesh glowing in another colour than sent (none is black): the full path, which keys it (#106)+ if it.kind == "mesh" && it.material.as_ref().and_then(|m| m.props.get("emissive")).and_then(Value::as_str).and_then(hex_cow).filter(|e| e != "#000000").as_deref() != self.rows[id].sent.get("emissive").and_then(|v| if let V::S(s) = v { Some(s.as_str()) } else { None }) { return None }parts.push((i, id));}}@@ -243,7 +245,7 @@ impl LiveScene {set(&mut want, &mut nw, name, Some(c[k]), false);}}- if !r.first.contains_key("emissive") {+ if !r.sent.contains_key("emissive") || r.sent.get("emissive") == Some(&V::S("#000000".into())) {set(&mut want, &mut nw, "emissive_k", None, false);} else {set(&mut want, &mut nw, "emissive_k", Some(1.0), true);diff --git a/runtime/scene/src/live.rs b/runtime/scene/src/live.rsindex c0e6666b..b919411f 100644--- a/runtime/scene/src/live.rs+++ b/runtime/scene/src/live.rs@@ -315,12 +315,14 @@ impl LiveScene {}}}- // the emissive strength only where the first frame glows (a render's column), opacity once it's been- // see-through, scale back to 1: what a render's keyed column says on a frame this one leaves it out- if !r.first.contains_key("emissive") {- want.remove("emissive_k");- } else {- want.entry("emissive_k".into()).or_insert(V::N(1.0));+ // 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());+ let (em, was) = (row.get("emissive").cloned().unwrap_or_else(black), r.sent.get("emissive").cloned().unwrap_or_else(black));+ match em {+ _ if em != was => drop((want.insert("emissive".into(), em), want.entry("emissive_k".into()).or_insert(V::N(0.0)))),+ _ if em == black() => drop(want.remove("emissive_k")),+ _ => drop(want.entry("emissive_k".into()).or_insert(V::N(1.0))),}}if matches!(kind.as_str(), "mesh" | "glyph") && r.sent.contains_key("opacity") {