@hackbuild/motion-views 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -69,7 +69,11 @@ document.querySelector("hb-avatar-drop")!.addEventListener("picked", (e) => stag
69
69
 
70
70
  ### speech on the stage
71
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.
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 built on the rig itself: each bone is aimed or turned in world space in the body's own frame, so the same wave works on a VRM or on any other humanoid rig, and the arm eases up, waves and eases down (`rigGestureClip`). `play(clip)` plays a presence clip or a three.js AnimationClip.
73
+
74
+ ### a clip pack for the idle
75
+
76
+ `clips` takes a clip pack baked onto the shown body's rig (its URL or the parsed file, the dog simulator's `anims.json` shape: roles, fps and int16 rotations per clip). Its `Idle_Loop` plays under everything once the body loads and `Idle_Talking_Loop` while the body speaks, with the clip player's fades. A body the pack does not fit (fewer than 12 roles land) keeps the rest stance. `packClips` and `packCoverage` do the conversion for any host. The name and doing plate at the top left shows only with `plate: true`.
73
77
 
74
78
  ### the rig check in plain words
75
79
 
@@ -161,6 +165,8 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
161
165
  | 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 |
162
166
  | the three demo pages at 1440 and 390 px against the suite's screen gate | pass |
163
167
  | unit tests over the words and the clip items | pass |
168
+ | unit tests: a pack maps onto the body's bone order; the rig wave raises the arm and ends where it began; the nod moves only the head | pass |
169
+ | the owner's person glb with its clip pack in headless Chrome: idle frames differ (head and both arms), the wave raises the right arm and hands back to the idle (frame strip, looked at by the coordinator) | pass, headless |
164
170
 
165
171
  ### Not verified by anything
166
172
 
@@ -175,8 +181,8 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
175
181
  | file | gzip (measured) | ceiling |
176
182
  |---|---|---|
177
183
  | `dist/index.js` (main entry, imports external) | 3,266 bytes | 3,429 bytes |
178
- | `dist/motion-views.iife.js` (single file build) | 215,543 bytes | 226,320 bytes |
184
+ | `dist/motion-views.iife.js` (single file build) | 221,256 bytes | 232,318 bytes |
179
185
 
180
- Measured 2026-11-25 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
186
+ Measured 2026-11-26 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
181
187
  tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
182
188
  5 percent from its row.
@@ -4,6 +4,7 @@ import { type Speech, type SpeechSource } from "./speech.js";
4
4
  import type { BodySource, DroppedFile } from "@hackbuild/avatar-host";
5
5
  import { AvatarStage, type Body, type BodyCaps, type StageOptions } from "@hackbuild/avatar-host/three";
6
6
  import { type Gesture } from "./gestures.js";
7
+ import { type ClipPack } from "./clip-pack.js";
7
8
  /** The stage shot: bust, or the full body. */
8
9
  export type Framing = "bust" | "full";
9
10
  /** One verb on the stage. `go` makes it the one pink action; give it to one verb at most. */
@@ -29,6 +30,14 @@ export interface CharacterStageOptions extends StageOptions {
29
30
  hello?: string | Speech | (() => Speech | Promise<Speech>);
30
31
  /** The context real speech plays through; default one made on the first audio. */
31
32
  audioContext?: AudioContext;
33
+ /**
34
+ * A clip pack baked onto the shown body's rig (its URL or the parsed
35
+ * file): its Idle_Loop plays under everything, Idle_Talking_Loop while it
36
+ * speaks. Ignored for bodies it does not fit (fewer than 12 bones land).
37
+ */
38
+ clips?: string | ClipPack;
39
+ /** Show the name and doing plate at the top left. Default false. */
40
+ plate?: boolean;
32
41
  }
33
42
  /** Events of CharacterStage: a body loaded or failed, what it is doing, a verb pressed, the framing changed. */
34
43
  export type CharacterStageEvent = {
@@ -12,7 +12,8 @@ import { posedBounds } from "@hackbuild/avatar/three";
12
12
  import { AvatarStage } from "@hackbuild/avatar-host/three";
13
13
  import { dropRoutes } from "@virgilvox/hackbuild-ui/vanilla";
14
14
  import { button, el, iconButton, part } from "./dom.js";
15
- import { GESTURES, gestureClip } from "./gestures.js";
15
+ import { GESTURES, gestureClip, rigGestureClip } from "./gestures.js";
16
+ import { packClips, packCoverage } from "./clip-pack.js";
16
17
  /** The verbs a stage shows by default: say hello is the next thing to do. */
17
18
  export const DEFAULT_VERBS = [
18
19
  { id: "say", label: "say hello", go: true },
@@ -40,6 +41,8 @@ export function characterStage(host, opts = {}) {
40
41
  const turnBtn = iconButton(doc, "flip", "turn around");
41
42
  const frameBtn = iconButton(doc, "frame", "full body", { "aria-pressed": "false" });
42
43
  const tag = el(doc, "div", "hb-stage-tag", {}, [nameEl, doingEl]);
44
+ if (!opts.plate)
45
+ tag.style.display = "none";
43
46
  const tagCorner = el(doc, "div", "hb-ov hb-ov-tl");
44
47
  const corner = el(doc, "div", "hb-ov hb-ov-tr", {}, [turnBtn, frameBtn]);
45
48
  // the stage first, so its canvas sits under the plate
@@ -78,8 +81,34 @@ export function characterStage(host, opts = {}) {
78
81
  nameEl.textContent = e.placeholder ? "stand-in" : e.name;
79
82
  applyFraming();
80
83
  setDoing("idle");
84
+ packed = null;
85
+ if (!e.placeholder)
86
+ void usePack();
81
87
  emit({ type: "loaded", name: e.name, caps: e.caps, warnings: e.warnings, placeholder: e.placeholder });
82
88
  }), stage.on("failed", (e) => emit({ type: "failed", message: e.message })));
89
+ // the clip pack: the body's own mocap idle under everything, the talking idle while it speaks
90
+ let packed = null;
91
+ let packFile = null;
92
+ async function usePack() {
93
+ const body = stage.body;
94
+ if (!opts.clips || !body)
95
+ return;
96
+ packFile ??= typeof opts.clips === "string"
97
+ ? fetch(opts.clips).then((r) => (r.ok ? r.json() : null)).catch(() => null)
98
+ : Promise.resolve(opts.clips);
99
+ const pack = await packFile;
100
+ if (!pack || stage.body !== body || packCoverage(pack, body.names) < 12)
101
+ return;
102
+ const base = new Float32Array(body.bones.length * 4);
103
+ body.bones.forEach((b, i) => b.quaternion.toArray(base, i * 4));
104
+ packed = packClips(pack, body.names, base);
105
+ idleLoop(0.4);
106
+ }
107
+ function idleLoop(fade, talking = false) {
108
+ const c = packed?.[talking ? "Idle_Talking_Loop" : "Idle_Loop"] ?? packed?.Idle_Loop;
109
+ if (c && stage.body)
110
+ stage.body.play(c, { layer: "body", loop: true, background: true, fade });
111
+ }
83
112
  // bust: the knees to the top of the head, the original's opening shot; full: the follow camera
84
113
  function applyFraming() {
85
114
  const body = stage.body;
@@ -149,9 +178,12 @@ export function characterStage(host, opts = {}) {
149
178
  const body = stage.body;
150
179
  if (!body)
151
180
  return false;
152
- const base = new Float32Array(body.bones.length * 4);
153
- body.bones.forEach((b, i) => b.quaternion.toArray(base, i * 4));
154
- const clip = gestureClip(id, body.names, base);
181
+ let clip = rigGestureClip(id, body.bones, body.names);
182
+ if (!clip) {
183
+ const base = new Float32Array(body.bones.length * 4);
184
+ body.bones.forEach((b, i) => b.quaternion.toArray(base, i * 4));
185
+ clip = gestureClip(id, body.names, base);
186
+ }
155
187
  if (!clip)
156
188
  return false;
157
189
  return play(clip, { layer: id === "bow" ? "body" : "upper" }) >= 0;
@@ -233,6 +265,7 @@ export function characterStage(host, opts = {}) {
233
265
  body.lip.push(events);
234
266
  body.setGazeMode("talk");
235
267
  setDoing("talking");
268
+ idleLoop(0.5, true);
236
269
  stage.loop.sync();
237
270
  start?.();
238
271
  if (analyser && audioCtx) {
@@ -260,6 +293,7 @@ export function characterStage(host, opts = {}) {
260
293
  analyser?.disconnect();
261
294
  stage.body?.lip.setLevel(0);
262
295
  stage.body?.setGazeMode("listen");
296
+ idleLoop(0.6);
263
297
  if (doing === "talking")
264
298
  setDoing("idle");
265
299
  }
@@ -0,0 +1,21 @@
1
+ import type { Clip } from "@hackbuild/presence";
2
+ /** The pack file: role names, frame rate and the clips. */
3
+ export interface ClipPack {
4
+ roles: readonly string[];
5
+ fps: number;
6
+ clips: Record<string, {
7
+ dur: number;
8
+ n: number;
9
+ loop: boolean;
10
+ q: string;
11
+ p?: string;
12
+ }>;
13
+ }
14
+ /** How many of the pack's roles land on one of `names`. */
15
+ export declare function packCoverage(pack: ClipPack, names: readonly string[]): number;
16
+ /**
17
+ * The pack's clips as presence clips over `names` (the body's bone order).
18
+ * `base` holds bones times 4 local rotations for the bones the pack does
19
+ * not move (fingers, eyes), usually the pose when the body loaded.
20
+ */
21
+ export declare function packClips(pack: ClipPack, names: readonly string[], base: ArrayLike<number>): Record<string, Clip>;
@@ -0,0 +1,53 @@
1
+ // pack role to the humanoid bone name the body uses
2
+ const ROLE = {
3
+ hips: "hips", spine: "spine", chest: "chest", upperChest: "upperChest", neck: "neck", head: "head",
4
+ shoulderL: "leftShoulder", upperArmL: "leftUpperArm", lowerArmL: "leftLowerArm", handL: "leftHand",
5
+ shoulderR: "rightShoulder", upperArmR: "rightUpperArm", lowerArmR: "rightLowerArm", handR: "rightHand",
6
+ upperLegL: "leftUpperLeg", lowerLegL: "leftLowerLeg", footL: "leftFoot",
7
+ upperLegR: "rightUpperLeg", lowerLegR: "rightLowerLeg", footR: "rightFoot",
8
+ };
9
+ function int16(b64) {
10
+ const s = atob(b64);
11
+ const u = new Uint8Array(s.length);
12
+ for (let i = 0; i < s.length; i++)
13
+ u[i] = s.charCodeAt(i);
14
+ return new Int16Array(u.buffer);
15
+ }
16
+ /** How many of the pack's roles land on one of `names`. */
17
+ export function packCoverage(pack, names) {
18
+ return pack.roles.filter((r) => ROLE[r] && names.includes(ROLE[r])).length;
19
+ }
20
+ /**
21
+ * The pack's clips as presence clips over `names` (the body's bone order).
22
+ * `base` holds bones times 4 local rotations for the bones the pack does
23
+ * not move (fingers, eyes), usually the pose when the body loaded.
24
+ */
25
+ export function packClips(pack, names, base) {
26
+ const R = pack.roles.length;
27
+ const n = names.length;
28
+ const slot = pack.roles.map((r) => (ROLE[r] ? names.indexOf(ROLE[r]) : -1));
29
+ const out = {};
30
+ for (const [name, c] of Object.entries(pack.clips)) {
31
+ const q = int16(c.q);
32
+ const frames = c.n;
33
+ const rotations = new Float32Array(frames * n * 4);
34
+ for (let f = 0; f < frames; f++) {
35
+ rotations.set(Array.prototype.slice.call(base, 0, n * 4), f * n * 4);
36
+ for (let r = 0; r < R; r++) {
37
+ const i = slot[r];
38
+ if (i < 0)
39
+ continue;
40
+ const a = (f * R + r) * 4;
41
+ let x = q[a] / 32767, y = q[a + 1] / 32767, z = q[a + 2] / 32767, w = q[a + 3] / 32767;
42
+ const len = Math.hypot(x, y, z, w) || 1;
43
+ x /= len;
44
+ y /= len;
45
+ z /= len;
46
+ w /= len;
47
+ rotations.set([x, y, z, w], (f * n + i) * 4);
48
+ }
49
+ }
50
+ out[name] = { name, fps: pack.fps, frames, bones: n, loop: c.loop, rotations };
51
+ }
52
+ return out;
53
+ }
@@ -1,4 +1,4 @@
1
- import { AnimationClip } from "three";
1
+ import { AnimationClip, type Object3D } from "three";
2
2
  import type { Clip } from "@hackbuild/presence";
3
3
  /** A gesture written in code over the body's own bones. */
4
4
  export type Gesture = "wave" | "nod" | "shake" | "bow";
@@ -12,3 +12,13 @@ export declare const GESTURES: readonly Gesture[];
12
12
  export declare function gestureClip(id: Gesture, names: readonly string[], base: ArrayLike<number>, fps?: number): Clip | null;
13
13
  /** A presence clip as a three.js AnimationClip with one quaternion track per bone object name. */
14
14
  export declare function animationClipOf(clip: Clip, names: readonly string[]): AnimationClip;
15
+ /**
16
+ * A gesture as a presence clip built on the rig itself: each bone is aimed
17
+ * or turned in world space, in the body's own frame (forward, left and up
18
+ * from its shoulders), then read back as local rotations. Works on any
19
+ * humanoid rig, whatever its bone axes. The arm eases up, waves and eases
20
+ * down; nod, shake and bow ease in and out. `bones` and `names` are the
21
+ * body's bone order; the pose they hold now is the base. Returns null when
22
+ * the rig lacks the gesture's bones.
23
+ */
24
+ export declare function rigGestureClip(id: Gesture, bones: readonly Object3D[], names: readonly string[], fps?: number): Clip | null;
package/dist/gestures.js CHANGED
@@ -71,3 +71,89 @@ export function animationClipOf(clip, names) {
71
71
  });
72
72
  return new AnimationClip(clip.name, (clip.frames - 1) / clip.fps, tracks);
73
73
  }
74
+ const ss = (a, b, x) => {
75
+ const t = Math.min(1, Math.max(0, (x - a) / (b - a)));
76
+ return t * t * (3 - 2 * t);
77
+ };
78
+ /** Seconds each rig gesture runs. */
79
+ const RIG_SECONDS = { wave: 2.6, nod: 1.2, shake: 1.4, bow: 2 };
80
+ /**
81
+ * A gesture as a presence clip built on the rig itself: each bone is aimed
82
+ * or turned in world space, in the body's own frame (forward, left and up
83
+ * from its shoulders), then read back as local rotations. Works on any
84
+ * humanoid rig, whatever its bone axes. The arm eases up, waves and eases
85
+ * down; nod, shake and bow ease in and out. `bones` and `names` are the
86
+ * body's bone order; the pose they hold now is the base. Returns null when
87
+ * the rig lacks the gesture's bones.
88
+ */
89
+ export function rigGestureClip(id, bones, names, fps = 30) {
90
+ const at = (n) => {
91
+ const i = names.indexOf(n);
92
+ return i < 0 ? null : bones[i];
93
+ };
94
+ const lu = at("leftUpperArm"), ru = at("rightUpperArm"), rl = at("rightLowerArm"), rh = at("rightHand"), head = at("head");
95
+ const spine = at("spine"), chest = at("chest");
96
+ if (!lu || !ru)
97
+ return null;
98
+ if (id === "wave" && (!rl || !rh))
99
+ return null;
100
+ if ((id === "nod" || id === "shake") && !head)
101
+ return null;
102
+ if (id === "bow" && !spine)
103
+ return null;
104
+ const n = bones.length;
105
+ const base = bones.map((b) => b.quaternion.clone());
106
+ const top = bones[0].parent ?? bones[0];
107
+ top.updateMatrixWorld(true);
108
+ const wp = (o, v = new Vector3()) => o.getWorldPosition(v);
109
+ const up = new Vector3(0, 1, 0);
110
+ const L = wp(lu).sub(wp(ru)).setY(0).normalize();
111
+ const F = new Vector3().crossVectors(L, up).normalize();
112
+ const R = L.clone().negate();
113
+ const pq = new Quaternion(), bq = new Quaternion(), rq = new Quaternion();
114
+ const turnWorld = (b, rw) => {
115
+ b.parent.getWorldQuaternion(pq);
116
+ b.getWorldQuaternion(bq);
117
+ b.quaternion.copy(pq.invert().multiply(rw).multiply(bq));
118
+ b.updateMatrixWorld(true);
119
+ };
120
+ const aim = (b, child, dir, w) => {
121
+ const cur = wp(child).sub(wp(b)).normalize();
122
+ const want = cur.clone().lerp(dir, w).normalize();
123
+ turnWorld(b, rq.setFromUnitVectors(cur, want));
124
+ };
125
+ const seconds = RIG_SECONDS[id];
126
+ const frames = Math.round(seconds * fps) + 1;
127
+ const rotations = new Float32Array(frames * n * 4);
128
+ const armUp = R.clone().multiplyScalar(0.55).addScaledVector(up, 0.8).addScaledVector(F, 0.22).normalize();
129
+ for (let f = 0; f < frames; f++) {
130
+ const t = f / (frames - 1);
131
+ bones.forEach((b, i) => b.quaternion.copy(base[i]));
132
+ top.updateMatrixWorld(true);
133
+ if (id === "wave") {
134
+ const e = ss(0, 0.22, t) * (1 - ss(0.8, 1, t));
135
+ aim(ru, rl, armUp, e);
136
+ const osc = 0.42 * Math.sin(2 * Math.PI * 3 * ss(0.18, 0.84, t)) * ss(0.12, 0.3, t) * (1 - ss(0.74, 0.86, t));
137
+ const fore = up.clone().addScaledVector(F, 0.12).addScaledVector(R, 0.08).applyAxisAngle(F, -osc).normalize();
138
+ aim(rl, rh, fore, e);
139
+ }
140
+ else if (id === "nod") {
141
+ turnWorld(head, rq.setFromAxisAngle(L, 0.24 * Math.sin(2 * Math.PI * t) ** 2 * (1 - ss(0.85, 1, t))));
142
+ }
143
+ else if (id === "shake") {
144
+ turnWorld(head, rq.setFromAxisAngle(up, 0.32 * Math.sin(4 * Math.PI * t) * Math.sin(Math.PI * t)));
145
+ }
146
+ else {
147
+ const e = ss(0, 0.35, t) * (1 - ss(0.65, 1, t));
148
+ turnWorld(spine, rq.setFromAxisAngle(L, 0.32 * e));
149
+ if (chest)
150
+ turnWorld(chest, rq.setFromAxisAngle(L, 0.18 * e));
151
+ if (head)
152
+ turnWorld(head, rq.setFromAxisAngle(L, -0.12 * e));
153
+ }
154
+ bones.forEach((b, i) => b.quaternion.toArray(rotations, (f * n + i) * 4));
155
+ }
156
+ bones.forEach((b, i) => b.quaternion.copy(base[i]));
157
+ top.updateMatrixWorld(true);
158
+ return { name: id, fps, frames, bones: n, loop: false, rotations };
159
+ }
@@ -13650,14 +13650,14 @@ var HackbuildMotionViews = (function(exports, three) {
13650
13650
  }
13651
13651
  };
13652
13652
  // ../../node_modules/@virgilvox/hackbuild-ui/dist/vanilla.js
13653
- const Yt = "M2 12c3-5 6.5-7 10-7s7 2 10 7c-3 5-6.5 7-10 7s-7-2-10-7zM9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0";
13654
- const Xt = "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3";
13655
- const Gt = "M3 6h12v12H3zM15 10l6-3v10l-6-3";
13656
- const Je = "M3 12h16M13 6l6 6-6 6";
13657
- const Qe = "M20 12a8 8 0 1 1-3-6.2M20 4v5h-5";
13658
- const Mt = {
13659
- send: { d: Je },
13660
- microphone: { d: Xt },
13653
+ const Zt = "M2 12c3-5 6.5-7 10-7s7 2 10 7c-3 5-6.5 7-10 7s-7-2-10-7zM9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0";
13654
+ const en = "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3";
13655
+ const tn = "M3 6h12v12H3zM15 10l6-3v10l-6-3";
13656
+ const et = "M3 12h16M13 6l6 6-6 6";
13657
+ const tt = "M20 12a8 8 0 1 1-3-6.2M20 4v5h-5";
13658
+ const Lt = {
13659
+ send: { d: et },
13660
+ microphone: { d: en },
13661
13661
  stop: { d: "M6 6h12v12H6z" },
13662
13662
  volume: { d: "M4 9v6h4l5 4V5L8 9zM17 8a5 5 0 0 1 0 8" },
13663
13663
  mute: { d: "M4 9v6h4l5 4V5L8 9zM17 9l4 6M21 9l-4 6" },
@@ -13669,11 +13669,11 @@ var HackbuildMotionViews = (function(exports, three) {
13669
13669
  upload: { d: "M12 16V4M7 9l5-5 5 5M4 20h16" },
13670
13670
  download: { d: "M12 4v11M7 11l5 5 5-5M5 20h14" },
13671
13671
  play: { d: "M7 5l11 7-11 7z" },
13672
- redo: { d: Qe },
13672
+ redo: { d: tt },
13673
13673
  trash: { d: "M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6" },
13674
13674
  sun: { d: "M8 12a4 4 0 1 0 8 0a4 4 0 1 0 -8 0M12 2v3M12 19v3M2 12h3M19 12h3" },
13675
- "paper-plane": { d: Je },
13676
- refresh: { d: Qe },
13675
+ "paper-plane": { d: et },
13676
+ refresh: { d: tt },
13677
13677
  undo: { d: "M4 12a8 8 0 1 0 3-6.2M4 4v5h5" },
13678
13678
  plus: { d: "M12 5v14M5 12h14" },
13679
13679
  minus: { d: "M5 12h14" },
@@ -13686,7 +13686,7 @@ var HackbuildMotionViews = (function(exports, three) {
13686
13686
  link: { d: "M9 15l6-6M11 6l2-2a4 4 0 0 1 6 6l-2 2M13 18l-2 2a4 4 0 0 1-6-6l2-2" },
13687
13687
  copy: { d: "M8 8h12v12H8zM16 8V4H4v12h4" },
13688
13688
  pen: { d: "M4 20v-4L15 5l4 4L8 20zM12 8l4 4" },
13689
- eye: { d: Yt },
13689
+ eye: { d: Zt },
13690
13690
  "eye-slash": { d: "M2 12c3-5 6.5-7 10-7s7 2 10 7c-3 5-6.5 7-10 7s-7-2-10-7zM9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0M4 4l16 16" },
13691
13691
  thumbtack: { d: "M8 3h8M10 3v6l-4 5h12l-4-5V3M12 14v7" },
13692
13692
  search: { d: "M4 10a6 6 0 1 0 12 0a6 6 0 1 0 -12 0M15 15l6 6" },
@@ -13714,7 +13714,7 @@ var HackbuildMotionViews = (function(exports, three) {
13714
13714
  wave: { d: "M2 12h3l2-4 3 9 3-13 3 13 2-5h4" },
13715
13715
  "microphone-slash": { d: "M9 3h6v11H9zM5 11v1a7 7 0 0 0 14 0v-1M12 19v3M3 3l18 18" },
13716
13716
  camera: { d: "M3 7h4l2-3h6l2 3h4v13H3zM8.5 13a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0 -7 0" },
13717
- video: { d: Gt },
13717
+ video: { d: tn },
13718
13718
  "video-slash": { d: "M3 6h12v12H3zM15 10l6-3v10l-6-3M3 3l18 18" },
13719
13719
  image: { d: "M3 4h18v16H3zM3 16l5-5 4 4 3-3 6 6M15 8v.5" },
13720
13720
  crosshairs: { d: "M5 12a7 7 0 1 0 14 0a7 7 0 1 0 -14 0M12 2v5M12 17v5M2 12h5M17 12h5" },
@@ -13744,15 +13744,15 @@ var HackbuildMotionViews = (function(exports, three) {
13744
13744
  bucket: { d: "M5 11l7-7 7 7-7 7zM5 11h14M20 15c0 1.5-1 3-1 3s-1-1.5-1-3a1 1 0 0 1 2 0z" },
13745
13745
  hand: { d: "M8 12V5a1.5 1.5 0 0 1 3 0v6M11 10V3.5a1.5 1.5 0 0 1 3 0V10M14 10V5a1.5 1.5 0 0 1 3 0v7c0 5-3 8-7 8c-3 0-4-2-6-5l-1.5-2.5a1.5 1.5 0 0 1 2.5-1.6L8 14" }
13746
13746
  };
13747
- function Jt(e) {
13748
- return Mt[e];
13747
+ function nn(e) {
13748
+ return Lt[e];
13749
13749
  }
13750
- const Ze = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
13751
- function Qt(e, t = {}) {
13752
- const r = Jt(e);
13750
+ const nt = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
13751
+ function rn(e, t = {}) {
13752
+ const r = nn(e);
13753
13753
  if (!r) return "";
13754
13754
  const n = t.size ?? 16;
13755
- return `<svg class="${"hb-icon is-stroke" + (t.className ? " " + Ze(t.className) : "")}" width="${n}" height="${n}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" ${t.label ? `role="img" aria-label="${Ze(t.label)}"` : "aria-hidden=\"true\""}><path d="${r.d}"/></svg>`;
13755
+ return `<svg class="${"hb-icon is-stroke" + (t.className ? " " + nt(t.className) : "")}" width="${n}" height="${n}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" ${t.label ? `role="img" aria-label="${nt(t.label)}"` : "aria-hidden=\"true\""}><path d="${r.d}"/></svg>`;
13756
13756
  }
13757
13757
  [
13758
13758
  "a[href]",
@@ -13763,15 +13763,15 @@ var HackbuildMotionViews = (function(exports, three) {
13763
13763
  "[tabindex]",
13764
13764
  "[contenteditable=\"true\"]"
13765
13765
  ].join(",");
13766
- function Et(e) {
13766
+ function Ct(e) {
13767
13767
  return (Array.isArray(e) ? e : e.split(",")).map((t) => t.trim().toLowerCase()).filter(Boolean);
13768
13768
  }
13769
- function et(e, t) {
13769
+ function rt(e, t) {
13770
13770
  if (typeof e == "function") return e(t);
13771
13771
  const r = t.name.toLowerCase(), n = t.type.toLowerCase();
13772
- return Et(e).some((o) => o.startsWith(".") ? r.endsWith(o) : o.endsWith("/*") ? n.startsWith(o.slice(0, -1)) : n === o);
13772
+ return Ct(e).some((o) => o.startsWith(".") ? r.endsWith(o) : o.endsWith("/*") ? n.startsWith(o.slice(0, -1)) : n === o);
13773
13773
  }
13774
- async function Lt(e, t) {
13774
+ async function Tt(e, t) {
13775
13775
  if (e.isFile && e.file) {
13776
13776
  t.push(await new Promise((n, o) => e.file(n, o)));
13777
13777
  return;
@@ -13781,10 +13781,10 @@ var HackbuildMotionViews = (function(exports, three) {
13781
13781
  for (;;) {
13782
13782
  const n = await new Promise((o, i) => r.readEntries(o, i));
13783
13783
  if (!n.length) return;
13784
- for (const o of n) await Lt(o, t);
13784
+ for (const o of n) await Tt(o, t);
13785
13785
  }
13786
13786
  }
13787
- function sn(e) {
13787
+ function fn(e) {
13788
13788
  var n;
13789
13789
  const r = [...((n = e.dataTransfer) == null ? void 0 : n.items) ?? []].filter((o) => o.kind === "file").map((o) => {
13790
13790
  var i;
@@ -13792,11 +13792,11 @@ var HackbuildMotionViews = (function(exports, three) {
13792
13792
  });
13793
13793
  return r.some((o) => o == null ? void 0 : o.isDirectory) ? r.filter((o) => !!o) : null;
13794
13794
  }
13795
- function ae(e) {
13795
+ function fe(e) {
13796
13796
  var t;
13797
13797
  return [...((t = e.dataTransfer) == null ? void 0 : t.types) ?? []].includes("Files");
13798
13798
  }
13799
- function Pr(e, t, r = {}) {
13799
+ function _r(e, t, r = {}) {
13800
13800
  let n = 0, o = {
13801
13801
  over: !1,
13802
13802
  route: null,
@@ -13804,29 +13804,29 @@ var HackbuildMotionViews = (function(exports, three) {
13804
13804
  count: 0
13805
13805
  };
13806
13806
  function i(p) {
13807
- var b;
13807
+ var v;
13808
13808
  const d = p.over === o.over && p.route === o.route && p.rejected === o.rejected && p.count === o.count;
13809
13809
  if (o = p, d) return;
13810
13810
  const u = r.overlay;
13811
- u && (u.classList.toggle("is-over", p.over), u.classList.toggle("is-reject", p.rejected), p.route ? u.dataset.route = p.route : delete u.dataset.route), (b = r.onState) == null || b.call(r, p);
13811
+ u && (u.classList.toggle("is-over", p.over), u.classList.toggle("is-reject", p.rejected), p.route ? u.dataset.route = p.route : delete u.dataset.route), (v = r.onState) == null || v.call(r, p);
13812
13812
  }
13813
13813
  function s(p) {
13814
- var v;
13815
- const d = [...((v = p.dataTransfer) == null ? void 0 : v.items) ?? []].filter((E) => E.kind === "file"), u = d.map((E) => E.type);
13816
- if (!u.length || u.some((E) => !E)) return {
13814
+ var b;
13815
+ const d = [...((b = p.dataTransfer) == null ? void 0 : b.items) ?? []].filter((x) => x.kind === "file"), u = d.map((x) => x.type);
13816
+ if (!u.length || u.some((x) => !x)) return {
13817
13817
  over: !0,
13818
13818
  route: null,
13819
13819
  rejected: !1,
13820
13820
  count: d.length
13821
13821
  };
13822
- const b = u.map((E) => t.find(($) => typeof $.accept != "function" && et($.accept, {
13822
+ const v = u.map((x) => t.find((T) => typeof T.accept != "function" && rt(T.accept, {
13823
13823
  name: "",
13824
- type: E
13825
- }))), w = new Set(b.map((E) => (E == null ? void 0 : E.name) ?? null)), x = b.every((E) => !E) && t.every((E) => typeof E.accept != "function" && Et(E.accept).every(($) => !$.startsWith(".")));
13824
+ type: x
13825
+ }))), w = new Set(v.map((x) => (x == null ? void 0 : x.name) ?? null)), k = v.every((x) => !x) && t.every((x) => typeof x.accept != "function" && Ct(x.accept).every((T) => !T.startsWith(".")));
13826
13826
  return {
13827
13827
  over: !0,
13828
13828
  route: w.size === 1 ? [...w][0] : null,
13829
- rejected: x,
13829
+ rejected: k,
13830
13830
  count: d.length
13831
13831
  };
13832
13832
  }
@@ -13836,51 +13836,51 @@ var HackbuildMotionViews = (function(exports, three) {
13836
13836
  };
13837
13837
  function a(p) {
13838
13838
  const d = p;
13839
- !c() || !ae(d) || (d.preventDefault(), n++, i(s(d)));
13839
+ !c() || !fe(d) || (d.preventDefault(), n++, i(s(d)));
13840
13840
  }
13841
- function g(p) {
13841
+ function h(p) {
13842
13842
  const d = p;
13843
- !c() || !ae(d) || (d.preventDefault(), o.over || i(s(d)));
13843
+ !c() || !fe(d) || (d.preventDefault(), o.over || i(s(d)));
13844
13844
  }
13845
13845
  function y(p) {
13846
- !ae(p) || n === 0 || (n--, n === 0 && i({
13846
+ !fe(p) || n === 0 || (n--, n === 0 && i({
13847
13847
  over: !1,
13848
13848
  route: null,
13849
13849
  rejected: !1,
13850
13850
  count: 0
13851
13851
  }));
13852
13852
  }
13853
- function h(p) {
13854
- var b;
13853
+ function f(p) {
13854
+ var v;
13855
13855
  const d = p;
13856
- if (!ae(d) || (d.preventDefault(), n = 0, i({
13856
+ if (!fe(d) || (d.preventDefault(), n = 0, i({
13857
13857
  over: !1,
13858
13858
  route: null,
13859
13859
  rejected: !1,
13860
13860
  count: 0
13861
13861
  }), !c())) return;
13862
- const u = r.folders !== !1 ? sn(d) : null;
13862
+ const u = r.folders !== !1 ? fn(d) : null;
13863
13863
  if (u) {
13864
13864
  "tagName" in e && d.stopPropagation();
13865
13865
  const w = [];
13866
- Promise.all(u.map((x) => Lt(x, w))).then(() => m(w, d), () => m(w, d));
13866
+ Promise.all(u.map((k) => Tt(k, w))).then(() => m(w, d), () => m(w, d));
13867
13867
  return;
13868
13868
  }
13869
- m([...((b = d.dataTransfer) == null ? void 0 : b.files) ?? []], d) && "tagName" in e && d.stopPropagation();
13869
+ m([...((v = d.dataTransfer) == null ? void 0 : v.files) ?? []], d) && "tagName" in e && d.stopPropagation();
13870
13870
  }
13871
13871
  function m(p, d) {
13872
13872
  var w;
13873
- const u = /* @__PURE__ */ new Map(), b = [];
13874
- for (const x of p) {
13875
- const v = t.find((E) => et(E.accept, x));
13876
- v ? u.set(v, [...u.get(v) ?? [], x]) : b.push(x);
13873
+ const u = /* @__PURE__ */ new Map(), v = [];
13874
+ for (const k of p) {
13875
+ const b = t.find((x) => rt(x.accept, k));
13876
+ b ? u.set(b, [...u.get(b) ?? [], k]) : v.push(k);
13877
13877
  }
13878
- for (const [x, v] of u) x.on(v, d);
13879
- return b.length && ((w = r.onReject) == null || w.call(r, b, d)), u.size > 0;
13878
+ for (const [k, b] of u) k.on(b, d);
13879
+ return v.length && ((w = r.onReject) == null || w.call(r, v, d)), u.size > 0;
13880
13880
  }
13881
- function f(p) {
13882
- var b;
13883
- const d = p, u = [...((b = d.clipboardData) == null ? void 0 : b.files) ?? []];
13881
+ function g(p) {
13882
+ var v;
13883
+ const d = p, u = [...((v = d.clipboardData) == null ? void 0 : v.files) ?? []];
13884
13884
  !u.length || !c() || (d.preventDefault(), m(u, d));
13885
13885
  }
13886
13886
  function l() {
@@ -13891,17 +13891,17 @@ var HackbuildMotionViews = (function(exports, three) {
13891
13891
  count: 0
13892
13892
  });
13893
13893
  }
13894
- return e.addEventListener("dragenter", a), e.addEventListener("dragover", g), e.addEventListener("dragleave", y), e.addEventListener("drop", h), e.addEventListener("dragend", l), r.paste && e.addEventListener("paste", f), {
13894
+ return e.addEventListener("dragenter", a), e.addEventListener("dragover", h), e.addEventListener("dragleave", y), e.addEventListener("drop", f), e.addEventListener("dragend", l), r.paste && e.addEventListener("paste", g), {
13895
13895
  get state() {
13896
13896
  return o;
13897
13897
  },
13898
13898
  dispose() {
13899
- e.removeEventListener("dragenter", a), e.removeEventListener("dragover", g), e.removeEventListener("dragleave", y), e.removeEventListener("drop", h), e.removeEventListener("dragend", l), e.removeEventListener("paste", f), l();
13899
+ e.removeEventListener("dragenter", a), e.removeEventListener("dragover", h), e.removeEventListener("dragleave", y), e.removeEventListener("drop", f), e.removeEventListener("dragend", l), e.removeEventListener("paste", g), l();
13900
13900
  }
13901
13901
  };
13902
13902
  }
13903
- W("wand", "add"), W("brush", "add"), W("eraser", "add"), W("lasso", "add"), W("polygon", "add"), W("rect", "add"), W("ellipse", "add"), W("flood", "add"), W("pan", "add");
13904
- function W(e, t) {
13903
+ Y("wand", "add"), Y("brush", "add"), Y("eraser", "add"), Y("lasso", "add"), Y("polygon", "add"), Y("rect", "add"), Y("ellipse", "add"), Y("flood", "add"), Y("pan", "add");
13904
+ function Y(e, t) {
13905
13905
  const r = t === "add", n = `x swaps to ${r ? "erase" : "add"}`;
13906
13906
  return e === "wand" ? `tap a colour to ${r ? "add" : "cut"} it. shift ${r ? "cuts" : "adds"}, ${n}` : e === "brush" ? `paint to ${r ? "add" : "erase"}. [ and ] size, ${n}` : e === "eraser" ? "paint to erase. shift adds, [ and ] size" : e === "polygon" ? `press corner by corner, enter or the first corner ${r ? "fills" : "cuts"}. backspace drops a corner, esc all` : e === "rect" || e === "ellipse" ? `drag a ${e === "rect" ? "box" : "ring"} to ${r ? "add" : "cut"} it. shift ${r ? "cuts" : "adds"}, ${n}` : e === "flood" ? `tap to fill the patch of one colour. shift ${r ? "cuts" : "adds"}, ${n}` : e === "pan" ? "drag to move the picture. space pans from any tool" : `drag around a shape, lift to ${r ? "fill" : "cut"}. esc drops it, ${n}`;
13907
13907
  }
@@ -13930,7 +13930,7 @@ var HackbuildMotionViews = (function(exports, three) {
13930
13930
  title: label,
13931
13931
  ...attrs
13932
13932
  });
13933
- b.innerHTML = Qt(icon, { size: 18 });
13933
+ b.innerHTML = rn(icon, { size: 18 });
13934
13934
  return b;
13935
13935
  }
13936
13936
  /** A light button, or the one pink action when `go`. */
@@ -14039,6 +14039,170 @@ var HackbuildMotionViews = (function(exports, three) {
14039
14039
  });
14040
14040
  return new three.AnimationClip(clip.name, (clip.frames - 1) / clip.fps, tracks);
14041
14041
  }
14042
+ const ss = (a, b, x) => {
14043
+ const t = Math.min(1, Math.max(0, (x - a) / (b - a)));
14044
+ return t * t * (3 - 2 * t);
14045
+ };
14046
+ /** Seconds each rig gesture runs. */
14047
+ const RIG_SECONDS = {
14048
+ wave: 2.6,
14049
+ nod: 1.2,
14050
+ shake: 1.4,
14051
+ bow: 2
14052
+ };
14053
+ /**
14054
+ * A gesture as a presence clip built on the rig itself: each bone is aimed
14055
+ * or turned in world space, in the body's own frame (forward, left and up
14056
+ * from its shoulders), then read back as local rotations. Works on any
14057
+ * humanoid rig, whatever its bone axes. The arm eases up, waves and eases
14058
+ * down; nod, shake and bow ease in and out. `bones` and `names` are the
14059
+ * body's bone order; the pose they hold now is the base. Returns null when
14060
+ * the rig lacks the gesture's bones.
14061
+ */
14062
+ function rigGestureClip(id, bones, names, fps = 30) {
14063
+ const at = (n) => {
14064
+ const i = names.indexOf(n);
14065
+ return i < 0 ? null : bones[i];
14066
+ };
14067
+ const lu = at("leftUpperArm"), ru = at("rightUpperArm"), rl = at("rightLowerArm"), rh = at("rightHand"), head = at("head");
14068
+ const spine = at("spine"), chest = at("chest");
14069
+ if (!lu || !ru) return null;
14070
+ if (id === "wave" && (!rl || !rh)) return null;
14071
+ if ((id === "nod" || id === "shake") && !head) return null;
14072
+ if (id === "bow" && !spine) return null;
14073
+ const n = bones.length;
14074
+ const base = bones.map((b) => b.quaternion.clone());
14075
+ const top = bones[0].parent ?? bones[0];
14076
+ top.updateMatrixWorld(true);
14077
+ const wp = (o, v = new three.Vector3()) => o.getWorldPosition(v);
14078
+ const up = new three.Vector3(0, 1, 0);
14079
+ const L = wp(lu).sub(wp(ru)).setY(0).normalize();
14080
+ const F = new three.Vector3().crossVectors(L, up).normalize();
14081
+ const R = L.clone().negate();
14082
+ const pq = new three.Quaternion(), bq = new three.Quaternion(), rq = new three.Quaternion();
14083
+ const turnWorld = (b, rw) => {
14084
+ b.parent.getWorldQuaternion(pq);
14085
+ b.getWorldQuaternion(bq);
14086
+ b.quaternion.copy(pq.invert().multiply(rw).multiply(bq));
14087
+ b.updateMatrixWorld(true);
14088
+ };
14089
+ const aim = (b, child, dir, w) => {
14090
+ const cur = wp(child).sub(wp(b)).normalize();
14091
+ const want = cur.clone().lerp(dir, w).normalize();
14092
+ turnWorld(b, rq.setFromUnitVectors(cur, want));
14093
+ };
14094
+ const seconds = RIG_SECONDS[id];
14095
+ const frames = Math.round(seconds * fps) + 1;
14096
+ const rotations = new Float32Array(frames * n * 4);
14097
+ const armUp = R.clone().multiplyScalar(.55).addScaledVector(up, .8).addScaledVector(F, .22).normalize();
14098
+ for (let f = 0; f < frames; f++) {
14099
+ const t = f / (frames - 1);
14100
+ bones.forEach((b, i) => b.quaternion.copy(base[i]));
14101
+ top.updateMatrixWorld(true);
14102
+ if (id === "wave") {
14103
+ const e = ss(0, .22, t) * (1 - ss(.8, 1, t));
14104
+ aim(ru, rl, armUp, e);
14105
+ const osc = .42 * Math.sin(2 * Math.PI * 3 * ss(.18, .84, t)) * ss(.12, .3, t) * (1 - ss(.74, .86, t));
14106
+ aim(rl, rh, up.clone().addScaledVector(F, .12).addScaledVector(R, .08).applyAxisAngle(F, -osc).normalize(), e);
14107
+ } else if (id === "nod") turnWorld(head, rq.setFromAxisAngle(L, .24 * Math.sin(2 * Math.PI * t) ** 2 * (1 - ss(.85, 1, t))));
14108
+ else if (id === "shake") turnWorld(head, rq.setFromAxisAngle(up, .32 * Math.sin(4 * Math.PI * t) * Math.sin(Math.PI * t)));
14109
+ else {
14110
+ const e = ss(0, .35, t) * (1 - ss(.65, 1, t));
14111
+ turnWorld(spine, rq.setFromAxisAngle(L, .32 * e));
14112
+ if (chest) turnWorld(chest, rq.setFromAxisAngle(L, .18 * e));
14113
+ if (head) turnWorld(head, rq.setFromAxisAngle(L, -.12 * e));
14114
+ }
14115
+ bones.forEach((b, i) => b.quaternion.toArray(rotations, (f * n + i) * 4));
14116
+ }
14117
+ bones.forEach((b, i) => b.quaternion.copy(base[i]));
14118
+ top.updateMatrixWorld(true);
14119
+ return {
14120
+ name: id,
14121
+ fps,
14122
+ frames,
14123
+ bones: n,
14124
+ loop: false,
14125
+ rotations
14126
+ };
14127
+ }
14128
+ // src/clip-pack.ts
14129
+ const ROLE = {
14130
+ hips: "hips",
14131
+ spine: "spine",
14132
+ chest: "chest",
14133
+ upperChest: "upperChest",
14134
+ neck: "neck",
14135
+ head: "head",
14136
+ shoulderL: "leftShoulder",
14137
+ upperArmL: "leftUpperArm",
14138
+ lowerArmL: "leftLowerArm",
14139
+ handL: "leftHand",
14140
+ shoulderR: "rightShoulder",
14141
+ upperArmR: "rightUpperArm",
14142
+ lowerArmR: "rightLowerArm",
14143
+ handR: "rightHand",
14144
+ upperLegL: "leftUpperLeg",
14145
+ lowerLegL: "leftLowerLeg",
14146
+ footL: "leftFoot",
14147
+ upperLegR: "rightUpperLeg",
14148
+ lowerLegR: "rightLowerLeg",
14149
+ footR: "rightFoot"
14150
+ };
14151
+ function int16(b64) {
14152
+ const s = atob(b64);
14153
+ const u = new Uint8Array(s.length);
14154
+ for (let i = 0; i < s.length; i++) u[i] = s.charCodeAt(i);
14155
+ return new Int16Array(u.buffer);
14156
+ }
14157
+ /** How many of the pack's roles land on one of `names`. */
14158
+ function packCoverage(pack, names) {
14159
+ return pack.roles.filter((r) => ROLE[r] && names.includes(ROLE[r])).length;
14160
+ }
14161
+ /**
14162
+ * The pack's clips as presence clips over `names` (the body's bone order).
14163
+ * `base` holds bones times 4 local rotations for the bones the pack does
14164
+ * not move (fingers, eyes), usually the pose when the body loaded.
14165
+ */
14166
+ function packClips(pack, names, base) {
14167
+ const R = pack.roles.length;
14168
+ const n = names.length;
14169
+ const slot = pack.roles.map((r) => ROLE[r] ? names.indexOf(ROLE[r]) : -1);
14170
+ const out = {};
14171
+ for (const [name, c] of Object.entries(pack.clips)) {
14172
+ const q = int16(c.q);
14173
+ const frames = c.n;
14174
+ const rotations = new Float32Array(frames * n * 4);
14175
+ for (let f = 0; f < frames; f++) {
14176
+ rotations.set(Array.prototype.slice.call(base, 0, n * 4), f * n * 4);
14177
+ for (let r = 0; r < R; r++) {
14178
+ const i = slot[r];
14179
+ if (i < 0) continue;
14180
+ const a = (f * R + r) * 4;
14181
+ let x = q[a] / 32767, y = q[a + 1] / 32767, z = q[a + 2] / 32767, w = q[a + 3] / 32767;
14182
+ const len = Math.hypot(x, y, z, w) || 1;
14183
+ x /= len;
14184
+ y /= len;
14185
+ z /= len;
14186
+ w /= len;
14187
+ rotations.set([
14188
+ x,
14189
+ y,
14190
+ z,
14191
+ w
14192
+ ], (f * n + i) * 4);
14193
+ }
14194
+ }
14195
+ out[name] = {
14196
+ name,
14197
+ fps: pack.fps,
14198
+ frames,
14199
+ bones: n,
14200
+ loop: c.loop,
14201
+ rotations
14202
+ };
14203
+ }
14204
+ return out;
14205
+ }
14042
14206
  // src/character-stage.ts
14043
14207
  init_three$1();
14044
14208
  /** The verbs a stage shows by default: say hello is the next thing to do. */
@@ -14082,6 +14246,7 @@ var HackbuildMotionViews = (function(exports, three) {
14082
14246
  const turnBtn = iconButton(doc, "flip", "turn around");
14083
14247
  const frameBtn = iconButton(doc, "frame", "full body", { "aria-pressed": "false" });
14084
14248
  const tag = el(doc, "div", "hb-stage-tag", {}, [nameEl, doingEl]);
14249
+ if (!opts.plate) tag.style.display = "none";
14085
14250
  const tagCorner = el(doc, "div", "hb-ov hb-ov-tl");
14086
14251
  const corner = el(doc, "div", "hb-ov hb-ov-tr", {}, [turnBtn, frameBtn]);
14087
14252
  const stage = new AvatarStage(subject, opts);
@@ -14116,6 +14281,8 @@ var HackbuildMotionViews = (function(exports, three) {
14116
14281
  if (!opts.name) nameEl.textContent = e.placeholder ? "stand-in" : e.name;
14117
14282
  applyFraming();
14118
14283
  setDoing("idle");
14284
+ packed = null;
14285
+ if (!e.placeholder) usePack();
14119
14286
  emit({
14120
14287
  type: "loaded",
14121
14288
  name: e.name,
@@ -14127,6 +14294,28 @@ var HackbuildMotionViews = (function(exports, three) {
14127
14294
  type: "failed",
14128
14295
  message: e.message
14129
14296
  })));
14297
+ let packed = null;
14298
+ let packFile = null;
14299
+ async function usePack() {
14300
+ const body = stage.body;
14301
+ if (!opts.clips || !body) return;
14302
+ packFile ??= typeof opts.clips === "string" ? fetch(opts.clips).then((r) => r.ok ? r.json() : null).catch(() => null) : Promise.resolve(opts.clips);
14303
+ const pack = await packFile;
14304
+ if (!pack || stage.body !== body || packCoverage(pack, body.names) < 12) return;
14305
+ const base = new Float32Array(body.bones.length * 4);
14306
+ body.bones.forEach((b, i) => b.quaternion.toArray(base, i * 4));
14307
+ packed = packClips(pack, body.names, base);
14308
+ idleLoop(.4);
14309
+ }
14310
+ function idleLoop(fade, talking = false) {
14311
+ const c = packed?.[talking ? "Idle_Talking_Loop" : "Idle_Loop"] ?? packed?.Idle_Loop;
14312
+ if (c && stage.body) stage.body.play(c, {
14313
+ layer: "body",
14314
+ loop: true,
14315
+ background: true,
14316
+ fade
14317
+ });
14318
+ }
14130
14319
  function applyFraming() {
14131
14320
  const body = stage.body;
14132
14321
  frameBtn.setAttribute("aria-pressed", String(framing === "full"));
@@ -14195,9 +14384,12 @@ var HackbuildMotionViews = (function(exports, three) {
14195
14384
  function gesture(id) {
14196
14385
  const body = stage.body;
14197
14386
  if (!body) return false;
14198
- const base = new Float32Array(body.bones.length * 4);
14199
- body.bones.forEach((b, i) => b.quaternion.toArray(base, i * 4));
14200
- const clip = gestureClip(id, body.names, base);
14387
+ let clip = rigGestureClip(id, body.bones, body.names);
14388
+ if (!clip) {
14389
+ const base = new Float32Array(body.bones.length * 4);
14390
+ body.bones.forEach((b, i) => b.quaternion.toArray(base, i * 4));
14391
+ clip = gestureClip(id, body.names, base);
14392
+ }
14201
14393
  if (!clip) return false;
14202
14394
  return play(clip, { layer: id === "bow" ? "body" : "upper" }) >= 0;
14203
14395
  }
@@ -14265,6 +14457,7 @@ var HackbuildMotionViews = (function(exports, three) {
14265
14457
  body.lip.push(events);
14266
14458
  body.setGazeMode("talk");
14267
14459
  setDoing("talking");
14460
+ idleLoop(.5, true);
14268
14461
  stage.loop.sync();
14269
14462
  start?.();
14270
14463
  if (analyser && audioCtx) {
@@ -14290,6 +14483,7 @@ var HackbuildMotionViews = (function(exports, three) {
14290
14483
  analyser?.disconnect();
14291
14484
  stage.body?.lip.setLevel(0);
14292
14485
  stage.body?.setGazeMode("listen");
14486
+ idleLoop(.6);
14293
14487
  if (doing === "talking") setDoing("idle");
14294
14488
  }
14295
14489
  function look() {
@@ -14325,7 +14519,7 @@ var HackbuildMotionViews = (function(exports, three) {
14325
14519
  frameBtn.addEventListener("click", () => frame(framing === "bust" ? "full" : "bust"), { signal: ac.signal });
14326
14520
  const ro = new ResizeObserver(() => framing === "bust" && applyFraming());
14327
14521
  ro.observe(subject);
14328
- const drop = opts.drop === false ? null : Pr(subject, [{
14522
+ const drop = opts.drop === false ? null : _r(subject, [{
14329
14523
  name: "model",
14330
14524
  accept: () => true,
14331
14525
  on: (files) => void show(files)
@@ -14621,7 +14815,7 @@ var HackbuildMotionViews = (function(exports, three) {
14621
14815
  input.value = "";
14622
14816
  if (list.length) take(list);
14623
14817
  }, { signal: ac.signal });
14624
- const drop = Pr(zone, [{
14818
+ const drop = _r(zone, [{
14625
14819
  name: "avatar",
14626
14820
  accept: () => true,
14627
14821
  on: (files) => void take(files)
@@ -15907,7 +16101,10 @@ var HackbuildMotionViews = (function(exports, three) {
15907
16101
  exports.licenceLine = licenceLine;
15908
16102
  exports.meshTurntable = meshTurntable;
15909
16103
  exports.nextClip = nextClip;
16104
+ exports.packClips = packClips;
16105
+ exports.packCoverage = packCoverage;
15910
16106
  exports.rigCheck = rigCheck;
16107
+ exports.rigGestureClip = rigGestureClip;
15911
16108
  exports.secondsWord = secondsWord;
15912
16109
  exports.sizeLine = sizeLine;
15913
16110
  exports.speechEvents = speechEvents;
package/dist/vanilla.d.ts CHANGED
@@ -3,5 +3,6 @@ export * from "./character-stage.js";
3
3
  export * from "./avatar-drop.js";
4
4
  export * from "./clip-strip.js";
5
5
  export * from "./gestures.js";
6
+ export * from "./clip-pack.js";
6
7
  export * from "./elements.js";
7
8
  export * from "./stage.js";
package/dist/vanilla.js CHANGED
@@ -7,5 +7,6 @@ export * from "./character-stage.js";
7
7
  export * from "./avatar-drop.js";
8
8
  export * from "./clip-strip.js";
9
9
  export * from "./gestures.js";
10
+ export * from "./clip-pack.js";
10
11
  export * from "./elements.js";
11
12
  export * from "./stage.js";
package/llms.md CHANGED
@@ -319,6 +319,18 @@ interface AvatarReport {
319
319
 
320
320
  What AvatarDrop learned about a dropped avatar: name, format, size, rig check, licence and still.
321
321
 
322
+ ```ts
323
+ const BOX_DOG_BONES: { readonly hips: "hips"; readonly legs: { readonly LF: { readonly end: "frontHorselink.L"; readonly mid: "frontLeg.L_03"; readonly toes: readonly ["frontToe.L"]; readonly up: "frontUpr.L" }; readonly LH: { readonly end: "rearHorselink.L"; readonly mid: "rearLwr.L"; readonly toes: readonly ["rearFoot.L", "rearToe.L"]; readonly up: "rearUpr.L" }; readonly RF: { readonly end: "frontHorselink.R"; readonly mid: "frontLeg.R_03"; readonly toes: readonly ["frontToe.R"]; readonly up: "frontUpr.R" }; readonly RH: { readonly end: "rearHorselink.R"; readonly mid: "rearLwr.R"; readonly toes: readonly ["rearFoot.R", "rearToe.R"]; readonly up: "rearUpr.R" } }; readonly spine: readonly ["spine2", "chest"]; readonly tail: readonly ["tail1", "tail3", "tail_03"] }
324
+ ```
325
+
326
+ The bone names of `boxDog`, in the shape `@hackbuild/gait` reads (hips, spine, tail, four legs).
327
+
328
+ ```ts
329
+ function boxDog(color?: string): Group
330
+ ```
331
+
332
+ A dog of bones and boxes facing +z, about 0.78 m nose to tail with the hips 0.38 m up; bone names are `BOX_DOG_BONES`.
333
+
322
334
  ```ts
323
335
  function characterStage(host: HTMLElement, opts?: CharacterStageOptions): CharacterStageHandle
324
336
  ```
@@ -371,6 +383,7 @@ interface CharacterStageOptions extends StageOptions {
371
383
  background?: number | null;
372
384
  body?: Omit<BodyOptions, "rng">;
373
385
  canvas?: HTMLCanvasElement;
386
+ clips?: string | ClipPack;
374
387
  drop?: boolean;
375
388
  environment?: string | EnvironmentRequest;
376
389
  follow?: FollowOptions;
@@ -380,6 +393,7 @@ interface CharacterStageOptions extends StageOptions {
380
393
  maxPixelRatio?: number;
381
394
  name?: string;
382
395
  normalize?: NormalizeOptions;
396
+ plate?: boolean;
383
397
  repair?: false | RepairOptions;
384
398
  restoreButton?: boolean;
385
399
  rng?: Rng;
@@ -392,6 +406,16 @@ interface CharacterStageOptions extends StageOptions {
392
406
 
393
407
  Options of `characterStage`: stage options plus name, model URL, verbs, framing, drop and the hello speech.
394
408
 
409
+ ```ts
410
+ interface ClipPack {
411
+ clips: Record<string, { dur: number; loop: boolean; n: number; p?: string; q: string }>;
412
+ fps: number;
413
+ roles: readonly string[];
414
+ }
415
+ ```
416
+
417
+ The pack file: role names, frame rate and the clips.
418
+
395
419
  ```ts
396
420
  function clipStrip(host: HTMLElement, opts?: ClipStripOptions): ClipStripHandle
397
421
  ```
@@ -459,6 +483,12 @@ type Framing = "bust" | "full"
459
483
 
460
484
  The stage shot: bust, or the full body.
461
485
 
486
+ ```ts
487
+ function freeMeshes(root: Object3D): void
488
+ ```
489
+
490
+ Frees the geometry and materials of every mesh under `root`.
491
+
462
492
  ```ts
463
493
  type Gesture = "wave" | "nod" | "shake" | "bow"
464
494
  ```
@@ -477,6 +507,22 @@ const GESTURES: readonly Gesture[]
477
507
 
478
508
  Every gesture `gestureClip` can make.
479
509
 
510
+ ```ts
511
+ function meshTurntable(host: HTMLElement, opts?: { renderer?: WebGLRenderer }): MeshTurntable
512
+ ```
513
+
514
+ A turntable that fills `host`: hemisphere light, drag to turn, one object at a time, sized for a relief or a depth surface tens of units across (the camera starts 80 units out, looking down at 30 degrees).
515
+
516
+ ```ts
517
+ interface MeshTurntable {
518
+ stage: ThreeStage;
519
+ dispose(): void;
520
+ show(o: Object3D): void;
521
+ }
522
+ ```
523
+
524
+ A running turntable: its stage, what it shows, and how to stop it.
525
+
480
526
  ```ts
481
527
  interface MotionViewsOptions {
482
528
  drop?: AvatarDropOptions;
@@ -486,6 +532,41 @@ interface MotionViewsOptions {
486
532
 
487
533
  Options `defineMotionViews` shares with every element it defines.
488
534
 
535
+ ```ts
536
+ function packClips(pack: ClipPack, names: readonly string[], base: ArrayLike<number>): Record<string, Clip>
537
+ ```
538
+
539
+ The pack's clips as presence clips over `names` (the body's bone order).
540
+
541
+ ```ts
542
+ function packCoverage(pack: ClipPack, names: readonly string[]): number
543
+ ```
544
+
545
+ How many of the pack's roles land on one of `names`.
546
+
547
+ ```ts
548
+ function rigGestureClip(id: Gesture, bones: readonly Object3D<Object3DEventMap>[], names: readonly string[], fps?: number): Clip | null
549
+ ```
550
+
551
+ A gesture as a presence clip built on the rig itself: each bone is aimed or turned in world space, in the body's own frame (forward, left and up from its shoulders), then read back as local rotations.
552
+
553
+ ```ts
554
+ function stageOrbit(camera: PerspectiveCamera, el: HTMLElement): StageOrbit
555
+ ```
556
+
557
+ A drag orbit on `el` for `camera`: horizontal drag turns, vertical drag tilts, the wheel moves in and out.
558
+
559
+ ```ts
560
+ interface StageOrbit {
561
+ enabled: boolean;
562
+ readonly target: Vector3;
563
+ dispose(): void;
564
+ update(): void;
565
+ }
566
+ ```
567
+
568
+ Drag to turn the camera round `target`, wheel or pinch to move in and out.
569
+
489
570
  ```ts
490
571
  interface StripItem extends ClipItem {
491
572
  animation?: () => AnimationClip | Promise<AnimationClip>;
@@ -502,6 +583,33 @@ interface StripItem extends ClipItem {
502
583
 
503
584
  A clip in the strip; `animation` lets the strip draw its still.
504
585
 
586
+ ```ts
587
+ function threeStage(host: HTMLElement, tick: (dt: number, t: number) => void, opts?: ThreeStageOptions): ThreeStage
588
+ ```
589
+
590
+ A stage lit in paper light that fills `host`: it sizes with the host, calls `tick(dt, t)` each frame (dt capped at 50 ms), draws, and on dispose stops the loop and frees the renderer, the orbit and every mesh.
591
+
592
+ ```ts
593
+ interface ThreeStage {
594
+ camera: PerspectiveCamera;
595
+ orbit: StageOrbit;
596
+ renderer: WebGLRenderer;
597
+ scene: Scene;
598
+ dispose(): void;
599
+ }
600
+ ```
601
+
602
+ A running stage: its scene, camera, renderer and orbit, and how to stop it.
603
+
604
+ ```ts
605
+ interface ThreeStageOptions {
606
+ ground?: boolean;
607
+ renderer?: WebGLRenderer;
608
+ }
609
+ ```
610
+
611
+ Options of `threeStage`.
612
+
505
613
  ```ts
506
614
  interface Verb {
507
615
  go?: boolean;
@@ -512,6 +620,22 @@ interface Verb {
512
620
 
513
621
  One verb on the stage.
514
622
 
623
+ ```ts
624
+ function walkBvh(o?: WalkBvhOptions): string
625
+ ```
626
+
627
+ A two step walk loop as bvh text for a humanoid that is not ours: other bone names (Hips, LeftUpLeg, RightForeArm and so on), centimetres, arms down, ZXY channels.
628
+
629
+ ```ts
630
+ interface WalkBvhOptions {
631
+ fps?: number;
632
+ seconds?: number;
633
+ swing?: number;
634
+ }
635
+ ```
636
+
637
+ Options of `walkBvh`.
638
+
515
639
  ### @hackbuild/motion-views/vue
516
640
 
517
641
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackbuild/motion-views",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "The motion views: CharacterStage, AvatarDrop and ClipStrip, binding the motion packages to hackbuild-ui, each as a Vue component and a custom element.",
5
5
  "type": "module",
6
6
  "license": "MIT",