@shopware-ag/dive 1.18.5-beta.0 → 1.18.5-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { Vector3Like } from 'three';
2
2
  export default interface GENERATE_MEDIA {
3
- DESCRIPTION: 'Generates a screenshot, stores it in a Blob and writes the URL into the payload.';
3
+ DESCRIPTION: 'Generates a screenshot, stores it in a Blob and returns a Promise of a valid URI.';
4
4
  PAYLOAD: ({
5
5
  position: Vector3Like;
6
6
  target: Vector3Like;
@@ -9,7 +9,6 @@ export default interface GENERATE_MEDIA {
9
9
  }) & {
10
10
  width: number;
11
11
  height: number;
12
- dataUri: string;
13
12
  };
14
- RETURN: boolean;
13
+ RETURN: Promise<string>;
15
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.18.5-beta.0",
3
+ "version": "1.18.5-beta.2",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "build/dive.cjs",
@@ -14,7 +14,9 @@ export class DIVEARQuickLook {
14
14
  const quickLookScene = new Object3D();
15
15
 
16
16
  // extract models from scene
17
- quickLookScene.add(...this.extractModels(scene));
17
+ const rootCopy = scene.Root.clone(true);
18
+
19
+ quickLookScene.add(...rootCopy.children);
18
20
 
19
21
  // launch ARQuickLook
20
22
  return this.launchARFromNode(quickLookScene, options);
@@ -1,4 +1,4 @@
1
- import { Box3, Color, Euler, Mesh, Object3D, Vector3 } from 'three';
1
+ import { Object3D } from 'three';
2
2
  import { DIVEScene } from '../../../scene/Scene';
3
3
  import { DIVEAROptions } from '../../AR';
4
4
  import { DIVEARQuickLook } from '../ARQuickLook';
@@ -14,7 +14,7 @@ export type DIVEPerspectiveCameraSettings = {
14
14
 
15
15
  export const DIVEPerspectiveCameraDefaultSettings: DIVEPerspectiveCameraSettings =
16
16
  {
17
- fov: 80,
17
+ fov: 70,
18
18
  near: 0.1,
19
19
  far: 1000,
20
20
  };
@@ -75,37 +75,78 @@ export class DIVECommunication {
75
75
  private toolbox: DIVEToolbox;
76
76
 
77
77
  private _mediaGenerator: DIVEMediaCreator | null;
78
- private get mediaGenerator(): DIVEMediaCreator {
78
+ private get mediaGenerator(): Promise<DIVEMediaCreator> {
79
79
  if (!this._mediaGenerator) {
80
- const DIVEMediaCreator = require('../mediacreator/MediaCreator.ts')
81
- .DIVEMediaCreator as typeof import('../mediacreator/MediaCreator.ts').DIVEMediaCreator;
82
- this._mediaGenerator = new DIVEMediaCreator(
83
- this.renderer,
84
- this.scene,
85
- this.controller,
86
- );
80
+ return new Promise((resolve, reject) => {
81
+ import('../mediacreator/MediaCreator.ts')
82
+ .then((module) => {
83
+ const DIVEMediaCreator = module.DIVEMediaCreator;
84
+ this._mediaGenerator = new DIVEMediaCreator(
85
+ this.renderer,
86
+ this.scene,
87
+ this.controller,
88
+ );
89
+ resolve(this._mediaGenerator);
90
+ })
91
+ .catch((error) => {
92
+ console.error(
93
+ 'DIVE: Error while lazy-loading IO module:',
94
+ error,
95
+ );
96
+ reject(error);
97
+ });
98
+ });
87
99
  }
88
- return this._mediaGenerator;
100
+ return Promise.resolve(this._mediaGenerator);
89
101
  }
90
102
 
91
103
  private _io: DIVEIO | null;
92
- private get io(): DIVEIO {
104
+ private get io(): Promise<DIVEIO> {
93
105
  if (!this._io) {
94
- const DIVEIO = require('../io/IO.ts')
95
- .DIVEIO as typeof import('../io/IO.ts').DIVEIO;
96
- this._io = new DIVEIO(this.scene);
106
+ return new Promise((resolve, reject) => {
107
+ import('../io/IO.ts')
108
+ .then((module) => {
109
+ const DIVEIO = module.DIVEIO;
110
+ this._io = new DIVEIO(this.scene);
111
+ resolve(this._io);
112
+ })
113
+ .catch((error) => {
114
+ console.error(
115
+ 'DIVE: Error while lazy-loading IO module:',
116
+ error,
117
+ );
118
+ reject(error);
119
+ });
120
+ });
97
121
  }
98
- return this._io;
122
+ return Promise.resolve(this._io);
99
123
  }
100
124
 
101
125
  private _ar: DIVEAR | null;
102
- private get ar(): DIVEAR {
126
+ private get ar(): Promise<DIVEAR> {
103
127
  if (!this._ar) {
104
- const DIVEAR = require('../ar/AR.ts')
105
- .DIVEAR as typeof import('../ar/AR.ts').DIVEAR;
106
- this._ar = new DIVEAR(this.renderer, this.scene, this.controller);
128
+ return new Promise((resolve, reject) => {
129
+ import('../ar/AR.ts')
130
+ .then((module) => {
131
+ const DIVEAR = module.DIVEAR;
132
+ this._ar = new DIVEAR(
133
+ this.renderer,
134
+ this.scene,
135
+ this.controller,
136
+ );
137
+ resolve(this._ar);
138
+ })
139
+ .catch((error) => {
140
+ console.error(
141
+ 'DIVE: Error while lazy-loading AR module:',
142
+ error,
143
+ );
144
+ reject(error);
145
+ });
146
+ });
107
147
  }
108
- return this._ar;
148
+
149
+ return Promise.resolve(this._ar);
109
150
  }
110
151
 
111
152
  private registered: Map<string, COMEntity> = new Map();
@@ -311,9 +352,17 @@ export class DIVECommunication {
311
352
  break;
312
353
  }
313
354
  case 'LAUNCH_AR': {
314
- returnValue = this.ar.Launch(
315
- payload as Actions['LAUNCH_AR']['PAYLOAD'],
316
- );
355
+ returnValue = new Promise<void>((resolve, reject) => {
356
+ this.ar
357
+ .then((arModule) => {
358
+ resolve(
359
+ arModule.Launch(
360
+ payload as Actions['LAUNCH_AR']['PAYLOAD'],
361
+ ),
362
+ );
363
+ })
364
+ .catch(reject);
365
+ });
317
366
  break;
318
367
  }
319
368
  default: {
@@ -735,14 +784,14 @@ export class DIVECommunication {
735
784
  target = payload.target;
736
785
  }
737
786
 
738
- payload.dataUri = this.mediaGenerator.GenerateMedia(
739
- position,
740
- target,
741
- payload.width,
742
- payload.height,
743
- );
744
-
745
- return true;
787
+ return this.mediaGenerator.then((module) => {
788
+ return module.GenerateMedia(
789
+ position,
790
+ target,
791
+ payload.width,
792
+ payload.height,
793
+ );
794
+ });
746
795
  }
747
796
 
748
797
  private setParent(
@@ -808,7 +857,13 @@ export class DIVECommunication {
808
857
  private exportScene(
809
858
  payload: Actions['EXPORT_SCENE']['PAYLOAD'],
810
859
  ): Actions['EXPORT_SCENE']['RETURN'] {
811
- return this.io.Export(payload.type);
860
+ return new Promise<string | null>((resolve, reject) => {
861
+ this.io
862
+ .then((ioModule) => {
863
+ resolve(ioModule.Export(payload.type));
864
+ })
865
+ .catch(reject);
866
+ });
812
867
  }
813
868
  }
814
869
 
@@ -842,7 +842,14 @@ describe('dive/communication/DIVECommunication', () => {
842
842
  expect(success1).toBe(true);
843
843
  });
844
844
 
845
- it('should perform action GENERATE_MEDIA', () => {
845
+ it('should perform action GENERATE_MEDIA', async () => {
846
+ const blobUri = 'blob:http://localhost:3000/1234';
847
+ const mediaGeneratorModule = await testCom['mediaGenerator'];
848
+
849
+ jest.spyOn(mediaGeneratorModule, 'GenerateMedia').mockReturnValue(
850
+ blobUri,
851
+ );
852
+
846
853
  const mock1 = {
847
854
  entityType: 'pov',
848
855
  id: 'test1',
@@ -851,22 +858,22 @@ describe('dive/communication/DIVECommunication', () => {
851
858
  } as COMPov;
852
859
  testCom.PerformAction('ADD_OBJECT', mock1);
853
860
 
854
- const success0 = testCom.PerformAction('GENERATE_MEDIA', {
861
+ const success0 = await testCom.PerformAction('GENERATE_MEDIA', {
855
862
  id: 'test1',
856
863
  width: 800,
857
864
  height: 600,
858
- dataUri: '',
859
865
  });
860
- expect(success0).toBe(true);
866
+ expect(success0).toBe(blobUri);
861
867
 
862
- const success1 = testCom.PerformAction('GENERATE_MEDIA', {
868
+ const success1 = await testCom.PerformAction('GENERATE_MEDIA', {
863
869
  position: { x: 0, y: 0, z: 0 },
864
870
  target: { x: 0, y: 0, z: 0 },
865
871
  width: 800,
866
872
  height: 600,
867
- dataUri: '',
868
873
  });
869
- expect(success1).toBe(true);
874
+ expect(success1).toBe(blobUri);
875
+
876
+ jest.restoreAllMocks();
870
877
  });
871
878
 
872
879
  it('should perform action SET_PARENT', () => {
@@ -955,8 +962,9 @@ describe('dive/communication/DIVECommunication', () => {
955
962
 
956
963
  it('should perform action EXPORT_SCENE', async () => {
957
964
  const url = 'https://example.com';
965
+ const ioModule = await testCom['io'];
958
966
 
959
- jest.spyOn(testCom['io'], 'Export').mockResolvedValueOnce(url);
967
+ jest.spyOn(ioModule, 'Export').mockResolvedValueOnce(url);
960
968
 
961
969
  const result = await testCom.PerformAction('EXPORT_SCENE', {
962
970
  type: 'glb',
@@ -965,8 +973,9 @@ describe('dive/communication/DIVECommunication', () => {
965
973
  });
966
974
 
967
975
  it('should perform action LAUNCH_AR', async () => {
976
+ const arModule = await testCom['ar'];
968
977
  const arLaunchSpy = jest
969
- .spyOn(testCom['ar'], 'Launch')
978
+ .spyOn(arModule, 'Launch')
970
979
  .mockResolvedValueOnce();
971
980
 
972
981
  const result = await testCom.PerformAction('LAUNCH_AR', undefined);
@@ -1,7 +1,7 @@
1
1
  import { Vector3Like } from 'three';
2
2
 
3
3
  export default interface GENERATE_MEDIA {
4
- DESCRIPTION: 'Generates a screenshot, stores it in a Blob and writes the URL into the payload.';
4
+ DESCRIPTION: 'Generates a screenshot, stores it in a Blob and returns a Promise of a valid URI.';
5
5
  PAYLOAD: (
6
6
  | {
7
7
  position: Vector3Like;
@@ -13,7 +13,6 @@ export default interface GENERATE_MEDIA {
13
13
  ) & {
14
14
  width: number; // image width in pixels
15
15
  height: number; // image height in pixels
16
- dataUri: string;
17
16
  };
18
- RETURN: boolean;
17
+ RETURN: Promise<string>;
19
18
  }