@shopware-ag/dive 1.15.2 → 1.15.4

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.cjs CHANGED
@@ -80,45 +80,27 @@ var init_VisibilityLayerMask = __esm({
80
80
  }
81
81
  });
82
82
 
83
- // src/interface/Draggable.ts
84
- var isDraggable, findDraggableInterface;
85
- var init_Draggable = __esm({
86
- "src/interface/Draggable.ts"() {
83
+ // src/helper/isInterface/implementsInterface.ts
84
+ function implementsInterface(object, discriminator) {
85
+ if (!object) return false;
86
+ return discriminator in object;
87
+ }
88
+ var init_implementsInterface = __esm({
89
+ "src/helper/isInterface/implementsInterface.ts"() {
87
90
  "use strict";
88
- isDraggable = (object) => {
89
- return "isDraggable" in object;
90
- };
91
- findDraggableInterface = (child) => {
92
- if (child === void 0) return void 0;
93
- if (child.parent === null) {
94
- return void 0;
95
- }
96
- if (isDraggable(child)) {
97
- return child;
98
- }
99
- return findDraggableInterface(child.parent);
100
- };
101
91
  }
102
92
  });
103
93
 
104
- // src/interface/Hoverable.ts
105
- var isHoverable, findHoverableInterface;
106
- var init_Hoverable = __esm({
107
- "src/interface/Hoverable.ts"() {
94
+ // src/helper/findInterface/findInterface.ts
95
+ function findInterface(object, discriminator) {
96
+ if (!object) return void 0;
97
+ if (implementsInterface(object, discriminator)) return object;
98
+ return findInterface(object.parent, discriminator);
99
+ }
100
+ var init_findInterface = __esm({
101
+ "src/helper/findInterface/findInterface.ts"() {
108
102
  "use strict";
109
- isHoverable = (object) => {
110
- return "isHoverable" in object;
111
- };
112
- findHoverableInterface = (child) => {
113
- if (child === void 0) return void 0;
114
- if (child.parent === null) {
115
- return void 0;
116
- }
117
- if (isHoverable(child)) {
118
- return child;
119
- }
120
- return findHoverableInterface(child.parent);
121
- };
103
+ init_implementsInterface();
122
104
  }
123
105
  });
124
106
 
@@ -129,8 +111,7 @@ var init_BaseTool = __esm({
129
111
  "use strict";
130
112
  import_three3 = require("three");
131
113
  init_VisibilityLayerMask();
132
- init_Draggable();
133
- init_Hoverable();
114
+ init_findInterface();
134
115
  DIVEBaseTool = class {
135
116
  constructor(scene, controller) {
136
117
  this.POINTER_DRAG_THRESHOLD = 1e-3;
@@ -177,7 +158,7 @@ var init_BaseTool = __esm({
177
158
  break;
178
159
  }
179
160
  this._lastPointerDown.copy(this._pointer);
180
- this._draggable = findDraggableInterface((_a = this._intersects[0]) == null ? void 0 : _a.object) || null;
161
+ this._draggable = findInterface((_a = this._intersects[0]) == null ? void 0 : _a.object, "isDraggable") || null;
181
162
  }
182
163
  onDragStart(e) {
183
164
  if (!this._draggable) return;
@@ -206,7 +187,7 @@ var init_BaseTool = __esm({
206
187
  this._pointer.y = -(e.offsetY / this._canvas.clientHeight) * 2 + 1;
207
188
  this._raycaster.setFromCamera(this._pointer, this._controller.object);
208
189
  this._intersects = this.raycast(this._scene.children);
209
- const hoverable = findHoverableInterface((_a = this._intersects[0]) == null ? void 0 : _a.object);
190
+ const hoverable = findInterface((_a = this._intersects[0]) == null ? void 0 : _a.object, "isHoverable");
210
191
  if (this._intersects[0] && hoverable) {
211
192
  if (!this._hovered) {
212
193
  if (hoverable.onPointerEnter) hoverable.onPointerEnter(this._intersects[0]);
@@ -318,6 +299,7 @@ var init_TransformTool = __esm({
318
299
  "use strict";
319
300
  init_BaseTool();
320
301
  import_Addons = require("three/examples/jsm/Addons");
302
+ init_implementsInterface();
321
303
  DIVETransformTool = class extends DIVEBaseTool {
322
304
  constructor(scene, controller) {
323
305
  super(scene, controller);
@@ -327,16 +309,21 @@ var init_TransformTool = __esm({
327
309
  this._gizmo.mode = "translate";
328
310
  this._gizmo.addEventListener("mouseDown", () => {
329
311
  controller.enabled = false;
330
- });
331
- this._gizmo.addEventListener("mouseUp", () => {
332
- controller.enabled = true;
312
+ if (!implementsInterface(this._gizmo.object, "isMovable")) return;
313
+ if (!this._gizmo.object.onMoveStart) return;
314
+ this._gizmo.object.onMoveStart();
333
315
  });
334
316
  this._gizmo.addEventListener("objectChange", () => {
335
- if (!this._gizmo.object) return;
336
- if (!("isMoveable" in this._gizmo.object)) return;
337
- if (!("onMove" in this._gizmo.object)) return;
317
+ if (!implementsInterface(this._gizmo.object, "isMovable")) return;
318
+ if (!this._gizmo.object.onMove) return;
338
319
  this._gizmo.object.onMove();
339
320
  });
321
+ this._gizmo.addEventListener("mouseUp", () => {
322
+ controller.enabled = true;
323
+ if (!implementsInterface(this._gizmo.object, "isMovable")) return;
324
+ if (!this._gizmo.object.onMoveEnd) return;
325
+ this._gizmo.object.onMoveEnd();
326
+ });
340
327
  scene.add(this._gizmo);
341
328
  }
342
329
  Activate() {
@@ -365,26 +352,6 @@ var init_TransformTool = __esm({
365
352
  }
366
353
  });
367
354
 
368
- // src/interface/Selectable.ts
369
- function isSelectable(object) {
370
- return "isSelectable" in object;
371
- }
372
- function findSelectableInterface(child) {
373
- if (child === void 0) return void 0;
374
- if (child.parent === null) {
375
- return void 0;
376
- }
377
- if (isSelectable(child)) {
378
- return child;
379
- }
380
- return findSelectableInterface(child.parent);
381
- }
382
- var init_Selectable = __esm({
383
- "src/interface/Selectable.ts"() {
384
- "use strict";
385
- }
386
- });
387
-
388
355
  // src/toolbox/select/SelectTool.ts
389
356
  var SelectTool_exports = {};
390
357
  __export(SelectTool_exports, {
@@ -396,7 +363,7 @@ var init_SelectTool = __esm({
396
363
  "src/toolbox/select/SelectTool.ts"() {
397
364
  "use strict";
398
365
  init_TransformTool();
399
- init_Selectable();
366
+ init_findInterface();
400
367
  isSelectTool = (tool) => {
401
368
  return tool.isSelectTool !== void 0;
402
369
  };
@@ -417,7 +384,7 @@ var init_SelectTool = __esm({
417
384
  this.DetachGizmo();
418
385
  }
419
386
  AttachGizmo(selectable) {
420
- if ("isMoveable" in selectable) {
387
+ if ("isMovable" in selectable) {
421
388
  const movable = selectable;
422
389
  this._gizmo.attach(movable);
423
390
  this.SetGizmoVisibility(movable.visible);
@@ -429,7 +396,7 @@ var init_SelectTool = __esm({
429
396
  onClick(e) {
430
397
  super.onClick(e);
431
398
  const first = this._raycaster.intersectObjects(this._scene.Root.children, true).filter((intersect) => intersect.object.visible)[0];
432
- const selectable = findSelectableInterface(first == null ? void 0 : first.object);
399
+ const selectable = findInterface(first == null ? void 0 : first.object, "isSelectable");
433
400
  if (!first || !selectable) {
434
401
  if (this._gizmo.object) {
435
402
  this.Deselect(this._gizmo.object);
@@ -1088,7 +1055,7 @@ var DIVEPointLight = class extends import_three5.Object3D {
1088
1055
  super();
1089
1056
  this.isDIVELight = true;
1090
1057
  this.isDIVEPointLight = true;
1091
- this.isMoveable = true;
1058
+ this.isMovable = true;
1092
1059
  this.isSelectable = true;
1093
1060
  this.gizmo = null;
1094
1061
  this.name = "DIVEPointLight";
@@ -1192,7 +1159,7 @@ var DIVENode = class extends import_three7.Object3D {
1192
1159
  super();
1193
1160
  this.isDIVENode = true;
1194
1161
  this.isSelectable = true;
1195
- this.isMoveable = true;
1162
+ this.isMovable = true;
1196
1163
  this.gizmo = null;
1197
1164
  this.layers.mask = PRODUCT_LAYER_MASK;
1198
1165
  this._boundingBox = new import_three7.Box3();
@@ -1217,6 +1184,9 @@ var DIVENode = class extends import_three7.Object3D {
1217
1184
  onMove() {
1218
1185
  var _a;
1219
1186
  (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
1187
+ if (this.parent && "isDIVEGroup" in this.parent) {
1188
+ this.parent.UpdateLineTo(this);
1189
+ }
1220
1190
  }
1221
1191
  onSelect() {
1222
1192
  var _a;
@@ -1496,66 +1466,118 @@ var DIVEPrimitive = class extends DIVENode {
1496
1466
  // src/group/Group.ts
1497
1467
  var import_three10 = require("three");
1498
1468
  var DIVEGroup = class extends DIVENode {
1469
+ // lines to children
1499
1470
  constructor() {
1500
1471
  super();
1501
1472
  this.isDIVEGroup = true;
1502
1473
  this.name = "DIVEGroup";
1503
- this._boxMesh = new import_three10.Mesh(new import_three10.BoxGeometry(0, 0, 0), new import_three10.MeshBasicMaterial({ color: 16711680, wireframe: true }));
1504
- this._boxMesh.visible = false;
1505
- this.add(this._boxMesh);
1474
+ this._members = [];
1475
+ this._lines = [];
1506
1476
  }
1507
- SetBoundingBoxVisibility(visible) {
1508
- this._boxMesh.visible = visible;
1477
+ SetLinesVisibility(visible, object) {
1478
+ if (!object) {
1479
+ this._lines.forEach((line) => {
1480
+ line.visible = visible;
1481
+ });
1482
+ return;
1483
+ }
1484
+ const index = this._members.indexOf(object);
1485
+ if (index === -1) return;
1486
+ this._lines[index].visible = visible;
1509
1487
  }
1510
1488
  attach(object) {
1489
+ const line = this.createLine();
1490
+ this.add(line);
1491
+ this._lines.push(line);
1511
1492
  super.attach(object);
1512
- this.recalculatePosition();
1513
- this.updateBoxMesh();
1493
+ this._members.push(object);
1494
+ this.updateLineTo(line, object);
1495
+ this.SetLinesVisibility(true, object);
1514
1496
  return this;
1515
1497
  }
1516
1498
  remove(object) {
1499
+ const index = this._members.indexOf(object);
1500
+ if (index === -1) return this;
1501
+ const line = this._lines[index];
1502
+ super.remove(line);
1503
+ this._lines.splice(index, 1);
1517
1504
  super.remove(object);
1518
- this.recalculatePosition();
1519
- this.updateBoxMesh();
1505
+ this._members.splice(index, 1);
1520
1506
  return this;
1521
1507
  }
1508
+ UpdateLineTo(object) {
1509
+ const index = this._members.indexOf(object);
1510
+ if (index === -1) return;
1511
+ this.updateLineTo(this._lines[index], object);
1512
+ }
1522
1513
  /**
1523
- * Recalculates the position of the group based on it's bounding box.
1524
- * Children's world positions are kept.
1514
+ * Adds a line to this grouo as last child.
1525
1515
  */
1526
- recalculatePosition() {
1527
- var _a;
1528
- const childrensWorldPositions = this.children.map((child) => child.getWorldPosition(new import_three10.Vector3()));
1529
- const bbcenter = this.updateBB();
1530
- this.position.copy(bbcenter);
1531
- this.children.forEach((child, i) => {
1532
- if (child.uuid === this._boxMesh.uuid) return;
1533
- child.position.copy(this.worldToLocal(childrensWorldPositions[i]));
1516
+ createLine() {
1517
+ const geo = new import_three10.BufferGeometry();
1518
+ const mat = new import_three10.LineDashedMaterial({
1519
+ color: 6710886,
1520
+ dashSize: 0.05,
1521
+ gapSize: 0.025
1534
1522
  });
1535
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position });
1523
+ const line = new import_three10.Line(geo, mat);
1524
+ line.visible = false;
1525
+ return line;
1536
1526
  }
1537
1527
  /**
1538
- * Updates the bounding box of the group.
1539
- * @returns {Vector3} The new center of the bounding box.
1528
+ * Updates a line to the object.
1540
1529
  */
1541
- updateBB() {
1542
- this._boundingBox.makeEmpty();
1543
- this.children.forEach((child) => {
1544
- if (child.uuid === this._boxMesh.uuid) return;
1545
- this._boundingBox.expandByObject(child);
1546
- });
1547
- return this._boundingBox.getCenter(new import_three10.Vector3());
1548
- }
1549
- updateBoxMesh() {
1550
- this._boxMesh.quaternion.copy(this.quaternion.clone().invert());
1551
- this._boxMesh.scale.set(1 / this.scale.x, 1 / this.scale.y, 1 / this.scale.z);
1552
- this._boxMesh.geometry = new import_three10.BoxGeometry(this._boundingBox.max.x - this._boundingBox.min.x, this._boundingBox.max.y - this._boundingBox.min.y, this._boundingBox.max.z - this._boundingBox.min.z);
1553
- }
1554
- onMove() {
1555
- super.onMove();
1556
- this.updateBB();
1557
- this.updateBoxMesh();
1558
- }
1530
+ updateLineTo(line, object) {
1531
+ line.geometry.setFromPoints([new import_three10.Vector3(0, 0, 0), object.position.clone()]);
1532
+ line.computeLineDistances();
1533
+ }
1534
+ // public SetBoundingBoxVisibility(visible: boolean): void {
1535
+ // this._boxMesh.visible = visible;
1536
+ // }
1537
+ // /**
1538
+ // * Recalculates the position of the group based on it's bounding box.
1539
+ // * Children's world positions are kept.
1540
+ // */
1541
+ // private recalculatePosition(): void {
1542
+ // // store all children's world positions
1543
+ // const childrensWorldPositions: Vector3[] = this.children.map((child) => child.getWorldPosition(new Vector3()));
1544
+ // // calculate new center and set it as the group's position
1545
+ // const bbcenter = this.updateBB();
1546
+ // this.position.copy(bbcenter);
1547
+ // // set childrens's positions so their world positions are kept
1548
+ // this.children.forEach((child, i) => {
1549
+ // if (child.uuid === this._boxMesh.uuid) return;
1550
+ // child.position.copy(this.worldToLocal(childrensWorldPositions[i]));
1551
+ // });
1552
+ // DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position });
1553
+ // }
1554
+ // /**
1555
+ // * Updates the bounding box of the group.
1556
+ // * @returns {Vector3} The new center of the bounding box.
1557
+ // */
1558
+ // private updateBB(): Vector3 {
1559
+ // this._boundingBox.makeEmpty();
1560
+ // if (this.children.length === 1) {
1561
+ // // because we always have the box mesh as 1 child
1562
+ // return this.position.clone();
1563
+ // }
1564
+ // this.children.forEach((child) => {
1565
+ // if (child.uuid === this._boxMesh.uuid) return;
1566
+ // this._boundingBox.expandByObject(child);
1567
+ // });
1568
+ // return this._boundingBox.getCenter(new Vector3());
1569
+ // }
1570
+ // private updateBoxMesh(): void {
1571
+ // if (this.children.length === 1) {
1572
+ // // because we always have the box mesh as 1 child
1573
+ // this._boxMesh.visible = false;
1574
+ // return;
1575
+ // }
1576
+ // this._boxMesh.quaternion.copy(this.quaternion.clone().invert());
1577
+ // this._boxMesh.scale.set(1 / this.scale.x, 1 / this.scale.y, 1 / this.scale.z);
1578
+ // this._boxMesh.geometry = new BoxGeometry(this._boundingBox.max.x - this._boundingBox.min.x, this._boundingBox.max.y - this._boundingBox.min.y, this._boundingBox.max.z - this._boundingBox.min.z);
1579
+ // this._boxMesh.visible = true;
1580
+ // }
1559
1581
  };
1560
1582
 
1561
1583
  // src/scene/root/Root.ts
@@ -1576,7 +1598,14 @@ var DIVERoot = class extends import_three11.Object3D {
1576
1598
  return bb;
1577
1599
  }
1578
1600
  GetSceneObject(object) {
1579
- return this.children.find((object3D) => object3D.userData.id === object.id);
1601
+ let foundObject;
1602
+ this.traverse((object3D) => {
1603
+ if (foundObject) return;
1604
+ if (object3D.userData.id === object.id) {
1605
+ foundObject = object3D;
1606
+ }
1607
+ });
1608
+ return foundObject;
1580
1609
  }
1581
1610
  AddSceneObject(object) {
1582
1611
  switch (object.entityType) {
@@ -1745,7 +1774,7 @@ var DIVERoot = class extends import_three11.Object3D {
1745
1774
  if (group.rotation !== void 0) sceneObject.SetRotation(group.rotation);
1746
1775
  if (group.scale !== void 0) sceneObject.SetScale(group.scale);
1747
1776
  if (group.visible !== void 0) sceneObject.SetVisibility(group.visible);
1748
- if (group.bbVisible !== void 0) sceneObject.SetBoundingBoxVisibility(group.bbVisible);
1777
+ if (group.bbVisible !== void 0) sceneObject.SetLinesVisibility(group.bbVisible);
1749
1778
  if (group.parent !== void 0) this.setParent(__spreadProps(__spreadValues({}, group), { parent: group.parent }));
1750
1779
  }
1751
1780
  deleteLight(light) {