@shopware-ag/dive 1.17.0 → 1.17.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.
package/build/dive.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Texture, Object3D, Vector3, Color, Mesh, ColorRepresentation, Intersection, Vector2, Raycaster } from 'three';
1
+ import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Texture, Object3D, Vector3, Color, Mesh, ColorRepresentation, Intersection, Vector2, Raycaster, Euler } from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
3
3
  import { Tween } from '@tweenjs/tween.js';
4
4
  import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
@@ -802,6 +802,41 @@ declare abstract class DIVEBaseTool {
802
802
  private pointerWasDragged;
803
803
  }
804
804
 
805
+ declare class DIVEGizmoPlane extends Object3D {
806
+ private _meshX;
807
+ get XPlane(): Mesh;
808
+ private _meshY;
809
+ get YPlane(): Mesh;
810
+ private _meshZ;
811
+ get ZPlane(): Mesh;
812
+ constructor();
813
+ assemble(mode: DIVEGizmoMode, axis: DIVEGizmoAxis): void;
814
+ }
815
+
816
+ type DIVEGizmoMode = 'translate' | 'rotate' | 'scale';
817
+ type DIVEGizmoAxis = 'x' | 'y' | 'z';
818
+ declare class DIVEGizmo extends Object3D {
819
+ private _mode;
820
+ get mode(): DIVEGizmoMode;
821
+ set mode(value: DIVEGizmoMode);
822
+ set debug(value: boolean);
823
+ private _gizmoNode;
824
+ get gizmoNode(): Object3D;
825
+ private _translateGizmo;
826
+ private _rotateGizmo;
827
+ private _scaleGizmo;
828
+ private _gizmoPlane;
829
+ get gizmoPlane(): DIVEGizmoPlane;
830
+ private _object;
831
+ get object(): (Object3D & DIVESelectable) | null;
832
+ constructor(controller: DIVEOrbitControls);
833
+ attach(object: Object3D & DIVESelectable): this;
834
+ detach(): this;
835
+ onHover(mode: DIVEGizmoMode, axis: DIVEGizmoAxis, value: boolean): void;
836
+ onChange(position?: Vector3, rotation?: Euler, scale?: Vector3): void;
837
+ private assemble;
838
+ }
839
+
805
840
  /**
806
841
  * A Tool to select and move objects in the scene.
807
842
  *
@@ -811,11 +846,12 @@ declare abstract class DIVEBaseTool {
811
846
  */
812
847
  declare class DIVETransformTool extends DIVEBaseTool {
813
848
  readonly isTransformTool: boolean;
814
- protected _gizmo: TransformControls;
849
+ protected _gizmo: TransformControls | DIVEGizmo;
815
850
  constructor(scene: DIVEScene, controller: DIVEOrbitControls);
816
851
  Activate(): void;
817
852
  SetGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void;
818
853
  SetGizmoVisibility(active: boolean): void;
854
+ private initGizmo;
819
855
  }
820
856
 
821
857
  /**
package/build/dive.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Texture, Object3D, Vector3, Color, Mesh, ColorRepresentation, Intersection, Vector2, Raycaster } from 'three';
1
+ import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Texture, Object3D, Vector3, Color, Mesh, ColorRepresentation, Intersection, Vector2, Raycaster, Euler } from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
3
3
  import { Tween } from '@tweenjs/tween.js';
4
4
  import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
@@ -802,6 +802,41 @@ declare abstract class DIVEBaseTool {
802
802
  private pointerWasDragged;
803
803
  }
804
804
 
805
+ declare class DIVEGizmoPlane extends Object3D {
806
+ private _meshX;
807
+ get XPlane(): Mesh;
808
+ private _meshY;
809
+ get YPlane(): Mesh;
810
+ private _meshZ;
811
+ get ZPlane(): Mesh;
812
+ constructor();
813
+ assemble(mode: DIVEGizmoMode, axis: DIVEGizmoAxis): void;
814
+ }
815
+
816
+ type DIVEGizmoMode = 'translate' | 'rotate' | 'scale';
817
+ type DIVEGizmoAxis = 'x' | 'y' | 'z';
818
+ declare class DIVEGizmo extends Object3D {
819
+ private _mode;
820
+ get mode(): DIVEGizmoMode;
821
+ set mode(value: DIVEGizmoMode);
822
+ set debug(value: boolean);
823
+ private _gizmoNode;
824
+ get gizmoNode(): Object3D;
825
+ private _translateGizmo;
826
+ private _rotateGizmo;
827
+ private _scaleGizmo;
828
+ private _gizmoPlane;
829
+ get gizmoPlane(): DIVEGizmoPlane;
830
+ private _object;
831
+ get object(): (Object3D & DIVESelectable) | null;
832
+ constructor(controller: DIVEOrbitControls);
833
+ attach(object: Object3D & DIVESelectable): this;
834
+ detach(): this;
835
+ onHover(mode: DIVEGizmoMode, axis: DIVEGizmoAxis, value: boolean): void;
836
+ onChange(position?: Vector3, rotation?: Euler, scale?: Vector3): void;
837
+ private assemble;
838
+ }
839
+
805
840
  /**
806
841
  * A Tool to select and move objects in the scene.
807
842
  *
@@ -811,11 +846,12 @@ declare abstract class DIVEBaseTool {
811
846
  */
812
847
  declare class DIVETransformTool extends DIVEBaseTool {
813
848
  readonly isTransformTool: boolean;
814
- protected _gizmo: TransformControls;
849
+ protected _gizmo: TransformControls | DIVEGizmo;
815
850
  constructor(scene: DIVEScene, controller: DIVEOrbitControls);
816
851
  Activate(): void;
817
852
  SetGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void;
818
853
  SetGizmoVisibility(active: boolean): void;
854
+ private initGizmo;
819
855
  }
820
856
 
821
857
  /**
package/build/dive.js CHANGED
@@ -330,40 +330,7 @@ var init_TransformTool = __esm({
330
330
  super(scene, controller);
331
331
  this.isTransformTool = true;
332
332
  this.name = "DIVETransformTool";
333
- this._gizmo = new TransformControls(
334
- this._controller.object,
335
- this._controller.domElement
336
- );
337
- this._gizmo.mode = "translate";
338
- this._gizmo.addEventListener("mouseDown", () => {
339
- controller.enabled = false;
340
- if (!implementsInterface(
341
- this._gizmo.object,
342
- "isMovable"
343
- ))
344
- return;
345
- if (!this._gizmo.object.onMoveStart) return;
346
- this._gizmo.object.onMoveStart();
347
- });
348
- this._gizmo.addEventListener("objectChange", () => {
349
- if (!implementsInterface(
350
- this._gizmo.object,
351
- "isMovable"
352
- ))
353
- return;
354
- if (!this._gizmo.object.onMove) return;
355
- this._gizmo.object.onMove();
356
- });
357
- this._gizmo.addEventListener("mouseUp", () => {
358
- controller.enabled = true;
359
- if (!implementsInterface(
360
- this._gizmo.object,
361
- "isMovable"
362
- ))
363
- return;
364
- if (!this._gizmo.object.onMoveEnd) return;
365
- this._gizmo.object.onMoveEnd();
366
- });
333
+ this._gizmo = this.initGizmo();
367
334
  this._scene.add(this._gizmo);
368
335
  }
369
336
  Activate() {
@@ -375,19 +342,58 @@ var init_TransformTool = __esm({
375
342
  const contains = this._scene.children.includes(this._gizmo);
376
343
  if (active && !contains) {
377
344
  this._scene.add(this._gizmo);
345
+ if ("isTransformControls" in this._gizmo) {
346
+ this._gizmo.getRaycaster().layers.enableAll();
347
+ }
378
348
  } else if (!active && contains) {
379
349
  this._scene.remove(this._gizmo);
350
+ if ("isTransformControls" in this._gizmo) {
351
+ this._gizmo.getRaycaster().layers.disableAll();
352
+ }
380
353
  }
381
354
  }
355
+ // only used for optimizing pointer events with DIVEGizmo
382
356
  // public onPointerDown(e: PointerEvent): void {
383
357
  // super.onPointerDown(e);
384
- // // if (this._hovered) {
385
- // // this._dragRaycastOnObjects = this._gizmo.gizmoPlane.children;
386
- // // }
358
+ // if (this._hovered) {
359
+ // this._dragRaycastOnObjects = (
360
+ // this._gizmo as DIVEGizmo
361
+ // ).gizmoPlane?.children;
362
+ // }
387
363
  // }
364
+ // only used for optimizing pointer events with DIVEGizmo
388
365
  // protected raycast(): Intersection[] {
389
- // return super.raycast(this._gizmo.gizmoNode.children);
366
+ // return super.raycast((this._gizmo as DIVEGizmo).gizmoNode.children);
390
367
  // }
368
+ initGizmo() {
369
+ const g = new TransformControls(
370
+ // this._controller,
371
+ this._controller.object,
372
+ this._controller.domElement
373
+ );
374
+ g.mode = "translate";
375
+ g.addEventListener("mouseDown", () => {
376
+ this._controller.enabled = false;
377
+ if (!implementsInterface(g.object, "isMovable"))
378
+ return;
379
+ if (!g.object.onMoveStart) return;
380
+ g.object.onMoveStart();
381
+ });
382
+ g.addEventListener("objectChange", () => {
383
+ if (!implementsInterface(g.object, "isMovable"))
384
+ return;
385
+ if (!g.object.onMove) return;
386
+ g.object.onMove();
387
+ });
388
+ g.addEventListener("mouseUp", () => {
389
+ this._controller.enabled = true;
390
+ if (!implementsInterface(g.object, "isMovable"))
391
+ return;
392
+ if (!g.object.onMoveEnd) return;
393
+ g.object.onMoveEnd();
394
+ });
395
+ return g;
396
+ }
391
397
  };
392
398
  }
393
399
  });
@@ -2553,6 +2559,22 @@ var _DIVECommunication = class _DIVECommunication {
2553
2559
  deleteObject(payload) {
2554
2560
  const deletedObject = this.registered.get(payload.id);
2555
2561
  if (!deletedObject) return false;
2562
+ if (deletedObject.parentId) {
2563
+ this.setParent({
2564
+ object: { id: deletedObject.id },
2565
+ parent: null
2566
+ });
2567
+ }
2568
+ if (deletedObject.entityType === "group") {
2569
+ this.registered.forEach((object) => {
2570
+ if (object.parentId === deletedObject.id) {
2571
+ this.updateObject({
2572
+ id: object.id,
2573
+ parentId: null
2574
+ });
2575
+ }
2576
+ });
2577
+ }
2556
2578
  Object.assign(payload, deletedObject);
2557
2579
  this.registered.delete(payload.id);
2558
2580
  Array.from(this.registered.values()).forEach((object) => {
@@ -2715,6 +2737,10 @@ var _DIVECommunication = class _DIVECommunication {
2715
2737
  if (!sceneObject) return false;
2716
2738
  if (payload.parent === null) {
2717
2739
  this.scene.Root.attach(sceneObject);
2740
+ this.updateObject({
2741
+ id: object.id,
2742
+ parentId: null
2743
+ });
2718
2744
  return true;
2719
2745
  }
2720
2746
  if (payload.object.id === payload.parent.id) {
@@ -2723,14 +2749,26 @@ var _DIVECommunication = class _DIVECommunication {
2723
2749
  const parent = this.registered.get(payload.parent.id);
2724
2750
  if (!parent) {
2725
2751
  this.scene.Root.attach(sceneObject);
2752
+ this.updateObject({
2753
+ id: object.id,
2754
+ parentId: null
2755
+ });
2726
2756
  return true;
2727
2757
  }
2728
2758
  const parentObject = this.scene.GetSceneObject(parent);
2729
2759
  if (!parentObject) {
2730
2760
  this.scene.Root.attach(sceneObject);
2761
+ this.updateObject({
2762
+ id: object.id,
2763
+ parentId: null
2764
+ });
2731
2765
  return true;
2732
2766
  }
2733
2767
  parentObject.attach(sceneObject);
2768
+ this.updateObject({
2769
+ id: object.id,
2770
+ parentId: parent.id
2771
+ });
2734
2772
  return true;
2735
2773
  }
2736
2774
  exportScene(payload) {
@@ -3005,12 +3043,15 @@ var DIVEModel = class extends DIVENode {
3005
3043
  }
3006
3044
  }
3007
3045
  PlaceOnFloor() {
3008
- var _a;
3046
+ var _a, _b, _c, _d, _e;
3009
3047
  const worldPos = this.getWorldPosition(this._positionWorldBuffer);
3010
3048
  const oldWorldPos = worldPos.clone();
3011
- worldPos.y = (this._boundingBox.max.y - this._boundingBox.min.y) / 2;
3049
+ (_b = (_a = this._mesh) == null ? void 0 : _a.geometry) == null ? void 0 : _b.computeBoundingBox();
3050
+ const meshBB = (_d = (_c = this._mesh) == null ? void 0 : _c.geometry) == null ? void 0 : _d.boundingBox;
3051
+ if (!meshBB || !this._mesh) return;
3052
+ worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
3012
3053
  if (worldPos.y === oldWorldPos.y) return;
3013
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3054
+ (_e = DIVECommunication.get(this.userData.id)) == null ? void 0 : _e.PerformAction(
3014
3055
  "UPDATE_OBJECT",
3015
3056
  {
3016
3057
  id: this.userData.id,
@@ -3154,12 +3195,15 @@ var DIVEPrimitive = class extends DIVENode {
3154
3195
  if (this._mesh) this._mesh.material = primitiveMaterial;
3155
3196
  }
3156
3197
  PlaceOnFloor() {
3157
- var _a;
3198
+ var _a, _b, _c, _d, _e;
3158
3199
  const worldPos = this.getWorldPosition(this._positionWorldBuffer);
3159
3200
  const oldWorldPos = worldPos.clone();
3160
- worldPos.y = (this._boundingBox.max.y - this._boundingBox.min.y) / 2;
3201
+ (_b = (_a = this._mesh) == null ? void 0 : _a.geometry) == null ? void 0 : _b.computeBoundingBox();
3202
+ const meshBB = (_d = (_c = this._mesh) == null ? void 0 : _c.geometry) == null ? void 0 : _d.boundingBox;
3203
+ if (!meshBB || !this._mesh) return;
3204
+ worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
3161
3205
  if (worldPos.y === oldWorldPos.y) return;
3162
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3206
+ (_e = DIVECommunication.get(this.userData.id)) == null ? void 0 : _e.PerformAction(
3163
3207
  "UPDATE_OBJECT",
3164
3208
  {
3165
3209
  id: this.userData.id,
@@ -4421,7 +4465,7 @@ import { generateUUID as generateUUID2 } from "three/src/math/MathUtils";
4421
4465
  // package.json
4422
4466
  var package_default = {
4423
4467
  name: "@shopware-ag/dive",
4424
- version: "1.17.0",
4468
+ version: "1.17.2",
4425
4469
  description: "Shopware Spatial Framework",
4426
4470
  type: "module",
4427
4471
  main: "./build/dive.cjs",
@@ -4465,6 +4509,7 @@ var package_default = {
4465
4509
  globals: "^15.0.0",
4466
4510
  jest: "^29.7.0",
4467
4511
  "jest-environment-jsdom": "^29.7.0",
4512
+ "jest-junit": "^16.0.0",
4468
4513
  jsdom: "^24.0.0",
4469
4514
  prettier: "^3.3.3",
4470
4515
  "prettier-plugin-multiline-arrays": "^3.0.6",