wireface 1.1.5 → 1.3.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/README.md CHANGED
@@ -15,8 +15,8 @@
15
15
  - repo: <https://github.com/styk-tv/wireface>
16
16
  - npm: <https://www.npmjs.com/package/wireface>
17
17
  - one source file: [`wireface.js`](wireface.js)
18
- - two runnable examples: [`examples/demo.html`](examples/demo.html) (consumer), [`examples/editor.html`](examples/editor.html) (preset authoring)
19
- - two preset samples: [`examples/presets/`](examples/presets/)
18
+ - three runnable examples: [`examples/demo.html`](examples/demo.html) (consumer), [`examples/behaviours.html`](examples/behaviours.html) (several faces, behaviours, streamed speech), [`examples/editor.html`](examples/editor.html) (preset authoring)
19
+ - four preset samples: [`examples/presets/`](examples/presets/)
20
20
  - preset format: plain JSON (drop a `.json` saved by the editor onto a panel)
21
21
  - audio: any browser-decodable file (`mp3`, `wav`, `ogg`, `m4a`, `flac`, `aac`, `opus`)
22
22
 
@@ -86,6 +86,17 @@ interface WireFace {
86
86
  loadPreset(presetObject): void // the JSON saved by the editor
87
87
  setRenderConfig(partial): void // apply one-or-more renderConfig fields live
88
88
  getRenderConfig(): object // snapshot of current renderConfig
89
+ getPreset(): object // the face's whole design — the JSON loadPreset() takes
90
+
91
+ // lips from audio that is not a loaded file (v1.2, on a clock since v1.3)
92
+ pushAudio(samples, sampleRate, opts?): number // streamed PCM chunks; opts { at, run, end, delay, lead, release, audible }
93
+ cutAudio(run?): void // a person cut in: drop queued speech, and late chunks of that run
94
+ isSpeaking(): boolean
95
+ on(event, fn): () => void // 'speechstart' | 'speechend' | 'underrun' | 'behaviour'
96
+ attachAudio(source): void // a MediaStream or AudioNode; never made audible
97
+ detachAudio(): void
98
+ setMuted(bool): void // analyse the loaded audio without sounding it
99
+ isMuted(): boolean
89
100
 
90
101
  // transport
91
102
  play(fromOffset?: number): void
@@ -99,7 +110,9 @@ interface WireFace {
99
110
  // expression
100
111
  setMood(name): void // 'neutral'|'happy'|'sad'|'angry'|'fear'|'surprise'|'sleep'
101
112
  getActiveMood(): string
102
- setChannel(name, value): void // manual override (auto-releases after ~1.2s)
113
+ setChannel(name, value, opts?): void // manual override (auto-releases after ~1.2s);
114
+ // opts { hold } keeps it, { smooth } eases to it
115
+ releaseChannel(name): void
103
116
  setChannelGain(name, gain): void
104
117
  getChannel(name): number // current smoothed value (0..1 or -1..1)
105
118
  getChannelTarget(name): number // latest target before smoothing
@@ -107,6 +120,13 @@ interface WireFace {
107
120
  getChannelNames(): string[]
108
121
  getMoodNames(): string[]
109
122
 
123
+ // behaviours — named framing: yaw, pitch, zoom, brightness, mood (v1.2)
124
+ setBehaviour(name, opts?): boolean // 'speak'|'listen'|'idle'|'busy'|'point'|'closeup'|'jump'|…
125
+ defineBehaviours(recipes): void // add or replace recipes on this instance
126
+ getBehaviour(): string | null
127
+ getBehaviourNames(): string[]
128
+ getBehaviours(): object
129
+
110
130
  // camera
111
131
  setView(view): void // 'front'|'three-q'|'profile'|'orbit'
112
132
 
@@ -117,12 +137,43 @@ interface WireFace {
117
137
 
118
138
  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.
119
139
 
140
+ ### Behaviours, streamed speech, designs (v1.2)
141
+
142
+ For a page that knows what is going on and wants the faces to show it:
143
+
144
+ ```js
145
+ wf.loadPreset(design); // pick a design (background colour included)
146
+ wf.setBehaviour('listen'); // named framing — no camera code in your page
147
+ wf.setBehaviour('idle', { side: -1 }); // turned toward whoever holds the floor
148
+ wf.setBehaviour('jump'); // hops for attention, then returns by itself
149
+ wf.pushAudio(chunk, 22050, { at, run, end }); // speech as it streams in, on a clock — lips match play()
150
+ wf.cutAudio(); // a person cut in
151
+ wf.on('speechstart', () => wf.setBehaviour('speak'));
152
+ wf.on('speechend', () => wf.setBehaviour('listen'));
153
+ store(wf.getPreset()); // keep this face's design
154
+ ```
155
+
156
+ Streamed speech is analysed the moment a chunk arrives and scheduled against the sound: measured in this repo's suite, the mouth opens 50 ms ahead of the sound, is closed 66 ms after it ends, and closes 83 ms after a cut. [`SPEC.WIREFACE.STREAM.v1.3`](SPEC.WIREFACE.STREAM.v1.3.md) has the contract.
157
+
158
+ Built-in behaviours: `asleep` `parked` `idle` `waiting` `busy` `listen` `speak` `attend` `important` `cut`, and the shots `point` `distant` `away` `work` `jump` `closeup` `closeup-eyes` `closeup-nose` `closeup-mouth`. Recipes, rules and the stored design format are specified in [`SPEC.WIREFACE.BEHAVIOURS.v1.2`](SPEC.WIREFACE.BEHAVIOURS.v1.2.md); [`examples/behaviours.html`](examples/behaviours.html) runs all of it with four faces.
159
+
160
+ ### Tests
161
+
162
+ ```bash
163
+ npm test # the suite: a real headless Chrome against wireface.js (Node 22+, no dependencies)
164
+ npm run test:min # the same checks against the minified build
165
+ ```
166
+
167
+ The suite is [`test/index.html`](test/index.html) — open it in a browser to watch it run. CI runs both on every push.
168
+
120
169
  ---
121
170
 
122
171
  ## Preset JSON
123
172
 
124
- A preset is one plain object — exactly the shape produced by the editor's **save** button. Two examples ship with this repo:
173
+ A preset is one plain object — exactly the shape produced by the editor's **save** button and by `getPreset()`. Four examples ship with this repo:
125
174
 
175
+ - [`examples/presets/asset-8pgwi9.json`](examples/presets/asset-8pgwi9.json) — `17×23` red-wire face, heavy white brows, jaw pushed forward
176
+ - [`examples/presets/asset-kln33e.json`](examples/presets/asset-kln33e.json) — blocky `9×9` low-poly red-wire face, wide spread
126
177
  - [`examples/presets/asset-th5rha.json`](examples/presets/asset-th5rha.json) — dense `21×21` red-wire face, glowy iris, deep eye sockets
127
178
  - [`examples/presets/asset-ydr7de.json`](examples/presets/asset-ydr7de.json) — sparse `7×9` low-poly blue-wire face, exaggerated mouth scale
128
179
 
@@ -167,6 +218,7 @@ A preset is one plain object — exactly the shape produced by the editor's **sa
167
218
  | **style** | `lineColor` | hex | wire color |
168
219
  | | `baseColor` | hex | mesh base color |
169
220
  | | `fadeColor` | hex | depth-fade target |
221
+ | | `backgroundColor` | hex | scene background behind the face (v1.2, default `#000000`) |
170
222
  | | `depthFade` | `0..1` | depth attenuation strength |
171
223
  | | `pupilColor` / `irisColor` / `irisSize` | hex / `1..4` | eye styling |
172
224
  | | `browColor` | hex | brow line color |
@@ -189,7 +241,7 @@ noseSneer
189
241
  headRotateX headRotateY headRotateZ
190
242
  ```
191
243
 
192
- Manual overrides via `setChannel(name, value)` lock the channel for ~1.2s, then auto-release back to audio-driven control.
244
+ Manual overrides via `setChannel(name, value)` lock the channel for ~1.2s, then auto-release back to its driver. `setChannel(name, value, { hold: true })` keeps the value until `releaseChannel(name)`; `{ smooth: true }` eases to it instead of jumping.
193
245
 
194
246
  ### Moods
195
247
 
@@ -225,6 +277,7 @@ Crossfade time is controlled by `renderConfig.moodTransitionTime`.
225
277
  | File | Purpose |
226
278
  |---|---|
227
279
  | [`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. |
280
+ | [`examples/behaviours.html`](examples/behaviours.html) | **several faces driven by events** — four designs from the bundled presets, each varied and with its own background; `setBehaviour` states and shots; speech streamed as PCM chunks through `pushAudio`. |
228
281
  | [`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. |
229
282
 
230
283
  To run them locally: