@shopware-ag/dive 1.16.24 → 1.16.26-beta.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.
Files changed (44) hide show
  1. package/build/dive.cjs +1652 -203
  2. package/build/dive.cjs.map +1 -1
  3. package/build/dive.d.cts +50 -8
  4. package/build/dive.d.ts +50 -8
  5. package/build/dive.js +1619 -159
  6. package/build/dive.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/ar/AR.ts +164 -0
  9. package/src/ar/arquicklook/ARQuickLook.ts +42 -0
  10. package/src/ar/webxr/WebXR.ts +176 -0
  11. package/src/ar/webxr/controller/WebXRController.ts +334 -0
  12. package/src/ar/webxr/crosshair/WebXRCrosshair.ts +35 -0
  13. package/src/ar/webxr/origin/WebXROrigin.ts +191 -0
  14. package/src/ar/webxr/overlay/Overlay.ts +50 -0
  15. package/src/ar/webxr/raycaster/WebXRRaycaster.ts +131 -0
  16. package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +102 -0
  17. package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +49 -0
  18. package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +356 -0
  19. package/src/axiscamera/AxisCamera.ts +4 -4
  20. package/src/axiscamera/__test__/AxisCamera.test.ts +4 -0
  21. package/src/com/Communication.ts +17 -0
  22. package/src/com/__test__/Communication.test.ts +1 -1
  23. package/src/com/actions/index.ts +2 -0
  24. package/src/dive.ts +51 -9
  25. package/src/events/EventExecutor.ts +35 -0
  26. package/src/helper/findSceneRecursive/findSceneRecursive.ts +2 -2
  27. package/src/info/Info.ts +37 -1
  28. package/src/info/__test__/Info.test.ts +45 -5
  29. package/src/mediacreator/MediaCreator.ts +4 -4
  30. package/src/mediacreator/__test__/MediaCreator.test.ts +7 -2
  31. package/src/renderer/Renderer.ts +21 -11
  32. package/src/renderer/__test__/Renderer.test.ts +19 -1
  33. package/src/scene/Scene.ts +35 -12
  34. package/src/scene/__test__/Scene.test.ts +39 -5
  35. package/src/scene/root/Root.ts +1 -0
  36. package/src/scene/xrroot/XRRoot.ts +56 -0
  37. package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +80 -0
  38. package/src/toolbox/BaseTool.ts +9 -3
  39. package/src/toolbox/Toolbox.ts +1 -1
  40. package/src/toolbox/__test__/Toolbox.test.ts +1 -1
  41. package/src/toolbox/select/SelectTool.ts +1 -1
  42. package/src/toolbox/select/__test__/SelectTool.test.ts +1 -1
  43. package/src/toolbox/transform/TransformTool.ts +4 -4
  44. package/src/toolbox/transform/__test__/TransformTool.test.ts +2 -4
@@ -1,6 +1,7 @@
1
1
  import { DIVEScene } from '../Scene';
2
2
  import { type Color } from 'three';
3
3
  import { type COMEntity } from '../../com/types';
4
+ import { DIVERenderer } from '../../renderer/Renderer';
4
5
 
5
6
  const mock_AddSceneObject = jest.fn();
6
7
  const mock_UpdateSceneObject = jest.fn();
@@ -26,6 +27,30 @@ jest.mock('../root/Root', () => {
26
27
  };
27
28
  });
28
29
 
30
+ jest.mock('../xrroot/XRRoot', () => {
31
+ return {
32
+ DIVEXRRoot: jest.fn(function (scene: DIVEScene) {
33
+ this.visible = true;
34
+ this.isObject3D = true;
35
+ this.parent = null;
36
+ this.dispatchEvent = jest.fn();
37
+ this.removeFromParent = jest.fn();
38
+ this.visible = true;
39
+ this.InitLightEstimation = jest.fn();
40
+ this.DisposeLightEstimation = jest.fn();
41
+ return this;
42
+ }),
43
+ };
44
+ });
45
+
46
+ jest.mock('../../renderer/Renderer.ts', () => {
47
+ return {
48
+ DIVERenderer: jest.fn(function () {}),
49
+ };
50
+ });
51
+
52
+ const mockRenderer = new DIVERenderer();
53
+
29
54
  describe('dive/scene/DIVEScene', () => {
30
55
  afterEach(() => {
31
56
  jest.clearAllMocks();
@@ -34,17 +59,26 @@ describe('dive/scene/DIVEScene', () => {
34
59
  it('should instantiate', () => {
35
60
  const scene = new DIVEScene();
36
61
  expect(scene).toBeDefined();
37
- expect(scene.children).toHaveLength(3);
38
62
  });
39
63
 
40
- it('should have Floor', () => {
64
+ it('should have Root', () => {
65
+ const scene = new DIVEScene();
66
+ expect(scene.Root).toBeDefined();
67
+ });
68
+
69
+ it('should have XRRoot', () => {
70
+ const scene = new DIVEScene();
71
+ expect(scene.XRRoot).toBeDefined();
72
+ });
73
+
74
+ it('should InitXR', () => {
41
75
  const scene = new DIVEScene();
42
- expect(scene.Floor).toBeDefined();
76
+ expect(() => scene.InitXR(mockRenderer)).not.toThrow();
43
77
  });
44
78
 
45
- it('should have Grid', () => {
79
+ it('should DisposeXR', () => {
46
80
  const scene = new DIVEScene();
47
- expect(scene.Grid).toBeDefined();
81
+ expect(() => scene.DisposeXR()).not.toThrow();
48
82
  });
49
83
 
50
84
  it('should set background color', () => {
@@ -238,6 +238,7 @@ export class DIVERoot extends Object3D {
238
238
  const created = new DIVEModel();
239
239
  sceneObject = created;
240
240
  sceneObject.userData.id = model.id;
241
+ sceneObject.userData.uri = model.uri;
241
242
  this.add(sceneObject);
242
243
  }
243
244
 
@@ -0,0 +1,56 @@
1
+ import { Mesh, Object3D, PlaneGeometry, ShadowMaterial } from 'three';
2
+ import { DIVERoot } from '../root/Root';
3
+ import { type DIVERenderer } from '../../renderer/Renderer';
4
+ import { DIVEXRLightRoot } from './xrlightroot/XRLightRoot';
5
+ import { type DIVEScene } from '../Scene';
6
+
7
+ export class DIVEXRRoot extends Object3D {
8
+ private _xrLightRoot: DIVEXRLightRoot;
9
+ private _xrModelRoot: DIVERoot;
10
+ private _xrHandNode: Object3D;
11
+
12
+ public get XRModelRoot(): DIVERoot {
13
+ return this._xrModelRoot;
14
+ }
15
+
16
+ public get XRLightRoot(): DIVEXRLightRoot {
17
+ return this._xrLightRoot;
18
+ }
19
+
20
+ public get XRHandNode(): Object3D {
21
+ return this._xrHandNode;
22
+ }
23
+
24
+ private _xrShadowPlane: Mesh;
25
+
26
+ constructor(scene: DIVEScene) {
27
+ super();
28
+ this.name = 'XRRoot';
29
+
30
+ this._xrModelRoot = new DIVERoot();
31
+ this._xrModelRoot.name = 'XRModelRoot';
32
+ this.add(this._xrModelRoot);
33
+
34
+ this._xrShadowPlane = new Mesh(
35
+ new PlaneGeometry(100, 100),
36
+ new ShadowMaterial({ opacity: 1, transparent: true }),
37
+ );
38
+ this._xrModelRoot.add(this._xrShadowPlane);
39
+
40
+ this._xrLightRoot = new DIVEXRLightRoot(scene);
41
+ this._xrLightRoot.name = 'XRLightRoot';
42
+ this.add(this._xrLightRoot);
43
+
44
+ this._xrHandNode = new Object3D();
45
+ this._xrHandNode.name = 'XRHandNode';
46
+ this.add(this._xrHandNode);
47
+ }
48
+
49
+ public InitLightEstimation(renderer: DIVERenderer): void {
50
+ this._xrLightRoot.InitLightEstimation(renderer);
51
+ }
52
+
53
+ public DisposeLightEstimation(): void {
54
+ this._xrLightRoot.DisposeLightEstimation();
55
+ }
56
+ }
@@ -0,0 +1,80 @@
1
+ import { XREstimatedLight } from 'three/examples/jsm/webxr/XREstimatedLight';
2
+ import { type DIVERenderer } from '../../../renderer/Renderer';
3
+ import { Object3D } from 'three';
4
+ import { type DIVEScene } from '../../Scene';
5
+ import { PRODUCT_LAYER_MASK } from '../../../constant/VisibilityLayerMask';
6
+ import { DIVERoot } from '../../root/Root';
7
+
8
+ export class DIVEXRLightRoot extends Object3D {
9
+ private _scene: DIVEScene;
10
+
11
+ private _xrLight: XREstimatedLight | null;
12
+ private _lightRoot: DIVERoot;
13
+
14
+ constructor(scene: DIVEScene) {
15
+ super();
16
+ this.name = 'XRLightRoot';
17
+
18
+ this._scene = scene;
19
+
20
+ // placeholder for XR light
21
+ this._xrLight = null;
22
+
23
+ // add scene
24
+ this._lightRoot = new DIVERoot();
25
+ this._lightRoot.UpdateSceneObject({
26
+ id: 'XRSceneLight',
27
+ entityType: 'light',
28
+ name: 'XRSceneLight',
29
+ type: 'scene',
30
+ color: 0xffffff,
31
+ intensity: 1,
32
+ enabled: true,
33
+ visible: true,
34
+ });
35
+ this.add(this._lightRoot);
36
+ }
37
+
38
+ public InitLightEstimation(renderer: DIVERenderer): void {
39
+ if (!this._xrLight) {
40
+ this._xrLight = new XREstimatedLight(renderer, true);
41
+ this._xrLight.layers.mask = PRODUCT_LAYER_MASK;
42
+ this.add(this._xrLight);
43
+ }
44
+
45
+ this._xrLight.addEventListener('estimationstart', () => {
46
+ this.onEstimationStart();
47
+ });
48
+ this._xrLight.addEventListener('estimationend', () => {
49
+ this.onEstimationEnd();
50
+ });
51
+ }
52
+
53
+ public DisposeLightEstimation(): void {
54
+ if (!this._xrLight) return;
55
+
56
+ this._xrLight.removeEventListener('estimationstart', () => {
57
+ this.onEstimationStart();
58
+ });
59
+ this._xrLight.removeEventListener('estimationend', () => {
60
+ this.onEstimationEnd();
61
+ });
62
+ }
63
+
64
+ private onEstimationStart(): void {
65
+ this._lightRoot.visible = false;
66
+
67
+ if (!this._xrLight) return;
68
+
69
+ if (this._xrLight.environment) {
70
+ this._scene.environment = this._xrLight.environment;
71
+ }
72
+ }
73
+
74
+ private onEstimationEnd(): void {
75
+ this._lightRoot.visible = true;
76
+ this._scene.environment = null;
77
+
78
+ if (!this._xrLight) return;
79
+ }
80
+ }
@@ -1,10 +1,16 @@
1
- import { Intersection, Object3D, Raycaster, Vector2, Vector3 } from 'three';
1
+ import {
2
+ type Intersection,
3
+ type Object3D,
4
+ Raycaster,
5
+ Vector2,
6
+ Vector3,
7
+ } from 'three';
2
8
  import {
3
9
  PRODUCT_LAYER_MASK,
4
10
  UI_LAYER_MASK,
5
11
  } from '../constant/VisibilityLayerMask';
6
- import { DIVEScene } from '../scene/Scene';
7
- import DIVEOrbitControls from '../controls/OrbitControls';
12
+ import { type DIVEScene } from '../scene/Scene';
13
+ import type DIVEOrbitControls from '../controls/OrbitControls';
8
14
  import { type DIVEDraggable } from '../interface/Draggable';
9
15
  import { type DIVEHoverable } from '../interface/Hoverable';
10
16
  import { findInterface } from '../helper/findInterface/findInterface';
@@ -1,5 +1,5 @@
1
1
  import type DIVEOrbitControls from '../controls/OrbitControls.ts';
2
- import type { DIVEScene } from '../scene/Scene.ts';
2
+ import { type DIVEScene } from '../scene/Scene.ts';
3
3
  import { type DIVEBaseTool } from './BaseTool.ts';
4
4
  import { type DIVESelectTool } from './select/SelectTool.ts';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import DIVEToolbox, { type ToolType } from '../Toolbox';
2
2
  import type DIVEOrbitControls from '../../controls/OrbitControls';
3
- import type { DIVEScene } from '../../scene/Scene';
3
+ import { type DIVEScene } from '../../scene/Scene';
4
4
 
5
5
  /**
6
6
  * @jest-environment jsdom
@@ -1,5 +1,5 @@
1
1
  import { type Object3D } from 'three';
2
- import { DIVEScene } from '../../scene/Scene.ts';
2
+ import { type DIVEScene } from '../../scene/Scene.ts';
3
3
  import DIVETransformTool from '../transform/TransformTool.ts';
4
4
  import { findInterface } from '../../helper/findInterface/findInterface.ts';
5
5
  import type DIVEOrbitControls from '../../controls/OrbitControls.ts';
@@ -100,7 +100,7 @@ jest.mock('three', () => {
100
100
  const mock_attach = jest.fn();
101
101
  const mock_detach = jest.fn();
102
102
 
103
- jest.mock('three/examples/jsm/Addons.js', () => {
103
+ jest.mock('three/examples/jsm/controls/TransformControls', () => {
104
104
  return {
105
105
  TransformControls: jest.fn(function () {
106
106
  (this.addEventListener = (
@@ -1,7 +1,7 @@
1
1
  import { DIVEBaseTool } from '../BaseTool.ts';
2
- import { DIVEScene } from '../../scene/Scene.ts';
3
- import DIVEOrbitControls from '../../controls/OrbitControls.ts';
4
- import { TransformControls } from 'three/examples/jsm/Addons';
2
+ import { type DIVEScene } from '../../scene/Scene.ts';
3
+ import type DIVEOrbitControls from '../../controls/OrbitControls.ts';
4
+ import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
5
5
  import { type DIVEMovable } from '../../interface/Movable.ts';
6
6
  import { implementsInterface } from '../../helper/isInterface/implementsInterface.ts';
7
7
 
@@ -81,7 +81,7 @@ export default class DIVETransformTool extends DIVEBaseTool {
81
81
  this._gizmo.object.onMoveEnd();
82
82
  });
83
83
 
84
- scene.add(this._gizmo);
84
+ this._scene.add(this._gizmo);
85
85
  }
86
86
 
87
87
  public Activate(): void {}
@@ -99,7 +99,7 @@ jest.mock('three', () => {
99
99
  const mock_attach = jest.fn();
100
100
  const mock_detach = jest.fn();
101
101
 
102
- jest.mock('three/examples/jsm/Addons.js', () => {
102
+ jest.mock('three/examples/jsm/controls/TransformControls', () => {
103
103
  return {
104
104
  TransformControls: jest.fn(function () {
105
105
  (this.addEventListener = (
@@ -189,9 +189,7 @@ describe('dive/toolbox/select/DIVETransformTool', () => {
189
189
  const transformTool = new DIVETransformTool(mockScene, mockController);
190
190
  expect(() => transformTool.SetGizmoVisibility(true)).not.toThrow();
191
191
 
192
- expect(mockScene.add).toBeCalled();
193
-
194
- mockScene.children.includes = jest.fn().mockReturnValue(true);
192
+ mockScene.Root.children.includes = jest.fn().mockReturnValue(true);
195
193
  expect(() => transformTool.SetGizmoVisibility(false)).not.toThrow();
196
194
  });
197
195
  });