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.

SG8, SG16: Label, page type that names a 3D part, placed through the shot's camera; the 3D guide names the check behind each rule

shinyobjectz67d85113fd55
diff --git a/docs/manual/reference/sdk/camera.md b/docs/manual/reference/sdk/camera.md
index a435bdaa..b6b6e793 100644
--- a/docs/manual/reference/sdk/camera.md
+++ b/docs/manual/reference/sdk/camera.md
@@ -22,7 +22,7 @@ const Shot = () => <Camera3d transform={Transform.fromXyz(-2, 2.5, 5).lookingAt(
import { Camera3d, cameraPath, Canvas3D, checkMatchmove } from "raea/camera"
```
-`raea/camera` exports 5 components, 1 hook, 4 functions, 13 types. Bevy's counterpart: `bevy_camera`. Source: [sdk/raea/src/camera.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/camera.ts).
+`raea/camera` exports 6 components, 1 hook, 4 functions, 1 value, 15 types. Bevy's counterpart: `bevy_camera`. Source: [sdk/raea/src/camera.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/camera.ts).
## Components
@@ -66,6 +66,26 @@ Bevy: `bevy_camera::components::Hdr`.
Used in: [3d/rotate_environment_map](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/bench/bevy-parity/3d/rotate_environment_map.tsx).
+### `Label`
+
+Page type that names a 3D part: drawn over the frame where the part's point lands through the shot's camera, at a
+size in pixels of the frame, inside title-safe, with a line to the point. Hidden while the point is behind the camera
+or out of frame. Put it beside the 3D, in the page, and give it the props the shot's Camera3d gets:
+
+`<Label at={[0, 1.2, 0]} camera={path.camera(frame)}>Reviews</Label>`
+
+| Prop | Type | What it does |
+| --- | --- | --- |
+| `at` (required) | `Vec3` | the point it names, in metres in the world: give the part's top, so the words stand clear above it |
+| `camera` (required) | `LabelCamera` | the shot's camera: the props its Camera3d is given (`path.camera(frame)`), so the label follows it exactly |
+| `children` (required) | `ReactNode` | its words |
+| `size` | `number` | capital height in px at 1080 lines, scaled to the frame (32; at least 22, so it reads) |
+| `side` | `"above" \| "below"` | which way the words stand from the point ("above") |
+| `gap` | `number` | the words' distance from the point, in px at 1080 lines (40) |
+| `leader` | `boolean` | a line from the words to a dot on the point (true) |
+| `color` | `string` | the words' and the line's colour (white) |
+| `style` | `CSSProperties` | more style for the words: font, weight, a background, padding |
+
### `Matchmove`
Footage with real 3D standing in it: the clip behind, its camera solved and followed, the subject in front. Fills
@@ -140,6 +160,12 @@ zoom) and the frame's window in it, in frame pixels.
function matchmoveView(footage: { width: number; height: number; }, frame: { width: number; height: number; }, crop?: number | [number, number], zoom?: number): { width: number; height: number; x: number; y: number; }
```
+## Values
+
+### `LABEL_MIN`
+
+The least capital height a Label takes, in px at 1080 lines (SG10's floor for words that read).
+
## Types
### `Camera3dProps`
@@ -203,6 +229,21 @@ Bevy: `bevy_camera::clear_color::ClearColorConfig`.
type ClearColorConfig = "Default" | "None" | { Custom: Srgba | LinearRgba }
```
+### `LabelCamera`
+
+The camera a Label projects through: the props its Camera3d is given.
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `transform` | `TransformValue` | where the camera stands and faces, as its Camera3d has it |
+| `projection` | `Projection` | its perspective (fov in radians, Bevy's default π/4) or orthographic view, as its Camera3d has it |
+
+### `LabelProps`
+
+Label's props: page type that points at a 3D part.
+
+The props of [`Label`](#label), tabled there.
+
### `MatchmoveCamera`
| Field | Type | What it is |
diff --git a/docs/manual/reference/sdk/index.md b/docs/manual/reference/sdk/index.md
index e7fd361f..4c479dc0 100644
--- a/docs/manual/reference/sdk/index.md
+++ b/docs/manual/reference/sdk/index.md
@@ -70,7 +70,7 @@ Bevy's 3D: cameras, lights, materials, meshes and the frame after it's drawn.
| Import | What it's for | Exports |
| --- | --- | --- |
| [`raea/3d`](3d.md) | raea's scene layer: models, physics, splats, matchmoves, instancing, custom shader passes and 3D text. | 70 components, 4 hooks, 26 functions, 3 classes, 12 values, 126 types |
-| [`raea/camera`](camera.md) | Cameras and the views they make: Camera3d, the Canvas3D a 2D scene draws in, HDR and matchmoved cameras. | 5 components, 1 hook, 4 functions, 13 types |
+| [`raea/camera`](camera.md) | Cameras and the views they make: Camera3d, the Canvas3D a 2D scene draws in, HDR and matchmoved cameras. | 6 components, 1 hook, 4 functions, 1 value, 15 types |
| [`raea/light`](light.md) | Bevy's lights in Bevy's units, environments, skies and daylight. | 15 components, 9 functions, 2 values, 15 types |
| [`raea/pbr`](pbr.md) | Materials and volumes: StandardMaterial, extended and toon materials, custom shaders, decals, fog and fire. | 22 components, 1 function, 1 value, 35 types |
| [`raea/mesh`](mesh.md) | Shapes and solids: Mesh3d and Mesh2d, Bevy's primitives, buffer meshes, instancing and exact solids. | 16 components, 1 function, 2 classes, 10 values, 26 types |
diff --git a/docs/stage-guards.feature b/docs/stage-guards.feature
index 8f3d536e..ffa53c17 100644
--- a/docs/stage-guards.feature
+++ b/docs/stage-guards.feature
@@ -214,9 +214,17 @@ Feature: Stage guards: a 3D render an agent can't break
Scenario: SG8. Labels that read
Given the plan
| crate | file | lines | job |
- | @raea/render | sdk/render/src/3d/label.tsx | 120 | Label: type drawn in the page at a part's projected point, from the engine's own camera; sized in pixels of the frame (at least 22 at 1080); kept clear of the parts' projected boxes |
+ | @raea/render | sdk/render/src/3d/label.tsx | 112 | Label: type drawn in the page at a part's projected point, from the engine's own camera; sized in pixels of the frame (at least 22 at 1080); kept clear of the parts' projected boxes |
+ | raea | sdk/raea/src/camera.ts | +2 | raea/camera exports Label |
+ | @raea/render | sdk/render/package.json | +1 | the ./3d/label subpath |
+ | raea (test) | sdk/raea/conformance/label.test.tsx | 60 | the point through a camera and a cameraPath, ortho, title-safe, px of the frame, refused under 22 |
Then type that points at a part is never at an angle, never tiny and never on top of the part
And RichText stays for type that is itself part of the scene (a sign, a page in a book)
+ # Status 11-21 (branch stage-guards-7): Label (raea/camera) projects its point through the props the shot's
+ # Camera3d gets (a cameraPath's camera(frame), perspective or orthographic) and draws flat page type there: its
+ # 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.
Rule: The render fails when a frame would look broken
Each check below reads the frame's scene (as systems/contact does) and the page's layout, runs in `raea render`
@@ -350,4 +358,7 @@ Feature: Stage guards: a 3D render an agent can't break
| render frame-pure: SG9 runs on every render; a chunked render is a workaround, never the plan |
And each rule names the check that enforces it
# Status 11-21 (branch stage-guards): sdk/guides/craft/bevy.md's rules 5 and 8-10 say these (grow by scale, one
- # clock, type that reads, a camera that settles). Left: the checks they name, Line3d, cameraPath and Label.
+ # clock, type that reads, a camera that settles). Branch stage-guards-7: rules 4, 5, 9, 10 and 11 name the check
+ # 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.
diff --git a/sdk/guides/craft/bevy.md b/sdk/guides/craft/bevy.md
index 6f147fb4..e3ec8585 100644
--- a/sdk/guides/craft/bevy.md
+++ b/sdk/guides/craft/bevy.md
@@ -64,11 +64,15 @@ the rest come from `raea`.
that takes degrees.
3. **Colours are hex** (`"#ff7a00"`), from the brand kit in a branded piece. CSS variables don't reach the 3D.
4. **Name what comes and goes.** Parts are matched across frames by `name`, else by kind and shape in tree order.
- A Mesh that appears, disappears or swaps places with one of the same shape needs a `name`.
+ A Mesh that appears, disappears or swaps places with one of the same shape needs a `name`, and so does a Fire or a
+ fog volume that comes and goes (a plate, a splat and a sequence are known by their file): SG2.
5. **Grow by scale; a changed shape is a new mesh.** Animate position, rotation, scale, colour, opacity, glow,
roughness and metalness. A part whose `shape`, `args` or words change is built again on each frame they change
(docs/stage-guards.feature SG1), which is right but costs a mesh a frame: a bar that grows is a fixed box scaled, and
- a counter's words change only when its number does.
+ a counter's words change only when its number does. A line that draws on is one `Line3d` or `Tube` cut at `p`
+ (`bevy/meshes`), never a chain of boxes: a chain of more than 8 parts named `NAME-i` that grows is the render's
+ `line-of-parts` warning, and a part whose size on screen jumps over 25% in a frame with no cut is its `part-snap`
+ (SG6, SG12).
6. **One camera a frame; each frame's own effects.** The first active camera in the tree is the piece's: give each
shot its own `<Camera3d>` and switch them with `is_active={...}`, so a cut between cameras is one render, not one
render a camera joined after (the frame another camera becomes active is drawn as a shot rendered alone starts,
@@ -84,16 +88,24 @@ the rest come from `raea`.
a prop to time a part: RichText's `at` and `exitAt` count in its Sequence's frames, and one past its last frame is
refused (SG5). Render a piece whole, one frame after another; a piece rendered in parts is a workaround, never the
plan.
-9. **Type that reads.** Words that name or point at a part go in the page over the 3D, sized in pixels of the frame,
- kept clear of the parts they name. Words in the world (a sign, a page in a book) are RichText: at least 22 px tall
+9. **Type that reads.** Words that name or point at a part are a `Label` (`raea/camera`): page type over the 3D,
+ placed where the part lands through the shot's own camera, sized in pixels of the frame, inside title-safe, with a
+ line to the point: `<Label at={partTop} camera={path.camera(frame)}>Reviews</Label>` (SG8). Words in the world (a sign, a page in a book) are RichText: at least 22 px tall
(caps) at 1080 lines, turned within 35° of the camera, inside the title-safe area, held still for their reading time
- (words ÷ 3 a second, plus half a second) and fully revealed before they go.
+ (words ÷ 3 a second, plus half a second) and fully revealed before they go. `raea render` fails on world type it
+ can't read (`type-small`, `type-angle` past 50°, `type-reveal`) and warns on the rest (`type-safe`, `type-time`, an
+ angle past 35°): SG10. A sign nobody is meant to read takes `read={false}`.
10. **A camera that settles.** Build a moving camera with `cameraPath` from `raea/camera`: keys timed by frames, the
path paced by time so its speed carries across each key, `hold` where it stops, and `<Camera3d
{...path.camera(frame)} />`. A hand-written spline whose segments each run 0 to 1 whatever their length jumps speed
at every key (11-21: 51 of 155 keys jumped 2x or more). `path.check()` names a key whose timing still makes the
camera brake hard (a quick move against a slow one): give the quick move more frames or end the slow one in a hold.
Never push in and pull back, or pan one way then the other, within 1.5 s. A camera still moving while words are up
- gives them their reading time first.
-11. **Render and look.** Render stills where things happen (`raea render edit.tsx --at A,B,C -o stills/`) and look at them. A 3D frame that renders
- black usually has no light or a camera inside or behind the subject.
+ gives them their reading time first. `raea render` fails on a speed that changes over 2x within 3 frames
+ (`camera-lurch`) and on a dolly in and back out (`camera-reverse`): SG13.
+11. **Render and look.** Before a render, `raea scene stage edit.tsx` steps every frame without drawing and runs the
+ checks above, and the render runs them again at its end, beside clipping: it warns when almost nothing is on screen
+ for a second (`frame-empty`) or the shot's part is cut by the edge (`subject-cut`), SG14. Render stills where things
+ happen (`raea render edit.tsx --at A,B,C -o stills/`) and look at them. A 3D frame that renders black usually has no
+ light or a camera inside or behind the subject. `raea show` refuses a render that still holds an error, naming each:
+ fix it, or say why it goes anyway with `--despite CHECK "why"`, which the person reads (SG15).
diff --git a/sdk/guides/craft/floor.md b/sdk/guides/craft/floor.md
index 120ac9ff..85c7df5e 100644
--- a/sdk/guides/craft/floor.md
+++ b/sdk/guides/craft/floor.md
@@ -46,6 +46,9 @@ direction asks for it by name, and the direction then says why in a line.
- **Close-ups with no reason.** A cut to a detail has to answer something the viewer just wondered about.
- **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 in
+ pixels 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).
- **Cameras that ease from A to B and stop.** A camera keeps moving at the start and end of a shot, so cuts join
motion 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 BPM
diff --git a/sdk/raea/conformance/label.test.tsx b/sdk/raea/conformance/label.test.tsx
new file mode 100644
index 00000000..e736c9db
--- /dev/null
+++ b/sdk/raea/conformance/label.test.tsx
@@ -0,0 +1,60 @@
+// Labels that read (docs/stage-guards.feature SG8): words that point at a part are page type, placed where the part
+// lands through the shot's own camera, sized in pixels of the frame, inside title-safe, never turned and never tiny.
+import { describe, expect, test } from "bun:test";
+import { Label, cameraPath } from "../src/camera";
+import { Camera3d } from "../src/camera";
+import { Transform } from "../src/transform";
+import { labelPlace, project } from "@raea/render/3d/label";
+import { renderFrame } from "../src/test";
+
+const W = 1920, H = 1080;
+const html = (el: React.ReactElement, height = H, width = W) => renderFrame(el, { frame: 0, width, height, fps: 30, durationInFrames: 30 });
+const cam = { transform: Transform.fromXyz(0, 1.5, 5).lookingAt([0, 1.5, 0]) };
+const near = (a: number, b: number, e = 1e-6) => Math.abs(a - b) <= e;
+
+describe("SG8: labels that read", () => {
+ test("a point lands where the camera sees it: the centre, its height by the fov, behind and outside are nowhere", () => {
+ const c = project([0, 1.5, 0], cam, W, H)!;
+ expect(near(c[0], W / 2) && near(c[1], H / 2) && near(c[2], 5)).toBe(true);
+ // a metre up at 5 m with a 45° vertical fov: (H/2) / tan(22.5°) / 5 px up
+ const up = project([0, 2.5, 0], cam, W, H)!;
+ expect(near(up[1], H / 2 - H / 2 / Math.tan(Math.PI / 8) / 5)).toBe(true);
+ expect(project([0, 1.5, 9], cam, W, H)).toBeUndefined();
+ expect(project([40, 1.5, 0], cam, W, H)).toBeUndefined();
+ // the props a cameraPath hands its Camera3d, fov and all
+ const path = cameraPath([{ at: 0, pos: [0, 1.5, 5], look: [0, 1.5, 0], fov: 30 }, { at: 30, pos: [0, 1.5, 4], look: [0, 1.5, 0], fov: 30 }]);
+ const p30 = project([0, 2.5, 0], path.camera(0), W, H)!;
+ expect(near(p30[1], H / 2 - H / 2 / Math.tan(Math.PI / 12) / 5)).toBe(true);
+ // an orthographic camera: its view's height in metres
+ const ortho = project([1, 1.5, 0], { ...cam, projection: { Orthographic: { scaling_mode: { FixedVertical: { viewport_height: 4 } } } } }, W, H)!;
+ expect(near(ortho[0], W / 2 + H / 4)).toBe(true);
+ });
+
+ test("the words stay inside title-safe and grow away from the nearer edge", () => {
+ const mid = labelPlace([W / 2, H / 2], W, H, "above", 40, 40);
+ expect(near(mid.ax, W / 2) && near(mid.ay, H / 2 - 40) && near(mid.along, 0.5)).toBe(true);
+ const left = labelPlace([10, 30], W, H, "above", 40, 40);
+ expect(left.ax).toBe(0.05 * W);
+ expect(left.along).toBe(0);
+ expect(left.ay).toBeGreaterThanOrEqual(0.05 * H + 48);
+ const right = labelPlace([W - 1, H - 5], W, H, "below", 40, 40);
+ expect(right.along).toBe(1);
+ expect(right.ay).toBeLessThanOrEqual(0.95 * H - 48);
+ });
+
+ test("drawn in the page, sized in pixels of the frame, with a line to the point; nothing when the point isn't seen", () => {
+ const out = html(<><Camera3d {...cam} /><Label at={[0, 1.5, 0]} camera={cam}>Reviews</Label></>);
+ expect(out).toContain('data-label=""');
+ expect(out).toContain("Reviews");
+ expect(out).toContain("data-label-leader");
+ // 32 px capitals at 1080 lines: a 45.7 px font; at 540 lines half that
+ expect(out).toMatch(/font-size:\s*45\.7\d*px/);
+ expect(html(<Label at={[0, 1.5, 0]} camera={cam}>Reviews</Label>, 540, 960)).toMatch(/font-size:\s*22\.8\d*px/);
+ expect(html(<Label at={[0, 1.5, 9]} camera={cam}>Behind</Label>)).not.toContain("Behind");
+ expect(html(<Label at={[0, 1.5, 0]} camera={cam} leader={false}>Reviews</Label>)).not.toContain("data-label-leader");
+ });
+
+ test("never tiny", () => {
+ expect(() => html(<Label at={[0, 1.5, 0]} camera={cam} size={16}>Reviews</Label>)).toThrow("at least 22 px");
+ });
+});
diff --git a/sdk/raea/src/camera.ts b/sdk/raea/src/camera.ts
index b7008498..396e2768 100644
--- a/sdk/raea/src/camera.ts
+++ b/sdk/raea/src/camera.ts
@@ -8,3 +8,5 @@ export { Camera3d, Hdr, type Camera3dProps, type CameraViewport, type ClearColor
export { TextureView } from "@raea/render/bevy3d";
// a camera path paced by time, so it can't lurch at a key (docs/stage-guards.feature SG7)
export { cameraPath, type CameraKey, type CameraPath, type CameraPose, type CameraVec3 } from "@raea/render/camera/path";
+// page type that names a 3D part, placed through the shot's camera (docs/stage-guards.feature SG8)
+export { Label, LABEL_MIN, type LabelProps, type LabelCamera } from "@raea/render/3d/label";
diff --git a/sdk/render/package.json b/sdk/render/package.json
index 921a7f6b..3c55cd45 100644
--- a/sdk/render/package.json
+++ b/sdk/render/package.json
@@ -24,7 +24,8 @@
"./feathers": "./src/feathers.ts",
"./camera/path": "./src/camera/path.ts",
"./3d/clock": "./src/3d/clock.ts",
- "./3d/line": "./src/3d/line.tsx"
+ "./3d/line": "./src/3d/line.tsx",
+ "./3d/label": "./src/3d/label.tsx"
},
"raea": {
"plugins": {
diff --git a/sdk/render/src/3d/label.tsx b/sdk/render/src/3d/label.tsx
new file mode 100644
index 00000000..64362bf2
--- /dev/null
+++ b/sdk/render/src/3d/label.tsx
@@ -0,0 +1,112 @@
+// Labels that read (docs/stage-guards.feature SG8). Words that name or point at a 3D part were written into the world as
+// RichText, where they turned with the floor and shrank with distance: the essay's floor labels read at 60 to 75
+// degrees, its code at 3 to 7 px. A Label is page type instead: drawn flat over the frame at the point its part
+// projects to through the shot's own camera (the props its Camera3d is given), sized in pixels of the frame, kept
+// inside the title-safe area, with a line to the point. It never turns, never shrinks and stands clear of the part.
+import type { CSSProperties, ReactNode } from "react";
+import { useVideoConfig } from "@raea/app/clock";
+import { Quat, type Projection, type TransformValue } from "../bevy3d/core";
+import type { Vec3 } from "./core";
+
+/** The least capital height a Label takes, in px at 1080 lines (SG10's floor for words that read). */
+export const LABEL_MIN = 22;
+/** The title-safe area's inset from each edge, a share of the frame (as raea-sys-stage's type-safe has it). */
+const SAFE = 0.05;
+/** A capital's height as a share of the font's size. */
+const CAP = 0.7;
+
+/** The camera a Label projects through: the props its Camera3d is given. */
+export interface LabelCamera {
+ /** where the camera stands and faces, as its Camera3d has it */
+ transform?: TransformValue;
+ /** its perspective (fov in radians, Bevy's default π/4) or orthographic view, as its Camera3d has it */
+ projection?: Projection;
+}
+
+/** Label's props: page type that points at a 3D part. */
+export interface LabelProps {
+ /** the point it names, in metres in the world: give the part's top, so the words stand clear above it */
+ at: Vec3;
+ /** the shot's camera: the props its Camera3d is given (`path.camera(frame)`), so the label follows it exactly */
+ camera: LabelCamera;
+ /** its words */
+ children: ReactNode;
+ /** capital height in px at 1080 lines, scaled to the frame (32; at least 22, so it reads) */
+ size?: number;
+ /** which way the words stand from the point ("above") */
+ side?: "above" | "below";
+ /** the words' distance from the point, in px at 1080 lines (40) */
+ gap?: number;
+ /** a line from the words to a dot on the point (true) */
+ leader?: boolean;
+ /** the words' and the line's colour (white) */
+ color?: string;
+ /** more style for the words: font, weight, a background, padding */
+ style?: CSSProperties;
+}
+
+/** Where a world point lands in a frame of width x height through a camera: [x, y] in px from the top left and its
+ * distance in front of the camera, or nothing when it's behind the camera or outside the frame. */
+export function project(at: Vec3, camera: LabelCamera, width: number, height: number): [number, number, number] | undefined {
+ const eye = camera.transform?.translation ?? [0, 0, 0];
+ const q = camera.transform?.rotation ?? Quat.IDENTITY;
+ const proj = camera.projection ?? { Perspective: {} };
+ // into the camera's own space: it looks along its -Z, +Y up
+ const c = Quat.mulVec3([-q[0], -q[1], -q[2], q[3]], [at[0] - eye[0], at[1] - eye[1], at[2] - eye[2]]);
+ const z = -c[2];
+ let s: number;
+ if ("Orthographic" in proj) {
+ s = height / (proj.Orthographic.scaling_mode?.FixedVertical.viewport_height ?? 10);
+ } else {
+ if (z <= (proj.Perspective.near ?? 0.1)) return undefined;
+ s = height / 2 / Math.tan((proj.Perspective.fov ?? Math.PI / 4) / 2) / z;
+ }
+ const x = width / 2 + c[0] * s;
+ const y = height / 2 - c[1] * s;
+ return x < 0 || x > width || y < 0 || y > height ? undefined : [x, y, z];
+}
+
+/** Where a Label's words go: the point, the words' anchor (on their near edge, inside title-safe) and how far along
+ * their width the anchor sits (0 at their left, 1 at their right), so they grow away from the nearer side. */
+export function labelPlace(point: [number, number], width: number, height: number, side: "above" | "below", gap: number, font: number) {
+ const [lo, hi] = [SAFE * width, (1 - SAFE) * width];
+ const ax = Math.min(hi, Math.max(lo, point[0]));
+ const want = point[1] + (side === "above" ? -gap : gap);
+ // a line of words fits between the anchor and the safe area's edge
+ const ay = side === "above" ? Math.max(SAFE * height + font * 1.2, Math.min((1 - SAFE) * height, want)) : Math.min((1 - SAFE) * height - font * 1.2, Math.max(SAFE * height, want));
+ return { ax, ay, along: (ax - lo) / (hi - lo), lo, hi };
+}
+
+/** Page type that names a 3D part: drawn over the frame where the part's point lands through the shot's camera, at a
+ * size in pixels of the frame, inside title-safe, with a line to the point. Hidden while the point is behind the camera
+ * or out of frame. Put it beside the 3D, in the page, and give it the props the shot's Camera3d gets:
+ *
+ * `<Label at={[0, 1.2, 0]} camera={path.camera(frame)}>Reviews</Label>` */
+export function Label({ at, camera, children, size = 32, side = "above", gap = 40, leader = true, color = "#ffffff", style }: LabelProps) {
+ if (!(size >= LABEL_MIN)) throw new RangeError(`Label: size is at least ${LABEL_MIN} px of capital height at 1080 lines, so it reads (SG10); got ${size}`);
+ if (side !== "above" && side !== "below") throw new TypeError(`Label: side is "above" or "below", got ${JSON.stringify(side)}`);
+ const { width, height } = useVideoConfig();
+ const p = project(at, camera, width, height);
+ if (!p) return null;
+ const k = height / 1080;
+ const font = (size * k) / CAP;
+ const { ax, ay, along, lo, hi } = labelPlace([p[0], p[1]], width, height, side, gap * k, font);
+ // the words' box spans the safe width; spacers grown in the ratio along : 1 - along put the point `along` its width
+ // at ax (no transform: the page lays it out as it is)
+ const row: CSSProperties = { position: "absolute", left: lo, width: hi - lo, display: "flex", flexDirection: "row", ...(side === "above" ? { bottom: height - ay } : { top: ay }) };
+ return (
+ <>
+ {leader ? (
+ <svg data-label-leader="" width={width} height={height} style={{ position: "absolute", left: 0, top: 0 }}>
+ <line x1={p[0]} y1={p[1]} x2={ax} y2={ay} stroke={color} strokeWidth={Math.max(1, 2 * k)} />
+ <circle cx={p[0]} cy={p[1]} r={Math.max(2, 4 * k)} fill={color} />
+ </svg>
+ ) : 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>
+ <div style={{ flexGrow: 1 - along, flexShrink: 1, flexBasis: 0 }} />
+ </div>
+ </>
+ );
+}
diff --git a/skills b/skills
index 06a182b7..7c3fd035 160000
--- a/skills
+++ b/skills
@@ -1 +1 @@
-Subproject commit 06a182b7006068e29643115fe72864fe160e2d58
+Subproject commit 7c3fd03553df5d65882ba24119f284610476b8b0