three-base 1.129.1 → 1.129.4
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/index.js +34 -0
- package/index.ts +5 -1
- package/lib/ApngTexture.d.ts +13 -0
- package/lib/{ApngTexture.ts → ApngTexture.js} +11 -41
- package/lib/ApngTextureManage.d.ts +18 -0
- package/lib/{ApngTextureManage.ts → ApngTextureManage.js} +13 -56
- package/lib/EventMesh.d.ts +18 -0
- package/lib/EventMesh.js +59 -0
- package/lib/ExtrudeMesh.d.ts +111 -0
- package/lib/{ExtrudeMesh.ts → ExtrudeMesh.js} +77 -284
- package/lib/FPScontrol.d.ts +44 -0
- package/lib/{FPScontrol.ts → FPScontrol.js} +25 -64
- package/lib/InstancedGroupMesh.d.ts +10 -0
- package/lib/InstancedGroupMesh.js +63 -0
- package/lib/KeyFrameAnimation.d.ts +25 -0
- package/lib/{KeyFrameAnimation.ts → KeyFrameAnimation.js} +19 -63
- package/lib/PlaneText.d.ts +37 -0
- package/lib/{PlaneText.ts → PlaneText.js} +5 -34
- package/lib/PointLight.d.ts +13 -0
- package/lib/{PointLight.ts → PointLight.js} +4 -18
- package/lib/Sky/Sky.d.ts +13 -0
- package/lib/Sky/{Sky.ts → Sky.js} +4 -12
- package/lib/Text3D/Text3D.d.ts +20 -0
- package/lib/Text3D/Text3D.js +60 -0
- package/lib/Text3D/fontController.d.ts +59 -0
- package/lib/Text3D/fontController.js +200 -0
- package/lib/Text3D/gentilis.json +811 -0
- package/lib/ThreeBase.d.ts +59 -0
- package/lib/{ThreeBase.ts → ThreeBase.js} +75 -131
- package/lib/ThreeMouse.d.ts +39 -0
- package/lib/{ThreeMouse.ts → ThreeMouse.js} +61 -168
- package/lib/Transition.d.ts +45 -0
- package/lib/{Transition.ts → Transition.js} +30 -101
- package/lib/index.d.ts +22 -0
- package/lib/keyContorls.d.ts +25 -0
- package/lib/{keyContorls.ts → keyContorls.js} +11 -40
- package/lib/planeModal1/PlaneModal1.d.ts +32 -0
- package/lib/planeModal1/{PlaneModal1.ts → PlaneModal1.js} +33 -77
- package/lib/shaders.d.ts +17 -0
- package/lib/{shaders.ts → shaders.js} +19 -38
- package/lib/spriteModal1/SpriteModal1.d.ts +31 -0
- package/lib/spriteModal1/{SpriteModal1.ts → SpriteModal1.js} +33 -80
- package/lib/threeLoader.d.ts +20 -0
- package/lib/{threeLoader.ts → threeLoader.js} +19 -45
- package/lib/threeUtils.d.ts +41 -0
- package/lib/{threeUtils.ts → threeUtils.js} +81 -82
- package/lib/type.d.ts +0 -0
- package/lib/{type.ts → type.js} +1 -4
- package/package.json +7 -6
- package/declare.d.ts +0 -5
- package/lib/EventMesh.ts +0 -79
- package/lib/InstancedGroupMesh.ts +0 -80
- package/lib/text/Text2D.ts +0 -41
- package/lib/text/Text3D.ts +0 -20
|
@@ -4,21 +4,15 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-06-22 19:44:23
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import threeUtils from "./threeUtils";
|
|
9
|
-
|
|
10
|
-
function bezier(arr: [number, number, number, number], t: number) {
|
|
8
|
+
function bezier(arr, t) {
|
|
11
9
|
const ut = 1 - t;
|
|
12
10
|
const a1 = arr[1] * ut + arr[2] * t;
|
|
13
11
|
const result = ((arr[0] * ut + arr[1] * t) * ut + a1 * t) * ut + (a1 * ut + (arr[2] * ut + arr[3] * t) * t) * t;
|
|
14
12
|
return result;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
interface TParam { [key: string]: number }
|
|
18
|
-
|
|
19
14
|
// 过渡动画插件
|
|
20
15
|
export default class Transition {
|
|
21
|
-
|
|
22
16
|
/**
|
|
23
17
|
*Creates an instance of transition.
|
|
24
18
|
* @param {{ [key: string]: number }} // 初始值
|
|
@@ -26,100 +20,71 @@ export default class Transition {
|
|
|
26
20
|
* @param {number} [duration=1000] // 过渡时间
|
|
27
21
|
* @memberof transition
|
|
28
22
|
*/
|
|
29
|
-
constructor(
|
|
30
|
-
param: TParam = {},
|
|
31
|
-
bezier: [number, number, number, number] = [0.8, 0, 0.2, 1],
|
|
32
|
-
duration = 500
|
|
33
|
-
) {
|
|
34
|
-
|
|
23
|
+
constructor(param = {}, bezier = [0.8, 0, 0.2, 1], duration = 500) {
|
|
35
24
|
this.setDuration(duration);
|
|
36
|
-
|
|
37
25
|
this.setBezier(bezier);
|
|
38
|
-
|
|
39
26
|
this.set(param);
|
|
40
27
|
}
|
|
41
|
-
|
|
42
28
|
// 所有的 key 的枚举
|
|
43
|
-
_keys
|
|
44
|
-
|
|
29
|
+
_keys = [];
|
|
45
30
|
// 贝塞尔曲线
|
|
46
|
-
_bezier
|
|
47
|
-
|
|
31
|
+
_bezier = [0.8, 0, 0.2, 1];
|
|
48
32
|
// x轴贝塞尔
|
|
49
|
-
_Xbezier
|
|
50
|
-
|
|
33
|
+
_Xbezier = [0, 0.8, 0.2, 1];
|
|
51
34
|
// y轴贝塞尔
|
|
52
|
-
_Ybezier
|
|
53
|
-
|
|
54
|
-
setBezier(bezier: [number, number, number, number] = [0.8, 0, 0.2, 1]): this {
|
|
35
|
+
_Ybezier = [0, 0, 1, 1];
|
|
36
|
+
setBezier(bezier = [0.8, 0, 0.2, 1]) {
|
|
55
37
|
this._bezier = [...bezier];
|
|
56
38
|
this._Xbezier = [0, bezier[0], bezier[2], 1];
|
|
57
39
|
this._Ybezier = [0, bezier[1], bezier[3], 1];
|
|
58
40
|
return this;
|
|
59
41
|
}
|
|
60
|
-
|
|
61
42
|
// 当前时间戳
|
|
62
43
|
timeTemp = performance.now();
|
|
63
|
-
|
|
64
44
|
// 过渡时间
|
|
65
45
|
_duration = 0;
|
|
66
|
-
|
|
67
46
|
//延时
|
|
68
47
|
_delay = 0;
|
|
69
|
-
|
|
70
48
|
// 设置过渡时间
|
|
71
|
-
setDuration(duration = 500)
|
|
49
|
+
setDuration(duration = 500) {
|
|
72
50
|
this._duration = duration;
|
|
73
51
|
return this;
|
|
74
52
|
}
|
|
75
|
-
|
|
76
53
|
// 设置延时
|
|
77
54
|
setDelay(delay = 0) {
|
|
78
55
|
this._delay = delay;
|
|
79
56
|
return this;
|
|
80
57
|
}
|
|
81
|
-
|
|
82
58
|
// 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
|
|
83
|
-
_
|
|
84
|
-
|
|
85
|
-
onChangeCall?: (josn: { [key: string]: number }) => void;
|
|
86
|
-
|
|
59
|
+
_ = {};
|
|
60
|
+
onChangeCall;
|
|
87
61
|
// 执行过度动画
|
|
88
|
-
run({ timeTemp }
|
|
62
|
+
run({ timeTemp }) {
|
|
89
63
|
this.timeTemp = timeTemp;
|
|
90
64
|
if (!this.onChangeCall || this.isDone()) {
|
|
91
65
|
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
92
|
-
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
93
68
|
this.onChangeCall(this.getJson());
|
|
94
69
|
}
|
|
95
70
|
return this;
|
|
96
71
|
}
|
|
97
|
-
|
|
98
72
|
runbindThis = this.run.bind(this);
|
|
99
|
-
|
|
100
73
|
// 设置动画对象的回调事件
|
|
101
|
-
onChange(onChangeCall
|
|
74
|
+
onChange(onChangeCall) {
|
|
102
75
|
this.onChangeCall = onChangeCall;
|
|
103
76
|
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
104
77
|
return this;
|
|
105
78
|
}
|
|
106
|
-
|
|
107
79
|
// 计算当前 key 的值
|
|
108
|
-
get(key
|
|
109
|
-
|
|
80
|
+
get(key) {
|
|
110
81
|
key = String(key);
|
|
111
|
-
|
|
112
82
|
if (this._keys.includes(key) && this.timeTemp < (this._[key + "_startTime"] + this._duration)) {
|
|
113
|
-
|
|
114
83
|
let start = this._[key + "_start"];
|
|
115
|
-
|
|
116
84
|
let end = this._[key + "_end"];
|
|
117
|
-
|
|
118
85
|
let timeProgress = Math.min(1, Math.max(0, (this.timeTemp - this._[key + "_startTime"]) / this._duration));
|
|
119
|
-
|
|
120
86
|
// 斜率
|
|
121
87
|
let t = 0;
|
|
122
|
-
|
|
123
88
|
// 微分法 求斜率t
|
|
124
89
|
while (bezier(this._Xbezier, t + 0.1) < timeProgress) {
|
|
125
90
|
t += 0.1;
|
|
@@ -130,135 +95,99 @@ export default class Transition {
|
|
|
130
95
|
while (bezier(this._Xbezier, t + 0.001) < timeProgress) {
|
|
131
96
|
t += 0.001;
|
|
132
97
|
}
|
|
133
|
-
|
|
134
|
-
t = Math.min(1, Math.max(0, t)) // 斜率最大为1
|
|
135
|
-
|
|
98
|
+
t = Math.min(1, Math.max(0, t)); // 斜率最大为1
|
|
136
99
|
// 通过斜率求y值
|
|
137
100
|
return (bezier(this._Ybezier, t) * (end - start)) + start;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
101
|
+
}
|
|
102
|
+
else if (this._keys.includes(key) && this.timeTemp >= (this._[key + "_startTime"] + this._duration)) {
|
|
141
103
|
return this._[key + "_end"];
|
|
142
104
|
}
|
|
143
|
-
|
|
144
105
|
// `没有 ${key} 的值`;
|
|
145
106
|
return 0;
|
|
146
107
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let timetemp = performance.now() + this._delay;;
|
|
151
|
-
|
|
108
|
+
async set(param) {
|
|
109
|
+
let timetemp = performance.now() + this._delay;
|
|
110
|
+
;
|
|
152
111
|
for (let key in param) {
|
|
153
|
-
|
|
154
112
|
// 有就赋值
|
|
155
113
|
if (this._keys.includes(key) && Math.abs(param[key] - this._[key + "_end"]) > 0.001) {
|
|
156
|
-
|
|
157
114
|
this._[key + "_start"] = this.get(key);
|
|
158
|
-
|
|
159
115
|
this._[key + "_end"] = param[key];
|
|
160
116
|
// 起始时间
|
|
161
117
|
this._[key + "_startTime"] = timetemp;
|
|
162
|
-
|
|
163
118
|
// 执行状态未完成
|
|
164
119
|
this._isDone = false;
|
|
165
|
-
|
|
166
120
|
// 没有就添加一个
|
|
167
|
-
}
|
|
168
|
-
|
|
121
|
+
}
|
|
122
|
+
else if (!this._keys.includes(key)) {
|
|
169
123
|
this._[key + "_start"] = param[key];
|
|
170
|
-
|
|
171
124
|
this._[key + "_end"] = param[key];
|
|
172
125
|
// 起始时间
|
|
173
126
|
this._[key + "_startTime"] = timetemp - this._duration;
|
|
174
|
-
|
|
175
127
|
// 执行状态未完成
|
|
176
128
|
this._isDone = false;
|
|
177
129
|
}
|
|
178
|
-
|
|
179
130
|
if (!this._keys.includes(key)) {
|
|
180
131
|
this._keys.push(key);
|
|
181
132
|
}
|
|
182
|
-
|
|
183
133
|
// // 执行状态未完成
|
|
184
134
|
// this._isDone = false;
|
|
185
|
-
|
|
186
135
|
}
|
|
187
|
-
|
|
188
136
|
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
189
137
|
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
190
|
-
|
|
191
138
|
if (!this._isDone) {
|
|
192
139
|
await new Promise(resolve => setTimeout(resolve, this._duration + 50));
|
|
193
140
|
}
|
|
194
|
-
|
|
195
141
|
return this;
|
|
196
142
|
}
|
|
197
143
|
// 重置起始和终止位置
|
|
198
|
-
reset(param
|
|
199
|
-
|
|
144
|
+
reset(param) {
|
|
200
145
|
for (let key in param) {
|
|
201
146
|
this._[key + "_start"] = param[key];
|
|
202
147
|
this._[key + "_end"] = param[key];
|
|
203
148
|
this._[key + "_startTime"] = -this._duration;
|
|
204
149
|
}
|
|
205
|
-
|
|
206
150
|
if (this.onChangeCall) {
|
|
207
151
|
this.onChangeCall(this.getJson());
|
|
208
152
|
}
|
|
209
|
-
|
|
210
153
|
this._isDone = true;
|
|
211
154
|
return this;
|
|
212
155
|
}
|
|
213
|
-
|
|
214
156
|
// 获取过渡对象上面的key
|
|
215
|
-
getKeys()
|
|
157
|
+
getKeys() {
|
|
216
158
|
return [...this._keys];
|
|
217
159
|
}
|
|
218
|
-
|
|
219
160
|
// 判断是否有这个参数
|
|
220
|
-
hasKey(key
|
|
161
|
+
hasKey(key) {
|
|
221
162
|
return this._keys.includes(key);
|
|
222
163
|
}
|
|
223
|
-
|
|
224
164
|
// 获取全部参数
|
|
225
|
-
getJson()
|
|
165
|
+
getJson() {
|
|
226
166
|
let keys = this.getKeys();
|
|
227
|
-
|
|
228
|
-
let json: { [key: string]: number } = {};
|
|
229
|
-
|
|
167
|
+
let json = {};
|
|
230
168
|
keys.map(key => {
|
|
231
169
|
json[key] = this.get(key);
|
|
232
170
|
});
|
|
233
171
|
return json;
|
|
234
172
|
}
|
|
235
|
-
|
|
236
173
|
_isDone = false;
|
|
237
|
-
|
|
238
174
|
// 是否执行完成了
|
|
239
|
-
isDone()
|
|
240
|
-
|
|
175
|
+
isDone() {
|
|
241
176
|
if (this._isDone) {
|
|
242
177
|
return true;
|
|
243
178
|
}
|
|
244
|
-
|
|
245
179
|
let isisDone = false;
|
|
246
|
-
|
|
247
180
|
for (let i in this._keys) {
|
|
248
|
-
|
|
249
181
|
isisDone = this._[this._keys[i] + "_startTime"] + this._duration < this.timeTemp;
|
|
250
|
-
|
|
251
182
|
// 只要有一个没有完成 都算没有完成 过渡
|
|
252
183
|
if (!isisDone) {
|
|
253
184
|
return false;
|
|
254
185
|
}
|
|
255
186
|
}
|
|
256
|
-
|
|
257
187
|
if (!this._isDone) {
|
|
258
188
|
this._isDone = true;
|
|
259
189
|
return false;
|
|
260
190
|
}
|
|
261
|
-
|
|
262
191
|
return true;
|
|
263
192
|
}
|
|
264
|
-
}
|
|
193
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { default } from "./lib/ThreeBase";
|
|
2
|
+
export { default as EventMesh } from "./lib/EventMesh";
|
|
3
|
+
export { default as ExtrudeMesh } from "./lib/ExtrudeMesh";
|
|
4
|
+
export type { ExtrudePath } from "./lib/ExtrudeMesh";
|
|
5
|
+
export type { ExtrudeMeshProps } from "./lib/ExtrudeMesh";
|
|
6
|
+
export { default as KeyFrameAnimation } from "./lib/KeyFrameAnimation";
|
|
7
|
+
export type { KeyframeAnimationProps } from "./lib/KeyFrameAnimation";
|
|
8
|
+
export type { Keyframe } from "./lib/KeyFrameAnimation";
|
|
9
|
+
export { default as InstancedGroupMesh } from "./lib/InstancedGroupMesh";
|
|
10
|
+
export { default as PointLight } from "./lib/PointLight";
|
|
11
|
+
export { default as Sky } from "./lib/Sky/Sky";
|
|
12
|
+
export { default as keyContorls } from "./lib/keyContorls";
|
|
13
|
+
export { default as Transition } from "./lib/Transition";
|
|
14
|
+
export { default as threeUtils } from "./lib/threeUtils";
|
|
15
|
+
export { default as threeLoader } from "./lib/threeLoader";
|
|
16
|
+
export { default as FPScontrol } from "./lib/FPScontrol";
|
|
17
|
+
export { default as PlaneText } from "./lib/PlaneText";
|
|
18
|
+
export { default as SpriteText } from "three-spritetext";
|
|
19
|
+
export { default as SpriteModal1 } from "./lib/spriteModal1/SpriteModal1";
|
|
20
|
+
export { default as PlaneModal1 } from "./lib/planeModal1/PlaneModal1";
|
|
21
|
+
export { default as Text3D } from "./lib/Text3D/Text3D";
|
|
22
|
+
export type { Text3DProps } from "./lib/Text3D/Text3D";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Event, EventDispatcher, Vector3 } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* 键盘 使用 ↑↓←→ 控制 x z 方向, 小键盘 1 0 控制 y 方向
|
|
4
|
+
*
|
|
5
|
+
* @class KeyContorls
|
|
6
|
+
* @extends {EventDispatcher}
|
|
7
|
+
*/
|
|
8
|
+
declare class KeyContorls extends EventDispatcher {
|
|
9
|
+
constructor();
|
|
10
|
+
uuid: string;
|
|
11
|
+
direction: Vector3;
|
|
12
|
+
add(e: any): void;
|
|
13
|
+
delete(e: any): void;
|
|
14
|
+
enter(e: any): void;
|
|
15
|
+
keyDown: (e: any) => void;
|
|
16
|
+
_listeners?: {
|
|
17
|
+
[key: string]: Array<any>;
|
|
18
|
+
};
|
|
19
|
+
removeEvent: import("lodash").DebouncedFunc<(type: string) => void>;
|
|
20
|
+
addEventListener(type: string, listener: (event: Event) => void): void;
|
|
21
|
+
addEvent(): void;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
24
|
+
declare const keyContorls: KeyContorls;
|
|
25
|
+
export default keyContorls;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2022-03-20 14:48:33
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-03-20 14:48:33
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2022-09-30 00:12:28
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { throttle } from "lodash";
|
|
9
|
-
import {
|
|
8
|
+
import { EventDispatcher, Vector3 } from "three";
|
|
10
9
|
import { generateUUID } from "three/src/math/MathUtils";
|
|
11
|
-
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* 键盘 使用 ↑↓←→ 控制 x z 方向, 小键盘 1 0 控制 y 方向
|
|
15
12
|
*
|
|
@@ -17,57 +14,44 @@ import { generateUUID } from "three/src/math/MathUtils";
|
|
|
17
14
|
* @extends {EventDispatcher}
|
|
18
15
|
*/
|
|
19
16
|
class KeyContorls extends EventDispatcher {
|
|
20
|
-
|
|
21
17
|
constructor() {
|
|
22
18
|
super();
|
|
23
19
|
this.addEvent();
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
uuid = generateUUID();
|
|
27
|
-
|
|
28
22
|
direction = new Vector3(0, 0, 0);
|
|
29
|
-
|
|
30
23
|
// 添加事件需要由外部实现
|
|
31
|
-
add(e
|
|
24
|
+
add(e) {
|
|
32
25
|
this.dispatchEvent({ ...e, type: "add" });
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
// 删除事件
|
|
36
|
-
delete(e
|
|
28
|
+
delete(e) {
|
|
37
29
|
this.dispatchEvent({ ...e, type: "delete" });
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
// 回车按钮
|
|
41
|
-
enter(e
|
|
32
|
+
enter(e) {
|
|
42
33
|
this.dispatchEvent({ ...e, type: "enter" });
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
keyDown = (e: any) => {
|
|
46
|
-
|
|
35
|
+
keyDown = (e) => {
|
|
47
36
|
switch (e.keyCode) {
|
|
48
|
-
|
|
49
37
|
case 46: // 删除按钮
|
|
50
38
|
this.delete(e);
|
|
51
39
|
return;
|
|
52
|
-
|
|
53
40
|
case 13: // 回车按钮
|
|
54
41
|
this.enter(e);
|
|
55
42
|
return;
|
|
56
|
-
|
|
57
43
|
case 97: // 小键盘1
|
|
58
44
|
this.direction.set(0, 1, 0);
|
|
59
45
|
break;
|
|
60
46
|
case 96: // 小键盘0
|
|
61
47
|
this.direction.set(0, -1, 0);
|
|
62
48
|
break;
|
|
63
|
-
|
|
64
49
|
case 35: //
|
|
65
50
|
this.direction.set(0, 0.001, 0);
|
|
66
51
|
break;
|
|
67
52
|
case 45:
|
|
68
53
|
this.direction.set(0, -0.001, 0);
|
|
69
54
|
break;
|
|
70
|
-
|
|
71
55
|
case 38: // 前
|
|
72
56
|
this.direction.set(0, 0, -1);
|
|
73
57
|
break;
|
|
@@ -80,48 +64,35 @@ class KeyContorls extends EventDispatcher {
|
|
|
80
64
|
case 39: // 右
|
|
81
65
|
this.direction.set(1, 0, 0);
|
|
82
66
|
break;
|
|
83
|
-
|
|
84
67
|
default:
|
|
85
68
|
return;
|
|
86
69
|
}
|
|
87
|
-
|
|
88
70
|
if (e.shiftKey) {
|
|
89
71
|
this.direction.multiplyScalar(0.001);
|
|
90
72
|
}
|
|
91
|
-
|
|
92
73
|
if (e.ctrlKey) {
|
|
93
74
|
this.direction.multiplyScalar(0.1);
|
|
94
75
|
}
|
|
95
|
-
|
|
96
76
|
this.dispatchEvent({
|
|
97
77
|
type: "change",
|
|
98
78
|
direction: this.direction
|
|
99
79
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
_listeners?: { [key: string]: Array<any> };
|
|
104
|
-
|
|
80
|
+
};
|
|
81
|
+
_listeners;
|
|
105
82
|
// 节流 删除事件监听
|
|
106
|
-
removeEvent = throttle((type
|
|
83
|
+
removeEvent = throttle((type) => {
|
|
107
84
|
this._listeners = undefined;
|
|
108
85
|
}, 1000, { trailing: false });
|
|
109
|
-
|
|
110
|
-
addEventListener(type: string, listener: (event: Event) => void): void {
|
|
86
|
+
addEventListener(type, listener) {
|
|
111
87
|
this.removeEvent(type);
|
|
112
88
|
super.addEventListener(type, listener);
|
|
113
89
|
}
|
|
114
|
-
|
|
115
90
|
addEvent() {
|
|
116
91
|
document.addEventListener("keydown", this.keyDown);
|
|
117
92
|
}
|
|
118
|
-
|
|
119
93
|
dispose() {
|
|
120
94
|
document.removeEventListener("keydown", this.keyDown);
|
|
121
95
|
}
|
|
122
|
-
|
|
123
96
|
}
|
|
124
|
-
|
|
125
97
|
const keyContorls = new KeyContorls();
|
|
126
|
-
|
|
127
98
|
export default keyContorls;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MeshBasicMaterial, Mesh, CanvasTexture, PlaneGeometry } from "three";
|
|
2
|
+
export type PlaneModal1Config = {
|
|
3
|
+
size?: number;
|
|
4
|
+
title?: string;
|
|
5
|
+
titleColor?: string;
|
|
6
|
+
texts?: Array<{
|
|
7
|
+
text?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
size?: number;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
export default class PlaneModal1 extends Mesh {
|
|
13
|
+
constructor(config?: PlaneModal1Config);
|
|
14
|
+
renderOrder: number;
|
|
15
|
+
geometry: PlaneGeometry;
|
|
16
|
+
material: MeshBasicMaterial;
|
|
17
|
+
static img: HTMLImageElement;
|
|
18
|
+
canvas: HTMLCanvasElement;
|
|
19
|
+
context: CanvasRenderingContext2D;
|
|
20
|
+
texture: CanvasTexture;
|
|
21
|
+
_config: {
|
|
22
|
+
size: number;
|
|
23
|
+
title: string;
|
|
24
|
+
titleColor: string;
|
|
25
|
+
texts: Array<{
|
|
26
|
+
text: string;
|
|
27
|
+
color: string;
|
|
28
|
+
size: number;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
updata(config: PlaneModal1Config): Promise<void>;
|
|
32
|
+
}
|
|
@@ -1,129 +1,89 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-03-09 18:51:11
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-03-09 18:51:11
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-03-09 19:15:35
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import { MeshBasicMaterial, Mesh, DoubleSide, CanvasTexture, Vector2, BufferGeometry, PlaneGeometry } from "three";
|
|
7
|
+
import { MeshBasicMaterial, Mesh, DoubleSide, CanvasTexture, Vector2, PlaneGeometry } from "three";
|
|
9
8
|
import planeModalPNG from "./planeModal.png";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export type PlaneModal1Config = {
|
|
13
|
-
size?: number,
|
|
14
|
-
title?: string,
|
|
15
|
-
titleColor?: string,
|
|
16
|
-
texts?: Array<{
|
|
17
|
-
text?: string,
|
|
18
|
-
color?: string,
|
|
19
|
-
size?: number
|
|
20
|
-
}>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
9
|
// 平面模型弹窗
|
|
24
10
|
export default class PlaneModal1 extends Mesh {
|
|
25
|
-
|
|
26
|
-
constructor(config: PlaneModal1Config = {}) {
|
|
11
|
+
constructor(config = {}) {
|
|
27
12
|
super();
|
|
28
13
|
this.updata(config);
|
|
29
14
|
this.material.map = this.texture;
|
|
30
15
|
this.scale.set(10, 10, 10);
|
|
31
16
|
}
|
|
32
|
-
|
|
17
|
+
renderOrder = 99;
|
|
33
18
|
geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
|
|
34
|
-
|
|
35
19
|
material = new MeshBasicMaterial({
|
|
36
20
|
side: DoubleSide,
|
|
37
|
-
transparent: true
|
|
21
|
+
transparent: true,
|
|
22
|
+
alphaTest: 0.01
|
|
38
23
|
});
|
|
39
|
-
|
|
40
24
|
// 背景图
|
|
41
25
|
static img = (() => {
|
|
42
26
|
const img = new Image();
|
|
43
27
|
img.src = planeModalPNG;
|
|
44
28
|
return img;
|
|
45
29
|
})();
|
|
46
|
-
|
|
47
30
|
canvas = (() => {
|
|
48
31
|
const canvas = document.createElement("canvas");
|
|
49
32
|
canvas.width = 660;
|
|
50
33
|
canvas.height = 481;
|
|
51
34
|
return canvas;
|
|
52
35
|
})();
|
|
53
|
-
|
|
54
|
-
context = this.canvas.getContext("2d")!;
|
|
55
|
-
|
|
36
|
+
context = this.canvas.getContext("2d");
|
|
56
37
|
texture = new CanvasTexture(this.canvas);
|
|
57
|
-
|
|
58
38
|
// 配置
|
|
59
|
-
_config
|
|
60
|
-
size:
|
|
61
|
-
title:
|
|
62
|
-
titleColor:
|
|
63
|
-
texts:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// {
|
|
80
|
-
// text: "2",
|
|
81
|
-
// color: "#ff00ff",
|
|
82
|
-
// size: 40
|
|
83
|
-
// },
|
|
84
|
-
// ]
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async updata(config: PlaneModal1Config) {
|
|
88
|
-
|
|
89
|
-
Object.assign(this._config, config)
|
|
90
|
-
|
|
39
|
+
_config = {
|
|
40
|
+
size: 10,
|
|
41
|
+
title: "PlaneModal1",
|
|
42
|
+
titleColor: "#ffffff",
|
|
43
|
+
texts: []
|
|
44
|
+
// [
|
|
45
|
+
// {
|
|
46
|
+
// text: "1",
|
|
47
|
+
// color: "#ffff00",
|
|
48
|
+
// size: 40
|
|
49
|
+
// },
|
|
50
|
+
// {
|
|
51
|
+
// text: "2",
|
|
52
|
+
// color: "#ff00ff",
|
|
53
|
+
// size: 40
|
|
54
|
+
// },
|
|
55
|
+
// ]
|
|
56
|
+
};
|
|
57
|
+
async updata(config) {
|
|
58
|
+
Object.assign(this._config, config);
|
|
91
59
|
//绘制背景
|
|
92
60
|
this.context.clearRect(0, 0, 660, 481);
|
|
93
|
-
|
|
94
61
|
while (!PlaneModal1.img.complete) {
|
|
95
62
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
96
63
|
}
|
|
97
|
-
|
|
98
64
|
// 设置大小
|
|
99
65
|
this.scale.set(this._config.size, this._config.size, this._config.size);
|
|
100
|
-
|
|
101
66
|
// this.context.fillStyle = "#00000088";
|
|
102
67
|
// this.context.fillRect(0, 0, 660, 481);
|
|
103
|
-
|
|
104
68
|
//绘制背景
|
|
105
69
|
this.context.drawImage(PlaneModal1.img, 0, 0);
|
|
106
|
-
|
|
107
70
|
// 绘制标题
|
|
108
71
|
this.context.fillStyle = this._config.titleColor;
|
|
109
|
-
this.context.font = '40px serif'
|
|
72
|
+
this.context.font = '40px serif'; // 设置字体大小
|
|
110
73
|
this.context.textAlign = "left";
|
|
111
74
|
this.context.textBaseline = "top";
|
|
112
75
|
this.context.fillText(this._config.title, 60, 72);
|
|
113
|
-
|
|
114
76
|
let textPos = new Vector2(60, 150);
|
|
115
77
|
let maxWidth = 530;
|
|
116
78
|
// 绘制内容
|
|
117
79
|
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
118
80
|
this.context.fillStyle = color;
|
|
119
|
-
this.context.font = `${size}px serif
|
|
81
|
+
this.context.font = `${size}px serif`; // 设置字体大小
|
|
120
82
|
this.context.textAlign = "left";
|
|
121
83
|
this.context.textBaseline = "top";
|
|
122
|
-
|
|
123
84
|
// 字符分隔为数组
|
|
124
85
|
var arrText = text.split('');
|
|
125
86
|
var line = '';
|
|
126
|
-
|
|
127
87
|
for (var n = 0; n < arrText.length; n++) {
|
|
128
88
|
var metrics = this.context.measureText(line + arrText[n]);
|
|
129
89
|
var testWidth = metrics.width;
|
|
@@ -131,18 +91,14 @@ export default class PlaneModal1 extends Mesh {
|
|
|
131
91
|
this.context.fillText(line, textPos.x, textPos.y);
|
|
132
92
|
line = "";
|
|
133
93
|
textPos.y += size;
|
|
134
|
-
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
135
96
|
line += arrText[n];
|
|
136
97
|
}
|
|
137
98
|
}
|
|
138
|
-
|
|
139
99
|
this.context.fillText(line, textPos.x, textPos.y);
|
|
140
100
|
textPos.y += size;
|
|
141
101
|
});
|
|
142
|
-
|
|
143
102
|
this.texture.needsUpdate = true;
|
|
144
|
-
|
|
145
103
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
104
|
+
}
|