@antv/g 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (491) hide show
  1. package/dist/index.umd.js +30 -0
  2. package/es/AbstractRenderer.d.ts +26 -0
  3. package/es/AbstractRenderer.js +42 -0
  4. package/es/Canvas.d.ts +96 -0
  5. package/es/Canvas.js +401 -0
  6. package/{dist → es}/DisplayObjectPool.d.ts +7 -6
  7. package/es/DisplayObjectPool.js +27 -0
  8. package/{dist → es/camera}/Camera.d.ts +279 -271
  9. package/es/camera/Camera.js +963 -0
  10. package/{dist → es/camera}/Landmark.d.ts +28 -28
  11. package/es/camera/Landmark.js +68 -0
  12. package/es/camera/index.d.ts +2 -0
  13. package/es/camera/index.js +2 -0
  14. package/es/canvas-module.d.ts +1 -0
  15. package/es/canvas-module.js +33 -0
  16. package/{dist → es}/components/Cullable.d.ts +15 -14
  17. package/es/components/Cullable.js +36 -0
  18. package/es/components/Geometry.d.ts +13 -0
  19. package/es/components/Geometry.js +17 -0
  20. package/{dist → es}/components/Renderable.d.ts +25 -36
  21. package/es/components/Renderable.js +26 -0
  22. package/es/components/Sortable.d.ts +17 -0
  23. package/es/components/Sortable.js +24 -0
  24. package/{dist → es}/components/Transform.d.ts +28 -28
  25. package/es/components/Transform.js +70 -0
  26. package/{dist → es}/components/index.d.ts +5 -7
  27. package/es/components/index.js +5 -0
  28. package/es/display-objects/Circle.d.ts +12 -0
  29. package/es/display-objects/Circle.js +26 -0
  30. package/es/display-objects/CustomElement.d.ts +25 -0
  31. package/es/display-objects/CustomElement.js +82 -0
  32. package/es/display-objects/DisplayObject.d.ts +258 -0
  33. package/es/display-objects/DisplayObject.js +857 -0
  34. package/es/display-objects/Ellipse.d.ts +14 -0
  35. package/es/display-objects/Ellipse.js +27 -0
  36. package/es/display-objects/Group.d.ts +6 -0
  37. package/es/display-objects/Group.js +27 -0
  38. package/es/display-objects/HTML.d.ts +36 -0
  39. package/es/display-objects/HTML.js +96 -0
  40. package/es/display-objects/Image.d.ts +16 -0
  41. package/es/display-objects/Image.js +25 -0
  42. package/es/display-objects/Line.d.ts +23 -0
  43. package/es/display-objects/Line.js +56 -0
  44. package/es/display-objects/Path.d.ts +47 -0
  45. package/es/display-objects/Path.js +132 -0
  46. package/es/display-objects/Polygon.d.ts +12 -0
  47. package/es/display-objects/Polygon.js +25 -0
  48. package/es/display-objects/Polyline.d.ts +21 -0
  49. package/es/display-objects/Polyline.js +75 -0
  50. package/es/display-objects/Rect.d.ts +16 -0
  51. package/es/display-objects/Rect.js +26 -0
  52. package/es/display-objects/Text.d.ts +65 -0
  53. package/es/display-objects/Text.js +61 -0
  54. package/es/display-objects/index.d.ts +13 -0
  55. package/es/display-objects/index.js +13 -0
  56. package/es/dom/Animation.d.ts +132 -0
  57. package/es/dom/Animation.js +498 -0
  58. package/es/dom/AnimationEffectTiming.d.ts +59 -0
  59. package/es/dom/AnimationEffectTiming.js +68 -0
  60. package/es/dom/AnimationEvent.d.ts +11 -0
  61. package/es/dom/AnimationEvent.js +34 -0
  62. package/es/dom/AnimationTimeline.d.ts +37 -0
  63. package/es/dom/AnimationTimeline.js +217 -0
  64. package/es/dom/CustomElementRegistry.d.ts +15 -0
  65. package/es/dom/CustomElementRegistry.js +42 -0
  66. package/es/dom/CustomEvent.d.ts +16 -0
  67. package/es/dom/CustomEvent.js +34 -0
  68. package/es/dom/Document.d.ts +59 -0
  69. package/es/dom/Document.js +167 -0
  70. package/es/dom/Element.d.ts +143 -0
  71. package/es/dom/Element.js +492 -0
  72. package/es/dom/EventTarget.d.ts +43 -0
  73. package/es/dom/EventTarget.js +161 -0
  74. package/{dist → es/dom}/FederatedEvent.d.ts +146 -102
  75. package/es/dom/FederatedEvent.js +232 -0
  76. package/{dist → es/dom}/FederatedMouseEvent.d.ts +52 -54
  77. package/es/dom/FederatedMouseEvent.js +124 -0
  78. package/{dist → es/dom}/FederatedPointerEvent.d.ts +69 -69
  79. package/es/dom/FederatedPointerEvent.js +53 -0
  80. package/{dist → es/dom}/FederatedWheelEvent.d.ts +20 -20
  81. package/es/dom/FederatedWheelEvent.js +27 -0
  82. package/es/dom/KeyframeEffect.d.ts +48 -0
  83. package/es/dom/KeyframeEffect.js +174 -0
  84. package/es/dom/KeyframeList.d.ts +2 -0
  85. package/es/dom/KeyframeList.js +176 -0
  86. package/es/dom/Node.d.ts +106 -0
  87. package/es/dom/Node.js +213 -0
  88. package/es/dom/index.d.ts +17 -0
  89. package/es/dom/index.js +17 -0
  90. package/es/dom/interfaces.d.ts +326 -0
  91. package/es/dom/interfaces.js +32 -0
  92. package/es/global-module.d.ts +2 -0
  93. package/es/global-module.js +159 -0
  94. package/es/index.d.ts +18 -0
  95. package/es/index.js +25 -0
  96. package/es/plugins/CullingPlugin.d.ts +19 -0
  97. package/es/plugins/CullingPlugin.js +80 -0
  98. package/es/plugins/DirtyCheckPlugin.d.ts +10 -0
  99. package/es/plugins/DirtyCheckPlugin.js +53 -0
  100. package/{dist → es}/plugins/EventPlugin.d.ts +26 -26
  101. package/es/plugins/EventPlugin.js +288 -0
  102. package/{dist → es}/plugins/FrustumCullingStrategy.d.ts +21 -21
  103. package/es/plugins/FrustumCullingStrategy.js +102 -0
  104. package/{dist → es}/plugins/PrepareRendererPlugin.d.ts +6 -7
  105. package/es/plugins/PrepareRendererPlugin.js +80 -0
  106. package/es/property-handlers/aabb.d.ts +2 -0
  107. package/es/property-handlers/aabb.js +135 -0
  108. package/es/property-handlers/anchor.d.ts +3 -0
  109. package/es/property-handlers/anchor.js +21 -0
  110. package/es/property-handlers/clipPath.d.ts +19 -0
  111. package/es/property-handlers/clipPath.js +36 -0
  112. package/es/property-handlers/color.d.ts +32 -0
  113. package/es/property-handlers/color.js +250 -0
  114. package/es/property-handlers/dimension.d.ts +18 -0
  115. package/es/property-handlers/dimension.js +123 -0
  116. package/es/property-handlers/filter.d.ts +9 -0
  117. package/es/property-handlers/filter.js +43 -0
  118. package/es/property-handlers/index.d.ts +17 -0
  119. package/es/property-handlers/index.js +17 -0
  120. package/es/property-handlers/interfaces.d.ts +20 -0
  121. package/es/property-handlers/interfaces.js +6 -0
  122. package/es/property-handlers/localPosition.d.ts +2 -0
  123. package/es/property-handlers/localPosition.js +9 -0
  124. package/es/property-handlers/numeric.d.ts +5 -0
  125. package/es/property-handlers/numeric.js +34 -0
  126. package/es/property-handlers/offsetDistance.d.ts +5 -0
  127. package/es/property-handlers/offsetDistance.js +20 -0
  128. package/es/property-handlers/offsetPath.d.ts +5 -0
  129. package/es/property-handlers/offsetPath.js +18 -0
  130. package/es/property-handlers/origin.d.ts +11 -0
  131. package/es/property-handlers/origin.js +68 -0
  132. package/es/property-handlers/path.d.ts +5 -0
  133. package/es/property-handlers/path.js +200 -0
  134. package/es/property-handlers/points.d.ts +6 -0
  135. package/es/property-handlers/points.js +23 -0
  136. package/es/property-handlers/transform.d.ts +45 -0
  137. package/es/property-handlers/transform.js +416 -0
  138. package/es/property-handlers/zIndex.d.ts +2 -0
  139. package/es/property-handlers/zIndex.js +17 -0
  140. package/{dist → es}/services/ContextService.d.ts +12 -10
  141. package/es/services/ContextService.js +5 -0
  142. package/es/services/EventService.d.ts +64 -0
  143. package/es/services/EventService.js +937 -0
  144. package/es/services/RenderingContext.d.ts +28 -0
  145. package/es/services/RenderingContext.js +13 -0
  146. package/{dist → es}/services/RenderingService.d.ts +51 -46
  147. package/es/services/RenderingService.js +145 -0
  148. package/es/services/SceneGraphSelector.d.ts +20 -0
  149. package/es/services/SceneGraphSelector.js +64 -0
  150. package/es/services/SceneGraphService.d.ts +146 -0
  151. package/es/services/SceneGraphService.js +805 -0
  152. package/es/services/aabb/CircleUpdater.d.ts +10 -0
  153. package/es/services/aabb/CircleUpdater.js +35 -0
  154. package/es/services/aabb/EllipseUpdater.d.ts +10 -0
  155. package/es/services/aabb/EllipseUpdater.js +37 -0
  156. package/es/services/aabb/LineUpdater.d.ts +10 -0
  157. package/es/services/aabb/LineUpdater.js +39 -0
  158. package/es/services/aabb/PathUpdater.d.ts +11 -0
  159. package/es/services/aabb/PathUpdater.js +172 -0
  160. package/es/services/aabb/PolylineUpdater.d.ts +10 -0
  161. package/es/services/aabb/PolylineUpdater.js +48 -0
  162. package/es/services/aabb/RectUpdater.d.ts +10 -0
  163. package/es/services/aabb/RectUpdater.js +55 -0
  164. package/es/services/aabb/TextUpdater.d.ts +13 -0
  165. package/es/services/aabb/TextUpdater.js +81 -0
  166. package/es/services/aabb/index.d.ts +8 -0
  167. package/es/services/aabb/index.js +8 -0
  168. package/es/services/aabb/interfaces.d.ts +16 -0
  169. package/es/services/aabb/interfaces.js +2 -0
  170. package/{dist → es}/services/index.d.ts +10 -10
  171. package/es/services/index.js +10 -0
  172. package/es/services/text/OffscreenCanvasCreator.d.ts +6 -0
  173. package/es/services/text/OffscreenCanvasCreator.js +47 -0
  174. package/{dist → es}/services/text/index.d.ts +35 -32
  175. package/es/services/text/index.js +355 -0
  176. package/{dist → es}/shapes/AABB.d.ts +33 -32
  177. package/es/shapes/AABB.js +217 -0
  178. package/{dist → es}/shapes/BoundingSphere.d.ts +8 -8
  179. package/es/shapes/BoundingSphere.js +31 -0
  180. package/{dist → es}/shapes/Frustum.d.ts +16 -16
  181. package/es/shapes/Frustum.js +79 -0
  182. package/{dist → es}/shapes/Plane.d.ts +14 -14
  183. package/es/shapes/Plane.js +42 -0
  184. package/{dist → es}/shapes/Point.d.ts +11 -7
  185. package/es/shapes/Point.js +31 -0
  186. package/es/shapes/Polygon.d.ts +9 -0
  187. package/es/shapes/Polygon.js +64 -0
  188. package/{dist → es}/shapes/Ray.d.ts +24 -24
  189. package/es/shapes/Ray.js +138 -0
  190. package/es/shapes/Rect.d.ts +12 -0
  191. package/es/shapes/Rect.js +24 -0
  192. package/es/shapes/Rectangle.d.ts +12 -0
  193. package/es/shapes/Rectangle.js +20 -0
  194. package/es/shapes/index.d.ts +8 -0
  195. package/{dist/shapes/index.d.ts → es/shapes/index.js} +8 -5
  196. package/{dist → es}/types.d.ts +219 -241
  197. package/es/types.js +17 -0
  198. package/es/utils/animation.d.ts +15 -0
  199. package/es/utils/animation.js +251 -0
  200. package/es/utils/bezier-easing.d.ts +20 -0
  201. package/es/utils/bezier-easing.js +90 -0
  202. package/{dist → es}/utils/canvas.d.ts +5 -5
  203. package/es/utils/canvas.js +15 -0
  204. package/es/utils/custom-easing.d.ts +75 -0
  205. package/es/utils/custom-easing.js +332 -0
  206. package/{dist → es}/utils/event.d.ts +11 -11
  207. package/es/utils/event.js +69 -0
  208. package/es/utils/index.d.ts +5 -0
  209. package/es/utils/index.js +5 -0
  210. package/es/utils/interpolation.d.ts +3 -0
  211. package/es/utils/interpolation.js +182 -0
  212. package/{dist → es}/utils/math.d.ts +22 -22
  213. package/es/utils/math.js +141 -0
  214. package/es/utils/path.d.ts +15 -0
  215. package/es/utils/path.js +333 -0
  216. package/es/utils/raf.d.ts +3 -0
  217. package/es/utils/raf.js +15 -0
  218. package/es/utils/text.d.ts +2 -0
  219. package/es/utils/text.js +32 -0
  220. package/lib/AbstractRenderer.d.ts +26 -0
  221. package/lib/AbstractRenderer.js +49 -0
  222. package/lib/Canvas.d.ts +96 -0
  223. package/lib/Canvas.js +423 -0
  224. package/lib/DisplayObjectPool.d.ts +7 -0
  225. package/lib/DisplayObjectPool.js +35 -0
  226. package/lib/camera/Camera.d.ts +279 -0
  227. package/lib/camera/Camera.js +1035 -0
  228. package/lib/camera/Landmark.d.ts +28 -0
  229. package/lib/camera/Landmark.js +75 -0
  230. package/lib/camera/index.d.ts +2 -0
  231. package/lib/camera/index.js +31 -0
  232. package/lib/canvas-module.d.ts +1 -0
  233. package/lib/canvas-module.js +48 -0
  234. package/lib/components/Cullable.d.ts +15 -0
  235. package/lib/components/Cullable.js +45 -0
  236. package/lib/components/Geometry.d.ts +13 -0
  237. package/lib/components/Geometry.js +25 -0
  238. package/lib/components/Renderable.d.ts +25 -0
  239. package/lib/components/Renderable.js +34 -0
  240. package/lib/components/Sortable.d.ts +17 -0
  241. package/lib/components/Sortable.js +32 -0
  242. package/lib/components/Transform.d.ts +28 -0
  243. package/lib/components/Transform.js +79 -0
  244. package/lib/components/index.d.ts +5 -0
  245. package/lib/components/index.js +70 -0
  246. package/lib/display-objects/Circle.d.ts +12 -0
  247. package/lib/display-objects/Circle.js +34 -0
  248. package/lib/display-objects/CustomElement.d.ts +25 -0
  249. package/lib/display-objects/CustomElement.js +91 -0
  250. package/lib/display-objects/DisplayObject.d.ts +258 -0
  251. package/lib/display-objects/DisplayObject.js +879 -0
  252. package/lib/display-objects/Ellipse.d.ts +14 -0
  253. package/lib/display-objects/Ellipse.js +35 -0
  254. package/lib/display-objects/Group.d.ts +6 -0
  255. package/lib/display-objects/Group.js +36 -0
  256. package/lib/display-objects/HTML.d.ts +36 -0
  257. package/lib/display-objects/HTML.js +109 -0
  258. package/lib/display-objects/Image.d.ts +16 -0
  259. package/lib/display-objects/Image.js +33 -0
  260. package/lib/display-objects/Line.d.ts +23 -0
  261. package/lib/display-objects/Line.js +68 -0
  262. package/lib/display-objects/Path.d.ts +47 -0
  263. package/lib/display-objects/Path.js +143 -0
  264. package/lib/display-objects/Polygon.d.ts +12 -0
  265. package/lib/display-objects/Polygon.js +33 -0
  266. package/lib/display-objects/Polyline.d.ts +21 -0
  267. package/lib/display-objects/Polyline.js +85 -0
  268. package/lib/display-objects/Rect.d.ts +16 -0
  269. package/lib/display-objects/Rect.js +34 -0
  270. package/lib/display-objects/Text.d.ts +65 -0
  271. package/lib/display-objects/Text.js +69 -0
  272. package/lib/display-objects/index.d.ts +13 -0
  273. package/lib/display-objects/index.js +174 -0
  274. package/lib/dom/Animation.d.ts +132 -0
  275. package/lib/dom/Animation.js +506 -0
  276. package/lib/dom/AnimationEffectTiming.d.ts +59 -0
  277. package/lib/dom/AnimationEffectTiming.js +75 -0
  278. package/lib/dom/AnimationEvent.d.ts +11 -0
  279. package/lib/dom/AnimationEvent.js +42 -0
  280. package/lib/dom/AnimationTimeline.d.ts +37 -0
  281. package/lib/dom/AnimationTimeline.js +229 -0
  282. package/lib/dom/CustomElementRegistry.d.ts +15 -0
  283. package/lib/dom/CustomElementRegistry.js +50 -0
  284. package/lib/dom/CustomEvent.d.ts +16 -0
  285. package/lib/dom/CustomEvent.js +42 -0
  286. package/lib/dom/Document.d.ts +59 -0
  287. package/lib/dom/Document.js +177 -0
  288. package/lib/dom/Element.d.ts +143 -0
  289. package/lib/dom/Element.js +505 -0
  290. package/lib/dom/EventTarget.d.ts +43 -0
  291. package/lib/dom/EventTarget.js +179 -0
  292. package/lib/dom/FederatedEvent.d.ts +146 -0
  293. package/lib/dom/FederatedEvent.js +239 -0
  294. package/lib/dom/FederatedMouseEvent.d.ts +52 -0
  295. package/lib/dom/FederatedMouseEvent.js +133 -0
  296. package/lib/dom/FederatedPointerEvent.d.ts +69 -0
  297. package/lib/dom/FederatedPointerEvent.js +61 -0
  298. package/lib/dom/FederatedWheelEvent.d.ts +20 -0
  299. package/lib/dom/FederatedWheelEvent.js +35 -0
  300. package/lib/dom/KeyframeEffect.d.ts +48 -0
  301. package/lib/dom/KeyframeEffect.js +192 -0
  302. package/lib/dom/KeyframeList.d.ts +2 -0
  303. package/lib/dom/KeyframeList.js +183 -0
  304. package/lib/dom/Node.d.ts +106 -0
  305. package/lib/dom/Node.js +221 -0
  306. package/lib/dom/__tests__/utils/easing.d.ts +14 -0
  307. package/lib/dom/__tests__/utils/keyframe.d.ts +38 -0
  308. package/lib/dom/index.d.ts +17 -0
  309. package/lib/dom/index.js +226 -0
  310. package/lib/dom/interfaces.d.ts +326 -0
  311. package/lib/dom/interfaces.js +40 -0
  312. package/lib/global-module.d.ts +2 -0
  313. package/lib/global-module.js +177 -0
  314. package/lib/index.d.ts +18 -0
  315. package/lib/index.js +222 -0
  316. package/lib/plugins/CullingPlugin.d.ts +19 -0
  317. package/lib/plugins/CullingPlugin.js +92 -0
  318. package/lib/plugins/DirtyCheckPlugin.d.ts +10 -0
  319. package/lib/plugins/DirtyCheckPlugin.js +62 -0
  320. package/lib/plugins/EventPlugin.d.ts +26 -0
  321. package/lib/plugins/EventPlugin.js +297 -0
  322. package/lib/plugins/FrustumCullingStrategy.d.ts +21 -0
  323. package/lib/plugins/FrustumCullingStrategy.js +116 -0
  324. package/lib/plugins/PrepareRendererPlugin.d.ts +6 -0
  325. package/lib/plugins/PrepareRendererPlugin.js +88 -0
  326. package/lib/property-handlers/aabb.d.ts +2 -0
  327. package/lib/property-handlers/aabb.js +152 -0
  328. package/lib/property-handlers/anchor.d.ts +3 -0
  329. package/lib/property-handlers/anchor.js +34 -0
  330. package/lib/property-handlers/clipPath.d.ts +19 -0
  331. package/lib/property-handlers/clipPath.js +43 -0
  332. package/lib/property-handlers/color.d.ts +32 -0
  333. package/lib/property-handlers/color.js +271 -0
  334. package/lib/property-handlers/dimension.d.ts +18 -0
  335. package/lib/property-handlers/dimension.js +144 -0
  336. package/lib/property-handlers/filter.d.ts +9 -0
  337. package/lib/property-handlers/filter.js +56 -0
  338. package/lib/property-handlers/index.d.ts +17 -0
  339. package/lib/property-handlers/index.js +213 -0
  340. package/lib/property-handlers/interfaces.d.ts +20 -0
  341. package/lib/property-handlers/interfaces.js +18 -0
  342. package/lib/property-handlers/localPosition.d.ts +2 -0
  343. package/lib/property-handlers/localPosition.js +16 -0
  344. package/lib/property-handlers/numeric.d.ts +5 -0
  345. package/lib/property-handlers/numeric.js +50 -0
  346. package/lib/property-handlers/offsetDistance.d.ts +5 -0
  347. package/lib/property-handlers/offsetDistance.js +27 -0
  348. package/lib/property-handlers/offsetPath.d.ts +5 -0
  349. package/lib/property-handlers/offsetPath.js +25 -0
  350. package/lib/property-handlers/origin.d.ts +11 -0
  351. package/lib/property-handlers/origin.js +79 -0
  352. package/lib/property-handlers/path.d.ts +5 -0
  353. package/lib/property-handlers/path.js +214 -0
  354. package/lib/property-handlers/points.d.ts +6 -0
  355. package/lib/property-handlers/points.js +33 -0
  356. package/lib/property-handlers/transform.d.ts +45 -0
  357. package/lib/property-handlers/transform.js +430 -0
  358. package/lib/property-handlers/zIndex.d.ts +2 -0
  359. package/lib/property-handlers/zIndex.js +25 -0
  360. package/lib/services/ContextService.d.ts +12 -0
  361. package/lib/services/ContextService.js +15 -0
  362. package/lib/services/EventService.d.ts +64 -0
  363. package/lib/services/EventService.js +961 -0
  364. package/lib/services/RenderingContext.d.ts +28 -0
  365. package/lib/services/RenderingContext.js +22 -0
  366. package/lib/services/RenderingService.d.ts +51 -0
  367. package/lib/services/RenderingService.js +159 -0
  368. package/lib/services/SceneGraphSelector.d.ts +20 -0
  369. package/lib/services/SceneGraphSelector.js +76 -0
  370. package/lib/services/SceneGraphService.d.ts +146 -0
  371. package/lib/services/SceneGraphService.js +854 -0
  372. package/lib/services/aabb/CircleUpdater.d.ts +10 -0
  373. package/lib/services/aabb/CircleUpdater.js +45 -0
  374. package/lib/services/aabb/EllipseUpdater.d.ts +10 -0
  375. package/lib/services/aabb/EllipseUpdater.js +47 -0
  376. package/lib/services/aabb/LineUpdater.d.ts +10 -0
  377. package/lib/services/aabb/LineUpdater.js +49 -0
  378. package/lib/services/aabb/PathUpdater.d.ts +11 -0
  379. package/lib/services/aabb/PathUpdater.js +183 -0
  380. package/lib/services/aabb/PolylineUpdater.d.ts +10 -0
  381. package/lib/services/aabb/PolylineUpdater.js +58 -0
  382. package/lib/services/aabb/RectUpdater.d.ts +10 -0
  383. package/lib/services/aabb/RectUpdater.js +66 -0
  384. package/lib/services/aabb/TextUpdater.d.ts +13 -0
  385. package/lib/services/aabb/TextUpdater.js +93 -0
  386. package/lib/services/aabb/index.d.ts +8 -0
  387. package/lib/services/aabb/index.js +84 -0
  388. package/lib/services/aabb/interfaces.d.ts +16 -0
  389. package/lib/services/aabb/interfaces.js +10 -0
  390. package/lib/services/index.d.ts +10 -0
  391. package/lib/services/index.js +122 -0
  392. package/lib/services/text/OffscreenCanvasCreator.d.ts +6 -0
  393. package/lib/services/text/OffscreenCanvasCreator.js +55 -0
  394. package/lib/services/text/index.d.ts +35 -0
  395. package/lib/services/text/index.js +364 -0
  396. package/lib/shapes/AABB.d.ts +33 -0
  397. package/lib/shapes/AABB.js +235 -0
  398. package/lib/shapes/BoundingSphere.d.ts +8 -0
  399. package/lib/shapes/BoundingSphere.js +41 -0
  400. package/lib/shapes/Frustum.d.ts +16 -0
  401. package/lib/shapes/Frustum.js +96 -0
  402. package/lib/shapes/Plane.d.ts +14 -0
  403. package/lib/shapes/Plane.js +51 -0
  404. package/lib/shapes/Point.d.ts +11 -0
  405. package/lib/shapes/Point.js +38 -0
  406. package/lib/shapes/Polygon.d.ts +9 -0
  407. package/lib/shapes/Polygon.js +71 -0
  408. package/lib/shapes/Ray.d.ts +24 -0
  409. package/lib/shapes/Ray.js +169 -0
  410. package/lib/shapes/Rect.d.ts +12 -0
  411. package/lib/shapes/Rect.js +31 -0
  412. package/lib/shapes/Rectangle.d.ts +12 -0
  413. package/lib/shapes/Rectangle.js +27 -0
  414. package/lib/shapes/index.d.ts +8 -0
  415. package/lib/shapes/index.js +109 -0
  416. package/lib/types.d.ts +219 -0
  417. package/lib/types.js +25 -0
  418. package/lib/utils/animation.d.ts +15 -0
  419. package/lib/utils/animation.js +275 -0
  420. package/lib/utils/bezier-easing.d.ts +20 -0
  421. package/lib/utils/bezier-easing.js +128 -0
  422. package/lib/utils/canvas.d.ts +5 -0
  423. package/lib/utils/canvas.js +21 -0
  424. package/lib/utils/custom-easing.d.ts +75 -0
  425. package/lib/utils/custom-easing.js +415 -0
  426. package/lib/utils/event.d.ts +11 -0
  427. package/lib/utils/event.js +88 -0
  428. package/lib/utils/index.d.ts +5 -0
  429. package/lib/utils/index.js +70 -0
  430. package/lib/utils/interpolation.d.ts +3 -0
  431. package/lib/utils/interpolation.js +197 -0
  432. package/lib/utils/math.d.ts +22 -0
  433. package/lib/utils/math.js +166 -0
  434. package/lib/utils/path.d.ts +15 -0
  435. package/lib/utils/path.js +359 -0
  436. package/lib/utils/raf.d.ts +3 -0
  437. package/lib/utils/raf.js +21 -0
  438. package/lib/utils/text.d.ts +2 -0
  439. package/lib/utils/text.js +41 -0
  440. package/package.json +19 -20
  441. package/dist/AbstractRenderer.d.ts +0 -22
  442. package/dist/Batch.d.ts +0 -22
  443. package/dist/Canvas.d.ts +0 -56
  444. package/dist/CustomElement.d.ts +0 -13
  445. package/dist/DisplayObject.d.ts +0 -342
  446. package/dist/__tests__/circle.spec.d.ts +0 -1
  447. package/dist/__tests__/display-object.event.spec.d.ts +0 -1
  448. package/dist/__tests__/display-object.node.spec.d.ts +0 -1
  449. package/dist/__tests__/display-object.sort.spec.d.ts +0 -1
  450. package/dist/__tests__/display-object.spec.d.ts +0 -1
  451. package/dist/__tests__/display-object.visibility.spec.d.ts +0 -1
  452. package/dist/__tests__/event.spec.d.ts +0 -1
  453. package/dist/canvas-module.d.ts +0 -2
  454. package/dist/components/Animator.d.ts +0 -12
  455. package/dist/components/Geometry.d.ts +0 -6
  456. package/dist/components/SceneGraphNode.d.ts +0 -39
  457. package/dist/components/Sortable.d.ts +0 -17
  458. package/dist/contribution-provider.d.ts +0 -17
  459. package/dist/global-module.d.ts +0 -2
  460. package/dist/index.d.ts +0 -16
  461. package/dist/index.esm.js +0 -9199
  462. package/dist/index.js +0 -9262
  463. package/dist/inversify.config.d.ts +0 -7
  464. package/dist/plugins/CullingPlugin.d.ts +0 -16
  465. package/dist/plugins/DirtyCheckPlugin.d.ts +0 -19
  466. package/dist/plugins/SortPlugin.d.ts +0 -8
  467. package/dist/services/EventService.d.ts +0 -44
  468. package/dist/services/RenderingContext.d.ts +0 -31
  469. package/dist/services/SceneGraphSelector.d.ts +0 -18
  470. package/dist/services/SceneGraphService.d.ts +0 -101
  471. package/dist/services/aabb/CircleUpdater.d.ts +0 -7
  472. package/dist/services/aabb/EllipseUpdater.d.ts +0 -7
  473. package/dist/services/aabb/LineUpdater.d.ts +0 -7
  474. package/dist/services/aabb/PathUpdater.d.ts +0 -7
  475. package/dist/services/aabb/PolylineUpdater.d.ts +0 -7
  476. package/dist/services/aabb/RectUpdater.d.ts +0 -7
  477. package/dist/services/aabb/TextUpdater.d.ts +0 -8
  478. package/dist/services/aabb/index.d.ts +0 -15
  479. package/dist/services/text/OffscreenCanvasCreator.d.ts +0 -6
  480. package/dist/shapes/__tests__/aabb.spec.d.ts +0 -1
  481. package/dist/shapes/__tests__/boundingSphere.spec.d.ts +0 -1
  482. package/dist/shapes/__tests__/frustum.spec.d.ts +0 -1
  483. package/dist/shapes/__tests__/plane.spec.d.ts +0 -1
  484. package/dist/shapes/__tests__/ray.spec.d.ts +0 -1
  485. package/dist/shapes-export.d.ts +0 -32
  486. package/dist/systems/Timeline.d.ts +0 -40
  487. package/dist/systems/index.d.ts +0 -1
  488. package/dist/utils/color.d.ts +0 -2
  489. package/dist/utils/index.d.ts +0 -2
  490. package/dist/utils/path.d.ts +0 -12
  491. package/dist/utils/text.d.ts +0 -2
@@ -0,0 +1,1035 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DefaultCamera = exports.Camera = exports.CAMERA_TYPE = exports.CAMERA_TRACKING_MODE = exports.CAMERA_PROJECTION_MODE = exports.CAMERA_EVENT = void 0;
7
+
8
+ var _tslib = require("tslib");
9
+
10
+ var _eventemitter = require("eventemitter3");
11
+
12
+ var _glMatrix = require("gl-matrix");
13
+
14
+ var _Landmark = require("./Landmark");
15
+
16
+ var _shapes = require("../shapes");
17
+
18
+ var _math = require("../utils/math");
19
+
20
+ var _raf = require("../utils/raf");
21
+
22
+ var DefaultCamera = 'DefaultCamera';
23
+ exports.DefaultCamera = DefaultCamera;
24
+ var CAMERA_TYPE;
25
+ exports.CAMERA_TYPE = CAMERA_TYPE;
26
+
27
+ (function (CAMERA_TYPE) {
28
+ CAMERA_TYPE["ORBITING"] = "ORBITING";
29
+ CAMERA_TYPE["EXPLORING"] = "EXPLORING";
30
+ CAMERA_TYPE["TRACKING"] = "TRACKING";
31
+ })(CAMERA_TYPE || (exports.CAMERA_TYPE = CAMERA_TYPE = {}));
32
+
33
+ var CAMERA_TRACKING_MODE;
34
+ exports.CAMERA_TRACKING_MODE = CAMERA_TRACKING_MODE;
35
+
36
+ (function (CAMERA_TRACKING_MODE) {
37
+ CAMERA_TRACKING_MODE["DEFAULT"] = "DEFAULT";
38
+ CAMERA_TRACKING_MODE["ROTATIONAL"] = "ROTATIONAL";
39
+ CAMERA_TRACKING_MODE["TRANSLATIONAL"] = "TRANSLATIONAL";
40
+ CAMERA_TRACKING_MODE["CINEMATIC"] = "CINEMATIC";
41
+ })(CAMERA_TRACKING_MODE || (exports.CAMERA_TRACKING_MODE = CAMERA_TRACKING_MODE = {}));
42
+
43
+ var CAMERA_PROJECTION_MODE;
44
+ exports.CAMERA_PROJECTION_MODE = CAMERA_PROJECTION_MODE;
45
+
46
+ (function (CAMERA_PROJECTION_MODE) {
47
+ CAMERA_PROJECTION_MODE["ORTHOGRAPHIC"] = "ORTHOGRAPHIC";
48
+ CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
49
+ })(CAMERA_PROJECTION_MODE || (exports.CAMERA_PROJECTION_MODE = CAMERA_PROJECTION_MODE = {}));
50
+
51
+ var CAMERA_EVENT = {
52
+ Updated: 'updated'
53
+ };
54
+ exports.CAMERA_EVENT = CAMERA_EVENT;
55
+ var DEG_2_RAD = Math.PI / 180;
56
+ var RAD_2_DEG = 180 / Math.PI;
57
+ /**
58
+ * 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
59
+ * 保存相机参数,定义相机动作:
60
+ * 1. dolly 沿 n 轴移动
61
+ * 2. pan 沿 u v 轴移动
62
+ * 3. rotate 以方位角旋转
63
+ * 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互
64
+ */
65
+
66
+ var Camera =
67
+ /** @class */
68
+ function (_super) {
69
+ (0, _tslib.__extends)(Camera, _super);
70
+
71
+ function Camera() {
72
+ var _this = _super !== null && _super.apply(this, arguments) || this;
73
+ /**
74
+ * 相机矩阵
75
+ */
76
+
77
+
78
+ _this.matrix = _glMatrix.mat4.create();
79
+ /**
80
+ * u 轴
81
+ * @see http://learnwebgl.brown37.net/07_cameras/camera_introduction.html#a-camera-definition
82
+ */
83
+
84
+ _this.right = _glMatrix.vec3.fromValues(1, 0, 0);
85
+ /**
86
+ * v 轴 +Y is down
87
+ */
88
+
89
+ _this.up = _glMatrix.vec3.fromValues(0, 1, 0);
90
+ /**
91
+ * n 轴 +Z is inside
92
+ */
93
+
94
+ _this.forward = _glMatrix.vec3.fromValues(0, 0, 1);
95
+ /**
96
+ * 相机位置
97
+ */
98
+
99
+ _this.position = _glMatrix.vec3.fromValues(0, 0, 1);
100
+ /**
101
+ * 视点位置
102
+ */
103
+
104
+ _this.focalPoint = _glMatrix.vec3.fromValues(0, 0, 0);
105
+ /**
106
+ * 相机位置到视点向量
107
+ * focalPoint - position
108
+ */
109
+
110
+ _this.distanceVector = _glMatrix.vec3.fromValues(0, 0, 0);
111
+ /**
112
+ * 相机位置到视点距离
113
+ * length(focalPoint - position)
114
+ */
115
+
116
+ _this.distance = 1;
117
+ /**
118
+ * @see https://en.wikipedia.org/wiki/Azimuth
119
+ */
120
+
121
+ _this.azimuth = 0;
122
+ _this.elevation = 0;
123
+ _this.roll = 0;
124
+ _this.relAzimuth = 0;
125
+ _this.relElevation = 0;
126
+ _this.relRoll = 0;
127
+ /**
128
+ * 沿 n 轴移动时,保证移动速度从快到慢
129
+ */
130
+
131
+ _this.dollyingStep = 0;
132
+ _this.maxDistance = Infinity;
133
+ _this.minDistance = -Infinity;
134
+ /**
135
+ * zoom factor of the camera, default is 1
136
+ * eg. https://threejs.org/docs/#api/en/cameras/OrthographicCamera.zoom
137
+ */
138
+
139
+ _this.zoom = 1;
140
+ /**
141
+ * invert the horizontal coordinate system HCS
142
+ */
143
+
144
+ _this.rotateWorld = false; // @inject(IDENTIFIER.InteractorService)
145
+ // interactor: IInteractorService;
146
+
147
+ /**
148
+ * 投影矩阵参数
149
+ */
150
+
151
+ /**
152
+ * field of view [0-360]
153
+ * @see http://en.wikipedia.org/wiki/Angle_of_view
154
+ */
155
+
156
+ _this.fov = 30;
157
+ _this.near = 0.1;
158
+ _this.far = 10000;
159
+ _this.aspect = 1;
160
+ _this.projectionMatrix = _glMatrix.mat4.create();
161
+ _this.projectionMatrixInverse = _glMatrix.mat4.create();
162
+ _this.jitteredProjectionMatrix = undefined;
163
+ _this.following = undefined;
164
+ _this.type = CAMERA_TYPE.EXPLORING;
165
+ _this.trackingMode = CAMERA_TRACKING_MODE.DEFAULT;
166
+ _this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
167
+ /**
168
+ * for culling use
169
+ */
170
+
171
+ _this.frustum = new _shapes.Frustum();
172
+ /**
173
+ * switch between multiple landmarks
174
+ */
175
+
176
+ _this.landmarks = [];
177
+ /**
178
+ * ortho matrix for Canvas2D & SVG
179
+ */
180
+
181
+ _this.orthoMatrix = _glMatrix.mat4.create();
182
+ return _this;
183
+ }
184
+
185
+ Camera.prototype.clone = function () {
186
+ var camera = new Camera();
187
+ camera.setType(this.type, undefined); // camera.interactor = this.interactor;
188
+
189
+ return camera;
190
+ };
191
+
192
+ Camera.prototype.getProjectionMode = function () {
193
+ return this.projectionMode;
194
+ };
195
+
196
+ Camera.prototype.getPerspective = function () {
197
+ // account for TAA
198
+ return this.jitteredProjectionMatrix || this.projectionMatrix;
199
+ };
200
+
201
+ Camera.prototype.getPerspectiveInverse = function () {
202
+ return this.projectionMatrixInverse;
203
+ };
204
+
205
+ Camera.prototype.getFrustum = function () {
206
+ return this.frustum;
207
+ };
208
+
209
+ Camera.prototype.getPosition = function () {
210
+ return this.position;
211
+ };
212
+
213
+ Camera.prototype.getFocalPoint = function () {
214
+ return this.focalPoint;
215
+ };
216
+
217
+ Camera.prototype.getNear = function () {
218
+ return this.near;
219
+ };
220
+
221
+ Camera.prototype.getFar = function () {
222
+ return this.far;
223
+ };
224
+
225
+ Camera.prototype.getZoom = function () {
226
+ return this.zoom;
227
+ };
228
+
229
+ Camera.prototype.getOrthoMatrix = function () {
230
+ return this.orthoMatrix;
231
+ };
232
+
233
+ Camera.prototype.setType = function (type, trackingMode) {
234
+ this.type = type;
235
+
236
+ if (this.type === CAMERA_TYPE.EXPLORING) {
237
+ this.setWorldRotation(true);
238
+ } else {
239
+ this.setWorldRotation(false);
240
+ }
241
+
242
+ this._getAngles();
243
+
244
+ if (this.type === CAMERA_TYPE.TRACKING && trackingMode !== undefined) {
245
+ this.setTrackingMode(trackingMode);
246
+ }
247
+
248
+ return this;
249
+ };
250
+
251
+ Camera.prototype.setProjectionMode = function (projectionMode) {
252
+ this.projectionMode = projectionMode;
253
+ return this;
254
+ };
255
+
256
+ Camera.prototype.setTrackingMode = function (trackingMode) {
257
+ if (this.type !== CAMERA_TYPE.TRACKING) {
258
+ throw new Error('Impossible to set a tracking mode if the camera is not of tracking type');
259
+ }
260
+
261
+ this.trackingMode = trackingMode;
262
+ return this;
263
+ };
264
+ /**
265
+ * If flag is true, it reverses the azimuth and elevation angles.
266
+ * Subsequent calls to rotate, setAzimuth, setElevation,
267
+ * changeAzimuth or changeElevation will cause the inverted effect.
268
+ * setRoll or changeRoll is not affected by this method.
269
+ *
270
+ * This inversion is useful when one wants to simulate that the world
271
+ * is moving, instead of the camera.
272
+ *
273
+ * By default the camera angles are not reversed.
274
+ * @param {Boolean} flag the boolean flag to reverse the angles.
275
+ */
276
+
277
+
278
+ Camera.prototype.setWorldRotation = function (flag) {
279
+ this.rotateWorld = flag;
280
+
281
+ this._getAngles();
282
+ };
283
+ /**
284
+ * 计算 MV 矩阵,为相机矩阵的逆矩阵
285
+ */
286
+
287
+
288
+ Camera.prototype.getViewTransform = function () {
289
+ return _glMatrix.mat4.invert(_glMatrix.mat4.create(), this.matrix);
290
+ };
291
+
292
+ Camera.prototype.getWorldTransform = function () {
293
+ return this.matrix;
294
+ };
295
+
296
+ Camera.prototype.jitterProjectionMatrix = function (x, y) {
297
+ var translation = _glMatrix.mat4.fromTranslation(_glMatrix.mat4.create(), [x, y, 0]);
298
+
299
+ this.jitteredProjectionMatrix = _glMatrix.mat4.multiply(_glMatrix.mat4.create(), translation, this.projectionMatrix);
300
+ };
301
+
302
+ Camera.prototype.clearJitterProjectionMatrix = function () {
303
+ this.jitteredProjectionMatrix = undefined;
304
+ };
305
+ /**
306
+ * 设置相机矩阵
307
+ */
308
+
309
+
310
+ Camera.prototype.setMatrix = function (matrix) {
311
+ this.matrix = matrix;
312
+
313
+ this._update();
314
+
315
+ return this;
316
+ };
317
+
318
+ Camera.prototype.setFov = function (fov) {
319
+ this.setPerspective(this.near, this.far, fov, this.aspect);
320
+ };
321
+
322
+ Camera.prototype.setAspect = function (aspect) {
323
+ this.setPerspective(this.near, this.far, this.fov, aspect);
324
+ return this;
325
+ };
326
+
327
+ Camera.prototype.setNear = function (near) {
328
+ if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
329
+ this.setPerspective(near, this.far, this.fov, this.aspect);
330
+ } else {
331
+ this.setOrthographic(this.left, this.rright, this.top, this.bottom, near, this.far);
332
+ }
333
+
334
+ return this;
335
+ };
336
+
337
+ Camera.prototype.setFar = function (far) {
338
+ if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
339
+ this.setPerspective(this.near, far, this.fov, this.aspect);
340
+ } else {
341
+ this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, far);
342
+ }
343
+
344
+ return this;
345
+ };
346
+ /**
347
+ * Sets an offset in a larger frustum, used in PixelPicking
348
+ */
349
+
350
+
351
+ Camera.prototype.setViewOffset = function (fullWidth, fullHeight, x, y, width, height) {
352
+ this.aspect = fullWidth / fullHeight;
353
+
354
+ if (this.view === undefined) {
355
+ this.view = {
356
+ enabled: true,
357
+ fullWidth: 1,
358
+ fullHeight: 1,
359
+ offsetX: 0,
360
+ offsetY: 0,
361
+ width: 1,
362
+ height: 1
363
+ };
364
+ }
365
+
366
+ this.view.enabled = true;
367
+ this.view.fullWidth = fullWidth;
368
+ this.view.fullHeight = fullHeight;
369
+ this.view.offsetX = x;
370
+ this.view.offsetY = y;
371
+ this.view.width = width;
372
+ this.view.height = height;
373
+
374
+ if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
375
+ this.setPerspective(this.near, this.far, this.fov, this.aspect);
376
+ } else {
377
+ this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
378
+ }
379
+
380
+ return this;
381
+ };
382
+
383
+ Camera.prototype.clearViewOffset = function () {
384
+ if (this.view !== undefined) {
385
+ this.view.enabled = false;
386
+ }
387
+
388
+ if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
389
+ this.setPerspective(this.near, this.far, this.fov, this.aspect);
390
+ } else {
391
+ this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
392
+ }
393
+
394
+ return this;
395
+ };
396
+
397
+ Camera.prototype.setZoom = function (zoom) {
398
+ this.zoom = zoom;
399
+
400
+ if (this.projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
401
+ this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
402
+ }
403
+
404
+ return this;
405
+ };
406
+
407
+ Camera.prototype.setPerspective = function (near, far, fov, aspect) {
408
+ this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
409
+ this.fov = fov;
410
+ this.near = near;
411
+ this.far = far;
412
+ this.aspect = aspect; // let top = this.near * Math.tan(DEG_2_RAD * 0.5 * this.fov) / this.zoom;
413
+ // let height = 2 * top;
414
+ // let width = this.aspect * height;
415
+ // let left = -0.5 * width;
416
+ // if (this.view !== undefined && this.view.enabled) {
417
+ // const fullWidth = this.view.fullWidth;
418
+ // const fullHeight = this.view.fullHeight;
419
+ // left += this.view.offsetX * width / fullWidth;
420
+ // top -= this.view.offsetY * height / fullHeight;
421
+ // width *= this.view.width / fullWidth;
422
+ // height *= this.view.height / fullHeight;
423
+ // }
424
+ // flip Y
425
+
426
+ _glMatrix.mat4.perspective(this.projectionMatrix, -this.fov * DEG_2_RAD, -this.aspect, this.near, this.far);
427
+
428
+ _glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
429
+
430
+ this.emit(CAMERA_EVENT.Updated);
431
+ return this;
432
+ };
433
+
434
+ Camera.prototype.setOrthographic = function (l, r, t, b, near, far) {
435
+ this.projectionMode = CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
436
+ this.rright = r;
437
+ this.left = l;
438
+ this.top = t;
439
+ this.bottom = b;
440
+ this.near = near;
441
+ this.far = far;
442
+ var dx = (this.rright - this.left) / (2 * this.zoom);
443
+ var dy = (this.top - this.bottom) / (2 * this.zoom);
444
+ var cx = (this.rright + this.left) / 2;
445
+ var cy = (this.top + this.bottom) / 2;
446
+ var left = cx - dx;
447
+ var right = cx + dx;
448
+ var top = cy + dy;
449
+ var bottom = cy - dy;
450
+
451
+ if (this.view !== undefined && this.view.enabled) {
452
+ var scaleW = (this.rright - this.left) / this.view.fullWidth / this.zoom;
453
+ var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
454
+ left += scaleW * this.view.offsetX;
455
+ right = left + scaleW * this.view.width;
456
+ top -= scaleH * this.view.offsetY;
457
+ bottom = top - scaleH * this.view.height;
458
+ }
459
+
460
+ _glMatrix.mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
461
+
462
+ _glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
463
+
464
+ this._getOrthoMatrix();
465
+
466
+ this.emit(CAMERA_EVENT.Updated);
467
+ return this;
468
+ };
469
+ /**
470
+ * 设置相机位置
471
+ */
472
+
473
+
474
+ Camera.prototype.setPosition = function (x, y, z) {
475
+ this._setPosition(x, y, z);
476
+
477
+ this.setFocalPoint(this.focalPoint);
478
+ return this;
479
+ };
480
+ /**
481
+ * 设置视点位置
482
+ */
483
+
484
+
485
+ Camera.prototype.setFocalPoint = function (x, y, z) {
486
+ var up = _glMatrix.vec3.fromValues(0, 1, 0);
487
+
488
+ this.focalPoint = (0, _math.createVec3)(x, y, z);
489
+
490
+ if (this.trackingMode === CAMERA_TRACKING_MODE.CINEMATIC) {
491
+ var d = _glMatrix.vec3.subtract(_glMatrix.vec3.create(), this.focalPoint, this.position);
492
+
493
+ x = d[0];
494
+ y = d[1];
495
+ z = d[2];
496
+
497
+ var r = _glMatrix.vec3.length(d);
498
+
499
+ var el = Math.asin(y / r) * RAD_2_DEG;
500
+ var az = 90 + Math.atan2(z, x) * RAD_2_DEG;
501
+
502
+ var m = _glMatrix.mat4.create();
503
+
504
+ _glMatrix.mat4.rotateY(m, m, az * DEG_2_RAD);
505
+
506
+ _glMatrix.mat4.rotateX(m, m, el * DEG_2_RAD);
507
+
508
+ up = _glMatrix.vec3.transformMat4(_glMatrix.vec3.create(), [0, 1, 0], m);
509
+ }
510
+
511
+ _glMatrix.mat4.invert(this.matrix, _glMatrix.mat4.lookAt(_glMatrix.mat4.create(), this.position, this.focalPoint, up));
512
+
513
+ this._getAxes();
514
+
515
+ this._getDistance();
516
+
517
+ this._getAngles();
518
+
519
+ return this;
520
+ };
521
+ /**
522
+ * 固定当前视点,按指定距离放置相机
523
+ */
524
+
525
+
526
+ Camera.prototype.setDistance = function (d) {
527
+ if (this.distance === d || d < 0) {
528
+ return;
529
+ }
530
+
531
+ this.distance = d;
532
+
533
+ if (this.distance < 0.0002) {
534
+ this.distance = 0.0002;
535
+ }
536
+
537
+ this.dollyingStep = this.distance / 100;
538
+
539
+ var pos = _glMatrix.vec3.create();
540
+
541
+ d = this.distance;
542
+ var n = this.forward;
543
+ var f = this.focalPoint;
544
+ pos[0] = d * n[0] + f[0];
545
+ pos[1] = d * n[1] + f[1];
546
+ pos[2] = d * n[2] + f[2];
547
+
548
+ this._setPosition(pos);
549
+
550
+ return this;
551
+ };
552
+
553
+ Camera.prototype.setMaxDistance = function (d) {
554
+ this.maxDistance = d;
555
+ return this;
556
+ };
557
+
558
+ Camera.prototype.setMinDistance = function (d) {
559
+ this.minDistance = d;
560
+ return this;
561
+ };
562
+ /**
563
+ * Changes the initial azimuth of the camera
564
+ */
565
+
566
+
567
+ Camera.prototype.changeAzimuth = function (az) {
568
+ this.setAzimuth(this.azimuth + az);
569
+ return this;
570
+ };
571
+ /**
572
+ * Changes the initial elevation of the camera
573
+ */
574
+
575
+
576
+ Camera.prototype.changeElevation = function (el) {
577
+ this.setElevation(this.elevation + el);
578
+ return this;
579
+ };
580
+ /**
581
+ * Changes the initial roll of the camera
582
+ */
583
+
584
+
585
+ Camera.prototype.changeRoll = function (rl) {
586
+ this.setRoll(this.roll + rl);
587
+ return this;
588
+ };
589
+ /**
590
+ * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
591
+ * @param {Number} el the azimuth in degrees
592
+ */
593
+
594
+
595
+ Camera.prototype.setAzimuth = function (az) {
596
+ this.azimuth = (0, _math.getAngle)(az);
597
+ this.computeMatrix();
598
+
599
+ this._getAxes();
600
+
601
+ if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
602
+ this._getPosition();
603
+ } else if (this.type === CAMERA_TYPE.TRACKING) {
604
+ this._getFocalPoint();
605
+ }
606
+
607
+ return this;
608
+ };
609
+
610
+ Camera.prototype.getAzimuth = function () {
611
+ return this.azimuth;
612
+ };
613
+ /**
614
+ * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
615
+ * @param {Number} el the elevation in degrees
616
+ */
617
+
618
+
619
+ Camera.prototype.setElevation = function (el) {
620
+ this.elevation = (0, _math.getAngle)(el);
621
+ this.computeMatrix();
622
+
623
+ this._getAxes();
624
+
625
+ if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
626
+ this._getPosition();
627
+ } else if (this.type === CAMERA_TYPE.TRACKING) {
628
+ this._getFocalPoint();
629
+ }
630
+
631
+ return this;
632
+ };
633
+ /**
634
+ * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
635
+ * @param {Number} angle the roll angle
636
+ */
637
+
638
+
639
+ Camera.prototype.setRoll = function (angle) {
640
+ this.roll = (0, _math.getAngle)(angle);
641
+ this.computeMatrix();
642
+
643
+ this._getAxes();
644
+
645
+ if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
646
+ this._getPosition();
647
+ } else if (this.type === CAMERA_TYPE.TRACKING) {
648
+ this._getFocalPoint();
649
+ }
650
+
651
+ return this;
652
+ };
653
+ /**
654
+ * Changes the azimuth and elevation with respect to the current camera axes
655
+ * @param {Number} azimuth the relative azimuth
656
+ * @param {Number} elevation the relative elevation
657
+ * @param {Number} roll the relative roll
658
+ */
659
+
660
+
661
+ Camera.prototype.rotate = function (azimuth, elevation, roll) {
662
+ this.relElevation = (0, _math.getAngle)(elevation);
663
+ this.relAzimuth = (0, _math.getAngle)(azimuth);
664
+ this.relRoll = (0, _math.getAngle)(roll);
665
+ this.elevation += this.relElevation;
666
+ this.azimuth += this.relAzimuth;
667
+ this.roll += this.relRoll;
668
+
669
+ if (this.type === CAMERA_TYPE.EXPLORING) {
670
+ var rotX = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [1, 0, 0], (this.rotateWorld ? 1 : -1) * this.relElevation * DEG_2_RAD);
671
+
672
+ var rotY = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 1, 0], (this.rotateWorld ? 1 : -1) * this.relAzimuth * DEG_2_RAD);
673
+
674
+ var rotZ = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 0, 1], this.relRoll * DEG_2_RAD);
675
+
676
+ var rotQ = _glMatrix.quat.multiply(_glMatrix.quat.create(), rotY, rotX);
677
+
678
+ rotQ = _glMatrix.quat.multiply(_glMatrix.quat.create(), rotQ, rotZ);
679
+
680
+ var rotMatrix = _glMatrix.mat4.fromQuat(_glMatrix.mat4.create(), rotQ);
681
+
682
+ _glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]);
683
+
684
+ _glMatrix.mat4.multiply(this.matrix, this.matrix, rotMatrix);
685
+
686
+ _glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
687
+ } else {
688
+ if (Math.abs(this.elevation) > 90) {
689
+ return;
690
+ }
691
+
692
+ this.computeMatrix();
693
+ }
694
+
695
+ this._getAxes();
696
+
697
+ if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
698
+ this._getPosition();
699
+ } else if (this.type === CAMERA_TYPE.TRACKING) {
700
+ this._getFocalPoint();
701
+ }
702
+
703
+ this._update();
704
+
705
+ return this;
706
+ };
707
+ /**
708
+ * 沿水平(right) & 垂直(up)平移相机
709
+ */
710
+
711
+
712
+ Camera.prototype.pan = function (tx, ty) {
713
+ var coords = (0, _math.createVec3)(tx, ty, 0);
714
+
715
+ var pos = _glMatrix.vec3.clone(this.position);
716
+
717
+ _glMatrix.vec3.add(pos, pos, _glMatrix.vec3.scale(_glMatrix.vec3.create(), this.right, coords[0]));
718
+
719
+ _glMatrix.vec3.add(pos, pos, _glMatrix.vec3.scale(_glMatrix.vec3.create(), this.up, coords[1]));
720
+
721
+ this._setPosition(pos);
722
+
723
+ this.emit(CAMERA_EVENT.Updated);
724
+ return this;
725
+ };
726
+ /**
727
+ * 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢
728
+ */
729
+
730
+
731
+ Camera.prototype.dolly = function (value) {
732
+ var n = this.forward;
733
+
734
+ var pos = _glMatrix.vec3.clone(this.position);
735
+
736
+ var step = value * this.dollyingStep;
737
+ var updatedDistance = this.distance + value * this.dollyingStep; // 限制视点距离范围
738
+
739
+ step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance;
740
+ pos[0] += step * n[0];
741
+ pos[1] += step * n[1];
742
+ pos[2] += step * n[2];
743
+
744
+ this._setPosition(pos);
745
+
746
+ if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
747
+ // 重新计算视点距离
748
+ this._getDistance();
749
+ } else if (this.type === CAMERA_TYPE.TRACKING) {
750
+ // 保持视距,移动视点位置
751
+ _glMatrix.vec3.add(this.focalPoint, pos, this.distanceVector);
752
+ }
753
+
754
+ this.emit(CAMERA_EVENT.Updated);
755
+ return this;
756
+ };
757
+
758
+ Camera.prototype.createLandmark = function (name, params) {
759
+ var camera = this.clone();
760
+ camera.setPosition(params.position);
761
+ camera.setFocalPoint(params.focalPoint);
762
+
763
+ if (params.roll !== undefined) {
764
+ camera.setRoll(params.roll);
765
+ }
766
+
767
+ var landmark = new _Landmark.Landmark(name, camera);
768
+ this.landmarks.push(landmark);
769
+ return landmark;
770
+ };
771
+
772
+ Camera.prototype.setLandmark = function (name) {
773
+ var landmark = new _Landmark.Landmark(name, this);
774
+ this.landmarks.push(landmark);
775
+ return this;
776
+ };
777
+
778
+ Camera.prototype.gotoLandmark = function (name, duration) {
779
+ var _this = this;
780
+
781
+ if (duration === void 0) {
782
+ duration = 1000;
783
+ }
784
+
785
+ var landmark = this.landmarks.find(function (l) {
786
+ return l.name === name;
787
+ });
788
+
789
+ if (landmark) {
790
+ if (duration === 0) {
791
+ landmark.retrieve(this);
792
+ return;
793
+ }
794
+
795
+ if (this.landmarkAnimationID !== undefined) {
796
+ (0, _raf.cancelAnimationFrame)(this.landmarkAnimationID);
797
+ } // TODO: do not process events during animation
798
+ // this.interactor.disconnect();
799
+
800
+
801
+ var destPosition_1 = landmark.getPosition();
802
+ var destFocalPoint_1 = landmark.getFocalPoint();
803
+ var destRoll_1 = landmark.getRoll();
804
+ var timeStart_1;
805
+
806
+ var animate_1 = function animate_1(timestamp) {
807
+ if (timeStart_1 === undefined) {
808
+ timeStart_1 = timestamp;
809
+ }
810
+
811
+ var elapsed = timestamp - timeStart_1; // TODO: use better ease function
812
+
813
+ var t = (1 - Math.cos(elapsed / duration * Math.PI)) / 2;
814
+
815
+ var interFocalPoint = _glMatrix.vec3.create();
816
+
817
+ var interPosition = _glMatrix.vec3.create();
818
+
819
+ var interRoll = 0;
820
+
821
+ _glMatrix.vec3.lerp(interFocalPoint, _this.focalPoint, destFocalPoint_1, t);
822
+
823
+ _glMatrix.vec3.lerp(interPosition, _this.position, destPosition_1, t);
824
+
825
+ interRoll = _this.roll * (1 - t) + destRoll_1 * t;
826
+
827
+ _this.setFocalPoint(interFocalPoint);
828
+
829
+ _this.setPosition(interPosition);
830
+
831
+ _this.setRoll(interRoll);
832
+
833
+ _this.computeMatrix();
834
+
835
+ _this.emit(CAMERA_EVENT.Updated);
836
+
837
+ var dist = _glMatrix.vec3.dist(interFocalPoint, destFocalPoint_1) + _glMatrix.vec3.dist(interPosition, destPosition_1);
838
+
839
+ if (dist > 0.01) {//
840
+ } else {
841
+ _this.setFocalPoint(interFocalPoint);
842
+
843
+ _this.setPosition(interPosition);
844
+
845
+ _this.setRoll(interRoll);
846
+
847
+ _this.computeMatrix(); // this.interactor.connect();
848
+
849
+
850
+ return;
851
+ }
852
+
853
+ if (elapsed < duration) {
854
+ _this.landmarkAnimationID = (0, _raf.requestAnimationFrame)(animate_1);
855
+ }
856
+ };
857
+
858
+ (0, _raf.requestAnimationFrame)(animate_1);
859
+ }
860
+ };
861
+ /**
862
+ * 根据相机矩阵重新计算各种相机参数
863
+ */
864
+
865
+
866
+ Camera.prototype._update = function () {
867
+ this._getAxes();
868
+
869
+ this._getPosition();
870
+
871
+ this._getDistance();
872
+
873
+ this._getAngles();
874
+
875
+ this._getOrthoMatrix();
876
+
877
+ this.emit(CAMERA_EVENT.Updated);
878
+ };
879
+ /**
880
+ * 计算相机矩阵
881
+ */
882
+
883
+
884
+ Camera.prototype.computeMatrix = function () {
885
+ var rotX;
886
+ var rotY; // 使用四元数描述 3D 旋转
887
+ // @see https://xiaoiver.github.io/coding/2018/12/28/Camera-%E8%AE%BE%E8%AE%A1-%E4%B8%80.html
888
+
889
+ var rotZ = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 0, 1], this.roll * DEG_2_RAD);
890
+
891
+ _glMatrix.mat4.identity(this.matrix); // only consider HCS for EXPLORING and ORBITING cameras
892
+
893
+
894
+ rotX = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [1, 0, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.elevation * DEG_2_RAD);
895
+ rotY = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 1, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.azimuth * DEG_2_RAD);
896
+
897
+ var rotQ = _glMatrix.quat.multiply(_glMatrix.quat.create(), rotY, rotX);
898
+
899
+ rotQ = _glMatrix.quat.multiply(_glMatrix.quat.create(), rotQ, rotZ);
900
+
901
+ var rotMatrix = _glMatrix.mat4.fromQuat(_glMatrix.mat4.create(), rotQ);
902
+
903
+ if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
904
+ _glMatrix.mat4.translate(this.matrix, this.matrix, this.focalPoint);
905
+
906
+ _glMatrix.mat4.multiply(this.matrix, this.matrix, rotMatrix);
907
+
908
+ _glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
909
+ } else if (this.type === CAMERA_TYPE.TRACKING) {
910
+ _glMatrix.mat4.translate(this.matrix, this.matrix, this.position);
911
+
912
+ _glMatrix.mat4.multiply(this.matrix, this.matrix, rotMatrix);
913
+ }
914
+ };
915
+ /**
916
+ * Sets the camera position in the camera matrix
917
+ */
918
+
919
+
920
+ Camera.prototype._setPosition = function (x, y, z) {
921
+ this.position = (0, _math.createVec3)(x, y, z);
922
+ var m = this.matrix;
923
+ m[12] = this.position[0];
924
+ m[13] = this.position[1];
925
+ m[14] = this.position[2];
926
+ m[15] = 1;
927
+
928
+ this._getOrthoMatrix();
929
+ };
930
+ /**
931
+ * Recalculates axes based on the current matrix
932
+ */
933
+
934
+
935
+ Camera.prototype._getAxes = function () {
936
+ _glMatrix.vec3.copy(this.right, (0, _math.createVec3)(_glMatrix.vec4.transformMat4(_glMatrix.vec4.create(), [1, 0, 0, 0], this.matrix)));
937
+
938
+ _glMatrix.vec3.copy(this.up, (0, _math.createVec3)(_glMatrix.vec4.transformMat4(_glMatrix.vec4.create(), [0, 1, 0, 0], this.matrix)));
939
+
940
+ _glMatrix.vec3.copy(this.forward, (0, _math.createVec3)(_glMatrix.vec4.transformMat4(_glMatrix.vec4.create(), [0, 0, 1, 0], this.matrix)));
941
+
942
+ _glMatrix.vec3.normalize(this.right, this.right);
943
+
944
+ _glMatrix.vec3.normalize(this.up, this.up);
945
+
946
+ _glMatrix.vec3.normalize(this.forward, this.forward);
947
+ };
948
+ /**
949
+ * Recalculates euler angles based on the current state
950
+ */
951
+
952
+
953
+ Camera.prototype._getAngles = function () {
954
+ // Recalculates angles
955
+ var x = this.distanceVector[0];
956
+ var y = this.distanceVector[1];
957
+ var z = this.distanceVector[2];
958
+
959
+ var r = _glMatrix.vec3.length(this.distanceVector); // FAST FAIL: If there is no distance we cannot compute angles
960
+
961
+
962
+ if (r === 0) {
963
+ this.elevation = 0;
964
+ this.azimuth = 0;
965
+ return;
966
+ }
967
+
968
+ if (this.type === CAMERA_TYPE.TRACKING) {
969
+ this.elevation = Math.asin(y / r) * RAD_2_DEG;
970
+ this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
971
+ } else {
972
+ if (this.rotateWorld) {
973
+ this.elevation = Math.asin(y / r) * RAD_2_DEG;
974
+ this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
975
+ } else {
976
+ this.elevation = -Math.asin(y / r) * RAD_2_DEG;
977
+ this.azimuth = -Math.atan2(-x, -z) * RAD_2_DEG;
978
+ }
979
+ }
980
+ };
981
+ /**
982
+ * 重新计算相机位置,只有 ORBITING 模式相机位置才会发生变化
983
+ */
984
+
985
+
986
+ Camera.prototype._getPosition = function () {
987
+ _glMatrix.vec3.copy(this.position, (0, _math.createVec3)(_glMatrix.vec4.transformMat4(_glMatrix.vec4.create(), [0, 0, 0, 1], this.matrix))); // 相机位置变化,需要重新计算视距
988
+
989
+
990
+ this._getDistance();
991
+ };
992
+ /**
993
+ * 重新计算视点,只有 TRACKING 模式视点才会发生变化
994
+ */
995
+
996
+
997
+ Camera.prototype._getFocalPoint = function () {
998
+ _glMatrix.vec3.transformMat3(this.distanceVector, [0, 0, -this.distance], _glMatrix.mat3.fromMat4(_glMatrix.mat3.create(), this.matrix));
999
+
1000
+ _glMatrix.vec3.add(this.focalPoint, this.position, this.distanceVector); // 视点变化,需要重新计算视距
1001
+
1002
+
1003
+ this._getDistance();
1004
+ };
1005
+ /**
1006
+ * 重新计算视距
1007
+ */
1008
+
1009
+
1010
+ Camera.prototype._getDistance = function () {
1011
+ this.distanceVector = _glMatrix.vec3.subtract(_glMatrix.vec3.create(), this.focalPoint, this.position);
1012
+ this.distance = _glMatrix.vec3.length(this.distanceVector);
1013
+ this.dollyingStep = this.distance / 100;
1014
+ };
1015
+
1016
+ Camera.prototype._getOrthoMatrix = function () {
1017
+ if (this.projectionMode !== CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
1018
+ return;
1019
+ }
1020
+
1021
+ var position = this.position;
1022
+
1023
+ var rotZ = _glMatrix.quat.setAxisAngle(_glMatrix.quat.create(), [0, 0, 1], -this.roll * Math.PI / 180);
1024
+
1025
+ _glMatrix.mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, _glMatrix.vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.bottom - this.top) / 2 - position[1], 0), _glMatrix.vec3.fromValues(this.zoom, this.zoom, 1), position);
1026
+ };
1027
+
1028
+ Camera.ProjectionMode = {
1029
+ ORTHOGRAPHIC: 'ORTHOGRAPHIC',
1030
+ PERSPECTIVE: 'PERSPECTIVE'
1031
+ };
1032
+ return Camera;
1033
+ }(_eventemitter.EventEmitter);
1034
+
1035
+ exports.Camera = Camera;