@shopware-ag/dive 1.19.0 → 1.19.1-beta.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 (197) hide show
  1. package/build/dive.cjs +388 -220
  2. package/build/dive.cjs.map +1 -1
  3. package/build/dive.js +395 -21946
  4. package/build/dive.js.map +1 -1
  5. package/build/dive.mjs +28206 -0
  6. package/build/dive.mjs.map +1 -0
  7. package/build/src/ar/AR.d.ts +37 -14
  8. package/build/src/ar/arquicklook/ARQuickLook.d.ts +5 -6
  9. package/build/src/ar/sceneviewer/SceneViewer.d.ts +42 -6
  10. package/build/src/com/actions/scene/launchar.d.ts +5 -2
  11. package/build/src/converter/Converter.d.ts +21 -0
  12. package/build/src/dive.d.ts +3 -2
  13. package/build/src/exporter/Exporter.d.ts +11 -0
  14. package/build/src/helper/applyMixins/applyMixins.d.ts +22 -6
  15. package/build/src/info/Info.d.ts +37 -13
  16. package/build/src/interface/Movable.d.ts +5 -5
  17. package/build/src/interface/Selectable.d.ts +4 -4
  18. package/build/src/loader/Loader.d.ts +11 -0
  19. package/build/src/model/Model.d.ts +2 -2
  20. package/build/src/node/Node.d.ts +3 -3
  21. package/build/src/scene/root/Root.d.ts +1 -1
  22. package/build/src/types/ExporterOptions.d.ts +15 -0
  23. package/build/src/types/FileTypes.d.ts +27 -0
  24. package/build/src/types/index.d.ts +4 -0
  25. package/build/src/types/info/index.d.ts +66 -0
  26. package/package.json +17 -3
  27. package/build/src/exporters/usdz/USDZExporter.d.ts +0 -15
  28. package/build/src/loadingmanager/LoadingManager.d.ts +0 -14
  29. package/src/__test__/DIVE.test.ts +0 -274
  30. package/src/animation/AnimationSystem.ts +0 -34
  31. package/src/animation/__test__/AnimationSystem.test.ts +0 -40
  32. package/src/ar/AR.ts +0 -98
  33. package/src/ar/__test__/AR.test.ts +0 -187
  34. package/src/ar/arquicklook/ARQuickLook.ts +0 -93
  35. package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -93
  36. package/src/ar/sceneviewer/SceneViewer.ts +0 -74
  37. package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -93
  38. package/src/ar/webxr/WebXR.ts +0 -176
  39. package/src/ar/webxr/controller/WebXRController.ts +0 -340
  40. package/src/ar/webxr/crosshair/WebXRCrosshair.ts +0 -35
  41. package/src/ar/webxr/origin/WebXROrigin.ts +0 -192
  42. package/src/ar/webxr/overlay/Overlay.ts +0 -50
  43. package/src/ar/webxr/raycaster/WebXRRaycaster.ts +0 -131
  44. package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +0 -102
  45. package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +0 -49
  46. package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +0 -356
  47. package/src/axiscamera/AxisCamera.ts +0 -108
  48. package/src/axiscamera/__test__/AxisCamera.test.ts +0 -150
  49. package/src/camera/PerspectiveCamera.ts +0 -63
  50. package/src/camera/__test__/PerspectiveCamera.test.ts +0 -36
  51. package/src/com/Communication.ts +0 -808
  52. package/src/com/__test__/Communication.test.ts +0 -1024
  53. package/src/com/actions/camera/computeencompassingview.ts +0 -10
  54. package/src/com/actions/camera/getcameratransform.ts +0 -10
  55. package/src/com/actions/camera/movecamera.ts +0 -18
  56. package/src/com/actions/camera/resetcamera.ts +0 -5
  57. package/src/com/actions/camera/setcameralayer.ts +0 -5
  58. package/src/com/actions/camera/setcameratransform.ts +0 -10
  59. package/src/com/actions/camera/zoomcamera.ts +0 -5
  60. package/src/com/actions/index.ts +0 -61
  61. package/src/com/actions/media/generatemedia.ts +0 -18
  62. package/src/com/actions/object/addobject.ts +0 -7
  63. package/src/com/actions/object/deleteobject.ts +0 -7
  64. package/src/com/actions/object/deselectobject.ts +0 -7
  65. package/src/com/actions/object/getallobjects.ts +0 -7
  66. package/src/com/actions/object/getobjects.ts +0 -7
  67. package/src/com/actions/object/model/dropit.ts +0 -5
  68. package/src/com/actions/object/model/modelloaded.ts +0 -5
  69. package/src/com/actions/object/model/placeonfloor.ts +0 -5
  70. package/src/com/actions/object/selectobject.ts +0 -7
  71. package/src/com/actions/object/setparent.ts +0 -10
  72. package/src/com/actions/object/updateobject.ts +0 -7
  73. package/src/com/actions/renderer/startrender.ts +0 -5
  74. package/src/com/actions/scene/exportscene.ts +0 -7
  75. package/src/com/actions/scene/getallscenedata.ts +0 -7
  76. package/src/com/actions/scene/launchar.ts +0 -7
  77. package/src/com/actions/scene/setbackground.ts +0 -5
  78. package/src/com/actions/scene/updatescene.ts +0 -11
  79. package/src/com/actions/toolbox/select/setgizmomode.ts +0 -5
  80. package/src/com/actions/toolbox/transform/setgizmoscalelinked.ts +0 -5
  81. package/src/com/actions/toolbox/transform/setgizmovisible.ts +0 -5
  82. package/src/com/actions/toolbox/usetool.ts +0 -7
  83. package/src/com/types/COMBaseEntity.ts +0 -9
  84. package/src/com/types/COMEntity.ts +0 -7
  85. package/src/com/types/COMEntityType.ts +0 -1
  86. package/src/com/types/COMGeometry.ts +0 -8
  87. package/src/com/types/COMGeometryType.ts +0 -9
  88. package/src/com/types/COMGroup.ts +0 -9
  89. package/src/com/types/COMLight.ts +0 -11
  90. package/src/com/types/COMMaterial.ts +0 -12
  91. package/src/com/types/COMModel.ts +0 -12
  92. package/src/com/types/COMPov.ts +0 -8
  93. package/src/com/types/COMPrimitive.ts +0 -12
  94. package/src/com/types/index.ts +0 -23
  95. package/src/constant/AxisHelperColors.ts +0 -7
  96. package/src/constant/GridColors.ts +0 -2
  97. package/src/constant/VisibilityLayerMask.ts +0 -5
  98. package/src/controls/OrbitControls.ts +0 -211
  99. package/src/controls/__test__/OrbitControls.test.ts +0 -256
  100. package/src/dive.ts +0 -363
  101. package/src/events/EventExecutor.ts +0 -35
  102. package/src/exporters/usdz/USDZExporter.ts +0 -21
  103. package/src/exporters/usdz/__test__/USDZExporter.test.ts +0 -57
  104. package/src/gizmo/Gizmo.ts +0 -144
  105. package/src/gizmo/handles/AxisHandle.ts +0 -153
  106. package/src/gizmo/handles/RadialHandle.ts +0 -149
  107. package/src/gizmo/handles/ScaleHandle.ts +0 -195
  108. package/src/gizmo/plane/GizmoPlane.ts +0 -84
  109. package/src/gizmo/rotate/RotateGizmo.ts +0 -143
  110. package/src/gizmo/scale/ScaleGizmo.ts +0 -125
  111. package/src/gizmo/translate/TranslateGizmo.ts +0 -114
  112. package/src/grid/Grid.ts +0 -34
  113. package/src/grid/__test__/Grid.test.ts +0 -28
  114. package/src/group/Group.ts +0 -184
  115. package/src/group/__test__/Group.test.ts +0 -212
  116. package/src/helper/applyMixins/__test__/applyMixins.test.ts +0 -30
  117. package/src/helper/applyMixins/applyMixins.ts +0 -18
  118. package/src/helper/findInterface/__test__/findInterface.test.ts +0 -63
  119. package/src/helper/findInterface/findInterface.ts +0 -13
  120. package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +0 -40
  121. package/src/helper/findSceneRecursive/findSceneRecursive.ts +0 -16
  122. package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +0 -186
  123. package/src/helper/getObjectDelta/getObjectDelta.ts +0 -105
  124. package/src/helper/isInterface/__test__/implementsInterface.test.ts +0 -19
  125. package/src/helper/isInterface/implementsInterface.ts +0 -9
  126. package/src/info/Info.ts +0 -154
  127. package/src/info/__test__/Info.test.ts +0 -338
  128. package/src/interface/Draggable.ts +0 -14
  129. package/src/interface/Hoverable.ts +0 -14
  130. package/src/interface/Movable.ts +0 -12
  131. package/src/interface/Rotatable.ts +0 -10
  132. package/src/interface/Scalable.ts +0 -10
  133. package/src/interface/Selectable.ts +0 -11
  134. package/src/io/IO.ts +0 -62
  135. package/src/io/__test__/IO.test.ts +0 -116
  136. package/src/io/gltf/GLTFIO.ts +0 -56
  137. package/src/io/gltf/__test__/GLTFIO.test.ts +0 -108
  138. package/src/light/AmbientLight.ts +0 -39
  139. package/src/light/PointLight.ts +0 -115
  140. package/src/light/SceneLight.ts +0 -63
  141. package/src/light/__test__/AmbientLight.test.ts +0 -29
  142. package/src/light/__test__/PointLight.test.ts +0 -74
  143. package/src/light/__test__/SceneLight.test.ts +0 -47
  144. package/src/loadingmanager/LoadingManager.ts +0 -50
  145. package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -27
  146. package/src/math/__test__/DIVEMath.test.ts +0 -12
  147. package/src/math/ceil/__test__/ceilExp.test.ts +0 -12
  148. package/src/math/ceil/ceilExp.ts +0 -6
  149. package/src/math/degToRad/__test__/degToRad.test.ts +0 -172
  150. package/src/math/degToRad/degToRad.ts +0 -5
  151. package/src/math/floor/__test__/floorExp.test.ts +0 -14
  152. package/src/math/floor/floorExp.ts +0 -6
  153. package/src/math/helper/__test__/shift.test.ts +0 -12
  154. package/src/math/helper/shift.ts +0 -4
  155. package/src/math/index.ts +0 -28
  156. package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -155
  157. package/src/math/radToDeg/radToDeg.ts +0 -5
  158. package/src/math/round/__test__/roundExp.test.ts +0 -14
  159. package/src/math/round/roundExp.ts +0 -10
  160. package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +0 -20
  161. package/src/math/signedAngleTo/signedAngleTo.ts +0 -20
  162. package/src/math/toFixed/__test__/toFixedExp.test.ts +0 -14
  163. package/src/math/toFixed/toFixedExp.ts +0 -9
  164. package/src/math/truncate/__test__/truncateExp.test.ts +0 -14
  165. package/src/math/truncate/truncateExp.ts +0 -9
  166. package/src/mediacreator/MediaCreator.ts +0 -75
  167. package/src/mediacreator/__test__/MediaCreator.test.ts +0 -155
  168. package/src/model/Model.ts +0 -185
  169. package/src/model/__test__/Model.test.ts +0 -222
  170. package/src/module/Module.ts +0 -45
  171. package/src/module/__test__/Module.test.ts +0 -54
  172. package/src/node/Node.ts +0 -98
  173. package/src/node/__test__/Node.test.ts +0 -120
  174. package/src/primitive/Primitive.ts +0 -299
  175. package/src/primitive/__test__/Primitive.test.ts +0 -281
  176. package/src/primitive/floor/Floor.ts +0 -45
  177. package/src/primitive/floor/__test__/Floor.test.ts +0 -24
  178. package/src/renderer/Renderer.ts +0 -215
  179. package/src/renderer/__test__/Renderer.test.ts +0 -228
  180. package/src/scene/Scene.ts +0 -106
  181. package/src/scene/__test__/Scene.test.ts +0 -124
  182. package/src/scene/root/Root.ts +0 -426
  183. package/src/scene/root/__test__/Root.test.ts +0 -903
  184. package/src/scene/xrroot/XRRoot.ts +0 -56
  185. package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +0 -80
  186. package/src/toolbox/BaseTool.ts +0 -319
  187. package/src/toolbox/Toolbox.ts +0 -129
  188. package/src/toolbox/__test__/BaseTool.test.ts +0 -627
  189. package/src/toolbox/__test__/Toolbox.test.ts +0 -143
  190. package/src/toolbox/select/SelectTool.ts +0 -92
  191. package/src/toolbox/select/__test__/SelectTool.test.ts +0 -237
  192. package/src/toolbox/transform/TransformTool.ts +0 -166
  193. package/src/toolbox/transform/__test__/TransformTool.test.ts +0 -147
  194. package/src/types/SceneData.ts +0 -26
  195. package/src/types/SceneObjects.ts +0 -14
  196. package/src/types/SceneType.ts +0 -14
  197. package/src/types/index.ts +0 -5
@@ -1,27 +0,0 @@
1
- import { DIVELoadingManager } from '../LoadingManager';
2
-
3
- describe('dive/loadingmanager/DIVELoadingManager', () => {
4
- it('should instantiate', () => {
5
- const testLight = new DIVELoadingManager();
6
- expect(testLight).toBeDefined();
7
- });
8
-
9
- it('should return GLTF promise', () => {
10
- const testLight = new DIVELoadingManager();
11
- const promise = testLight.LoadGLTF('test.gltf');
12
- expect(promise).toBeDefined();
13
- });
14
-
15
- it('should return progress', () => {
16
- const testLight = new DIVELoadingManager();
17
- testLight.LoadGLTF('test.gltf');
18
- const progress = testLight.PollProgress();
19
- expect(progress).toBe(0);
20
- });
21
-
22
- it('should return done progress without load', () => {
23
- const testLight = new DIVELoadingManager();
24
- const progress = testLight.PollProgress();
25
- expect(progress).toBe(1);
26
- });
27
- });
@@ -1,12 +0,0 @@
1
- import { DIVEMath } from '../index';
2
-
3
- describe('dive/math', () => {
4
- it('should be defined', () => {
5
- expect(DIVEMath).toBeDefined();
6
- expect(DIVEMath.ceilExp).toBeDefined();
7
- expect(DIVEMath.floorExp).toBeDefined();
8
- expect(DIVEMath.roundExp).toBeDefined();
9
- expect(DIVEMath.toFixedExp).toBeDefined();
10
- expect(DIVEMath.truncateExp).toBeDefined();
11
- });
12
- });
@@ -1,12 +0,0 @@
1
- import ceilExp from '../ceilExp';
2
-
3
- describe('dive/math/ceil/ceilExp', () => {
4
- it('should ceilExp', () => {
5
- expect(ceilExp(-0.5)).toBe(0);
6
- expect(ceilExp(0.5)).toBe(1);
7
- expect(ceilExp(0.55)).toBe(1);
8
- expect(ceilExp(0.49)).toBe(1);
9
- expect(ceilExp(0.49, 2)).toBe(0.49);
10
- expect(ceilExp(-1.49, 2)).toBe(-1.49);
11
- });
12
- });
@@ -1,6 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function ceilExp(number: number, decimals: number = 0): number {
4
- const n = shift(number, +decimals);
5
- return shift(Math.ceil(n), -decimals);
6
- }
@@ -1,172 +0,0 @@
1
- import degToRad from '../degToRad';
2
- import { MathUtils } from 'three';
3
-
4
- // Type assertion for the mocked MathUtils.degToRad
5
- const mockedDegToRad = MathUtils.degToRad as jest.Mock;
6
-
7
- /**
8
- * Test Suite for degToRad Function
9
- */
10
- describe('degToRad', () => {
11
- beforeEach(() => {
12
- // Clear all previous mock calls and implementations before each test
13
- mockedDegToRad.mockClear();
14
- });
15
-
16
- it('should convert 0 degrees to 0 radians', () => {
17
- // Arrange
18
- mockedDegToRad.mockReturnValue(0);
19
-
20
- // Act
21
- const result = degToRad(0);
22
-
23
- // Assert
24
- expect(MathUtils.degToRad).toHaveBeenCalledWith(0);
25
- expect(result).toBe(0);
26
- });
27
-
28
- it('should convert 180 degrees to π radians', () => {
29
- // Arrange
30
- const degrees = 180;
31
- const radians = Math.PI;
32
- mockedDegToRad.mockReturnValue(radians);
33
-
34
- // Act
35
- const result = degToRad(degrees);
36
-
37
- // Assert
38
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
39
- expect(result).toBe(radians);
40
- });
41
-
42
- it('should convert 360 degrees to 2π radians', () => {
43
- // Arrange
44
- const degrees = 360;
45
- const radians = 2 * Math.PI;
46
- mockedDegToRad.mockReturnValue(radians);
47
-
48
- // Act
49
- const result = degToRad(degrees);
50
-
51
- // Assert
52
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
53
- expect(result).toBe(radians);
54
- });
55
-
56
- it('should convert 90 degrees to π/2 radians', () => {
57
- // Arrange
58
- const degrees = 90;
59
- const radians = Math.PI / 2;
60
- mockedDegToRad.mockReturnValue(radians);
61
-
62
- // Act
63
- const result = degToRad(degrees);
64
-
65
- // Assert
66
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
67
- expect(result).toBe(radians);
68
- });
69
-
70
- it('should convert 45 degrees to π/4 radians', () => {
71
- // Arrange
72
- const degrees = 45;
73
- const radians = Math.PI / 4;
74
- mockedDegToRad.mockReturnValue(radians);
75
-
76
- // Act
77
- const result = degToRad(degrees);
78
-
79
- // Assert
80
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
81
- expect(result).toBe(radians);
82
- });
83
-
84
- it('should handle multiple calls with different degrees', () => {
85
- // Arrange
86
- const degrees1 = 30;
87
- const radians1 = Math.PI / 6;
88
- const degrees2 = 60;
89
- const radians2 = Math.PI / 3;
90
- const degrees3 = 120;
91
- const radians3 = (2 * Math.PI) / 3;
92
-
93
- mockedDegToRad
94
- .mockReturnValueOnce(radians1)
95
- .mockReturnValueOnce(radians2)
96
- .mockReturnValueOnce(radians3);
97
-
98
- // Act
99
- const result1 = degToRad(degrees1);
100
- const result2 = degToRad(degrees2);
101
- const result3 = degToRad(degrees3);
102
-
103
- // Assert
104
- expect(MathUtils.degToRad).toHaveBeenNthCalledWith(1, degrees1);
105
- expect(MathUtils.degToRad).toHaveBeenNthCalledWith(2, degrees2);
106
- expect(MathUtils.degToRad).toHaveBeenNthCalledWith(3, degrees3);
107
-
108
- expect(result1).toBe(radians1);
109
- expect(result2).toBe(radians2);
110
- expect(result3).toBe(radians3);
111
- });
112
-
113
- it('should handle edge case of degrees just below 360', () => {
114
- // Arrange
115
- const degrees = 359.999;
116
- const radians = MathUtils.degToRad(degrees);
117
- mockedDegToRad.mockReturnValue(radians);
118
-
119
- // Act
120
- const result = degToRad(degrees);
121
-
122
- // Assert
123
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
124
- expect(result).toBe(radians);
125
- });
126
-
127
- it('should not allow negative degrees', () => {
128
- // Arrange
129
- const degrees = -45;
130
- const radians = MathUtils.degToRad(degrees);
131
- mockedDegToRad.mockReturnValue(radians);
132
-
133
- // Act
134
- const result = degToRad(degrees);
135
-
136
- // Assert
137
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
138
- expect(result).toBe(radians);
139
- // Depending on implementation, you might want to expect an error
140
- // or handle negative degrees differently. Adjust assertions accordingly.
141
- });
142
-
143
- it('should handle undefined degrees gracefully', () => {
144
- // Arrange
145
- const degrees = undefined;
146
- // Since the function expects a number, this might throw an error or pass undefined
147
- mockedDegToRad.mockReturnValue(NaN);
148
-
149
- // Act
150
- // @ts-ignore: Testing undefined input
151
- const result = degToRad(degrees);
152
-
153
- // Assert
154
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
155
- expect(result).toBe(NaN);
156
- });
157
-
158
- it('should handle null degrees gracefully', () => {
159
- // Arrange
160
- const degrees = null;
161
- // Depending on implementation, this might throw an error or pass null
162
- mockedDegToRad.mockReturnValue(NaN);
163
-
164
- // Act
165
- // @ts-ignore: Testing null input
166
- const result = degToRad(degrees);
167
-
168
- // Assert
169
- expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
170
- expect(result).toBe(NaN);
171
- });
172
- });
@@ -1,5 +0,0 @@
1
- import { MathUtils } from 'three';
2
-
3
- export default function degToRad(degrees: number): number {
4
- return MathUtils.degToRad(degrees);
5
- }
@@ -1,14 +0,0 @@
1
- import floorExp from '../floorExp';
2
-
3
- describe('dive/math/floor/floorExp', () => {
4
- it('should floorExp', () => {
5
- expect(floorExp(-0.5)).toBe(-1);
6
- expect(floorExp(0.5)).toBe(0);
7
- expect(floorExp(0.55)).toBe(0);
8
- expect(floorExp(0.49)).toBe(0);
9
- expect(floorExp(1.49)).toBe(1);
10
- expect(floorExp(0.49, 2)).toBe(0.49);
11
- expect(floorExp(1.49, 2)).toBe(1.49);
12
- expect(floorExp(-1.49, 2)).toBe(-1.49);
13
- });
14
- });
@@ -1,6 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function floorExp(number: number, decimals: number = 0): number {
4
- const n = shift(number, +decimals);
5
- return shift(Math.floor(n), -decimals);
6
- }
@@ -1,12 +0,0 @@
1
- import shift from '../shift';
2
-
3
- describe('dive/math/helper/shift', () => {
4
- it('should shift', () => {
5
- expect(shift(0.5, 2)).toBe(50);
6
- expect(shift(0.55, 2)).toBe(55);
7
- expect(shift(0.49, 2)).toBe(49);
8
- expect(shift(1.49, 2)).toBe(149);
9
- expect(shift(0.49, 2)).toBe(49);
10
- expect(shift(1.49, 2)).toBe(149);
11
- });
12
- });
@@ -1,4 +0,0 @@
1
- export default function shift(value: number, exponent: number): number {
2
- const subvalues = (value + 'e').split('e');
3
- return +(subvalues[0] + 'e' + (+subvalues[1] + (exponent || 0)));
4
- }
package/src/math/index.ts DELETED
@@ -1,28 +0,0 @@
1
- import ceilExp from './ceil/ceilExp.ts';
2
- import floorExp from './floor/floorExp.ts';
3
- import roundExp from './round/roundExp.ts';
4
- import signedAngleTo from './signedAngleTo/signedAngleTo.ts';
5
- import toFixedExp from './toFixed/toFixedExp.ts';
6
- import truncateExp from './truncate/truncateExp.ts';
7
- import radToDeg from './radToDeg/radToDeg.ts';
8
- import degToRad from './degToRad/degToRad.ts';
9
-
10
- export const DIVEMath: {
11
- ceilExp: typeof ceilExp;
12
- floorExp: typeof floorExp;
13
- roundExp: typeof roundExp;
14
- toFixedExp: typeof toFixedExp;
15
- truncateExp: typeof truncateExp;
16
- signedAngleTo: typeof signedAngleTo;
17
- radToDeg: typeof radToDeg;
18
- degToRad: typeof degToRad;
19
- } = {
20
- ceilExp,
21
- floorExp,
22
- roundExp,
23
- toFixedExp,
24
- truncateExp,
25
- signedAngleTo,
26
- radToDeg,
27
- degToRad,
28
- };
@@ -1,155 +0,0 @@
1
- import radToDeg from '../radToDeg';
2
- import { MathUtils } from 'three';
3
-
4
- // Type assertion for the mocked MathUtils.radToDeg
5
- const mockedRadToDeg = MathUtils.radToDeg as jest.Mock;
6
-
7
- /**
8
- * Test Suite for radToDeg Function
9
- */
10
- describe('radToDeg', () => {
11
- beforeEach(() => {
12
- // Clear all previous mock calls and implementations before each test
13
- mockedRadToDeg.mockClear();
14
- });
15
-
16
- it('should convert 0 radians to 0 degrees', () => {
17
- // Arrange
18
- mockedRadToDeg.mockReturnValue(0);
19
-
20
- // Act
21
- const result = radToDeg(0);
22
-
23
- // Assert
24
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(0);
25
- expect(result).toBe(0);
26
- });
27
-
28
- it('should convert π radians to 180 degrees', () => {
29
- // Arrange
30
- const pi = Math.PI;
31
- mockedRadToDeg.mockReturnValue(180);
32
-
33
- // Act
34
- const result = radToDeg(pi);
35
-
36
- // Assert
37
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(pi);
38
- expect(result).toBe(180);
39
- });
40
-
41
- it('should convert 2π radians to 0 degrees (wrapped)', () => {
42
- // Arrange
43
- const twoPi = 2 * Math.PI;
44
- mockedRadToDeg.mockReturnValue(360);
45
-
46
- // Act
47
- const result = radToDeg(twoPi);
48
-
49
- // Assert
50
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(twoPi);
51
- expect(result).toBe(0);
52
- });
53
-
54
- it('should convert 3π/2 radians to 270 degrees', () => {
55
- // Arrange
56
- const threePiOver2 = (3 * Math.PI) / 2;
57
- mockedRadToDeg.mockReturnValue(270);
58
-
59
- // Act
60
- const result = radToDeg(threePiOver2);
61
-
62
- // Assert
63
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(threePiOver2);
64
- expect(result).toBe(270);
65
- });
66
-
67
- it('should handle angles greater than 2π radians correctly', () => {
68
- // Arrange
69
- const sevenPi = 7 * Math.PI; // 1260 degrees
70
- const expectedDegrees = (1260 + 360) % 360; // 180 degrees
71
- mockedRadToDeg.mockReturnValue(1260);
72
-
73
- // Act
74
- const result = radToDeg(sevenPi);
75
-
76
- // Assert
77
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(sevenPi);
78
- expect(result).toBe(expectedDegrees);
79
- });
80
-
81
- it('should handle fractional radians correctly', () => {
82
- // Arrange
83
- const fractionalRadians = Math.PI / 4; // 45 degrees
84
- mockedRadToDeg.mockReturnValue(45);
85
-
86
- // Act
87
- const result = radToDeg(fractionalRadians);
88
-
89
- // Assert
90
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(fractionalRadians);
91
- expect(result).toBe(45);
92
- });
93
-
94
- it('should wrap negative angles correctly', () => {
95
- // Since the function does not handle negative inputs, this test ensures it behaves as expected
96
- // However, based on initial requirements, negative degrees are not allowed and inputs are non-negative
97
- // This test is optional and based on how you want the function to behave
98
- const negativeRadians = -Math.PI / 2; // -90 degrees
99
- mockedRadToDeg.mockReturnValue(-90);
100
- const expectedDegrees = (-90 + 360) % 360; // 270 degrees
101
-
102
- const result = radToDeg(negativeRadians);
103
-
104
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(negativeRadians);
105
- expect(result).toBe(expectedDegrees);
106
- });
107
-
108
- it('should handle multiple full rotations correctly', () => {
109
- // Arrange
110
- const multipleRotations = 5 * 2 * Math.PI; // 360 * 5 = 1800 degrees
111
- const expectedDegrees = (1800 + 360) % 360; // 0 degrees
112
- mockedRadToDeg.mockReturnValue(1800);
113
-
114
- // Act
115
- const result = radToDeg(multipleRotations);
116
-
117
- // Assert
118
- expect(MathUtils.radToDeg).toHaveBeenCalledWith(multipleRotations);
119
- expect(result).toBe(0);
120
- });
121
-
122
- it('should handle mixed angles', () => {
123
- // Arrange
124
- const angles = [
125
- Math.PI / 6,
126
- Math.PI,
127
- (5 * Math.PI) / 3,
128
- ];
129
- const mockReturns = [
130
- 30,
131
- 180,
132
- 300,
133
- ];
134
- const expectedDegrees = [
135
- (30 + 360) % 360,
136
- (180 + 360) % 360,
137
- (300 + 360) % 360,
138
- ]; // [30, 180, 300]
139
-
140
- mockedRadToDeg
141
- .mockReturnValueOnce(mockReturns[0])
142
- .mockReturnValueOnce(mockReturns[1])
143
- .mockReturnValueOnce(mockReturns[2]);
144
-
145
- // Act & Assert for each angle
146
- angles.forEach((angle, index) => {
147
- const result = radToDeg(angle);
148
- expect(MathUtils.radToDeg).toHaveBeenNthCalledWith(
149
- index + 1,
150
- angle,
151
- );
152
- expect(result).toBe(expectedDegrees[index]);
153
- });
154
- });
155
- });
@@ -1,5 +0,0 @@
1
- import { MathUtils } from 'three';
2
-
3
- export default function radToDeg(radians: number): number {
4
- return (MathUtils.radToDeg(radians) + 360) % 360;
5
- }
@@ -1,14 +0,0 @@
1
- import roundExp from '../roundExp';
2
-
3
- describe('dive/math/round/roundExp', () => {
4
- it('should roundExp', () => {
5
- expect(roundExp(-0.5)).toBe(-1);
6
- expect(roundExp(0.5)).toBe(1);
7
- expect(roundExp(0.55)).toBe(1);
8
- expect(roundExp(0.49)).toBe(0);
9
- expect(roundExp(1.49)).toBe(1);
10
- expect(roundExp(0.49, 2)).toBe(0.49);
11
- expect(roundExp(1.49, 2)).toBe(1.49);
12
- expect(roundExp(-1.49, 2)).toBe(-1.49);
13
- });
14
- });
@@ -1,10 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function roundExponential(
4
- number: number,
5
- decimals: number = 0,
6
- ): number {
7
- if (number < 0) return -roundExponential(-number, decimals);
8
- const n = shift(number, +decimals);
9
- return shift(Math.round(n), -decimals);
10
- }
@@ -1,20 +0,0 @@
1
- import { Vector3 } from 'three';
2
- import signedAngleTo from '../signedAngleTo';
3
-
4
- describe('dive/math/signedAngleTo', () => {
5
- it('should signedAngleTo', () => {
6
- const planeNormal = new Vector3(0, 0, 1);
7
- const a = new Vector3(1, 0, 0);
8
- expect(signedAngleTo(a, new Vector3(1, 0, 0), planeNormal)).toBe(0);
9
- expect(signedAngleTo(a, new Vector3(0, 1, 0), planeNormal)).toBe(
10
- Math.PI / 2,
11
- );
12
- expect(signedAngleTo(a, new Vector3(-1, 0, 0), planeNormal)).toBe(
13
- Math.PI,
14
- );
15
- expect(signedAngleTo(a, new Vector3(0, -1, 0), planeNormal)).toBe(
16
- -Math.PI / 2,
17
- );
18
- expect(signedAngleTo(a, planeNormal, planeNormal)).toBe(0);
19
- });
20
- });
@@ -1,20 +0,0 @@
1
- import { Vector3 } from 'three';
2
-
3
- /**
4
- * Calculate the signed angle between two vectors. Only works when the vectors are on the same plane.
5
- * @param vecB Start Vector
6
- * @param vecA Target Vector
7
- * @param planeNormal The vector's plane normal
8
- * @returns Signed angle in radians
9
- */
10
-
11
- export default function signedAngleTo(
12
- vecA: Vector3,
13
- vecB: Vector3,
14
- planeNormal: Vector3,
15
- ): number {
16
- return Math.atan2(
17
- vecA.clone().cross(vecB).dot(planeNormal),
18
- vecB.clone().dot(vecA),
19
- );
20
- }
@@ -1,14 +0,0 @@
1
- import toFixedExp from '../toFixedExp';
2
-
3
- describe('dive/math/toFixed/toFixedExp', () => {
4
- it('should toFixedExp', () => {
5
- expect(toFixedExp(-0.5)).toBe('0');
6
- expect(toFixedExp(0.5)).toBe('1');
7
- expect(toFixedExp(0.55)).toBe('1');
8
- expect(toFixedExp(0.49)).toBe('0');
9
- expect(toFixedExp(1.49)).toBe('1');
10
- expect(toFixedExp(0.49, 2)).toBe('0.49');
11
- expect(toFixedExp(1.49, 2)).toBe('1.49');
12
- expect(toFixedExp(-1.49, 2)).toBe('-1.49');
13
- });
14
- });
@@ -1,9 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function toFixedExp(
4
- number: number,
5
- decimals: number = 0,
6
- ): string {
7
- const n = shift(number, +decimals);
8
- return shift(Math.round(n), -decimals).toFixed(decimals);
9
- }
@@ -1,14 +0,0 @@
1
- import truncateExp from '../truncateExp';
2
-
3
- describe('dive/math/truncate/truncateExp', () => {
4
- it('should truncateExp', () => {
5
- expect(truncateExp(-0.5)).toBe(0);
6
- expect(truncateExp(0.5)).toBe(0);
7
- expect(truncateExp(0.55)).toBe(0);
8
- expect(truncateExp(0.49)).toBe(0);
9
- expect(truncateExp(1.49)).toBe(1);
10
- expect(truncateExp(0.49, 2)).toBe(0.49);
11
- expect(truncateExp(1.49, 2)).toBe(1.49);
12
- expect(truncateExp(-1.49, 2)).toBe(-1.49);
13
- });
14
- });
@@ -1,9 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function truncateExp(
4
- number: number,
5
- decimals: number = 0,
6
- ): number {
7
- const n = shift(number, +decimals);
8
- return shift(Math.trunc(n), -decimals);
9
- }
@@ -1,75 +0,0 @@
1
- import DIVEPerspectiveCamera from '../camera/PerspectiveCamera.ts';
2
- import { type DIVEScene } from '../scene/Scene.ts';
3
- import { type DIVERenderer } from '../renderer/Renderer.ts';
4
- import type DIVEOrbitControls from '../controls/OrbitControls.ts';
5
- import { type Vector3Like } from 'three';
6
-
7
- /**
8
- * Creates renderings of the current scene
9
- *
10
- * @module
11
- */
12
-
13
- export class DIVEMediaCreator {
14
- private renderer: DIVERenderer;
15
- private scene: DIVEScene;
16
- private controller: DIVEOrbitControls;
17
-
18
- constructor(
19
- renderer: DIVERenderer,
20
- scene: DIVEScene,
21
- controller: DIVEOrbitControls,
22
- ) {
23
- this.renderer = renderer;
24
- this.scene = scene;
25
- this.controller = controller;
26
- }
27
-
28
- public GenerateMedia(
29
- position: Vector3Like,
30
- target: Vector3Like,
31
- width: number,
32
- height: number,
33
- ): string {
34
- const resetPosition = this.controller.object.position.clone();
35
- const resetRotation = this.controller.object.quaternion.clone();
36
-
37
- this.renderer.OnResize(width, height);
38
- this.controller.object.OnResize(width, height);
39
-
40
- this.controller.object.position.copy(position);
41
- this.controller.target.copy(target);
42
- this.controller.update();
43
-
44
- const dataUri = this.DrawCanvas().toDataURL();
45
-
46
- this.controller.object.position.copy(resetPosition);
47
- this.controller.object.quaternion.copy(resetRotation);
48
-
49
- return dataUri;
50
- }
51
-
52
- public DrawCanvas(canvasElement?: HTMLCanvasElement): HTMLCanvasElement {
53
- // save current canvas
54
- const restore = this.renderer.domElement;
55
- if (canvasElement) {
56
- this.renderer.domElement = canvasElement;
57
- }
58
-
59
- // draw canvas
60
- this.controller.object.layers.mask =
61
- DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
62
- this.renderer.render(this.scene, this.controller.object);
63
- this.controller.object.layers.mask =
64
- DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
65
-
66
- const returnCanvas = this.renderer.domElement;
67
-
68
- // restore canvas
69
- if (canvasElement) {
70
- this.renderer.domElement = restore;
71
- }
72
-
73
- return returnCanvas;
74
- }
75
- }