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
layers LA1-LA2: captions marked data-raea-role="caption", and RAEA_LAYER renders one layer of an export (captions, graphics, under)
Zachary Guglin9df6d769e34a
diff --git a/Cargo.lock b/Cargo.lockindex a1bd6812..a5ef7b24 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -15429,6 +15429,7 @@ dependencies = ["raea-runtime-look","raea-runtime-scene2d","raea-sys-frame",+ "raea-sys-layers","raea-sys-procmat","raea-sys-wear","serde_json",diff --git a/runtime/bundle/src/cache.rs b/runtime/bundle/src/cache.rsindex 62d6141d..029c7f5c 100644--- a/runtime/bundle/src/cache.rs+++ b/runtime/bundle/src/cache.rs@@ -11,8 +11,8 @@ use super::*;pub fn export_cache(tsx: &Path, js: &Path, out: &Path, args: &[String]) -> Option<PathBuf> {let ext = out.extension()?.to_str()?.to_ascii_lowercase();// RAEA_FRAME_LOG measures a render, so it renders (a hit would hand back the earlier file and write no log)- // RAEA_HIDE_MEDIA and RAEA_HIDE_LAYERS draw a page the bundle doesn't say (CSS the render adds): never the cache's- let hides = std::env::var_os("RAEA_HIDE_MEDIA").is_some() || std::env::var_os("RAEA_HIDE_LAYERS").is_some();+ // RAEA_HIDE_MEDIA, RAEA_HIDE_LAYERS and RAEA_LAYER draw a page the bundle doesn't say (CSS the render adds): never the cache's+ let hides = ["RAEA_HIDE_MEDIA", "RAEA_HIDE_LAYERS", "RAEA_LAYER"].iter().any(|k| std::env::var_os(k).is_some());if !matches!(ext.as_str(), "mp4" | "mov") || hides || std::env::var_os("RAEA_AUDIO_BOUNCE").is_some() || std::env::var_os("RAEA_FRAME_LOG").is_some() {return None;}diff --git a/runtime/bundle/src/lib.rs b/runtime/bundle/src/lib.rsindex 167f4748..ad5ebf96 100644--- a/runtime/bundle/src/lib.rs+++ b/runtime/bundle/src/lib.rs@@ -60,7 +60,8 @@ pub fn bundle_css(js: &str) -> Option<String> {pub fn page_css(dir: &Path, w: u32, js: &Path) -> Option<String> {// its url()s as files from the edit's folder (raea-runtime-cssurls), where the CSS files it imports are foundlet bundled = std::fs::read_to_string(js).ok().and_then(|t| bundle_css(&t)).map(|c| css_file_urls(&c, dir, dir, |_| ()));- // then the layers RAEA_HIDE_LAYERS hides (the layer pass's oracle)+ // then the layers RAEA_HIDE_LAYERS hides (the layer pass's oracle), and what RAEA_HIDE_MEDIA and RAEA_LAYER hide (an+ // export's layers, docs/capcut.feature CC2b, docs/layers.feature LA2a)let parts: Vec<String> = [brand_css(dir, w), bundled, raea_sys_layers::hidden_css()].into_iter().flatten().collect();(!parts.is_empty()).then(|| parts.join("\n"))}diff --git a/runtime/page/src/elements.rs b/runtime/page/src/elements.rsindex 46ff7ecc..91165dd0 100644--- a/runtime/page/src/elements.rs+++ b/runtime/page/src/elements.rs@@ -249,8 +249,9 @@ pub(crate) fn page_props(kind: &str, props: Option<&Map<String, Value>>, dir: &P// a spreading box shadow's data-raea-bevy-shadow kept: Blitz spreads it as bevy_ui does, vendor/blitz-paint render/box_shadow.rs;// a Popover's data-raea-bevy-popover kept: Blitz places it beside its parent after layout, vendor/blitz-dom bevy_popover.rs;// the source stamps data-raea-loc, data-raea-use and data-raea-idx kept for the render manifest and the layer pass,- // engine/bundle stamp.rs)- const KEPT: [&str; 15] = ["data-raea-idx", "data-raea-start", "data-raea-bevy-debug", "data-raea-bevy-popover", "data-raea-bevy-shadow", "data-raea-bevy-text", "data-raea-bevy-slice", "data-raea-bevy-global-z", "data-raea-blend", "data-raea-bevy-scroll", "data-raea-bevy-ignore-scroll", "data-raea-bevy-scrollbar", "data-raea-bevy-thumb", "data-raea-loc", "data-raea-use"];+ // engine/bundle stamp.rs; a caption's data-raea-role kept: an export's layers find it by that, docs/layers.feature LA1a,+ // systems/layers hide.rs)+ const KEPT: [&str; 16] = ["data-raea-role", "data-raea-idx", "data-raea-start", "data-raea-bevy-debug", "data-raea-bevy-popover", "data-raea-bevy-shadow", "data-raea-bevy-text", "data-raea-bevy-slice", "data-raea-bevy-global-z", "data-raea-blend", "data-raea-bevy-scroll", "data-raea-bevy-ignore-scroll", "data-raea-bevy-scrollbar", "data-raea-bevy-thumb", "data-raea-loc", "data-raea-use"];if k == "children" || k == "key" || (k.starts_with("data-raea") && !KEPT.contains(&k.as_str())) || k == "data-props" || k == "data-shape" || k == "data-anim" || v.is_null() {continue;}@@ -376,3 +377,19 @@ mod css_url_tests {assert_eq!(super::css_urls(&dir, "linear-gradient(red, blue)"), "linear-gradient(red, blue)");}}++#[cfg(test)]+mod kept_tests {+ use serde_json::json;++ /// a caption's mark reaches the page, where an export's layers find it (docs/layers.feature LA1a); the renderer's+ /// other bookkeeping doesn't+ #[test]+ fn a_captions_mark_reaches_the_page() {+ let props = json!({"data-raea-role": "caption", "data-raea-owner": "x", "data-role": "kept", "children": "Hi"});+ let out = super::page_props("div", props.as_object(), std::path::Path::new("."));+ assert_eq!(out.get("data-raea-role"), Some(&json!("caption")));+ assert_eq!(out.get("data-role"), Some(&json!("kept")));+ assert!(!out.contains_key("data-raea-owner") && !out.contains_key("children"), "{out:?}");+ }+}diff --git a/runtime/scene/Cargo.toml b/runtime/scene/Cargo.tomlindex 2de06a5a..1cc38104 100644--- a/runtime/scene/Cargo.toml+++ b/runtime/scene/Cargo.toml@@ -21,3 +21,5 @@ raea-sys-procmat = { path = "../../systems/procmat" }raea-core-review = { path = "../../core/review" }# a part's layer key from its source stamp (docs/review.feature R2a)raea-sys-frame = { path = "../../systems/frame" }+# which of an export's layers draw the 3D (RAEA_LAYER, docs/layers.feature LA2a)+raea-sys-layers = { path = "../../systems/layers" }diff --git a/runtime/scene/src/lib.rs b/runtime/scene/src/lib.rsindex 9cfb46f3..a0f01502 100644--- a/runtime/scene/src/lib.rs+++ b/runtime/scene/src/lib.rs@@ -221,6 +221,7 @@ pub fn items_of(scene: &[Node3]) -> Vec<Item> {out.retain(|i| i.kind != "ambient" || own(i));}raea_core_review::camera_override(&mut out); // a review's fixed camera in place of the scene's own (RAEA_CAMERA)+ out.retain(|i| raea_sys_layers::draws_part(std::env::var("RAEA_LAYER").ok().as_deref(), i.kind)); // an export's layer (LA2a)out}diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.tsindex da19a46a..4d0a0543 100644--- a/sdk/timeline/src/read.ts+++ b/sdk/timeline/src/read.ts@@ -125,7 +125,7 @@ export type SeqEdit =/** a text sequence's words (TL7c) */| { op: "words"; i: number; text: string }/** words put on the picture from `at` for `frames`: a new sequence after the composition's last (TL7c) */- | { op: "text"; at: number; frames: number; text: string; /** how the words are drawn: a text style (registry.ts), raea's title when none */ style?: TextStyle }+ | { op: "text"; at: number; frames: number; text: string; /** how the words are drawn: a text style (registry.ts), raea's title when none */ style?: TextStyle; /** words said, made by the captions operation (TL7c): the code written marks them data-raea-role="caption", so an export puts them on its captions layer (docs/layers.feature LA1a) */ caption?: true }/** an effect put on the picture from `at` for `frames`: a new sequence holding an <Effect>, after the composition's last (TL7b) */| { op: "effect"; at: number; frames: number; kind: string; amount: number; /** a plugin's effect: the parts that draw it */ parts?: EffectPart[] }/** a recording put on the timeline from `at` for `frames` (TL8b): a new sequence holding an <Audio> of the file */@@ -431,7 +431,7 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {// words put on the picture: a new sequence of its ownif (op.clip.kind !== "text") return { why: "only words, effects, recordings and the project's files are added to a composition here" }const style = textStyleOf(op.clip.props?.style)- return [{ op: "text", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), text: (op.clip.name ?? "Text").trim() || "Text", ...(style && { style }) }]+ return [{ op: "text", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), text: (op.clip.name ?? "Text").trim() || "Text", ...(style && { style }), ...(op.clip.props?.said === true && { caption: true as const }) }]}case "captions": {// captions made from what is said (TL7c): each line a sequence of words of its own, in the captions' style@@ -439,7 +439,7 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {const tried = apply(t, op)if (!tried.ok) return { why: tried.why }const made = tried.timeline.tracks.find((k) => !t.tracks.some((o) => o.id === k.id))?.clips ?? []- return made.map((c) => ({ op: "text", at: c.start, frames: c.length, text: c.name ?? "", style: op.style }))+ return made.map((c) => ({ op: "text", at: c.start, frames: c.length, text: c.name ?? "", style: op.style, caption: true as const }))}default:return { why: `the composition's sequences don't take "${op.op}" yet` }diff --git a/sdk/timeline/test/captions.test.ts b/sdk/timeline/test/captions.test.tsindex 32ed2403..14a14914 100644--- a/sdk/timeline/test/captions.test.ts+++ b/sdk/timeline/test/captions.test.ts@@ -78,8 +78,15 @@ describe("TL7c: captions made from what is said", () => {test("in a composition each line is a sequence of words of its own", () => {const t = film()expect(seqEdits(t, { op: "captions", lines: [w("Hello there.", 0, 20), w("This is raea", 21, 40)], style: caption })).toEqual([- { op: "text", at: 0, frames: 20, text: "Hello there.", style: caption },- { op: "text", at: 21, frames: 19, text: "This is raea", style: caption },+ { op: "text", at: 0, frames: 20, text: "Hello there.", style: caption, caption: true },+ { op: "text", at: 21, frames: 19, text: "This is raea", style: caption, caption: true },])})++ test("a caption clip added on its own is still a caption in the code; other words aren't (docs/layers.feature LA1a)", () => {+ const t = film()+ const said = { id: "text-9", kind: "text", name: "Said here", props: { said: true }, start: 0, length: 30 }+ expect(seqEdits(t, { op: "add", kind: "text", clip: said })).toEqual([{ op: "text", at: 0, frames: 30, text: "Said here", caption: true }])+ expect(seqEdits(t, { op: "add", kind: "text", clip: { ...said, props: {} } })).toEqual([{ op: "text", at: 0, frames: 30, text: "Said here" }])+ })})diff --git a/systems/layers/src/hide.rs b/systems/layers/src/hide.rsindex 528ad8f6..dd2f2a6b 100644--- a/systems/layers/src/hide.rs+++ b/systems/layers/src/hide.rs@@ -2,28 +2,62 @@//! element as CSS (this), a 3D part as its Visibility (runtime/scene). And the footage hidden (RAEA_HIDE_MEDIA), for//! the CapCut export (docs/capcut.feature CC2b): `1` hides every <Video> drawn from a file and the backgrounds of what//! holds one, so what's left is what raea draws over the footage; `under` keeps only those backgrounds, what raea-//! draws under it.+//! draws under it. And one layer of an export in layers (RAEA_LAYER, docs/layers.feature LA2a): `captions` draws only+//! what is marked data-raea-role="caption", `graphics` and `under` what RAEA_HIDE_MEDIA's `1` and `under` draw, less+//! the captions.use crate::Layer;+/// What a caption is marked with (docs/layers.feature LA1a): its element and everything inside it.+pub const CAPTION: &str = r#"[data-raea-role="caption"], [data-raea-role="caption"] *"#;++/// What holds a caption, outside it: drawn in the captions layer only so the caption inside it is.+const HOLDS: &str = r#":has([data-raea-role="caption"]):not([data-raea-role="caption"] *)"#;+/// RAEA_HIDE_LAYERS: the layers keyed (a key a line or comma) drawn hidden, each element with its stamps and all/// inside it; RAEA_HIDE_MEDIA: the footage (the page's only elements with data-raea-src) and what's over it or under-/// it, as above; as page CSS. None when neither hides anything.+/// it, as above; RAEA_LAYER: one layer of an export, which wins over RAEA_HIDE_MEDIA; as page CSS. None when none of+/// them hides anything.pub fn hidden_css() -> Option<String> {- let keys = std::env::var("RAEA_HIDE_LAYERS").unwrap_or_default();+ let var = |k: &str| std::env::var(k).ok();+ hiding_css(&var("RAEA_HIDE_LAYERS").unwrap_or_default(), var("RAEA_HIDE_MEDIA").as_deref(), var("RAEA_LAYER").as_deref())+}++/// `hidden_css` from its three settings' values, read from nowhere else. A RAEA_LAYER it doesn't know draws the page+/// as it is, and says so.+pub fn hiding_css(keys: &str, media: Option<&str>, layer: Option<&str>) -> Option<String> {let mut hide: Vec<String> = keys.split([',', '\n']).filter(|k| !k.trim().is_empty()).map(|k| layer_selector(k.trim())).collect();let mut css = String::new();- match std::env::var("RAEA_HIDE_MEDIA").as_deref() {- // an element holding footage paints its background before it, under it- Ok("1") => {- hide.push("[data-raea-src]".into());- css.push_str(":has([data-raea-src]) { background: transparent !important; box-shadow: none !important; }\n");+ // the footage hidden as RAEA_HIDE_MEDIA's `1` or `under` hides it+ fn footage(hide: &mut Vec<String>, css: &mut String, mode: &str) {+ match mode {+ // an element holding footage paints its background before it, under it+ "1" => {+ hide.push("[data-raea-src]".into());+ css.push_str(":has([data-raea-src]) { background: transparent !important; box-shadow: none !important; }\n");+ }+ "under" => {+ hide.extend(["[data-raea-src]".into(), ":not(:has([data-raea-src]))".into()]);+ css.push_str(":has([data-raea-src]) { color: transparent !important; text-shadow: none !important; }\n");+ }+ _ => {}+ }+ }+ match layer {+ Some("captions") => {+ // the page draws nothing inside a hidden element (vendor/blitz-paint render.rs), so what holds a caption is+ // cleared rather than hidden, as RAEA_HIDE_MEDIA's `under` clears what holds footage, and everything else+ // is hidden; the root's background is cleared too, which the canvas takes from it+ css.push_str("html, body { background: transparent !important; }\n");+ css.push_str(&format!("{HOLDS} {{ background: transparent !important; border-color: transparent !important; box-shadow: none !important; outline: none !important; }}\n"));+ hide.push(format!(":not({HOLDS}, [data-raea-role=\"caption\"], [data-raea-role=\"caption\"] *)"));}- Ok("under") => {- hide.extend(["[data-raea-src]".into(), ":not(:has([data-raea-src]))".into()]);- css.push_str(":has([data-raea-src]) { color: transparent !important; text-shadow: none !important; }\n");+ Some(mode @ ("graphics" | "under")) => {+ footage(&mut hide, &mut css, if mode == "graphics" { "1" } else { "under" });+ hide.push(CAPTION.into());}- _ => {}+ Some(other) => eprintln!("raea: RAEA_LAYER={other} isn't a layer (captions, graphics or under); the page is drawn whole"),+ None => footage(&mut hide, &mut css, media.unwrap_or_default()),}if !hide.is_empty() {css.push_str(&format!("{} {{ visibility: hidden !important; }}", hide.join(", ")));@@ -31,6 +65,19 @@ pub fn hidden_css() -> Option<String> {(!css.is_empty()).then_some(css)}+/// Whether an export's layer (RAEA_LAYER's value) draws the composition's 3D: the graphics do, as everything raea+/// draws over the footage; captions and what's under the footage don't (docs/layers.feature LA2a). 3D is drawn by+/// Bevy, not the page, so the page's CSS can't hide it: runtime/scene leaves its parts out instead.+pub fn draws_3d(layer: Option<&str>) -> bool {+ !matches!(layer, Some("captions" | "under"))+}++/// Whether an export's layer draws a part of the 3D of `kind` (runtime/scene's): every part, or in a layer that draws+/// none of the 3D (draws_3d) only its cameras, so its view still renders, empty.+pub fn draws_part(layer: Option<&str>, kind: &str) -> bool {+ draws_3d(layer) || matches!(kind, "camera" | "rendercam")+}+/// The CSS selector of the element a layer key names, and of everything inside it: "loc[#index][|use|use…]" as its/// data-raea-loc, data-raea-idx and data-raea-use (engine/bundle stamp.rs)pub fn layer_selector(key: &str) -> String {diff --git a/systems/layers/src/lib.rs b/systems/layers/src/lib.rsindex e1ec4aa8..ea38a6c5 100644--- a/systems/layers/src/lib.rs+++ b/systems/layers/src/lib.rs@@ -15,7 +15,7 @@ mod page;mod scene;pub use file::Recorder;-pub use hide::{hidden_css, layer_selector};+pub use hide::{CAPTION, draws_3d, draws_part, hidden_css, hiding_css, layer_selector};pub use raster::{Tri, raster};#[cfg(feature = "page")]pub use page::page_ids;diff --git a/systems/layers/src/tests.rs b/systems/layers/src/tests.rsindex 380e9571..f2871f17 100644--- a/systems/layers/src/tests.rs+++ b/systems/layers/src/tests.rs@@ -94,3 +94,44 @@ fn a_layer_key_selects_its_element_alone() {let s = layer_selector("card.tsx:2:10#2|comp.tsx:6:27#2|x.tsx:1:1");assert!(s.starts_with(r#"[data-raea-loc="card.tsx:2:10"][data-raea-idx="2"][data-raea-use="comp.tsx:6:27#2|x.tsx:1:1"]"#), "{s}");}++#[test]+fn the_footage_hidden_draws_as_it_did() {+ // RAEA_HIDE_MEDIA's CSS as it was before docs/layers.feature: the CapCut export's passes don't change+ assert_eq!(hiding_css("", None, None), None);+ assert_eq!(hiding_css("", Some("1"), None).unwrap(), ":has([data-raea-src]) { background: transparent !important; box-shadow: none !important; }\n[data-raea-src] { visibility: hidden !important; }");+ assert_eq!(hiding_css("", Some("under"), None).unwrap(), ":has([data-raea-src]) { color: transparent !important; text-shadow: none !important; }\n[data-raea-src], :not(:has([data-raea-src])) { visibility: hidden !important; }");+}++#[test]+fn an_exports_layers_split_the_captions_from_the_rest() {+ // docs/layers.feature LA2a: captions alone; the graphics and what's under the footage without them+ let captions = hiding_css("", None, Some("captions")).unwrap();+ // what holds a caption is cleared, not hidden (the page draws nothing inside a hidden element); the rest is hidden+ assert!(captions.contains(r#":has([data-raea-role="caption"]):not([data-raea-role="caption"] *) { background: transparent !important;"#), "{captions}");+ assert!(captions.ends_with(r#":not(:has([data-raea-role="caption"]):not([data-raea-role="caption"] *), [data-raea-role="caption"], [data-raea-role="caption"] *) { visibility: hidden !important; }"#), "{captions}");+ assert!(captions.contains("html, body { background: transparent !important; }"), "{captions}");+ let graphics = hiding_css("", None, Some("graphics")).unwrap();+ assert_eq!(graphics, format!("{}, {CAPTION} {{ visibility: hidden !important; }}", hiding_css("", Some("1"), None).unwrap().trim_end_matches(" { visibility: hidden !important; }")));+ let under = hiding_css("", None, Some("under")).unwrap();+ assert_eq!(under, format!("{}, {CAPTION} {{ visibility: hidden !important; }}", hiding_css("", Some("under"), None).unwrap().trim_end_matches(" { visibility: hidden !important; }")));+ // RAEA_LAYER wins over RAEA_HIDE_MEDIA; layers hidden by key stay hidden in every layer+ assert_eq!(hiding_css("", Some("under"), Some("graphics")), Some(graphics));+ assert!(hiding_css("a.tsx:3:5", None, Some("captions")).unwrap().contains(r#"[data-raea-loc="a.tsx:3:5"]"#));+ // a layer it doesn't know draws the page whole+ assert_eq!(hiding_css("", Some("1"), Some("text")), None);+}++/// docs/layers.feature LA2a: the captions and under layers draw none of the 3D, keeping only its cameras; the+/// graphics layer and a render that isn't an export draw it all+#[test]+fn a_layer_without_3d_keeps_only_the_cameras() {+ let all = ["camera", "mesh", "directional", "text", "rendercam", "splat"];+ let kinds = |layer: Option<&str>| all.iter().filter(|k| draws_part(layer, k)).copied().collect::<Vec<_>>();+ for layer in [Some("captions"), Some("under")] {+ assert_eq!(kinds(layer), ["camera", "rendercam"], "{layer:?}");+ }+ for layer in [None, Some("graphics")] {+ assert_eq!(kinds(layer).len(), 6, "{layer:?}");+ }+}