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