@zeewain/3d-avatar-sdk 1.2.5 → 2.1.2
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 +249 -12
- package/dist/assets/Build/webgl.data.unityweb +0 -0
- package/dist/assets/Build/webgl.framework.js.unityweb +0 -0
- package/dist/assets/Build/webgl.wasm.unityweb +0 -0
- package/dist/examples/test-umd/index.html +2 -1
- package/dist/examples/test-vue2/package.json +1 -1
- package/dist/examples/test-vue2/src/App.vue +1 -0
- package/dist/examples/test-vue3/package.json +1 -1
- package/dist/examples/test-vue3/src/App.vue +1 -1
- package/dist/examples/test-vue3/src/components/GlobalConfig.vue +9 -6
- package/dist/examples/test-vue3/src/types.ts +1 -1
- package/dist/index.d.ts +63 -39
- package/dist/index.es5.js +180 -87
- package/dist/index.es5.umd.js +180 -87
- package/dist/index.esm.js +229 -90
- package/dist/index.umd.cjs +229 -89
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -32,10 +32,29 @@
|
|
|
32
32
|
|
|
33
33
|
## 📦 安装方式
|
|
34
34
|
|
|
35
|
-
> **WebGL
|
|
35
|
+
> **WebGL文件与资源包说明**:
|
|
36
|
+
>
|
|
37
|
+
> **1. WebGL构建文件(必需)**
|
|
36
38
|
> - 所有WebGL构建文件(webgl.loader.js、webgl.data.unityweb、webgl.framework.js.unityweb、webgl.wasm.unityweb)均来源于SDK包(@zeewain/3d-avatar-sdk)的`dist/assets/Build/`目录。
|
|
37
39
|
> - 使用SDK前,请先将这些文件从 `node_modules/@zeewain/3d-avatar-sdk/dist/assets/Build/` 目录拷贝到你项目的静态资源目录,如 `public` 目录或你的CDN服务器上。
|
|
38
40
|
> - 然后在SDK初始化时,通过config参数设置这些WebGL文件的路径。
|
|
41
|
+
>
|
|
42
|
+
> **2. 数字人资源包(必需)**
|
|
43
|
+
> - **资源包获取**:从紫为云开放平台下载与SDK版本对应的数字人资源包(`版本号前两位必须一致`)。
|
|
44
|
+
> - **资源包内容**:包含数字人所需的形象资源、动作资源等完整资源文件。
|
|
45
|
+
> - **资源部署**:将下载的资源包解压后,部署到您的服务器或CDN服务器上。
|
|
46
|
+
> - **路径配置**:通过`assetsUrl`参数配置资源包的访问地址。
|
|
47
|
+
> - **路径格式**:`assetsUrl`通常格式为:`https://your-domain.com/<SDK版本号前两位>`
|
|
48
|
+
> - 示例:SDK版本为 2.1.3,则 `assetsUrl` 应配置为:`https://cdn.zeewain3d.com/webgl/2.1`
|
|
49
|
+
>
|
|
50
|
+
> **3. 动作资源扩展(可选)**
|
|
51
|
+
> - 动作资源可单独从开放平台下载**(版本号前两位也必须跟SDK版本号一致)**,下载后解压到资源包所在目录即可。
|
|
52
|
+
> - 新增的动作将自动集成到现有资源体系中。
|
|
53
|
+
>
|
|
54
|
+
> **⚠️ 版本兼容性要求**
|
|
55
|
+
> - SDK版本与资源包版本的前两位版本号必须一致。
|
|
56
|
+
> - 例如:SDK 2.1.x 必须使用 2.1.x 的资源包,不能使用 2.0.x 或 2.2.x 的资源包。
|
|
57
|
+
> - SDK在初始化时会自动检查版本兼容性,若不兼容会抛出 `ResourceErrorCode.VERSION_INCOMPATIBLE` 错误并自动卸载。
|
|
39
58
|
|
|
40
59
|
### npm/yarn 安装(推荐)
|
|
41
60
|
|
|
@@ -94,6 +113,9 @@ const sdk = new ZEEAvatarSDK({
|
|
|
94
113
|
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
95
114
|
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
96
115
|
|
|
116
|
+
// 数字人资源包配置(必填)
|
|
117
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
118
|
+
|
|
97
119
|
// 基础配置
|
|
98
120
|
containerId: 'unity-container',
|
|
99
121
|
token: 'your-auth-token',
|
|
@@ -178,6 +200,7 @@ class AvatarApp {
|
|
|
178
200
|
dataUrl: './assets/Build/webgl.data.unityweb',
|
|
179
201
|
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
180
202
|
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
203
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
181
204
|
containerId: 'unity-container',
|
|
182
205
|
token: 'your-auth-token',
|
|
183
206
|
env: 'prod',
|
|
@@ -480,17 +503,23 @@ interface IAvatarSDKConfig {
|
|
|
480
503
|
frameworkUrl: string; // Unity框架文件URL
|
|
481
504
|
codeUrl: string; // Unity代码文件URL
|
|
482
505
|
|
|
506
|
+
// 数字人资源包配置(必填)
|
|
507
|
+
assetsUrl: string; // 数字人资源包地址(必填)
|
|
508
|
+
// 从开放平台下载资源包并部署后的访问地址
|
|
509
|
+
// 格式:https://your-domain.com/<SDK版本号前两位>
|
|
510
|
+
// 示例:https://cdn.zeewain3d.com/webgl/2.1
|
|
511
|
+
// 注意:版本号前两位必须与SDK版本一致
|
|
512
|
+
|
|
483
513
|
// 基础配置
|
|
484
514
|
containerId?: string; // 容器DOM元素ID,默认'unity-container'
|
|
485
515
|
token?: string; // 用户认证令牌
|
|
486
516
|
env?: 'dev' | 'test' | 'prod' | 'custom'; // 运行环境,默认'prod'
|
|
487
517
|
apiUrl?: string; // 自定义API地址(env='custom'时需要)
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
idleMotionList?:string[]; // 待机动作编码列表,随机播放(排重方式),可选
|
|
518
|
+
idleMotionList?: string[]; // 待机动作编码列表,随机播放(排重方式),可选
|
|
519
|
+
|
|
491
520
|
// 回调函数
|
|
492
521
|
onProgress?: (progress: number) => void; // 加载进度回调,可选
|
|
493
|
-
broadcastCallbacks?:IBroadcastCallbacks; // 播报回调函数,可选
|
|
522
|
+
broadcastCallbacks?: IBroadcastCallbacks; // 播报回调函数,可选
|
|
494
523
|
}
|
|
495
524
|
```
|
|
496
525
|
|
|
@@ -871,6 +900,121 @@ destroy(): void
|
|
|
871
900
|
|
|
872
901
|
销毁SDK实例,清理所有资源。**重要:页面卸载前务必调用此方法!**
|
|
873
902
|
|
|
903
|
+
## 🔄 版本兼容性管理
|
|
904
|
+
|
|
905
|
+
### 自动版本检查机制
|
|
906
|
+
|
|
907
|
+
SDK内置了严格的版本兼容性检查机制,确保SDK版本与资源包版本匹配,避免因版本不一致导致的运行异常。
|
|
908
|
+
|
|
909
|
+
#### 版本检查规则
|
|
910
|
+
|
|
911
|
+
- **检查时机**:在 `initializeAvatar()` 初始化数字人时自动进行
|
|
912
|
+
- **检查范围**:SDK版本号与资源包版本号的**前两位**必须一致
|
|
913
|
+
- **版本格式**:采用语义化版本号 `主版本号.次版本号.修订号`(如 2.1.3)
|
|
914
|
+
- **兼容规则**:
|
|
915
|
+
- ✅ SDK 2.1.3 + 资源包 2.1.0 → 兼容
|
|
916
|
+
- ✅ SDK 2.1.3 + 资源包 2.1.5 → 兼容
|
|
917
|
+
- ❌ SDK 2.1.3 + 资源包 2.0.0 → 不兼容
|
|
918
|
+
- ❌ SDK 2.1.3 + 资源包 2.2.0 → 不兼容
|
|
919
|
+
|
|
920
|
+
#### 版本不兼容时的行为
|
|
921
|
+
|
|
922
|
+
当检测到版本不兼容时,SDK会:
|
|
923
|
+
|
|
924
|
+
1. **抛出错误**:抛出 `ResourceErrorCode.VERSION_INCOMPATIBLE` (错误码: 3005) 错误
|
|
925
|
+
2. **自动卸载**:自动调用 `destroy()` 清理已初始化的资源
|
|
926
|
+
3. **详细信息**:错误消息包含SDK版本和资源包版本信息
|
|
927
|
+
|
|
928
|
+
**示例错误信息:**
|
|
929
|
+
```
|
|
930
|
+
资源版本不兼容: SDK版本为 2.1.3,WebGL资源版本为 2.0.5,前两位版本号必须一致
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
#### 版本兼容性处理示例
|
|
934
|
+
|
|
935
|
+
```javascript
|
|
936
|
+
import { ZEEAvatarSDK, ResourceErrorCode, SDKError } from '@zeewain/3d-avatar-sdk'
|
|
937
|
+
|
|
938
|
+
async function initAvatarWithVersionCheck() {
|
|
939
|
+
const sdk = new ZEEAvatarSDK({
|
|
940
|
+
loaderUrl: './assets/Build/webgl.loader.js',
|
|
941
|
+
dataUrl: './assets/Build/webgl.data.unityweb',
|
|
942
|
+
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
943
|
+
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
944
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
945
|
+
containerId: 'unity-container',
|
|
946
|
+
token: 'your-auth-token'
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
try {
|
|
950
|
+
const response = await sdk.initializeAvatar('avatar001');
|
|
951
|
+
|
|
952
|
+
if (response.success) {
|
|
953
|
+
console.log('✅ 数字人初始化成功,版本检查通过');
|
|
954
|
+
}
|
|
955
|
+
} catch (error) {
|
|
956
|
+
if (error instanceof SDKError && error.code === ResourceErrorCode.VERSION_INCOMPATIBLE) {
|
|
957
|
+
// 版本不兼容错误处理
|
|
958
|
+
console.error('❌ 版本不兼容:', error.message);
|
|
959
|
+
|
|
960
|
+
// 提示用户更新资源包
|
|
961
|
+
showUpdateNotification({
|
|
962
|
+
title: '资源包版本不匹配',
|
|
963
|
+
message: '请下载与当前SDK版本匹配的资源包',
|
|
964
|
+
action: '前往下载'
|
|
965
|
+
});
|
|
966
|
+
} else {
|
|
967
|
+
// 其他错误处理
|
|
968
|
+
console.error('初始化失败:', error);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// 显示更新提示
|
|
974
|
+
function showUpdateNotification(options) {
|
|
975
|
+
// 显示友好的UI提示
|
|
976
|
+
const notification = document.createElement('div');
|
|
977
|
+
notification.className = 'version-notification';
|
|
978
|
+
notification.innerHTML = `
|
|
979
|
+
<h3>${options.title}</h3>
|
|
980
|
+
<p>${options.message}</p>
|
|
981
|
+
<button onclick="window.open('https://open.zeewain3d.com/downloads', '_blank')">
|
|
982
|
+
${options.action}
|
|
983
|
+
</button>
|
|
984
|
+
`;
|
|
985
|
+
document.body.appendChild(notification);
|
|
986
|
+
}
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
#### 资源包下载与部署建议
|
|
990
|
+
|
|
991
|
+
1. **获取SDK版本号**
|
|
992
|
+
```javascript
|
|
993
|
+
import { SDK_VERSION } from '@zeewain/3d-avatar-sdk'
|
|
994
|
+
console.log('当前SDK版本:', SDK_VERSION); // 如: 2.1.3
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
2. **下载对应资源包**
|
|
998
|
+
- 访问紫为·AI开放平台
|
|
999
|
+
- 下载版本号前两位一致的资源包(如:2.1.x 系列)
|
|
1000
|
+
|
|
1001
|
+
3. **部署资源包**
|
|
1002
|
+
- 将资源包解压到服务器或CDN
|
|
1003
|
+
- 按版本号组织目录结构:`/webgl/2.1`
|
|
1004
|
+
- 配置 `assetsUrl: 'https://your-cdn.com/webgl/2.1'`
|
|
1005
|
+
|
|
1006
|
+
#### 版本升级策略
|
|
1007
|
+
|
|
1008
|
+
当需要升级SDK版本时:
|
|
1009
|
+
|
|
1010
|
+
**场景1:修订号升级(如 2.1.3 → 2.1.5)**
|
|
1011
|
+
- ✅ 资源包无需更新
|
|
1012
|
+
- ✅ 直接升级SDK即可
|
|
1013
|
+
|
|
1014
|
+
**场景2:主版本号或次版本号升级(如 2.1.3 → 2.2.0 或 2.1.3 → 3.0.0)**
|
|
1015
|
+
- ⚠️ 需要重新下载资源包(2.2.x 或 3.0.x)
|
|
1016
|
+
- ⚠️ 更新 `assetsUrl` 配置为新版本路径
|
|
1017
|
+
|
|
874
1018
|
## 🔧 高级功能
|
|
875
1019
|
|
|
876
1020
|
### 🎯 智能播报队列
|
|
@@ -965,6 +1109,7 @@ const sdk1 = new ZEEAvatarSDK({
|
|
|
965
1109
|
dataUrl: './assets/Build/webgl.data.unityweb',
|
|
966
1110
|
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
967
1111
|
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
1112
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
968
1113
|
containerId: 'unity-container-1',
|
|
969
1114
|
token: 'token1'
|
|
970
1115
|
});
|
|
@@ -974,6 +1119,7 @@ const sdk2 = new ZEEAvatarSDK({
|
|
|
974
1119
|
dataUrl: './assets/Build/webgl.data.unityweb',
|
|
975
1120
|
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
976
1121
|
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
1122
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
977
1123
|
containerId: 'unity-container-2',
|
|
978
1124
|
token: 'token2'
|
|
979
1125
|
});
|
|
@@ -1063,6 +1209,26 @@ function handleOperationError(error) {
|
|
|
1063
1209
|
}
|
|
1064
1210
|
}
|
|
1065
1211
|
|
|
1212
|
+
// 资源错误处理
|
|
1213
|
+
function handleResourceError(error) {
|
|
1214
|
+
switch (error.code) {
|
|
1215
|
+
case ResourceErrorCode.LOAD_FAILED:
|
|
1216
|
+
showUserMessage('资源加载失败,请检查网络或资源路径');
|
|
1217
|
+
break;
|
|
1218
|
+
case ResourceErrorCode.VERSION_INCOMPATIBLE:
|
|
1219
|
+
showUserMessage('资源版本不兼容,请下载与SDK版本匹配的资源包');
|
|
1220
|
+
// 显示详细版本信息
|
|
1221
|
+
console.error('版本不兼容:', error.message);
|
|
1222
|
+
break;
|
|
1223
|
+
case ResourceErrorCode.NOT_FOUND:
|
|
1224
|
+
showUserMessage('资源不存在,请检查assetsUrl配置');
|
|
1225
|
+
break;
|
|
1226
|
+
case ResourceErrorCode.FILE_CORRUPTED:
|
|
1227
|
+
showUserMessage('资源文件损坏,请重新下载资源包');
|
|
1228
|
+
break;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1066
1232
|
// 在SDK操作中使用
|
|
1067
1233
|
try {
|
|
1068
1234
|
await sdk.initializeAvatar('avatar001');
|
|
@@ -1204,6 +1370,7 @@ document.addEventListener('visibilitychange', () => {
|
|
|
1204
1370
|
| 3002 | `ResourceErrorCode.FILE_CORRUPTED` | 资源文件损坏 | 重新下载资源文件 |
|
|
1205
1371
|
| 3003 | `ResourceErrorCode.NOT_FOUND` | 资源不存在 | 检查资源路径 |
|
|
1206
1372
|
| 3004 | `ResourceErrorCode.UNSUPPORTED_FORMAT` | 资源格式不支持 | 使用支持的格式 |
|
|
1373
|
+
| 3005 | `ResourceErrorCode.VERSION_INCOMPATIBLE` | 资源版本不兼容 | 下载与SDK版本匹配的资源包(前两位版本号一致) |
|
|
1207
1374
|
|
|
1208
1375
|
### 系统错误 (4xxx)
|
|
1209
1376
|
| 错误码 | 常量名 | 描述 | 处理建议 |
|
|
@@ -1380,6 +1547,7 @@ export const avatarConfig = {
|
|
|
1380
1547
|
dataUrl: './assets/Build/webgl.data.unityweb',
|
|
1381
1548
|
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
1382
1549
|
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
1550
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
1383
1551
|
containerId: 'unity-container',
|
|
1384
1552
|
env: 'dev',
|
|
1385
1553
|
token: 'dev-token'
|
|
@@ -1389,6 +1557,7 @@ export const avatarConfig = {
|
|
|
1389
1557
|
dataUrl: 'https://cdn.example.com/webgl.data.unityweb',
|
|
1390
1558
|
frameworkUrl: 'https://cdn.example.com/webgl.framework.js.unityweb',
|
|
1391
1559
|
codeUrl: 'https://cdn.example.com/webgl.wasm.unityweb',
|
|
1560
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
1392
1561
|
containerId: 'unity-container',
|
|
1393
1562
|
env: 'prod',
|
|
1394
1563
|
token: process.env.AVATAR_TOKEN
|
|
@@ -1518,10 +1687,11 @@ class NewAvatarApp {
|
|
|
1518
1687
|
|
|
1519
1688
|
**A1:** 请按以下步骤排查:
|
|
1520
1689
|
|
|
1521
|
-
1. **检查文件路径**:确保Unity
|
|
1522
|
-
2.
|
|
1523
|
-
3.
|
|
1524
|
-
4.
|
|
1690
|
+
1. **检查文件路径**:确保Unity构建文件路径和资源包路径配置正确
|
|
1691
|
+
2. **检查assetsUrl**:确认资源包已正确部署且assetsUrl配置正确
|
|
1692
|
+
3. **CORS问题**:如果文件在不同域名,需要配置CORS
|
|
1693
|
+
4. **网络连接**:确认网络可以访问构建文件URL和资源包URL
|
|
1694
|
+
5. **浏览器兼容性**:确认浏览器支持WebGL 2.0
|
|
1525
1695
|
|
|
1526
1696
|
```javascript
|
|
1527
1697
|
// 检查资源可访问性
|
|
@@ -1530,17 +1700,20 @@ async function checkResourcesAvailability(config) {
|
|
|
1530
1700
|
config.loaderUrl,
|
|
1531
1701
|
config.dataUrl,
|
|
1532
1702
|
config.frameworkUrl,
|
|
1533
|
-
config.codeUrl
|
|
1703
|
+
config.codeUrl,
|
|
1704
|
+
config.assetsUrl // 检查资源包地址
|
|
1534
1705
|
];
|
|
1535
1706
|
|
|
1536
1707
|
for (const url of resources) {
|
|
1537
1708
|
try {
|
|
1538
1709
|
const response = await fetch(url, { method: 'HEAD' });
|
|
1539
1710
|
if (!response.ok) {
|
|
1540
|
-
console.error(
|
|
1711
|
+
console.error(`❌ 资源不可访问: ${url}`);
|
|
1712
|
+
} else {
|
|
1713
|
+
console.log(`✅ 资源可访问: ${url}`);
|
|
1541
1714
|
}
|
|
1542
1715
|
} catch (error) {
|
|
1543
|
-
console.error(
|
|
1716
|
+
console.error(`❌ 资源检查失败: ${url}`, error);
|
|
1544
1717
|
}
|
|
1545
1718
|
}
|
|
1546
1719
|
}
|
|
@@ -1718,6 +1891,70 @@ class AvatarManager {
|
|
|
1718
1891
|
}
|
|
1719
1892
|
```
|
|
1720
1893
|
|
|
1894
|
+
### Q6: 遇到版本不兼容错误怎么办?
|
|
1895
|
+
|
|
1896
|
+
**A6:** 版本不兼容错误(错误码3005)说明SDK版本与资源包版本不匹配,请按以下步骤解决:
|
|
1897
|
+
|
|
1898
|
+
**1. 确认版本信息**
|
|
1899
|
+
```javascript
|
|
1900
|
+
import { SDK_VERSION } from '@zeewain/3d-avatar-sdk'
|
|
1901
|
+
console.log('当前SDK版本:', SDK_VERSION); // 如: 2.1.3
|
|
1902
|
+
```
|
|
1903
|
+
|
|
1904
|
+
**2. 检查错误详情**
|
|
1905
|
+
```javascript
|
|
1906
|
+
try {
|
|
1907
|
+
await sdk.initializeAvatar('avatar001');
|
|
1908
|
+
} catch (error) {
|
|
1909
|
+
if (error.code === 3005) {
|
|
1910
|
+
// 错误消息会显示具体的版本信息
|
|
1911
|
+
console.error(error.message);
|
|
1912
|
+
// 示例: "资源版本不兼容: SDK版本为 2.1.3,WebGL资源版本为 2.0.5,前两位版本号必须一致"
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
```
|
|
1916
|
+
|
|
1917
|
+
**3. 解决方案**
|
|
1918
|
+
|
|
1919
|
+
**方案A:更新资源包(推荐)**
|
|
1920
|
+
- 访问紫为·AI开放平台
|
|
1921
|
+
- 下载与SDK版本号前两位一致的资源包
|
|
1922
|
+
- 例如:SDK版本为 2.1.3,需下载 2.1.x 系列的资源包
|
|
1923
|
+
- 将资源包部署到服务器或CDN
|
|
1924
|
+
- 更新 `assetsUrl` 配置
|
|
1925
|
+
|
|
1926
|
+
**方案B:回退SDK版本**
|
|
1927
|
+
```bash
|
|
1928
|
+
# 如果资源包是 2.1.x 版本,回退SDK到对应版本
|
|
1929
|
+
npm install @zeewain/3d-avatar-sdk@2.1.x
|
|
1930
|
+
```
|
|
1931
|
+
|
|
1932
|
+
**4. 版本匹配示例**
|
|
1933
|
+
|
|
1934
|
+
| SDK版本 | 兼容的资源包版本 | 是否兼容 |
|
|
1935
|
+
|:--------|:----------------|:---------|
|
|
1936
|
+
| 2.1.3 | 2.1.0, 2.1.5, 2.1.10 | ✅ 兼容 |
|
|
1937
|
+
| 2.1.3 | 2.0.8, 2.2.0, 3.0.0 | ❌ 不兼容 |
|
|
1938
|
+
|
|
1939
|
+
**5. 预防措施**
|
|
1940
|
+
```javascript
|
|
1941
|
+
// 在配置文件中记录版本信息
|
|
1942
|
+
const config = {
|
|
1943
|
+
sdkVersion: '2.1.3', // SDK版本
|
|
1944
|
+
assetsVersion: '2.1', // 资源包版本
|
|
1945
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
1946
|
+
// ... 其他配置
|
|
1947
|
+
};
|
|
1948
|
+
|
|
1949
|
+
// 定期检查版本一致性
|
|
1950
|
+
function checkVersionConsistency(config) {
|
|
1951
|
+
const sdkMajorMinor = config.sdkVersion.split('.').slice(0, 2).join('.');
|
|
1952
|
+
if (sdkMajorMinor !== config.assetsVersion) {
|
|
1953
|
+
console.warn('⚠️ 配置文件中SDK版本与资源包版本不匹配');
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
```
|
|
1957
|
+
|
|
1721
1958
|
## 🆚 新旧版本对比
|
|
1722
1959
|
|
|
1723
1960
|
### 使用体验对比
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -441,10 +441,11 @@ function updateUnityPlaceholder(display)
|
|
|
441
441
|
// frameworkUrl: 'https://unpkg.com/@zeewain/3d-avatar-sdk@1.2.1/dist/assets/Build/webgl.framework.js.unityweb',
|
|
442
442
|
// codeUrl: 'https://unpkg.com/@zeewain/3d-avatar-sdk@1.2.1/dist/assets/Build/webgl.wasm.unityweb',
|
|
443
443
|
// 使用本地WebGL文件
|
|
444
|
-
|
|
444
|
+
loaderUrl: './public/assets/Build/webgl.loader.js',
|
|
445
445
|
dataUrl: './public/assets/Build/webgl.data.unityweb',
|
|
446
446
|
frameworkUrl: './public/assets/Build/webgl.framework.js.unityweb',
|
|
447
447
|
codeUrl: './public/assets/Build/webgl.wasm.unityweb',
|
|
448
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
448
449
|
containerId: 'unity-container',
|
|
449
450
|
env: 'dev',
|
|
450
451
|
onProgress: (progress) =>
|
|
@@ -313,6 +313,7 @@ export default {
|
|
|
313
313
|
dataUrl: './assets/Build/webgl.data.unityweb',
|
|
314
314
|
frameworkUrl: './assets/Build/webgl.framework.js.unityweb',
|
|
315
315
|
codeUrl: './assets/Build/webgl.wasm.unityweb',
|
|
316
|
+
assetsUrl: 'https://cdn.zeewain3d.com/webgl/2.1',
|
|
316
317
|
containerId: 'unity-container',
|
|
317
318
|
|
|
318
319
|
// 认证配置
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@element-plus/icons-vue": "^2.3.1",
|
|
25
25
|
"@vueuse/core": "^13.5.0",
|
|
26
26
|
"@vueuse/integrations": "^13.5.0",
|
|
27
|
-
"@zeewain/3d-avatar-sdk": "^1.2
|
|
27
|
+
"@zeewain/3d-avatar-sdk": "^2.1.2",
|
|
28
28
|
"dayjs": "^1.11.13",
|
|
29
29
|
"element-plus": "^2.10.4",
|
|
30
30
|
"vite-plugin-html": "^3.2.2",
|
|
@@ -306,7 +306,7 @@ function initializeSDKConfig(): ZEEAvatarSDK | null {
|
|
|
306
306
|
token: globalConfig.token,
|
|
307
307
|
env: globalConfig.env,
|
|
308
308
|
apiUrl: globalConfig.apiBaseUrl,
|
|
309
|
-
|
|
309
|
+
assetsUrl: globalConfig.assetsUrl || undefined,
|
|
310
310
|
enableDebugLog: true,
|
|
311
311
|
// 待机动作列表:比心,左手指示(低)
|
|
312
312
|
idleMotionList: globalConfig.idleMotionListString?.split(',').filter(item => item.trim()) || [],
|
|
@@ -27,17 +27,20 @@
|
|
|
27
27
|
</template>
|
|
28
28
|
</el-input>
|
|
29
29
|
</el-form-item>
|
|
30
|
-
<el-form-item
|
|
30
|
+
<el-form-item label="WebGL路径" required>
|
|
31
31
|
<el-input
|
|
32
|
-
v-model="modelValue.
|
|
33
|
-
placeholder="请输入
|
|
32
|
+
v-model="modelValue.webglPath"
|
|
33
|
+
placeholder="请输入WebGL路径"
|
|
34
34
|
clearable>
|
|
35
|
+
<template #prefix>
|
|
36
|
+
<el-icon><Folder /></el-icon>
|
|
37
|
+
</template>
|
|
35
38
|
</el-input>
|
|
36
39
|
</el-form-item>
|
|
37
|
-
<el-form-item label="
|
|
40
|
+
<el-form-item label="资源路径" required>
|
|
38
41
|
<el-input
|
|
39
|
-
v-model="modelValue.
|
|
40
|
-
placeholder="
|
|
42
|
+
v-model="modelValue.assetsUrl"
|
|
43
|
+
placeholder="请输入资源路径"
|
|
41
44
|
clearable>
|
|
42
45
|
<template #prefix>
|
|
43
46
|
<el-icon><Folder /></el-icon>
|
package/dist/index.d.ts
CHANGED
|
@@ -114,32 +114,6 @@ interface IUnityMessageSender<T extends string> {
|
|
|
114
114
|
/** 发送异步消息到Unity并等待回调 */
|
|
115
115
|
sendAsyncMessage(methodName: string, operation: T, parameter?: any): Promise<IUnityCallbackResponse>;
|
|
116
116
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Unity服务日志级别枚举
|
|
119
|
-
* @enum {string}
|
|
120
|
-
* @description 定义日志记录的级别
|
|
121
|
-
*/
|
|
122
|
-
declare enum LogLevel {
|
|
123
|
-
DEBUG = "debug",
|
|
124
|
-
INFO = "info",
|
|
125
|
-
WARN = "warn",
|
|
126
|
-
ERROR = "error"
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Unity服务日志记录器接口
|
|
130
|
-
* @interface IUnityLogger
|
|
131
|
-
* @description 统一的日志记录接口
|
|
132
|
-
*/
|
|
133
|
-
interface IUnityLogger {
|
|
134
|
-
/** 记录调试信息 */
|
|
135
|
-
debug(message: string, data?: any): void;
|
|
136
|
-
/** 记录一般信息 */
|
|
137
|
-
info(message: string, data?: any): void;
|
|
138
|
-
/** 记录警告信息 */
|
|
139
|
-
warn(message: string, data?: any): void;
|
|
140
|
-
/** 记录错误信息 */
|
|
141
|
-
error(message: string, error?: Error, data?: any): void;
|
|
142
|
-
}
|
|
143
117
|
|
|
144
118
|
/**
|
|
145
119
|
* @fileoverview 流式播报服务接口定义
|
|
@@ -337,10 +311,8 @@ interface IAvatarSDKConfig {
|
|
|
337
311
|
env?: 'dev' | 'test' | 'prod' | 'custom';
|
|
338
312
|
/** api接口地址,仅当env为custom时有效 */
|
|
339
313
|
apiUrl?: string;
|
|
340
|
-
/**
|
|
341
|
-
assetsUrl
|
|
342
|
-
/** AB资源文件地址 */
|
|
343
|
-
resourcesUrl?: string;
|
|
314
|
+
/** 资源文件地址(父级路径),从平台下载的资源文件所解压出来的目录 */
|
|
315
|
+
assetsUrl: string;
|
|
344
316
|
/** Unity加载器脚本URL */
|
|
345
317
|
loaderUrl: string;
|
|
346
318
|
/** Unity数据文件URL */
|
|
@@ -359,6 +331,8 @@ interface IAvatarSDKConfig {
|
|
|
359
331
|
broadcastCallbacks?: IBroadcastCallbacks;
|
|
360
332
|
/** 是否启用调试日志,默认为false */
|
|
361
333
|
enableDebugLog?: boolean;
|
|
334
|
+
/** 内部 WEBGL 版本 */
|
|
335
|
+
audioDrivenVersion?: string;
|
|
362
336
|
}
|
|
363
337
|
|
|
364
338
|
/**
|
|
@@ -400,6 +374,8 @@ interface IAvatarCallbackResponse extends IUnityCallbackResponse {
|
|
|
400
374
|
motionId?: string;
|
|
401
375
|
/** 动作剩余时间,可选 */
|
|
402
376
|
motionRemainingTime?: number;
|
|
377
|
+
/** 内部 WEBGL 版本 */
|
|
378
|
+
audioDrivenVersion?: string;
|
|
403
379
|
};
|
|
404
380
|
}
|
|
405
381
|
/**
|
|
@@ -460,8 +436,6 @@ interface IAvatarAPI {
|
|
|
460
436
|
* @description 提供统一的SDK接口,简化用户使用体验,支持多实例
|
|
461
437
|
*/
|
|
462
438
|
declare class ZEEAvatarSDK {
|
|
463
|
-
/** SDK配置 */
|
|
464
|
-
private config;
|
|
465
439
|
/** SDK唯一标识符 */
|
|
466
440
|
private readonly instanceId;
|
|
467
441
|
/** Unity加载器实例 */
|
|
@@ -474,6 +448,8 @@ declare class ZEEAvatarSDK {
|
|
|
474
448
|
private unityInstance;
|
|
475
449
|
/** SDK初始化状态 */
|
|
476
450
|
private isInitialized;
|
|
451
|
+
/** SDK日志 */
|
|
452
|
+
private readonly logger;
|
|
477
453
|
/**
|
|
478
454
|
* 构造函数
|
|
479
455
|
* @param config SDK配置对象
|
|
@@ -585,7 +561,7 @@ declare class ZEEAvatarSDK {
|
|
|
585
561
|
* 获取SDK配置
|
|
586
562
|
* @returns IAvatarSDKConfig 当前配置
|
|
587
563
|
*/
|
|
588
|
-
getConfig(): IAvatarSDKConfig;
|
|
564
|
+
getConfig(): IAvatarSDKConfig | null;
|
|
589
565
|
/**
|
|
590
566
|
* 确保SDK已初始化
|
|
591
567
|
* @private
|
|
@@ -593,6 +569,32 @@ declare class ZEEAvatarSDK {
|
|
|
593
569
|
private ensureInitialized;
|
|
594
570
|
}
|
|
595
571
|
|
|
572
|
+
/**
|
|
573
|
+
* @fileoverview SDK 版本号常量
|
|
574
|
+
* @description 此文件由构建脚本自动生成,请勿手动修改
|
|
575
|
+
*/
|
|
576
|
+
/**
|
|
577
|
+
* SDK 版本号
|
|
578
|
+
* @const {string} SDK_VERSION
|
|
579
|
+
*/
|
|
580
|
+
declare const SDK_VERSION = "2.1.2";
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Unity服务日志记录器接口
|
|
584
|
+
* @interface ISimpleLogger
|
|
585
|
+
* @description 统一的日志记录接口
|
|
586
|
+
*/
|
|
587
|
+
interface ISimpleLogger {
|
|
588
|
+
/** 记录调试信息 */
|
|
589
|
+
debug(message: string, data?: any): void;
|
|
590
|
+
/** 记录一般信息 */
|
|
591
|
+
info(message: string, data?: any): void;
|
|
592
|
+
/** 记录警告信息 */
|
|
593
|
+
warn(message: string, data?: any): void;
|
|
594
|
+
/** 记录错误信息 */
|
|
595
|
+
error(message: string, error?: Error, data?: any): void;
|
|
596
|
+
}
|
|
597
|
+
|
|
596
598
|
/**
|
|
597
599
|
* @fileoverview Unity服务抽象基类
|
|
598
600
|
* @description 提供Unity服务的通用基础实现,包括回调管理、消息发送、错误处理等功能
|
|
@@ -613,7 +615,7 @@ declare abstract class UnityBaseService<T extends string> implements IUnityCallb
|
|
|
613
615
|
/** 操作超时时间 */
|
|
614
616
|
protected readonly timeout: number;
|
|
615
617
|
/** 日志记录器 */
|
|
616
|
-
protected readonly logger:
|
|
618
|
+
protected readonly logger: ISimpleLogger;
|
|
617
619
|
/** 最大重试次数 */
|
|
618
620
|
protected readonly maxRetries: number;
|
|
619
621
|
/** SDK实例唯一标识符 */
|
|
@@ -763,6 +765,7 @@ declare class AvatarService extends UnityBaseService<AvatarOperationType> implem
|
|
|
763
765
|
* ```
|
|
764
766
|
*/
|
|
765
767
|
initializeAvatar(avatarCode: string, cameraType?: AvatarCameraType): Promise<IAvatarCallbackResponse>;
|
|
768
|
+
handleCallback(operation: AvatarOperationType, code: number, message: string, data?: string): void;
|
|
766
769
|
/**
|
|
767
770
|
* 播放数字人动作
|
|
768
771
|
* @param clipCode - 动作编码
|
|
@@ -1045,7 +1048,7 @@ declare class BroadcastService extends UnityBaseService<BroadcastOperationType>
|
|
|
1045
1048
|
* 处理任务错误
|
|
1046
1049
|
* @param task - 播报任务
|
|
1047
1050
|
* @param error - 错误对象
|
|
1048
|
-
* @description
|
|
1051
|
+
* @description 处理任务执行过程中的错误,防止重复触发错误回调
|
|
1049
1052
|
* @private
|
|
1050
1053
|
*/
|
|
1051
1054
|
private handleTaskError;
|
|
@@ -1100,6 +1103,25 @@ declare class BroadcastService extends UnityBaseService<BroadcastOperationType>
|
|
|
1100
1103
|
* @private
|
|
1101
1104
|
*/
|
|
1102
1105
|
private clearQueueProcessTimer;
|
|
1106
|
+
/**
|
|
1107
|
+
* 根据 HTTP 状态码创建对应的 SDKError
|
|
1108
|
+
* @param status - HTTP 状态码
|
|
1109
|
+
* @param statusText - HTTP 状态文本
|
|
1110
|
+
* @param taskId - 任务 ID(用于日志记录)
|
|
1111
|
+
* @returns SDKError 实例
|
|
1112
|
+
* @description 将 HTTP 错误状态码映射为对应的 SDKError
|
|
1113
|
+
* @private
|
|
1114
|
+
*/
|
|
1115
|
+
private createHttpError;
|
|
1116
|
+
/**
|
|
1117
|
+
* 将任意错误转换为 SDKError
|
|
1118
|
+
* @param error - 原始错误对象
|
|
1119
|
+
* @param taskId - 任务 ID(用于日志记录)
|
|
1120
|
+
* @returns SDKError 实例
|
|
1121
|
+
* @description 统一将各种类型的错误转换为 SDKError,便于上层统一处理
|
|
1122
|
+
* @private
|
|
1123
|
+
*/
|
|
1124
|
+
private convertToSDKError;
|
|
1103
1125
|
}
|
|
1104
1126
|
|
|
1105
1127
|
/**
|
|
@@ -1174,7 +1196,9 @@ declare enum ResourceErrorCode {
|
|
|
1174
1196
|
/** 资源不存在 */
|
|
1175
1197
|
NOT_FOUND = 3003,
|
|
1176
1198
|
/** 资源格式不支持 */
|
|
1177
|
-
UNSUPPORTED_FORMAT = 3004
|
|
1199
|
+
UNSUPPORTED_FORMAT = 3004,
|
|
1200
|
+
/** 资源版本不兼容 */
|
|
1201
|
+
VERSION_INCOMPATIBLE = 3005
|
|
1178
1202
|
}
|
|
1179
1203
|
/**
|
|
1180
1204
|
* 系统错误码 (4xxx)
|
|
@@ -1338,7 +1362,7 @@ declare class ZEEAvatarLoader {
|
|
|
1338
1362
|
* @param config - Unity配置对象
|
|
1339
1363
|
* @description 初始化数字人加载器,创建Unity加载器实例
|
|
1340
1364
|
*/
|
|
1341
|
-
constructor(
|
|
1365
|
+
constructor();
|
|
1342
1366
|
/**
|
|
1343
1367
|
* 初始化数字人SDK
|
|
1344
1368
|
* @returns Promise<IAvatarAPI> 返回Avatar API的Promise
|
|
@@ -1399,5 +1423,5 @@ declare class ZEEAvatarLoader {
|
|
|
1399
1423
|
protected initGlobalConfig(): void;
|
|
1400
1424
|
}
|
|
1401
1425
|
|
|
1402
|
-
export { AvatarCameraType, AvatarOperationType, AvatarService, BroadcastOperationType, BroadcastService, BroadcastType, ConfigErrorCode, ERROR_CODE_MAP, ErrorCategory,
|
|
1403
|
-
export type { IAvatarAPI, IAvatarCallbackResponse, IAvatarSDKConfig, IBroadcastAPI, IBroadcastCallbacks, IBroadcastParams, IBroadcastResponse, IBroadcastServiceConfig, IUnityCallbackManager, IUnityCallbackResponse, IUnityInstance,
|
|
1426
|
+
export { AvatarCameraType, AvatarOperationType, AvatarService, BroadcastOperationType, BroadcastService, BroadcastType, ConfigErrorCode, ERROR_CODE_MAP, ErrorCategory, NetworkErrorCode, OperationErrorCode, ResourceErrorCode, SDKError, SDK_VERSION, SystemErrorCode, UnityOperationStatus, ZEEAvatarLoader, ZEEAvatarSDK, getErrorInfo };
|
|
1427
|
+
export type { IAvatarAPI, IAvatarCallbackResponse, IAvatarSDKConfig, IBroadcastAPI, IBroadcastCallbacks, IBroadcastParams, IBroadcastResponse, IBroadcastServiceConfig, IUnityCallbackManager, IUnityCallbackResponse, IUnityInstance, IUnityMessageSender, IUnityServiceConfig, SDKErrorCode, TOperationType };
|