@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 +21 -0
- package/README.md +175 -2
- package/dist/avatar-drop.d.ts +56 -0
- package/dist/avatar-drop.js +153 -0
- package/dist/character-stage.d.ts +85 -0
- package/dist/character-stage.js +367 -0
- package/dist/clip-strip.d.ts +48 -0
- package/dist/clip-strip.js +151 -0
- package/dist/clips.d.ts +53 -0
- package/dist/clips.js +39 -0
- package/dist/dom.d.ts +14 -0
- package/dist/dom.js +52 -0
- package/dist/elements.d.ts +26 -0
- package/dist/elements.js +120 -0
- package/dist/gestures.d.ts +14 -0
- package/dist/gestures.js +73 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/motion-views.iife.js +15344 -0
- package/dist/single.d.ts +1 -0
- package/dist/single.js +3 -0
- package/dist/speech.d.ts +37 -0
- package/dist/speech.js +38 -0
- package/dist/thumb.d.ts +13 -0
- package/dist/thumb.js +62 -0
- package/dist/vanilla.d.ts +6 -0
- package/dist/vanilla.js +9 -0
- package/dist/vue.d.ts +169 -0
- package/dist/vue.js +112 -0
- package/dist/words.d.ts +57 -0
- package/dist/words.js +96 -0
- package/how.ts +27 -0
- package/llms.md +581 -0
- package/package.json +62 -4
package/dist/single.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./vanilla.js";
|
package/dist/single.js
ADDED
package/dist/speech.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type SpeechEvent } from "@hackbuild/lipsync";
|
|
2
|
+
/** A word or phoneme with its time from the start of the audio, as @hackbuild/speak reports it. */
|
|
3
|
+
export interface SpeechTiming {
|
|
4
|
+
t0: number;
|
|
5
|
+
t1: number;
|
|
6
|
+
/** Character offsets in `text`, for a word. */
|
|
7
|
+
start?: number;
|
|
8
|
+
end?: number;
|
|
9
|
+
/** The word, when the offsets are not given. */
|
|
10
|
+
text?: string;
|
|
11
|
+
/** A phoneme symbol (ARPAbet), for a phoneme timing. */
|
|
12
|
+
phoneme?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Something to say. Give audio for real speech; text alone is spoken on estimated timings with no sound. */
|
|
15
|
+
export interface Speech {
|
|
16
|
+
text?: string;
|
|
17
|
+
audio?: AudioBuffer | HTMLMediaElement;
|
|
18
|
+
words?: readonly SpeechTiming[];
|
|
19
|
+
phonemes?: readonly SpeechTiming[];
|
|
20
|
+
/** Lipsync events timed from the start of the audio, as `fromSpans` of the bellows adapter makes them. */
|
|
21
|
+
events?: readonly SpeechEvent[];
|
|
22
|
+
}
|
|
23
|
+
/** Where the mouth timings come from, for the readout and the tests. */
|
|
24
|
+
export type SpeechSource = "events" | "phonemes" | "words" | "estimate" | "audio level";
|
|
25
|
+
/** Seconds text takes on estimated timings: about 0.34 s a word (inferred), at least 0.8 s. */
|
|
26
|
+
export declare function estimateSeconds(text: string): number;
|
|
27
|
+
/**
|
|
28
|
+
* The mouth events for a speech starting at `t0` on the mouth clock and
|
|
29
|
+
* lasting `seconds`, closed by an end event, and where they came from.
|
|
30
|
+
* Timings win in the order events, phonemes, words; text alone is
|
|
31
|
+
* estimated only when there is no audio, since audio drives the mouth by
|
|
32
|
+
* its level when no timings come with it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function speechEvents(s: Speech, t0: number, seconds: number): {
|
|
35
|
+
events: SpeechEvent[];
|
|
36
|
+
source: SpeechSource;
|
|
37
|
+
};
|
package/dist/speech.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// What a stage is told to say, and the mouth events it becomes. Real speech
|
|
2
|
+
// arrives as audio (an AudioBuffer or an audio element) with the timings a
|
|
3
|
+
// speech engine reports: words and phonemes as @hackbuild/speak's Timed
|
|
4
|
+
// (t0 and t1 in seconds from the start of the audio, start and end as
|
|
5
|
+
// character offsets in the text), or lipsync events as the bellows adapter
|
|
6
|
+
// makes them. The audio level drives the mouth between timings; text alone
|
|
7
|
+
// falls back to estimated word timings.
|
|
8
|
+
import { estimateWords } from "@hackbuild/lipsync";
|
|
9
|
+
/** Seconds text takes on estimated timings: about 0.34 s a word (inferred), at least 0.8 s. */
|
|
10
|
+
export function estimateSeconds(text) {
|
|
11
|
+
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
|
|
12
|
+
return Math.max(0.8, words * 0.34);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The mouth events for a speech starting at `t0` on the mouth clock and
|
|
16
|
+
* lasting `seconds`, closed by an end event, and where they came from.
|
|
17
|
+
* Timings win in the order events, phonemes, words; text alone is
|
|
18
|
+
* estimated only when there is no audio, since audio drives the mouth by
|
|
19
|
+
* its level when no timings come with it.
|
|
20
|
+
*/
|
|
21
|
+
export function speechEvents(s, t0, seconds) {
|
|
22
|
+
const end = { type: "end", time: t0 + seconds };
|
|
23
|
+
const shift = (e) => ({ ...e, time: e.time + t0, ...("end" in e && e.end !== undefined ? { end: e.end + t0 } : {}) });
|
|
24
|
+
if (s.events?.length)
|
|
25
|
+
return { events: [...s.events.map(shift), end], source: "events" };
|
|
26
|
+
if (s.phonemes?.some((p) => p.phoneme)) {
|
|
27
|
+
const events = s.phonemes.filter((p) => p.phoneme).map((p) => ({ type: "phoneme", time: t0 + p.t0, end: t0 + p.t1, phoneme: p.phoneme }));
|
|
28
|
+
return { events: [...events, end], source: "phonemes" };
|
|
29
|
+
}
|
|
30
|
+
if (s.words?.length) {
|
|
31
|
+
const text = s.text ?? "";
|
|
32
|
+
const events = s.words.map((w) => ({ type: "word", time: t0 + w.t0, end: t0 + w.t1, text: w.text ?? (w.start !== undefined && w.end !== undefined ? text.slice(w.start, w.end) : "") }));
|
|
33
|
+
return { events: [...events, end], source: "words" };
|
|
34
|
+
}
|
|
35
|
+
if (s.text?.trim() && !s.audio)
|
|
36
|
+
return { events: [...estimateWords(s.text, t0, t0 + seconds), end], source: "estimate" };
|
|
37
|
+
return { events: [end], source: "audio level" };
|
|
38
|
+
}
|
package/dist/thumb.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Object3D } from "three";
|
|
2
|
+
export declare class Still {
|
|
3
|
+
readonly width: number;
|
|
4
|
+
readonly height: number;
|
|
5
|
+
private renderer;
|
|
6
|
+
private readonly scene;
|
|
7
|
+
private readonly camera;
|
|
8
|
+
private readonly canvas;
|
|
9
|
+
constructor(doc: Document, width?: number, height?: number);
|
|
10
|
+
/** Draws `root` as a PNG, or null when there is no webgl here. `root` is put back where it was. */
|
|
11
|
+
draw(root: Object3D): Promise<Blob | null>;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
}
|
package/dist/thumb.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A still of a loaded avatar for the drop card: one small renderer per
|
|
2
|
+
// card, made on the first still, the body seen a little from its left and
|
|
3
|
+
// above as the clip thumbnails see their figure, so the two read alike.
|
|
4
|
+
import { Box3, DirectionalLight, HemisphereLight, OrthographicCamera, SRGBColorSpace, Scene, Vector3, WebGLRenderer } from "three";
|
|
5
|
+
export class Still {
|
|
6
|
+
width;
|
|
7
|
+
height;
|
|
8
|
+
renderer = null;
|
|
9
|
+
scene = new Scene();
|
|
10
|
+
camera = new OrthographicCamera();
|
|
11
|
+
canvas;
|
|
12
|
+
constructor(doc, width = 120, height = 160) {
|
|
13
|
+
this.width = width;
|
|
14
|
+
this.height = height;
|
|
15
|
+
this.canvas = doc.createElement("canvas");
|
|
16
|
+
const key = new DirectionalLight(0xffffff, 2.6);
|
|
17
|
+
key.position.set(1.6, 2.6, 2.4);
|
|
18
|
+
const rim = new DirectionalLight(0xffffff, 1.4);
|
|
19
|
+
rim.position.set(-2, 1.4, -2);
|
|
20
|
+
this.scene.add(key, rim, new HemisphereLight(0xffffff, 0x303038, 1.3));
|
|
21
|
+
}
|
|
22
|
+
/** Draws `root` as a PNG, or null when there is no webgl here. `root` is put back where it was. */
|
|
23
|
+
async draw(root) {
|
|
24
|
+
if (!this.renderer) {
|
|
25
|
+
try {
|
|
26
|
+
this.renderer = new WebGLRenderer({ canvas: this.canvas, alpha: true, antialias: true, preserveDrawingBuffer: true });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
this.renderer.setPixelRatio(1);
|
|
32
|
+
this.renderer.setSize(this.width, this.height, false);
|
|
33
|
+
this.renderer.outputColorSpace = SRGBColorSpace;
|
|
34
|
+
this.renderer.setClearColor(0x000000, 0);
|
|
35
|
+
}
|
|
36
|
+
const parent = root.parent;
|
|
37
|
+
this.scene.add(root);
|
|
38
|
+
root.updateMatrixWorld(true);
|
|
39
|
+
const box = new Box3().setFromObject(root);
|
|
40
|
+
const c = box.getCenter(new Vector3());
|
|
41
|
+
const size = box.getSize(new Vector3());
|
|
42
|
+
const aspect = this.width / this.height;
|
|
43
|
+
const half = Math.max(size.y / 2, size.x / 2 / aspect) * 1.08;
|
|
44
|
+
const cam = this.camera;
|
|
45
|
+
Object.assign(cam, { left: -half * aspect, right: half * aspect, top: half, bottom: -half, near: 0.01, far: 100 });
|
|
46
|
+
const d = Math.max(size.x, size.y, size.z) * 3 + 1;
|
|
47
|
+
cam.position.set(c.x + Math.sin(0.42) * d, c.y + Math.sin(0.17) * d, c.z + Math.cos(0.42) * d);
|
|
48
|
+
cam.lookAt(c);
|
|
49
|
+
cam.updateProjectionMatrix();
|
|
50
|
+
this.renderer.render(this.scene, cam);
|
|
51
|
+
if (parent)
|
|
52
|
+
parent.add(root);
|
|
53
|
+
else
|
|
54
|
+
this.scene.remove(root);
|
|
55
|
+
return new Promise((ok) => this.canvas.toBlob(ok, "image/png"));
|
|
56
|
+
}
|
|
57
|
+
dispose() {
|
|
58
|
+
this.renderer?.dispose();
|
|
59
|
+
this.renderer?.forceContextLoss();
|
|
60
|
+
this.renderer = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/vanilla.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @hackbuild/motion-views/vanilla: CharacterStage, AvatarDrop and ClipStrip
|
|
2
|
+
// as framework free views over hackbuild-ui classes, and as custom
|
|
3
|
+
// elements once defineMotionViews() runs. Importing defines nothing.
|
|
4
|
+
export * from "./index.js";
|
|
5
|
+
export * from "./character-stage.js";
|
|
6
|
+
export * from "./avatar-drop.js";
|
|
7
|
+
export * from "./clip-strip.js";
|
|
8
|
+
export * from "./gestures.js";
|
|
9
|
+
export * from "./elements.js";
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { type PropType } from "vue";
|
|
2
|
+
import { type CharacterStageOptions, type Framing, type Verb } from "./character-stage.js";
|
|
3
|
+
import { type AvatarDropOptions } from "./avatar-drop.js";
|
|
4
|
+
import { type StripItem } from "./clip-strip.js";
|
|
5
|
+
/** The character stage. Use it as the stage of HbStageRack; the inset slot sits top left. */
|
|
6
|
+
export declare const CharacterStage: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
|
+
name: {
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
default: undefined;
|
|
10
|
+
};
|
|
11
|
+
src: {
|
|
12
|
+
type: StringConstructor;
|
|
13
|
+
default: undefined;
|
|
14
|
+
};
|
|
15
|
+
framing: {
|
|
16
|
+
type: PropType<Framing>;
|
|
17
|
+
default: string;
|
|
18
|
+
};
|
|
19
|
+
verbs: {
|
|
20
|
+
type: PropType<readonly Verb[]>;
|
|
21
|
+
default: () => readonly Verb[];
|
|
22
|
+
};
|
|
23
|
+
drop: {
|
|
24
|
+
type: BooleanConstructor;
|
|
25
|
+
default: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** Stage options: the vrm hook, lights, follow, hello. */
|
|
28
|
+
options: {
|
|
29
|
+
type: PropType<CharacterStageOptions>;
|
|
30
|
+
default: () => {};
|
|
31
|
+
};
|
|
32
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("doing" | "failed" | "framing" | "loaded" | "verb")[], "doing" | "failed" | "framing" | "loaded" | "verb", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
35
|
+
name: {
|
|
36
|
+
type: StringConstructor;
|
|
37
|
+
default: undefined;
|
|
38
|
+
};
|
|
39
|
+
src: {
|
|
40
|
+
type: StringConstructor;
|
|
41
|
+
default: undefined;
|
|
42
|
+
};
|
|
43
|
+
framing: {
|
|
44
|
+
type: PropType<Framing>;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
verbs: {
|
|
48
|
+
type: PropType<readonly Verb[]>;
|
|
49
|
+
default: () => readonly Verb[];
|
|
50
|
+
};
|
|
51
|
+
drop: {
|
|
52
|
+
type: BooleanConstructor;
|
|
53
|
+
default: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** Stage options: the vrm hook, lights, follow, hello. */
|
|
56
|
+
options: {
|
|
57
|
+
type: PropType<CharacterStageOptions>;
|
|
58
|
+
default: () => {};
|
|
59
|
+
};
|
|
60
|
+
}>> & Readonly<{
|
|
61
|
+
onDoing?: (...args: any[]) => any;
|
|
62
|
+
onFailed?: (...args: any[]) => any;
|
|
63
|
+
onFraming?: (...args: any[]) => any;
|
|
64
|
+
onLoaded?: (...args: any[]) => any;
|
|
65
|
+
onVerb?: (...args: any[]) => any;
|
|
66
|
+
}>, {
|
|
67
|
+
name: string;
|
|
68
|
+
src: string;
|
|
69
|
+
framing: Framing;
|
|
70
|
+
verbs: readonly Verb[];
|
|
71
|
+
drop: boolean;
|
|
72
|
+
options: CharacterStageOptions;
|
|
73
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
74
|
+
/** The avatar drop card: zone, still, size, licence and rig check. */
|
|
75
|
+
export declare const AvatarDrop: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
76
|
+
go: {
|
|
77
|
+
type: BooleanConstructor;
|
|
78
|
+
default: boolean;
|
|
79
|
+
};
|
|
80
|
+
label: {
|
|
81
|
+
type: StringConstructor;
|
|
82
|
+
default: undefined;
|
|
83
|
+
};
|
|
84
|
+
options: {
|
|
85
|
+
type: PropType<AvatarDropOptions>;
|
|
86
|
+
default: () => {};
|
|
87
|
+
};
|
|
88
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("checked" | "failed" | "picked" | "use")[], "checked" | "failed" | "picked" | "use", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
91
|
+
go: {
|
|
92
|
+
type: BooleanConstructor;
|
|
93
|
+
default: boolean;
|
|
94
|
+
};
|
|
95
|
+
label: {
|
|
96
|
+
type: StringConstructor;
|
|
97
|
+
default: undefined;
|
|
98
|
+
};
|
|
99
|
+
options: {
|
|
100
|
+
type: PropType<AvatarDropOptions>;
|
|
101
|
+
default: () => {};
|
|
102
|
+
};
|
|
103
|
+
}>> & Readonly<{
|
|
104
|
+
onChecked?: (...args: any[]) => any;
|
|
105
|
+
onFailed?: (...args: any[]) => any;
|
|
106
|
+
onPicked?: (...args: any[]) => any;
|
|
107
|
+
onUse?: (...args: any[]) => any;
|
|
108
|
+
}>, {
|
|
109
|
+
go: boolean;
|
|
110
|
+
label: string;
|
|
111
|
+
options: AvatarDropOptions;
|
|
112
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
113
|
+
/** The clip strip: stills to pick from and one play button. */
|
|
114
|
+
export declare const ClipStrip: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
115
|
+
items: {
|
|
116
|
+
type: PropType<readonly StripItem[]>;
|
|
117
|
+
default: () => never[];
|
|
118
|
+
};
|
|
119
|
+
current: {
|
|
120
|
+
type: PropType<string | null>;
|
|
121
|
+
default: null;
|
|
122
|
+
};
|
|
123
|
+
playing: {
|
|
124
|
+
type: BooleanConstructor;
|
|
125
|
+
default: boolean;
|
|
126
|
+
};
|
|
127
|
+
go: {
|
|
128
|
+
type: BooleanConstructor;
|
|
129
|
+
default: boolean;
|
|
130
|
+
};
|
|
131
|
+
label: {
|
|
132
|
+
type: StringConstructor;
|
|
133
|
+
default: string;
|
|
134
|
+
};
|
|
135
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
136
|
+
[key: string]: any;
|
|
137
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("pick" | "play" | "stop" | "thumb")[], "pick" | "play" | "stop" | "thumb", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
138
|
+
items: {
|
|
139
|
+
type: PropType<readonly StripItem[]>;
|
|
140
|
+
default: () => never[];
|
|
141
|
+
};
|
|
142
|
+
current: {
|
|
143
|
+
type: PropType<string | null>;
|
|
144
|
+
default: null;
|
|
145
|
+
};
|
|
146
|
+
playing: {
|
|
147
|
+
type: BooleanConstructor;
|
|
148
|
+
default: boolean;
|
|
149
|
+
};
|
|
150
|
+
go: {
|
|
151
|
+
type: BooleanConstructor;
|
|
152
|
+
default: boolean;
|
|
153
|
+
};
|
|
154
|
+
label: {
|
|
155
|
+
type: StringConstructor;
|
|
156
|
+
default: string;
|
|
157
|
+
};
|
|
158
|
+
}>> & Readonly<{
|
|
159
|
+
onPick?: (...args: any[]) => any;
|
|
160
|
+
onPlay?: (...args: any[]) => any;
|
|
161
|
+
onStop?: (...args: any[]) => any;
|
|
162
|
+
onThumb?: (...args: any[]) => any;
|
|
163
|
+
}>, {
|
|
164
|
+
items: readonly StripItem[];
|
|
165
|
+
current: string | null;
|
|
166
|
+
playing: boolean;
|
|
167
|
+
go: boolean;
|
|
168
|
+
label: string;
|
|
169
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// The views as Vue 3 components, written as render functions so the
|
|
2
|
+
// package needs no SFC compiler. Each mounts the same vanilla view the
|
|
3
|
+
// custom elements use and hands its events on as Vue events.
|
|
4
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
|
|
5
|
+
import { DEFAULT_VERBS, characterStage } from "./character-stage.js";
|
|
6
|
+
import { avatarDrop } from "./avatar-drop.js";
|
|
7
|
+
import { clipStrip } from "./clip-strip.js";
|
|
8
|
+
/** The character stage. Use it as the stage of HbStageRack; the inset slot sits top left. */
|
|
9
|
+
export const CharacterStage = defineComponent({
|
|
10
|
+
name: "CharacterStage",
|
|
11
|
+
props: {
|
|
12
|
+
name: { type: String, default: undefined },
|
|
13
|
+
src: { type: String, default: undefined },
|
|
14
|
+
framing: { type: String, default: "bust" },
|
|
15
|
+
verbs: { type: Array, default: () => DEFAULT_VERBS },
|
|
16
|
+
drop: { type: Boolean, default: true },
|
|
17
|
+
/** Stage options: the vrm hook, lights, follow, hello. */
|
|
18
|
+
options: { type: Object, default: () => ({}) },
|
|
19
|
+
},
|
|
20
|
+
emits: ["loaded", "failed", "doing", "verb", "framing"],
|
|
21
|
+
setup(props, { emit, slots, expose }) {
|
|
22
|
+
const root = ref(null);
|
|
23
|
+
const handle = shallowRef(null);
|
|
24
|
+
let off = null;
|
|
25
|
+
onMounted(() => {
|
|
26
|
+
const o = { ...props.options, framing: props.framing, verbs: props.verbs, drop: props.drop };
|
|
27
|
+
if (props.name)
|
|
28
|
+
o.name = props.name;
|
|
29
|
+
if (props.src)
|
|
30
|
+
o.src = props.src;
|
|
31
|
+
handle.value = characterStage(root.value, o);
|
|
32
|
+
off = handle.value.on((e) => emit(e.type, e));
|
|
33
|
+
});
|
|
34
|
+
watch(() => props.src, (src) => {
|
|
35
|
+
if (src)
|
|
36
|
+
void handle.value?.show(src);
|
|
37
|
+
else
|
|
38
|
+
handle.value?.showPlaceholder();
|
|
39
|
+
});
|
|
40
|
+
watch(() => props.framing, (f) => handle.value?.frame(f));
|
|
41
|
+
watch(() => props.verbs, (v) => handle.value?.setVerbs(v));
|
|
42
|
+
onBeforeUnmount(() => {
|
|
43
|
+
off?.();
|
|
44
|
+
handle.value?.dispose();
|
|
45
|
+
});
|
|
46
|
+
expose({ handle });
|
|
47
|
+
return () => h("section", { ref: root, class: "hb-lay-stage" }, [
|
|
48
|
+
h("div", { class: "hb-lay-subject" }),
|
|
49
|
+
h("div", { class: "hb-lay-inset" }, slots.inset?.()),
|
|
50
|
+
h("div", { class: "hb-lay-verbs", role: "toolbar", "aria-label": "what he does" }),
|
|
51
|
+
]);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
/** The avatar drop card: zone, still, size, licence and rig check. */
|
|
55
|
+
export const AvatarDrop = defineComponent({
|
|
56
|
+
name: "AvatarDrop",
|
|
57
|
+
props: {
|
|
58
|
+
go: { type: Boolean, default: false },
|
|
59
|
+
label: { type: String, default: undefined },
|
|
60
|
+
options: { type: Object, default: () => ({}) },
|
|
61
|
+
},
|
|
62
|
+
emits: ["picked", "checked", "failed", "use"],
|
|
63
|
+
setup(props, { emit, expose }) {
|
|
64
|
+
const root = ref(null);
|
|
65
|
+
const handle = shallowRef(null);
|
|
66
|
+
let off = null;
|
|
67
|
+
onMounted(() => {
|
|
68
|
+
const o = { ...props.options, go: props.go };
|
|
69
|
+
if (props.label)
|
|
70
|
+
o.label = props.label;
|
|
71
|
+
handle.value = avatarDrop(root.value, o);
|
|
72
|
+
off = handle.value.on((e) => emit(e.type, e));
|
|
73
|
+
});
|
|
74
|
+
onBeforeUnmount(() => {
|
|
75
|
+
off?.();
|
|
76
|
+
handle.value?.dispose();
|
|
77
|
+
});
|
|
78
|
+
expose({ handle });
|
|
79
|
+
return () => h("div", { ref: root });
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
/** The clip strip: stills to pick from and one play button. */
|
|
83
|
+
export const ClipStrip = defineComponent({
|
|
84
|
+
name: "ClipStrip",
|
|
85
|
+
props: {
|
|
86
|
+
items: { type: Array, default: () => [] },
|
|
87
|
+
current: { type: String, default: null },
|
|
88
|
+
playing: { type: Boolean, default: false },
|
|
89
|
+
go: { type: Boolean, default: true },
|
|
90
|
+
label: { type: String, default: "clips" },
|
|
91
|
+
},
|
|
92
|
+
emits: ["pick", "play", "stop", "thumb"],
|
|
93
|
+
setup(props, { emit, expose }) {
|
|
94
|
+
// the strip and its play button join the parent row
|
|
95
|
+
const root = ref(null);
|
|
96
|
+
const handle = shallowRef(null);
|
|
97
|
+
let off = null;
|
|
98
|
+
onMounted(() => {
|
|
99
|
+
handle.value = clipStrip(root.value, { items: props.items, current: props.current, go: props.go, label: props.label });
|
|
100
|
+
off = handle.value.on((e) => emit(e.type, e));
|
|
101
|
+
});
|
|
102
|
+
watch(() => props.items, (items) => handle.value?.setItems(items, props.current));
|
|
103
|
+
watch(() => props.current, (id) => id && handle.value?.pick(id));
|
|
104
|
+
watch(() => props.playing, (on) => handle.value?.setPlaying(on));
|
|
105
|
+
onBeforeUnmount(() => {
|
|
106
|
+
off?.();
|
|
107
|
+
handle.value?.dispose();
|
|
108
|
+
});
|
|
109
|
+
expose({ handle });
|
|
110
|
+
return () => h("div", { ref: root, style: "display:contents" });
|
|
111
|
+
},
|
|
112
|
+
});
|
package/dist/words.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** What a loaded body can do, as @hackbuild/avatar-host reports it in BodyCaps. */
|
|
2
|
+
export interface RigFacts {
|
|
3
|
+
/** Humanoid bones the mapper found, by VRM 1.0 name. */
|
|
4
|
+
bones: readonly string[];
|
|
5
|
+
/** Expression names the face carries. */
|
|
6
|
+
expressions: readonly string[];
|
|
7
|
+
/** Clip names inside the file. */
|
|
8
|
+
clips: readonly string[];
|
|
9
|
+
mouth: boolean;
|
|
10
|
+
blink: boolean;
|
|
11
|
+
gaze: boolean;
|
|
12
|
+
/** Load warnings from the avatar package, already in plain words. */
|
|
13
|
+
warnings?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** How a rig check line reads: fine, a limit, or a blocker. */
|
|
16
|
+
export type RigTone = "ok" | "warn" | "bad";
|
|
17
|
+
/** One line of the rig check: what works or what does not, and why. */
|
|
18
|
+
export interface RigLine {
|
|
19
|
+
tone: RigTone;
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
/** The rig check: overall tone, a headline and the lines worst first. */
|
|
23
|
+
export interface RigCheck {
|
|
24
|
+
tone: RigTone;
|
|
25
|
+
/** The headline: "ready to act", "ready, with limits", "cannot act". */
|
|
26
|
+
head: string;
|
|
27
|
+
lines: RigLine[];
|
|
28
|
+
}
|
|
29
|
+
/** The rig check in plain words, worst first. */
|
|
30
|
+
export declare function rigCheck(f: RigFacts): RigCheck;
|
|
31
|
+
/** Bytes as "820 kb" or "12.4 mb". */
|
|
32
|
+
export declare function bytesWord(n: number): string;
|
|
33
|
+
/** The facts the size line reads: bytes, format, file and triangle counts. */
|
|
34
|
+
export interface SizeFacts {
|
|
35
|
+
/** Every file of the drop, model and textures. */
|
|
36
|
+
bytes: number;
|
|
37
|
+
/** vrm, glb, gltf or fbx. */
|
|
38
|
+
format: string;
|
|
39
|
+
files?: number;
|
|
40
|
+
triangles?: number;
|
|
41
|
+
}
|
|
42
|
+
/** The size line: "12.4 mb vrm, 3 files, 38 k triangles". */
|
|
43
|
+
export declare function sizeLine(s: SizeFacts): string;
|
|
44
|
+
/** VRM metadata fields the licence line reads (VRM 1.0 and 0.x). */
|
|
45
|
+
export interface LicenceMeta {
|
|
46
|
+
metaVersion?: string;
|
|
47
|
+
licenseName?: string;
|
|
48
|
+
licenseUrl?: string;
|
|
49
|
+
allowRedistribution?: boolean;
|
|
50
|
+
modification?: string;
|
|
51
|
+
commercialUsage?: string;
|
|
52
|
+
otherLicenseUrl?: string;
|
|
53
|
+
}
|
|
54
|
+
/** The licence line. A file with no metadata says so instead of guessing. */
|
|
55
|
+
export declare function licenceLine(format: string, meta: LicenceMeta | null | undefined): RigLine;
|
|
56
|
+
/** A clip's length: "2.4 s", "0.5 s", "1 min 12 s". */
|
|
57
|
+
export declare function secondsWord(s: number): string;
|
package/dist/words.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The plain words the views show: what a dropped avatar can do, its size
|
|
2
|
+
// and its licence, and a clip's length. Pure functions over plain data, so
|
|
3
|
+
// they run in Node and the tests read them without a browser.
|
|
4
|
+
const LEGS = ["leftUpperLeg", "leftLowerLeg", "leftFoot", "rightUpperLeg", "rightLowerLeg", "rightFoot"];
|
|
5
|
+
const ARMS = ["leftUpperArm", "leftLowerArm", "leftHand", "rightUpperArm", "rightLowerArm", "rightHand"];
|
|
6
|
+
const FINGER = /(Thumb|Index|Middle|Ring|Little)/;
|
|
7
|
+
/** The rig check in plain words, worst first. */
|
|
8
|
+
export function rigCheck(f) {
|
|
9
|
+
const has = new Set(f.bones);
|
|
10
|
+
const lines = [];
|
|
11
|
+
const bad = (text) => lines.push({ tone: "bad", text });
|
|
12
|
+
const warn = (text) => lines.push({ tone: "warn", text });
|
|
13
|
+
const ok = (text) => lines.push({ tone: "ok", text });
|
|
14
|
+
if (!has.has("hips"))
|
|
15
|
+
bad("no hips bone. nothing on the stage can move this body.");
|
|
16
|
+
if (!has.has("head"))
|
|
17
|
+
bad("no head bone. it cannot look at you or nod.");
|
|
18
|
+
const legs = LEGS.filter((b) => !has.has(b));
|
|
19
|
+
if (legs.length)
|
|
20
|
+
warn(legs.length === LEGS.length ? "no leg bones. it stands still and cannot walk." : "a leg is missing bones. walks will look wrong.");
|
|
21
|
+
const arms = ARMS.filter((b) => !has.has(b));
|
|
22
|
+
if (arms.length)
|
|
23
|
+
warn(arms.length === ARMS.length ? "no arm bones. it cannot wave or point." : "an arm is missing bones. gestures on that side do nothing.");
|
|
24
|
+
if (!f.mouth)
|
|
25
|
+
warn("no mouth shapes. the lips stay still while it talks.");
|
|
26
|
+
if (!f.blink)
|
|
27
|
+
warn("no blink shape. the eyes stay open.");
|
|
28
|
+
if (has.has("head") && !f.gaze)
|
|
29
|
+
warn("the head does not rest upright, so it will not follow you with its eyes.");
|
|
30
|
+
for (const w of f.warnings ?? [])
|
|
31
|
+
warn(w);
|
|
32
|
+
if (!lines.some((l) => l.tone === "bad")) {
|
|
33
|
+
const fingers = f.bones.some((b) => FINGER.test(b));
|
|
34
|
+
ok(`${f.bones.length} bones mapped${fingers ? ", fingers too" : ""}.`);
|
|
35
|
+
if (f.mouth)
|
|
36
|
+
ok("the lips follow speech.");
|
|
37
|
+
if (f.clips.length)
|
|
38
|
+
ok(`${f.clips.length} ${f.clips.length === 1 ? "clip" : "clips"} inside the file.`);
|
|
39
|
+
}
|
|
40
|
+
const tone = lines.some((l) => l.tone === "bad") ? "bad" : lines.some((l) => l.tone === "warn") ? "warn" : "ok";
|
|
41
|
+
const order = { bad: 0, warn: 1, ok: 2 };
|
|
42
|
+
lines.sort((a, b) => order[a.tone] - order[b.tone]);
|
|
43
|
+
return { tone, head: tone === "ok" ? "ready to act" : tone === "warn" ? "ready, with limits" : "cannot act", lines };
|
|
44
|
+
}
|
|
45
|
+
/** Bytes as "820 kb" or "12.4 mb". */
|
|
46
|
+
export function bytesWord(n) {
|
|
47
|
+
if (!(n >= 0))
|
|
48
|
+
return "size unknown";
|
|
49
|
+
if (n < 1000)
|
|
50
|
+
return `${n} bytes`;
|
|
51
|
+
if (n < 1e6)
|
|
52
|
+
return `${Math.round(n / 1000)} kb`;
|
|
53
|
+
const mb = n / 1e6;
|
|
54
|
+
return `${mb < 100 ? mb.toFixed(1) : Math.round(mb)} mb`;
|
|
55
|
+
}
|
|
56
|
+
/** Thousands as "38 k". */
|
|
57
|
+
const countWord = (n) => (n < 1000 ? String(n) : `${n < 10000 ? (n / 1000).toFixed(1) : Math.round(n / 1000)} k`);
|
|
58
|
+
/** The size line: "12.4 mb vrm, 3 files, 38 k triangles". */
|
|
59
|
+
export function sizeLine(s) {
|
|
60
|
+
const parts = [`${bytesWord(s.bytes)} ${s.format}`];
|
|
61
|
+
if (s.files && s.files > 1)
|
|
62
|
+
parts.push(`${s.files} files`);
|
|
63
|
+
if (s.triangles !== undefined)
|
|
64
|
+
parts.push(`${countWord(s.triangles)} triangles`);
|
|
65
|
+
return parts.join(", ");
|
|
66
|
+
}
|
|
67
|
+
/** The licence line. A file with no metadata says so instead of guessing. */
|
|
68
|
+
export function licenceLine(format, meta) {
|
|
69
|
+
if (format !== "vrm" || !meta)
|
|
70
|
+
return { tone: "warn", text: "no licence in the file. use it only if you made it or have the right to." };
|
|
71
|
+
const v1 = meta.metaVersion === "1" || meta.allowRedistribution !== undefined || meta.modification !== undefined;
|
|
72
|
+
if (v1) {
|
|
73
|
+
const name = meta.licenseUrl ? meta.licenseUrl.replace(/^https?:\/\//, "").replace(/\/$/, "") : "vrm 1.0 licence";
|
|
74
|
+
const share = meta.allowRedistribution === true ? "may be shared" : "may not be shared";
|
|
75
|
+
const edit = meta.modification === "prohibited" ? ", no edits" : meta.modification === "allowModificationRedistribution" ? ", edits may be shared" : "";
|
|
76
|
+
const sell = meta.commercialUsage && meta.commercialUsage !== "personalNonProfit" ? "" : ", personal use only";
|
|
77
|
+
return { tone: meta.allowRedistribution === true ? "ok" : "warn", text: `${name}: ${share}${edit}${sell}.` };
|
|
78
|
+
}
|
|
79
|
+
const lic = meta.licenseName ?? "";
|
|
80
|
+
if (!lic)
|
|
81
|
+
return { tone: "warn", text: "the vrm names no licence. use it only if you have the right to." };
|
|
82
|
+
if (lic === "Redistribution_Prohibited")
|
|
83
|
+
return { tone: "warn", text: "the licence forbids sharing this avatar." };
|
|
84
|
+
if (lic === "Other")
|
|
85
|
+
return { tone: "warn", text: `a custom licence${meta.otherLicenseUrl ? ` at ${meta.otherLicenseUrl}` : ""}. read it before you share.` };
|
|
86
|
+
return { tone: "ok", text: `${lic.replace(/_/g, " ").toLowerCase()}.` };
|
|
87
|
+
}
|
|
88
|
+
/** A clip's length: "2.4 s", "0.5 s", "1 min 12 s". */
|
|
89
|
+
export function secondsWord(s) {
|
|
90
|
+
if (!(s >= 0))
|
|
91
|
+
return "length unknown";
|
|
92
|
+
if (s < 60)
|
|
93
|
+
return `${s < 10 ? s.toFixed(1) : Math.round(s)} s`;
|
|
94
|
+
const m = Math.floor(s / 60);
|
|
95
|
+
return `${m} min ${Math.round(s - m * 60)} s`;
|
|
96
|
+
}
|
package/how.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// how this works: the fold of the package page and of the suite tool. Plain data, no imports;
|
|
2
|
+
// shape in tools/how.d.ts, checked by tsconfig.how.json, shipped in the tarball, never imported
|
|
3
|
+
// by the runtime entry. Text from the README.
|
|
4
|
+
const how: HowDoc = {
|
|
5
|
+
what: "the motion views: CharacterStage, AvatarDrop and ClipStrip. each binds the motion packages to hackbuild-ui and ships as a vue component and a custom element.",
|
|
6
|
+
how: [
|
|
7
|
+
"CharacterStage puts a body on the @hackbuild/avatar-host stage, with the idle, gaze, blinks and lips that @hackbuild/presence and @hackbuild/lipsync give it. it writes the stage of the hackbuild-ui stage and rack layout: the lit stage, the corner plate with the name and what the body is doing, turn around and framing at the top right, the verb row at the foot and an inset slot at the top left. files dropped on it become the body. `say` plays real speech, an AudioBuffer or an audio element with the word or phoneme timings a speech engine gives, and the audio level opens the mouth; text alone moves the lips on estimated timings.",
|
|
8
|
+
"AvatarDrop loads a dropped or picked file once into the normalized humanoid, checks it as a stage body would be checked, draws a still and frees it. it says what the body can do in plain words (no mouth shapes, no leg bones), the size, and the licence the file states, and hands the files on so a stage can wear them.",
|
|
9
|
+
"ClipStrip shows clips as stills to pick from, with one play button. items come from a @hackbuild/bake clip pack (`clipsFromPack`, which flags a loop that does not close), from a @hackbuild/retarget motion (`clipFromFindings`) or from a body's own file. stills are drawn in the background on a clay figure by the avatar-host thumb queue.",
|
|
10
|
+
"the main entry holds the words and the clip items with no three.js; `/vanilla` holds the views and `defineMotionViews()`, which defines hb-character-stage, hb-avatar-drop and hb-clip-strip; `/vue` holds the same views as vue components. the views carry no styles: every class is hackbuild-ui's.",
|
|
11
|
+
],
|
|
12
|
+
packages: ["@hackbuild/motion-views", "@hackbuild/avatar-host", "@hackbuild/presence", "@hackbuild/lipsync", "@virgilvox/hackbuild-ui"],
|
|
13
|
+
install: "npm install @hackbuild/motion-views @virgilvox/hackbuild-ui three",
|
|
14
|
+
today: "git clone https://github.com/hackbuild/hackbuild-motion && cd hackbuild-motion && npm ci && npm run build && npm pack -w @hackbuild/motion-views",
|
|
15
|
+
code: `import { defineMotionViews } from "@hackbuild/motion-views/vanilla";
|
|
16
|
+
|
|
17
|
+
defineMotionViews({ stage: { vrm: () => import("@hackbuild/avatar/vrm").then((m) => m.vrmHook()) } });
|
|
18
|
+
// <hb-character-stage name="moheeb"></hb-character-stage> <hb-avatar-drop></hb-avatar-drop>
|
|
19
|
+
const stage = document.querySelector("hb-character-stage")!;
|
|
20
|
+
document.querySelector("hb-avatar-drop")!.addEventListener("picked", (e) => stage.handle?.show(e.detail.files));
|
|
21
|
+
stage.addEventListener("doing", (e) => console.info(e.detail.word));
|
|
22
|
+
|
|
23
|
+
// vue: <CharacterStage :verbs="verbs" @verb="onVerb"><template #inset>..</template></CharacterStage>
|
|
24
|
+
import { CharacterStage, AvatarDrop, ClipStrip } from "@hackbuild/motion-views/vue";`,
|
|
25
|
+
links: { page: "https://hackbuild.github.io/hackbuild-motion/character-stage/", source: "https://github.com/hackbuild/hackbuild-motion/tree/main/packages/motion-views" },
|
|
26
|
+
};
|
|
27
|
+
export default how;
|