three-base 2.0.75 → 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 (82) 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 -187
  24. package/Mirror.d.ts +25 -25
  25. package/Mirror.js +139 -139
  26. package/PlaneModal1/PlaneModal1.d.ts +31 -31
  27. package/PlaneModal1/PlaneModal1.js +105 -105
  28. package/PlaneModal1/index.d.ts +1 -1
  29. package/PlaneModal1/index.js +1 -1
  30. package/PlaneText.d.ts +44 -44
  31. package/PlaneText.js +30 -30
  32. package/PlaneWithHtml.d.ts +11 -11
  33. package/PlaneWithHtml.js +68 -68
  34. package/PointLight/PointLight.d.ts +13 -13
  35. package/PointLight/PointLight.js +64 -64
  36. package/PointLight/index.d.ts +1 -1
  37. package/PointLight/index.js +1 -1
  38. package/Sky/Sky.d.ts +13 -13
  39. package/Sky/Sky.js +28 -28
  40. package/Sky/index.d.ts +1 -1
  41. package/Sky/index.js +1 -1
  42. package/SpriteModal1/SpriteModal1.d.ts +30 -30
  43. package/SpriteModal1/SpriteModal1.js +110 -110
  44. package/SpriteModal1/index.d.ts +1 -1
  45. package/SpriteModal1/index.js +1 -1
  46. package/SpriteText.d.ts +45 -45
  47. package/SpriteText.js +163 -163
  48. package/SpriteText2.d.ts +47 -47
  49. package/SpriteText2.js +198 -198
  50. package/SpriteWithHtml.d.ts +7 -7
  51. package/SpriteWithHtml.js +49 -49
  52. package/Text3D/Text3D.d.ts +20 -20
  53. package/Text3D/Text3D.js +62 -62
  54. package/Text3D/fontController.d.ts +59 -59
  55. package/Text3D/fontController.js +200 -200
  56. package/Text3D/index.d.ts +1 -1
  57. package/Text3D/index.js +1 -1
  58. package/ThreeBase.d.ts +92 -92
  59. package/ThreeBase.js +619 -619
  60. package/ThreeMouse.d.ts +39 -39
  61. package/ThreeMouse.js +359 -359
  62. package/Transition.d.ts +40 -40
  63. package/Transition.js +207 -207
  64. package/index.d.ts +1 -1
  65. package/index.js +2 -2
  66. package/keyContorls.d.ts +25 -25
  67. package/keyContorls.js +98 -98
  68. package/package.json +1 -1
  69. package/pass/FullScreenQuad.d.ts +7 -7
  70. package/pass/FullScreenQuad.js +25 -25
  71. package/pass/glow_pass.d.ts +2 -2
  72. package/pass/glow_pass.js +236 -236
  73. package/pass/stroke_pass.d.ts +2 -2
  74. package/pass/stroke_pass.js +202 -202
  75. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  76. package/shaders/FXAAShaderMaterial.js +21 -21
  77. package/shaders.d.ts +17 -17
  78. package/shaders.js +99 -99
  79. package/threeLoader.d.ts +26 -26
  80. package/threeLoader.js +189 -189
  81. package/threeUtils.d.ts +47 -47
  82. package/threeUtils.js +266 -266
package/ThreeMouse.js CHANGED
@@ -1,359 +1,359 @@
1
- //
2
- //
3
- //
4
- //
5
- //
6
- // 启动鼠标事件
7
- import * as THREE from "three";
8
- import { Raycaster } from "three";
9
- import { debounce } from "lodash";
10
- /**
11
- * three.js 专用的鼠标拾取模型对象
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 { face, object } = intersection;
111
- // face && face.normal.applyMatrix4(object.matrixWorld);
112
- const MouseEvent = Object.assign(intersection, {
113
- renderer: this._renderer,
114
- camera: this._camera,
115
- object: intersection.object,
116
- type: this._mousemoveEvent.type,
117
- offsetX: this._mousemoveEvent.offsetX,
118
- offsetY: this._mousemoveEvent.offsetY,
119
- x: this._mousemoveEvent.x,
120
- y: this._mousemoveEvent.y
121
- });
122
- // 触发滑动事件
123
- if (this._mesh_on === MouseEvent.object) {
124
- if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
125
- MouseEvent.type = "mousemove";
126
- MouseEvent.object.dispatchEvent(MouseEvent);
127
- }
128
- // 鼠标划入滑出事件
129
- }
130
- else if (this._mesh_on !== MouseEvent.object) {
131
- if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
132
- MouseEvent.type = "mouseleave";
133
- this._mesh_on.dispatchEvent(MouseEvent);
134
- }
135
- if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
136
- MouseEvent.type = "mouseenter";
137
- MouseEvent.object.dispatchEvent(MouseEvent);
138
- }
139
- }
140
- this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
141
- // 鼠标样式
142
- if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
143
- this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
144
- }
145
- else {
146
- this._renderer.domElement.style.cursor = "auto";
147
- }
148
- }
149
- else {
150
- if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
151
- // 鼠标离开事件
152
- this._mesh_on.dispatchEvent({
153
- renderer: this._renderer,
154
- camera: this._camera,
155
- object: this._mesh_on,
156
- type: "mouseleave",
157
- offsetX: this._mousemoveEvent.offsetX,
158
- offsetY: this._mousemoveEvent.offsetY,
159
- x: this._mousemoveEvent.x,
160
- y: this._mousemoveEvent.y
161
- });
162
- }
163
- // 置空当前鼠标上面的对象
164
- this._mesh_on = undefined;
165
- this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
166
- }
167
- }
168
- // 鼠标离开事件
169
- _mouseleave = (e) => {
170
- this._mouseInRenderer = false;
171
- // 鼠标离开事件
172
- if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
173
- this._mesh_on.dispatchEvent({
174
- renderer: this._renderer,
175
- camera: this._camera,
176
- object: this._mesh_on,
177
- type: "mouseleave",
178
- offsetX: this._mousemoveEvent.offsetX,
179
- offsetY: this._mousemoveEvent.offsetY,
180
- x: this._mousemoveEvent.x,
181
- y: this._mousemoveEvent.y
182
- });
183
- }
184
- // 置空当前鼠标上面的对象
185
- this._mesh_on = undefined;
186
- this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
187
- };
188
- // 鼠标滑动 设置鼠标位置
189
- _mousemove = (e) => {
190
- this._mousemoveEvent = e;
191
- this._frame = this._renderer.info.render.frame;
192
- if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
193
- this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
194
- }
195
- else {
196
- this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
197
- this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
198
- }
199
- this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
200
- };
201
- // 鼠标按下事件
202
- _mousedown = (e) => {
203
- // 记录按下的位置
204
- this._mouseDownPosition.set(e.offsetX, e.offsetY);
205
- this._mousemove(e);
206
- let intersection = this._getSelected(this._object3ds);
207
- if (!intersection || !this._mousemoveEvent) {
208
- return;
209
- }
210
- this._mesh_Down = this._mesh_on = intersection.object;
211
- // 触发鼠标按下事件
212
- if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
213
- this._mesh_Down.dispatchEvent({
214
- ...intersection,
215
- renderer: this._renderer,
216
- camera: this._camera,
217
- object: intersection.object,
218
- type: "mousedown",
219
- offsetX: this._mousemoveEvent.offsetX,
220
- offsetY: this._mousemoveEvent.offsetY,
221
- x: this._mousemoveEvent.x,
222
- y: this._mousemoveEvent.y
223
- });
224
- }
225
- };
226
- // 鼠标弹起事件
227
- _mouseup = debounce(async (e) => {
228
- // 提取有事件的对象
229
- const meshs = [];
230
- let intersection = this._getSelected(this._object3ds);
231
- if (!intersection || !this._mousemoveEvent) {
232
- return;
233
- }
234
- this._mesh_on = intersection.object;
235
- if (this.hasEvent(this._mesh_on, ["mouseup"])) {
236
- this._mesh_on.dispatchEvent({
237
- ...intersection,
238
- renderer: this._renderer,
239
- camera: this._camera,
240
- object: intersection.object,
241
- type: "mouseup",
242
- offsetX: this._mousemoveEvent.offsetX,
243
- offsetY: this._mousemoveEvent.offsetY,
244
- x: this._mousemoveEvent.x,
245
- y: this._mousemoveEvent.y
246
- });
247
- }
248
- // 触发鼠标弹起事件
249
- if (this._mesh_Down &&
250
- this._mesh_Down === this._mesh_on &&
251
- Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
252
- Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
253
- // 是否有双击事件
254
- if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
255
- this._click_num++;
256
- await new Promise(resolve => setTimeout(resolve, 200));
257
- // 只点击了一次
258
- if (this._click_num === 1) {
259
- if (this.hasEvent(this._mesh_Down, ["click"])) {
260
- this._mesh_Down.dispatchEvent({
261
- ...intersection,
262
- renderer: this._renderer,
263
- camera: this._camera,
264
- object: intersection.object,
265
- type: "click",
266
- offsetX: this._mousemoveEvent.offsetX,
267
- offsetY: this._mousemoveEvent.offsetY,
268
- x: this._mousemoveEvent.x,
269
- y: this._mousemoveEvent.y
270
- });
271
- }
272
- if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
273
- this._mesh_Down.dispatchEvent({
274
- ...intersection,
275
- renderer: this._renderer,
276
- camera: this._camera,
277
- object: intersection.object,
278
- type: "leftclick",
279
- offsetX: this._mousemoveEvent.offsetX,
280
- offsetY: this._mousemoveEvent.offsetY,
281
- x: this._mousemoveEvent.x,
282
- y: this._mousemoveEvent.y
283
- });
284
- }
285
- if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
286
- this._mesh_Down.dispatchEvent({
287
- ...intersection,
288
- renderer: this._renderer,
289
- camera: this._camera,
290
- object: intersection.object,
291
- type: "rightclick",
292
- offsetX: this._mousemoveEvent.offsetX,
293
- offsetY: this._mousemoveEvent.offsetY,
294
- x: this._mousemoveEvent.x,
295
- y: this._mousemoveEvent.y
296
- });
297
- }
298
- }
299
- else if (this._click_num > 1) {
300
- if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
301
- this._mesh_Down.dispatchEvent({
302
- ...intersection,
303
- renderer: this._renderer,
304
- camera: this._camera,
305
- object: intersection.object,
306
- type: "dbclick",
307
- offsetX: this._mousemoveEvent.offsetX,
308
- offsetY: this._mousemoveEvent.offsetY,
309
- x: this._mousemoveEvent.x,
310
- y: this._mousemoveEvent.y
311
- });
312
- }
313
- }
314
- }
315
- else {
316
- if (this.hasEvent(this._mesh_Down, ["click"])) {
317
- this._mesh_Down.dispatchEvent({
318
- ...intersection,
319
- renderer: this._renderer,
320
- camera: this._camera,
321
- object: intersection.object,
322
- type: "click",
323
- offsetX: this._mousemoveEvent.offsetX,
324
- offsetY: this._mousemoveEvent.offsetY,
325
- x: this._mousemoveEvent.x,
326
- y: this._mousemoveEvent.y
327
- });
328
- }
329
- if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
330
- this._mesh_Down.dispatchEvent({
331
- ...intersection,
332
- renderer: this._renderer,
333
- camera: this._camera,
334
- object: intersection.object,
335
- type: "leftclick",
336
- offsetX: this._mousemoveEvent.offsetX,
337
- offsetY: this._mousemoveEvent.offsetY,
338
- x: this._mousemoveEvent.x,
339
- y: this._mousemoveEvent.y
340
- });
341
- }
342
- if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
343
- this._mesh_Down.dispatchEvent({
344
- ...intersection,
345
- renderer: this._renderer,
346
- camera: this._camera,
347
- object: intersection.object,
348
- type: "rightclick",
349
- offsetX: this._mousemoveEvent.offsetX,
350
- offsetY: this._mousemoveEvent.offsetY,
351
- x: this._mousemoveEvent.x,
352
- y: this._mousemoveEvent.y
353
- });
354
- }
355
- }
356
- this._click_num = 0;
357
- }
358
- });
359
- }
1
+ //
2
+ //
3
+ //
4
+ //
5
+ //
6
+ // 启动鼠标事件
7
+ import * as THREE from "three";
8
+ import { Raycaster } from "three";
9
+ import { debounce } from "lodash";
10
+ /**
11
+ * three.js 专用的鼠标拾取模型对象
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 { face, object } = intersection;
111
+ // face && face.normal.applyMatrix4(object.matrixWorld);
112
+ const MouseEvent = Object.assign(intersection, {
113
+ renderer: this._renderer,
114
+ camera: this._camera,
115
+ object: intersection.object,
116
+ type: this._mousemoveEvent.type,
117
+ offsetX: this._mousemoveEvent.offsetX,
118
+ offsetY: this._mousemoveEvent.offsetY,
119
+ x: this._mousemoveEvent.x,
120
+ y: this._mousemoveEvent.y
121
+ });
122
+ // 触发滑动事件
123
+ if (this._mesh_on === MouseEvent.object) {
124
+ if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
125
+ MouseEvent.type = "mousemove";
126
+ MouseEvent.object.dispatchEvent(MouseEvent);
127
+ }
128
+ // 鼠标划入滑出事件
129
+ }
130
+ else if (this._mesh_on !== MouseEvent.object) {
131
+ if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
132
+ MouseEvent.type = "mouseleave";
133
+ this._mesh_on.dispatchEvent(MouseEvent);
134
+ }
135
+ if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
136
+ MouseEvent.type = "mouseenter";
137
+ MouseEvent.object.dispatchEvent(MouseEvent);
138
+ }
139
+ }
140
+ this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
141
+ // 鼠标样式
142
+ if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
143
+ this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
144
+ }
145
+ else {
146
+ this._renderer.domElement.style.cursor = "auto";
147
+ }
148
+ }
149
+ else {
150
+ if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
151
+ // 鼠标离开事件
152
+ this._mesh_on.dispatchEvent({
153
+ renderer: this._renderer,
154
+ camera: this._camera,
155
+ object: this._mesh_on,
156
+ type: "mouseleave",
157
+ offsetX: this._mousemoveEvent.offsetX,
158
+ offsetY: this._mousemoveEvent.offsetY,
159
+ x: this._mousemoveEvent.x,
160
+ y: this._mousemoveEvent.y
161
+ });
162
+ }
163
+ // 置空当前鼠标上面的对象
164
+ this._mesh_on = undefined;
165
+ this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
166
+ }
167
+ }
168
+ // 鼠标离开事件
169
+ _mouseleave = (e) => {
170
+ this._mouseInRenderer = false;
171
+ // 鼠标离开事件
172
+ if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
173
+ this._mesh_on.dispatchEvent({
174
+ renderer: this._renderer,
175
+ camera: this._camera,
176
+ object: this._mesh_on,
177
+ type: "mouseleave",
178
+ offsetX: this._mousemoveEvent.offsetX,
179
+ offsetY: this._mousemoveEvent.offsetY,
180
+ x: this._mousemoveEvent.x,
181
+ y: this._mousemoveEvent.y
182
+ });
183
+ }
184
+ // 置空当前鼠标上面的对象
185
+ this._mesh_on = undefined;
186
+ this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
187
+ };
188
+ // 鼠标滑动 设置鼠标位置
189
+ _mousemove = (e) => {
190
+ this._mousemoveEvent = e;
191
+ this._frame = this._renderer.info.render.frame;
192
+ if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
193
+ this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
194
+ }
195
+ else {
196
+ this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
197
+ this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
198
+ }
199
+ this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
200
+ };
201
+ // 鼠标按下事件
202
+ _mousedown = (e) => {
203
+ // 记录按下的位置
204
+ this._mouseDownPosition.set(e.offsetX, e.offsetY);
205
+ this._mousemove(e);
206
+ let intersection = this._getSelected(this._object3ds);
207
+ if (!intersection || !this._mousemoveEvent) {
208
+ return;
209
+ }
210
+ this._mesh_Down = this._mesh_on = intersection.object;
211
+ // 触发鼠标按下事件
212
+ if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
213
+ this._mesh_Down.dispatchEvent({
214
+ ...intersection,
215
+ renderer: this._renderer,
216
+ camera: this._camera,
217
+ object: intersection.object,
218
+ type: "mousedown",
219
+ offsetX: this._mousemoveEvent.offsetX,
220
+ offsetY: this._mousemoveEvent.offsetY,
221
+ x: this._mousemoveEvent.x,
222
+ y: this._mousemoveEvent.y
223
+ });
224
+ }
225
+ };
226
+ // 鼠标弹起事件
227
+ _mouseup = debounce(async (e) => {
228
+ // 提取有事件的对象
229
+ const meshs = [];
230
+ let intersection = this._getSelected(this._object3ds);
231
+ if (!intersection || !this._mousemoveEvent) {
232
+ return;
233
+ }
234
+ this._mesh_on = intersection.object;
235
+ if (this.hasEvent(this._mesh_on, ["mouseup"])) {
236
+ this._mesh_on.dispatchEvent({
237
+ ...intersection,
238
+ renderer: this._renderer,
239
+ camera: this._camera,
240
+ object: intersection.object,
241
+ type: "mouseup",
242
+ offsetX: this._mousemoveEvent.offsetX,
243
+ offsetY: this._mousemoveEvent.offsetY,
244
+ x: this._mousemoveEvent.x,
245
+ y: this._mousemoveEvent.y
246
+ });
247
+ }
248
+ // 触发鼠标弹起事件
249
+ if (this._mesh_Down &&
250
+ this._mesh_Down === this._mesh_on &&
251
+ Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
252
+ Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
253
+ // 是否有双击事件
254
+ if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
255
+ this._click_num++;
256
+ await new Promise(resolve => setTimeout(resolve, 200));
257
+ // 只点击了一次
258
+ if (this._click_num === 1) {
259
+ if (this.hasEvent(this._mesh_Down, ["click"])) {
260
+ this._mesh_Down.dispatchEvent({
261
+ ...intersection,
262
+ renderer: this._renderer,
263
+ camera: this._camera,
264
+ object: intersection.object,
265
+ type: "click",
266
+ offsetX: this._mousemoveEvent.offsetX,
267
+ offsetY: this._mousemoveEvent.offsetY,
268
+ x: this._mousemoveEvent.x,
269
+ y: this._mousemoveEvent.y
270
+ });
271
+ }
272
+ if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
273
+ this._mesh_Down.dispatchEvent({
274
+ ...intersection,
275
+ renderer: this._renderer,
276
+ camera: this._camera,
277
+ object: intersection.object,
278
+ type: "leftclick",
279
+ offsetX: this._mousemoveEvent.offsetX,
280
+ offsetY: this._mousemoveEvent.offsetY,
281
+ x: this._mousemoveEvent.x,
282
+ y: this._mousemoveEvent.y
283
+ });
284
+ }
285
+ if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
286
+ this._mesh_Down.dispatchEvent({
287
+ ...intersection,
288
+ renderer: this._renderer,
289
+ camera: this._camera,
290
+ object: intersection.object,
291
+ type: "rightclick",
292
+ offsetX: this._mousemoveEvent.offsetX,
293
+ offsetY: this._mousemoveEvent.offsetY,
294
+ x: this._mousemoveEvent.x,
295
+ y: this._mousemoveEvent.y
296
+ });
297
+ }
298
+ }
299
+ else if (this._click_num > 1) {
300
+ if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
301
+ this._mesh_Down.dispatchEvent({
302
+ ...intersection,
303
+ renderer: this._renderer,
304
+ camera: this._camera,
305
+ object: intersection.object,
306
+ type: "dbclick",
307
+ offsetX: this._mousemoveEvent.offsetX,
308
+ offsetY: this._mousemoveEvent.offsetY,
309
+ x: this._mousemoveEvent.x,
310
+ y: this._mousemoveEvent.y
311
+ });
312
+ }
313
+ }
314
+ }
315
+ else {
316
+ if (this.hasEvent(this._mesh_Down, ["click"])) {
317
+ this._mesh_Down.dispatchEvent({
318
+ ...intersection,
319
+ renderer: this._renderer,
320
+ camera: this._camera,
321
+ object: intersection.object,
322
+ type: "click",
323
+ offsetX: this._mousemoveEvent.offsetX,
324
+ offsetY: this._mousemoveEvent.offsetY,
325
+ x: this._mousemoveEvent.x,
326
+ y: this._mousemoveEvent.y
327
+ });
328
+ }
329
+ if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
330
+ this._mesh_Down.dispatchEvent({
331
+ ...intersection,
332
+ renderer: this._renderer,
333
+ camera: this._camera,
334
+ object: intersection.object,
335
+ type: "leftclick",
336
+ offsetX: this._mousemoveEvent.offsetX,
337
+ offsetY: this._mousemoveEvent.offsetY,
338
+ x: this._mousemoveEvent.x,
339
+ y: this._mousemoveEvent.y
340
+ });
341
+ }
342
+ if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
343
+ this._mesh_Down.dispatchEvent({
344
+ ...intersection,
345
+ renderer: this._renderer,
346
+ camera: this._camera,
347
+ object: intersection.object,
348
+ type: "rightclick",
349
+ offsetX: this._mousemoveEvent.offsetX,
350
+ offsetY: this._mousemoveEvent.offsetY,
351
+ x: this._mousemoveEvent.x,
352
+ y: this._mousemoveEvent.y
353
+ });
354
+ }
355
+ }
356
+ this._click_num = 0;
357
+ }
358
+ });
359
+ }