@spatialwalk/avatarkit 1.0.0-beta.10 → 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 +765 -4
- package/README.md +676 -365
- package/dist/StreamingAudioPlayer-CY6WeP2p.js +643 -0
- package/dist/{avatar_core_wasm.wasm → avatar_core_wasm-6656456a.wasm} +0 -0
- package/dist/avatar_core_wasm-Dci9E9jF.js +2696 -0
- package/dist/core/Avatar.d.ts +5 -7
- package/dist/core/AvatarController.d.ts +99 -60
- package/dist/core/AvatarManager.d.ts +32 -12
- package/dist/core/AvatarSDK.d.ts +58 -0
- package/dist/core/AvatarView.d.ts +136 -128
- package/dist/index-DADGbRoo.js +18392 -0
- package/dist/index.d.ts +2 -4
- 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 +165 -45
- package/dist/vite.d.ts +19 -0
- package/next.d.ts +3 -0
- package/next.js +187 -0
- package/package.json +38 -8
- package/vite.d.ts +20 -0
- package/vite.js +126 -0
- package/dist/StreamingAudioPlayer-Bq2-bQiT.js +0 -319
- package/dist/StreamingAudioPlayer-Bq2-bQiT.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 -57
- package/dist/audio/AnimationPlayer.d.ts.map +0 -1
- package/dist/audio/StreamingAudioPlayer.d.ts +0 -123
- package/dist/audio/StreamingAudioPlayer.d.ts.map +0 -1
- package/dist/avatar_core_wasm-D4eEi7Eh.js +0 -1666
- package/dist/avatar_core_wasm-D4eEi7Eh.js.map +0 -1
- package/dist/config/app-config.d.ts +0 -44
- package/dist/config/app-config.d.ts.map +0 -1
- package/dist/config/constants.d.ts +0 -29
- package/dist/config/constants.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 -95
- package/dist/core/AvatarDownloader.d.ts.map +0 -1
- package/dist/core/AvatarKit.d.ts +0 -48
- 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/core/NetworkLayer.d.ts +0 -59
- package/dist/core/NetworkLayer.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/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/index-bQnEVIkT.js +0 -5999
- package/dist/index-bQnEVIkT.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 -79
- 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/cls-tracker.d.ts +0 -17
- package/dist/utils/cls-tracker.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/reqId.d.ts +0 -20
- package/dist/utils/reqId.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,15 +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 资源数据
|
|
9
|
+
* Get character metadata
|
|
10
|
+
* @returns Character metadata, including all configuration information (version, resource URLs, camera config, etc.)
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
getCharacterMeta(): CharacterMeta;
|
|
14
13
|
}
|
|
15
|
-
//# sourceMappingURL=Avatar.d.ts.map
|
|
@@ -1,101 +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
5
|
private networkLayer?;
|
|
7
|
-
readonly playbackMode
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
protected pendingAudioChunks: Array<{
|
|
12
|
-
data: Uint8Array;
|
|
13
|
-
isLast: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
protected isPlaying: boolean;
|
|
16
|
-
protected isConnected: boolean;
|
|
17
|
-
protected currentState: AvatarState;
|
|
6
|
+
private readonly playbackMode;
|
|
7
|
+
private isStartingPlayback;
|
|
8
|
+
private currentConversationId;
|
|
9
|
+
private reqEnd;
|
|
18
10
|
onConnectionState: ((state: ConnectionState) => void) | null;
|
|
19
|
-
|
|
20
|
-
onError: ((error:
|
|
11
|
+
onConversationState: ((state: ConversationState) => void) | null;
|
|
12
|
+
onError: ((error: AvatarError) => void) | null;
|
|
21
13
|
private eventListeners;
|
|
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);
|
|
22
21
|
private renderCallback?;
|
|
23
|
-
private
|
|
22
|
+
private characterHandle;
|
|
23
|
+
private characterId;
|
|
24
|
+
private postProcessingConfig;
|
|
24
25
|
private playbackLoopId;
|
|
26
|
+
private playbackLoopGeneration;
|
|
25
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;
|
|
26
42
|
constructor(avatar: Avatar, options?: {
|
|
27
|
-
playbackMode?:
|
|
43
|
+
playbackMode?: DrivingServiceMode;
|
|
28
44
|
});
|
|
45
|
+
private handleVisibilityChange;
|
|
46
|
+
private shouldReportPlaybackStats;
|
|
47
|
+
private _getDeviceScoreProps;
|
|
29
48
|
/**
|
|
30
|
-
*
|
|
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
|
|
31
52
|
*/
|
|
32
|
-
|
|
53
|
+
getCurrentConversationId(): string | null;
|
|
33
54
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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
|
+
* })
|
|
36
66
|
*/
|
|
37
|
-
|
|
67
|
+
initializeAudioContext(): Promise<void>;
|
|
38
68
|
/**
|
|
39
|
-
*
|
|
69
|
+
* Start service (SDK mode only)
|
|
40
70
|
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 开始播放(外部数据模式)
|
|
44
|
-
* 必须先调用此方法,传入初始数据开始播放
|
|
45
|
-
*/
|
|
46
|
-
play(initialAudioChunks?: Array<{
|
|
47
|
-
data: Uint8Array;
|
|
48
|
-
isLast: boolean;
|
|
49
|
-
}>, initialKeyframes?: Flame[]): Promise<void>;
|
|
71
|
+
start(): Promise<void>;
|
|
50
72
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
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
|
|
53
76
|
*/
|
|
54
|
-
|
|
77
|
+
send(audioData: ArrayBuffer, end?: boolean): string | null;
|
|
55
78
|
/**
|
|
56
|
-
*
|
|
57
|
-
* 在 play() 之后流式添加剩余动画数据
|
|
79
|
+
* Close service (SDK mode only)
|
|
58
80
|
*/
|
|
59
|
-
|
|
81
|
+
close(): void;
|
|
60
82
|
/**
|
|
61
|
-
*
|
|
83
|
+
* Send audio data (host mode)
|
|
84
|
+
* Stream additional audio data after playback()
|
|
85
|
+
* @returns conversationId - Conversation ID for this audio session
|
|
62
86
|
*/
|
|
63
|
-
|
|
87
|
+
yieldAudioData(data: Uint8Array, isLast?: boolean): string | null;
|
|
64
88
|
/**
|
|
65
|
-
*
|
|
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.
|
|
66
97
|
*/
|
|
67
|
-
|
|
98
|
+
yieldFramesData(keyframesDataArray: (Uint8Array | ArrayBuffer)[], conversationId: string): boolean;
|
|
68
99
|
/**
|
|
69
|
-
*
|
|
100
|
+
* Pause playback (can be resumed later)
|
|
101
|
+
* Pause audio playback and stop render loop, but preserve all state (keyframes, audio buffers, etc.)
|
|
70
102
|
*/
|
|
71
|
-
|
|
103
|
+
pause(): void;
|
|
72
104
|
/**
|
|
73
|
-
*
|
|
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)
|
|
74
108
|
*/
|
|
75
|
-
|
|
109
|
+
resume(): Promise<void>;
|
|
76
110
|
/**
|
|
77
|
-
*
|
|
111
|
+
* Interrupt current playback
|
|
78
112
|
*/
|
|
79
|
-
|
|
113
|
+
interrupt(): void;
|
|
80
114
|
/**
|
|
81
|
-
*
|
|
115
|
+
* Clear all data and resources
|
|
82
116
|
*/
|
|
83
|
-
|
|
117
|
+
clear(): void;
|
|
84
118
|
/**
|
|
85
|
-
*
|
|
119
|
+
* Get point cloud count of the current avatar
|
|
120
|
+
* @returns Point cloud count, or null if avatar is not loaded
|
|
86
121
|
*/
|
|
87
|
-
|
|
122
|
+
getPointCount(): number | null;
|
|
88
123
|
/**
|
|
89
|
-
*
|
|
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
|
|
90
127
|
*/
|
|
91
|
-
|
|
128
|
+
setPostProcessingConfig(config: PostProcessingConfig | null): void;
|
|
92
129
|
/**
|
|
93
|
-
*
|
|
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)
|
|
94
133
|
*/
|
|
95
|
-
|
|
134
|
+
setVolume(volume: number): void;
|
|
96
135
|
/**
|
|
97
|
-
*
|
|
136
|
+
* Get current audio playback volume
|
|
137
|
+
* @returns Current volume value (0.0 - 1.0)
|
|
98
138
|
*/
|
|
99
|
-
|
|
139
|
+
getVolume(): number;
|
|
100
140
|
}
|
|
101
|
-
//# 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,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
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
5
|
private readonly avatarController;
|
|
6
|
-
readonly playbackMode: AvatarPlaybackMode;
|
|
7
6
|
private readonly avatar;
|
|
7
|
+
onFirstRendering?: () => void;
|
|
8
8
|
private canvas;
|
|
9
9
|
private renderSystem;
|
|
10
10
|
private isInitialized;
|
|
@@ -17,143 +17,151 @@ export declare class AvatarView {
|
|
|
17
17
|
private realtimeAnimationLoopId;
|
|
18
18
|
private resizeObserver;
|
|
19
19
|
private onWindowResize;
|
|
20
|
+
private frameCount;
|
|
21
|
+
private lastFpsUpdate;
|
|
22
|
+
private currentFPS;
|
|
20
23
|
private transitionKeyframes;
|
|
21
24
|
private transitionStartTime;
|
|
22
|
-
private readonly
|
|
25
|
+
private readonly startTransitionDurationMs;
|
|
26
|
+
private readonly endTransitionDurationMs;
|
|
23
27
|
private cachedIdleFirstFrame;
|
|
24
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;
|
|
25
36
|
/**
|
|
26
|
-
*
|
|
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)
|
|
27
41
|
*/
|
|
28
|
-
|
|
42
|
+
constructor(avatar: Avatar, container: HTMLElement);
|
|
29
43
|
/**
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
private isEmptyFlame;
|
|
33
|
-
/**
|
|
34
|
-
* 生成并对齐过渡帧,确保首尾帧与起止帧完全一致
|
|
35
|
-
*/
|
|
36
|
-
private generateAndAlignTransitionFrames;
|
|
37
|
-
/**
|
|
38
|
-
* 获取缓存的 Idle 首帧,如果未缓存则获取并缓存
|
|
39
|
-
*/
|
|
40
|
-
private getCachedIdleFirstFrame;
|
|
41
|
-
/**
|
|
42
|
-
* 构造函数
|
|
43
|
-
* 创建统一的 AvatarController,内部根据配置自动组合网络层
|
|
44
|
-
*/
|
|
45
|
-
constructor(avatar: Avatar, options?: AvatarViewOptions);
|
|
46
|
-
/**
|
|
47
|
-
* 获取控制器(公共接口)
|
|
44
|
+
* Get controller (public interface)
|
|
48
45
|
*/
|
|
49
46
|
get controller(): AvatarController;
|
|
50
47
|
/**
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
private createCanvas;
|
|
54
|
-
/**
|
|
55
|
-
* 初始化视图系统
|
|
56
|
-
*/
|
|
57
|
-
private initializeView;
|
|
58
|
-
/**
|
|
59
|
-
* 初始化渲染系统
|
|
60
|
-
*/
|
|
61
|
-
private initializeRenderSystem;
|
|
62
|
-
/**
|
|
63
|
-
* 获取默认相机配置
|
|
64
|
-
*/
|
|
65
|
-
private getDefaultCameraConfig;
|
|
66
|
-
/**
|
|
67
|
-
* 根据资源解析最终的相机配置,优先使用角色设置,其次 camera.json
|
|
68
|
-
*/
|
|
69
|
-
private resolveCameraConfig;
|
|
70
|
-
/**
|
|
71
|
-
* 从角色设置中推导相机配置
|
|
72
|
-
*/
|
|
73
|
-
private deriveCameraConfigFromSettings;
|
|
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
|
-
* 过渡完成回调(通知播放层启动音频)
|
|
104
|
-
*/
|
|
105
|
-
private onTransitionComplete;
|
|
106
|
-
/**
|
|
107
|
-
* 状态转换方法
|
|
108
|
-
* 统一管理状态转换,确保状态一致性
|
|
109
|
-
*/
|
|
110
|
-
private setState;
|
|
111
|
-
/**
|
|
112
|
-
* 检查是否在实时播放状态(Speaking 或过渡到 Speaking)
|
|
113
|
-
*/
|
|
114
|
-
private get isRealtimePlaying();
|
|
115
|
-
/**
|
|
116
|
-
* 检查是否在过渡中
|
|
117
|
-
*/
|
|
118
|
-
private get isTransitioning();
|
|
119
|
-
/**
|
|
120
|
-
* 检查过渡结束后是否回到 Idle
|
|
121
|
-
*/
|
|
122
|
-
private get endToIdleAfterTransition();
|
|
123
|
-
/**
|
|
124
|
-
* 处理打断
|
|
125
|
-
* 打断时应该生成过渡动画,而不是直接跳回 Idle
|
|
126
|
-
*/
|
|
127
|
-
private handleInterrupt;
|
|
128
|
-
/**
|
|
129
|
-
* 设置 AvatarController 事件监听器
|
|
130
|
-
*/
|
|
131
|
-
private setupControllerEventListeners;
|
|
132
|
-
/**
|
|
133
|
-
* 准备实时渲染(生成 Idle -> Speaking 过渡)
|
|
134
|
-
*/
|
|
135
|
-
private prepareRealtimeRendering;
|
|
136
|
-
/**
|
|
137
|
-
* 开始实时渲染循环
|
|
138
|
-
*/
|
|
139
|
-
private startRealtimeRendering;
|
|
140
|
-
/**
|
|
141
|
-
* 停止实时对话渲染
|
|
142
|
-
*/
|
|
143
|
-
private stopRealtimeRendering;
|
|
144
|
-
/**
|
|
145
|
-
* 清理视图资源
|
|
146
|
-
* 关闭 avatarController 并清理所有相关资源
|
|
48
|
+
* Cleanup view resources
|
|
49
|
+
* Closes avatarController and cleans up all related resources
|
|
147
50
|
*/
|
|
148
51
|
dispose(): void;
|
|
149
52
|
/**
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
*
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
53
|
+
* 获取相机配置
|
|
54
|
+
*/
|
|
55
|
+
getCameraConfig(): CameraConfig | null;
|
|
56
|
+
/**
|
|
57
|
+
* 更新相机配置
|
|
58
|
+
*/
|
|
59
|
+
updateCameraConfig(cameraConfig: CameraConfig): void;
|
|
60
|
+
/**
|
|
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
|
+
});
|
|
158
167
|
}
|
|
159
|
-
//# sourceMappingURL=AvatarView.d.ts.map
|