Skip to content

armgit / raea

Public Imported from GitHub
0

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.

DR4: raea/check in the manual and the skill's router: doc comments on every export (and on raea/ecs World's members it re-exports), the module in the SDK reference's Tools group with its page written by hand above the generated block, and craft/ROUTER.md's evidence step says when a line the work keeps every round is a rule: a controller field naming one of raea's checks or a .ts check written with raea/check, run by raea check PROJECT

shinyobjectz089ff3557776
diff --git a/docs/manual/reference/sdk/check.md b/docs/manual/reference/sdk/check.md
new file mode 100644
index 00000000..1dcd2a4e
--- /dev/null
+++ b/docs/manual/reference/sdk/check.md
@@ -0,0 +1,350 @@
+---
+title: "raea/check"
+summary: "A check written as a system over a composition's world: what `raea check` runs for a rule a controller holds."
+order: 102
+sources: ["sdk/raea/src/check.ts", "sdk/raea/src/facts.gen.ts", "apps/direction/src/check.rs"]
+---
+
+A check holds the work to one line. It is a system over each frame's world, the same world
+[`raea world`](../cli/world.md) prints: a caption, a footage cut, a sound cue and a 3D part are entities with
+components, so one check reads the same for any of them. It finds entities, measures, and calls `found` for each
+thing that breaks its line; it never prints. A rule in a project's controller names it by its path, with its values,
+and [`raea check`](../cli/check.md) runs it on every composition, on the frames it says it ranges over. A check that
+reads what only a render has (`needs: "render"`) waits for one, and says so. raea's own checks are the same thing
+written in Rust, under the names `text-hold`, `text-above`, `text-below`, `text-margin`, `loudness`, `still-max` and
+`floor`.
+
+```ts
+// controllers/rules.ts holds the rule:
+// { label: "Captions clear the button band", type: "rule", check: "../checks/caption.ts", values: { band: 0.8 } }
+
+// checks/caption.ts
+import { check, found, type Layer, type Text } from "raea/check";
+
+export default check({ id: "caption", text: "a caption clears the platform's button band" }, (world, _frame, values) => {
+ const band = Number(values.band ?? 0.8);
+ for (const t of world.find({ with: ["Text", "Layer"] })) {
+ if (world.component<Layer>(t, "Layer")!.medium !== "2d-type") continue;
+ const box = world.component<Text>(t, "Text")!.box; // in frame fractions: left, top, right, bottom
+ if (box && box[3] > band) found({ about: [t], says: `the caption reaches ${Math.round(box[3] * 100)}% down the frame` });
+ }
+});
+```
+
+<!-- generated:begin by tools/manual-ref/sdk.ts from the SDK's exports and doc comments; edit outside this block -->
+
+```ts
+import { check, declared, found, runChecks } from "raea/check"
+```
+
+`raea/check` exports 5 functions, 1 class, 31 types. Source: [sdk/raea/src/check.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/check.ts).
+
+## Functions
+
+### `check`
+
+A check: what it holds the work to, and the system that finds where the work doesn't hold.
+
+```ts
+function check(meta: CheckMeta, run: CheckFn): Check
+```
+
+### `declared`
+
+Each check's declaration, as raea check reads it before it reads any frame.
+
+```ts
+function declared(checks: Check[]): CheckMeta[]
+```
+
+### `found`
+
+Says what the running check found. Only inside a check's system, as raea check runs it.
+
+```ts
+function found(f: Found): void
+```
+
+### `runChecks`
+
+Every planned check run on its frames' worlds: what they found, a run of frames finding the same thing as one
+finding over those frames, and each check that threw, with what it threw.
+
+```ts
+function runChecks(checks: Check[], plan: Planned[], worlds: Facts[]): { findings: Finding[]; threw: { check: string; says: string; }[]; }
+```
+
+### `worldOf`
+
+A frame's facts as a raea/ecs world: the same components, the frame's size and rate as the `Frame` resource, and
+what the render added as resources. An entity's references to others (a Covered's `layer`, a relation's `to`)
+are its id in this world.
+
+```ts
+function worldOf(facts: Facts): World
+```
+
+## Classes
+
+### `World`
+
+A world of entities: rows in tables by kind.
+
+| Member | What it does |
+| --- | --- |
+| `new World(store?: Store \| undefined)` | A world on `store`: the engine's tables when it has them, else TypeScript's (createWorld picks for you). |
+| `.native: boolean` | whether the tables are the engine's (native) or TypeScript's |
+| `.spawn(kind: string, cols?: Cols): number` | A new entity of `kind` with its columns; its id. |
+| `.set(id: number, cols: Cols): void` | Columns set on an entity. |
+| `.get(id: number): Row` | An entity's row. |
+| `.despawn(id: number): void` | An entity taken out of the world, with its children. |
+| `.query(kind: string, where?: Where): number[]` | The ids of `kind`'s entities whose columns pass every condition, filtered by the engine. |
+| `.column(kind: string, col: string): (number \| null)[]` | One numeric column of `kind`, in id order (null where unset). |
+| `.count(kind: string): number` | How many entities of `kind` there are. |
+| `.rows(): Row[]` | Every row, by kind then id. |
+| `.add(components: Components, opts?: { parent?: number \| undefined; }): number` | A new entity with components ({Position: {x, y}, Ball: {}}), optionally a child of `parent`. |
+| `.insert(id: number, components: Components): void` | Components added to (or replacing those on) an entity. |
+| `.remove(id: number, ...names: string[]): void` | Components taken off an entity. |
+| `.components(id: number): Components` | An entity's components by name. |
+| `.component<T = Record<string, Value>>(id: number, name: string): T \| undefined` | One component of an entity (undefined when it hasn't it). |
+| `.find(f: Find): number[]` | Entities with every `with` component and no `without` one, passing every condition ("Comp.field", or a field of the first `with`), in id order: Bevy's query in the engine. |
+| `.setParent(id: number, parent: number \| null): void` | An entity's parent (despawning a parent despawns its children). |
+| `.parent(id: number): number \| null` | An entity's parent (null when it has none). |
+| `.children(id: number): number[]` | An entity's children's ids. |
+| `.resource<T = unknown>(name: string, value?: T \| undefined): T \| null` | A resource: one value for the world (set it with a value; null when unset). |
+| `.send(name: string, value?: unknown): void` | An event for the systems after this one, this frame (each frame starts with none). |
+| `.events<T = unknown>(name: string): T[]` | This frame's events of a name, in the order sent. |
+| `.scene(): unknown[]` | What draws: Mesh + Transform entities (world space, parents composed) and lights (`<Entities world={w.at(frame)} />` hands this to the renderer). From the engine's tables natively; from the world's own store in a browser (raea-web), the same list as runtime/calls ecs.scene makes. |
+| `.handle: number \| null` | The engine's id of this world's tables (for the renderer), or null under plain bun. |
+| `.system(fn: System): World` | A system run on every frame, after the ones before it. |
+| `.step(frame: number): void` | Run the systems once, for `frame`. |
+| `.at(frame: number): World` | The world after frames 0..frame-1 have run (a copy; this world as built is the state before frame 0). |
+
+## Types
+
+### `About`
+
+```ts
+type About = { name: string, key?: string, }
+```
+
+### `Camera`
+
+```ts
+type Camera = { eye: [number, number, number], look: [number, number, number], /** * vertical field of view in degrees (a perspective camera) */ fov?: number, /** * the height it sees in metres (an orthographic camera) */ ortho?: number, near: number, far: number, /** * how its eye moves, metres a second, to t…
+```
+
+### `Check`
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `run` (required) | `CheckFn` | its system, run on each frame it ranges over |
+| `id` (required) | `string` | what `raea check --only` names, and its findings' check |
+| `text` (required) | `string` | the line it holds the work to |
+| `needs` | `"render"` | "render": it reads what only a render has (Contrast, Picture, Mix, Onset, Covers); with none, it waits for one |
+| `level` | `Level` | how bad what it finds is, where a finding doesn't say (error when unset) |
+| `frames` | `Frames` | where it runs ("all" when unset) |
+
+### `CheckFn`
+
+The system: a frame's world, the frame, and the rule's values.
+
+```ts
+type CheckFn = (world: World, frame: number, values: Values) => void
+```
+
+### `CheckMeta`
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `id` (required) | `string` | what `raea check --only` names, and its findings' check |
+| `text` (required) | `string` | the line it holds the work to |
+| `needs` | `"render"` | "render": it reads what only a render has (Contrast, Picture, Mix, Onset, Covers); with none, it waits for one |
+| `level` | `Level` | how bad what it finds is, where a finding doesn't say (error when unset) |
+| `frames` | `Frames` | where it runs ("all" when unset) |
+
+### `Clip`
+
+```ts
+type Clip = { source: string, hash?: string, time?: number, in: number, out?: number, at: number, words: Array<Word>, }
+```
+
+### `Contrast`
+
+```ts
+type Contrast = { ratio: number, }
+```
+
+### `Covered`
+
+```ts
+type Covered = { layer: number, share: number, }
+```
+
+### `Covers`
+
+```ts
+type Covers = Array<Covered>
+```
+
+### `Cue`
+
+```ts
+type Cue = { source: string, at: number, gain?: number, bus?: string, }
+```
+
+### `Facts`
+
+A frame's facts as `raea world --json` prints them.
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `frame` (required) | `number` | the frame, from the composition's first |
+| `width` (required) | `number` | the composition's width in pixels |
+| `height` (required) | `number` | the composition's height in pixels |
+| `fps` (required) | `number` | the composition's frames a second |
+| `entities` (required) | `{ id: number; parent?: number \| null; components: Record<string, unknown> }[]` | each entity: its id, its parent's, and its components by name |
+| `resources` | `Record<string, unknown>` | what is the frame's or the piece's, not an entity's (Rendered, Picture, Mix, Waits) |
+
+### `Finding`
+
+```ts
+type Finding = { check: string, level: Level, about: Array<About>, /** * from its first frame to the frame after its last; None when it is about the whole piece */ frames: [number, number] | null, says: string, measure: Measure | null, fix: string | null, by: string, }
+```
+
+### `Found`
+
+What a check found: the entities it is about, what it says, and, where they aren't the check's or the frame's,
+its level and frames (its first, and the frame after its last); the number it turns on and the fix, when there
+are.
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `about` | `number[]` | the entities it is about, by their ids in this frame's world |
+| `says` (required) | `string` | what is wrong, in a line a person reads |
+| `level` | `Level` | its level, where it isn't its rule's or its check's |
+| `frames` | `[number, number]` | its first frame and the frame after its last (this frame alone when unset) |
+| `measure` | `Omit<Measure, "limit"> & { limit?: number }` | the number it turns on: its name, value and unit, and the limit it broke |
+| `fix` | `string` | what to change, when there is one thing to change |
+
+### `Frames`
+
+The frames a check runs on: every frame; the first frame of each shot after the first, and the frame before it;
+every frame a line is said or sung on; once, on the first frame (for what is the piece's, as its mix); or these.
+
+```ts
+type Frames = "all" | "cuts" | "lines" | "once" | number[]
+```
+
+### `Layer`
+
+```ts
+type Layer = { medium: Medium, /** * its place in the stack, 0 at the back */ order: number, opacity: number, /** * how it blends with what's under it (CSS mix-blend-mode), when not normally */ blend?: string, }
+```
+
+### `Level`
+
+```ts
+type Level = "error" | "warn" | "note"
+```
+
+### `Line`
+
+```ts
+type Line = { text: string, from: number, to?: number, words: Array<Word>, needs?: string, }
+```
+
+### `Measure`
+
+```ts
+type Measure = { name: string, value: number, unit: string, limit?: number, }
+```
+
+### `Medium`
+
+```ts
+type Medium = "2d-type" | "2d-graphic" | "3d" | "footage" | "page"
+```
+
+### `Mix`
+
+```ts
+type Mix = { lufs?: number, peak?: number, }
+```
+
+### `Onset`
+
+```ts
+type Onset = { at?: number, late_ms?: number, }
+```
+
+### `Part`
+
+```ts
+type Part = { /** * what draws it: "mesh", "model", "text3d" ... */ kind: string, /** * its name in the scene (`<Mesh3d name>`), or what it draws */ name: string, /** * its taxonomy tags (a component's `meta`, DR11), none until it has one */ tags: Array<string>, /** * its world position, rotation (x, y, z, w…
+```
+
+### `Picture`
+
+```ts
+type Picture = { luma: number, motion?: number, frames?: number, }
+```
+
+### `Planned`
+
+Which check runs on which frames with which values, as raea check plans it from a rule: the rule's level (none:
+the check's own) and where the rule was written.
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `check` (required) | `number` | the check, by its place in the list run |
+| `frames` (required) | `number[]` | the frames it runs on |
+| `values` (required) | `Values` | the rule's values, which the check's system is given |
+| `level` | `Level \| null` | the rule's level, which its findings take where they don't say their own |
+| `by` | `string` | where the rule was written, which its findings carry |
+
+### `Rendered`
+
+```ts
+type Rendered = { out: string, manifest: string, record?: string, stale: boolean, }
+```
+
+### `Shot`
+
+```ts
+type Shot = { name?: string, from: number, /** * None: it runs to the end */ to?: number, }
+```
+
+### `Source`
+
+```ts
+type Source = { file?: string, line?: number, component?: string, /** * the layer key as the engine has it */ key?: string, }
+```
+
+### `Text`
+
+```ts
+type Text = { words: string, font?: string, /** * its letters' height in px of a frame 1080 on its short side (None: not laid out without a render) */ size?: number, /** * its box in the frame, each 0 to 1: x0, y0, x1, y1 (None: not laid out without a render) */ box?: [number, number, number, number], extrud…
+```
+
+### `Values`
+
+A rule's values for its check (a controller's `values`).
+
+```ts
+type Values = Record<string, number | string | boolean>
+```
+
+### `Waits`
+
+```ts
+type Waits = { [key in string]: string }
+```
+
+### `Word`
+
+```ts
+type Word = { text: string, start: number, end: number, }
+```
+
+<!-- generated:end -->
diff --git a/docs/manual/reference/sdk/dev_tools.md b/docs/manual/reference/sdk/dev_tools.md
index 2ad2807f..27b2ca26 100644
--- a/docs/manual/reference/sdk/dev_tools.md
+++ b/docs/manual/reference/sdk/dev_tools.md
@@ -1,7 +1,7 @@
---
title: "raea/dev_tools"
summary: "Checks and lints you can run from code: a motion performance's lint report."
-order: 102
+order: 103
sources: ["sdk/raea/src/dev_tools.ts"]
---
diff --git a/docs/manual/reference/sdk/index.md b/docs/manual/reference/sdk/index.md
index e2c31834..4d5bbe08 100644
--- a/docs/manual/reference/sdk/index.md
+++ b/docs/manual/reference/sdk/index.md
@@ -92,6 +92,7 @@ Checks, lints and a headless App you can drive.
| Import | What it's for | Exports |
| --- | --- | --- |
+| [`raea/check`](check.md) | A check written as a system over a composition's world: what `raea check` runs for a rule a controller holds. | 5 functions, 1 class, 31 types |
| [`raea/dev_tools`](dev_tools.md) | Checks and lints you can run from code: a motion performance's lint report. | 2 functions, 3 types |
| [`raea/remote`](remote.md) | A headless Bevy App you open, step and query from TypeScript, through Bevy's remote protocol. | 1 class, 1 type |
diff --git a/docs/manual/reference/sdk/remote.md b/docs/manual/reference/sdk/remote.md
index 9f0e55fc..c2586bef 100644
--- a/docs/manual/reference/sdk/remote.md
+++ b/docs/manual/reference/sdk/remote.md
@@ -1,7 +1,7 @@
---
title: "raea/remote"
summary: "A headless Bevy App you open, step and query from TypeScript, through Bevy's remote protocol."
-order: 103
+order: 104
sources: ["sdk/raea/src/remote.ts"]
---
diff --git a/sdk/app/src/ecs.ts b/sdk/app/src/ecs.ts
index 86a472ce..0efb3014 100644
--- a/sdk/app/src/ecs.ts
+++ b/sdk/app/src/ecs.ts
@@ -274,6 +274,7 @@ export class World {
/** whether the tables are the engine's (native) or TypeScript's */
readonly native: boolean;
+ /** A world on `store`: the engine's tables when it has them, else TypeScript's (createWorld picks for you). */
constructor(store?: Store) {
this.native = store ? store instanceof NativeStore : hasNative();
this.store = store ?? (this.native ? NativeStore.create() : new JsStore());
@@ -292,6 +293,7 @@ export class World {
get(id: number): Row {
return this.store.get(id);
}
+ /** An entity taken out of the world, with its children. */
despawn(id: number): void {
this.store.despawn(id);
}
@@ -303,6 +305,7 @@ export class World {
column(kind: string, col: string): (number | null)[] {
return this.store.column(kind, col);
}
+ /** How many entities of `kind` there are. */
count(kind: string): number {
return this.store.count(kind);
}
@@ -340,9 +343,11 @@ export class World {
setParent(id: number, parent: number | null): void {
this.store.setParent(id, parent);
}
+ /** An entity's parent (null when it has none). */
parent(id: number): number | null {
return this.store.parent(id);
}
+ /** An entity's children's ids. */
children(id: number): number[] {
return this.store.children(id);
}
diff --git a/sdk/guides/craft/ROUTER.md b/sdk/guides/craft/ROUTER.md
index 69fd1e5e..85b1a421 100644
--- a/sdk/guides/craft/ROUTER.md
+++ b/sdk/guides/craft/ROUTER.md
@@ -56,6 +56,10 @@ leads. raea will add modes as its work grows; `raea context` says when a brief n
5. **The floor:** read it right before you edit.
6. **Make it.**
7. **Evidence:** run `raea check`, look at the frames, critique against the mode's guide, fix, and look again.
+ A line the work must keep every round is a rule, not a reminder: a field `{ label, type: "rule", check, values }`
+ in the project's controller, whose check is one of raea's by name (`text-above`, `loudness`) or a `.ts` check you
+ write with `raea/check` (`check({ id, text }, (world, frame, values) => ...)` and `found(...)`). `raea check
+ PROJECT` runs every rule on every composition and says what waits for a render.
A quick edit (one value, one word, one cut) skips to the floor and makes the change. "This isn't working" means a
redesign: go back to shaping.
diff --git a/sdk/raea/src/check.ts b/sdk/raea/src/check.ts
index 3a5f7e58..08a41cdc 100644
--- a/sdk/raea/src/check.ts
+++ b/sdk/raea/src/check.ts
@@ -43,6 +43,7 @@ export type Values = Record<string, number | string | boolean>;
/** The system: a frame's world, the frame, and the rule's values. */
export type CheckFn = (world: World, frame: number, values: Values) => void;
export interface Check extends CheckMeta {
+ /** its system, run on each frame it ranges over */
run: CheckFn;
}
@@ -55,11 +56,17 @@ export function check(meta: CheckMeta, run: CheckFn): Check {
* its level and frames (its first, and the frame after its last); the number it turns on and the fix, when there
* are. */
export interface Found {
+ /** the entities it is about, by their ids in this frame's world */
about?: number[];
+ /** what is wrong, in a line a person reads */
says: string;
+ /** its level, where it isn't its rule's or its check's */
level?: Level;
+ /** its first frame and the frame after its last (this frame alone when unset) */
frames?: [number, number];
+ /** the number it turns on: its name, value and unit, and the limit it broke */
measure?: Omit<Measure, "limit"> & { limit?: number };
+ /** what to change, when there is one thing to change */
fix?: string;
}
@@ -92,11 +99,17 @@ function aboutOf(world: World, id: number): About {
/** A frame's facts as `raea world --json` prints them. */
export interface Facts {
+ /** the frame, from the composition's first */
frame: number;
+ /** the composition's width in pixels */
width: number;
+ /** the composition's height in pixels */
height: number;
+ /** the composition's frames a second */
fps: number;
+ /** each entity: its id, its parent's, and its components by name */
entities: { id: number; parent?: number | null; components: Record<string, unknown> }[];
+ /** what is the frame's or the piece's, not an entity's (Rendered, Picture, Mix, Waits) */
resources?: Record<string, unknown>;
}
@@ -131,10 +144,15 @@ export function declared(checks: Check[]): CheckMeta[] {
/** Which check runs on which frames with which values, as raea check plans it from a rule: the rule's level (none:
* the check's own) and where the rule was written. */
export interface Planned {
+ /** the check, by its place in the list run */
check: number;
+ /** the frames it runs on */
frames: number[];
+ /** the rule's values, which the check's system is given */
values: Values;
+ /** the rule's level, which its findings take where they don't say their own */
level?: Level | null;
+ /** where the rule was written, which its findings carry */
by?: string;
}
diff --git a/tools/manual-ref/sdk.ts b/tools/manual-ref/sdk.ts
index 75be1dce..e81279ad 100644
--- a/tools/manual-ref/sdk.ts
+++ b/tools/manual-ref/sdk.ts
@@ -27,7 +27,7 @@ const GROUPS: [string, string, string[]][] = [
["Video, sound and text", "Footage, pictures, sound, words and colour.", ["video", "audio", "text", "image", "asset", "color"]],
["3D", "Bevy's 3D: cameras, lights, materials, meshes and the frame after it's drawn.", ["3d", "camera", "light", "pbr", "mesh", "transform", "post_process", "picking", "gizmos"]],
["2D and UI", "Sprites and flat shapes, bevy_ui and Bevy's widgets.", ["sprite", "ui", "feathers"]],
- ["Tools", "Checks, lints and a headless App you can drive.", ["dev_tools", "remote"]],
+ ["Tools", "Checks, lints and a headless App you can drive.", ["check", "dev_tools", "remote"]],
]
const groupAt = new Map(GROUPS.flatMap(([, , ps], g) => ps.map((p, i) => [p, g * 20 + i + 2] as const)))
const BEGIN = "<!-- generated:begin by tools/manual-ref/sdk.ts from the SDK's exports and doc comments; edit outside this block -->"