three-base 1.129.0 → 1.129.2

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 (53) hide show
  1. package/index.js +34 -0
  2. package/index.ts +5 -1
  3. package/lib/{ApngTexture.ts → ApngTexture.js} +11 -41
  4. package/lib/{ApngTextureManage.ts → ApngTextureManage.js} +13 -56
  5. package/lib/EventMesh.js +59 -0
  6. package/lib/{ExtrudeMesh.ts → ExtrudeMesh.js} +77 -284
  7. package/lib/{FPScontrol.ts → FPScontrol.js} +25 -64
  8. package/lib/InstancedGroupMesh.js +63 -0
  9. package/lib/{KeyFrameAnimation.ts → KeyFrameAnimation.js} +19 -63
  10. package/lib/{PlaneText.ts → PlaneText.js} +5 -34
  11. package/lib/{PointLight.ts → PointLight.js} +4 -18
  12. package/lib/Sky/{Sky.ts → Sky.js} +4 -12
  13. package/lib/Text3D/Text3D.js +60 -0
  14. package/lib/Text3D/fontController.js +200 -0
  15. package/lib/Text3D/gentilis.json +811 -0
  16. package/lib/{ThreeBase.ts → ThreeBase.js} +75 -131
  17. package/lib/{ThreeMouse.ts → ThreeMouse.js} +61 -168
  18. package/lib/{Transition.ts → Transition.js} +30 -101
  19. package/lib/index.d.ts +22 -0
  20. package/lib/{keyContorls.ts → keyContorls.js} +11 -40
  21. package/lib/lib/ApngTexture.d.ts +13 -0
  22. package/lib/lib/ApngTextureManage.d.ts +18 -0
  23. package/lib/lib/EventMesh.d.ts +18 -0
  24. package/lib/lib/ExtrudeMesh.d.ts +111 -0
  25. package/lib/lib/FPScontrol.d.ts +44 -0
  26. package/lib/lib/InstancedGroupMesh.d.ts +10 -0
  27. package/lib/lib/KeyFrameAnimation.d.ts +25 -0
  28. package/lib/lib/PlaneText.d.ts +37 -0
  29. package/lib/lib/PointLight.d.ts +13 -0
  30. package/lib/lib/Sky/Sky.d.ts +13 -0
  31. package/lib/lib/Text3D/Text3D.d.ts +20 -0
  32. package/lib/lib/Text3D/fontController.d.ts +59 -0
  33. package/lib/lib/ThreeBase.d.ts +59 -0
  34. package/lib/lib/ThreeMouse.d.ts +39 -0
  35. package/lib/lib/Transition.d.ts +45 -0
  36. package/lib/lib/keyContorls.d.ts +25 -0
  37. package/lib/lib/planeModal1/PlaneModal1.d.ts +32 -0
  38. package/lib/lib/shaders.d.ts +17 -0
  39. package/lib/lib/spriteModal1/SpriteModal1.d.ts +31 -0
  40. package/lib/lib/threeLoader.d.ts +20 -0
  41. package/lib/lib/threeUtils.d.ts +41 -0
  42. package/lib/lib/type.d.ts +0 -0
  43. package/lib/planeModal1/{PlaneModal1.ts → PlaneModal1.js} +33 -77
  44. package/lib/{shaders.ts → shaders.js} +19 -38
  45. package/lib/spriteModal1/{SpriteModal1.ts → SpriteModal1.js} +33 -80
  46. package/lib/{threeLoader.ts → threeLoader.js} +19 -45
  47. package/lib/{threeUtils.ts → threeUtils.js} +81 -82
  48. package/lib/{type.ts → type.js} +1 -4
  49. package/package.json +7 -6
  50. package/lib/EventMesh.ts +0 -79
  51. package/lib/InstancedGroupMesh.ts +0 -80
  52. package/lib/text/Text2D.ts +0 -41
  53. package/lib/text/Text3D.ts +0 -20
@@ -5,118 +5,79 @@
5
5
  //
6
6
  // 启动鼠标事件
7
7
  import * as THREE from "three";
8
- import { Object3D, Raycaster, Scene } from "three";
9
- import type { Intersection } from "three";
8
+ import { Raycaster } from "three";
10
9
  import { debounce } from "lodash";
11
-
12
- export interface ThreeMouseEvent extends Intersection {
13
- renderer: THREE.Renderer;
14
- camera: THREE.Camera;
15
- type: string;
16
- offsetX: number;
17
- offsetY: number
18
- x: number;
19
- y: number;
20
- }
21
-
22
-
23
10
  /**
24
11
  * harp.gl 专用的鼠标拾取模型对象
25
12
  */
26
13
  export default class ThreeMouse {
27
-
28
- constructor(renderer: THREE.WebGLRenderer, camera: THREE.Camera, scene: THREE.Scene) {
29
-
14
+ constructor(renderer, camera, scene) {
30
15
  this._renderer = renderer;
31
16
  this._camera = camera;
32
17
  this._scene = scene;
33
18
  this._frame = this._renderer.info.render.frame;
34
-
35
- this._renderer.domElement.addEventListener("mouseenter", () => { this._mouseInRenderer = true }, true); //鼠标进入开启拾取
19
+ this._renderer.domElement.addEventListener("mouseenter", () => { this._mouseInRenderer = true; }, true); //鼠标进入开启拾取
36
20
  this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
37
-
38
21
  this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
39
22
  this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
40
-
41
23
  this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
42
24
  }
43
-
44
25
  // 渲染器
45
- _renderer!: THREE.WebGLRenderer;
46
-
47
- _camera!: THREE.Camera;
48
-
49
- _scene!: Scene;
50
-
26
+ _renderer;
27
+ _camera;
28
+ _scene;
51
29
  // 鼠标在渲染器上面的位置
52
30
  _mosePosition = new THREE.Vector2(0, 0);
53
-
54
31
  // 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
55
32
  _mouseDownPosition = new THREE.Vector2(0, 0);
56
-
57
33
  //当前鼠标指针上的对象
58
- _mesh_on?: Object3D;
59
-
34
+ _mesh_on;
60
35
  //鼠标按下的对象
61
- _mesh_Down?: Object3D;
62
-
36
+ _mesh_Down;
63
37
  //射线拾取器
64
38
  _raycaster = new Raycaster();
65
-
66
39
  // 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
67
- _frame: number = 0;
68
-
40
+ _frame = 0;
69
41
  //鼠标是否在渲染器上
70
- _mouseInRenderer: boolean = false;
71
-
42
+ _mouseInRenderer = false;
72
43
  // 鼠标滑动的事件
73
- _mousemoveEvent?: MouseEvent;
74
-
44
+ _mousemoveEvent;
75
45
  // 需要被拾取的对象数组
76
- _object3ds: Object3D[] = [];
77
-
46
+ _object3ds = [];
78
47
  // 点击次数
79
48
  _click_num = 0;
80
-
81
49
  // 获取拾取到的对象
82
- _getSelected(object3ds: Object3D[]): Intersection | undefined {
83
- let intersection: Intersection | undefined;
84
-
50
+ _getSelected(object3ds) {
51
+ let intersection;
85
52
  if (object3ds.length) {
86
53
  intersection = this._raycaster.intersectObjects(object3ds, false)[0];
87
54
  }
88
-
89
55
  return intersection;
90
- };
91
-
56
+ }
57
+ ;
92
58
  // 判断对象上面是否有事件
93
- hasEvent(object?: Object3D, types: Array<"leftclick" | "rightclick" | "click" | "dbclick" | "mouseenter" | "mouseleave" | "mousemove" | "mousedown" | "mouseup"> = []) {
94
-
59
+ hasEvent(object, types = []) {
95
60
  if (!object) {
96
61
  return false;
97
62
  }
98
-
99
63
  // 如果 启用事件为关闭的话就不执行事件
100
64
  if (object["userData"] && object["userData"]["enableEvent"] === false) {
101
65
  return false;
102
66
  }
103
-
104
67
  const hasevent = types.some(type => {
105
68
  //@ts-ignore
106
69
  if (object["_listeners"] && object["_listeners"][type] && object["_listeners"][type][0]) {
107
- return true
70
+ return true;
108
71
  }
109
72
  // if (object["userData"] && object["userData"]["cursor"]) {
110
73
  // return true;
111
74
  // }
112
75
  return false;
113
76
  });
114
-
115
77
  return hasevent;
116
78
  }
117
-
118
79
  // 判断对象上是否有鼠标样式
119
- hasCursor(object?: Object3D) {
80
+ hasCursor(object) {
120
81
  if (!object) {
121
82
  return false;
122
83
  }
@@ -128,31 +89,25 @@ export default class ThreeMouse {
128
89
  return true;
129
90
  }
130
91
  }
131
-
132
92
  // 分发鼠标拾取事件
133
93
  dispatchEvent() {
134
94
  // 提取有事件的对象
135
- const meshs: Object3D[] = [];
136
-
95
+ const meshs = [];
137
96
  this._scene.traverseVisible(mesh => {
138
97
  // 判断对象是否有指定的事件
139
98
  if (this.hasCursor(mesh) || this.hasEvent(mesh, ["leftclick", "rightclick", "click", "dbclick", "mouseenter", "mouseleave", "mousemove", "mousedown", "mouseup"])) {
140
99
  meshs.push(mesh);
141
100
  }
142
101
  });
143
-
144
102
  this._object3ds = meshs;
145
-
146
103
  // 没有鼠标事件就不往下执行了
147
104
  if (!this._mousemoveEvent || !this._mouseInRenderer) {
148
105
  return;
149
106
  }
150
107
  // 拾取模型
151
108
  let intersection = this._getSelected(meshs);
152
-
153
109
  if (intersection) {
154
-
155
- const MouseEvent: ThreeMouseEvent = Object.assign(intersection, { // 将来可能用到的对象
110
+ const MouseEvent = Object.assign(intersection, {
156
111
  renderer: this._renderer,
157
112
  camera: this._camera,
158
113
  object: intersection.object,
@@ -162,46 +117,40 @@ export default class ThreeMouse {
162
117
  x: this._mousemoveEvent.x,
163
118
  y: this._mousemoveEvent.y
164
119
  });
165
-
166
120
  // 触发滑动事件
167
121
  if (this._mesh_on === MouseEvent.object) {
168
122
  if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
169
123
  MouseEvent.type = "mousemove";
170
124
  MouseEvent.object.dispatchEvent(MouseEvent);
171
125
  }
172
-
173
126
  // 鼠标划入滑出事件
174
- } else if (this._mesh_on !== MouseEvent.object) {
175
-
127
+ }
128
+ else if (this._mesh_on !== MouseEvent.object) {
176
129
  if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
177
130
  MouseEvent.type = "mouseleave";
178
- this._mesh_on!.dispatchEvent(MouseEvent);
131
+ this._mesh_on.dispatchEvent(MouseEvent);
179
132
  }
180
-
181
133
  if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
182
134
  MouseEvent.type = "mouseenter";
183
135
  MouseEvent.object.dispatchEvent(MouseEvent);
184
136
  }
185
-
186
137
  }
187
-
188
138
  this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
189
-
190
139
  // 鼠标样式
191
140
  if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
192
141
  this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
193
- } else {
142
+ }
143
+ else {
194
144
  this._renderer.domElement.style.cursor = "auto";
195
145
  }
196
-
197
- } else {
198
-
146
+ }
147
+ else {
199
148
  if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
200
149
  // 鼠标离开事件
201
- this._mesh_on!.dispatchEvent({
150
+ this._mesh_on.dispatchEvent({
202
151
  renderer: this._renderer,
203
152
  camera: this._camera,
204
- object: this._mesh_on as Object3D,
153
+ object: this._mesh_on,
205
154
  type: "mouseleave",
206
155
  offsetX: this._mousemoveEvent.offsetX,
207
156
  offsetY: this._mousemoveEvent.offsetY,
@@ -209,26 +158,20 @@ export default class ThreeMouse {
209
158
  y: this._mousemoveEvent.y
210
159
  });
211
160
  }
212
-
213
-
214
161
  // 置空当前鼠标上面的对象
215
162
  this._mesh_on = undefined;
216
-
217
163
  this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
218
164
  }
219
-
220
165
  }
221
-
222
166
  // 鼠标离开事件
223
- _mouseleave = (e: MouseEvent) => {
167
+ _mouseleave = (e) => {
224
168
  this._mouseInRenderer = false;
225
-
226
169
  // 鼠标离开事件
227
170
  if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
228
- this._mesh_on!.dispatchEvent({
171
+ this._mesh_on.dispatchEvent({
229
172
  renderer: this._renderer,
230
173
  camera: this._camera,
231
- object: this._mesh_on as Object3D,
174
+ object: this._mesh_on,
232
175
  type: "mouseleave",
233
176
  offsetX: this._mousemoveEvent.offsetX,
234
177
  offsetY: this._mousemoveEvent.offsetY,
@@ -236,88 +179,63 @@ export default class ThreeMouse {
236
179
  y: this._mousemoveEvent.y
237
180
  });
238
181
  }
239
-
240
182
  // 置空当前鼠标上面的对象
241
183
  this._mesh_on = undefined;
242
-
243
184
  this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
244
- }
245
-
185
+ };
246
186
  // 鼠标滑动 设置鼠标位置
247
- _mousemove = (e: MouseEvent) => {
248
-
187
+ _mousemove = (e) => {
249
188
  this._mousemoveEvent = e;
250
-
251
189
  this._frame = this._renderer.info.render.frame;
252
-
253
190
  if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
254
-
255
191
  this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
256
- } else {
257
-
192
+ }
193
+ else {
258
194
  this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
259
195
  this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
260
196
  }
261
-
262
197
  this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
263
-
264
198
  };
265
-
266
199
  // 鼠标按下事件
267
- _mousedown = (e: MouseEvent) => {
200
+ _mousedown = (e) => {
268
201
  // 记录按下的位置
269
202
  this._mouseDownPosition.set(e.offsetX, e.offsetY);
270
-
271
203
  this._mousemove(e);
272
-
273
204
  let intersection = this._getSelected(this._object3ds);
274
-
275
205
  if (!intersection || !this._mousemoveEvent) {
276
- return
206
+ return;
277
207
  }
278
-
279
- this._mesh_Down = this._mesh_on = intersection.object as Object3D;
280
-
208
+ this._mesh_Down = this._mesh_on = intersection.object;
281
209
  // 触发鼠标按下事件
282
210
  if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
283
-
284
211
  this._mesh_Down.dispatchEvent({
285
212
  ...intersection,
286
213
  renderer: this._renderer,
287
214
  camera: this._camera,
288
- object: intersection.object as Object3D,
215
+ object: intersection.object,
289
216
  type: "mousedown",
290
217
  offsetX: this._mousemoveEvent.offsetX,
291
218
  offsetY: this._mousemoveEvent.offsetY,
292
219
  x: this._mousemoveEvent.x,
293
220
  y: this._mousemoveEvent.y
294
221
  });
295
-
296
222
  }
297
-
298
- }
299
-
223
+ };
300
224
  // 鼠标弹起事件
301
- _mouseup = debounce(async (e: PointerEvent) => {
302
-
225
+ _mouseup = debounce(async (e) => {
303
226
  // 提取有事件的对象
304
- const meshs: Object3D[] = [];
305
-
227
+ const meshs = [];
306
228
  let intersection = this._getSelected(this._object3ds);
307
-
308
229
  if (!intersection || !this._mousemoveEvent) {
309
230
  return;
310
231
  }
311
-
312
- this._mesh_on = intersection.object as Object3D;
313
-
232
+ this._mesh_on = intersection.object;
314
233
  if (this.hasEvent(this._mesh_Down, ["mouseup"])) {
315
-
316
234
  this._mesh_on.dispatchEvent({
317
235
  ...intersection,
318
236
  renderer: this._renderer,
319
237
  camera: this._camera,
320
- object: intersection.object as Object3D,
238
+ object: intersection.object,
321
239
  type: "mouseup",
322
240
  offsetX: this._mousemoveEvent.offsetX,
323
241
  offsetY: this._mousemoveEvent.offsetY,
@@ -325,31 +243,23 @@ export default class ThreeMouse {
325
243
  y: this._mousemoveEvent.y
326
244
  });
327
245
  }
328
-
329
246
  // 触发鼠标弹起事件
330
- if (
331
- this._mesh_Down &&
247
+ if (this._mesh_Down &&
332
248
  this._mesh_Down === this._mesh_on &&
333
249
  Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
334
- Math.abs(this._mouseDownPosition.y - e.offsetY) < 5
335
- ) {
336
-
250
+ Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
337
251
  // 是否有双击事件
338
252
  if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
339
-
340
253
  this._click_num++;
341
-
342
254
  await new Promise(resolve => setTimeout(resolve, 200));
343
-
344
255
  // 只点击了一次
345
256
  if (this._click_num === 1) {
346
-
347
257
  if (this.hasEvent(this._mesh_Down, ["click"])) {
348
258
  this._mesh_Down.dispatchEvent({
349
259
  ...intersection,
350
260
  renderer: this._renderer,
351
261
  camera: this._camera,
352
- object: intersection.object as Object3D,
262
+ object: intersection.object,
353
263
  type: "click",
354
264
  offsetX: this._mousemoveEvent.offsetX,
355
265
  offsetY: this._mousemoveEvent.offsetY,
@@ -357,13 +267,12 @@ export default class ThreeMouse {
357
267
  y: this._mousemoveEvent.y
358
268
  });
359
269
  }
360
-
361
270
  if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
362
271
  this._mesh_Down.dispatchEvent({
363
272
  ...intersection,
364
273
  renderer: this._renderer,
365
274
  camera: this._camera,
366
- object: intersection.object as Object3D,
275
+ object: intersection.object,
367
276
  type: "leftclick",
368
277
  offsetX: this._mousemoveEvent.offsetX,
369
278
  offsetY: this._mousemoveEvent.offsetY,
@@ -371,13 +280,12 @@ export default class ThreeMouse {
371
280
  y: this._mousemoveEvent.y
372
281
  });
373
282
  }
374
-
375
283
  if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
376
284
  this._mesh_Down.dispatchEvent({
377
285
  ...intersection,
378
286
  renderer: this._renderer,
379
287
  camera: this._camera,
380
- object: intersection.object as Object3D,
288
+ object: intersection.object,
381
289
  type: "rightclick",
382
290
  offsetX: this._mousemoveEvent.offsetX,
383
291
  offsetY: this._mousemoveEvent.offsetY,
@@ -385,35 +293,30 @@ export default class ThreeMouse {
385
293
  y: this._mousemoveEvent.y
386
294
  });
387
295
  }
388
-
389
- } else if (this._click_num > 1) {
390
-
296
+ }
297
+ else if (this._click_num > 1) {
391
298
  if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
392
-
393
299
  this._mesh_Down.dispatchEvent({
394
300
  ...intersection,
395
301
  renderer: this._renderer,
396
302
  camera: this._camera,
397
- object: intersection.object as Object3D,
303
+ object: intersection.object,
398
304
  type: "dbclick",
399
305
  offsetX: this._mousemoveEvent.offsetX,
400
306
  offsetY: this._mousemoveEvent.offsetY,
401
307
  x: this._mousemoveEvent.x,
402
308
  y: this._mousemoveEvent.y
403
309
  });
404
-
405
310
  }
406
-
407
311
  }
408
-
409
- } else {
410
-
312
+ }
313
+ else {
411
314
  if (this.hasEvent(this._mesh_Down, ["click"])) {
412
315
  this._mesh_Down.dispatchEvent({
413
316
  ...intersection,
414
317
  renderer: this._renderer,
415
318
  camera: this._camera,
416
- object: intersection.object as Object3D,
319
+ object: intersection.object,
417
320
  type: "click",
418
321
  offsetX: this._mousemoveEvent.offsetX,
419
322
  offsetY: this._mousemoveEvent.offsetY,
@@ -421,13 +324,12 @@ export default class ThreeMouse {
421
324
  y: this._mousemoveEvent.y
422
325
  });
423
326
  }
424
-
425
327
  if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
426
328
  this._mesh_Down.dispatchEvent({
427
329
  ...intersection,
428
330
  renderer: this._renderer,
429
331
  camera: this._camera,
430
- object: intersection.object as Object3D,
332
+ object: intersection.object,
431
333
  type: "leftclick",
432
334
  offsetX: this._mousemoveEvent.offsetX,
433
335
  offsetY: this._mousemoveEvent.offsetY,
@@ -435,13 +337,12 @@ export default class ThreeMouse {
435
337
  y: this._mousemoveEvent.y
436
338
  });
437
339
  }
438
-
439
340
  if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
440
341
  this._mesh_Down.dispatchEvent({
441
342
  ...intersection,
442
343
  renderer: this._renderer,
443
344
  camera: this._camera,
444
- object: intersection.object as Object3D,
345
+ object: intersection.object,
445
346
  type: "rightclick",
446
347
  offsetX: this._mousemoveEvent.offsetX,
447
348
  offsetY: this._mousemoveEvent.offsetY,
@@ -449,16 +350,8 @@ export default class ThreeMouse {
449
350
  y: this._mousemoveEvent.y
450
351
  });
451
352
  }
452
-
453
353
  }
454
-
455
354
  this._click_num = 0;
456
-
457
355
  }
458
-
459
- })
460
-
461
-
462
-
463
-
464
- }
356
+ });
357
+ }