@shopware-ag/dive 1.16.4 → 1.16.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.16.4",
3
+ "version": "1.16.6",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
@@ -208,6 +208,14 @@ describe('dive/DIVE', () => {
208
208
  expect(() => (window as any).DIVE.PrintScene()).not.toThrow();
209
209
  });
210
210
 
211
+ it('should instantiate in development NODE_ENV', () => {
212
+ process.env.NODE_ENV = 'development';
213
+ const dive = new DIVE();
214
+ expect(dive).toBeDefined();
215
+ expect((window as any).DIVE.PrintScene).toBeDefined();
216
+ expect(() => (window as any).DIVE.PrintScene()).not.toThrow();
217
+ });
218
+
211
219
  it('should dispose', () => {
212
220
  let dive = new DIVE();
213
221
  expect(() => dive.Dispose()).not.toThrow();
@@ -516,9 +516,10 @@ export class DIVECommunication {
516
516
  private placeOnFloor(
517
517
  payload: Actions['PLACE_ON_FLOOR']['PAYLOAD'],
518
518
  ): Actions['PLACE_ON_FLOOR']['RETURN'] {
519
- if (!this.registered.get(payload.id)) return false;
519
+ const object = this.registered.get(payload.id);
520
+ if (!object) return false;
520
521
 
521
- this.scene.PlaceOnFloor(payload);
522
+ this.scene.PlaceOnFloor(object);
522
523
 
523
524
  return true;
524
525
  }
package/src/dive.ts CHANGED
@@ -277,7 +277,9 @@ export default class DIVE {
277
277
  },
278
278
  };
279
279
 
280
- console.log(`DIVE ${pkgjson.version} initialized`);
280
+ console.log(
281
+ `DIVE ${pkgjson.version} initialized ${process.env.NODE_ENV === 'development' ? 'in development mode' : ''}`,
282
+ );
281
283
  }
282
284
 
283
285
  public Dispose(): void {
@@ -1,6 +1,5 @@
1
1
  import { Mesh, MeshStandardMaterial, Raycaster, Vector3 } from 'three';
2
2
  import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
3
- import { DIVECommunication } from '../com/Communication';
4
3
  import type { GLTF } from 'three/examples/jsm/Addons.js';
5
4
  import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
6
5
  import { type COMMaterial } from '../com/types';
@@ -111,16 +110,11 @@ export class DIVEModel extends DIVENode {
111
110
  }
112
111
 
113
112
  public PlaceOnFloor(): void {
113
+ const oldPos = this.position.clone();
114
114
  this.position.y = -this._boundingBox.min.y * this.scale.y;
115
- DIVECommunication.get(this.userData.id)?.PerformAction(
116
- 'UPDATE_OBJECT',
117
- {
118
- id: this.userData.id,
119
- position: this.position,
120
- rotation: this.rotation,
121
- scale: this.scale,
122
- },
123
- );
115
+ if (this.position.y === oldPos.y) return;
116
+
117
+ this.onMove();
124
118
  }
125
119
 
126
120
  public DropIt(): void {
@@ -163,15 +157,8 @@ export class DIVEModel extends DIVENode {
163
157
 
164
158
  // if the position changed, update the object in communication
165
159
  if (this.position.y === oldPos.y) return;
166
- DIVECommunication.get(this.userData.id)?.PerformAction(
167
- 'UPDATE_OBJECT',
168
- {
169
- id: this.userData.id,
170
- position: this.position,
171
- rotation: this.rotation,
172
- scale: this.scale,
173
- },
174
- );
160
+
161
+ this.onMove();
175
162
  }
176
163
  }
177
164
  }
@@ -228,10 +228,14 @@ describe('dive/model/DIVEModel', () => {
228
228
  it('should place on floor', () => {
229
229
  model.userData.id = 'something';
230
230
 
231
+ const spy = jest.spyOn(model, 'onMove').mockImplementation(() => {});
232
+
231
233
  expect(() => model.PlaceOnFloor()).not.toThrow();
234
+ expect(spy).toHaveBeenCalledTimes(1);
232
235
 
233
236
  jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
234
237
  expect(() => model.PlaceOnFloor()).not.toThrow();
238
+ expect(spy).toHaveBeenCalledTimes(1);
235
239
  });
236
240
 
237
241
  it('should drop it', () => {
@@ -240,6 +244,8 @@ describe('dive/model/DIVEModel', () => {
240
244
  } as unknown as DIVECommunication;
241
245
  jest.spyOn(DIVECommunication, 'get').mockReturnValue(comMock);
242
246
 
247
+ const spy = jest.spyOn(model, 'onMove').mockImplementation(() => {});
248
+
243
249
  const size = {
244
250
  x: 1,
245
251
  y: 1,
@@ -284,16 +290,16 @@ describe('dive/model/DIVEModel', () => {
284
290
 
285
291
  expect(() => model.DropIt()).not.toThrow();
286
292
  expect(model.position.y).toBe(2.5);
287
- expect(comMock.PerformAction).toHaveBeenCalledTimes(1);
293
+ expect(spy).toHaveBeenCalledTimes(1);
288
294
 
289
295
  expect(() => model.DropIt()).not.toThrow();
290
- expect(comMock.PerformAction).toHaveBeenCalledTimes(1);
296
+ expect(spy).toHaveBeenCalledTimes(1);
291
297
 
292
- // reset for PerformAction to be called again
298
+ // alter position so onMove will be called again
293
299
  model.position.y = 2;
294
300
  jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
295
301
  expect(() => model.DropIt()).not.toThrow();
296
- expect(comMock.PerformAction).toHaveBeenCalledTimes(1);
302
+ expect(spy).toHaveBeenCalledTimes(2);
297
303
  });
298
304
 
299
305
  it('should set material', () => {
@@ -10,7 +10,6 @@ import {
10
10
  SphereGeometry,
11
11
  Vector3,
12
12
  } from 'three';
13
- import { DIVECommunication } from '../com/Communication';
14
13
  import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
15
14
  import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
16
15
  import { DIVENode } from '../node/Node';
@@ -107,16 +106,11 @@ export class DIVEPrimitive extends DIVENode {
107
106
  }
108
107
 
109
108
  public PlaceOnFloor(): void {
109
+ const oldPos = this.position.clone();
110
110
  this.position.y = -this._boundingBox.min.y * this.scale.y;
111
- DIVECommunication.get(this.userData.id)?.PerformAction(
112
- 'UPDATE_OBJECT',
113
- {
114
- id: this.userData.id,
115
- position: this.position,
116
- rotation: this.rotation,
117
- scale: this.scale,
118
- },
119
- );
111
+ if (this.position.y === oldPos.y) return;
112
+
113
+ this.onMove();
120
114
  }
121
115
 
122
116
  public DropIt(): void {
@@ -159,15 +153,8 @@ export class DIVEPrimitive extends DIVENode {
159
153
 
160
154
  // if the position changed, update the object in communication
161
155
  if (this.position.y === oldPos.y) return;
162
- DIVECommunication.get(this.userData.id)?.PerformAction(
163
- 'UPDATE_OBJECT',
164
- {
165
- id: this.userData.id,
166
- position: this.position,
167
- rotation: this.rotation,
168
- scale: this.scale,
169
- },
170
- );
156
+
157
+ this.onMove();
171
158
  }
172
159
  }
173
160
 
@@ -255,6 +255,10 @@ describe('dive/primitive/DIVEPrimitive', () => {
255
255
  } as unknown as DIVECommunication;
256
256
  jest.spyOn(DIVECommunication, 'get').mockReturnValue(comMock);
257
257
 
258
+ const spy = jest
259
+ .spyOn(primitive, 'onMove')
260
+ .mockImplementation(() => {});
261
+
258
262
  const size = {
259
263
  x: 1,
260
264
  y: 1,
@@ -299,16 +303,16 @@ describe('dive/primitive/DIVEPrimitive', () => {
299
303
 
300
304
  expect(() => primitive.DropIt()).not.toThrow();
301
305
  expect(primitive.position.y).toBe(2.5);
302
- expect(comMock.PerformAction).toHaveBeenCalledTimes(1);
306
+ expect(spy).toHaveBeenCalledTimes(1);
303
307
 
304
308
  expect(() => primitive.DropIt()).not.toThrow();
305
- expect(comMock.PerformAction).toHaveBeenCalledTimes(1);
309
+ expect(spy).toHaveBeenCalledTimes(1);
306
310
 
307
- // reset for PerformAction to be called again
311
+ // alter position so onMove will be called again
308
312
  primitive.position.y = 2;
309
313
  jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
310
314
  expect(() => primitive.DropIt()).not.toThrow();
311
- expect(comMock.PerformAction).toHaveBeenCalledTimes(1);
315
+ expect(spy).toHaveBeenCalledTimes(2);
312
316
  });
313
317
 
314
318
  it('should set geometry', () => {
@@ -64,18 +64,20 @@ export class DIVEScene extends Scene {
64
64
  }
65
65
 
66
66
  public UpdateSceneObject(
67
- object: Partial<COMEntity> & { id: string },
67
+ object: Partial<COMEntity> & { id: string; entityType: string },
68
68
  ): void {
69
69
  this.Root.UpdateSceneObject(object);
70
70
  }
71
71
 
72
72
  public DeleteSceneObject(
73
- object: Partial<COMEntity> & { id: string },
73
+ object: Partial<COMEntity> & { id: string; entityType: string },
74
74
  ): void {
75
75
  this.Root.DeleteSceneObject(object);
76
76
  }
77
77
 
78
- public PlaceOnFloor(object: Partial<COMModel> & { id: string }): void {
78
+ public PlaceOnFloor(
79
+ object: Partial<COMModel> & { id: string; entityType: string },
80
+ ): void {
79
81
  this.Root.PlaceOnFloor(object);
80
82
  }
81
83
  }
@@ -66,7 +66,7 @@ export class DIVERoot extends Object3D {
66
66
  break;
67
67
  }
68
68
  case 'light': {
69
- this.updateLight(object);
69
+ this.updateLight(object as COMLight);
70
70
  break;
71
71
  }
72
72
  case 'model': {
@@ -90,14 +90,14 @@ export class DIVERoot extends Object3D {
90
90
  }
91
91
 
92
92
  public UpdateSceneObject(
93
- object: Partial<COMEntity> & { id: string },
93
+ object: Partial<COMEntity> & { id: string; entityType: string },
94
94
  ): void {
95
95
  switch (object.entityType) {
96
96
  case 'pov': {
97
97
  break;
98
98
  }
99
99
  case 'light': {
100
- this.updateLight(object);
100
+ this.updateLight(object as COMLight);
101
101
  break;
102
102
  }
103
103
  case 'model': {
@@ -121,7 +121,7 @@ export class DIVERoot extends Object3D {
121
121
  }
122
122
 
123
123
  public DeleteSceneObject(
124
- object: Partial<COMEntity> & { id: string },
124
+ object: Partial<COMEntity> & { id: string; entityType: string },
125
125
  ): void {
126
126
  switch (object.entityType) {
127
127
  case 'pov': {
@@ -151,7 +151,9 @@ export class DIVERoot extends Object3D {
151
151
  }
152
152
  }
153
153
 
154
- public PlaceOnFloor(object: Partial<COMEntity> & { id: string }): void {
154
+ public PlaceOnFloor(
155
+ object: Partial<COMEntity> & { id: string; entityType: string },
156
+ ): void {
155
157
  switch (object.entityType) {
156
158
  case 'pov':
157
159
  case 'light': {
@@ -170,7 +172,13 @@ export class DIVERoot extends Object3D {
170
172
  }
171
173
  }
172
174
 
173
- private updateLight(light: Partial<COMLight> & { id: string }): void {
175
+ private updateLight(
176
+ light: Partial<COMLight> & {
177
+ id: string;
178
+ entityType: string;
179
+ type: string;
180
+ },
181
+ ): void {
174
182
  let sceneObject = this.GetSceneObject(light);
175
183
  if (!sceneObject) {
176
184
  switch (light.type) {
@@ -413,8 +413,6 @@ jest.mock('../../../group/Group.ts', () => {
413
413
 
414
414
  let root: DIVERoot;
415
415
 
416
- jest.spyOn(console, 'warn').mockImplementation(() => {});
417
-
418
416
  describe('DIVE/scene/root/DIVERoot', () => {
419
417
  beforeEach(() => {
420
418
  root = new DIVERoot();
@@ -714,6 +712,22 @@ describe('DIVE/scene/root/DIVERoot', () => {
714
712
  parentId: 'does_not_exist',
715
713
  } as COMGroup),
716
714
  ).not.toThrow();
715
+
716
+ jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
717
+ expect(() =>
718
+ root.UpdateSceneObject({
719
+ entityType: 'INVALID' as COMEntityType,
720
+ } as COMPrimitive),
721
+ ).not.toThrow();
722
+ expect(console.warn).toHaveBeenCalled();
723
+
724
+ jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
725
+ expect(() =>
726
+ root.UpdateSceneObject({
727
+ entityType: undefined,
728
+ } as unknown as COMPrimitive),
729
+ ).not.toThrow();
730
+ expect(console.warn).toHaveBeenCalled();
717
731
  });
718
732
 
719
733
  it('should delete object', () => {
@@ -846,6 +860,22 @@ describe('DIVE/scene/root/DIVERoot', () => {
846
860
  visible: true,
847
861
  } as COMGroup),
848
862
  ).not.toThrow();
863
+
864
+ jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
865
+ expect(() =>
866
+ root.DeleteSceneObject({
867
+ entityType: 'INVALID' as COMEntityType,
868
+ } as COMPrimitive),
869
+ ).not.toThrow();
870
+ expect(console.warn).toHaveBeenCalled();
871
+
872
+ jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
873
+ expect(() =>
874
+ root.DeleteSceneObject({
875
+ entityType: undefined,
876
+ } as unknown as COMPrimitive),
877
+ ).not.toThrow();
878
+ expect(console.warn).toHaveBeenCalled();
849
879
  });
850
880
 
851
881
  it('should place object on floor', () => {
@@ -928,10 +958,28 @@ describe('DIVE/scene/root/DIVERoot', () => {
928
958
  visible: true,
929
959
  } as COMPrimitive),
930
960
  ).not.toThrow();
961
+
962
+ jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
963
+ expect(() =>
964
+ root.PlaceOnFloor({
965
+ entityType: 'INVALID' as COMEntityType,
966
+ } as COMPrimitive),
967
+ ).not.toThrow();
968
+ expect(console.warn).toHaveBeenCalled();
969
+
970
+ jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
971
+ expect(() =>
972
+ root.PlaceOnFloor({
973
+ entityType: undefined,
974
+ } as unknown as COMPrimitive),
975
+ ).not.toThrow();
976
+ expect(console.warn).toHaveBeenCalled();
931
977
  });
932
978
 
933
979
  it('should warn if entity type is invalid while adding object', () => {
934
- const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
980
+ const spy = jest
981
+ .spyOn(console, 'warn')
982
+ .mockImplementationOnce(() => {});
935
983
  expect(() =>
936
984
  root.AddSceneObject({
937
985
  id: 'id',
@@ -944,7 +992,9 @@ describe('DIVE/scene/root/DIVERoot', () => {
944
992
  });
945
993
 
946
994
  it('should warn if entity type is invalid while updating object', () => {
947
- const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
995
+ const spy = jest
996
+ .spyOn(console, 'warn')
997
+ .mockImplementationOnce(() => {});
948
998
  expect(() =>
949
999
  root.UpdateSceneObject({
950
1000
  id: 'id',
@@ -957,7 +1007,9 @@ describe('DIVE/scene/root/DIVERoot', () => {
957
1007
  });
958
1008
 
959
1009
  it('should warn if entity type is invalid while deleting object', () => {
960
- const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1010
+ const spy = jest
1011
+ .spyOn(console, 'warn')
1012
+ .mockImplementationOnce(() => {});
961
1013
  expect(() =>
962
1014
  root.DeleteSceneObject({
963
1015
  id: 'id',
@@ -970,7 +1022,9 @@ describe('DIVE/scene/root/DIVERoot', () => {
970
1022
  });
971
1023
 
972
1024
  it('should warn if entity type is invalid while placing on floor', () => {
973
- const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
1025
+ const spy = jest
1026
+ .spyOn(console, 'warn')
1027
+ .mockImplementationOnce(() => {});
974
1028
  expect(() =>
975
1029
  root.PlaceOnFloor({
976
1030
  id: 'id',