@shopware-ag/dive 1.17.1 → 1.18.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 (48) hide show
  1. package/README.md +56 -22
  2. package/build/dive.cjs +56 -45
  3. package/build/dive.cjs.map +1 -1
  4. package/build/dive.d.cts +41 -6
  5. package/build/dive.d.ts +41 -6
  6. package/build/dive.js +54 -43
  7. package/build/dive.js.map +1 -1
  8. package/package.json +2 -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/gizmo/Gizmo.ts +6 -0
  19. package/src/gizmo/handles/AxisHandle.ts +14 -8
  20. package/src/gizmo/handles/RadialHandle.ts +12 -6
  21. package/src/gizmo/handles/ScaleHandle.ts +14 -8
  22. package/src/gizmo/rotate/RotateGizmo.ts +6 -0
  23. package/src/gizmo/scale/ScaleGizmo.ts +6 -0
  24. package/src/gizmo/translate/TranslateGizmo.ts +6 -0
  25. package/src/group/Group.ts +6 -1
  26. package/src/group/__test__/Group.test.ts +6 -3
  27. package/src/io/gltf/__test__/GLTFIO.test.ts +0 -77
  28. package/src/light/PointLight.ts +1 -1
  29. package/src/light/__test__/AmbientLight.test.ts +0 -24
  30. package/src/light/__test__/PointLight.test.ts +0 -61
  31. package/src/light/__test__/SceneLight.test.ts +0 -89
  32. package/src/loadingmanager/LoadingManager.ts +2 -1
  33. package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -30
  34. package/src/math/degToRad/__test__/degToRad.test.ts +0 -7
  35. package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -7
  36. package/src/model/Model.ts +1 -1
  37. package/src/model/__test__/Model.test.ts +5 -155
  38. package/src/node/__test__/Node.test.ts +0 -149
  39. package/src/primitive/__test__/Primitive.test.ts +6 -199
  40. package/src/primitive/floor/__test__/Floor.test.ts +0 -3
  41. package/src/renderer/__test__/Renderer.test.ts +16 -46
  42. package/src/scene/__test__/Scene.test.ts +6 -16
  43. package/src/scene/root/Root.ts +4 -4
  44. package/src/scene/root/__test__/Root.test.ts +6 -188
  45. package/src/toolbox/__test__/BaseTool.test.ts +34 -38
  46. package/src/toolbox/select/__test__/SelectTool.test.ts +21 -89
  47. package/src/toolbox/transform/TransformTool.ts +61 -53
  48. package/src/toolbox/transform/__test__/TransformTool.test.ts +14 -80
package/README.md CHANGED
@@ -47,10 +47,6 @@ npm install @shopware-ag/dive
47
47
  yarn add @shopware-ag/dive
48
48
  ```
49
49
 
50
- # Formatter
51
-
52
- DIVE uses Prettier as a preconfigured formatter.
53
-
54
50
  #### Setup in Shopware
55
51
 
56
52
  Don't forget to include DIVE in your webpack.config.js:
@@ -60,24 +56,33 @@ const path = require('path');
60
56
 
61
57
  module.exports = () => {
62
58
  return {
63
- ...
59
+ // Other configurations...
64
60
  resolve: {
65
- extensions: ['.ts', '.cjs', '.js'],
61
+ extensions: [
62
+ '.ts',
63
+ '.cjs',
64
+ '.js',
65
+ ],
66
66
  alias: {
67
67
  three: path.resolve(__dirname, 'path/to/node_modules/three'),
68
- "@shopware-ag/dive": path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive'),
69
- }
68
+ '@shopware-ag/dive': path.resolve(
69
+ __dirname,
70
+ 'path/to/node_modules/@shopware-ag/dive',
71
+ ),
72
+ },
70
73
  },
71
- ...
72
74
  module: {
73
75
  rules: [
74
- ...
76
+ // Other rules...
75
77
  {
76
78
  test: /\.(js|ts)$/,
77
79
  loader: 'swc-loader',
78
80
  include: [
79
81
  path.resolve(__dirname, 'path/to/node_modules/three'),
80
- path.resolve(__dirname, 'path/to/node_modules/@shopware-ag/dive')
82
+ path.resolve(
83
+ __dirname,
84
+ 'path/to/node_modules/@shopware-ag/dive',
85
+ ),
81
86
  ],
82
87
  options: {
83
88
  jsc: {
@@ -88,18 +93,20 @@ module.exports = () => {
88
93
  },
89
94
  },
90
95
  },
91
- ...
96
+ // Other rules...
92
97
  ],
93
- }
98
+ },
94
99
  };
95
100
  };
96
101
  ```
97
102
 
98
- # Quick View
103
+ # Usage
104
+
105
+ ## Quick View
99
106
 
100
107
  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.
108
+ possible. Simply call the static `QuickView()` method, with your data URI as a
109
+ parameter, to create an instance of DIVE with your asset to use in further code.
103
110
 
104
111
  ```ts
105
112
  import { DIVE } from '@shopware-ag/dive';
@@ -110,15 +117,30 @@ const myCanvasWrapper = document.createElement('div');
110
117
  myCanvasWrapper.appendChild(dive.Canvas);
111
118
  ```
112
119
 
113
- # Getting started
120
+ ### Example with Error Handling:
121
+
122
+ ```ts
123
+ import { DIVE } from '@shopware-ag/dive';
124
+
125
+ try {
126
+ const dive = DIVE.QuickView('your/asset/uri.glb'); // <-- call QuickView()
127
+
128
+ const myCanvasWrapper = document.createElement('div');
129
+ myCanvasWrapper.appendChild(dive.Canvas);
130
+ } catch (error) {
131
+ console.error('Failed to load asset:', error);
132
+ }
133
+ ```
134
+
135
+ ## Getting started
114
136
 
115
- Import:
137
+ ### Import:
116
138
 
117
139
  ```ts
118
140
  import { DIVE } from '@shopware-ag/dive'; // <-- import DIVE
119
141
  ```
120
142
 
121
- Instantiate:
143
+ ### Instantiate:
122
144
 
123
145
  ```ts
124
146
  import { DIVE } from '@shopware-ag/dive';
@@ -127,7 +149,7 @@ const dive = new DIVE(); // <-- instantiate DIVE
127
149
  ```
128
150
 
129
151
  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
152
+ target. After instantiating, you can use the supplied canvas within your frontend
131
153
  code to attach it to your DOM.
132
154
 
133
155
  ```ts
@@ -155,7 +177,7 @@ com.PerformAction('SET_CAMERA_TRANSFORM', {
155
177
  });
156
178
  ```
157
179
 
158
- # Actions
180
+ ## Actions
159
181
 
160
182
  Actions symbolize the communication between frontend and 3D space. All actions
161
183
  can be performed anywhere, no matter if you are in frontend or 3D.
@@ -206,7 +228,7 @@ com.PerformAction('SET_CAMERA_TRANSFORM', {
206
228
  unsubscribe(); // <-- execute unsubscribe callback when done
207
229
  ```
208
230
 
209
- # Actions (List)
231
+ ### Actions List
210
232
 
211
233
  In the following you find a list of all available actions to perform on
212
234
  DIVECommunication class via
@@ -434,3 +456,15 @@ DIVECommunication class via
434
456
  </td>
435
457
  </tr>
436
458
  </table>
459
+
460
+ # Unit Tests
461
+
462
+ 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.
463
+
464
+ 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.
465
+
466
+ 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.
467
+
468
+ # Formatting
469
+
470
+ DIVE uses Prettier as a preconfigured formatter.
package/build/dive.cjs CHANGED
@@ -337,40 +337,7 @@ var init_TransformTool = __esm({
337
337
  super(scene, controller);
338
338
  this.isTransformTool = true;
339
339
  this.name = "DIVETransformTool";
340
- this._gizmo = new import_TransformControls.TransformControls(
341
- this._controller.object,
342
- this._controller.domElement
343
- );
344
- this._gizmo.mode = "translate";
345
- this._gizmo.addEventListener("mouseDown", () => {
346
- controller.enabled = false;
347
- if (!implementsInterface(
348
- this._gizmo.object,
349
- "isMovable"
350
- ))
351
- return;
352
- if (!this._gizmo.object.onMoveStart) return;
353
- this._gizmo.object.onMoveStart();
354
- });
355
- this._gizmo.addEventListener("objectChange", () => {
356
- if (!implementsInterface(
357
- this._gizmo.object,
358
- "isMovable"
359
- ))
360
- return;
361
- if (!this._gizmo.object.onMove) return;
362
- this._gizmo.object.onMove();
363
- });
364
- this._gizmo.addEventListener("mouseUp", () => {
365
- controller.enabled = true;
366
- if (!implementsInterface(
367
- this._gizmo.object,
368
- "isMovable"
369
- ))
370
- return;
371
- if (!this._gizmo.object.onMoveEnd) return;
372
- this._gizmo.object.onMoveEnd();
373
- });
340
+ this._gizmo = this.initGizmo();
374
341
  this._scene.add(this._gizmo);
375
342
  }
376
343
  Activate() {
@@ -382,19 +349,58 @@ var init_TransformTool = __esm({
382
349
  const contains = this._scene.children.includes(this._gizmo);
383
350
  if (active && !contains) {
384
351
  this._scene.add(this._gizmo);
352
+ if ("isTransformControls" in this._gizmo) {
353
+ this._gizmo.getRaycaster().layers.enableAll();
354
+ }
385
355
  } else if (!active && contains) {
386
356
  this._scene.remove(this._gizmo);
357
+ if ("isTransformControls" in this._gizmo) {
358
+ this._gizmo.getRaycaster().layers.disableAll();
359
+ }
387
360
  }
388
361
  }
362
+ // only used for optimizing pointer events with DIVEGizmo
389
363
  // public onPointerDown(e: PointerEvent): void {
390
364
  // super.onPointerDown(e);
391
- // // if (this._hovered) {
392
- // // this._dragRaycastOnObjects = this._gizmo.gizmoPlane.children;
393
- // // }
365
+ // if (this._hovered) {
366
+ // this._dragRaycastOnObjects = (
367
+ // this._gizmo as DIVEGizmo
368
+ // ).gizmoPlane?.children;
369
+ // }
394
370
  // }
371
+ // only used for optimizing pointer events with DIVEGizmo
395
372
  // protected raycast(): Intersection[] {
396
- // return super.raycast(this._gizmo.gizmoNode.children);
373
+ // return super.raycast((this._gizmo as DIVEGizmo).gizmoNode.children);
397
374
  // }
375
+ initGizmo() {
376
+ const g = new import_TransformControls.TransformControls(
377
+ // this._controller,
378
+ this._controller.object,
379
+ this._controller.domElement
380
+ );
381
+ g.mode = "translate";
382
+ g.addEventListener("mouseDown", () => {
383
+ this._controller.enabled = false;
384
+ if (!implementsInterface(g.object, "isMovable"))
385
+ return;
386
+ if (!g.object.onMoveStart) return;
387
+ g.object.onMoveStart();
388
+ });
389
+ g.addEventListener("objectChange", () => {
390
+ if (!implementsInterface(g.object, "isMovable"))
391
+ return;
392
+ if (!g.object.onMove) return;
393
+ g.object.onMove();
394
+ });
395
+ g.addEventListener("mouseUp", () => {
396
+ this._controller.enabled = true;
397
+ if (!implementsInterface(g.object, "isMovable"))
398
+ return;
399
+ if (!g.object.onMoveEnd) return;
400
+ g.object.onMoveEnd();
401
+ });
402
+ return g;
403
+ }
398
404
  };
399
405
  }
400
406
  });
@@ -3086,13 +3092,14 @@ var DIVEModel = class extends DIVENode {
3086
3092
  };
3087
3093
 
3088
3094
  // src/loadingmanager/LoadingManager.ts
3089
- 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");
3090
3097
  var DIVELoadingManager = class {
3091
3098
  // ... maybe extend with other loaders later
3092
3099
  constructor() {
3093
3100
  this.progress = /* @__PURE__ */ new Map();
3094
- this.gltfloader = new import_Addons.GLTFLoader();
3095
- this.dracoloader = new import_Addons.DRACOLoader();
3101
+ this.gltfloader = new import_GLTFLoader2.GLTFLoader();
3102
+ this.dracoloader = new import_DRACOLoader.DRACOLoader();
3096
3103
  this.dracoloader.setDecoderPath(
3097
3104
  "https://www.gstatic.com/draco/v1/decoders/"
3098
3105
  );
@@ -3388,6 +3395,9 @@ var DIVEGroup = class extends DIVENode {
3388
3395
  this._lines[index].visible = visible;
3389
3396
  }
3390
3397
  attach(object) {
3398
+ if (this._members.includes(object)) {
3399
+ return this;
3400
+ }
3391
3401
  const line = this.createLine();
3392
3402
  this.add(line);
3393
3403
  this._lines.push(line);
@@ -4422,13 +4432,13 @@ var getObjectDelta = (a, b) => {
4422
4432
  };
4423
4433
 
4424
4434
  // src/dive.ts
4425
- var import_MathUtils2 = require("three/src/math/MathUtils");
4435
+ var import_three28 = require("three");
4426
4436
  init_Info();
4427
4437
 
4428
4438
  // package.json
4429
4439
  var package_default = {
4430
4440
  name: "@shopware-ag/dive",
4431
- version: "1.17.1",
4441
+ version: "1.18.0",
4432
4442
  description: "Shopware Spatial Framework",
4433
4443
  type: "module",
4434
4444
  main: "./build/dive.cjs",
@@ -4472,6 +4482,7 @@ var package_default = {
4472
4482
  globals: "^15.0.0",
4473
4483
  jest: "^29.7.0",
4474
4484
  "jest-environment-jsdom": "^29.7.0",
4485
+ "jest-junit": "^16.0.0",
4475
4486
  jsdom: "^24.0.0",
4476
4487
  prettier: "^3.3.3",
4477
4488
  "prettier-plugin-multiline-arrays": "^3.0.6",
@@ -4587,7 +4598,7 @@ var DIVE = class _DIVE {
4587
4598
  position: { x: 0, y: 2, z: 2 },
4588
4599
  target: { x: 0, y: 0.5, z: 0 }
4589
4600
  });
4590
- const lightid = (0, import_MathUtils2.generateUUID)();
4601
+ const lightid = import_three28.MathUtils.generateUUID();
4591
4602
  dive.Communication.PerformAction("ADD_OBJECT", {
4592
4603
  entityType: "light",
4593
4604
  type: "scene",
@@ -4598,7 +4609,7 @@ var DIVE = class _DIVE {
4598
4609
  intensity: 1,
4599
4610
  color: 16777215
4600
4611
  });
4601
- const modelid = (0, import_MathUtils2.generateUUID)();
4612
+ const modelid = import_three28.MathUtils.generateUUID();
4602
4613
  dive.Communication.Subscribe("MODEL_LOADED", (data) => {
4603
4614
  if (data.id !== modelid) return;
4604
4615
  const transform = dive.Communication.PerformAction(