@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.
- package/README.md +271 -40
- package/build/dive.cjs +575 -159
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +83 -57
- package/build/dive.d.ts +83 -57
- package/build/dive.js +614 -164
- package/build/dive.js.map +1 -1
- package/package.json +72 -60
- package/src/__test__/DIVE.test.ts +35 -31
- package/src/animation/AnimationSystem.ts +4 -4
- package/src/animation/__test__/AnimationSystem.test.ts +3 -3
- package/src/axiscamera/AxisCamera.ts +31 -11
- package/src/axiscamera/__test__/AxisCamera.test.ts +18 -10
- package/src/camera/PerspectiveCamera.ts +28 -13
- package/src/camera/__test__/PerspectiveCamera.test.ts +2 -2
- package/src/com/Communication.ts +282 -100
- package/src/com/__test__/Communication.test.ts +207 -141
- package/src/com/actions/camera/computeencompassingview.ts +8 -7
- package/src/com/actions/camera/getcameratransform.ts +8 -7
- package/src/com/actions/camera/movecamera.ts +16 -13
- package/src/com/actions/camera/resetcamera.ts +4 -3
- package/src/com/actions/camera/setcameralayer.ts +4 -3
- package/src/com/actions/camera/setcameratransform.ts +8 -7
- package/src/com/actions/camera/zoomcamera.ts +4 -3
- package/src/com/actions/index.ts +54 -54
- package/src/com/actions/media/generatemedia.ts +17 -13
- package/src/com/actions/object/addobject.ts +5 -4
- package/src/com/actions/object/deleteobject.ts +5 -4
- package/src/com/actions/object/deselectobject.ts +5 -4
- package/src/com/actions/object/getallobjects.ts +5 -4
- package/src/com/actions/object/getobjects.ts +5 -4
- package/src/com/actions/object/model/dropit.ts +4 -3
- package/src/com/actions/object/model/modelloaded.ts +4 -3
- package/src/com/actions/object/model/placeonfloor.ts +4 -3
- package/src/com/actions/object/selectobject.ts +5 -4
- package/src/com/actions/object/setparent.ts +8 -7
- package/src/com/actions/object/updateobject.ts +5 -4
- package/src/com/actions/scene/exportscene.ts +5 -4
- package/src/com/actions/scene/getallscenedata.ts +24 -18
- package/src/com/actions/scene/setbackground.ts +4 -3
- package/src/com/actions/scene/updatescene.ts +10 -9
- package/src/com/actions/toolbox/select/setgizmomode.ts +4 -3
- package/src/com/actions/toolbox/transform/setgizmovisible.ts +4 -3
- package/src/com/actions/toolbox/usetool.ts +5 -4
- package/src/com/types/COMBaseEntity.ts +2 -2
- package/src/com/types/COMEntity.ts +6 -6
- package/src/com/types/COMEntityType.ts +1 -1
- package/src/com/types/COMGeometry.ts +2 -2
- package/src/com/types/COMGroup.ts +3 -3
- package/src/com/types/COMLight.ts +3 -3
- package/src/com/types/COMMaterial.ts +2 -2
- package/src/com/types/COMModel.ts +4 -4
- package/src/com/types/COMPov.ts +3 -3
- package/src/com/types/COMPrimitive.ts +5 -5
- package/src/com/types/index.ts +10 -10
- package/src/constant/AxisHelperColors.ts +1 -1
- package/src/constant/GridColors.ts +1 -1
- package/src/controls/OrbitControls.ts +62 -29
- package/src/controls/__test__/OrbitControls.test.ts +133 -39
- package/src/dive.ts +82 -36
- package/src/gizmo/Gizmo.ts +21 -13
- package/src/gizmo/handles/AxisHandle.ts +40 -17
- package/src/gizmo/handles/RadialHandle.ts +39 -15
- package/src/gizmo/handles/ScaleHandle.ts +62 -25
- package/src/gizmo/plane/GizmoPlane.ts +5 -6
- package/src/gizmo/rotate/RotateGizmo.ts +58 -16
- package/src/gizmo/scale/ScaleGizmo.ts +37 -15
- package/src/gizmo/translate/TranslateGizmo.ts +34 -14
- package/src/grid/Grid.ts +13 -5
- package/src/grid/__test__/Grid.test.ts +5 -3
- package/src/group/Group.ts +9 -7
- package/src/group/__test__/Group.test.ts +8 -6
- package/src/helper/applyMixins/__test__/applyMixins.test.ts +9 -6
- package/src/helper/applyMixins/applyMixins.ts +6 -3
- package/src/helper/findInterface/__test__/findInterface.test.ts +28 -18
- package/src/helper/findInterface/findInterface.ts +7 -4
- package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +1 -1
- package/src/helper/findSceneRecursive/findSceneRecursive.ts +1 -1
- package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +43 -7
- package/src/helper/getObjectDelta/getObjectDelta.ts +13 -9
- package/src/helper/isInterface/__test__/implementsInterface.test.ts +1 -1
- package/src/helper/isInterface/implementsInterface.ts +6 -3
- package/src/info/Info.ts +20 -16
- package/src/info/__test__/Info.test.ts +67 -36
- package/src/interface/Draggable.ts +2 -2
- package/src/interface/Hoverable.ts +2 -2
- package/src/interface/Movable.ts +1 -1
- package/src/interface/Rotatable.ts +1 -1
- package/src/interface/Scalable.ts +1 -1
- package/src/io/IO.ts +21 -43
- package/src/io/__test__/IO.test.ts +16 -62
- package/src/io/gltf/GLTFIO.ts +34 -31
- package/src/io/gltf/__test__/GLTFIO.test.ts +88 -78
- package/src/light/PointLight.ts +42 -9
- package/src/light/SceneLight.ts +5 -5
- package/src/light/__test__/AmbientLight.test.ts +5 -4
- package/src/light/__test__/PointLight.test.ts +14 -10
- package/src/light/__test__/SceneLight.test.ts +19 -13
- package/src/loadingmanager/LoadingManager.ts +11 -6
- package/src/loadingmanager/__test__/LoadingManager.test.ts +14 -9
- package/src/math/__test__/DIVEMath.test.ts +1 -1
- package/src/math/ceil/__test__/ceilExp.test.ts +1 -1
- package/src/math/ceil/ceilExp.ts +2 -2
- package/src/math/floor/__test__/floorExp.test.ts +1 -1
- package/src/math/floor/floorExp.ts +2 -2
- package/src/math/helper/__test__/shift.test.ts +1 -1
- package/src/math/helper/shift.ts +1 -1
- package/src/math/index.ts +7 -7
- package/src/math/round/__test__/roundExp.test.ts +1 -1
- package/src/math/round/roundExp.ts +6 -3
- package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +10 -4
- package/src/math/signedAngleTo/signedAngleTo.ts +11 -4
- package/src/math/toFixed/__test__/toFixedExp.test.ts +9 -9
- package/src/math/toFixed/toFixedExp.ts +6 -3
- package/src/math/truncate/__test__/truncateExp.test.ts +1 -1
- package/src/math/truncate/truncateExp.ts +6 -3
- package/src/mediacreator/MediaCreator.ts +20 -10
- package/src/mediacreator/__test__/MediaCreator.test.ts +27 -12
- package/src/model/Model.ts +35 -7
- package/src/model/__test__/Model.test.ts +71 -44
- package/src/node/Node.ts +34 -12
- package/src/node/__test__/Node.test.ts +17 -13
- package/src/primitive/Primitive.ts +78 -13
- package/src/primitive/__test__/Primitive.test.ts +49 -38
- package/src/primitive/floor/Floor.ts +14 -3
- package/src/primitive/floor/__test__/Floor.test.ts +10 -4
- package/src/renderer/Renderer.ts +46 -15
- package/src/renderer/__test__/Renderer.test.ts +74 -24
- package/src/scene/Scene.ts +9 -3
- package/src/scene/__test__/Scene.test.ts +2 -2
- package/src/scene/root/Root.ts +142 -75
- package/src/scene/root/__test__/Root.test.ts +439 -111
- package/src/toolbox/BaseTool.ts +69 -33
- package/src/toolbox/Toolbox.ts +37 -17
- package/src/toolbox/__test__/BaseTool.test.ts +324 -160
- package/src/toolbox/__test__/Toolbox.test.ts +31 -14
- package/src/toolbox/select/SelectTool.ts +24 -19
- package/src/toolbox/select/__test__/SelectTool.test.ts +95 -59
- package/src/toolbox/transform/TransformTool.ts +40 -17
- package/src/toolbox/transform/__test__/TransformTool.test.ts +22 -15
- package/src/types/SceneObjects.ts +8 -8
- package/src/types/SceneType.ts +3 -3
- package/src/types/index.ts +3 -6
package/src/com/Communication.ts
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import { Actions } from
|
|
1
|
+
import { Actions } from './actions/index.ts';
|
|
2
2
|
import { generateUUID } from 'three/src/math/MathUtils';
|
|
3
|
-
import { isSelectTool } from
|
|
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
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import { type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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(
|
|
55
|
+
const fromComID = this.__instances.find(
|
|
56
|
+
(instance) => instance.id === id,
|
|
57
|
+
);
|
|
48
58
|
if (fromComID) return fromComID;
|
|
49
|
-
return this.__instances.find((instance) =>
|
|
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')
|
|
66
|
-
|
|
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')
|
|
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>[]> =
|
|
84
|
-
|
|
85
|
-
|
|
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(
|
|
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>(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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>(
|
|
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
|
|
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(
|
|
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>(
|
|
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(
|
|
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:
|
|
343
|
+
backgroundColor:
|
|
344
|
+
'#' + (this.scene.background as Color).getHexString(),
|
|
249
345
|
floorEnabled: this.scene.Floor.visible,
|
|
250
|
-
floorColor:
|
|
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(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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({
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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)
|
|
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.
|
|
475
|
-
|
|
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 =
|
|
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 =
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
}
|