@omote/babylon 0.2.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.
@@ -0,0 +1,214 @@
1
+ import * as _omote_core from '@omote/core';
2
+ import { FaceCompositorConfig, CharacterControllerConfig, EmotionWeights, ConversationalState, A2EOrchestratorConfig } from '@omote/core';
3
+ import { AbstractMesh, TransformNode, Scene, Camera } from '@babylonjs/core';
4
+
5
+ /**
6
+ * SceneDiscovery — Discover avatar structure from a Babylon.js scene graph.
7
+ *
8
+ * Finds morph targets, head/neck/eye bones, and pre-computes a fast index
9
+ * mapping from LAM_BLENDSHAPES order to per-mesh morph target indices.
10
+ *
11
+ * @category Babylon
12
+ */
13
+
14
+ interface MorphIndexEntry {
15
+ mesh: AbstractMesh;
16
+ /** indices[lamIndex] = morphTargetIndex (or -1 if not found) */
17
+ indices: Int16Array;
18
+ }
19
+ interface SceneDiscoveryResult {
20
+ /** All meshes under the root that have a MorphTargetManager */
21
+ meshes: AbstractMesh[];
22
+ /** Head bone (TransformNode named 'Head') or null */
23
+ headBone: TransformNode | null;
24
+ /** Neck bone (TransformNode named 'Neck') or null */
25
+ neckBone: TransformNode | null;
26
+ /** Left eye bone (TransformNode named 'LeftEye') or null */
27
+ leftEyeBone: TransformNode | null;
28
+ /** Right eye bone (TransformNode named 'RightEye') or null */
29
+ rightEyeBone: TransformNode | null;
30
+ /** Pre-computed morph index mapping per mesh */
31
+ morphEntries: MorphIndexEntry[];
32
+ /** Primary face mesh (prefers 'Head_Mesh', falls back to first with morph targets) */
33
+ faceMesh: AbstractMesh | null;
34
+ /** Total number of ARKit blendshapes successfully mapped across all meshes */
35
+ mappedBlendshapeCount: number;
36
+ }
37
+ /**
38
+ * Discover avatar structure from a Babylon.js root node.
39
+ *
40
+ * Traverses the scene graph under `root` to find:
41
+ * - Meshes with MorphTargetManagers
42
+ * - Head, neck, and eye bones
43
+ * - Pre-computed LAM_BLENDSHAPES -> morph target index mapping
44
+ *
45
+ * @param root - The root AbstractMesh (typically loaded via SceneLoader)
46
+ * @returns SceneDiscoveryResult with all discovered components
47
+ */
48
+ declare function discoverScene(root: AbstractMesh): SceneDiscoveryResult;
49
+
50
+ /** Generic frame source -- any object that emits 'frame' events */
51
+ interface FrameSource {
52
+ on(event: 'frame', callback: (frame: {
53
+ blendshapes: Float32Array;
54
+ }) => void): void;
55
+ off?(event: 'frame', callback: (...args: any[]) => void): void;
56
+ }
57
+ interface OmoteAvatarOptions {
58
+ /** Root mesh of the avatar (typically loaded via SceneLoader) */
59
+ target: AbstractMesh;
60
+ /** Babylon.js scene */
61
+ scene: Scene;
62
+ /** FaceCompositor configuration */
63
+ compositor?: FaceCompositorConfig;
64
+ /** Gaze tracking configuration */
65
+ gaze?: CharacterControllerConfig['gaze'];
66
+ /**
67
+ * Register scene.registerBeforeRender() for automatic update.
68
+ * Requires setCamera() to be called before the first frame.
69
+ * Default: false
70
+ */
71
+ autoUpdate?: boolean;
72
+ }
73
+ declare class OmoteAvatar {
74
+ private readonly controller;
75
+ private readonly discovery;
76
+ private readonly scene;
77
+ private currentBlendshapes;
78
+ private _emotion;
79
+ private _isSpeaking;
80
+ private _state;
81
+ private _audioEnergy;
82
+ private _camera;
83
+ private frameSourceCallback;
84
+ private connectedSource;
85
+ private renderCallback;
86
+ private lastTime;
87
+ constructor(options: OmoteAvatarOptions);
88
+ /**
89
+ * Call each frame with delta time and camera.
90
+ *
91
+ * Runs CharacterController (compositor, gaze, procedural life) then writes
92
+ * blendshapes to morph targets and applies head rotation.
93
+ *
94
+ * If using autoUpdate, this is called automatically via scene.registerBeforeRender().
95
+ *
96
+ * @param delta - Time since last frame in seconds
97
+ * @param camera - Active Babylon.js camera (for gaze tracking)
98
+ * @param avatarRotationY - Optional avatar Y rotation in radians for gaze compensation
99
+ */
100
+ update(delta: number, camera: Camera, avatarRotationY?: number): void;
101
+ /**
102
+ * Connect a frame source (PlaybackPipeline, MicLipSync, etc.).
103
+ *
104
+ * Automatically listens for 'frame' events and stores the latest blendshapes.
105
+ * Only one source can be connected at a time; calling again disconnects the previous.
106
+ */
107
+ connectFrameSource(source: FrameSource): void;
108
+ /** Disconnect the current frame source (if any). */
109
+ disconnectFrameSource(): void;
110
+ /** Set blendshapes directly (alternative to connectFrameSource). */
111
+ setFrame(blendshapes: Float32Array): void;
112
+ /** Set emotion (string preset like 'happy' or EmotionWeights object). */
113
+ setEmotion(emotion: string | EmotionWeights): void;
114
+ /** Set whether the avatar is currently speaking (drives mouth emphasis). */
115
+ setSpeaking(speaking: boolean): void;
116
+ /** Set conversational state (idle, listening, thinking, speaking). */
117
+ setState(state: ConversationalState): void;
118
+ /** Set audio energy level (0-1, drives emphasis/gesture intensity). */
119
+ setAudioEnergy(energy: number): void;
120
+ /**
121
+ * Set the active camera for gaze tracking.
122
+ * Required when using autoUpdate. Can also be passed directly to update().
123
+ */
124
+ setCamera(camera: Camera): void;
125
+ /** Access underlying FaceCompositor for advanced use. */
126
+ get compositor(): _omote_core.FaceCompositor;
127
+ /** Access SceneDiscoveryResult (meshes, bones, morph entries). */
128
+ get parts(): SceneDiscoveryResult;
129
+ /** Whether the scene has any mapped morph targets. */
130
+ get hasMorphTargets(): boolean;
131
+ /** Number of successfully mapped ARKit blendshapes. */
132
+ get mappedBlendshapeCount(): number;
133
+ /** Reset all state (smoothing, life layer, emotions). */
134
+ reset(): void;
135
+ /** Clean up all resources: disconnect frame source, unregister render loop, dispose controller. */
136
+ dispose(): void;
137
+ private registerAutoUpdate;
138
+ }
139
+
140
+ /**
141
+ * BlendshapeWriter — Zero-lookup hot-path blendshape application.
142
+ *
143
+ * Uses pre-computed Int16Array indices from SceneDiscovery for O(1) lookups
144
+ * per blendshape per mesh. No Map.get(), no string comparison on the hot path.
145
+ *
146
+ * @category Babylon
147
+ */
148
+
149
+ /**
150
+ * Write 52 ARKit blendshapes to Babylon.js morph targets.
151
+ *
152
+ * Uses pre-computed indices for zero-lookup hot path.
153
+ * Call this every frame after CharacterController.update().
154
+ *
155
+ * @param blendshapes - 52-element Float32Array in LAM_BLENDSHAPES order
156
+ * @param morphEntries - Pre-computed index mappings from discoverScene()
157
+ */
158
+ declare function writeBlendshapes(blendshapes: Float32Array, morphEntries: MorphIndexEntry[]): void;
159
+
160
+ interface BlendshapeControllerOptions {
161
+ /** Blendshape names in order (default: LAM_BLENDSHAPES, 52 ARKit) */
162
+ names?: readonly string[];
163
+ /** Smoothing factor 0-1 (0 = no change, 1 = snap to target). Default: 0.7 */
164
+ smoothing?: number;
165
+ /** Traverse target for child meshes with MorphTargetManager automatically. Default: true */
166
+ autoFind?: boolean;
167
+ /** Register scene.registerBeforeRender() callback automatically. Default: false */
168
+ autoRegister?: boolean;
169
+ /** Called when meshes with morph targets are found */
170
+ onMeshesFound?: (meshes: AbstractMesh[]) => void;
171
+ }
172
+ declare class BlendshapeController {
173
+ private _meshes;
174
+ private nameToIndex;
175
+ private currentWeights;
176
+ private blendshapeNames;
177
+ private smoothing;
178
+ private scene;
179
+ private renderObserver;
180
+ private pendingWeights;
181
+ private onMeshesFound?;
182
+ constructor(target: AbstractMesh, scene: Scene, options?: BlendshapeControllerOptions);
183
+ get meshes(): AbstractMesh[];
184
+ /** Normalize Babylon morph target names (strip common prefixes) */
185
+ private normalizeName;
186
+ setTarget(target: AbstractMesh): void;
187
+ update(weights: Float32Array | number[]): void;
188
+ /** Buffer weights for the next render loop tick (used with autoRegister) */
189
+ setWeightsForNextFrame(weights: Float32Array | number[]): void;
190
+ private registerRenderLoop;
191
+ dispose(): void;
192
+ }
193
+
194
+ interface OmoteA2EOptions extends A2EOrchestratorConfig {
195
+ target: AbstractMesh;
196
+ scene: Scene;
197
+ controllerOptions?: BlendshapeControllerOptions;
198
+ }
199
+ /** @deprecated Use {@link OmoteAvatar} instead. OmoteA2E will be removed in v0.8.0. */
200
+ declare class OmoteA2E {
201
+ private orchestrator;
202
+ private controller;
203
+ constructor(options: OmoteA2EOptions);
204
+ load(): Promise<void>;
205
+ start(): Promise<void>;
206
+ stop(): void;
207
+ update(): void;
208
+ dispose(): Promise<void>;
209
+ get isReady(): boolean;
210
+ get isStreaming(): boolean;
211
+ get backend(): string | null;
212
+ }
213
+
214
+ export { BlendshapeController, type BlendshapeControllerOptions, type FrameSource, type MorphIndexEntry, OmoteA2E, type OmoteA2EOptions, OmoteAvatar, type OmoteAvatarOptions, type SceneDiscoveryResult, discoverScene, writeBlendshapes };
@@ -0,0 +1,214 @@
1
+ import * as _omote_core from '@omote/core';
2
+ import { FaceCompositorConfig, CharacterControllerConfig, EmotionWeights, ConversationalState, A2EOrchestratorConfig } from '@omote/core';
3
+ import { AbstractMesh, TransformNode, Scene, Camera } from '@babylonjs/core';
4
+
5
+ /**
6
+ * SceneDiscovery — Discover avatar structure from a Babylon.js scene graph.
7
+ *
8
+ * Finds morph targets, head/neck/eye bones, and pre-computes a fast index
9
+ * mapping from LAM_BLENDSHAPES order to per-mesh morph target indices.
10
+ *
11
+ * @category Babylon
12
+ */
13
+
14
+ interface MorphIndexEntry {
15
+ mesh: AbstractMesh;
16
+ /** indices[lamIndex] = morphTargetIndex (or -1 if not found) */
17
+ indices: Int16Array;
18
+ }
19
+ interface SceneDiscoveryResult {
20
+ /** All meshes under the root that have a MorphTargetManager */
21
+ meshes: AbstractMesh[];
22
+ /** Head bone (TransformNode named 'Head') or null */
23
+ headBone: TransformNode | null;
24
+ /** Neck bone (TransformNode named 'Neck') or null */
25
+ neckBone: TransformNode | null;
26
+ /** Left eye bone (TransformNode named 'LeftEye') or null */
27
+ leftEyeBone: TransformNode | null;
28
+ /** Right eye bone (TransformNode named 'RightEye') or null */
29
+ rightEyeBone: TransformNode | null;
30
+ /** Pre-computed morph index mapping per mesh */
31
+ morphEntries: MorphIndexEntry[];
32
+ /** Primary face mesh (prefers 'Head_Mesh', falls back to first with morph targets) */
33
+ faceMesh: AbstractMesh | null;
34
+ /** Total number of ARKit blendshapes successfully mapped across all meshes */
35
+ mappedBlendshapeCount: number;
36
+ }
37
+ /**
38
+ * Discover avatar structure from a Babylon.js root node.
39
+ *
40
+ * Traverses the scene graph under `root` to find:
41
+ * - Meshes with MorphTargetManagers
42
+ * - Head, neck, and eye bones
43
+ * - Pre-computed LAM_BLENDSHAPES -> morph target index mapping
44
+ *
45
+ * @param root - The root AbstractMesh (typically loaded via SceneLoader)
46
+ * @returns SceneDiscoveryResult with all discovered components
47
+ */
48
+ declare function discoverScene(root: AbstractMesh): SceneDiscoveryResult;
49
+
50
+ /** Generic frame source -- any object that emits 'frame' events */
51
+ interface FrameSource {
52
+ on(event: 'frame', callback: (frame: {
53
+ blendshapes: Float32Array;
54
+ }) => void): void;
55
+ off?(event: 'frame', callback: (...args: any[]) => void): void;
56
+ }
57
+ interface OmoteAvatarOptions {
58
+ /** Root mesh of the avatar (typically loaded via SceneLoader) */
59
+ target: AbstractMesh;
60
+ /** Babylon.js scene */
61
+ scene: Scene;
62
+ /** FaceCompositor configuration */
63
+ compositor?: FaceCompositorConfig;
64
+ /** Gaze tracking configuration */
65
+ gaze?: CharacterControllerConfig['gaze'];
66
+ /**
67
+ * Register scene.registerBeforeRender() for automatic update.
68
+ * Requires setCamera() to be called before the first frame.
69
+ * Default: false
70
+ */
71
+ autoUpdate?: boolean;
72
+ }
73
+ declare class OmoteAvatar {
74
+ private readonly controller;
75
+ private readonly discovery;
76
+ private readonly scene;
77
+ private currentBlendshapes;
78
+ private _emotion;
79
+ private _isSpeaking;
80
+ private _state;
81
+ private _audioEnergy;
82
+ private _camera;
83
+ private frameSourceCallback;
84
+ private connectedSource;
85
+ private renderCallback;
86
+ private lastTime;
87
+ constructor(options: OmoteAvatarOptions);
88
+ /**
89
+ * Call each frame with delta time and camera.
90
+ *
91
+ * Runs CharacterController (compositor, gaze, procedural life) then writes
92
+ * blendshapes to morph targets and applies head rotation.
93
+ *
94
+ * If using autoUpdate, this is called automatically via scene.registerBeforeRender().
95
+ *
96
+ * @param delta - Time since last frame in seconds
97
+ * @param camera - Active Babylon.js camera (for gaze tracking)
98
+ * @param avatarRotationY - Optional avatar Y rotation in radians for gaze compensation
99
+ */
100
+ update(delta: number, camera: Camera, avatarRotationY?: number): void;
101
+ /**
102
+ * Connect a frame source (PlaybackPipeline, MicLipSync, etc.).
103
+ *
104
+ * Automatically listens for 'frame' events and stores the latest blendshapes.
105
+ * Only one source can be connected at a time; calling again disconnects the previous.
106
+ */
107
+ connectFrameSource(source: FrameSource): void;
108
+ /** Disconnect the current frame source (if any). */
109
+ disconnectFrameSource(): void;
110
+ /** Set blendshapes directly (alternative to connectFrameSource). */
111
+ setFrame(blendshapes: Float32Array): void;
112
+ /** Set emotion (string preset like 'happy' or EmotionWeights object). */
113
+ setEmotion(emotion: string | EmotionWeights): void;
114
+ /** Set whether the avatar is currently speaking (drives mouth emphasis). */
115
+ setSpeaking(speaking: boolean): void;
116
+ /** Set conversational state (idle, listening, thinking, speaking). */
117
+ setState(state: ConversationalState): void;
118
+ /** Set audio energy level (0-1, drives emphasis/gesture intensity). */
119
+ setAudioEnergy(energy: number): void;
120
+ /**
121
+ * Set the active camera for gaze tracking.
122
+ * Required when using autoUpdate. Can also be passed directly to update().
123
+ */
124
+ setCamera(camera: Camera): void;
125
+ /** Access underlying FaceCompositor for advanced use. */
126
+ get compositor(): _omote_core.FaceCompositor;
127
+ /** Access SceneDiscoveryResult (meshes, bones, morph entries). */
128
+ get parts(): SceneDiscoveryResult;
129
+ /** Whether the scene has any mapped morph targets. */
130
+ get hasMorphTargets(): boolean;
131
+ /** Number of successfully mapped ARKit blendshapes. */
132
+ get mappedBlendshapeCount(): number;
133
+ /** Reset all state (smoothing, life layer, emotions). */
134
+ reset(): void;
135
+ /** Clean up all resources: disconnect frame source, unregister render loop, dispose controller. */
136
+ dispose(): void;
137
+ private registerAutoUpdate;
138
+ }
139
+
140
+ /**
141
+ * BlendshapeWriter — Zero-lookup hot-path blendshape application.
142
+ *
143
+ * Uses pre-computed Int16Array indices from SceneDiscovery for O(1) lookups
144
+ * per blendshape per mesh. No Map.get(), no string comparison on the hot path.
145
+ *
146
+ * @category Babylon
147
+ */
148
+
149
+ /**
150
+ * Write 52 ARKit blendshapes to Babylon.js morph targets.
151
+ *
152
+ * Uses pre-computed indices for zero-lookup hot path.
153
+ * Call this every frame after CharacterController.update().
154
+ *
155
+ * @param blendshapes - 52-element Float32Array in LAM_BLENDSHAPES order
156
+ * @param morphEntries - Pre-computed index mappings from discoverScene()
157
+ */
158
+ declare function writeBlendshapes(blendshapes: Float32Array, morphEntries: MorphIndexEntry[]): void;
159
+
160
+ interface BlendshapeControllerOptions {
161
+ /** Blendshape names in order (default: LAM_BLENDSHAPES, 52 ARKit) */
162
+ names?: readonly string[];
163
+ /** Smoothing factor 0-1 (0 = no change, 1 = snap to target). Default: 0.7 */
164
+ smoothing?: number;
165
+ /** Traverse target for child meshes with MorphTargetManager automatically. Default: true */
166
+ autoFind?: boolean;
167
+ /** Register scene.registerBeforeRender() callback automatically. Default: false */
168
+ autoRegister?: boolean;
169
+ /** Called when meshes with morph targets are found */
170
+ onMeshesFound?: (meshes: AbstractMesh[]) => void;
171
+ }
172
+ declare class BlendshapeController {
173
+ private _meshes;
174
+ private nameToIndex;
175
+ private currentWeights;
176
+ private blendshapeNames;
177
+ private smoothing;
178
+ private scene;
179
+ private renderObserver;
180
+ private pendingWeights;
181
+ private onMeshesFound?;
182
+ constructor(target: AbstractMesh, scene: Scene, options?: BlendshapeControllerOptions);
183
+ get meshes(): AbstractMesh[];
184
+ /** Normalize Babylon morph target names (strip common prefixes) */
185
+ private normalizeName;
186
+ setTarget(target: AbstractMesh): void;
187
+ update(weights: Float32Array | number[]): void;
188
+ /** Buffer weights for the next render loop tick (used with autoRegister) */
189
+ setWeightsForNextFrame(weights: Float32Array | number[]): void;
190
+ private registerRenderLoop;
191
+ dispose(): void;
192
+ }
193
+
194
+ interface OmoteA2EOptions extends A2EOrchestratorConfig {
195
+ target: AbstractMesh;
196
+ scene: Scene;
197
+ controllerOptions?: BlendshapeControllerOptions;
198
+ }
199
+ /** @deprecated Use {@link OmoteAvatar} instead. OmoteA2E will be removed in v0.8.0. */
200
+ declare class OmoteA2E {
201
+ private orchestrator;
202
+ private controller;
203
+ constructor(options: OmoteA2EOptions);
204
+ load(): Promise<void>;
205
+ start(): Promise<void>;
206
+ stop(): void;
207
+ update(): void;
208
+ dispose(): Promise<void>;
209
+ get isReady(): boolean;
210
+ get isStreaming(): boolean;
211
+ get backend(): string | null;
212
+ }
213
+
214
+ export { BlendshapeController, type BlendshapeControllerOptions, type FrameSource, type MorphIndexEntry, OmoteA2E, type OmoteA2EOptions, OmoteAvatar, type OmoteAvatarOptions, type SceneDiscoveryResult, discoverScene, writeBlendshapes };