@shopware-ag/dive 1.19.1-beta.0 → 1.19.1-beta.2

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 (188) hide show
  1. package/build/dive.cjs +362 -199
  2. package/build/dive.cjs.map +1 -1
  3. package/build/dive.js +330 -167
  4. package/build/dive.js.map +1 -1
  5. package/build/dive.mjs +10803 -8714
  6. package/build/dive.mjs.map +1 -1
  7. package/build/src/converter/Converter.d.ts +3 -12
  8. package/build/src/dive.d.ts +1 -0
  9. package/build/src/exporter/Exporter.d.ts +20 -2
  10. package/build/src/loader/Loader.d.ts +0 -4
  11. package/build/src/types/error/index.d.ts +12 -0
  12. package/build/src/types/file/FileTypes.d.ts +17 -0
  13. package/build/src/types/file/index.d.ts +1 -0
  14. package/build/src/types/index.d.ts +5 -8
  15. package/package.json +2 -3
  16. package/build/src/types/ExporterOptions.d.ts +0 -15
  17. package/build/src/types/FileTypes.d.ts +0 -27
  18. package/src/__test__/DIVE.test.ts +0 -274
  19. package/src/animation/AnimationSystem.ts +0 -34
  20. package/src/animation/__test__/AnimationSystem.test.ts +0 -40
  21. package/src/ar/AR.ts +0 -101
  22. package/src/ar/__test__/AR.test.ts +0 -276
  23. package/src/ar/arquicklook/ARQuickLook.ts +0 -53
  24. package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -144
  25. package/src/ar/sceneviewer/SceneViewer.ts +0 -119
  26. package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -190
  27. package/src/ar/webxr/WebXR.ts +0 -177
  28. package/src/ar/webxr/controller/WebXRController.ts +0 -340
  29. package/src/ar/webxr/crosshair/WebXRCrosshair.ts +0 -35
  30. package/src/ar/webxr/origin/WebXROrigin.ts +0 -192
  31. package/src/ar/webxr/overlay/Overlay.ts +0 -50
  32. package/src/ar/webxr/raycaster/WebXRRaycaster.ts +0 -131
  33. package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +0 -102
  34. package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +0 -49
  35. package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +0 -356
  36. package/src/axiscamera/AxisCamera.ts +0 -108
  37. package/src/axiscamera/__test__/AxisCamera.test.ts +0 -150
  38. package/src/camera/PerspectiveCamera.ts +0 -63
  39. package/src/camera/__test__/PerspectiveCamera.test.ts +0 -36
  40. package/src/com/Communication.ts +0 -806
  41. package/src/com/__test__/Communication.test.ts +0 -1030
  42. package/src/com/actions/camera/computeencompassingview.ts +0 -10
  43. package/src/com/actions/camera/getcameratransform.ts +0 -10
  44. package/src/com/actions/camera/movecamera.ts +0 -18
  45. package/src/com/actions/camera/resetcamera.ts +0 -5
  46. package/src/com/actions/camera/setcameralayer.ts +0 -5
  47. package/src/com/actions/camera/setcameratransform.ts +0 -10
  48. package/src/com/actions/camera/zoomcamera.ts +0 -5
  49. package/src/com/actions/index.ts +0 -61
  50. package/src/com/actions/media/generatemedia.ts +0 -18
  51. package/src/com/actions/object/addobject.ts +0 -7
  52. package/src/com/actions/object/deleteobject.ts +0 -7
  53. package/src/com/actions/object/deselectobject.ts +0 -7
  54. package/src/com/actions/object/getallobjects.ts +0 -7
  55. package/src/com/actions/object/getobjects.ts +0 -7
  56. package/src/com/actions/object/model/dropit.ts +0 -5
  57. package/src/com/actions/object/model/modelloaded.ts +0 -5
  58. package/src/com/actions/object/model/placeonfloor.ts +0 -5
  59. package/src/com/actions/object/selectobject.ts +0 -7
  60. package/src/com/actions/object/setparent.ts +0 -10
  61. package/src/com/actions/object/updateobject.ts +0 -7
  62. package/src/com/actions/renderer/startrender.ts +0 -5
  63. package/src/com/actions/scene/exportscene.ts +0 -7
  64. package/src/com/actions/scene/getallscenedata.ts +0 -7
  65. package/src/com/actions/scene/launchar.ts +0 -7
  66. package/src/com/actions/scene/setbackground.ts +0 -5
  67. package/src/com/actions/scene/updatescene.ts +0 -11
  68. package/src/com/actions/toolbox/select/setgizmomode.ts +0 -5
  69. package/src/com/actions/toolbox/transform/setgizmoscalelinked.ts +0 -5
  70. package/src/com/actions/toolbox/transform/setgizmovisible.ts +0 -5
  71. package/src/com/actions/toolbox/usetool.ts +0 -7
  72. package/src/com/types/COMBaseEntity.ts +0 -9
  73. package/src/com/types/COMEntity.ts +0 -7
  74. package/src/com/types/COMEntityType.ts +0 -1
  75. package/src/com/types/COMGeometry.ts +0 -8
  76. package/src/com/types/COMGeometryType.ts +0 -9
  77. package/src/com/types/COMGroup.ts +0 -9
  78. package/src/com/types/COMLight.ts +0 -11
  79. package/src/com/types/COMMaterial.ts +0 -12
  80. package/src/com/types/COMModel.ts +0 -12
  81. package/src/com/types/COMPov.ts +0 -8
  82. package/src/com/types/COMPrimitive.ts +0 -12
  83. package/src/com/types/index.ts +0 -23
  84. package/src/constant/AxisHelperColors.ts +0 -7
  85. package/src/constant/GridColors.ts +0 -2
  86. package/src/constant/VisibilityLayerMask.ts +0 -5
  87. package/src/controls/OrbitControls.ts +0 -211
  88. package/src/controls/__test__/OrbitControls.test.ts +0 -256
  89. package/src/converter/Converter.ts +0 -117
  90. package/src/dive.ts +0 -363
  91. package/src/events/EventExecutor.ts +0 -35
  92. package/src/exporter/Exporter.ts +0 -75
  93. package/src/gizmo/Gizmo.ts +0 -144
  94. package/src/gizmo/handles/AxisHandle.ts +0 -153
  95. package/src/gizmo/handles/RadialHandle.ts +0 -149
  96. package/src/gizmo/handles/ScaleHandle.ts +0 -195
  97. package/src/gizmo/plane/GizmoPlane.ts +0 -84
  98. package/src/gizmo/rotate/RotateGizmo.ts +0 -143
  99. package/src/gizmo/scale/ScaleGizmo.ts +0 -125
  100. package/src/gizmo/translate/TranslateGizmo.ts +0 -114
  101. package/src/grid/Grid.ts +0 -34
  102. package/src/grid/__test__/Grid.test.ts +0 -28
  103. package/src/group/Group.ts +0 -184
  104. package/src/group/__test__/Group.test.ts +0 -212
  105. package/src/helper/applyMixins/__test__/applyMixins.test.ts +0 -30
  106. package/src/helper/applyMixins/applyMixins.ts +0 -70
  107. package/src/helper/findInterface/__test__/findInterface.test.ts +0 -63
  108. package/src/helper/findInterface/findInterface.ts +0 -13
  109. package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +0 -40
  110. package/src/helper/findSceneRecursive/findSceneRecursive.ts +0 -16
  111. package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +0 -186
  112. package/src/helper/getObjectDelta/getObjectDelta.ts +0 -105
  113. package/src/helper/isInterface/__test__/implementsInterface.test.ts +0 -19
  114. package/src/helper/isInterface/implementsInterface.ts +0 -9
  115. package/src/info/Info.ts +0 -178
  116. package/src/info/__test__/Info.test.ts +0 -346
  117. package/src/interface/Draggable.ts +0 -14
  118. package/src/interface/Hoverable.ts +0 -14
  119. package/src/interface/Movable.ts +0 -12
  120. package/src/interface/Rotatable.ts +0 -10
  121. package/src/interface/Scalable.ts +0 -10
  122. package/src/interface/Selectable.ts +0 -11
  123. package/src/io/IO.ts +0 -62
  124. package/src/io/__test__/IO.test.ts +0 -116
  125. package/src/io/gltf/GLTFIO.ts +0 -56
  126. package/src/io/gltf/__test__/GLTFIO.test.ts +0 -108
  127. package/src/light/AmbientLight.ts +0 -39
  128. package/src/light/PointLight.ts +0 -115
  129. package/src/light/SceneLight.ts +0 -63
  130. package/src/light/__test__/AmbientLight.test.ts +0 -29
  131. package/src/light/__test__/PointLight.test.ts +0 -74
  132. package/src/light/__test__/SceneLight.test.ts +0 -47
  133. package/src/loader/Loader.ts +0 -48
  134. package/src/math/__test__/DIVEMath.test.ts +0 -12
  135. package/src/math/ceil/__test__/ceilExp.test.ts +0 -12
  136. package/src/math/ceil/ceilExp.ts +0 -6
  137. package/src/math/degToRad/__test__/degToRad.test.ts +0 -172
  138. package/src/math/degToRad/degToRad.ts +0 -5
  139. package/src/math/floor/__test__/floorExp.test.ts +0 -14
  140. package/src/math/floor/floorExp.ts +0 -6
  141. package/src/math/helper/__test__/shift.test.ts +0 -12
  142. package/src/math/helper/shift.ts +0 -4
  143. package/src/math/index.ts +0 -28
  144. package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -155
  145. package/src/math/radToDeg/radToDeg.ts +0 -5
  146. package/src/math/round/__test__/roundExp.test.ts +0 -14
  147. package/src/math/round/roundExp.ts +0 -10
  148. package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +0 -20
  149. package/src/math/signedAngleTo/signedAngleTo.ts +0 -20
  150. package/src/math/toFixed/__test__/toFixedExp.test.ts +0 -14
  151. package/src/math/toFixed/toFixedExp.ts +0 -9
  152. package/src/math/truncate/__test__/truncateExp.test.ts +0 -14
  153. package/src/math/truncate/truncateExp.ts +0 -9
  154. package/src/mediacreator/MediaCreator.ts +0 -75
  155. package/src/mediacreator/__test__/MediaCreator.test.ts +0 -155
  156. package/src/model/Model.ts +0 -190
  157. package/src/model/__test__/Model.test.ts +0 -215
  158. package/src/module/Module.ts +0 -45
  159. package/src/module/__test__/Module.test.ts +0 -54
  160. package/src/node/Node.ts +0 -100
  161. package/src/node/__test__/Node.test.ts +0 -120
  162. package/src/primitive/Primitive.ts +0 -299
  163. package/src/primitive/__test__/Primitive.test.ts +0 -281
  164. package/src/primitive/floor/Floor.ts +0 -45
  165. package/src/primitive/floor/__test__/Floor.test.ts +0 -24
  166. package/src/renderer/Renderer.ts +0 -215
  167. package/src/renderer/__test__/Renderer.test.ts +0 -228
  168. package/src/scene/Scene.ts +0 -106
  169. package/src/scene/__test__/Scene.test.ts +0 -124
  170. package/src/scene/root/Root.ts +0 -426
  171. package/src/scene/root/__test__/Root.test.ts +0 -903
  172. package/src/scene/xrroot/XRRoot.ts +0 -56
  173. package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +0 -80
  174. package/src/toolbox/BaseTool.ts +0 -319
  175. package/src/toolbox/Toolbox.ts +0 -129
  176. package/src/toolbox/__test__/BaseTool.test.ts +0 -627
  177. package/src/toolbox/__test__/Toolbox.test.ts +0 -143
  178. package/src/toolbox/select/SelectTool.ts +0 -92
  179. package/src/toolbox/select/__test__/SelectTool.test.ts +0 -237
  180. package/src/toolbox/transform/TransformTool.ts +0 -166
  181. package/src/toolbox/transform/__test__/TransformTool.test.ts +0 -147
  182. package/src/types/ExporterOptions.ts +0 -14
  183. package/src/types/FileTypes.ts +0 -37
  184. package/src/types/SceneData.ts +0 -26
  185. package/src/types/SceneObjects.ts +0 -14
  186. package/src/types/SceneType.ts +0 -14
  187. package/src/types/index.ts +0 -31
  188. package/src/types/info/index.ts +0 -76
@@ -1,806 +0,0 @@
1
- import { Actions } from './actions/index.ts';
2
- import { generateUUID } from 'three/src/math/MathUtils';
3
- import { isSelectTool } from '../toolbox/select/SelectTool.ts';
4
- import { merge } from 'lodash';
5
- import { DIVEModule } from '../module/Module.ts';
6
-
7
- // type imports
8
- import { type Color, type MeshStandardMaterial } from 'three';
9
- import {
10
- type COMLight,
11
- type COMModel,
12
- type COMEntity,
13
- type COMPov,
14
- type COMPrimitive,
15
- type COMGroup,
16
- } from './types';
17
- import { type DIVEScene } from '../scene/Scene.ts';
18
- import type DIVEToolbox from '../toolbox/Toolbox.ts';
19
- import type DIVEOrbitControls from '../controls/OrbitControls.ts';
20
- import { type DIVEModel } from '../model/Model.ts';
21
- import { type DIVEMediaCreator } from '../mediacreator/MediaCreator.ts';
22
- import { type DIVERenderer } from '../renderer/Renderer.ts';
23
- import { type DIVESelectable } from '../interface/Selectable.ts';
24
- import { type DIVEIO } from '../io/IO.ts';
25
- import { type ARSystem } from '../ar/AR.ts';
26
-
27
- type EventListener<Action extends keyof Actions> = (
28
- payload: Actions[Action]['PAYLOAD'],
29
- ) => void;
30
-
31
- type Unsubscribe = () => boolean;
32
-
33
- /**
34
- * Main class for communicating with DIVE.
35
- *
36
- * You can subscribe to actions and perform them from outside and inside DIVE.
37
- *
38
- * ```ts
39
- * import { DIVE } from "@shopware-ag/dive";
40
- *
41
- * const dive = new DIVE();
42
- *
43
- * dive.Communication.Subscribe('GET_ALL_SCENE_DATA', () => {
44
- * // do something
45
- * }));
46
- *
47
- * dive.Communication.PerformAction('GET_ALL_SCENE_DATA', {});
48
- * ```
49
- *
50
- * @module
51
- */
52
-
53
- export class DIVECommunication {
54
- private static __instances: DIVECommunication[] = [];
55
-
56
- public static get(id: string): DIVECommunication | undefined {
57
- const fromComID = this.__instances.find(
58
- (instance) => instance.id === id,
59
- );
60
- if (fromComID) return fromComID;
61
- return this.__instances.find((instance) =>
62
- Array.from(instance.registered.values()).find(
63
- (object) => object.id === id,
64
- ),
65
- );
66
- }
67
-
68
- private _id: string;
69
- public get id(): string {
70
- return this._id;
71
- }
72
-
73
- private renderer: DIVERenderer;
74
- private scene: DIVEScene;
75
- private controller: DIVEOrbitControls;
76
- private toolbox: DIVEToolbox;
77
-
78
- private _mediaGenerator: DIVEModule<DIVEMediaCreator> = new DIVEModule(
79
- '../mediacreator/MediaCreator.ts',
80
- 'DIVEMediaCreator',
81
- );
82
- private _io: DIVEModule<DIVEIO> = new DIVEModule('../io/IO.ts', 'DIVEIO');
83
-
84
- private _ar: DIVEModule<ARSystem> = new DIVEModule('../ar/AR.ts', 'DIVEAR');
85
-
86
- private registered: Map<string, COMEntity> = new Map();
87
-
88
- // private listeners: { [key: string]: EventListener[] } = {};
89
- private listeners: Map<keyof Actions, EventListener<keyof Actions>[]> =
90
- new Map();
91
-
92
- constructor(
93
- renderer: DIVERenderer,
94
- scene: DIVEScene,
95
- controls: DIVEOrbitControls,
96
- toolbox: DIVEToolbox,
97
- ) {
98
- this._id = generateUUID();
99
- this.renderer = renderer;
100
- this.scene = scene;
101
- this.controller = controls;
102
- this.toolbox = toolbox;
103
-
104
- DIVECommunication.__instances.push(this);
105
- }
106
-
107
- public DestroyInstance(): boolean {
108
- const existingIndex = DIVECommunication.__instances.findIndex(
109
- (entry) => entry.id === this.id,
110
- );
111
- if (existingIndex === -1) return false;
112
- DIVECommunication.__instances.splice(existingIndex, 1);
113
- return true;
114
- }
115
-
116
- public PerformAction<Action extends keyof Actions>(
117
- action: Action,
118
- payload?: Actions[Action]['PAYLOAD'],
119
- ): Actions[Action]['RETURN'] {
120
- let returnValue: Actions[Action]['RETURN'] = false;
121
-
122
- switch (action) {
123
- case 'START_RENDER': {
124
- this.renderer.StartRenderer(this.scene, this.controller.object);
125
- returnValue = true;
126
- break;
127
- }
128
- case 'GET_ALL_SCENE_DATA': {
129
- returnValue = this.getAllSceneData(
130
- payload as Actions['GET_ALL_SCENE_DATA']['PAYLOAD'],
131
- );
132
- break;
133
- }
134
- case 'GET_ALL_OBJECTS': {
135
- returnValue = this.getAllObjects(
136
- payload as Actions['GET_ALL_OBJECTS']['PAYLOAD'],
137
- );
138
- break;
139
- }
140
- case 'GET_OBJECTS': {
141
- returnValue = this.getObjects(
142
- payload as Actions['GET_OBJECTS']['PAYLOAD'],
143
- );
144
- break;
145
- }
146
- case 'ADD_OBJECT': {
147
- returnValue = this.addObject(
148
- payload as Actions['ADD_OBJECT']['PAYLOAD'],
149
- );
150
- break;
151
- }
152
- case 'UPDATE_OBJECT': {
153
- returnValue = this.updateObject(
154
- payload as Actions['UPDATE_OBJECT']['PAYLOAD'],
155
- );
156
- break;
157
- }
158
- case 'DELETE_OBJECT': {
159
- returnValue = this.deleteObject(
160
- payload as Actions['DELETE_OBJECT']['PAYLOAD'],
161
- );
162
- break;
163
- }
164
- case 'SELECT_OBJECT': {
165
- returnValue = this.selectObject(
166
- payload as Actions['SELECT_OBJECT']['PAYLOAD'],
167
- );
168
- break;
169
- }
170
- case 'DESELECT_OBJECT': {
171
- returnValue = this.deselectObject(
172
- payload as Actions['DESELECT_OBJECT']['PAYLOAD'],
173
- );
174
- break;
175
- }
176
- case 'SET_BACKGROUND': {
177
- returnValue = this.setBackground(
178
- payload as Actions['SET_BACKGROUND']['PAYLOAD'],
179
- );
180
- break;
181
- }
182
- case 'DROP_IT': {
183
- returnValue = this.dropIt(
184
- payload as Actions['DROP_IT']['PAYLOAD'],
185
- );
186
- break;
187
- }
188
- case 'PLACE_ON_FLOOR': {
189
- returnValue = this.placeOnFloor(
190
- payload as Actions['PLACE_ON_FLOOR']['PAYLOAD'],
191
- );
192
- break;
193
- }
194
- case 'SET_CAMERA_TRANSFORM': {
195
- returnValue = this.setCameraTransform(
196
- payload as Actions['SET_CAMERA_TRANSFORM']['PAYLOAD'],
197
- );
198
- break;
199
- }
200
- case 'GET_CAMERA_TRANSFORM': {
201
- returnValue = this.getCameraTransform(
202
- payload as Actions['GET_CAMERA_TRANSFORM']['PAYLOAD'],
203
- );
204
- break;
205
- }
206
- case 'MOVE_CAMERA': {
207
- returnValue = this.moveCamera(
208
- payload as Actions['MOVE_CAMERA']['PAYLOAD'],
209
- );
210
- break;
211
- }
212
- case 'RESET_CAMERA': {
213
- returnValue = this.resetCamera(
214
- payload as Actions['RESET_CAMERA']['PAYLOAD'],
215
- );
216
- break;
217
- }
218
- case 'COMPUTE_ENCOMPASSING_VIEW': {
219
- returnValue = this.computeEncompassingView(
220
- payload as Actions['COMPUTE_ENCOMPASSING_VIEW']['PAYLOAD'],
221
- );
222
- break;
223
- }
224
- case 'SET_CAMERA_LAYER': {
225
- returnValue = this.setCameraLayer(
226
- payload as Actions['SET_CAMERA_LAYER']['PAYLOAD'],
227
- );
228
- break;
229
- }
230
- case 'ZOOM_CAMERA': {
231
- returnValue = this.zoomCamera(
232
- payload as Actions['ZOOM_CAMERA']['PAYLOAD'],
233
- );
234
- break;
235
- }
236
- case 'SET_GIZMO_MODE': {
237
- returnValue = this.setGizmoMode(
238
- payload as Actions['SET_GIZMO_MODE']['PAYLOAD'],
239
- );
240
- break;
241
- }
242
- case 'SET_GIZMO_VISIBILITY': {
243
- returnValue = this.setGizmoVisibility(
244
- payload as Actions['SET_GIZMO_VISIBILITY']['PAYLOAD'],
245
- );
246
- break;
247
- }
248
- case 'SET_GIZMO_SCALE_LINKED': {
249
- returnValue = this.setGizmoScaleLinked(
250
- payload as Actions['SET_GIZMO_SCALE_LINKED']['PAYLOAD'],
251
- );
252
- break;
253
- }
254
- case 'USE_TOOL': {
255
- returnValue = this.useTool(
256
- payload as Actions['USE_TOOL']['PAYLOAD'],
257
- );
258
- break;
259
- }
260
- case 'MODEL_LOADED': {
261
- returnValue = this.modelLoaded(
262
- payload as Actions['MODEL_LOADED']['PAYLOAD'],
263
- );
264
- break;
265
- }
266
- case 'UPDATE_SCENE': {
267
- returnValue = this.updateScene(
268
- payload as Actions['UPDATE_SCENE']['PAYLOAD'],
269
- );
270
- break;
271
- }
272
- case 'GENERATE_MEDIA': {
273
- returnValue = this.generateMedia(
274
- payload as Actions['GENERATE_MEDIA']['PAYLOAD'],
275
- );
276
- break;
277
- }
278
- case 'SET_PARENT': {
279
- returnValue = this.setParent(
280
- payload as Actions['SET_PARENT']['PAYLOAD'],
281
- );
282
- break;
283
- }
284
- case 'EXPORT_SCENE': {
285
- returnValue = this.exportScene(
286
- payload as Actions['EXPORT_SCENE']['PAYLOAD'],
287
- );
288
- break;
289
- }
290
- case 'LAUNCH_AR': {
291
- const { uri, options } =
292
- payload as Actions['LAUNCH_AR']['PAYLOAD'];
293
- returnValue = new Promise<void>((resolve, reject) => {
294
- this._ar
295
- .get()
296
- .then((ar) => {
297
- resolve(ar.launch(uri, options));
298
- })
299
- .catch(reject);
300
- });
301
- break;
302
- }
303
- default: {
304
- console.warn(
305
- `DIVECommunication.PerformAction: has been executed with unknown Action type ${action}`,
306
- );
307
- }
308
- }
309
-
310
- this.dispatch(action, payload);
311
-
312
- return returnValue;
313
- }
314
-
315
- public Subscribe<Action extends keyof Actions>(
316
- type: Action,
317
- listener: EventListener<Action>,
318
- ): Unsubscribe {
319
- if (!this.listeners.get(type)) this.listeners.set(type, []);
320
-
321
- // casting to any because of typescript not finding between Action and typeof Actions being equal in this case
322
- this.listeners
323
- .get(type)!
324
- .push(listener as EventListener<keyof Actions>);
325
-
326
- return () => {
327
- const listenerArray = this.listeners.get(type);
328
- if (!listenerArray) return false;
329
-
330
- const existingIndex = listenerArray.findIndex(
331
- (entry) => entry === listener,
332
- );
333
- if (existingIndex === -1) return false;
334
-
335
- listenerArray.splice(existingIndex, 1);
336
- return true;
337
- };
338
- }
339
-
340
- private dispatch<Action extends keyof Actions>(
341
- type: Action,
342
- payload: Actions[Action]['PAYLOAD'],
343
- ): void {
344
- const listenerArray = this.listeners.get(type);
345
- if (!listenerArray) return;
346
-
347
- listenerArray.forEach((listener) => listener(payload));
348
- }
349
-
350
- private getAllSceneData(
351
- payload: Actions['GET_ALL_SCENE_DATA']['PAYLOAD'],
352
- ): Actions['GET_ALL_SCENE_DATA']['RETURN'] {
353
- const sceneData = {
354
- name: this.scene.name,
355
- mediaItem: null,
356
- backgroundColor:
357
- '#' + (this.scene.background as Color).getHexString(),
358
- floorEnabled: this.scene.Floor.visible,
359
- floorColor:
360
- '#' +
361
- (
362
- this.scene.Floor.material as MeshStandardMaterial
363
- ).color.getHexString(),
364
- userCamera: {
365
- position: this.controller.object.position.clone(),
366
- target: this.controller.target.clone(),
367
- },
368
- spotmarks: [],
369
- lights: Array.from(this.registered.values()).filter(
370
- (object) => object.entityType === 'light',
371
- ) as COMLight[],
372
- objects: Array.from(this.registered.values()).filter(
373
- (object) => object.entityType === 'model',
374
- ) as COMModel[],
375
- cameras: Array.from(this.registered.values()).filter(
376
- (object) => object.entityType === 'pov',
377
- ) as COMPov[],
378
- primitives: Array.from(this.registered.values()).filter(
379
- (object) => object.entityType === 'primitive',
380
- ) as COMPrimitive[],
381
- groups: Array.from(this.registered.values()).filter(
382
- (object) => object.entityType === 'group',
383
- ) as COMGroup[],
384
- };
385
- Object.assign(payload, sceneData);
386
- return sceneData;
387
- }
388
-
389
- private getAllObjects(
390
- payload: Actions['GET_ALL_OBJECTS']['PAYLOAD'],
391
- ): Actions['GET_ALL_OBJECTS']['RETURN'] {
392
- Object.assign(payload, this.registered);
393
- return this.registered;
394
- }
395
-
396
- private getObjects(
397
- payload: Actions['GET_OBJECTS']['PAYLOAD'],
398
- ): Actions['GET_OBJECTS']['RETURN'] {
399
- if (payload.ids.length === 0) return [];
400
-
401
- const objects: COMEntity[] = [];
402
- this.registered.forEach((object) => {
403
- if (!payload.ids.includes(object.id)) return;
404
- objects.push(object);
405
- });
406
-
407
- return objects;
408
- }
409
-
410
- private addObject(
411
- payload: Actions['ADD_OBJECT']['PAYLOAD'],
412
- ): Actions['ADD_OBJECT']['RETURN'] {
413
- if (this.registered.get(payload.id)) return false;
414
-
415
- if (payload.parentId === undefined) payload.parentId = null;
416
-
417
- this.registered.set(payload.id, payload);
418
-
419
- this.scene.AddSceneObject(payload);
420
-
421
- return true;
422
- }
423
-
424
- private updateObject(
425
- payload: Actions['UPDATE_OBJECT']['PAYLOAD'],
426
- ): Actions['UPDATE_OBJECT']['RETURN'] {
427
- const objectToUpdate = this.registered.get(payload.id);
428
- if (!objectToUpdate) return false;
429
-
430
- this.registered.set(payload.id, merge(objectToUpdate, payload));
431
-
432
- const updatedObject = this.registered.get(payload.id)!;
433
- this.scene.UpdateSceneObject({
434
- ...payload,
435
- id: updatedObject.id,
436
- entityType: updatedObject.entityType,
437
- });
438
-
439
- Object.assign(payload, updatedObject);
440
-
441
- return true;
442
- }
443
-
444
- private deleteObject(
445
- payload: Actions['DELETE_OBJECT']['PAYLOAD'],
446
- ): Actions['DELETE_OBJECT']['RETURN'] {
447
- const deletedObject = this.registered.get(payload.id);
448
- if (!deletedObject) return false;
449
-
450
- // If the object has a parent, detach it first
451
- if (deletedObject.parentId) {
452
- // First detach from parent group
453
- this.setParent({
454
- object: { id: deletedObject.id },
455
- parent: null,
456
- });
457
- }
458
-
459
- // If deleting a group, update all children to have no parent
460
- if (deletedObject.entityType === 'group') {
461
- this.registered.forEach((object) => {
462
- if (object.parentId === deletedObject.id) {
463
- this.updateObject({
464
- id: object.id,
465
- parentId: null,
466
- });
467
- }
468
- });
469
- }
470
-
471
- // copy object to payload to use later
472
- Object.assign(payload, deletedObject);
473
-
474
- this.registered.delete(payload.id);
475
-
476
- // detach all children from parent if we delete a group
477
- Array.from(this.registered.values()).forEach((object) => {
478
- if (!object.parentId) return;
479
- if (object.parentId !== payload.id) return;
480
- object.parentId = null;
481
- });
482
-
483
- this.scene.DeleteSceneObject(deletedObject);
484
-
485
- return true;
486
- }
487
-
488
- private selectObject(
489
- payload: Actions['SELECT_OBJECT']['PAYLOAD'],
490
- ): Actions['SELECT_OBJECT']['RETURN'] {
491
- const object = this.registered.get(payload.id);
492
- if (!object) return false;
493
-
494
- const sceneObject = this.scene.GetSceneObject(object);
495
- if (!sceneObject) return false;
496
-
497
- if (!('isSelectable' in sceneObject)) return false;
498
-
499
- const activeTool = this.toolbox.GetActiveTool();
500
- if (activeTool && isSelectTool(activeTool)) {
501
- activeTool.AttachGizmo(sceneObject as DIVESelectable);
502
- }
503
-
504
- // copy object to payload to use later
505
- Object.assign(payload, object);
506
-
507
- return true;
508
- }
509
-
510
- private deselectObject(
511
- payload: Actions['DESELECT_OBJECT']['PAYLOAD'],
512
- ): Actions['DESELECT_OBJECT']['RETURN'] {
513
- const object = this.registered.get(payload.id);
514
- if (!object) return false;
515
-
516
- const sceneObject = this.scene.GetSceneObject(object);
517
- if (!sceneObject) return false;
518
-
519
- if (!('isSelectable' in sceneObject)) return false;
520
-
521
- const activeTool = this.toolbox.GetActiveTool();
522
- if (activeTool && isSelectTool(activeTool)) {
523
- activeTool.DetachGizmo();
524
- }
525
-
526
- // copy object to payload to use later
527
- Object.assign(payload, object);
528
-
529
- return true;
530
- }
531
-
532
- private setBackground(
533
- payload: Actions['SET_BACKGROUND']['PAYLOAD'],
534
- ): Actions['SET_BACKGROUND']['RETURN'] {
535
- this.scene.SetBackground(payload.color);
536
-
537
- return true;
538
- }
539
-
540
- private dropIt(
541
- payload: Actions['DROP_IT']['PAYLOAD'],
542
- ): Actions['DROP_IT']['RETURN'] {
543
- const object = this.registered.get(payload.id);
544
- if (!object) return false;
545
-
546
- const model = this.scene.GetSceneObject(object) as DIVEModel;
547
- model.DropIt();
548
-
549
- return true;
550
- }
551
-
552
- private placeOnFloor(
553
- payload: Actions['PLACE_ON_FLOOR']['PAYLOAD'],
554
- ): Actions['PLACE_ON_FLOOR']['RETURN'] {
555
- const object = this.registered.get(payload.id);
556
- if (!object) return false;
557
-
558
- this.scene.PlaceOnFloor(object);
559
-
560
- return true;
561
- }
562
-
563
- private setCameraTransform(
564
- payload: Actions['SET_CAMERA_TRANSFORM']['PAYLOAD'],
565
- ): Actions['SET_CAMERA_TRANSFORM']['RETURN'] {
566
- this.controller.object.position.copy(payload.position);
567
- this.controller.target.copy(payload.target);
568
- this.controller.update();
569
-
570
- return true;
571
- }
572
-
573
- private getCameraTransform(
574
- payload: Actions['GET_CAMERA_TRANSFORM']['PAYLOAD'],
575
- ): Actions['GET_CAMERA_TRANSFORM']['RETURN'] {
576
- const transform = {
577
- position: this.controller.object.position.clone(),
578
- target: this.controller.target.clone(),
579
- };
580
- Object.assign(payload, transform);
581
-
582
- return transform;
583
- }
584
-
585
- private moveCamera(
586
- payload: Actions['MOVE_CAMERA']['PAYLOAD'],
587
- ): Actions['MOVE_CAMERA']['RETURN'] {
588
- let position = { x: 0, y: 0, z: 0 };
589
- let target = { x: 0, y: 0, z: 0 };
590
- if ('id' in payload) {
591
- position = (this.registered.get(payload.id) as COMPov).position;
592
- target = (this.registered.get(payload.id) as COMPov).target;
593
- } else {
594
- position = payload.position;
595
- target = payload.target;
596
- }
597
- this.controller.MoveTo(
598
- position,
599
- target,
600
- payload.duration,
601
- payload.locked,
602
- );
603
-
604
- return true;
605
- }
606
-
607
- private setCameraLayer(
608
- payload: Actions['SET_CAMERA_LAYER']['PAYLOAD'],
609
- ): Actions['SET_CAMERA_LAYER']['RETURN'] {
610
- this.controller.object.SetCameraLayer(payload.layer);
611
-
612
- return true;
613
- }
614
-
615
- private resetCamera(
616
- payload: Actions['RESET_CAMERA']['PAYLOAD'],
617
- ): Actions['RESET_CAMERA']['RETURN'] {
618
- this.controller.RevertLast(payload.duration);
619
-
620
- return true;
621
- }
622
-
623
- private computeEncompassingView(
624
- payload: Actions['COMPUTE_ENCOMPASSING_VIEW']['PAYLOAD'],
625
- ): Actions['COMPUTE_ENCOMPASSING_VIEW']['RETURN'] {
626
- const sceneBB = this.scene.ComputeSceneBB();
627
-
628
- const transform = this.controller.ComputeEncompassingView(sceneBB);
629
- Object.assign(payload, transform);
630
-
631
- return transform;
632
- }
633
-
634
- private zoomCamera(
635
- payload: Actions['ZOOM_CAMERA']['PAYLOAD'],
636
- ): Actions['ZOOM_CAMERA']['RETURN'] {
637
- if (payload.direction === 'IN') this.controller.ZoomIn(payload.by);
638
- if (payload.direction === 'OUT') this.controller.ZoomOut(payload.by);
639
-
640
- return true;
641
- }
642
-
643
- private setGizmoMode(
644
- payload: Actions['SET_GIZMO_MODE']['PAYLOAD'],
645
- ): Actions['SET_GIZMO_MODE']['RETURN'] {
646
- this.toolbox.SetGizmoMode(payload.mode);
647
- return true;
648
- }
649
-
650
- private setGizmoVisibility(
651
- payload: Actions['SET_GIZMO_VISIBILITY']['PAYLOAD'],
652
- ): Actions['SET_GIZMO_VISIBILITY']['RETURN'] {
653
- this.toolbox.SetGizmoVisibility(payload);
654
- return payload;
655
- }
656
-
657
- private setGizmoScaleLinked(
658
- payload: Actions['SET_GIZMO_SCALE_LINKED']['PAYLOAD'],
659
- ): Actions['SET_GIZMO_SCALE_LINKED']['RETURN'] {
660
- this.toolbox.SetGizmoScaleLinked(payload);
661
- return payload;
662
- }
663
-
664
- private useTool(
665
- payload: Actions['USE_TOOL']['PAYLOAD'],
666
- ): Actions['USE_TOOL']['RETURN'] {
667
- this.toolbox.UseTool(payload.tool);
668
- return true;
669
- }
670
-
671
- private modelLoaded(
672
- payload: Actions['MODEL_LOADED']['PAYLOAD'],
673
- ): Actions['MODEL_LOADED']['RETURN'] {
674
- (this.registered.get(payload.id) as COMModel).loaded = true;
675
- return true;
676
- }
677
-
678
- private updateScene(
679
- payload: Actions['UPDATE_SCENE']['PAYLOAD'],
680
- ): Actions['UPDATE_SCENE']['RETURN'] {
681
- if (payload.name !== undefined) this.scene.name = payload.name;
682
- if (payload.backgroundColor !== undefined)
683
- this.scene.SetBackground(payload.backgroundColor);
684
-
685
- if (payload.gridEnabled !== undefined)
686
- this.scene.Grid.SetVisibility(payload.gridEnabled);
687
-
688
- if (payload.floorEnabled !== undefined)
689
- this.scene.Floor.SetVisibility(payload.floorEnabled);
690
- if (payload.floorColor !== undefined)
691
- this.scene.Floor.SetColor(payload.floorColor);
692
-
693
- // fill payload with current values
694
- // TODO optmize this
695
- payload.name = this.scene.name;
696
- payload.backgroundColor =
697
- '#' + (this.scene.background as Color).getHexString();
698
- payload.gridEnabled = this.scene.Grid.visible;
699
- payload.floorEnabled = this.scene.Floor.visible;
700
- payload.floorColor =
701
- '#' +
702
- (
703
- this.scene.Floor.material as MeshStandardMaterial
704
- ).color.getHexString();
705
-
706
- return true;
707
- }
708
-
709
- private generateMedia(
710
- payload: Actions['GENERATE_MEDIA']['PAYLOAD'],
711
- ): Actions['GENERATE_MEDIA']['RETURN'] {
712
- let position = { x: 0, y: 0, z: 0 };
713
- let target = { x: 0, y: 0, z: 0 };
714
- if ('id' in payload) {
715
- position = (this.registered.get(payload.id) as COMPov).position;
716
- target = (this.registered.get(payload.id) as COMPov).target;
717
- } else {
718
- position = payload.position;
719
- target = payload.target;
720
- }
721
-
722
- return this._mediaGenerator.get().then((module) => {
723
- return module.GenerateMedia(
724
- position,
725
- target,
726
- payload.width,
727
- payload.height,
728
- );
729
- });
730
- }
731
-
732
- private setParent(
733
- payload: Actions['SET_PARENT']['PAYLOAD'],
734
- ): Actions['SET_PARENT']['RETURN'] {
735
- const object = this.registered.get(payload.object.id);
736
- if (!object) return false;
737
-
738
- const sceneObject = this.scene.GetSceneObject(object);
739
- if (!sceneObject) return false;
740
-
741
- if (payload.parent === null) {
742
- // detach from current parent
743
- this.scene.Root.attach(sceneObject);
744
- // Update registration to reflect no parent
745
- this.updateObject({
746
- id: object.id,
747
- parentId: null,
748
- });
749
- return true;
750
- }
751
-
752
- if (payload.object.id === payload.parent.id) {
753
- // cannot attach object to itself
754
- return false;
755
- }
756
-
757
- const parent = this.registered.get(payload.parent.id);
758
- if (!parent) {
759
- // detach from current parent
760
- this.scene.Root.attach(sceneObject);
761
- // Update registration to reflect no parent
762
- this.updateObject({
763
- id: object.id,
764
- parentId: null,
765
- });
766
- return true;
767
- }
768
-
769
- // attach to new parent
770
- const parentObject = this.scene.GetSceneObject(parent);
771
- if (!parentObject) {
772
- // detach from current parent
773
- this.scene.Root.attach(sceneObject);
774
- // Update registration to reflect no parent
775
- this.updateObject({
776
- id: object.id,
777
- parentId: null,
778
- });
779
- return true;
780
- }
781
-
782
- // attach to new parent
783
- parentObject.attach(sceneObject);
784
- // Update registration to reflect new parent
785
- this.updateObject({
786
- id: object.id,
787
- parentId: parent.id,
788
- });
789
- return true;
790
- }
791
-
792
- private exportScene(
793
- payload: Actions['EXPORT_SCENE']['PAYLOAD'],
794
- ): Actions['EXPORT_SCENE']['RETURN'] {
795
- return new Promise<string | null>((resolve, reject) => {
796
- this._io
797
- .get()
798
- .then((io) => {
799
- resolve(io.Export(payload.type));
800
- })
801
- .catch(reject);
802
- });
803
- }
804
- }
805
-
806
- export type { Actions } from './actions/index.ts';