@spatius/avatarkit 0.5.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/CHANGELOG.md +22 -0
- package/README.md +976 -0
- package/dist/StreamingAudioPlayer-D-7zAYjb.js +639 -0
- package/dist/avatar_core_wasm-CQbUl6zN.js +2696 -0
- package/dist/avatar_core_wasm-bd762669.wasm +0 -0
- package/dist/core/Avatar.d.ts +13 -0
- package/dist/core/AvatarController.d.ts +140 -0
- package/dist/core/AvatarManager.d.ts +46 -0
- package/dist/core/AvatarSDK.d.ts +57 -0
- package/dist/core/AvatarView.d.ts +170 -0
- package/dist/index-DrRoews_.js +18246 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +19 -0
- package/dist/next.d.ts +2 -0
- package/dist/performance/FrameRateMonitor.d.ts +85 -0
- package/dist/types/character-settings.d.ts +29 -0
- package/dist/types/character.d.ts +65 -0
- package/dist/types/index.d.ts +176 -0
- package/dist/vite.d.ts +19 -0
- package/next.d.ts +3 -0
- package/next.js +187 -0
- package/package.json +89 -0
- package/vite.d.ts +20 -0
- package/vite.js +126 -0
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spatius/avatarkit",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"packageManager": "pnpm@10.18.2",
|
|
6
|
+
"description": "AvatarKit SDK - 3D Gaussian Splatting Avatar Rendering SDK",
|
|
7
|
+
"author": "AvatarKit Team",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"avatar",
|
|
11
|
+
"3d",
|
|
12
|
+
"gaussian-splatting",
|
|
13
|
+
"webgl",
|
|
14
|
+
"webgpu",
|
|
15
|
+
"wasm"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./vite": {
|
|
23
|
+
"types": "./vite.d.ts",
|
|
24
|
+
"import": "./vite.js"
|
|
25
|
+
},
|
|
26
|
+
"./next": {
|
|
27
|
+
"types": "./next.d.ts",
|
|
28
|
+
"import": "./next.js"
|
|
29
|
+
},
|
|
30
|
+
"./*": {
|
|
31
|
+
"types": "./dist/*.d.ts",
|
|
32
|
+
"import": "./dist/*.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"files": [
|
|
39
|
+
"README.md",
|
|
40
|
+
"CHANGELOG.md",
|
|
41
|
+
"dist",
|
|
42
|
+
"vite.js",
|
|
43
|
+
"vite.d.ts",
|
|
44
|
+
"next.js",
|
|
45
|
+
"next.d.ts"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "SDK_BUILD=true vite build --mode library && npm run build:vite-plugin && npm run build:next-plugin",
|
|
49
|
+
"build:vite-plugin": "tsc vite.ts --outDir . --module esnext --target es2020 --moduleResolution bundler --esModuleInterop --skipLibCheck --declaration --declarationMap",
|
|
50
|
+
"build:next-plugin": "tsc next.ts --outDir . --module esnext --target es2020 --moduleResolution bundler --esModuleInterop --skipLibCheck --declaration --declarationMap",
|
|
51
|
+
"dev": "vite build --mode library --watch",
|
|
52
|
+
"demo": "vite --config demo/vite.config.mjs",
|
|
53
|
+
"demo:benchmark": "vite --config benchmark-demo/vite.config.mjs",
|
|
54
|
+
"test:integration": "vite --config tests/integration-runner/vite.config.mjs",
|
|
55
|
+
"clean": "rm -rf dist",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"test": "cd tests && pnpm test",
|
|
58
|
+
"test:watch": "cd tests && pnpm run test:watch",
|
|
59
|
+
"test:e2e": "cd tests && pnpm run test:e2e",
|
|
60
|
+
"test:perf": "cd tests && pnpm run test:perf"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@webgpu/types": "*",
|
|
64
|
+
"next": ">=13.0.0",
|
|
65
|
+
"vite": "^5.0.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"vite": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"next": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"@bufbuild/protobuf": "^2.10.0",
|
|
77
|
+
"@guiiai/logg": "^1.2.4",
|
|
78
|
+
"nanoid": "^5.1.6",
|
|
79
|
+
"posthog-js": "^1.310.1"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@types/node": "^20.11.30",
|
|
83
|
+
"@webgpu/types": "^0.1.65",
|
|
84
|
+
"tsx": "^4.20.6",
|
|
85
|
+
"typescript": "^5.0.0",
|
|
86
|
+
"vite": "^5.0.0",
|
|
87
|
+
"vite-plugin-dts": "^4.5.4"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/vite.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Vite plugin for @spatius/avatarkit
|
|
4
|
+
* Automatically handles WASM file configuration for development and production builds
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { defineConfig } from 'vite'
|
|
9
|
+
* import { avatarkitVitePlugin } from '@spatius/avatarkit/vite'
|
|
10
|
+
*
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* plugins: [
|
|
13
|
+
* avatarkitVitePlugin()
|
|
14
|
+
* ]
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function avatarkitVitePlugin(): Plugin;
|
|
19
|
+
export default avatarkitVitePlugin;
|
|
20
|
+
//# sourceMappingURL=vite.d.ts.map
|
package/vite.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, writeFileSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin for @spatius/avatarkit
|
|
5
|
+
* Automatically handles WASM file configuration for development and production builds
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { defineConfig } from 'vite'
|
|
10
|
+
* import { avatarkitVitePlugin } from '@spatius/avatarkit/vite'
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* plugins: [
|
|
14
|
+
* avatarkitVitePlugin()
|
|
15
|
+
* ]
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function avatarkitVitePlugin() {
|
|
20
|
+
let rootDir;
|
|
21
|
+
return {
|
|
22
|
+
name: 'avatarkit-wasm',
|
|
23
|
+
// 保存项目根目录
|
|
24
|
+
configResolved(config) {
|
|
25
|
+
rootDir = config.root;
|
|
26
|
+
},
|
|
27
|
+
// 开发服务器 MIME 类型配置
|
|
28
|
+
configureServer(server) {
|
|
29
|
+
server.middlewares.use((req, res, next) => {
|
|
30
|
+
if (req.url?.endsWith('.wasm')) {
|
|
31
|
+
res.setHeader('Content-Type', 'application/wasm');
|
|
32
|
+
}
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
// 构建时自动复制 WASM 文件和生成 headers
|
|
37
|
+
closeBundle() {
|
|
38
|
+
if (!rootDir)
|
|
39
|
+
return;
|
|
40
|
+
const wasmSourceDir = join(rootDir, 'node_modules/@spatius/avatarkit/dist');
|
|
41
|
+
// 先查找并读取 JS glue 文件,提取它引用的 WASM 文件名
|
|
42
|
+
let wasmFileName = null;
|
|
43
|
+
if (existsSync(wasmSourceDir)) {
|
|
44
|
+
const files = readdirSync(wasmSourceDir);
|
|
45
|
+
const wasmJsFile = files.find((f) => f.startsWith('avatar_core_wasm') && f.endsWith('.js'));
|
|
46
|
+
if (wasmJsFile) {
|
|
47
|
+
const wasmJsSource = join(wasmSourceDir, wasmJsFile);
|
|
48
|
+
try {
|
|
49
|
+
const jsContent = readFileSync(wasmJsSource, 'utf-8');
|
|
50
|
+
// 从 JS 文件中提取 WASM 文件名
|
|
51
|
+
// 匹配 avatar_core_wasm-{hash}.wasm 或 avatar_core_wasm.wasm
|
|
52
|
+
// 使用更精确的正则,匹配带引号或不带引号的情况
|
|
53
|
+
const wasmMatch = jsContent.match(/["'`]?avatar_core_wasm[-\w]*\.wasm["'`]?/g);
|
|
54
|
+
if (wasmMatch && wasmMatch.length > 0) {
|
|
55
|
+
// 取第一个匹配,去掉引号
|
|
56
|
+
wasmFileName = wasmMatch[0].replace(/["'`]/g, '');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.warn('⚠️ [avatarkit] Could not read JS glue file:', error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// 如果从 JS 文件中找到了 WASM 文件名,使用它;否则回退到默认名称
|
|
65
|
+
const targetWasmName = wasmFileName || 'avatar_core_wasm.wasm';
|
|
66
|
+
const wasmSource = join(wasmSourceDir, targetWasmName);
|
|
67
|
+
const wasmDest = join(rootDir, `dist/assets/${targetWasmName}`);
|
|
68
|
+
const wasmJsDest = join(rootDir, 'dist/assets/avatar_core_wasm.js');
|
|
69
|
+
const headersDest = join(rootDir, 'dist/_headers');
|
|
70
|
+
// 复制 WASM 文件
|
|
71
|
+
if (existsSync(wasmSource)) {
|
|
72
|
+
copyFileSync(wasmSource, wasmDest);
|
|
73
|
+
console.log(`✅ [avatarkit] Copied WASM file to dist/assets/${targetWasmName}`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.warn(`⚠️ [avatarkit] WASM file not found: ${wasmSource}`);
|
|
77
|
+
if (wasmFileName) {
|
|
78
|
+
console.warn(` Expected file: ${targetWasmName} (extracted from JS glue file)`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// 复制 WASM JS glue 文件
|
|
82
|
+
if (existsSync(wasmSourceDir)) {
|
|
83
|
+
const files = readdirSync(wasmSourceDir);
|
|
84
|
+
const wasmJsFile = files.find((f) => f.startsWith('avatar_core_wasm') && f.endsWith('.js'));
|
|
85
|
+
if (wasmJsFile) {
|
|
86
|
+
const wasmJsSource = join(wasmSourceDir, wasmJsFile);
|
|
87
|
+
copyFileSync(wasmJsSource, wasmJsDest);
|
|
88
|
+
console.log(`✅ [avatarkit] Copied WASM JS file to dist/assets/avatar_core_wasm.js (from ${wasmJsFile})`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log('ℹ️ [avatarkit] WASM JS file not found (may be handled by Vite):', wasmSourceDir);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 生成 _headers 文件(用于 Cloudflare Pages 等平台)
|
|
95
|
+
const headersContent = '/*.wasm\n Content-Type: application/wasm\n';
|
|
96
|
+
writeFileSync(headersDest, headersContent);
|
|
97
|
+
console.log('✅ [avatarkit] Created _headers file for Cloudflare Pages');
|
|
98
|
+
},
|
|
99
|
+
// 自动配置 Vite 选项
|
|
100
|
+
config() {
|
|
101
|
+
return {
|
|
102
|
+
optimizeDeps: {
|
|
103
|
+
exclude: ['@spatius/avatarkit']
|
|
104
|
+
},
|
|
105
|
+
assetsInclude: ['**/*.wasm'],
|
|
106
|
+
build: {
|
|
107
|
+
assetsInlineLimit: 0, // 确保 WASM 文件不被内联
|
|
108
|
+
rollupOptions: {
|
|
109
|
+
output: {
|
|
110
|
+
assetFileNames: (assetInfo) => {
|
|
111
|
+
// WASM 文件使用固定名称
|
|
112
|
+
if (assetInfo.name?.endsWith('.wasm')) {
|
|
113
|
+
return 'assets/[name][extname]';
|
|
114
|
+
}
|
|
115
|
+
// 其他资源使用 hash
|
|
116
|
+
return 'assets/[name]-[hash][extname]';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// 默认导出
|
|
126
|
+
export default avatarkitVitePlugin;
|