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