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