@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,212 +0,0 @@
1
- import { Object3D, type Vector3Like } from 'three';
2
- import { DIVECommunication } from '../../com/Communication';
3
- import { type DIVENode } from '../../node/Node';
4
- import { DIVEGroup } from '../Group';
5
-
6
- jest.mock('../../com/Communication.ts', () => {
7
- return {
8
- DIVECommunication: {
9
- get: jest.fn(() => {
10
- return {
11
- PerformAction: jest.fn(),
12
- };
13
- }),
14
- },
15
- };
16
- });
17
-
18
- jest.spyOn(DIVECommunication, 'get').mockReturnValue({
19
- PerformAction: jest.fn(),
20
- } as unknown as DIVECommunication);
21
-
22
- let group: DIVEGroup;
23
-
24
- Object3D.prototype.attach = jest.fn();
25
-
26
- describe('dive/group/DIVEGroup', () => {
27
- beforeEach(() => {
28
- group = new DIVEGroup();
29
- });
30
-
31
- afterEach(() => {
32
- jest.clearAllMocks();
33
- });
34
-
35
- it('should instantiate', () => {
36
- expect(group).toBeDefined();
37
- });
38
-
39
- it('should add an object', () => {
40
- const mockObject = new DIVEGroup();
41
-
42
- expect(() => group.attach(mockObject)).not.toThrow();
43
- expect(group.members).toContainEqual(
44
- expect.objectContaining(mockObject),
45
- );
46
-
47
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
48
- expect(() => group.attach(mockObject)).not.toThrow();
49
- });
50
-
51
- it('should remove an object', () => {
52
- const mockObject = new DIVEGroup();
53
-
54
- expect(() => group.remove(mockObject)).not.toThrow();
55
- expect(group.children).not.toContain(mockObject);
56
- expect(group.members).not.toContain(mockObject);
57
-
58
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
59
- expect(() => group.remove(mockObject)).not.toThrow();
60
- });
61
-
62
- it('should set lines visibility', () => {
63
- expect(() => group.SetLinesVisibility(true)).not.toThrow();
64
-
65
- const mockObject = new DIVEGroup();
66
- expect(() => group.SetLinesVisibility(false, mockObject)).not.toThrow();
67
-
68
- expect(() => group.attach(mockObject)).not.toThrow();
69
- expect(() => group.SetLinesVisibility(false)).not.toThrow();
70
-
71
- expect(() => group.SetLinesVisibility(true, mockObject)).not.toThrow();
72
- });
73
-
74
- it('update lines', () => {
75
- const mockObject = new DIVEGroup();
76
- expect(() => group.UpdateLineTo(mockObject)).not.toThrow();
77
-
78
- expect(() => group.attach(mockObject)).not.toThrow();
79
- expect(() => group.UpdateLineTo(mockObject)).not.toThrow();
80
- });
81
-
82
- it('should onMove', () => {
83
- group.userData.id = 'something';
84
-
85
- expect(() => group.onMove()).not.toThrow();
86
-
87
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
88
- expect(() => group.onMove()).not.toThrow();
89
- });
90
-
91
- it('should onSelect', () => {
92
- group.userData.id = 'something';
93
-
94
- expect(() => group.onSelect()).not.toThrow();
95
-
96
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
97
- expect(() => group.onSelect()).not.toThrow();
98
- });
99
-
100
- it('should onDeselect', () => {
101
- group.userData.id = 'something';
102
-
103
- expect(() => group.onDeselect()).not.toThrow();
104
-
105
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
106
- expect(() => group.onDeselect()).not.toThrow();
107
- });
108
-
109
- it('should onMove', () => {
110
- group.userData.id = 'something';
111
-
112
- expect(() => group.onMove()).not.toThrow();
113
-
114
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
115
- expect(() => group.onMove()).not.toThrow();
116
- });
117
-
118
- it('should call onMove on members with isDIVENode', () => {
119
- // Create mock members
120
- const diveNode1: DIVENode = {
121
- isDIVENode: true,
122
- onMove: jest.fn(),
123
- } as unknown as DIVENode;
124
-
125
- const diveNode2: DIVENode = {
126
- isDIVENode: true,
127
- onMove: jest.fn(),
128
- } as unknown as DIVENode;
129
-
130
- const member1: DIVENode = {
131
- // Define other properties/methods if necessary
132
- } as unknown as DIVENode;
133
-
134
- const member2: DIVENode = {
135
- // Define other properties/methods if necessary
136
- } as unknown as DIVENode;
137
-
138
- // Assign the _members array (assuming it's protected or public for testing)
139
- // If _members is private, you might need to use a different approach or modify the class for testability
140
- (group as any)._members = [
141
- diveNode1,
142
- member1,
143
- diveNode2,
144
- member2,
145
- ];
146
-
147
- const position: Vector3Like = { x: 4, y: 5, z: 6 };
148
- group.SetPosition(position);
149
-
150
- // Check that onMove was called on diveNode1 and diveNode2
151
- expect(diveNode1.onMove).toHaveBeenCalled();
152
- expect(diveNode2.onMove).toHaveBeenCalled();
153
-
154
- // Ensure onMove was not called on other members
155
- // Since member1 and member2 don't have onMove, there's nothing to assert here
156
- // If members have onMove, you should mock and verify they are not called
157
- });
158
-
159
- it('should not call onMove on members without isDIVENode', () => {
160
- // Create mock members without isDIVENode
161
- const member1: DIVENode = {
162
- // Define other properties/methods if necessary
163
- } as unknown as DIVENode;
164
-
165
- const member2: DIVENode = {
166
- // Define other properties/methods if necessary
167
- } as unknown as DIVENode;
168
-
169
- // Assign the _members array
170
- (group as any)._members = [
171
- member1,
172
- member2,
173
- ];
174
-
175
- const position: Vector3Like = { x: 7, y: 8, z: 9 };
176
- group.SetPosition(position);
177
-
178
- // Since members do not have onMove, there's nothing to assert
179
- // If members have onMove as optional, you can spy on them to ensure they're not called
180
- });
181
-
182
- it('should handle an empty _members array without errors', () => {
183
- // Assign an empty _members array
184
- (group as any)._members = [];
185
-
186
- const position: Vector3Like = { x: 10, y: 11, z: 12 };
187
- expect(() => group.SetPosition(position)).not.toThrow();
188
- });
189
-
190
- it('should handle _members with mixed types correctly', () => {
191
- // Create mixed members
192
- const diveNode: DIVENode = {
193
- isDIVENode: true,
194
- onMove: jest.fn(),
195
- } as unknown as DIVENode;
196
-
197
- const member: DIVENode = {
198
- // Define other properties/methods if necessary
199
- } as unknown as DIVENode;
200
-
201
- (group as any)._members = [
202
- diveNode,
203
- member,
204
- ];
205
-
206
- const position: Vector3Like = { x: 13, y: 14, z: 15 };
207
- group.SetPosition(position);
208
-
209
- // Ensure onMove is called only on diveNode
210
- expect(diveNode.onMove).toHaveBeenCalled();
211
- });
212
- });
@@ -1,30 +0,0 @@
1
- import { applyMixins } from '../applyMixins.ts';
2
-
3
- class Movable {
4
- move() {}
5
- }
6
-
7
- class Selectable {
8
- select() {}
9
- }
10
-
11
- describe('dive/helper/applyMixins', () => {
12
- it('should apply mixins', () => {
13
- class Product {
14
- doProductThings() {}
15
- }
16
-
17
- interface Product extends Movable, Selectable {}
18
-
19
- applyMixins(Product, [
20
- Movable,
21
- Selectable,
22
- ]);
23
-
24
- const instance = new Product();
25
- expect(instance).toBeDefined();
26
- expect(instance.move).toBeDefined();
27
- expect(instance.select).toBeDefined();
28
- expect(instance.doProductThings).toBeDefined();
29
- });
30
- });
@@ -1,18 +0,0 @@
1
- /**
2
- * Merges two class prototypes to a new one.
3
- */
4
-
5
- export const applyMixins = (
6
- derivedCtor: { prototype: object },
7
- constructors: { prototype: object }[],
8
- ): void => {
9
- constructors.forEach((baseCtor) => {
10
- Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
11
- Object.defineProperty(
12
- derivedCtor.prototype,
13
- name,
14
- Object.getOwnPropertyDescriptor(baseCtor.prototype, name)!,
15
- );
16
- });
17
- });
18
- };
@@ -1,63 +0,0 @@
1
- import { Object3D } from 'three';
2
- import { findInterface } from '../findInterface.ts';
3
-
4
- describe('dive/helper/findInterface', () => {
5
- it('should not find interface', () => {
6
- expect(findInterface(null, 'isInterface')).toBe(undefined);
7
-
8
- const obj = {} as unknown as Object3D;
9
-
10
- expect(findInterface(obj, 'isInterface')).toBe(undefined);
11
-
12
- // add traverse function
13
- obj.traverseAncestors = jest.fn(
14
- (callback: (object: Object3D) => any) => {
15
- callback(obj);
16
- },
17
- );
18
-
19
- expect(findInterface(obj, 'isInterface')).toBe(undefined);
20
- });
21
-
22
- it('should find interface in object', () => {
23
- const obj = {
24
- isInterface: true,
25
- traverseAncestors: jest.fn(
26
- (callback: (object: Object3D) => any) => {
27
- callback(obj);
28
- },
29
- ),
30
- } as unknown as Object3D;
31
-
32
- expect(findInterface(obj, 'isInterface')).toBe(obj);
33
- });
34
-
35
- it('should find interface in parent', () => {
36
- const obj = {
37
- traverseAncestors: jest.fn(
38
- (callback: (object: Object3D) => any) => {
39
- callback(obj);
40
- },
41
- ),
42
- parent: {
43
- isInterface: true,
44
-
45
- traverseAncestors: jest.fn(
46
- (callback: (object: Object3D) => any) => {
47
- callback(obj.parent!);
48
- },
49
- ),
50
-
51
- parent: {
52
- traverseAncestors: jest.fn(
53
- (callback: (object: Object3D) => any) => {
54
- callback(obj.parent!);
55
- },
56
- ),
57
- },
58
- },
59
- } as unknown as Object3D;
60
-
61
- expect(findInterface(obj, 'isInterface')).toBe(obj.parent);
62
- });
63
- });
@@ -1,13 +0,0 @@
1
- import { implementsInterface } from '../isInterface/implementsInterface';
2
- import { type Object3D } from 'three';
3
-
4
- export function findInterface<T>(
5
- object: Object3D | null | undefined,
6
- discriminator: string,
7
- ): (Object3D & T) | undefined {
8
- if (!object) return undefined;
9
-
10
- if (implementsInterface<T>(object, discriminator)) return object;
11
-
12
- return findInterface<T>(object.parent, discriminator);
13
- }
@@ -1,40 +0,0 @@
1
- import type { Object3D } from 'three';
2
- import { findSceneRecursive } from '../findSceneRecursive.ts';
3
-
4
- describe('dive/helper/findSceneRecursive', () => {
5
- it('should find itself if parent is not set', () => {
6
- const obj = {} as Object3D;
7
-
8
- const found = findSceneRecursive(obj);
9
-
10
- expect(found).toStrictEqual(obj);
11
- });
12
-
13
- it('should find itself if it has no parent', () => {
14
- const obj = {
15
- parent: null,
16
- } as Object3D;
17
-
18
- const found = findSceneRecursive(obj);
19
-
20
- expect(found).toStrictEqual(obj);
21
- });
22
-
23
- it('should find itself if it has no parent', () => {
24
- const scene = {
25
- parent: null,
26
- } as Object3D;
27
-
28
- const objparent = {
29
- parent: scene,
30
- } as Object3D;
31
-
32
- const obj = {
33
- parent: objparent,
34
- } as Object3D;
35
-
36
- const found = findSceneRecursive(obj);
37
-
38
- expect(found).toStrictEqual(scene);
39
- });
40
- });
@@ -1,16 +0,0 @@
1
- import { type Object3D } from 'three';
2
- import { type DIVEScene } from '../../scene/Scene';
3
-
4
- /**
5
- * Find the scene object of an object.
6
- *
7
- * @param object - The object to find the scene of.
8
- * @returns The scene object.
9
- */
10
-
11
- export const findSceneRecursive = (object: Object3D): DIVEScene => {
12
- if (object.parent) {
13
- return findSceneRecursive(object.parent);
14
- }
15
- return object as DIVEScene;
16
- };
@@ -1,186 +0,0 @@
1
- import { getObjectDelta } from '../getObjectDelta.ts';
2
-
3
- describe('dive/helper/getObjectDelta', () => {
4
- // NO DELTAS
5
- it('should not find any deltas with empty objects', () => {
6
- const obj0 = {};
7
- const obj1 = {};
8
-
9
- const delta = getObjectDelta(obj0, obj1);
10
-
11
- expect(delta).toStrictEqual({});
12
- });
13
-
14
- it('should not find any deltas with equal references', () => {
15
- const obj0 = {
16
- test0: 'test',
17
- value0: 42,
18
- array0: [
19
- 187,
20
- 6,
21
- 9,
22
- 42,
23
- ],
24
- };
25
- const obj1 = obj0;
26
-
27
- const delta = getObjectDelta(obj0, obj1);
28
-
29
- expect(delta).toStrictEqual({});
30
- });
31
-
32
- it('should not find any deltas with equal objects', () => {
33
- const obj0 = {
34
- test0: 'test',
35
- value0: 42,
36
- array0: [
37
- 187,
38
- 6,
39
- 9,
40
- 42,
41
- ],
42
- };
43
- const obj1 = { ...obj0 };
44
-
45
- const delta = getObjectDelta(obj0, obj1);
46
-
47
- expect(delta).toStrictEqual({});
48
- });
49
-
50
- it('should not find any deltas with empty arrays', () => {
51
- const obj0 = { array0: [] };
52
- const obj1 = { array0: [] };
53
-
54
- const delta = getObjectDelta(obj0, obj1);
55
-
56
- expect(delta).toStrictEqual({});
57
- });
58
-
59
- // DELTAS
60
- it('should find deltas with incorrect types (case a)', () => {
61
- const obj0 = 'test' as unknown as object;
62
- const obj1 = { test: 0 };
63
-
64
- const delta = getObjectDelta(obj0, obj1);
65
-
66
- expect(delta).toStrictEqual(obj1);
67
- });
68
-
69
- it('should find deltas with incorrect types (case b)', () => {
70
- const obj0 = { test: 0 };
71
- const obj1 = 'test' as unknown as object;
72
-
73
- const delta = getObjectDelta(obj0, obj1);
74
-
75
- expect(delta).toStrictEqual(obj1);
76
- });
77
-
78
- it('should find deltas with one empty object', () => {
79
- const obj0 = {};
80
- const obj1 = { test: 0 };
81
-
82
- const delta = getObjectDelta(obj0, obj1);
83
-
84
- expect(delta).toStrictEqual(obj1);
85
- });
86
-
87
- it('should find deltas with different key lengths', () => {
88
- const obj0 = { test: 0 };
89
- const obj1 = { test: 0, test0: 0 };
90
-
91
- const delta = getObjectDelta(obj0, obj1);
92
-
93
- expect(delta).toStrictEqual({ test0: 0 });
94
- });
95
-
96
- it('should find deltas with a type delta', () => {
97
- const obj0 = { test: 'test' };
98
- const obj1 = { test: 0 as unknown as string };
99
-
100
- const delta = getObjectDelta(obj0, obj1);
101
-
102
- expect(delta).toStrictEqual(obj1);
103
- });
104
-
105
- it('should find deltas with a value delta', () => {
106
- const obj0 = { test: 'test' };
107
- const obj1 = { test: 'hello world!' };
108
-
109
- const delta = getObjectDelta(obj0, obj1);
110
-
111
- expect(delta).toStrictEqual(obj1);
112
- });
113
-
114
- it('should find deltas with array value delta', () => {
115
- const obj0 = {
116
- array0: [
117
- 187,
118
- 6,
119
- 9,
120
- 42,
121
- ],
122
- };
123
- const obj1 = {
124
- array0: [
125
- 187,
126
- 6,
127
- 9,
128
- ],
129
- };
130
-
131
- const delta = getObjectDelta(obj0, obj1);
132
-
133
- expect(delta).toStrictEqual(obj1);
134
- });
135
-
136
- it('should find deltas with array type difference', () => {
137
- const obj0 = { array0: 'array0' };
138
- const obj1 = {
139
- array0: [
140
- 187,
141
- 6,
142
- 9,
143
- ] as unknown as string,
144
- };
145
-
146
- const delta = getObjectDelta(obj0, obj1);
147
-
148
- expect(delta).toStrictEqual(obj1);
149
- });
150
-
151
- it('should find deltas with deltas in objects in array', () => {
152
- const obj0 = { array0: [{ test: 0 }] };
153
- const obj1 = { array0: [{ test: 1 }] };
154
-
155
- const delta = getObjectDelta(obj0, obj1);
156
-
157
- expect(delta).toStrictEqual(obj1);
158
- });
159
-
160
- it('should find deltas with undefined value in objects in object', () => {
161
- const obj0 = { object0: undefined as unknown as object };
162
- const obj1 = { object0: { test: 1 } };
163
-
164
- const delta = getObjectDelta(obj0, obj1);
165
-
166
- expect(delta).toStrictEqual(obj1);
167
- });
168
-
169
- it('should find deltas with wrong type in objects in object', () => {
170
- const obj0 = { object0: 'test' };
171
- const obj1 = { object0: { test: 1 } as unknown as string };
172
-
173
- const delta = getObjectDelta(obj0, obj1);
174
-
175
- expect(delta).toStrictEqual(obj1);
176
- });
177
-
178
- it('should find deltas with empty value in objects in object', () => {
179
- const obj0 = { object0: {} };
180
- const obj1 = { object0: { test: 1 } };
181
-
182
- const delta = getObjectDelta(obj0, obj1);
183
-
184
- expect(delta).toStrictEqual(obj1);
185
- });
186
- });
@@ -1,105 +0,0 @@
1
- /**
2
- * Find the difference between two objects.
3
- */
4
-
5
- export const getObjectDelta = <T extends object>(
6
- a: T,
7
- b: Partial<T>,
8
- ): Partial<T> => {
9
- // if a and b have no entries we have no delta
10
- if (Object.keys(a).length === 0 && Object.keys(b).length === 0) {
11
- return {};
12
- }
13
-
14
- // if a or b is not an object we have a delta
15
- if (typeof a !== 'object' || typeof b !== 'object') {
16
- return b;
17
- }
18
-
19
- let delta = {};
20
-
21
- Object.keys(b).forEach((key) => {
22
- // if key is not in a we have a delta
23
- if (!Object.keys(a).includes(key)) {
24
- delta = { ...delta, [key]: b[key as keyof object] };
25
- return;
26
- }
27
-
28
- // assumption: b[key] is an array
29
- if (Array.isArray(b[key as keyof object])) {
30
- // if a[key] is not an array we have a delta
31
- if (!Array.isArray(a[key as keyof object])) {
32
- delta = { ...delta, [key]: b[key as keyof object] };
33
- return;
34
- }
35
-
36
- // create arrays (for TS types to be correct)
37
- const aArray = a[key as keyof object] as [];
38
- const bArray = b[key as keyof object] as [];
39
-
40
- // if both arrays are empty we have no delta
41
- if (aArray.length === 0 && bArray.length === 0) {
42
- delta = { ...delta };
43
- return;
44
- }
45
-
46
- // if array length is different we have a delta
47
- if (aArray.length !== bArray.length) {
48
- delta = { ...delta, [key]: b[key as keyof object] };
49
- return;
50
- }
51
-
52
- // create array for deltas
53
- const arrayDeltas: [] = [];
54
-
55
- bArray.forEach((entry, index) => {
56
- // getObjectDelta in array
57
- const inArrayDelta = getObjectDelta(
58
- aArray[index],
59
- bArray[index],
60
- );
61
-
62
- // if inArrayDelta has more then 0 entries we have a delta
63
- if (Object.keys(inArrayDelta).length) {
64
- arrayDeltas.push(bArray[index]);
65
- }
66
- });
67
-
68
- // if arrayDeltas has more than 0 entries we have a delta
69
- if (Object.keys(arrayDeltas).length) {
70
- delta = { ...delta, [key]: arrayDeltas };
71
- return;
72
- }
73
-
74
- return;
75
- }
76
-
77
- // assumption: b[key] is an object
78
- if (typeof b[key as keyof object] === 'object') {
79
- // if a[key] is not an object we have a delta
80
- if (typeof a[key as keyof object] !== 'object') {
81
- delta = { ...delta, [key]: b[key as keyof object] };
82
- return;
83
- }
84
-
85
- // recursive: find objectDelta in a and b
86
- const objectDelta = getObjectDelta(
87
- a[key as keyof object],
88
- b[key as keyof object],
89
- );
90
-
91
- // if objectDelta has more than 0 entries we have a delta
92
- if (Object.keys(objectDelta).length) {
93
- delta = { ...delta, [key]: objectDelta };
94
- return;
95
- }
96
- }
97
-
98
- // if a[key] is not equal to b[key] we have a delta
99
- if (a[key as keyof object] !== b[key as keyof object]) {
100
- delta = { ...delta, [key]: b[key as keyof object] };
101
- }
102
- });
103
-
104
- return delta;
105
- };