metamaker-for-three 0.1.8-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.
Files changed (51) hide show
  1. package/.env.dev +1 -0
  2. package/.env.mlib +1 -0
  3. package/.gitlab-ci.yml +1 -0
  4. package/.prettierrc.js +50 -0
  5. package/README.md +207 -0
  6. package/babel.config.js +3 -0
  7. package/code.jpg +0 -0
  8. package/examples/example.ts +624 -0
  9. package/libs/metamaker-for-three.js +1 -0
  10. package/package.json +89 -0
  11. package/public/SSSLUT.png +0 -0
  12. package/public/f9d25cc22be065191dca0f2ac7b248fd.zip +0 -0
  13. package/public/favicon.ico +0 -0
  14. package/public/index.html +31 -0
  15. package/public/models/gltf/xj/-43190.jpg +0 -0
  16. package/public/models/gltf/xj/-43240.jpg +0 -0
  17. package/public/models/gltf/xj/-43256.png +0 -0
  18. package/public/models/gltf/xj/-44804.jpg +0 -0
  19. package/public/models/gltf/xj/22344.jpg +0 -0
  20. package/public/models/gltf/xj/37430.jpg +0 -0
  21. package/public/models/gltf/xj/37432.jpg +0 -0
  22. package/public/models/gltf/xj/character.bin +0 -0
  23. package/public/models/gltf/xj/character.glb +0 -0
  24. package/public/models/gltf/xj/character.gltf +12110 -0
  25. package/public/models/gltf/xj/character.zip +0 -0
  26. package/src/assets/SSSLUT.png +0 -0
  27. package/src/assets/metacrypto.wasm +0 -0
  28. package/src/lib/core/index.ts +103 -0
  29. package/src/lib/core/utils/GLTFLoader.d.ts +319 -0
  30. package/src/lib/core/utils/GLTFLoader.js +3827 -0
  31. package/src/lib/core/utils/ResetMaterial.ts +264 -0
  32. package/src/lib/core/utils/convert.ts +124 -0
  33. package/src/lib/core/utils/downloadAnimation.ts +117 -0
  34. package/src/lib/core/utils/downloadData.ts +20 -0
  35. package/src/lib/core/utils/index.ts +59 -0
  36. package/src/lib/core/utils/metacrypto.js +49 -0
  37. package/src/lib/globals.d.ts +7 -0
  38. package/src/lib/index.ts +7 -0
  39. package/tsconfig.dist.json +7 -0
  40. package/tsconfig.json +33 -0
  41. package/types/core/index.d.ts +9 -0
  42. package/types/core/utils/GLTFLoader.d.ts +17 -0
  43. package/types/core/utils/ResetMaterial.d.ts +2 -0
  44. package/types/core/utils/convert.d.ts +13 -0
  45. package/types/core/utils/downloadAnimation.d.ts +10 -0
  46. package/types/core/utils/downloadData.d.ts +2 -0
  47. package/types/core/utils/index.d.ts +13 -0
  48. package/types/core/utils/metacrypto.d.ts +12 -0
  49. package/types/index.d.ts +5 -0
  50. package/vue.config.js +49 -0
  51. package/vue.config.lib.js +61 -0
package/.env.dev ADDED
@@ -0,0 +1 @@
1
+ VUE_APP_METACRYPTO = /
package/.env.mlib ADDED
@@ -0,0 +1 @@
1
+ VUE_BUILD_APP = mlib
package/.gitlab-ci.yml ADDED
@@ -0,0 +1 @@
1
+
package/.prettierrc.js ADDED
@@ -0,0 +1,50 @@
1
+ module.exports = {
2
+ // 行宽 default:80
3
+ printWidth: 100,
4
+ // tab 宽度 default:2
5
+ tabWidth: 2,
6
+ // 使用 tab 键 default:false
7
+ useTabs: false,
8
+ // 语句行末是否添加分号 default:true
9
+ semi: true,
10
+ // 是否使用单引号 default:false
11
+ singleQuote: false,
12
+ // 对象需要引号在加 default:"as-needed"
13
+ quoteProps: "as-needed",
14
+ // jsx单引号 default:false
15
+ jsxSingleQuote: false,
16
+ // 最后一个对象元素加逗号 default:"es5"
17
+ trailingComma: "es5",
18
+ // 在对象字面量声明所使用的的花括号后({)和前(})输出空格 default:true
19
+ bracketSpacing: true,
20
+ // 将 > 多行 JSX 元素放在最后一行的末尾,而不是单独放在下一行(不适用于自闭元素)。default:false
21
+ jsxBracketSameLine: false,
22
+ // (x) => {} 是否要有小括号 default:"always"
23
+ arrowParens: "always",
24
+ // default:0
25
+ rangeStart: 0,
26
+ // default:Infinity
27
+ rangeEnd: Infinity,
28
+ // default:false
29
+ insertPragma: false,
30
+ // default:false
31
+ requirePragma: false,
32
+ // 不包装 markdown text default:"preserve"
33
+ proseWrap: "never",
34
+ // HTML空白敏感性 default:"css"
35
+ htmlWhitespaceSensitivity: "strict",
36
+ // 在 *.vue 文件中 Script 和 Style 标签内的代码是否缩进 default:false
37
+ vueIndentScriptAndStyle: false,
38
+ // 末尾换行符 default:"lf"
39
+ //endOfLine: "lf",
40
+ // default:"auto"
41
+ embeddedLanguageFormatting: "auto",
42
+ overrides: [
43
+ {
44
+ files: "*.md",
45
+ options: {
46
+ tabWidth: 2,
47
+ },
48
+ },
49
+ ],
50
+ };
package/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # human-three-example
2
+
3
+ ## 项目安装
4
+
5
+ ```
6
+ yarn install
7
+ ```
8
+
9
+ ### 开发模型
10
+
11
+ ```
12
+ yarn serve
13
+ ```
14
+
15
+ ### 打包为 lib
16
+
17
+ ```
18
+ yarn build:lib
19
+ ```
20
+
21
+ ## 前置
22
+
23
+ 1. 如果您不是使用 npm 进行开发,请先前往 [threejs git](https://github.com/mrdoob/three.js) 下载 build/three.min.js 引入到项目中,再加载 meta-maker-for-three。
24
+
25
+ 2. npm : npm install three
26
+
27
+ ## 说明
28
+
29
+ 这是黑镜数字人结合 threejs 使用的一个例子。本例子提供了结合 threejs 中 3 个关键点,
30
+
31
+ 1. 数字人的加载
32
+ 2. 数字人物的语音与口型动画的播放
33
+ 3. TTS 语音鉴权代码
34
+
35
+ 其余情况,直接使用 threejs 相关功能完成
36
+
37
+ ### 引入 metamaker-for-three
38
+
39
+ 1. 通过 npm
40
+
41
+ metamaker-for-three 暂时没有上 npm,通过在 packagejson 中添加 github 的地址,并进行 yarn install
42
+
43
+ ```
44
+ "dependencies": {
45
+ "metamaker-for-three": "https://github.com/MetaMakerDeveloper/AweSDK-ThreeJS.git#最新版本号"
46
+ }
47
+ ```
48
+
49
+ 在无法连接 github 的情况下使用 gitee 连接
50
+
51
+ ```
52
+ "dependencies": {
53
+ "metamaker-for-three": "https://gitee.com/metamaker/AweSDK-ThreeJS.git#最新版本号"
54
+ }
55
+ ```
56
+
57
+ 2. 直接在[链接中](https://github.com/MetaMakerDeveloper/AweSDK-ThreeJS)的 libs 下载文件通过
58
+
59
+ ```
60
+ <script src="<您的js存放地址>/metamaker-for-three.js"></script>
61
+ ```
62
+
63
+ ### 接口引入
64
+
65
+ ```
66
+ import MMFT from 'metamaker-for-three'
67
+ ```
68
+
69
+ 1. 数字人加载
70
+
71
+ 数字人目前支持 gltf,zip 包含的 glb 模型 人物,开发者从黑镜开放平台,获得数字人模型文件后,通过调用。
72
+
73
+ 进行模型的加载,随后添加到场景中.
74
+
75
+ 加载服务器的 glb 文件
76
+
77
+ ```js
78
+ import MMFT from "metamaker-for-three";
79
+ const path = "./your.glb";
80
+ const idol = await MMFT.core.loadGLTFModel(path);
81
+ ```
82
+
83
+ _加载 zip_: 在实际应用中,往往会使用 zip 压缩 glb 文件,**metamaker-for-three**并不直接提供加载 zip 的 glb 文件。但是你可以参考 [例子](./examples/example.ts)中的 **replaceIdol**方法中**uncompress**的解压 zip 的代码。
84
+
85
+ 2. 数字人动作
86
+
87
+ 数字人加载完毕后,处于 A POSE 的状态,需要让数字人做某些动作
88
+
89
+ ```js
90
+ import * as THREE from "three";
91
+ import MMFT from "metamaker-for-three";
92
+
93
+ const animateName = `anim/Stand_idel`;
94
+ const json = await MMFT.core.loadAnimationData(animateName);
95
+ const clip = MMFT.core.Convert(json);
96
+ let mixer = new THREE.AnimationMixer(idol);
97
+ let action = mixer.clipAction(clip);
98
+ action.play();
99
+ ```
100
+
101
+ 3. 数字人口型动画
102
+
103
+ 通过调用 tts 接口可以获得口型动画与音频文件,使得数字人开口说话。 而我们的关键是从接口的返回结果中获取音频文件与解析口型动画文件
104
+
105
+ ```js
106
+ const tts = {
107
+ voice_name: "zh-CN-XiaoxiaoNeural",
108
+ speed: 42,
109
+ volume: 100,
110
+ };
111
+ let response: any = await fetch("//open.metamaker.cn/api/openmm/v1/text_to_anim", {
112
+ method: "post",
113
+ headers: {
114
+ "Content-Type": "application/x-www-form-urlencoded",
115
+ Authorization: ttsAuth,
116
+ },
117
+ body: qs.stringify({
118
+ text: text,
119
+ tts_args: JSON.stringify(tts),
120
+ audio_type: "wav",
121
+ storage_type: "cloud",
122
+ }),
123
+ mode: "cors",
124
+ });
125
+
126
+ response = await response.json();
127
+ if (response.err_code !== 0) {
128
+ throw new Error("fetch tts failed");
129
+ }
130
+
131
+ let teethAnimClip = await MMFT.core.loadTTSTeethAnimation(response.ret.teeth_anim);
132
+ let emoAnimClip = await MMFT.core.loadTTSEmoAnimation(response.ret.expression_anim);
133
+ ```
134
+
135
+ [转化口型动画参考](./examples/example.ts) 中 **fetchTTSToAnim**
136
+
137
+ 获得 AnimationClip ,Clip 不能直接播放,还需要变成 Animation 后才可以播放哦 。具体参考该段代码
138
+
139
+ ```js
140
+ import * as THREE from "three";
141
+ let clip = 您的加载后得到AnimateClip对象;
142
+ let mixer = new THREE.AimationMixer(idol);
143
+ let action = mixer.clipAction(clip);
144
+ action.play();
145
+ ```
146
+
147
+ 4. TTS 接口鉴权
148
+
149
+ TTS 接口并不是免费的,所以需要鉴权。js 代码参考
150
+
151
+ ```js
152
+ function makeSignCode() {
153
+ const convertTextToUint8Array = (text: string) => {
154
+ return Array.from(text).map((letter) => letter.charCodeAt(0));
155
+ };
156
+ const convertWordArrayToUint8Array = (wordArray) => {
157
+ const len = wordArray.words.length;
158
+ const uint8Array = new Uint8Array(len << 2);
159
+ let offset = 0;
160
+ let word;
161
+ for (let i = 0; i < len; i++) {
162
+ word = wordArray.words[i];
163
+ uint8Array[offset++] = word >> 24;
164
+ uint8Array[offset++] = (word >> 16) & 0xff;
165
+ uint8Array[offset++] = (word >> 8) & 0xff;
166
+ uint8Array[offset++] = word & 0xff;
167
+ }
168
+ return uint8Array;
169
+ };
170
+
171
+ const appKey = params.appKey;
172
+ const appSecret = params.appSecret;
173
+ const timestamp = Math.floor(new Date().getTime() / 1000);
174
+ console.log(`timestamp:`, timestamp);
175
+ const message = `${timestamp}:${appKey}`;
176
+ const wordsArray = CryptoJS.HmacSHA256(message, appSecret);
177
+ const hashSuffix = convertWordArrayToUint8Array(wordsArray);
178
+ const hashPrefix = convertTextToUint8Array(`${timestamp}:`);
179
+ const totalArray = new Uint8Array(hashPrefix.length + hashSuffix.length);
180
+ totalArray.set(hashPrefix);
181
+ totalArray.set(hashSuffix, hashPrefix.length);
182
+ const tempstr = String.fromCharCode.apply(null, totalArray);
183
+ console.log(`temp str`, tempstr);
184
+ const base64 = btoa(tempstr);
185
+ return `AW ${appKey}:${base64}`;
186
+ }
187
+ ```
188
+ [更多语言鉴权参考](https://help.metamaker.cn/open/28ca/c4e6)
189
+ ## 注意
190
+
191
+ MetaMakerDeveloper 发布的代码或数字资产(数字人、服装、动作、表情等)以及试用数字人小镜、大黑都属于黑镜科技公司,如需商用,请添加以下二维码联系,谢谢!
192
+
193
+ ![image](./code.jpg)
194
+
195
+ ## 更新日志
196
+
197
+ 2022-10-25:动画资源请求路径重复出现/符
198
+
199
+ 2022-09-07:example 增加动作 Loop 设置,请求动作时增加库的版本号。
200
+
201
+ 2022-09-02: 处理部分动作补间,导致模型的踢腿动作,core 中增加 resetPolyonOffset 处理人物模型穿模问题 ; FIX:鉴权生成 code 错误 BUGFIX
202
+
203
+ 2022-8-31: 替换非鉴权的 TTS 接口,请调用者运行例子时,自行替换 appKey,appSecret。替换例子中的人物模型
204
+
205
+ ```
206
+
207
+ ```
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: ["@vue/cli-plugin-babel/preset"],
3
+ };
package/code.jpg ADDED
Binary file