@zenvor/view360 4.0.0-beta.7-fork.1

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 (261) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +88 -0
  3. package/css/base.css +19 -0
  4. package/css/base.min.css +1 -0
  5. package/css/control-bar.css +329 -0
  6. package/css/control-bar.min.css +1 -0
  7. package/css/helper.css +51 -0
  8. package/css/helper.min.css +1 -0
  9. package/css/hotspot.css +21 -0
  10. package/css/hotspot.min.css +1 -0
  11. package/css/loading-spinner.css +37 -0
  12. package/css/loading-spinner.min.css +1 -0
  13. package/css/variable.css +1 -0
  14. package/css/variable.min.css +0 -0
  15. package/css/view360.css +468 -0
  16. package/css/view360.min.css +1 -0
  17. package/css/vr.css +8 -0
  18. package/css/vr.min.css +1 -0
  19. package/declaration/View360.d.ts +150 -0
  20. package/declaration/cfc/const.d.ts +1 -0
  21. package/declaration/cfc/index.d.ts +4 -0
  22. package/declaration/cfc/utils.d.ts +1 -0
  23. package/declaration/cfc/withMethods.d.ts +2 -0
  24. package/declaration/const/browser.d.ts +71 -0
  25. package/declaration/const/error.d.ts +47 -0
  26. package/declaration/const/external.d.ts +33 -0
  27. package/declaration/const/internal.d.ts +34 -0
  28. package/declaration/control/CameraControl.d.ts +10 -0
  29. package/declaration/control/GyroControl.d.ts +30 -0
  30. package/declaration/control/PanoControl.d.ts +58 -0
  31. package/declaration/control/RotateControl.d.ts +75 -0
  32. package/declaration/control/ZoomControl.d.ts +45 -0
  33. package/declaration/control/index.d.ts +7 -0
  34. package/declaration/control/input/GyroInput.d.ts +46 -0
  35. package/declaration/control/input/KeyboardInput.d.ts +21 -0
  36. package/declaration/control/input/MouseInput.d.ts +16 -0
  37. package/declaration/control/input/PinchInput.d.ts +14 -0
  38. package/declaration/control/input/PointerInput.d.ts +18 -0
  39. package/declaration/control/input/TouchInput.d.ts +21 -0
  40. package/declaration/control/input/WheelInput.d.ts +16 -0
  41. package/declaration/core/AutoResizer.d.ts +13 -0
  42. package/declaration/core/Autoplay.d.ts +54 -0
  43. package/declaration/core/Camera.d.ts +88 -0
  44. package/declaration/core/CameraAnimation.d.ts +25 -0
  45. package/declaration/core/CameraPath.d.ts +55 -0
  46. package/declaration/core/CubeTexturePainter.d.ts +16 -0
  47. package/declaration/core/FrameAnimator.d.ts +13 -0
  48. package/declaration/core/Motion.d.ts +39 -0
  49. package/declaration/core/Object3D.d.ts +21 -0
  50. package/declaration/core/ShaderProgram.d.ts +10 -0
  51. package/declaration/core/TextureLoader.d.ts +26 -0
  52. package/declaration/core/TriangleMesh.d.ts +20 -0
  53. package/declaration/core/VertexArrayObject.d.ts +14 -0
  54. package/declaration/core/VertexData.d.ts +8 -0
  55. package/declaration/core/View360Error.d.ts +5 -0
  56. package/declaration/core/WebGLContext.d.ts +74 -0
  57. package/declaration/core/WebGLRenderer.d.ts +26 -0
  58. package/declaration/core/XRManager.d.ts +33 -0
  59. package/declaration/core/index.d.ts +12 -0
  60. package/declaration/geometry/CubeGeometry.d.ts +9 -0
  61. package/declaration/geometry/CylinderGeometry.d.ts +5 -0
  62. package/declaration/geometry/Geometry.d.ts +8 -0
  63. package/declaration/geometry/PlaneGeometry.d.ts +5 -0
  64. package/declaration/geometry/SphereGeometry.d.ts +5 -0
  65. package/declaration/hotspot/Hotspot.d.ts +7 -0
  66. package/declaration/hotspot/HotspotRenderer.d.ts +17 -0
  67. package/declaration/hotspot/index.d.ts +4 -0
  68. package/declaration/index.cjs.d.ts +3 -0
  69. package/declaration/index.d.ts +11 -0
  70. package/declaration/index.umd.d.ts +2 -0
  71. package/declaration/plugin/ControlBar/AutoHide.d.ts +42 -0
  72. package/declaration/plugin/ControlBar/ControlBar.d.ts +113 -0
  73. package/declaration/plugin/ControlBar/ControlBarItem.d.ts +15 -0
  74. package/declaration/plugin/ControlBar/FullscreenButton.d.ts +19 -0
  75. package/declaration/plugin/ControlBar/GyroButton.d.ts +14 -0
  76. package/declaration/plugin/ControlBar/PieView.d.ts +26 -0
  77. package/declaration/plugin/ControlBar/PlayButton.d.ts +16 -0
  78. package/declaration/plugin/ControlBar/ProgressBar.d.ts +23 -0
  79. package/declaration/plugin/ControlBar/RangeControl.d.ts +27 -0
  80. package/declaration/plugin/ControlBar/VRButton.d.ts +12 -0
  81. package/declaration/plugin/ControlBar/VideoControl.d.ts +11 -0
  82. package/declaration/plugin/ControlBar/VideoTime.d.ts +17 -0
  83. package/declaration/plugin/ControlBar/VolumeControl.d.ts +23 -0
  84. package/declaration/plugin/ControlBar/const.d.ts +41 -0
  85. package/declaration/plugin/ControlBar/index.d.ts +11 -0
  86. package/declaration/plugin/LoadingSpinner/LoadingSpinner.d.ts +22 -0
  87. package/declaration/plugin/View360Plugin.d.ts +6 -0
  88. package/declaration/plugin/index.d.ts +5 -0
  89. package/declaration/projection/CorrectionPass.d.ts +26 -0
  90. package/declaration/projection/CubemapProjection.d.ts +19 -0
  91. package/declaration/projection/CubestripProjection.d.ts +18 -0
  92. package/declaration/projection/CylindricalProjection.d.ts +22 -0
  93. package/declaration/projection/EquiangularProjection.d.ts +13 -0
  94. package/declaration/projection/EquirectProjection.d.ts +15 -0
  95. package/declaration/projection/LittlePlanetProjection.d.ts +21 -0
  96. package/declaration/projection/Projection.d.ts +19 -0
  97. package/declaration/projection/StereoEquiProjection.d.ts +25 -0
  98. package/declaration/projection/WideAngleCorrectionProjection.d.ts +27 -0
  99. package/declaration/projection/WideAngleRealtimeProjection.d.ts +50 -0
  100. package/declaration/projection/index.d.ts +12 -0
  101. package/declaration/texture/Texture.d.ts +18 -0
  102. package/declaration/texture/Texture2D.d.ts +11 -0
  103. package/declaration/texture/TextureCube.d.ts +12 -0
  104. package/declaration/texture/TextureRenderTarget.d.ts +8 -0
  105. package/declaration/texture/TextureVideo.d.ts +11 -0
  106. package/declaration/type/events.d.ts +74 -0
  107. package/declaration/type/external.d.ts +13 -0
  108. package/declaration/type/internal.d.ts +47 -0
  109. package/declaration/type/utils.d.ts +11 -0
  110. package/declaration/uniform/Uniform.d.ts +7 -0
  111. package/declaration/uniform/UniformBoolean.d.ts +7 -0
  112. package/declaration/uniform/UniformCanvasCube.d.ts +12 -0
  113. package/declaration/uniform/UniformFloat.d.ts +7 -0
  114. package/declaration/uniform/UniformInt.d.ts +7 -0
  115. package/declaration/uniform/UniformMatrix.d.ts +8 -0
  116. package/declaration/uniform/UniformTexture2D.d.ts +11 -0
  117. package/declaration/uniform/UniformTextureCube.d.ts +12 -0
  118. package/declaration/uniform/UniformTextureRenderTarget.d.ts +11 -0
  119. package/declaration/uniform/UniformVec2.d.ts +7 -0
  120. package/declaration/uniform/UniformVec3.d.ts +7 -0
  121. package/declaration/uniform/UniformVector4Array.d.ts +7 -0
  122. package/declaration/utils.d.ts +25 -0
  123. package/dist/view360.cjs.js +9392 -0
  124. package/dist/view360.cjs.js.map +1 -0
  125. package/dist/view360.esm.js +9274 -0
  126. package/dist/view360.esm.js.map +1 -0
  127. package/dist/view360.js +9350 -0
  128. package/dist/view360.js.map +1 -0
  129. package/dist/view360.min.js +2 -0
  130. package/dist/view360.min.js.map +1 -0
  131. package/dist/view360.pkgd.js +48537 -0
  132. package/dist/view360.pkgd.js.map +1 -0
  133. package/dist/view360.pkgd.min.js +16 -0
  134. package/dist/view360.pkgd.min.js.map +1 -0
  135. package/package.json +110 -0
  136. package/sass/base.sass +17 -0
  137. package/sass/control-bar.sass +284 -0
  138. package/sass/helper.sass +51 -0
  139. package/sass/hotspot.sass +20 -0
  140. package/sass/loading-spinner.sass +34 -0
  141. package/sass/variable.sass +2 -0
  142. package/sass/view360.sass +6 -0
  143. package/sass/vr.sass +10 -0
  144. package/src/View360.ts +1220 -0
  145. package/src/cfc/const.ts +15 -0
  146. package/src/cfc/index.ts +8 -0
  147. package/src/cfc/utils.ts +12 -0
  148. package/src/cfc/withMethods.ts +40 -0
  149. package/src/const/browser.ts +109 -0
  150. package/src/const/error.ts +83 -0
  151. package/src/const/external.ts +77 -0
  152. package/src/const/internal.ts +53 -0
  153. package/src/control/CameraControl.ts +53 -0
  154. package/src/control/GyroControl.ts +225 -0
  155. package/src/control/PanoControl.ts +434 -0
  156. package/src/control/RotateControl.ts +411 -0
  157. package/src/control/ZoomControl.ts +254 -0
  158. package/src/control/index.ts +24 -0
  159. package/src/control/input/GyroInput.ts +315 -0
  160. package/src/control/input/KeyboardInput.ts +151 -0
  161. package/src/control/input/MouseInput.ts +102 -0
  162. package/src/control/input/PinchInput.ts +101 -0
  163. package/src/control/input/PointerInput.ts +118 -0
  164. package/src/control/input/TouchInput.ts +138 -0
  165. package/src/control/input/WheelInput.ts +89 -0
  166. package/src/core/AutoResizer.ts +92 -0
  167. package/src/core/Autoplay.ts +326 -0
  168. package/src/core/Camera.ts +616 -0
  169. package/src/core/CameraAnimation.ts +110 -0
  170. package/src/core/CameraPath.ts +454 -0
  171. package/src/core/CubeTexturePainter.ts +95 -0
  172. package/src/core/FrameAnimator.ts +69 -0
  173. package/src/core/Motion.ts +205 -0
  174. package/src/core/Object3D.ts +81 -0
  175. package/src/core/ShaderProgram.ts +21 -0
  176. package/src/core/TextureLoader.ts +303 -0
  177. package/src/core/TriangleMesh.ts +54 -0
  178. package/src/core/VertexArrayObject.ts +29 -0
  179. package/src/core/VertexData.ts +23 -0
  180. package/src/core/View360Error.ts +35 -0
  181. package/src/core/WebGLContext.ts +558 -0
  182. package/src/core/WebGLRenderer.ts +205 -0
  183. package/src/core/XRManager.ts +193 -0
  184. package/src/core/index.ts +35 -0
  185. package/src/geometry/CubeGeometry.ts +121 -0
  186. package/src/geometry/CylinderGeometry.ts +49 -0
  187. package/src/geometry/Geometry.ts +23 -0
  188. package/src/geometry/PlaneGeometry.ts +36 -0
  189. package/src/geometry/SphereGeometry.ts +55 -0
  190. package/src/hotspot/Hotspot.ts +32 -0
  191. package/src/hotspot/HotspotRenderer.ts +155 -0
  192. package/src/hotspot/index.ts +11 -0
  193. package/src/index.cjs.ts +13 -0
  194. package/src/index.ts +21 -0
  195. package/src/index.umd.ts +10 -0
  196. package/src/plugin/ControlBar/AutoHide.ts +246 -0
  197. package/src/plugin/ControlBar/ControlBar.ts +564 -0
  198. package/src/plugin/ControlBar/ControlBarItem.ts +84 -0
  199. package/src/plugin/ControlBar/FullscreenButton.ts +145 -0
  200. package/src/plugin/ControlBar/GyroButton.ts +124 -0
  201. package/src/plugin/ControlBar/PieView.ts +195 -0
  202. package/src/plugin/ControlBar/PlayButton.ts +130 -0
  203. package/src/plugin/ControlBar/ProgressBar.ts +175 -0
  204. package/src/plugin/ControlBar/RangeControl.ts +165 -0
  205. package/src/plugin/ControlBar/VRButton.ts +78 -0
  206. package/src/plugin/ControlBar/VideoControl.ts +79 -0
  207. package/src/plugin/ControlBar/VideoTime.ts +120 -0
  208. package/src/plugin/ControlBar/VolumeControl.ts +220 -0
  209. package/src/plugin/ControlBar/const.ts +72 -0
  210. package/src/plugin/ControlBar/index.ts +31 -0
  211. package/src/plugin/LoadingSpinner/LoadingSpinner.ts +116 -0
  212. package/src/plugin/View360Plugin.ts +30 -0
  213. package/src/plugin/index.ts +16 -0
  214. package/src/projection/CorrectionPass.ts +161 -0
  215. package/src/projection/CubemapProjection.ts +92 -0
  216. package/src/projection/CubestripProjection.ts +85 -0
  217. package/src/projection/CylindricalProjection.ts +123 -0
  218. package/src/projection/EquiangularProjection.ts +52 -0
  219. package/src/projection/EquirectProjection.ts +56 -0
  220. package/src/projection/LittlePlanetProjection.ts +82 -0
  221. package/src/projection/Projection.ts +103 -0
  222. package/src/projection/StereoEquiProjection.ts +104 -0
  223. package/src/projection/WideAngleCorrectionProjection.ts +307 -0
  224. package/src/projection/WideAngleRealtimeProjection.ts +653 -0
  225. package/src/projection/index.ts +36 -0
  226. package/src/shader/common.frag +7 -0
  227. package/src/shader/common.vert +12 -0
  228. package/src/shader/correction.frag +110 -0
  229. package/src/shader/cube.frag +8 -0
  230. package/src/shader/cube.vert +12 -0
  231. package/src/shader/eac.frag +40 -0
  232. package/src/shader/fullscreen.vert +7 -0
  233. package/src/shader/little-planet.frag +47 -0
  234. package/src/shader/little-planet.vert +12 -0
  235. package/src/shader/stereoequi.vert +15 -0
  236. package/src/shader/wideangle_realtime.frag +109 -0
  237. package/src/shader/wideangle_realtime.vert +17 -0
  238. package/src/shim.d.ts +9 -0
  239. package/src/texture/Texture.ts +47 -0
  240. package/src/texture/Texture2D.ts +34 -0
  241. package/src/texture/TextureCube.ts +36 -0
  242. package/src/texture/TextureRenderTarget.ts +33 -0
  243. package/src/texture/TextureVideo.ts +56 -0
  244. package/src/type/events.ts +389 -0
  245. package/src/type/external.ts +78 -0
  246. package/src/type/internal.ts +54 -0
  247. package/src/type/utils.ts +27 -0
  248. package/src/types/hls.d.ts +78 -0
  249. package/src/uniform/Uniform.ts +20 -0
  250. package/src/uniform/UniformBoolean.ts +23 -0
  251. package/src/uniform/UniformCanvasCube.ts +44 -0
  252. package/src/uniform/UniformFloat.ts +23 -0
  253. package/src/uniform/UniformInt.ts +25 -0
  254. package/src/uniform/UniformMatrix.ts +24 -0
  255. package/src/uniform/UniformTexture2D.ts +46 -0
  256. package/src/uniform/UniformTextureCube.ts +51 -0
  257. package/src/uniform/UniformTextureRenderTarget.ts +55 -0
  258. package/src/uniform/UniformVec2.ts +25 -0
  259. package/src/uniform/UniformVec3.ts +25 -0
  260. package/src/uniform/UniformVector4Array.ts +23 -0
  261. package/src/utils.ts +217 -0
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import Geometry from "./Geometry";
6
+
7
+ /**
8
+ * @hidden
9
+ */
10
+ class SphereGeometry extends Geometry {
11
+ /** */
12
+ public constructor() {
13
+ // const radius = 1;
14
+ const widthSegments = 60;
15
+ const heightSegments = 60;
16
+ const ANGLE_CORRECTION_FOR_CENTER_ALIGN = -0.5 * Math.PI;
17
+
18
+ const uvs: number[] = [];
19
+ const vertices: number[] = [];
20
+ const indicies: number[] = [];
21
+ let latIdx: number;
22
+ let lngIdx: number;
23
+
24
+ for (latIdx = 0; latIdx <= widthSegments; latIdx++) {
25
+ const theta = (latIdx / widthSegments - 0.5) * Math.PI;
26
+ const sinTheta = Math.sin(theta);
27
+ const cosTheta = Math.cos(theta);
28
+
29
+ for (lngIdx = 0; lngIdx <= heightSegments; lngIdx++) {
30
+ const phi = (lngIdx / heightSegments - 0.5) * 2 * Math.PI + ANGLE_CORRECTION_FOR_CENTER_ALIGN;
31
+ const sinPhi = Math.sin(phi);
32
+ const cosPhi = Math.cos(phi);
33
+ const x = cosPhi * cosTheta;
34
+ const y = sinTheta;
35
+ const z = sinPhi * cosTheta;
36
+ const u = lngIdx / heightSegments;
37
+ const v = latIdx / widthSegments;
38
+
39
+ uvs.push(u, v);
40
+ vertices.push(x, y, z);
41
+
42
+ if (lngIdx !== heightSegments && latIdx !== widthSegments) {
43
+ const a = latIdx * (heightSegments + 1) + lngIdx;
44
+ const b = a + heightSegments + 1;
45
+
46
+ indicies.push(a, a + 1, b, b, a + 1, b + 1);
47
+ }
48
+ }
49
+ }
50
+
51
+ super(vertices, indicies, uvs);
52
+ }
53
+ }
54
+
55
+ export default SphereGeometry;
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import { vec3 } from "gl-matrix";
6
+
7
+ /**
8
+ * Hotspot data
9
+ * @ko 핫스팟 데이터
10
+ * @since 4.0.0
11
+ */
12
+ class Hotspot {
13
+ /**
14
+ * HTMLElement of the hotspot
15
+ * @ko 핫스팟의 HTMLElement
16
+ * @since 4.0.0
17
+ */
18
+ public readonly element: HTMLElement;
19
+ /**
20
+ * Position to render hotspot
21
+ * @ko 핫스팟을 렌더링할 위치
22
+ * @since 4.0.0
23
+ */
24
+ public readonly position: vec3;
25
+
26
+ public constructor(element: HTMLElement, position: vec3) {
27
+ this.element = element;
28
+ this.position = position;
29
+ }
30
+ }
31
+
32
+ export default Hotspot;
@@ -0,0 +1,155 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import { vec2, vec3 } from "gl-matrix";
6
+ import Hotspot from "./Hotspot";
7
+ import Camera from "../core/Camera";
8
+ import WebGLRenderer from "../core/WebGLRenderer";
9
+ import View360Error from "../core/View360Error";
10
+ import { getNullableElement } from "../utils";
11
+ import ERROR from "../const/error";
12
+ import { DEFAULT_CLASS } from "../const/external";
13
+ import { DEG_TO_RAD } from "../const/internal";
14
+
15
+ /**
16
+ * Options for {@link HotspotRenderer}
17
+ * @ko {@link HotspotRenderer}용 옵션들
18
+ * @since 4.0.0
19
+ */
20
+ export interface HotspotOptions {
21
+ /**
22
+ * Apply scale for hotspots, makes their size sync with background panorama image.
23
+ * @ko 핫스팟에 스케일을 적용해서 배경 파노라마 이미지의 크기 변화와 동일하게 크기를 조절합니다.
24
+ * @since 4.0.0
25
+ */
26
+ zoom: boolean;
27
+ }
28
+
29
+ /**
30
+ * Hotspot renderer
31
+ * @ko Hotspot 렌더러
32
+ * @since 4.0.0
33
+ */
34
+ class HotspotRenderer {
35
+ // Options
36
+ private _zoom: HotspotOptions["zoom"];
37
+
38
+ // Internal properties
39
+ private _containerEl: HTMLElement | null;
40
+ private _renderer: WebGLRenderer;
41
+ private _hotspots: Hotspot[];
42
+
43
+ /**
44
+ * Create new instance
45
+ * @ko 새 인스턴스를 생성합니다.
46
+ * @param rootEl - Container element for hotspots {@ko 핫스팟들의 컨테이너 엘리먼트}
47
+ * @param renderer - instance of WebGLRenderer {@ko WebGLRenderer의 인스턴스}
48
+ * @param options - Hotspot options {@ko Hotspot 옵션들 }
49
+ */
50
+ public constructor(rootEl: HTMLElement, renderer: WebGLRenderer, {
51
+ zoom = false
52
+ }: Partial<HotspotOptions>) {
53
+ this._containerEl = getNullableElement(`.${DEFAULT_CLASS.HOTSPOT_CONTAINER}`, rootEl);
54
+ this._renderer = renderer;
55
+ this._hotspots = [];
56
+
57
+ this._zoom = zoom;
58
+ }
59
+
60
+ /**
61
+ * Refresh hotspots by collecting hotspot elements from current hotspot root element
62
+ * @ko 현재 핫스팟 루트 엘리먼트 내에서 핫스팟 엘리먼트들을 수집하여 갱신합니다.
63
+ * @throws {ERROR_CODES.INSUFFICIENT_ARGS} if data-position doesn't include all x, y, z values {@ko data-position이 x, y, z좌표를 전부 포함하고 있지 않을 때}
64
+ */
65
+ public refresh() {
66
+ const container = this._containerEl;
67
+ if (!container) return;
68
+
69
+ const hotspotEls = [].slice.apply(container.querySelectorAll(`.${DEFAULT_CLASS.HOTSPOT}`)) as HTMLElement[];
70
+ this._hotspots = hotspotEls.map(el => this._parseHotspot(el));
71
+ }
72
+
73
+ /**
74
+ * Render hotspots
75
+ * @ko 핫스팟들을 렌더링합니다.
76
+ * @param camera - Instance of Camera {@ko Camera의 인스턴스}
77
+ */
78
+ public render(camera: Camera) {
79
+ const hotspots = this._hotspots;
80
+ const halfWidth = this._renderer.width * 0.5;
81
+ const halfHeight = this._renderer.height * 0.5;
82
+ const zoom = camera.zoom;
83
+ const centerTransform = "translate(-50%, -50%)";
84
+ const zoomTransform = this._zoom ? `scale(${zoom})` : "";
85
+
86
+ hotspots.forEach(hotspot => {
87
+ const position = hotspot.position;
88
+ const relPos = vec3.create();
89
+
90
+ vec3.copy(relPos, position);
91
+ vec3.transformMat4(relPos, relPos, camera.viewMatrix);
92
+ vec3.transformMat4(relPos, relPos, camera.projectionMatrix);
93
+
94
+ if (relPos[2] > 1 || relPos[2] < 0) {
95
+ hotspot.element.classList.remove(DEFAULT_CLASS.HOTSPOT_VISIBLE);
96
+ return;
97
+ }
98
+
99
+ const screenPos = vec2.fromValues(
100
+ relPos[0] * halfWidth + halfWidth,
101
+ -relPos[1] * halfHeight + halfHeight
102
+ );
103
+
104
+ hotspot.element.classList.add(DEFAULT_CLASS.HOTSPOT_VISIBLE);
105
+ hotspot.element.style.transform = [
106
+ centerTransform,
107
+ `translate(${screenPos[0]}px, ${screenPos[1]}px)`,
108
+ zoomTransform
109
+ ].join(" ");
110
+ });
111
+ }
112
+
113
+ private _parseHotspot(element: HTMLElement): Hotspot {
114
+ const yawStr = element.dataset.yaw;
115
+ const pitchStr = element.dataset.pitch;
116
+ const positionStr = element.dataset.position;
117
+
118
+ if (yawStr || pitchStr) {
119
+ const yaw = yawStr ? parseFloat(yawStr) : 0;
120
+ const pitch = pitchStr ? parseFloat(pitchStr) : 0;
121
+
122
+ const position = this._yawPitchToVec3(yaw, pitch);
123
+
124
+ return new Hotspot(element, position);
125
+ } else if (positionStr) {
126
+ const pos: number[] = positionStr.split(" ").map(val => parseFloat(val));
127
+ if (pos.length < 3) {
128
+ throw new View360Error(ERROR.MESSAGES.INSUFFICIENT_ARGS(positionStr, "hotspot attribute \"data-position\""), ERROR.CODES.INSUFFICIENT_ARGS);
129
+ }
130
+
131
+ return new Hotspot(element, vec3.fromValues(pos[0], pos[1], pos[2]));
132
+ } else {
133
+ // Place hotspot at yaw: 0, pitch: 0
134
+ const defaultPos = vec3.fromValues(0, 0, -1);
135
+
136
+ return new Hotspot(element, defaultPos);
137
+ }
138
+ }
139
+
140
+ private _yawPitchToVec3(yaw: number, pitch: number) {
141
+ const yawRad = yaw * DEG_TO_RAD;
142
+ const pitchRad = pitch * DEG_TO_RAD;
143
+ const position = vec3.create();
144
+
145
+ position[1] = Math.sin(pitchRad);
146
+ position[2] = Math.cos(pitchRad);
147
+
148
+ position[0] = position[2] * Math.sin(-yawRad);
149
+ position[2] = -position[2] * Math.cos(-yawRad);
150
+
151
+ return position;
152
+ }
153
+ }
154
+
155
+ export default HotspotRenderer;
@@ -0,0 +1,11 @@
1
+ import Hotspot from "./Hotspot";
2
+ import HotspotRenderer, { HotspotOptions } from "./HotspotRenderer";
3
+
4
+ export {
5
+ Hotspot,
6
+ HotspotRenderer
7
+ };
8
+
9
+ export type {
10
+ HotspotOptions
11
+ };
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import View360, * as modules from "./index";
6
+ import { merge } from "./utils";
7
+
8
+ merge(View360, modules);
9
+
10
+ declare const module: any;
11
+ module.exports = View360;
12
+ export default View360;
13
+ export * from "./index";
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import View360, { View360Options, View360Events } from "./View360";
6
+
7
+ export * from "./core";
8
+ export * from "./control";
9
+ export * from "./plugin";
10
+ export * from "./projection";
11
+ export * from "./hotspot";
12
+ export * from "./const/external";
13
+ export * from "./type/external";
14
+ export * from "./cfc";
15
+
16
+ export type {
17
+ View360Options,
18
+ View360Events
19
+ };
20
+
21
+ export default View360;
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import View360, * as modules from "./index";
6
+ import { merge } from "./utils";
7
+
8
+ merge(View360, modules);
9
+
10
+ export default View360;
@@ -0,0 +1,246 @@
1
+ /*
2
+ * Copyright (c) 2023-present NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import ControlBar from "./ControlBar";
6
+ import View360 from "../../View360";
7
+ import * as BROWSER from "../../const/browser";
8
+ import { FULLSCREEN_CHANGE } from "../../const/browser";
9
+ import TextureVideo from "../../texture/TextureVideo";
10
+ import { isFullscreen } from "../../utils";
11
+
12
+ /**
13
+ * Options for ControlBar's {@link ControlBarOptions#autoHide}
14
+ * @ko ControlBar의 {@link ControlBarOptions#autoHide}용 옵션
15
+ * @category Plugin
16
+ * @since 4.0.0
17
+ */
18
+ export interface AutoHideOptions {
19
+ /**
20
+ * Initial delay before the control bar hides (ms)
21
+ * @ko 컨트롤바가 처음으로 표시되고 사라지기까지 걸리는 시간 (ms)
22
+ * @default 3000
23
+ * @since 4.0.0
24
+ */
25
+ initialDelay: number;
26
+ /**
27
+ * Delay time before hiding the control bar after mouse leave (ms)
28
+ * @ko 마우스가 컨트롤바 영역을 떠난 뒤 컨트롤바가 사라지기까지 걸리는 시간 (ms)
29
+ * @default 0
30
+ * @since 4.0.0
31
+ */
32
+ delay: number;
33
+ /**
34
+ * Delay time before hiding the control bar becomes active, like touch on mobile device or mouse move in fullscreen mode (ms)
35
+ * @ko 모바일이나 풀스크린 환경 등에서 사용자 입력이 없을 때 컨트롤바가 사라지기까지 걸리는 시간 (ms)
36
+ * @default 3000
37
+ * @since 4.0.0
38
+ */
39
+ idleDelay: number;
40
+ }
41
+
42
+ class AutoHide {
43
+ private _initialDelay: AutoHideOptions["initialDelay"];
44
+ private _delay: AutoHideOptions["delay"];
45
+ private _idleDelay: AutoHideOptions["idleDelay"];
46
+
47
+ private _controlBar: ControlBar;
48
+ private _timer: number;
49
+ private _isGrabbing: boolean;
50
+ private _isCursorInside: boolean;
51
+ private _isFullscreen: boolean;
52
+ private _targetEl: HTMLElement | null;
53
+ private _video: TextureVideo | null;
54
+
55
+ public get enabled() { return !!this._targetEl; }
56
+ public get hidden() { return this._controlBar.containerEl.classList.contains(this._hiddenClass); }
57
+
58
+ private get _hiddenClass() { return this._controlBar.className.HIDDEN; }
59
+ private get _fixedClass() { return this._controlBar.className.FIXED; }
60
+
61
+ public constructor(controlBar: ControlBar, {
62
+ initialDelay = 3000,
63
+ delay = 0,
64
+ idleDelay: activationDelay = 3000
65
+ }: Partial<AutoHideOptions>) {
66
+ this._controlBar = controlBar;
67
+ this._initialDelay = initialDelay;
68
+ this._delay = delay;
69
+ this._idleDelay = activationDelay;
70
+ this._timer = -1;
71
+ this._isCursorInside = false;
72
+ this._isGrabbing = false;
73
+ this._isFullscreen = false;
74
+ this._video = null;
75
+ this._targetEl = null;
76
+ }
77
+
78
+ public enable(viewer: View360) {
79
+ if (this._targetEl) {
80
+ this.disable(viewer);
81
+ }
82
+
83
+ const initialDelay = this._initialDelay;
84
+ const root = viewer.rootEl;
85
+
86
+ this._targetEl = viewer.rootEl;
87
+ this._timer = window.setTimeout(() => {
88
+ this.hide();
89
+ }, initialDelay);
90
+
91
+ root.addEventListener(BROWSER.EVENTS.MOUSE_DOWN, this._onHold);
92
+ root.addEventListener(BROWSER.EVENTS.MOUSE_ENTER, this._onMouseEnter);
93
+ root.addEventListener(BROWSER.EVENTS.MOUSE_MOVE, this._onMouseMove);
94
+ root.addEventListener(BROWSER.EVENTS.MOUSE_LEAVE, this._onMouseLeave);
95
+ this._addFullscreenHandlers();
96
+
97
+ const video = viewer.mesh?.getTexture();
98
+ if (!video || !video.isVideo()) {
99
+ return;
100
+ }
101
+
102
+ if (video.isPaused()) {
103
+ this._controlBar.containerEl.classList.add(this._fixedClass);
104
+ }
105
+
106
+ video.source.addEventListener(BROWSER.EVENTS.VIDEO_PLAY, this._onVideoPlay);
107
+ video.source.addEventListener(BROWSER.EVENTS.VIDEO_PAUSE, this._onVideoPause);
108
+
109
+ this._video = video;
110
+ }
111
+
112
+ public disable(viewer: View360) {
113
+ if (!this._targetEl) return;
114
+
115
+ const controlBar = this._controlBar;
116
+ const root = viewer.rootEl;
117
+ const video = this._video;
118
+
119
+ root.removeEventListener(BROWSER.EVENTS.MOUSE_DOWN, this._onHold);
120
+ window.removeEventListener(BROWSER.EVENTS.MOUSE_UP, this._onRelease);
121
+ root.removeEventListener(BROWSER.EVENTS.MOUSE_ENTER, this._onMouseEnter);
122
+ root.removeEventListener(BROWSER.EVENTS.MOUSE_MOVE, this._onMouseMove);
123
+ root.removeEventListener(BROWSER.EVENTS.MOUSE_LEAVE, this._onMouseLeave);
124
+ this._removeFullscreenHandlers();
125
+
126
+ window.clearTimeout(this._timer);
127
+ controlBar.containerEl.classList.remove(this._fixedClass);
128
+
129
+ if (video) {
130
+ video.source.removeEventListener(BROWSER.EVENTS.VIDEO_PLAY, this._onVideoPlay);
131
+ video.source.removeEventListener(BROWSER.EVENTS.VIDEO_PAUSE, this._onVideoPause);
132
+ }
133
+
134
+ this._isCursorInside = false;
135
+ this._isGrabbing = false;
136
+ this._video = null;
137
+ this._targetEl = null;
138
+ }
139
+
140
+ public show() {
141
+ this._clearHideTimer();
142
+ this._controlBar.containerEl.classList.remove(this._hiddenClass);
143
+ }
144
+
145
+ public showTemporaliy() {
146
+ this.show();
147
+ this._hideAfterDelay(this._idleDelay);
148
+ }
149
+
150
+ public hide() {
151
+ this._clearHideTimer();
152
+ this._controlBar.containerEl.classList.add(this._hiddenClass);
153
+ }
154
+
155
+ private _clearHideTimer() {
156
+ if (this._timer) {
157
+ window.clearTimeout(this._timer);
158
+ this._timer = -1;
159
+ }
160
+ }
161
+
162
+ private _hideAfterDelay(delay = this._delay) {
163
+ if (this._isGrabbing || (!this._isFullscreen && this._isCursorInside)) return;
164
+
165
+ this._clearHideTimer();
166
+ if (delay <= 0) {
167
+ this.hide();
168
+ } else {
169
+ this._timer = window.setTimeout(() => {
170
+ this.hide();
171
+ }, delay);
172
+ }
173
+ }
174
+
175
+ private _onMouseEnter = () => {
176
+ this._isCursorInside = true;
177
+ this.show();
178
+ };
179
+
180
+ private _onMouseLeave = () => {
181
+ this._isCursorInside = false;
182
+ this._hideAfterDelay();
183
+ };
184
+
185
+ private _onMouseMove = () => {
186
+ if (!this._isFullscreen) return;
187
+
188
+ this.showTemporaliy();
189
+ }
190
+
191
+ private _onHold = (evt: PointerEvent) => {
192
+ this._isGrabbing = true;
193
+
194
+ if (evt.pointerType === "mouse") {
195
+ this._isCursorInside = true;
196
+ }
197
+
198
+ window.addEventListener(BROWSER.EVENTS.MOUSE_UP, this._onRelease);
199
+
200
+ this.show();
201
+ };
202
+
203
+ private _onRelease = () => {
204
+ this._isGrabbing = false;
205
+
206
+ window.removeEventListener(BROWSER.EVENTS.MOUSE_UP, this._onRelease);
207
+
208
+ this._hideAfterDelay();
209
+ };
210
+
211
+ private _onVideoPlay = () => {
212
+ const root = this._targetEl;
213
+ if (!root) return;
214
+
215
+ this._controlBar.containerEl.classList.remove(this._fixedClass);
216
+ };
217
+
218
+ private _onVideoPause = () => {
219
+ const root = this._targetEl;
220
+ if (!root) return;
221
+
222
+ this._controlBar.containerEl.classList.add(this._fixedClass);
223
+ };
224
+
225
+ private _addFullscreenHandlers() {
226
+ FULLSCREEN_CHANGE.forEach(evtName => {
227
+ document.addEventListener(evtName, this._onFullscreenChange);
228
+ });
229
+ }
230
+
231
+ private _removeFullscreenHandlers() {
232
+ FULLSCREEN_CHANGE.forEach(evtName => {
233
+ document.removeEventListener(evtName, this._onFullscreenChange);
234
+ });
235
+ }
236
+
237
+ private _onFullscreenChange = () => {
238
+ this._isFullscreen = isFullscreen();
239
+
240
+ if (this._isFullscreen) {
241
+ this._hideAfterDelay();
242
+ }
243
+ };
244
+ }
245
+
246
+ export default AutoHide;