three-base 2.0.137 → 2.0.142

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 (307) hide show
  1. package/DirectionalLight.d.ts +6 -6
  2. package/DirectionalLight.js +68 -68
  3. package/DirectionalLight.ts +70 -0
  4. package/EventMap.d.ts +103 -0
  5. package/EventMap.js +17 -0
  6. package/EventMap.ts +139 -0
  7. package/EventMesh.d.ts +18 -18
  8. package/EventMesh.js +59 -59
  9. package/EventMesh.ts +60 -0
  10. package/ExtrudeMesh.d.ts +112 -112
  11. package/ExtrudeMesh.js +342 -366
  12. package/ExtrudeMesh.ts +553 -0
  13. package/FPScontrol.d.ts +511 -78
  14. package/FPScontrol.js +1799 -617
  15. package/FPScontrol.ts +1855 -0
  16. package/Fire/Fire.d.ts +28 -28
  17. package/Fire/Fire.js +80 -79
  18. package/Fire/Fire.ts +89 -0
  19. package/Fire/{FireGromtry.d.ts → FireGeometry.d.ts} +9 -9
  20. package/Fire/{FireGromtry.js → FireGeometry.js} +40 -40
  21. package/Fire/FireGeometry.ts +40 -0
  22. package/Fire/FireMaterial.d.ts +28 -28
  23. package/Fire/FireMaterial.js +32 -32
  24. package/Fire/FireMaterial.ts +89 -0
  25. package/Fire/index.d.ts +2 -1
  26. package/Fire/index.js +2 -1
  27. package/Fire/index.ts +2 -0
  28. package/GLTFDracoLoader.d.ts +71 -0
  29. package/GLTFDracoLoader.js +266 -0
  30. package/GLTFDracoLoader.ts +430 -0
  31. package/Grass/Grass.d.ts +8 -8
  32. package/Grass/Grass.js +38 -38
  33. package/Grass/Grass.ts +38 -0
  34. package/Grass/index.d.ts +2 -1
  35. package/Grass/index.js +2 -1
  36. package/Grass/index.ts +2 -0
  37. package/Ground1/Ground1.d.ts +10 -11
  38. package/Ground1/Ground1.js +95 -91
  39. package/Ground1/Ground1.ts +114 -0
  40. package/Ground1/index.d.ts +1 -1
  41. package/Ground1/index.js +1 -1
  42. package/Ground1/index.ts +1 -0
  43. package/MeshBase.d.ts +36 -35
  44. package/MeshBase.js +247 -223
  45. package/MeshBase.ts +253 -0
  46. package/Mirror.d.ts +25 -25
  47. package/Mirror.js +143 -139
  48. package/Mirror.ts +203 -0
  49. package/MktMesh/MktMesh.d.ts +291 -0
  50. package/MktMesh/MktMesh.js +1045 -0
  51. package/MktMesh/MktMesh.ts +1075 -0
  52. package/MktMesh/assetUrl.d.ts +35 -0
  53. package/MktMesh/assetUrl.js +69 -0
  54. package/MktMesh/assetUrl.ts +69 -0
  55. package/MktMesh/mktMappingShader.d.ts +12 -0
  56. package/MktMesh/mktMappingShader.js +139 -0
  57. package/MktMesh/mktMappingShader.ts +139 -0
  58. package/MktMesh/mktShader.d.ts +263 -0
  59. package/MktMesh/mktShader.js +1248 -0
  60. package/MktMesh/mktShader.ts +1344 -0
  61. package/MktMesh/panoBitmapTexture.d.ts +25 -0
  62. package/MktMesh/panoBitmapTexture.js +52 -0
  63. package/MktMesh/panoBitmapTexture.ts +54 -0
  64. package/MktMesh/panoSlotBind.d.ts +29 -0
  65. package/MktMesh/panoSlotBind.js +106 -0
  66. package/MktMesh/panoSlotBind.ts +153 -0
  67. package/MktMesh/panoSlotRoster.d.ts +22 -0
  68. package/MktMesh/panoSlotRoster.js +169 -0
  69. package/MktMesh/panoSlotRoster.ts +168 -0
  70. package/MktMesh/panoTileStitcher.d.ts +119 -0
  71. package/MktMesh/panoTileStitcher.js +533 -0
  72. package/MktMesh/panoTileStitcher.ts +616 -0
  73. package/MktMesh/types.d.ts +75 -0
  74. package/MktMesh/types.js +1 -0
  75. package/MktMesh/types.ts +87 -0
  76. package/MktMesh/wallCapTessellate.d.ts +33 -0
  77. package/MktMesh/wallCapTessellate.js +97 -0
  78. package/MktMesh/wallCapTessellate.ts +68 -0
  79. package/PipeMesh/PathGeometry.d.ts +44 -44
  80. package/PipeMesh/PathGeometry.js +307 -300
  81. package/PipeMesh/PathGeometry.ts +343 -0
  82. package/PipeMesh/PathPoint.d.ts +17 -17
  83. package/PipeMesh/PathPoint.js +31 -31
  84. package/PipeMesh/PathPoint.ts +36 -0
  85. package/PipeMesh/PathPointList.d.ts +31 -31
  86. package/PipeMesh/PathPointList.js +209 -208
  87. package/PipeMesh/PathPointList.ts +227 -0
  88. package/PipeMesh/PathTubeGeometry.d.ts +25 -25
  89. package/PipeMesh/PathTubeGeometry.js +130 -130
  90. package/PipeMesh/PathTubeGeometry.ts +146 -0
  91. package/PipeMesh/PipeMesh.d.ts +25 -25
  92. package/PipeMesh/PipeMesh.js +63 -63
  93. package/PipeMesh/PipeMesh.ts +76 -0
  94. package/PipeMesh/index.d.ts +1 -1
  95. package/PipeMesh/index.js +1 -1
  96. package/PipeMesh/index.ts +1 -0
  97. package/PlaneModal1/PlaneModal1.d.ts +34 -31
  98. package/PlaneModal1/PlaneModal1.js +109 -105
  99. package/PlaneModal1/PlaneModal1.ts +138 -0
  100. package/PlaneModal1/index.d.ts +1 -1
  101. package/PlaneModal1/index.js +1 -1
  102. package/PlaneModal1/index.ts +1 -0
  103. package/PlaneText.d.ts +27 -39
  104. package/PlaneText.js +35 -30
  105. package/PlaneText.ts +55 -0
  106. package/PlaneWithHtml.d.ts +13 -11
  107. package/PlaneWithHtml.js +64 -63
  108. package/PlaneWithHtml.ts +70 -0
  109. package/PointLight/PointLight.d.ts +13 -14
  110. package/PointLight/PointLight.js +64 -70
  111. package/PointLight/PointLight.ts +67 -0
  112. package/PointLight/index.d.ts +1 -1
  113. package/PointLight/index.js +1 -1
  114. package/PointLight/index.ts +1 -0
  115. package/README.md +110 -79
  116. package/Sky/Sky.d.ts +9 -9
  117. package/Sky/Sky.js +22 -22
  118. package/Sky/Sky.ts +22 -0
  119. package/Sky/index.d.ts +1 -1
  120. package/Sky/index.js +1 -1
  121. package/Sky/index.ts +1 -0
  122. package/SpotLight.d.ts +6 -6
  123. package/SpotLight.js +72 -72
  124. package/SpotLight.ts +74 -0
  125. package/SpriteModal1/SpriteModal1.d.ts +33 -30
  126. package/SpriteModal1/SpriteModal1.js +116 -110
  127. package/SpriteModal1/SpriteModal1.ts +146 -0
  128. package/SpriteModal1/index.d.ts +1 -1
  129. package/SpriteModal1/index.js +1 -1
  130. package/SpriteModal1/index.ts +1 -0
  131. package/SpriteText.d.ts +46 -45
  132. package/SpriteText.js +176 -163
  133. package/SpriteText.ts +205 -0
  134. package/SpriteText2.d.ts +48 -47
  135. package/SpriteText2.js +223 -198
  136. package/SpriteText2.ts +258 -0
  137. package/SpriteText3.d.ts +86 -0
  138. package/SpriteText3.js +519 -0
  139. package/SpriteText3.ts +599 -0
  140. package/SpriteWithHtml.d.ts +9 -7
  141. package/SpriteWithHtml.js +44 -44
  142. package/SpriteWithHtml.ts +50 -0
  143. package/Text3D/Text3D.d.ts +20 -20
  144. package/Text3D/Text3D.js +58 -62
  145. package/Text3D/Text3D.ts +77 -0
  146. package/Text3D/fontController.d.ts +60 -59
  147. package/Text3D/fontController.js +166 -199
  148. package/Text3D/fontController.ts +209 -0
  149. package/Text3D/index.d.ts +1 -1
  150. package/Text3D/index.js +1 -1
  151. package/Text3D/index.ts +1 -0
  152. package/ThreeBase.d.ts +248 -111
  153. package/ThreeBase.js +1202 -656
  154. package/ThreeBase.ts +1314 -0
  155. package/ThreeMouse.d.ts +54 -40
  156. package/ThreeMouse.js +453 -407
  157. package/ThreeMouse.ts +472 -0
  158. package/Transition.d.ts +45 -40
  159. package/Transition.js +209 -210
  160. package/Transition.ts +242 -0
  161. package/Water/Water.d.ts +5 -5
  162. package/Water/Water.js +44 -26
  163. package/Water/Water.ts +45 -0
  164. package/Water/index.d.ts +2 -0
  165. package/Water/index.js +2 -0
  166. package/Water/index.ts +2 -0
  167. package/WaterFlow/FloatingDuck.d.ts +88 -0
  168. package/WaterFlow/FloatingDuck.js +307 -0
  169. package/WaterFlow/FloatingDuck.ts +445 -0
  170. package/WaterFlow/GPUFluidSimulation.d.ts +56 -0
  171. package/WaterFlow/GPUFluidSimulation.js +785 -0
  172. package/WaterFlow/GPUFluidSimulation.ts +827 -0
  173. package/WaterFlow/ReservoirSystem.d.ts +106 -0
  174. package/WaterFlow/ReservoirSystem.js +621 -0
  175. package/WaterFlow/ReservoirSystem.ts +754 -0
  176. package/WaterFlow/SPHField.d.ts +35 -0
  177. package/WaterFlow/SPHField.js +204 -0
  178. package/WaterFlow/SPHField.ts +228 -0
  179. package/WaterFlow/ScreenSpaceFluidPass.d.ts +69 -0
  180. package/WaterFlow/ScreenSpaceFluidPass.js +736 -0
  181. package/WaterFlow/ScreenSpaceFluidPass.ts +789 -0
  182. package/WaterFlow/ShallowWaterSurface.d.ts +45 -0
  183. package/WaterFlow/ShallowWaterSurface.js +441 -0
  184. package/WaterFlow/ShallowWaterSurface.ts +510 -0
  185. package/WaterFlow/WaterFlow.d.ts +87 -0
  186. package/WaterFlow/WaterFlow.js +171 -0
  187. package/WaterFlow/WaterFlow.ts +219 -0
  188. package/WaterFlow/types.d.ts +161 -0
  189. package/WaterFlow/types.js +1 -0
  190. package/WaterFlow/types.ts +189 -0
  191. package/WaterFlow/waterFlowPass.d.ts +3 -0
  192. package/WaterFlow/waterFlowPass.js +20 -0
  193. package/WaterFlow/waterFlowPass.ts +40 -0
  194. package/collisionOBB.d.ts +42 -0
  195. package/collisionOBB.js +112 -0
  196. package/collisionOBB.ts +108 -0
  197. package/declare.d.ts +23 -165
  198. package/index.d.ts +1 -1
  199. package/index.js +1 -2
  200. package/index.ts +1 -0
  201. package/instanced/InstancedBatch.d.ts +57 -0
  202. package/instanced/InstancedBatch.js +348 -0
  203. package/instanced/InstancedBatch.ts +406 -0
  204. package/instanced/InstancedChild.d.ts +174 -0
  205. package/instanced/InstancedChild.js +264 -0
  206. package/instanced/InstancedChild.ts +327 -0
  207. package/instanced/InstancedGroup.d.ts +43 -0
  208. package/instanced/InstancedGroup.js +126 -0
  209. package/instanced/InstancedGroup.ts +137 -0
  210. package/{InstancedMeshBase.d.ts → instanced/InstancedMeshBase.d.ts} +38 -39
  211. package/{InstancedMeshBase.js → instanced/InstancedMeshBase.js} +282 -293
  212. package/instanced/InstancedMeshBase.ts +292 -0
  213. package/instanced/InstancedTemplate.d.ts +46 -0
  214. package/instanced/InstancedTemplate.js +125 -0
  215. package/instanced/InstancedTemplate.ts +188 -0
  216. package/keyControls.d.ts +30 -0
  217. package/{keyContorls.js → keyControls.js} +101 -98
  218. package/keyControls.ts +107 -0
  219. package/lensflare/LensFlare.d.ts +39 -0
  220. package/lensflare/LensFlare.js +373 -0
  221. package/lensflare/LensFlare.ts +448 -0
  222. package/lensflare/lensflare0.png +0 -0
  223. package/lensflare/lensflare3.png +0 -0
  224. package/lensflare/lensflare_custom.png +0 -0
  225. package/lensflare/lensflare_hex_ghost.png +0 -0
  226. package/lensflare/lensflare_hex_main.png +0 -0
  227. package/package.json +99 -25
  228. package/pass/bloom_pass.d.ts +2 -2
  229. package/pass/bloom_pass.js +188 -101
  230. package/pass/bloom_pass.ts +243 -0
  231. package/pass/cover_pass.d.ts +2 -2
  232. package/pass/cover_pass.js +122 -99
  233. package/pass/cover_pass.ts +182 -0
  234. package/pass/debugDepthState.d.ts +20 -0
  235. package/pass/debugDepthState.js +9 -0
  236. package/pass/debugDepthState.ts +22 -0
  237. package/pass/depthTestBias.d.ts +12 -0
  238. package/pass/depthTestBias.js +12 -0
  239. package/pass/depthTestBias.ts +12 -0
  240. package/pass/effectUserData.d.ts +27 -0
  241. package/pass/effectUserData.js +1 -0
  242. package/pass/effectUserData.ts +46 -0
  243. package/pass/frosted_glass_pass.d.ts +2 -2
  244. package/pass/frosted_glass_pass.js +167 -186
  245. package/pass/frosted_glass_pass.ts +288 -0
  246. package/pass/fsQuad.d.ts +9 -9
  247. package/pass/fsQuad.js +28 -28
  248. package/pass/fsQuad.ts +34 -0
  249. package/pass/glow_pass.d.ts +2 -2
  250. package/pass/glow_pass.js +449 -233
  251. package/pass/glow_pass.ts +654 -0
  252. package/pass/screen_bloom_pass.d.ts +11 -0
  253. package/pass/screen_bloom_pass.js +235 -0
  254. package/pass/screen_bloom_pass.ts +263 -0
  255. package/pass/ssao_pass.d.ts +88 -13
  256. package/pass/ssao_pass.js +802 -366
  257. package/pass/ssao_pass.ts +918 -0
  258. package/pass/stroke_pass.d.ts +2 -2
  259. package/pass/stroke_pass.js +329 -258
  260. package/pass/stroke_pass.ts +638 -0
  261. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  262. package/shaders/FXAAShaderMaterial.js +23 -66
  263. package/shaders/FXAAShaderMaterial.ts +201 -0
  264. package/shaders/baseDepthVisShader.d.ts +11 -0
  265. package/shaders/baseDepthVisShader.js +36 -0
  266. package/shaders/baseDepthVisShader.ts +36 -0
  267. package/shaders/baseTextureToRenderShader.d.ts +2 -2
  268. package/shaders/baseTextureToRenderShader.js +55 -60
  269. package/shaders/baseTextureToRenderShader.ts +232 -0
  270. package/shaders/copyShader.d.ts +3 -3
  271. package/shaders/copyShader.js +13 -14
  272. package/shaders/copyShader.ts +32 -0
  273. package/shaders/debugDepthCompareShader.d.ts +14 -0
  274. package/shaders/debugDepthCompareShader.js +49 -0
  275. package/shaders/debugDepthCompareShader.ts +50 -0
  276. package/shaders/debugDepthJudgeShader.d.ts +18 -0
  277. package/shaders/debugDepthJudgeShader.js +52 -0
  278. package/shaders/debugDepthJudgeShader.ts +54 -0
  279. package/shaders/debugExcludedShader.d.ts +13 -0
  280. package/shaders/debugExcludedShader.js +46 -0
  281. package/shaders/debugExcludedShader.ts +48 -0
  282. package/spriteTextBg.d.ts +1 -0
  283. package/spriteTextBg.js +20 -0
  284. package/spriteTextBg.ts +20 -0
  285. package/threeLoader.d.ts +35 -34
  286. package/threeLoader.js +518 -527
  287. package/threeLoader.ts +525 -0
  288. package/threeUtils.d.ts +53 -52
  289. package/threeUtils.js +329 -330
  290. package/threeUtils.ts +373 -0
  291. package/types.d.ts +2 -0
  292. package/types.js +6 -0
  293. package/types.ts +8 -0
  294. package/ApngTexture.d.ts +0 -13
  295. package/ApngTexture.js +0 -61
  296. package/ApngTextureManage.d.ts +0 -18
  297. package/ApngTextureManage.js +0 -87
  298. package/KeyFrameAnimation.d.ts +0 -25
  299. package/KeyFrameAnimation.js +0 -78
  300. package/keyContorls.d.ts +0 -25
  301. package/lib/draco/draco_decoder.js +0 -34
  302. package/lib/draco/draco_decoder.wasm +0 -0
  303. package/lib/draco/draco_wasm_wrapper.js +0 -117
  304. package/pass/emissive_ao_pass.d.ts +0 -13
  305. package/pass/emissive_ao_pass.js +0 -370
  306. package/shaders.d.ts +0 -5
  307. package/shaders.js +0 -93
package/ThreeMouse.js CHANGED
@@ -1,407 +1,453 @@
1
- //
2
- //
3
- //
4
- //
5
- //
6
- // 启动鼠标事件
7
- import { Raycaster, Vector2 } from "three";
8
- import { Mesh } from "three";
9
- import { debounce } from "lodash";
10
- import { computeBoundsTree, acceleratedRaycast } from "three-mesh-bvh";
11
- // Add the extension functions
12
- Mesh.prototype.raycast = acceleratedRaycast;
13
- /**
14
- * js 专用的鼠标拾取模型对象
15
- */
16
- export default class ThreeMouse {
17
- constructor(renderer, camera, scene) {
18
- this._renderer = renderer;
19
- this._camera = camera;
20
- this._scene = scene;
21
- this._frame = this._renderer.info.render.frame;
22
- this._renderer.domElement.addEventListener("mouseenter", () => {
23
- this._mouseInRenderer = true;
24
- }, true); //鼠标进入开启拾取
25
- this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
26
- this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
27
- this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
28
- this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
29
- }
30
- // 渲染器
31
- _renderer;
32
- _camera;
33
- _scene;
34
- // 鼠标在渲染器上面的位置
35
- _mosePosition = new Vector2(0, 0);
36
- // 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
37
- _mouseDownPosition = new Vector2(0, 0);
38
- //当前鼠标指针上的对象
39
- _mesh_on;
40
- //鼠标按下的对象
41
- _mesh_Down;
42
- //射线拾取器
43
- _raycaster = new Raycaster();
44
- // 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
45
- _frame = 0;
46
- //鼠标是否在渲染器上
47
- _mouseInRenderer = false;
48
- // 鼠标滑动的事件
49
- _mousemoveEvent;
50
- // 鼠标事件
51
- _mouseEvent;
52
- // 需要被拾取的对象数组
53
- _object3ds = [];
54
- // 点击次数
55
- _click_num = 0;
56
- // 获取拾取到的对象
57
- _getSelected(object3ds) {
58
- let intersection;
59
- if (object3ds.length) {
60
- intersection = this._raycaster.intersectObjects(object3ds, false)[0];
61
- }
62
- return intersection;
63
- }
64
- // 判断对象上面是否有事件
65
- hasEvent(object, types = []) {
66
- if (!object) {
67
- return false;
68
- }
69
- // 如果 启用事件为关闭的话就不执行事件
70
- if (object["userData"] && object["userData"]["enableEvent"] === false) {
71
- return false;
72
- }
73
- const hasevent = types.some((type) => {
74
- //@ts-ignore
75
- if (object["_listeners"] &&
76
- object["_listeners"][type] &&
77
- object["_listeners"][type][0]) {
78
- return true;
79
- }
80
- // if (object["userData"] && object["userData"]["cursor"]) {
81
- // return true;
82
- // }
83
- return false;
84
- });
85
- return hasevent;
86
- }
87
- // 判断对象上是否有鼠标样式
88
- hasCursor(object) {
89
- if (!object) {
90
- return false;
91
- }
92
- // 如果 启用事件为关闭的话就不执行事件
93
- if (object["userData"] && object["userData"]["enableEvent"] === false) {
94
- return false;
95
- }
96
- if (object["userData"] && object["userData"]["cursor"]) {
97
- return true;
98
- }
99
- }
100
- // 分发鼠标拾取事件
101
- dispatchEvent() {
102
- // 提取有事件的对象
103
- const meshs = [];
104
- this._scene.traverseVisible((mesh) => {
105
- // 判断对象是否有指定的事件
106
- if (this.hasCursor(mesh) ||
107
- this.hasEvent(mesh, [
108
- "leftclick",
109
- "rightclick",
110
- "click",
111
- "dbclick",
112
- "mouseenter",
113
- "mouseleave",
114
- "mousemove",
115
- "mousedown",
116
- "mouseup",
117
- ])) {
118
- if (mesh.isMesh &&
119
- !mesh.geometry.boundsTree &&
120
- mesh.geometry.attributes.position &&
121
- mesh.geometry.attributes.position.count > 0) {
122
- computeBoundsTree.apply(mesh.geometry);
123
- // disposeBoundsTree.apply((mesh as Mesh).geometry);
124
- }
125
- meshs.push(mesh);
126
- }
127
- });
128
- this._object3ds = meshs;
129
- // 没有鼠标事件就不往下执行了
130
- if (!this._mousemoveEvent || !this._mouseInRenderer) {
131
- return;
132
- }
133
- // 拾取模型
134
- let intersection = this._getSelected(meshs);
135
- if (intersection) {
136
- const { face, object } = intersection;
137
- // face && face.normal.applyMatrix4(object.matrixWorld);
138
- const MouseEvent = Object.assign(intersection, {
139
- // 将来可能用到的对象
140
- e: this._mousemoveEvent,
141
- renderer: this._renderer,
142
- camera: this._camera,
143
- object: intersection.object,
144
- type: this._mousemoveEvent.type,
145
- offsetX: this._mousemoveEvent.offsetX,
146
- offsetY: this._mousemoveEvent.offsetY,
147
- x: this._mousemoveEvent.x,
148
- y: this._mousemoveEvent.y,
149
- });
150
- // 触发滑动事件
151
- if (this._mesh_on === MouseEvent.object) {
152
- if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
153
- MouseEvent.type = "mousemove";
154
- MouseEvent.object.dispatchEvent(MouseEvent);
155
- }
156
- // 鼠标划入滑出事件
157
- }
158
- else if (this._mesh_on !== MouseEvent.object) {
159
- if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
160
- MouseEvent.type = "mouseleave";
161
- this._mesh_on.dispatchEvent(MouseEvent);
162
- }
163
- if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
164
- MouseEvent.type = "mouseenter";
165
- MouseEvent.object.dispatchEvent(MouseEvent);
166
- }
167
- }
168
- this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
169
- // 鼠标样式
170
- if (this._mesh_on &&
171
- this._mesh_on.userData &&
172
- this._mesh_on.userData.cursor) {
173
- this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
174
- }
175
- else {
176
- this._renderer.domElement.style.cursor = "auto";
177
- }
178
- }
179
- else {
180
- if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
181
- // 鼠标离开事件
182
- this._mesh_on.dispatchEvent({
183
- e: this._mouseEvent,
184
- renderer: this._renderer,
185
- camera: this._camera,
186
- object: this._mesh_on,
187
- type: "mouseleave",
188
- offsetX: this._mousemoveEvent.offsetX,
189
- offsetY: this._mousemoveEvent.offsetY,
190
- x: this._mousemoveEvent.x,
191
- y: this._mousemoveEvent.y,
192
- });
193
- }
194
- // 置空当前鼠标上面的对象
195
- this._mesh_on = undefined;
196
- this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
197
- }
198
- }
199
- // 鼠标离开事件
200
- _mouseleave = (e) => {
201
- this._mouseEvent = e;
202
- this._mouseInRenderer = false;
203
- // 鼠标离开事件
204
- if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
205
- this._mesh_on.dispatchEvent({
206
- e: this._mouseEvent,
207
- renderer: this._renderer,
208
- camera: this._camera,
209
- object: this._mesh_on,
210
- type: "mouseleave",
211
- offsetX: this._mousemoveEvent.offsetX,
212
- offsetY: this._mousemoveEvent.offsetY,
213
- x: this._mousemoveEvent.x,
214
- y: this._mousemoveEvent.y,
215
- });
216
- }
217
- // 置空当前鼠标上面的对象
218
- this._mesh_on = undefined;
219
- this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
220
- };
221
- // 鼠标滑动 设置鼠标位置
222
- _mousemove = (e) => {
223
- this._mousemoveEvent = e;
224
- this._frame = this._renderer.info.render.frame;
225
- if (document.pointerLockElement) {
226
- // 如果当前有元素 锁住了鼠标
227
- this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
228
- }
229
- else {
230
- this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
231
- this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
232
- }
233
- this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
234
- };
235
- // 鼠标按下事件
236
- _mousedown = (e) => {
237
- this._mouseEvent = e;
238
- // 记录按下的位置
239
- this._mouseDownPosition.set(e.offsetX, e.offsetY);
240
- this._mousemove(e);
241
- let intersection = this._getSelected(this._object3ds);
242
- if (!intersection || !this._mousemoveEvent) {
243
- return;
244
- }
245
- this._mesh_Down = this._mesh_on = intersection.object;
246
- // 触发鼠标按下事件
247
- if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
248
- this._mesh_Down.dispatchEvent({
249
- e: this._mouseEvent,
250
- ...intersection,
251
- renderer: this._renderer,
252
- camera: this._camera,
253
- object: intersection.object,
254
- type: "mousedown",
255
- offsetX: this._mousemoveEvent.offsetX,
256
- offsetY: this._mousemoveEvent.offsetY,
257
- x: this._mousemoveEvent.x,
258
- y: this._mousemoveEvent.y,
259
- });
260
- }
261
- };
262
- // 鼠标弹起事件
263
- _mouseup = debounce(async (e) => {
264
- this._mouseEvent = e;
265
- // 提取有事件的对象
266
- const meshs = [];
267
- let intersection = this._getSelected(this._object3ds);
268
- if (!intersection || !this._mousemoveEvent) {
269
- return;
270
- }
271
- this._mesh_on = intersection.object;
272
- if (this.hasEvent(this._mesh_on, ["mouseup"])) {
273
- this._mesh_on.dispatchEvent({
274
- e: this._mouseEvent,
275
- ...intersection,
276
- renderer: this._renderer,
277
- camera: this._camera,
278
- object: intersection.object,
279
- type: "mouseup",
280
- offsetX: this._mousemoveEvent.offsetX,
281
- offsetY: this._mousemoveEvent.offsetY,
282
- x: this._mousemoveEvent.x,
283
- y: this._mousemoveEvent.y,
284
- });
285
- }
286
- // 触发鼠标弹起事件
287
- if (this._mesh_Down &&
288
- this._mesh_Down === this._mesh_on &&
289
- Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
290
- Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
291
- // 是否有双击事件
292
- if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
293
- this._click_num++;
294
- await new Promise((resolve) => setTimeout(resolve, 200));
295
- // 只点击了一次
296
- if (this._click_num === 1) {
297
- if (this.hasEvent(this._mesh_Down, ["click"])) {
298
- this._mesh_Down.dispatchEvent({
299
- e: this._mouseEvent,
300
- ...intersection,
301
- renderer: this._renderer,
302
- camera: this._camera,
303
- object: intersection.object,
304
- type: "click",
305
- offsetX: this._mousemoveEvent.offsetX,
306
- offsetY: this._mousemoveEvent.offsetY,
307
- x: this._mousemoveEvent.x,
308
- y: this._mousemoveEvent.y,
309
- });
310
- }
311
- if (this.hasEvent(this._mesh_Down, ["leftclick"]) && e.button === 0) {
312
- this._mesh_Down.dispatchEvent({
313
- e: this._mouseEvent,
314
- ...intersection,
315
- renderer: this._renderer,
316
- camera: this._camera,
317
- object: intersection.object,
318
- type: "leftclick",
319
- offsetX: this._mousemoveEvent.offsetX,
320
- offsetY: this._mousemoveEvent.offsetY,
321
- x: this._mousemoveEvent.x,
322
- y: this._mousemoveEvent.y,
323
- });
324
- }
325
- if (this.hasEvent(this._mesh_Down, ["rightclick"]) &&
326
- e.button === 2) {
327
- this._mesh_Down.dispatchEvent({
328
- e: this._mouseEvent,
329
- ...intersection,
330
- renderer: this._renderer,
331
- camera: this._camera,
332
- object: intersection.object,
333
- type: "rightclick",
334
- offsetX: this._mousemoveEvent.offsetX,
335
- offsetY: this._mousemoveEvent.offsetY,
336
- x: this._mousemoveEvent.x,
337
- y: this._mousemoveEvent.y,
338
- });
339
- }
340
- }
341
- else if (this._click_num > 1) {
342
- if (this.hasEvent(this._mesh_Down, ["dbclick"]) &&
343
- new Date().valueOf() - this._click_num > 1 &&
344
- e.button === 0) {
345
- this._mesh_Down.dispatchEvent({
346
- e: this._mouseEvent,
347
- ...intersection,
348
- renderer: this._renderer,
349
- camera: this._camera,
350
- object: intersection.object,
351
- type: "dbclick",
352
- offsetX: this._mousemoveEvent.offsetX,
353
- offsetY: this._mousemoveEvent.offsetY,
354
- x: this._mousemoveEvent.x,
355
- y: this._mousemoveEvent.y,
356
- });
357
- }
358
- }
359
- }
360
- else {
361
- if (this.hasEvent(this._mesh_Down, ["click"])) {
362
- this._mesh_Down.dispatchEvent({
363
- e: this._mouseEvent,
364
- ...intersection,
365
- renderer: this._renderer,
366
- camera: this._camera,
367
- object: intersection.object,
368
- type: "click",
369
- offsetX: this._mousemoveEvent.offsetX,
370
- offsetY: this._mousemoveEvent.offsetY,
371
- x: this._mousemoveEvent.x,
372
- y: this._mousemoveEvent.y,
373
- });
374
- }
375
- if (this.hasEvent(this._mesh_Down, ["leftclick"]) && e.button === 0) {
376
- this._mesh_Down.dispatchEvent({
377
- e: this._mouseEvent,
378
- ...intersection,
379
- renderer: this._renderer,
380
- camera: this._camera,
381
- object: intersection.object,
382
- type: "leftclick",
383
- offsetX: this._mousemoveEvent.offsetX,
384
- offsetY: this._mousemoveEvent.offsetY,
385
- x: this._mousemoveEvent.x,
386
- y: this._mousemoveEvent.y,
387
- });
388
- }
389
- if (this.hasEvent(this._mesh_Down, ["rightclick"]) && e.button === 2) {
390
- this._mesh_Down.dispatchEvent({
391
- e: this._mouseEvent,
392
- ...intersection,
393
- renderer: this._renderer,
394
- camera: this._camera,
395
- object: intersection.object,
396
- type: "rightclick",
397
- offsetX: this._mousemoveEvent.offsetX,
398
- offsetY: this._mousemoveEvent.offsetY,
399
- x: this._mousemoveEvent.x,
400
- y: this._mousemoveEvent.y,
401
- });
402
- }
403
- }
404
- this._click_num = 0;
405
- }
406
- });
407
- }
1
+ //
2
+ //
3
+ //
4
+ //
5
+ //
6
+ // 启动鼠标事件
7
+ import { InstancedMesh, Mesh, Raycaster, Vector2 } from "three";
8
+ import { debounce } from "lodash";
9
+ import { computeBoundsTree, acceleratedRaycast } from "three-mesh-bvh";
10
+ /** 安全地分发事件到 Object3D 对象 */
11
+ function dispatchObjectEvent(object, event) {
12
+ // 使用双重断言来安全地传递事件对象
13
+ object.dispatchEvent(event);
14
+ }
15
+ /** Patch Mesh.raycast with BVH acceleration. Call once before using ThreeMouse. */
16
+ export function initBVHRaycast() {
17
+ if (Mesh.prototype.raycast !== acceleratedRaycast) {
18
+ Mesh.prototype.raycast = acceleratedRaycast;
19
+ }
20
+ }
21
+ export { computeBoundsTree, acceleratedRaycast };
22
+ /**
23
+ * js 专用的鼠标拾取模型对象
24
+ */
25
+ export default class ThreeMouse {
26
+ constructor(renderer, camera, scene) {
27
+ this._renderer = renderer;
28
+ this._camera = camera;
29
+ this._scene = scene;
30
+ this._frame = this._renderer.info.render.frame;
31
+ this._renderer.domElement.addEventListener("mouseenter", () => {
32
+ this._mouseInRenderer = true;
33
+ }, true); //鼠标进入开启拾取
34
+ this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
35
+ this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
36
+ this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
37
+ this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
38
+ }
39
+ // 渲染器
40
+ _renderer;
41
+ _camera;
42
+ _scene;
43
+ // 固定的实例化分组器(由 ThreeBase 注入),用于把 InstancedMesh 命中路由到 InstancedChild
44
+ instancedGroup;
45
+ // 鼠标在渲染器上面的位置
46
+ _mosePosition = new Vector2(0, 0);
47
+ // 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
48
+ _mouseDownPosition = new Vector2(0, 0);
49
+ //当前鼠标指针上的对象
50
+ _mesh_on;
51
+ //鼠标按下的对象
52
+ _mesh_Down;
53
+ //射线拾取器
54
+ _raycaster = new Raycaster();
55
+ // 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
56
+ _frame = 0;
57
+ //鼠标是否在渲染器上
58
+ _mouseInRenderer = false;
59
+ // 鼠标滑动的事件
60
+ _mousemoveEvent;
61
+ // 鼠标事件
62
+ _mouseEvent;
63
+ // 需要被拾取的对象数组
64
+ _object3ds = [];
65
+ // 点击次数
66
+ _click_num = 0;
67
+ // 获取拾取到的对象
68
+ _getSelected(object3ds) {
69
+ let intersection;
70
+ if (object3ds.length) {
71
+ intersection = this._raycaster.intersectObjects(object3ds, false)[0];
72
+ }
73
+ return intersection;
74
+ }
75
+ // 判断对象上面是否有事件
76
+ hasEvent(object, types = []) {
77
+ if (!object) {
78
+ return false;
79
+ }
80
+ // 如果 启用事件为关闭的话就不执行事件
81
+ if (object["userData"] && object["userData"]["enableEvent"] === false) {
82
+ return false;
83
+ }
84
+ // 注意:three 的 hasEventListener(type, null) 因 indexOf(null) 永远 -1 而恒返回 false,
85
+ // 无法用来判断"是否存在任意监听器"。改为直接读取私有 _listeners 表判断该类型是否有监听。
86
+ const listeners = object._listeners;
87
+ const hasevent = types.some((type) => {
88
+ return !!(listeners && listeners[type] && listeners[type].length > 0);
89
+ });
90
+ return hasevent;
91
+ }
92
+ // 判断对象上是否有鼠标样式
93
+ hasCursor(object) {
94
+ if (!object) {
95
+ return false;
96
+ }
97
+ // 如果 启用事件为关闭的话就不执行事件
98
+ if (object["userData"] && object["userData"]["enableEvent"] === false) {
99
+ return false;
100
+ }
101
+ if (object["userData"] && object["userData"]["cursor"]) {
102
+ return true;
103
+ }
104
+ }
105
+ // 把命中的对象解析为事件派发目标:若命中 InstancedMesh 且属于某个 batch,
106
+ // 则路由到对应的 InstancedChild(逻辑实例),使实例成为透明事件接收端。
107
+ resolveTarget(object, instanceId) {
108
+ if (object instanceof InstancedMesh && this.instancedGroup) {
109
+ const child = this.instancedGroup.resolveInstance(object, instanceId);
110
+ if (child) {
111
+ return child;
112
+ }
113
+ }
114
+ return object;
115
+ }
116
+ // 分发鼠标拾取事件
117
+ dispatchEvent() {
118
+ // 提取有事件的对象
119
+ const meshs = [];
120
+ this._scene.traverseVisible((mesh) => {
121
+ // 逻辑实例节点(InstancedChild)自身不渲染、无几何,跳过收集(命中由 InstancedMesh 路由回来)
122
+ if (mesh.userData?.__instancedChild) {
123
+ return;
124
+ }
125
+ // 判断对象是否有指定的事件
126
+ if (this.hasCursor(mesh) ||
127
+ this.hasEvent(mesh, [
128
+ "leftclick",
129
+ "rightclick",
130
+ "click",
131
+ "dbclick",
132
+ "mouseenter",
133
+ "mouseleave",
134
+ "mousemove",
135
+ "mousedown",
136
+ "mouseup",
137
+ ])) {
138
+ if (mesh instanceof Mesh &&
139
+ !mesh.geometry.boundsTree &&
140
+ mesh.geometry.attributes.position &&
141
+ mesh.geometry.attributes.position.count > 0) {
142
+ computeBoundsTree.apply(mesh.geometry);
143
+ // disposeBoundsTree.apply((mesh as Mesh).geometry);
144
+ }
145
+ meshs.push(mesh);
146
+ }
147
+ });
148
+ this._object3ds = meshs;
149
+ // 收集可拾取的 InstancedMesh(仅含注册了监听的已就绪 batch)
150
+ if (this.instancedGroup) {
151
+ this.instancedGroup.collectPickable(meshs);
152
+ }
153
+ // 没有鼠标事件就不往下执行了
154
+ if (!this._mousemoveEvent || !this._mouseInRenderer) {
155
+ return;
156
+ }
157
+ // 拾取模型
158
+ let intersection = this._getSelected(meshs);
159
+ if (intersection) {
160
+ const { face, object } = intersection;
161
+ // face && face.normal.applyMatrix4(object.matrixWorld);
162
+ const MouseEvent = Object.assign(intersection, {
163
+ // 将来可能用到的对象
164
+ e: this._mousemoveEvent,
165
+ renderer: this._renderer,
166
+ camera: this._camera,
167
+ object: intersection.object,
168
+ type: this._mousemoveEvent.type,
169
+ offsetX: this._mousemoveEvent.offsetX,
170
+ offsetY: this._mousemoveEvent.offsetY,
171
+ x: this._mousemoveEvent.x,
172
+ y: this._mousemoveEvent.y,
173
+ });
174
+ // 命中 InstancedMesh 时,把派发目标重定向到对应的 InstancedChild
175
+ const _target = this.resolveTarget(intersection.object, intersection.instanceId);
176
+ if (_target)
177
+ MouseEvent.object = _target;
178
+ // 触发滑动事件
179
+ if (this._mesh_on === MouseEvent.object) {
180
+ if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
181
+ MouseEvent.type = "mousemove";
182
+ dispatchObjectEvent(MouseEvent.object, MouseEvent);
183
+ }
184
+ // 鼠标划入滑出事件
185
+ }
186
+ else if (this._mesh_on !== MouseEvent.object) {
187
+ if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
188
+ MouseEvent.type = "mouseleave";
189
+ dispatchObjectEvent(this._mesh_on, MouseEvent);
190
+ }
191
+ if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
192
+ MouseEvent.type = "mouseenter";
193
+ dispatchObjectEvent(MouseEvent.object, MouseEvent);
194
+ }
195
+ }
196
+ this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
197
+ // 鼠标样式
198
+ if (this._mesh_on &&
199
+ this._mesh_on.userData &&
200
+ this._mesh_on.userData.cursor) {
201
+ this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
202
+ }
203
+ else {
204
+ this._renderer.domElement.style.cursor = "auto";
205
+ }
206
+ }
207
+ else {
208
+ if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
209
+ // 鼠标离开事件
210
+ dispatchObjectEvent(this._mesh_on, {
211
+ e: this._mouseEvent,
212
+ renderer: this._renderer,
213
+ camera: this._camera,
214
+ object: this._mesh_on,
215
+ type: "mouseleave",
216
+ offsetX: this._mousemoveEvent.offsetX,
217
+ offsetY: this._mousemoveEvent.offsetY,
218
+ x: this._mousemoveEvent.x,
219
+ y: this._mousemoveEvent.y,
220
+ });
221
+ }
222
+ // 置空当前鼠标上面的对象
223
+ this._mesh_on = undefined;
224
+ this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
225
+ }
226
+ }
227
+ // 鼠标离开事件
228
+ _mouseleave = (e) => {
229
+ this._mouseEvent = e;
230
+ this._mouseInRenderer = false;
231
+ // 鼠标离开事件
232
+ if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
233
+ dispatchObjectEvent(this._mesh_on, {
234
+ e: this._mouseEvent,
235
+ renderer: this._renderer,
236
+ camera: this._camera,
237
+ object: this._mesh_on,
238
+ type: "mouseleave",
239
+ offsetX: this._mousemoveEvent.offsetX,
240
+ offsetY: this._mousemoveEvent.offsetY,
241
+ x: this._mousemoveEvent.x,
242
+ y: this._mousemoveEvent.y,
243
+ });
244
+ }
245
+ // 置空当前鼠标上面的对象
246
+ this._mesh_on = undefined;
247
+ this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
248
+ };
249
+ // 鼠标滑动 设置鼠标位置
250
+ _mousemove = (e) => {
251
+ this._mousemoveEvent = e;
252
+ this._frame = this._renderer.info.render.frame;
253
+ if (document.pointerLockElement) {
254
+ // 如果当前有元素 锁住了鼠标
255
+ this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
256
+ }
257
+ else {
258
+ this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
259
+ this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
260
+ }
261
+ this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
262
+ };
263
+ // 鼠标按下事件
264
+ _mousedown = (e) => {
265
+ this._mouseEvent = e;
266
+ // 记录按下的位置
267
+ this._mouseDownPosition.set(e.offsetX, e.offsetY);
268
+ this._mousemove(e);
269
+ let intersection = this._getSelected(this._object3ds);
270
+ if (!intersection || !this._mousemoveEvent) {
271
+ return;
272
+ }
273
+ // 命中 InstancedMesh 时把派发目标重定向到 InstancedChild,并改写 intersection.object
274
+ this._mesh_Down = this._mesh_on = this.resolveTarget(intersection.object, intersection.instanceId);
275
+ intersection.object = this._mesh_Down;
276
+ // 触发鼠标按下事件
277
+ if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
278
+ dispatchObjectEvent(this._mesh_Down, {
279
+ e: this._mouseEvent,
280
+ ...intersection,
281
+ renderer: this._renderer,
282
+ camera: this._camera,
283
+ object: intersection.object,
284
+ type: "mousedown",
285
+ offsetX: this._mousemoveEvent.offsetX,
286
+ offsetY: this._mousemoveEvent.offsetY,
287
+ x: this._mousemoveEvent.x,
288
+ y: this._mousemoveEvent.y,
289
+ });
290
+ }
291
+ };
292
+ // 鼠标弹起事件
293
+ _mouseup = debounce(async (e) => {
294
+ this._mouseEvent = e;
295
+ // 提取有事件的对象
296
+ const meshs = [];
297
+ let intersection = this._getSelected(this._object3ds);
298
+ if (!intersection || !this._mousemoveEvent) {
299
+ return;
300
+ }
301
+ // 命中 InstancedMesh 时把派发目标重定向到 InstancedChild,并改写 intersection.object
302
+ this._mesh_on = this.resolveTarget(intersection.object, intersection.instanceId);
303
+ intersection.object = this._mesh_on;
304
+ if (this.hasEvent(this._mesh_on, ["mouseup"])) {
305
+ dispatchObjectEvent(this._mesh_on, {
306
+ e: this._mouseEvent,
307
+ ...intersection,
308
+ renderer: this._renderer,
309
+ camera: this._camera,
310
+ object: intersection.object,
311
+ type: "mouseup",
312
+ offsetX: this._mousemoveEvent.offsetX,
313
+ offsetY: this._mousemoveEvent.offsetY,
314
+ x: this._mousemoveEvent.x,
315
+ y: this._mousemoveEvent.y,
316
+ });
317
+ }
318
+ // 触发鼠标弹起事件
319
+ if (this._mesh_Down &&
320
+ this._mesh_Down === this._mesh_on &&
321
+ Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
322
+ Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
323
+ // 是否有双击事件
324
+ if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
325
+ this._click_num++;
326
+ await new Promise((resolve) => setTimeout(resolve, 200));
327
+ // 只点击了一次
328
+ if (this._click_num === 1) {
329
+ if (this.hasEvent(this._mesh_Down, ["click"])) {
330
+ dispatchObjectEvent(this._mesh_Down, {
331
+ e: this._mouseEvent,
332
+ ...intersection,
333
+ renderer: this._renderer,
334
+ camera: this._camera,
335
+ object: intersection.object,
336
+ type: "click",
337
+ offsetX: this._mousemoveEvent.offsetX,
338
+ offsetY: this._mousemoveEvent.offsetY,
339
+ x: this._mousemoveEvent.x,
340
+ y: this._mousemoveEvent.y,
341
+ });
342
+ }
343
+ if (this.hasEvent(this._mesh_Down, ["leftclick"]) && e.button === 0) {
344
+ dispatchObjectEvent(this._mesh_Down, {
345
+ e: this._mouseEvent,
346
+ ...intersection,
347
+ renderer: this._renderer,
348
+ camera: this._camera,
349
+ object: intersection.object,
350
+ type: "leftclick",
351
+ offsetX: this._mousemoveEvent.offsetX,
352
+ offsetY: this._mousemoveEvent.offsetY,
353
+ x: this._mousemoveEvent.x,
354
+ y: this._mousemoveEvent.y,
355
+ });
356
+ }
357
+ if (this.hasEvent(this._mesh_Down, ["rightclick"]) &&
358
+ e.button === 2) {
359
+ dispatchObjectEvent(this._mesh_Down, {
360
+ e: this._mouseEvent,
361
+ ...intersection,
362
+ renderer: this._renderer,
363
+ camera: this._camera,
364
+ object: intersection.object,
365
+ type: "rightclick",
366
+ offsetX: this._mousemoveEvent.offsetX,
367
+ offsetY: this._mousemoveEvent.offsetY,
368
+ x: this._mousemoveEvent.x,
369
+ y: this._mousemoveEvent.y,
370
+ });
371
+ }
372
+ }
373
+ else if (this._click_num > 1) {
374
+ if (this.hasEvent(this._mesh_Down, ["dbclick"]) &&
375
+ new Date().valueOf() - this._click_num > 1 &&
376
+ e.button === 0) {
377
+ dispatchObjectEvent(this._mesh_Down, {
378
+ e: this._mouseEvent,
379
+ ...intersection,
380
+ renderer: this._renderer,
381
+ camera: this._camera,
382
+ object: intersection.object,
383
+ type: "dbclick",
384
+ offsetX: this._mousemoveEvent.offsetX,
385
+ offsetY: this._mousemoveEvent.offsetY,
386
+ x: this._mousemoveEvent.x,
387
+ y: this._mousemoveEvent.y,
388
+ });
389
+ }
390
+ }
391
+ }
392
+ else {
393
+ if (this.hasEvent(this._mesh_Down, ["click"])) {
394
+ dispatchObjectEvent(this._mesh_Down, {
395
+ e: this._mouseEvent,
396
+ ...intersection,
397
+ renderer: this._renderer,
398
+ camera: this._camera,
399
+ object: intersection.object,
400
+ type: "click",
401
+ offsetX: this._mousemoveEvent.offsetX,
402
+ offsetY: this._mousemoveEvent.offsetY,
403
+ x: this._mousemoveEvent.x,
404
+ y: this._mousemoveEvent.y,
405
+ });
406
+ }
407
+ if (this.hasEvent(this._mesh_Down, ["leftclick"]) && e.button === 0) {
408
+ dispatchObjectEvent(this._mesh_Down, {
409
+ e: this._mouseEvent,
410
+ ...intersection,
411
+ renderer: this._renderer,
412
+ camera: this._camera,
413
+ object: intersection.object,
414
+ type: "leftclick",
415
+ offsetX: this._mousemoveEvent.offsetX,
416
+ offsetY: this._mousemoveEvent.offsetY,
417
+ x: this._mousemoveEvent.x,
418
+ y: this._mousemoveEvent.y,
419
+ });
420
+ }
421
+ if (this.hasEvent(this._mesh_Down, ["rightclick"]) && e.button === 2) {
422
+ dispatchObjectEvent(this._mesh_Down, {
423
+ e: this._mouseEvent,
424
+ ...intersection,
425
+ renderer: this._renderer,
426
+ camera: this._camera,
427
+ object: intersection.object,
428
+ type: "rightclick",
429
+ offsetX: this._mousemoveEvent.offsetX,
430
+ offsetY: this._mousemoveEvent.offsetY,
431
+ x: this._mousemoveEvent.x,
432
+ y: this._mousemoveEvent.y,
433
+ });
434
+ }
435
+ }
436
+ this._click_num = 0;
437
+ }
438
+ });
439
+ /** 设置 Points(点云)拾取阈值(世界单位),数值越大越容易点中。
440
+ * 全景纹理标记改用 Points 后,通过它调节点击命中范围。 */
441
+ setPointsThreshold(threshold) {
442
+ this._raycaster.params.Points.threshold = threshold;
443
+ }
444
+ /** 移除 canvas 上的所有鼠标/指针事件监听(渲染器销毁时调用)。
445
+ * 注:mouseenter 为内联匿名监听,销毁时 canvas 已脱离 DOM,无需显式移除。 */
446
+ dispose() {
447
+ const dom = this._renderer.domElement;
448
+ dom.removeEventListener("mouseleave", this._mouseleave, true);
449
+ dom.removeEventListener("mousemove", this._mousemove, true);
450
+ dom.removeEventListener("pointerdown", this._mousedown, true);
451
+ dom.removeEventListener("pointerup", this._mouseup, true);
452
+ }
453
+ }