@shopware-ag/dive 1.19.1-beta.0 → 1.19.1-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.
Files changed (188) hide show
  1. package/build/dive.cjs +362 -199
  2. package/build/dive.cjs.map +1 -1
  3. package/build/dive.js +330 -167
  4. package/build/dive.js.map +1 -1
  5. package/build/dive.mjs +10803 -8714
  6. package/build/dive.mjs.map +1 -1
  7. package/build/src/converter/Converter.d.ts +3 -12
  8. package/build/src/dive.d.ts +1 -0
  9. package/build/src/exporter/Exporter.d.ts +20 -2
  10. package/build/src/loader/Loader.d.ts +0 -4
  11. package/build/src/types/error/index.d.ts +12 -0
  12. package/build/src/types/file/FileTypes.d.ts +17 -0
  13. package/build/src/types/file/index.d.ts +1 -0
  14. package/build/src/types/index.d.ts +5 -8
  15. package/package.json +2 -3
  16. package/build/src/types/ExporterOptions.d.ts +0 -15
  17. package/build/src/types/FileTypes.d.ts +0 -27
  18. package/src/__test__/DIVE.test.ts +0 -274
  19. package/src/animation/AnimationSystem.ts +0 -34
  20. package/src/animation/__test__/AnimationSystem.test.ts +0 -40
  21. package/src/ar/AR.ts +0 -101
  22. package/src/ar/__test__/AR.test.ts +0 -276
  23. package/src/ar/arquicklook/ARQuickLook.ts +0 -53
  24. package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -144
  25. package/src/ar/sceneviewer/SceneViewer.ts +0 -119
  26. package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -190
  27. package/src/ar/webxr/WebXR.ts +0 -177
  28. package/src/ar/webxr/controller/WebXRController.ts +0 -340
  29. package/src/ar/webxr/crosshair/WebXRCrosshair.ts +0 -35
  30. package/src/ar/webxr/origin/WebXROrigin.ts +0 -192
  31. package/src/ar/webxr/overlay/Overlay.ts +0 -50
  32. package/src/ar/webxr/raycaster/WebXRRaycaster.ts +0 -131
  33. package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +0 -102
  34. package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +0 -49
  35. package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +0 -356
  36. package/src/axiscamera/AxisCamera.ts +0 -108
  37. package/src/axiscamera/__test__/AxisCamera.test.ts +0 -150
  38. package/src/camera/PerspectiveCamera.ts +0 -63
  39. package/src/camera/__test__/PerspectiveCamera.test.ts +0 -36
  40. package/src/com/Communication.ts +0 -806
  41. package/src/com/__test__/Communication.test.ts +0 -1030
  42. package/src/com/actions/camera/computeencompassingview.ts +0 -10
  43. package/src/com/actions/camera/getcameratransform.ts +0 -10
  44. package/src/com/actions/camera/movecamera.ts +0 -18
  45. package/src/com/actions/camera/resetcamera.ts +0 -5
  46. package/src/com/actions/camera/setcameralayer.ts +0 -5
  47. package/src/com/actions/camera/setcameratransform.ts +0 -10
  48. package/src/com/actions/camera/zoomcamera.ts +0 -5
  49. package/src/com/actions/index.ts +0 -61
  50. package/src/com/actions/media/generatemedia.ts +0 -18
  51. package/src/com/actions/object/addobject.ts +0 -7
  52. package/src/com/actions/object/deleteobject.ts +0 -7
  53. package/src/com/actions/object/deselectobject.ts +0 -7
  54. package/src/com/actions/object/getallobjects.ts +0 -7
  55. package/src/com/actions/object/getobjects.ts +0 -7
  56. package/src/com/actions/object/model/dropit.ts +0 -5
  57. package/src/com/actions/object/model/modelloaded.ts +0 -5
  58. package/src/com/actions/object/model/placeonfloor.ts +0 -5
  59. package/src/com/actions/object/selectobject.ts +0 -7
  60. package/src/com/actions/object/setparent.ts +0 -10
  61. package/src/com/actions/object/updateobject.ts +0 -7
  62. package/src/com/actions/renderer/startrender.ts +0 -5
  63. package/src/com/actions/scene/exportscene.ts +0 -7
  64. package/src/com/actions/scene/getallscenedata.ts +0 -7
  65. package/src/com/actions/scene/launchar.ts +0 -7
  66. package/src/com/actions/scene/setbackground.ts +0 -5
  67. package/src/com/actions/scene/updatescene.ts +0 -11
  68. package/src/com/actions/toolbox/select/setgizmomode.ts +0 -5
  69. package/src/com/actions/toolbox/transform/setgizmoscalelinked.ts +0 -5
  70. package/src/com/actions/toolbox/transform/setgizmovisible.ts +0 -5
  71. package/src/com/actions/toolbox/usetool.ts +0 -7
  72. package/src/com/types/COMBaseEntity.ts +0 -9
  73. package/src/com/types/COMEntity.ts +0 -7
  74. package/src/com/types/COMEntityType.ts +0 -1
  75. package/src/com/types/COMGeometry.ts +0 -8
  76. package/src/com/types/COMGeometryType.ts +0 -9
  77. package/src/com/types/COMGroup.ts +0 -9
  78. package/src/com/types/COMLight.ts +0 -11
  79. package/src/com/types/COMMaterial.ts +0 -12
  80. package/src/com/types/COMModel.ts +0 -12
  81. package/src/com/types/COMPov.ts +0 -8
  82. package/src/com/types/COMPrimitive.ts +0 -12
  83. package/src/com/types/index.ts +0 -23
  84. package/src/constant/AxisHelperColors.ts +0 -7
  85. package/src/constant/GridColors.ts +0 -2
  86. package/src/constant/VisibilityLayerMask.ts +0 -5
  87. package/src/controls/OrbitControls.ts +0 -211
  88. package/src/controls/__test__/OrbitControls.test.ts +0 -256
  89. package/src/converter/Converter.ts +0 -117
  90. package/src/dive.ts +0 -363
  91. package/src/events/EventExecutor.ts +0 -35
  92. package/src/exporter/Exporter.ts +0 -75
  93. package/src/gizmo/Gizmo.ts +0 -144
  94. package/src/gizmo/handles/AxisHandle.ts +0 -153
  95. package/src/gizmo/handles/RadialHandle.ts +0 -149
  96. package/src/gizmo/handles/ScaleHandle.ts +0 -195
  97. package/src/gizmo/plane/GizmoPlane.ts +0 -84
  98. package/src/gizmo/rotate/RotateGizmo.ts +0 -143
  99. package/src/gizmo/scale/ScaleGizmo.ts +0 -125
  100. package/src/gizmo/translate/TranslateGizmo.ts +0 -114
  101. package/src/grid/Grid.ts +0 -34
  102. package/src/grid/__test__/Grid.test.ts +0 -28
  103. package/src/group/Group.ts +0 -184
  104. package/src/group/__test__/Group.test.ts +0 -212
  105. package/src/helper/applyMixins/__test__/applyMixins.test.ts +0 -30
  106. package/src/helper/applyMixins/applyMixins.ts +0 -70
  107. package/src/helper/findInterface/__test__/findInterface.test.ts +0 -63
  108. package/src/helper/findInterface/findInterface.ts +0 -13
  109. package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +0 -40
  110. package/src/helper/findSceneRecursive/findSceneRecursive.ts +0 -16
  111. package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +0 -186
  112. package/src/helper/getObjectDelta/getObjectDelta.ts +0 -105
  113. package/src/helper/isInterface/__test__/implementsInterface.test.ts +0 -19
  114. package/src/helper/isInterface/implementsInterface.ts +0 -9
  115. package/src/info/Info.ts +0 -178
  116. package/src/info/__test__/Info.test.ts +0 -346
  117. package/src/interface/Draggable.ts +0 -14
  118. package/src/interface/Hoverable.ts +0 -14
  119. package/src/interface/Movable.ts +0 -12
  120. package/src/interface/Rotatable.ts +0 -10
  121. package/src/interface/Scalable.ts +0 -10
  122. package/src/interface/Selectable.ts +0 -11
  123. package/src/io/IO.ts +0 -62
  124. package/src/io/__test__/IO.test.ts +0 -116
  125. package/src/io/gltf/GLTFIO.ts +0 -56
  126. package/src/io/gltf/__test__/GLTFIO.test.ts +0 -108
  127. package/src/light/AmbientLight.ts +0 -39
  128. package/src/light/PointLight.ts +0 -115
  129. package/src/light/SceneLight.ts +0 -63
  130. package/src/light/__test__/AmbientLight.test.ts +0 -29
  131. package/src/light/__test__/PointLight.test.ts +0 -74
  132. package/src/light/__test__/SceneLight.test.ts +0 -47
  133. package/src/loader/Loader.ts +0 -48
  134. package/src/math/__test__/DIVEMath.test.ts +0 -12
  135. package/src/math/ceil/__test__/ceilExp.test.ts +0 -12
  136. package/src/math/ceil/ceilExp.ts +0 -6
  137. package/src/math/degToRad/__test__/degToRad.test.ts +0 -172
  138. package/src/math/degToRad/degToRad.ts +0 -5
  139. package/src/math/floor/__test__/floorExp.test.ts +0 -14
  140. package/src/math/floor/floorExp.ts +0 -6
  141. package/src/math/helper/__test__/shift.test.ts +0 -12
  142. package/src/math/helper/shift.ts +0 -4
  143. package/src/math/index.ts +0 -28
  144. package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -155
  145. package/src/math/radToDeg/radToDeg.ts +0 -5
  146. package/src/math/round/__test__/roundExp.test.ts +0 -14
  147. package/src/math/round/roundExp.ts +0 -10
  148. package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +0 -20
  149. package/src/math/signedAngleTo/signedAngleTo.ts +0 -20
  150. package/src/math/toFixed/__test__/toFixedExp.test.ts +0 -14
  151. package/src/math/toFixed/toFixedExp.ts +0 -9
  152. package/src/math/truncate/__test__/truncateExp.test.ts +0 -14
  153. package/src/math/truncate/truncateExp.ts +0 -9
  154. package/src/mediacreator/MediaCreator.ts +0 -75
  155. package/src/mediacreator/__test__/MediaCreator.test.ts +0 -155
  156. package/src/model/Model.ts +0 -190
  157. package/src/model/__test__/Model.test.ts +0 -215
  158. package/src/module/Module.ts +0 -45
  159. package/src/module/__test__/Module.test.ts +0 -54
  160. package/src/node/Node.ts +0 -100
  161. package/src/node/__test__/Node.test.ts +0 -120
  162. package/src/primitive/Primitive.ts +0 -299
  163. package/src/primitive/__test__/Primitive.test.ts +0 -281
  164. package/src/primitive/floor/Floor.ts +0 -45
  165. package/src/primitive/floor/__test__/Floor.test.ts +0 -24
  166. package/src/renderer/Renderer.ts +0 -215
  167. package/src/renderer/__test__/Renderer.test.ts +0 -228
  168. package/src/scene/Scene.ts +0 -106
  169. package/src/scene/__test__/Scene.test.ts +0 -124
  170. package/src/scene/root/Root.ts +0 -426
  171. package/src/scene/root/__test__/Root.test.ts +0 -903
  172. package/src/scene/xrroot/XRRoot.ts +0 -56
  173. package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +0 -80
  174. package/src/toolbox/BaseTool.ts +0 -319
  175. package/src/toolbox/Toolbox.ts +0 -129
  176. package/src/toolbox/__test__/BaseTool.test.ts +0 -627
  177. package/src/toolbox/__test__/Toolbox.test.ts +0 -143
  178. package/src/toolbox/select/SelectTool.ts +0 -92
  179. package/src/toolbox/select/__test__/SelectTool.test.ts +0 -237
  180. package/src/toolbox/transform/TransformTool.ts +0 -166
  181. package/src/toolbox/transform/__test__/TransformTool.test.ts +0 -147
  182. package/src/types/ExporterOptions.ts +0 -14
  183. package/src/types/FileTypes.ts +0 -37
  184. package/src/types/SceneData.ts +0 -26
  185. package/src/types/SceneObjects.ts +0 -14
  186. package/src/types/SceneType.ts +0 -14
  187. package/src/types/index.ts +0 -31
  188. package/src/types/info/index.ts +0 -76
@@ -1,14 +0,0 @@
1
- import toFixedExp from '../toFixedExp';
2
-
3
- describe('dive/math/toFixed/toFixedExp', () => {
4
- it('should toFixedExp', () => {
5
- expect(toFixedExp(-0.5)).toBe('0');
6
- expect(toFixedExp(0.5)).toBe('1');
7
- expect(toFixedExp(0.55)).toBe('1');
8
- expect(toFixedExp(0.49)).toBe('0');
9
- expect(toFixedExp(1.49)).toBe('1');
10
- expect(toFixedExp(0.49, 2)).toBe('0.49');
11
- expect(toFixedExp(1.49, 2)).toBe('1.49');
12
- expect(toFixedExp(-1.49, 2)).toBe('-1.49');
13
- });
14
- });
@@ -1,9 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function toFixedExp(
4
- number: number,
5
- decimals: number = 0,
6
- ): string {
7
- const n = shift(number, +decimals);
8
- return shift(Math.round(n), -decimals).toFixed(decimals);
9
- }
@@ -1,14 +0,0 @@
1
- import truncateExp from '../truncateExp';
2
-
3
- describe('dive/math/truncate/truncateExp', () => {
4
- it('should truncateExp', () => {
5
- expect(truncateExp(-0.5)).toBe(0);
6
- expect(truncateExp(0.5)).toBe(0);
7
- expect(truncateExp(0.55)).toBe(0);
8
- expect(truncateExp(0.49)).toBe(0);
9
- expect(truncateExp(1.49)).toBe(1);
10
- expect(truncateExp(0.49, 2)).toBe(0.49);
11
- expect(truncateExp(1.49, 2)).toBe(1.49);
12
- expect(truncateExp(-1.49, 2)).toBe(-1.49);
13
- });
14
- });
@@ -1,9 +0,0 @@
1
- import shift from '../helper/shift.ts';
2
-
3
- export default function truncateExp(
4
- number: number,
5
- decimals: number = 0,
6
- ): number {
7
- const n = shift(number, +decimals);
8
- return shift(Math.trunc(n), -decimals);
9
- }
@@ -1,75 +0,0 @@
1
- import DIVEPerspectiveCamera from '../camera/PerspectiveCamera.ts';
2
- import { type DIVEScene } from '../scene/Scene.ts';
3
- import { type DIVERenderer } from '../renderer/Renderer.ts';
4
- import type DIVEOrbitControls from '../controls/OrbitControls.ts';
5
- import { type Vector3Like } from 'three';
6
-
7
- /**
8
- * Creates renderings of the current scene
9
- *
10
- * @module
11
- */
12
-
13
- export class DIVEMediaCreator {
14
- private renderer: DIVERenderer;
15
- private scene: DIVEScene;
16
- private controller: DIVEOrbitControls;
17
-
18
- constructor(
19
- renderer: DIVERenderer,
20
- scene: DIVEScene,
21
- controller: DIVEOrbitControls,
22
- ) {
23
- this.renderer = renderer;
24
- this.scene = scene;
25
- this.controller = controller;
26
- }
27
-
28
- public GenerateMedia(
29
- position: Vector3Like,
30
- target: Vector3Like,
31
- width: number,
32
- height: number,
33
- ): string {
34
- const resetPosition = this.controller.object.position.clone();
35
- const resetRotation = this.controller.object.quaternion.clone();
36
-
37
- this.renderer.OnResize(width, height);
38
- this.controller.object.OnResize(width, height);
39
-
40
- this.controller.object.position.copy(position);
41
- this.controller.target.copy(target);
42
- this.controller.update();
43
-
44
- const dataUri = this.DrawCanvas().toDataURL();
45
-
46
- this.controller.object.position.copy(resetPosition);
47
- this.controller.object.quaternion.copy(resetRotation);
48
-
49
- return dataUri;
50
- }
51
-
52
- public DrawCanvas(canvasElement?: HTMLCanvasElement): HTMLCanvasElement {
53
- // save current canvas
54
- const restore = this.renderer.domElement;
55
- if (canvasElement) {
56
- this.renderer.domElement = canvasElement;
57
- }
58
-
59
- // draw canvas
60
- this.controller.object.layers.mask =
61
- DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
62
- this.renderer.render(this.scene, this.controller.object);
63
- this.controller.object.layers.mask =
64
- DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
65
-
66
- const returnCanvas = this.renderer.domElement;
67
-
68
- // restore canvas
69
- if (canvasElement) {
70
- this.renderer.domElement = restore;
71
- }
72
-
73
- return returnCanvas;
74
- }
75
- }
@@ -1,155 +0,0 @@
1
- import { DIVEMediaCreator } from '../MediaCreator';
2
- import { DIVERenderer } from '../../renderer/Renderer';
3
- import { DIVEScene } from '../../scene/Scene';
4
- import DIVEPerspectiveCamera, {
5
- DIVEPerspectiveCameraDefaultSettings,
6
- } from '../../camera/PerspectiveCamera';
7
- import { type COMPov } from '../../com/types';
8
- import DIVEOrbitControls from '../../controls/OrbitControls';
9
- import { DIVEAnimationSystem } from '../../animation/AnimationSystem';
10
-
11
- /**
12
- * @jest-environment jsdom
13
- */
14
-
15
- const mock_render = jest.fn();
16
- const mock_toDataURL = jest.fn();
17
-
18
- jest.mock('../../scene/Scene', () => {
19
- return {
20
- DIVEScene: jest.fn(function () {
21
- this.add = jest.fn();
22
- this.children = [];
23
- this.Root = {
24
- children: [],
25
- };
26
- return this;
27
- }),
28
- };
29
- });
30
-
31
- jest.mock('../../camera/PerspectiveCamera', () => {
32
- return jest.fn(function () {
33
- this.position = {
34
- clone: jest.fn(),
35
- copy: jest.fn(),
36
- };
37
- this.quaternion = {
38
- clone: jest.fn(),
39
- copy: jest.fn(),
40
- };
41
- this.orbitControls = {
42
- target: {
43
- clone: jest.fn(),
44
- copy: jest.fn(),
45
- },
46
- update: jest.fn(),
47
- };
48
- this.layers = {
49
- mask: 0,
50
- };
51
- return this;
52
- });
53
- });
54
-
55
- jest.mock('../../controls/OrbitControls', () => {
56
- return jest.fn(function () {
57
- this.object = {
58
- position: {
59
- clone: jest.fn(),
60
- copy: jest.fn(),
61
- },
62
- quaternion: {
63
- clone: jest.fn(),
64
- copy: jest.fn(),
65
- },
66
- layers: {
67
- mask: 0,
68
- },
69
- OnResize: jest.fn(),
70
- };
71
-
72
- this.target = {
73
- clone: jest.fn(),
74
- copy: jest.fn(),
75
- };
76
-
77
- this.update = jest.fn();
78
-
79
- return this;
80
- });
81
- });
82
-
83
- jest.mock('../../renderer/Renderer', () => {
84
- return {
85
- DIVERenderer: jest.fn(function () {
86
- this.domElement = {
87
- toDataURL: mock_toDataURL,
88
- };
89
- this.render = mock_render;
90
- this.OnResize = jest.fn();
91
- return this;
92
- }),
93
- };
94
- });
95
-
96
- jest.mock('../../animation/AnimationSystem', () => {
97
- return {
98
- DIVEAnimationSystem: jest.fn(function () {
99
- this.domElement = {
100
- toDataURL: mock_toDataURL,
101
- };
102
- this.render = mock_render;
103
- this.OnResize = jest.fn();
104
- this.AddPreRenderCallback = jest.fn((callback) => {
105
- callback();
106
- return 'id';
107
- });
108
- return this;
109
- }),
110
- };
111
- });
112
-
113
- let mediaCreator: DIVEMediaCreator;
114
-
115
- describe('dive/mediacreator/DIVEMediaCreator', () => {
116
- beforeEach(() => {
117
- jest.clearAllMocks();
118
- mediaCreator = new DIVEMediaCreator(
119
- new DIVERenderer(),
120
- new DIVEScene(),
121
- new DIVEOrbitControls(
122
- new DIVEPerspectiveCamera(DIVEPerspectiveCameraDefaultSettings),
123
- new DIVERenderer(),
124
- new DIVEAnimationSystem(new DIVERenderer()),
125
- ),
126
- );
127
- });
128
-
129
- it('should instantiate', () => {
130
- expect(mediaCreator).toBeDefined();
131
- });
132
-
133
- it('should generate media', () => {
134
- const mock_POV = {
135
- position: { x: 0, y: 0, z: 0 },
136
- target: { x: 0, y: 0, z: 0 },
137
- } as COMPov;
138
- expect(() => {
139
- mediaCreator.GenerateMedia(
140
- mock_POV.position,
141
- mock_POV.target,
142
- 800,
143
- 600,
144
- );
145
- }).not.toThrow();
146
- expect(mock_render).toHaveBeenCalledTimes(1);
147
- expect(mock_toDataURL).toHaveBeenCalledTimes(1);
148
- });
149
-
150
- it('should draw canvas with custom canvas', () => {
151
- const canvas = document.createElement('canvas');
152
- mediaCreator.DrawCanvas(canvas);
153
- expect(mock_render).toHaveBeenCalledTimes(1);
154
- });
155
- });
@@ -1,190 +0,0 @@
1
- import {
2
- Mesh,
3
- MeshStandardMaterial,
4
- type Object3D,
5
- Raycaster,
6
- Vector3,
7
- } from 'three';
8
- import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
9
- import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
10
- import { type COMMaterial } from '../com/types';
11
- import { DIVENode } from '../node/Node';
12
- import { DIVECommunication } from '../com/Communication';
13
-
14
- /**
15
- * A basic model class.
16
- *
17
- * It does calculate it's own bounding box which is used for positioning on the floor.
18
- *
19
- * Can be moved and selected.
20
- *
21
- * @module
22
- */
23
-
24
- export class DIVEModel extends DIVENode {
25
- readonly isDIVEModel: true = true;
26
-
27
- private _mesh: Mesh | null = null;
28
- private _material: MeshStandardMaterial | null = null;
29
-
30
- public SetModel(gltf: Object3D): void {
31
- this.clear();
32
- this._boundingBox.makeEmpty();
33
-
34
- gltf.traverse((child) => {
35
- child.castShadow = true;
36
- child.receiveShadow = true;
37
-
38
- child.layers.mask = this.layers.mask;
39
- this._boundingBox.expandByObject(child);
40
-
41
- // only search for first mesh for now
42
- if (!this._mesh && 'isMesh' in child) {
43
- this._mesh = child as Mesh;
44
-
45
- // if the material is already set, use it, otherwise set it from the model's material
46
- if (this._material) {
47
- this._mesh.material = this._material;
48
- } else {
49
- this._material = (child as Mesh)
50
- .material as MeshStandardMaterial;
51
- }
52
- }
53
- });
54
-
55
- this.add(gltf);
56
- }
57
-
58
- public SetMaterial(material: Partial<COMMaterial>): void {
59
- // if there is no material, create a new one
60
- if (!this._material) {
61
- this._material = new MeshStandardMaterial();
62
- }
63
-
64
- if (material.vertexColors !== undefined) {
65
- this._material.vertexColors = material.vertexColors;
66
- }
67
-
68
- // apply color if supplied
69
- if (material.color !== undefined) {
70
- this._material.color.set(material.color);
71
- }
72
-
73
- // apply albedo map if supplied
74
- if (material.map !== undefined) {
75
- this._material.map = material.map;
76
- }
77
-
78
- // apply normal map
79
- if (material.normalMap !== undefined) {
80
- this._material.normalMap = material.normalMap;
81
- }
82
-
83
- // set roughness value
84
- // if supplied, apply roughness map
85
- // if we applied a roughness map, set roughness to 1.0
86
- if (material.roughness !== undefined) {
87
- this._material.roughness = material.roughness;
88
- }
89
-
90
- if (material.roughnessMap !== undefined) {
91
- this._material.roughnessMap = material.roughnessMap;
92
-
93
- if (this._material.roughnessMap) {
94
- this._material.roughness = 1.0;
95
- }
96
- }
97
-
98
- // set metalness value
99
- // if supplied, apply metalness map
100
- // if we applied a metalness map, set metalness to 1.0
101
- if (material.metalness !== undefined) {
102
- this._material.metalness = material.metalness;
103
- }
104
-
105
- if (material.metalnessMap !== undefined) {
106
- this._material.metalnessMap = material.metalnessMap;
107
-
108
- if (this._material.metalnessMap) {
109
- this._material.metalness = 1.0;
110
- }
111
- }
112
-
113
- // if the mesh is already set, update the material
114
- if (this._mesh) {
115
- this._mesh.material = this._material;
116
- }
117
- }
118
-
119
- public PlaceOnFloor(): void {
120
- // calculate and temporary save world position
121
- const worldPos = this.getWorldPosition(this._positionWorldBuffer);
122
- const oldWorldPos = worldPos.clone();
123
-
124
- // compute the bounding box
125
- this._mesh?.geometry?.computeBoundingBox();
126
- const meshBB = this._mesh?.geometry?.boundingBox;
127
-
128
- // subtract the bounding box min y axis value from the world position y value
129
- if (!meshBB || !this._mesh) return;
130
- worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
131
-
132
- // skip any action when the position did not change
133
- if (worldPos.y === oldWorldPos.y) return;
134
-
135
- DIVECommunication.get(this.userData.id)?.PerformAction(
136
- 'UPDATE_OBJECT',
137
- {
138
- id: this.userData.id,
139
- position: worldPos,
140
- rotation: this.rotation,
141
- scale: this.scale,
142
- },
143
- );
144
- }
145
-
146
- public DropIt(): void {
147
- if (!this.parent) {
148
- console.warn(
149
- 'DIVEModel: DropIt() called on a model that is not in the scene.',
150
- this,
151
- );
152
- return;
153
- }
154
-
155
- // calculate the bottom center of the bounding box
156
- const bottomY = this._boundingBox.min.y * this.scale.y;
157
- const bbBottomCenter = this.localToWorld(
158
- this._boundingBox.getCenter(new Vector3()).multiply(this.scale),
159
- );
160
- bbBottomCenter.y = bottomY + this.position.y;
161
-
162
- // set up raycaster and raycast all scene objects (product layer)
163
- const raycaster = new Raycaster(bbBottomCenter, new Vector3(0, -1, 0));
164
- raycaster.layers.mask = PRODUCT_LAYER_MASK;
165
- const intersections = raycaster.intersectObjects(
166
- findSceneRecursive(this).Root.children,
167
- true,
168
- );
169
-
170
- // if we hit something, move the model to the top on the hit object's bounding box
171
- if (intersections.length > 0) {
172
- const mesh = intersections[0].object as Mesh;
173
- mesh.geometry.computeBoundingBox();
174
- const meshBB = mesh.geometry.boundingBox!;
175
- const worldPos = mesh.localToWorld(meshBB.max.clone());
176
-
177
- const oldPos = this.position.clone();
178
- const newPos = this.position
179
- .clone()
180
- .setY(worldPos.y)
181
- .sub(new Vector3(0, bottomY, 0));
182
- this.position.copy(newPos);
183
-
184
- // if the position changed, update the object in communication
185
- if (this.position.y === oldPos.y) return;
186
-
187
- this.onMove();
188
- }
189
- }
190
- }
@@ -1,215 +0,0 @@
1
- import { RaycasterIntersectObjectMock } from '../../../__mocks__/three';
2
-
3
- import { DIVEModel } from '../Model';
4
- import { DIVECommunication } from '../../com/Communication';
5
- import { DIVEScene } from '../../scene/Scene';
6
- import {
7
- Vector3,
8
- Box3,
9
- Mesh,
10
- MeshStandardMaterial,
11
- type Texture,
12
- Object3D,
13
- } from 'three';
14
- import { type COMMaterial } from '../../com/types';
15
-
16
- jest.mock('../../com/Communication.ts', () => {
17
- return {
18
- DIVECommunication: {
19
- get: jest.fn(() => {
20
- return {
21
- PerformAction: jest.fn(),
22
- };
23
- }),
24
- },
25
- };
26
- });
27
-
28
- const object = new Object3D();
29
- object.children.push(new Mesh());
30
-
31
- jest.spyOn(DIVECommunication, 'get').mockReturnValue({
32
- PerformAction: jest.fn(),
33
- } as unknown as DIVECommunication);
34
-
35
- let model: DIVEModel;
36
-
37
- describe('dive/model/DIVEModel', () => {
38
- beforeEach(() => {
39
- jest.clearAllMocks();
40
- RaycasterIntersectObjectMock.mockClear();
41
- model = new DIVEModel();
42
- });
43
-
44
- afterEach(() => {
45
- jest.clearAllMocks();
46
- });
47
-
48
- it('should instantiate', () => {
49
- expect(model).toBeDefined();
50
- });
51
-
52
- it('should set model', () => {
53
- expect(() => model.SetModel(object)).not.toThrow();
54
- });
55
-
56
- it('should place on floor', () => {
57
- model.SetModel(object);
58
-
59
- const com = DIVECommunication.get('id')!;
60
- const spyPerformAction = jest.spyOn(com, 'PerformAction');
61
-
62
- model.userData.id = 'something';
63
- model.position.set(0, 4, 0);
64
-
65
- jest.spyOn(model['_mesh']!, 'localToWorld').mockReturnValueOnce(
66
- new Vector3(0, 2, 0),
67
- );
68
-
69
- const scene = {
70
- parent: null,
71
- Root: {
72
- children: [
73
- model,
74
- ],
75
- },
76
- } as unknown as DIVEScene;
77
- scene.Root.parent = scene;
78
- model.parent = scene.Root;
79
-
80
- expect(() => model.PlaceOnFloor()).not.toThrow();
81
- expect(spyPerformAction).toHaveBeenCalledWith(
82
- 'UPDATE_OBJECT',
83
- expect.objectContaining({
84
- position: expect.objectContaining({
85
- y: 2,
86
- }),
87
- }),
88
- );
89
- });
90
-
91
- it('should drop it', () => {
92
- const comMock = {
93
- PerformAction: jest.fn(),
94
- } as unknown as DIVECommunication;
95
- jest.spyOn(DIVECommunication, 'get').mockReturnValue(comMock);
96
-
97
- const spy = jest.spyOn(model, 'onMove').mockImplementation(() => {});
98
-
99
- const size = {
100
- x: 1,
101
- y: 1,
102
- z: 1,
103
- };
104
-
105
- model.userData.id = 'something';
106
- model.position.set(0, 4, 0);
107
- model['_boundingBox'] = {
108
- min: new Vector3(-size.x / 2, -size.y / 2, -size.z / 2),
109
- max: new Vector3(size.x / 2, size.y / 2, size.z / 2),
110
- getCenter: jest.fn(() => {
111
- return new Vector3(0, 0, 0);
112
- }),
113
- } as unknown as Box3;
114
-
115
- const hitObject = new Mesh();
116
- hitObject.geometry.boundingBox = new Box3();
117
- hitObject.geometry.boundingBox.max = new Vector3(0, 2, 0);
118
- RaycasterIntersectObjectMock.mockReturnValue([
119
- {
120
- object: hitObject,
121
- },
122
- ]);
123
-
124
- const scene = {
125
- parent: null,
126
- Root: {
127
- children: [
128
- model,
129
- ],
130
- },
131
- } as unknown as DIVEScene;
132
- scene.Root.parent = scene;
133
-
134
- // test when parent is not set
135
- console.warn = jest.fn();
136
- expect(() => model.DropIt()).not.toThrow();
137
- expect(console.warn).toHaveBeenCalledTimes(1);
138
-
139
- model.parent = scene.Root;
140
-
141
- expect(() => model.DropIt()).not.toThrow();
142
- expect(model.position.y).toBe(2.5);
143
- expect(spy).toHaveBeenCalledTimes(1);
144
-
145
- expect(() => model.DropIt()).not.toThrow();
146
- expect(spy).toHaveBeenCalledTimes(1);
147
-
148
- // alter position so onMove will be called again
149
- model.position.y = 2;
150
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
151
- expect(() => model.DropIt()).not.toThrow();
152
- expect(spy).toHaveBeenCalledTimes(2);
153
- });
154
-
155
- it('should set material', () => {
156
- // apply invalid material should not crash
157
- expect(() => model.SetMaterial({} as COMMaterial)).not.toThrow();
158
- expect(model['_material']).not.toBeNull();
159
-
160
- expect(() =>
161
- model.SetMaterial({
162
- color: 0xffffff,
163
- roughness: 0,
164
- metalness: 1,
165
- } as COMMaterial),
166
- ).not.toThrow();
167
- expect((model['_material'] as MeshStandardMaterial).roughness).toBe(0);
168
- expect(
169
- (model['_material'] as MeshStandardMaterial).roughnessMap,
170
- ).toBeUndefined();
171
- expect((model['_material'] as MeshStandardMaterial).metalness).toBe(1);
172
- expect(
173
- (model['_material'] as MeshStandardMaterial).metalnessMap,
174
- ).toBeUndefined();
175
-
176
- expect(() =>
177
- model.SetMaterial({
178
- color: 0xff00ff,
179
- vertexColors: true,
180
- map: 'This_Is_A_Texture' as unknown as Texture,
181
- normalMap: 'This_Is_A_Texture' as unknown as Texture,
182
- roughness: 0,
183
- roughnessMap: 'This_Is_A_Texture' as unknown as Texture,
184
- metalness: 1,
185
- metalnessMap: 'This_Is_A_Texture' as unknown as Texture,
186
- } as COMMaterial),
187
- ).not.toThrow();
188
- expect((model['_material'] as MeshStandardMaterial).roughness).toBe(1);
189
- expect(
190
- (model['_material'] as MeshStandardMaterial).roughnessMap,
191
- ).toBeDefined();
192
- expect((model['_material'] as MeshStandardMaterial).metalness).toBe(1);
193
- expect(
194
- (model['_material'] as MeshStandardMaterial).metalnessMap,
195
- ).toBeDefined();
196
- });
197
-
198
- it('should set model material when material already set before', () => {
199
- model.SetMaterial({ roughness: 0.5 } as COMMaterial);
200
- expect(() => model.SetModel(object)).not.toThrow();
201
- expect(
202
- (model['_mesh']?.material as MeshStandardMaterial).roughness,
203
- ).toBe(0.5);
204
- });
205
-
206
- it('should set material to model when model already set before', () => {
207
- model.SetModel(object);
208
- expect(() =>
209
- model.SetMaterial({ roughness: 0.5 } as COMMaterial),
210
- ).not.toThrow();
211
- expect(
212
- (model['_mesh']?.material as MeshStandardMaterial).roughness,
213
- ).toBe(0.5);
214
- });
215
- });