@shopware-ag/dive 1.16.7 → 1.16.9

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.js CHANGED
@@ -1401,7 +1401,7 @@ var DIVESceneLight = class extends Object3D4 {
1401
1401
 
1402
1402
  // src/model/Model.ts
1403
1403
  init_VisibilityLayerMask();
1404
- import { MeshStandardMaterial, Raycaster as Raycaster2, Vector3 as Vector32 } from "three";
1404
+ import { MeshStandardMaterial, Raycaster as Raycaster2, Vector3 as Vector33 } from "three";
1405
1405
 
1406
1406
  // src/helper/findSceneRecursive/findSceneRecursive.ts
1407
1407
  var findSceneRecursive = (object) => {
@@ -1413,7 +1413,7 @@ var findSceneRecursive = (object) => {
1413
1413
 
1414
1414
  // src/node/Node.ts
1415
1415
  init_VisibilityLayerMask();
1416
- import { Box3, Object3D as Object3D5 } from "three";
1416
+ import { Box3, Object3D as Object3D5, Vector3 as Vector32 } from "three";
1417
1417
  var DIVENode = class extends Object3D5 {
1418
1418
  constructor() {
1419
1419
  super();
@@ -1422,10 +1422,19 @@ var DIVENode = class extends Object3D5 {
1422
1422
  this.isMovable = true;
1423
1423
  this.gizmo = null;
1424
1424
  this.layers.mask = PRODUCT_LAYER_MASK;
1425
+ this._positionWorldBuffer = new Vector32();
1425
1426
  this._boundingBox = new Box3();
1426
1427
  }
1427
1428
  SetPosition(position) {
1428
- this.position.set(position.x, position.y, position.z);
1429
+ if (!this.parent) {
1430
+ this.position.set(position.x, position.y, position.z);
1431
+ return;
1432
+ }
1433
+ const newPosition = new Vector32(position.x, position.y, position.z);
1434
+ this.position.copy(this.parent.worldToLocal(newPosition));
1435
+ if ("isDIVEGroup" in this.parent) {
1436
+ this.parent.UpdateLineTo(this);
1437
+ }
1429
1438
  }
1430
1439
  SetRotation(rotation) {
1431
1440
  this.rotation.set(rotation.x, rotation.y, rotation.z);
@@ -1443,26 +1452,26 @@ var DIVENode = class extends Object3D5 {
1443
1452
  "UPDATE_OBJECT",
1444
1453
  {
1445
1454
  id: this.userData.id,
1446
- position: this.position,
1455
+ position: this.getWorldPosition(this._positionWorldBuffer),
1447
1456
  rotation: this.rotation,
1448
1457
  scale: this.scale
1449
1458
  }
1450
1459
  );
1451
1460
  }
1461
+ /**
1462
+ * Can be called when the object is moved from a foreign object (gizmo, parent, etc.) to update the object's position.
1463
+ */
1452
1464
  onMove() {
1453
1465
  var _a;
1454
1466
  (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
1455
1467
  "UPDATE_OBJECT",
1456
1468
  {
1457
1469
  id: this.userData.id,
1458
- position: this.position,
1470
+ position: this.getWorldPosition(this._positionWorldBuffer),
1459
1471
  rotation: this.rotation,
1460
1472
  scale: this.scale
1461
1473
  }
1462
1474
  );
1463
- if (this.parent && "isDIVEGroup" in this.parent) {
1464
- this.parent.UpdateLineTo(this);
1465
- }
1466
1475
  }
1467
1476
  onSelect() {
1468
1477
  var _a;
@@ -1490,6 +1499,7 @@ var DIVEModel = class extends DIVENode {
1490
1499
  }
1491
1500
  SetModel(gltf) {
1492
1501
  this.clear();
1502
+ this._boundingBox.makeEmpty();
1493
1503
  gltf.scene.traverse((child) => {
1494
1504
  child.castShadow = true;
1495
1505
  child.receiveShadow = true;
@@ -1545,10 +1555,20 @@ var DIVEModel = class extends DIVENode {
1545
1555
  }
1546
1556
  }
1547
1557
  PlaceOnFloor() {
1548
- const oldPos = this.position.clone();
1549
- this.position.y = -this._boundingBox.min.y * this.scale.y;
1550
- if (this.position.y === oldPos.y) return;
1551
- this.onMove();
1558
+ var _a;
1559
+ const worldPos = this.getWorldPosition(this._positionWorldBuffer);
1560
+ const oldWorldPos = worldPos.clone();
1561
+ worldPos.y = -this._boundingBox.min.y * this.scale.y;
1562
+ if (worldPos.y === oldWorldPos.y) return;
1563
+ (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
1564
+ "UPDATE_OBJECT",
1565
+ {
1566
+ id: this.userData.id,
1567
+ position: worldPos,
1568
+ rotation: this.rotation,
1569
+ scale: this.scale
1570
+ }
1571
+ );
1552
1572
  }
1553
1573
  DropIt() {
1554
1574
  if (!this.parent) {
@@ -1560,10 +1580,10 @@ var DIVEModel = class extends DIVENode {
1560
1580
  }
1561
1581
  const bottomY = this._boundingBox.min.y * this.scale.y;
1562
1582
  const bbBottomCenter = this.localToWorld(
1563
- this._boundingBox.getCenter(new Vector32()).multiply(this.scale)
1583
+ this._boundingBox.getCenter(new Vector33()).multiply(this.scale)
1564
1584
  );
1565
1585
  bbBottomCenter.y = bottomY + this.position.y;
1566
- const raycaster = new Raycaster2(bbBottomCenter, new Vector32(0, -1, 0));
1586
+ const raycaster = new Raycaster2(bbBottomCenter, new Vector33(0, -1, 0));
1567
1587
  raycaster.layers.mask = PRODUCT_LAYER_MASK;
1568
1588
  const intersections = raycaster.intersectObjects(
1569
1589
  findSceneRecursive(this).Root.children,
@@ -1575,7 +1595,7 @@ var DIVEModel = class extends DIVENode {
1575
1595
  const meshBB = mesh.geometry.boundingBox;
1576
1596
  const worldPos = mesh.localToWorld(meshBB.max.clone());
1577
1597
  const oldPos = this.position.clone();
1578
- const newPos = this.position.clone().setY(worldPos.y).sub(new Vector32(0, bottomY, 0));
1598
+ const newPos = this.position.clone().setY(worldPos.y).sub(new Vector33(0, bottomY, 0));
1579
1599
  this.position.copy(newPos);
1580
1600
  if (this.position.y === oldPos.y) return;
1581
1601
  this.onMove();
@@ -1621,6 +1641,8 @@ var DIVELoadingManager = class {
1621
1641
  init_VisibilityLayerMask();
1622
1642
  import {
1623
1643
  BoxGeometry,
1644
+ BufferAttribute,
1645
+ BufferGeometry,
1624
1646
  Color as Color4,
1625
1647
  ConeGeometry,
1626
1648
  CylinderGeometry,
@@ -1628,7 +1650,7 @@ import {
1628
1650
  MeshStandardMaterial as MeshStandardMaterial2,
1629
1651
  Raycaster as Raycaster3,
1630
1652
  SphereGeometry as SphereGeometry2,
1631
- Vector3 as Vector33
1653
+ Vector3 as Vector34
1632
1654
  } from "three";
1633
1655
  var DIVEPrimitive = class extends DIVENode {
1634
1656
  constructor() {
@@ -1682,10 +1704,20 @@ var DIVEPrimitive = class extends DIVENode {
1682
1704
  if (this._mesh) this._mesh.material = primitiveMaterial;
1683
1705
  }
1684
1706
  PlaceOnFloor() {
1685
- const oldPos = this.position.clone();
1686
- this.position.y = -this._boundingBox.min.y * this.scale.y;
1687
- if (this.position.y === oldPos.y) return;
1688
- this.onMove();
1707
+ var _a;
1708
+ const worldPos = this.getWorldPosition(this._positionWorldBuffer);
1709
+ const oldWorldPos = worldPos.clone();
1710
+ worldPos.y = -this._boundingBox.min.y * this.scale.y;
1711
+ if (worldPos.y === oldWorldPos.y) return;
1712
+ (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
1713
+ "UPDATE_OBJECT",
1714
+ {
1715
+ id: this.userData.id,
1716
+ position: worldPos,
1717
+ rotation: this.rotation,
1718
+ scale: this.scale
1719
+ }
1720
+ );
1689
1721
  }
1690
1722
  DropIt() {
1691
1723
  if (!this.parent) {
@@ -1697,10 +1729,10 @@ var DIVEPrimitive = class extends DIVENode {
1697
1729
  }
1698
1730
  const bottomY = this._boundingBox.min.y * this.scale.y;
1699
1731
  const bbBottomCenter = this.localToWorld(
1700
- this._boundingBox.getCenter(new Vector33()).multiply(this.scale)
1732
+ this._boundingBox.getCenter(new Vector34()).multiply(this.scale)
1701
1733
  );
1702
1734
  bbBottomCenter.y = bottomY + this.position.y;
1703
- const raycaster = new Raycaster3(bbBottomCenter, new Vector33(0, -1, 0));
1735
+ const raycaster = new Raycaster3(bbBottomCenter, new Vector34(0, -1, 0));
1704
1736
  raycaster.layers.mask = PRODUCT_LAYER_MASK;
1705
1737
  const intersections = raycaster.intersectObjects(
1706
1738
  findSceneRecursive(this).Root.children,
@@ -1712,19 +1744,21 @@ var DIVEPrimitive = class extends DIVENode {
1712
1744
  const meshBB = mesh.geometry.boundingBox;
1713
1745
  const worldPos = mesh.localToWorld(meshBB.max.clone());
1714
1746
  const oldPos = this.position.clone();
1715
- const newPos = this.position.clone().setY(worldPos.y).sub(new Vector33(0, bottomY, 0));
1747
+ const newPos = this.position.clone().setY(worldPos.y).sub(new Vector34(0, bottomY, 0));
1716
1748
  this.position.copy(newPos);
1717
1749
  if (this.position.y === oldPos.y) return;
1718
1750
  this.onMove();
1719
1751
  }
1720
1752
  }
1721
1753
  assembleGeometry(geometry) {
1754
+ this._mesh.material.flatShading = false;
1722
1755
  switch (geometry.name.toLowerCase()) {
1723
1756
  case "cylinder":
1724
1757
  return this.createCylinderGeometry(geometry);
1725
1758
  case "sphere":
1726
1759
  return this.createSphereGeometry(geometry);
1727
1760
  case "pyramid":
1761
+ this._mesh.material.flatShading = true;
1728
1762
  return this.createPyramidGeometry(geometry);
1729
1763
  case "cube":
1730
1764
  case "box":
@@ -1759,16 +1793,57 @@ var DIVEPrimitive = class extends DIVENode {
1759
1793
  return geo;
1760
1794
  }
1761
1795
  createPyramidGeometry(geometry) {
1762
- const geo = new ConeGeometry(
1796
+ const vertices = new Float32Array([
1797
+ -geometry.width / 2,
1798
+ 0,
1799
+ -geometry.depth / 2,
1800
+ // 0
1801
+ geometry.width / 2,
1802
+ 0,
1803
+ -geometry.depth / 2,
1804
+ // 1
1763
1805
  geometry.width / 2,
1806
+ 0,
1807
+ geometry.depth / 2,
1808
+ // 2
1809
+ -geometry.width / 2,
1810
+ 0,
1811
+ geometry.depth / 2,
1812
+ // 3
1813
+ 0,
1764
1814
  geometry.height,
1815
+ 0
1816
+ ]);
1817
+ const indices = new Uint16Array([
1818
+ 0,
1819
+ 1,
1820
+ 2,
1821
+ 0,
1822
+ 2,
1823
+ 3,
1824
+ 0,
1765
1825
  4,
1766
1826
  1,
1767
- true
1827
+ 1,
1828
+ 4,
1829
+ 2,
1830
+ 2,
1831
+ 4,
1832
+ 3,
1833
+ 3,
1834
+ 4,
1835
+ 0
1836
+ ]);
1837
+ const geometryBuffer = new BufferGeometry();
1838
+ geometryBuffer.setAttribute(
1839
+ "position",
1840
+ new BufferAttribute(vertices, 3)
1768
1841
  );
1769
- geo.rotateY(Math.PI / 4);
1770
- geo.translate(0, geometry.height / 2, 0);
1771
- return geo;
1842
+ geometryBuffer.setIndex(new BufferAttribute(indices, 1));
1843
+ geometryBuffer.computeVertexNormals();
1844
+ geometryBuffer.computeBoundingBox();
1845
+ geometryBuffer.computeBoundingSphere();
1846
+ return geometryBuffer;
1772
1847
  }
1773
1848
  createBoxGeometry(geometry) {
1774
1849
  const geo = new BoxGeometry(
@@ -1806,7 +1881,12 @@ var DIVEPrimitive = class extends DIVENode {
1806
1881
  };
1807
1882
 
1808
1883
  // src/group/Group.ts
1809
- import { BufferGeometry as BufferGeometry2, Line, LineDashedMaterial, Vector3 as Vector34 } from "three";
1884
+ import {
1885
+ BufferGeometry as BufferGeometry2,
1886
+ Line,
1887
+ LineDashedMaterial,
1888
+ Vector3 as Vector35
1889
+ } from "three";
1810
1890
  var DIVEGroup = class extends DIVENode {
1811
1891
  // lines to children
1812
1892
  constructor() {
@@ -1816,6 +1896,14 @@ var DIVEGroup = class extends DIVENode {
1816
1896
  this._members = [];
1817
1897
  this._lines = [];
1818
1898
  }
1899
+ SetPosition(position) {
1900
+ super.SetPosition(position);
1901
+ this._members.forEach((member) => {
1902
+ if ("isDIVENode" in member) {
1903
+ member.onMove();
1904
+ }
1905
+ });
1906
+ }
1819
1907
  SetLinesVisibility(visible, object) {
1820
1908
  if (!object) {
1821
1909
  this._lines.forEach((line) => {
@@ -1871,7 +1959,7 @@ var DIVEGroup = class extends DIVENode {
1871
1959
  */
1872
1960
  updateLineTo(line, object) {
1873
1961
  line.geometry.setFromPoints([
1874
- new Vector34(0, 0, 0),
1962
+ new Vector35(0, 0, 0),
1875
1963
  object.position.clone()
1876
1964
  ]);
1877
1965
  line.computeLineDistances();
@@ -2368,7 +2456,7 @@ init_PerspectiveCamera();
2368
2456
 
2369
2457
  // src/controls/OrbitControls.ts
2370
2458
  import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
2371
- import { MathUtils as MathUtils2, Vector3 as Vector35 } from "three";
2459
+ import { MathUtils as MathUtils2, Vector3 as Vector36 } from "three";
2372
2460
  import { Easing } from "@tweenjs/tween.js";
2373
2461
  var DIVEOrbitControlsDefaultSettings = {
2374
2462
  enableDamping: true,
@@ -2410,8 +2498,8 @@ var _DIVEOrbitControls = class _DIVEOrbitControls extends OrbitControls {
2410
2498
  this.dispose();
2411
2499
  }
2412
2500
  ComputeEncompassingView(bb) {
2413
- const center = bb.getCenter(new Vector35());
2414
- const size = bb.getSize(new Vector35());
2501
+ const center = bb.getCenter(new Vector36());
2502
+ const size = bb.getSize(new Vector36());
2415
2503
  const distance = Math.max(size.x, size.y, size.z) * 1.25;
2416
2504
  const direction = this.object.position.clone().normalize();
2417
2505
  return {
@@ -2859,7 +2947,7 @@ DIVEInfo._supportsWebXR = null;
2859
2947
  // package.json
2860
2948
  var package_default = {
2861
2949
  name: "@shopware-ag/dive",
2862
- version: "1.16.7",
2950
+ version: "1.16.9",
2863
2951
  description: "Shopware Spatial Framework",
2864
2952
  type: "module",
2865
2953
  main: "./build/dive.cjs",
@@ -2977,6 +3065,18 @@ function truncateExp(number, decimals = 0) {
2977
3065
  return shift(Math.trunc(n), -decimals);
2978
3066
  }
2979
3067
 
3068
+ // src/math/radToDeg/radToDeg.ts
3069
+ import { MathUtils as MathUtils3 } from "three";
3070
+ function radToDeg(radians) {
3071
+ return (MathUtils3.radToDeg(radians) + 360) % 360;
3072
+ }
3073
+
3074
+ // src/math/degToRad/degToRad.ts
3075
+ import { MathUtils as MathUtils4 } from "three";
3076
+ function degToRad(degrees) {
3077
+ return MathUtils4.degToRad(degrees);
3078
+ }
3079
+
2980
3080
  // src/math/index.ts
2981
3081
  var DIVEMath = {
2982
3082
  ceilExp,
@@ -2984,7 +3084,9 @@ var DIVEMath = {
2984
3084
  roundExp: roundExponential,
2985
3085
  toFixedExp,
2986
3086
  truncateExp,
2987
- signedAngleTo
3087
+ signedAngleTo,
3088
+ radToDeg,
3089
+ degToRad
2988
3090
  };
2989
3091
 
2990
3092
  // src/dive.ts