@spatialwalk/avatarkit 1.0.0-beta.1 → 1.0.0-beta.100
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/CHANGELOG.md +938 -0
- package/README.md +821 -208
- package/dist/StreamingAudioPlayer-CY6WeP2p.js +643 -0
- package/dist/avatar_core_wasm-6656456a.wasm +0 -0
- package/dist/avatar_core_wasm-Dci9E9jF.js +2696 -0
- package/dist/core/Avatar.d.ts +4 -14
- package/dist/core/AvatarController.d.ts +108 -93
- package/dist/core/AvatarManager.d.ts +32 -12
- package/dist/core/AvatarSDK.d.ts +58 -0
- package/dist/core/AvatarView.d.ts +132 -123
- package/dist/index-DADGbRoo.js +18392 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +17 -17
- package/dist/next.d.ts +2 -0
- package/dist/performance/FrameRateMonitor.d.ts +85 -0
- package/dist/types/character-settings.d.ts +7 -1
- package/dist/types/character.d.ts +42 -16
- package/dist/types/index.d.ts +170 -32
- package/dist/vite.d.ts +19 -0
- package/next.d.ts +3 -0
- package/next.js +187 -0
- package/package.json +42 -15
- package/vite.d.ts +20 -0
- package/vite.js +126 -0
- package/dist/StreamingAudioPlayer-C2TfYsO8.js +0 -293
- package/dist/StreamingAudioPlayer-C2TfYsO8.js.map +0 -1
- package/dist/animation/AnimationWebSocketClient.d.ts +0 -50
- package/dist/animation/AnimationWebSocketClient.d.ts.map +0 -1
- package/dist/animation/utils/eventEmitter.d.ts +0 -13
- package/dist/animation/utils/eventEmitter.d.ts.map +0 -1
- package/dist/animation/utils/flameConverter.d.ts +0 -26
- package/dist/animation/utils/flameConverter.d.ts.map +0 -1
- package/dist/audio/AnimationPlayer.d.ts +0 -53
- package/dist/audio/AnimationPlayer.d.ts.map +0 -1
- package/dist/audio/StreamingAudioPlayer.d.ts +0 -113
- package/dist/audio/StreamingAudioPlayer.d.ts.map +0 -1
- package/dist/avatar_core_wasm-DmkU6dYn.js +0 -1666
- package/dist/avatar_core_wasm-DmkU6dYn.js.map +0 -1
- package/dist/avatar_core_wasm.wasm +0 -0
- package/dist/config/app-config.d.ts +0 -48
- package/dist/config/app-config.d.ts.map +0 -1
- package/dist/config/constants.d.ts +0 -13
- package/dist/config/constants.d.ts.map +0 -1
- package/dist/config/region-config.d.ts +0 -17
- package/dist/config/region-config.d.ts.map +0 -1
- package/dist/config/sdk-config-loader.d.ts +0 -12
- package/dist/config/sdk-config-loader.d.ts.map +0 -1
- package/dist/core/Avatar.d.ts.map +0 -1
- package/dist/core/AvatarController.d.ts.map +0 -1
- package/dist/core/AvatarDownloader.d.ts +0 -100
- package/dist/core/AvatarDownloader.d.ts.map +0 -1
- package/dist/core/AvatarKit.d.ts +0 -60
- package/dist/core/AvatarKit.d.ts.map +0 -1
- package/dist/core/AvatarManager.d.ts.map +0 -1
- package/dist/core/AvatarView.d.ts.map +0 -1
- package/dist/generated/driveningress/v1/driveningress.d.ts +0 -80
- package/dist/generated/driveningress/v1/driveningress.d.ts.map +0 -1
- package/dist/generated/driveningress/v2/driveningress.d.ts +0 -81
- package/dist/generated/driveningress/v2/driveningress.d.ts.map +0 -1
- package/dist/generated/google/protobuf/any.d.ts +0 -145
- package/dist/generated/google/protobuf/any.d.ts.map +0 -1
- package/dist/generated/google/protobuf/struct.d.ts +0 -108
- package/dist/generated/google/protobuf/struct.d.ts.map +0 -1
- package/dist/generated/google/protobuf/timestamp.d.ts +0 -129
- package/dist/generated/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/generated/jsonapi/v1/base.d.ts +0 -140
- package/dist/generated/jsonapi/v1/base.d.ts.map +0 -1
- package/dist/generated/platform/v1/asset_groups.d.ts +0 -225
- package/dist/generated/platform/v1/asset_groups.d.ts.map +0 -1
- package/dist/generated/platform/v1/assets.d.ts +0 -149
- package/dist/generated/platform/v1/assets.d.ts.map +0 -1
- package/dist/generated/platform/v1/character.d.ts +0 -395
- package/dist/generated/platform/v1/character.d.ts.map +0 -1
- package/dist/generated/platform/v1/redeem.d.ts +0 -22
- package/dist/generated/platform/v1/redeem.d.ts.map +0 -1
- package/dist/index-DwhR9l52.js +0 -9712
- package/dist/index-DwhR9l52.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/renderer/RenderSystem.d.ts +0 -77
- package/dist/renderer/RenderSystem.d.ts.map +0 -1
- package/dist/renderer/covariance.d.ts +0 -13
- package/dist/renderer/covariance.d.ts.map +0 -1
- package/dist/renderer/renderer.d.ts +0 -8
- package/dist/renderer/renderer.d.ts.map +0 -1
- package/dist/renderer/sortSplats.d.ts +0 -12
- package/dist/renderer/sortSplats.d.ts.map +0 -1
- package/dist/renderer/webgl/reorderData.d.ts +0 -14
- package/dist/renderer/webgl/reorderData.d.ts.map +0 -1
- package/dist/renderer/webgl/webglRenderer.d.ts +0 -66
- package/dist/renderer/webgl/webglRenderer.d.ts.map +0 -1
- package/dist/renderer/webgpu/webgpuRenderer.d.ts +0 -54
- package/dist/renderer/webgpu/webgpuRenderer.d.ts.map +0 -1
- package/dist/types/character-settings.d.ts.map +0 -1
- package/dist/types/character.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/animation-interpolation.d.ts +0 -17
- package/dist/utils/animation-interpolation.d.ts.map +0 -1
- package/dist/utils/error-utils.d.ts +0 -27
- package/dist/utils/error-utils.d.ts.map +0 -1
- package/dist/utils/logger.d.ts +0 -35
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/posthog-tracker.d.ts +0 -82
- package/dist/utils/posthog-tracker.d.ts.map +0 -1
- package/dist/utils/reqId.d.ts +0 -20
- package/dist/utils/reqId.d.ts.map +0 -1
- package/dist/utils/toast.d.ts +0 -74
- package/dist/utils/toast.d.ts.map +0 -1
- package/dist/wasm/avatarCoreAdapter.d.ts +0 -188
- package/dist/wasm/avatarCoreAdapter.d.ts.map +0 -1
- package/dist/wasm/avatarCoreMemory.d.ts +0 -141
- package/dist/wasm/avatarCoreMemory.d.ts.map +0 -1
package/dist/core/Avatar.d.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import { CharacterMeta } from '../types';
|
|
2
|
-
import { PreloadResult } from './AvatarDownloader';
|
|
3
2
|
export declare class Avatar {
|
|
4
3
|
readonly id: string;
|
|
5
4
|
private characterMeta;
|
|
6
5
|
private resources;
|
|
6
|
+
/** Local-only field: tracks whether cached model is "standard" or "compressed". */
|
|
7
|
+
_cachedModelType: string;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @param characterMeta 角色元数据
|
|
11
|
-
* @param resources 资源数据
|
|
12
|
-
*/
|
|
13
|
-
constructor(id: string, characterMeta: CharacterMeta, resources: PreloadResult);
|
|
14
|
-
/**
|
|
15
|
-
* 获取角色元数据(内部使用)
|
|
9
|
+
* Get character metadata
|
|
10
|
+
* @returns Character metadata, including all configuration information (version, resource URLs, camera config, etc.)
|
|
16
11
|
*/
|
|
17
12
|
getCharacterMeta(): CharacterMeta;
|
|
18
|
-
/**
|
|
19
|
-
* 获取资源数据(内部使用)
|
|
20
|
-
*/
|
|
21
|
-
getResources(): PreloadResult;
|
|
22
13
|
}
|
|
23
|
-
//# sourceMappingURL=Avatar.d.ts.map
|
|
@@ -1,125 +1,140 @@
|
|
|
1
|
-
import { Flame } from '../generated/driveningress/v1/driveningress';
|
|
2
1
|
import { Avatar } from './Avatar';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ConnectionState, AvatarError, DrivingServiceMode, ConversationState, PostProcessingConfig } from '../types';
|
|
3
|
+
import { FrameRateInfo } from '../performance/FrameRateMonitor';
|
|
5
4
|
export declare class AvatarController {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
protected currentKeyframes: Flame[];
|
|
12
|
-
protected transitionKeyframes: Flame[];
|
|
13
|
-
protected currentReqId: string | null;
|
|
14
|
-
protected isPlaying: boolean;
|
|
15
|
-
private hasSentEnd;
|
|
5
|
+
private networkLayer?;
|
|
6
|
+
private readonly playbackMode;
|
|
7
|
+
private isStartingPlayback;
|
|
8
|
+
private currentConversationId;
|
|
9
|
+
private reqEnd;
|
|
16
10
|
onConnectionState: ((state: ConnectionState) => void) | null;
|
|
17
|
-
|
|
18
|
-
onError: ((error:
|
|
11
|
+
onConversationState: ((state: ConversationState) => void) | null;
|
|
12
|
+
onError: ((error: AvatarError) => void) | null;
|
|
19
13
|
private eventListeners;
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
private readonly frameRateMonitor;
|
|
15
|
+
/** Frame rate monitoring callback. Fires with aggregated metrics from a 2-second sliding window. */
|
|
16
|
+
get onFrameRateInfo(): ((info: FrameRateInfo) => void) | null;
|
|
17
|
+
set onFrameRateInfo(value: ((info: FrameRateInfo) => void) | null);
|
|
18
|
+
/** Whether frame rate monitoring is enabled. Default is false (zero overhead when disabled). */
|
|
19
|
+
get frameRateMonitorEnabled(): boolean;
|
|
20
|
+
set frameRateMonitorEnabled(value: boolean);
|
|
21
|
+
private renderCallback?;
|
|
22
|
+
private characterHandle;
|
|
23
|
+
private characterId;
|
|
24
|
+
private postProcessingConfig;
|
|
25
|
+
private playbackLoopId;
|
|
26
|
+
private playbackLoopGeneration;
|
|
27
|
+
private lastRenderedFrameIndex;
|
|
28
|
+
private keyframesOffset;
|
|
29
|
+
private readonly MAX_KEYFRAMES;
|
|
30
|
+
private readonly KEYFRAMES_CLEANUP_THRESHOLD;
|
|
31
|
+
private lastSyncLogTime;
|
|
32
|
+
private lastOutOfBoundsState;
|
|
33
|
+
private isFallbackMode;
|
|
34
|
+
private frameStarvationEvents;
|
|
35
|
+
private isFrameStarved;
|
|
36
|
+
private playbackStuckCheckState;
|
|
37
|
+
private readonly MAX_AUDIO_TIME_ZERO_COUNT;
|
|
38
|
+
private readonly MAX_AUDIO_TIME_STUCK_COUNT;
|
|
39
|
+
private readonly AUDIO_TIME_STUCK_THRESHOLD;
|
|
40
|
+
private hostModeMetrics;
|
|
41
|
+
private readonly audioBytesPerSecond;
|
|
42
|
+
constructor(avatar: Avatar, options?: {
|
|
43
|
+
playbackMode?: DrivingServiceMode;
|
|
44
|
+
});
|
|
45
|
+
private handleVisibilityChange;
|
|
46
|
+
private shouldReportPlaybackStats;
|
|
47
|
+
private _getDeviceScoreProps;
|
|
48
|
+
/**
|
|
49
|
+
* Get current conversation ID
|
|
50
|
+
* Returns the current conversation ID for the active audio session
|
|
51
|
+
* @returns Current conversation ID, or null if no active session
|
|
52
|
+
*/
|
|
53
|
+
getCurrentConversationId(): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Initialize audio context (must be called in user gesture context)
|
|
56
|
+
*
|
|
57
|
+
* This method must be called before any audio operations (send, yieldAudioData, etc.)
|
|
58
|
+
* to ensure AudioContext is created and initialized in a user gesture context.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // In user click handler
|
|
62
|
+
* button.addEventListener('click', async () => {
|
|
63
|
+
* await avatarView.controller.initializeAudioContext()
|
|
64
|
+
* // Now you can safely use send() or yieldAudioData()
|
|
65
|
+
* })
|
|
66
|
+
*/
|
|
67
|
+
initializeAudioContext(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Start service (SDK mode only)
|
|
25
70
|
*/
|
|
26
71
|
start(): Promise<void>;
|
|
27
72
|
/**
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 发送文字消息(Animation Only 模式不支持文字输入)
|
|
73
|
+
* Send audio to server (SDK mode only)
|
|
74
|
+
* Also cache to data layer for playback
|
|
75
|
+
* @returns conversationId - Conversation ID for this audio session
|
|
33
76
|
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 打断当前对话
|
|
37
|
-
*/
|
|
38
|
-
interrupt(): void;
|
|
77
|
+
send(audioData: ArrayBuffer, end?: boolean): string | null;
|
|
39
78
|
/**
|
|
40
|
-
*
|
|
79
|
+
* Close service (SDK mode only)
|
|
41
80
|
*/
|
|
42
81
|
close(): void;
|
|
43
82
|
/**
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
set mute(value: boolean);
|
|
48
|
-
/**
|
|
49
|
-
* 获取当前状态
|
|
50
|
-
*/
|
|
51
|
-
get state(): AvatarState;
|
|
52
|
-
/**
|
|
53
|
-
* 获取动画播放器实例
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
getAnimationPlayer(): AnimationPlayer | null;
|
|
57
|
-
/**
|
|
58
|
-
* 提供给视图层读取的过渡关键帧(Idle->Speaking),独立于主序列
|
|
83
|
+
* Send audio data (host mode)
|
|
84
|
+
* Stream additional audio data after playback()
|
|
85
|
+
* @returns conversationId - Conversation ID for this audio session
|
|
59
86
|
*/
|
|
60
|
-
|
|
87
|
+
yieldAudioData(data: Uint8Array, isLast?: boolean): string | null;
|
|
61
88
|
/**
|
|
62
|
-
*
|
|
89
|
+
* Send animation keyframes (host mode or SDK mode)
|
|
90
|
+
* Stream additional animation data after playback()
|
|
91
|
+
*
|
|
92
|
+
* Public API: accepts binary data array (protobuf encoded Message array)
|
|
93
|
+
* @param keyframesDataArray - Animation keyframes binary data array (each element is a protobuf encoded Message) or empty array to trigger audio-only mode
|
|
94
|
+
* @param conversationId - Conversation ID (required). If conversationId doesn't match current conversationId, keyframes will be discarded.
|
|
95
|
+
* Use getCurrentConversationId() to get the current conversationId.
|
|
96
|
+
* @returns `true` if the server has sent all animation data for this conversation (end signal received), `false` otherwise.
|
|
63
97
|
*/
|
|
64
|
-
|
|
98
|
+
yieldFramesData(keyframesDataArray: (Uint8Array | ArrayBuffer)[], conversationId: string): boolean;
|
|
65
99
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
100
|
+
* Pause playback (can be resumed later)
|
|
101
|
+
* Pause audio playback and stop render loop, but preserve all state (keyframes, audio buffers, etc.)
|
|
68
102
|
*/
|
|
69
|
-
|
|
70
|
-
onKeyframesUpdate?: (keyframes: Flame[]) => void;
|
|
71
|
-
onStartRendering?: () => void;
|
|
72
|
-
onStopRendering?: () => void;
|
|
73
|
-
}): void;
|
|
103
|
+
pause(): void;
|
|
74
104
|
/**
|
|
75
|
-
*
|
|
105
|
+
* Resume playback (from paused state)
|
|
106
|
+
* Resume audio playback and restart render loop
|
|
107
|
+
* Animation will continue from paused frame (because animation time base comes from audio, will auto-sync)
|
|
76
108
|
*/
|
|
77
|
-
|
|
109
|
+
resume(): Promise<void>;
|
|
78
110
|
/**
|
|
79
|
-
*
|
|
111
|
+
* Interrupt current playback
|
|
80
112
|
*/
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 停止播放
|
|
84
|
-
*/
|
|
85
|
-
protected stopPlayback(): void;
|
|
86
|
-
/**
|
|
87
|
-
* 开始播放音频和动画
|
|
88
|
-
*/
|
|
89
|
-
protected startPlayback(): Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* 注册内部事件监听器(仅供内部使用)
|
|
92
|
-
*/
|
|
93
|
-
private registerEventListener;
|
|
94
|
-
/**
|
|
95
|
-
* 触发内部事件(仅供内部使用)
|
|
96
|
-
*/
|
|
97
|
-
private emit;
|
|
98
|
-
/**
|
|
99
|
-
* 处理接收到的消息
|
|
100
|
-
*/
|
|
101
|
-
private handleMessage;
|
|
113
|
+
interrupt(): void;
|
|
102
114
|
/**
|
|
103
|
-
*
|
|
115
|
+
* Clear all data and resources
|
|
104
116
|
*/
|
|
105
|
-
|
|
117
|
+
clear(): void;
|
|
106
118
|
/**
|
|
107
|
-
*
|
|
119
|
+
* Get point cloud count of the current avatar
|
|
120
|
+
* @returns Point cloud count, or null if avatar is not loaded
|
|
108
121
|
*/
|
|
109
|
-
|
|
122
|
+
getPointCount(): number | null;
|
|
110
123
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
124
|
+
* Set post-processing configuration
|
|
125
|
+
* These parameters will be applied in real-time to animation parameters returned by the server
|
|
126
|
+
* @param config Post-processing configuration, or null to clear
|
|
113
127
|
*/
|
|
114
|
-
|
|
128
|
+
setPostProcessingConfig(config: PostProcessingConfig | null): void;
|
|
115
129
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
130
|
+
* Set audio playback volume
|
|
131
|
+
* Note: This only controls the avatar audio player volume, not the system volume
|
|
132
|
+
* @param volume Volume value, range from 0.0 to 1.0 (0.0 = mute, 1.0 = max volume)
|
|
118
133
|
*/
|
|
119
|
-
|
|
134
|
+
setVolume(volume: number): void;
|
|
120
135
|
/**
|
|
121
|
-
*
|
|
136
|
+
* Get current audio playback volume
|
|
137
|
+
* @returns Current volume value (0.0 - 1.0)
|
|
122
138
|
*/
|
|
123
|
-
|
|
139
|
+
getVolume(): number;
|
|
124
140
|
}
|
|
125
|
-
//# sourceMappingURL=AvatarController.d.ts.map
|
|
@@ -3,24 +3,44 @@ import { Avatar } from './Avatar';
|
|
|
3
3
|
export declare class AvatarManager {
|
|
4
4
|
private static _instance;
|
|
5
5
|
private avatarDownloader;
|
|
6
|
-
private
|
|
6
|
+
private avatarCache;
|
|
7
|
+
/** 下载队列:FIFO 顺序 */
|
|
8
|
+
private downloadQueue;
|
|
9
|
+
/** 当前正在执行的任务 */
|
|
10
|
+
private currentTask;
|
|
11
|
+
/** 任务索引:快速查找 id 对应的任务 */
|
|
12
|
+
private taskIndex;
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
14
|
+
* Access via global singleton
|
|
9
15
|
*/
|
|
10
16
|
static get shared(): AvatarManager;
|
|
11
17
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param id
|
|
14
|
-
* @param onProgress
|
|
15
|
-
* @param
|
|
18
|
+
* Load avatar
|
|
19
|
+
* @param id Avatar ID
|
|
20
|
+
* @param onProgress Progress callback
|
|
21
|
+
* @param useCompressedModel Use compressed model resource (~30% of original size, with minor quality degradation). Defaults to false.
|
|
16
22
|
* @returns Promise<Avatar>
|
|
17
23
|
*/
|
|
18
|
-
load(id: string, onProgress?: (progress: LoadProgressInfo) => void,
|
|
19
|
-
enableMonologue?: boolean;
|
|
20
|
-
}): Promise<Avatar>;
|
|
24
|
+
load(id: string, onProgress?: (progress: LoadProgressInfo) => void, useCompressedModel?: boolean): Promise<Avatar>;
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
* Cancel a pending or running download task
|
|
27
|
+
* @param id Avatar ID to cancel
|
|
28
|
+
* @returns true if task was found and cancelled
|
|
23
29
|
*/
|
|
24
|
-
|
|
30
|
+
cancelLoad(id: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Get cached avatar
|
|
33
|
+
* @param id Avatar ID
|
|
34
|
+
* @returns Avatar instance, or undefined if not in cache
|
|
35
|
+
*/
|
|
36
|
+
retrieve(id: string): Avatar | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Clear cached avatar for specified ID
|
|
39
|
+
* @param id Avatar ID
|
|
40
|
+
*/
|
|
41
|
+
clear(id: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Clear all avatar cache and cancel all tasks
|
|
44
|
+
*/
|
|
45
|
+
clearAll(): void;
|
|
25
46
|
}
|
|
26
|
-
//# sourceMappingURL=AvatarManager.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Configuration } from '../types';
|
|
2
|
+
export declare class AvatarSDK {
|
|
3
|
+
private static _initializationState;
|
|
4
|
+
private static _initializingPromise;
|
|
5
|
+
private static _configuration;
|
|
6
|
+
private static readonly _version;
|
|
7
|
+
private static _avatarCore;
|
|
8
|
+
private static _dynamicSdkConfig;
|
|
9
|
+
private static _cachedDeviceScore;
|
|
10
|
+
private static _rendererBackend;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize SDK
|
|
13
|
+
* @param appId Application ID to be included in both HTTP Headers and WebSocket Headers
|
|
14
|
+
* @param configuration Configuration parameters
|
|
15
|
+
*/
|
|
16
|
+
static initialize(appId: string, configuration: Configuration): Promise<void>;
|
|
17
|
+
private static _initializeInternal;
|
|
18
|
+
/**
|
|
19
|
+
* Set sessionToken
|
|
20
|
+
* Developer Client -> Developer Server -> AvatarKit Server -> return sessionToken (max 1 hour validity)
|
|
21
|
+
* Include in WebSocket Headers for avatar WebSocket service authentication
|
|
22
|
+
*/
|
|
23
|
+
static setSessionToken(token: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Set userId
|
|
26
|
+
* Optional interface for developers, SDK includes this in telemetry logs
|
|
27
|
+
*/
|
|
28
|
+
static setUserId(userId: string): void;
|
|
29
|
+
static get isInitialized(): boolean;
|
|
30
|
+
static get appId(): string | null;
|
|
31
|
+
static get configuration(): Configuration | null;
|
|
32
|
+
static get sessionToken(): string | null;
|
|
33
|
+
static get userId(): string | null;
|
|
34
|
+
static get version(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Cleanup resources
|
|
37
|
+
*/
|
|
38
|
+
static cleanup(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Device performance score (CPU + GPU).
|
|
41
|
+
* CPU: matrix multiply throughput in Web Worker (warmup 1s + measure 1s).
|
|
42
|
+
* GPU: WebGPU compute shader throughput (warmup 1s + measure 1s).
|
|
43
|
+
* Returns 0 for GPU if WebGPU is not available.
|
|
44
|
+
*/
|
|
45
|
+
static deviceScore(): Promise<{
|
|
46
|
+
cpuScore: number;
|
|
47
|
+
gpuScore: number;
|
|
48
|
+
}>;
|
|
49
|
+
private static readonly CPU_SCORE_THRESHOLD;
|
|
50
|
+
private static readonly GPU_SCORE_THRESHOLD;
|
|
51
|
+
/**
|
|
52
|
+
* Check if the current device can run the avatar.
|
|
53
|
+
* Runs a ~2s benchmark, reports device info and scores to PostHog.
|
|
54
|
+
* Currently always returns true — thresholds will be calibrated from production data.
|
|
55
|
+
*/
|
|
56
|
+
static isDeviceSupported(): Promise<boolean>;
|
|
57
|
+
private static _getGPURenderer;
|
|
58
|
+
}
|
|
@@ -1,133 +1,52 @@
|
|
|
1
|
-
import { CameraConfig,
|
|
1
|
+
import { CameraConfig, KeyframeData } from '../types';
|
|
2
2
|
import { Avatar } from './Avatar';
|
|
3
3
|
import { AvatarController } from './AvatarController';
|
|
4
4
|
export declare class AvatarView {
|
|
5
|
-
readonly avatarController
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
private readonly avatarController;
|
|
6
|
+
private readonly avatar;
|
|
7
|
+
onFirstRendering?: () => void;
|
|
8
8
|
private canvas;
|
|
9
9
|
private renderSystem;
|
|
10
10
|
private isInitialized;
|
|
11
11
|
private cameraConfig;
|
|
12
|
-
private
|
|
12
|
+
private renderingState;
|
|
13
13
|
private currentKeyframes;
|
|
14
14
|
private lastRenderedFrameIndex;
|
|
15
|
-
private realtimeStartTime;
|
|
16
15
|
private lastRealtimeProtoFrame;
|
|
17
|
-
private idleResumeIndexPending;
|
|
18
16
|
private idleAnimationLoopId;
|
|
19
17
|
private realtimeAnimationLoopId;
|
|
20
18
|
private resizeObserver;
|
|
21
19
|
private onWindowResize;
|
|
20
|
+
private frameCount;
|
|
21
|
+
private lastFpsUpdate;
|
|
22
|
+
private currentFPS;
|
|
22
23
|
private transitionKeyframes;
|
|
23
|
-
private isTransitioning;
|
|
24
24
|
private transitionStartTime;
|
|
25
|
-
private readonly
|
|
26
|
-
private
|
|
25
|
+
private readonly startTransitionDurationMs;
|
|
26
|
+
private readonly endTransitionDurationMs;
|
|
27
27
|
private cachedIdleFirstFrame;
|
|
28
28
|
private idleCurrentFrameIndex;
|
|
29
|
+
private currentPlayingFrame;
|
|
30
|
+
private characterHandle;
|
|
31
|
+
private characterId;
|
|
32
|
+
private isPureRenderingMode;
|
|
33
|
+
private _renderingEnabled;
|
|
34
|
+
private avatarActiveTimer;
|
|
35
|
+
private readonly AVATAR_ACTIVE_INTERVAL;
|
|
29
36
|
/**
|
|
30
|
-
*
|
|
37
|
+
* Constructor
|
|
38
|
+
* Creates a unified AvatarController, internally composes network layer based on configuration
|
|
39
|
+
* @param avatar - Avatar instance
|
|
40
|
+
* @param container - Canvas container element (required)
|
|
31
41
|
*/
|
|
32
|
-
|
|
42
|
+
constructor(avatar: Avatar, container: HTMLElement);
|
|
33
43
|
/**
|
|
34
|
-
*
|
|
44
|
+
* Get controller (public interface)
|
|
35
45
|
*/
|
|
36
|
-
|
|
46
|
+
get controller(): AvatarController;
|
|
37
47
|
/**
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
private generateAndAlignTransitionFrames;
|
|
41
|
-
/**
|
|
42
|
-
* 获取缓存的 Idle 首帧,如果未缓存则获取并缓存
|
|
43
|
-
*/
|
|
44
|
-
private getCachedIdleFirstFrame;
|
|
45
|
-
/**
|
|
46
|
-
* 构造函数
|
|
47
|
-
* 使用 AvatarController(纯动画驱动模式)
|
|
48
|
-
*/
|
|
49
|
-
constructor(avatar: Avatar, canvasContainer?: HTMLElement);
|
|
50
|
-
/**
|
|
51
|
-
* 创建canvas元素
|
|
52
|
-
*/
|
|
53
|
-
private createCanvas;
|
|
54
|
-
/**
|
|
55
|
-
* 获取canvas元素(供外部访问)
|
|
56
|
-
*/
|
|
57
|
-
getCanvas(): HTMLCanvasElement;
|
|
58
|
-
/**
|
|
59
|
-
* 初始化视图系统
|
|
60
|
-
*/
|
|
61
|
-
private initializeView;
|
|
62
|
-
/**
|
|
63
|
-
* 初始化渲染系统
|
|
64
|
-
*/
|
|
65
|
-
private initializeRenderSystem;
|
|
66
|
-
/**
|
|
67
|
-
* 获取默认相机配置
|
|
68
|
-
*/
|
|
69
|
-
private getDefaultCameraConfig;
|
|
70
|
-
/**
|
|
71
|
-
* 根据 PreloadCameraSettings 转换为 CameraConfig
|
|
72
|
-
*/
|
|
73
|
-
private convertPreloadCameraToConfig;
|
|
74
|
-
/**
|
|
75
|
-
* 渲染第一帧
|
|
76
|
-
*/
|
|
77
|
-
private renderFirstFrame;
|
|
78
|
-
/**
|
|
79
|
-
* 开始idle动画循环
|
|
80
|
-
*/
|
|
81
|
-
private startIdleAnimationLoop;
|
|
82
|
-
/**
|
|
83
|
-
* 开始实时对话动画循环
|
|
84
|
-
*/
|
|
85
|
-
private startRealtimeAnimationLoop;
|
|
86
|
-
/**
|
|
87
|
-
* 停止idle动画循环
|
|
88
|
-
*/
|
|
89
|
-
private stopIdleAnimationLoop;
|
|
90
|
-
/**
|
|
91
|
-
* 停止实时对话动画循环
|
|
92
|
-
*/
|
|
93
|
-
private stopRealtimeAnimationLoop;
|
|
94
|
-
/**
|
|
95
|
-
* 停止所有动画循环
|
|
96
|
-
*/
|
|
97
|
-
private stopAllAnimationLoops;
|
|
98
|
-
/**
|
|
99
|
-
* 渲染实时对话帧
|
|
100
|
-
*/
|
|
101
|
-
private renderRealtimeFrame;
|
|
102
|
-
/**
|
|
103
|
-
* 设置 AvatarController 事件监听器
|
|
104
|
-
*/
|
|
105
|
-
private setupControllerEventListeners;
|
|
106
|
-
/**
|
|
107
|
-
* 设置当前关键帧数据
|
|
108
|
-
*/
|
|
109
|
-
private setCurrentKeyframes;
|
|
110
|
-
/**
|
|
111
|
-
* 开始实时对话渲染
|
|
112
|
-
*/
|
|
113
|
-
private startRealtimeRendering;
|
|
114
|
-
/**
|
|
115
|
-
* 停止实时对话渲染
|
|
116
|
-
*/
|
|
117
|
-
private stopRealtimeRendering;
|
|
118
|
-
/**
|
|
119
|
-
* 设置背景图
|
|
120
|
-
* 支持开发者来设置渲染数字人背景图
|
|
121
|
-
*/
|
|
122
|
-
setBackgroundImage(imageUrl: string | null): void;
|
|
123
|
-
/**
|
|
124
|
-
* 设置背景是否不透明
|
|
125
|
-
* 支持开发者来设置是否背景不透明
|
|
126
|
-
*/
|
|
127
|
-
setBackgroundOpaque(opaque: boolean): void;
|
|
128
|
-
/**
|
|
129
|
-
* 清理视图资源
|
|
130
|
-
* 关闭 avatarController 并清理所有相关资源
|
|
48
|
+
* Cleanup view resources
|
|
49
|
+
* Closes avatarController and cleans up all related resources
|
|
131
50
|
*/
|
|
132
51
|
dispose(): void;
|
|
133
52
|
/**
|
|
@@ -139,20 +58,110 @@ export declare class AvatarView {
|
|
|
139
58
|
*/
|
|
140
59
|
updateCameraConfig(cameraConfig: CameraConfig): void;
|
|
141
60
|
/**
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
61
|
+
* Render specified keyframe (pure rendering mode, no audio-animation synchronization)
|
|
62
|
+
* Suitable for scenarios where external application controls audio playback and animation playback
|
|
63
|
+
* @param keyframeData - Keyframe data
|
|
64
|
+
* @param enableIdleRendering - Whether to enable idle loop rendering. true: Enable idle rendering and return immediately (skip this keyframe); false: Disable idle rendering and process keyframe (default)
|
|
65
|
+
*/
|
|
66
|
+
renderFlame(keyframeData: KeyframeData, enableIdleRendering?: boolean): Promise<void>;
|
|
67
|
+
generateTransition(options: {
|
|
68
|
+
from?: KeyframeData;
|
|
69
|
+
to?: KeyframeData;
|
|
70
|
+
frameCount: number;
|
|
71
|
+
useLinear?: boolean;
|
|
72
|
+
}): Promise<KeyframeData[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Render a single animation frame from raw protobuf data.
|
|
75
|
+
*
|
|
76
|
+
* Decodes the protobuf Message internally and renders the first keyframe.
|
|
77
|
+
* This is the preferred method for RTC consumers that receive raw animation bytes.
|
|
78
|
+
*
|
|
79
|
+
* @param data - Raw protobuf bytes (a single Message containing ServerResponseAnimation)
|
|
80
|
+
*/
|
|
81
|
+
renderFromProtobuf(data: ArrayBuffer | Uint8Array): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Play a transition from idle to the target frame in the protobuf data,
|
|
84
|
+
* then resolve when the transition is complete.
|
|
85
|
+
*
|
|
86
|
+
* The transition frames are generated and played internally at 25fps.
|
|
87
|
+
* The caller should wait for the returned Promise before pushing streaming frames.
|
|
88
|
+
*
|
|
89
|
+
* @param data - Raw protobuf bytes containing the target frame
|
|
90
|
+
* @param frameCount - Number of transition frames to generate
|
|
91
|
+
* @returns Promise that resolves when the transition playback finishes
|
|
92
|
+
*/
|
|
93
|
+
playTransitionFromProtobuf(data: ArrayBuffer | Uint8Array, frameCount: number): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Play a transition from current animation back to idle,
|
|
96
|
+
* then start the idle animation loop.
|
|
97
|
+
*
|
|
98
|
+
* Generates reverse transition frames from idle→lastFrame, reverses them,
|
|
99
|
+
* plays at 25fps, then starts idle.
|
|
100
|
+
*
|
|
101
|
+
* @param data - Raw protobuf bytes containing the last animation frame
|
|
102
|
+
* @param frameCount - Number of transition frames to generate
|
|
103
|
+
* @returns Promise that resolves when idle animation starts
|
|
104
|
+
*/
|
|
105
|
+
playTransitionToIdleFromProtobuf(data: ArrayBuffer | Uint8Array, frameCount: number): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Start idle animation (stop pure rendering mode, resume idle loop).
|
|
108
|
+
*/
|
|
109
|
+
startIdle(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Cancel any in-progress frame sequence playback.
|
|
112
|
+
* Called by renderFromProtobuf when streaming frames arrive during transition.
|
|
113
|
+
*/
|
|
114
|
+
cancelFrameSequence(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Pause rendering loop
|
|
117
|
+
*
|
|
118
|
+
* When called:
|
|
119
|
+
* - Rendering loop stops (no GPU/canvas updates)
|
|
120
|
+
* - Audio playback continues normally
|
|
121
|
+
* - Animation state machine continues running
|
|
122
|
+
*
|
|
123
|
+
* Use `resumeRendering()` to resume rendering.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // Stop rendering to save GPU resources (audio continues)
|
|
127
|
+
* avatarView.pauseRendering()
|
|
128
|
+
*/
|
|
129
|
+
pauseRendering(): void;
|
|
130
|
+
/**
|
|
131
|
+
* Resume rendering loop
|
|
132
|
+
*
|
|
133
|
+
* When called:
|
|
134
|
+
* - Rendering loop resumes from current state
|
|
135
|
+
* - If in Idle state, immediately renders current frame to restore display
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* // Resume rendering
|
|
139
|
+
* avatarView.resumeRendering()
|
|
140
|
+
*/
|
|
141
|
+
resumeRendering(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Check if rendering is currently enabled
|
|
144
|
+
* @returns true if rendering is enabled, false if paused
|
|
145
|
+
*/
|
|
146
|
+
isRenderingEnabled(): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Get or set avatar transform in canvas
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* // Get current transform
|
|
152
|
+
* const current = avatarView.avatarTransform
|
|
153
|
+
*
|
|
154
|
+
* // Set transform
|
|
155
|
+
* avatarView.avatarTransform = { x: 0.5, y: 0, scale: 2.0 }
|
|
156
|
+
*/
|
|
157
|
+
get avatarTransform(): {
|
|
158
|
+
x: number;
|
|
159
|
+
y: number;
|
|
160
|
+
scale: number;
|
|
161
|
+
};
|
|
162
|
+
set avatarTransform(value: {
|
|
163
|
+
x: number;
|
|
164
|
+
y: number;
|
|
165
|
+
scale: number;
|
|
166
|
+
});
|
|
157
167
|
}
|
|
158
|
-
//# sourceMappingURL=AvatarView.d.ts.map
|