three-base 1.129.17 → 2.0.1

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 (91) hide show
  1. package/README.md +1 -0
  2. package/index.js +1 -37
  3. package/index.ts +1 -61
  4. package/package.json +4 -4
  5. package/lib/ApngTexture.d.ts +0 -13
  6. package/lib/ApngTexture.js +0 -61
  7. package/lib/ApngTexture.ts +0 -91
  8. package/lib/ApngTextureManage.d.ts +0 -18
  9. package/lib/ApngTextureManage.js +0 -87
  10. package/lib/ApngTextureManage.ts +0 -130
  11. package/lib/EventMesh.d.ts +0 -18
  12. package/lib/EventMesh.js +0 -59
  13. package/lib/EventMesh.ts +0 -79
  14. package/lib/ExtrudeMesh.d.ts +0 -111
  15. package/lib/ExtrudeMesh.js +0 -363
  16. package/lib/ExtrudeMesh.ts +0 -571
  17. package/lib/FPScontrol.d.ts +0 -44
  18. package/lib/FPScontrol.js +0 -170
  19. package/lib/FPScontrol.ts +0 -209
  20. package/lib/InstancedGroupMesh.d.ts +0 -10
  21. package/lib/InstancedGroupMesh.js +0 -63
  22. package/lib/InstancedGroupMesh.ts +0 -80
  23. package/lib/KeyFrameAnimation.d.ts +0 -25
  24. package/lib/KeyFrameAnimation.js +0 -78
  25. package/lib/KeyFrameAnimation.ts +0 -122
  26. package/lib/PlaneText.d.ts +0 -37
  27. package/lib/PlaneText.js +0 -30
  28. package/lib/PlaneText.ts +0 -58
  29. package/lib/PlaneWithHtml.d.ts +0 -11
  30. package/lib/PlaneWithHtml.js +0 -67
  31. package/lib/PlaneWithHtml.ts +0 -84
  32. package/lib/PointLight/PointLight.d.ts +0 -13
  33. package/lib/PointLight/PointLight.js +0 -63
  34. package/lib/PointLight/PointLight.ts +0 -74
  35. package/lib/PointLight/pointLight_map.png +0 -0
  36. package/lib/Sky/Sky.d.ts +0 -13
  37. package/lib/Sky/Sky.js +0 -28
  38. package/lib/Sky/Sky.ts +0 -36
  39. package/lib/Sky/bluesky.jpg +0 -0
  40. package/lib/SpriteText.d.ts +0 -45
  41. package/lib/SpriteText.js +0 -162
  42. package/lib/SpriteText.ts +0 -189
  43. package/lib/SpriteText2.d.ts +0 -47
  44. package/lib/SpriteText2.js +0 -197
  45. package/lib/SpriteText2.ts +0 -236
  46. package/lib/Text3D/Text3D.d.ts +0 -20
  47. package/lib/Text3D/Text3D.js +0 -61
  48. package/lib/Text3D/Text3D.ts +0 -92
  49. package/lib/Text3D/fontController.d.ts +0 -59
  50. package/lib/Text3D/fontController.js +0 -200
  51. package/lib/Text3D/fontController.ts +0 -285
  52. package/lib/Text3D/gentilis.json +0 -811
  53. package/lib/ThreeBase.d.ts +0 -59
  54. package/lib/ThreeBase.js +0 -395
  55. package/lib/ThreeBase.ts +0 -475
  56. package/lib/ThreeMouse.d.ts +0 -39
  57. package/lib/ThreeMouse.js +0 -357
  58. package/lib/ThreeMouse.ts +0 -464
  59. package/lib/Transition.d.ts +0 -43
  60. package/lib/Transition.js +0 -196
  61. package/lib/Transition.ts +0 -268
  62. package/lib/index.d.ts +0 -22
  63. package/lib/keyContorls.d.ts +0 -25
  64. package/lib/keyContorls.js +0 -98
  65. package/lib/keyContorls.ts +0 -127
  66. package/lib/planeModal1/PlaneModal1.d.ts +0 -31
  67. package/lib/planeModal1/PlaneModal1.js +0 -104
  68. package/lib/planeModal1/PlaneModal1.ts +0 -150
  69. package/lib/planeModal1/planeModal.png +0 -0
  70. package/lib/shaders.d.ts +0 -17
  71. package/lib/shaders.js +0 -245
  72. package/lib/shaders.ts +0 -264
  73. package/lib/spriteModal1/SpriteModal1.d.ts +0 -30
  74. package/lib/spriteModal1/SpriteModal1.js +0 -109
  75. package/lib/spriteModal1/SpriteModal1.ts +0 -159
  76. package/lib/spriteModal1/spriteModal1.png +0 -0
  77. package/lib/stroke_pass/FullScreenQuad.d.ts +0 -7
  78. package/lib/stroke_pass/FullScreenQuad.js +0 -25
  79. package/lib/stroke_pass/FullScreenQuad.ts +0 -33
  80. package/lib/stroke_pass/stroke_pass.d.ts +0 -2
  81. package/lib/stroke_pass/stroke_pass.js +0 -190
  82. package/lib/stroke_pass/stroke_pass.ts +0 -211
  83. package/lib/threeLoader.d.ts +0 -20
  84. package/lib/threeLoader.js +0 -110
  85. package/lib/threeLoader.ts +0 -136
  86. package/lib/threeUtils.d.ts +0 -41
  87. package/lib/threeUtils.js +0 -179
  88. package/lib/threeUtils.ts +0 -212
  89. package/lib/type.d.ts +0 -0
  90. package/lib/type.js +0 -10
  91. package/lib/type.ts +0 -13
@@ -1,285 +0,0 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2021-04-15 00:34:44
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-04-04 19:26:27
6
- */
7
-
8
- import Dexie, { Table } from "dexie";
9
- import { filter, first, isEmpty } from "lodash";
10
- import { Font } from "three";
11
- import threeUtils from "../threeUtils";
12
- import gentilisJSON from "./gentilis.json";
13
-
14
- export type saveFontParam = {
15
- fontType?: string,
16
- fontName: string,
17
- fontJson: any
18
- }
19
-
20
- export type addFontFamilyParam = {
21
- fontType?: string,
22
- fontFamilyJson: any
23
- }
24
-
25
- export type getFontParam = {
26
- fontType?: string,
27
- fontName: string
28
- }
29
-
30
- export type loadTextParam = {
31
- fontBasePath: string,
32
- fontType?: string,
33
- text?: string,
34
- callback?: (font: Font) => void
35
- }
36
-
37
- class indexBD extends Dexie {
38
- constructor(dbName: string) {
39
- super(dbName)
40
- }
41
- threeFont!: Table;
42
- }
43
-
44
- // 字体加载器
45
- class fontContorl {
46
-
47
- constructor() { }
48
-
49
- THREEFontMap: Map<string, Font> = new Map();
50
-
51
- // 专门存储字体的数据库
52
- fontBD: indexBD = (() => {
53
-
54
- let fontDB = new indexBD("three-base-font");
55
-
56
- fontDB.version(1).stores({ threeFont: "++KeyPath,fontType,fontName,fontJson" });
57
- return fontDB;
58
- })();
59
-
60
-
61
- /**
62
- * 保存 字体json到本地数据库中
63
- * @param {saveFontParam} { fontType = "simhei", fontName, fontJson }
64
- * @memberof fontContorl
65
- */
66
- async saveFont({ fontType = "simhei", fontName, fontJson = "" }: saveFontParam) {
67
-
68
- let findResult = await this.getFont({ fontType, fontName });
69
-
70
- if (isEmpty(findResult)) {
71
- await this.fontBD.threeFont.add({ fontType, fontName, fontJson });
72
- }
73
- }
74
-
75
- /**
76
- * 通过 fontType 和 fontName 查询 fontJson
77
- * @param {getFontParam} { fontType = "simhei", fontName }
78
- * @returns
79
- * @memberof fontContorl
80
- */
81
- async getFont({ fontType = "simhei", fontName }: getFontParam) {
82
-
83
- let fondResult = await this.fontBD.threeFont
84
- .filter(d => (d.fontType === fontType && d.fontName === fontName))
85
- .toArray();
86
-
87
- if (isEmpty(fondResult)) {
88
- return undefined;
89
- } else {
90
- return first(fondResult)!.fontJson;
91
- }
92
-
93
- }
94
-
95
- // 加载字体的回调函数们
96
- _loadTextCall: Map<string, Array<() => void>> = new Map();
97
-
98
- // 加载文字 提供给需要创建字体模型的方法使用 以节流的形式调用 回调函数
99
- async loadText({ fontType = "simhei", text = "", fontBasePath, callback }: loadTextParam) {
100
-
101
- // 加载字体容器
102
- await this._loadFontIndexJson({ fontType, fontBasePath });
103
-
104
- let newCallback = () => {
105
- let fontFamily = this.THREEFontMap.get(fontType);
106
- if (callback && fontFamily) {
107
- callback(fontFamily);
108
- }
109
- }
110
-
111
- // 遍历文本
112
- filter(text).map(fontName => {
113
-
114
- // 没有的就去加载
115
- if (!this.hasFont({ fontType, fontName })) {
116
-
117
- // 添加文字的默认模型 避免报错
118
- let fontFamily = this.THREEFontMap.get(fontType);
119
-
120
- // 创建 three 字体对象
121
- if (fontFamily) {
122
- //@ts-ignore
123
- fontFamily.data.glyphs[fontName] = { "ha": 1389, "x_min": 477, "x_max": 949, "o": "m 700 901 q 906 770 830 906 q 770 477 949 618 q 711 288 711 412 l 613 288 q 781 608 613 494 q 819 722 825 651 q 700 808 808 803 l 684 808 q 581 673 575 803 l 477 673 q 613 884 477 836 q 700 901 629 901 m 732 184 l 732 71 l 591 71 l 591 184 l 732 184 z " }
124
- }
125
-
126
- this._loadFontJson({ fontType, fontName, fontBasePath });
127
- }
128
-
129
- // 加入待执行的回调
130
- let origin_callbacks = this._loadTextCall.get(`${fontType}_${fontName}`) || [];
131
-
132
- if (newCallback) {
133
- this._loadTextCall.set(`${fontType}_${fontName}`, [...origin_callbacks, newCallback]);
134
- }
135
- });
136
-
137
- // 执行任务队列
138
- threeUtils.addWork(newCallback);
139
- }
140
-
141
- // 加载字体
142
- async _loadFontIndexJson({ fontType = "simhei", fontBasePath }: loadTextParam) {
143
-
144
- let fontFamily = this.THREEFontMap.get(fontType);
145
-
146
- // 创建 three 字体对象
147
- if (!fontFamily) {
148
-
149
- // 初始字体结构
150
- fontFamily = new Font({
151
- "underlineThickness": 69,
152
- "underlinePosition": -174,
153
- "resolution": 1000,
154
- "original_font_information": {},
155
- "familyName": "Source Han Sans CN Normal",
156
- "descender": -167,
157
- "cssFontWeight": "normal",
158
- "cssFontStyle": "normal",
159
- "boundingBox": {
160
- "yMin": -700,
161
- "xMin": -1389,
162
- "yMax": 700,
163
- "xMax": 4067
164
- },
165
- "glyphs": {}
166
- });
167
-
168
- this.THREEFontMap.set(fontType, fontFamily);
169
-
170
- // 读取本地数据库中的字体初始结构文件
171
- let fontFamilyIndexJson = await this.getFont({ fontType, fontName: "index" });
172
-
173
- // 加载外部字体初始结构文件
174
- if (!fontFamilyIndexJson) {
175
- this._loadFontJson({ fontType, fontName: "index", fontBasePath });
176
- }
177
- }
178
- }
179
-
180
- // 加载外部字体.js
181
- async _loadFontJson({ fontType = "simhei", fontName, fontBasePath }: { fontType: string, fontName: string, fontBasePath: string }) {
182
-
183
- let fontJson = await this.getFont({ fontType, fontName });
184
-
185
- if (!fontJson) {
186
- fontJson = (gentilisJSON as any).glyphs[fontName];
187
- }
188
-
189
- // 数据库中没有 就去加载字体js
190
- if (!fontJson) {
191
-
192
- // 加载字体js
193
- await new Promise<void>(resolve => {
194
-
195
- let script = document.createElement("script");
196
-
197
- Object.assign(script, {
198
- type: "text/javascript",
199
- src: `${fontBasePath}${fontType}/${fontName}.js`,
200
- async: true,
201
- onload: () => {
202
- script.remove();
203
- resolve();
204
- },
205
- onerror: () => {
206
- }
207
- });
208
- document.head.appendChild(script);
209
- });
210
-
211
- } else {
212
- // 数据库或者默认字体中 有就加入字体文件中
213
- let fontFamily = this.THREEFontMap.get(fontType);
214
-
215
- // 创建 three 字体对象
216
- if (fontFamily) {
217
- //@ts-ignore
218
- fontFamily.data.glyphs[fontName] = fontJson;
219
- }
220
- }
221
-
222
- // 执行相应的回调函数
223
- let origin_callbacks = this._loadTextCall.get(`${fontType}_${fontName}`) || [];
224
-
225
- // // 删除待执行的回调
226
- this._loadTextCall.delete(`${fontType}_${fontName}`);
227
-
228
- origin_callbacks.map(callback => {
229
-
230
- // 执行任务队列
231
- threeUtils.addWork(callback);
232
- });
233
- }
234
-
235
- // 判断是否有这个文字
236
- hasFont({ fontType, fontName }: { fontType: string, fontName: string }) {
237
- return !isEmpty(
238
- this.THREEFontMap.get(fontType) &&
239
- //@ts-ignore
240
- this.THREEFontMap.get(fontType).data.glyphs[fontName]
241
- );
242
- }
243
-
244
- // 这个方法是提供给外部字体文件调用的
245
- addFont({ fontType = "simhei", fontName, fontJson }: saveFontParam) {
246
-
247
- // 保存字体json到本地数据中
248
- this.saveFont({ fontType, fontName, fontJson });
249
-
250
- let fontFamily = this.THREEFontMap.get(fontType);
251
-
252
- // 创建 three 字体对象
253
- if (fontFamily) {
254
- //@ts-ignore
255
- fontFamily.data.glyphs[fontName] = fontJson;
256
- }
257
- }
258
-
259
- // 这个方法是提供给外部字体文件调用的
260
- addFontFamily({ fontType = "simhei", fontFamilyJson }: addFontFamilyParam) {
261
-
262
- // 保存字体初始结构到数据库中
263
- this.saveFont({ fontType, fontName: "index", fontJson: fontFamilyJson });
264
-
265
- let fontFamily = this.THREEFontMap.get(fontType);
266
-
267
- // 创建 three 字体对象
268
- if (fontFamily) {
269
- //@ts-ignore
270
- fontFamily.data = {
271
- ...fontFamilyJson,
272
- //@ts-ignore
273
- glyphs: fontFamily.data.glyphs
274
- }
275
- }
276
-
277
- }
278
-
279
- }
280
-
281
- const fontContorller = new fontContorl();
282
-
283
- Object.assign(window, { fontContorller });
284
-
285
- export default fontContorller;