three-base 1.0.62 → 1.0.64

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 (47) hide show
  1. package/lib/ApngTexture.js +61 -0
  2. package/lib/ApngTextureManage.js +87 -0
  3. package/lib/EventMesh.js +59 -0
  4. package/lib/ExtrudeMesh.js +362 -0
  5. package/lib/FPScontrol.js +170 -0
  6. package/lib/InstancedGroupMesh.js +63 -0
  7. package/lib/KeyFrameAnimation.js +78 -0
  8. package/lib/PlaneText.js +30 -0
  9. package/lib/PointLight.js +64 -0
  10. package/lib/Sky/Sky.js +28 -0
  11. package/lib/Text3D/Text3D.js +61 -0
  12. package/lib/Text3D/Text3D.ts +3 -3
  13. package/lib/Text3D/fontController.js +200 -0
  14. package/lib/ThreeBase.js +393 -0
  15. package/lib/ThreeMouse.js +357 -0
  16. package/lib/Transition.js +193 -0
  17. package/lib/index.d.ts +22 -0
  18. package/lib/keyContorls.js +98 -0
  19. package/lib/lib/ApngTexture.d.ts +13 -0
  20. package/lib/lib/ApngTextureManage.d.ts +18 -0
  21. package/lib/lib/EventMesh.d.ts +18 -0
  22. package/lib/lib/ExtrudeMesh.d.ts +111 -0
  23. package/lib/lib/FPScontrol.d.ts +44 -0
  24. package/lib/lib/InstancedGroupMesh.d.ts +10 -0
  25. package/lib/lib/KeyFrameAnimation.d.ts +25 -0
  26. package/lib/lib/PlaneText.d.ts +37 -0
  27. package/lib/lib/PointLight.d.ts +13 -0
  28. package/lib/lib/Sky/Sky.d.ts +13 -0
  29. package/lib/lib/Text3D/Text3D.d.ts +20 -0
  30. package/lib/lib/Text3D/fontController.d.ts +59 -0
  31. package/lib/lib/ThreeBase.d.ts +59 -0
  32. package/lib/lib/ThreeMouse.d.ts +39 -0
  33. package/lib/lib/Transition.d.ts +45 -0
  34. package/lib/lib/keyContorls.d.ts +25 -0
  35. package/lib/lib/planeModal1/PlaneModal1.d.ts +32 -0
  36. package/lib/lib/shaders.d.ts +17 -0
  37. package/lib/lib/spriteModal1/SpriteModal1.d.ts +31 -0
  38. package/lib/lib/threeLoader.d.ts +20 -0
  39. package/lib/lib/threeUtils.d.ts +41 -0
  40. package/lib/lib/type.d.ts +0 -0
  41. package/lib/planeModal1/PlaneModal1.js +104 -0
  42. package/lib/shaders.js +245 -0
  43. package/lib/spriteModal1/SpriteModal1.js +109 -0
  44. package/lib/threeLoader.js +110 -0
  45. package/lib/threeUtils.js +179 -0
  46. package/lib/type.js +10 -0
  47. package/package.json +1 -1
@@ -0,0 +1,357 @@
1
+ //
2
+ //
3
+ //
4
+ //
5
+ //
6
+ // 启动鼠标事件
7
+ import * as THREE from "three";
8
+ import { Raycaster } from "three";
9
+ import { debounce } from "lodash";
10
+ /**
11
+ * harp.gl 专用的鼠标拾取模型对象
12
+ */
13
+ export default class ThreeMouse {
14
+ constructor(renderer, camera, scene) {
15
+ this._renderer = renderer;
16
+ this._camera = camera;
17
+ this._scene = scene;
18
+ this._frame = this._renderer.info.render.frame;
19
+ this._renderer.domElement.addEventListener("mouseenter", () => { this._mouseInRenderer = true; }, true); //鼠标进入开启拾取
20
+ this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
21
+ this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
22
+ this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
23
+ this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
24
+ }
25
+ // 渲染器
26
+ _renderer;
27
+ _camera;
28
+ _scene;
29
+ // 鼠标在渲染器上面的位置
30
+ _mosePosition = new THREE.Vector2(0, 0);
31
+ // 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
32
+ _mouseDownPosition = new THREE.Vector2(0, 0);
33
+ //当前鼠标指针上的对象
34
+ _mesh_on;
35
+ //鼠标按下的对象
36
+ _mesh_Down;
37
+ //射线拾取器
38
+ _raycaster = new Raycaster();
39
+ // 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
40
+ _frame = 0;
41
+ //鼠标是否在渲染器上
42
+ _mouseInRenderer = false;
43
+ // 鼠标滑动的事件
44
+ _mousemoveEvent;
45
+ // 需要被拾取的对象数组
46
+ _object3ds = [];
47
+ // 点击次数
48
+ _click_num = 0;
49
+ // 获取拾取到的对象
50
+ _getSelected(object3ds) {
51
+ let intersection;
52
+ if (object3ds.length) {
53
+ intersection = this._raycaster.intersectObjects(object3ds, false)[0];
54
+ }
55
+ return intersection;
56
+ }
57
+ ;
58
+ // 判断对象上面是否有事件
59
+ hasEvent(object, types = []) {
60
+ if (!object) {
61
+ return false;
62
+ }
63
+ // 如果 启用事件为关闭的话就不执行事件
64
+ if (object["userData"] && object["userData"]["enableEvent"] === false) {
65
+ return false;
66
+ }
67
+ const hasevent = types.some(type => {
68
+ //@ts-ignore
69
+ if (object["_listeners"] && object["_listeners"][type] && object["_listeners"][type][0]) {
70
+ return true;
71
+ }
72
+ // if (object["userData"] && object["userData"]["cursor"]) {
73
+ // return true;
74
+ // }
75
+ return false;
76
+ });
77
+ return hasevent;
78
+ }
79
+ // 判断对象上是否有鼠标样式
80
+ hasCursor(object) {
81
+ if (!object) {
82
+ return false;
83
+ }
84
+ // 如果 启用事件为关闭的话就不执行事件
85
+ if (object["userData"] && object["userData"]["enableEvent"] === false) {
86
+ return false;
87
+ }
88
+ if (object["userData"] && object["userData"]["cursor"]) {
89
+ return true;
90
+ }
91
+ }
92
+ // 分发鼠标拾取事件
93
+ dispatchEvent() {
94
+ // 提取有事件的对象
95
+ const meshs = [];
96
+ this._scene.traverseVisible(mesh => {
97
+ // 判断对象是否有指定的事件
98
+ if (this.hasCursor(mesh) || this.hasEvent(mesh, ["leftclick", "rightclick", "click", "dbclick", "mouseenter", "mouseleave", "mousemove", "mousedown", "mouseup"])) {
99
+ meshs.push(mesh);
100
+ }
101
+ });
102
+ this._object3ds = meshs;
103
+ // 没有鼠标事件就不往下执行了
104
+ if (!this._mousemoveEvent || !this._mouseInRenderer) {
105
+ return;
106
+ }
107
+ // 拾取模型
108
+ let intersection = this._getSelected(meshs);
109
+ if (intersection) {
110
+ const MouseEvent = Object.assign(intersection, {
111
+ renderer: this._renderer,
112
+ camera: this._camera,
113
+ object: intersection.object,
114
+ type: this._mousemoveEvent.type,
115
+ offsetX: this._mousemoveEvent.offsetX,
116
+ offsetY: this._mousemoveEvent.offsetY,
117
+ x: this._mousemoveEvent.x,
118
+ y: this._mousemoveEvent.y
119
+ });
120
+ // 触发滑动事件
121
+ if (this._mesh_on === MouseEvent.object) {
122
+ if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
123
+ MouseEvent.type = "mousemove";
124
+ MouseEvent.object.dispatchEvent(MouseEvent);
125
+ }
126
+ // 鼠标划入滑出事件
127
+ }
128
+ else if (this._mesh_on !== MouseEvent.object) {
129
+ if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
130
+ MouseEvent.type = "mouseleave";
131
+ this._mesh_on.dispatchEvent(MouseEvent);
132
+ }
133
+ if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
134
+ MouseEvent.type = "mouseenter";
135
+ MouseEvent.object.dispatchEvent(MouseEvent);
136
+ }
137
+ }
138
+ this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
139
+ // 鼠标样式
140
+ if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
141
+ this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
142
+ }
143
+ else {
144
+ this._renderer.domElement.style.cursor = "auto";
145
+ }
146
+ }
147
+ else {
148
+ if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
149
+ // 鼠标离开事件
150
+ this._mesh_on.dispatchEvent({
151
+ renderer: this._renderer,
152
+ camera: this._camera,
153
+ object: this._mesh_on,
154
+ type: "mouseleave",
155
+ offsetX: this._mousemoveEvent.offsetX,
156
+ offsetY: this._mousemoveEvent.offsetY,
157
+ x: this._mousemoveEvent.x,
158
+ y: this._mousemoveEvent.y
159
+ });
160
+ }
161
+ // 置空当前鼠标上面的对象
162
+ this._mesh_on = undefined;
163
+ this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
164
+ }
165
+ }
166
+ // 鼠标离开事件
167
+ _mouseleave = (e) => {
168
+ this._mouseInRenderer = false;
169
+ // 鼠标离开事件
170
+ if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
171
+ this._mesh_on.dispatchEvent({
172
+ renderer: this._renderer,
173
+ camera: this._camera,
174
+ object: this._mesh_on,
175
+ type: "mouseleave",
176
+ offsetX: this._mousemoveEvent.offsetX,
177
+ offsetY: this._mousemoveEvent.offsetY,
178
+ x: this._mousemoveEvent.x,
179
+ y: this._mousemoveEvent.y
180
+ });
181
+ }
182
+ // 置空当前鼠标上面的对象
183
+ this._mesh_on = undefined;
184
+ this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
185
+ };
186
+ // 鼠标滑动 设置鼠标位置
187
+ _mousemove = (e) => {
188
+ this._mousemoveEvent = e;
189
+ this._frame = this._renderer.info.render.frame;
190
+ if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
191
+ this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
192
+ }
193
+ else {
194
+ this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
195
+ this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
196
+ }
197
+ this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
198
+ };
199
+ // 鼠标按下事件
200
+ _mousedown = (e) => {
201
+ // 记录按下的位置
202
+ this._mouseDownPosition.set(e.offsetX, e.offsetY);
203
+ this._mousemove(e);
204
+ let intersection = this._getSelected(this._object3ds);
205
+ if (!intersection || !this._mousemoveEvent) {
206
+ return;
207
+ }
208
+ this._mesh_Down = this._mesh_on = intersection.object;
209
+ // 触发鼠标按下事件
210
+ if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
211
+ this._mesh_Down.dispatchEvent({
212
+ ...intersection,
213
+ renderer: this._renderer,
214
+ camera: this._camera,
215
+ object: intersection.object,
216
+ type: "mousedown",
217
+ offsetX: this._mousemoveEvent.offsetX,
218
+ offsetY: this._mousemoveEvent.offsetY,
219
+ x: this._mousemoveEvent.x,
220
+ y: this._mousemoveEvent.y
221
+ });
222
+ }
223
+ };
224
+ // 鼠标弹起事件
225
+ _mouseup = debounce(async (e) => {
226
+ // 提取有事件的对象
227
+ const meshs = [];
228
+ let intersection = this._getSelected(this._object3ds);
229
+ if (!intersection || !this._mousemoveEvent) {
230
+ return;
231
+ }
232
+ this._mesh_on = intersection.object;
233
+ if (this.hasEvent(this._mesh_Down, ["mouseup"])) {
234
+ this._mesh_on.dispatchEvent({
235
+ ...intersection,
236
+ renderer: this._renderer,
237
+ camera: this._camera,
238
+ object: intersection.object,
239
+ type: "mouseup",
240
+ offsetX: this._mousemoveEvent.offsetX,
241
+ offsetY: this._mousemoveEvent.offsetY,
242
+ x: this._mousemoveEvent.x,
243
+ y: this._mousemoveEvent.y
244
+ });
245
+ }
246
+ // 触发鼠标弹起事件
247
+ if (this._mesh_Down &&
248
+ this._mesh_Down === this._mesh_on &&
249
+ Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
250
+ Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
251
+ // 是否有双击事件
252
+ if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
253
+ this._click_num++;
254
+ await new Promise(resolve => setTimeout(resolve, 200));
255
+ // 只点击了一次
256
+ if (this._click_num === 1) {
257
+ if (this.hasEvent(this._mesh_Down, ["click"])) {
258
+ this._mesh_Down.dispatchEvent({
259
+ ...intersection,
260
+ renderer: this._renderer,
261
+ camera: this._camera,
262
+ object: intersection.object,
263
+ type: "click",
264
+ offsetX: this._mousemoveEvent.offsetX,
265
+ offsetY: this._mousemoveEvent.offsetY,
266
+ x: this._mousemoveEvent.x,
267
+ y: this._mousemoveEvent.y
268
+ });
269
+ }
270
+ if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
271
+ this._mesh_Down.dispatchEvent({
272
+ ...intersection,
273
+ renderer: this._renderer,
274
+ camera: this._camera,
275
+ object: intersection.object,
276
+ type: "leftclick",
277
+ offsetX: this._mousemoveEvent.offsetX,
278
+ offsetY: this._mousemoveEvent.offsetY,
279
+ x: this._mousemoveEvent.x,
280
+ y: this._mousemoveEvent.y
281
+ });
282
+ }
283
+ if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
284
+ this._mesh_Down.dispatchEvent({
285
+ ...intersection,
286
+ renderer: this._renderer,
287
+ camera: this._camera,
288
+ object: intersection.object,
289
+ type: "rightclick",
290
+ offsetX: this._mousemoveEvent.offsetX,
291
+ offsetY: this._mousemoveEvent.offsetY,
292
+ x: this._mousemoveEvent.x,
293
+ y: this._mousemoveEvent.y
294
+ });
295
+ }
296
+ }
297
+ else if (this._click_num > 1) {
298
+ if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
299
+ this._mesh_Down.dispatchEvent({
300
+ ...intersection,
301
+ renderer: this._renderer,
302
+ camera: this._camera,
303
+ object: intersection.object,
304
+ type: "dbclick",
305
+ offsetX: this._mousemoveEvent.offsetX,
306
+ offsetY: this._mousemoveEvent.offsetY,
307
+ x: this._mousemoveEvent.x,
308
+ y: this._mousemoveEvent.y
309
+ });
310
+ }
311
+ }
312
+ }
313
+ else {
314
+ if (this.hasEvent(this._mesh_Down, ["click"])) {
315
+ this._mesh_Down.dispatchEvent({
316
+ ...intersection,
317
+ renderer: this._renderer,
318
+ camera: this._camera,
319
+ object: intersection.object,
320
+ type: "click",
321
+ offsetX: this._mousemoveEvent.offsetX,
322
+ offsetY: this._mousemoveEvent.offsetY,
323
+ x: this._mousemoveEvent.x,
324
+ y: this._mousemoveEvent.y
325
+ });
326
+ }
327
+ if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
328
+ this._mesh_Down.dispatchEvent({
329
+ ...intersection,
330
+ renderer: this._renderer,
331
+ camera: this._camera,
332
+ object: intersection.object,
333
+ type: "leftclick",
334
+ offsetX: this._mousemoveEvent.offsetX,
335
+ offsetY: this._mousemoveEvent.offsetY,
336
+ x: this._mousemoveEvent.x,
337
+ y: this._mousemoveEvent.y
338
+ });
339
+ }
340
+ if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
341
+ this._mesh_Down.dispatchEvent({
342
+ ...intersection,
343
+ renderer: this._renderer,
344
+ camera: this._camera,
345
+ object: intersection.object,
346
+ type: "rightclick",
347
+ offsetX: this._mousemoveEvent.offsetX,
348
+ offsetY: this._mousemoveEvent.offsetY,
349
+ x: this._mousemoveEvent.x,
350
+ y: this._mousemoveEvent.y
351
+ });
352
+ }
353
+ }
354
+ this._click_num = 0;
355
+ }
356
+ });
357
+ }
@@ -0,0 +1,193 @@
1
+ /*
2
+ * @Author: xiaosihan
3
+ * @Date: 2021-04-10 02:44:01
4
+ * @Last Modified by: xiaosihan
5
+ * @Last Modified time: 2022-06-22 19:44:23
6
+ */
7
+ import threeUtils from "./threeUtils";
8
+ function bezier(arr, t) {
9
+ const ut = 1 - t;
10
+ const a1 = arr[1] * ut + arr[2] * t;
11
+ const result = ((arr[0] * ut + arr[1] * t) * ut + a1 * t) * ut + (a1 * ut + (arr[2] * ut + arr[3] * t) * t) * t;
12
+ return result;
13
+ }
14
+ // 过渡动画插件
15
+ export default class Transition {
16
+ /**
17
+ *Creates an instance of transition.
18
+ * @param {{ [key: string]: number }} // 初始值
19
+ * @param {[0.8, 0, 0.2, 1]} // 贝塞尔曲线
20
+ * @param {number} [duration=1000] // 过渡时间
21
+ * @memberof transition
22
+ */
23
+ constructor(param = {}, bezier = [0.8, 0, 0.2, 1], duration = 500) {
24
+ this.setDuration(duration);
25
+ this.setBezier(bezier);
26
+ this.set(param);
27
+ }
28
+ // 所有的 key 的枚举
29
+ _keys = [];
30
+ // 贝塞尔曲线
31
+ _bezier = [0.8, 0, 0.2, 1];
32
+ // x轴贝塞尔
33
+ _Xbezier = [0, 0.8, 0.2, 1];
34
+ // y轴贝塞尔
35
+ _Ybezier = [0, 0, 1, 1];
36
+ setBezier(bezier = [0.8, 0, 0.2, 1]) {
37
+ this._bezier = [...bezier];
38
+ this._Xbezier = [0, bezier[0], bezier[2], 1];
39
+ this._Ybezier = [0, bezier[1], bezier[3], 1];
40
+ return this;
41
+ }
42
+ // 当前时间戳
43
+ timeTemp = performance.now();
44
+ // 过渡时间
45
+ _duration = 0;
46
+ //延时
47
+ _delay = 0;
48
+ // 设置过渡时间
49
+ setDuration(duration = 500) {
50
+ this._duration = duration;
51
+ return this;
52
+ }
53
+ // 设置延时
54
+ setDelay(delay = 0) {
55
+ this._delay = delay;
56
+ return this;
57
+ }
58
+ // 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
59
+ _ = {};
60
+ onChangeCall;
61
+ // 执行过度动画
62
+ run({ timeTemp }) {
63
+ this.timeTemp = timeTemp;
64
+ if (!this.onChangeCall || this.isDone()) {
65
+ threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
66
+ }
67
+ else {
68
+ this.onChangeCall(this.getJson());
69
+ }
70
+ return this;
71
+ }
72
+ runbindThis = this.run.bind(this);
73
+ // 设置动画对象的回调事件
74
+ onChange(onChangeCall) {
75
+ this.onChangeCall = onChangeCall;
76
+ threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
77
+ return this;
78
+ }
79
+ // 计算当前 key 的值
80
+ get(key) {
81
+ key = String(key);
82
+ if (this._keys.includes(key) && this.timeTemp < (this._[key + "_startTime"] + this._duration)) {
83
+ let start = this._[key + "_start"];
84
+ let end = this._[key + "_end"];
85
+ let timeProgress = Math.min(1, Math.max(0, (this.timeTemp - this._[key + "_startTime"]) / this._duration));
86
+ // 斜率
87
+ let t = 0;
88
+ // 微分法 求斜率t
89
+ while (bezier(this._Xbezier, t + 0.1) < timeProgress) {
90
+ t += 0.1;
91
+ }
92
+ while (bezier(this._Xbezier, t + 0.01) < timeProgress) {
93
+ t += 0.01;
94
+ }
95
+ while (bezier(this._Xbezier, t + 0.001) < timeProgress) {
96
+ t += 0.001;
97
+ }
98
+ t = Math.min(1, Math.max(0, t)); // 斜率最大为1
99
+ // 通过斜率求y值
100
+ return (bezier(this._Ybezier, t) * (end - start)) + start;
101
+ }
102
+ else if (this._keys.includes(key) && this.timeTemp >= (this._[key + "_startTime"] + this._duration)) {
103
+ return this._[key + "_end"];
104
+ }
105
+ // `没有 ${key} 的值`;
106
+ return 0;
107
+ }
108
+ async set(param) {
109
+ let timetemp = performance.now() + this._delay;
110
+ ;
111
+ for (let key in param) {
112
+ // 有就赋值
113
+ if (this._keys.includes(key) && Math.abs(param[key] - this._[key + "_end"]) > 0.001) {
114
+ this._[key + "_start"] = this.get(key);
115
+ this._[key + "_end"] = param[key];
116
+ // 起始时间
117
+ this._[key + "_startTime"] = timetemp;
118
+ // 执行状态未完成
119
+ this._isDone = false;
120
+ // 没有就添加一个
121
+ }
122
+ else if (!this._keys.includes(key)) {
123
+ this._[key + "_start"] = param[key];
124
+ this._[key + "_end"] = param[key];
125
+ // 起始时间
126
+ this._[key + "_startTime"] = timetemp - this._duration;
127
+ // 执行状态未完成
128
+ this._isDone = false;
129
+ }
130
+ if (!this._keys.includes(key)) {
131
+ this._keys.push(key);
132
+ }
133
+ // // 执行状态未完成
134
+ // this._isDone = false;
135
+ }
136
+ threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
137
+ threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
138
+ if (!this._isDone) {
139
+ await new Promise(resolve => setTimeout(resolve, this._duration + 50));
140
+ }
141
+ return this;
142
+ }
143
+ // 重置起始和终止位置
144
+ reset(param) {
145
+ for (let key in param) {
146
+ this._[key + "_start"] = param[key];
147
+ this._[key + "_end"] = param[key];
148
+ this._[key + "_startTime"] = -this._duration;
149
+ }
150
+ if (this.onChangeCall) {
151
+ this.onChangeCall(this.getJson());
152
+ }
153
+ this._isDone = true;
154
+ return this;
155
+ }
156
+ // 获取过渡对象上面的key
157
+ getKeys() {
158
+ return [...this._keys];
159
+ }
160
+ // 判断是否有这个参数
161
+ hasKey(key) {
162
+ return this._keys.includes(key);
163
+ }
164
+ // 获取全部参数
165
+ getJson() {
166
+ let keys = this.getKeys();
167
+ let json = {};
168
+ keys.map(key => {
169
+ json[key] = this.get(key);
170
+ });
171
+ return json;
172
+ }
173
+ _isDone = false;
174
+ // 是否执行完成了
175
+ isDone() {
176
+ if (this._isDone) {
177
+ return true;
178
+ }
179
+ let isisDone = false;
180
+ for (let i in this._keys) {
181
+ isisDone = this._[this._keys[i] + "_startTime"] + this._duration < this.timeTemp;
182
+ // 只要有一个没有完成 都算没有完成 过渡
183
+ if (!isisDone) {
184
+ return false;
185
+ }
186
+ }
187
+ if (!this._isDone) {
188
+ this._isDone = true;
189
+ return false;
190
+ }
191
+ return true;
192
+ }
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,98 @@
1
+ /*
2
+ * @Author: xiaosihan
3
+ * @Date: 2022-03-20 14:48:33
4
+ * @Last Modified by: xiaosihan
5
+ * @Last Modified time: 2022-09-30 00:12:28
6
+ */
7
+ import { throttle } from "lodash";
8
+ import { EventDispatcher, Vector3 } from "three";
9
+ import { generateUUID } from "three/src/math/MathUtils";
10
+ /**
11
+ * 键盘 使用 ↑↓←→ 控制 x z 方向, 小键盘 1 0 控制 y 方向
12
+ *
13
+ * @class KeyContorls
14
+ * @extends {EventDispatcher}
15
+ */
16
+ class KeyContorls extends EventDispatcher {
17
+ constructor() {
18
+ super();
19
+ this.addEvent();
20
+ }
21
+ uuid = generateUUID();
22
+ direction = new Vector3(0, 0, 0);
23
+ // 添加事件需要由外部实现
24
+ add(e) {
25
+ this.dispatchEvent({ ...e, type: "add" });
26
+ }
27
+ // 删除事件
28
+ delete(e) {
29
+ this.dispatchEvent({ ...e, type: "delete" });
30
+ }
31
+ // 回车按钮
32
+ enter(e) {
33
+ this.dispatchEvent({ ...e, type: "enter" });
34
+ }
35
+ keyDown = (e) => {
36
+ switch (e.keyCode) {
37
+ case 46: // 删除按钮
38
+ this.delete(e);
39
+ return;
40
+ case 13: // 回车按钮
41
+ this.enter(e);
42
+ return;
43
+ case 97: // 小键盘1
44
+ this.direction.set(0, 1, 0);
45
+ break;
46
+ case 96: // 小键盘0
47
+ this.direction.set(0, -1, 0);
48
+ break;
49
+ case 35: //
50
+ this.direction.set(0, 0.001, 0);
51
+ break;
52
+ case 45:
53
+ this.direction.set(0, -0.001, 0);
54
+ break;
55
+ case 38: // 前
56
+ this.direction.set(0, 0, -1);
57
+ break;
58
+ case 37: // 后
59
+ this.direction.set(-1, 0, 0);
60
+ break;
61
+ case 40: // 左
62
+ this.direction.set(0, 0, 1);
63
+ break;
64
+ case 39: // 右
65
+ this.direction.set(1, 0, 0);
66
+ break;
67
+ default:
68
+ return;
69
+ }
70
+ if (e.shiftKey) {
71
+ this.direction.multiplyScalar(0.001);
72
+ }
73
+ if (e.ctrlKey) {
74
+ this.direction.multiplyScalar(0.1);
75
+ }
76
+ this.dispatchEvent({
77
+ type: "change",
78
+ direction: this.direction
79
+ });
80
+ };
81
+ _listeners;
82
+ // 节流 删除事件监听
83
+ removeEvent = throttle((type) => {
84
+ this._listeners = undefined;
85
+ }, 1000, { trailing: false });
86
+ addEventListener(type, listener) {
87
+ this.removeEvent(type);
88
+ super.addEventListener(type, listener);
89
+ }
90
+ addEvent() {
91
+ document.addEventListener("keydown", this.keyDown);
92
+ }
93
+ dispose() {
94
+ document.removeEventListener("keydown", this.keyDown);
95
+ }
96
+ }
97
+ const keyContorls = new KeyContorls();
98
+ export default keyContorls;
@@ -0,0 +1,13 @@
1
+ import { APNG } from "apng-js";
2
+ import Player from "apng-js/types/library/player";
3
+ import { CanvasTexture } from "three";
4
+ export default class ApngTexture extends CanvasTexture {
5
+ constructor(url: string);
6
+ static TimeTemp: number;
7
+ preUpdate: number;
8
+ player?: Player;
9
+ apng?: APNG;
10
+ onUpdate: () => void;
11
+ getUuid(): number | "";
12
+ loadApng(url: string): Promise<void>;
13
+ }