@hackbuild/motion-views 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Moheeb Zara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,176 @@
1
- # Temporary Holding Version
1
+ # @hackbuild/motion-views
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Put a character stage, an avatar drop card and a clip strip on your page, drawn with the hackbuild-ui stylesheet, as custom elements or Vue components.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@hackbuild/motion-views)](https://www.npmjs.com/package/@hackbuild/motion-views) [![licence MIT](https://img.shields.io/badge/licence-MIT-blue)](../../LICENSE) ![gzip 3.3 kB measured](https://img.shields.io/badge/gzip-3.3%20kB-blue) ![types included](https://img.shields.io/badge/types-included-blue)
6
+
7
+ ## What it does
8
+
9
+ - `CharacterStage`: a body on a lit stage with idle, gaze, blinks and lips, a corner plate, turn around and framing tools, a verb row and an inset slot. It speaks real audio with word timings, or text alone on estimated timings.
10
+ - `AvatarDrop`: a drop zone and pick button that loads a VRM, GLB or FBX once, checks its rig in plain words, draws a still and shows the avatar card.
11
+ - `ClipStrip`: each clip's still, name and length, the picked one pressed and one play button.
12
+ - Ships every view as a mount function, a custom element and a Vue 3 component, on one code path.
13
+ - Carries no styles of its own; every class is hackbuild-ui's.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ npm install @hackbuild/motion-views three @virgilvox/hackbuild-ui
19
+ ```
20
+
21
+ `@virgilvox/hackbuild-ui` 0.10 is a required peer, and the page loads its stylesheet (`@virgilvox/hackbuild-ui/styles.css`). three.js is needed by the views; Vue only by `/vue`. It depends on `@hackbuild/avatar`, `@hackbuild/avatar-host`, `@hackbuild/presence`, `@hackbuild/lipsync` and `@hackbuild/organic`, which install with it.
22
+
23
+ | subpath | needs | pin |
24
+ |---|---|---|
25
+ | `@hackbuild/motion-views` | nothing; the words, clip items and speech timings | none |
26
+ | `@hackbuild/motion-views/vanilla` | `three` (optional peer), `@virgilvox/hackbuild-ui` (peer) | three 0.186.1 or later, hackbuild-ui `>=0.10.0 <0.11.0` |
27
+ | `@hackbuild/motion-views/vue` | `vue` (optional peer) and the above | vue 3.5.0 or later |
28
+ | `@hackbuild/motion-views/iife` | `THREE` on the page | one classic script |
29
+
30
+ ## Quick start
31
+
32
+ ```ts
33
+ import { avatarDrop, characterStage } from "@hackbuild/motion-views/vanilla";
34
+
35
+ // the stage shows a placeholder body built in code until you give it one
36
+ const host = document.createElement("div");
37
+ host.style.height = "480px";
38
+ document.body.append(host);
39
+ const stage = characterStage(host, { name: "stand-in", hello: "hello. drop a vrm, glb or fbx on me." });
40
+ stage.on((e) => e.type === "doing" && console.log("doing", e.word));
41
+
42
+ // a drop card: press the card of a checked avatar to put it on the stage
43
+ const card = document.body.appendChild(document.createElement("div"));
44
+ avatarDrop(card).on((e) => {
45
+ if (e.type === "checked") console.log(e.report.check.head, e.report.size);
46
+ if (e.type === "use") void stage.show(e.files);
47
+ });
48
+
49
+ // text alone moves the lips on estimated word timings, with no sound
50
+ await stage.say("you can drop a model on me");
51
+ stage.gesture("wave");
52
+ ```
53
+
54
+ ## Live example
55
+
56
+ The demo pages run each view on the placeholder body built in code: [character stage](https://hackbuild.github.io/hackbuild-motion/character-stage/), [avatar drop](https://hackbuild.github.io/hackbuild-motion/avatar-drop/) and [clip strip](https://hackbuild.github.io/hackbuild-motion/clip-strip/). The package page is [hackbuild-motion/motion-views](https://hackbuild.github.io/hackbuild-motion/motion-views/), and the suite's character screen runs on it: [hackbuild-suite character](https://hackbuild.github.io/hackbuild-suite/#/character).
57
+
58
+ ## Concepts
59
+
60
+ ### one view, three ways to mount it
61
+
62
+ `characterStage(host, opts)`, `avatarDrop(host, opts)` and `clipStrip(host, opts)` mount into an element and return a handle with `on(fn)` and `dispose()`. `defineMotionViews(opts)` defines `hb-character-stage`, `hb-avatar-drop` and `hb-clip-strip`, which dispatch the view's events as DOM events with the event as `detail` and keep the handle on `.handle`; importing defines nothing. The Vue components take the same options as props and emit the same events by type.
63
+
64
+ ```ts
65
+ defineMotionViews({ stage: { vrm: () => import("@hackbuild/avatar/vrm").then((m) => m.vrmHook()) } });
66
+ const stage = document.querySelector<CharacterStageElement>("hb-character-stage")!;
67
+ document.querySelector("hb-avatar-drop")!.addEventListener("picked", (e) => stage.handle?.show((e as CustomEvent).detail.files));
68
+ ```
69
+
70
+ ### speech on the stage
71
+
72
+ `say(speech)` plays an AudioBuffer or an audio element through an analyser whose level and bands open the mouth, with the word or phoneme timings a speech engine reports. Text alone moves the lips on estimated word timings with no sound. `speechSource` says where the last timings came from. `gesture("wave" | "nod" | "shake" | "bow")` plays a gesture written in code over the body's own bones, and `play(clip)` plays a presence clip or a three.js AnimationClip.
73
+
74
+ ### the rig check in plain words
75
+
76
+ `rigCheck(facts)` turns what a loaded body can do into a headline ("ready to act", "ready, with limits", "cannot act") and lines worst first, such as "no mouth shapes. the lips stay still while it talks." `sizeLine` and `licenceLine` give the card's other lines; the licence is the one the file states.
77
+
78
+ ### clip items from any source
79
+
80
+ `clipsFromPack` (a `@hackbuild/bake` pack and report, with a warning on a loop that does not close), `clipFromFindings` (a `@hackbuild/retarget` motion) and `clipsFromBody` all give one `ClipItem` shape for the strip. They read structural types, so the main entry needs neither wasm package.
81
+
82
+ ### hackbuild-ui classes only
83
+
84
+ The stage writes a `.hb-lay-stage`, the card is `.hb-avcard`, the strip `.hb-clipstrip`. A view adds no style of its own, so it looks like the rest of a page that loads the hackbuild-ui stylesheet.
85
+
86
+ ## API overview
87
+
88
+ | export | what it does |
89
+ |---|---|
90
+ | [`characterStage`](../../docs/api/motion-views/vanilla.md#characterstage) | mount the character stage |
91
+ | [`CharacterStageHandle`](../../docs/api/motion-views/vanilla.md#characterstagehandle) | show a body, say, gesture, play, frame and listen |
92
+ | [`avatarDrop`](../../docs/api/motion-views/vanilla.md#avatardrop) | mount the drop zone and avatar card |
93
+ | [`AvatarReport`](../../docs/api/motion-views/vanilla.md#avatarreport) | what the drop learned about an avatar |
94
+ | [`clipStrip`](../../docs/api/motion-views/vanilla.md#clipstrip) | mount the clip strip |
95
+ | [`defineMotionViews`](../../docs/api/motion-views/vanilla.md#definemotionviews) | define the three custom elements |
96
+ | [`gestureClip`](../../docs/api/motion-views/vanilla.md#gestureclip) | a gesture written in code as a clip |
97
+ | [`CharacterStage`](../../docs/api/motion-views/vue.md#characterstage) | the stage as a Vue component |
98
+ | [`AvatarDrop`](../../docs/api/motion-views/vue.md#avatardrop) | the drop card as a Vue component |
99
+ | [`ClipStrip`](../../docs/api/motion-views/vue.md#clipstrip) | the strip as a Vue component |
100
+ | [`rigCheck`](../../docs/api/motion-views/index.md#rigcheck) | what a body can do, in plain words |
101
+ | [`sizeLine`](../../docs/api/motion-views/index.md#sizeline) | the size line of the avatar card |
102
+ | [`clipsFromPack`](../../docs/api/motion-views/index.md#clipsfrompack) | clip items from a baked pack |
103
+ | [`speechEvents`](../../docs/api/motion-views/index.md#speechevents) | what a speech becomes on the mouth clock |
104
+
105
+ The full reference is in [docs/api/motion-views](../../docs/api/motion-views/README.md).
106
+
107
+ ## Browser support
108
+
109
+ | feature | needs | notes |
110
+ |---|---|---|
111
+ | main entry | any JavaScript runtime | no DOM, no three.js, runs in Node |
112
+ | the views | WebGL through three.js, custom elements | the stage pauses while hidden or off screen |
113
+ | real speech | Web Audio | an AudioContext is made on the first audio unless you pass `audioContext` |
114
+ | avatar stills | WebGL | `report.thumb` is null with no WebGL |
115
+ | single file build | `dist/motion-views.iife.js` | the vanilla entry as one classic script, `THREE` read from the page, runs from file:// |
116
+
117
+ The views ran in headless Chrome on macOS; Safari, Firefox and phones are unknown.
118
+
119
+ ## Errors and troubleshooting
120
+
121
+ The views throw nothing to your code; a failure becomes an event and a plain line on screen.
122
+
123
+ | message | cause | what to do |
124
+ |---|---|---|
125
+ | a `failed` event from CharacterStage | the body could not load from the URL or files | read `e.message`; give the model with its textures, or a VRM, GLB or FBX |
126
+ | a `failed` event from AvatarDrop | the dropped files held no body it could read | drop a .vrm, .glb, .gltf with its .bin and textures, or .fbx |
127
+ | `-1` from `play` | the clip cannot play on this body | check the body has the bones the clip moves |
128
+ | `false` from `gesture` | the body lacks the bones the gesture needs | check the rig check lines of the body |
129
+
130
+ ## Works with
131
+
132
+ - [@hackbuild/avatar-host](../avatar-host/README.md) is the stage under CharacterStage and draws the clip stills.
133
+ - [@hackbuild/avatar](../avatar/README.md) loads the VRM, GLB and FBX files.
134
+ - [@hackbuild/presence](../presence/README.md) and [@hackbuild/lipsync](../lipsync/README.md) give idle, gaze, blinks and lips.
135
+ - [@hackbuild/bake](../bake/README.md) and [@hackbuild/retarget](../retarget/README.md) make the clips the strip lists.
136
+
137
+ ## Changelog and licences
138
+
139
+ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LICENSE](../../LICENSE)); this README is CC-BY-4.0 with its code samples also MIT. No model or weight file ships here; an avatar keeps the licence its file states, which the card shows.
140
+
141
+ ## What is verified, and what is not
142
+
143
+ ### Verified on this machine
144
+
145
+ | check | result |
146
+ |---|---|
147
+ | `node tools/smoke-views.mjs` in headless Chrome on macOS 12 | pass |
148
+ | the stand-in shows and a frame is drawn | pass |
149
+ | the full body shot stands further back than the bust | 2.78 m to 4.03 m (measured) |
150
+ | say hello plays audio written in code with word timings and the level reaches the lips | peak 0.215 (measured) |
151
+ | audio with no timings moves the lips by level; text alone falls back to estimated timings; quiet when the audio ends | pass |
152
+ | wave plays on the upper body; turn around turns the body half a circle | pass |
153
+ | the stand-in written as a .glb loads, maps 24 bones, gets a still and reads "no licence in the file" | pass (measured) |
154
+ | a text file is refused in plain words | pass |
155
+ | a bvh walk retargets onto the stand-in; six clips bake into one pack and read back; a loop cut short is flagged at its seam | pass |
156
+ | the three demo pages at 1440 and 390 px against the suite's screen gate | pass |
157
+ | unit tests over the words and the clip items | pass |
158
+
159
+ ### Not verified by anything
160
+
161
+ - Speech from a real speech engine; the smoke's voice is a hum written in code with word timings in an engine's shape.
162
+ - A real VRM, GLB or FBX avatar with a face; the smoke uses the stand-in built in code, which has no mouth or blink shapes.
163
+ - The Vue components in a running Vue app; they typecheck, and no page mounts them yet.
164
+ - Frame rate on a real GPU, since the smoke runs headless.
165
+ - AvatarDrop loads the file once and the stage loads it again, so a large file is read twice.
166
+
167
+ ## Size budget
168
+
169
+ | file | gzip (measured) | ceiling |
170
+ |---|---|---|
171
+ | `dist/index.js` (main entry, imports external) | 3,266 bytes | 3,429 bytes |
172
+ | `dist/motion-views.iife.js` (single file build) | 215,543 bytes | 226,320 bytes |
173
+
174
+ Measured 2026-11-25 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
175
+ tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
176
+ 5 percent from its row.
@@ -0,0 +1,56 @@
1
+ import { type DroppedFile } from "@hackbuild/avatar-host";
2
+ import { type BodyCaps, type BodyLoadOptions } from "@hackbuild/avatar-host/three";
3
+ import { type RigCheck, type RigLine } from "./words.js";
4
+ /** What AvatarDrop learned about a dropped avatar: name, format, size, rig check, licence and still. */
5
+ export interface AvatarReport {
6
+ name: string;
7
+ format: string;
8
+ bytes: number;
9
+ files: number;
10
+ triangles: number;
11
+ caps: BodyCaps;
12
+ check: RigCheck;
13
+ licence: RigLine;
14
+ size: string;
15
+ /** The still, a PNG, or null when there is no webgl. */
16
+ thumb: Blob | null;
17
+ }
18
+ /** Options of `avatarDrop`: the load options of a body plus the pick button and hint words. */
19
+ export interface AvatarDropOptions extends BodyLoadOptions {
20
+ /** The pick button is the one pink action of the screen. Default false. */
21
+ go?: boolean;
22
+ /** The pick button's words. */
23
+ label?: string;
24
+ /** The line in the empty zone. */
25
+ hint?: string;
26
+ }
27
+ /** Events of AvatarDrop: files picked, the report checked, a failure, or the card pressed to use the avatar. */
28
+ export type AvatarDropEvent = {
29
+ type: "picked";
30
+ files: readonly DroppedFile[];
31
+ } | {
32
+ type: "checked";
33
+ report: AvatarReport;
34
+ files: readonly DroppedFile[];
35
+ } | {
36
+ type: "failed";
37
+ message: string;
38
+ }
39
+ /** The card was pressed: wear this avatar. */
40
+ | {
41
+ type: "use";
42
+ report: AvatarReport;
43
+ files: readonly DroppedFile[];
44
+ };
45
+ /** The handle `avatarDrop` returns: the last report, take files, open the picker, listen, dispose. */
46
+ export interface AvatarDropHandle {
47
+ readonly report: AvatarReport | null;
48
+ /** Reads files as a drop would. Resolves to the report, or null when the files held no body it could read. */
49
+ take(files: readonly DroppedFile[]): Promise<AvatarReport | null>;
50
+ /** Opens the file picker. */
51
+ pick(): void;
52
+ on(fn: (e: AvatarDropEvent) => void): () => void;
53
+ dispose(): void;
54
+ }
55
+ /** Mounts the drop card into `host`. */
56
+ export declare function avatarDrop(host: HTMLElement, opts?: AvatarDropOptions): AvatarDropHandle;
@@ -0,0 +1,153 @@
1
+ import { seededRng } from "@hackbuild/organic";
2
+ import { sniffFormat } from "@hackbuild/avatar";
3
+ import { bodyError, sourceFromFiles } from "@hackbuild/avatar-host";
4
+ import { Body, loadBody } from "@hackbuild/avatar-host/three";
5
+ import { dropRoutes } from "@virgilvox/hackbuild-ui/vanilla";
6
+ import { button, el, statusLine, urlSlot } from "./dom.js";
7
+ import { Still } from "./thumb.js";
8
+ import { licenceLine, rigCheck, sizeLine } from "./words.js";
9
+ const ACCEPT = ".vrm,.glb,.gltf,.fbx,.png,.jpg,.jpeg,.tga,.bin";
10
+ function triangles(root) {
11
+ let n = 0;
12
+ root.traverse((o) => {
13
+ const g = o.isMesh ? o.geometry : null;
14
+ if (!g)
15
+ return;
16
+ n += Math.floor((g.index ? g.index.count : (g.getAttribute("position")?.count ?? 0)) / 3);
17
+ });
18
+ return n;
19
+ }
20
+ /** Mounts the drop card into `host`. */
21
+ export function avatarDrop(host, opts = {}) {
22
+ const doc = host.ownerDocument;
23
+ const input = el(doc, "input", "", { type: "file", multiple: true, accept: ACCEPT, hidden: true, "aria-label": "pick an avatar file" });
24
+ const pickBtn = button(doc, opts.label ?? "pick a file", opts.go === true, { "data-pick": "" });
25
+ const zone = el(doc, "div", "hb-dropzone", {}, [el(doc, "span", "", {}, [opts.hint ?? "drop a .vrm, .glb or .fbx here, with its textures"]), pickBtn, input]);
26
+ // the card is hackbuild-ui's avatar card: still, name, size line, rig line; pressing it uses the avatar
27
+ const thumbBox = el(doc, "span", "hb-avcard-thumb");
28
+ const nameEl = el(doc, "span", "hb-avcard-name");
29
+ const sizeEl = el(doc, "span", "hb-avcard-meta");
30
+ const rigEl = el(doc, "span", "hb-avcard-rig");
31
+ const head = el(doc, "button", "hb-avcard", { type: "button", hidden: true, "aria-pressed": "false" }, [thumbBox, el(doc, "span", "hb-avcard-body", {}, [nameEl, sizeEl, rigEl])]);
32
+ const lines = el(doc, "div", "", { role: "status", "aria-live": "polite" });
33
+ host.append(zone, head, lines);
34
+ const listeners = new Set();
35
+ const emit = (e) => {
36
+ for (const f of listeners)
37
+ f(e);
38
+ };
39
+ const still = new Still(doc);
40
+ const thumbUrl = urlSlot();
41
+ let report = null;
42
+ let lastFiles = null;
43
+ let ticket = 0;
44
+ let hook = null;
45
+ async function take(files) {
46
+ const mine = ++ticket;
47
+ emit({ type: "picked", files });
48
+ lines.replaceChildren(statusLine(doc, "reading the file.", "busy"));
49
+ let body = null;
50
+ try {
51
+ const src = sourceFromFiles(files);
52
+ const model = files.find((f) => f.name === src.name || (f.webkitRelativePath ?? "").endsWith(src.name)) ?? files[0];
53
+ const format = sniffFormat(new Uint8Array(await model.slice(0, 64 * 1024).arrayBuffer()), model.name);
54
+ const vrm = src.kind === "vrm" && opts.vrm ? await (hook ??= opts.vrm()) : null;
55
+ const avatar = await loadBody(src, vrm, opts);
56
+ src.release?.();
57
+ if (mine !== ticket) {
58
+ avatar.dispose();
59
+ return null;
60
+ }
61
+ body = new Body(avatar, { rng: seededRng("avatar-drop") });
62
+ const bytes = files.reduce((s, f) => s + f.size, 0);
63
+ const tris = triangles(avatar.root);
64
+ avatar.update(0);
65
+ const thumb = await still.draw(avatar.root);
66
+ const check = rigCheck({ bones: body.names, expressions: body.caps.expressions, clips: body.caps.clips, mouth: body.caps.mouth, blink: body.caps.blink, gaze: body.caps.gaze, warnings: avatar.warnings });
67
+ const r = {
68
+ name: src.name.replace(/\.[^.]+$/, ""),
69
+ format: format === "unknown" ? src.kind : format,
70
+ bytes,
71
+ files: files.length,
72
+ triangles: tris,
73
+ caps: body.caps,
74
+ check,
75
+ licence: licenceLine(format, (avatar.vrm?.meta ?? null)),
76
+ size: sizeLine({ bytes, format: format === "unknown" ? src.kind : format, files: files.length, triangles: tris }),
77
+ thumb,
78
+ };
79
+ if (mine !== ticket)
80
+ return null;
81
+ report = r;
82
+ lastFiles = files;
83
+ head.setAttribute("aria-pressed", "false");
84
+ head.classList.remove("is-on");
85
+ draw(r);
86
+ emit({ type: "checked", report: r, files });
87
+ return r;
88
+ }
89
+ catch (e) {
90
+ if (mine !== ticket)
91
+ return null;
92
+ const message = bodyError(e);
93
+ lines.replaceChildren(statusLine(doc, message, "bad"));
94
+ emit({ type: "failed", message });
95
+ return null;
96
+ }
97
+ finally {
98
+ body?.dispose();
99
+ }
100
+ }
101
+ function draw(r) {
102
+ head.hidden = false;
103
+ const src = thumbUrl(r.thumb);
104
+ thumbBox.replaceChildren(src ? el(doc, "img", "", { src, alt: "" }) : el(doc, "span", "", { "aria-hidden": "true" }, [r.name.slice(0, 1)]));
105
+ nameEl.textContent = r.name;
106
+ sizeEl.textContent = r.size;
107
+ const worst = r.check.lines.find((l) => l.tone !== "ok");
108
+ rigEl.textContent = worst ? `${r.check.head}: ${worst.text}` : `${r.check.head}, ${r.caps.bones} bones`;
109
+ rigEl.className = `hb-avcard-rig ${r.check.tone === "bad" ? "is-bad" : "is-ok"}`;
110
+ head.setAttribute("aria-label", `use ${r.name}, ${r.size}`);
111
+ const tone = (t) => (t === "bad" ? "bad" : t === "warn" ? "warn" : "ok");
112
+ lines.replaceChildren(...r.check.lines.filter((l) => l !== worst).map((l) => statusLine(doc, l.text, tone(l.tone))), statusLine(doc, r.licence.text, tone(r.licence.tone)));
113
+ pickBtn.textContent = "pick another";
114
+ }
115
+ const ac = new AbortController();
116
+ pickBtn.addEventListener("click", () => input.click(), { signal: ac.signal });
117
+ head.addEventListener("click", () => {
118
+ if (!report || !lastFiles)
119
+ return;
120
+ head.setAttribute("aria-pressed", "true");
121
+ head.classList.add("is-on");
122
+ emit({ type: "use", report, files: lastFiles });
123
+ }, { signal: ac.signal });
124
+ input.addEventListener("change", () => {
125
+ const list = [...(input.files ?? [])];
126
+ input.value = "";
127
+ if (list.length)
128
+ void take(list);
129
+ }, { signal: ac.signal });
130
+ const drop = dropRoutes(zone, [{ name: "avatar", accept: () => true, on: (files) => void take(files) }], { overlay: zone });
131
+ return {
132
+ get report() {
133
+ return report;
134
+ },
135
+ take,
136
+ pick: () => input.click(),
137
+ on(fn) {
138
+ listeners.add(fn);
139
+ return () => listeners.delete(fn);
140
+ },
141
+ dispose() {
142
+ ticket++;
143
+ ac.abort();
144
+ drop.dispose();
145
+ still.dispose();
146
+ thumbUrl(null);
147
+ listeners.clear();
148
+ zone.remove();
149
+ head.remove();
150
+ lines.remove();
151
+ },
152
+ };
153
+ }
@@ -0,0 +1,85 @@
1
+ import { type AnimationClip } from "three";
2
+ import type { Clip, PlayOptions } from "@hackbuild/presence";
3
+ import { type Speech, type SpeechSource } from "./speech.js";
4
+ import type { BodySource, DroppedFile } from "@hackbuild/avatar-host";
5
+ import { AvatarStage, type Body, type BodyCaps, type StageOptions } from "@hackbuild/avatar-host/three";
6
+ import { type Gesture } from "./gestures.js";
7
+ /** The stage shot: bust, or the full body. */
8
+ export type Framing = "bust" | "full";
9
+ /** One verb on the stage. `go` makes it the one pink action; give it to one verb at most. */
10
+ export interface Verb {
11
+ id: string;
12
+ label: string;
13
+ go?: boolean;
14
+ }
15
+ /** The verbs a stage shows by default: say hello is the next thing to do. */
16
+ export declare const DEFAULT_VERBS: readonly Verb[];
17
+ /** Options of `characterStage`: stage options plus name, model URL, verbs, framing, drop and the hello speech. */
18
+ export interface CharacterStageOptions extends StageOptions {
19
+ /** The name on the corner plate. Default the body's name. */
20
+ name?: string;
21
+ /** A model URL to show; the placeholder body shows until it loads, and without one. */
22
+ src?: string;
23
+ verbs?: readonly Verb[];
24
+ /** Bust frames from the knees to just over the head; full shows the whole body. Default bust. */
25
+ framing?: Framing;
26
+ /** Take files dropped on the stage. Default true. */
27
+ drop?: boolean;
28
+ /** What say hello says: text, real speech, or a function that makes the speech when pressed. */
29
+ hello?: string | Speech | (() => Speech | Promise<Speech>);
30
+ /** The context real speech plays through; default one made on the first audio. */
31
+ audioContext?: AudioContext;
32
+ }
33
+ /** Events of CharacterStage: a body loaded or failed, what it is doing, a verb pressed, the framing changed. */
34
+ export type CharacterStageEvent = {
35
+ type: "loaded";
36
+ name: string;
37
+ caps: BodyCaps;
38
+ warnings: string[];
39
+ placeholder: boolean;
40
+ } | {
41
+ type: "failed";
42
+ message: string;
43
+ } | {
44
+ type: "doing";
45
+ word: string;
46
+ } | {
47
+ type: "verb";
48
+ id: string;
49
+ } | {
50
+ type: "framing";
51
+ framing: Framing;
52
+ };
53
+ /** The handle `characterStage` returns: show a body, speak, gesture, play clips, frame and listen. */
54
+ export interface CharacterStageHandle {
55
+ readonly stage: AvatarStage;
56
+ readonly body: Body | null;
57
+ /** The inset slot, top left: put an eye view or a caption card in it. Hidden while empty. */
58
+ readonly inset: HTMLElement;
59
+ readonly verbsEl: HTMLElement;
60
+ readonly subject: HTMLElement;
61
+ /** What the body is doing, as the corner plate says it. */
62
+ readonly doing: string;
63
+ readonly framing: Framing;
64
+ show(source: string | BodySource | readonly DroppedFile[]): Promise<Body | null>;
65
+ showPlaceholder(): void;
66
+ /**
67
+ * Speaks. Audio plays and its level moves the mouth, with the words or
68
+ * phonemes the engine timed; text alone moves the mouth on estimated word
69
+ * timings with no sound. Resolves when the speech ends or a newer one starts.
70
+ */
71
+ say(speech: string | Speech, seconds?: number): Promise<void>;
72
+ /** Where the mouth timings of the last speech came from. */
73
+ readonly speechSource: SpeechSource | null;
74
+ gesture(id: Gesture): boolean;
75
+ /** Plays a clip on the body; the corner plate shows its name. Returns the ticket, -1 when it cannot play. */
76
+ play(clip: Clip | AnimationClip | string, opts?: PlayOptions): number;
77
+ stop(): void;
78
+ turn(): void;
79
+ frame(mode: Framing): void;
80
+ setVerbs(verbs: readonly Verb[]): void;
81
+ on(fn: (e: CharacterStageEvent) => void): () => void;
82
+ dispose(): void;
83
+ }
84
+ /** Mounts a character stage into `host`, which becomes the `.hb-lay-stage`. */
85
+ export declare function characterStage(host: HTMLElement, opts?: CharacterStageOptions): CharacterStageHandle;