@shopware-ag/dive 1.0.7 → 1.0.8

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 (97) hide show
  1. package/package.json +6 -3
  2. package/src/__test__/DIVE.test.ts +244 -0
  3. package/src/animation/AnimationSystem.ts +14 -0
  4. package/src/animation/__test__/AnimationSystem.test.ts +19 -0
  5. package/src/axiscamera/AxisCamera.ts +50 -0
  6. package/src/axiscamera/__test__/AxisCamera.test.ts +41 -0
  7. package/src/camera/PerspectiveCamera.ts +43 -0
  8. package/src/camera/__test__/PerspectiveCamera.test.ts +27 -0
  9. package/src/com/Communication.ts +382 -0
  10. package/src/com/__test__/Communication.test.ts +612 -0
  11. package/src/com/actions/camera/getcameratransform.ts +9 -0
  12. package/src/com/actions/camera/movecamera.ts +15 -0
  13. package/src/com/actions/camera/resetcamera.ts +4 -0
  14. package/src/com/actions/camera/setcameralayer.ts +4 -0
  15. package/src/com/actions/camera/setcameratransform.ts +9 -0
  16. package/src/com/actions/camera/zoomcamera.ts +4 -0
  17. package/src/com/actions/index.ts +41 -0
  18. package/src/com/actions/media/generatemedia.ts +15 -0
  19. package/src/com/actions/object/addobject.ts +6 -0
  20. package/src/com/actions/object/deleteobject.ts +6 -0
  21. package/src/com/actions/object/getallobjects.ts +6 -0
  22. package/src/com/actions/object/getobjects.ts +6 -0
  23. package/src/com/actions/object/model/modelloaded.ts +4 -0
  24. package/src/com/actions/object/model/placeonfloor.ts +4 -0
  25. package/src/com/actions/object/selectobject.ts +6 -0
  26. package/src/com/actions/object/updateobject.ts +6 -0
  27. package/src/com/actions/scene/getallscenedata.ts +23 -0
  28. package/src/com/actions/scene/setbackground.ts +4 -0
  29. package/src/com/actions/scene/updatescene.ts +9 -0
  30. package/src/com/actions/toolbox/select/setgizmomode.ts +4 -0
  31. package/src/com/index.ts +4 -0
  32. package/src/com/types.ts +30 -0
  33. package/src/constant/AxisHelperColors.ts +7 -0
  34. package/src/constant/GridColors.ts +2 -0
  35. package/src/constant/VisibilityLayerMask.ts +5 -0
  36. package/src/controls/OrbitControls.ts +145 -0
  37. package/src/controls/__test__/OrbitControls.test.ts +181 -0
  38. package/src/grid/Grid.ts +22 -0
  39. package/src/grid/__test__/Grid.test.ts +19 -0
  40. package/src/helper/applyMixins/__test__/applyMixins.test.ts +27 -0
  41. package/src/helper/applyMixins/applyMixins.ts +15 -0
  42. package/src/helper/getObjectDelta/__test__/getObjectDelta.spec.ts +152 -0
  43. package/src/helper/getObjectDelta/getObjectDelta.ts +101 -0
  44. package/src/interface/Moveable.ts +13 -0
  45. package/src/interface/Rotatable.ts +10 -0
  46. package/src/interface/Scalable.ts +10 -0
  47. package/src/interface/Selectable.ts +11 -0
  48. package/src/interface/__test__/Interfaces.test.ts +13 -0
  49. package/src/light/AmbientLight.ts +29 -0
  50. package/src/light/PointLight.ts +63 -0
  51. package/src/light/SceneLight.ts +60 -0
  52. package/src/light/__test__/AmbientLight.test.ts +44 -0
  53. package/src/light/__test__/PointLight.test.ts +98 -0
  54. package/src/light/__test__/SceneLight.test.ts +122 -0
  55. package/src/loadingmanager/LoadingManager.ts +44 -0
  56. package/src/loadingmanager/__test__/LoadingManager.test.ts +52 -0
  57. package/src/math/__test__/DIVEMath.test.ts +12 -0
  58. package/src/math/ceil/__test__/ceilExp.test.ts +12 -0
  59. package/src/math/ceil/ceilExp.ts +6 -0
  60. package/src/math/floor/__test__/floorExp.test.ts +14 -0
  61. package/src/math/floor/floorExp.ts +6 -0
  62. package/src/math/helper/__test__/shift.test.ts +12 -0
  63. package/src/math/helper/shift.ts +4 -0
  64. package/src/math/index.ts +19 -0
  65. package/src/math/round/__test__/roundExp.test.ts +14 -0
  66. package/src/math/round/roundExp.ts +7 -0
  67. package/src/math/toFixed/__test__/toFixedExp.test.ts +14 -0
  68. package/src/math/toFixed/toFixedExp.ts +6 -0
  69. package/src/math/truncate/__test__/truncateExp.test.ts +14 -0
  70. package/src/math/truncate/truncateExp.ts +6 -0
  71. package/src/mediacreator/MediaCreator.ts +65 -0
  72. package/src/mediacreator/__test__/MediaCreator.test.ts +113 -0
  73. package/src/model/Model.ts +72 -0
  74. package/src/model/__test__/Model.test.ts +163 -0
  75. package/src/primitive/floor/Floor.ts +34 -0
  76. package/src/primitive/floor/__test__/Floor.test.ts +21 -0
  77. package/src/renderer/Renderer.ts +165 -0
  78. package/src/renderer/__test__/Renderer.test.ts +169 -0
  79. package/src/scene/Scene.ts +49 -0
  80. package/src/scene/__test__/Scene.test.ts +70 -0
  81. package/src/scene/root/Root.ts +107 -0
  82. package/src/scene/root/__test__/Root.test.ts +129 -0
  83. package/src/scene/root/lightroot/LightRoot.ts +84 -0
  84. package/src/scene/root/lightroot/__test__/LightRoot.test.ts +137 -0
  85. package/src/scene/root/modelroot/ModelRoot.ts +82 -0
  86. package/src/scene/root/modelroot/__test__/ModelRoot.test.ts +185 -0
  87. package/src/toolbox/BaseTool.ts +18 -0
  88. package/src/toolbox/Toolbox.ts +76 -0
  89. package/src/toolbox/__test__/Toolbox.test.ts +109 -0
  90. package/src/toolbox/select/SelectTool.ts +123 -0
  91. package/src/toolbox/select/__test__/SelectTool.test.ts +190 -0
  92. package/build/dive.cjs +0 -1551
  93. package/build/dive.cjs.map +0 -1
  94. package/build/dive.d.cts +0 -558
  95. package/build/dive.d.ts +0 -558
  96. package/build/dive.js +0 -1516
  97. package/build/dive.js.map +0 -1
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
7
7
  "module": "./build/dive.js",
8
8
  "types": "./build/dive.d.ts",
9
9
  "files": [
10
- "/build/*",
11
- "/src/*"
10
+ "build",
11
+ "LICENSE",
12
+ "package.json",
13
+ "README.md",
14
+ "src"
12
15
  ],
13
16
  "keywords": [
14
17
  "dive",
@@ -0,0 +1,244 @@
1
+ import DIVE, { DIVESettings } from '../dive.ts';
2
+
3
+ jest.mock('three', () => {
4
+ return {
5
+ Vector4: jest.fn(),
6
+ WebGLRenderer: jest.fn(function () {
7
+ this.domElement = {
8
+ clientWidth: 800,
9
+ clientHeight: 600,
10
+ style: {
11
+ position: 'absolute',
12
+ },
13
+ };
14
+ this.domElement.parentElement = this.domElement;
15
+ this.debug = {
16
+ checkShaderErrors: true,
17
+ };
18
+ this.setSize = jest.fn();
19
+ this.setPixelRatio = jest.fn();
20
+ this.render = jest.fn();
21
+ this.setAnimationLoop = jest.fn();
22
+ this.shadowMap = {
23
+ enabled: false,
24
+ };
25
+ return this;
26
+ }),
27
+ MathUtils: {
28
+ generateUUID: () => { return 'test_uuid'; },
29
+ },
30
+ }
31
+ });
32
+
33
+ jest.mock('../renderer/Renderer.ts', () => {
34
+ return jest.fn(function () {
35
+ this.domElement = {
36
+ clientWidth: 800,
37
+ clientHeight: 600,
38
+ style: {
39
+ position: 'absolute',
40
+ },
41
+ };
42
+ this.domElement.parentElement = this.domElement;
43
+ this.AddPreRenderCallback = (callback: () => void) => {
44
+ callback();
45
+ };
46
+ this.RemovePreRenderCallback = jest.fn();
47
+ this.AddPostRenderCallback = (callback: () => void) => {
48
+ callback();
49
+ };
50
+ this.getViewport = jest.fn();
51
+ this.setViewport = jest.fn();
52
+ this.autoClear = false;
53
+ this.render = jest.fn();
54
+ this.StartRenderer = jest.fn();
55
+ this.OnResize = jest.fn();
56
+
57
+ return this;
58
+ });
59
+ });
60
+
61
+ jest.mock('../scene/Scene.ts', () => {
62
+ return jest.fn(function () {
63
+ this.add = jest.fn();
64
+ this.isObject3D = true;
65
+ this.parent = null;
66
+ this.dispatchEvent = jest.fn();
67
+ this.position = {
68
+ set: jest.fn(),
69
+ }
70
+ this.SetIntensity = jest.fn();
71
+ this.SetEnabled = jest.fn();
72
+ this.SetColor = jest.fn();
73
+ this.userData = {
74
+ id: undefined,
75
+ }
76
+ this.removeFromParent = jest.fn();
77
+ return this;
78
+ });
79
+ });
80
+
81
+ jest.mock('../camera/PerspectiveCamera.ts', () => {
82
+ return jest.fn(function () {
83
+ this.isObject3D = true;
84
+ this.parent = null;
85
+ this.dispatchEvent = jest.fn();
86
+ this.position = {
87
+ set: jest.fn(),
88
+ }
89
+ this.SetIntensity = jest.fn();
90
+ this.SetEnabled = jest.fn();
91
+ this.SetColor = jest.fn();
92
+ this.userData = {
93
+ id: undefined,
94
+ }
95
+ this.removeFromParent = jest.fn();
96
+ this.OnResize = jest.fn();
97
+ return this;
98
+ });
99
+ });
100
+
101
+ jest.mock('../controls/OrbitControls.ts', () => {
102
+ return jest.fn(function () {
103
+ this.isObject3D = true;
104
+ this.parent = null;
105
+ this.dispatchEvent = jest.fn();
106
+ this.position = {
107
+ set: jest.fn(),
108
+ }
109
+ this.SetIntensity = jest.fn();
110
+ this.SetEnabled = jest.fn();
111
+ this.SetColor = jest.fn();
112
+ this.userData = {
113
+ id: undefined,
114
+ }
115
+ this.removeFromParent = jest.fn();
116
+ return this;
117
+ });
118
+ });
119
+
120
+ jest.mock('../toolbox/Toolbox.ts', () => {
121
+ return jest.fn(function () {
122
+ this.isObject3D = true;
123
+ this.parent = null;
124
+ this.dispatchEvent = jest.fn();
125
+ this.position = {
126
+ set: jest.fn(),
127
+ }
128
+ this.SetIntensity = jest.fn();
129
+ this.SetEnabled = jest.fn();
130
+ this.SetColor = jest.fn();
131
+ this.userData = {
132
+ id: undefined,
133
+ }
134
+ this.removeFromParent = jest.fn();
135
+ return this;
136
+ });
137
+ });
138
+
139
+ jest.mock('../axiscamera/AxisCamera.ts', () => {
140
+ return jest.fn(function () {
141
+ this.isObject3D = true;
142
+ this.parent = null;
143
+ this.dispatchEvent = jest.fn();
144
+ this.position = {
145
+ set: jest.fn(),
146
+ }
147
+ this.SetIntensity = jest.fn();
148
+ this.SetEnabled = jest.fn();
149
+ this.SetColor = jest.fn();
150
+ this.userData = {
151
+ id: undefined,
152
+ }
153
+ this.removeFromParent = jest.fn();
154
+ this.SetFromCameraMatrix = jest.fn();
155
+ return this;
156
+ });
157
+ });
158
+
159
+ describe('dive/DIVE', () => {
160
+ it('should instantiate', () => {
161
+ const dive = new DIVE();
162
+ expect(dive).toBeDefined();
163
+ });
164
+
165
+ it('should instantiate with settings', () => {
166
+ const settings = {
167
+ autoResize: false,
168
+ renderer: {
169
+ antialias: false,
170
+ alpha: false,
171
+ stencil: false,
172
+ shadowMapEnabled: false,
173
+ shadowMapType: 0,
174
+ toneMapping: 0,
175
+ },
176
+ perspectiveCamera: {
177
+ fov: 0,
178
+ near: 0,
179
+ far: 0,
180
+ },
181
+ orbitControls: {
182
+ enableDamping: false,
183
+ dampingFactor: 0,
184
+ }
185
+ } as DIVESettings;
186
+ const dive = new DIVE(settings);
187
+ expect(dive).toBeDefined();
188
+ });
189
+
190
+ it('should have Canvas', () => {
191
+ const dive = new DIVE();
192
+ expect(dive.Canvas).toBeDefined();
193
+ });
194
+
195
+ it('should have Communication', () => {
196
+ const dive = new DIVE();
197
+ expect(dive.Communication).toBeDefined();
198
+ });
199
+
200
+ it('should resize', () => {
201
+ const dive = new DIVE();
202
+ expect(() => dive.OnResize(800, 600)).not.toThrow();
203
+ });
204
+
205
+ it('should update settings', () => {
206
+ const dive = new DIVE();
207
+ dive.Settings = {
208
+ autoResize: false,
209
+ renderer: {
210
+ antialias: false,
211
+ alpha: false,
212
+ stencil: false,
213
+ shadowMapEnabled: false,
214
+ shadowMapType: 0,
215
+ toneMapping: 0,
216
+ },
217
+ perspectiveCamera: {
218
+ fov: 0,
219
+ near: 0,
220
+ far: 0,
221
+ },
222
+ orbitControls: {
223
+ enableDamping: false,
224
+ dampingFactor: 0,
225
+ }
226
+ }
227
+
228
+ dive.Settings = {
229
+ autoResize: true,
230
+ }
231
+
232
+ Object.assign(dive.Canvas, { parentElement: null });
233
+
234
+ dive.Settings = {
235
+ autoResize: false,
236
+ }
237
+
238
+ dive.Settings = {
239
+ autoResize: true,
240
+ }
241
+ });
242
+
243
+
244
+ });
@@ -0,0 +1,14 @@
1
+ import { update as updateTween } from "@tweenjs/tween.js";
2
+
3
+ /**
4
+ * Updates all animations.
5
+ * DIVE uses Tween.js to handle animations.
6
+ *
7
+ * @module
8
+ */
9
+
10
+ export default class DIVEAnimationSystem {
11
+ public update(): void {
12
+ updateTween();
13
+ }
14
+ }
@@ -0,0 +1,19 @@
1
+ import DIVEAnimationSystem from '../AnimationSystem';
2
+
3
+ jest.mock('@tweenjs/tween.js', () => {
4
+ return {
5
+ update: jest.fn(),
6
+ }
7
+ });
8
+
9
+ describe('dive/animation/DIVEAnimationSystem', () => {
10
+ it('should instantiate', () => {
11
+ const anim = new DIVEAnimationSystem();
12
+ expect(anim).toBeDefined();
13
+ });
14
+
15
+ it('should update', () => {
16
+ const anim = new DIVEAnimationSystem();
17
+ expect(() => anim.update()).not.toThrow();
18
+ });
19
+ });
@@ -0,0 +1,50 @@
1
+ import { AxesHelper, Color, Material, Matrix4, OrthographicCamera } from "three";
2
+ import SpriteText from "three-spritetext";
3
+ import { COORDINATE_LAYER_MASK } from "../constant/VisibilityLayerMask.ts";
4
+ import { AxesColorRed, AxesColorGreen, AxesColorBlue, AxesColorRedLetter, AxesColorGreenLetter, AxesColorBlueLetter } from "../constant/AxisHelperColors.ts";
5
+
6
+ /**
7
+ * Shows the scene axes in the bottom left corner of the screen.
8
+ *
9
+ * @module
10
+ */
11
+
12
+ export default class DIVEAxisCamera extends OrthographicCamera {
13
+ private axesHelper: AxesHelper;
14
+
15
+ constructor() {
16
+ super(-1, 1, 1, -1, 0.1, 100);
17
+
18
+ this.layers.mask = COORDINATE_LAYER_MASK;
19
+
20
+ this.axesHelper = new AxesHelper(0.5);
21
+ this.axesHelper.layers.mask = COORDINATE_LAYER_MASK;
22
+ (this.axesHelper.material as Material).depthTest = false; // always draw
23
+ this.axesHelper.position.set(0, 0, -1);
24
+
25
+ this.axesHelper.setColors(
26
+ new Color(AxesColorRed),
27
+ new Color(AxesColorGreen),
28
+ new Color(AxesColorBlue)
29
+ );
30
+
31
+ const x = new SpriteText('X', 0.2, AxesColorRedLetter);
32
+ const y = new SpriteText('Y', 0.2, AxesColorGreenLetter);
33
+ const z = new SpriteText('Z', 0.2, AxesColorBlueLetter);
34
+ x.layers.mask = COORDINATE_LAYER_MASK;
35
+ y.layers.mask = COORDINATE_LAYER_MASK;
36
+ z.layers.mask = COORDINATE_LAYER_MASK;
37
+ x.position.set(0.7, 0, 0);
38
+ y.position.set(0, 0.7, 0);
39
+ z.position.set(0, 0, 0.7);
40
+ this.axesHelper.add(x);
41
+ this.axesHelper.add(y);
42
+ this.axesHelper.add(z);
43
+
44
+ this.add(this.axesHelper);
45
+ }
46
+
47
+ public SetFromCameraMatrix(matrix: Matrix4): void {
48
+ this.axesHelper.rotation.setFromRotationMatrix(new Matrix4().extractRotation(matrix).invert());
49
+ }
50
+ }
@@ -0,0 +1,41 @@
1
+ import { Matrix4 } from 'three';
2
+ import DIVEAxisCamera from '../AxisCamera';
3
+
4
+ jest.mock('three-spritetext', () => {
5
+ return jest.fn(() => {
6
+ return {
7
+ isObject3D: true,
8
+ parent: null,
9
+ dispatchEvent: jest.fn(),
10
+ layers: {
11
+ mask: 0,
12
+ },
13
+ position: {
14
+ set: jest.fn(),
15
+ },
16
+ removeFromParent: jest.fn(),
17
+ }
18
+ },
19
+ )
20
+ });
21
+
22
+ describe('dive/axiscamera/DIVEAxisCamera', () => {
23
+ it('should instantiate', () => {
24
+ const cam = new DIVEAxisCamera();
25
+ expect(cam).toBeDefined();
26
+ });
27
+
28
+ it('should set rotation from Matrix4', () => {
29
+ expect.assertions(0);
30
+ const matrix = {
31
+ elements: [
32
+ 1, 0, 0, 0,
33
+ 0, 1, 0, 0,
34
+ 0, 0, 1, 0,
35
+ 0, 0, 0, 1,
36
+ ],
37
+ } as Matrix4;
38
+ const cam = new DIVEAxisCamera();
39
+ cam.SetFromCameraMatrix(matrix);
40
+ });
41
+ });
@@ -0,0 +1,43 @@
1
+ import { PerspectiveCamera } from "three";
2
+ import { DEFAULT_LAYER_MASK, HELPER_LAYER_MASK, PRODUCT_LAYER_MASK, UI_LAYER_MASK } from "../constant/VisibilityLayerMask.ts";
3
+
4
+ export type DIVEPerspectiveCameraSettings = {
5
+ fov: number;
6
+ near: number;
7
+ far: number;
8
+ }
9
+
10
+ export const DIVEPerspectiveCameraDefaultSettings: DIVEPerspectiveCameraSettings = {
11
+ fov: 80,
12
+ near: 0.1,
13
+ far: 1000,
14
+ }
15
+
16
+ /**
17
+ * A Perspective camera. Can change the layer mask to show different objects.
18
+ *
19
+ * @module
20
+ */
21
+
22
+ export default class DIVEPerspectiveCamera extends PerspectiveCamera {
23
+ public static readonly EDITOR_VIEW_LAYER_MASK = DEFAULT_LAYER_MASK | UI_LAYER_MASK | HELPER_LAYER_MASK | PRODUCT_LAYER_MASK;
24
+ public static readonly LIVE_VIEW_LAYER_MASK = PRODUCT_LAYER_MASK;
25
+
26
+ public onSetCameraLayer: (mask: number) => void = () => { };
27
+
28
+ constructor(settings: DIVEPerspectiveCameraSettings = DIVEPerspectiveCameraDefaultSettings) {
29
+ super(settings.fov, 1, settings.near, settings.far);
30
+
31
+ this.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
32
+ }
33
+
34
+ public OnResize(width: number, height: number): void {
35
+ this.aspect = width / height;
36
+ this.updateProjectionMatrix();
37
+ }
38
+
39
+ public SetCameraLayer(layer: 'LIVE' | 'EDITOR'): void {
40
+ this.layers.mask = layer === 'LIVE' ? DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK : DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
41
+ this.onSetCameraLayer(this.layers.mask);
42
+ }
43
+ }
@@ -0,0 +1,27 @@
1
+ import DIVEPerspectiveCamera, { DIVEPerspectiveCameraDefaultSettings } from '../PerspectiveCamera';
2
+
3
+ let cam: DIVEPerspectiveCamera;
4
+
5
+ describe('dive/camera/DIVEPerspectiveCamera', () => {
6
+ beforeEach(() => {
7
+ jest.clearAllMocks();
8
+ cam = new DIVEPerspectiveCamera(DIVEPerspectiveCameraDefaultSettings);
9
+ });
10
+
11
+ it('should instantiate', () => {
12
+ cam = new DIVEPerspectiveCamera();
13
+ expect(cam).toBeDefined();
14
+ });
15
+
16
+ it('should resize', () => {
17
+ const spy = jest.spyOn(cam, 'updateProjectionMatrix');
18
+ expect(() => cam.OnResize(800, 600)).not.toThrow();
19
+ expect(cam.aspect).toBe(800 / 600);
20
+ expect(spy).toHaveBeenCalledTimes(1);
21
+ });
22
+
23
+ it('should set camera layer', () => {
24
+ expect(() => cam.SetCameraLayer('LIVE')).not.toThrow();
25
+ expect(() => cam.SetCameraLayer('EDITOR')).not.toThrow();
26
+ });
27
+ });