three-base 2.0.74 → 2.0.76

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 (83) hide show
  1. package/ApngTexture.d.ts +13 -13
  2. package/ApngTexture.js +61 -61
  3. package/ApngTextureManage.d.ts +18 -18
  4. package/ApngTextureManage.js +87 -87
  5. package/EventMesh.d.ts +18 -18
  6. package/EventMesh.js +59 -59
  7. package/ExtrudeMesh.d.ts +111 -111
  8. package/ExtrudeMesh.js +363 -363
  9. package/FPScontrol.d.ts +45 -45
  10. package/FPScontrol.js +171 -171
  11. package/Fire/Fire.d.ts +28 -28
  12. package/Fire/Fire.js +79 -79
  13. package/Fire/FireGromtry.d.ts +9 -9
  14. package/Fire/FireGromtry.js +40 -40
  15. package/Fire/FireMaterial.d.ts +28 -28
  16. package/Fire/FireMaterial.js +32 -32
  17. package/InstancedMeshBase.d.ts +32 -32
  18. package/InstancedMeshBase.js +234 -236
  19. package/InstancedMeshBase.ts +1 -4
  20. package/KeyFrameAnimation.d.ts +25 -25
  21. package/KeyFrameAnimation.js +78 -78
  22. package/MeshBase.d.ts +34 -34
  23. package/MeshBase.js +187 -185
  24. package/MeshBase.ts +15 -13
  25. package/Mirror.d.ts +25 -25
  26. package/Mirror.js +139 -139
  27. package/PlaneModal1/PlaneModal1.d.ts +31 -31
  28. package/PlaneModal1/PlaneModal1.js +105 -105
  29. package/PlaneModal1/index.d.ts +1 -1
  30. package/PlaneModal1/index.js +1 -1
  31. package/PlaneText.d.ts +44 -44
  32. package/PlaneText.js +30 -30
  33. package/PlaneWithHtml.d.ts +11 -11
  34. package/PlaneWithHtml.js +68 -68
  35. package/PointLight/PointLight.d.ts +13 -13
  36. package/PointLight/PointLight.js +64 -64
  37. package/PointLight/index.d.ts +1 -1
  38. package/PointLight/index.js +1 -1
  39. package/Sky/Sky.d.ts +13 -13
  40. package/Sky/Sky.js +28 -28
  41. package/Sky/index.d.ts +1 -1
  42. package/Sky/index.js +1 -1
  43. package/SpriteModal1/SpriteModal1.d.ts +30 -30
  44. package/SpriteModal1/SpriteModal1.js +110 -110
  45. package/SpriteModal1/index.d.ts +1 -1
  46. package/SpriteModal1/index.js +1 -1
  47. package/SpriteText.d.ts +45 -45
  48. package/SpriteText.js +163 -163
  49. package/SpriteText2.d.ts +47 -47
  50. package/SpriteText2.js +198 -198
  51. package/SpriteWithHtml.d.ts +7 -7
  52. package/SpriteWithHtml.js +49 -49
  53. package/Text3D/Text3D.d.ts +20 -20
  54. package/Text3D/Text3D.js +62 -62
  55. package/Text3D/fontController.d.ts +59 -59
  56. package/Text3D/fontController.js +200 -200
  57. package/Text3D/index.d.ts +1 -1
  58. package/Text3D/index.js +1 -1
  59. package/ThreeBase.d.ts +92 -92
  60. package/ThreeBase.js +619 -619
  61. package/ThreeMouse.d.ts +39 -39
  62. package/ThreeMouse.js +359 -359
  63. package/Transition.d.ts +40 -40
  64. package/Transition.js +207 -207
  65. package/index.d.ts +1 -1
  66. package/index.js +2 -2
  67. package/keyContorls.d.ts +25 -25
  68. package/keyContorls.js +98 -98
  69. package/package.json +1 -1
  70. package/pass/FullScreenQuad.d.ts +7 -7
  71. package/pass/FullScreenQuad.js +25 -25
  72. package/pass/glow_pass.d.ts +2 -2
  73. package/pass/glow_pass.js +236 -236
  74. package/pass/stroke_pass.d.ts +2 -2
  75. package/pass/stroke_pass.js +202 -202
  76. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  77. package/shaders/FXAAShaderMaterial.js +21 -21
  78. package/shaders.d.ts +17 -17
  79. package/shaders.js +99 -99
  80. package/threeLoader.d.ts +26 -26
  81. package/threeLoader.js +189 -189
  82. package/threeUtils.d.ts +47 -47
  83. package/threeUtils.js +266 -266
package/Text3D/Text3D.js CHANGED
@@ -1,62 +1,62 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2022-06-14 09:48:00
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2023-04-07 21:52:03
6
- */
7
- import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry.js';
8
- import { Mesh, MeshStandardMaterial } from "three";
9
- import fontContorller from "./fontController";
10
- // 3D文字模型
11
- export default class Text3D extends Mesh {
12
- constructor(text = "new Text3D()") {
13
- super();
14
- this.setText({ text });
15
- }
16
- // 字体的存储路径 例如 : "http://drm.gitee.io/three-base-font/simhei/字.js"
17
- static path = "//www.3dkeshihua.com/three-base-font/";
18
- material = new MeshStandardMaterial({
19
- metalness: 1, // 金属度,值为0到1
20
- roughness: 0.5, // 粗糙度,值为0到1
21
- });
22
- // 配置
23
- _config = {
24
- text: "",
25
- fontType: "simhei",
26
- size: 1,
27
- curveSegments: 10,
28
- height: 0.1, // 文字的厚度
29
- bevelEnabled: true, // 斜角开启
30
- bevelThickness: 0.02, // 斜角厚度
31
- bevelSize: 0.015, // 斜角大小
32
- bevelOffset: 0, // 斜角偏移
33
- bevelSegments: 3, //斜角分段
34
- };
35
- // 设置文字
36
- setText(text3DProps) {
37
- if (Object.keys(text3DProps).some(key => text3DProps[key] !== this._config[key])) {
38
- Object.assign(this._config, text3DProps);
39
- fontContorller.loadText({
40
- fontBasePath: Text3D.path,
41
- text: this._config.text,
42
- fontType: this._config.fontType,
43
- callback: THREEFont => {
44
- this.geometry.dispose();
45
- this.geometry = new TextGeometry(this._config.text || "", {
46
- font: THREEFont,
47
- size: this._config.size,
48
- curveSegments: this._config.curveSegments,
49
- height: this._config.height, // 文字的厚度
50
- bevelEnabled: this._config.bevelEnabled, // 斜角开启
51
- bevelThickness: this._config.bevelThickness, // 斜角厚度
52
- bevelSize: this._config.bevelSize, // 斜角大小
53
- bevelOffset: this._config.bevelOffset, // 斜角偏移
54
- bevelSegments: this._config.bevelSegments, //斜角分段
55
- });
56
- this.geometry.center();
57
- this.dispatchEvent({ type: "loaded" });
58
- }
59
- });
60
- }
61
- }
62
- }
1
+ /*
2
+ * @Author: xiaosihan
3
+ * @Date: 2022-06-14 09:48:00
4
+ * @Last Modified by: xiaosihan
5
+ * @Last Modified time: 2023-04-07 21:52:03
6
+ */
7
+ import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry.js';
8
+ import { Mesh, MeshStandardMaterial } from "three";
9
+ import fontContorller from "./fontController";
10
+ // 3D文字模型
11
+ export default class Text3D extends Mesh {
12
+ constructor(text = "new Text3D()") {
13
+ super();
14
+ this.setText({ text });
15
+ }
16
+ // 字体的存储路径 例如 : "http://drm.gitee.io/three-base-font/simhei/字.js"
17
+ static path = "//www.3dkeshihua.com/three-base-font/";
18
+ material = new MeshStandardMaterial({
19
+ metalness: 1,
20
+ roughness: 0.5, // 粗糙度,值为0到1
21
+ });
22
+ // 配置
23
+ _config = {
24
+ text: "",
25
+ fontType: "simhei",
26
+ size: 1,
27
+ curveSegments: 10,
28
+ height: 0.1,
29
+ bevelEnabled: true,
30
+ bevelThickness: 0.02,
31
+ bevelSize: 0.015,
32
+ bevelOffset: 0,
33
+ bevelSegments: 3, //斜角分段
34
+ };
35
+ // 设置文字
36
+ setText(text3DProps) {
37
+ if (Object.keys(text3DProps).some(key => text3DProps[key] !== this._config[key])) {
38
+ Object.assign(this._config, text3DProps);
39
+ fontContorller.loadText({
40
+ fontBasePath: Text3D.path,
41
+ text: this._config.text,
42
+ fontType: this._config.fontType,
43
+ callback: THREEFont => {
44
+ this.geometry.dispose();
45
+ this.geometry = new TextGeometry(this._config.text || "", {
46
+ font: THREEFont,
47
+ size: this._config.size,
48
+ curveSegments: this._config.curveSegments,
49
+ height: this._config.height,
50
+ bevelEnabled: this._config.bevelEnabled,
51
+ bevelThickness: this._config.bevelThickness,
52
+ bevelSize: this._config.bevelSize,
53
+ bevelOffset: this._config.bevelOffset,
54
+ bevelSegments: this._config.bevelSegments, //斜角分段
55
+ });
56
+ this.geometry.center();
57
+ this.dispatchEvent({ type: "loaded" });
58
+ }
59
+ });
60
+ }
61
+ }
62
+ }
@@ -1,59 +1,59 @@
1
- import Dexie, { Table } from "dexie";
2
- import { Font } from "three/examples/jsm/loaders/FontLoader.js";
3
- export type saveFontParam = {
4
- fontType?: string;
5
- fontName: string;
6
- fontJson: any;
7
- };
8
- export type addFontFamilyParam = {
9
- fontType?: string;
10
- fontFamilyJson: any;
11
- };
12
- export type getFontParam = {
13
- fontType?: string;
14
- fontName: string;
15
- };
16
- export type loadTextParam = {
17
- fontBasePath: string;
18
- fontType?: string;
19
- text?: string;
20
- callback?: (font: Font) => void;
21
- };
22
- declare class indexBD extends Dexie {
23
- constructor(dbName: string);
24
- threeFont: Table;
25
- }
26
- declare class fontContorl {
27
- constructor();
28
- THREEFontMap: Map<string, Font>;
29
- fontBD: indexBD;
30
- /**
31
- * 保存 字体json到本地数据库中
32
- * @param {saveFontParam} { fontType = "simhei", fontName, fontJson }
33
- * @memberof fontContorl
34
- */
35
- saveFont({ fontType, fontName, fontJson }: saveFontParam): Promise<void>;
36
- /**
37
- * 通过 fontType 和 fontName 查询 fontJson
38
- * @param {getFontParam} { fontType = "simhei", fontName }
39
- * @returns
40
- * @memberof fontContorl
41
- */
42
- getFont({ fontType, fontName }: getFontParam): Promise<any>;
43
- _loadTextCall: Map<string, Array<() => void>>;
44
- loadText({ fontType, text, fontBasePath, callback }: loadTextParam): Promise<void>;
45
- _loadFontIndexJson({ fontType, fontBasePath }: loadTextParam): Promise<void>;
46
- _loadFontJson({ fontType, fontName, fontBasePath }: {
47
- fontType: string;
48
- fontName: string;
49
- fontBasePath: string;
50
- }): Promise<void>;
51
- hasFont({ fontType, fontName }: {
52
- fontType: string;
53
- fontName: string;
54
- }): boolean;
55
- addFont({ fontType, fontName, fontJson }: saveFontParam): void;
56
- addFontFamily({ fontType, fontFamilyJson }: addFontFamilyParam): void;
57
- }
58
- declare const fontContorller: fontContorl;
59
- export default fontContorller;
1
+ import Dexie, { Table } from "dexie";
2
+ import { Font } from "three/examples/jsm/loaders/FontLoader.js";
3
+ export type saveFontParam = {
4
+ fontType?: string;
5
+ fontName: string;
6
+ fontJson: any;
7
+ };
8
+ export type addFontFamilyParam = {
9
+ fontType?: string;
10
+ fontFamilyJson: any;
11
+ };
12
+ export type getFontParam = {
13
+ fontType?: string;
14
+ fontName: string;
15
+ };
16
+ export type loadTextParam = {
17
+ fontBasePath: string;
18
+ fontType?: string;
19
+ text?: string;
20
+ callback?: (font: Font) => void;
21
+ };
22
+ declare class indexBD extends Dexie {
23
+ constructor(dbName: string);
24
+ threeFont: Table;
25
+ }
26
+ declare class fontContorl {
27
+ constructor();
28
+ THREEFontMap: Map<string, Font>;
29
+ fontBD: indexBD;
30
+ /**
31
+ * 保存 字体json到本地数据库中
32
+ * @param {saveFontParam} { fontType = "simhei", fontName, fontJson }
33
+ * @memberof fontContorl
34
+ */
35
+ saveFont({ fontType, fontName, fontJson }: saveFontParam): Promise<void>;
36
+ /**
37
+ * 通过 fontType 和 fontName 查询 fontJson
38
+ * @param {getFontParam} { fontType = "simhei", fontName }
39
+ * @returns
40
+ * @memberof fontContorl
41
+ */
42
+ getFont({ fontType, fontName }: getFontParam): Promise<any>;
43
+ _loadTextCall: Map<string, Array<() => void>>;
44
+ loadText({ fontType, text, fontBasePath, callback }: loadTextParam): Promise<void>;
45
+ _loadFontIndexJson({ fontType, fontBasePath }: loadTextParam): Promise<void>;
46
+ _loadFontJson({ fontType, fontName, fontBasePath }: {
47
+ fontType: string;
48
+ fontName: string;
49
+ fontBasePath: string;
50
+ }): Promise<void>;
51
+ hasFont({ fontType, fontName }: {
52
+ fontType: string;
53
+ fontName: string;
54
+ }): boolean;
55
+ addFont({ fontType, fontName, fontJson }: saveFontParam): void;
56
+ addFontFamily({ fontType, fontFamilyJson }: addFontFamilyParam): void;
57
+ }
58
+ declare const fontContorller: fontContorl;
59
+ export default fontContorller;
@@ -1,200 +1,200 @@
1
- /*
2
- * @Author: xiaosihan
3
- * @Date: 2021-04-15 00:34:44
4
- * @Last Modified by: xiaosihan
5
- * @Last Modified time: 2022-06-08 14:33:45
6
- */
7
- import Dexie from "dexie";
8
- import { filter, first, isEmpty } from "lodash";
9
- import { Font } from "three/examples/jsm/loaders/FontLoader.js";
10
- import threeUtils from "../threeUtils";
11
- import gentilisJSON from "./gentilis.json";
12
- class indexBD extends Dexie {
13
- constructor(dbName) {
14
- super(dbName);
15
- }
16
- threeFont;
17
- }
18
- // 字体加载器
19
- class fontContorl {
20
- constructor() { }
21
- THREEFontMap = new Map();
22
- // 专门存储字体的数据库
23
- fontBD = (() => {
24
- let fontDB = new indexBD("three-base-font");
25
- fontDB.version(1).stores({ threeFont: "++KeyPath,fontType,fontName,fontJson" });
26
- return fontDB;
27
- })();
28
- /**
29
- * 保存 字体json到本地数据库中
30
- * @param {saveFontParam} { fontType = "simhei", fontName, fontJson }
31
- * @memberof fontContorl
32
- */
33
- async saveFont({ fontType = "simhei", fontName, fontJson = "" }) {
34
- let findResult = await this.getFont({ fontType, fontName });
35
- if (isEmpty(findResult)) {
36
- await this.fontBD.threeFont.add({ fontType, fontName, fontJson });
37
- }
38
- }
39
- /**
40
- * 通过 fontType 和 fontName 查询 fontJson
41
- * @param {getFontParam} { fontType = "simhei", fontName }
42
- * @returns
43
- * @memberof fontContorl
44
- */
45
- async getFont({ fontType = "simhei", fontName }) {
46
- let fondResult = await this.fontBD.threeFont
47
- .filter(d => (d.fontType === fontType && d.fontName === fontName))
48
- .toArray();
49
- if (isEmpty(fondResult)) {
50
- return undefined;
51
- }
52
- else {
53
- return first(fondResult).fontJson;
54
- }
55
- }
56
- // 加载字体的回调函数们
57
- _loadTextCall = new Map();
58
- // 加载文字 提供给需要创建字体模型的方法使用 以节流的形式调用 回调函数
59
- async loadText({ fontType = "simhei", text = "", fontBasePath, callback }) {
60
- // 加载字体容器
61
- await this._loadFontIndexJson({ fontType, fontBasePath });
62
- let newCallback = () => {
63
- let fontFamily = this.THREEFontMap.get(fontType);
64
- if (callback && fontFamily) {
65
- callback(fontFamily);
66
- }
67
- };
68
- // 遍历文本
69
- filter(text).map(fontName => {
70
- // 没有的就去加载
71
- if (!this.hasFont({ fontType, fontName })) {
72
- // 添加文字的默认模型 避免报错
73
- let fontFamily = this.THREEFontMap.get(fontType);
74
- // 创建 three 字体对象
75
- if (fontFamily) {
76
- //@ts-ignore
77
- 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 " };
78
- }
79
- this._loadFontJson({ fontType, fontName, fontBasePath });
80
- }
81
- // 加入待执行的回调
82
- let origin_callbacks = this._loadTextCall.get(`${fontType}_${fontName}`) || [];
83
- if (newCallback) {
84
- this._loadTextCall.set(`${fontType}_${fontName}`, [...origin_callbacks, newCallback]);
85
- }
86
- });
87
- // 执行任务队列
88
- threeUtils.addWork(newCallback);
89
- }
90
- // 加载字体
91
- async _loadFontIndexJson({ fontType = "simhei", fontBasePath }) {
92
- let fontFamily = this.THREEFontMap.get(fontType);
93
- // 创建 three 字体对象
94
- if (!fontFamily) {
95
- // 初始字体结构
96
- fontFamily = new Font({
97
- "underlineThickness": 69,
98
- "underlinePosition": -174,
99
- "resolution": 1000,
100
- "original_font_information": {},
101
- "familyName": "Source Han Sans CN Normal",
102
- "descender": -167,
103
- "cssFontWeight": "normal",
104
- "cssFontStyle": "normal",
105
- "boundingBox": {
106
- "yMin": -700,
107
- "xMin": -1389,
108
- "yMax": 700,
109
- "xMax": 4067
110
- },
111
- "glyphs": {}
112
- });
113
- this.THREEFontMap.set(fontType, fontFamily);
114
- // 读取本地数据库中的字体初始结构文件
115
- let fontFamilyIndexJson = await this.getFont({ fontType, fontName: "index" });
116
- // 加载外部字体初始结构文件
117
- if (!fontFamilyIndexJson) {
118
- this._loadFontJson({ fontType, fontName: "index", fontBasePath });
119
- }
120
- }
121
- }
122
- // 加载外部字体.js
123
- async _loadFontJson({ fontType = "simhei", fontName, fontBasePath }) {
124
- let fontJson = await this.getFont({ fontType, fontName });
125
- if (!fontJson) {
126
- fontJson = gentilisJSON.glyphs[fontName];
127
- }
128
- // 数据库中没有 就去加载字体js
129
- if (!fontJson) {
130
- // 加载字体js
131
- await new Promise(resolve => {
132
- let script = document.createElement("script");
133
- Object.assign(script, {
134
- type: "text/javascript",
135
- src: `${fontBasePath}${fontType}/${fontName}.js`,
136
- async: true,
137
- onload: () => {
138
- script.remove();
139
- resolve();
140
- },
141
- onerror: () => {
142
- }
143
- });
144
- document.head.appendChild(script);
145
- });
146
- }
147
- else {
148
- // 数据库或者默认字体中 有就加入字体文件中
149
- let fontFamily = this.THREEFontMap.get(fontType);
150
- // 创建 three 字体对象
151
- if (fontFamily) {
152
- //@ts-ignore
153
- fontFamily.data.glyphs[fontName] = fontJson;
154
- }
155
- }
156
- // 执行相应的回调函数
157
- let origin_callbacks = this._loadTextCall.get(`${fontType}_${fontName}`) || [];
158
- // // 删除待执行的回调
159
- this._loadTextCall.delete(`${fontType}_${fontName}`);
160
- origin_callbacks.map(callback => {
161
- // 执行任务队列
162
- threeUtils.addWork(callback);
163
- });
164
- }
165
- // 判断是否有这个文字
166
- hasFont({ fontType, fontName }) {
167
- return !isEmpty(this.THREEFontMap.get(fontType) &&
168
- //@ts-ignore
169
- this.THREEFontMap.get(fontType).data.glyphs[fontName]);
170
- }
171
- // 这个方法是提供给外部字体文件调用的
172
- addFont({ fontType = "simhei", fontName, fontJson }) {
173
- // 保存字体json到本地数据中
174
- this.saveFont({ fontType, fontName, fontJson });
175
- let fontFamily = this.THREEFontMap.get(fontType);
176
- // 创建 three 字体对象
177
- if (fontFamily) {
178
- //@ts-ignore
179
- fontFamily.data.glyphs[fontName] = fontJson;
180
- }
181
- }
182
- // 这个方法是提供给外部字体文件调用的
183
- addFontFamily({ fontType = "simhei", fontFamilyJson }) {
184
- // 保存字体初始结构到数据库中
185
- this.saveFont({ fontType, fontName: "index", fontJson: fontFamilyJson });
186
- let fontFamily = this.THREEFontMap.get(fontType);
187
- // 创建 three 字体对象
188
- if (fontFamily) {
189
- //@ts-ignore
190
- fontFamily.data = {
191
- ...fontFamilyJson,
192
- //@ts-ignore
193
- glyphs: fontFamily.data.glyphs
194
- };
195
- }
196
- }
197
- }
198
- const fontContorller = new fontContorl();
199
- Object.assign(window, { fontContorller });
200
- export default fontContorller;
1
+ /*
2
+ * @Author: xiaosihan
3
+ * @Date: 2021-04-15 00:34:44
4
+ * @Last Modified by: xiaosihan
5
+ * @Last Modified time: 2022-06-08 14:33:45
6
+ */
7
+ import Dexie from "dexie";
8
+ import { filter, first, isEmpty } from "lodash";
9
+ import { Font } from "three/examples/jsm/loaders/FontLoader.js";
10
+ import threeUtils from "../threeUtils";
11
+ import gentilisJSON from "./gentilis.json";
12
+ class indexBD extends Dexie {
13
+ constructor(dbName) {
14
+ super(dbName);
15
+ }
16
+ threeFont;
17
+ }
18
+ // 字体加载器
19
+ class fontContorl {
20
+ constructor() { }
21
+ THREEFontMap = new Map();
22
+ // 专门存储字体的数据库
23
+ fontBD = (() => {
24
+ let fontDB = new indexBD("three-base-font");
25
+ fontDB.version(1).stores({ threeFont: "++KeyPath,fontType,fontName,fontJson" });
26
+ return fontDB;
27
+ })();
28
+ /**
29
+ * 保存 字体json到本地数据库中
30
+ * @param {saveFontParam} { fontType = "simhei", fontName, fontJson }
31
+ * @memberof fontContorl
32
+ */
33
+ async saveFont({ fontType = "simhei", fontName, fontJson = "" }) {
34
+ let findResult = await this.getFont({ fontType, fontName });
35
+ if (isEmpty(findResult)) {
36
+ await this.fontBD.threeFont.add({ fontType, fontName, fontJson });
37
+ }
38
+ }
39
+ /**
40
+ * 通过 fontType 和 fontName 查询 fontJson
41
+ * @param {getFontParam} { fontType = "simhei", fontName }
42
+ * @returns
43
+ * @memberof fontContorl
44
+ */
45
+ async getFont({ fontType = "simhei", fontName }) {
46
+ let fondResult = await this.fontBD.threeFont
47
+ .filter(d => (d.fontType === fontType && d.fontName === fontName))
48
+ .toArray();
49
+ if (isEmpty(fondResult)) {
50
+ return undefined;
51
+ }
52
+ else {
53
+ return first(fondResult).fontJson;
54
+ }
55
+ }
56
+ // 加载字体的回调函数们
57
+ _loadTextCall = new Map();
58
+ // 加载文字 提供给需要创建字体模型的方法使用 以节流的形式调用 回调函数
59
+ async loadText({ fontType = "simhei", text = "", fontBasePath, callback }) {
60
+ // 加载字体容器
61
+ await this._loadFontIndexJson({ fontType, fontBasePath });
62
+ let newCallback = () => {
63
+ let fontFamily = this.THREEFontMap.get(fontType);
64
+ if (callback && fontFamily) {
65
+ callback(fontFamily);
66
+ }
67
+ };
68
+ // 遍历文本
69
+ filter(text).map(fontName => {
70
+ // 没有的就去加载
71
+ if (!this.hasFont({ fontType, fontName })) {
72
+ // 添加文字的默认模型 避免报错
73
+ let fontFamily = this.THREEFontMap.get(fontType);
74
+ // 创建 three 字体对象
75
+ if (fontFamily) {
76
+ //@ts-ignore
77
+ 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 " };
78
+ }
79
+ this._loadFontJson({ fontType, fontName, fontBasePath });
80
+ }
81
+ // 加入待执行的回调
82
+ let origin_callbacks = this._loadTextCall.get(`${fontType}_${fontName}`) || [];
83
+ if (newCallback) {
84
+ this._loadTextCall.set(`${fontType}_${fontName}`, [...origin_callbacks, newCallback]);
85
+ }
86
+ });
87
+ // 执行任务队列
88
+ threeUtils.addWork(newCallback);
89
+ }
90
+ // 加载字体
91
+ async _loadFontIndexJson({ fontType = "simhei", fontBasePath }) {
92
+ let fontFamily = this.THREEFontMap.get(fontType);
93
+ // 创建 three 字体对象
94
+ if (!fontFamily) {
95
+ // 初始字体结构
96
+ fontFamily = new Font({
97
+ "underlineThickness": 69,
98
+ "underlinePosition": -174,
99
+ "resolution": 1000,
100
+ "original_font_information": {},
101
+ "familyName": "Source Han Sans CN Normal",
102
+ "descender": -167,
103
+ "cssFontWeight": "normal",
104
+ "cssFontStyle": "normal",
105
+ "boundingBox": {
106
+ "yMin": -700,
107
+ "xMin": -1389,
108
+ "yMax": 700,
109
+ "xMax": 4067
110
+ },
111
+ "glyphs": {}
112
+ });
113
+ this.THREEFontMap.set(fontType, fontFamily);
114
+ // 读取本地数据库中的字体初始结构文件
115
+ let fontFamilyIndexJson = await this.getFont({ fontType, fontName: "index" });
116
+ // 加载外部字体初始结构文件
117
+ if (!fontFamilyIndexJson) {
118
+ this._loadFontJson({ fontType, fontName: "index", fontBasePath });
119
+ }
120
+ }
121
+ }
122
+ // 加载外部字体.js
123
+ async _loadFontJson({ fontType = "simhei", fontName, fontBasePath }) {
124
+ let fontJson = await this.getFont({ fontType, fontName });
125
+ if (!fontJson) {
126
+ fontJson = gentilisJSON.glyphs[fontName];
127
+ }
128
+ // 数据库中没有 就去加载字体js
129
+ if (!fontJson) {
130
+ // 加载字体js
131
+ await new Promise(resolve => {
132
+ let script = document.createElement("script");
133
+ Object.assign(script, {
134
+ type: "text/javascript",
135
+ src: `${fontBasePath}${fontType}/${fontName}.js`,
136
+ async: true,
137
+ onload: () => {
138
+ script.remove();
139
+ resolve();
140
+ },
141
+ onerror: () => {
142
+ }
143
+ });
144
+ document.head.appendChild(script);
145
+ });
146
+ }
147
+ else {
148
+ // 数据库或者默认字体中 有就加入字体文件中
149
+ let fontFamily = this.THREEFontMap.get(fontType);
150
+ // 创建 three 字体对象
151
+ if (fontFamily) {
152
+ //@ts-ignore
153
+ fontFamily.data.glyphs[fontName] = fontJson;
154
+ }
155
+ }
156
+ // 执行相应的回调函数
157
+ let origin_callbacks = this._loadTextCall.get(`${fontType}_${fontName}`) || [];
158
+ // // 删除待执行的回调
159
+ this._loadTextCall.delete(`${fontType}_${fontName}`);
160
+ origin_callbacks.map(callback => {
161
+ // 执行任务队列
162
+ threeUtils.addWork(callback);
163
+ });
164
+ }
165
+ // 判断是否有这个文字
166
+ hasFont({ fontType, fontName }) {
167
+ return !isEmpty(this.THREEFontMap.get(fontType) &&
168
+ //@ts-ignore
169
+ this.THREEFontMap.get(fontType).data.glyphs[fontName]);
170
+ }
171
+ // 这个方法是提供给外部字体文件调用的
172
+ addFont({ fontType = "simhei", fontName, fontJson }) {
173
+ // 保存字体json到本地数据中
174
+ this.saveFont({ fontType, fontName, fontJson });
175
+ let fontFamily = this.THREEFontMap.get(fontType);
176
+ // 创建 three 字体对象
177
+ if (fontFamily) {
178
+ //@ts-ignore
179
+ fontFamily.data.glyphs[fontName] = fontJson;
180
+ }
181
+ }
182
+ // 这个方法是提供给外部字体文件调用的
183
+ addFontFamily({ fontType = "simhei", fontFamilyJson }) {
184
+ // 保存字体初始结构到数据库中
185
+ this.saveFont({ fontType, fontName: "index", fontJson: fontFamilyJson });
186
+ let fontFamily = this.THREEFontMap.get(fontType);
187
+ // 创建 three 字体对象
188
+ if (fontFamily) {
189
+ //@ts-ignore
190
+ fontFamily.data = {
191
+ ...fontFamilyJson,
192
+ //@ts-ignore
193
+ glyphs: fontFamily.data.glyphs
194
+ };
195
+ }
196
+ }
197
+ }
198
+ const fontContorller = new fontContorl();
199
+ Object.assign(window, { fontContorller });
200
+ export default fontContorller;
package/Text3D/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default } from "./Text3D";
1
+ export { default } from "./Text3D";
package/Text3D/index.js CHANGED
@@ -1 +1 @@
1
- export { default } from "./Text3D";
1
+ export { default } from "./Text3D";