@shopware-ag/dive 1.0.17 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,23 @@
1
1
 
2
+ <p align="center">
3
+ <img alt="DIVE logo" src="./assets/svg/dive.svg" style="width: 100%; height: auto; max-height: 500px;">
4
+ </p>
5
+
6
+ <p align="center">
7
+ <a href="#badge">
8
+ <img alt="dive: downloads" src="https://img.shields.io/npm/v/%40shopware-ag%2Fdive">
9
+ </a>
10
+ <a href="#badge">
11
+ <img alt="dive: downloads" src="https://img.shields.io/npm/d18m/%40shopware-ag%2Fdive">
12
+ </a>
13
+ <a href="#badge">
14
+ <img alt="dive: downloads" src="https://img.shields.io/npm/l/%40shopware-ag%2Fdive">
15
+ </a>
16
+ <a href="#badge">
17
+ <img alt="dive: downloads" src="https://img.shields.io/npm/types/%40shopware-ag%2Fdive">
18
+ </a>
19
+ </p>
20
+
2
21
  # About
3
22
  DIVE is a spatial framework made by and optimized for Shopware. It can be used directly integrated in a Shopware frontend such as Storefront or in any other frontend you want to use it in, it is not tied to Shopware.
4
23
 
@@ -25,9 +44,9 @@ module.exports = () => {
25
44
  return {
26
45
  ...
27
46
  resolve: {
28
- extensions: ['.ts', '.tsx', '.js', '.vue'],
47
+ extensions: ['.ts', '.cjs', '.js'],
29
48
  alias: {
30
- dive: path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive'),
49
+ "@shopware-ag/dive": path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive'),
31
50
  }
32
51
  },
33
52
  ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.0.17",
3
+ "version": "1.1.0",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
package/src/com/types.ts CHANGED
@@ -4,6 +4,7 @@ type COMBaseEntity = {
4
4
  id: string;
5
5
  name: string;
6
6
  entityType: 'pov' | 'light' | 'model';
7
+ visible: boolean;
7
8
  }
8
9
  export type COMPov = COMBaseEntity & {
9
10
  position: Vector3Like;
@@ -1,4 +1,4 @@
1
- import { AmbientLight, Color } from 'three';
1
+ import { AmbientLight, Color, Object3D } from 'three';
2
2
  import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
3
3
 
4
4
  /**
@@ -9,21 +9,28 @@ import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
9
9
  * @module
10
10
  */
11
11
 
12
- export default class DIVEAmbientLight extends AmbientLight {
12
+ export default class DIVEAmbientLight extends Object3D {
13
+ private _light: AmbientLight;
14
+
13
15
  constructor() {
14
- super(0xffffff, 1);
15
- this.layers.mask = PRODUCT_LAYER_MASK;
16
+ super();
17
+
18
+ this.name = 'DIVEAmbientLight';
19
+
20
+ this._light = new AmbientLight(0xffffff, 1);
21
+ this._light.layers.mask = PRODUCT_LAYER_MASK;
22
+ this.add(this._light);
16
23
  }
17
24
 
18
25
  public SetColor(color: Color): void {
19
- this.color = color;
26
+ this._light.color = color;
20
27
  }
21
28
 
22
29
  public SetIntensity(intensity: number): void {
23
- this.intensity = intensity;
30
+ this._light.intensity = intensity;
24
31
  }
25
32
 
26
33
  public SetEnabled(enabled: boolean): void {
27
- this.visible = enabled;
34
+ this._light.visible = enabled;
28
35
  }
29
36
  }
@@ -1,4 +1,4 @@
1
- import { PointLight, Color, SphereGeometry, MeshBasicMaterial, Mesh, FrontSide } from 'three';
1
+ import { PointLight, Color, SphereGeometry, MeshBasicMaterial, Mesh, FrontSide, Object3D } from 'three';
2
2
  import DIVECommunication from '../com/Communication';
3
3
  import { HELPER_LAYER_MASK, PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
4
4
  import { DIVEMoveable } from '../interface/Moveable';
@@ -15,46 +15,54 @@ import type { TransformControls } from 'three/examples/jsm/Addons.js';
15
15
  * @module
16
16
  */
17
17
 
18
- export default class DIVEPointLight extends PointLight implements DIVESelectable, DIVEMoveable {
18
+ export default class DIVEPointLight extends Object3D implements DIVESelectable, DIVEMoveable {
19
19
  public isMoveable: true = true;
20
20
  public isSelectable: true = true;
21
21
  public gizmo: TransformControls | null = null;
22
22
 
23
+ private light: PointLight;
24
+ private mesh: Mesh;
25
+
23
26
  constructor() {
24
- super(0xffffff, 1);
27
+ super();
28
+
29
+ this.name = 'DIVEPointLight';
30
+
31
+ this.light = new PointLight(0xffffff, 1);
25
32
 
26
- this.layers.mask = PRODUCT_LAYER_MASK;
33
+ this.light.layers.mask = PRODUCT_LAYER_MASK;
27
34
 
28
- this.castShadow = true;
29
- this.shadow.mapSize.width = 512;
30
- this.shadow.mapSize.height = 512;
35
+ this.light.castShadow = true;
36
+ this.light.shadow.mapSize.width = 512;
37
+ this.light.shadow.mapSize.height = 512;
38
+ this.add(this.light);
31
39
 
32
40
  const geoSize = 0.1;
33
41
 
34
42
  const geometry = new SphereGeometry(geoSize, geoSize * 320, geoSize * 320);
35
43
 
36
- const material = new MeshBasicMaterial({ color: this.color, transparent: true, opacity: 0.8, side: FrontSide });
44
+ const material = new MeshBasicMaterial({ color: this.light.color, transparent: true, opacity: 0.8, side: FrontSide });
37
45
 
38
- const mesh = new Mesh(geometry, material);
39
- mesh.layers.mask = HELPER_LAYER_MASK;
46
+ this.mesh = new Mesh(geometry, material);
47
+ this.mesh.layers.mask = HELPER_LAYER_MASK;
40
48
 
41
- this.add(mesh);
49
+ this.add(this.mesh);
42
50
  }
43
51
 
44
52
  public SetColor(color: Color): void {
45
- this.color = color;
53
+ this.light.color = color;
46
54
 
47
- ((this.children[0] as Mesh).material as MeshBasicMaterial).color = color;
55
+ (this.mesh.material as MeshBasicMaterial).color = color;
48
56
  }
49
57
 
50
58
  public SetIntensity(intensity: number): void {
51
- this.intensity = intensity;
59
+ this.light.intensity = intensity;
52
60
 
53
- ((this.children[0] as Mesh).material as MeshBasicMaterial).opacity = intensity > 0.8 ? 0.8 : intensity * 0.8;
61
+ (this.mesh.material as MeshBasicMaterial).opacity = intensity > 0.8 ? 0.8 : intensity * 0.8;
54
62
  }
55
63
 
56
64
  public SetEnabled(enabled: boolean): void {
57
- this.visible = enabled;
65
+ this.light.visible = enabled;
58
66
  }
59
67
 
60
68
  public onMove(): void {
@@ -11,50 +11,51 @@ import { Color, DirectionalLight, HemisphereLight, Object3D } from "three";
11
11
 
12
12
  export default class DIVESceneLight extends Object3D {
13
13
 
14
- private hemiLight: HemisphereLight;
15
- private dirLight: DirectionalLight;
14
+ private _hemiLight: HemisphereLight;
15
+ private _dirLight: DirectionalLight;
16
16
 
17
17
  constructor() {
18
18
  super();
19
19
 
20
- this.name = "SceneLight";
20
+ this.name = 'DIVESceneLight';
21
21
 
22
- this.hemiLight = new HemisphereLight(0xffffff, 0xffffff, 2);
23
- this.hemiLight.layers.mask = PRODUCT_LAYER_MASK;
24
- this.hemiLight.position.set(0, 50, 0);
25
- this.add(this.hemiLight);
22
+ this._hemiLight = new HemisphereLight(0xffffff, 0xffffff, 2);
23
+ this._hemiLight.layers.mask = PRODUCT_LAYER_MASK;
24
+ this._hemiLight.position.set(0, 50, 0);
25
+ this.add(this._hemiLight);
26
26
 
27
- this.dirLight = new DirectionalLight(0xffffff, 3);
28
- this.dirLight.layers.mask = PRODUCT_LAYER_MASK;
29
- this.dirLight.position.set(1, 1.75, 1);
30
- this.dirLight.position.multiplyScalar(30);
31
- this.dirLight.castShadow = true;
27
+ this._dirLight = new DirectionalLight(0xffffff, 3);
28
+ this._dirLight.layers.mask = PRODUCT_LAYER_MASK;
29
+ this._dirLight.position.set(1, 1.75, 1);
30
+ this._dirLight.position.multiplyScalar(30);
31
+ this._dirLight.castShadow = true;
32
32
 
33
- this.dirLight.shadow.mapSize.width = 2048;
34
- this.dirLight.shadow.mapSize.height = 2048;
33
+ this._dirLight.shadow.mapSize.width = 2048;
34
+ this._dirLight.shadow.mapSize.height = 2048;
35
35
 
36
36
  const d = 5;
37
37
 
38
- this.dirLight.shadow.camera.left = - d;
39
- this.dirLight.shadow.camera.right = d;
40
- this.dirLight.shadow.camera.top = d;
41
- this.dirLight.shadow.camera.bottom = - d;
38
+ this._dirLight.shadow.camera.left = - d;
39
+ this._dirLight.shadow.camera.right = d;
40
+ this._dirLight.shadow.camera.top = d;
41
+ this._dirLight.shadow.camera.bottom = - d;
42
42
 
43
- this.dirLight.shadow.camera.far = 3500;
44
- this.add(this.dirLight);
43
+ this._dirLight.shadow.camera.far = 3500;
44
+ this.add(this._dirLight);
45
45
  }
46
46
 
47
47
  public SetColor(color: Color): void {
48
- this.hemiLight.color = color;
49
- this.dirLight.color = color;
48
+ this._hemiLight.color = color;
49
+ this._dirLight.color = color;
50
50
  }
51
51
 
52
52
  public SetIntensity(intensity: number): void {
53
- this.hemiLight.intensity = intensity * 2;
54
- this.dirLight.intensity = intensity * 3;
53
+ this._hemiLight.intensity = intensity * 2;
54
+ this._dirLight.intensity = intensity * 3;
55
55
  }
56
56
 
57
57
  public SetEnabled(enabled: boolean): void {
58
- this.visible = enabled;
58
+ this._hemiLight.visible = enabled;
59
+ this._dirLight.visible = enabled;
59
60
  }
60
61
  }
@@ -1,4 +1,4 @@
1
- import { Color } from 'three';
1
+ import { AmbientLight, Color, Object3D } from 'three';
2
2
  import DIVEAmbientLight from '../AmbientLight';
3
3
 
4
4
  jest.mock('three', () => {
@@ -12,6 +12,14 @@ jest.mock('three', () => {
12
12
  this.layers = {
13
13
  mask: 0,
14
14
  };
15
+ this.removeFromParent = jest.fn();
16
+ return this;
17
+ }),
18
+ Object3D: jest.fn(function () {
19
+ this.children = [];
20
+ this.add = (obj: Object3D) => {
21
+ this.children.push(obj);
22
+ };
15
23
  return this;
16
24
  }),
17
25
  }
@@ -27,18 +35,18 @@ describe('dive/light/DIVEAmbientLight', () => {
27
35
  it('should set intensity', () => {
28
36
  const testLight = new DIVEAmbientLight();
29
37
  testLight.SetIntensity(1.0);
30
- expect(testLight.intensity).toBe(1.0);
38
+ expect((testLight.children[0] as AmbientLight).intensity).toBe(1.0);
31
39
  });
32
40
 
33
41
  it('should set color', () => {
34
42
  const testLight = new DIVEAmbientLight();
35
43
  testLight.SetColor({ test: true } as unknown as Color);
36
- expect(testLight.color).toEqual({ test: true });
44
+ expect((testLight.children[0] as AmbientLight).color).toEqual({ test: true });
37
45
  });
38
46
 
39
47
  it('should set enabled', () => {
40
48
  const testLight = new DIVEAmbientLight();
41
49
  testLight.SetEnabled(false);
42
- expect(testLight.visible).toBe(false);
50
+ expect(testLight.children[0].visible).toBe(false);
43
51
  });
44
52
  });
@@ -1,6 +1,6 @@
1
1
  import DIVEPointLight from '../PointLight.ts';
2
2
  import DIVECommunication from '../../com/Communication.ts';
3
- import { Color } from 'three';
3
+ import { Color, MeshBasicMaterial, Object3D, PointLight } from 'three';
4
4
 
5
5
  const mockAdd = jest.fn();
6
6
 
@@ -10,6 +10,7 @@ jest.mock('three', () => {
10
10
  return {};
11
11
  }),
12
12
  PointLight: jest.fn(function () {
13
+ this.visible = true;
13
14
  this.color = {};
14
15
  this.intensity = 0;
15
16
  this.layers = {
@@ -31,19 +32,30 @@ jest.mock('three', () => {
31
32
  color: {},
32
33
  },
33
34
  }];
34
- this.userData = {};
35
35
  return this;
36
36
  }),
37
37
  SphereGeometry: jest.fn(function () {
38
38
  return this;
39
39
  }),
40
40
  MeshBasicMaterial: jest.fn(function () {
41
+ this.opacity = 1.0;
42
+ this.color = new Color();
41
43
  return this;
42
44
  }),
43
45
  Mesh: jest.fn(function () {
44
46
  this.layers = {
45
47
  mask: 0,
46
48
  };
49
+ this.visible = true;
50
+ this.material = new MeshBasicMaterial();
51
+ return this;
52
+ }),
53
+ Object3D: jest.fn(function () {
54
+ this.children = [];
55
+ this.add = (obj: Object3D) => {
56
+ this.children.push(obj);
57
+ };
58
+ this.userData = {};
47
59
  return this;
48
60
  }),
49
61
  }
@@ -64,27 +76,28 @@ describe('dive/light/DIVEPointLight', () => {
64
76
  const testLight = new DIVEPointLight();
65
77
  testLight.userData.id = 'something';
66
78
  expect(testLight).toBeDefined();
67
- expect(mockAdd).toHaveBeenCalledTimes(1);
79
+ expect(testLight.userData.id).toBe('something');
80
+ expect(testLight.children).toHaveLength(2);
68
81
  });
69
82
 
70
83
  it('should set intensity', () => {
71
84
  const testLight = new DIVEPointLight();
72
85
  testLight.SetIntensity(1.0);
73
- expect(testLight.intensity).toBe(1.0);
86
+ expect((testLight.children[0] as PointLight).intensity).toBe(1.0);
74
87
  testLight.SetIntensity(0.6);
75
- expect(testLight.intensity).toBe(0.6);
88
+ expect((testLight.children[0] as PointLight).intensity).toBe(0.6);
76
89
  });
77
90
 
78
91
  it('should set color', () => {
79
92
  const testLight = new DIVEPointLight();
80
93
  testLight.SetColor({ test: true } as unknown as Color);
81
- expect(testLight.color).toEqual({ test: true });
94
+ expect((testLight.children[0] as PointLight).color).toEqual({ test: true });
82
95
  });
83
96
 
84
97
  it('should set enabled', () => {
85
98
  const testLight = new DIVEPointLight();
86
99
  testLight.SetEnabled(false);
87
- expect(testLight.visible).toBe(false);
100
+ expect(testLight.children[0].visible).toBe(false);
88
101
  });
89
102
 
90
103
  it('should onMove', () => {
@@ -1,6 +1,6 @@
1
1
  import DIVESceneLight from '../SceneLight';
2
2
  import DIVECommunication from '../../com/Communication';
3
- import { Color } from 'three';
3
+ import { Color, HemisphereLight as THREEHemisphereLight, DirectionalLight as THREEDirectionalLight, Object3D } from 'three';
4
4
 
5
5
  jest.mock('../../com/Communication.ts', () => {
6
6
  return {
@@ -57,10 +57,14 @@ jest.mock('three', () => {
57
57
  return this;
58
58
  }),
59
59
  Object3D: jest.fn(function () {
60
- this.add = mockAdd;
60
+ this.children = [];
61
+ this.add = (obj: Object3D) => {
62
+ this.children.push(obj);
63
+ };
61
64
  return this;
62
65
  }),
63
66
  HemisphereLight: jest.fn(function () {
67
+ this.visible = true;
64
68
  this.layers = {
65
69
  mask: 0,
66
70
  };
@@ -71,6 +75,7 @@ jest.mock('three', () => {
71
75
  return this;
72
76
  }),
73
77
  DirectionalLight: jest.fn(function () {
78
+ this.visible = true;
74
79
  this.layers = {
75
80
  mask: 0,
76
81
  };
@@ -100,7 +105,7 @@ describe('dive/light/DIVESceneLight', () => {
100
105
  it('should instantiate', () => {
101
106
  const testLight = new DIVESceneLight();
102
107
  expect(testLight).toBeDefined();
103
- expect(mockAdd).toHaveBeenCalledTimes(2);
108
+ expect(testLight.children).toHaveLength(2);
104
109
  });
105
110
 
106
111
  it('should set intensity', () => {
@@ -117,6 +122,7 @@ describe('dive/light/DIVESceneLight', () => {
117
122
  it('should set enabled', () => {
118
123
  const testLight = new DIVESceneLight();
119
124
  testLight.SetEnabled(false);
120
- expect(testLight.visible).toBe(false);
125
+ expect(testLight.children[0].visible).toBe(false);
126
+ expect(testLight.children[1].visible).toBe(false);
121
127
  });
122
128
  });
@@ -61,6 +61,7 @@ export default class DIVELightRoot extends Object3D {
61
61
  if (light.intensity !== undefined && light.intensity !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).SetIntensity(light.intensity);
62
62
  if (light.enabled !== undefined && light.enabled !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).SetEnabled(light.enabled);
63
63
  if (light.color !== undefined && light.color !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).SetColor(new Color(light.color));
64
+ if (light.visible !== undefined && light.visible !== null) (sceneObject as (DIVEAmbientLight | DIVEPointLight)).visible = light.visible;
64
65
  }
65
66
 
66
67
  public DeleteLight(light: Partial<COMLight>): void {
@@ -74,7 +74,7 @@ describe('dive/scene/root/lightroot/DIVELightRoot', () => {
74
74
 
75
75
  it('should update basic scene light', () => {
76
76
  const lightRoot = new DIVELightRoot();
77
- lightRoot.UpdateLight({ id: 'test_id', type: 'scene', name: 'test', position: undefined, enabled: true });
77
+ lightRoot.UpdateLight({ id: 'test_id', type: 'scene', name: 'test', position: undefined, enabled: true, visible: false });
78
78
  expect(lightRoot.children).toHaveLength(1);
79
79
  expect(lightRoot.children[0].userData.id).toBe('test_id');
80
80
  });
@@ -50,6 +50,7 @@ export default class DIVEModelRoot extends Object3D {
50
50
  if (object.position !== undefined) (sceneObject as Model).SetPosition(object.position);
51
51
  if (object.rotation !== undefined) (sceneObject as Model).SetRotation(object.rotation);
52
52
  if (object.scale !== undefined) (sceneObject as Model).SetScale(object.scale);
53
+ if (object.visible !== undefined) (sceneObject as Model).visible = object.visible;
53
54
  }
54
55
 
55
56
  public DeleteModel(object: Partial<COMModel>): void {
@@ -77,6 +77,7 @@ describe('dive/scene/root/modelroot/DIVEModelRoot', () => {
77
77
  await expect(() => modelRoot.UpdateModel({
78
78
  id: 'test_id',
79
79
  uri: 'not a real uri',
80
+ visible: false,
80
81
  })).not.toThrow();
81
82
  expect(mock_LoadGLTF).toHaveBeenCalledTimes(1);
82
83
  expect(mock_SetModel).toHaveBeenCalledTimes(1);