@aibee/owlly 1.0.25

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 (500) hide show
  1. package/README.external.md +75 -0
  2. package/README.md +28 -0
  3. package/lib/src/external/lines/line-geometry.d.ts +9 -0
  4. package/lib/src/external/lines/line-geometry.js +52 -0
  5. package/lib/src/external/lines/line-geometry.js.map +1 -0
  6. package/lib/src/external/lines/line-material.d.ts +10 -0
  7. package/lib/src/external/lines/line-material.js +377 -0
  8. package/lib/src/external/lines/line-material.js.map +1 -0
  9. package/lib/src/external/lines/line-segments-2.d.ts +7 -0
  10. package/lib/src/external/lines/line-segments-2.js +144 -0
  11. package/lib/src/external/lines/line-segments-2.js.map +1 -0
  12. package/lib/src/external/lines/line-segments-geometry.d.ts +15 -0
  13. package/lib/src/external/lines/line-segments-geometry.js +141 -0
  14. package/lib/src/external/lines/line-segments-geometry.js.map +1 -0
  15. package/lib/src/external/loaders/gltf-loader.d.ts +77 -0
  16. package/lib/src/external/loaders/gltf-loader.js +2319 -0
  17. package/lib/src/external/loaders/gltf-loader.js.map +1 -0
  18. package/lib/src/external/orbit-controls.d.ts +44 -0
  19. package/lib/src/external/orbit-controls.js +746 -0
  20. package/lib/src/external/orbit-controls.js.map +1 -0
  21. package/lib/src/external/renderers/css-2d-renderer.d.ts +16 -0
  22. package/lib/src/external/renderers/css-2d-renderer.js +122 -0
  23. package/lib/src/external/renderers/css-2d-renderer.js.map +1 -0
  24. package/lib/src/external/renderers/css-3d-renderer.d.ts +18 -0
  25. package/lib/src/external/renderers/css-3d-renderer.js +139 -0
  26. package/lib/src/external/renderers/css-3d-renderer.js.map +1 -0
  27. package/lib/src/external/transform-controls.d.ts +106 -0
  28. package/lib/src/external/transform-controls.js +1113 -0
  29. package/lib/src/external/transform-controls.js.map +1 -0
  30. package/lib/src/external/util/buffer-geometry-utils.d.ts +45 -0
  31. package/lib/src/external/util/buffer-geometry-utils.js +569 -0
  32. package/lib/src/external/util/buffer-geometry-utils.js.map +1 -0
  33. package/lib/src/owlly/controller/aerial-element-controller.d.ts +65 -0
  34. package/lib/src/owlly/controller/aerial-element-controller.js +236 -0
  35. package/lib/src/owlly/controller/aerial-element-controller.js.map +1 -0
  36. package/lib/src/owlly/controller/basic-controller.d.ts +324 -0
  37. package/lib/src/owlly/controller/basic-controller.js +1239 -0
  38. package/lib/src/owlly/controller/basic-controller.js.map +1 -0
  39. package/lib/src/owlly/controller/camera-controller.d.ts +37 -0
  40. package/lib/src/owlly/controller/camera-controller.js +138 -0
  41. package/lib/src/owlly/controller/camera-controller.js.map +1 -0
  42. package/lib/src/owlly/controller/controller.d.ts +61 -0
  43. package/lib/src/owlly/controller/controller.js +24 -0
  44. package/lib/src/owlly/controller/controller.js.map +1 -0
  45. package/lib/src/owlly/controller/index.d.ts +2 -0
  46. package/lib/src/owlly/controller/index.js +14 -0
  47. package/lib/src/owlly/controller/index.js.map +1 -0
  48. package/lib/src/owlly/controller/mouse-indicator-controller.d.ts +34 -0
  49. package/lib/src/owlly/controller/mouse-indicator-controller.js +119 -0
  50. package/lib/src/owlly/controller/mouse-indicator-controller.js.map +1 -0
  51. package/lib/src/owlly/controller/orbit-control.d.ts +147 -0
  52. package/lib/src/owlly/controller/orbit-control.js +265 -0
  53. package/lib/src/owlly/controller/orbit-control.js.map +1 -0
  54. package/lib/src/owlly/controller/panorama-adjust-controller.d.ts +45 -0
  55. package/lib/src/owlly/controller/panorama-adjust-controller.js +158 -0
  56. package/lib/src/owlly/controller/panorama-adjust-controller.js.map +1 -0
  57. package/lib/src/owlly/controller/panorama-controller.d.ts +441 -0
  58. package/lib/src/owlly/controller/panorama-controller.js +1944 -0
  59. package/lib/src/owlly/controller/panorama-controller.js.map +1 -0
  60. package/lib/src/owlly/controller/panorama-transform-controller.d.ts +66 -0
  61. package/lib/src/owlly/controller/panorama-transform-controller.js +137 -0
  62. package/lib/src/owlly/controller/panorama-transform-controller.js.map +1 -0
  63. package/lib/src/owlly/controller/plane-controller.d.ts +43 -0
  64. package/lib/src/owlly/controller/plane-controller.js +174 -0
  65. package/lib/src/owlly/controller/plane-controller.js.map +1 -0
  66. package/lib/src/owlly/controller/texture-controller.d.ts +181 -0
  67. package/lib/src/owlly/controller/texture-controller.js +876 -0
  68. package/lib/src/owlly/controller/texture-controller.js.map +1 -0
  69. package/lib/src/owlly/controller/tile-panorama-controller.d.ts +308 -0
  70. package/lib/src/owlly/controller/tile-panorama-controller.js +1354 -0
  71. package/lib/src/owlly/controller/tile-panorama-controller.js.map +1 -0
  72. package/lib/src/owlly/controller/transform-controller.d.ts +106 -0
  73. package/lib/src/owlly/controller/transform-controller.js +546 -0
  74. package/lib/src/owlly/controller/transform-controller.js.map +1 -0
  75. package/lib/src/owlly/element/bottom-nav-element.d.ts +65 -0
  76. package/lib/src/owlly/element/bottom-nav-element.js +258 -0
  77. package/lib/src/owlly/element/bottom-nav-element.js.map +1 -0
  78. package/lib/src/owlly/element/camera.d.ts +82 -0
  79. package/lib/src/owlly/element/camera.js +284 -0
  80. package/lib/src/owlly/element/camera.js.map +1 -0
  81. package/lib/src/owlly/element/dom-2d-element.d.ts +35 -0
  82. package/lib/src/owlly/element/dom-2d-element.js +49 -0
  83. package/lib/src/owlly/element/dom-2d-element.js.map +1 -0
  84. package/lib/src/owlly/element/dom-3d-element.d.ts +27 -0
  85. package/lib/src/owlly/element/dom-3d-element.js +34 -0
  86. package/lib/src/owlly/element/dom-3d-element.js.map +1 -0
  87. package/lib/src/owlly/element/dom-label-2d.d.ts +116 -0
  88. package/lib/src/owlly/element/dom-label-2d.js +383 -0
  89. package/lib/src/owlly/element/dom-label-2d.js.map +1 -0
  90. package/lib/src/owlly/element/element.d.ts +53 -0
  91. package/lib/src/owlly/element/element.js +76 -0
  92. package/lib/src/owlly/element/element.js.map +1 -0
  93. package/lib/src/owlly/element/floor-model.d.ts +83 -0
  94. package/lib/src/owlly/element/floor-model.js +228 -0
  95. package/lib/src/owlly/element/floor-model.js.map +1 -0
  96. package/lib/src/owlly/element/gif-kit/Gif.d.ts +96 -0
  97. package/lib/src/owlly/element/gif-kit/Gif.js +433 -0
  98. package/lib/src/owlly/element/gif-kit/Gif.js.map +1 -0
  99. package/lib/src/owlly/element/gif-kit/GifColor.d.ts +21 -0
  100. package/lib/src/owlly/element/gif-kit/GifColor.js +38 -0
  101. package/lib/src/owlly/element/gif-kit/GifColor.js.map +1 -0
  102. package/lib/src/owlly/element/gif-kit/GifCompressedCodesToByteArrayConverter.d.ts +20 -0
  103. package/lib/src/owlly/element/gif-kit/GifCompressedCodesToByteArrayConverter.js +51 -0
  104. package/lib/src/owlly/element/gif-kit/GifCompressedCodesToByteArrayConverter.js.map +1 -0
  105. package/lib/src/owlly/element/gif-kit/GifFrame.d.ts +31 -0
  106. package/lib/src/owlly/element/gif-kit/GifFrame.js +97 -0
  107. package/lib/src/owlly/element/gif-kit/GifFrame.js.map +1 -0
  108. package/lib/src/owlly/element/gif-kit/GifImage.d.ts +23 -0
  109. package/lib/src/owlly/element/gif-kit/GifImage.js +8 -0
  110. package/lib/src/owlly/element/gif-kit/GifImage.js.map +1 -0
  111. package/lib/src/owlly/element/gif-kit/GifParser.d.ts +17 -0
  112. package/lib/src/owlly/element/gif-kit/GifParser.js +197 -0
  113. package/lib/src/owlly/element/gif-kit/GifParser.js.map +1 -0
  114. package/lib/src/owlly/element/gif-kit/GifPresenter.d.ts +20 -0
  115. package/lib/src/owlly/element/gif-kit/GifPresenter.js +44 -0
  116. package/lib/src/owlly/element/gif-kit/GifPresenter.js.map +1 -0
  117. package/lib/src/owlly/element/gif-kit/GifVersion.d.ts +10 -0
  118. package/lib/src/owlly/element/gif-kit/GifVersion.js +13 -0
  119. package/lib/src/owlly/element/gif-kit/GifVersion.js.map +1 -0
  120. package/lib/src/owlly/element/gltf-mesh-element.d.ts +31 -0
  121. package/lib/src/owlly/element/gltf-mesh-element.js +137 -0
  122. package/lib/src/owlly/element/gltf-mesh-element.js.map +1 -0
  123. package/lib/src/owlly/element/index.d.ts +20 -0
  124. package/lib/src/owlly/element/index.js +25 -0
  125. package/lib/src/owlly/element/index.js.map +1 -0
  126. package/lib/src/owlly/element/map-kit/area.d.ts +24 -0
  127. package/lib/src/owlly/element/map-kit/area.js +218 -0
  128. package/lib/src/owlly/element/map-kit/area.js.map +1 -0
  129. package/lib/src/owlly/element/map-kit/block-set.d.ts +39 -0
  130. package/lib/src/owlly/element/map-kit/block-set.js +91 -0
  131. package/lib/src/owlly/element/map-kit/block-set.js.map +1 -0
  132. package/lib/src/owlly/element/map-kit/block.d.ts +77 -0
  133. package/lib/src/owlly/element/map-kit/block.js +339 -0
  134. package/lib/src/owlly/element/map-kit/block.js.map +1 -0
  135. package/lib/src/owlly/element/map-kit/index.d.ts +4 -0
  136. package/lib/src/owlly/element/map-kit/index.js +7 -0
  137. package/lib/src/owlly/element/map-kit/index.js.map +1 -0
  138. package/lib/src/owlly/element/map-kit/shape.d.ts +131 -0
  139. package/lib/src/owlly/element/map-kit/shape.js +190 -0
  140. package/lib/src/owlly/element/map-kit/shape.js.map +1 -0
  141. package/lib/src/owlly/element/mesh-element.d.ts +22 -0
  142. package/lib/src/owlly/element/mesh-element.js +64 -0
  143. package/lib/src/owlly/element/mesh-element.js.map +1 -0
  144. package/lib/src/owlly/element/mesh-line-2d.d.ts +82 -0
  145. package/lib/src/owlly/element/mesh-line-2d.js +888 -0
  146. package/lib/src/owlly/element/mesh-line-2d.js.map +1 -0
  147. package/lib/src/owlly/element/meshline-o.d.ts +64 -0
  148. package/lib/src/owlly/element/meshline-o.js +679 -0
  149. package/lib/src/owlly/element/meshline-o.js.map +1 -0
  150. package/lib/src/owlly/element/panorama-group.d.ts +241 -0
  151. package/lib/src/owlly/element/panorama-group.js +967 -0
  152. package/lib/src/owlly/element/panorama-group.js.map +1 -0
  153. package/lib/src/owlly/element/panorama.d.ts +132 -0
  154. package/lib/src/owlly/element/panorama.js +813 -0
  155. package/lib/src/owlly/element/panorama.js.map +1 -0
  156. package/lib/src/owlly/element/path-group.d.ts +69 -0
  157. package/lib/src/owlly/element/path-group.js +172 -0
  158. package/lib/src/owlly/element/path-group.js.map +1 -0
  159. package/lib/src/owlly/element/path.d.ts +99 -0
  160. package/lib/src/owlly/element/path.js +532 -0
  161. package/lib/src/owlly/element/path.js.map +1 -0
  162. package/lib/src/owlly/element/placeable-2d.d.ts +158 -0
  163. package/lib/src/owlly/element/placeable-2d.js +471 -0
  164. package/lib/src/owlly/element/placeable-2d.js.map +1 -0
  165. package/lib/src/owlly/element/polygon-mesh.d.ts +107 -0
  166. package/lib/src/owlly/element/polygon-mesh.js +308 -0
  167. package/lib/src/owlly/element/polygon-mesh.js.map +1 -0
  168. package/lib/src/owlly/element/ring-element.d.ts +79 -0
  169. package/lib/src/owlly/element/ring-element.js +384 -0
  170. package/lib/src/owlly/element/ring-element.js.map +1 -0
  171. package/lib/src/owlly/element/sphere-mesh.d.ts +28 -0
  172. package/lib/src/owlly/element/sphere-mesh.js +70 -0
  173. package/lib/src/owlly/element/sphere-mesh.js.map +1 -0
  174. package/lib/src/owlly/element/svg-floor-model.d.ts +22 -0
  175. package/lib/src/owlly/element/svg-floor-model.js +185 -0
  176. package/lib/src/owlly/element/svg-floor-model.js.map +1 -0
  177. package/lib/src/owlly/element/svg-floors.d.ts +27 -0
  178. package/lib/src/owlly/element/svg-floors.js +110 -0
  179. package/lib/src/owlly/element/svg-floors.js.map +1 -0
  180. package/lib/src/owlly/element/tile-panorama-group.d.ts +335 -0
  181. package/lib/src/owlly/element/tile-panorama-group.js +1007 -0
  182. package/lib/src/owlly/element/tile-panorama-group.js.map +1 -0
  183. package/lib/src/owlly/element/tile-panorama.d.ts +161 -0
  184. package/lib/src/owlly/element/tile-panorama.js +511 -0
  185. package/lib/src/owlly/element/tile-panorama.js.map +1 -0
  186. package/lib/src/owlly/element/tile-plane.d.ts +105 -0
  187. package/lib/src/owlly/element/tile-plane.js +361 -0
  188. package/lib/src/owlly/element/tile-plane.js.map +1 -0
  189. package/lib/src/owlly/element/video-element.d.ts +33 -0
  190. package/lib/src/owlly/element/video-element.js +160 -0
  191. package/lib/src/owlly/element/video-element.js.map +1 -0
  192. package/lib/src/owlly/geometries/ExtrudeGeometry2.d.ts +15 -0
  193. package/lib/src/owlly/geometries/ExtrudeGeometry2.js +211 -0
  194. package/lib/src/owlly/geometries/ExtrudeGeometry2.js.map +1 -0
  195. package/lib/src/owlly/index.d.ts +13 -0
  196. package/lib/src/owlly/index.js +17 -0
  197. package/lib/src/owlly/index.js.map +1 -0
  198. package/lib/src/owlly/overlay/canvas-overlay.d.ts +96 -0
  199. package/lib/src/owlly/overlay/canvas-overlay.js +511 -0
  200. package/lib/src/owlly/overlay/canvas-overlay.js.map +1 -0
  201. package/lib/src/owlly/overlay/css-2d-overlay.d.ts +14 -0
  202. package/lib/src/owlly/overlay/css-2d-overlay.js +36 -0
  203. package/lib/src/owlly/overlay/css-2d-overlay.js.map +1 -0
  204. package/lib/src/owlly/overlay/css-3d-overlay.d.ts +16 -0
  205. package/lib/src/owlly/overlay/css-3d-overlay.js +37 -0
  206. package/lib/src/owlly/overlay/css-3d-overlay.js.map +1 -0
  207. package/lib/src/owlly/overlay/index.d.ts +6 -0
  208. package/lib/src/owlly/overlay/index.js +12 -0
  209. package/lib/src/owlly/overlay/index.js.map +1 -0
  210. package/lib/src/owlly/overlay/label-overlay.d.ts +62 -0
  211. package/lib/src/owlly/overlay/label-overlay.js +329 -0
  212. package/lib/src/owlly/overlay/label-overlay.js.map +1 -0
  213. package/lib/src/owlly/overlay/overlay.d.ts +14 -0
  214. package/lib/src/owlly/overlay/overlay.js +5 -0
  215. package/lib/src/owlly/overlay/overlay.js.map +1 -0
  216. package/lib/src/owlly/overlay/path-overlay.d.ts +39 -0
  217. package/lib/src/owlly/overlay/path-overlay.js +125 -0
  218. package/lib/src/owlly/overlay/path-overlay.js.map +1 -0
  219. package/lib/src/owlly/overlay/path-overlay2.d.ts +35 -0
  220. package/lib/src/owlly/overlay/path-overlay2.js +119 -0
  221. package/lib/src/owlly/overlay/path-overlay2.js.map +1 -0
  222. package/lib/src/owlly/overlay/poi-overlay-3d.d.ts +278 -0
  223. package/lib/src/owlly/overlay/poi-overlay-3d.js +1433 -0
  224. package/lib/src/owlly/overlay/poi-overlay-3d.js.map +1 -0
  225. package/lib/src/owlly/overlay/poi-overlay.d.ts +277 -0
  226. package/lib/src/owlly/overlay/poi-overlay.js +1412 -0
  227. package/lib/src/owlly/overlay/poi-overlay.js.map +1 -0
  228. package/lib/src/owlly/owlly-2d/index.d.ts +28 -0
  229. package/lib/src/owlly/owlly-2d/index.js +93 -0
  230. package/lib/src/owlly/owlly-2d/index.js.map +1 -0
  231. package/lib/src/owlly/screen/index.d.ts +1 -0
  232. package/lib/src/owlly/screen/index.js +2 -0
  233. package/lib/src/owlly/screen/index.js.map +1 -0
  234. package/lib/src/owlly/screen/screen.d.ts +73 -0
  235. package/lib/src/owlly/screen/screen.js +237 -0
  236. package/lib/src/owlly/screen/screen.js.map +1 -0
  237. package/lib/src/owlly/stage/__test__/stage.spec.d.ts +1 -0
  238. package/lib/src/owlly/stage/__test__/stage.spec.js +15 -0
  239. package/lib/src/owlly/stage/__test__/stage.spec.js.map +1 -0
  240. package/lib/src/owlly/stage/externals.d.ts +19 -0
  241. package/lib/src/owlly/stage/externals.js +25 -0
  242. package/lib/src/owlly/stage/externals.js.map +1 -0
  243. package/lib/src/owlly/stage/index.d.ts +4 -0
  244. package/lib/src/owlly/stage/index.js +7 -0
  245. package/lib/src/owlly/stage/index.js.map +1 -0
  246. package/lib/src/owlly/stage/owlly.d.ts +38 -0
  247. package/lib/src/owlly/stage/owlly.js +168 -0
  248. package/lib/src/owlly/stage/owlly.js.map +1 -0
  249. package/lib/src/owlly/stage/stage.d.ts +108 -0
  250. package/lib/src/owlly/stage/stage.js +235 -0
  251. package/lib/src/owlly/stage/stage.js.map +1 -0
  252. package/lib/src/owlly/utils/alignment-utils.d.ts +20 -0
  253. package/lib/src/owlly/utils/alignment-utils.js +64 -0
  254. package/lib/src/owlly/utils/alignment-utils.js.map +1 -0
  255. package/lib/src/owlly/utils/basic-calc.d.ts +18 -0
  256. package/lib/src/owlly/utils/basic-calc.js +130 -0
  257. package/lib/src/owlly/utils/basic-calc.js.map +1 -0
  258. package/lib/src/owlly/utils/basic-tools.d.ts +71 -0
  259. package/lib/src/owlly/utils/basic-tools.js +236 -0
  260. package/lib/src/owlly/utils/basic-tools.js.map +1 -0
  261. package/lib/src/owlly/utils/bvh-tree.d.ts +105 -0
  262. package/lib/src/owlly/utils/bvh-tree.js +540 -0
  263. package/lib/src/owlly/utils/bvh-tree.js.map +1 -0
  264. package/lib/src/owlly/utils/camera.d.ts +37 -0
  265. package/lib/src/owlly/utils/camera.js +51 -0
  266. package/lib/src/owlly/utils/camera.js.map +1 -0
  267. package/lib/src/owlly/utils/cube-texture-cache.d.ts +25 -0
  268. package/lib/src/owlly/utils/cube-texture-cache.js +144 -0
  269. package/lib/src/owlly/utils/cube-texture-cache.js.map +1 -0
  270. package/lib/src/owlly/utils/device-utils.d.ts +18 -0
  271. package/lib/src/owlly/utils/device-utils.js +42 -0
  272. package/lib/src/owlly/utils/device-utils.js.map +1 -0
  273. package/lib/src/owlly/utils/environment-utils.d.ts +37 -0
  274. package/lib/src/owlly/utils/environment-utils.js +74 -0
  275. package/lib/src/owlly/utils/environment-utils.js.map +1 -0
  276. package/lib/src/owlly/utils/event-hub.d.ts +50 -0
  277. package/lib/src/owlly/utils/event-hub.js +107 -0
  278. package/lib/src/owlly/utils/event-hub.js.map +1 -0
  279. package/lib/src/owlly/utils/events.d.ts +219 -0
  280. package/lib/src/owlly/utils/events.js +220 -0
  281. package/lib/src/owlly/utils/events.js.map +1 -0
  282. package/lib/src/owlly/utils/geometry-utils.d.ts +119 -0
  283. package/lib/src/owlly/utils/geometry-utils.js +623 -0
  284. package/lib/src/owlly/utils/geometry-utils.js.map +1 -0
  285. package/lib/src/owlly/utils/helper.d.ts +6 -0
  286. package/lib/src/owlly/utils/helper.js +25 -0
  287. package/lib/src/owlly/utils/helper.js.map +1 -0
  288. package/lib/src/owlly/utils/index.d.ts +14 -0
  289. package/lib/src/owlly/utils/index.js +18 -0
  290. package/lib/src/owlly/utils/index.js.map +1 -0
  291. package/lib/src/owlly/utils/lru-cache.d.ts +26 -0
  292. package/lib/src/owlly/utils/lru-cache.js +110 -0
  293. package/lib/src/owlly/utils/lru-cache.js.map +1 -0
  294. package/lib/src/owlly/utils/map-utils.d.ts +7 -0
  295. package/lib/src/owlly/utils/map-utils.js +53 -0
  296. package/lib/src/owlly/utils/map-utils.js.map +1 -0
  297. package/lib/src/owlly/utils/number-utils.d.ts +8 -0
  298. package/lib/src/owlly/utils/number-utils.js +73 -0
  299. package/lib/src/owlly/utils/number-utils.js.map +1 -0
  300. package/lib/src/owlly/utils/panorama-model-util.d.ts +46 -0
  301. package/lib/src/owlly/utils/panorama-model-util.js +246 -0
  302. package/lib/src/owlly/utils/panorama-model-util.js.map +1 -0
  303. package/lib/src/owlly/utils/path-utils.d.ts +80 -0
  304. package/lib/src/owlly/utils/path-utils.js +729 -0
  305. package/lib/src/owlly/utils/path-utils.js.map +1 -0
  306. package/lib/src/owlly/utils/svgutils.d.ts +138 -0
  307. package/lib/src/owlly/utils/svgutils.js +562 -0
  308. package/lib/src/owlly/utils/svgutils.js.map +1 -0
  309. package/lib/src/owlly/utils/texture-cache.d.ts +29 -0
  310. package/lib/src/owlly/utils/texture-cache.js +116 -0
  311. package/lib/src/owlly/utils/texture-cache.js.map +1 -0
  312. package/lib/src/owlly/utils/tile-util.d.ts +187 -0
  313. package/lib/src/owlly/utils/tile-util.js +457 -0
  314. package/lib/src/owlly/utils/tile-util.js.map +1 -0
  315. package/lib/src/owlly/utils/time-profiler.d.ts +21 -0
  316. package/lib/src/owlly/utils/time-profiler.js +49 -0
  317. package/lib/src/owlly/utils/time-profiler.js.map +1 -0
  318. package/lib/src/owlly/view/__test__/perspective-view.spec.d.ts +0 -0
  319. package/lib/src/owlly/view/__test__/perspective-view.spec.js +22 -0
  320. package/lib/src/owlly/view/__test__/perspective-view.spec.js.map +1 -0
  321. package/lib/src/owlly/view/camera-view.d.ts +35 -0
  322. package/lib/src/owlly/view/camera-view.js +102 -0
  323. package/lib/src/owlly/view/camera-view.js.map +1 -0
  324. package/lib/src/owlly/view/index.d.ts +3 -0
  325. package/lib/src/owlly/view/index.js +6 -0
  326. package/lib/src/owlly/view/index.js.map +1 -0
  327. package/lib/src/owlly/view/orthographic-view.d.ts +40 -0
  328. package/lib/src/owlly/view/orthographic-view.js +95 -0
  329. package/lib/src/owlly/view/orthographic-view.js.map +1 -0
  330. package/lib/src/owlly/view/perspective-view.d.ts +40 -0
  331. package/lib/src/owlly/view/perspective-view.js +96 -0
  332. package/lib/src/owlly/view/perspective-view.js.map +1 -0
  333. package/lib/src/owlly/view/svg-map-view.d.ts +46 -0
  334. package/lib/src/owlly/view/svg-map-view.js +145 -0
  335. package/lib/src/owlly/view/svg-map-view.js.map +1 -0
  336. package/lib/src/owlly/view/view.d.ts +146 -0
  337. package/lib/src/owlly/view/view.js +318 -0
  338. package/lib/src/owlly/view/view.js.map +1 -0
  339. package/lib/src/web/main.centroid.d.ts +0 -0
  340. package/lib/src/web/main.centroid.js +74 -0
  341. package/lib/src/web/main.centroid.js.map +1 -0
  342. package/lib/src/web/main.hyma.meshline2d.d.ts +1 -0
  343. package/lib/src/web/main.hyma.meshline2d.js +76 -0
  344. package/lib/src/web/main.hyma.meshline2d.js.map +1 -0
  345. package/lib/src/web/main.jyfang.sample.d.ts +0 -0
  346. package/lib/src/web/main.jyfang.sample.js +122 -0
  347. package/lib/src/web/main.jyfang.sample.js.map +1 -0
  348. package/lib/src/web/main.rpeng.extrude.d.ts +1 -0
  349. package/lib/src/web/main.rpeng.extrude.js +180 -0
  350. package/lib/src/web/main.rpeng.extrude.js.map +1 -0
  351. package/lib/src/web/main.rpeng.mes.plane.d.ts +1 -0
  352. package/lib/src/web/main.rpeng.mes.plane.js +135 -0
  353. package/lib/src/web/main.rpeng.mes.plane.js.map +1 -0
  354. package/lib/src/web/main.rpeng.sample.d.ts +0 -0
  355. package/lib/src/web/main.rpeng.sample.js +318 -0
  356. package/lib/src/web/main.rpeng.sample.js.map +1 -0
  357. package/lib/src/web/main.rpeng.vr.d.ts +1 -0
  358. package/lib/src/web/main.rpeng.vr.js +141 -0
  359. package/lib/src/web/main.rpeng.vr.js.map +1 -0
  360. package/lib/src/web/main.sample.d.ts +1 -0
  361. package/lib/src/web/main.sample.js +52 -0
  362. package/lib/src/web/main.sample.js.map +1 -0
  363. package/lib/src/web/quattree.hyma.d.ts +0 -0
  364. package/lib/src/web/quattree.hyma.js +150 -0
  365. package/lib/src/web/quattree.hyma.js.map +1 -0
  366. package/lib/src/web/sensor-vr-plugin.d.ts +0 -0
  367. package/lib/src/web/sensor-vr-plugin.js +166 -0
  368. package/lib/src/web/sensor-vr-plugin.js.map +1 -0
  369. package/package.json +142 -0
  370. package/src/@types/SceneUtils.d.ts +9 -0
  371. package/src/@types/chaikin-smooth.d.ts +5 -0
  372. package/src/@types/global.d.ts +3 -0
  373. package/src/@types/snapsvg.d.ts +11 -0
  374. package/src/@types/svgson.d.ts +30 -0
  375. package/src/assets/favicon.ico +0 -0
  376. package/src/external/lines/line-geometry.ts +70 -0
  377. package/src/external/lines/line-material.ts +453 -0
  378. package/src/external/lines/line-segments-2.ts +194 -0
  379. package/src/external/lines/line-segments-geometry.ts +197 -0
  380. package/src/external/loaders/gltf-loader.ts +3004 -0
  381. package/src/external/orbit-controls.ts +1070 -0
  382. package/src/external/renderers/css-2d-renderer.ts +185 -0
  383. package/src/external/renderers/css-3d-renderer.ts +245 -0
  384. package/src/external/transform-controls.ts +1532 -0
  385. package/src/external/util/buffer-geometry-utils.ts +783 -0
  386. package/src/owlly/controller/aerial-element-controller.ts +277 -0
  387. package/src/owlly/controller/basic-controller.ts +1509 -0
  388. package/src/owlly/controller/camera-controller.ts +155 -0
  389. package/src/owlly/controller/controller.ts +76 -0
  390. package/src/owlly/controller/index.ts +15 -0
  391. package/src/owlly/controller/mouse-indicator-controller.ts +157 -0
  392. package/src/owlly/controller/orbit-control.ts +310 -0
  393. package/src/owlly/controller/panorama-adjust-controller.ts +183 -0
  394. package/src/owlly/controller/panorama-controller.ts +2234 -0
  395. package/src/owlly/controller/panorama-transform-controller.ts +151 -0
  396. package/src/owlly/controller/plane-controller.ts +222 -0
  397. package/src/owlly/controller/texture-controller.ts +949 -0
  398. package/src/owlly/controller/tile-panorama-controller.ts +1633 -0
  399. package/src/owlly/controller/transform-controller.ts +684 -0
  400. package/src/owlly/element/bottom-nav-element.ts +352 -0
  401. package/src/owlly/element/camera.ts +389 -0
  402. package/src/owlly/element/dom-2d-element.ts +88 -0
  403. package/src/owlly/element/dom-3d-element.ts +87 -0
  404. package/src/owlly/element/dom-label-2d.ts +497 -0
  405. package/src/owlly/element/element.ts +117 -0
  406. package/src/owlly/element/floor-model.ts +290 -0
  407. package/src/owlly/element/gif-kit/Gif.ts +509 -0
  408. package/src/owlly/element/gif-kit/GifColor.ts +44 -0
  409. package/src/owlly/element/gif-kit/GifCompressedCodesToByteArrayConverter.ts +56 -0
  410. package/src/owlly/element/gif-kit/GifFrame.ts +207 -0
  411. package/src/owlly/element/gif-kit/GifImage.ts +26 -0
  412. package/src/owlly/element/gif-kit/GifParser.ts +254 -0
  413. package/src/owlly/element/gif-kit/GifPresenter.ts +46 -0
  414. package/src/owlly/element/gif-kit/GifVersion.ts +12 -0
  415. package/src/owlly/element/gltf-mesh-element.ts +184 -0
  416. package/src/owlly/element/index.ts +25 -0
  417. package/src/owlly/element/map-kit/area.ts +232 -0
  418. package/src/owlly/element/map-kit/block-set.ts +102 -0
  419. package/src/owlly/element/map-kit/block.ts +417 -0
  420. package/src/owlly/element/map-kit/index.ts +6 -0
  421. package/src/owlly/element/map-kit/shape.ts +285 -0
  422. package/src/owlly/element/mesh-element.ts +94 -0
  423. package/src/owlly/element/mesh-line-2d.ts +1032 -0
  424. package/src/owlly/element/meshline-o.ts +802 -0
  425. package/src/owlly/element/panorama-group.ts +1250 -0
  426. package/src/owlly/element/panorama.ts +1044 -0
  427. package/src/owlly/element/path-group.ts +212 -0
  428. package/src/owlly/element/path.ts +727 -0
  429. package/src/owlly/element/placeable-2d.ts +627 -0
  430. package/src/owlly/element/polygon-mesh.ts +344 -0
  431. package/src/owlly/element/ring-element.ts +517 -0
  432. package/src/owlly/element/sphere-mesh.ts +96 -0
  433. package/src/owlly/element/svg-floor-model.ts +200 -0
  434. package/src/owlly/element/svg-floors.ts +121 -0
  435. package/src/owlly/element/tile-panorama-group.ts +1314 -0
  436. package/src/owlly/element/tile-panorama.ts +636 -0
  437. package/src/owlly/element/tile-plane.ts +430 -0
  438. package/src/owlly/element/video-element.ts +190 -0
  439. package/src/owlly/geometries/ExtrudeGeometry2.ts +255 -0
  440. package/src/owlly/index.ts +19 -0
  441. package/src/owlly/overlay/canvas-overlay.ts +642 -0
  442. package/src/owlly/overlay/css-2d-overlay.ts +48 -0
  443. package/src/owlly/overlay/css-3d-overlay.ts +50 -0
  444. package/src/owlly/overlay/index.ts +11 -0
  445. package/src/owlly/overlay/label-overlay.ts +419 -0
  446. package/src/owlly/overlay/overlay.ts +17 -0
  447. package/src/owlly/overlay/path-overlay.ts +170 -0
  448. package/src/owlly/overlay/path-overlay2.ts +149 -0
  449. package/src/owlly/overlay/poi-overlay-3d.ts +1759 -0
  450. package/src/owlly/overlay/poi-overlay.ts +1739 -0
  451. package/src/owlly/owlly-2d/index.ts +108 -0
  452. package/src/owlly/screen/index.ts +1 -0
  453. package/src/owlly/screen/screen.ts +323 -0
  454. package/src/owlly/stage/__test__/stage.spec.ts +15 -0
  455. package/src/owlly/stage/externals.ts +45 -0
  456. package/src/owlly/stage/index.ts +12 -0
  457. package/src/owlly/stage/owlly.ts +223 -0
  458. package/src/owlly/stage/stage.ts +274 -0
  459. package/src/owlly/utils/alignment-utils.ts +84 -0
  460. package/src/owlly/utils/basic-calc.ts +141 -0
  461. package/src/owlly/utils/basic-tools.ts +286 -0
  462. package/src/owlly/utils/bvh-tree.ts +695 -0
  463. package/src/owlly/utils/camera.ts +72 -0
  464. package/src/owlly/utils/cube-texture-cache.ts +155 -0
  465. package/src/owlly/utils/device-utils.ts +53 -0
  466. package/src/owlly/utils/environment-utils.ts +81 -0
  467. package/src/owlly/utils/event-hub.ts +120 -0
  468. package/src/owlly/utils/events.ts +266 -0
  469. package/src/owlly/utils/geometry-utils.ts +749 -0
  470. package/src/owlly/utils/helper.ts +33 -0
  471. package/src/owlly/utils/index.ts +17 -0
  472. package/src/owlly/utils/lru-cache.ts +126 -0
  473. package/src/owlly/utils/map-utils.ts +55 -0
  474. package/src/owlly/utils/number-utils.ts +75 -0
  475. package/src/owlly/utils/panorama-model-util.ts +255 -0
  476. package/src/owlly/utils/path-utils.ts +837 -0
  477. package/src/owlly/utils/svgutils.ts +732 -0
  478. package/src/owlly/utils/texture-cache.ts +132 -0
  479. package/src/owlly/utils/tile-util.ts +563 -0
  480. package/src/owlly/utils/time-profiler.ts +57 -0
  481. package/src/owlly/view/__test__/perspective-view.spec.ts +23 -0
  482. package/src/owlly/view/camera-view.ts +114 -0
  483. package/src/owlly/view/index.ts +5 -0
  484. package/src/owlly/view/orthographic-view.ts +124 -0
  485. package/src/owlly/view/perspective-view.ts +125 -0
  486. package/src/owlly/view/svg-map-view.ts +187 -0
  487. package/src/owlly/view/view.ts +409 -0
  488. package/src/public/js/jsmpeg.min.js +3129 -0
  489. package/src/web/index.html +52 -0
  490. package/src/web/main.centroid.ts +85 -0
  491. package/src/web/main.hyma.meshline2d.ts +84 -0
  492. package/src/web/main.jyfang.sample.ts +139 -0
  493. package/src/web/main.rpeng.extrude.ts +194 -0
  494. package/src/web/main.rpeng.mes.plane.ts +161 -0
  495. package/src/web/main.rpeng.sample.ts +345 -0
  496. package/src/web/main.rpeng.vr.ts +159 -0
  497. package/src/web/main.sample.ts +59 -0
  498. package/src/web/quattree.hyma.ts +163 -0
  499. package/src/web/sensor-vr-plugin.ts +201 -0
  500. package/src/web/testPixel.png +0 -0
@@ -0,0 +1,1739 @@
1
+ /* eslint-disable max-len */
2
+ import TWEEN, { Group } from '@tweenjs/tween.js';
3
+ import { SceneUtils } from 'three/examples/jsm/utils/SceneUtils.js';
4
+ import { Externals, NS_THREE } from '../stage/externals';
5
+ import { BasicTools } from '../utils/basic-tools';
6
+ import { Overlay } from './overlay';
7
+ import { View } from '../view/view';
8
+ import { OwllyEvents, Events } from '../utils/events';
9
+ import { Env, EnvironmentUtils } from '../utils/environment-utils';
10
+
11
+ /**
12
+ * POI元素, 包含一个图标与一段文字
13
+ * @example
14
+ * ```typescript
15
+ * const poiOverlay = new PoiOverlay();
16
+ * const poi = poiOverlay.createPoi(new Vector3(0, 0, 0));
17
+ * ```
18
+ */
19
+ interface Rect {
20
+ xMin: number; xMax: number; yMin: number; yMax: number;
21
+ }
22
+
23
+
24
+ enum MouseState {
25
+ IDLE,
26
+ DOWN,
27
+ MOVE,
28
+ }
29
+
30
+ /**
31
+ * POI覆盖层, 可以展示POI图标与文字, 存在图标时以图标中心为中心, 否则为文字中心
32
+ * @example
33
+ * ```typescript
34
+ * const poiOverlay = new PoiOverlay();
35
+ * // 任意View
36
+ * view.addOverlay(poiOverlay);
37
+ * ```
38
+ */
39
+
40
+ class PoiOverlay extends Overlay {
41
+ static canvas: HTMLCanvasElement;
42
+
43
+ static ctx: CanvasRenderingContext2D;
44
+
45
+ private parent: View;
46
+
47
+ private rectMap: Map<Rect, Poi>;
48
+
49
+ private pois: Set<Poi>; // 按照level递增的顺序排
50
+
51
+ private mouseState: MouseState;
52
+
53
+ private mousePositionBuffer: NS_THREE.Vector2;
54
+
55
+ private eventTarget: Poi;
56
+
57
+ private enabled: boolean;
58
+
59
+ private renderThisFrame: boolean;
60
+
61
+ private visible: boolean; // 兼容
62
+
63
+ public camera: NS_THREE.Camera;
64
+
65
+ public scene: NS_THREE.Scene;
66
+
67
+ public renderCamera: NS_THREE.OrthographicCamera;
68
+
69
+ public renderer: NS_THREE.WebGL1Renderer;
70
+
71
+ public orderPois: Function;
72
+
73
+ // 这里有接收小程序传入的canvas,会调用小程序中的方法
74
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
+ // public canvas: any = {};
76
+
77
+ public prevPosition: NS_THREE.Vector3 | null;
78
+
79
+ public prevQuaternion: NS_THREE.Quaternion | null;
80
+
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ public prevZoom: any;
83
+
84
+ private needRender = false;
85
+
86
+ private listeners: {
87
+ pointerDown: (event: MouseEvent) => void;
88
+ pointerUp: (event: MouseEvent) => void;
89
+ touchStart: (event: TouchEvent) => void;
90
+ touchEnd: (event: TouchEvent) => void;
91
+ };
92
+
93
+ constructor(canvas?: HTMLCanvasElement) {
94
+ super();
95
+ if (EnvironmentUtils.GetEnv() === Env.Miniapp) {
96
+ if (!canvas) throw Error('poi-overlay need a offscreenCanvas');
97
+ PoiOverlay.canvas = canvas;
98
+ } else if (!PoiOverlay.canvas) {
99
+ PoiOverlay.canvas = document.createElement('canvas');
100
+ }
101
+ // fix: poi名字太长展示不全
102
+ const dpr = EnvironmentUtils.GetGlobalDPR();
103
+ PoiOverlay.canvas.width = 500 * dpr;
104
+ PoiOverlay.canvas.height = 500 * dpr;
105
+ PoiOverlay.ctx = PoiOverlay.canvas.getContext('2d') as CanvasRenderingContext2D;
106
+ }
107
+
108
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
+ // get canvas(): any {
110
+ // return PoiOverlay.canvas;
111
+ // }
112
+
113
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
+ // get ctx(): any {
115
+ // return PoiOverlay.canvas.getContext('2d');
116
+ // }
117
+
118
+ init(parent: View): void {
119
+ const { THREE } = Externals.getInstance();
120
+ this.rectMap = new Map();
121
+ this.parent = parent;
122
+ this.scene = new THREE.Scene();
123
+ const width = parent.getViewWidth();
124
+ const height = parent.getViewHeight();
125
+ this.renderCamera = new NS_THREE.OrthographicCamera(-width / 2, width / 2, height / 2, -height / 2, 0.1, 1000);
126
+ this.renderCamera.up.set(0, 1, 0);
127
+ this.renderCamera.position.set(0, 0, 50);
128
+ this.renderCamera.lookAt(0, 0, 0);
129
+ this.camera = this.parent.camera as NS_THREE.Camera;
130
+ this.renderer = this.parent.renderer as NS_THREE.WebGL1Renderer;
131
+ // const canvas = this.canvas;
132
+ // canvas.width = parent.getViewWidth();
133
+ // canvas.height = parent.getViewHeight();
134
+ // this.canvas = canvas; // 离屏canvas
135
+ this.pois = new Set();
136
+ this.enabled = true;
137
+ this.orderPois = BasicTools.debounce(this.orderPoisByLevel.bind(this), 50);
138
+ this.listeners = {
139
+ pointerDown: (e): void => { this.onPointerDown(e); },
140
+ pointerUp: (e): void => { this.onPointerUp(e); },
141
+ touchStart: (e): void => { this.onTouchStart(e); },
142
+ touchEnd: (e): void => { this.onTouchEnd(e); },
143
+ };
144
+ this.mouseState = MouseState.IDLE;
145
+ this.mousePositionBuffer = new THREE.Vector2();
146
+
147
+ this.parent.on(OwllyEvents.MOUSE_DOWN, this.listeners.pointerDown);
148
+ this.parent.on(OwllyEvents.MOUSE_UP, this.listeners.pointerUp);
149
+ this.parent.on(OwllyEvents.TOUCH_START, this.listeners.touchStart);
150
+ this.parent.on(OwllyEvents.TOUCH_END, this.listeners.touchEnd);
151
+ }
152
+
153
+ update(): boolean {
154
+ if (this.renderThisFrame || Array.from(this.pois).reduce((r, p) => (p.update() || r), false)) {
155
+ this.renderThisFrame = false;
156
+ this.needRender = true;
157
+ return true;
158
+ }
159
+ return false;
160
+ }
161
+
162
+ forceRenderInThisFrame(): void {
163
+ this.renderThisFrame = true;
164
+ }
165
+
166
+ render(): void {
167
+ if (!this.enabled) return;
168
+ const { THREE } = Externals.getInstance();
169
+ const frustum = new THREE.Frustum();
170
+ frustum.setFromProjectionMatrix(
171
+ new THREE.Matrix4().multiplyMatrices(
172
+ this.parent.camera!.projectionMatrix,
173
+ this.parent.camera!.matrixWorldInverse,
174
+ ),
175
+ );
176
+ const viewWidth = this.parent.getViewWidth();
177
+ const viewHeight = this.parent.getViewHeight();
178
+
179
+ const euler = new THREE.Euler();
180
+ euler.setFromQuaternion(this.parent.camera!.quaternion, 'ZYX');
181
+ this.checkUpdate();
182
+ if (this.needRender || this.renderThisFrame) {
183
+ this.rectMap.clear();
184
+ const inFrustumPois: Poi[] = [];
185
+ this.pois.forEach((p) => {
186
+ p.draw();
187
+ const { isInFrustum } = p.calcPosAndSize(
188
+ frustum,
189
+ viewWidth / 2,
190
+ viewHeight / 2,
191
+ );
192
+ if (isInFrustum) {
193
+ inFrustumPois.push(p);
194
+ }
195
+ });
196
+ this.recalculateVisibilities(inFrustumPois); // 计算可见性
197
+ Array.from(this.pois).forEach((p, index: number) => {
198
+ p.updatePosition(
199
+ viewWidth / 2,
200
+ viewHeight / 2,
201
+ index,
202
+ );
203
+ });
204
+ this.renderer.clearDepth();
205
+ this.renderer.render(this.scene, this.renderCamera);
206
+ }
207
+ this.renderThisFrame = false;
208
+ this.needRender = false;
209
+ }
210
+
211
+ orderPoisByLevel(): void { // 按level递增顺序排序, 以使得collision为false时 level高的渲染的比较高
212
+ const pois = Array.from(this.pois);
213
+ pois.sort((p, q) => p.getLevel() - q.getLevel());
214
+ this.pois = new Set(pois);
215
+ this.renderThisFrame = true;
216
+ }
217
+
218
+ recalculateVisibilities(pois: Poi[]): void { // 确定是否在视野范围内, 再推到range里, 不
219
+ // 碰撞测试
220
+ const range: [number, number, number, number][] = [];
221
+ let first = true;
222
+ Array.from(pois)
223
+ .sort((p, q) => (q.collision ? -1 : (q.getLevel() - p.getLevel())))
224
+ .forEach((poi): void => {
225
+ const {
226
+ xMin, yMin, xMax, yMax,
227
+ } = poi.getBoundingRect(); // 最小级别的碰撞检测盒
228
+
229
+ if (!poi.collision) {
230
+ poi.setHidden(false);
231
+ range.push([xMin, xMax, yMin, yMax]);
232
+ first = false;
233
+ return;
234
+ }
235
+
236
+ const {
237
+ xMin: oXMin, yMin: oYMin, xMax: oXMax, yMax: oYMax,
238
+ } = poi.getOuterRect(); // 最外层碰撞检测盒
239
+
240
+ if (first) {
241
+ range.push([xMin, xMax, yMin, yMax]);
242
+ first = false;
243
+ poi.setHidden(false);
244
+ return;
245
+ }
246
+
247
+ const valid = !range.some(([lx, rx, by, ty]) => {
248
+ const xIntersect = xMax < lx || xMin > rx; // x方向不重叠
249
+ const yIntersect = yMax < by || yMin > ty; // y 方向不重叠
250
+ return !xIntersect && !yIntersect;
251
+ });
252
+ if (valid) {
253
+ range.push([xMin, xMax, yMin, yMax]);
254
+ poi.setHidden(false);
255
+ } else if (poi.collisionMode === 'outer') {
256
+ poi.setHidden(true); // 全部隐藏
257
+ } else if (poi.collisionMode === 'icon' || poi.collisionMode === 'label') {
258
+ const subvalid = !range.some(([lx, rx, by, ty]) => {
259
+ const xIntersect = oXMax < lx || oXMin > rx; // x方向不重叠
260
+ const yIntersect = oYMax < by || oYMin > ty; // y 方向不重叠
261
+ return !xIntersect && !yIntersect;
262
+ });
263
+ if (subvalid) {
264
+ range.push([xMin, xMax, yMin, yMax]);
265
+ poi.setHidden(true, true); // 部分显示
266
+ } else {
267
+ poi.setHidden(true); // 全部隐藏
268
+ }
269
+ }
270
+ });
271
+ }
272
+
273
+ checkUpdate(): void {
274
+ // 检查更新
275
+ const { THREE } = Externals.getInstance();
276
+ if (this.renderThisFrame) return;
277
+ const poiNeedUpdate = Array.from(this.pois).some((p) => p.update());
278
+ if (poiNeedUpdate) {
279
+ this.renderThisFrame = true;
280
+ return;
281
+ }
282
+
283
+ const { camera } = this.parent;
284
+ const {
285
+ quaternion, position, zoom, up,
286
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
287
+ } = camera as any;
288
+ // 检查平移
289
+ const curPos = position.clone();
290
+ const curQuaternion = quaternion.clone();
291
+ const curZoom = zoom;
292
+
293
+ if (!this.prevPosition) {
294
+ this.prevPosition = curPos.clone();
295
+ this.prevQuaternion = curQuaternion.clone();
296
+ this.prevZoom = curZoom;
297
+ this.renderThisFrame = true;
298
+ return;
299
+ }
300
+ const quat1 = new THREE.Quaternion().setFromUnitVectors(up, new THREE.Vector3(0, 1, 0));
301
+ const lookAtVector1 = new THREE.Vector3(0, 0, -1).applyQuaternion(this.prevQuaternion as NS_THREE.Quaternion);
302
+ lookAtVector1.applyQuaternion(quat1);
303
+ const spherical1 = new THREE.Spherical();
304
+ spherical1.setFromVector3(lookAtVector1);
305
+
306
+ const quat2 = new THREE.Quaternion().setFromUnitVectors(up, new THREE.Vector3(0, 1, 0));
307
+ const lookAtVector2 = new THREE.Vector3(0, 0, -1).applyQuaternion(curQuaternion);
308
+ lookAtVector2.applyQuaternion(quat2);
309
+ const spherical2 = new THREE.Spherical();
310
+ spherical2.setFromVector3(lookAtVector2);
311
+
312
+ // eslint-disable-next-line max-len
313
+ if (Math.abs(spherical1.phi * (180 / Math.PI) - spherical2.phi * (180 / Math.PI)) + Math.abs(spherical1.theta * (180 / Math.PI) - spherical2.theta * (180 / Math.PI)) > 0.0001) {
314
+ this.prevPosition = curPos.clone();
315
+ this.prevQuaternion = curQuaternion.clone();
316
+ this.prevZoom = curZoom;
317
+ this.renderThisFrame = true;
318
+ return;
319
+ }
320
+
321
+ const viewWidth = this.parent.getViewWidth();
322
+ const viewHeight = this.parent.getViewHeight();
323
+ const curPagePos = curPos.clone().project(camera as THREE.Camera);
324
+ const curPagePosX = (curPagePos.x - 1) / 2 * viewWidth;
325
+ const curPagePosY = (1 - curPagePos.y) / 2 * viewHeight;
326
+ curPagePos.set(curPagePosX, curPagePosY, 0);
327
+ const prevPagePos = this.prevPosition.clone().project(camera as THREE.Camera);
328
+ const prevPagePosX = (prevPagePos.x - 1) / 2 * viewWidth;
329
+ const prevPagePosY = (1 - prevPagePos.y) / 2 * viewHeight;
330
+ prevPagePos.set(prevPagePosX, prevPagePosY, 0);
331
+ if (curPagePos.distanceTo(prevPagePos) > 0.0001) {
332
+ // console.log('检测到平移更新', prevPagePos, curPagePos, curPos, curPos.x, curPos.y, this.prevPosition.x, this.prevPosition.y, camera, quaternion);
333
+ // 平移
334
+ this.prevPosition = curPos.clone();
335
+ this.prevQuaternion = curQuaternion.clone();
336
+ this.prevZoom = curZoom;
337
+ this.renderThisFrame = true;
338
+ return;
339
+ }
340
+ // 非线性, zoom越小, 更新频率越快
341
+ // curZoom > this.prevZoom 时 在放大 zoom变大相同大小带来的更新减缓
342
+ // curZoom < this.prevZoom 时 在减小 zoom变小相同大小带来的更新加快
343
+ if (this.prevZoom !== curZoom
344
+ && (Math.abs((curZoom - this.prevZoom) / curZoom) > 0.0001)
345
+ || (Math.abs((this.prevZoom - curZoom) / this.prevZoom) > 0.0001)) {
346
+ // console.log('检测到zoom更新');
347
+ this.prevPosition = curPos.clone();
348
+ this.prevQuaternion = curQuaternion.clone();
349
+ this.prevZoom = curZoom;
350
+ this.renderThisFrame = true;
351
+ return;
352
+ }
353
+ this.renderThisFrame = false;
354
+ }
355
+
356
+ public dispose(): void {
357
+ this.parent.off(OwllyEvents.MOUSE_DOWN, this.listeners.pointerDown);
358
+ this.parent.off(OwllyEvents.MOUSE_UP, this.listeners.pointerUp);
359
+ this.parent.off(OwllyEvents.TOUCH_START, this.listeners.touchStart);
360
+ this.parent.off(OwllyEvents.TOUCH_END, this.listeners.touchEnd);
361
+ this.clearPoi();
362
+ if (PoiOverlay.canvas) {
363
+ PoiOverlay.canvas.remove();
364
+ PoiOverlay.canvas = null as unknown as HTMLCanvasElement;
365
+ }
366
+ if (PoiOverlay.ctx) {
367
+ PoiOverlay.ctx = null as unknown as CanvasRenderingContext2D;
368
+ }
369
+ }
370
+
371
+ private onPointerDown(e: MouseEvent): void {
372
+ const { clientX, clientY } = e;
373
+ const [left, top] = this.parent.getViewOffset();
374
+ const x = clientX - left;
375
+ const y = clientY - top;
376
+ let target = null;
377
+ Array.from(this.rectMap).some(([rect, poi]) => {
378
+ // v.visible && ( !v.hide || v.subHide)
379
+ const {
380
+ xMin, yMin, xMax, yMax,
381
+ } = rect;
382
+ const box2 = new NS_THREE.Box2(
383
+ new NS_THREE.Vector2(xMin, yMin), new NS_THREE.Vector2(xMax, yMax),
384
+ );
385
+ if (box2.containsPoint(new NS_THREE.Vector2(x, y))) {
386
+ target = poi;
387
+ return true;
388
+ }
389
+ return false;
390
+ });
391
+ if (target) {
392
+ this.onNodePointerDown(target, x, y, e.button);
393
+ }
394
+ }
395
+
396
+ private onPointerUp(e: MouseEvent): void {
397
+ const { THREE } = Externals.getInstance();
398
+ const { clientX, clientY } = e;
399
+ const [left, top] = this.parent.getViewOffset();
400
+ const x = clientX - left;
401
+ const y = clientY - top;
402
+ const distance = new THREE.Vector2(x, y).distanceToSquared(this.mousePositionBuffer);
403
+ this.emit(Events.POI_UP, this.eventTarget, e.button);
404
+ if (this.mouseState === MouseState.DOWN && distance < 100) {
405
+ this.emit(Events.POI_CLICKED, this.eventTarget, e.button);
406
+ }
407
+ this.mouseState = MouseState.IDLE;
408
+ }
409
+
410
+ private onTouchStart(e: TouchEvent): void {
411
+ const { clientX, clientY } = e.touches[0];
412
+ const [left, top] = this.parent.getViewOffset();
413
+ const x = clientX - left;
414
+ const y = clientY - top;
415
+ let target = null;
416
+ Array.from(this.rectMap).some(([rect, poi]) => {
417
+ // v.visible && ( !v.hide || v.subHide)
418
+ const {
419
+ xMin, yMin, xMax, yMax,
420
+ } = rect;
421
+ const box2 = new NS_THREE.Box2(
422
+ new NS_THREE.Vector2(xMin, yMin), new NS_THREE.Vector2(xMax, yMax),
423
+ );
424
+ if (box2.containsPoint(new NS_THREE.Vector2(x, y))) {
425
+ target = poi;
426
+ return true;
427
+ }
428
+ return false;
429
+ });
430
+ if (target) {
431
+ this.onNodePointerDown(target, x, y, 0);
432
+ }
433
+ }
434
+
435
+ private onTouchEnd(e: TouchEvent): void {
436
+ const { THREE } = Externals.getInstance();
437
+ const { clientX, clientY } = e.changedTouches[0];
438
+ const [left, top] = this.parent.getViewOffset();
439
+ const x = clientX - left;
440
+ const y = clientY - top;
441
+ const distance = new THREE.Vector2(x, y).distanceToSquared(this.mousePositionBuffer);
442
+ this.emit(Events.POI_UP, this.eventTarget, 0);
443
+ if (this.mouseState === MouseState.DOWN && distance < 100) {
444
+ this.emit(Events.POI_CLICKED, this.eventTarget, 0);
445
+ }
446
+ this.mouseState = MouseState.IDLE;
447
+ }
448
+
449
+ private onNodePointerDown(target: Poi, x: number, y: number, button = 0): void {
450
+ if (this.mouseState !== MouseState.IDLE) return;
451
+ this.mouseState = MouseState.DOWN;
452
+ this.mousePositionBuffer.set(x, y);
453
+ this.eventTarget = target;
454
+ this.emit(Events.POI_DOWN, target, button);
455
+ }
456
+
457
+ /**
458
+ * 新建POI
459
+ * @param position POI在3D空间中的位置
460
+ */
461
+ public createPoi(position: NS_THREE.Vector3): Poi {
462
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
463
+ const poi = new Poi();
464
+ poi.setParent(this);
465
+ this.renderThisFrame = true;
466
+ poi.setPosition(position);
467
+ if (!this.pois) throw Error('poiOverlay need bind a view, use view.addOverlay()');
468
+ this.pois.add(poi);
469
+ this.scene.add(poi.group!);
470
+ return poi;
471
+ }
472
+
473
+ public setRectMap(rect: Rect, ele: Poi): void {
474
+ this.rectMap.set(rect, ele);
475
+ }
476
+
477
+ /**
478
+ * 删除POI
479
+ * @param poi 待删除的POI
480
+ */
481
+ public removePoi(poi: Poi): void {
482
+ this.pois.delete(poi);
483
+ this.scene.remove(poi.group!);
484
+ poi.dispose();
485
+ this.renderThisFrame = true;
486
+ }
487
+
488
+ public clearPoi(): void{
489
+ const pois = Array.from(this.pois);
490
+ pois.forEach((poi) => {
491
+ this.scene.remove(poi.group!);
492
+ });
493
+ this.pois.clear();
494
+ this.renderThisFrame = true;
495
+ }
496
+
497
+ /**
498
+ * 设置覆盖层可见性 兼容旧poi
499
+ * @param visible 覆盖层是否可见
500
+ */
501
+ public setVisibility(visible: boolean): void {
502
+ this.visible = visible;
503
+ this.enabled = visible;
504
+ }
505
+
506
+ public setEnabled(value: boolean): void {
507
+ this.enabled = value;
508
+ }
509
+
510
+ public resize(viewWidth: number, viewHeight: number): void {
511
+ this.updateCameraAspect(viewWidth, viewHeight);
512
+ this.renderThisFrame = true;
513
+ }
514
+
515
+ private updateCameraAspect(viewWidth: number, viewHeight: number): void {
516
+ const width = viewWidth;
517
+ const height = viewHeight;
518
+ this.renderCamera.left = -width / 2;
519
+ this.renderCamera.right = width / 2;
520
+ this.renderCamera.top = height / 2;
521
+ this.renderCamera.bottom = -height / 2;
522
+ this.renderCamera.updateProjectionMatrix();
523
+ }
524
+ }
525
+ PoiOverlay.canvas = document.createElement('canvas');
526
+ PoiOverlay.ctx = PoiOverlay.canvas.getContext('2d') as CanvasRenderingContext2D;
527
+
528
+
529
+ class Poi {
530
+ static ImageMaterialMap = new Map();
531
+
532
+ private position: NS_THREE.Vector3;
533
+
534
+ private screenPosition: { x: number; y: number };
535
+
536
+ private visible: boolean;
537
+
538
+ private hide: boolean;
539
+
540
+ private parent: PoiOverlay|null;
541
+
542
+ private subHide: boolean;
543
+
544
+ private textVisibility: boolean; // 做兼容, 未用到
545
+
546
+ private iconVisibility: boolean; // 做兼容, 未用到
547
+
548
+ private animationEnabled: boolean;
549
+
550
+ public isInFrustum: boolean;
551
+
552
+ private textPosInfo: {
553
+ anchor: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
554
+ offsetX: number; // 相对position
555
+ offsetY: number; // 相对position
556
+ anchorOffsetX: number; // 相对设置的position, 为 正 表示向右偏移
557
+ anchorOffsetY: number; // 相对设置的position, 为 正 表示向上偏移
558
+ }
559
+
560
+ private iconPosInfo: {
561
+ anchor: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright';
562
+ offsetX: number; // 相对锚点
563
+ offsetY: number; // 相对锚点
564
+ anchorOffsetX: number; // 相对设置的position
565
+ anchorOffsetY: number; // 相对设置的position
566
+ }
567
+
568
+ // 是否开启自动旋转
569
+ // 开启时跟随画布一起旋转
570
+ // 默认:false
571
+ private autoRotation: boolean;
572
+
573
+ private rotation: number;
574
+
575
+ public collision: boolean;
576
+
577
+ private boundingBox: NS_THREE.Group | null;
578
+
579
+ private overlapArea: { x: number; y: number }; // 开启碰撞检测时允许设置可重叠区域
580
+
581
+ public collisionMode: string; // icon || label || outer
582
+
583
+ private withBoundingBox: boolean;
584
+
585
+ private subAreaOpacity: number; // 在设置
586
+
587
+ private abandonedAreaOpacity: number;
588
+
589
+ private visiblePartWhenCollision: string;
590
+
591
+ // 用于计算poi碰撞边界
592
+ private boundingRect: Rect;
593
+
594
+ // 用于计算poi全部展示区域边界
595
+ private outerRect: Rect;
596
+
597
+ private iconCircleOptions: {
598
+ width: number;
599
+ color: string;
600
+ }
601
+
602
+ private iconInCircle: boolean;
603
+
604
+ private iconRect: Rect;
605
+
606
+ private textRect: Rect;
607
+
608
+ private visibilityAnimation: {
609
+ anim: TWEEN.Tween | null;
610
+ from: number | null;
611
+ to: number | null;
612
+ current: number | null;
613
+ };
614
+
615
+ private textWidth: number;
616
+
617
+ private textHeight: number;
618
+
619
+ private iconSize: [number, number];
620
+
621
+ private textMaterial: NS_THREE.MeshBasicMaterial | null;
622
+
623
+ private iconMaterial: NS_THREE.MeshBasicMaterial | null;
624
+
625
+ private iconCircleMaterial: NS_THREE.MeshBasicMaterial | null;
626
+
627
+ private rectMaterial: NS_THREE.MeshBasicMaterial | null;
628
+
629
+
630
+ private text: NS_THREE.Mesh | null;
631
+
632
+ private icon: NS_THREE.Group | null;
633
+
634
+ public group: NS_THREE.Group | null;
635
+
636
+ public poiId: number;
637
+
638
+ // private renderThisFrame: boolean;
639
+
640
+ private iconOptions: { size: [number, number]; src: null | string };
641
+
642
+ private labelOptions: { fontSize: number; padding: number; content: null | string };
643
+
644
+ // eslint-disable-next-line max-len
645
+ private rectOptions: { width: number; height: number; fill: number | string; opacity: number; offsetX: number; offsetY: number };
646
+
647
+ private withRect: boolean;
648
+
649
+ private rect: NS_THREE.Group | null;
650
+
651
+ private level: number;
652
+
653
+ private dpr: number;
654
+
655
+ private isFlipY: boolean;
656
+
657
+ private _renderThisFrame = false;
658
+
659
+ private labelOpacity: number;
660
+
661
+ private iconOpacity: number;
662
+
663
+ private set renderThisFrame(value: boolean) {
664
+ this._renderThisFrame = value;
665
+ }
666
+
667
+ private get renderThisFrame(): boolean {
668
+ return this._renderThisFrame;
669
+ }
670
+
671
+ constructor(position?: NS_THREE.Vector3) {
672
+ const { THREE } = Externals.getInstance();
673
+ this.dpr = EnvironmentUtils.GetGlobalDPR();
674
+ this.isFlipY = false;
675
+ this.position = position || new THREE.Vector3();
676
+ this.group = new NS_THREE.Group();
677
+ this.textVisibility = true;
678
+ this.iconVisibility = true;
679
+ this.iconInCircle = false;
680
+ this.iconCircleOptions = {
681
+ width: 0,
682
+ color: '#ffffff',
683
+ };
684
+ this.textPosInfo = {
685
+ anchor: 'center',
686
+ offsetX: 0,
687
+ offsetY: 0,
688
+ anchorOffsetX: 0,
689
+ anchorOffsetY: 0,
690
+ };
691
+ this.iconPosInfo = {
692
+ anchor: 'center',
693
+ offsetX: 0,
694
+ offsetY: 0,
695
+ anchorOffsetX: 0,
696
+ anchorOffsetY: 0,
697
+ };
698
+ this.level = 1;
699
+ this.isInFrustum = false;
700
+ this.animationEnabled = false;
701
+ this.text = null;
702
+ this.icon = null;
703
+ this.rect = null;
704
+ this.boundingBox = null;
705
+ this.overlapArea = { x: 0, y: 0 };
706
+ this.visible = true; // 检查是否用到
707
+ this.hide = false;
708
+ this.subHide = false;
709
+ this.rotation = 0;
710
+ this.autoRotation = false;
711
+ this.collision = true;
712
+ this.collisionMode = 'outer';
713
+ this.iconRect = {
714
+ xMin: 0,
715
+ yMin: 0,
716
+ xMax: 0,
717
+ yMax: 0,
718
+ };
719
+ this.textRect = {
720
+ xMin: 0,
721
+ yMin: 0,
722
+ xMax: 0,
723
+ yMax: 0,
724
+ };
725
+ this.boundingRect = {
726
+ xMin: 0,
727
+ yMin: 0,
728
+ xMax: 0,
729
+ yMax: 0,
730
+ };
731
+
732
+ this.outerRect = {
733
+ xMin: 0,
734
+ yMin: 0,
735
+ xMax: 0,
736
+ yMax: 0,
737
+ };
738
+ this.visibilityAnimation = {
739
+ anim: null,
740
+ from: 1,
741
+ to: 1,
742
+ current: 1,
743
+ };
744
+ this.text = null;
745
+ this.textWidth = 0;
746
+ this.textHeight = 0;
747
+ this.icon = null;
748
+ this.iconOptions = {
749
+ size: [20, 20],
750
+ src: null,
751
+ };
752
+ this.labelOptions = {
753
+ fontSize: 12,
754
+ padding: 0,
755
+ content: null,
756
+ };
757
+
758
+ this.rectOptions = {
759
+ width: 0,
760
+ height: 0,
761
+ fill: 0xff0000,
762
+ opacity: 0.5,
763
+ offsetX: 0,
764
+ offsetY: 0,
765
+ };
766
+ this.visiblePartWhenCollision = 'none';
767
+ this.subAreaOpacity = 1;
768
+ this.abandonedAreaOpacity = 1;
769
+ this.screenPosition = { x: 0, y: 0 };
770
+ this.labelOpacity = 1;
771
+ this.iconOpacity = 1;
772
+ }
773
+
774
+ public dispose(): void{
775
+ if (this.group) {
776
+ BasicTools.dispose(this.group, true);
777
+ }
778
+ this.parent = null;
779
+ this.iconCircleMaterial = null;
780
+ this.iconMaterial = null;
781
+ this.textMaterial = null;
782
+ this.icon = null;
783
+ this.rect = null;
784
+ this.boundingBox = null;
785
+ this.group = null;
786
+ }
787
+
788
+ public setParent(parent: PoiOverlay): void {
789
+ this.parent = parent;
790
+ }
791
+
792
+ public setPosition(position: NS_THREE.Vector3, tolerance = 0.0001): void {
793
+ if (position.distanceTo(this.position) < tolerance) return;
794
+ this.position.copy(position);
795
+ this.renderThisFrame = true;
796
+ }
797
+
798
+ public setOpacity(labelOpacity = this.labelOpacity, iconOpacity = this.iconOpacity): void {
799
+ this.labelOpacity = labelOpacity;
800
+ this.iconOpacity = iconOpacity;
801
+ }
802
+
803
+ /**
804
+ * 设置旋转角度
805
+ * @param rotation 旋转角度
806
+ */
807
+ public setRotation(rotation: number, tolerance = 0.0001): void {
808
+ if (Math.abs(rotation - this.rotation) < tolerance) return;
809
+ this.group!.rotateZ(rotation - this.rotation);
810
+ this.rotation = rotation;
811
+ this.renderThisFrame = true;
812
+ }
813
+
814
+ /**
815
+ * 设置是否碰撞
816
+ * @param collision 是否碰撞
817
+ */
818
+ public setCollision(collision: boolean): void {
819
+ this.collision = collision;
820
+ this.renderThisFrame = true;
821
+ }
822
+
823
+ /**
824
+ * 设置碰撞模式
825
+ * @param mode 碰撞模式 label || icon || outer(默认)
826
+ */
827
+ public setCollisionMode(mode: string): void {
828
+ this.collisionMode = mode;
829
+ this.renderThisFrame = true;
830
+ }
831
+
832
+ public setLabelVisibility(visible: boolean): void {
833
+ this.textVisibility = visible;
834
+ this.renderThisFrame = true;
835
+ }
836
+
837
+ public setIconVisiblity(visible: boolean): void {
838
+ this.iconVisibility = visible;
839
+ this.renderThisFrame = true;
840
+ }
841
+
842
+ public setHideModeWhenCollision(mode: string): void {
843
+ // 即将废弃
844
+ if (mode === 'all') {
845
+ this.setVisiblePartWhenCollision('none');
846
+ } else if (mode === 'none') {
847
+ this.setVisiblePartWhenCollision('all');
848
+ } else {
849
+ this.setVisiblePartWhenCollision(mode);
850
+ }
851
+ }
852
+
853
+ // 碰撞下的显隐: 全部显示 / 全部隐藏 / label隐藏 / icon隐藏
854
+ public setVisiblePartWhenCollision(part: string): void {
855
+ this.visiblePartWhenCollision = part;
856
+ }
857
+
858
+ public setCollisionOverlap(x: number, y: number): void {
859
+ this.overlapArea = { x, y };
860
+ this.renderThisFrame = true;
861
+ }
862
+
863
+ /**
864
+ * 设置POI层级
865
+ * @param level 层级
866
+ */
867
+ public setLevel(level: number, forceOrder = false): void {
868
+ this.level = level;
869
+ this.renderThisFrame = true;
870
+ this.parent!.orderPois(forceOrder);
871
+ }
872
+
873
+ /**
874
+ * 获取POI层级
875
+ */
876
+ public getLevel(): number {
877
+ return this.level;
878
+ }
879
+
880
+ /**
881
+ * 设置POI可见性
882
+ * @param visible 可见性
883
+ */
884
+ public setVisibility(visible: boolean): void {
885
+ if (this.visible !== visible) this.renderThisFrame = true;
886
+ this.visible = visible;
887
+ }
888
+
889
+ /**
890
+ * 设置POI是否暂时隐藏
891
+ * @param hide true 全部隐藏 false: 根据 hideModeWhenCollision 做显隐判断
892
+ */
893
+ public setHidden(hide: boolean, subHide = false): void {
894
+ // 优先级 hide > subHide
895
+ // hide 为 false 完全显示
896
+ // hide === true && subHide === true 部分显示
897
+ // hide === true && subHide === false 全部隐藏
898
+ if (!this.animationEnabled) {
899
+ if (this.hide !== hide || this.subHide !== subHide) {
900
+ this.hide = hide;
901
+ this.subHide = subHide;
902
+ this.renderThisFrame = true;
903
+ }
904
+ } else {
905
+ // 在动画中 判断终点是否相同
906
+ // eslint-disable-next-line no-nested-ternary
907
+ const to = !hide ? 1 : (subHide ? 0.5 : 0);
908
+ if (this.visibilityAnimation.anim && to === this.visibilityAnimation.to) return;
909
+ // 不在动画中 判断 hide === this.hide && subHide === this.subHide
910
+ if (!this.visibilityAnimation.anim && (hide === this.hide && subHide === this.subHide)) return;
911
+ if (this.visibilityAnimation.anim) { // 假设之前在执行, ani.stop()
912
+ this.visibilityAnimation.anim!.stop();
913
+ this.visibilityAnimation.anim = null;
914
+ }
915
+ const start = { subAreaOpacity: this.subAreaOpacity, abandonedAreaOpacity: this.abandonedAreaOpacity };
916
+ const end = { subAreaOpacity: 0, abandonedAreaOpacity: 0 };
917
+
918
+ if (hide) { // hide = true 隐藏 || 部分显示
919
+ if (subHide) {
920
+ // 部分显示
921
+ end.subAreaOpacity = 1;
922
+ end.abandonedAreaOpacity = 0;
923
+ } else {
924
+ // 全部隐藏
925
+ end.subAreaOpacity = 0;
926
+ end.abandonedAreaOpacity = 0;
927
+ }
928
+ } else { // !hide 完全展示
929
+ end.subAreaOpacity = 1;
930
+ end.abandonedAreaOpacity = 1;
931
+ }
932
+ let subMaterials: NS_THREE.MeshBasicMaterial[] = [];
933
+ const abandonedMaterials: NS_THREE.MeshBasicMaterial[] = [];
934
+ switch (this.visiblePartWhenCollision) {
935
+ case 'all':
936
+ if (this.text) {
937
+ subMaterials.push(this.textMaterial as NS_THREE.MeshBasicMaterial);
938
+ }
939
+ // if (this.rect) {
940
+ // subMaterials.push(this.rectMaterial);
941
+ // }
942
+ if (this.icon) {
943
+ subMaterials.push(this.iconMaterial as NS_THREE.MeshBasicMaterial);
944
+ if (this.iconCircleMaterial && this.iconCircleMaterial.visible) {
945
+ subMaterials.push(this.iconCircleMaterial as NS_THREE.MeshBasicMaterial);
946
+ }
947
+ }
948
+ break;
949
+ case 'none':
950
+ if (this.text) {
951
+ abandonedMaterials.push(this.textMaterial as NS_THREE.MeshBasicMaterial);
952
+ }
953
+ if (this.icon) {
954
+ abandonedMaterials.push(this.iconMaterial as NS_THREE.MeshBasicMaterial);
955
+ if (this.iconCircleMaterial && this.iconCircleMaterial.visible) {
956
+ abandonedMaterials.push(this.iconCircleMaterial as NS_THREE.MeshBasicMaterial);
957
+ }
958
+ }
959
+ break;
960
+ case 'label':
961
+ // eslint-disable-next-line max-len
962
+ subMaterials = [this.textMaterial as NS_THREE.MeshBasicMaterial, this.rectMaterial as NS_THREE.MeshBasicMaterial];
963
+ if (this.text) {
964
+ subMaterials.push(this.textMaterial as NS_THREE.MeshBasicMaterial);
965
+ }
966
+ if (this.icon) {
967
+ abandonedMaterials.push(this.iconMaterial as NS_THREE.MeshBasicMaterial);
968
+ if (this.iconCircleMaterial && this.iconCircleMaterial.visible) {
969
+ abandonedMaterials.push(this.iconCircleMaterial as NS_THREE.MeshBasicMaterial);
970
+ }
971
+ }
972
+ break;
973
+ case 'icon':
974
+ if (this.text) {
975
+ abandonedMaterials.push(this.textMaterial as NS_THREE.MeshBasicMaterial);
976
+ }
977
+ if (this.icon) {
978
+ subMaterials.push(this.iconMaterial as NS_THREE.MeshBasicMaterial);
979
+ if (this.iconCircleMaterial && this.iconCircleMaterial.visible) {
980
+ subMaterials.push(this.iconCircleMaterial as NS_THREE.MeshBasicMaterial);
981
+ }
982
+ }
983
+ break;
984
+ default:
985
+ break;
986
+ }
987
+ this.visibilityAnimation.from = this.visibilityAnimation.current;
988
+ // eslint-disable-next-line no-nested-ternary
989
+ this.visibilityAnimation.to = !hide ? 1 : (subHide ? 0.5 : 0);
990
+ // 动画
991
+ const duration = 300;
992
+ this.visibilityAnimation.anim = new TWEEN.Tween(start).to(end, duration).onUpdate((cur) => {
993
+ this.subAreaOpacity = cur.subAreaOpacity;
994
+ this.abandonedAreaOpacity = cur.abandonedAreaOpacity;
995
+ subMaterials.forEach((areaM: NS_THREE.MeshBasicMaterial) => {
996
+ areaM.opacity = cur.subAreaOpacity;
997
+ });
998
+ abandonedMaterials.forEach((areaM: NS_THREE.MeshBasicMaterial) => {
999
+ areaM.opacity = cur.abandonedAreaOpacity;
1000
+ });
1001
+ }).start()
1002
+ .onComplete(() => {
1003
+ this.visibilityAnimation.anim = null;
1004
+ this.visibilityAnimation.from = null;
1005
+ this.visibilityAnimation.current = null;
1006
+ this.visibilityAnimation.to = null;
1007
+ this.hide = hide;
1008
+ this.subHide = subHide;
1009
+ });
1010
+ }
1011
+ }
1012
+
1013
+ /**
1014
+ * 设置Rect是否可见
1015
+ * @param withRect 可见性
1016
+ */
1017
+ public setRect(withRect: boolean): void {
1018
+ this.withRect = withRect;
1019
+ this.renderThisFrame = true;
1020
+ }
1021
+
1022
+ /**
1023
+ * 设置Rect默认宽高 未废弃, 不发挥作用
1024
+ * @param withRect 可见性
1025
+ */
1026
+ private setRectDefSize(width: number, height: number): void {
1027
+ this.rectOptions.width = width;
1028
+ this.rectOptions.height = height;
1029
+ this.renderThisFrame = true;
1030
+ }
1031
+
1032
+ /**
1033
+ * 设置Rect背景色 未废弃, 不发挥作用
1034
+ * @param color
1035
+ */
1036
+ public setRectFill(color: number | string): void {
1037
+ this.rectOptions.fill = color;
1038
+ this.renderThisFrame = true;
1039
+ }
1040
+
1041
+ /**
1042
+ * 设置Rect偏移 未废弃, 不发挥作用
1043
+ * @param x
1044
+ * @param y
1045
+ */
1046
+ public setRectOffset(x = 0, y = 0): void {
1047
+ this.rectOptions.offsetX = x;
1048
+ this.rectOptions.offsetY = y;
1049
+ this.renderThisFrame = true;
1050
+ }
1051
+
1052
+ public setIconImage(src: string): void {
1053
+ if (this.iconOptions && this.iconOptions.src === src) return;
1054
+ this.iconOptions.src = src;
1055
+ this.clearIcon();
1056
+ this.renderThisFrame = true;
1057
+ }
1058
+
1059
+ public setIconSize(width: number, height: number): void {
1060
+ this.iconSize = [width, height];
1061
+ this.iconOptions.size = [width, height];
1062
+ this.renderThisFrame = true;
1063
+ }
1064
+
1065
+ /**
1066
+ * 设置POI中icon的显示
1067
+ */
1068
+ public setIconShowInCircle(lineWidth: number, lineColor: string): void {
1069
+ this.iconInCircle = true;
1070
+ this.iconCircleOptions = {
1071
+ width: lineWidth,
1072
+ color: lineColor,
1073
+ };
1074
+ }
1075
+
1076
+ drawIcon(): void {
1077
+ const { src, size } = this.iconOptions;
1078
+ if (!src) return;
1079
+ if (this.icon
1080
+ && this.group!.getObjectByName('poi_icon')
1081
+ && !!this.iconInCircle === !!this.iconCircleMaterial
1082
+ ) return;
1083
+ if (!Poi.ImageMaterialMap.has(src)) {
1084
+ Poi.ImageMaterialMap.set(src, 'dealing');
1085
+ const loader = new NS_THREE.TextureLoader();
1086
+ loader.load(src, (texture) => {
1087
+ texture.needsUpdate = true;
1088
+ texture.magFilter = NS_THREE.LinearFilter;
1089
+ // fix: ios 16.4 纹理变黑块
1090
+ texture.minFilter = NS_THREE.NearestFilter;
1091
+ texture.flipY = this.isFlipY;
1092
+ const material = new NS_THREE.MeshBasicMaterial({
1093
+ map: texture,
1094
+ transparent: true,
1095
+ opacity: this.iconOpacity,
1096
+ });
1097
+ material.needsUpdate = true;
1098
+ material.visible = true;
1099
+ Poi.ImageMaterialMap.set(src, material);
1100
+ });
1101
+ } else if (Poi.ImageMaterialMap.get(src) === 'dealing') {
1102
+ this.renderThisFrame = true;
1103
+ } else {
1104
+ if (this.icon) this.group!.remove(this.icon);
1105
+ this.iconMaterial = Poi.ImageMaterialMap.get(src).clone();
1106
+ this.iconMaterial!.opacity = this.iconOpacity;
1107
+ const { width: cWidth, color: cColor } = this.iconCircleOptions;
1108
+ const ifDrawCircle = cWidth && this.iconInCircle;
1109
+ if (ifDrawCircle) {
1110
+ this.iconCircleMaterial = new NS_THREE.MeshBasicMaterial({
1111
+ color: cColor,
1112
+ transparent: true,
1113
+ opacity: this.iconOpacity,
1114
+ });
1115
+ }
1116
+ const mats = ifDrawCircle ? [
1117
+ this.iconCircleMaterial as NS_THREE.Material,
1118
+ this.iconMaterial as NS_THREE.Material,
1119
+ ] : [
1120
+ this.iconMaterial as NS_THREE.Material,
1121
+ ];
1122
+ const iconGeo = ifDrawCircle ? new NS_THREE.CircleGeometry(size[0] / 2, 30) : new NS_THREE.PlaneGeometry(size[0], size[1]);
1123
+ const icon = SceneUtils.createMultiMaterialObject(
1124
+ iconGeo,
1125
+ mats,
1126
+ );
1127
+ this.icon = icon;
1128
+ if (this.icon) {
1129
+ // console.log('cWidth', size[0], cWidth);
1130
+ if (this.icon.children.length > 1) {
1131
+ this.icon!.children[1].scale.set(size[0] / (cWidth + size[0]), size[0] / (cWidth + size[0]), 1);
1132
+ }
1133
+ this.icon.renderOrder = 3;
1134
+ this.icon.name = 'poi_icon';
1135
+ this.group!.add(this.icon);
1136
+ this.renderThisFrame = true;
1137
+ }
1138
+ }
1139
+ }
1140
+
1141
+ private clearIcon(): void {
1142
+ if (!this.icon) return;
1143
+ if (this.group) {
1144
+ this.group.remove(this.icon);
1145
+ }
1146
+ this.icon.children.forEach((mesh: NS_THREE.Mesh) => {
1147
+ if (mesh.geometry) {
1148
+ mesh.geometry.dispose();
1149
+ }
1150
+ });
1151
+ if (this.iconMaterial) {
1152
+ this.iconMaterial.dispose();
1153
+ this.iconMaterial = null;
1154
+ }
1155
+ if (this.iconCircleMaterial) {
1156
+ this.iconCircleMaterial.dispose();
1157
+ this.iconCircleMaterial = null;
1158
+ }
1159
+ this.icon = null;
1160
+ }
1161
+
1162
+ /**
1163
+ * 设置图标相对(0,0)的位置
1164
+ * @param direction: x / y value: + / - 表示方向
1165
+ * x = 2 的时候, 表示label 中心 和 icon 中心 同一条y轴, label 右边框 距离 icon 左边框2个单位
1166
+ */
1167
+ public setIconAnchor(
1168
+ anchor: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright',
1169
+ ): void {
1170
+ this.iconPosInfo.anchor = anchor;
1171
+ this.renderThisFrame = true;
1172
+ }
1173
+
1174
+ /**
1175
+ * 设置图标反转
1176
+ */
1177
+ public setIconFlipY(flipY: boolean): void {
1178
+ this.isFlipY = flipY;
1179
+ }
1180
+
1181
+ public setIconOffset(x: number, y: number): void {
1182
+ this.iconPosInfo.anchorOffsetX = x;
1183
+ this.iconPosInfo.anchorOffsetY = y;
1184
+ this.renderThisFrame = true;
1185
+ }
1186
+
1187
+ /**
1188
+ * 设置文字字体大小
1189
+ * @param fontSize 字号, 单位为px
1190
+ */
1191
+ public setFontSize(fontSize: number): void {
1192
+ this.labelOptions.fontSize = fontSize;
1193
+ this.renderThisFrame = true;
1194
+ }
1195
+
1196
+ public setFontPadding(fPadding: number): void {
1197
+ this.labelOptions.padding = fPadding;
1198
+ this.renderThisFrame = true;
1199
+ }
1200
+
1201
+ public setLabelText(text: string): void {
1202
+ this.labelOptions.content = text;
1203
+ this.renderThisFrame = true;
1204
+ }
1205
+
1206
+ public drawText(): void {
1207
+ if (!this.labelOptions.content) return;
1208
+ if (this.group!.getObjectByName('poi_text')) return;
1209
+ const dpr = this.dpr;
1210
+ const { fontSize, padding, content } = this.labelOptions;
1211
+ (PoiOverlay.ctx as CanvasRenderingContext2D).font = `${fontSize * dpr}px sans-serif`;
1212
+ (PoiOverlay.ctx as CanvasRenderingContext2D).fillStyle = 'black';
1213
+ const textSize = (PoiOverlay.ctx as CanvasRenderingContext2D).measureText(content as string);
1214
+ const textWidth = Math.ceil(textSize.width) + 10 + (padding * 2);
1215
+ const textHeight = (fontSize + 5 + (padding * 2)) * dpr;
1216
+ this.textWidth = textWidth / dpr;
1217
+ this.textHeight = textHeight / dpr;
1218
+ this.setRectDefSize(this.textWidth, this.textHeight); // 根据text占据位置自动设置rect大小
1219
+ (PoiOverlay.ctx as CanvasRenderingContext2D).clearRect(0, 0, textWidth, textHeight);
1220
+ (PoiOverlay.ctx as CanvasRenderingContext2D).fillText(content as string, padding * dpr, (fontSize + padding) * dpr);
1221
+ const textImageData = (PoiOverlay.ctx as CanvasRenderingContext2D).getImageData(0, 0, textWidth, textHeight);
1222
+ this.textMaterial = new NS_THREE.MeshBasicMaterial({
1223
+ transparent: true,
1224
+ map: new NS_THREE.DataTexture(
1225
+ Uint8Array.from(textImageData.data),
1226
+ textWidth,
1227
+ textHeight,
1228
+ NS_THREE.RGBAFormat,
1229
+ ),
1230
+ side: NS_THREE.DoubleSide,
1231
+ opacity: this.labelOpacity,
1232
+ });
1233
+ this.text = new NS_THREE.Mesh(
1234
+ new NS_THREE.PlaneGeometry(this.textWidth, this.textHeight),
1235
+ this.textMaterial as NS_THREE.MeshBasicMaterial,
1236
+ );
1237
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1238
+ (this.text.material as any).map.flipY = true;
1239
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1240
+ (this.text.material as any).map.flipX = true;
1241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1242
+ (this.text.material as any).map.needsUpdate = true;
1243
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1244
+ (this.text.material as any).map.magFilter = NS_THREE.LinearFilter;
1245
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1246
+ (this.text.material as any).visible = true;
1247
+ this.text.name = 'poi_text';
1248
+ this.text.renderOrder = 4;
1249
+ const {
1250
+ offsetX, offsetY,
1251
+ } = this.recalcOffset(
1252
+ this.textWidth,
1253
+ this.textHeight,
1254
+ this.textPosInfo.anchor,
1255
+ this.textPosInfo.anchorOffsetX,
1256
+ this.textPosInfo.anchorOffsetY,
1257
+ );
1258
+ this.textPosInfo.offsetX = offsetX;
1259
+ this.textPosInfo.offsetY = offsetY;
1260
+ this.group!.add(this.text);
1261
+ }
1262
+
1263
+ public recalcOffset(width: number,
1264
+ height: number,
1265
+ anchor: string,
1266
+ anchorOffsetX: number,
1267
+ anchorOffsetY: number): { offsetX: number; offsetY: number } {
1268
+ // 在已有text宽高情况下计算 textOffsetX 和 textOffsetY
1269
+ let offsetX = 0;
1270
+ let offsetY = 0;
1271
+ switch (anchor) {
1272
+ case 'center':
1273
+ // 默认
1274
+ offsetX = anchorOffsetX;
1275
+ offsetY = anchorOffsetY;
1276
+ break;
1277
+ case 'left':
1278
+ offsetX = width / 2 + anchorOffsetX;
1279
+ offsetY = anchorOffsetY;
1280
+ break;
1281
+ case 'right':
1282
+ offsetX = -width / 2 + anchorOffsetX;
1283
+ offsetY = anchorOffsetY;
1284
+ break;
1285
+ case 'top':
1286
+ offsetX = anchorOffsetX;
1287
+ offsetY = -height / 2 + anchorOffsetY;
1288
+ break;
1289
+ case 'bottom':
1290
+ offsetX = anchorOffsetX;
1291
+ offsetY = height / 2 + anchorOffsetY;
1292
+ break;
1293
+ case 'topleft':
1294
+ offsetX = width / 2 + anchorOffsetX;
1295
+ offsetY = -height / 2 + anchorOffsetY;
1296
+ break;
1297
+ case 'topright':
1298
+ offsetX = -width / 2 + anchorOffsetX;
1299
+ offsetY = -height / 2 + anchorOffsetY;
1300
+ break;
1301
+ case 'bottomleft':
1302
+ offsetX = width / 2 + anchorOffsetX;
1303
+ offsetY = height / 2 + anchorOffsetY;
1304
+ break;
1305
+ case 'bottomright':
1306
+ offsetX = -width / 2 + anchorOffsetX;
1307
+ offsetY = height / 2 + anchorOffsetY;
1308
+ break;
1309
+ default:
1310
+ break;
1311
+ }
1312
+ return { offsetX, offsetY };
1313
+ }
1314
+
1315
+ /**
1316
+ * 设置POI文字相对(0,0)的位置。在有icon 和 无icon时锚点不同
1317
+ * @param direction: x / y value: + / - 表示方向
1318
+ * x = 2 的时候, 表示label 中心 和 icon 中心 同一条y轴, label 右边框 距离 icon 左边框2个单位
1319
+ */
1320
+ public setLabelAnchor(
1321
+ anchor: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright',
1322
+ ): void {
1323
+ // center label的锚点在 position
1324
+ // top position在label 上方线条的中心
1325
+ // left position在label 左边线条的中心
1326
+ this.textPosInfo.anchor = anchor;
1327
+ this.renderThisFrame = true;
1328
+ }
1329
+
1330
+ public setLabelOffset(x: number, y: number): void {
1331
+ this.textPosInfo.anchorOffsetX = x;
1332
+ this.textPosInfo.anchorOffsetY = y;
1333
+ this.renderThisFrame = true;
1334
+ }
1335
+
1336
+ public getLabelAnchor(): 'center' | 'left' | 'right' | 'top' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright' {
1337
+ return this.textPosInfo.anchor;
1338
+ }
1339
+
1340
+ public getLabelOffset(): { x: number; y: number } {
1341
+ const { anchorOffsetX, anchorOffsetY } = this.textPosInfo;
1342
+ return { x: anchorOffsetX, y: anchorOffsetY };
1343
+ }
1344
+
1345
+ calcBoundingSize(): void { // 2D画布上的 size
1346
+ const pos = this.screenPosition;
1347
+ const textOffsetX = this.textPosInfo.offsetX;
1348
+ const textOffsetY = this.textPosInfo.offsetY;
1349
+
1350
+ const iconOffsetX = this.iconPosInfo.offsetX;
1351
+ const iconOffsetY = this.iconPosInfo.offsetY;
1352
+
1353
+ const label = {
1354
+ xMin: this.text ? pos.x - this.textWidth / 2 + textOffsetX : pos.x,
1355
+ xMax: this.text ? pos.x + this.textWidth / 2 + textOffsetX : pos.x,
1356
+ yMin: this.text ? pos.y - this.textHeight / 2 - textOffsetY : pos.y,
1357
+ yMax: this.text ? pos.y + this.textHeight / 2 - textOffsetY : pos.y,
1358
+ };
1359
+
1360
+ const icon = {
1361
+ xMin: this.icon ? pos.x - this.iconOptions.size[0] / 2 + iconOffsetX : pos.x,
1362
+ xMax: this.icon ? pos.x + this.iconOptions.size[0] / 2 + iconOffsetX : pos.x,
1363
+ yMin: this.icon ? pos.y - this.iconOptions.size[1] / 2 - iconOffsetY : pos.y,
1364
+ yMax: this.icon ? pos.y + this.iconOptions.size[1] / 2 - iconOffsetY : pos.y,
1365
+ };
1366
+
1367
+ let xMax = Math.max(icon.xMax, label.xMax);
1368
+ let xMin = Math.min(icon.xMin, label.xMin);
1369
+ let yMax = Math.max(icon.yMax, label.yMax);
1370
+ let yMin = Math.min(icon.yMin, label.yMin);
1371
+
1372
+ this.iconRect = {
1373
+ xMin: this.icon ? pos.x - this.iconOptions.size[0] / 2 + iconOffsetX : pos.x,
1374
+ xMax: this.icon ? pos.x + this.iconOptions.size[0] / 2 + iconOffsetX : pos.x,
1375
+ yMin: this.icon ? pos.y - this.iconOptions.size[1] / 2 - iconOffsetY : pos.y,
1376
+ yMax: this.icon ? pos.y + this.iconOptions.size[1] / 2 - iconOffsetY : pos.y,
1377
+ };
1378
+
1379
+ this.textRect = {
1380
+ xMin: this.text ? pos.x - this.textWidth / 2 + textOffsetX : pos.x,
1381
+ xMax: this.text ? pos.x + this.textWidth / 2 + textOffsetX : pos.x,
1382
+ yMin: this.text ? pos.y - this.textHeight / 2 - textOffsetY : pos.y,
1383
+ yMax: this.text ? pos.y + this.textHeight / 2 - textOffsetY : pos.y,
1384
+ };
1385
+ this.outerRect = {
1386
+ xMax, xMin, yMax, yMin,
1387
+ };
1388
+ if (this.collisionMode === 'icon') {
1389
+ xMax = icon.xMax;
1390
+ xMin = icon.xMin;
1391
+ yMax = icon.yMax;
1392
+ yMin = icon.yMin;
1393
+ } else if (this.collisionMode === 'label') {
1394
+ xMax = label.xMax;
1395
+ xMin = label.xMin;
1396
+ yMax = label.yMax;
1397
+ yMin = label.yMin;
1398
+ }
1399
+ // 得到 x 的 最大(> 0)和最小(< 0), y 的 最大(>0)和最小(<0)
1400
+ this.boundingRect.xMax = xMax;
1401
+ this.boundingRect.yMax = yMax;
1402
+ this.boundingRect.xMin = xMin;
1403
+ this.boundingRect.yMin = yMin;
1404
+ }
1405
+
1406
+ private drawRect(): void {
1407
+ if (!this.withRect || !this.labelOptions.content) return;
1408
+ if (this.rect && this.group!.getObjectByName('poi_rect')) return;
1409
+ this.rect = new NS_THREE.Group();
1410
+ const rWidth = this.rectOptions.width || this.textWidth;
1411
+ const rHeight = this.rectOptions.height || this.textHeight;
1412
+ const cornerR = 10;
1413
+ const x = 0;
1414
+ const y = 0;
1415
+ const rightT1 = [x + rWidth / 2 - cornerR, y + rHeight / 2];
1416
+ const rightT2 = [x + rWidth / 2, y + rHeight / 2 - cornerR];
1417
+ const rightB1 = [x + rWidth / 2, y - rHeight / 2 + cornerR];
1418
+ const rightB2 = [x + rWidth / 2 - cornerR, y - rHeight / 2];
1419
+ const leftB1 = [x - rWidth / 2 + cornerR, y - rHeight / 2];
1420
+ const leftB2 = [x - rWidth / 2, y - rHeight / 2 + cornerR];
1421
+ const leftT1 = [x - rWidth / 2, y + rHeight / 2 - cornerR];
1422
+ const leftT2 = [x - rWidth / 2 + cornerR, y + rHeight / 2];
1423
+ const rectShape = new NS_THREE.Shape();
1424
+ rectShape.moveTo(rightT1[0], rightT1[1]);
1425
+ rectShape.bezierCurveTo(rightT1[0], rightT1[1], x + rWidth / 2, y + rHeight / 2, rightT2[0], rightT2[1]);
1426
+ rectShape.moveTo(rightB1[0], rightB1[1]);
1427
+ rectShape.bezierCurveTo(rightB1[0], rightB1[1], x + rWidth / 2, y - rHeight / 2, rightB2[0], rightB2[1]);
1428
+ rectShape.moveTo(leftB1[0], leftB1[1]);
1429
+ rectShape.bezierCurveTo(leftB1[0], leftB1[1], x - rWidth / 2, y - rHeight / 2, leftB2[0], leftB2[1]);
1430
+ rectShape.moveTo(leftT1[0], leftT1[1]);
1431
+ rectShape.bezierCurveTo(leftT1[0], leftT1[1], x - rWidth / 2, y + rHeight / 2, leftT2[0], leftT2[1]);
1432
+ rectShape.moveTo(rightT1[0], rightT1[1]);
1433
+ const geometry = new NS_THREE.ShapeGeometry(rectShape);
1434
+ const material = new NS_THREE.MeshBasicMaterial({
1435
+ color: 0x0000ff,
1436
+ transparent: true,
1437
+ opacity: 0.5,
1438
+ });
1439
+ this.rectMaterial = material;
1440
+ const mesh = new NS_THREE.Mesh(geometry, material);
1441
+ rectShape.autoClose = true;
1442
+ const points = rectShape.getPoints();
1443
+ const geometryPoints = new NS_THREE.BufferGeometry().setFromPoints(points);
1444
+ const line = new NS_THREE.Line(geometryPoints, new NS_THREE.LineBasicMaterial({ color: 0xff0000 }));
1445
+ line.position.set(0, 0, 0);
1446
+ this.rect.add(mesh);
1447
+ this.rect.add(line);
1448
+ this.rect.renderOrder = 2;
1449
+ this.rect.name = 'poi_rect';
1450
+ this.group!.add(this.rect);
1451
+ }
1452
+
1453
+ private drawBoundingBox(): void {
1454
+ if (!this.withBoundingBox) return;
1455
+ if (this.group!.getObjectByName('poi_bounding_rect')) return;
1456
+ if (this.outerRect.xMin === 0 && this.outerRect.xMax === 0) return;
1457
+ const {
1458
+ xMax, yMax, xMin, yMin,
1459
+ } = this.outerRect;
1460
+ this.boundingBox = new NS_THREE.Group();
1461
+ const cornerR = 10;
1462
+ const x = 0;
1463
+ const y = 0;
1464
+ const width = xMax - xMin;
1465
+ const height = yMax - yMin;
1466
+ const rightT1 = [x + width / 2 - cornerR, y + height / 2];
1467
+ const rightT2 = [x + width / 2, y + height / 2 - cornerR];
1468
+ const rightB1 = [x + width / 2, y - height / 2 + cornerR];
1469
+ const rightB2 = [x + width / 2 - cornerR, y - height / 2];
1470
+ const leftB1 = [x - width / 2 + cornerR, y - height / 2];
1471
+ const leftB2 = [x - width / 2, y - height / 2 + cornerR];
1472
+ const leftT1 = [x - width / 2, y + height / 2 - cornerR];
1473
+ const leftT2 = [x - width / 2 + cornerR, y + height / 2];
1474
+ const rectShape = new NS_THREE.Shape();
1475
+ rectShape.moveTo(rightT1[0], rightT1[1]);
1476
+ rectShape.bezierCurveTo(rightT1[0], rightT1[1], x + width / 2, y + height / 2, rightT2[0], rightT2[1]);
1477
+ rectShape.moveTo(rightB1[0], rightB1[1]);
1478
+ rectShape.bezierCurveTo(rightB1[0], rightB1[1], x + width / 2, y - height / 2, rightB2[0], rightB2[1]);
1479
+ rectShape.moveTo(leftB1[0], leftB1[1]);
1480
+ rectShape.bezierCurveTo(leftB1[0], leftB1[1], x - width / 2, y - height / 2, leftB2[0], leftB2[1]);
1481
+ rectShape.moveTo(leftT1[0], leftT1[1]);
1482
+ rectShape.bezierCurveTo(leftT1[0], leftT1[1], x - width / 2, y + height / 2, leftT2[0], leftT2[1]);
1483
+ rectShape.moveTo(rightT1[0], rightT1[1]);
1484
+ const geometry = new NS_THREE.ShapeGeometry(rectShape);
1485
+ const material = new NS_THREE.MeshBasicMaterial({
1486
+ color: 0xff0000,
1487
+ transparent: true,
1488
+ opacity: 0.5,
1489
+ });
1490
+ const mesh = new NS_THREE.Mesh(geometry, material);
1491
+ rectShape.autoClose = true;
1492
+ const points = rectShape.getPoints();
1493
+ const geometryPoints = new NS_THREE.BufferGeometry().setFromPoints(points);
1494
+ const line = new NS_THREE.Line(geometryPoints, new NS_THREE.LineBasicMaterial({ color: 0xff0000, linewidth: 2 }));
1495
+ line.position.set(0, 0, 0);
1496
+ this.boundingBox.name = 'poi_bounding_rect';
1497
+ this.boundingBox.add(mesh);
1498
+ this.boundingBox.add(line);
1499
+ this.boundingBox.renderOrder = 0;
1500
+ this.group!.add(this.boundingBox);
1501
+ }
1502
+
1503
+ public setBoundingBox(): void {
1504
+ this.withBoundingBox = true;
1505
+ }
1506
+
1507
+ /** @ignore */
1508
+ public getBoundingRect(): { xMin: number; yMin: number; xMax: number; yMax: number } {
1509
+ const { x: ox, y: oy } = this.overlapArea;
1510
+ const {
1511
+ xMin: xmin, yMin: ymin, xMax: xmax, yMax: ymax,
1512
+ } = this.boundingRect;
1513
+ return {
1514
+ xMin: xmin + ox,
1515
+ yMin: ymin + oy,
1516
+ xMax: xmax - ox,
1517
+ yMax: ymax - oy,
1518
+ };
1519
+ }
1520
+
1521
+ /** @ignore */
1522
+ public getOuterRect(): { xMin: number; yMin: number; xMax: number; yMax: number } {
1523
+ const { x: ox, y: oy } = this.overlapArea;
1524
+ const {
1525
+ xMin: xmin, yMin: ymin, xMax: xmax, yMax: ymax,
1526
+ } = this.outerRect;
1527
+ return {
1528
+ xMin: xmin + ox,
1529
+ yMin: ymin + oy,
1530
+ xMax: xmax - ox,
1531
+ yMax: ymax - oy,
1532
+ };
1533
+ }
1534
+
1535
+ public setAnimationEnabled(value: boolean): void {
1536
+ this.animationEnabled = value;
1537
+ }
1538
+
1539
+ // 获取旋转角度
1540
+ private calcPoiRotation(cameraDeg: number): number {
1541
+ if (this.autoRotation) {
1542
+ return cameraDeg + this.rotation;
1543
+ }
1544
+ return this.rotation;
1545
+ }
1546
+
1547
+ public getVisibility(): boolean {
1548
+ return this.visible;
1549
+ }
1550
+
1551
+ public calcPosAndSize(frustum: NS_THREE.Frustum, widthHalf: number, heightHalf: number): { isInFrustum: boolean } { // 重新计算位置和包围盒/ 不现实的话不推入rectMap
1552
+ if (!this.parent) {
1553
+ return { isInFrustum: this.isInFrustum };
1554
+ }
1555
+ let isInFrustum = this.visible && frustum.containsPoint(this.position);
1556
+ if (isInFrustum) {
1557
+ const p = this.position.clone().project(this.parent!.camera);
1558
+ this.screenPosition = { x: (p.x + 1) * widthHalf, y: (1 - p.y) * heightHalf };
1559
+ this.calcBoundingSize();
1560
+ // 计算与view是否相交
1561
+ if (this.outerRect.xMin < 0 || this.outerRect.xMax > widthHalf * 2 || this.outerRect.yMin < 0 || this.outerRect.yMax > heightHalf * 2) {
1562
+ isInFrustum = false;
1563
+ }
1564
+ }
1565
+ this.isInFrustum = isInFrustum;
1566
+ return {
1567
+ isInFrustum: this.isInFrustum,
1568
+ };
1569
+ }
1570
+
1571
+
1572
+ public draw(): void {
1573
+ this.drawText();
1574
+ this.drawIcon();
1575
+ this.drawRect();
1576
+ this.drawBoundingBox();
1577
+ }
1578
+
1579
+ public updatePosition( // 根据已计算出的position, offset, visible 等更新渲染位置, 显隐
1580
+ widthHalf: number,
1581
+ heightHalf: number,
1582
+ index: number,
1583
+ ): void {
1584
+ if (!this.group) return;
1585
+ if (!this.isInFrustum) {
1586
+ this.hide = true;
1587
+ this.subHide = false;
1588
+ this.group!.visible = false;
1589
+ return;
1590
+ }
1591
+
1592
+ this.group!.visible = this.visible;
1593
+ if (!this.visible) {
1594
+ return;
1595
+ }
1596
+ const textOffsetX = this.textPosInfo.offsetX;
1597
+ const textOffsetY = this.textPosInfo.offsetY;
1598
+ const iconOffsetX = this.iconPosInfo.offsetX;
1599
+ const iconOffsetY = this.iconPosInfo.offsetY;
1600
+ const zIndex = index * 0.0001; // index是根据level递增排序的
1601
+ this.group!.position.set(this.screenPosition.x - widthHalf, heightHalf - this.screenPosition.y, zIndex);
1602
+
1603
+ if (this.text) {
1604
+ this.text.position.set(textOffsetX, textOffsetY, 0);
1605
+ }
1606
+ if (this.rect) {
1607
+ this.rect.position.set(textOffsetX, textOffsetY, 0);
1608
+ }
1609
+ if (this.icon) {
1610
+ this.icon.position.set(iconOffsetX, iconOffsetY, 0);
1611
+ }
1612
+ if (this.boundingBox) {
1613
+ const pos2dx = (this.outerRect.xMax + this.outerRect.xMin) / 2;
1614
+ const pos2dy = (this.outerRect.yMax + this.outerRect.yMin) / 2;
1615
+ this.boundingBox.position.set(pos2dx - this.screenPosition.x, this.screenPosition.y - pos2dy, 0);
1616
+ }
1617
+
1618
+ const animating = this.visibilityAnimation.anim; // onComplete 时候会销毁
1619
+ const groupVisible = !!animating || (!animating && (!this.hide || this.subHide));
1620
+ this.group!.visible = groupVisible;
1621
+ // console.log('groupVisible', groupVisible, !this.hide, this.subHide, (!this.hide || this.subHide));
1622
+ // subArea 和 abandonedArea 的展示
1623
+ // 1- 根据碰撞检测结果和碰撞类型判断group icon text 的显示
1624
+ // 2- 上一步通过, 则判断 当前是否设置了 iconVisibility 和 textVisibility
1625
+ if (groupVisible && (!animating || !this.animationEnabled)) { // 显示 && 动画执行完 || 无设置动画效果
1626
+ let subAreas: Array<NS_THREE.Mesh | NS_THREE.Group> = [];
1627
+ let abandonedAreas: Array<NS_THREE.Mesh | NS_THREE.Group> = [];
1628
+ switch (this.visiblePartWhenCollision) {
1629
+ case 'all':
1630
+ subAreas = [this.group!];
1631
+ abandonedAreas = [];
1632
+ break;
1633
+ case 'none':
1634
+ subAreas = [];
1635
+ abandonedAreas = [this.group!];
1636
+ break;
1637
+ case 'label':
1638
+ subAreas = [];
1639
+ if (this.text) {
1640
+ subAreas.push(this.text);
1641
+ }
1642
+ if (this.rect) {
1643
+ subAreas.push(this.rect);
1644
+ }
1645
+ if (this.icon) {
1646
+ abandonedAreas.push(this.icon);
1647
+ }
1648
+ break;
1649
+ case 'icon':
1650
+ if (this.icon) {
1651
+ subAreas.push(this.icon);
1652
+ }
1653
+ if (this.text) {
1654
+ abandonedAreas.push(this.text);
1655
+ }
1656
+ if (this.rect) {
1657
+ abandonedAreas.push(this.rect);
1658
+ }
1659
+ break;
1660
+ default:
1661
+ subAreas = [];
1662
+ abandonedAreas = [this.group!];
1663
+ break;
1664
+ }
1665
+ if (this.subHide) { // 部分显示
1666
+ subAreas.forEach((area: NS_THREE.Mesh | NS_THREE.Group) => {
1667
+ area.visible = true;
1668
+ if (area instanceof NS_THREE.Group) {
1669
+ area.children.forEach((child: NS_THREE.Mesh) => {
1670
+ child.visible = true;
1671
+ });
1672
+ }
1673
+ });
1674
+ abandonedAreas.forEach((area: NS_THREE.Mesh | NS_THREE.Group) => {
1675
+ area.visible = false;
1676
+ if (area instanceof NS_THREE.Group) {
1677
+ area.children.forEach((child: NS_THREE.Mesh) => {
1678
+ child.visible = false;
1679
+ });
1680
+ }
1681
+ });
1682
+ } else if (!this.hide) { // 全部显示
1683
+ subAreas.forEach((area: NS_THREE.Mesh | NS_THREE.Group) => {
1684
+ area.visible = true;
1685
+ if (area instanceof NS_THREE.Group) {
1686
+ area.children.forEach((child: NS_THREE.Mesh) => {
1687
+ child.visible = true;
1688
+ });
1689
+ }
1690
+ });
1691
+ abandonedAreas.forEach((area: NS_THREE.Mesh | NS_THREE.Group) => {
1692
+ area.visible = true;
1693
+ if (area instanceof NS_THREE.Group) {
1694
+ area.children.forEach((child: NS_THREE.Mesh) => {
1695
+ child.visible = true;
1696
+ });
1697
+ }
1698
+ });
1699
+ }
1700
+ if (this.icon && !this.iconVisibility) { // 独立设置了icon不允许显示
1701
+ this.icon.visible = false;
1702
+ }
1703
+ if (this.text && !this.textVisibility) { // 独立设置了text不允许显示
1704
+ this.text.visible = false;
1705
+ }
1706
+ }
1707
+ if (!groupVisible) {
1708
+ // do nothing
1709
+ } else if (this.subHide) {
1710
+ if (this.parent) {
1711
+ // 部分显示
1712
+ if (this.visiblePartWhenCollision === 'icon') {
1713
+ this.parent!.setRectMap(this.iconRect, this);
1714
+ } else {
1715
+ this.parent!.setRectMap(this.textRect, this);
1716
+ }
1717
+ }
1718
+ } else if (this.parent) {
1719
+ // fix: poi-click 不触发
1720
+ this.parent.setRectMap(this.textRect, this);
1721
+ this.parent.setRectMap(this.iconRect, this);
1722
+ }
1723
+
1724
+ // this.renderThisFrame = true;
1725
+ }
1726
+
1727
+ public update(): boolean {
1728
+ const needRender = this.renderThisFrame || (this.isInFrustum && !!this.iconOptions.src && !this.icon);
1729
+ this.renderThisFrame = false;
1730
+ return needRender;
1731
+ }
1732
+
1733
+ public setPoiId(poiId: number): void {
1734
+ this.poiId = poiId;
1735
+ }
1736
+ }
1737
+ Poi.ImageMaterialMap = new Map();
1738
+
1739
+ export { PoiOverlay, Poi };