@shopware-ag/dive 1.17.2 → 1.18.1

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 (40) hide show
  1. package/README.md +124 -28
  2. package/build/dive.cjs +11 -7
  3. package/build/dive.cjs.map +1 -1
  4. package/build/dive.d.cts +3 -4
  5. package/build/dive.d.ts +3 -4
  6. package/build/dive.js +9 -5
  7. package/build/dive.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/__test__/DIVE.test.ts +0 -40
  10. package/src/animation/__test__/AnimationSystem.test.ts +0 -7
  11. package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -140
  12. package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -140
  13. package/src/axiscamera/__test__/AxisCamera.test.ts +0 -76
  14. package/src/com/__test__/Communication.test.ts +0 -6
  15. package/src/controls/__test__/OrbitControls.test.ts +0 -87
  16. package/src/dive.ts +3 -3
  17. package/src/exporters/usdz/__test__/USDZExporter.test.ts +57 -0
  18. package/src/group/Group.ts +6 -1
  19. package/src/group/__test__/Group.test.ts +6 -3
  20. package/src/io/gltf/__test__/GLTFIO.test.ts +0 -77
  21. package/src/light/PointLight.ts +1 -1
  22. package/src/light/__test__/AmbientLight.test.ts +0 -24
  23. package/src/light/__test__/PointLight.test.ts +0 -61
  24. package/src/light/__test__/SceneLight.test.ts +0 -89
  25. package/src/loadingmanager/LoadingManager.ts +2 -1
  26. package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -30
  27. package/src/math/degToRad/__test__/degToRad.test.ts +0 -7
  28. package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -7
  29. package/src/model/Model.ts +1 -1
  30. package/src/model/__test__/Model.test.ts +5 -155
  31. package/src/node/__test__/Node.test.ts +0 -149
  32. package/src/primitive/__test__/Primitive.test.ts +6 -199
  33. package/src/primitive/floor/__test__/Floor.test.ts +0 -3
  34. package/src/renderer/__test__/Renderer.test.ts +16 -46
  35. package/src/scene/__test__/Scene.test.ts +6 -16
  36. package/src/scene/root/Root.ts +4 -4
  37. package/src/scene/root/__test__/Root.test.ts +6 -188
  38. package/src/toolbox/__test__/BaseTool.test.ts +34 -38
  39. package/src/toolbox/select/__test__/SelectTool.test.ts +16 -89
  40. package/src/toolbox/transform/__test__/TransformTool.test.ts +14 -82
package/README.md CHANGED
@@ -21,9 +21,21 @@ You can find the template in ci/readme/template/TEMPLATE_README.md
21
21
  <a href="#badge">
22
22
  <img alt="dive: types" src="https://img.shields.io/npm/types/%40shopware-ag%2Fdive">
23
23
  </a>
24
+ <a href="#badge">
25
+ <img alt="dive: types" src="https://img.shields.io/codecov/c/github/shopware/dive">
26
+ </a>
24
27
  </p>
25
28
 
26
- # About
29
+ ## Table of Contents
30
+
31
+ 1. [About](#about)
32
+ 2. [Installation](#installation)
33
+ 3. [Local development](#local-development)
34
+ 4. [Usage](#usage)
35
+ 5. [Unit Tests](#unit-tests)
36
+ 6. [Formatting](#formatting)
37
+
38
+ ## About
27
39
 
28
40
  DIVE is a spatial framework made by and optimized for Shopware. It can be used
29
41
  directly integrated in a Shopware frontend such as Storefront or in any other
@@ -33,51 +45,106 @@ DIVE supplies your frontend application with all needed tooling to set up a
33
45
  basic 3D application with event-based controls called "Actions". For further
34
46
  information, see [Getting started](#getting-started).
35
47
 
36
- # Installation
48
+ ## Installation
37
49
 
38
- #### npm:
50
+ The `@shopware-ag/dive` package can be installed via
39
51
 
40
- ```
52
+ ```bash
41
53
  npm install @shopware-ag/dive
54
+
55
+ or
56
+
57
+ yarn add @shopware-ag/dive
42
58
  ```
43
59
 
44
- #### yarn:
60
+ ## Local development
61
+
62
+ ### with devenv
45
63
 
64
+ If you are using `devenv`, you have to make sure that you are in the correct shell while linking. `nix` (what `devenv` is
65
+ based on) uses it's own instances of `npm` so we need to make sure that the `npm link` get's executed within the correct `devenv` environment a.k.a `nix/store`.
66
+ To make sure you are using the correct instance of `npm` you have to browse to your `devenv` project:
67
+
68
+ ```bash
69
+ cd path/to/your/devenv.nix
46
70
  ```
47
- yarn add @shopware-ag/dive
71
+
72
+ #### with direnv
73
+
74
+ If you use `direnv` you should be launched into the correct shell automatically.
75
+
76
+ #### without direnv
77
+
78
+ If you don't use `direnv` you can start the correct shell manually by running
79
+
80
+ ```bash
81
+ devenv shell
48
82
  ```
49
83
 
50
- # Formatter
84
+ Within the `devenv shell` you have to browse to your DIVE folder
51
85
 
52
- DIVE uses Prettier as a preconfigured formatter.
86
+ ```bash
87
+ cd path/to/@shopware-ag/dive
88
+ ```
53
89
 
54
- #### Setup in Shopware
90
+ ### without devenv
91
+
92
+ You don't have to do anything special if you don't use `devenv`.
93
+
94
+ ### npm link
95
+
96
+ If you want to link DIVE package locally after checking out, you can to that in the package's project folder:
97
+
98
+ ```bash
99
+ cd path/to/@shopware-ag/dive
100
+ npm link
101
+ ```
55
102
 
56
- Don't forget to include DIVE in your webpack.config.js:
103
+ After registering the package in npm, you can use the sym-link in your project:
104
+
105
+ ```bash
106
+ cd path/to/your/package.json
107
+ npm link @shopware-ag/dive
108
+ ```
109
+
110
+ After successfully linking DIVE into your project you will find the according sym-link in your `node_modules`.
111
+
112
+ ### Setup in Shopware
113
+
114
+ Don't forget to include DIVE in your `webpack.config.js`:
57
115
 
58
116
  ```js
59
117
  const path = require('path');
60
118
 
61
119
  module.exports = () => {
62
120
  return {
63
- ...
121
+ // Other configurations...
64
122
  resolve: {
65
- extensions: ['.ts', '.cjs', '.js'],
123
+ extensions: [
124
+ '.ts',
125
+ '.cjs',
126
+ '.js',
127
+ ],
66
128
  alias: {
67
129
  three: path.resolve(__dirname, 'path/to/node_modules/three'),
68
- "@shopware-ag/dive": path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive'),
69
- }
130
+ '@shopware-ag/dive': path.resolve(
131
+ __dirname,
132
+ 'path/to/node_modules/@shopware-ag/dive',
133
+ ),
134
+ },
70
135
  },
71
- ...
72
136
  module: {
73
137
  rules: [
74
- ...
138
+ // Other rules...
75
139
  {
76
140
  test: /\.(js|ts)$/,
77
141
  loader: 'swc-loader',
78
142
  include: [
79
143
  path.resolve(__dirname, 'path/to/node_modules/three'),
80
- path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive')
144
+ path.resolve(
145
+ __dirname,
146
+ 'path/to/node_modules/@shopware-ag/dive',
147
+ ),
81
148
  ],
82
149
  options: {
83
150
  jsc: {
@@ -88,18 +155,20 @@ module.exports = () => {
88
155
  },
89
156
  },
90
157
  },
91
- ...
158
+ // Other rules...
92
159
  ],
93
- }
160
+ },
94
161
  };
95
162
  };
96
163
  ```
97
164
 
98
- # Quick View
165
+ ## Usage
166
+
167
+ ### Quick View
99
168
 
100
169
  QuickView is used to quickly display your assets with as few lines of code as
101
- possible. Simply call the static `QuickView()` method (with your data-uri as a
102
- parameter) to create an instance of DIVE with your asset to use in further code.
170
+ possible. Simply call the static `QuickView()` method, with your data URI as a
171
+ parameter, to create an instance of DIVE with your asset to use in further code.
103
172
 
104
173
  ```ts
105
174
  import { DIVE } from '@shopware-ag/dive';
@@ -110,15 +179,30 @@ const myCanvasWrapper = document.createElement('div');
110
179
  myCanvasWrapper.appendChild(dive.Canvas);
111
180
  ```
112
181
 
113
- # Getting started
182
+ ### Example with Error Handling:
183
+
184
+ ```ts
185
+ import { DIVE } from '@shopware-ag/dive';
186
+
187
+ try {
188
+ const dive = DIVE.QuickView('your/asset/uri.glb'); // <-- call QuickView()
189
+
190
+ const myCanvasWrapper = document.createElement('div');
191
+ myCanvasWrapper.appendChild(dive.Canvas);
192
+ } catch (error) {
193
+ console.error('Failed to load asset:', error);
194
+ }
195
+ ```
196
+
197
+ ### Getting started
114
198
 
115
- Import:
199
+ #### Import:
116
200
 
117
201
  ```ts
118
202
  import { DIVE } from '@shopware-ag/dive'; // <-- import DIVE
119
203
  ```
120
204
 
121
- Instantiate:
205
+ #### Instantiate:
122
206
 
123
207
  ```ts
124
208
  import { DIVE } from '@shopware-ag/dive';
@@ -127,7 +211,7 @@ const dive = new DIVE(); // <-- instantiate DIVE
127
211
  ```
128
212
 
129
213
  DIVE supplies your application with a HTMLCanvasElement that it uses as a render
130
- target. After instantiating, you can use the supplied canvas within you frontend
214
+ target. After instantiating, you can use the supplied canvas within your frontend
131
215
  code to attach it to your DOM.
132
216
 
133
217
  ```ts
@@ -155,7 +239,7 @@ com.PerformAction('SET_CAMERA_TRANSFORM', {
155
239
  });
156
240
  ```
157
241
 
158
- # Actions
242
+ ### Actions
159
243
 
160
244
  Actions symbolize the communication between frontend and 3D space. All actions
161
245
  can be performed anywhere, no matter if you are in frontend or 3D.
@@ -206,7 +290,7 @@ com.PerformAction('SET_CAMERA_TRANSFORM', {
206
290
  unsubscribe(); // <-- execute unsubscribe callback when done
207
291
  ```
208
292
 
209
- # Actions (List)
293
+ #### Actions List
210
294
 
211
295
  In the following you find a list of all available actions to perform on
212
296
  DIVECommunication class via
@@ -434,3 +518,15 @@ DIVECommunication class via
434
518
  </td>
435
519
  </tr>
436
520
  </table>
521
+
522
+ ## Unit Tests
523
+
524
+ All relevant files are covered by Jest tests. If you find any file that has not been covered yet, feel free to add unit tests accordingly.
525
+
526
+ If there are any modules that have to be mocked (like `three`) you can create a given file in the `__mocks__` folder in project root. Jest manages to mock modules with a given file with the modules name as a file name (for example `three.ts`). Every export will be part of the modules mock. You don't need to mock the module in your test anymore, you only extend the module mock.
527
+
528
+ If you have any other things from a module to import, you can simply create a folder structure and place the mock file at the end of your structure. To understand better please take a look at the `__mocks__` folder for yourself.
529
+
530
+ ## Formatting
531
+
532
+ DIVE uses Prettier as a preconfigured formatter.
package/build/dive.cjs CHANGED
@@ -3092,13 +3092,14 @@ var DIVEModel = class extends DIVENode {
3092
3092
  };
3093
3093
 
3094
3094
  // src/loadingmanager/LoadingManager.ts
3095
- var import_Addons = require("three/examples/jsm/Addons.js");
3095
+ var import_DRACOLoader = require("three/examples/jsm/loaders/DRACOLoader");
3096
+ var import_GLTFLoader2 = require("three/examples/jsm/loaders/GLTFLoader");
3096
3097
  var DIVELoadingManager = class {
3097
3098
  // ... maybe extend with other loaders later
3098
3099
  constructor() {
3099
3100
  this.progress = /* @__PURE__ */ new Map();
3100
- this.gltfloader = new import_Addons.GLTFLoader();
3101
- this.dracoloader = new import_Addons.DRACOLoader();
3101
+ this.gltfloader = new import_GLTFLoader2.GLTFLoader();
3102
+ this.dracoloader = new import_DRACOLoader.DRACOLoader();
3102
3103
  this.dracoloader.setDecoderPath(
3103
3104
  "https://www.gstatic.com/draco/v1/decoders/"
3104
3105
  );
@@ -3394,6 +3395,9 @@ var DIVEGroup = class extends DIVENode {
3394
3395
  this._lines[index].visible = visible;
3395
3396
  }
3396
3397
  attach(object) {
3398
+ if (this._members.includes(object)) {
3399
+ return this;
3400
+ }
3397
3401
  const line = this.createLine();
3398
3402
  this.add(line);
3399
3403
  this._lines.push(line);
@@ -4428,13 +4432,13 @@ var getObjectDelta = (a, b) => {
4428
4432
  };
4429
4433
 
4430
4434
  // src/dive.ts
4431
- var import_MathUtils2 = require("three/src/math/MathUtils");
4435
+ var import_three28 = require("three");
4432
4436
  init_Info();
4433
4437
 
4434
4438
  // package.json
4435
4439
  var package_default = {
4436
4440
  name: "@shopware-ag/dive",
4437
- version: "1.17.2",
4441
+ version: "1.18.1",
4438
4442
  description: "Shopware Spatial Framework",
4439
4443
  type: "module",
4440
4444
  main: "./build/dive.cjs",
@@ -4594,7 +4598,7 @@ var DIVE = class _DIVE {
4594
4598
  position: { x: 0, y: 2, z: 2 },
4595
4599
  target: { x: 0, y: 0.5, z: 0 }
4596
4600
  });
4597
- const lightid = (0, import_MathUtils2.generateUUID)();
4601
+ const lightid = import_three28.MathUtils.generateUUID();
4598
4602
  dive.Communication.PerformAction("ADD_OBJECT", {
4599
4603
  entityType: "light",
4600
4604
  type: "scene",
@@ -4605,7 +4609,7 @@ var DIVE = class _DIVE {
4605
4609
  intensity: 1,
4606
4610
  color: 16777215
4607
4611
  });
4608
- const modelid = (0, import_MathUtils2.generateUUID)();
4612
+ const modelid = import_three28.MathUtils.generateUUID();
4609
4613
  dive.Communication.Subscribe("MODEL_LOADED", (data) => {
4610
4614
  if (data.id !== modelid) return;
4611
4615
  const transform = dive.Communication.PerformAction(