@vyr/three 0.0.15 → 0.0.16

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 (379) hide show
  1. package/build/actor/ComposerServiceActor.d.ts +23 -0
  2. package/build/actor/ComposerServiceActor.js +93 -0
  3. package/build/actor/ComposerServiceActor.js.map +1 -0
  4. package/build/actor/GeometryActor.d.ts +7 -0
  5. package/build/actor/GeometryActor.js +10 -0
  6. package/build/actor/GeometryActor.js.map +1 -0
  7. package/build/actor/HTMLConvertActor.d.ts +14 -0
  8. package/build/actor/HTMLConvertActor.js +52 -0
  9. package/build/actor/HTMLConvertActor.js.map +1 -0
  10. package/build/actor/MaterialActor.d.ts +7 -0
  11. package/build/actor/MaterialActor.js +10 -0
  12. package/build/actor/MaterialActor.js.map +1 -0
  13. package/build/actor/NodeActor.d.ts +9 -0
  14. package/build/actor/NodeActor.js +21 -0
  15. package/build/actor/NodeActor.js.map +1 -0
  16. package/build/actor/OrbitControllerActor.d.ts +20 -0
  17. package/build/actor/OrbitControllerActor.js +103 -0
  18. package/build/actor/OrbitControllerActor.js.map +1 -0
  19. package/build/actor/PassActor.d.ts +8 -0
  20. package/build/actor/PassActor.js +16 -0
  21. package/build/actor/PassActor.js.map +1 -0
  22. package/build/actor/SceneServiceActor.d.ts +21 -0
  23. package/build/actor/SceneServiceActor.js +112 -0
  24. package/build/actor/SceneServiceActor.js.map +1 -0
  25. package/build/actor/TextureActor.d.ts +7 -0
  26. package/build/actor/TextureActor.js +10 -0
  27. package/build/actor/TextureActor.js.map +1 -0
  28. package/build/actor/TransformControllerActor.d.ts +10 -0
  29. package/build/actor/TransformControllerActor.js +19 -0
  30. package/build/actor/TransformControllerActor.js.map +1 -0
  31. package/build/actor/index.d.ts +8 -0
  32. package/build/actor/index.js +11 -0
  33. package/build/actor/index.js.map +1 -0
  34. package/build/asset/index.d.ts +1 -0
  35. package/build/asset/index.js +219 -0
  36. package/build/asset/index.js.map +1 -0
  37. package/build/controls/CameraControls.d.ts +647 -0
  38. package/build/controls/CameraControls.js +2332 -0
  39. package/build/controls/CameraControls.js.map +1 -0
  40. package/build/controls/TransformControls.d.ts +72 -0
  41. package/build/controls/TransformControls.js +1359 -0
  42. package/build/controls/TransformControls.js.map +1 -0
  43. package/build/controls/index.d.ts +2 -0
  44. package/build/controls/index.js +3 -0
  45. package/build/controls/index.js.map +1 -0
  46. package/build/descriptor/ComposerServiceDescriptor.d.ts +33 -0
  47. package/build/descriptor/ComposerServiceDescriptor.js +42 -0
  48. package/build/descriptor/ComposerServiceDescriptor.js.map +1 -0
  49. package/build/descriptor/GeoMapDescriptor.d.ts +12 -0
  50. package/build/descriptor/GeoMapDescriptor.js +22 -0
  51. package/build/descriptor/GeoMapDescriptor.js.map +1 -0
  52. package/build/descriptor/HTMLConvertDescriptor.d.ts +6 -0
  53. package/build/descriptor/HTMLConvertDescriptor.js +10 -0
  54. package/build/descriptor/HTMLConvertDescriptor.js.map +1 -0
  55. package/build/descriptor/InstancedMeshDescriptor.d.ts +12 -0
  56. package/build/descriptor/InstancedMeshDescriptor.js +12 -0
  57. package/build/descriptor/InstancedMeshDescriptor.js.map +1 -0
  58. package/build/descriptor/MeshDescriptor.d.ts +8 -0
  59. package/build/descriptor/MeshDescriptor.js +14 -0
  60. package/build/descriptor/MeshDescriptor.js.map +1 -0
  61. package/build/descriptor/ModelDescriptor.d.ts +7 -0
  62. package/build/descriptor/ModelDescriptor.js +12 -0
  63. package/build/descriptor/ModelDescriptor.js.map +1 -0
  64. package/build/descriptor/OrbitControllerDescriptor.d.ts +54 -0
  65. package/build/descriptor/OrbitControllerDescriptor.js +73 -0
  66. package/build/descriptor/OrbitControllerDescriptor.js.map +1 -0
  67. package/build/descriptor/OrthographicCameraDescriptor.d.ts +6 -0
  68. package/build/descriptor/OrthographicCameraDescriptor.js +10 -0
  69. package/build/descriptor/OrthographicCameraDescriptor.js.map +1 -0
  70. package/build/descriptor/ParticleDescriptor.d.ts +55 -0
  71. package/build/descriptor/ParticleDescriptor.js +85 -0
  72. package/build/descriptor/ParticleDescriptor.js.map +1 -0
  73. package/build/descriptor/PassDescriptor.d.ts +16 -0
  74. package/build/descriptor/PassDescriptor.js +23 -0
  75. package/build/descriptor/PassDescriptor.js.map +1 -0
  76. package/build/descriptor/PerspectiveCameraDescriptor.d.ts +7 -0
  77. package/build/descriptor/PerspectiveCameraDescriptor.js +12 -0
  78. package/build/descriptor/PerspectiveCameraDescriptor.js.map +1 -0
  79. package/build/descriptor/PointsDescriptor.d.ts +8 -0
  80. package/build/descriptor/PointsDescriptor.js +14 -0
  81. package/build/descriptor/PointsDescriptor.js.map +1 -0
  82. package/build/descriptor/SceneServiceDescriptor.d.ts +20 -0
  83. package/build/descriptor/SceneServiceDescriptor.js +35 -0
  84. package/build/descriptor/SceneServiceDescriptor.js.map +1 -0
  85. package/build/descriptor/SpriteDescriptor.d.ts +8 -0
  86. package/build/descriptor/SpriteDescriptor.js +14 -0
  87. package/build/descriptor/SpriteDescriptor.js.map +1 -0
  88. package/build/descriptor/TextDescriptor.d.ts +21 -0
  89. package/build/descriptor/TextDescriptor.js +37 -0
  90. package/build/descriptor/TextDescriptor.js.map +1 -0
  91. package/build/descriptor/TransformControllerDescriptor.d.ts +20 -0
  92. package/build/descriptor/TransformControllerDescriptor.js +22 -0
  93. package/build/descriptor/TransformControllerDescriptor.js.map +1 -0
  94. package/build/descriptor/animation/AnimationActionDescriptor.d.ts +27 -0
  95. package/build/descriptor/animation/AnimationActionDescriptor.js +46 -0
  96. package/build/descriptor/animation/AnimationActionDescriptor.js.map +1 -0
  97. package/build/descriptor/geometry/BoxGeometryDescriptor.d.ts +14 -0
  98. package/build/descriptor/geometry/BoxGeometryDescriptor.js +23 -0
  99. package/build/descriptor/geometry/BoxGeometryDescriptor.js.map +1 -0
  100. package/build/descriptor/geometry/BufferGeometryDescriptor.d.ts +8 -0
  101. package/build/descriptor/geometry/BufferGeometryDescriptor.js +12 -0
  102. package/build/descriptor/geometry/BufferGeometryDescriptor.js.map +1 -0
  103. package/build/descriptor/geometry/CircleGeometryDescriptor.d.ts +12 -0
  104. package/build/descriptor/geometry/CircleGeometryDescriptor.js +19 -0
  105. package/build/descriptor/geometry/CircleGeometryDescriptor.js.map +1 -0
  106. package/build/descriptor/geometry/CylinderGeometryDescriptor.d.ts +16 -0
  107. package/build/descriptor/geometry/CylinderGeometryDescriptor.js +27 -0
  108. package/build/descriptor/geometry/CylinderGeometryDescriptor.js.map +1 -0
  109. package/build/descriptor/geometry/ExtrudeGeometryDescriptor.d.ts +18 -0
  110. package/build/descriptor/geometry/ExtrudeGeometryDescriptor.js +33 -0
  111. package/build/descriptor/geometry/ExtrudeGeometryDescriptor.js.map +1 -0
  112. package/build/descriptor/geometry/GeometryDescriptor.d.ts +5 -0
  113. package/build/descriptor/geometry/GeometryDescriptor.js +7 -0
  114. package/build/descriptor/geometry/GeometryDescriptor.js.map +1 -0
  115. package/build/descriptor/geometry/PlaneGeometryDescriptor.d.ts +12 -0
  116. package/build/descriptor/geometry/PlaneGeometryDescriptor.js +19 -0
  117. package/build/descriptor/geometry/PlaneGeometryDescriptor.js.map +1 -0
  118. package/build/descriptor/geometry/RingGeometryDescriptor.d.ts +14 -0
  119. package/build/descriptor/geometry/RingGeometryDescriptor.js +23 -0
  120. package/build/descriptor/geometry/RingGeometryDescriptor.js.map +1 -0
  121. package/build/descriptor/geometry/SphereGeometryDescriptor.d.ts +14 -0
  122. package/build/descriptor/geometry/SphereGeometryDescriptor.js +24 -0
  123. package/build/descriptor/geometry/SphereGeometryDescriptor.js.map +1 -0
  124. package/build/descriptor/geometry/SurfaceGeometryDescriptor.d.ts +8 -0
  125. package/build/descriptor/geometry/SurfaceGeometryDescriptor.js +12 -0
  126. package/build/descriptor/geometry/SurfaceGeometryDescriptor.js.map +1 -0
  127. package/build/descriptor/geometry/TubeGeometryDescriptor.d.ts +13 -0
  128. package/build/descriptor/geometry/TubeGeometryDescriptor.js +23 -0
  129. package/build/descriptor/geometry/TubeGeometryDescriptor.js.map +1 -0
  130. package/build/descriptor/helper/AxesHelperDescriptor.d.ts +5 -0
  131. package/build/descriptor/helper/AxesHelperDescriptor.js +7 -0
  132. package/build/descriptor/helper/AxesHelperDescriptor.js.map +1 -0
  133. package/build/descriptor/index.d.ts +43 -0
  134. package/build/descriptor/index.js +46 -0
  135. package/build/descriptor/index.js.map +1 -0
  136. package/build/descriptor/light/AmbientLightDescriptor.d.ts +5 -0
  137. package/build/descriptor/light/AmbientLightDescriptor.js +7 -0
  138. package/build/descriptor/light/AmbientLightDescriptor.js.map +1 -0
  139. package/build/descriptor/light/DirectionalLightDescriptor.d.ts +20 -0
  140. package/build/descriptor/light/DirectionalLightDescriptor.js +21 -0
  141. package/build/descriptor/light/DirectionalLightDescriptor.js.map +1 -0
  142. package/build/descriptor/light/HemisphereLightDescriptor.d.ts +8 -0
  143. package/build/descriptor/light/HemisphereLightDescriptor.js +12 -0
  144. package/build/descriptor/light/HemisphereLightDescriptor.js.map +1 -0
  145. package/build/descriptor/light/LightDescriptor.d.ts +8 -0
  146. package/build/descriptor/light/LightDescriptor.js +14 -0
  147. package/build/descriptor/light/LightDescriptor.js.map +1 -0
  148. package/build/descriptor/light/PointLightDescriptor.d.ts +15 -0
  149. package/build/descriptor/light/PointLightDescriptor.js +21 -0
  150. package/build/descriptor/light/PointLightDescriptor.js.map +1 -0
  151. package/build/descriptor/light/RectAreaLightDescriptor.d.ts +10 -0
  152. package/build/descriptor/light/RectAreaLightDescriptor.js +16 -0
  153. package/build/descriptor/light/RectAreaLightDescriptor.js.map +1 -0
  154. package/build/descriptor/light/SpotLightDescriptor.d.ts +18 -0
  155. package/build/descriptor/light/SpotLightDescriptor.js +27 -0
  156. package/build/descriptor/light/SpotLightDescriptor.js.map +1 -0
  157. package/build/descriptor/material/MaterialDescriptor.d.ts +54 -0
  158. package/build/descriptor/material/MaterialDescriptor.js +73 -0
  159. package/build/descriptor/material/MaterialDescriptor.js.map +1 -0
  160. package/build/descriptor/material/MeshBasicMaterialDescriptor.d.ts +35 -0
  161. package/build/descriptor/material/MeshBasicMaterialDescriptor.js +51 -0
  162. package/build/descriptor/material/MeshBasicMaterialDescriptor.js.map +1 -0
  163. package/build/descriptor/material/MeshPhongMaterialDescriptor.d.ts +65 -0
  164. package/build/descriptor/material/MeshPhongMaterialDescriptor.js +98 -0
  165. package/build/descriptor/material/MeshPhongMaterialDescriptor.js.map +1 -0
  166. package/build/descriptor/material/MeshStandardMaterialDescriptor.d.ts +63 -0
  167. package/build/descriptor/material/MeshStandardMaterialDescriptor.js +95 -0
  168. package/build/descriptor/material/MeshStandardMaterialDescriptor.js.map +1 -0
  169. package/build/descriptor/material/PointsMaterialDescriptor.d.ts +19 -0
  170. package/build/descriptor/material/PointsMaterialDescriptor.js +29 -0
  171. package/build/descriptor/material/PointsMaterialDescriptor.js.map +1 -0
  172. package/build/descriptor/material/ShaderMaterialDescriptor.d.ts +24 -0
  173. package/build/descriptor/material/ShaderMaterialDescriptor.js +26 -0
  174. package/build/descriptor/material/ShaderMaterialDescriptor.js.map +1 -0
  175. package/build/descriptor/material/ShadowMaterialDescriptor.d.ts +11 -0
  176. package/build/descriptor/material/ShadowMaterialDescriptor.js +17 -0
  177. package/build/descriptor/material/ShadowMaterialDescriptor.js.map +1 -0
  178. package/build/descriptor/material/SpriteMaterialDescriptor.d.ts +19 -0
  179. package/build/descriptor/material/SpriteMaterialDescriptor.js +29 -0
  180. package/build/descriptor/material/SpriteMaterialDescriptor.js.map +1 -0
  181. package/build/descriptor/texture/TextureDescriptor.d.ts +80 -0
  182. package/build/descriptor/texture/TextureDescriptor.js +103 -0
  183. package/build/descriptor/texture/TextureDescriptor.js.map +1 -0
  184. package/build/index.d.ts +9 -0
  185. package/build/index.js +10 -0
  186. package/build/index.js.map +1 -0
  187. package/build/interpreter/ComposerServiceInterpreter.d.ts +0 -0
  188. package/build/interpreter/ComposerServiceInterpreter.js +22 -0
  189. package/build/interpreter/ComposerServiceInterpreter.js.map +1 -0
  190. package/build/interpreter/GeoMapInterpreter.d.ts +36 -0
  191. package/build/interpreter/GeoMapInterpreter.js +216 -0
  192. package/build/interpreter/GeoMapInterpreter.js.map +1 -0
  193. package/build/interpreter/HTMLConvertInterpreter.d.ts +12 -0
  194. package/build/interpreter/HTMLConvertInterpreter.js +25 -0
  195. package/build/interpreter/HTMLConvertInterpreter.js.map +1 -0
  196. package/build/interpreter/InstancedMeshInterpreter.d.ts +19 -0
  197. package/build/interpreter/InstancedMeshInterpreter.js +67 -0
  198. package/build/interpreter/InstancedMeshInterpreter.js.map +1 -0
  199. package/build/interpreter/MeshInterpreter.d.ts +9 -0
  200. package/build/interpreter/MeshInterpreter.js +21 -0
  201. package/build/interpreter/MeshInterpreter.js.map +1 -0
  202. package/build/interpreter/ModelInterpreter.d.ts +16 -0
  203. package/build/interpreter/ModelInterpreter.js +52 -0
  204. package/build/interpreter/ModelInterpreter.js.map +1 -0
  205. package/build/interpreter/NodeInterpreter.d.ts +18 -0
  206. package/build/interpreter/NodeInterpreter.js +53 -0
  207. package/build/interpreter/NodeInterpreter.js.map +1 -0
  208. package/build/interpreter/OrbitControllerInterpreter.d.ts +13 -0
  209. package/build/interpreter/OrbitControllerInterpreter.js +38 -0
  210. package/build/interpreter/OrbitControllerInterpreter.js.map +1 -0
  211. package/build/interpreter/OrthographicCameraInterpreter.d.ts +8 -0
  212. package/build/interpreter/OrthographicCameraInterpreter.js +9 -0
  213. package/build/interpreter/OrthographicCameraInterpreter.js.map +1 -0
  214. package/build/interpreter/ParticleInterpreter.d.ts +24 -0
  215. package/build/interpreter/ParticleInterpreter.js +180 -0
  216. package/build/interpreter/ParticleInterpreter.js.map +1 -0
  217. package/build/interpreter/PassInterpreter.d.ts +0 -0
  218. package/build/interpreter/PassInterpreter.js +36 -0
  219. package/build/interpreter/PassInterpreter.js.map +1 -0
  220. package/build/interpreter/PerspectiveCameraInterpreter.d.ts +13 -0
  221. package/build/interpreter/PerspectiveCameraInterpreter.js +26 -0
  222. package/build/interpreter/PerspectiveCameraInterpreter.js.map +1 -0
  223. package/build/interpreter/PointsInterpreter.d.ts +17 -0
  224. package/build/interpreter/PointsInterpreter.js +54 -0
  225. package/build/interpreter/PointsInterpreter.js.map +1 -0
  226. package/build/interpreter/SceneServiceInterpreter.d.ts +27 -0
  227. package/build/interpreter/SceneServiceInterpreter.js +95 -0
  228. package/build/interpreter/SceneServiceInterpreter.js.map +1 -0
  229. package/build/interpreter/ServiceSchedulerInterpreter.d.ts +9 -0
  230. package/build/interpreter/ServiceSchedulerInterpreter.js +19 -0
  231. package/build/interpreter/ServiceSchedulerInterpreter.js.map +1 -0
  232. package/build/interpreter/SpriteInterpreter.d.ts +14 -0
  233. package/build/interpreter/SpriteInterpreter.js +38 -0
  234. package/build/interpreter/SpriteInterpreter.js.map +1 -0
  235. package/build/interpreter/TextInterpreter.d.ts +16 -0
  236. package/build/interpreter/TextInterpreter.js +68 -0
  237. package/build/interpreter/TextInterpreter.js.map +1 -0
  238. package/build/interpreter/TransformControllerInterpreter.d.ts +12 -0
  239. package/build/interpreter/TransformControllerInterpreter.js +36 -0
  240. package/build/interpreter/TransformControllerInterpreter.js.map +1 -0
  241. package/build/interpreter/animation/AnimationActionInterpreter.d.ts +13 -0
  242. package/build/interpreter/animation/AnimationActionInterpreter.js +57 -0
  243. package/build/interpreter/animation/AnimationActionInterpreter.js.map +1 -0
  244. package/build/interpreter/geometry/BoxGeometryInterpreter.d.ts +12 -0
  245. package/build/interpreter/geometry/BoxGeometryInterpreter.js +29 -0
  246. package/build/interpreter/geometry/BoxGeometryInterpreter.js.map +1 -0
  247. package/build/interpreter/geometry/BufferGeometryInterpreter.d.ts +13 -0
  248. package/build/interpreter/geometry/BufferGeometryInterpreter.js +43 -0
  249. package/build/interpreter/geometry/BufferGeometryInterpreter.js.map +1 -0
  250. package/build/interpreter/geometry/CircleGeometryInterpreter.d.ts +12 -0
  251. package/build/interpreter/geometry/CircleGeometryInterpreter.js +29 -0
  252. package/build/interpreter/geometry/CircleGeometryInterpreter.js.map +1 -0
  253. package/build/interpreter/geometry/CylinderGeometryInterpreter.d.ts +12 -0
  254. package/build/interpreter/geometry/CylinderGeometryInterpreter.js +29 -0
  255. package/build/interpreter/geometry/CylinderGeometryInterpreter.js.map +1 -0
  256. package/build/interpreter/geometry/ExtrudeGeometryInterpreter.d.ts +13 -0
  257. package/build/interpreter/geometry/ExtrudeGeometryInterpreter.js +48 -0
  258. package/build/interpreter/geometry/ExtrudeGeometryInterpreter.js.map +1 -0
  259. package/build/interpreter/geometry/PlaneGeometryInterpreter.d.ts +12 -0
  260. package/build/interpreter/geometry/PlaneGeometryInterpreter.js +29 -0
  261. package/build/interpreter/geometry/PlaneGeometryInterpreter.js.map +1 -0
  262. package/build/interpreter/geometry/RingGeometryInterpreter.d.ts +12 -0
  263. package/build/interpreter/geometry/RingGeometryInterpreter.js +29 -0
  264. package/build/interpreter/geometry/RingGeometryInterpreter.js.map +1 -0
  265. package/build/interpreter/geometry/SphereGeometryInterpreter.d.ts +12 -0
  266. package/build/interpreter/geometry/SphereGeometryInterpreter.js +29 -0
  267. package/build/interpreter/geometry/SphereGeometryInterpreter.js.map +1 -0
  268. package/build/interpreter/geometry/SurfaceGeometryInterpreter.d.ts +16 -0
  269. package/build/interpreter/geometry/SurfaceGeometryInterpreter.js +29 -0
  270. package/build/interpreter/geometry/SurfaceGeometryInterpreter.js.map +1 -0
  271. package/build/interpreter/geometry/TubeGeometryInterpreter.d.ts +13 -0
  272. package/build/interpreter/geometry/TubeGeometryInterpreter.js +36 -0
  273. package/build/interpreter/geometry/TubeGeometryInterpreter.js.map +1 -0
  274. package/build/interpreter/helper/AxesHelperInterpreter.d.ts +12 -0
  275. package/build/interpreter/helper/AxesHelperInterpreter.js +32 -0
  276. package/build/interpreter/helper/AxesHelperInterpreter.js.map +1 -0
  277. package/build/interpreter/index.d.ts +43 -0
  278. package/build/interpreter/index.js +46 -0
  279. package/build/interpreter/index.js.map +1 -0
  280. package/build/interpreter/light/AmbientLightInterpreter.d.ts +13 -0
  281. package/build/interpreter/light/AmbientLightInterpreter.js +24 -0
  282. package/build/interpreter/light/AmbientLightInterpreter.js.map +1 -0
  283. package/build/interpreter/light/DirectionalLightInterpreter.d.ts +16 -0
  284. package/build/interpreter/light/DirectionalLightInterpreter.js +75 -0
  285. package/build/interpreter/light/DirectionalLightInterpreter.js.map +1 -0
  286. package/build/interpreter/light/HemisphereLightInterpreter.d.ts +13 -0
  287. package/build/interpreter/light/HemisphereLightInterpreter.js +25 -0
  288. package/build/interpreter/light/HemisphereLightInterpreter.js.map +1 -0
  289. package/build/interpreter/light/PointLightInterpreter.d.ts +14 -0
  290. package/build/interpreter/light/PointLightInterpreter.js +37 -0
  291. package/build/interpreter/light/PointLightInterpreter.js.map +1 -0
  292. package/build/interpreter/light/RectAreaLightInterpreter.d.ts +13 -0
  293. package/build/interpreter/light/RectAreaLightInterpreter.js +27 -0
  294. package/build/interpreter/light/RectAreaLightInterpreter.js.map +1 -0
  295. package/build/interpreter/light/SpotLightInterpreter.d.ts +15 -0
  296. package/build/interpreter/light/SpotLightInterpreter.js +63 -0
  297. package/build/interpreter/light/SpotLightInterpreter.js.map +1 -0
  298. package/build/interpreter/material/MaterialInterpreter.d.ts +9 -0
  299. package/build/interpreter/material/MaterialInterpreter.js +28 -0
  300. package/build/interpreter/material/MaterialInterpreter.js.map +1 -0
  301. package/build/interpreter/material/MeshBasicMaterialInterpreter.d.ts +11 -0
  302. package/build/interpreter/material/MeshBasicMaterialInterpreter.js +37 -0
  303. package/build/interpreter/material/MeshBasicMaterialInterpreter.js.map +1 -0
  304. package/build/interpreter/material/MeshPhongMaterialInterpreter.d.ts +11 -0
  305. package/build/interpreter/material/MeshPhongMaterialInterpreter.js +56 -0
  306. package/build/interpreter/material/MeshPhongMaterialInterpreter.js.map +1 -0
  307. package/build/interpreter/material/MeshStandardMaterialInterpreter.d.ts +11 -0
  308. package/build/interpreter/material/MeshStandardMaterialInterpreter.js +52 -0
  309. package/build/interpreter/material/MeshStandardMaterialInterpreter.js.map +1 -0
  310. package/build/interpreter/material/PointsMaterialInterpreter.d.ts +11 -0
  311. package/build/interpreter/material/PointsMaterialInterpreter.js +30 -0
  312. package/build/interpreter/material/PointsMaterialInterpreter.js.map +1 -0
  313. package/build/interpreter/material/ShaderMaterialInterpreter.d.ts +14 -0
  314. package/build/interpreter/material/ShaderMaterialInterpreter.js +46 -0
  315. package/build/interpreter/material/ShaderMaterialInterpreter.js.map +1 -0
  316. package/build/interpreter/material/ShadowMaterialInterpreter.d.ts +11 -0
  317. package/build/interpreter/material/ShadowMaterialInterpreter.js +25 -0
  318. package/build/interpreter/material/ShadowMaterialInterpreter.js.map +1 -0
  319. package/build/interpreter/material/SpriteMaterialInterpreter.d.ts +11 -0
  320. package/build/interpreter/material/SpriteMaterialInterpreter.js +30 -0
  321. package/build/interpreter/material/SpriteMaterialInterpreter.js.map +1 -0
  322. package/build/interpreter/texture/TextureInterpreter.d.ts +13 -0
  323. package/build/interpreter/texture/TextureInterpreter.js +54 -0
  324. package/build/interpreter/texture/TextureInterpreter.js.map +1 -0
  325. package/build/locale/Language.d.ts +3 -0
  326. package/build/locale/Language.js +6 -0
  327. package/build/locale/Language.js.map +1 -0
  328. package/build/locale/LanguageProvider.d.ts +6 -0
  329. package/build/locale/LanguageProvider.js +7 -0
  330. package/build/locale/LanguageProvider.js.map +1 -0
  331. package/build/locale/index.d.ts +2 -0
  332. package/build/locale/index.js +3 -0
  333. package/build/locale/index.js.map +1 -0
  334. package/build/preset/execute/GeoMap/drilldown.d.ts +16 -0
  335. package/build/preset/execute/GeoMap/drilldown.js +45 -0
  336. package/build/preset/execute/GeoMap/drilldown.js.map +1 -0
  337. package/build/preset/execute/GeoMap/index.d.ts +1 -0
  338. package/build/preset/execute/GeoMap/index.js +2 -0
  339. package/build/preset/execute/GeoMap/index.js.map +1 -0
  340. package/build/preset/execute/index.d.ts +1 -0
  341. package/build/preset/execute/index.js +2 -0
  342. package/build/preset/execute/index.js.map +1 -0
  343. package/build/preset/index.d.ts +3 -0
  344. package/build/preset/index.js +4 -0
  345. package/build/preset/index.js.map +1 -0
  346. package/build/preset/interaction/GeoMap/drilldown.d.ts +5 -0
  347. package/build/preset/interaction/GeoMap/drilldown.js +19 -0
  348. package/build/preset/interaction/GeoMap/drilldown.js.map +1 -0
  349. package/build/preset/interaction/GeoMap/index.d.ts +1 -0
  350. package/build/preset/interaction/GeoMap/index.js +2 -0
  351. package/build/preset/interaction/GeoMap/index.js.map +1 -0
  352. package/build/preset/interaction/index.d.ts +1 -0
  353. package/build/preset/interaction/index.js +2 -0
  354. package/build/preset/interaction/index.js.map +1 -0
  355. package/build/utils/dispose/index.d.ts +3 -0
  356. package/build/utils/dispose/index.js +22 -0
  357. package/build/utils/dispose/index.js.map +1 -0
  358. package/build/utils/geometry/index.d.ts +19 -0
  359. package/build/utils/geometry/index.js +61 -0
  360. package/build/utils/geometry/index.js.map +1 -0
  361. package/build/utils/index.d.ts +7 -0
  362. package/build/utils/index.js +8 -0
  363. package/build/utils/index.js.map +1 -0
  364. package/build/utils/material/index.d.ts +7 -0
  365. package/build/utils/material/index.js +46 -0
  366. package/build/utils/material/index.js.map +1 -0
  367. package/build/utils/pickup/index.d.ts +5 -0
  368. package/build/utils/pickup/index.js +14 -0
  369. package/build/utils/pickup/index.js.map +1 -0
  370. package/build/utils/random/index.d.ts +2 -0
  371. package/build/utils/random/index.js +5 -0
  372. package/build/utils/random/index.js.map +1 -0
  373. package/build/utils/text/index.d.ts +98 -0
  374. package/build/utils/text/index.js +379 -0
  375. package/build/utils/text/index.js.map +1 -0
  376. package/build/utils/texture/index.d.ts +4 -0
  377. package/build/utils/texture/index.js +17 -0
  378. package/build/utils/texture/index.js.map +1 -0
  379. package/package.json +25 -1
@@ -0,0 +1,2332 @@
1
+ import { EventDispatcher, Vector3, Vector2, Spherical, Box3, Sphere, Quaternion, Matrix4, Raycaster, Vector4 } from 'three';
2
+ const MOUSE_BUTTON = {
3
+ LEFT: 1,
4
+ RIGHT: 2,
5
+ MIDDLE: 4,
6
+ };
7
+ const ACTION = Object.freeze({
8
+ NONE: 0,
9
+ ROTATE: 1,
10
+ TRUCK: 2,
11
+ OFFSET: 4,
12
+ DOLLY: 8,
13
+ ZOOM: 16,
14
+ TOUCH_ROTATE: 32,
15
+ TOUCH_TRUCK: 64,
16
+ TOUCH_OFFSET: 128,
17
+ TOUCH_DOLLY: 256,
18
+ TOUCH_ZOOM: 512,
19
+ TOUCH_DOLLY_TRUCK: 1024,
20
+ TOUCH_DOLLY_OFFSET: 2048,
21
+ TOUCH_DOLLY_ROTATE: 4096,
22
+ TOUCH_ZOOM_TRUCK: 8192,
23
+ TOUCH_ZOOM_OFFSET: 16384,
24
+ TOUCH_ZOOM_ROTATE: 32768,
25
+ });
26
+ const DOLLY_DIRECTION = {
27
+ NONE: 0,
28
+ IN: 1,
29
+ OUT: -1,
30
+ };
31
+ function isPerspectiveCamera(camera) {
32
+ return camera.isPerspectiveCamera;
33
+ }
34
+ function isOrthographicCamera(camera) {
35
+ return camera.isOrthographicCamera;
36
+ }
37
+ const PI_2 = Math.PI * 2;
38
+ const PI_HALF = Math.PI / 2;
39
+ const EPSILON = 1e-5;
40
+ const DEG2RAD = Math.PI / 180;
41
+ function clamp(value, min, max) {
42
+ return Math.max(min, Math.min(max, value));
43
+ }
44
+ function approxZero(number, error = EPSILON) {
45
+ return Math.abs(number) < error;
46
+ }
47
+ function approxEquals(a, b, error = EPSILON) {
48
+ return approxZero(a - b, error);
49
+ }
50
+ function roundToStep(value, step) {
51
+ return Math.round(value / step) * step;
52
+ }
53
+ function infinityToMaxNumber(value) {
54
+ if (isFinite(value))
55
+ return value;
56
+ if (value < 0)
57
+ return -Number.MAX_VALUE;
58
+ return Number.MAX_VALUE;
59
+ }
60
+ function maxNumberToInfinity(value) {
61
+ if (Math.abs(value) < Number.MAX_VALUE)
62
+ return value;
63
+ return value * Infinity;
64
+ }
65
+ // https://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.html
66
+ // https://github.com/Unity-Technologies/UnityCsReference/blob/a2bdfe9b3c4cd4476f44bf52f848063bfaf7b6b9/Runtime/Export/Math/Mathf.cs#L308
67
+ function smoothDamp(current, target, currentVelocityRef, smoothTime, maxSpeed = Infinity, deltaTime) {
68
+ // Based on Game Programming Gems 4 Chapter 1.10
69
+ smoothTime = Math.max(0.0001, smoothTime);
70
+ const omega = 2 / smoothTime;
71
+ const x = omega * deltaTime;
72
+ const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x);
73
+ let change = current - target;
74
+ const originalTo = target;
75
+ // Clamp maximum speed
76
+ const maxChange = maxSpeed * smoothTime;
77
+ change = clamp(change, -maxChange, maxChange);
78
+ target = current - change;
79
+ const temp = (currentVelocityRef.value + omega * change) * deltaTime;
80
+ currentVelocityRef.value = (currentVelocityRef.value - omega * temp) * exp;
81
+ let output = target + (change + temp) * exp;
82
+ // Prevent overshooting
83
+ if (originalTo - current > 0.0 === output > originalTo) {
84
+ output = originalTo;
85
+ currentVelocityRef.value = (output - originalTo) / deltaTime;
86
+ }
87
+ return output;
88
+ }
89
+ // https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
90
+ // https://github.com/Unity-Technologies/UnityCsReference/blob/a2bdfe9b3c4cd4476f44bf52f848063bfaf7b6b9/Runtime/Export/Math/Vector3.cs#L97
91
+ function smoothDampVec3(current, target, currentVelocityRef, smoothTime, maxSpeed = Infinity, deltaTime, out) {
92
+ // Based on Game Programming Gems 4 Chapter 1.10
93
+ smoothTime = Math.max(0.0001, smoothTime);
94
+ const omega = 2 / smoothTime;
95
+ const x = omega * deltaTime;
96
+ const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x);
97
+ let targetX = target.x;
98
+ let targetY = target.y;
99
+ let targetZ = target.z;
100
+ let changeX = current.x - targetX;
101
+ let changeY = current.y - targetY;
102
+ let changeZ = current.z - targetZ;
103
+ const originalToX = targetX;
104
+ const originalToY = targetY;
105
+ const originalToZ = targetZ;
106
+ // Clamp maximum speed
107
+ const maxChange = maxSpeed * smoothTime;
108
+ const maxChangeSq = maxChange * maxChange;
109
+ const magnitudeSq = changeX * changeX + changeY * changeY + changeZ * changeZ;
110
+ if (magnitudeSq > maxChangeSq) {
111
+ const magnitude = Math.sqrt(magnitudeSq);
112
+ changeX = changeX / magnitude * maxChange;
113
+ changeY = changeY / magnitude * maxChange;
114
+ changeZ = changeZ / magnitude * maxChange;
115
+ }
116
+ targetX = current.x - changeX;
117
+ targetY = current.y - changeY;
118
+ targetZ = current.z - changeZ;
119
+ const tempX = (currentVelocityRef.x + omega * changeX) * deltaTime;
120
+ const tempY = (currentVelocityRef.y + omega * changeY) * deltaTime;
121
+ const tempZ = (currentVelocityRef.z + omega * changeZ) * deltaTime;
122
+ currentVelocityRef.x = (currentVelocityRef.x - omega * tempX) * exp;
123
+ currentVelocityRef.y = (currentVelocityRef.y - omega * tempY) * exp;
124
+ currentVelocityRef.z = (currentVelocityRef.z - omega * tempZ) * exp;
125
+ out.x = targetX + (changeX + tempX) * exp;
126
+ out.y = targetY + (changeY + tempY) * exp;
127
+ out.z = targetZ + (changeZ + tempZ) * exp;
128
+ // Prevent overshooting
129
+ const origMinusCurrentX = originalToX - current.x;
130
+ const origMinusCurrentY = originalToY - current.y;
131
+ const origMinusCurrentZ = originalToZ - current.z;
132
+ const outMinusOrigX = out.x - originalToX;
133
+ const outMinusOrigY = out.y - originalToY;
134
+ const outMinusOrigZ = out.z - originalToZ;
135
+ if (origMinusCurrentX * outMinusOrigX + origMinusCurrentY * outMinusOrigY + origMinusCurrentZ * outMinusOrigZ > 0) {
136
+ out.x = originalToX;
137
+ out.y = originalToY;
138
+ out.z = originalToZ;
139
+ currentVelocityRef.x = (out.x - originalToX) / deltaTime;
140
+ currentVelocityRef.y = (out.y - originalToY) / deltaTime;
141
+ currentVelocityRef.z = (out.z - originalToZ) / deltaTime;
142
+ }
143
+ return out;
144
+ }
145
+ function extractClientCoordFromEvent(pointers, out) {
146
+ out.set(0, 0);
147
+ if (pointers.length === 0)
148
+ return;
149
+ pointers.forEach((pointer) => {
150
+ out.x += pointer.clientX;
151
+ out.y += pointer.clientY;
152
+ });
153
+ out.x /= pointers.length;
154
+ out.y /= pointers.length;
155
+ }
156
+ function notSupportedInOrthographicCamera(camera, message) {
157
+ if (isOrthographicCamera(camera)) {
158
+ console.warn(`${message} is not supported in OrthographicCamera`);
159
+ return true;
160
+ }
161
+ return false;
162
+ }
163
+ const VERSION = '2.7.4'; // will be replaced with `version` in package.json during the build process.
164
+ const TOUCH_DOLLY_FACTOR = 1 / 8;
165
+ const isBrowser = typeof window !== 'undefined';
166
+ const isMac = isBrowser && /Mac/.test(navigator.platform);
167
+ const isPointerEventsNotSupported = !(isBrowser && 'PointerEvent' in window); // macOS Safari 12 does not support PointerEvents API
168
+ let _ORIGIN = Object.freeze(new Vector3(0, 0, 0));
169
+ let _AXIS_Y = Object.freeze(new Vector3(0, 1, 0));
170
+ let _AXIS_Z = Object.freeze(new Vector3(0, 0, 1));
171
+ let _v2 = new Vector2();
172
+ let _v3A = new Vector3();
173
+ let _v3B = new Vector3();
174
+ let _v3C = new Vector3();
175
+ let _cameraDirection = new Vector3();
176
+ let _xColumn = new Vector3();
177
+ let _yColumn = new Vector3();
178
+ let _zColumn = new Vector3();
179
+ let _deltaTarget = new Vector3();
180
+ let _deltaOffset = new Vector3();
181
+ let _sphericalA = new Spherical();
182
+ let _sphericalB = new Spherical();
183
+ let _box3A = new Box3();
184
+ let _box3B = new Box3();
185
+ let _sphere = new Sphere();
186
+ let _quaternionA = new Quaternion();
187
+ let _quaternionB = new Quaternion();
188
+ let _rotationMatrix = new Matrix4();
189
+ let _raycaster = new Raycaster();
190
+ const mouseButtons = {
191
+ left: ACTION.ROTATE,
192
+ middle: ACTION.DOLLY,
193
+ right: ACTION.TRUCK,
194
+ wheel: ACTION.NONE,
195
+ };
196
+ const touches = {
197
+ one: ACTION.TOUCH_ROTATE,
198
+ two: ACTION.NONE,
199
+ three: ACTION.TOUCH_TRUCK,
200
+ };
201
+ class CameraControls extends EventDispatcher {
202
+ static get ACTION() {
203
+ return ACTION;
204
+ }
205
+ _listeners;
206
+ minPolarAngle = 0; // radians
207
+ maxPolarAngle = Math.PI; // radians
208
+ minAzimuthAngle = -Infinity; // radians
209
+ maxAzimuthAngle = Infinity; // radians
210
+ minDistance = Number.EPSILON;
211
+ maxDistance = Infinity;
212
+ infinityDolly = false;
213
+ minZoom = 0.01;
214
+ maxZoom = Infinity;
215
+ smoothTime = 0.25;
216
+ draggingSmoothTime = 0.125;
217
+ maxSpeed = Infinity;
218
+ azimuthRotateSpeed = 1.0;
219
+ polarRotateSpeed = 1.0;
220
+ dollySpeed = 1.0;
221
+ dollyDragInverted = false;
222
+ truckSpeed = 2.0;
223
+ dollyToCursor = false;
224
+ dragToOffset = false;
225
+ verticalDragToForward = false;
226
+ boundaryFriction = 0.0;
227
+ restThreshold = 0.01;
228
+ colliderMeshes = [];
229
+ cancel = () => { };
230
+ _enabled = true;
231
+ _state = ACTION.NONE;
232
+ _viewport = null;
233
+ _changedDolly = 0;
234
+ _changedZoom = 0;
235
+ _hasRested = true;
236
+ _boundaryEnclosesCamera = false;
237
+ _needsUpdate = true;
238
+ _updatedLastTime = false;
239
+ _elementRect = new DOMRect();
240
+ _isDragging = false;
241
+ _dragNeedsUpdate = true;
242
+ _activePointers = [];
243
+ _lockedPointer = null;
244
+ _interactiveArea = new DOMRect(0, 0, 1, 1);
245
+ _isUserControllingRotate = false;
246
+ _isUserControllingDolly = false;
247
+ _isUserControllingTruck = false;
248
+ _isUserControllingOffset = false;
249
+ _isUserControllingZoom = false;
250
+ _lastDollyDirection = DOLLY_DIRECTION.NONE;
251
+ _thetaVelocity = { value: 0 };
252
+ _phiVelocity = { value: 0 };
253
+ _radiusVelocity = { value: 0 };
254
+ _targetVelocity = new Vector3();
255
+ _focalOffsetVelocity = new Vector3();
256
+ _zoomVelocity = { value: 0 };
257
+ _truckInternal = (deltaX, deltaY, dragToOffset) => {
258
+ let truckX;
259
+ let pedestalY;
260
+ if (isPerspectiveCamera(this._camera)) {
261
+ const offset = _v3A.copy(this._camera.position).sub(this._target);
262
+ // half of the fov is center to top of screen
263
+ const fov = this._camera.getEffectiveFOV() * DEG2RAD;
264
+ const targetDistance = offset.length() * Math.tan(fov * 0.5);
265
+ truckX = (this.truckSpeed * deltaX * targetDistance / this._elementRect.height);
266
+ pedestalY = (this.truckSpeed * deltaY * targetDistance / this._elementRect.height);
267
+ }
268
+ else if (isOrthographicCamera(this._camera)) {
269
+ const camera = this._camera;
270
+ truckX = deltaX * (camera.right - camera.left) / camera.zoom / this._elementRect.width;
271
+ pedestalY = deltaY * (camera.top - camera.bottom) / camera.zoom / this._elementRect.height;
272
+ }
273
+ else {
274
+ return;
275
+ }
276
+ if (this.verticalDragToForward) {
277
+ dragToOffset ?
278
+ this.setFocalOffset(this._focalOffsetEnd.x + truckX, this._focalOffsetEnd.y, this._focalOffsetEnd.z, true) :
279
+ this.truck(truckX, 0, true);
280
+ this.forward(-pedestalY, true);
281
+ }
282
+ else {
283
+ dragToOffset ?
284
+ this.setFocalOffset(this._focalOffsetEnd.x + truckX, this._focalOffsetEnd.y + pedestalY, this._focalOffsetEnd.z, true) :
285
+ this.truck(truckX, pedestalY, true);
286
+ }
287
+ };
288
+ _rotateInternal = (deltaX, deltaY) => {
289
+ const theta = PI_2 * this.azimuthRotateSpeed * deltaX / this._elementRect.height; // divide by *height* to refer the resolution
290
+ const phi = PI_2 * this.polarRotateSpeed * deltaY / this._elementRect.height;
291
+ this.rotate(theta, phi, true);
292
+ };
293
+ _dollyInternal = (delta, x, y) => {
294
+ const dollyScale = Math.pow(0.95, -delta * this.dollySpeed);
295
+ const lastDistance = this._sphericalEnd.radius;
296
+ const distance = this._sphericalEnd.radius * dollyScale;
297
+ const clampedDistance = clamp(distance, this.minDistance, this.maxDistance);
298
+ const overflowedDistance = clampedDistance - distance;
299
+ if (this.infinityDolly && this.dollyToCursor) {
300
+ this._dollyToNoClamp(distance, true);
301
+ }
302
+ else if (this.infinityDolly && !this.dollyToCursor) {
303
+ this.dollyInFixed(overflowedDistance, true);
304
+ this._dollyToNoClamp(clampedDistance, true);
305
+ }
306
+ else {
307
+ this._dollyToNoClamp(clampedDistance, true);
308
+ }
309
+ if (this.dollyToCursor) {
310
+ this._changedDolly += (this.infinityDolly ? distance : clampedDistance) - lastDistance;
311
+ this._dollyControlCoord.set(x, y);
312
+ }
313
+ this._lastDollyDirection = Math.sign(-delta);
314
+ };
315
+ _zoomInternal = (delta, x, y) => {
316
+ const zoomScale = Math.pow(0.95, delta * this.dollySpeed);
317
+ const lastZoom = this._zoom;
318
+ const zoom = this._zoom * zoomScale;
319
+ // for both PerspectiveCamera and OrthographicCamera
320
+ this.zoomTo(zoom, true);
321
+ if (this.dollyToCursor) {
322
+ this._changedZoom += zoom - lastZoom;
323
+ this._dollyControlCoord.set(x, y);
324
+ }
325
+ };
326
+ _nearPlaneCorners = [
327
+ new Vector3(),
328
+ new Vector3(),
329
+ new Vector3(),
330
+ new Vector3(),
331
+ ];
332
+ _target = new Vector3();
333
+ _focalOffset = new Vector3();
334
+ _domElement;
335
+ dragStartPosition = new Vector2();
336
+ lastDragPosition = new Vector2();
337
+ dollyStart = new Vector2();
338
+ _camera;
339
+ _yAxisUpSpace;
340
+ _yAxisUpSpaceInverse;
341
+ _targetEnd;
342
+ _focalOffsetEnd;
343
+ _spherical;
344
+ _sphericalEnd;
345
+ _lastDistance;
346
+ _zoom;
347
+ _zoomEnd;
348
+ _lastZoom;
349
+ _boundary;
350
+ _cameraUp0;
351
+ _target0;
352
+ _position0;
353
+ _zoom0;
354
+ _focalOffset0;
355
+ _dollyControlCoord = new Vector2();
356
+ mouseButtons;
357
+ touches;
358
+ events = [];
359
+ lockPointer;
360
+ unlockPointer;
361
+ constructor(graphics) {
362
+ super();
363
+ this.mouseButtons = mouseButtons;
364
+ this.touches = touches;
365
+ const onPointerDown = (event) => {
366
+ if (!this._enabled || !this._domElement)
367
+ return;
368
+ if (this._interactiveArea.left !== 0 ||
369
+ this._interactiveArea.top !== 0 ||
370
+ this._interactiveArea.width !== 1 ||
371
+ this._interactiveArea.height !== 1) {
372
+ const elRect = this._domElement.getBoundingClientRect();
373
+ const left = event.clientX / elRect.width;
374
+ const top = event.clientY / elRect.height;
375
+ // check if the interactiveArea contains the drag start position.
376
+ if (left < this._interactiveArea.left ||
377
+ left > this._interactiveArea.right ||
378
+ top < this._interactiveArea.top ||
379
+ top > this._interactiveArea.bottom)
380
+ return;
381
+ }
382
+ // Don't call `event.preventDefault()` on the pointerdown event
383
+ // to keep receiving pointermove evens outside dragging iframe
384
+ // https://taye.me/blog/tips/2015/11/16/mouse-drag-outside-iframe/
385
+ const mouseButton = event.pointerType !== 'mouse' ? null :
386
+ (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT ? MOUSE_BUTTON.LEFT :
387
+ (event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE ? MOUSE_BUTTON.MIDDLE :
388
+ (event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT ? MOUSE_BUTTON.RIGHT :
389
+ null;
390
+ if (mouseButton !== null) {
391
+ const zombiePointer = this._findPointerByMouseButton(mouseButton);
392
+ zombiePointer && this._disposePointer(zombiePointer);
393
+ }
394
+ if ((event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT && this._lockedPointer)
395
+ return;
396
+ const pointer = {
397
+ pointerId: event.pointerId,
398
+ clientX: event.clientX,
399
+ clientY: event.clientY,
400
+ deltaX: 0,
401
+ deltaY: 0,
402
+ mouseButton,
403
+ };
404
+ this._activePointers.push(pointer);
405
+ this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
406
+ this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
407
+ this._domElement.ownerDocument.addEventListener('pointermove', onPointerMove, { passive: false });
408
+ this._domElement.ownerDocument.addEventListener('pointerup', onPointerUp);
409
+ this._isDragging = true;
410
+ startDragging(event);
411
+ };
412
+ const onMouseDown = (event) => {
413
+ if (!this._enabled || !this._domElement || this._lockedPointer)
414
+ return;
415
+ if (this._interactiveArea.left !== 0 ||
416
+ this._interactiveArea.top !== 0 ||
417
+ this._interactiveArea.width !== 1 ||
418
+ this._interactiveArea.height !== 1) {
419
+ const elRect = this._domElement.getBoundingClientRect();
420
+ const left = event.clientX / elRect.width;
421
+ const top = event.clientY / elRect.height;
422
+ // check if the interactiveArea contains the drag start position.
423
+ if (left < this._interactiveArea.left ||
424
+ left > this._interactiveArea.right ||
425
+ top < this._interactiveArea.top ||
426
+ top > this._interactiveArea.bottom)
427
+ return;
428
+ }
429
+ const mouseButton = (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT ? MOUSE_BUTTON.LEFT :
430
+ (event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE ? MOUSE_BUTTON.MIDDLE :
431
+ (event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT ? MOUSE_BUTTON.RIGHT :
432
+ null;
433
+ if (mouseButton !== null) {
434
+ const zombiePointer = this._findPointerByMouseButton(mouseButton);
435
+ zombiePointer && this._disposePointer(zombiePointer);
436
+ }
437
+ const pointer = {
438
+ pointerId: 1,
439
+ clientX: event.clientX,
440
+ clientY: event.clientY,
441
+ deltaX: 0,
442
+ deltaY: 0,
443
+ mouseButton: (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT ? MOUSE_BUTTON.LEFT :
444
+ (event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.LEFT ? MOUSE_BUTTON.MIDDLE :
445
+ (event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.LEFT ? MOUSE_BUTTON.RIGHT :
446
+ null,
447
+ };
448
+ this._activePointers.push(pointer);
449
+ // see https://github.com/microsoft/TypeScript/issues/32912#issuecomment-522142969
450
+ // eslint-disable-next-line no-undef
451
+ this._domElement.ownerDocument.removeEventListener('mousemove', onMouseMove);
452
+ this._domElement.ownerDocument.removeEventListener('mouseup', onMouseUp);
453
+ this._domElement.ownerDocument.addEventListener('mousemove', onMouseMove);
454
+ this._domElement.ownerDocument.addEventListener('mouseup', onMouseUp);
455
+ this._isDragging = true;
456
+ startDragging(event);
457
+ };
458
+ const onPointerMove = (event) => {
459
+ if (event.cancelable)
460
+ event.preventDefault();
461
+ const pointerId = event.pointerId;
462
+ const pointer = this._lockedPointer || this._findPointerById(pointerId);
463
+ if (!pointer)
464
+ return;
465
+ pointer.clientX = event.clientX;
466
+ pointer.clientY = event.clientY;
467
+ pointer.deltaX = event.movementX;
468
+ pointer.deltaY = event.movementY;
469
+ this._state = 0;
470
+ if (event.pointerType === 'touch') {
471
+ switch (this._activePointers.length) {
472
+ case 1:
473
+ this._state = this.touches.one;
474
+ break;
475
+ case 2:
476
+ this._state = this.touches.two;
477
+ break;
478
+ case 3:
479
+ this._state = this.touches.three;
480
+ break;
481
+ }
482
+ }
483
+ else {
484
+ if ((!this._isDragging && this._lockedPointer) ||
485
+ this._isDragging && (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT) {
486
+ this._state = this._state | this.mouseButtons.left;
487
+ }
488
+ if (this._isDragging && (event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE) {
489
+ this._state = this._state | this.mouseButtons.middle;
490
+ }
491
+ if (this._isDragging && (event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT) {
492
+ this._state = this._state | this.mouseButtons.right;
493
+ }
494
+ }
495
+ dragging();
496
+ };
497
+ const onMouseMove = (event) => {
498
+ const pointer = this._lockedPointer || this._findPointerById(1);
499
+ if (!pointer)
500
+ return;
501
+ pointer.clientX = event.clientX;
502
+ pointer.clientY = event.clientY;
503
+ pointer.deltaX = event.movementX;
504
+ pointer.deltaY = event.movementY;
505
+ this._state = 0;
506
+ if (this._lockedPointer ||
507
+ (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT) {
508
+ this._state = this._state | this.mouseButtons.left;
509
+ }
510
+ if ((event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE) {
511
+ this._state = this._state | this.mouseButtons.middle;
512
+ }
513
+ if ((event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT) {
514
+ this._state = this._state | this.mouseButtons.right;
515
+ }
516
+ dragging();
517
+ };
518
+ const onPointerUp = (event) => {
519
+ const pointer = this._findPointerById(event.pointerId);
520
+ if (pointer && pointer === this._lockedPointer)
521
+ return;
522
+ pointer && this._disposePointer(pointer);
523
+ if (event.pointerType === 'touch') {
524
+ switch (this._activePointers.length) {
525
+ case 0:
526
+ this._state = ACTION.NONE;
527
+ break;
528
+ case 1:
529
+ this._state = this.touches.one;
530
+ break;
531
+ case 2:
532
+ this._state = this.touches.two;
533
+ break;
534
+ case 3:
535
+ this._state = this.touches.three;
536
+ break;
537
+ }
538
+ }
539
+ else {
540
+ this._state = ACTION.NONE;
541
+ }
542
+ endDragging();
543
+ };
544
+ const onMouseUp = () => {
545
+ const pointer = this._findPointerById(1);
546
+ if (pointer && pointer === this._lockedPointer)
547
+ return;
548
+ pointer && this._disposePointer(pointer);
549
+ this._state = ACTION.NONE;
550
+ endDragging();
551
+ };
552
+ let lastScrollTimeStamp = -1;
553
+ const onMouseWheel = (event) => {
554
+ if (!this._domElement)
555
+ return;
556
+ if (!this._enabled || this.mouseButtons.wheel === ACTION.NONE)
557
+ return;
558
+ if (this._interactiveArea.left !== 0 ||
559
+ this._interactiveArea.top !== 0 ||
560
+ this._interactiveArea.width !== 1 ||
561
+ this._interactiveArea.height !== 1) {
562
+ const elRect = this._domElement.getBoundingClientRect();
563
+ const left = event.clientX / elRect.width;
564
+ const top = event.clientY / elRect.height;
565
+ // check if the interactiveArea contains the drag start position.
566
+ if (left < this._interactiveArea.left ||
567
+ left > this._interactiveArea.right ||
568
+ top < this._interactiveArea.top ||
569
+ top > this._interactiveArea.bottom)
570
+ return;
571
+ }
572
+ event.preventDefault();
573
+ if (this.dollyToCursor ||
574
+ this.mouseButtons.wheel === ACTION.ROTATE ||
575
+ this.mouseButtons.wheel === ACTION.TRUCK) {
576
+ const now = performance.now();
577
+ // only need to fire this at scroll start.
578
+ if (lastScrollTimeStamp - now < 1000)
579
+ this._getClientRect(this._elementRect);
580
+ lastScrollTimeStamp = now;
581
+ }
582
+ // Ref: https://github.com/cedricpinson/osgjs/blob/00e5a7e9d9206c06fdde0436e1d62ab7cb5ce853/sources/osgViewer/input/source/InputSourceMouse.js#L89-L103
583
+ const deltaYFactor = isMac ? -1 : -3;
584
+ const delta = (event.deltaMode === 1) ? event.deltaY / deltaYFactor : event.deltaY / (deltaYFactor * 10);
585
+ const x = this.dollyToCursor ? (event.clientX - this._elementRect.x) / this._elementRect.width * 2 - 1 : 0;
586
+ const y = this.dollyToCursor ? (event.clientY - this._elementRect.y) / this._elementRect.height * -2 + 1 : 0;
587
+ switch (this.mouseButtons.wheel) {
588
+ case ACTION.ROTATE: {
589
+ this._rotateInternal(event.deltaX, event.deltaY);
590
+ this._isUserControllingRotate = true;
591
+ break;
592
+ }
593
+ case ACTION.TRUCK: {
594
+ this._truckInternal(event.deltaX, event.deltaY, false);
595
+ this._isUserControllingTruck = true;
596
+ break;
597
+ }
598
+ case ACTION.OFFSET: {
599
+ this._truckInternal(event.deltaX, event.deltaY, true);
600
+ this._isUserControllingOffset = true;
601
+ break;
602
+ }
603
+ case ACTION.DOLLY: {
604
+ this._dollyInternal(-delta, x, y);
605
+ this._isUserControllingDolly = true;
606
+ break;
607
+ }
608
+ case ACTION.ZOOM: {
609
+ this._zoomInternal(-delta, x, y);
610
+ this._isUserControllingZoom = true;
611
+ break;
612
+ }
613
+ }
614
+ this.dispatchEvent({ type: 'control' });
615
+ };
616
+ const onContextMenu = (event) => {
617
+ if (!this._domElement || !this._enabled)
618
+ return;
619
+ // contextmenu event is fired right after pointerdown/mousedown.
620
+ // remove attached handlers and active pointer, if interrupted by contextmenu.
621
+ if (this.mouseButtons.right === CameraControls.ACTION.NONE) {
622
+ const pointerId = event instanceof PointerEvent ? event.pointerId :
623
+ event instanceof MouseEvent ? 0 :
624
+ 0;
625
+ const pointer = this._findPointerById(pointerId);
626
+ pointer && this._disposePointer(pointer);
627
+ this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
628
+ this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
629
+ this._domElement.ownerDocument.removeEventListener('mousemove', onMouseMove);
630
+ this._domElement.ownerDocument.removeEventListener('mouseup', onMouseUp);
631
+ return;
632
+ }
633
+ event.preventDefault();
634
+ };
635
+ const startDragging = (event) => {
636
+ if (!this._enabled)
637
+ return;
638
+ extractClientCoordFromEvent(this._activePointers, _v2);
639
+ this._getClientRect(this._elementRect);
640
+ this.dragStartPosition.copy(_v2);
641
+ this.lastDragPosition.copy(_v2);
642
+ const isMultiTouch = this._activePointers.length >= 2;
643
+ if (isMultiTouch) {
644
+ // 2 finger pinch
645
+ const dx = _v2.x - this._activePointers[1].clientX;
646
+ const dy = _v2.y - this._activePointers[1].clientY;
647
+ const distance = Math.sqrt(dx * dx + dy * dy);
648
+ this.dollyStart.set(0, distance);
649
+ // center coords of 2 finger truck
650
+ const x = (this._activePointers[0].clientX + this._activePointers[1].clientX) * 0.5;
651
+ const y = (this._activePointers[0].clientY + this._activePointers[1].clientY) * 0.5;
652
+ this.lastDragPosition.set(x, y);
653
+ }
654
+ this._state = 0;
655
+ if (!event) {
656
+ if (this._lockedPointer)
657
+ this._state = this._state | this.mouseButtons.left;
658
+ }
659
+ else if ('pointerType' in event && event.pointerType === 'touch') {
660
+ switch (this._activePointers.length) {
661
+ case 1:
662
+ this._state = this.touches.one;
663
+ break;
664
+ case 2:
665
+ this._state = this.touches.two;
666
+ break;
667
+ case 3:
668
+ this._state = this.touches.three;
669
+ break;
670
+ }
671
+ }
672
+ else {
673
+ if (!this._lockedPointer && (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT) {
674
+ this._state = this._state | this.mouseButtons.left;
675
+ }
676
+ if ((event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE) {
677
+ this._state = this._state | this.mouseButtons.middle;
678
+ }
679
+ if ((event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT) {
680
+ this._state = this._state | this.mouseButtons.right;
681
+ }
682
+ }
683
+ // stop current movement on drag start
684
+ if ((this._state & ACTION.ROTATE) === ACTION.ROTATE ||
685
+ (this._state & ACTION.TOUCH_ROTATE) === ACTION.TOUCH_ROTATE ||
686
+ (this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
687
+ (this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
688
+ this._sphericalEnd.theta = this._spherical.theta;
689
+ this._sphericalEnd.phi = this._spherical.phi;
690
+ this._thetaVelocity.value = 0;
691
+ this._phiVelocity.value = 0;
692
+ }
693
+ if ((this._state & ACTION.TRUCK) === ACTION.TRUCK ||
694
+ (this._state & ACTION.TOUCH_TRUCK) === ACTION.TOUCH_TRUCK ||
695
+ (this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
696
+ (this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK) {
697
+ this._targetEnd.copy(this._target);
698
+ this._targetVelocity.set(0, 0, 0);
699
+ }
700
+ if ((this._state & ACTION.DOLLY) === ACTION.DOLLY ||
701
+ (this._state & ACTION.TOUCH_DOLLY) === ACTION.TOUCH_DOLLY ||
702
+ (this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
703
+ (this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
704
+ (this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE) {
705
+ this._sphericalEnd.radius = this._spherical.radius;
706
+ this._radiusVelocity.value = 0;
707
+ }
708
+ if ((this._state & ACTION.ZOOM) === ACTION.ZOOM ||
709
+ (this._state & ACTION.TOUCH_ZOOM) === ACTION.TOUCH_ZOOM ||
710
+ (this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK ||
711
+ (this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET ||
712
+ (this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
713
+ this._zoomEnd = this._zoom;
714
+ this._zoomVelocity.value = 0;
715
+ }
716
+ if ((this._state & ACTION.OFFSET) === ACTION.OFFSET ||
717
+ (this._state & ACTION.TOUCH_OFFSET) === ACTION.TOUCH_OFFSET ||
718
+ (this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
719
+ (this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET) {
720
+ this._focalOffsetEnd.copy(this._focalOffset);
721
+ this._focalOffsetVelocity.set(0, 0, 0);
722
+ }
723
+ this.dispatchEvent({ type: 'controlstart' });
724
+ };
725
+ const dragging = () => {
726
+ if (!this._enabled || !this._dragNeedsUpdate)
727
+ return;
728
+ this._dragNeedsUpdate = false;
729
+ extractClientCoordFromEvent(this._activePointers, _v2);
730
+ // When pointer lock is enabled clientX, clientY, screenX, and screenY remain 0.
731
+ // If pointer lock is enabled, use the Delta directory, and assume active-pointer is not multiple.
732
+ const isPointerLockActive = this._domElement && document.pointerLockElement === this._domElement;
733
+ const lockedPointer = isPointerLockActive ? this._lockedPointer || this._activePointers[0] : null;
734
+ const deltaX = lockedPointer ? -lockedPointer.deltaX : this.lastDragPosition.x - _v2.x;
735
+ const deltaY = lockedPointer ? -lockedPointer.deltaY : this.lastDragPosition.y - _v2.y;
736
+ this.lastDragPosition.copy(_v2);
737
+ if ((this._state & ACTION.ROTATE) === ACTION.ROTATE ||
738
+ (this._state & ACTION.TOUCH_ROTATE) === ACTION.TOUCH_ROTATE ||
739
+ (this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
740
+ (this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
741
+ this._rotateInternal(deltaX, deltaY);
742
+ this._isUserControllingRotate = true;
743
+ }
744
+ if ((this._state & ACTION.DOLLY) === ACTION.DOLLY ||
745
+ (this._state & ACTION.ZOOM) === ACTION.ZOOM) {
746
+ const dollyX = this.dollyToCursor ? (this.dragStartPosition.x - this._elementRect.x) / this._elementRect.width * 2 - 1 : 0;
747
+ const dollyY = this.dollyToCursor ? (this.dragStartPosition.y - this._elementRect.y) / this._elementRect.height * -2 + 1 : 0;
748
+ const dollyDirection = this.dollyDragInverted ? -1 : 1;
749
+ if ((this._state & ACTION.DOLLY) === ACTION.DOLLY) {
750
+ this._dollyInternal(dollyDirection * deltaY * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
751
+ this._isUserControllingDolly = true;
752
+ }
753
+ else {
754
+ this._zoomInternal(dollyDirection * deltaY * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
755
+ this._isUserControllingZoom = true;
756
+ }
757
+ }
758
+ if ((this._state & ACTION.TOUCH_DOLLY) === ACTION.TOUCH_DOLLY ||
759
+ (this._state & ACTION.TOUCH_ZOOM) === ACTION.TOUCH_ZOOM ||
760
+ (this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
761
+ (this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK ||
762
+ (this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
763
+ (this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET ||
764
+ (this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
765
+ (this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
766
+ const dx = _v2.x - this._activePointers[1].clientX;
767
+ const dy = _v2.y - this._activePointers[1].clientY;
768
+ const distance = Math.sqrt(dx * dx + dy * dy);
769
+ const dollyDelta = this.dollyStart.y - distance;
770
+ this.dollyStart.set(0, distance);
771
+ const dollyX = this.dollyToCursor ? (this.lastDragPosition.x - this._elementRect.x) / this._elementRect.width * 2 - 1 : 0;
772
+ const dollyY = this.dollyToCursor ? (this.lastDragPosition.y - this._elementRect.y) / this._elementRect.height * -2 + 1 : 0;
773
+ if ((this._state & ACTION.TOUCH_DOLLY) === ACTION.TOUCH_DOLLY ||
774
+ (this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
775
+ (this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
776
+ (this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET) {
777
+ this._dollyInternal(dollyDelta * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
778
+ this._isUserControllingDolly = true;
779
+ }
780
+ else {
781
+ this._zoomInternal(dollyDelta * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
782
+ this._isUserControllingZoom = true;
783
+ }
784
+ }
785
+ if ((this._state & ACTION.TRUCK) === ACTION.TRUCK ||
786
+ (this._state & ACTION.TOUCH_TRUCK) === ACTION.TOUCH_TRUCK ||
787
+ (this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
788
+ (this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK) {
789
+ this._truckInternal(deltaX, deltaY, false);
790
+ this._isUserControllingTruck = true;
791
+ }
792
+ if ((this._state & ACTION.OFFSET) === ACTION.OFFSET ||
793
+ (this._state & ACTION.TOUCH_OFFSET) === ACTION.TOUCH_OFFSET ||
794
+ (this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
795
+ (this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET) {
796
+ this._truckInternal(deltaX, deltaY, true);
797
+ this._isUserControllingOffset = true;
798
+ }
799
+ this.dispatchEvent({ type: 'control' });
800
+ };
801
+ const endDragging = () => {
802
+ extractClientCoordFromEvent(this._activePointers, _v2);
803
+ this.lastDragPosition.copy(_v2);
804
+ this._dragNeedsUpdate = false;
805
+ if (this._activePointers.length === 0 ||
806
+ (this._activePointers.length === 1 && this._activePointers[0] === this._lockedPointer)) {
807
+ this._isDragging = false;
808
+ }
809
+ if (this._activePointers.length === 0 && this._domElement) {
810
+ // eslint-disable-next-line no-undef
811
+ this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
812
+ this._domElement.ownerDocument.removeEventListener('mousemove', onMouseMove);
813
+ this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
814
+ this._domElement.ownerDocument.removeEventListener('mouseup', onMouseUp);
815
+ this.dispatchEvent({ type: 'controlend' });
816
+ }
817
+ };
818
+ this.lockPointer = () => {
819
+ if (!this._enabled || !this._domElement)
820
+ return;
821
+ this.cancel();
822
+ // Element.requestPointerLock is allowed to happen without any pointer active - create a faux one for compatibility with controls
823
+ this._lockedPointer = {
824
+ pointerId: -1,
825
+ clientX: 0,
826
+ clientY: 0,
827
+ deltaX: 0,
828
+ deltaY: 0,
829
+ mouseButton: null,
830
+ };
831
+ this._activePointers.push(this._lockedPointer);
832
+ // eslint-disable-next-line no-undef
833
+ this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
834
+ this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
835
+ this._domElement.requestPointerLock();
836
+ this._domElement.ownerDocument.addEventListener('pointerlockchange', onPointerLockChange);
837
+ this._domElement.ownerDocument.addEventListener('pointerlockerror', onPointerLockError);
838
+ this._domElement.ownerDocument.addEventListener('pointermove', onPointerMove, { passive: false });
839
+ this._domElement.ownerDocument.addEventListener('pointerup', onPointerUp);
840
+ startDragging();
841
+ };
842
+ this.unlockPointer = () => {
843
+ if (this._lockedPointer !== null) {
844
+ this._disposePointer(this._lockedPointer);
845
+ this._lockedPointer = null;
846
+ }
847
+ document.exitPointerLock();
848
+ this.cancel();
849
+ if (!this._domElement)
850
+ return;
851
+ this._domElement.ownerDocument.removeEventListener('pointerlockchange', onPointerLockChange);
852
+ this._domElement.ownerDocument.removeEventListener('pointerlockerror', onPointerLockError);
853
+ };
854
+ const onPointerLockChange = () => {
855
+ const isPointerLockActive = this._domElement && this._domElement.ownerDocument.pointerLockElement === this._domElement;
856
+ if (!isPointerLockActive)
857
+ this.unlockPointer();
858
+ };
859
+ const onPointerLockError = () => {
860
+ this.unlockPointer();
861
+ };
862
+ this._addAllEventListeners = (domElement) => {
863
+ this._domElement = domElement;
864
+ this._domElement.style.touchAction = 'none';
865
+ this._domElement.style.userSelect = 'none';
866
+ this._domElement.style.webkitUserSelect = 'none';
867
+ this.events.push(graphics.engine.inputSystem.listen('pointerdown', onPointerDown, { target: domElement }));
868
+ isPointerEventsNotSupported && this.events.push(graphics.engine.inputSystem.listen('mousedown', onMouseDown, { target: domElement }));
869
+ this.events.push(graphics.engine.inputSystem.listen('pointercancel', onPointerUp, { target: domElement }));
870
+ this.events.push(graphics.engine.inputSystem.listen('wheel', onMouseWheel, { target: domElement, passive: false }));
871
+ this.events.push(graphics.engine.inputSystem.listen('contextmenu', onContextMenu, { target: domElement }));
872
+ };
873
+ this._removeAllEventListeners = () => {
874
+ if (!this._domElement)
875
+ return;
876
+ this._domElement.style.touchAction = '';
877
+ this._domElement.style.userSelect = '';
878
+ this._domElement.style.webkitUserSelect = '';
879
+ for (const event of this.events)
880
+ graphics.engine.inputSystem.unlisten(event);
881
+ this.events.length = 0;
882
+ this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
883
+ this._domElement.ownerDocument.removeEventListener('mousemove', onMouseMove);
884
+ this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
885
+ this._domElement.ownerDocument.removeEventListener('mouseup', onMouseUp);
886
+ this._domElement.ownerDocument.removeEventListener('pointerlockchange', onPointerLockChange);
887
+ this._domElement.ownerDocument.removeEventListener('pointerlockerror', onPointerLockError);
888
+ };
889
+ this.cancel = () => {
890
+ if (this._state === ACTION.NONE)
891
+ return;
892
+ this._state = ACTION.NONE;
893
+ this._activePointers.length = 0;
894
+ endDragging();
895
+ };
896
+ }
897
+ /**
898
+ * The camera to be controlled
899
+ * @category Properties
900
+ */
901
+ get camera() {
902
+ return this._camera;
903
+ }
904
+ set camera(camera) {
905
+ this._camera = camera;
906
+ this.updateCameraUp();
907
+ this._camera.updateProjectionMatrix();
908
+ this._updateNearPlaneCorners();
909
+ this._needsUpdate = true;
910
+ }
911
+ /**
912
+ * Whether or not the controls are enabled.
913
+ * `false` to disable user dragging/touch-move, but all methods works.
914
+ * @category Properties
915
+ */
916
+ get enabled() {
917
+ return this._enabled;
918
+ }
919
+ set enabled(enabled) {
920
+ this._enabled = enabled;
921
+ if (!this._domElement)
922
+ return;
923
+ if (enabled) {
924
+ this._domElement.style.touchAction = 'none';
925
+ this._domElement.style.userSelect = 'none';
926
+ this._domElement.style.webkitUserSelect = 'none';
927
+ }
928
+ else {
929
+ this.cancel();
930
+ this._domElement.style.touchAction = '';
931
+ this._domElement.style.userSelect = '';
932
+ this._domElement.style.webkitUserSelect = '';
933
+ }
934
+ }
935
+ /**
936
+ * Returns `true` if the controls are active updating.
937
+ * readonly value.
938
+ * @category Properties
939
+ */
940
+ get active() {
941
+ return !this._hasRested;
942
+ }
943
+ /**
944
+ * Getter for the current `ACTION`.
945
+ * readonly value.
946
+ * @category Properties
947
+ */
948
+ get currentAction() {
949
+ return this._state;
950
+ }
951
+ /**
952
+ * get/set Current distance.
953
+ * @category Properties
954
+ */
955
+ get distance() {
956
+ return this._spherical.radius;
957
+ }
958
+ set distance(distance) {
959
+ if (this._spherical.radius === distance &&
960
+ this._sphericalEnd.radius === distance)
961
+ return;
962
+ this._spherical.radius = distance;
963
+ this._sphericalEnd.radius = distance;
964
+ this._needsUpdate = true;
965
+ }
966
+ // horizontal angle
967
+ /**
968
+ * get/set the azimuth angle (horizontal) in radians.
969
+ * Every 360 degrees turn is added to `.azimuthAngle` value, which is accumulative.
970
+ * @category Properties
971
+ */
972
+ get azimuthAngle() {
973
+ return this._spherical.theta;
974
+ }
975
+ set azimuthAngle(azimuthAngle) {
976
+ if (this._spherical.theta === azimuthAngle &&
977
+ this._sphericalEnd.theta === azimuthAngle)
978
+ return;
979
+ this._spherical.theta = azimuthAngle;
980
+ this._sphericalEnd.theta = azimuthAngle;
981
+ this._needsUpdate = true;
982
+ }
983
+ // vertical angle
984
+ /**
985
+ * get/set the polar angle (vertical) in radians.
986
+ * @category Properties
987
+ */
988
+ get polarAngle() {
989
+ return this._spherical.phi;
990
+ }
991
+ set polarAngle(polarAngle) {
992
+ if (this._spherical.phi === polarAngle &&
993
+ this._sphericalEnd.phi === polarAngle)
994
+ return;
995
+ this._spherical.phi = polarAngle;
996
+ this._sphericalEnd.phi = polarAngle;
997
+ this._needsUpdate = true;
998
+ }
999
+ /**
1000
+ * Whether camera position should be enclosed in the boundary or not.
1001
+ * @category Properties
1002
+ */
1003
+ get boundaryEnclosesCamera() {
1004
+ return this._boundaryEnclosesCamera;
1005
+ }
1006
+ set boundaryEnclosesCamera(boundaryEnclosesCamera) {
1007
+ this._boundaryEnclosesCamera = boundaryEnclosesCamera;
1008
+ this._needsUpdate = true;
1009
+ }
1010
+ /**
1011
+ * Set drag-start, touches and wheel enable area in the domElement.
1012
+ * each values are between `0` and `1` inclusive, where `0` is left/top and `1` is right/bottom of the screen.
1013
+ * e.g. `{ x: 0, y: 0, width: 1, height: 1 }` for entire area.
1014
+ * @category Properties
1015
+ */
1016
+ set interactiveArea(interactiveArea) {
1017
+ this._interactiveArea.width = clamp(interactiveArea.width, 0, 1);
1018
+ this._interactiveArea.height = clamp(interactiveArea.height, 0, 1);
1019
+ this._interactiveArea.x = clamp(interactiveArea.x, 0, 1 - this._interactiveArea.width);
1020
+ this._interactiveArea.y = clamp(interactiveArea.y, 0, 1 - this._interactiveArea.height);
1021
+ }
1022
+ /**
1023
+ * Adds the specified event listener.
1024
+ * Applicable event types (which is `K`) are:
1025
+ * | Event name | Timing |
1026
+ * | ------------------- | ------ |
1027
+ * | `'controlstart'` | When the user starts to control the camera via mouse / touches. ¹ |
1028
+ * | `'control'` | When the user controls the camera (dragging). |
1029
+ * | `'controlend'` | When the user ends to control the camera. ¹ |
1030
+ * | `'transitionstart'` | When any kind of transition starts, either user control or using a method with `enableTransition = true` |
1031
+ * | `'update'` | When the camera position is updated. |
1032
+ * | `'wake'` | When the camera starts moving. |
1033
+ * | `'rest'` | When the camera movement is below `.restThreshold` ². |
1034
+ * | `'sleep'` | When the camera end moving. |
1035
+ *
1036
+ * 1. `mouseButtons.wheel` (Mouse wheel control) does not emit `'controlstart'` and `'controlend'`. `mouseButtons.wheel` uses scroll-event internally, and scroll-event happens intermittently. That means "start" and "end" cannot be detected.
1037
+ * 2. Due to damping, `sleep` will usually fire a few seconds after the camera _appears_ to have stopped moving. If you want to do something (e.g. enable UI, perform another transition) at the point when the camera has stopped, you probably want the `rest` event. This can be fine tuned using the `.restThreshold` parameter. See the [Rest and Sleep Example](https://yomotsu.github.io/camera-controls/examples/rest-and-sleep.html).
1038
+ *
1039
+ * e.g.
1040
+ * ```
1041
+ * cameraControl.addEventListener( 'controlstart', myCallbackFunction );
1042
+ * ```
1043
+ * @param type event name
1044
+ * @param listener handler function
1045
+ * @category Methods
1046
+ */
1047
+ addEventListener(type, listener) {
1048
+ super.addEventListener(type, listener);
1049
+ }
1050
+ /**
1051
+ * Removes the specified event listener
1052
+ * e.g.
1053
+ * ```
1054
+ * cameraControl.addEventListener( 'controlstart', myCallbackFunction );
1055
+ * ```
1056
+ * @param type event name
1057
+ * @param listener handler function
1058
+ * @category Methods
1059
+ */
1060
+ removeEventListener(type, listener) {
1061
+ super.removeEventListener(type, listener);
1062
+ }
1063
+ removeAllEventListeners(type) {
1064
+ if (!type) {
1065
+ this._listeners = {};
1066
+ return;
1067
+ }
1068
+ if (Array.isArray(this._listeners[type]))
1069
+ this._listeners[type].length = 0;
1070
+ }
1071
+ /**
1072
+ * Rotate azimuthal angle(horizontal) and polar angle(vertical).
1073
+ * Every value is added to the current value.
1074
+ * @param azimuthAngle Azimuth rotate angle. In radian.
1075
+ * @param polarAngle Polar rotate angle. In radian.
1076
+ * @param enableTransition Whether to move smoothly or immediately
1077
+ * @category Methods
1078
+ */
1079
+ rotate(azimuthAngle, polarAngle, enableTransition = false) {
1080
+ return this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi + polarAngle, enableTransition);
1081
+ }
1082
+ /**
1083
+ * Rotate azimuthal angle(horizontal) to the given angle and keep the same polar angle(vertical) target.
1084
+ *
1085
+ * e.g.
1086
+ * ```
1087
+ * cameraControls.rotateAzimuthTo( 30 * MathUtils.DEG2RAD, true );
1088
+ * ```
1089
+ * @param azimuthAngle Azimuth rotate angle. In radian.
1090
+ * @param enableTransition Whether to move smoothly or immediately
1091
+ * @category Methods
1092
+ */
1093
+ rotateAzimuthTo(azimuthAngle, enableTransition = false) {
1094
+ return this.rotateTo(azimuthAngle, this._sphericalEnd.phi, enableTransition);
1095
+ }
1096
+ /**
1097
+ * Rotate polar angle(vertical) to the given angle and keep the same azimuthal angle(horizontal) target.
1098
+ *
1099
+ * e.g.
1100
+ * ```
1101
+ * cameraControls.rotatePolarTo( 30 * MathUtils.DEG2RAD, true );
1102
+ * ```
1103
+ * @param polarAngle Polar rotate angle. In radian.
1104
+ * @param enableTransition Whether to move smoothly or immediately
1105
+ * @category Methods
1106
+ */
1107
+ rotatePolarTo(polarAngle, enableTransition = false) {
1108
+ return this.rotateTo(this._sphericalEnd.theta, polarAngle, enableTransition);
1109
+ }
1110
+ /**
1111
+ * Rotate azimuthal angle(horizontal) and polar angle(vertical) to the given angle.
1112
+ * Camera view will rotate over the orbit pivot absolutely:
1113
+ *
1114
+ * azimuthAngle
1115
+ * ```
1116
+ * 0º
1117
+ * \
1118
+ * 90º -----+----- -90º
1119
+ * \
1120
+ * 180º
1121
+ * ```
1122
+ * | direction | angle |
1123
+ * | --------- | ---------------------- |
1124
+ * | front | 0º |
1125
+ * | left | 90º (`Math.PI / 2`) |
1126
+ * | right | -90º (`- Math.PI / 2`) |
1127
+ * | back | 180º (`Math.PI`) |
1128
+ *
1129
+ * polarAngle
1130
+ * ```
1131
+ * 180º
1132
+ * |
1133
+ * 90º
1134
+ * |
1135
+ * 0º
1136
+ * ```
1137
+ * | direction | angle |
1138
+ * | -------------------- | ---------------------- |
1139
+ * | top/sky | 180º (`Math.PI`) |
1140
+ * | horizontal from view | 90º (`Math.PI / 2`) |
1141
+ * | bottom/floor | 0º |
1142
+ *
1143
+ * @param azimuthAngle Azimuth rotate angle to. In radian.
1144
+ * @param polarAngle Polar rotate angle to. In radian.
1145
+ * @param enableTransition Whether to move smoothly or immediately
1146
+ * @category Methods
1147
+ */
1148
+ rotateTo(azimuthAngle, polarAngle, enableTransition = false) {
1149
+ this._isUserControllingRotate = false;
1150
+ const theta = clamp(azimuthAngle, this.minAzimuthAngle, this.maxAzimuthAngle);
1151
+ const phi = clamp(polarAngle, this.minPolarAngle, this.maxPolarAngle);
1152
+ this._sphericalEnd.theta = theta;
1153
+ this._sphericalEnd.phi = phi;
1154
+ this._sphericalEnd.makeSafe();
1155
+ this._needsUpdate = true;
1156
+ if (!enableTransition) {
1157
+ this._spherical.theta = this._sphericalEnd.theta;
1158
+ this._spherical.phi = this._sphericalEnd.phi;
1159
+ }
1160
+ const resolveImmediately = !enableTransition ||
1161
+ approxEquals(this._spherical.theta, this._sphericalEnd.theta, this.restThreshold) &&
1162
+ approxEquals(this._spherical.phi, this._sphericalEnd.phi, this.restThreshold);
1163
+ return this._createOnRestPromise(resolveImmediately);
1164
+ }
1165
+ /**
1166
+ * Dolly in/out camera position.
1167
+ * @param distance Distance of dollyIn. Negative number for dollyOut.
1168
+ * @param enableTransition Whether to move smoothly or immediately.
1169
+ * @category Methods
1170
+ */
1171
+ dolly(distance, enableTransition = false) {
1172
+ return this.dollyTo(this._sphericalEnd.radius - distance, enableTransition);
1173
+ }
1174
+ /**
1175
+ * Dolly in/out camera position to given distance.
1176
+ * @param distance Distance of dolly.
1177
+ * @param enableTransition Whether to move smoothly or immediately.
1178
+ * @category Methods
1179
+ */
1180
+ dollyTo(distance, enableTransition = false) {
1181
+ this._isUserControllingDolly = false;
1182
+ this._lastDollyDirection = DOLLY_DIRECTION.NONE;
1183
+ this._changedDolly = 0;
1184
+ return this._dollyToNoClamp(clamp(distance, this.minDistance, this.maxDistance), enableTransition);
1185
+ }
1186
+ _dollyToNoClamp(distance, enableTransition = false) {
1187
+ const lastRadius = this._sphericalEnd.radius;
1188
+ const hasCollider = this.colliderMeshes.length >= 1;
1189
+ if (hasCollider) {
1190
+ const maxDistanceByCollisionTest = this._collisionTest();
1191
+ const isCollided = approxEquals(maxDistanceByCollisionTest, this._spherical.radius);
1192
+ const isDollyIn = lastRadius > distance;
1193
+ if (!isDollyIn && isCollided)
1194
+ return Promise.resolve();
1195
+ this._sphericalEnd.radius = Math.min(distance, maxDistanceByCollisionTest);
1196
+ }
1197
+ else {
1198
+ this._sphericalEnd.radius = distance;
1199
+ }
1200
+ this._needsUpdate = true;
1201
+ if (!enableTransition) {
1202
+ this._spherical.radius = this._sphericalEnd.radius;
1203
+ }
1204
+ const resolveImmediately = !enableTransition || approxEquals(this._spherical.radius, this._sphericalEnd.radius, this.restThreshold);
1205
+ return this._createOnRestPromise(resolveImmediately);
1206
+ }
1207
+ /**
1208
+ * Dolly in, but does not change the distance between the target and the camera, and moves the target position instead.
1209
+ * Specify a negative value for dolly out.
1210
+ * @param distance Distance of dolly.
1211
+ * @param enableTransition Whether to move smoothly or immediately.
1212
+ * @category Methods
1213
+ */
1214
+ dollyInFixed(distance, enableTransition = false) {
1215
+ this._targetEnd.add(this._getCameraDirection(_cameraDirection).multiplyScalar(distance));
1216
+ if (!enableTransition) {
1217
+ this._target.copy(this._targetEnd);
1218
+ }
1219
+ const resolveImmediately = !enableTransition ||
1220
+ approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
1221
+ approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
1222
+ approxEquals(this._target.z, this._targetEnd.z, this.restThreshold);
1223
+ return this._createOnRestPromise(resolveImmediately);
1224
+ }
1225
+ /**
1226
+ * Zoom in/out camera. The value is added to camera zoom.
1227
+ * Limits set with `.minZoom` and `.maxZoom`
1228
+ * @param zoomStep zoom scale
1229
+ * @param enableTransition Whether to move smoothly or immediately
1230
+ * @category Methods
1231
+ */
1232
+ zoom(zoomStep, enableTransition = false) {
1233
+ return this.zoomTo(this._zoomEnd + zoomStep, enableTransition);
1234
+ }
1235
+ /**
1236
+ * Zoom in/out camera to given scale. The value overwrites camera zoom.
1237
+ * Limits set with .minZoom and .maxZoom
1238
+ * @param zoom
1239
+ * @param enableTransition
1240
+ * @category Methods
1241
+ */
1242
+ zoomTo(zoom, enableTransition = false) {
1243
+ this._isUserControllingZoom = false;
1244
+ this._zoomEnd = clamp(zoom, this.minZoom, this.maxZoom);
1245
+ this._needsUpdate = true;
1246
+ if (!enableTransition) {
1247
+ this._zoom = this._zoomEnd;
1248
+ }
1249
+ const resolveImmediately = !enableTransition || approxEquals(this._zoom, this._zoomEnd, this.restThreshold);
1250
+ this._changedZoom = 0;
1251
+ return this._createOnRestPromise(resolveImmediately);
1252
+ }
1253
+ /**
1254
+ * @deprecated `pan()` has been renamed to `truck()`
1255
+ * @category Methods
1256
+ */
1257
+ pan(x, y, enableTransition = false) {
1258
+ console.warn('`pan` has been renamed to `truck`');
1259
+ return this.truck(x, y, enableTransition);
1260
+ }
1261
+ /**
1262
+ * Truck and pedestal camera using current azimuthal angle
1263
+ * @param x Horizontal translate amount
1264
+ * @param y Vertical translate amount
1265
+ * @param enableTransition Whether to move smoothly or immediately
1266
+ * @category Methods
1267
+ */
1268
+ truck(x, y, enableTransition = false) {
1269
+ this._camera.updateMatrix();
1270
+ _xColumn.setFromMatrixColumn(this._camera.matrix, 0);
1271
+ _yColumn.setFromMatrixColumn(this._camera.matrix, 1);
1272
+ _xColumn.multiplyScalar(x);
1273
+ _yColumn.multiplyScalar(-y);
1274
+ const offset = _v3A.copy(_xColumn).add(_yColumn);
1275
+ const to = _v3B.copy(this._targetEnd).add(offset);
1276
+ return this.moveTo(to.x, to.y, to.z, enableTransition);
1277
+ }
1278
+ /**
1279
+ * Move forward / backward.
1280
+ * @param distance Amount to move forward / backward. Negative value to move backward
1281
+ * @param enableTransition Whether to move smoothly or immediately
1282
+ * @category Methods
1283
+ */
1284
+ forward(distance, enableTransition = false) {
1285
+ _v3A.setFromMatrixColumn(this._camera.matrix, 0);
1286
+ _v3A.crossVectors(this._camera.up, _v3A);
1287
+ _v3A.multiplyScalar(distance);
1288
+ const to = _v3B.copy(this._targetEnd).add(_v3A);
1289
+ return this.moveTo(to.x, to.y, to.z, enableTransition);
1290
+ }
1291
+ /**
1292
+ * Move up / down.
1293
+ * @param height Amount to move up / down. Negative value to move down
1294
+ * @param enableTransition Whether to move smoothly or immediately
1295
+ * @category Methods
1296
+ */
1297
+ elevate(height, enableTransition = false) {
1298
+ _v3A.copy(this._camera.up).multiplyScalar(height);
1299
+ return this.moveTo(this._targetEnd.x + _v3A.x, this._targetEnd.y + _v3A.y, this._targetEnd.z + _v3A.z, enableTransition);
1300
+ }
1301
+ /**
1302
+ * Move target position to given point.
1303
+ * @param x x coord to move center position
1304
+ * @param y y coord to move center position
1305
+ * @param z z coord to move center position
1306
+ * @param enableTransition Whether to move smoothly or immediately
1307
+ * @category Methods
1308
+ */
1309
+ moveTo(x, y, z, enableTransition = false) {
1310
+ this._isUserControllingTruck = false;
1311
+ const offset = _v3A.set(x, y, z).sub(this._targetEnd);
1312
+ this._encloseToBoundary(this._targetEnd, offset, this.boundaryFriction);
1313
+ this._needsUpdate = true;
1314
+ if (!enableTransition) {
1315
+ this._target.copy(this._targetEnd);
1316
+ }
1317
+ const resolveImmediately = !enableTransition ||
1318
+ approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
1319
+ approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
1320
+ approxEquals(this._target.z, this._targetEnd.z, this.restThreshold);
1321
+ return this._createOnRestPromise(resolveImmediately);
1322
+ }
1323
+ /**
1324
+ * Look in the given point direction.
1325
+ * @param x point x.
1326
+ * @param y point y.
1327
+ * @param z point z.
1328
+ * @param enableTransition Whether to move smoothly or immediately.
1329
+ * @returns Transition end promise
1330
+ * @category Methods
1331
+ */
1332
+ lookInDirectionOf(x, y, z, enableTransition = false) {
1333
+ const point = _v3A.set(x, y, z);
1334
+ const direction = point.sub(this._targetEnd).normalize();
1335
+ const position = direction.multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);
1336
+ return this.setPosition(position.x, position.y, position.z, enableTransition);
1337
+ }
1338
+ /**
1339
+ * Fit the viewport to the box or the bounding box of the object, using the nearest axis. paddings are in unit.
1340
+ * set `cover: true` to fill enter screen.
1341
+ * e.g.
1342
+ * ```
1343
+ * cameraControls.fitToBox( myMesh );
1344
+ * ```
1345
+ * @param box3OrObject Axis aligned bounding box to fit the view.
1346
+ * @param enableTransition Whether to move smoothly or immediately.
1347
+ * @param options | `<object>` { cover: boolean, paddingTop: number, paddingLeft: number, paddingBottom: number, paddingRight: number }
1348
+ * @returns Transition end promise
1349
+ * @category Methods
1350
+ */
1351
+ fitToBox(box3OrObject, enableTransition, { cover = false, paddingLeft = 0, paddingRight = 0, paddingBottom = 0, paddingTop = 0 } = {}) {
1352
+ const promises = [];
1353
+ //@ts-ignore
1354
+ const aabb = box3OrObject.isBox3 ? _box3A.copy(box3OrObject) : _box3A.setFromObject(box3OrObject);
1355
+ if (aabb.isEmpty()) {
1356
+ console.warn('camera-controls: fitTo() cannot be used with an empty box. Aborting');
1357
+ Promise.resolve();
1358
+ }
1359
+ // round to closest axis ( forward | backward | right | left | top | bottom )
1360
+ const theta = roundToStep(this._sphericalEnd.theta, PI_HALF);
1361
+ const phi = roundToStep(this._sphericalEnd.phi, PI_HALF);
1362
+ promises.push(this.rotateTo(theta, phi, enableTransition));
1363
+ const normal = _v3A.setFromSpherical(this._sphericalEnd).normalize();
1364
+ const rotation = _quaternionA.setFromUnitVectors(normal, _AXIS_Z);
1365
+ const viewFromPolar = approxEquals(Math.abs(normal.y), 1);
1366
+ if (viewFromPolar) {
1367
+ rotation.multiply(_quaternionB.setFromAxisAngle(_AXIS_Y, theta));
1368
+ }
1369
+ rotation.multiply(this._yAxisUpSpaceInverse);
1370
+ // make oriented bounding box
1371
+ const bb = _box3B.makeEmpty();
1372
+ // left bottom back corner
1373
+ _v3B.copy(aabb.min).applyQuaternion(rotation);
1374
+ bb.expandByPoint(_v3B);
1375
+ // right bottom back corner
1376
+ _v3B.copy(aabb.min).setX(aabb.max.x).applyQuaternion(rotation);
1377
+ bb.expandByPoint(_v3B);
1378
+ // left top back corner
1379
+ _v3B.copy(aabb.min).setY(aabb.max.y).applyQuaternion(rotation);
1380
+ bb.expandByPoint(_v3B);
1381
+ // right top back corner
1382
+ _v3B.copy(aabb.max).setZ(aabb.min.z).applyQuaternion(rotation);
1383
+ bb.expandByPoint(_v3B);
1384
+ // left bottom front corner
1385
+ _v3B.copy(aabb.min).setZ(aabb.max.z).applyQuaternion(rotation);
1386
+ bb.expandByPoint(_v3B);
1387
+ // right bottom front corner
1388
+ _v3B.copy(aabb.max).setY(aabb.min.y).applyQuaternion(rotation);
1389
+ bb.expandByPoint(_v3B);
1390
+ // left top front corner
1391
+ _v3B.copy(aabb.max).setX(aabb.min.x).applyQuaternion(rotation);
1392
+ bb.expandByPoint(_v3B);
1393
+ // right top front corner
1394
+ _v3B.copy(aabb.max).applyQuaternion(rotation);
1395
+ bb.expandByPoint(_v3B);
1396
+ // add padding
1397
+ bb.min.x -= paddingLeft;
1398
+ bb.min.y -= paddingBottom;
1399
+ bb.max.x += paddingRight;
1400
+ bb.max.y += paddingTop;
1401
+ rotation.setFromUnitVectors(_AXIS_Z, normal);
1402
+ if (viewFromPolar) {
1403
+ rotation.premultiply(_quaternionB.invert());
1404
+ }
1405
+ rotation.premultiply(this._yAxisUpSpace);
1406
+ const bbSize = bb.getSize(_v3A);
1407
+ const center = bb.getCenter(_v3B).applyQuaternion(rotation);
1408
+ if (isPerspectiveCamera(this._camera)) {
1409
+ const distance = this.getDistanceToFitBox(bbSize.x, bbSize.y, bbSize.z, cover);
1410
+ promises.push(this.moveTo(center.x, center.y, center.z, enableTransition));
1411
+ promises.push(this.dollyTo(distance, enableTransition));
1412
+ promises.push(this.setFocalOffset(0, 0, 0, enableTransition));
1413
+ }
1414
+ else if (isOrthographicCamera(this._camera)) {
1415
+ const camera = this._camera;
1416
+ const width = camera.right - camera.left;
1417
+ const height = camera.top - camera.bottom;
1418
+ const zoom = cover ? Math.max(width / bbSize.x, height / bbSize.y) : Math.min(width / bbSize.x, height / bbSize.y);
1419
+ promises.push(this.moveTo(center.x, center.y, center.z, enableTransition));
1420
+ promises.push(this.zoomTo(zoom, enableTransition));
1421
+ promises.push(this.setFocalOffset(0, 0, 0, enableTransition));
1422
+ }
1423
+ return Promise.all(promises);
1424
+ }
1425
+ /**
1426
+ * Fit the viewport to the sphere or the bounding sphere of the object.
1427
+ * @param sphereOrMesh
1428
+ * @param enableTransition
1429
+ * @category Methods
1430
+ */
1431
+ fitToSphere(sphereOrMesh, enableTransition) {
1432
+ const promises = [];
1433
+ const isSphere = sphereOrMesh instanceof Sphere;
1434
+ const boundingSphere = isSphere ?
1435
+ _sphere.copy(sphereOrMesh) :
1436
+ CameraControls.createBoundingSphere(sphereOrMesh, _sphere);
1437
+ promises.push(this.moveTo(boundingSphere.center.x, boundingSphere.center.y, boundingSphere.center.z, enableTransition));
1438
+ if (isPerspectiveCamera(this._camera)) {
1439
+ const distanceToFit = this.getDistanceToFitSphere(boundingSphere.radius);
1440
+ promises.push(this.dollyTo(distanceToFit, enableTransition));
1441
+ }
1442
+ else if (isOrthographicCamera(this._camera)) {
1443
+ const width = this._camera.right - this._camera.left;
1444
+ const height = this._camera.top - this._camera.bottom;
1445
+ const diameter = 2 * boundingSphere.radius;
1446
+ const zoom = Math.min(width / diameter, height / diameter);
1447
+ promises.push(this.zoomTo(zoom, enableTransition));
1448
+ }
1449
+ promises.push(this.setFocalOffset(0, 0, 0, enableTransition));
1450
+ return Promise.all(promises);
1451
+ }
1452
+ /**
1453
+ * Look at the `target` from the `position`.
1454
+ * @param positionX
1455
+ * @param positionY
1456
+ * @param positionZ
1457
+ * @param targetX
1458
+ * @param targetY
1459
+ * @param targetZ
1460
+ * @param enableTransition
1461
+ * @category Methods
1462
+ */
1463
+ setLookAt(positionX, positionY, positionZ, targetX, targetY, targetZ, enableTransition = false) {
1464
+ this._isUserControllingRotate = false;
1465
+ this._isUserControllingDolly = false;
1466
+ this._isUserControllingTruck = false;
1467
+ this._lastDollyDirection = DOLLY_DIRECTION.NONE;
1468
+ this._changedDolly = 0;
1469
+ const target = _v3B.set(targetX, targetY, targetZ);
1470
+ const position = _v3A.set(positionX, positionY, positionZ);
1471
+ this._targetEnd.copy(target);
1472
+ this._sphericalEnd.setFromVector3(position.sub(target).applyQuaternion(this._yAxisUpSpace));
1473
+ this.normalizeRotations();
1474
+ this._needsUpdate = true;
1475
+ if (!enableTransition) {
1476
+ this._target.copy(this._targetEnd);
1477
+ this._spherical.copy(this._sphericalEnd);
1478
+ }
1479
+ const resolveImmediately = !enableTransition ||
1480
+ approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
1481
+ approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
1482
+ approxEquals(this._target.z, this._targetEnd.z, this.restThreshold) &&
1483
+ approxEquals(this._spherical.theta, this._sphericalEnd.theta, this.restThreshold) &&
1484
+ approxEquals(this._spherical.phi, this._sphericalEnd.phi, this.restThreshold) &&
1485
+ approxEquals(this._spherical.radius, this._sphericalEnd.radius, this.restThreshold);
1486
+ return this._createOnRestPromise(resolveImmediately);
1487
+ }
1488
+ /**
1489
+ * Similar to setLookAt, but it interpolates between two states.
1490
+ * @param positionAX
1491
+ * @param positionAY
1492
+ * @param positionAZ
1493
+ * @param targetAX
1494
+ * @param targetAY
1495
+ * @param targetAZ
1496
+ * @param positionBX
1497
+ * @param positionBY
1498
+ * @param positionBZ
1499
+ * @param targetBX
1500
+ * @param targetBY
1501
+ * @param targetBZ
1502
+ * @param t
1503
+ * @param enableTransition
1504
+ * @category Methods
1505
+ */
1506
+ lerpLookAt(positionAX, positionAY, positionAZ, targetAX, targetAY, targetAZ, positionBX, positionBY, positionBZ, targetBX, targetBY, targetBZ, t, enableTransition = false) {
1507
+ this._isUserControllingRotate = false;
1508
+ this._isUserControllingDolly = false;
1509
+ this._isUserControllingTruck = false;
1510
+ this._lastDollyDirection = DOLLY_DIRECTION.NONE;
1511
+ this._changedDolly = 0;
1512
+ const targetA = _v3A.set(targetAX, targetAY, targetAZ);
1513
+ const positionA = _v3B.set(positionAX, positionAY, positionAZ);
1514
+ _sphericalA.setFromVector3(positionA.sub(targetA).applyQuaternion(this._yAxisUpSpace));
1515
+ const targetB = _v3C.set(targetBX, targetBY, targetBZ);
1516
+ const positionB = _v3B.set(positionBX, positionBY, positionBZ);
1517
+ _sphericalB.setFromVector3(positionB.sub(targetB).applyQuaternion(this._yAxisUpSpace));
1518
+ this._targetEnd.copy(targetA.lerp(targetB, t)); // tricky
1519
+ const deltaTheta = _sphericalB.theta - _sphericalA.theta;
1520
+ const deltaPhi = _sphericalB.phi - _sphericalA.phi;
1521
+ const deltaRadius = _sphericalB.radius - _sphericalA.radius;
1522
+ this._sphericalEnd.set(_sphericalA.radius + deltaRadius * t, _sphericalA.phi + deltaPhi * t, _sphericalA.theta + deltaTheta * t);
1523
+ this.normalizeRotations();
1524
+ this._needsUpdate = true;
1525
+ if (!enableTransition) {
1526
+ this._target.copy(this._targetEnd);
1527
+ this._spherical.copy(this._sphericalEnd);
1528
+ }
1529
+ const resolveImmediately = !enableTransition ||
1530
+ approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
1531
+ approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
1532
+ approxEquals(this._target.z, this._targetEnd.z, this.restThreshold) &&
1533
+ approxEquals(this._spherical.theta, this._sphericalEnd.theta, this.restThreshold) &&
1534
+ approxEquals(this._spherical.phi, this._sphericalEnd.phi, this.restThreshold) &&
1535
+ approxEquals(this._spherical.radius, this._sphericalEnd.radius, this.restThreshold);
1536
+ return this._createOnRestPromise(resolveImmediately);
1537
+ }
1538
+ /**
1539
+ * Set angle and distance by given position.
1540
+ * An alias of `setLookAt()`, without target change. Thus keep gazing at the current target
1541
+ * @param positionX
1542
+ * @param positionY
1543
+ * @param positionZ
1544
+ * @param enableTransition
1545
+ * @category Methods
1546
+ */
1547
+ setPosition(positionX, positionY, positionZ, enableTransition = false) {
1548
+ return this.setLookAt(positionX, positionY, positionZ, this._targetEnd.x, this._targetEnd.y, this._targetEnd.z, enableTransition);
1549
+ }
1550
+ /**
1551
+ * Set the target position where gaze at.
1552
+ * An alias of `setLookAt()`, without position change. Thus keep the same position.
1553
+ * @param targetX
1554
+ * @param targetY
1555
+ * @param targetZ
1556
+ * @param enableTransition
1557
+ * @category Methods
1558
+ */
1559
+ setTarget(targetX, targetY, targetZ, enableTransition = false) {
1560
+ const pos = this.getPosition(_v3A);
1561
+ const promise = this.setLookAt(pos.x, pos.y, pos.z, targetX, targetY, targetZ, enableTransition);
1562
+ // see https://github.com/yomotsu/camera-controls/issues/335
1563
+ this._sphericalEnd.phi = clamp(this._sphericalEnd.phi, this.minPolarAngle, this.maxPolarAngle);
1564
+ return promise;
1565
+ }
1566
+ /**
1567
+ * Set focal offset using the screen parallel coordinates. z doesn't affect in Orthographic as with Dolly.
1568
+ * @param x
1569
+ * @param y
1570
+ * @param z
1571
+ * @param enableTransition
1572
+ * @category Methods
1573
+ */
1574
+ setFocalOffset(x, y, z, enableTransition = false) {
1575
+ this._isUserControllingOffset = false;
1576
+ this._focalOffsetEnd.set(x, y, z);
1577
+ this._needsUpdate = true;
1578
+ if (!enableTransition)
1579
+ this._focalOffset.copy(this._focalOffsetEnd);
1580
+ const resolveImmediately = !enableTransition ||
1581
+ approxEquals(this._focalOffset.x, this._focalOffsetEnd.x, this.restThreshold) &&
1582
+ approxEquals(this._focalOffset.y, this._focalOffsetEnd.y, this.restThreshold) &&
1583
+ approxEquals(this._focalOffset.z, this._focalOffsetEnd.z, this.restThreshold);
1584
+ return this._createOnRestPromise(resolveImmediately);
1585
+ }
1586
+ /**
1587
+ * Set orbit point without moving the camera.
1588
+ * SHOULD NOT RUN DURING ANIMATIONS. `setOrbitPoint()` will immediately fix the positions.
1589
+ * @param targetX
1590
+ * @param targetY
1591
+ * @param targetZ
1592
+ * @category Methods
1593
+ */
1594
+ setOrbitPoint(targetX, targetY, targetZ) {
1595
+ this._camera.updateMatrixWorld();
1596
+ _xColumn.setFromMatrixColumn(this._camera.matrixWorldInverse, 0);
1597
+ _yColumn.setFromMatrixColumn(this._camera.matrixWorldInverse, 1);
1598
+ _zColumn.setFromMatrixColumn(this._camera.matrixWorldInverse, 2);
1599
+ const position = _v3A.set(targetX, targetY, targetZ);
1600
+ const distance = position.distanceTo(this._camera.position);
1601
+ const cameraToPoint = position.sub(this._camera.position);
1602
+ _xColumn.multiplyScalar(cameraToPoint.x);
1603
+ _yColumn.multiplyScalar(cameraToPoint.y);
1604
+ _zColumn.multiplyScalar(cameraToPoint.z);
1605
+ _v3A.copy(_xColumn).add(_yColumn).add(_zColumn);
1606
+ _v3A.z = _v3A.z + distance;
1607
+ this.dollyTo(distance, false);
1608
+ this.setFocalOffset(-_v3A.x, _v3A.y, -_v3A.z, false);
1609
+ this.moveTo(targetX, targetY, targetZ, false);
1610
+ }
1611
+ /**
1612
+ * Set the boundary box that encloses the target of the camera. box3 is in Box3
1613
+ * @param box3
1614
+ * @category Methods
1615
+ */
1616
+ setBoundary(box3) {
1617
+ if (!box3) {
1618
+ this._boundary.min.set(-Infinity, -Infinity, -Infinity);
1619
+ this._boundary.max.set(Infinity, Infinity, Infinity);
1620
+ this._needsUpdate = true;
1621
+ return;
1622
+ }
1623
+ this._boundary.copy(box3);
1624
+ this._boundary.clampPoint(this._targetEnd, this._targetEnd);
1625
+ this._needsUpdate = true;
1626
+ }
1627
+ /**
1628
+ * Set (or unset) the current viewport.
1629
+ * Set this when you want to use renderer viewport and .dollyToCursor feature at the same time.
1630
+ * @param viewportOrX
1631
+ * @param y
1632
+ * @param width
1633
+ * @param height
1634
+ * @category Methods
1635
+ */
1636
+ setViewport(viewportOrX, y, width, height) {
1637
+ if (viewportOrX === null) { // null
1638
+ this._viewport = null;
1639
+ return;
1640
+ }
1641
+ this._viewport = this._viewport || new Vector4();
1642
+ if (typeof viewportOrX === 'number') { // number
1643
+ this._viewport.set(viewportOrX, y, width, height);
1644
+ }
1645
+ else { // Vector4
1646
+ this._viewport.copy(viewportOrX);
1647
+ }
1648
+ }
1649
+ /**
1650
+ * Calculate the distance to fit the box.
1651
+ * @param width box width
1652
+ * @param height box height
1653
+ * @param depth box depth
1654
+ * @returns distance
1655
+ * @category Methods
1656
+ */
1657
+ getDistanceToFitBox(width, height, depth, cover = false) {
1658
+ if (notSupportedInOrthographicCamera(this._camera, 'getDistanceToFitBox'))
1659
+ return this._spherical.radius;
1660
+ const boundingRectAspect = width / height;
1661
+ const fov = this._camera.getEffectiveFOV() * DEG2RAD;
1662
+ const aspect = this._camera.aspect;
1663
+ const heightToFit = (cover ? boundingRectAspect > aspect : boundingRectAspect < aspect) ? height : width / aspect;
1664
+ return heightToFit * 0.5 / Math.tan(fov * 0.5) + depth * 0.5;
1665
+ }
1666
+ /**
1667
+ * Calculate the distance to fit the sphere.
1668
+ * @param radius sphere radius
1669
+ * @returns distance
1670
+ * @category Methods
1671
+ */
1672
+ getDistanceToFitSphere(radius) {
1673
+ if (notSupportedInOrthographicCamera(this._camera, 'getDistanceToFitSphere'))
1674
+ return this._spherical.radius;
1675
+ // https://stackoverflow.com/a/44849975
1676
+ const vFOV = this._camera.getEffectiveFOV() * DEG2RAD;
1677
+ const hFOV = Math.atan(Math.tan(vFOV * 0.5) * this._camera.aspect) * 2;
1678
+ const fov = 1 < this._camera.aspect ? vFOV : hFOV;
1679
+ return radius / (Math.sin(fov * 0.5));
1680
+ }
1681
+ /**
1682
+ * Returns the orbit center position, where the camera looking at.
1683
+ * @param out The receiving Vector3 instance to copy the result
1684
+ * @param receiveEndValue Whether receive the transition end coords or current. default is `true`
1685
+ * @category Methods
1686
+ */
1687
+ getTarget(out, receiveEndValue = true) {
1688
+ const _out = !!out && out.isVector3 ? out : new Vector3();
1689
+ return _out.copy(receiveEndValue ? this._targetEnd : this._target);
1690
+ }
1691
+ /**
1692
+ * Returns the camera position.
1693
+ * @param out The receiving Vector3 instance to copy the result
1694
+ * @param receiveEndValue Whether receive the transition end coords or current. default is `true`
1695
+ * @category Methods
1696
+ */
1697
+ getPosition(out, receiveEndValue = true) {
1698
+ const _out = !!out && out.isVector3 ? out : new Vector3();
1699
+ return _out.setFromSpherical(receiveEndValue ? this._sphericalEnd : this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(receiveEndValue ? this._targetEnd : this._target);
1700
+ }
1701
+ /**
1702
+ * Returns the spherical coordinates of the orbit.
1703
+ * @param out The receiving Spherical instance to copy the result
1704
+ * @param receiveEndValue Whether receive the transition end coords or current. default is `true`
1705
+ * @category Methods
1706
+ */
1707
+ getSpherical(out, receiveEndValue = true) {
1708
+ const _out = !!out && out instanceof Spherical ? out : new Spherical();
1709
+ return _out.copy(receiveEndValue ? this._sphericalEnd : this._spherical);
1710
+ }
1711
+ /**
1712
+ * Returns the focal offset, which is how much the camera appears to be translated in screen parallel coordinates.
1713
+ * @param out The receiving Vector3 instance to copy the result
1714
+ * @param receiveEndValue Whether receive the transition end coords or current. default is `true`
1715
+ * @category Methods
1716
+ */
1717
+ getFocalOffset(out, receiveEndValue = true) {
1718
+ const _out = !!out && out.isVector3 ? out : new Vector3();
1719
+ return _out.copy(receiveEndValue ? this._focalOffsetEnd : this._focalOffset);
1720
+ }
1721
+ /**
1722
+ * Normalize camera azimuth angle rotation between 0 and 360 degrees.
1723
+ * @category Methods
1724
+ */
1725
+ normalizeRotations() {
1726
+ this._sphericalEnd.theta = this._sphericalEnd.theta % PI_2;
1727
+ if (this._sphericalEnd.theta < 0)
1728
+ this._sphericalEnd.theta += PI_2;
1729
+ this._spherical.theta += PI_2 * Math.round((this._sphericalEnd.theta - this._spherical.theta) / PI_2);
1730
+ }
1731
+ listen(camera) {
1732
+ this._camera = camera;
1733
+ // this.dragStartPosition = new Vector2();
1734
+ // this.lastDragPosition = new Vector2();
1735
+ // this.dollyStart = new Vector2();
1736
+ this._yAxisUpSpace = new Quaternion().setFromUnitVectors(this._camera.up, _AXIS_Y);
1737
+ this._yAxisUpSpaceInverse = this._yAxisUpSpace.clone().invert();
1738
+ // the location
1739
+ this._targetEnd = this._target.clone();
1740
+ this._focalOffsetEnd = this._focalOffset.clone();
1741
+ // rotation
1742
+ this._spherical = new Spherical().setFromVector3(_v3A.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace));
1743
+ this._sphericalEnd = this._spherical.clone();
1744
+ this._lastDistance = this._spherical.radius;
1745
+ this._zoom = this._camera.zoom;
1746
+ this._zoomEnd = this._zoom;
1747
+ this._lastZoom = this._zoom;
1748
+ // collisionTest uses nearPlane.s
1749
+ this._updateNearPlaneCorners();
1750
+ // Target cannot move outside of this box
1751
+ this._boundary = new Box3(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(Infinity, Infinity, Infinity));
1752
+ // reset
1753
+ this._cameraUp0 = this._camera.up.clone();
1754
+ this._target0 = this._target.clone();
1755
+ this._position0 = this._camera.position.clone();
1756
+ this._zoom0 = this._zoom;
1757
+ this._focalOffset0 = this._focalOffset.clone();
1758
+ // configs
1759
+ this.mouseButtons = {
1760
+ left: ACTION.ROTATE,
1761
+ middle: ACTION.DOLLY,
1762
+ right: ACTION.TRUCK,
1763
+ wheel: isPerspectiveCamera(this._camera) ? ACTION.DOLLY :
1764
+ isOrthographicCamera(this._camera) ? ACTION.ZOOM :
1765
+ ACTION.NONE,
1766
+ };
1767
+ this.touches = {
1768
+ one: ACTION.TOUCH_ROTATE,
1769
+ two: isPerspectiveCamera(this._camera) ? ACTION.TOUCH_DOLLY_TRUCK :
1770
+ isOrthographicCamera(this._camera) ? ACTION.TOUCH_ZOOM_TRUCK :
1771
+ ACTION.NONE,
1772
+ three: ACTION.TOUCH_TRUCK,
1773
+ };
1774
+ }
1775
+ /**
1776
+ * Reset all rotation and position to defaults.
1777
+ * @param enableTransition
1778
+ * @category Methods
1779
+ */
1780
+ reset(enableTransition = false) {
1781
+ if (!approxEquals(this._camera.up.x, this._cameraUp0.x) ||
1782
+ !approxEquals(this._camera.up.y, this._cameraUp0.y) ||
1783
+ !approxEquals(this._camera.up.z, this._cameraUp0.z)) {
1784
+ this._camera.up.copy(this._cameraUp0);
1785
+ const position = this.getPosition(_v3A);
1786
+ this.updateCameraUp();
1787
+ this.setPosition(position.x, position.y, position.z);
1788
+ }
1789
+ const promises = [
1790
+ this.setLookAt(this._position0.x, this._position0.y, this._position0.z, this._target0.x, this._target0.y, this._target0.z, enableTransition),
1791
+ this.setFocalOffset(this._focalOffset0.x, this._focalOffset0.y, this._focalOffset0.z, enableTransition),
1792
+ this.zoomTo(this._zoom0, enableTransition),
1793
+ ];
1794
+ return Promise.all(promises);
1795
+ }
1796
+ /**
1797
+ * Set current camera position as the default position.
1798
+ * @category Methods
1799
+ */
1800
+ saveState() {
1801
+ this._cameraUp0.copy(this._camera.up);
1802
+ this.getTarget(this._target0);
1803
+ this.getPosition(this._position0);
1804
+ this._zoom0 = this._zoom;
1805
+ this._focalOffset0.copy(this._focalOffset);
1806
+ }
1807
+ /**
1808
+ * Sync camera-up direction.
1809
+ * When camera-up vector is changed, `.updateCameraUp()` must be called.
1810
+ * @category Methods
1811
+ */
1812
+ updateCameraUp() {
1813
+ this._yAxisUpSpace.setFromUnitVectors(this._camera.up, _AXIS_Y);
1814
+ this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert();
1815
+ }
1816
+ /**
1817
+ * Apply current camera-up direction to the camera.
1818
+ * The orbit system will be re-initialized with the current position.
1819
+ * @category Methods
1820
+ */
1821
+ applyCameraUp() {
1822
+ const cameraDirection = _v3A.subVectors(this._target, this._camera.position).normalize();
1823
+ // So first find the vector off to the side, orthogonal to both this.object.up and
1824
+ // the "view" vector.
1825
+ const side = _v3B.crossVectors(cameraDirection, this._camera.up);
1826
+ // Then find the vector orthogonal to both this "side" vector and the "view" vector.
1827
+ // This vector will be the new "up" vector.
1828
+ this._camera.up.crossVectors(side, cameraDirection).normalize();
1829
+ this._camera.updateMatrixWorld();
1830
+ const position = this.getPosition(_v3A);
1831
+ this.updateCameraUp();
1832
+ this.setPosition(position.x, position.y, position.z);
1833
+ }
1834
+ /**
1835
+ * Update camera position and directions.
1836
+ * This should be called in your tick loop every time, and returns true if re-rendering is needed.
1837
+ * @param delta
1838
+ * @returns updated
1839
+ * @category Methods
1840
+ */
1841
+ update(delta) {
1842
+ const deltaTheta = this._sphericalEnd.theta - this._spherical.theta;
1843
+ const deltaPhi = this._sphericalEnd.phi - this._spherical.phi;
1844
+ const deltaRadius = this._sphericalEnd.radius - this._spherical.radius;
1845
+ const deltaTarget = _deltaTarget.subVectors(this._targetEnd, this._target);
1846
+ const deltaOffset = _deltaOffset.subVectors(this._focalOffsetEnd, this._focalOffset);
1847
+ const deltaZoom = this._zoomEnd - this._zoom;
1848
+ // update theta
1849
+ if (approxZero(deltaTheta)) {
1850
+ this._thetaVelocity.value = 0;
1851
+ this._spherical.theta = this._sphericalEnd.theta;
1852
+ }
1853
+ else {
1854
+ const smoothTime = this._isUserControllingRotate ? this.draggingSmoothTime : this.smoothTime;
1855
+ this._spherical.theta = smoothDamp(this._spherical.theta, this._sphericalEnd.theta, this._thetaVelocity, smoothTime, Infinity, delta);
1856
+ this._needsUpdate = true;
1857
+ }
1858
+ // update phi
1859
+ if (approxZero(deltaPhi)) {
1860
+ this._phiVelocity.value = 0;
1861
+ this._spherical.phi = this._sphericalEnd.phi;
1862
+ }
1863
+ else {
1864
+ const smoothTime = this._isUserControllingRotate ? this.draggingSmoothTime : this.smoothTime;
1865
+ this._spherical.phi = smoothDamp(this._spherical.phi, this._sphericalEnd.phi, this._phiVelocity, smoothTime, Infinity, delta);
1866
+ this._needsUpdate = true;
1867
+ }
1868
+ // update distance
1869
+ if (approxZero(deltaRadius)) {
1870
+ this._radiusVelocity.value = 0;
1871
+ this._spherical.radius = this._sphericalEnd.radius;
1872
+ }
1873
+ else {
1874
+ const smoothTime = this._isUserControllingDolly ? this.draggingSmoothTime : this.smoothTime;
1875
+ this._spherical.radius = smoothDamp(this._spherical.radius, this._sphericalEnd.radius, this._radiusVelocity, smoothTime, this.maxSpeed, delta);
1876
+ this._needsUpdate = true;
1877
+ }
1878
+ // update target position
1879
+ if (approxZero(deltaTarget.x) && approxZero(deltaTarget.y) && approxZero(deltaTarget.z)) {
1880
+ this._targetVelocity.set(0, 0, 0);
1881
+ this._target.copy(this._targetEnd);
1882
+ }
1883
+ else {
1884
+ const smoothTime = this._isUserControllingTruck ? this.draggingSmoothTime : this.smoothTime;
1885
+ smoothDampVec3(this._target, this._targetEnd, this._targetVelocity, smoothTime, this.maxSpeed, delta, this._target);
1886
+ this._needsUpdate = true;
1887
+ }
1888
+ // update focalOffset
1889
+ if (approxZero(deltaOffset.x) && approxZero(deltaOffset.y) && approxZero(deltaOffset.z)) {
1890
+ this._focalOffsetVelocity.set(0, 0, 0);
1891
+ this._focalOffset.copy(this._focalOffsetEnd);
1892
+ }
1893
+ else {
1894
+ const smoothTime = this._isUserControllingOffset ? this.draggingSmoothTime : this.smoothTime;
1895
+ smoothDampVec3(this._focalOffset, this._focalOffsetEnd, this._focalOffsetVelocity, smoothTime, this.maxSpeed, delta, this._focalOffset);
1896
+ this._needsUpdate = true;
1897
+ }
1898
+ // update zoom
1899
+ if (approxZero(deltaZoom)) {
1900
+ this._zoomVelocity.value = 0;
1901
+ this._zoom = this._zoomEnd;
1902
+ }
1903
+ else {
1904
+ const smoothTime = this._isUserControllingZoom ? this.draggingSmoothTime : this.smoothTime;
1905
+ this._zoom = smoothDamp(this._zoom, this._zoomEnd, this._zoomVelocity, smoothTime, Infinity, delta);
1906
+ }
1907
+ if (this.dollyToCursor) {
1908
+ if (isPerspectiveCamera(this._camera) && this._changedDolly !== 0) {
1909
+ const dollyControlAmount = this._spherical.radius - this._lastDistance;
1910
+ const camera = this._camera;
1911
+ const cameraDirection = this._getCameraDirection(_cameraDirection);
1912
+ const planeX = _v3A.copy(cameraDirection).cross(camera.up).normalize();
1913
+ if (planeX.lengthSq() === 0)
1914
+ planeX.x = 1.0;
1915
+ const planeY = _v3B.crossVectors(planeX, cameraDirection);
1916
+ const worldToScreen = this._sphericalEnd.radius * Math.tan(camera.getEffectiveFOV() * DEG2RAD * 0.5);
1917
+ const prevRadius = this._sphericalEnd.radius - dollyControlAmount;
1918
+ const lerpRatio = (prevRadius - this._sphericalEnd.radius) / this._sphericalEnd.radius;
1919
+ const cursor = _v3C.copy(this._targetEnd)
1920
+ .add(planeX.multiplyScalar(this._dollyControlCoord.x * worldToScreen * camera.aspect))
1921
+ .add(planeY.multiplyScalar(this._dollyControlCoord.y * worldToScreen));
1922
+ const newTargetEnd = _v3A.copy(this._targetEnd).lerp(cursor, lerpRatio);
1923
+ const isMin = this._lastDollyDirection === DOLLY_DIRECTION.IN && this._spherical.radius <= this.minDistance;
1924
+ const isMax = this._lastDollyDirection === DOLLY_DIRECTION.OUT && this.maxDistance <= this._spherical.radius;
1925
+ if (this.infinityDolly && (isMin || isMax)) {
1926
+ this._sphericalEnd.radius -= dollyControlAmount;
1927
+ this._spherical.radius -= dollyControlAmount;
1928
+ const dollyAmount = _v3B.copy(cameraDirection).multiplyScalar(-dollyControlAmount);
1929
+ newTargetEnd.add(dollyAmount);
1930
+ }
1931
+ // target position may be moved beyond boundary.
1932
+ this._boundary.clampPoint(newTargetEnd, newTargetEnd);
1933
+ const targetEndDiff = _v3B.subVectors(newTargetEnd, this._targetEnd);
1934
+ this._targetEnd.copy(newTargetEnd);
1935
+ this._target.add(targetEndDiff);
1936
+ this._changedDolly -= dollyControlAmount;
1937
+ if (approxZero(this._changedDolly))
1938
+ this._changedDolly = 0;
1939
+ }
1940
+ else if (isOrthographicCamera(this._camera) && this._changedZoom !== 0) {
1941
+ const dollyControlAmount = this._zoom - this._lastZoom;
1942
+ const camera = this._camera;
1943
+ const worldCursorPosition = _v3A.set(this._dollyControlCoord.x, this._dollyControlCoord.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera);
1944
+ const quaternion = _v3B.set(0, 0, -1).applyQuaternion(camera.quaternion);
1945
+ const cursor = _v3C.copy(worldCursorPosition).add(quaternion.multiplyScalar(-worldCursorPosition.dot(camera.up)));
1946
+ const prevZoom = this._zoom - dollyControlAmount;
1947
+ const lerpRatio = -(prevZoom - this._zoom) / this._zoom;
1948
+ // find the "distance" (aka plane constant in three.js) of Plane
1949
+ // from a given position (this._targetEnd) and normal vector (cameraDirection)
1950
+ // https://www.maplesoft.com/support/help/maple/view.aspx?path=MathApps%2FEquationOfAPlaneNormal#bkmrk0
1951
+ const cameraDirection = this._getCameraDirection(_cameraDirection);
1952
+ const prevPlaneConstant = this._targetEnd.dot(cameraDirection);
1953
+ const newTargetEnd = _v3A.copy(this._targetEnd).lerp(cursor, lerpRatio);
1954
+ const newPlaneConstant = newTargetEnd.dot(cameraDirection);
1955
+ // Pull back the camera depth that has moved, to be the camera stationary as zoom
1956
+ const pullBack = cameraDirection.multiplyScalar(newPlaneConstant - prevPlaneConstant);
1957
+ newTargetEnd.sub(pullBack);
1958
+ // target position may be moved beyond boundary.
1959
+ this._boundary.clampPoint(newTargetEnd, newTargetEnd);
1960
+ const targetEndDiff = _v3B.subVectors(newTargetEnd, this._targetEnd);
1961
+ this._targetEnd.copy(newTargetEnd);
1962
+ this._target.add(targetEndDiff);
1963
+ // this._target.copy( this._targetEnd );
1964
+ this._changedZoom -= dollyControlAmount;
1965
+ if (approxZero(this._changedZoom))
1966
+ this._changedZoom = 0;
1967
+ }
1968
+ }
1969
+ if (this._camera.zoom !== this._zoom) {
1970
+ this._camera.zoom = this._zoom;
1971
+ this._camera.updateProjectionMatrix();
1972
+ this._updateNearPlaneCorners();
1973
+ this._needsUpdate = true;
1974
+ }
1975
+ this._dragNeedsUpdate = true;
1976
+ // collision detection
1977
+ const maxDistance = this._collisionTest();
1978
+ this._spherical.radius = Math.min(this._spherical.radius, maxDistance);
1979
+ // decompose spherical to the camera position
1980
+ this._spherical.makeSafe();
1981
+ this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target);
1982
+ this._camera.lookAt(this._target);
1983
+ // set offset after the orbit movement
1984
+ const affectOffset = !approxZero(this._focalOffset.x) ||
1985
+ !approxZero(this._focalOffset.y) ||
1986
+ !approxZero(this._focalOffset.z);
1987
+ if (affectOffset) {
1988
+ this._camera.updateMatrixWorld();
1989
+ _xColumn.setFromMatrixColumn(this._camera.matrix, 0);
1990
+ _yColumn.setFromMatrixColumn(this._camera.matrix, 1);
1991
+ _zColumn.setFromMatrixColumn(this._camera.matrix, 2);
1992
+ _xColumn.multiplyScalar(this._focalOffset.x);
1993
+ _yColumn.multiplyScalar(-this._focalOffset.y);
1994
+ _zColumn.multiplyScalar(this._focalOffset.z); // notice: z-offset will not affect in Orthographic.
1995
+ _v3A.copy(_xColumn).add(_yColumn).add(_zColumn);
1996
+ this._camera.position.add(_v3A);
1997
+ }
1998
+ if (this._boundaryEnclosesCamera) {
1999
+ this._encloseToBoundary(this._camera.position.copy(this._target), _v3A.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse), 1.0);
2000
+ }
2001
+ const updated = this._needsUpdate;
2002
+ if (updated && !this._updatedLastTime) {
2003
+ this._hasRested = false;
2004
+ this.dispatchEvent({ type: 'wake' });
2005
+ this.dispatchEvent({ type: 'update' });
2006
+ }
2007
+ else if (updated) {
2008
+ this.dispatchEvent({ type: 'update' });
2009
+ if (approxZero(deltaTheta, this.restThreshold) &&
2010
+ approxZero(deltaPhi, this.restThreshold) &&
2011
+ approxZero(deltaRadius, this.restThreshold) &&
2012
+ approxZero(deltaTarget.x, this.restThreshold) &&
2013
+ approxZero(deltaTarget.y, this.restThreshold) &&
2014
+ approxZero(deltaTarget.z, this.restThreshold) &&
2015
+ approxZero(deltaOffset.x, this.restThreshold) &&
2016
+ approxZero(deltaOffset.y, this.restThreshold) &&
2017
+ approxZero(deltaOffset.z, this.restThreshold) &&
2018
+ approxZero(deltaZoom, this.restThreshold) &&
2019
+ !this._hasRested) {
2020
+ this._hasRested = true;
2021
+ this.dispatchEvent({ type: 'rest' });
2022
+ }
2023
+ }
2024
+ else if (!updated && this._updatedLastTime) {
2025
+ this.dispatchEvent({ type: 'sleep' });
2026
+ }
2027
+ this._lastDistance = this._spherical.radius;
2028
+ this._lastZoom = this._zoom;
2029
+ this._updatedLastTime = updated;
2030
+ this._needsUpdate = false;
2031
+ return updated;
2032
+ }
2033
+ /**
2034
+ * Get all state in JSON string
2035
+ * @category Methods
2036
+ */
2037
+ toJSON() {
2038
+ return JSON.stringify({
2039
+ enabled: this._enabled,
2040
+ minDistance: this.minDistance,
2041
+ maxDistance: infinityToMaxNumber(this.maxDistance),
2042
+ minZoom: this.minZoom,
2043
+ maxZoom: infinityToMaxNumber(this.maxZoom),
2044
+ minPolarAngle: this.minPolarAngle,
2045
+ maxPolarAngle: infinityToMaxNumber(this.maxPolarAngle),
2046
+ minAzimuthAngle: infinityToMaxNumber(this.minAzimuthAngle),
2047
+ maxAzimuthAngle: infinityToMaxNumber(this.maxAzimuthAngle),
2048
+ smoothTime: this.smoothTime,
2049
+ draggingSmoothTime: this.draggingSmoothTime,
2050
+ dollySpeed: this.dollySpeed,
2051
+ truckSpeed: this.truckSpeed,
2052
+ dollyToCursor: this.dollyToCursor,
2053
+ verticalDragToForward: this.verticalDragToForward,
2054
+ target: this._targetEnd.toArray(),
2055
+ position: _v3A.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),
2056
+ zoom: this._zoomEnd,
2057
+ focalOffset: this._focalOffsetEnd.toArray(),
2058
+ target0: this._target0.toArray(),
2059
+ position0: this._position0.toArray(),
2060
+ zoom0: this._zoom0,
2061
+ focalOffset0: this._focalOffset0.toArray(),
2062
+ });
2063
+ }
2064
+ /**
2065
+ * Reproduce the control state with JSON. enableTransition is where anim or not in a boolean.
2066
+ * @param json
2067
+ * @param enableTransition
2068
+ * @category Methods
2069
+ */
2070
+ fromJSON(json, enableTransition = false) {
2071
+ const obj = JSON.parse(json);
2072
+ this.enabled = obj.enabled;
2073
+ this.minDistance = obj.minDistance;
2074
+ this.maxDistance = maxNumberToInfinity(obj.maxDistance);
2075
+ this.minZoom = obj.minZoom;
2076
+ this.maxZoom = maxNumberToInfinity(obj.maxZoom);
2077
+ this.minPolarAngle = obj.minPolarAngle;
2078
+ this.maxPolarAngle = maxNumberToInfinity(obj.maxPolarAngle);
2079
+ this.minAzimuthAngle = maxNumberToInfinity(obj.minAzimuthAngle);
2080
+ this.maxAzimuthAngle = maxNumberToInfinity(obj.maxAzimuthAngle);
2081
+ this.smoothTime = obj.smoothTime;
2082
+ this.draggingSmoothTime = obj.draggingSmoothTime;
2083
+ this.dollySpeed = obj.dollySpeed;
2084
+ this.truckSpeed = obj.truckSpeed;
2085
+ this.dollyToCursor = obj.dollyToCursor;
2086
+ this.verticalDragToForward = obj.verticalDragToForward;
2087
+ this._target0.fromArray(obj.target0);
2088
+ this._position0.fromArray(obj.position0);
2089
+ this._zoom0 = obj.zoom0;
2090
+ this._focalOffset0.fromArray(obj.focalOffset0);
2091
+ this.moveTo(obj.target[0], obj.target[1], obj.target[2], enableTransition);
2092
+ _sphericalA.setFromVector3(_v3A.fromArray(obj.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace));
2093
+ this.rotateTo(_sphericalA.theta, _sphericalA.phi, enableTransition);
2094
+ this.dollyTo(_sphericalA.radius, enableTransition);
2095
+ this.zoomTo(obj.zoom, enableTransition);
2096
+ this.setFocalOffset(obj.focalOffset[0], obj.focalOffset[1], obj.focalOffset[2], enableTransition);
2097
+ this._needsUpdate = true;
2098
+ }
2099
+ /**
2100
+ * Attach all internal event handlers to enable drag control.
2101
+ * @category Methods
2102
+ */
2103
+ connect(domElement) {
2104
+ if (this._domElement) {
2105
+ console.warn('camera-controls is already connected.');
2106
+ return;
2107
+ }
2108
+ domElement.setAttribute('data-camera-controls-version', VERSION);
2109
+ this._addAllEventListeners(domElement);
2110
+ this._getClientRect(this._elementRect);
2111
+ // this.update(0);
2112
+ }
2113
+ /**
2114
+ * Detach all internal event handlers to disable drag control.
2115
+ */
2116
+ disconnect() {
2117
+ this.cancel();
2118
+ this._removeAllEventListeners();
2119
+ if (this._domElement) {
2120
+ this._domElement.removeAttribute('data-camera-controls-version');
2121
+ //@ts-ignore
2122
+ this._domElement = undefined;
2123
+ }
2124
+ }
2125
+ /**
2126
+ * Dispose the cameraControls instance itself, remove all eventListeners.
2127
+ * @category Methods
2128
+ */
2129
+ dispose() {
2130
+ // remove all user event listeners
2131
+ this.removeAllEventListeners();
2132
+ // remove all internal event listeners
2133
+ this.disconnect();
2134
+ }
2135
+ // it's okay to expose public though
2136
+ _getTargetDirection(out) {
2137
+ // divide by distance to normalize, lighter than `Vector3.prototype.normalize()`
2138
+ return out.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse);
2139
+ }
2140
+ // it's okay to expose public though
2141
+ _getCameraDirection(out) {
2142
+ return this._getTargetDirection(out).negate();
2143
+ }
2144
+ _findPointerById(pointerId) {
2145
+ return this._activePointers.find((activePointer) => activePointer.pointerId === pointerId);
2146
+ }
2147
+ _findPointerByMouseButton(mouseButton) {
2148
+ return this._activePointers.find((activePointer) => activePointer.mouseButton === mouseButton);
2149
+ }
2150
+ _disposePointer(pointer) {
2151
+ this._activePointers.splice(this._activePointers.indexOf(pointer), 1);
2152
+ }
2153
+ _encloseToBoundary(position, offset, friction) {
2154
+ const offsetLength2 = offset.lengthSq();
2155
+ if (offsetLength2 === 0.0) { // sanity check
2156
+ return position;
2157
+ }
2158
+ // See: https://twitter.com/FMS_Cat/status/1106508958640988161
2159
+ const newTarget = _v3B.copy(offset).add(position); // target
2160
+ const clampedTarget = this._boundary.clampPoint(newTarget, _v3C); // clamped target
2161
+ const deltaClampedTarget = clampedTarget.sub(newTarget); // newTarget -> clampedTarget
2162
+ const deltaClampedTargetLength2 = deltaClampedTarget.lengthSq(); // squared length of deltaClampedTarget
2163
+ if (deltaClampedTargetLength2 === 0.0) { // when the position doesn't have to be clamped
2164
+ return position.add(offset);
2165
+ }
2166
+ else if (deltaClampedTargetLength2 === offsetLength2) { // when the position is completely stuck
2167
+ return position;
2168
+ }
2169
+ else if (friction === 0.0) {
2170
+ return position.add(offset).add(deltaClampedTarget);
2171
+ }
2172
+ else {
2173
+ const offsetFactor = 1.0 + friction * deltaClampedTargetLength2 / offset.dot(deltaClampedTarget);
2174
+ return position
2175
+ .add(_v3B.copy(offset).multiplyScalar(offsetFactor))
2176
+ .add(deltaClampedTarget.multiplyScalar(1.0 - friction));
2177
+ }
2178
+ }
2179
+ _updateNearPlaneCorners() {
2180
+ if (isPerspectiveCamera(this._camera)) {
2181
+ const camera = this._camera;
2182
+ const near = camera.near;
2183
+ const fov = camera.getEffectiveFOV() * DEG2RAD;
2184
+ const heightHalf = Math.tan(fov * 0.5) * near; // near plain half height
2185
+ const widthHalf = heightHalf * camera.aspect; // near plain half width
2186
+ this._nearPlaneCorners[0].set(-widthHalf, -heightHalf, 0);
2187
+ this._nearPlaneCorners[1].set(widthHalf, -heightHalf, 0);
2188
+ this._nearPlaneCorners[2].set(widthHalf, heightHalf, 0);
2189
+ this._nearPlaneCorners[3].set(-widthHalf, heightHalf, 0);
2190
+ }
2191
+ else if (isOrthographicCamera(this._camera)) {
2192
+ const camera = this._camera;
2193
+ const zoomInv = 1 / camera.zoom;
2194
+ const left = camera.left * zoomInv;
2195
+ const right = camera.right * zoomInv;
2196
+ const top = camera.top * zoomInv;
2197
+ const bottom = camera.bottom * zoomInv;
2198
+ this._nearPlaneCorners[0].set(left, top, 0);
2199
+ this._nearPlaneCorners[1].set(right, top, 0);
2200
+ this._nearPlaneCorners[2].set(right, bottom, 0);
2201
+ this._nearPlaneCorners[3].set(left, bottom, 0);
2202
+ }
2203
+ }
2204
+ // lateUpdate
2205
+ _collisionTest() {
2206
+ let distance = Infinity;
2207
+ const hasCollider = this.colliderMeshes.length >= 1;
2208
+ if (!hasCollider)
2209
+ return distance;
2210
+ if (notSupportedInOrthographicCamera(this._camera, '_collisionTest'))
2211
+ return distance;
2212
+ const rayDirection = this._getTargetDirection(_cameraDirection);
2213
+ _rotationMatrix.lookAt(_ORIGIN, rayDirection, this._camera.up);
2214
+ for (let i = 0; i < 4; i++) {
2215
+ const nearPlaneCorner = _v3B.copy(this._nearPlaneCorners[i]);
2216
+ nearPlaneCorner.applyMatrix4(_rotationMatrix);
2217
+ const origin = _v3C.addVectors(this._target, nearPlaneCorner);
2218
+ _raycaster.set(origin, rayDirection);
2219
+ _raycaster.far = this._spherical.radius + 1;
2220
+ const intersects = _raycaster.intersectObjects(this.colliderMeshes);
2221
+ if (intersects.length !== 0 && intersects[0].distance < distance) {
2222
+ distance = intersects[0].distance;
2223
+ }
2224
+ }
2225
+ return distance;
2226
+ }
2227
+ /**
2228
+ * Get its client rect and package into given `DOMRect` .
2229
+ */
2230
+ _getClientRect(target) {
2231
+ if (!this._domElement)
2232
+ return;
2233
+ const rect = this._domElement.getBoundingClientRect();
2234
+ target.x = rect.left;
2235
+ target.y = rect.top;
2236
+ if (this._viewport) {
2237
+ target.x += this._viewport.x;
2238
+ target.y += rect.height - this._viewport.w - this._viewport.y;
2239
+ target.width = this._viewport.z;
2240
+ target.height = this._viewport.w;
2241
+ }
2242
+ else {
2243
+ target.width = rect.width;
2244
+ target.height = rect.height;
2245
+ }
2246
+ return target;
2247
+ }
2248
+ _createOnRestPromise(resolveImmediately) {
2249
+ if (resolveImmediately)
2250
+ return Promise.resolve();
2251
+ this._hasRested = false;
2252
+ this.dispatchEvent({ type: 'transitionstart' });
2253
+ return new Promise((resolve) => {
2254
+ const onResolve = () => {
2255
+ this.removeEventListener('rest', onResolve);
2256
+ resolve();
2257
+ };
2258
+ this.addEventListener('rest', onResolve);
2259
+ });
2260
+ }
2261
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2262
+ _addAllEventListeners(_domElement) { }
2263
+ _removeAllEventListeners() { }
2264
+ /**
2265
+ * backward compatible
2266
+ * @deprecated use smoothTime (in seconds) instead
2267
+ * @category Properties
2268
+ */
2269
+ get dampingFactor() {
2270
+ console.warn('.dampingFactor has been deprecated. use smoothTime (in seconds) instead.');
2271
+ return 0;
2272
+ }
2273
+ /**
2274
+ * backward compatible
2275
+ * @deprecated use smoothTime (in seconds) instead
2276
+ * @category Properties
2277
+ */
2278
+ set dampingFactor(_) {
2279
+ console.warn('.dampingFactor has been deprecated. use smoothTime (in seconds) instead.');
2280
+ }
2281
+ /**
2282
+ * backward compatible
2283
+ * @deprecated use draggingSmoothTime (in seconds) instead
2284
+ * @category Properties
2285
+ */
2286
+ get draggingDampingFactor() {
2287
+ console.warn('.draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.');
2288
+ return 0;
2289
+ }
2290
+ /**
2291
+ * backward compatible
2292
+ * @deprecated use draggingSmoothTime (in seconds) instead
2293
+ * @category Properties
2294
+ */
2295
+ set draggingDampingFactor(_) {
2296
+ console.warn('.draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.');
2297
+ }
2298
+ static createBoundingSphere(object3d, out = new Sphere()) {
2299
+ const boundingSphere = out;
2300
+ const center = boundingSphere.center;
2301
+ _box3A.makeEmpty();
2302
+ // find the center
2303
+ object3d.traverseVisible((object) => {
2304
+ //@ts-ignore
2305
+ if (!object.isMesh)
2306
+ return;
2307
+ _box3A.expandByObject(object);
2308
+ });
2309
+ _box3A.getCenter(center);
2310
+ // find the radius
2311
+ let maxRadiusSq = 0;
2312
+ object3d.traverseVisible((object) => {
2313
+ //@ts-ignore
2314
+ if (!object.isMesh)
2315
+ return;
2316
+ const mesh = object;
2317
+ //@ts-ignore
2318
+ const geometry = mesh.geometry.clone();
2319
+ geometry.applyMatrix4(mesh.matrixWorld);
2320
+ const bufferGeometry = geometry;
2321
+ const position = bufferGeometry.attributes.position;
2322
+ for (let i = 0, l = position.count; i < l; i++) {
2323
+ _v3A.fromBufferAttribute(position, i);
2324
+ maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_v3A));
2325
+ }
2326
+ });
2327
+ boundingSphere.radius = Math.sqrt(maxRadiusSq);
2328
+ return boundingSphere;
2329
+ }
2330
+ }
2331
+ export { CameraControls };
2332
+ //# sourceMappingURL=CameraControls.js.map