distark-render 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/README.md +75 -0
- package/dist/modules/eyeSystem.d.ts +104 -0
- package/dist/modules/eyeSystem.d.ts.map +1 -0
- package/dist/modules/eyeSystem.js +326 -0
- package/dist/modules/eyeSystem.js.map +1 -0
- package/dist/modules/imageLoad.d.ts +86 -0
- package/dist/modules/imageLoad.d.ts.map +1 -0
- package/dist/modules/imageLoad.js +259 -0
- package/dist/modules/imageLoad.js.map +1 -0
- package/dist/modules/mouthSystem.d.ts +147 -0
- package/dist/modules/mouthSystem.d.ts.map +1 -0
- package/dist/modules/mouthSystem.js +277 -0
- package/dist/modules/mouthSystem.js.map +1 -0
- package/dist/modules/renderRig.d.ts +53 -0
- package/dist/modules/renderRig.d.ts.map +1 -0
- package/dist/modules/renderRig.js +1248 -0
- package/dist/modules/renderRig.js.map +1 -0
- package/dist/test-skia.d.ts +15 -0
- package/dist/test-skia.d.ts.map +1 -0
- package/dist/test-skia.js +179 -0
- package/dist/test-skia.js.map +1 -0
- package/dist/types.d.ts +204 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mouth System Module
|
|
3
|
+
* Handles mouth animation based on audio volume, visemes, or manual control
|
|
4
|
+
*
|
|
5
|
+
* Note: This module does NOT handle rendering - it only manages state.
|
|
6
|
+
* The renderRig module handles actual rendering of mouth images.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* MouthSystem class - Manages mouth animation state
|
|
10
|
+
*/
|
|
11
|
+
export class MouthSystem {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new MouthSystem instance
|
|
14
|
+
* @param characterId - Unique identifier for the character
|
|
15
|
+
* @param availableMouths - Set of available mouth shapes for this character
|
|
16
|
+
* @param config - Optional mouth configuration
|
|
17
|
+
*/
|
|
18
|
+
constructor(characterId, availableMouths = new Set(['closed', 'neutral']), config = {}) {
|
|
19
|
+
this.characterId = characterId;
|
|
20
|
+
this.availableMouths = availableMouths;
|
|
21
|
+
this.config = {
|
|
22
|
+
volumeThreshold: config.volumeThreshold ?? 10,
|
|
23
|
+
mouthChangeInterval: config.mouthChangeInterval ?? 120, // ms
|
|
24
|
+
talkingMouths: config.talkingMouths ?? MouthSystem.DEFAULT_TALKING_MOUTHS,
|
|
25
|
+
visemeMapping: config.visemeMapping ?? MouthSystem.DEFAULT_VISEME_MAPPING
|
|
26
|
+
};
|
|
27
|
+
this.state = {
|
|
28
|
+
currentMouthKey: 'neutral',
|
|
29
|
+
lastMouthChangeTime: 0,
|
|
30
|
+
currentVolume: 0,
|
|
31
|
+
mode: 'manual'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get current mouth state
|
|
36
|
+
*/
|
|
37
|
+
getState() {
|
|
38
|
+
return { ...this.state };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get current mouth shape
|
|
42
|
+
*/
|
|
43
|
+
getCurrentMouth() {
|
|
44
|
+
return this.state.currentMouthKey;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Manually set mouth shape
|
|
48
|
+
*/
|
|
49
|
+
setMouthShape(shape) {
|
|
50
|
+
if (this.availableMouths.has(shape)) {
|
|
51
|
+
this.state.currentMouthKey = shape;
|
|
52
|
+
this.state.mode = 'manual';
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.warn(`Mouth shape "${shape}" not available for character ${this.characterId}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Set available mouth shapes
|
|
60
|
+
*/
|
|
61
|
+
setAvailableMouths(mouths) {
|
|
62
|
+
this.availableMouths = new Set(mouths);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Update mouth animation based on audio volume
|
|
66
|
+
* @param currentTime - Current time in milliseconds
|
|
67
|
+
* @param audioData - Audio analysis data
|
|
68
|
+
*/
|
|
69
|
+
updateFromAudio(currentTime, audioData) {
|
|
70
|
+
this.state.mode = 'audio';
|
|
71
|
+
// Get audio volume from analyser
|
|
72
|
+
if (audioData.analyser && audioData.dataArray && audioData.audioElement && !audioData.audioElement.paused) {
|
|
73
|
+
audioData.analyser.getByteFrequencyData(audioData.dataArray);
|
|
74
|
+
// Calculate average volume
|
|
75
|
+
let sum = 0;
|
|
76
|
+
for (let i = 0; i < audioData.dataArray.length; i++) {
|
|
77
|
+
sum += audioData.dataArray[i];
|
|
78
|
+
}
|
|
79
|
+
const avgVolume = sum / audioData.dataArray.length;
|
|
80
|
+
this.state.currentVolume = avgVolume;
|
|
81
|
+
// Update mouth based on volume
|
|
82
|
+
if (avgVolume < (this.config.volumeThreshold ?? 10)) {
|
|
83
|
+
// Low volume: close mouth
|
|
84
|
+
this.state.currentMouthKey = this.availableMouths.has('neutral') ? 'neutral' : 'closed';
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Speaking: change mouth shape periodically
|
|
88
|
+
const timeSinceLastChange = currentTime - this.state.lastMouthChangeTime;
|
|
89
|
+
if (timeSinceLastChange > (this.config.mouthChangeInterval ?? 120)) {
|
|
90
|
+
// Filter available talking mouths
|
|
91
|
+
const availableTalkingMouths = (this.config.talkingMouths ?? []).filter(mouth => this.availableMouths.has(mouth));
|
|
92
|
+
if (availableTalkingMouths.length > 0) {
|
|
93
|
+
const randomIndex = Math.floor(Math.random() * availableTalkingMouths.length);
|
|
94
|
+
this.state.currentMouthKey = availableTalkingMouths[randomIndex];
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Fallback: use any available mouth except neutral/closed
|
|
98
|
+
const fallbackMouths = Array.from(this.availableMouths).filter(m => m !== 'neutral' && m !== 'closed');
|
|
99
|
+
if (fallbackMouths.length > 0) {
|
|
100
|
+
const randomIndex = Math.floor(Math.random() * fallbackMouths.length);
|
|
101
|
+
this.state.currentMouthKey = fallbackMouths[randomIndex];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.state.lastMouthChangeTime = currentTime;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// No audio or paused: reset to neutral
|
|
110
|
+
this.state.currentVolume = 0;
|
|
111
|
+
this.state.currentMouthKey = this.availableMouths.has('neutral') ? 'neutral' : 'closed';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Update mouth animation based on viseme data
|
|
116
|
+
* @param viseme - Viseme identifier (e.g., 'A', 'E', 'O')
|
|
117
|
+
*/
|
|
118
|
+
updateFromViseme(viseme) {
|
|
119
|
+
this.state.mode = 'viseme';
|
|
120
|
+
const mapping = this.config.visemeMapping ?? MouthSystem.DEFAULT_VISEME_MAPPING;
|
|
121
|
+
const mappedShape = mapping[viseme];
|
|
122
|
+
if (mappedShape && this.availableMouths.has(mappedShape)) {
|
|
123
|
+
this.state.currentMouthKey = mappedShape;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// Fallback to closed if viseme not found
|
|
127
|
+
this.state.currentMouthKey = this.availableMouths.has('closed') ? 'closed' : 'neutral';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Reset mouth to neutral/closed state
|
|
132
|
+
*/
|
|
133
|
+
reset() {
|
|
134
|
+
this.state.currentMouthKey = this.availableMouths.has('neutral') ? 'neutral' : 'closed';
|
|
135
|
+
this.state.currentVolume = 0;
|
|
136
|
+
this.state.lastMouthChangeTime = 0;
|
|
137
|
+
this.state.mode = 'manual';
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get the image key for the current mouth shape
|
|
141
|
+
* This is used by renderRig to determine which image to render
|
|
142
|
+
*
|
|
143
|
+
* @returns The image key for the current mouth (e.g., 'imagePaths.mouth_open')
|
|
144
|
+
*/
|
|
145
|
+
getCurrentMouthImageKey() {
|
|
146
|
+
const currentMouth = this.state.currentMouthKey === 'neutral' ? 'closed' : this.state.currentMouthKey;
|
|
147
|
+
// Map mouth shape to possible image key variations
|
|
148
|
+
const keyMappings = {
|
|
149
|
+
'closed': ['mouth_closed', 'closed', 'neutral'],
|
|
150
|
+
'slightly-open': ['mouth_slightly_open', 'slightly-open', 'half-open'],
|
|
151
|
+
'half-open': ['mouth_half_open', 'half-open', 'slightly-open'],
|
|
152
|
+
'open': ['mouth_open', 'open'],
|
|
153
|
+
'wide-open': ['mouth_wide_open', 'wide-open'],
|
|
154
|
+
'ah': ['mouth_ah', 'ah'],
|
|
155
|
+
'ee': ['mouth_ee', 'ee'],
|
|
156
|
+
'woo': ['mouth_woo', 'woo'],
|
|
157
|
+
'ds': ['mouth_ds', 'ds'],
|
|
158
|
+
'neutral': ['mouth_closed', 'closed', 'neutral']
|
|
159
|
+
};
|
|
160
|
+
const candidates = keyMappings[currentMouth] || [currentMouth];
|
|
161
|
+
// Return the first candidate (renderRig will try all variants)
|
|
162
|
+
return candidates[0];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get all possible image key candidates for current mouth
|
|
166
|
+
* Used by renderRig to try multiple image name variations
|
|
167
|
+
*/
|
|
168
|
+
getMouthImageKeyCandidates() {
|
|
169
|
+
const currentMouth = this.state.currentMouthKey === 'neutral' ? 'closed' : this.state.currentMouthKey;
|
|
170
|
+
const keyMappings = {
|
|
171
|
+
'closed': ['mouth_closed', 'closed', 'neutral'],
|
|
172
|
+
'slightly-open': ['mouth_slightly_open', 'slightly-open', 'half-open'],
|
|
173
|
+
'half-open': ['mouth_half_open', 'half-open', 'slightly-open'],
|
|
174
|
+
'open': ['mouth_open', 'open'],
|
|
175
|
+
'wide-open': ['mouth_wide_open', 'wide-open'],
|
|
176
|
+
'ah': ['mouth_ah', 'ah'],
|
|
177
|
+
'ee': ['mouth_ee', 'ee'],
|
|
178
|
+
'woo': ['mouth_woo', 'woo'],
|
|
179
|
+
'ds': ['mouth_ds', 'ds'],
|
|
180
|
+
'neutral': ['mouth_closed', 'closed', 'neutral']
|
|
181
|
+
};
|
|
182
|
+
return keyMappings[currentMouth] || [currentMouth];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get configuration
|
|
186
|
+
*/
|
|
187
|
+
getConfig() {
|
|
188
|
+
return { ...this.config };
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Update configuration
|
|
192
|
+
*/
|
|
193
|
+
updateConfig(config) {
|
|
194
|
+
this.config = { ...this.config, ...config };
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get debug information
|
|
198
|
+
*/
|
|
199
|
+
getDebugInfo() {
|
|
200
|
+
return `Mouth System [${this.characterId}]
|
|
201
|
+
Current: ${this.state.currentMouthKey}
|
|
202
|
+
Mode: ${this.state.mode}
|
|
203
|
+
Volume: ${this.state.currentVolume.toFixed(1)}
|
|
204
|
+
Available: [${Array.from(this.availableMouths).join(', ')}]`;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Default viseme to mouth shape mapping
|
|
209
|
+
*/
|
|
210
|
+
MouthSystem.DEFAULT_VISEME_MAPPING = {
|
|
211
|
+
'X': 'closed',
|
|
212
|
+
'A': 'open',
|
|
213
|
+
'B': 'closed',
|
|
214
|
+
'C': 'half-open',
|
|
215
|
+
'D': 'ds',
|
|
216
|
+
'E': 'ee',
|
|
217
|
+
'F': 'half-open',
|
|
218
|
+
'G': 'half-open',
|
|
219
|
+
'H': 'slightly-open',
|
|
220
|
+
'I': 'ee',
|
|
221
|
+
'J': 'slightly-open',
|
|
222
|
+
'K': 'half-open',
|
|
223
|
+
'L': 'slightly-open',
|
|
224
|
+
'M': 'closed',
|
|
225
|
+
'N': 'slightly-open',
|
|
226
|
+
'O': 'woo',
|
|
227
|
+
'P': 'closed',
|
|
228
|
+
'Q': 'woo',
|
|
229
|
+
'R': 'slightly-open',
|
|
230
|
+
'S': 'slightly-open',
|
|
231
|
+
'T': 'ds',
|
|
232
|
+
'U': 'woo',
|
|
233
|
+
'V': 'half-open',
|
|
234
|
+
'W': 'woo',
|
|
235
|
+
'Y': 'ee',
|
|
236
|
+
'Z': 'slightly-open'
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Default talking mouths (used for random audio-based animation)
|
|
240
|
+
*/
|
|
241
|
+
MouthSystem.DEFAULT_TALKING_MOUTHS = [
|
|
242
|
+
'slightly-open',
|
|
243
|
+
'half-open',
|
|
244
|
+
'open',
|
|
245
|
+
'wide-open',
|
|
246
|
+
'ah',
|
|
247
|
+
'ee',
|
|
248
|
+
'woo'
|
|
249
|
+
];
|
|
250
|
+
/**
|
|
251
|
+
* Factory function to create mouth system
|
|
252
|
+
*/
|
|
253
|
+
export function createMouthSystem(characterId, availableMouths = ['closed', 'neutral'], config = {}) {
|
|
254
|
+
return new MouthSystem(characterId, new Set(availableMouths), config);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Helper: Extract available mouth shapes from rig data
|
|
258
|
+
*/
|
|
259
|
+
export function extractMouthShapesFromRigData(rigData) {
|
|
260
|
+
const mouths = [];
|
|
261
|
+
const mouthTypes = [
|
|
262
|
+
'closed', 'slightly-open', 'half-open', 'ds', 'open', 'ee', 'wide-open', 'ah', 'woo', 'neutral'
|
|
263
|
+
];
|
|
264
|
+
if (rigData.imagePaths) {
|
|
265
|
+
for (const mouthType of mouthTypes) {
|
|
266
|
+
if (rigData.imagePaths[mouthType] || rigData.imagePaths[`mouth_${mouthType}`]) {
|
|
267
|
+
mouths.push(mouthType);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// Always include at least closed/neutral as fallback
|
|
272
|
+
if (mouths.length === 0) {
|
|
273
|
+
mouths.push('closed', 'neutral');
|
|
274
|
+
}
|
|
275
|
+
return mouths;
|
|
276
|
+
}
|
|
277
|
+
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EAAE,CAAC;gBAC9E,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,qDAAqD;IACrD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering-agnostic character rig data generator
|
|
3
|
+
* Computes all transforms and returns a data structure that can be used with any rendering library
|
|
4
|
+
*/
|
|
5
|
+
import { ImageLoader } from './imageLoad.js';
|
|
6
|
+
import type { RigData, RenderOptions, RigRenderData, Position } from '../types.js';
|
|
7
|
+
/**
|
|
8
|
+
* CharacterRigRenderer class - Handles character rig computation and rendering
|
|
9
|
+
*/
|
|
10
|
+
export declare class CharacterRigRenderer {
|
|
11
|
+
private imageLoader;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new CharacterRigRenderer instance
|
|
14
|
+
* @param imageLoader - Optional ImageLoader instance (creates a new one if not provided)
|
|
15
|
+
*/
|
|
16
|
+
constructor(imageLoader?: ImageLoader);
|
|
17
|
+
/**
|
|
18
|
+
* Get the ImageLoader instance
|
|
19
|
+
* @returns The ImageLoader instance
|
|
20
|
+
*/
|
|
21
|
+
getImageLoader(): ImageLoader;
|
|
22
|
+
/**
|
|
23
|
+
* Helper: apply parent transform to get world space position
|
|
24
|
+
*/
|
|
25
|
+
private applyTransform;
|
|
26
|
+
/**
|
|
27
|
+
* Computes all character rig objects with their final transforms and properties
|
|
28
|
+
*/
|
|
29
|
+
computeCharacterRigData(rigData: RigData, options?: RenderOptions): RigRenderData;
|
|
30
|
+
/**
|
|
31
|
+
* Universal Canvas renderer - handles both sync (with cache) and async (loads images)
|
|
32
|
+
*
|
|
33
|
+
* @param canvas - Canvas element to render to
|
|
34
|
+
* @param rigData - Character rig data
|
|
35
|
+
* @param loadedImages - Optional pre-loaded images. If not provided, will check cache or load from network
|
|
36
|
+
* @param cameraOffset - Camera offset for positioning
|
|
37
|
+
* @param showPivotPoints - Whether to show pivot points for debugging
|
|
38
|
+
* @returns Promise that resolves when rendering is complete
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // With pre-loaded images (fast, synchronous path)
|
|
42
|
+
* await renderer.render(canvas, rigData, myImages);
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Without images - auto-loads if needed (async path)
|
|
46
|
+
* await renderer.render(canvas, rigData);
|
|
47
|
+
*/
|
|
48
|
+
render(canvas: HTMLCanvasElement, rigData: RigData, loadedImages?: Record<string, HTMLImageElement | HTMLCanvasElement>, cameraOffset?: Position, showPivotPoints?: boolean): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare const defaultRenderer: CharacterRigRenderer;
|
|
51
|
+
export declare function renderCharacterRig(canvas: HTMLCanvasElement, rigData: RigData, loadedImages?: Record<string, HTMLImageElement | HTMLCanvasElement>, cameraOffset?: Position, showPivotPoints?: boolean): Promise<void>;
|
|
52
|
+
export declare function computeCharacterRigData(rigData: RigData, options?: RenderOptions): RigRenderData;
|
|
53
|
+
//# sourceMappingURL=renderRig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderRig.d.ts","sourceRoot":"","sources":["../../modules/renderRig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,KAAK,EACR,OAAO,EACP,aAAa,EACb,aAAa,EAGb,QAAQ,EACX,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,qBAAa,oBAAoB;IAC7B,OAAO,CAAC,WAAW,CAAc;IAEjC;;;OAGG;gBACS,WAAW,CAAC,EAAE,WAAW;IAIrC;;;OAGG;IACH,cAAc,IAAI,WAAW;IAI7B;;OAEG;IACH,OAAO,CAAC,cAAc;IAYtB;;OAEG;IACH,uBAAuB,CACnB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,aAAkB,GAC5B,aAAa;IAstChB;;;;;;;;;;;;;;;;;OAiBG;IACG,MAAM,CACR,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,OAAO,EAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,EACnE,YAAY,GAAE,QAAyB,EACvC,eAAe,GAAE,OAAc,GAChC,OAAO,CAAC,IAAI,CAAC;CA8EnB;AAGD,eAAO,MAAM,eAAe,sBAA6B,CAAC;AAG1D,wBAAsB,kBAAkB,CACpC,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,OAAO,EAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,EACnE,YAAY,GAAE,QAAyB,EACvC,eAAe,GAAE,OAAc,GAChC,OAAO,CAAC,IAAI,CAAC,CAEf;AAGD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,aAAa,CAEpG"}
|