@shopware-ag/dive 1.16.26-beta.2 → 1.17.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.
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,119 +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...");
2018
- anchor.click();
2027
+ console.log("DIVE: Launching AR with ARQuickLook ...");
2028
+ yield DIVEARQuickLook.Launch(this._scene, options);
2029
+ return Promise.resolve();
2030
+ });
2019
2031
  }
2020
- createSceneViewerSrc() {
2021
- let uri = null;
2022
- this._scene.traverse((object) => {
2023
- if (uri) return;
2024
- if (object.userData.uri) {
2025
- 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();
2026
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();
2027
2051
  });
2028
- if (!uri) {
2029
- throw new Error("No model found in scene");
2030
- }
2031
- return uri;
2032
2052
  }
2033
2053
  };
2034
2054
  }
@@ -2431,8 +2451,9 @@ var _DIVECommunication = class _DIVECommunication {
2431
2451
  break;
2432
2452
  }
2433
2453
  case "LAUNCH_AR": {
2434
- this.ar.Launch();
2435
- returnValue = true;
2454
+ returnValue = this.ar.Launch(
2455
+ payload
2456
+ );
2436
2457
  break;
2437
2458
  }
2438
2459
  default: {
@@ -4369,7 +4390,7 @@ init_Info();
4369
4390
  // package.json
4370
4391
  var package_default = {
4371
4392
  name: "@shopware-ag/dive",
4372
- version: "1.16.26-beta.2",
4393
+ version: "1.17.0",
4373
4394
  description: "Shopware Spatial Framework",
4374
4395
  type: "module",
4375
4396
  main: "./build/dive.cjs",
@@ -4438,7 +4459,8 @@ var package_default = {
4438
4459
  "generate-readme": "yarn generate-readme:transpile && yarn generate-readme:write && yarn generate-readme:cleanup",
4439
4460
  "generate-readme:transpile": "yarn tsc --resolveJsonModule --esModuleInterop ci/readme/generate-readme.ts && mv ci/readme/generate-readme.js ci/readme/generate-readme.cjs",
4440
4461
  "generate-readme:write": "node ci/readme/generate-readme.cjs",
4441
- "generate-readme:cleanup": `node -e "require('fs').unlinkSync('ci/readme/generate-readme.cjs')"`
4462
+ "generate-readme:cleanup": `node -e "require('fs').unlinkSync('ci/readme/generate-readme.cjs')"`,
4463
+ ci: "yarn lint && yarn coverage && yarn prettier:check && yarn build && bash ci/lint/lint-actions.sh"
4442
4464
  }
4443
4465
  };
4444
4466