wireface 1.0.0
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 +22 -0
- package/README.md +288 -0
- package/dist/wireface.js +1447 -0
- package/dist/wireface.min.js +1 -0
- package/docs/wireface.png +0 -0
- package/examples/demo.html +296 -0
- package/examples/editor.html +3023 -0
- package/examples/presets/asset-th5rha.json +121 -0
- package/examples/presets/asset-ydr7de.json +121 -0
- package/package.json +59 -0
- package/wireface.js +1447 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
wireface — https://github.com/styk-tv/wireface
|
|
4
|
+
Copyright (c) 2026 Peter Styk
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# wireface
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**Minimal embeddable wireframe lipsync face renderer** — drives expressive character profiles from voice or TTS audio in the browser.
|
|
6
|
+
|
|
7
|
+
Each call to `createWireface(canvas)` builds a fully independent instance: its own Babylon engine + scene, its own audio context, its own channel state, its own materials and meshes. Multiple instances live on the same page side-by-side without sharing state — drop a different preset and a different voice clip on each one.
|
|
8
|
+
|
|
9
|
+
- repo: <https://github.com/styk-tv/wireface>
|
|
10
|
+
- npm: <https://www.npmjs.com/package/wireface>
|
|
11
|
+
- one source file: [`wireface.js`](wireface.js)
|
|
12
|
+
- two runnable examples: [`examples/demo.html`](examples/demo.html) (consumer), [`examples/editor.html`](examples/editor.html) (preset authoring)
|
|
13
|
+
- two preset samples: [`examples/presets/`](examples/presets/)
|
|
14
|
+
- preset format: plain JSON (drop a `.json` saved by the editor onto a panel)
|
|
15
|
+
- audio: any browser-decodable file (`mp3`, `wav`, `ogg`, `m4a`, `flac`, `aac`, `opus`)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
### npm
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install wireface
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### CDN (no build step)
|
|
28
|
+
|
|
29
|
+
Two flavors are published — pick by file extension:
|
|
30
|
+
|
|
31
|
+
| Flavor | jsDelivr | unpkg |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| **indented** (readable, debuggable) | `https://cdn.jsdelivr.net/npm/wireface@1/wireface.js` | `https://unpkg.com/wireface@1/wireface.js` |
|
|
34
|
+
| **minified** (smaller, production) | `https://cdn.jsdelivr.net/npm/wireface@1/dist/wireface.min.js` | `https://unpkg.com/wireface@1/dist/wireface.min.js` |
|
|
35
|
+
|
|
36
|
+
Pin to a major (`@1`), a minor (`@1.0`), or an exact version (`@1.0.0`) — `latest` works too but isn't recommended for production.
|
|
37
|
+
|
|
38
|
+
`wireface` has one **peer dependency**: [Babylon.js](https://www.babylonjs.com/) (`babylonjs >= 6.0.0`). Load it from CDN or bundle it yourself before `wireface.js` runs.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<!-- Babylon.js v9 as a global, loaded BEFORE wireface.js -->
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
|
|
47
|
+
<!-- pick one — minified for production, indented for debugging -->
|
|
48
|
+
<script src="https://cdn.jsdelivr.net/npm/wireface@1/dist/wireface.min.js"></script>
|
|
49
|
+
|
|
50
|
+
<canvas id="face" style="width:480px;height:480px"></canvas>
|
|
51
|
+
|
|
52
|
+
<script>
|
|
53
|
+
const wf = createWireface(document.getElementById('face'));
|
|
54
|
+
|
|
55
|
+
// Optional: load a saved preset (see "Preset JSON" below)
|
|
56
|
+
fetch('preset.json').then(r => r.json()).then(p => wf.loadPreset(p));
|
|
57
|
+
|
|
58
|
+
// Pull an audio file (or use a File from a drop / file input)
|
|
59
|
+
fetch('voice.mp3').then(r => r.blob()).then(blob => wf.loadAudio(blob));
|
|
60
|
+
|
|
61
|
+
// Drive it
|
|
62
|
+
wf.setMood('happy');
|
|
63
|
+
wf.setLoop(true);
|
|
64
|
+
wf.play();
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
That's the entire surface. Everything else is presets, channels, and moods.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Public API
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
createWireface(canvas: HTMLCanvasElement, options?: object) → WireFace
|
|
76
|
+
|
|
77
|
+
interface WireFace {
|
|
78
|
+
// audio + preset
|
|
79
|
+
loadAudio(file_or_blob): Promise<void>
|
|
80
|
+
loadPreset(presetObject): void // the JSON saved by the editor
|
|
81
|
+
setRenderConfig(partial): void // apply one-or-more renderConfig fields live
|
|
82
|
+
getRenderConfig(): object // snapshot of current renderConfig
|
|
83
|
+
|
|
84
|
+
// transport
|
|
85
|
+
play(fromOffset?: number): void
|
|
86
|
+
pause(): void
|
|
87
|
+
stop(): void
|
|
88
|
+
setLoop(bool): void
|
|
89
|
+
isPlaying(): boolean
|
|
90
|
+
getDuration(): number // seconds (0 if no audio loaded)
|
|
91
|
+
getPosition(): number // seconds since playback start
|
|
92
|
+
|
|
93
|
+
// expression
|
|
94
|
+
setMood(name): void // 'neutral'|'happy'|'sad'|'angry'|'fear'|'surprise'|'sleep'
|
|
95
|
+
getActiveMood(): string
|
|
96
|
+
setChannel(name, value): void // manual override (auto-releases after ~1.2s)
|
|
97
|
+
setChannelGain(name, gain): void
|
|
98
|
+
getChannel(name): number // current smoothed value (0..1 or -1..1)
|
|
99
|
+
getChannelTarget(name): number // latest target before smoothing
|
|
100
|
+
getChannelGain(name): number
|
|
101
|
+
getChannelNames(): string[]
|
|
102
|
+
getMoodNames(): string[]
|
|
103
|
+
|
|
104
|
+
// camera
|
|
105
|
+
setView(view): void // 'front'|'three-q'|'profile'|'orbit'
|
|
106
|
+
|
|
107
|
+
// teardown
|
|
108
|
+
dispose(): void
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Multiple instances are independent — see [`examples/demo.html`](examples/demo.html) for a two-panel example with per-panel drag/drop, transport buttons, and mood pills.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Preset JSON
|
|
117
|
+
|
|
118
|
+
A preset is one plain object — exactly the shape produced by the editor's **save** button. Two examples ship with this repo:
|
|
119
|
+
|
|
120
|
+
- [`examples/presets/asset-th5rha.json`](examples/presets/asset-th5rha.json) — dense `21×21` red-wire face, glowy iris, deep eye sockets
|
|
121
|
+
- [`examples/presets/asset-ydr7de.json`](examples/presets/asset-ydr7de.json) — sparse `7×9` low-poly blue-wire face, exaggerated mouth scale
|
|
122
|
+
|
|
123
|
+
### Top-level fields
|
|
124
|
+
|
|
125
|
+
| Field | Type | Meaning |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `version` | string | preset format version (e.g. `"wireface-v010"`) |
|
|
128
|
+
| `createdAt` | ISO string | when the preset was saved |
|
|
129
|
+
| `renderConfig` | object | mesh + render + style — see below |
|
|
130
|
+
| `channelGains` | object | per-channel gain (`0..N`); scales how much each input drives the face |
|
|
131
|
+
| `channelGainSliders` | object | UI-side slider position; `loadPreset` reads `channelGains` |
|
|
132
|
+
| `activeMood` | string | one of `neutral`, `happy`, `sad`, `angry`, `fear`, `surprise`, `sleep` |
|
|
133
|
+
| `moodTargetWeights` | object | per-mood target weight `0..1` (sum is normally 1) |
|
|
134
|
+
| `audioName` | string | hint of the audio that was paired with this preset (informational) |
|
|
135
|
+
| `lineColor` / `pupilColor` | hex | top-level color overrides applied after `renderConfig` |
|
|
136
|
+
| `id` / `name` | string | UI identifier |
|
|
137
|
+
|
|
138
|
+
### `renderConfig` fields
|
|
139
|
+
|
|
140
|
+
| Group | Field | Range | Notes |
|
|
141
|
+
|---|---|---|---|
|
|
142
|
+
| **mesh** | `meshCols` / `meshRows` | int | grid resolution; rebuild on change. e.g. `21×21` (smooth) or `7×9` (low-poly) |
|
|
143
|
+
| | `mode` | `"wire"` / `"solid"` / etc. | render mode |
|
|
144
|
+
| | `meshVisible` | bool | show the underlying grid |
|
|
145
|
+
| | `minimal` | bool | thin line overlays for mouth/eyes/brows/nose |
|
|
146
|
+
| | `fragment` | bool | break the wire mesh into per-tri fragments |
|
|
147
|
+
| | `flipFace` | bool | mirror the face left↔right |
|
|
148
|
+
| | `lineThickness` | `0.1..2` | overlay tube radius |
|
|
149
|
+
| **face shape** | `scaleNose` / `scaleEyes` / `scaleMouth` | `0..2+` | per-feature scaling |
|
|
150
|
+
| | `spread` | `0..1` | how widely shapes spread across the mesh |
|
|
151
|
+
| | `reactivity` | `0..1` | overall morph amplitude in response to audio |
|
|
152
|
+
| | `lipVertAmp` | `0..N` | vertical amplitude of lip motion |
|
|
153
|
+
| | `lipPressForce` | `0..N` | "press" force for closure visemes (`PP`, `MM`-like) |
|
|
154
|
+
| | `jawExtend` / `mouthGrow` | offsets | static mouth shape biases |
|
|
155
|
+
| **holes / depth** | `mouthHole` / `eyeHoles` | bool | cut holes in the mesh |
|
|
156
|
+
| | `mouthHoleSize` | `~1..2` | radius multiplier |
|
|
157
|
+
| | `eyeDepth` | int | how deep eye sockets push into the mesh |
|
|
158
|
+
| | `mouthAnchor` / `eyeAnchor` | bool | pin anchor rings to track shape changes |
|
|
159
|
+
| | `overlayTracksMesh` | bool | minimal-line overlays follow mesh deformation |
|
|
160
|
+
| **style** | `lineColor` | hex | wire color |
|
|
161
|
+
| | `baseColor` | hex | mesh base color |
|
|
162
|
+
| | `fadeColor` | hex | depth-fade target |
|
|
163
|
+
| | `depthFade` | `0..1` | depth attenuation strength |
|
|
164
|
+
| | `pupilColor` / `irisColor` / `irisSize` | hex / `1..4` | eye styling |
|
|
165
|
+
| | `browColor` | hex | brow line color |
|
|
166
|
+
| | `glow` | bool | bloom-style glow on emissive lines |
|
|
167
|
+
| | `pupils` | bool | render pupils at all |
|
|
168
|
+
| **mood** | `moodTransitionTime` | seconds | crossfade time between moods |
|
|
169
|
+
|
|
170
|
+
### Channels (drives)
|
|
171
|
+
|
|
172
|
+
Channels are the live signal surface. Audio analysis writes them; `setChannel()` overrides them; `channelGains` scales them; the renderer reads them every frame.
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
viseme_sil viseme_PP viseme_FF viseme_TH viseme_DD viseme_kk
|
|
176
|
+
viseme_CH viseme_SS viseme_nn viseme_RR viseme_aa viseme_E
|
|
177
|
+
viseme_I viseme_O viseme_U
|
|
178
|
+
jawOpen mouthSmile mouthPucker
|
|
179
|
+
eyeBlinkLeft eyeBlinkRight eyeLookH eyeLookV eyeSquint
|
|
180
|
+
browInnerUp browOuterUp browDown
|
|
181
|
+
noseSneer
|
|
182
|
+
headRotateX headRotateY headRotateZ
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Manual overrides via `setChannel(name, value)` lock the channel for ~1.2s, then auto-release back to audio-driven control.
|
|
186
|
+
|
|
187
|
+
### Moods
|
|
188
|
+
|
|
189
|
+
Moods are convenience presets that fade across a fixed subset of channels (`browInnerUp`, `browOuterUp`, `browDown`, `mouthSmile`, `eyeSquint`, `noseSneer`, `eyeBlinkLeft`, `eyeBlinkRight`):
|
|
190
|
+
|
|
191
|
+
| Mood | Effect |
|
|
192
|
+
|---|---|
|
|
193
|
+
| `neutral` | all-zero |
|
|
194
|
+
| `happy` | brows up, smile, slight squint |
|
|
195
|
+
| `sad` | inner-brow up, slight brow down, frown, half-blink |
|
|
196
|
+
| `angry` | brow down, frown, sneer, squint |
|
|
197
|
+
| `fear` | brows up, frown, eyes wide |
|
|
198
|
+
| `surprise` | brows up, jaw open |
|
|
199
|
+
| `sleep` | eyes closed, brows down |
|
|
200
|
+
|
|
201
|
+
Crossfade time is controlled by `renderConfig.moodTransitionTime`.
|
|
202
|
+
|
|
203
|
+
### Views
|
|
204
|
+
|
|
205
|
+
`setView(view)` snaps the camera; `'orbit'` engages a slow auto-orbit.
|
|
206
|
+
|
|
207
|
+
| View | Camera |
|
|
208
|
+
|---|---|
|
|
209
|
+
| `front` | dead-on |
|
|
210
|
+
| `three-q` | three-quarter |
|
|
211
|
+
| `profile` | side |
|
|
212
|
+
| `orbit` | slow continuous orbit |
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Examples
|
|
217
|
+
|
|
218
|
+
| File | Purpose |
|
|
219
|
+
|---|---|
|
|
220
|
+
| [`examples/demo.html`](examples/demo.html) | minimal **library consumer** — two side-by-side instances, drag-drop preset/audio, transport buttons, mood pills. Use this as your reference for embedding wireface into your own page. |
|
|
221
|
+
| [`examples/editor.html`](examples/editor.html) | full **preset authoring** UI — sliders, knobs, color pickers, mood weights, save/load. Currently self-contained (ships its own copy of the rendering pipeline) for offline authoring; produces the `.json` shape the library consumes. |
|
|
222
|
+
|
|
223
|
+
To run them locally:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
npm run demo
|
|
227
|
+
# → opens a static server at http://localhost:5173 — visit /examples/demo.html
|
|
228
|
+
# or /examples/editor.html
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Then drop the bundled presets onto each panel of the demo:
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
examples/presets/asset-th5rha.json → left
|
|
235
|
+
examples/presets/asset-ydr7de.json → right
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
…and drop any `.mp3` of speech on top of either panel.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## How it sounds → how it moves
|
|
243
|
+
|
|
244
|
+
1. `loadAudio()` decodes via `AudioContext` and wires through an `AnalyserNode`.
|
|
245
|
+
2. Each frame, the renderer reads frequency-band energies and translates them into viseme channel targets (`viseme_aa`, `viseme_O`, …) plus jaw open / lip press / smile.
|
|
246
|
+
3. Active mood blends in across mood-channels with `moodTransitionTime` crossfade.
|
|
247
|
+
4. Idle micro-motion adds breathing, blinks, and head sway when no audio is playing.
|
|
248
|
+
5. Per-channel smoothing prevents the face from snapping (visemes get heavier smoothing, brows lighter — see `SMOOTH` table in [`wireface.js`](wireface.js)).
|
|
249
|
+
6. Final channel state drives mesh morphs + minimal overlay line meshes (mouth lips, eyelids, brows, nose).
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Build & publish
|
|
254
|
+
|
|
255
|
+
The npm tarball ships both flavors:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
wireface.js — original, indented source (also at the package root)
|
|
259
|
+
dist/wireface.js — copy of the indented source under dist/ for CDN parity
|
|
260
|
+
dist/wireface.min.js — terser-minified, comments stripped
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Local build:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npm install
|
|
267
|
+
npm run build
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
CI publishes on tag push — see [`.github/workflows/publish.yml`](.github/workflows/publish.yml).
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# bump → commit → tag → push tag → CI publishes to npm with provenance
|
|
274
|
+
npm version 1.0.1
|
|
275
|
+
git push --follow-tags
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The workflow expects an **`NPM_TOKEN`** repo secret (an npm "Automation" token, not "Publish"). Set it once with:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
gh secret set NPM_TOKEN -R styk-tv/wireface
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
MIT © 2026 Peter Styk — see [`LICENSE`](LICENSE).
|