@shopware-ag/dive 1.0.7 → 1.0.8
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/package.json +6 -3
- package/src/__test__/DIVE.test.ts +244 -0
- package/src/animation/AnimationSystem.ts +14 -0
- package/src/animation/__test__/AnimationSystem.test.ts +19 -0
- package/src/axiscamera/AxisCamera.ts +50 -0
- package/src/axiscamera/__test__/AxisCamera.test.ts +41 -0
- package/src/camera/PerspectiveCamera.ts +43 -0
- package/src/camera/__test__/PerspectiveCamera.test.ts +27 -0
- package/src/com/Communication.ts +382 -0
- package/src/com/__test__/Communication.test.ts +612 -0
- package/src/com/actions/camera/getcameratransform.ts +9 -0
- package/src/com/actions/camera/movecamera.ts +15 -0
- package/src/com/actions/camera/resetcamera.ts +4 -0
- package/src/com/actions/camera/setcameralayer.ts +4 -0
- package/src/com/actions/camera/setcameratransform.ts +9 -0
- package/src/com/actions/camera/zoomcamera.ts +4 -0
- package/src/com/actions/index.ts +41 -0
- package/src/com/actions/media/generatemedia.ts +15 -0
- package/src/com/actions/object/addobject.ts +6 -0
- package/src/com/actions/object/deleteobject.ts +6 -0
- package/src/com/actions/object/getallobjects.ts +6 -0
- package/src/com/actions/object/getobjects.ts +6 -0
- package/src/com/actions/object/model/modelloaded.ts +4 -0
- package/src/com/actions/object/model/placeonfloor.ts +4 -0
- package/src/com/actions/object/selectobject.ts +6 -0
- package/src/com/actions/object/updateobject.ts +6 -0
- package/src/com/actions/scene/getallscenedata.ts +23 -0
- package/src/com/actions/scene/setbackground.ts +4 -0
- package/src/com/actions/scene/updatescene.ts +9 -0
- package/src/com/actions/toolbox/select/setgizmomode.ts +4 -0
- package/src/com/index.ts +4 -0
- package/src/com/types.ts +30 -0
- package/src/constant/AxisHelperColors.ts +7 -0
- package/src/constant/GridColors.ts +2 -0
- package/src/constant/VisibilityLayerMask.ts +5 -0
- package/src/controls/OrbitControls.ts +145 -0
- package/src/controls/__test__/OrbitControls.test.ts +181 -0
- package/src/grid/Grid.ts +22 -0
- package/src/grid/__test__/Grid.test.ts +19 -0
- package/src/helper/applyMixins/__test__/applyMixins.test.ts +27 -0
- package/src/helper/applyMixins/applyMixins.ts +15 -0
- package/src/helper/getObjectDelta/__test__/getObjectDelta.spec.ts +152 -0
- package/src/helper/getObjectDelta/getObjectDelta.ts +101 -0
- package/src/interface/Moveable.ts +13 -0
- package/src/interface/Rotatable.ts +10 -0
- package/src/interface/Scalable.ts +10 -0
- package/src/interface/Selectable.ts +11 -0
- package/src/interface/__test__/Interfaces.test.ts +13 -0
- package/src/light/AmbientLight.ts +29 -0
- package/src/light/PointLight.ts +63 -0
- package/src/light/SceneLight.ts +60 -0
- package/src/light/__test__/AmbientLight.test.ts +44 -0
- package/src/light/__test__/PointLight.test.ts +98 -0
- package/src/light/__test__/SceneLight.test.ts +122 -0
- package/src/loadingmanager/LoadingManager.ts +44 -0
- package/src/loadingmanager/__test__/LoadingManager.test.ts +52 -0
- package/src/math/__test__/DIVEMath.test.ts +12 -0
- package/src/math/ceil/__test__/ceilExp.test.ts +12 -0
- package/src/math/ceil/ceilExp.ts +6 -0
- package/src/math/floor/__test__/floorExp.test.ts +14 -0
- package/src/math/floor/floorExp.ts +6 -0
- package/src/math/helper/__test__/shift.test.ts +12 -0
- package/src/math/helper/shift.ts +4 -0
- package/src/math/index.ts +19 -0
- package/src/math/round/__test__/roundExp.test.ts +14 -0
- package/src/math/round/roundExp.ts +7 -0
- package/src/math/toFixed/__test__/toFixedExp.test.ts +14 -0
- package/src/math/toFixed/toFixedExp.ts +6 -0
- package/src/math/truncate/__test__/truncateExp.test.ts +14 -0
- package/src/math/truncate/truncateExp.ts +6 -0
- package/src/mediacreator/MediaCreator.ts +65 -0
- package/src/mediacreator/__test__/MediaCreator.test.ts +113 -0
- package/src/model/Model.ts +72 -0
- package/src/model/__test__/Model.test.ts +163 -0
- package/src/primitive/floor/Floor.ts +34 -0
- package/src/primitive/floor/__test__/Floor.test.ts +21 -0
- package/src/renderer/Renderer.ts +165 -0
- package/src/renderer/__test__/Renderer.test.ts +169 -0
- package/src/scene/Scene.ts +49 -0
- package/src/scene/__test__/Scene.test.ts +70 -0
- package/src/scene/root/Root.ts +107 -0
- package/src/scene/root/__test__/Root.test.ts +129 -0
- package/src/scene/root/lightroot/LightRoot.ts +84 -0
- package/src/scene/root/lightroot/__test__/LightRoot.test.ts +137 -0
- package/src/scene/root/modelroot/ModelRoot.ts +82 -0
- package/src/scene/root/modelroot/__test__/ModelRoot.test.ts +185 -0
- package/src/toolbox/BaseTool.ts +18 -0
- package/src/toolbox/Toolbox.ts +76 -0
- package/src/toolbox/__test__/Toolbox.test.ts +109 -0
- package/src/toolbox/select/SelectTool.ts +123 -0
- package/src/toolbox/select/__test__/SelectTool.test.ts +190 -0
- package/build/dive.cjs +0 -1551
- package/build/dive.cjs.map +0 -1
- package/build/dive.d.cts +0 -558
- package/build/dive.d.ts +0 -558
- package/build/dive.js +0 -1516
- package/build/dive.js.map +0 -1
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
import DIVECommunication from '../Communication';
|
|
2
|
+
import DIVEScene from '../../scene/Scene';
|
|
3
|
+
import DIVEToolbox from '../../toolbox/Toolbox';
|
|
4
|
+
import DIVEMediaCreator from '../../mediacreator/MediaCreator';
|
|
5
|
+
import '..';
|
|
6
|
+
import '../types';
|
|
7
|
+
import '../actions';
|
|
8
|
+
import '../actions/camera/movecamera';
|
|
9
|
+
import '../actions/camera/resetcamera';
|
|
10
|
+
import '../actions/camera/setcameralayer';
|
|
11
|
+
import '../actions/camera/setcameratransform';
|
|
12
|
+
import '../actions/camera/zoomcamera';
|
|
13
|
+
import '../actions/media/generatemedia';
|
|
14
|
+
import '../actions/object/addobject';
|
|
15
|
+
import '../actions/object/deleteobject';
|
|
16
|
+
import '../actions/object/getallobjects';
|
|
17
|
+
import '../actions/object/getobjects';
|
|
18
|
+
import '../actions/object/selectobject';
|
|
19
|
+
import '../actions/object/updateobject';
|
|
20
|
+
import '../actions/object/model/modelloaded';
|
|
21
|
+
import '../actions/object/model/placeonfloor';
|
|
22
|
+
import '../actions/scene/getallscenedata';
|
|
23
|
+
import '../actions/scene/setbackground';
|
|
24
|
+
import '../actions/scene/updatescene';
|
|
25
|
+
import '../actions/toolbox/select/setgizmomode';
|
|
26
|
+
import '../actions/camera/getcameratransform';
|
|
27
|
+
import DIVEOrbitControls from '../../controls/OrbitControls';
|
|
28
|
+
import { COMLight, COMModel, COMPov } from '../types';
|
|
29
|
+
import { Object3D } from 'three';
|
|
30
|
+
|
|
31
|
+
jest.mock('three/src/math/MathUtils', () => {
|
|
32
|
+
return {
|
|
33
|
+
generateUUID: jest.fn().mockReturnValue('uuid'),
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const mockScene = {
|
|
38
|
+
SetBackground: jest.fn(),
|
|
39
|
+
AddSceneObject: jest.fn(),
|
|
40
|
+
UpdateSceneObject: jest.fn(),
|
|
41
|
+
DeleteSceneObject: jest.fn(),
|
|
42
|
+
PlaceOnFloor: jest.fn(),
|
|
43
|
+
GetSceneObject: jest.fn(),
|
|
44
|
+
background: {
|
|
45
|
+
getHexString: jest.fn().mockReturnValue('ffffff'),
|
|
46
|
+
},
|
|
47
|
+
Root: {
|
|
48
|
+
Floor: {
|
|
49
|
+
isFloor: true,
|
|
50
|
+
visible: true,
|
|
51
|
+
material: {
|
|
52
|
+
color: {
|
|
53
|
+
getHexString: jest.fn().mockReturnValue('ffffff'),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
SetVisibility: jest.fn(),
|
|
57
|
+
SetColor: jest.fn(),
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
} as unknown as DIVEScene;
|
|
61
|
+
|
|
62
|
+
const mockController = {
|
|
63
|
+
enableDamping: true,
|
|
64
|
+
dampingFactor: 0.25,
|
|
65
|
+
enableZoom: true,
|
|
66
|
+
enablePan: true,
|
|
67
|
+
minPolarAngle: 0,
|
|
68
|
+
maxPolarAngle: Math.PI,
|
|
69
|
+
minDistance: 0,
|
|
70
|
+
maxDistance: Infinity,
|
|
71
|
+
rotateSpeed: 0.5,
|
|
72
|
+
panSpeed: 0.5,
|
|
73
|
+
zoomSpeed: 0.5,
|
|
74
|
+
keyPanSpeed: 0.5,
|
|
75
|
+
screenSpacePanning: true,
|
|
76
|
+
autoRotate: false,
|
|
77
|
+
autoRotateSpeed: 2.0,
|
|
78
|
+
enableKeys: true,
|
|
79
|
+
keys: {
|
|
80
|
+
LEFT: 37,
|
|
81
|
+
UP: 38,
|
|
82
|
+
RIGHT: 39,
|
|
83
|
+
BOTTOM: 40,
|
|
84
|
+
},
|
|
85
|
+
mouseButtons: {
|
|
86
|
+
LEFT: 0,
|
|
87
|
+
MIDDLE: 1,
|
|
88
|
+
RIGHT: 2,
|
|
89
|
+
},
|
|
90
|
+
target: {
|
|
91
|
+
x: 4,
|
|
92
|
+
y: 5,
|
|
93
|
+
z: 6,
|
|
94
|
+
set: jest.fn(),
|
|
95
|
+
clone: jest.fn().mockReturnValue({ x: 4, y: 5, z: 6 }),
|
|
96
|
+
copy: jest.fn(),
|
|
97
|
+
},
|
|
98
|
+
update: jest.fn(),
|
|
99
|
+
dispose: jest.fn(),
|
|
100
|
+
ZoomIn: jest.fn(),
|
|
101
|
+
ZoomOut: jest.fn(),
|
|
102
|
+
object: {
|
|
103
|
+
position: {
|
|
104
|
+
x: 1,
|
|
105
|
+
y: 2,
|
|
106
|
+
z: 3,
|
|
107
|
+
clone: jest.fn().mockReturnValue({ x: 1, y: 2, z: 3 }),
|
|
108
|
+
copy: jest.fn(),
|
|
109
|
+
},
|
|
110
|
+
SetCameraLayer: jest.fn(),
|
|
111
|
+
},
|
|
112
|
+
MoveTo: jest.fn(),
|
|
113
|
+
RevertLast: jest.fn(),
|
|
114
|
+
} as unknown as DIVEOrbitControls;
|
|
115
|
+
|
|
116
|
+
const mockSelect = jest.fn();
|
|
117
|
+
const mockToolBox = {
|
|
118
|
+
UseTool: jest.fn(),
|
|
119
|
+
GetActiveTool: jest.fn().mockReturnValue({
|
|
120
|
+
Select: mockSelect,
|
|
121
|
+
}),
|
|
122
|
+
SetGizmoMode: jest.fn(),
|
|
123
|
+
} as unknown as DIVEToolbox;
|
|
124
|
+
|
|
125
|
+
const mockMediaCreator = {
|
|
126
|
+
GenerateMedia: jest.fn(),
|
|
127
|
+
} as unknown as DIVEMediaCreator;
|
|
128
|
+
let testCom: DIVECommunication;
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
describe('dive/communication/DIVECommunication', () => {
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
testCom = new DIVECommunication(mockScene, mockController, mockToolBox, mockMediaCreator);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
afterEach(() => {
|
|
137
|
+
testCom.DestroyInstance();
|
|
138
|
+
jest.clearAllMocks();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should instantiate', () => {
|
|
142
|
+
expect(testCom).toBeDefined();
|
|
143
|
+
expect(() => DIVECommunication.get('id')).not.toThrow();
|
|
144
|
+
expect(DIVECommunication['__instances']).toHaveLength(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should destroy instance', () => {
|
|
148
|
+
expect(testCom).toBeDefined();
|
|
149
|
+
testCom.DestroyInstance();
|
|
150
|
+
expect(DIVECommunication['__instances']).toBeDefined();
|
|
151
|
+
expect(DIVECommunication['__instances']).toHaveLength(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should subscribe, listen and unsubscribe from action', () => {
|
|
155
|
+
const listener = jest.fn();
|
|
156
|
+
const unsub = testCom.Subscribe('GET_ALL_OBJECTS', listener);
|
|
157
|
+
expect(unsub).toBeDefined();
|
|
158
|
+
expect(unsub).toBeInstanceOf(Function);
|
|
159
|
+
const objects0 = testCom.PerformAction('GET_ALL_OBJECTS', new Map());
|
|
160
|
+
expect(objects0).toBeDefined();
|
|
161
|
+
expect(objects0.size).toBeDefined();
|
|
162
|
+
expect(objects0.size).toBe(0);
|
|
163
|
+
unsub();
|
|
164
|
+
testCom.PerformAction('GET_ALL_OBJECTS', new Map());
|
|
165
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should not unsubscribe twice', () => {
|
|
169
|
+
const unsub = testCom.Subscribe('GET_ALL_OBJECTS', () => { });
|
|
170
|
+
expect(unsub()).toBe(true);
|
|
171
|
+
expect(unsub()).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should not unsubscribe if listener does not exist anymore', () => {
|
|
175
|
+
const unsub = testCom.Subscribe('GET_ALL_OBJECTS', () => { });
|
|
176
|
+
testCom['listeners'].clear();
|
|
177
|
+
expect(unsub()).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should tigger onChange callback', () => {
|
|
181
|
+
const payload = {
|
|
182
|
+
name: 'name',
|
|
183
|
+
entityType: "light",
|
|
184
|
+
id: "ambient00",
|
|
185
|
+
type: "ambient",
|
|
186
|
+
intensity: 0.5,
|
|
187
|
+
color: 'white',
|
|
188
|
+
} as COMLight;
|
|
189
|
+
expect(() => testCom.PerformAction('ADD_OBJECT', payload)).not.toThrow();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// it('should not dispatch with invalid action type', () => {
|
|
193
|
+
// const listener = jest.fn();
|
|
194
|
+
// testCom.Subscribe('GET_ALL_OBJECTS', listener);
|
|
195
|
+
// testCom.dispatch('INVALID_ACTION_TYPE', {});
|
|
196
|
+
// expect(listener).toHaveBeenCalledTimes(0);
|
|
197
|
+
// });
|
|
198
|
+
|
|
199
|
+
it('should perform action ADD_OBJECT', () => {
|
|
200
|
+
const payload = {
|
|
201
|
+
entityType: "light",
|
|
202
|
+
id: "ambient00",
|
|
203
|
+
type: "ambient",
|
|
204
|
+
intensity: 0.5,
|
|
205
|
+
color: 'white',
|
|
206
|
+
} as COMLight;
|
|
207
|
+
const success = testCom.PerformAction('ADD_OBJECT', payload);
|
|
208
|
+
expect(mockScene.AddSceneObject).toHaveBeenCalledTimes(1);
|
|
209
|
+
expect(success).toBe(true);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should not perform action ADD_OBJECT with same object', () => {
|
|
213
|
+
const payload = {
|
|
214
|
+
entityType: "light",
|
|
215
|
+
id: "ambient00",
|
|
216
|
+
type: "ambient",
|
|
217
|
+
intensity: 0.5,
|
|
218
|
+
color: 'white',
|
|
219
|
+
} as COMLight;
|
|
220
|
+
expect(testCom.PerformAction('ADD_OBJECT', payload)).toBe(true);
|
|
221
|
+
expect(testCom.PerformAction('ADD_OBJECT', payload)).toBe(false);
|
|
222
|
+
expect(mockScene.AddSceneObject).toHaveBeenCalledTimes(1);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should perform action UPDATE_OBJECT with existing oject', () => {
|
|
226
|
+
const payload = {
|
|
227
|
+
entityType: "light",
|
|
228
|
+
id: "ambient00",
|
|
229
|
+
type: "ambient",
|
|
230
|
+
intensity: 0.5,
|
|
231
|
+
color: 'white',
|
|
232
|
+
} as COMLight;
|
|
233
|
+
|
|
234
|
+
testCom.PerformAction('ADD_OBJECT', payload);
|
|
235
|
+
|
|
236
|
+
const successUpdate = testCom.PerformAction('UPDATE_OBJECT', payload);
|
|
237
|
+
expect(mockScene.UpdateSceneObject).toHaveBeenCalledTimes(1);
|
|
238
|
+
expect(successUpdate).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('should perform action UPDATE_OBJECT without existing oject', () => {
|
|
242
|
+
const payload = {
|
|
243
|
+
entityType: "light",
|
|
244
|
+
id: "ambient00",
|
|
245
|
+
type: "ambient",
|
|
246
|
+
intensity: 0.5,
|
|
247
|
+
color: 'white',
|
|
248
|
+
} as COMLight;
|
|
249
|
+
const successUpdate = testCom.PerformAction('UPDATE_OBJECT', payload);
|
|
250
|
+
expect(mockScene.UpdateSceneObject).toHaveBeenCalledTimes(0);
|
|
251
|
+
expect(successUpdate).toBe(false);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should perform action DELETE_OBJECT with existing object', () => {
|
|
255
|
+
const payload = {
|
|
256
|
+
entityType: "light",
|
|
257
|
+
id: "ambient00",
|
|
258
|
+
type: "ambient",
|
|
259
|
+
intensity: 0.5,
|
|
260
|
+
color: 'white',
|
|
261
|
+
} as COMLight;
|
|
262
|
+
|
|
263
|
+
testCom.PerformAction('ADD_OBJECT', payload);
|
|
264
|
+
|
|
265
|
+
const successDelete = testCom.PerformAction('DELETE_OBJECT', payload);
|
|
266
|
+
expect(mockScene.DeleteSceneObject).toHaveBeenCalledTimes(1);
|
|
267
|
+
expect(successDelete).toBe(true);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should perform action DELETE_OBJECT without existing object', () => {
|
|
271
|
+
const payload = {
|
|
272
|
+
entityType: "light",
|
|
273
|
+
id: "ambient00",
|
|
274
|
+
type: "ambient",
|
|
275
|
+
intensity: 0.5,
|
|
276
|
+
color: 'white',
|
|
277
|
+
} as COMLight;
|
|
278
|
+
const successDelete = testCom.PerformAction('DELETE_OBJECT', payload);
|
|
279
|
+
expect(mockScene.DeleteSceneObject).toHaveBeenCalledTimes(0);
|
|
280
|
+
expect(successDelete).toBe(false);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('should perform action SET_BACKGROUND', () => {
|
|
284
|
+
const payload = {
|
|
285
|
+
color: 'white',
|
|
286
|
+
};
|
|
287
|
+
const successSet = testCom.PerformAction('SET_BACKGROUND', payload);
|
|
288
|
+
expect(mockScene.SetBackground).toHaveBeenCalledTimes(1);
|
|
289
|
+
expect(successSet).toBe(true);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('should perform action PLACE_ON_FLOOR with existing model', () => {
|
|
293
|
+
const payload = {
|
|
294
|
+
entityType: "model",
|
|
295
|
+
id: "model",
|
|
296
|
+
position: { x: 0, y: 0, z: 0 },
|
|
297
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
298
|
+
scale: { x: 0.01, y: 0.01, z: 0.01 },
|
|
299
|
+
|
|
300
|
+
uri: "https://threejs.org/examples/models/gltf/LittlestTokyo.glb",
|
|
301
|
+
} as COMModel;
|
|
302
|
+
|
|
303
|
+
testCom.PerformAction('ADD_OBJECT', payload);
|
|
304
|
+
|
|
305
|
+
const placeSpy = jest.spyOn(mockScene, 'PlaceOnFloor');
|
|
306
|
+
|
|
307
|
+
const successPlace = testCom.PerformAction('PLACE_ON_FLOOR', payload);
|
|
308
|
+
expect(successPlace).toBe(true);
|
|
309
|
+
expect(placeSpy).toHaveBeenCalledTimes(1);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should perform action PLACE_ON_FLOOR without existing model', () => {
|
|
313
|
+
const payload = {
|
|
314
|
+
entityType: "model",
|
|
315
|
+
id: "model",
|
|
316
|
+
position: { x: 0, y: 0, z: 0 },
|
|
317
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
318
|
+
scale: { x: 0.01, y: 0.01, z: 0.01 },
|
|
319
|
+
|
|
320
|
+
uri: "https://threejs.org/examples/models/gltf/LittlestTokyo.glb",
|
|
321
|
+
};
|
|
322
|
+
const placeSpy = jest.spyOn(mockScene, 'PlaceOnFloor');
|
|
323
|
+
|
|
324
|
+
const successPlace = testCom.PerformAction('PLACE_ON_FLOOR', payload);
|
|
325
|
+
expect(successPlace).toBe(false);
|
|
326
|
+
expect(placeSpy).toHaveBeenCalledTimes(0);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('should perform action GET_ALL_OBJECTS', () => {
|
|
330
|
+
const payload = {
|
|
331
|
+
entityType: "model",
|
|
332
|
+
id: "model",
|
|
333
|
+
position: { x: 0, y: 0, z: 0 },
|
|
334
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
335
|
+
scale: { x: 0.01, y: 0.01, z: 0.01 },
|
|
336
|
+
|
|
337
|
+
uri: "https://threejs.org/examples/models/gltf/LittlestTokyo.glb",
|
|
338
|
+
} as COMModel;
|
|
339
|
+
|
|
340
|
+
const objects0 = testCom.PerformAction('GET_ALL_OBJECTS', new Map());
|
|
341
|
+
expect(objects0).toBeDefined();
|
|
342
|
+
expect(objects0.size).toBeDefined();
|
|
343
|
+
expect(objects0.size).toBe(0);
|
|
344
|
+
|
|
345
|
+
testCom.PerformAction('ADD_OBJECT', payload);
|
|
346
|
+
|
|
347
|
+
const objects1 = testCom.PerformAction('GET_ALL_OBJECTS', new Map());
|
|
348
|
+
expect(objects1).toBeDefined();
|
|
349
|
+
expect(objects1.size).toBeDefined();
|
|
350
|
+
expect(objects1.size).toBe(1);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('should perform action MOVE_CAMERA', () => {
|
|
354
|
+
const payload = {
|
|
355
|
+
position: { x: 0, y: 0, z: 0 },
|
|
356
|
+
target: { x: 0, y: 0, z: 0 },
|
|
357
|
+
duration: 1000,
|
|
358
|
+
locked: true,
|
|
359
|
+
};
|
|
360
|
+
const successSet = testCom.PerformAction('MOVE_CAMERA', payload);
|
|
361
|
+
const moveToSpy = jest.spyOn(mockController, 'MoveTo');
|
|
362
|
+
expect(moveToSpy).toHaveBeenCalledTimes(1);
|
|
363
|
+
expect(successSet).toBe(true);
|
|
364
|
+
|
|
365
|
+
moveToSpy.mockClear();
|
|
366
|
+
testCom.PerformAction('ADD_OBJECT', {
|
|
367
|
+
entityType: "pov",
|
|
368
|
+
id: "pov",
|
|
369
|
+
position: { x: 0, y: 0, z: 0 },
|
|
370
|
+
target: { x: 0, y: 0, z: 0 },
|
|
371
|
+
} as COMPov);
|
|
372
|
+
|
|
373
|
+
const payloadId = {
|
|
374
|
+
id: 'pov',
|
|
375
|
+
locked: true,
|
|
376
|
+
duration: 1000,
|
|
377
|
+
};
|
|
378
|
+
const successSet1 = testCom.PerformAction('MOVE_CAMERA', payloadId);
|
|
379
|
+
expect(moveToSpy).toHaveBeenCalledTimes(1);
|
|
380
|
+
expect(successSet1).toBe(true);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should perform action RESET_CAMERA', () => {
|
|
384
|
+
const payload = {
|
|
385
|
+
duration: 1000,
|
|
386
|
+
};
|
|
387
|
+
const successSet = testCom.PerformAction('RESET_CAMERA', payload);
|
|
388
|
+
expect(mockController.RevertLast).toHaveBeenCalledTimes(1);
|
|
389
|
+
expect(successSet).toBe(true);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('should perform action GET_ALL_SCENE_DATA', () => {
|
|
393
|
+
testCom.PerformAction('ADD_OBJECT', {
|
|
394
|
+
entityType: "pov",
|
|
395
|
+
id: "pov",
|
|
396
|
+
position: { x: 0, y: 0, z: 0 },
|
|
397
|
+
target: { x: 0, y: 0, z: 0 },
|
|
398
|
+
} as COMPov);
|
|
399
|
+
|
|
400
|
+
testCom.PerformAction('ADD_OBJECT', {
|
|
401
|
+
entityType: "model",
|
|
402
|
+
id: "model",
|
|
403
|
+
position: { x: 0, y: 0, z: 0 },
|
|
404
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
405
|
+
scale: { x: 0.01, y: 0.01, z: 0.01 },
|
|
406
|
+
|
|
407
|
+
uri: "https://threejs.org/examples/models/gltf/LittlestTokyo.glb",
|
|
408
|
+
} as COMModel);
|
|
409
|
+
|
|
410
|
+
testCom.PerformAction('ADD_OBJECT', {
|
|
411
|
+
entityType: "light",
|
|
412
|
+
id: "ambient00",
|
|
413
|
+
type: "ambient",
|
|
414
|
+
intensity: 0.5,
|
|
415
|
+
color: 'white',
|
|
416
|
+
} as COMLight);
|
|
417
|
+
|
|
418
|
+
const success = testCom.PerformAction('GET_ALL_SCENE_DATA', {});
|
|
419
|
+
expect(success).toStrictEqual({
|
|
420
|
+
backgroundColor: "#ffffff",
|
|
421
|
+
cameras: [{
|
|
422
|
+
entityType: "pov",
|
|
423
|
+
id: "pov",
|
|
424
|
+
position: { x: 0, y: 0, z: 0 },
|
|
425
|
+
target: { x: 0, y: 0, z: 0 },
|
|
426
|
+
}],
|
|
427
|
+
floorColor: "#ffffff",
|
|
428
|
+
floorEnabled: true,
|
|
429
|
+
lights: [{
|
|
430
|
+
entityType: "light",
|
|
431
|
+
id: "ambient00",
|
|
432
|
+
type: "ambient",
|
|
433
|
+
intensity: 0.5,
|
|
434
|
+
color: 'white',
|
|
435
|
+
}],
|
|
436
|
+
mediaItem: null,
|
|
437
|
+
name: undefined,
|
|
438
|
+
objects: [{
|
|
439
|
+
entityType: "model",
|
|
440
|
+
id: "model",
|
|
441
|
+
position: { x: 0, y: 0, z: 0 },
|
|
442
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
443
|
+
scale: { x: 0.01, y: 0.01, z: 0.01 },
|
|
444
|
+
|
|
445
|
+
uri: "https://threejs.org/examples/models/gltf/LittlestTokyo.glb",
|
|
446
|
+
}],
|
|
447
|
+
spotmarks: [],
|
|
448
|
+
userCamera: {
|
|
449
|
+
position: { x: 1, y: 2, z: 3 },
|
|
450
|
+
target: { x: 4, y: 5, z: 6 },
|
|
451
|
+
},
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('should perform action GET_OBJECTS', () => {
|
|
456
|
+
const mock0 = {
|
|
457
|
+
entityType: "pov",
|
|
458
|
+
id: "test0",
|
|
459
|
+
position: { x: 0, y: 0, z: 0 },
|
|
460
|
+
target: { x: 0, y: 0, z: 0 },
|
|
461
|
+
} as COMPov;
|
|
462
|
+
testCom.PerformAction('ADD_OBJECT', mock0);
|
|
463
|
+
|
|
464
|
+
const mock1 = {
|
|
465
|
+
entityType: "pov",
|
|
466
|
+
id: "test1",
|
|
467
|
+
position: { x: 0, y: 0, z: 0 },
|
|
468
|
+
target: { x: 0, y: 0, z: 0 },
|
|
469
|
+
} as COMPov;
|
|
470
|
+
testCom.PerformAction('ADD_OBJECT', mock1);
|
|
471
|
+
|
|
472
|
+
let map = new Map([['test0', mock0], ['test1', mock1]]);
|
|
473
|
+
|
|
474
|
+
const successWithoutIds = testCom.PerformAction('GET_OBJECTS', { map });
|
|
475
|
+
expect(successWithoutIds).toStrictEqual(map);
|
|
476
|
+
|
|
477
|
+
map = new Map();
|
|
478
|
+
const successWithIds = testCom.PerformAction('GET_OBJECTS', { map, ids: ['test1'] });
|
|
479
|
+
expect(Array.from(successWithIds.values())).toStrictEqual([{ entityType: "pov", id: "test1", position: { x: 0, y: 0, z: 0 }, target: { x: 0, y: 0, z: 0 } }]);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it('should perform action SELECT_OBJECT', () => {
|
|
483
|
+
const success0 = testCom.PerformAction('SELECT_OBJECT', { id: 'test0' });
|
|
484
|
+
expect(success0).toBe(false);
|
|
485
|
+
|
|
486
|
+
const mock0 = {
|
|
487
|
+
entityType: "pov",
|
|
488
|
+
id: "test0",
|
|
489
|
+
position: { x: 0, y: 0, z: 0 },
|
|
490
|
+
target: { x: 0, y: 0, z: 0 },
|
|
491
|
+
} as COMPov;
|
|
492
|
+
testCom.PerformAction('ADD_OBJECT', mock0);
|
|
493
|
+
|
|
494
|
+
jest.spyOn(mockScene, 'GetSceneObject').mockReturnValueOnce(undefined);
|
|
495
|
+
const success1 = testCom.PerformAction('SELECT_OBJECT', { id: 'test0' });
|
|
496
|
+
expect(success1).toBe(false);
|
|
497
|
+
|
|
498
|
+
jest.spyOn(mockScene, 'GetSceneObject').mockReturnValueOnce({} as unknown as Object3D);
|
|
499
|
+
const success2 = testCom.PerformAction('SELECT_OBJECT', { id: 'test0' });
|
|
500
|
+
expect(success2).toBe(false);
|
|
501
|
+
|
|
502
|
+
jest.spyOn(mockScene, 'GetSceneObject').mockReturnValueOnce({ isSelectable: true } as unknown as Object3D);
|
|
503
|
+
const success3 = testCom.PerformAction('SELECT_OBJECT', { id: 'test0' });
|
|
504
|
+
expect(success3).toBe(true);
|
|
505
|
+
expect(mockSelect).toHaveBeenCalledTimes(1);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('should perform action SET_CAMERA_TRANSFORM', () => {
|
|
509
|
+
const success = testCom.PerformAction('SET_CAMERA_TRANSFORM', {
|
|
510
|
+
position: { x: 0, y: 0, z: 0 },
|
|
511
|
+
target: { x: 0, y: 0, z: 0 },
|
|
512
|
+
});
|
|
513
|
+
expect(success).toBe(true);
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it('should perform action GET_CAMERA_TRANSFORM', () => {
|
|
517
|
+
const success = testCom.PerformAction('GET_CAMERA_TRANSFORM', {});
|
|
518
|
+
expect(success).toStrictEqual({
|
|
519
|
+
position: { x: 1, y: 2, z: 3 },
|
|
520
|
+
target: { x: 4, y: 5, z: 6 },
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('should perform action SET_CAMERA_LAYER', () => {
|
|
525
|
+
const success = testCom.PerformAction('SET_CAMERA_LAYER', {
|
|
526
|
+
layer: 'EDITOR',
|
|
527
|
+
});
|
|
528
|
+
expect(success).toBe(true);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('should perform action ZOOM_CAMERA', () => {
|
|
532
|
+
const success0 = testCom.PerformAction('ZOOM_CAMERA', {
|
|
533
|
+
direction: 'IN',
|
|
534
|
+
by: 10,
|
|
535
|
+
});
|
|
536
|
+
expect(success0).toBe(true);
|
|
537
|
+
const success1 = testCom.PerformAction('ZOOM_CAMERA', {
|
|
538
|
+
direction: 'OUT',
|
|
539
|
+
by: 10,
|
|
540
|
+
});
|
|
541
|
+
expect(success1).toBe(true);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it('should perform action SET_GIZMO_MODE', () => {
|
|
545
|
+
const success = testCom.PerformAction('SET_GIZMO_MODE', {
|
|
546
|
+
mode: 'translate',
|
|
547
|
+
});
|
|
548
|
+
expect(success).toBe(true);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it('should perform action MODEL_LOADED', () => {
|
|
552
|
+
const payload = {
|
|
553
|
+
entityType: "model",
|
|
554
|
+
id: "modelID",
|
|
555
|
+
position: { x: 0, y: 0, z: 0 },
|
|
556
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
557
|
+
scale: { x: 0.01, y: 0.01, z: 0.01 },
|
|
558
|
+
|
|
559
|
+
uri: "https://threejs.org/examples/models/gltf/LittlestTokyo.glb",
|
|
560
|
+
} as COMModel;
|
|
561
|
+
testCom.PerformAction('ADD_OBJECT', payload);
|
|
562
|
+
const success = testCom.PerformAction('MODEL_LOADED', {
|
|
563
|
+
id: 'modelID',
|
|
564
|
+
});
|
|
565
|
+
expect(success).toBe(true);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('should perform action UPDATE_SCENE', () => {
|
|
569
|
+
const success0 = testCom.PerformAction('UPDATE_SCENE', {
|
|
570
|
+
name: 'scene name',
|
|
571
|
+
backgroundColor: 'ffffff',
|
|
572
|
+
floorEnabled: true,
|
|
573
|
+
floorColor: 'ffffff',
|
|
574
|
+
});
|
|
575
|
+
expect(success0).toBe(true);
|
|
576
|
+
|
|
577
|
+
const success1 = testCom.PerformAction('UPDATE_SCENE', {
|
|
578
|
+
name: undefined,
|
|
579
|
+
backgroundColor: undefined,
|
|
580
|
+
floorEnabled: undefined,
|
|
581
|
+
floorColor: undefined,
|
|
582
|
+
});
|
|
583
|
+
expect(success1).toBe(true);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it('should perform action GENERATE_MEDIA', () => {
|
|
587
|
+
const mock1 = {
|
|
588
|
+
entityType: "pov",
|
|
589
|
+
id: "test1",
|
|
590
|
+
position: { x: 0, y: 0, z: 0 },
|
|
591
|
+
target: { x: 0, y: 0, z: 0 },
|
|
592
|
+
} as COMPov;
|
|
593
|
+
testCom.PerformAction('ADD_OBJECT', mock1);
|
|
594
|
+
|
|
595
|
+
const success0 = testCom.PerformAction('GENERATE_MEDIA', {
|
|
596
|
+
id: 'test1',
|
|
597
|
+
width: 800,
|
|
598
|
+
height: 600,
|
|
599
|
+
dataUri: '',
|
|
600
|
+
});
|
|
601
|
+
expect(success0).toBe(true);
|
|
602
|
+
|
|
603
|
+
const success1 = testCom.PerformAction('GENERATE_MEDIA', {
|
|
604
|
+
position: { x: 0, y: 0, z: 0 },
|
|
605
|
+
target: { x: 0, y: 0, z: 0 },
|
|
606
|
+
width: 800,
|
|
607
|
+
height: 600,
|
|
608
|
+
dataUri: '',
|
|
609
|
+
});
|
|
610
|
+
expect(success1).toBe(true);
|
|
611
|
+
});
|
|
612
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Vector3Like } from "three";
|
|
2
|
+
|
|
3
|
+
export default interface MOVE_CAMERA {
|
|
4
|
+
'PAYLOAD': {
|
|
5
|
+
position: Vector3Like,
|
|
6
|
+
target: Vector3Like,
|
|
7
|
+
locked: boolean,
|
|
8
|
+
duration: number,
|
|
9
|
+
} | {
|
|
10
|
+
id: string,
|
|
11
|
+
locked: boolean,
|
|
12
|
+
duration: number
|
|
13
|
+
},
|
|
14
|
+
'RETURN': boolean,
|
|
15
|
+
};
|