@shopware-ag/dive 1.16.26-beta.3 → 1.17.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.
package/README.md CHANGED
@@ -305,6 +305,14 @@ DIVECommunication class via
305
305
  Returns a list of objects of given IDs.
306
306
  </td>
307
307
  </tr>
308
+ <tr>
309
+ <td>
310
+ <a href="src/com/actions/scene/launchar.ts"> LAUNCH_AR </a>
311
+ </td>
312
+ <td>
313
+ Launches AR mode in native capabilities. (iOS: AR Quick Look, Android: Google Scene Viewer)
314
+ </td>
315
+ </tr>
308
316
  <tr>
309
317
  <td>
310
318
  <a href="src/com/actions/object/model/modelloaded.ts"> MODEL_LOADED </a>
package/build/dive.cjs CHANGED
@@ -766,26 +766,51 @@ var init_Info = __esm({
766
766
  }
767
767
  });
768
768
 
769
+ // src/exporters/usdz/USDZExporter.ts
770
+ var import_USDZExporter, DIVEUSDZExporter;
771
+ var init_USDZExporter = __esm({
772
+ "src/exporters/usdz/USDZExporter.ts"() {
773
+ "use strict";
774
+ import_USDZExporter = require("three/examples/jsm/exporters/USDZExporter");
775
+ DIVEUSDZExporter = class extends import_USDZExporter.USDZExporter {
776
+ parse(scene, options) {
777
+ return super.parse(scene, options);
778
+ }
779
+ };
780
+ }
781
+ });
782
+
769
783
  // src/ar/arquicklook/ARQuickLook.ts
770
- var import_three5, import_USDZExporter, DIVEARQuickLook;
784
+ var import_three5, DIVEARQuickLook;
771
785
  var init_ARQuickLook = __esm({
772
786
  "src/ar/arquicklook/ARQuickLook.ts"() {
773
787
  "use strict";
774
788
  import_three5 = require("three");
775
- import_USDZExporter = require("three/examples/jsm/exporters/USDZExporter");
789
+ init_USDZExporter();
776
790
  DIVEARQuickLook = class {
777
- static Launch(scene) {
791
+ static Launch(scene, options) {
778
792
  const quickLookScene = new import_three5.Object3D();
779
793
  quickLookScene.add(...this.extractModels(scene));
780
- return this.launchARFromNode(quickLookScene);
794
+ return this.launchARFromNode(quickLookScene, options);
781
795
  }
782
796
  static extractModels(scene) {
783
797
  return scene.Root.children;
784
798
  }
785
- static launchARFromNode(node) {
786
- return this._usdzExporter.parse(node, { quickLookCompatible: true }).then((usdz) => {
799
+ static launchARFromNode(node, options) {
800
+ return this._usdzExporter.parse(node, {
801
+ quickLookCompatible: true,
802
+ ar: {
803
+ anchoring: { type: "plane" },
804
+ planeAnchoring: {
805
+ alignment: (options == null ? void 0 : options.arPlacement) === "vertical" ? "vertical" : "horizontal"
806
+ }
807
+ }
808
+ }).then((usdz) => {
787
809
  const blob = new Blob([usdz], { type: "model/vnd.usdz+zip" });
788
- const url = URL.createObjectURL(blob);
810
+ let url = URL.createObjectURL(blob);
811
+ if ((options == null ? void 0 : options.arScale) === "fixed") {
812
+ url = url.concat("#allowsContentScaling=0");
813
+ }
789
814
  const a = document.createElement("a");
790
815
  a.innerHTML = "<picture></picture>";
791
816
  a.rel = "ar";
@@ -795,7 +820,7 @@ var init_ARQuickLook = __esm({
795
820
  });
796
821
  }
797
822
  };
798
- DIVEARQuickLook._usdzExporter = new import_USDZExporter.USDZExporter();
823
+ DIVEARQuickLook._usdzExporter = new DIVEUSDZExporter();
799
824
  }
800
825
  });
801
826
 
@@ -1621,18 +1646,21 @@ var init_WebXRController = __esm({
1621
1646
  Update(frame) {
1622
1647
  this._frameBuffer = frame;
1623
1648
  if (!this._placed) {
1624
- this._xrCamera.updateMatrixWorld();
1625
- this._scene.XRRoot.XRHandNode.position.copy(
1626
- this._handNodeInitialPosition.clone().applyMatrix4(this._xrCamera.matrixWorld)
1627
- );
1628
- this._scene.XRRoot.XRHandNode.quaternion.setFromRotationMatrix(
1629
- this._xrCamera.matrixWorld
1630
- );
1649
+ this.updateHandNode();
1631
1650
  if (this._origin) {
1632
1651
  this._origin.Update(frame);
1633
1652
  }
1634
1653
  }
1635
1654
  }
1655
+ updateHandNode() {
1656
+ this._xrCamera.updateMatrixWorld();
1657
+ this._scene.XRRoot.XRHandNode.position.copy(
1658
+ this._handNodeInitialPosition.clone().applyMatrix4(this._xrCamera.matrixWorld)
1659
+ );
1660
+ this._scene.XRRoot.XRHandNode.quaternion.setFromRotationMatrix(
1661
+ this._xrCamera.matrixWorld
1662
+ );
1663
+ }
1636
1664
  // placement
1637
1665
  initOrigin() {
1638
1666
  return __async(this, null, function* () {
@@ -1904,6 +1932,54 @@ var init_WebXR = __esm({
1904
1932
  }
1905
1933
  });
1906
1934
 
1935
+ // src/ar/sceneviewer/SceneViewer.ts
1936
+ var DIVESceneViewer;
1937
+ var init_SceneViewer = __esm({
1938
+ "src/ar/sceneviewer/SceneViewer.ts"() {
1939
+ "use strict";
1940
+ DIVESceneViewer = class {
1941
+ static Launch(scene, options) {
1942
+ const url = this.findSceneViewerSrc(scene);
1943
+ this.launchSceneViewer(url, options);
1944
+ }
1945
+ static launchSceneViewer(url, options) {
1946
+ const anchor = document.createElement("a");
1947
+ const noArViewerSigil = "#model-viewer-no-ar-fallback";
1948
+ const location = self.location.toString();
1949
+ const locationUrl = new URL(location);
1950
+ const modelUrl = new URL(url, location);
1951
+ const params = new URLSearchParams(modelUrl.search);
1952
+ locationUrl.hash = noArViewerSigil;
1953
+ params.set("mode", "ar_only");
1954
+ if ((options == null ? void 0 : options.arScale) === "fixed") {
1955
+ params.set("resizable", "false");
1956
+ }
1957
+ if ((options == null ? void 0 : options.arPlacement) === "vertical") {
1958
+ params.set("enable_vertical_placement", "true");
1959
+ }
1960
+ const intent = `intent://arvr.google.com/scene-viewer/1.2?${params.toString() + "&file=" + modelUrl.toString()}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(
1961
+ locationUrl.toString()
1962
+ )};end;`;
1963
+ anchor.setAttribute("href", intent);
1964
+ anchor.click();
1965
+ }
1966
+ static findSceneViewerSrc(scene) {
1967
+ let uri = null;
1968
+ scene.traverse((object) => {
1969
+ if (uri) return;
1970
+ if (object.userData.uri) {
1971
+ uri = object.userData.uri;
1972
+ }
1973
+ });
1974
+ if (!uri) {
1975
+ throw new Error("No model found in scene");
1976
+ }
1977
+ return uri;
1978
+ }
1979
+ };
1980
+ }
1981
+ });
1982
+
1907
1983
  // src/ar/AR.ts
1908
1984
  var AR_exports = {};
1909
1985
  __export(AR_exports, {
@@ -1916,118 +1992,63 @@ var init_AR = __esm({
1916
1992
  init_Info();
1917
1993
  init_ARQuickLook();
1918
1994
  init_WebXR();
1995
+ init_SceneViewer();
1919
1996
  DIVEAR = class {
1920
1997
  constructor(renderer, scene, controller) {
1921
- this.arPlacement = "floor";
1922
- this.arScale = "auto";
1923
1998
  this._renderer = renderer;
1924
1999
  this._scene = scene;
1925
2000
  this._controller = controller;
1926
2001
  }
1927
- Launch() {
2002
+ Launch(options) {
1928
2003
  return __async(this, null, function* () {
1929
2004
  const system = DIVEInfo.GetSystem();
1930
2005
  if (system === "iOS") {
1931
- const support = DIVEInfo.GetSupportsARQuickLook();
1932
- if (!support) {
1933
- console.log("ARQuickLook not supported");
1934
- return Promise.reject();
1935
- }
1936
- console.log("Launching AR on iOS");
1937
- yield DIVEARQuickLook.Launch(this._scene);
1938
- return Promise.resolve();
2006
+ return this.tryARQuickLook();
1939
2007
  }
1940
2008
  if (system === "Android") {
1941
- this.openSceneViewer();
1942
- return;
1943
- const support = yield DIVEInfo.GetSupportsWebXR();
1944
- if (!support) {
1945
- console.log(
1946
- "WebXR not supported. Reason: " + WebXRUnsupportedReason[DIVEInfo.GetWebXRUnsupportedReason()]
1947
- );
1948
- return Promise.reject();
2009
+ if (options == null ? void 0 : options.useWebXR) {
2010
+ console.warn("DIVE: WebXR is experimental on Android.");
2011
+ return this.tryWebXR();
1949
2012
  }
1950
- console.log("Launching AR on Android");
1951
- yield DIVEWebXR.Launch(
1952
- this._renderer,
1953
- this._scene,
1954
- this._controller
1955
- );
1956
- return Promise.resolve();
2013
+ return this.trySceneViewer();
1957
2014
  }
1958
2015
  console.log(
1959
- "AR not supported. Not a mobile system. (System is " + system + ")"
2016
+ "DIVE: AR not supported. Not a mobile system. (System is " + system + ")"
1960
2017
  );
1961
2018
  });
1962
2019
  }
1963
- openSceneViewer() {
1964
- const src = this.createSceneViewerSrc();
1965
- const anchor = document.createElement("a");
1966
- const noArViewerSigil = "#model-viewer-no-ar-fallback";
1967
- const location = self.location.toString();
1968
- const locationUrl = new URL(location);
1969
- const modelUrl = new URL(src, location);
1970
- if (modelUrl.hash) modelUrl.hash = "";
1971
- const params = new URLSearchParams(modelUrl.search);
1972
- locationUrl.hash = noArViewerSigil;
1973
- params.set("mode", "ar_preferred");
1974
- if (!params.has("disable_occlusion")) {
1975
- params.set("disable_occlusion", "true");
1976
- }
1977
- if (this.arScale === "fixed") {
1978
- params.set("resizable", "false");
1979
- }
1980
- if (this.arPlacement === "wall") {
1981
- params.set("enable_vertical_placement", "true");
1982
- }
1983
- if (params.has("sound")) {
1984
- const soundUrl = new URL(params.get("sound"), location);
1985
- params.set("sound", soundUrl.toString());
1986
- }
1987
- if (params.has("link")) {
1988
- const linkUrl = new URL(params.get("link"), location);
1989
- params.set("link", linkUrl.toString());
1990
- }
1991
- console.log("modelUrl.toString()", modelUrl.toString());
1992
- console.log(
1993
- "encodeURIComponent(modelUrl.toString())",
1994
- encodeURIComponent(modelUrl.toString())
1995
- );
1996
- const version = "1.0";
1997
- console.log("USING SCENE VIEWER");
1998
- console.log("version:", version);
1999
- console.log("params:", params.toString());
2000
- console.log("modelUrl:", modelUrl.toString());
2001
- console.log("locationUrl:", locationUrl.toString());
2002
- const intent = `intent://arvr.google.com/scene-viewer/${version}?${params.toString() + "&file=" + modelUrl.toString()}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(
2003
- locationUrl.toString()
2004
- )};end;`;
2005
- console.log({ intent });
2006
- const undoHashChange = () => {
2007
- if (self.location.hash === noArViewerSigil) {
2008
- self.history.back();
2009
- console.warn(
2010
- "Error while trying to present in AR with Scene Viewer"
2011
- );
2012
- console.warn("Falling back to next ar-mode");
2020
+ tryARQuickLook(options) {
2021
+ return __async(this, null, function* () {
2022
+ const support = DIVEInfo.GetSupportsARQuickLook();
2023
+ if (!support) {
2024
+ console.log("ARQuickLook not supported");
2025
+ return Promise.reject();
2013
2026
  }
2014
- };
2015
- self.addEventListener("hashchange", undoHashChange, { once: true });
2016
- anchor.setAttribute("href", intent);
2017
- console.log("Attempting to present in AR with Scene Viewer...");
2027
+ console.log("DIVE: Launching AR with ARQuickLook ...");
2028
+ yield DIVEARQuickLook.Launch(this._scene, options);
2029
+ return Promise.resolve();
2030
+ });
2018
2031
  }
2019
- createSceneViewerSrc() {
2020
- let uri = null;
2021
- this._scene.traverse((object) => {
2022
- if (uri) return;
2023
- if (object.userData.uri) {
2024
- uri = object.userData.uri;
2032
+ tryWebXR() {
2033
+ return __async(this, null, function* () {
2034
+ const support = yield DIVEInfo.GetSupportsWebXR();
2035
+ if (!support) {
2036
+ console.log(
2037
+ "WebXR not supported. Reason: " + WebXRUnsupportedReason[DIVEInfo.GetWebXRUnsupportedReason()]
2038
+ );
2039
+ return Promise.reject();
2025
2040
  }
2041
+ console.log("DIVE: Launching AR with WebXR ...");
2042
+ yield DIVEWebXR.Launch(this._renderer, this._scene, this._controller);
2043
+ return Promise.resolve();
2044
+ });
2045
+ }
2046
+ trySceneViewer(options) {
2047
+ return __async(this, null, function* () {
2048
+ console.log("DIVE: Launching AR with SceneViewer ...");
2049
+ DIVESceneViewer.Launch(this._scene, options);
2050
+ return Promise.resolve();
2026
2051
  });
2027
- if (!uri) {
2028
- throw new Error("No model found in scene");
2029
- }
2030
- return uri;
2031
2052
  }
2032
2053
  };
2033
2054
  }
@@ -2430,8 +2451,9 @@ var _DIVECommunication = class _DIVECommunication {
2430
2451
  break;
2431
2452
  }
2432
2453
  case "LAUNCH_AR": {
2433
- this.ar.Launch();
2434
- returnValue = true;
2454
+ returnValue = this.ar.Launch(
2455
+ payload
2456
+ );
2435
2457
  break;
2436
2458
  }
2437
2459
  default: {
@@ -2528,6 +2550,22 @@ var _DIVECommunication = class _DIVECommunication {
2528
2550
  deleteObject(payload) {
2529
2551
  const deletedObject = this.registered.get(payload.id);
2530
2552
  if (!deletedObject) return false;
2553
+ if (deletedObject.parentId) {
2554
+ this.setParent({
2555
+ object: { id: deletedObject.id },
2556
+ parent: null
2557
+ });
2558
+ }
2559
+ if (deletedObject.entityType === "group") {
2560
+ this.registered.forEach((object) => {
2561
+ if (object.parentId === deletedObject.id) {
2562
+ this.updateObject({
2563
+ id: object.id,
2564
+ parentId: null
2565
+ });
2566
+ }
2567
+ });
2568
+ }
2531
2569
  Object.assign(payload, deletedObject);
2532
2570
  this.registered.delete(payload.id);
2533
2571
  Array.from(this.registered.values()).forEach((object) => {
@@ -2690,6 +2728,10 @@ var _DIVECommunication = class _DIVECommunication {
2690
2728
  if (!sceneObject) return false;
2691
2729
  if (payload.parent === null) {
2692
2730
  this.scene.Root.attach(sceneObject);
2731
+ this.updateObject({
2732
+ id: object.id,
2733
+ parentId: null
2734
+ });
2693
2735
  return true;
2694
2736
  }
2695
2737
  if (payload.object.id === payload.parent.id) {
@@ -2698,14 +2740,26 @@ var _DIVECommunication = class _DIVECommunication {
2698
2740
  const parent = this.registered.get(payload.parent.id);
2699
2741
  if (!parent) {
2700
2742
  this.scene.Root.attach(sceneObject);
2743
+ this.updateObject({
2744
+ id: object.id,
2745
+ parentId: null
2746
+ });
2701
2747
  return true;
2702
2748
  }
2703
2749
  const parentObject = this.scene.GetSceneObject(parent);
2704
2750
  if (!parentObject) {
2705
2751
  this.scene.Root.attach(sceneObject);
2752
+ this.updateObject({
2753
+ id: object.id,
2754
+ parentId: null
2755
+ });
2706
2756
  return true;
2707
2757
  }
2708
2758
  parentObject.attach(sceneObject);
2759
+ this.updateObject({
2760
+ id: object.id,
2761
+ parentId: parent.id
2762
+ });
2709
2763
  return true;
2710
2764
  }
2711
2765
  exportScene(payload) {
@@ -2980,12 +3034,15 @@ var DIVEModel = class extends DIVENode {
2980
3034
  }
2981
3035
  }
2982
3036
  PlaceOnFloor() {
2983
- var _a;
3037
+ var _a, _b, _c, _d, _e;
2984
3038
  const worldPos = this.getWorldPosition(this._positionWorldBuffer);
2985
3039
  const oldWorldPos = worldPos.clone();
2986
- worldPos.y = (this._boundingBox.max.y - this._boundingBox.min.y) / 2;
3040
+ (_b = (_a = this._mesh) == null ? void 0 : _a.geometry) == null ? void 0 : _b.computeBoundingBox();
3041
+ const meshBB = (_d = (_c = this._mesh) == null ? void 0 : _c.geometry) == null ? void 0 : _d.boundingBox;
3042
+ if (!meshBB || !this._mesh) return;
3043
+ worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
2987
3044
  if (worldPos.y === oldWorldPos.y) return;
2988
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3045
+ (_e = DIVECommunication.get(this.userData.id)) == null ? void 0 : _e.PerformAction(
2989
3046
  "UPDATE_OBJECT",
2990
3047
  {
2991
3048
  id: this.userData.id,
@@ -3117,12 +3174,15 @@ var DIVEPrimitive = class extends DIVENode {
3117
3174
  if (this._mesh) this._mesh.material = primitiveMaterial;
3118
3175
  }
3119
3176
  PlaceOnFloor() {
3120
- var _a;
3177
+ var _a, _b, _c, _d, _e;
3121
3178
  const worldPos = this.getWorldPosition(this._positionWorldBuffer);
3122
3179
  const oldWorldPos = worldPos.clone();
3123
- worldPos.y = (this._boundingBox.max.y - this._boundingBox.min.y) / 2;
3180
+ (_b = (_a = this._mesh) == null ? void 0 : _a.geometry) == null ? void 0 : _b.computeBoundingBox();
3181
+ const meshBB = (_d = (_c = this._mesh) == null ? void 0 : _c.geometry) == null ? void 0 : _d.boundingBox;
3182
+ if (!meshBB || !this._mesh) return;
3183
+ worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
3124
3184
  if (worldPos.y === oldWorldPos.y) return;
3125
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3185
+ (_e = DIVECommunication.get(this.userData.id)) == null ? void 0 : _e.PerformAction(
3126
3186
  "UPDATE_OBJECT",
3127
3187
  {
3128
3188
  id: this.userData.id,
@@ -4368,7 +4428,7 @@ init_Info();
4368
4428
  // package.json
4369
4429
  var package_default = {
4370
4430
  name: "@shopware-ag/dive",
4371
- version: "1.16.26-beta.3",
4431
+ version: "1.17.1",
4372
4432
  description: "Shopware Spatial Framework",
4373
4433
  type: "module",
4374
4434
  main: "./build/dive.cjs",
@@ -4437,7 +4497,8 @@ var package_default = {
4437
4497
  "generate-readme": "yarn generate-readme:transpile && yarn generate-readme:write && yarn generate-readme:cleanup",
4438
4498
  "generate-readme:transpile": "yarn tsc --resolveJsonModule --esModuleInterop ci/readme/generate-readme.ts && mv ci/readme/generate-readme.js ci/readme/generate-readme.cjs",
4439
4499
  "generate-readme:write": "node ci/readme/generate-readme.cjs",
4440
- "generate-readme:cleanup": `node -e "require('fs').unlinkSync('ci/readme/generate-readme.cjs')"`
4500
+ "generate-readme:cleanup": `node -e "require('fs').unlinkSync('ci/readme/generate-readme.cjs')"`,
4501
+ ci: "yarn lint && yarn coverage && yarn prettier:check && yarn build && bash ci/lint/lint-actions.sh"
4441
4502
  }
4442
4503
  };
4443
4504