@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
package/src/dive.ts DELETED
@@ -1,363 +0,0 @@
1
- import {
2
- DIVERenderer,
3
- DIVERendererDefaultSettings,
4
- DIVERendererSettings,
5
- } from './renderer/Renderer.ts';
6
- import { DIVEScene } from './scene/Scene.ts';
7
- import DIVEPerspectiveCamera, {
8
- DIVEPerspectiveCameraDefaultSettings,
9
- DIVEPerspectiveCameraSettings,
10
- } from './camera/PerspectiveCamera.ts';
11
- import DIVEOrbitControls, {
12
- DIVEOrbitControlsDefaultSettings,
13
- DIVEOrbitControlsSettings,
14
- } from './controls/OrbitControls.ts';
15
- import DIVEToolbox from './toolbox/Toolbox.ts';
16
- import { DIVECommunication } from './com/Communication.ts';
17
- import { DIVEAnimationSystem } from './animation/AnimationSystem.ts';
18
- import DIVEAxisCamera from './axiscamera/AxisCamera.ts';
19
- import { getObjectDelta } from './helper/getObjectDelta/getObjectDelta.ts';
20
- import { MathUtils } from 'three';
21
- import { DIVEInfo } from './info/Info.ts';
22
- import pkgjson from '../package.json';
23
-
24
- export type DIVESettings = {
25
- autoResize: boolean;
26
- autoStart: boolean;
27
- displayAxes: boolean;
28
- renderer: Partial<DIVERendererSettings>;
29
- perspectiveCamera: Partial<DIVEPerspectiveCameraSettings>;
30
- orbitControls: Partial<DIVEOrbitControlsSettings>;
31
- };
32
-
33
- export const DIVEDefaultSettings: DIVESettings = {
34
- autoResize: true,
35
- autoStart: true,
36
- displayAxes: false,
37
- renderer: DIVERendererDefaultSettings,
38
- perspectiveCamera: DIVEPerspectiveCameraDefaultSettings,
39
- orbitControls: DIVEOrbitControlsDefaultSettings,
40
- };
41
-
42
- /**
43
- * #### DIVE
44
- * is the main class of the DIVE framework.
45
- *
46
- * An instance of this class delivers a complete 3D environment with a perspective camera, orbit controls, a toolbox, and a communication system.
47
- * ```ts
48
- * import { DIVE } from "@shopware-ag/dive";
49
- *
50
- * const myWrapper = document.getElementById('myWrapper');
51
- *
52
- * const dive = new DIVE();
53
- *
54
- * myWrapper.appendChild(dive.Canvas);
55
- *
56
- * dive.Communication.Subscribe('GET_ALL_SCENE_DATA', () => {
57
- * // do something
58
- * }));
59
- *
60
- * dive.Communication.PerformAction('GET_ALL_SCENE_DATA', {});
61
- * ```
62
- * @module
63
- */
64
-
65
- export default class DIVE {
66
- // static members
67
- public static QuickView(
68
- uri: string,
69
- settings?: Partial<DIVESettings>,
70
- ): DIVE {
71
- const dive = new DIVE(settings);
72
-
73
- dive.Communication.PerformAction('SET_CAMERA_TRANSFORM', {
74
- position: { x: 0, y: 2, z: 2 },
75
- target: { x: 0, y: 0.5, z: 0 },
76
- });
77
-
78
- // generate scene light id
79
- const lightid = MathUtils.generateUUID();
80
-
81
- // add scene light
82
- dive.Communication.PerformAction('ADD_OBJECT', {
83
- entityType: 'light',
84
- type: 'scene',
85
- name: 'light',
86
- id: lightid,
87
- enabled: true,
88
- visible: true,
89
- intensity: 1,
90
- color: 0xffffff,
91
- });
92
-
93
- // generate model id
94
- const modelid = MathUtils.generateUUID();
95
-
96
- // add loaded listener
97
- dive.Communication.Subscribe('MODEL_LOADED', (data) => {
98
- if (data.id !== modelid) return;
99
-
100
- const transform = dive.Communication.PerformAction(
101
- 'COMPUTE_ENCOMPASSING_VIEW',
102
- {},
103
- );
104
-
105
- dive.Communication.PerformAction('SET_CAMERA_TRANSFORM', {
106
- position: transform.position,
107
- target: transform.target,
108
- });
109
- });
110
-
111
- // instantiate model
112
- dive.Communication.PerformAction('ADD_OBJECT', {
113
- entityType: 'model',
114
- name: 'object',
115
- id: modelid,
116
- position: { x: 0, y: 0, z: 0 },
117
- rotation: { x: 0, y: 0, z: 0 },
118
- scale: { x: 1, y: 1, z: 1 },
119
- uri: uri,
120
- visible: true,
121
- loaded: false,
122
- });
123
-
124
- // set scene properties
125
- dive.Communication.PerformAction('UPDATE_SCENE', {
126
- backgroundColor: 0xffffff,
127
- gridEnabled: false,
128
- floorColor: 0xffffff,
129
- });
130
-
131
- return dive;
132
- }
133
-
134
- // descriptive members
135
- private _settings: DIVESettings;
136
- private _resizeObserverId: string;
137
- private _width: number;
138
- private _height: number;
139
-
140
- // functional components
141
- private renderer: DIVERenderer;
142
- private scene: DIVEScene;
143
- private perspectiveCamera: DIVEPerspectiveCamera;
144
- private orbitControls: DIVEOrbitControls;
145
- private toolbox: DIVEToolbox;
146
- private communication: DIVECommunication;
147
-
148
- // additional components
149
- private animationSystem: DIVEAnimationSystem;
150
- private axisCamera: DIVEAxisCamera | null;
151
-
152
- // getters
153
- public get Communication(): DIVECommunication {
154
- return this.communication;
155
- }
156
-
157
- public get Canvas(): HTMLCanvasElement {
158
- return this.renderer.domElement;
159
- }
160
-
161
- public get Info(): DIVEInfo {
162
- return DIVEInfo;
163
- }
164
-
165
- // setters
166
- public set Settings(settings: Partial<DIVESettings>) {
167
- const settingsDelta = getObjectDelta(this._settings, settings);
168
-
169
- // apply renderer settings (we have to rebuild the renderer to apply the settings)
170
- if (settingsDelta.renderer)
171
- this.renderer = new DIVERenderer(this._settings.renderer);
172
-
173
- // apply perspective camera settings
174
- if (settingsDelta.perspectiveCamera) {
175
- if (settingsDelta.perspectiveCamera.fov !== undefined)
176
- this.perspectiveCamera.fov =
177
- settingsDelta.perspectiveCamera.fov;
178
- if (settingsDelta.perspectiveCamera.near !== undefined)
179
- this.perspectiveCamera.near =
180
- settingsDelta.perspectiveCamera.near;
181
- if (settingsDelta.perspectiveCamera.far !== undefined)
182
- this.perspectiveCamera.far =
183
- settingsDelta.perspectiveCamera.far;
184
- this.perspectiveCamera.OnResize(
185
- this.renderer.domElement.width,
186
- this.renderer.domElement.height,
187
- );
188
- }
189
- // apply orbit controls settings
190
- if (settingsDelta.orbitControls) {
191
- if (settingsDelta.orbitControls.enableDamping !== undefined)
192
- this.orbitControls.enableDamping =
193
- settingsDelta.orbitControls.enableDamping;
194
- if (settingsDelta.orbitControls.dampingFactor !== undefined)
195
- this.orbitControls.dampingFactor =
196
- settingsDelta.orbitControls.dampingFactor;
197
- }
198
-
199
- if (settingsDelta.autoResize !== this._settings.autoResize) {
200
- if (settingsDelta.autoResize) {
201
- this.addResizeObserver();
202
- } else {
203
- this.removeResizeObserver();
204
- }
205
- }
206
-
207
- if (settingsDelta.displayAxes) {
208
- this.axisCamera = new DIVEAxisCamera(
209
- this.renderer,
210
- this.scene,
211
- this.orbitControls,
212
- );
213
- } else {
214
- this.axisCamera?.Dispose();
215
- this.axisCamera = null;
216
- }
217
-
218
- Object.assign(this._settings, settings);
219
- }
220
-
221
- constructor(settings?: Partial<DIVESettings>) {
222
- this._settings = {
223
- ...DIVEDefaultSettings,
224
- ...(settings !== undefined ? settings : {}),
225
- };
226
-
227
- this._resizeObserverId = '';
228
- this._width = 0;
229
- this._height = 0;
230
-
231
- // initialize functional components
232
- this.renderer = new DIVERenderer(this._settings.renderer);
233
- this.scene = new DIVEScene();
234
- this.perspectiveCamera = new DIVEPerspectiveCamera(
235
- this._settings.perspectiveCamera,
236
- );
237
-
238
- // initialize animation system
239
- this.animationSystem = new DIVEAnimationSystem(this.renderer);
240
-
241
- this.orbitControls = new DIVEOrbitControls(
242
- this.perspectiveCamera,
243
- this.renderer,
244
- this.animationSystem,
245
- this._settings.orbitControls,
246
- );
247
- this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
248
- this.communication = new DIVECommunication(
249
- this.renderer,
250
- this.scene,
251
- this.orbitControls,
252
- this.toolbox,
253
- );
254
-
255
- // initialize axis camera
256
- if (this._settings.displayAxes) {
257
- this.axisCamera = new DIVEAxisCamera(
258
- this.renderer,
259
- this.scene,
260
- this.orbitControls,
261
- );
262
- } else {
263
- this.axisCamera = null;
264
- }
265
-
266
- // add resize observer if autoResize is enabled
267
- if (this._settings.autoResize) {
268
- this.addResizeObserver();
269
- }
270
-
271
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
- (window as any).DIVE = {
273
- PrintScene: () => {
274
- console.log(this.scene);
275
- },
276
- };
277
-
278
- console.log(`DIVE ${pkgjson.version} initialized successfully!`);
279
- console.log(`
280
- @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@
281
- @@@@+-:::::::---------------------==------------------------------=#@@@@
282
- @@%=::::.......::---------------------------------------------------------+@@
283
- @@+:::...........::-----------------------------------------------------------#@@
284
- @@=:::.........::::::-------------------------------------------------------------%@
285
- @%:::.......:::::::-----------------------------------------------------------------#@
286
- @*:::.....:::::-----------------------------------------------------------------------*@
287
- @%::::::.::::---------------------------------------------------------------------------@@
288
- @@-:::::::::-----------------------------------------------------------------------------=@
289
- @%::::::::--------------------------------------------------------------------------------%@
290
- @+::::::::--------------------------------=@@@@@%-----------------------------------------%@
291
- @=:::::::--------------------------------*@@ @@+---------------------------------------#@
292
- @+:::::::-------------------------------*@ @*--------------------------------------%@
293
- @#::::::::-----------------------------=@@ @@=-------------------------------------%@
294
- @@-::::::::----------------------------@@ @@------------------------------------=@
295
- @%:::::::::--------------------------*@ @*-----------------------------------@@
296
- @*:::::::::-------------------------@@ @@----------------------------------%@
297
- @#::::::::::----------------------%@ @%--------------------------------%@
298
- @#:::::::::::-------------------=@@ @@=------------------------------%@
299
- @@-::::::::::::----------------%@ @%----------------------------=@@
300
- @@#::::::::::::::------------*@ @*--------------------------#@@
301
- @@+::::::::::::::::--------@@ @@------------------------+@@
302
- @@*:::::::::::::::::----@@ @@---------------------+@@
303
- @@@-:::::::::::::::--#@ @#-----------------=%@@
304
- @@%-::::::::::::-%@ @%-------------=%@@
305
- @@@@+:::::::#@@ @@*-------*@@@@
306
- @@@@@@@ @@@@@@
307
-
308
- `);
309
-
310
- if (this._settings.autoStart) {
311
- // when everything is done, start the renderer
312
- this.renderer.StartRenderer(this.scene, this.perspectiveCamera);
313
- }
314
- }
315
-
316
- public Dispose(): void {
317
- this.removeResizeObserver();
318
- this.renderer.Dispose();
319
- this.orbitControls.Dispose();
320
- this.axisCamera?.Dispose();
321
- this.animationSystem.Dispose();
322
- this.toolbox.Dispose();
323
- this.communication.DestroyInstance();
324
- }
325
-
326
- // methods
327
- public OnResize(width: number, height: number): void {
328
- // resize renderer
329
- this.renderer.OnResize(width, height);
330
-
331
- // resize camera
332
- this.perspectiveCamera.OnResize(width, height);
333
- }
334
-
335
- private addResizeObserver(): void {
336
- this._resizeObserverId = this.renderer.AddPreRenderCallback(() => {
337
- // check if the canvas is mounted
338
- const canvasWrapper = this.renderer.domElement.parentElement;
339
- if (!canvasWrapper) return;
340
-
341
- const { clientWidth, clientHeight } = canvasWrapper;
342
- if (clientWidth === this._width && clientHeight === this._height)
343
- return;
344
-
345
- this.OnResize(clientWidth, clientHeight);
346
-
347
- this._width = clientWidth;
348
- this._height = clientHeight;
349
- });
350
- }
351
-
352
- private removeResizeObserver(): void {
353
- this.renderer.RemovePreRenderCallback(this._resizeObserverId);
354
- }
355
- }
356
-
357
- export { DIVE, DIVECommunication };
358
-
359
- export * from './math/index.ts';
360
-
361
- export type * from './com/actions/index.ts';
362
- export type * from './com/types';
363
- export type * from './types';
@@ -1,35 +0,0 @@
1
- export class DIVEEventExecutor<T> {
2
- private _listeners: Map<keyof T, ((payload: T[keyof T]) => void)[]> =
3
- new Map();
4
-
5
- public Subscribe<S extends keyof T>(
6
- type: S,
7
- listener: (payload: T[S]) => void,
8
- ): () => boolean {
9
- if (!this._listeners.get(type)) this._listeners.set(type, []);
10
-
11
- this._listeners
12
- .get(type)!
13
- .push(listener as (payload: T[keyof T]) => void);
14
-
15
- return () => {
16
- const listenerArray = this._listeners.get(type);
17
- if (!listenerArray) return false;
18
-
19
- const existingIndex = listenerArray.findIndex(
20
- (entry) => entry === listener,
21
- );
22
- if (existingIndex === -1) return false;
23
-
24
- listenerArray.splice(existingIndex, 1);
25
- return true;
26
- };
27
- }
28
-
29
- protected dispatch<S extends keyof T>(type: S, payload?: T[S]): void {
30
- const listenerArray = this._listeners.get(type);
31
- if (!listenerArray) return;
32
-
33
- listenerArray.forEach((listener) => listener(payload as T[S]));
34
- }
35
- }
@@ -1,21 +0,0 @@
1
- import { Object3D } from 'three';
2
- import {
3
- USDZExporter,
4
- USDZExporterOptions,
5
- } from 'three/examples/jsm/exporters/USDZExporter';
6
-
7
- export type DIVEUSDZExporterOptions = USDZExporterOptions & {
8
- ar?: {
9
- anchoring: { type: 'plane' | 'image' | 'face' | 'none' }; // source: https://developer.apple.com/documentation/realitykit/preliminary-anchoring-type
10
- planeAnchoring: { alignment: 'horizontal' | 'vertical' | 'any' }; // source: https://developer.apple.com/documentation/realitykit/preliminary-planeanchoring-alignment
11
- };
12
- };
13
-
14
- export class DIVEUSDZExporter extends USDZExporter {
15
- public parse(
16
- scene: Object3D,
17
- options?: DIVEUSDZExporterOptions,
18
- ): Promise<Uint8Array> {
19
- return super.parse(scene, options);
20
- }
21
- }
@@ -1,57 +0,0 @@
1
- import { Object3D } from 'three';
2
- import { DIVEUSDZExporter, DIVEUSDZExporterOptions } from '../USDZExporter';
3
-
4
- describe('DIVEUSDZExporter', () => {
5
- let exporter: DIVEUSDZExporter;
6
- let scene: Object3D;
7
-
8
- beforeEach(() => {
9
- exporter = new DIVEUSDZExporter();
10
- scene = new Object3D();
11
- });
12
-
13
- test('should create an instance of DIVEUSDZExporter', () => {
14
- expect(exporter).toBeInstanceOf(DIVEUSDZExporter);
15
- });
16
-
17
- test('should call parse method with scene and options', async () => {
18
- const options: DIVEUSDZExporterOptions = {
19
- ar: {
20
- anchoring: { type: 'plane' },
21
- planeAnchoring: { alignment: 'horizontal' },
22
- },
23
- };
24
-
25
- const result = await exporter.parse(scene, options);
26
- expect(result).toBeInstanceOf(Uint8Array);
27
- });
28
-
29
- test('should call parse method without options', async () => {
30
- const result = await exporter.parse(scene);
31
- expect(result).toBeInstanceOf(Uint8Array);
32
- });
33
-
34
- test('should handle parse method with different anchoring types', async () => {
35
- const options: DIVEUSDZExporterOptions = {
36
- ar: {
37
- anchoring: { type: 'image' },
38
- planeAnchoring: { alignment: 'vertical' },
39
- },
40
- };
41
-
42
- const result = await exporter.parse(scene, options);
43
- expect(result).toBeInstanceOf(Uint8Array);
44
- });
45
-
46
- test('should handle parse method with different plane anchoring alignments', async () => {
47
- const options: DIVEUSDZExporterOptions = {
48
- ar: {
49
- anchoring: { type: 'face' },
50
- planeAnchoring: { alignment: 'any' },
51
- },
52
- };
53
-
54
- const result = await exporter.parse(scene, options);
55
- expect(result).toBeInstanceOf(Uint8Array);
56
- });
57
- });
@@ -1,144 +0,0 @@
1
- import { Euler, Object3D, Vector3 } from 'three';
2
- import { DIVERotateGizmo } from './rotate/RotateGizmo';
3
- import { DIVETranslateGizmo } from './translate/TranslateGizmo';
4
- import DIVEOrbitControls from '../controls/OrbitControls';
5
- import { DIVEScaleGizmo } from './scale/ScaleGizmo';
6
- import { DIVEGizmoPlane as DIVEGizmoPlane } from './plane/GizmoPlane';
7
- import { DIVESelectable } from '../interface/Selectable';
8
-
9
- export type DIVEGizmoMode = 'translate' | 'rotate' | 'scale';
10
-
11
- export type DIVEGizmoAxis = 'x' | 'y' | 'z';
12
-
13
- export class DIVEGizmo extends Object3D {
14
- private _mode: DIVEGizmoMode;
15
- public get mode(): DIVEGizmoMode {
16
- return this._mode;
17
- }
18
- public set mode(value: DIVEGizmoMode) {
19
- this._mode = value;
20
- this.assemble();
21
- }
22
-
23
- public set debug(value: boolean) {
24
- this._translateGizmo.debug = value;
25
- this._rotateGizmo.debug = value;
26
- this._scaleGizmo.debug = value;
27
- }
28
-
29
- private _gizmoNode: Object3D;
30
- public get gizmoNode(): Object3D {
31
- return this._gizmoNode;
32
- }
33
- private _translateGizmo: DIVETranslateGizmo;
34
- private _rotateGizmo: DIVERotateGizmo;
35
- private _scaleGizmo: DIVEScaleGizmo;
36
-
37
- private _gizmoPlane: DIVEGizmoPlane;
38
- public get gizmoPlane(): DIVEGizmoPlane {
39
- return this._gizmoPlane;
40
- }
41
-
42
- // attachment stuff
43
- private _object: (Object3D & DIVESelectable) | null;
44
- public get object(): (Object3D & DIVESelectable) | null {
45
- return this._object;
46
- }
47
-
48
- constructor(controller: DIVEOrbitControls) {
49
- super();
50
- this.name = 'DIVEGizmo';
51
-
52
- controller.addEventListener('change', () => {
53
- const size = controller.getDistance() / 2.5;
54
- this.scale.set(size, size, size);
55
- });
56
-
57
- this._mode = 'translate';
58
-
59
- this._gizmoNode = new Object3D();
60
- this.add(this._gizmoNode);
61
-
62
- this._translateGizmo = new DIVETranslateGizmo(controller);
63
- this._rotateGizmo = new DIVERotateGizmo(controller);
64
- this._scaleGizmo = new DIVEScaleGizmo(controller);
65
-
66
- this._gizmoPlane = new DIVEGizmoPlane();
67
- this._gizmoPlane.visible = false;
68
-
69
- this._object = null;
70
- }
71
-
72
- public attach(object: Object3D & DIVESelectable): this {
73
- this._object = object;
74
- this.assemble();
75
- return this;
76
- }
77
-
78
- public detach(): this {
79
- this._object = null;
80
- this.assemble();
81
- return this;
82
- }
83
-
84
- public onHover(
85
- mode: DIVEGizmoMode,
86
- axis: DIVEGizmoAxis,
87
- value: boolean,
88
- ): void {
89
- if (!value) return;
90
- this._gizmoPlane.assemble(mode, axis);
91
- }
92
-
93
- public onChange(
94
- position?: Vector3,
95
- rotation?: Euler,
96
- scale?: Vector3,
97
- ): void {
98
- if (this.object === null) return;
99
-
100
- if (position) {
101
- this.position.copy(position);
102
- this.object.position.copy(position);
103
- }
104
-
105
- if (rotation) {
106
- this.object.rotation.copy(rotation);
107
- }
108
-
109
- if (scale) {
110
- this.object.scale.copy(scale);
111
- this._scaleGizmo.update(scale);
112
- }
113
- }
114
-
115
- private assemble(): void {
116
- // clear all children
117
- this._gizmoNode.clear();
118
- this._gizmoPlane.clear();
119
-
120
- // reset all gizmos
121
- this._translateGizmo.reset();
122
- this._rotateGizmo.reset();
123
- this._scaleGizmo.reset();
124
-
125
- // check for object
126
- if (this.object === null) return;
127
-
128
- // add gizmos
129
- if (this._mode === 'translate') {
130
- this._gizmoNode.add(this._translateGizmo);
131
- }
132
-
133
- if (this._mode === 'rotate') {
134
- this._gizmoNode.add(this._rotateGizmo);
135
- }
136
-
137
- if (this._mode === 'scale') {
138
- this._gizmoNode.add(this._scaleGizmo);
139
- }
140
-
141
- // add plane for raycasting properly while dragging
142
- this.add(this._gizmoPlane);
143
- }
144
- }