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
SG10, SG14: 3D type behind a part and Text3D are checked; a part a Label names is the shot's subject
shinyobjectzcab9f4bb28bc
diff --git a/apps/scene/src/stage.rs b/apps/scene/src/stage.rsindex 393ba8dc..b8b3e433 100644--- a/apps/scene/src/stage.rs+++ b/apps/scene/src/stage.rs@@ -1,7 +1,9 @@//! `raea scene stage EDIT.tsx [--composition ID] [--from N] [--to N] [--json]`: every frame's scene stepped without//! drawing and held to the stage checks a render runs at its end (raea-sys-stage, docs/stage-guards.feature SG10-SG14)://! 3D type that can't be read, parts that snap, a camera that lurches or reverses, frames with nothing composed in-//! them. Errors fail it, as they fail a render, so it's the cheap look before one.+//! them. Errors fail it, as they fail a render, so it's the cheap look before one. It lays out no page, so what the+//! page holds waits for a render: its words over the parts (type-over-part), a Label's part as the shot's subject, and+//! a frame its words or pictures fill, which reads empty here and is said as a warning, not failed (SG11).use serde_json::json;@@ -24,11 +26,16 @@ pub(crate) fn cli(args: &[String]) -> Result<String, String> {let frames: Vec<_> = frames.into_iter().filter(|(f, _)| *f >= from && to.is_none_or(|t| *f <= t)).collect();let (Some(first), Some(last)) = (frames.first().map(|f| f.0), frames.last().map(|f| f.0)) else { return Err(format!("no frames from {from}")) };let nums: Vec<i64> = frames.iter().map(|(f, _)| *f).collect();- let fs = raea_sys_stage::check(&all_items(&frames), &nums, w, h, fps, "raea scene stage");+ let mut fs = raea_sys_stage::check(&all_items(&frames), &nums, w, h, fps, "raea scene stage");+ for f in fs.iter_mut().filter(|f| f.check == "frame-empty" && f.level == Level::Error) {+ f.level = Level::Warn;+ f.says.push_str(" (no page is laid out here: if its words or pictures fill these frames, a render passes them)");+ }let text = if args.iter().any(|a| a == "--json") {serde_json::to_string_pretty(&json!({"frames": [first, last], "findings": fs})).unwrap_or_default()} else {- fs.iter().map(raea_core_facts::Finding::line).chain([format!("frames {first} to {last}: {}", finding::count(&fs))]).collect::<Vec<_>>().join("\n")+ let note = "the page's checks (its words over parts, a Label's subject) run in raea render";+ fs.iter().map(raea_core_facts::Finding::line).chain([format!("frames {first} to {last}: {} ({note})", finding::count(&fs))]).collect::<Vec<_>>().join("\n")};if fs.iter().any(|f| f.level == Level::Error) {println!("{text}");diff --git a/docs/manual/reference/sdk/3d.md b/docs/manual/reference/sdk/3d.mdindex 1dba3334..9339220e 100644--- a/docs/manual/reference/sdk/3d.md+++ b/docs/manual/reference/sdk/3d.md@@ -2548,6 +2548,7 @@ from the first frame.| `depth` | `number` | extrusion depth (default 0.2) || `font` | `string` | a family (Inter by default, or another of raea's bundled faces) || `weight` | `number` | 100..900 (800 by default) |+| `read` | `boolean` | false: scenery (a sign seen in passing), not held to the type checks raea render runs on 3D type: its size on screen, its angle to the camera, the title-safe area, its reading time and parts in front of it. Words meant to be read are better as page type: a Label |### `ThreeShaderMaterialProps`diff --git a/docs/manual/reference/sdk/mesh.md b/docs/manual/reference/sdk/mesh.mdindex 0d864b48..c9139802 100644--- a/docs/manual/reference/sdk/mesh.md+++ b/docs/manual/reference/sdk/mesh.md@@ -114,7 +114,7 @@ One part, so a curve that grows is solid at every frame (never a chain of parts:| `normal` | `Vec3` | the way its face looks: the normal of the plane it lies in (left out: the plane of its points, else +z) || `children` | `ReactNode` | its material (a white StandardMaterial when left out) |-Also takes the props of `MeshProps` (`animate`, `name`, `pass`, `quaternion`, `allowOverlap`, `posed`, `shape`, `driven`, `shadow`, `material`, `castShadow`, `surface`, `receiveShadow`, `attributes`, `compressed`, `layers`); `PointerHandlers3d` (`onClick`, `onDrag`, `onDragEnd`, `onDragEnter`, `onDragLeave`, `onDragOver`, `onDragStart`, `onDrop`, `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerEnter`, `onPointerLeave`, `onPointerOver`, `onPointerOut`, `onWheel`); [`Mesh3dProps`](#mesh3dprops) (`visibility`, `transform`, `detail`).+Also takes the props of `MeshProps` (`animate`, `name`, `read`, `pass`, `quaternion`, `allowOverlap`, `posed`, `shape`, `driven`, `shadow`, `material`, `castShadow`, `surface`, `receiveShadow`, `attributes`, `compressed`, `layers`); `PointerHandlers3d` (`onClick`, `onDrag`, `onDragEnd`, `onDragEnter`, `onDragLeave`, `onDragOver`, `onDragStart`, `onDrop`, `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerEnter`, `onPointerLeave`, `onPointerOver`, `onPointerOut`, `onWheel`); [`Mesh3dProps`](#mesh3dprops) (`visibility`, `transform`, `detail`).### `Mesh2d`@@ -139,7 +139,7 @@ shadow="only" draws it with the shadow-only material (engine/render shadow_only.| `detail` | `Detail` | where it's drawn: its distances or sizes on screen, cross-faded, and its shadow (Detail; raea-sys-lod) || `children` | `ReactNode` | its material and child entities |-Also takes the props of `MeshProps` (`animate`, `name`, `pass`, `quaternion`, `allowOverlap`, `posed`, `shape`, `driven`, `shadow`, `material`, `castShadow`, `surface`, `receiveShadow`, `attributes`, `compressed`, `layers`); `PointerHandlers3d` (`onClick`, `onDrag`, `onDragEnd`, `onDragEnter`, `onDragLeave`, `onDragOver`, `onDragStart`, `onDrop`, `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerEnter`, `onPointerLeave`, `onPointerOver`, `onPointerOut`, `onWheel`).+Also takes the props of `MeshProps` (`animate`, `name`, `read`, `pass`, `quaternion`, `allowOverlap`, `posed`, `shape`, `driven`, `shadow`, `material`, `castShadow`, `surface`, `receiveShadow`, `attributes`, `compressed`, `layers`); `PointerHandlers3d` (`onClick`, `onDrag`, `onDragEnd`, `onDragEnter`, `onDragLeave`, `onDragOver`, `onDragStart`, `onDrop`, `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerEnter`, `onPointerLeave`, `onPointerOver`, `onPointerOut`, `onWheel`).Used in: [ui/render_ui_to_texture](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/ui/render_ui_to_texture.tsx), [ui/widgets/viewport_node](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/ui/widgets/viewport_node.tsx), [3d/fog](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/fog.tsx), [3d/vertex_colors](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/vertex_colors.tsx), [3d/rotate_environment_map](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/rotate_environment_map.tsx), [3d/transparency_3d](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/transparency_3d.tsx), [3d/spherical_area_lights](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/spherical_area_lights.tsx), [3d/animated_material](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/animated_material.tsx), and 54 more.@@ -181,7 +181,7 @@ A line through points in 3D with a round section (a pipe, a wire): one mesh, dra| `radius` | `number` | its radius in metres (0.025) || `sides` | `number` | sides around its section (12) |-Also takes the props of `MeshProps` (`animate`, `name`, `pass`, `quaternion`, `allowOverlap`, `posed`, `shape`, `driven`, `shadow`, `material`, `castShadow`, `surface`, `receiveShadow`, `attributes`, `compressed`, `layers`); `PointerHandlers3d` (`onClick`, `onDrag`, `onDragEnd`, `onDragEnter`, `onDragLeave`, `onDragOver`, `onDragStart`, `onDrop`, `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerEnter`, `onPointerLeave`, `onPointerOver`, `onPointerOut`, `onWheel`); [`Mesh3dProps`](#mesh3dprops) (`visibility`, `transform`, `detail`).+Also takes the props of `MeshProps` (`animate`, `name`, `read`, `pass`, `quaternion`, `allowOverlap`, `posed`, `shape`, `driven`, `shadow`, `material`, `castShadow`, `surface`, `receiveShadow`, `attributes`, `compressed`, `layers`); `PointerHandlers3d` (`onClick`, `onDrag`, `onDragEnd`, `onDragEnter`, `onDragLeave`, `onDragOver`, `onDragStart`, `onDrop`, `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerEnter`, `onPointerLeave`, `onPointerOver`, `onPointerOut`, `onWheel`); [`Mesh3dProps`](#mesh3dprops) (`visibility`, `transform`, `detail`).## Functionsdiff --git a/docs/manual/reference/sdk/text.md b/docs/manual/reference/sdk/text.mdindex b1b31af5..66d8bbe3 100644--- a/docs/manual/reference/sdk/text.md+++ b/docs/manual/reference/sdk/text.md@@ -185,6 +185,7 @@ multiplied into (scale, opacity) or replacing (color, visible) what the block's| `depth` | `number` | extrusion depth (default 0.2) || `font` | `string` | a family (Inter by default, or another of raea's bundled faces) || `weight` | `number` | 100..900 (800 by default) |+| `read` | `boolean` | false: scenery (a sign seen in passing), not held to the type checks raea render runs on 3D type: its size on screen, its angle to the camera, the title-safe area, its reading time and parts in front of it. Words meant to be read are better as page type: a Label |### `WordOptions`diff --git a/docs/stage-guards.feature b/docs/stage-guards.featureindex 6476ce67..eba9620b 100644--- a/docs/stage-guards.feature+++ b/docs/stage-guards.feature@@ -81,6 +81,7 @@ Feature: Stage guards: a 3D render an agent can't breakRule: The engine stops doing it+ @doneScenario: SG1. A part's shape and its type follow the frameThe fix sits where rows are made, not in the engine: the engine keeps building a part once, at spawn, and a partwhose kept columns change is spawned again. An mp4's 3D is made live frame by frame (raea-runtime-scene live.rs);@@ -106,7 +107,13 @@ Feature: Stage guards: a 3D render an agent can't break# uniforms go as `own:uniforms` rows, as a <Material>'s do (runtime/look own_uniforms, `ext` for a 3D mesh), and# raea-sys-shader own_live.rs packs them into the shaded material's slots when they change (ShaderExt slots_for).# `three` sends its uniforms each frame as `three:uniforms` rows (R3F11).+ # Status 11-22 (branch stage-guards-23): done. The Ribbon is engine/render/tests/diag/ribbon.tsx, a chain of 48+ # boxes whose newest grows, drawn over 90 frames, in frame-pure-3d's set: on 0.1.9 frames 0, 30, 60 and 89 of the+ # sequence match the frames alone at SSIM 1.000, no pixel off. Its cost against the same 48 boxes whole from frame+ # 0 (640x360, three runs each, the median): 2.99 s against 2.88 s; with the 1.4 s start-up taken out, 1.59 s+ # against 1.48 s, 7.5% more, inside 10%.+ @doneScenario: SG2. A part never inherits another part's rowThe cause was live.rs: a text block kept the id its frame gave it (`text0` is the frame's first block), where amesh, model, panel or decal has its identity's (its name, else what it draws). So a block mounted as another@@ -127,6 +134,8 @@ Feature: Stage guards: a 3D render an agent can't break# WHOLE): a_new_plate_never_takes_an_old_ones_row. An unnamed fire or fog has only its order to be known by, so# name the ones that come and go. Sprites, 2D shapes and bare entities keep their render ids, which components# target.+ # Status 11-22: done. kept-props3 passes SG0 on every sampled frame (SSIM 0.9998 or more), and+ # runtime/live/tests/stage_guards.rs holds "changes nothing else's row" for words and plates in L1.@doneScenario: SG3. The atlas allocates before it draws@@ -362,6 +371,7 @@ Feature: Stage guards: a 3D render an agent can't break# must brake for, and check() names exactly those 18 with the fix. One scene's keys weren't in time order: the# old path drew them anyway, and cameraPath refuses them.+ @doneScenario: SG8. Labels that readGiven the plan| crate | file | lines | job |@@ -376,6 +386,10 @@ Feature: Stage guards: a 3D render an agent can't break# capitals 32 px at 1080 by default and refused under 22, its box inside title-safe and growing away from the# nearer edge, a line and a dot to the point, nothing while the point is behind the camera or out of frame# (sdk/raea/conformance/label.test.tsx). It stands `gap` px off the point you give it: give the part's top.+ # Status 11-22 (branch stage-guards-23): done. Never at an angle (flat page type), never tiny (refused under 22+ # px), never on the part (it stands off the point given, and page words over a part are SG11's type-over-part+ # error). Its point now reaches the stage checks (the manifest's `points`), which make the part there the shot's+ # subject (SG14).Rule: The render fails when a frame would look brokenEach check below reads the frame's scene (as systems/contact does) and the page's layout, runs in `raea render`@@ -385,6 +399,7 @@ Feature: Stage guards: a 3D render an agent can't break(runtime/export/src/scene.rs), and run without drawing in `raea scene stage`, which moved with lint, explain andlight out of raea-runtime-export into raea-app-scene (apps/scene) so the export crate keeps room under 2,000 lines.+ @doneScenario: SG9. A frame looks the same however it is reachedGiven a render of more than 60 frames with 3D in itWhen raea render re-renders a sample alone: every 300th frame, each chunk's first, and the frame after any@@ -429,7 +444,8 @@ Feature: Stage guards: a 3D render an agent can't break# the cells it picked to update that frame, the rest keeping the last place's light at that place's exposure# (an exposure cut 0.992 to its still 25 frames on, 0.996 with it). tools/frame-pure-3d.sh holds both repros,# each composition a repro names at the bar it names (Solari's 0.99), and L1 runs it on Solari's and the traced- # scene's code too.+ # scene's code too. Landed 7e2df514de: in L1, kept-scenes 0.996-0.997 and solari-gone 0.997-0.998 to the frames+ # alone, none past the pixel bar.Given the plan| crate | file | lines | job || raea-app-direction | apps/direction/src/pure.rs | 234 | the sample, the stills and the alone frame, the patch, the parts under it, the findings |@@ -438,6 +454,7 @@ Feature: Stage guards: a 3D render an agent can't break| raea-runtime-export | runtime/export/src/lib.rs | +4 | write_manifest takes them || raea-sys-stage | systems/stage/src/framing.rs | +12 | on_screen: each part's box on screen, named |+ @doneScenario: SG10. 3D type that readsGiven the plan| crate | file | lines | job |@@ -445,6 +462,8 @@ Feature: Stage guards: a 3D render an agent can't break| raea-sys-stage | systems/stage/src/lib.rs | 183 | told and check, the frames as the checks read them, shots, runs, findings || raea-sys-stage | systems/stage/src/text.rs | 217 | each RichText's capitals on screen, its turn from the camera, its box against title-safe, its reveal, its reading time; `read={false}` for scenery || @raea/render | sdk/render/src/3d/text.tsx | +3 | RichText's `read` prop |+ | raea-sys-stage | systems/stage/src/cover.rs | 113 | parts in front of the words: a 3x3 grid's lines to the eye against each part's own box |+ | @raea/render | sdk/render/src/3d/shapes.tsx | +14 | Text3D's `read`, carried on its mesh || raea-app-scene | apps/scene/src/stage.rs | 38 | `raea scene stage`: every frame stepped without drawing, the checks, errors fail it || raea-app-scene | apps/scene/src/lib.rs | 59 | `raea scene`, moved from raea-runtime-export (lint and explain) with light.rs || raea-app-scene | apps/scene/src/light.rs | 58 | `raea scene light`, moved |@@ -469,7 +488,23 @@ Feature: Stage guards: a 3D render an agent can't break# error on 33 clean scenes (gambit, sheet3d, lightbench, Stay, floor3, blender-loop). The film was rewritten since# the notes: its placement wall no longer exists, so the 16 px labels can't be named. Left: Text3D, and parts in# front of the words.+ # Status 11-22 (branch stage-guards-23): done. A Text3D is held to the same checks: its words and em come from its+ # mesh's shape (text3d("WORDS", size, ...)), one line centred on its origin; `read={false}` on the Text3D (or its+ # mesh) makes it scenery, and a Text3D cut into a solid is the solid's. Parts in front (cover.rs): the words' face+ # sampled on a 3x3 grid through the middle of the letters, each point's line to the eye tested against every+ # other part's own box in that part's space; more than half stopped more than an em short of the words, for half+ # a second, is a type-hidden error naming the part. Words never hide words (a block is mostly air), nor do+ # see-through parts (opacity under 0.5), a part round the camera, or a model (no box here). raea scene stage over+ # the 48 clean scenes: no finding added or lost. Over 14 scenes with 3D type: the heros game's spoken captions+ # (Text3D at 26 px capitals on a 1920-line frame, 39 needed, carried by a turning camera) give one type-small+ # error and two type-time warnings; nothing else changes. On the essay film: 26 type-hidden errors, every other+ # count the same. Looked at: its APK's file names behind the phone (3:17-3:23, none visible), the apk card's+ # words turned away behind the cards (3:28-3:31), and MON, WED and THU under the BRIEF, ASSETS and LIVE tokens+ # (1:21-1:48: the row reads TUE, FRI, SAT, SUN). First measured with a 3x2 grid and half the points: 35, the+ # other 9 false (words over words: "ASSETS behind VARIATION" read clearly) or partial (day labels whose lower+ # third the next tile cuts, still read).+ @doneScenario: SG11. 2D type stays off the partsGiven the plan| crate | file | lines | job |@@ -499,7 +534,11 @@ Feature: Stage guards: a 3D render an agent can't break# stage-guards-12: the 3D guide's rule 9 and the skill's 3D router name type-over-part and data-allow-overlap# (raea-skills #112). Branch stage-guards-13: the findings are said in the order they start (a HashMap's order# changed from run to run). Left: `raea scene stage` doesn't know the page, since it draws none.+ # Status 11-22 (branch stage-guards-23): done. `raea scene stage` lays out no page, by design: it is the look+ # before a render and draws nothing. It says the page's checks run in raea render, and a frame it reads empty is+ # a warning there, since the page's words or pictures may fill it; a render knows the page and fails it.+ @doneScenario: SG12. Nothing snapsGiven the plan| crate | file | lines | job |@@ -516,7 +555,11 @@ Feature: Stage guards: a 3D render an agent can't break# the frame is a warning (a tile recycled, a part thrown). Now 0 errors on film2 and on 33 clean scenes. Left:# the red dot at 1:10.06 and the chunks' first frames were drawn wrong by the engine from right props, which only# SG9's re-render sees; and RichText words changing without a remount (SG1).+ # Status 11-22: done. Wrong pictures from right props are what SG9's re-render sees, on every render of a film+ # with 3D (its whole-film fault fixed on stage-guards-22), and RichText words that change follow the frame (SG1,+ # kept-props in SG0).+ @doneScenario: SG13. A camera that settlesGiven the plan| crate | file | lines | job |@@ -544,12 +587,17 @@ Feature: Stage guards: a 3D render an agent can't break# Stay's own reversal (11-22): its montage's glasshouse pair (72.26-73.50 s) slid past the plant while aimed at# it; the move now ends where it comes nearest, and its words over the picture ('turn', the end title) say# data-allow-overlap. Rendered whole it has neither error.+ # Status 11-22: done; the left lurch check was folded in on stage-guards-16.+ @doneScenario: SG14. The frame is composedGiven the plan| crate | file | lines | job || raea-sys-stage | systems/stage/src/framing.rs | 314 | the share of the frame any part covers (a grid of their boxes), and the shot's subject cut by the edge || raea-sys-stage | systems/stage/src/manifest.rs | +17 | a CSS background over half the frame is the page's ground, not shown |+ | @raea/render | sdk/render/src/3d/label.tsx | +2 | a Label writes its point (data-points) |+ | raea-page | engine/page/src/motion/manifest.rs | +17 | the manifest carries a Label's point on its words (`points`) |+ | raea-sys-stage | systems/stage/src/framing.rs | +20 | the named part nearest a Label's point is the shot's subject; its cut an error |Then the part a shot is about (one a Label or pin points at, else the nearest named part) cut by the frame's edgefor more than 10 frames is an errorAnd under 8% of the frame showing any part, for more than 1 s, is an error@@ -585,6 +633,12 @@ Feature: Stage guards: a 3D render an agent can't break# and 6:03-6:07; 1:59 holds a caption that fills it), 439 errors where it had 435, and Stay (approved) on none,# its findings otherwise the same as before (its three meant errors, three warnings). Left: the subject a Label# points at; subject-cut stays a warning (33, on Stay and four clean scenes).+ # Status 11-22 (branch stage-guards-23): done. A Label writes its point (data-points), the manifest carries it on+ # its words (`points`), and the named part nearest it (within a quarter of the part's size plus 0.3 m: a Label is+ # given the part's top) is the shot's subject. A part a Label names, cut by the frame's edge for more than 10+ # frames, is a subject-cut error; the part showing most is still a guess at the subject, so its cut stays a+ # warning. A room's inside is content by stage-guards-17's standing-slab rule. On the clean scenes and the essay+ # film, which use no Label, every finding is the same.@doneScenario: SG15. A broken render can't be posted@@ -606,6 +660,7 @@ Feature: Stage guards: a 3D render an agent can't break# the stage checks run on them (a still stepped alone is judged for what a still shows).Rule: SG16. The 3D guide says it first+ @doneScenario: SG16. The guide's 3D rules, before any recipeThen sdk/guides (3d.md and craft/floor.md) and the raea skill say, before any recipe:| rule |@@ -620,3 +675,10 @@ Feature: Stage guards: a 3D render an agent can't break# that holds each (SG2's names, line-of-parts and part-snap, the type checks and read={false}, camera-lurch and# camera-reverse, raea scene stage, frame-empty and subject-cut, raea show --despite), Line3d and cameraPath are# the recipes, and craft/floor.md refuses labels written into the 3D, naming Label (SG8). Left: SG9's re-render.+ # Status 11-22 (branch stage-guards-23): done. craft/floor.md refuses a 3D film rendered a shot at a time+ # (`frame-pure`: a shot a process works round an engine fault, so report it with raea bug), and its Labels line+ # names the new checks (words behind a part, subject-cut). bevy/solari.md drops its 0.1.2 cautions, none of which+ # 0.1.9 shows (a sun mounted at frame 15 lights frame 40 as it does alone, SSIM 0.9988; a 10 s --at jump, 0.9994;+ # the sun's strength follows, kept-light), and says to render a film whole. The skill carries both on its main+ # (raea-skills #116, 74ab897); raea's pin takes it with the next pin after the story branch's (ST8a pins 4a77a0b,+ # not yet landed: pinning past it here would ship that branch's skill pages before its code).diff --git a/engine/page/src/motion/manifest.rs b/engine/page/src/motion/manifest.rsindex 6cec4e81..7d49a4a1 100644--- a/engine/page/src/motion/manifest.rs+++ b/engine/page/src/motion/manifest.rs@@ -208,6 +208,10 @@ impl BlitzPage {if up(doc, owner, |node| node.attr(LocalName::from("data-allow-overlap")).is_some()) {t["allowOverlap"] = json!(true);}+ // the world point a Label's words name ("x y z"), which makes the part there the shot's subject (SG14)+ if let Some(p) = up_attr(doc, owner, "data-points").and_then(|v| v.split_whitespace().map(|n| n.parse::<f64>().ok()).collect::<Option<Vec<f64>>>()).filter(|p| p.len() == 3 && p.iter().all(|n| n.is_finite())) {+ t["points"] = json!(p);+ }stamps(owner, &mut t);text.push(t);}@@ -354,6 +358,19 @@ fn in_caption(doc: &blitz_dom::BaseDocument, n: blitz_dom::NodeId) -> bool {}/// Whether `n` or an element it's in passes `test`.+/// The value of an attribute on n or the nearest element above it that has one.+fn up_attr(doc: &blitz_dom::BaseDocument, n: blitz_dom::NodeId, name: &str) -> Option<String> {+ let mut at = Some(n);+ while let Some(x) = at {+ let node = doc.get_node(x)?;+ if let Some(v) = node.attr(LocalName::from(name)) {+ return Some(v.to_string());+ }+ at = node.parent;+ }+ None+}+fn up(doc: &blitz_dom::BaseDocument, n: blitz_dom::NodeId, test: impl Fn(&blitz_dom::Node) -> bool) -> bool {let mut at = Some(n);while let Some(x) = at {diff --git a/engine/render/tests/diag/ribbon.tsx b/engine/render/tests/diag/ribbon.tsxnew file mode 100644index 00000000..fa6d7049--- /dev/null+++ b/engine/render/tests/diag/ribbon.tsx@@ -0,0 +1,63 @@+// Repro (docs/stage-guards.feature SG1): a curve drawn over time as a chain of boxes. The film's Ribbon was a box a+// segment of a 48-point curve, its newest box growing in length each frame; in a sequence render the chain broke into+// dashes, since a box's size stayed its first frame's, while each frame rendered alone was solid. "grow" draws it over 90+// frames: a frame of the sequence must match the frame alone. "whole" is the same 48 boxes from the first frame, the+// cost's control: a growing shape (one mesh a frame, cached) renders within 10% of it.+// frame-pure: compositions grow+import React from "react";+import { AbsoluteFill, Composition, registerRoot, useCurrentFrame } from "raea";+import { Canvas3D } from "raea/3d";+import { Cuboid, Mesh3d } from "raea/mesh";+import { StandardMaterial } from "raea/pbr";+import { Srgba } from "raea/color";+import { Camera3d } from "raea/camera";+import { Quat, Transform } from "raea/transform";+import { AmbientLight, DirectionalLight } from "raea/light";++const N = 48;+// a rise, a peak and a long fall, x 0..4.8 m, y 0..1.6 m (the film's lifeCurve)+const PTS: [number, number][] = Array.from({ length: N + 1 }, (_, i) => {+ const x = i / N;+ const y = x < 0.22 ? Math.sin((x / 0.22) * Math.PI / 2) : Math.exp(-(x - 0.22) * 3.2);+ return [x * 4.8 - 2.4, y * 1.6 - 0.6];+});++function Ribbon({ p }: { p: number }) {+ const upto = Math.min(1, Math.max(0, p)) * N;+ const segs: React.ReactNode[] = [];+ for (let i = 0; i < N; i++) {+ const k = Math.min(1, Math.max(0, upto - i));+ if (k <= 0) break;+ const [x0, y0] = PTS[i];+ const [x1, y1] = [x0 + (PTS[i + 1][0] - x0) * k, y0 + (PTS[i + 1][1] - y0) * k];+ const len = Math.hypot(x1 - x0, y1 - y0) + 0.06;+ segs.push(+ <Mesh3d key={i} name={`rib-${i}`} allowOverlap transform={Transform.fromXyz((x0 + x1) / 2, (y0 + y1) / 2, 0).withRotation(Quat.fromEuler("XYZ", 0, 0, Math.atan2(y1 - y0, x1 - x0)))}>+ <Cuboid half_size={[len / 2, 0.035, 0.02]} />+ <StandardMaterial base_color={Srgba.hex("#d8342c")} />+ </Mesh3d>,+ );+ }+ return <>{segs}</>;+}++function Scene({ grow }: { grow: boolean }) {+ const f = useCurrentFrame();+ return (+ <AbsoluteFill style={{ background: "#f4efe6" }}>+ <Canvas3D>+ <Camera3d transform={Transform.fromXyz(0, 0.2, 4.2).lookingAt([0, 0.2, 0])} />+ <AmbientLight brightness={600} />+ <DirectionalLight name="sun" illuminance={6000} transform={Transform.fromXyz(2, 4, 5).lookingAt([0, 0, 0])} />+ <Ribbon p={grow ? f / 89 : 1} />+ </Canvas3D>+ </AbsoluteFill>+ );+}++registerRoot(() => (+ <>+ <Composition id="grow" component={() => <Scene grow />} width={640} height={360} fps={30} durationInFrames={90} />+ <Composition id="whole" component={() => <Scene grow={false} />} width={640} height={360} fps={30} durationInFrames={90} />+ </>+));diff --git a/sdk/guides/craft/bevy/solari.md b/sdk/guides/craft/bevy/solari.mdindex 4653b881..cec93bff 100644--- a/sdk/guides/craft/bevy/solari.md+++ b/sdk/guides/craft/bevy/solari.md@@ -61,14 +61,13 @@faces. The bounce cache's cells are 15 cm, so a wall thinner than that next to a bright light leaks too.- Keep an interior under about 50 m across. A bounce ray that goes 50 m without hitting anything counts as sky, so abigger hall gets sky light in its bounce.-- Put every light in the tree from the first frame, and change brightness with the sky, the glows and the exposure- rather than the sun's `illuminance`. As of raea 0.1.2:- - a `DirectionalLight` that appears after the first frame lights nothing directly;- - the traced sun keeps its first frame's strength (its direction does follow);- - one `--at` render that jumps more than about 4.5 s between two frames loses the traced sun for every frame- after.-- So render stills one per process (`--frame N`), and a film a shot a chunk.+- Lights may come, go and change. Under Solari a sun that appears after the first frame, a change of its strength or+ colour, the exposure and a long `--at` jump all follow the frame (0.1.9, measured: a frame matches the same frame+ rendered alone). Reset at each cut (`reset`), so the next place doesn't start from the last one's light.+- Render a film whole, in one process. Up to 0.1.9 a part a frame left out stayed in the traced scene, unseen, and+ shaded what was on screen, so a film's later places drew darker than the same frames alone. From the next release it+ leaves, and `raea render` holds a film's frames to the same frames alone (`frame-pure`). On 0.1.9, render a film+ that changes place a scene a process.- In a surface hook (`fn surface`), write `emissive` with alpha 1.0. Bevy reads that alpha as how much the camera'sexposure applies, so 1.0 puts the hook's glow in the traced light's units. At 0.0 the glow skips the exposure andcomes out about 1,000 times brighter at the default.diff --git a/sdk/guides/craft/floor.md b/sdk/guides/craft/floor.mdindex 85c7df5e..01fe0e07 100644--- a/sdk/guides/craft/floor.md+++ b/sdk/guides/craft/floor.md@@ -48,7 +48,11 @@ direction asks for it by name, and the direction then says why in a line.- **Wide, empty shots.** Frame close or medium on a subject: a person, a product, the thing that's happening.- **Labels written into the 3D.** Words that name or point at a part are a `Label`: page type over the scene, sized inpixels of the frame, placed through the shot's camera. Words in the world are only what's really there (a sign, a page in a book), and `raea render` fails on- any it can't read: too small, turned past 50° or never fully revealed (`bevy` rule 9).+ any it can't read: too small, turned past 50°, behind a part or never fully revealed (`bevy` rule 9). A part a+ `Label` names is what the shot is about, so it fails when the frame's edge cuts that part (`subject-cut`).+- **A 3D film rendered a shot at a time.** Render the film whole. A frame looks the same however it's reached, and+ `raea render` renders a sample of a film's frames again alone and fails on one that differs (`frame-pure`). A shot a+ process works round an engine fault; when one shows, report it with `raea bug` instead of building round it.- **Cameras that ease from A to B and stop.** A camera keeps moving at the start and end of a shot, so cuts joinmotion to motion. Stop only when following a subject that stops.- **Cutting to a constant tempo.** Cut to the song's map (its beats, downbeats, builds and drops), never to a BPMdiff --git a/sdk/render/src/3d/label.tsx b/sdk/render/src/3d/label.tsxindex 64362bf2..55c91582 100644--- a/sdk/render/src/3d/label.tsx+++ b/sdk/render/src/3d/label.tsx@@ -104,7 +104,8 @@ export function Label({ at, camera, children, size = 32, side = "above", gap = 4) : null}<div style={row}><div style={{ flexGrow: along, flexShrink: 1, flexBasis: 0 }} />- <div data-label="" style={{ flexGrow: 0, flexShrink: 0, fontSize: font, lineHeight: 1.15, color, whiteSpace: "nowrap", ...style }}>{children}</div>+ {/* data-points: the world point it names, carried to the stage checks, which make the part there the shot's subject (SG14) */}+ <div data-label="" data-points={at.join(" ")} style={{ flexGrow: 0, flexShrink: 0, fontSize: font, lineHeight: 1.15, color, whiteSpace: "nowrap", ...style }}>{children}</div><div style={{ flexGrow: 1 - along, flexShrink: 1, flexBasis: 0 }} /></div></>diff --git a/sdk/render/src/3d/shapes.tsx b/sdk/render/src/3d/shapes.tsxindex 48ebfab5..9287fae5 100644--- a/sdk/render/src/3d/shapes.tsx+++ b/sdk/render/src/3d/shapes.tsx@@ -358,6 +358,10 @@ export interface Text3DProps {font?: string;/** 100..900 (800 by default) */weight?: number;+ /** false: scenery (a sign seen in passing), not held to the type checks raea render runs on 3D type: its size on screen,+ * its angle to the camera, the title-safe area, its reading time and parts in front of it (docs/stage-guards.feature+ * SG10). Words meant to be read are better as page type: a Label */+ read?: boolean;}/** Solid 3D letters (Manifold's text3d), as a Mesh's geometry: `<Mesh><Text3D size={0.6}>SALE</Text3D>...</Mesh>`. */@@ -377,6 +381,9 @@ function text3dShape(p: Text3DProps): string {export interface MeshProps extends PointerHandlers3d {/** what the mesh is called across frames: give one when meshes come and go, so each keeps its own motion */name?: string;+ /** false: its 3D type (a Text3D child) is scenery, not held to raea render's type checks (SG10); a Text3D's own+ * `read` sets it */+ read?: boolean;/** the composition pass it draws in ("scene" by default): a frame-wide effect told to skip a pass (<Look skip>,* <Outline skip>, <Bloom skip>, <Grade skip>) leaves its pixels as drawn, and <Look passes> gives one its own paint;* a piece names at most three passes besides "scene"; keyed per frame */@@ -447,6 +454,12 @@ export function apply3d<T extends object>(props: T, v: Record<string, number | s/** a mesh's element children with fragments opened: <><Sphere /><StandardMaterial /></> is the same mesh as its two */const flat = (kids: ReactNode): ReactElement[] => Children.toArray(kids).flatMap((c) => (!isValidElement(c) ? [] : c.type === Fragment ? flat((c as ReactElement<{ children?: ReactNode }>).props.children) : [c]));+/** A Text3D child's `read`, when it has one. */+function text3dRead(children: ReactNode): boolean | undefined {+ for (const child of flat(children)) if (child.type === Text3D) return (child as ReactElement<Text3DProps>).props.read;+ return undefined;+}+export function shapeFromChildren(children: ReactNode): string | undefined {for (const child of flat(children)) {if (child.type === Text3D) {@@ -490,11 +503,13 @@ export function Mesh(props: MeshProps) {if (props.material !== undefined && props.material !== false) throw new TypeError(`Mesh: material is false (no material) or left out, got ${JSON.stringify(props.material)}`);checkPass("Mesh", props.pass);const manifold = shape instanceof Solid ? shape.expr : shape ?? shapeFromChildren(props.children);+ // a Text3D's read={false} rides on its mesh, which the stage checks read (SG10)+ const read = props.read ?? text3dRead(props.children);const extra: Record<string, string> = {};if (manifold !== undefined) extra["data-shape"] = manifold as string;if (anim.attr) extra["data-raea-anim"] = anim.attr;const id = useId();const m = usePlace3d(position, rotation, scale, props.quaternion);usePointer3d(props.name ?? id, m, () => (shape === undefined ? boundsFromChildren(props.children) : undefined), props as Record<string, unknown>);- return node3d("Mesh", { ...props, animate: undefined, shape: undefined, position, rotation, scale, attributes: props.attributes && JSON.stringify(props.attributes) }, <Place3d.Provider value={m}>{props.children}</Place3d.Provider>, Object.keys(extra).length ? extra : undefined);+ return node3d("Mesh", { ...props, read, animate: undefined, shape: undefined, position, rotation, scale, attributes: props.attributes && JSON.stringify(props.attributes) }, <Place3d.Provider value={m}>{props.children}</Place3d.Provider>, Object.keys(extra).length ? extra : undefined);}diff --git a/systems/stage/src/cover.rs b/systems/stage/src/cover.rsnew file mode 100644index 00000000..dffbfa86--- /dev/null+++ b/systems/stage/src/cover.rs@@ -0,0 +1,113 @@+//! SG10, parts in front of the words: which part, if any, stands between a block of words and the camera. The block's+//! face is sampled on a 3x3 grid through the middle of its letters, and each point's line to the eye tested against+//! every other part's box, in the part's own space (a mesh's shape, a picture's card: framing.rs own_box). Words never+//! hide words: a block is mostly air between its letters (on the essay film, every "ASSETS behind VARIATION" read+//! clearly). A model has no box here (its file's box is mostly air round a tree, and raea poses a person off its rest+//! box), so it never hides words either.++use std::collections::HashMap;++use bevy::math::{Mat4, Vec3};+use raea_core_scene::Item;+use serde_json::Value;++use super::called;+use crate::framing::own_box;++/// More than this share of a block's points hidden, and the words are behind a part (the essay film's day labels, their+/// lower third under the next tile, still read)+const HIDES: f32 = 0.5;+/// A part this see-through or more never hides words (glass, a fade)+const SEE_THROUGH: f64 = 0.5;++/// A frame's parts that can stand in front of words: (its index, its world's inverse, its own box), the see-through+/// left out. Made once a frame, for every block of words in it.+pub(crate) type Part = (usize, Mat4, Vec3, Vec3);++pub(crate) fn parts(its: &[Item], boxes: &mut HashMap<String, Option<(Vec3, Vec3)>>) -> Vec<Part> {+ its.iter()+ .enumerate()+ .filter(|(_, it)| it.kind != "text" && !see_through(it))+ .filter_map(|(j, it)| own_box(it, boxes).map(|(lo, hi)| (j, it.world.inverse(), lo, hi)))+ .collect()+}++/// The part hiding at least half of a block of words (item `me`) from `eye`, by what it's called: the block spans `x`+/// across and `tall` up its own face (z = 0 in `world`), an `em` high. A line counts as stopped only where it enters a+/// part more than an em short of the words, so words on a sign's face, or cut into it, aren't behind the sign; and a+/// part round the eye (a room's box with the camera inside) is the set, not something in front.+pub(crate) fn behind(its: &[Item], parts: &[Part], me: usize, world: &Mat4, x: (f32, f32), tall: f32, em: f32, eye: Vec3) -> Option<String> {+ let points: Vec<Vec3> = [0.2f32, 0.5, 0.8]+ .iter()+ .flat_map(|fx| [-0.2f32, 0.0, 0.2].map(move |fy| (*fx, fy)))+ .map(|(fx, fy)| world.transform_point3(Vec3::new(x.0 + (x.1 - x.0) * fx, tall * fy, 0.0)))+ .collect();+ let mut hidden = 0;+ let mut by: HashMap<usize, usize> = HashMap::new();+ for p in &points {+ let dist = (*p - eye).length();+ if dist <= em {+ continue;+ }+ let stopped = parts.iter().find(|(j, inv, lo, hi)| {+ if *j == me {+ return false;+ }+ let (o, q) = (inv.transform_point3(eye), inv.transform_point3(*p));+ let inside = (0..3).all(|a| o[a] >= lo[a] && o[a] <= hi[a]);+ !inside && enters(o, q, *lo, *hi).is_some_and(|t| t * dist < dist - em)+ });+ if let Some((j, ..)) = stopped {+ hidden += 1;+ *by.entry(*j).or_default() += 1;+ }+ }+ if (hidden as f32) <= HIDES * points.len() as f32 {+ return None;+ }+ by.into_iter().max_by_key(|(j, n)| (*n, std::cmp::Reverse(*j))).map(|(j, _)| called(&its[j]))+}++/// Whether a part lets the words through: its material's opacity under SEE_THROUGH.+fn see_through(it: &Item) -> bool {+ let o = |p: &serde_json::Map<String, Value>| p.get("opacity").and_then(Value::as_f64);+ it.material.as_ref().and_then(|m| o(&m.props)).or_else(|| o(&it.props)).is_some_and(|o| o < SEE_THROUGH)+}++/// Where the segment o to q first enters the box [lo, hi], as a share of its length, if it does before q.+fn enters(o: Vec3, q: Vec3, lo: Vec3, hi: Vec3) -> Option<f32> {+ let d = q - o;+ let (mut t0, mut t1) = (0.0f32, 1.0f32);+ for a in 0..3 {+ if d[a].abs() < 1e-9 {+ if o[a] < lo[a] || o[a] > hi[a] {+ return None;+ }+ continue;+ }+ let (mut ta, mut tb) = ((lo[a] - o[a]) / d[a], (hi[a] - o[a]) / d[a]);+ if ta > tb {+ std::mem::swap(&mut ta, &mut tb);+ }+ t0 = t0.max(ta);+ t1 = t1.min(tb);+ if t0 > t1 {+ return None;+ }+ }+ Some(t0)+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn a_segment_enters_a_box_where_it_meets_it() {+ let (lo, hi) = (Vec3::splat(-1.0), Vec3::splat(1.0));+ assert_eq!(enters(Vec3::new(0.0, 0.0, 5.0), Vec3::new(0.0, 0.0, -5.0), lo, hi), Some(0.4));+ assert_eq!(enters(Vec3::new(3.0, 0.0, 5.0), Vec3::new(3.0, 0.0, -5.0), lo, hi), None);+ // ends before the box+ assert_eq!(enters(Vec3::new(0.0, 0.0, 5.0), Vec3::new(0.0, 0.0, 2.0), lo, hi), None);+ }+}diff --git a/systems/stage/src/framing.rs b/systems/stage/src/framing.rsindex 38745ece..413006c4 100644--- a/systems/stage/src/framing.rs+++ b/systems/stage/src/framing.rs@@ -118,15 +118,20 @@ fn mark(grid: &mut [bool], b: [f32; 4], w: f32, h: f32) {}/// Each frame as it comes: the share covered, whether it can be judged (no part of unknown size in view, no footage or-/// 2D over the 3D), and its subject: (name, the share of its box outside the frame, whether it could fit).+/// 2D over the 3D), and its subject: (name, the share of its box outside the frame, whether it could fit, whether a+/// Label names it).#[derive(Default)]pub(crate) struct Framing {boxes: HashMap<String, Option<(Vec3, Vec3)>>,covered: Vec<f32>,judged: Vec<bool>,- subject: Vec<Option<(String, f32, bool)>>,+ subject: Vec<Option<Subject>>,}+/// A frame's subject: what it's called, the share of its box outside the frame, whether it could fit, and whether a+/// Label names it (the part nearest the Label's point; else the named part showing most, a guess)+type Subject = (String, f32, bool, bool);+impl Framing {/// A frame's parts through its camera `v`, and what its page draws over them, on a w x h frame.pub(crate) fn push(&mut self, _k: usize, its: &[Item], v: Option<View>, page: Option<&crate::Page>, w: f32, h: f32) {@@ -136,11 +141,14 @@ impl Framing {self.subject.push(s);}- fn frame(&mut self, its: &[Item], v: View, page: Option<&crate::Page>, w: f32, h: f32) -> (f32, bool, Option<(String, f32, bool)>) {+ fn frame(&mut self, its: &[Item], v: View, page: Option<&crate::Page>, w: f32, h: f32) -> (f32, bool, Option<Subject>) {let boxes = &mut self.boxes;let mut grid = vec![false; GX * GY];let mut sure = true;let mut best: Option<(String, f32, f32, bool)> = None;+ // the points the page's Labels name, and the named part nearest one: (name, its distance, out, fits)+ let points: Vec<Vec3> = page.into_iter().flat_map(|p| p.words.iter().filter_map(|w| w.points.map(Vec3::from))).collect();+ let mut named: Option<(String, f32, f32, bool)> = None;for it in its {// drawn where the boxes can't say: footage, 2D, a field, a shader over the frame, a set of copies (<Instances>)if matches!(it.kind, "plate" | "sprite" | "shape2d" | "grass" | "splat" | "meshseq" | "frame_pass") || it.at.is_some() {@@ -189,16 +197,28 @@ impl Framing {continue;}// the subject: the named part showing most, when it could fit in the frame- if it.props.get("name").is_some() && inside > 0.0 && best.as_ref().is_none_or(|s| inside > s.1) {- let fits = b[2] - b[0] < 0.9 * w && b[3] - b[1] < 0.9 * h;- best = Some((called(it), inside, 1.0 - inside / whole, fits && scale_of(it) > 0.0));+ if it.props.get("name").is_some() && inside > 0.0 {+ let fits = b[2] - b[0] < 0.9 * w && b[3] - b[1] < 0.9 * h && scale_of(it) > 0.0;+ if best.as_ref().is_none_or(|s| inside > s.1) {+ best = Some((called(it), inside, 1.0 - inside / whole, fits));+ }+ // a Label's point is on or near its part (its top, as Label asks): within a quarter of the part's size+ // and 0.3 m+ if !points.is_empty() {+ let (lo, hi) = corners(&it.world, lo, hi).into_iter().fold((Vec3::MAX, Vec3::MIN), |(a, b), p| (a.min(p), b.max(p)));+ let d = points.iter().map(|p| (lo - *p).max(*p - hi).max(Vec3::ZERO).length()).fold(f32::MAX, f32::min);+ if d <= 0.25 * (hi - lo).length() + 0.3 && named.as_ref().is_none_or(|s| d < s.1) {+ named = Some((called(it), d, 1.0 - inside / whole, fits));+ }+ }}}// the page's words and videos fill the frame too: a headline over an empty 3D isn't an empty framefor b in page.into_iter().flat_map(|p| p.words.iter().map(|w| w.bx).chain(p.videos.iter().copied()).chain(p.pictures.iter().copied())) {mark(&mut grid, b, w, h);}- (grid.iter().filter(|c| **c).count() as f32 / (GX * GY) as f32, sure, best.map(|(name, _, out, fits)| (name, out, fits)))+ let subject = named.map(|(name, _, out, fits)| (name, out, fits, true)).or(best.map(|(name, _, out, fits)| (name, out, fits, false)));+ (grid.iter().filter(|c| **c).count() as f32 / (GX * GY) as f32, sure, subject)}/// SG14 over the frames given.@@ -214,11 +234,15 @@ impl Framing {out.push(st.finding("frame-empty", Level::Error, a, b, says).fix("aim the camera at what the shot is about, or bring it into the frame"));}}- for (a, b) in runs(st, n, |k| subject[k].as_ref().is_some_and(|(_, out, fits)| *fits && *out > CUT_LO && *out < CUT_HI)) {+ for (a, b) in runs(st, n, |k| subject[k].as_ref().is_some_and(|(_, out, fits, _)| *fits && *out > CUT_LO && *out < CUT_HI)) {let names: Vec<&str> = subject[a..=b].iter().filter_map(|s| s.as_ref().map(|s| s.0.as_str())).collect();if b + 1 - a > CUT_FRAMES && names.windows(2).all(|w| w[0] == w[1]) {- let says = format!("'{}', the part the shot shows most, is cut by the frame's edge from {} to {}", names[0], st.at(a), st.at(b));- out.push(st.finding("subject-cut", Level::Warn, a, b, says).fix("frame it whole (move the camera back or aim it), or move in until the cut is plainly meant"));+ // a part a Label names is what the shot is about, so its cut is an error; the part showing most is a+ // guess at the subject, so its cut is a warning+ let labelled = subject[a..=b].iter().all(|s| s.as_ref().is_some_and(|s| s.3));+ let (level, what) = if labelled { (Level::Error, "the part a Label names") } else { (Level::Warn, "the part the shot shows most") };+ let says = format!("'{}', {what}, is cut by the frame's edge from {} to {}", names[0], st.at(a), st.at(b));+ out.push(st.finding("subject-cut", level, a, b, says).fix("frame it whole (move the camera back or aim it), or move in until the cut is plainly meant"));}}out@@ -268,7 +292,7 @@ mod tests {fn words_or_a_video_in_the_page_fill_the_frame() {let fs: Vec<Vec<Item>> = (0..120).map(|i| vec![cam([0.0, 0.0, 6.0], if (30..90).contains(&i) { [0.0, 40.0, 0.0] } else { [0.0; 3] }), cube("dash", [0.0; 3])]).collect();let n: Vec<i64> = (0..120).collect();- let headline = crate::Page { words: vec![crate::Words { text: "The rule".into(), bx: [360.0, 380.0, 1560.0, 700.0], allow_overlap: false }], videos: Vec::new(), pictures: Vec::new() };+ let headline = crate::Page { words: vec![crate::Words { text: "The rule".into(), bx: [360.0, 380.0, 1560.0, 700.0], allow_overlap: false, points: None }], videos: Vec::new(), pictures: Vec::new() };let f = crate::check_with(&fs, &n, &vec![headline; 120], 1920, 1080, 30.0, "test");assert!(!f.iter().any(|f| f.check == "frame-empty"), "{f:?}");let clip = crate::Page { words: Vec::new(), videos: Vec::new(), pictures: vec![[656.0, 0.0, 1264.0, 1080.0]] };@@ -337,4 +361,22 @@ mod tests {let fs: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), cube("logo", [4.9, 0.0, 0.0])]).collect();assert!(run(fs).iter().any(|f| f.check == "subject-cut"));}++ #[test]+ fn a_part_a_label_names_cut_by_the_edge_is_an_error() {+ // the badge, small and near the middle, shows most; the logo half out at the right is the one the Label names+ let fs: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), cube("badge", [0.0, 0.0, 1.0]), cube("logo", [4.9, 0.0, 0.0])]).collect();+ let label = |at: [f32; 3]| crate::Page { words: vec![crate::Words { text: "Our logo".into(), bx: [1500.0, 200.0, 1800.0, 260.0], allow_overlap: false, points: Some(at) }], ..crate::Page::default() };+ let n: Vec<i64> = (0..30).collect();+ let named = check_with(&fs, &n, &vec![label([4.9, 0.5, 0.0]); 30], 1920, 1080, 30.0, "test");+ let cut = named.iter().find(|f| f.check == "subject-cut").expect("subject-cut");+ assert_eq!(cut.level, Level::Error);+ assert!(cut.says.contains("'logo'") && cut.says.contains("a Label names"), "{}", cut.says);+ // a Label on the badge, shown whole: nothing is cut+ let whole = check_with(&fs, &n, &vec![label([0.0, 0.5, 1.0]); 30], 1920, 1080, 30.0, "test");+ assert!(!whole.iter().any(|f| f.check == "subject-cut"), "{whole:?}");+ // a Label pointing at nothing near a part leaves the guess: the logo cut is a warning+ let far = check_with(&fs, &n, &vec![label([0.0, 3.0, -9.0]); 30], 1920, 1080, 30.0, "test");+ assert!(far.iter().all(|f| f.check != "subject-cut" || f.level == Level::Warn), "{far:?}");+ }}diff --git a/systems/stage/src/lib.rs b/systems/stage/src/lib.rsindex 4441adbc..0fd67e13 100644--- a/systems/stage/src/lib.rs+++ b/systems/stage/src/lib.rs@@ -11,6 +11,7 @@ use raea_core_facts::{Finding, Level};use raea_core_scene::{Item, base_ident};use serde_json::Value;+mod cover;mod framing;mod manifest;mod motion;diff --git a/systems/stage/src/manifest.rs b/systems/stage/src/manifest.rsindex 494bb37a..328c08cc 100644--- a/systems/stage/src/manifest.rs+++ b/systems/stage/src/manifest.rs@@ -31,7 +31,8 @@ pub fn pages(frames: &[Value], nums: &[i64], w: u32, h: u32) -> Vec<Page> {}let words = |t: &Value| {let text = Some(t["text"].as_str()?.trim()).filter(|s| !s.is_empty())?.into();- Some(Words { text, bx: shown(t, "ink").or_else(|| shown(t, "box"))?, allow_overlap: t["allowOverlap"] == true })+ let points = t["points"].as_array().and_then(|p| p.iter().map(|v| v.as_f64().map(|v| v as f32)).collect::<Option<Vec<f32>>>()?.try_into().ok());+ Some(Words { text, bx: shown(t, "ink").or_else(|| shown(t, "box"))?, allow_overlap: t["allowOverlap"] == true, points })};nums.iter().map(|f| Page {diff --git a/systems/stage/src/page.rs b/systems/stage/src/page.rsindex 56a36249..641133f8 100644--- a/systems/stage/src/page.rs+++ b/systems/stage/src/page.rs@@ -19,6 +19,8 @@ pub struct Words {pub text: String,pub bx: [f32; 4],pub allow_overlap: bool,+ /// the world point a Label's words name (its `at`), which makes the part there the shot's subject (SG14)+ pub points: Option<[f32; 3]>,}/// What the page draws over one frame's 3D, as its manifest has it: its words, its videos' boxes and its pictures'@@ -126,7 +128,7 @@ mod tests {fn run(part: Item, words: [f32; 4], n: usize) -> Vec<raea_core_facts::Finding> {let all: Vec<Vec<Item>> = (0..n).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), part.clone()]).collect();let frames: Vec<i64> = (0..n as i64).collect();- let page: Vec<Page> = (0..n).map(|_| Page { words: vec![Words { text: "Install now".into(), bx: words, allow_overlap: false }], videos: Vec::new(), pictures: Vec::new() }).collect();+ let page: Vec<Page> = (0..n).map(|_| Page { words: vec![Words { text: "Install now".into(), bx: words, allow_overlap: false, points: None }], videos: Vec::new(), pictures: Vec::new() }).collect();crate::check_with(&all, &frames, &page, 1920, 1080, 30.0, "test").into_iter().filter(|f| f.check == "type-over-part").collect()}@@ -146,7 +148,7 @@ mod tests {right.world = Mat4::from_translation(Vec3::new(0.6, 0.0, 0.0));let all: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), left.clone(), right.clone()]).collect();let frames: Vec<i64> = (0..30).collect();- let page: Vec<Page> = (0..30).map(|_| Page { words: vec![Words { text: "Install now".into(), bx: [560.0, 500.0, 1360.0, 580.0], allow_overlap: false }], videos: Vec::new(), pictures: Vec::new() }).collect();+ let page: Vec<Page> = (0..30).map(|_| Page { words: vec![Words { text: "Install now".into(), bx: [560.0, 500.0, 1360.0, 580.0], allow_overlap: false, points: None }], videos: Vec::new(), pictures: Vec::new() }).collect();let f: Vec<_> = crate::check_with(&all, &frames, &page, 1920, 1080, 30.0, "test").into_iter().filter(|f| f.check == "type-over-part").collect();assert_eq!(f.len(), 1, "{f:?}");assert!(f[0].says.contains("'left'") && f[0].says.contains("'right'"), "{}", f[0].says);@@ -156,7 +158,7 @@ mod tests {fn words_that_say_allow_overlap_may_cover_a_part() {let all: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 6.0], [0.0; 3]), card("card", json!({}))]).collect();let frames: Vec<i64> = (0..30).collect();- let page: Vec<Page> = (0..30).map(|_| Page { words: vec![Words { text: "on the card".into(), bx: [760.0, 500.0, 1160.0, 580.0], allow_overlap: true }], ..Page::default() }).collect();+ let page: Vec<Page> = (0..30).map(|_| Page { words: vec![Words { text: "on the card".into(), bx: [760.0, 500.0, 1160.0, 580.0], allow_overlap: true, points: None }], ..Page::default() }).collect();assert!(!crate::check_with(&all, &frames, &page, 1920, 1080, 30.0, "test").iter().any(|f| f.check == "type-over-part"));}diff --git a/systems/stage/src/text.rs b/systems/stage/src/text.rsindex d7dc2a9a..f9b27900 100644--- a/systems/stage/src/text.rs+++ b/systems/stage/src/text.rs@@ -1,9 +1,9 @@-//! SG10, 3D type that reads: each RichText checked on every frame it shows, through the frame's camera. Its letters'-//! height on screen, its face against the line to the camera, its box against the title-safe area, whether its reveal-//! starts and finishes while it's up, and whether it's up long enough to be read. A RichText with `read={false}` is-//! scenery (a sign seen in passing) and isn't held to it.+//! SG10, 3D type that reads: each RichText and Text3D checked on every frame it shows, through the frame's camera. Its+//! letters' height on screen, its face against the line to the camera, its box against the title-safe area, a part in+//! front of it (cover.rs), whether its reveal starts and finishes while it's up, and whether it's up long enough to be+//! read. A RichText or Text3D with `read={false}` is scenery (a sign seen in passing) and isn't held to it.-use std::collections::BTreeMap;+use std::collections::{BTreeMap, HashMap};use bevy::math::Vec3;use raea_core_facts::{Finding, Level};@@ -47,12 +47,16 @@ struct Seen {/// some glyph shown, every glyph fully inshown: bool,whole: bool,+ /// the part hiding it from the camera (cover.rs), when one does+ hid: Option<String>,}/// Each block's frames as they come, by what it's called, in frame order (and its words' count, and whether it reveals).#[derive(Default)]pub(crate) struct Texts {by: BTreeMap<String, (Vec<Seen>, usize, bool)>,+ /// each shape's own box, read once a render (cover.rs)+ boxes: HashMap<String, Option<(Vec3, Vec3)>>,}impl Texts {@@ -60,18 +64,16 @@ impl Texts {pub(crate) fn push(&mut self, k: usize, its: &[Item], v: Option<View>) {let Some(v) = v else { return };let by = &mut self.by;- for it in its.iter().filter(|i| i.kind == "text") {- if it.props.get("read").and_then(Value::as_bool) == Some(false) {- continue;- }- let words = it.props.get("text").and_then(Value::as_str).unwrap_or("");- if words.trim().is_empty() {+ // the parts that can stand in front of words, made once a frame and only when it has words+ let mut parts: Option<Vec<crate::cover::Part>> = None;+ for (i, it) in its.iter().enumerate() {+ let Some((words, size, text3d)) = words_of(it) else { continue };+ if it.props.get("read").and_then(Value::as_bool) == Some(false) || words.trim().is_empty() {continue;}let o = origin(it);let Some([cx, cy, depth]) = v.project(o) else { continue };// its em on screen: the em's height carried by its matrix, at its depth- let size = num(it, "size", 0.5) as f32;let up = it.world.transform_vector3(Vec3::Y * size);let cap = CAP * up.length() * v.focal / depth;let face = it.world.transform_vector3(Vec3::Z).normalize_or(Vec3::Z);@@ -79,14 +81,17 @@ impl Texts {let lines: Vec<&str> = words.split('\n').collect();let wide = lines.iter().map(|l| l.chars().count()).max().unwrap_or(0) as f32 * ADVANCE * size;let tall = lines.len() as f32 * num(it, "lineHeight", 1.2) as f32 * size;- let align = num(it, "align", 0.5) as f32;+ // a Text3D is one line, centred on its origin+ let align = if text3d { 0.5 } else { num(it, "align", 0.5) as f32 };let (x0, x1) = (-align * wide, (1.0 - align) * wide);let b = v.bounds(corners(&it.world, Vec3::new(x0, -tall / 2.0, 0.0), Vec3::new(x1, tall / 2.0, 0.0)));let os: Vec<f64> = it.props.get("glyphs").and_then(Value::as_array).map(|gs| gs.iter().map(|g| if g.get("v").and_then(Value::as_bool) == Some(false) { 0.0 } else { g.get("o").and_then(Value::as_f64).unwrap_or(1.0) }).collect()).unwrap_or_default();let shown = os.is_empty() || os.iter().any(|o| *o > SHOWN);let whole = os.iter().all(|o| *o > IN);- let e = by.entry(called(it)).or_insert_with(|| (Vec::new(), words.split_whitespace().count(), it.props.get("at").is_some()));- e.0.push(Seen { k, cap, turn, b, c: [cx, cy], shown, whole });+ let parts = parts.get_or_insert_with(|| crate::cover::parts(its, &mut self.boxes));+ let hid = crate::cover::behind(its, parts, i, &it.world, (x0, x1), tall, up.length(), v.eye);+ let e = by.entry(called(it)).or_insert_with(|| (Vec::new(), words.split_whitespace().count(), !text3d && it.props.get("at").is_some()));+ e.0.push(Seen { k, cap, turn, b, c: [cx, cy], shown, whole, hid });}}@@ -113,6 +118,11 @@ impl Texts {let level = if most > TURN_ERROR { Level::Error } else { Level::Warn };out.push(fix(st.finding("type-angle", level, a, b, says), "turn the words to face the camera (their rotation), or move the camera round to face them", most, MAX_TURN, "°"));}+ for (a, b) in lasting(&|s| s.hid.is_some()) {+ let part = during(a, b).find_map(|s| s.hid.clone()).unwrap_or_default();+ let f = st.finding("type-hidden", Level::Error, a, b, format!("the words '{name}' are behind '{part}' from {} to {}: more than half of them can't be seen", st.at(a), st.at(b)));+ out.push(f.fix("move the part, the words or the camera so nothing stands between the words and the camera; words that point at a part read better as page type over the frame (a Label)"));+ }let (mx, my) = (SAFE * st.w, SAFE * st.h);for (a, b) in lasting(&|s| s.whole && s.b.is_some_and(|b| b[0] < mx || b[1] < my || b[2] > st.w - mx || b[3] > st.h - my)) {let f = st.finding("type-safe", Level::Warn, a, b, format!("the words '{name}' run outside the title-safe area from {} to {}", st.at(a), st.at(b)));@@ -146,6 +156,22 @@ impl Texts {}}+/// A block's words and em: a RichText's (a `text` item), or a Text3D's (a mesh whose shape is `text3d("WORDS", size,+/// depth, ...)`: the SDK keeps quotes and backslashes out of the words), with whether it's a Text3D. A Text3D cut into+/// a solid (minus(box, text3d(...))) is part of that solid, not words of its own.+fn words_of(it: &Item) -> Option<(&str, f32, bool)> {+ match it.kind {+ "text" => Some((it.props.get("text").and_then(Value::as_str).unwrap_or(""), num(it, "size", 0.5) as f32, false)),+ "mesh" => {+ let rest = it.shape.as_deref()?.strip_prefix("text3d(\"")?;+ let (words, rest) = rest.split_once('"')?;+ let size: f32 = rest.strip_prefix(',')?.split(',').next()?.trim().trim_end_matches(')').trim().parse().ok()?;+ (size > 0.0).then_some((words, size, true))+ }+ _ => None,+ }+}+fn in_frame(st: &Stage, c: [f32; 2]) -> bool {c[0] >= 0.0 && c[0] <= st.w && c[1] >= 0.0 && c[1] <= st.h}@@ -223,6 +249,61 @@ mod tests {assert!(check(&half, &at, 1920, 1080, 30.0, "test").is_empty());}+ fn text3d(text: &str, size: f64, world: Mat4) -> Item {+ let mut it = item("mesh", json!({}), world);+ it.shape = Some(format!("text3d(\"{text}\", {size}, 0.1, \"Inter\", 800)").into());+ it+ }++ fn block(name: &str, half: [f32; 3], at: [f32; 3], opacity: Option<f64>) -> Item {+ let mut it = item("mesh", json!({"name": name}), Mat4::from_translation(at.into()));+ it.shape = Some(format!("box({}, {}, {})", half[0] * 2.0, half[1] * 2.0, half[2] * 2.0).into());+ if let Some(o) = opacity {+ std::sync::Arc::make_mut(&mut it.props).insert("opacity".into(), json!(o));+ }+ it+ }++ #[test]+ fn a_text3d_is_held_to_the_same_checks() {+ let far: Vec<Vec<Item>> = (0..30).map(|_| vec![cam([0.0, 0.0, 10.0], [0.0; 3]), text3d("SALE", 0.1, Mat4::IDENTITY)]).collect();+ let f = run(far);+ assert!(f.iter().any(|f| f.check == "type-small" && f.says.contains("SALE")), "{f:?}");+ let near: Vec<Vec<Item>> = (0..90).map(|_| vec![cam([0.0, 0.0, 4.0], [0.0; 3]), text3d("SALE", 0.5, Mat4::IDENTITY)]).collect();+ assert_eq!(run(near).iter().map(|f| f.check.as_str()).collect::<Vec<_>>(), Vec::<&str>::new());+ // a word cut into a sign is the sign's, not words of its own+ let mut cut = text3d("SALE", 0.1, Mat4::IDENTITY);+ cut.shape = Some("minus(rounded_box(2, 1, 0.2, 0.05), text3d(\"SALE\", 0.1, 0.3))".into());+ assert!(!run((0..30).map(|_| vec![cam([0.0, 0.0, 10.0], [0.0; 3]), cut.clone()]).collect()).iter().any(|f| f.check.starts_with("type-")));+ }++ #[test]+ fn a_part_in_front_of_the_words_is_said_and_their_sign_isnt() {+ let cam_at = cam([0.0, 0.0, 6.0], [0.0; 3]);+ // a crate between the words and the camera+ let hidden: Vec<Vec<Item>> = (0..60).map(|_| vec![cam_at.clone(), words("Placement", 0.4, Mat4::IDENTITY, 1.0), block("crate", [1.5, 0.6, 0.3], [0.0, 0.0, 2.0], None)]).collect();+ let f = run(hidden);+ let h = f.iter().find(|f| f.check == "type-hidden").expect("type-hidden");+ assert_eq!(h.level, Level::Error);+ assert!(h.says.contains("crate"), "{}", h.says);+ // the words on the face of their sign, the sign behind them+ let sign: Vec<Vec<Item>> = (0..90).map(|_| vec![cam_at.clone(), words("Placement", 0.4, Mat4::from_translation([0.0, 0.0, 0.11].into()), 1.0), block("sign", [1.5, 0.5, 0.1], [0.0; 3], None)]).collect();+ assert!(!run(sign).iter().any(|f| f.check == "type-hidden"));+ // glass in front, and a part off to the side, hide nothing+ let glass: Vec<Vec<Item>> = (0..60).map(|_| vec![cam_at.clone(), words("Placement", 0.4, Mat4::IDENTITY, 1.0), block("pane", [1.5, 0.6, 0.05], [0.0, 0.0, 2.0], Some(0.2)), block("post", [0.2, 1.0, 0.2], [3.0, 0.0, 2.0], None)]).collect();+ assert!(!run(glass).iter().any(|f| f.check == "type-hidden"));+ // words in front of words hide nothing (the essay film's "ASSETS behind VARIATION" read clearly)+ let over: Vec<Vec<Item>> = (0..60).map(|_| vec![cam_at.clone(), words("Placement", 0.4, Mat4::IDENTITY, 1.0), words("VARIATION COSTS", 0.8, Mat4::from_translation([0.0, 0.0, 2.0].into()), 1.0)]).collect();+ assert!(!run(over).iter().any(|f| f.check == "type-hidden"));+ // a tile over the lower third of the letters (the film's day labels; seen from the eye it covers the bottom row of+ // points and no other): still read, not said+ let low: Vec<Vec<Item>> = (0..60).map(|_| vec![cam_at.clone(), words("Placement", 0.4, Mat4::IDENTITY, 1.0), block("tile", [1.5, 0.235, 0.1], [0.0, -0.265, 2.0], None)]).collect();+ assert!(!run(low).iter().any(|f| f.check == "type-hidden"));+ // a part that passes in front for a moment (under half a second) isn't said+ let past: Vec<Vec<Item>> = (0..90).map(|k| { let mut v = vec![cam_at.clone(), words("Placement", 0.4, Mat4::IDENTITY, 1.0)]; if (40..48).contains(&k) { v.push(block("bird", [1.5, 0.6, 0.3], [0.0, 0.0, 2.0], None)) } v }).collect();+ assert!(!run(past).iter().any(|f| f.check == "type-hidden"));+ }+#[test]fn words_up_too_briefly_to_read_are_a_warning() {let brief: Vec<Vec<Item>> = (0..20).map(|_| vec![cam([0.0, 0.0, 4.0], [0.0; 3]), words("The best ad network for growing studios", 0.3, Mat4::IDENTITY, 1.0)]).collect();