@plattar/plattar-ar-adapter 1.180.1 → 1.183.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.
@@ -0,0 +1,33 @@
1
+ import { LauncherAR } from "./launcher-ar";
2
+ export interface SceneGraphAROptions {
3
+ readonly id: string;
4
+ readonly sceneID: string;
5
+ readonly useARBanner: boolean;
6
+ }
7
+ /**
8
+ * Performs AR functionality related to Plattar Scenes
9
+ */
10
+ export declare class SceneGraphAR extends LauncherAR {
11
+ private _analytics;
12
+ private _options;
13
+ private _ar;
14
+ constructor(options: SceneGraphAROptions);
15
+ private _SetupAnalytics;
16
+ /**
17
+ * Composes a Scene into an AR Model (remote operation) that can be used to launch
18
+ * an AR File
19
+ */
20
+ private _Compose;
21
+ /**
22
+ * Initialise the SceneAR instance. This returns a Promise that resolves
23
+ * successfully if initialisation is successful, otherwise it will fail.
24
+ *
25
+ * filure can occur for a number of reasons but it generally means that AR
26
+ * cannot be performed.
27
+ */
28
+ init(): Promise<LauncherAR>;
29
+ start(): void;
30
+ canQuicklook(): boolean;
31
+ canRealityViewer(): boolean;
32
+ canSceneViewer(): boolean;
33
+ }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SceneGraphAR = void 0;
7
+ const plattar_analytics_1 = require("@plattar/plattar-analytics");
8
+ const plattar_api_1 = require("@plattar/plattar-api");
9
+ const util_1 = require("../util/util");
10
+ const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
11
+ const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
12
+ const launcher_ar_1 = require("./launcher-ar");
13
+ const version_1 = __importDefault(require("../version"));
14
+ /**
15
+ * Performs AR functionality related to Plattar Scenes
16
+ */
17
+ class SceneGraphAR extends launcher_ar_1.LauncherAR {
18
+ constructor(options) {
19
+ super();
20
+ // analytics instance
21
+ this._analytics = null;
22
+ this._options = options;
23
+ this._ar = null;
24
+ }
25
+ async _SetupAnalytics() {
26
+ const scene = new plattar_api_1.Scene(this._options.sceneID);
27
+ scene.include(plattar_api_1.Project);
28
+ const fetchedScene = await scene.get();
29
+ let analytics = null;
30
+ analytics = new plattar_analytics_1.Analytics(fetchedScene.attributes.application_id);
31
+ analytics.origin = plattar_api_1.Server.location().type;
32
+ this._analytics = analytics;
33
+ analytics.data.push("type", "scene-graph-ar");
34
+ analytics.data.push("sdkVersion", version_1.default);
35
+ analytics.data.push("sceneId", fetchedScene.id);
36
+ analytics.data.push("sceneTitle", fetchedScene.attributes.title);
37
+ const application = fetchedScene.relationships.find(plattar_api_1.Project);
38
+ // setup application stuff (if any)
39
+ if (application) {
40
+ analytics.data.push("applicationId", application.id);
41
+ analytics.data.push("applicationTitle", application.attributes.title);
42
+ if (this._options.useARBanner) {
43
+ this.options.banner = {
44
+ title: application.attributes.title,
45
+ subtitle: fetchedScene.attributes.title,
46
+ button: 'Visit'
47
+ };
48
+ }
49
+ }
50
+ return fetchedScene;
51
+ }
52
+ /**
53
+ * Composes a Scene into an AR Model (remote operation) that can be used to launch
54
+ * an AR File
55
+ */
56
+ async _Compose(output) {
57
+ const type = output === 'glb' ? "viewer" : "reality";
58
+ const url = `https://xrutils.plattar.com/v3/scene/${this._options.sceneID}/${type}/${this._options.id}`;
59
+ // grab our existing scene-graph from the saved API
60
+ try {
61
+ const response = await fetch(url, {
62
+ method: "GET",
63
+ headers: {
64
+ "Content-Type": "application/json"
65
+ }
66
+ });
67
+ if (!response.ok) {
68
+ throw new Error(`ARAdapter - Fetching Existing Graph Error - network response was not ok ${response.status}`);
69
+ }
70
+ const data = await response.json();
71
+ return data.data.attributes.url;
72
+ }
73
+ catch (error) {
74
+ throw new Error(`ARAdapter - Fetching Existing Graph Error - there was a request error to ${url}, error was ${error.message}`);
75
+ }
76
+ }
77
+ /**
78
+ * Initialise the SceneAR instance. This returns a Promise that resolves
79
+ * successfully if initialisation is successful, otherwise it will fail.
80
+ *
81
+ * filure can occur for a number of reasons but it generally means that AR
82
+ * cannot be performed.
83
+ */
84
+ async init() {
85
+ if (!util_1.Util.canAugment()) {
86
+ throw new Error("SceneGraphAR.init() - cannot proceed as AR not available in context");
87
+ }
88
+ const scene = await this._SetupAnalytics();
89
+ const sceneOpt = scene.attributes.custom_json || {};
90
+ // we need to define our AR module here
91
+ // we are in Safari/Quicklook mode here
92
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
93
+ // we need to launch a VTO experience here
94
+ // VTO requires Reality Support
95
+ if (sceneOpt.anchor === "face") {
96
+ if (util_1.Util.canRealityViewer()) {
97
+ const modelUrl = await this._Compose("vto");
98
+ this._ar = new quicklook_viewer_1.default();
99
+ this._ar.modelUrl = modelUrl;
100
+ this._ar.banner = this.options.banner;
101
+ return this;
102
+ }
103
+ else {
104
+ throw new Error("SceneGraphAR.init() - cannot proceed as VTO AR requires Reality Viewer support");
105
+ }
106
+ }
107
+ // otherwise, load the USDZ stuff second if available
108
+ if (util_1.Util.canQuicklook()) {
109
+ const modelUrl = await this._Compose("usdz");
110
+ this._ar = new quicklook_viewer_1.default();
111
+ this._ar.modelUrl = modelUrl;
112
+ this._ar.banner = this.options.banner;
113
+ return this;
114
+ }
115
+ throw new Error("SceneGraphAR.init() - cannot proceed as IOS device does not support AR Mode");
116
+ }
117
+ // check android
118
+ if (util_1.Util.canSceneViewer()) {
119
+ const modelUrl = await this._Compose("glb");
120
+ const arviewer = new scene_viewer_1.default();
121
+ arviewer.modelUrl = modelUrl;
122
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
123
+ arviewer.banner = this.options.banner;
124
+ if (sceneOpt.anchor === "vertical") {
125
+ arviewer.isVertical = true;
126
+ }
127
+ this._ar = arviewer;
128
+ return this;
129
+ }
130
+ // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
131
+ // earlier in the process
132
+ throw new Error("SceneGraphAR.init() - could not initialise AR correctly, check values");
133
+ }
134
+ start() {
135
+ if (!this._ar) {
136
+ throw new Error("SceneGraphAR.start() - cannot proceed as AR instance is null");
137
+ }
138
+ const analytics = this._analytics;
139
+ if (analytics) {
140
+ analytics.data.push("device", this._ar.device);
141
+ analytics.data.push("eventCategory", this._ar.nodeType);
142
+ analytics.data.push("eventAction", "Start Scene Augment");
143
+ analytics.write();
144
+ analytics.startRecordEngagement();
145
+ }
146
+ // this was initialised via the init() function
147
+ this._ar.start();
148
+ }
149
+ canQuicklook() {
150
+ return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
151
+ }
152
+ canRealityViewer() {
153
+ return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
154
+ }
155
+ canSceneViewer() {
156
+ return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
157
+ }
158
+ }
159
+ exports.SceneGraphAR = SceneGraphAR;
@@ -6,6 +6,7 @@ const scene_product_ar_1 = require("../../ar/scene-product-ar");
6
6
  const util_1 = require("../../util/util");
7
7
  const plattar_controller_1 = require("./plattar-controller");
8
8
  const configurator_ar_1 = require("../../ar/configurator-ar");
9
+ const scene_graph_ar_1 = require("../../ar/scene-graph-ar");
9
10
  /**
10
11
  * Manages an instance of the <plattar-configurator> HTML Element
11
12
  */
@@ -142,6 +143,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
142
143
  const showAR = this.getAttribute("show-ar");
143
144
  const showUI = this.getAttribute("show-ui");
144
145
  const showBanner = this.getAttribute("show-ar-banner");
146
+ const sceneGraphID = this.getAttribute("scene-graph-id");
145
147
  if (showUI && showUI === "true") {
146
148
  dst = plattar_api_1.Server.location().base + "configurator/dist/index.html?scene_id=" + sceneID;
147
149
  }
@@ -154,6 +156,9 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
154
156
  if (showBanner) {
155
157
  dst += "&show_ar_banner=" + showBanner;
156
158
  }
159
+ if (sceneGraphID) {
160
+ dst += "&scene_graph_id=" + sceneGraphID;
161
+ }
157
162
  viewer.setAttribute("url", opt.url || dst);
158
163
  this._state = plattar_controller_1.ControllerState.QRCode;
159
164
  this._prevQROpt = opt;
@@ -293,6 +298,16 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
293
298
  if (!sceneID) {
294
299
  throw new Error("VTOController.initAR() - generated AR minimum required attributes not set, use scene-id as a minimum");
295
300
  }
301
+ const graphID = this.getAttribute("scene-graph-id");
302
+ // use the scene-graph route if available
303
+ if (graphID) {
304
+ const configAR = new scene_graph_ar_1.SceneGraphAR({
305
+ useARBanner: this.getBooleanAttribute("show-ar-banner"),
306
+ id: graphID,
307
+ sceneID: sceneID
308
+ });
309
+ return configAR.init();
310
+ }
296
311
  const configAR = new configurator_ar_1.ConfiguratorAR({ state: await this.getConfiguratorState(), useARBanner: this.getBooleanAttribute("show-ar-banner") });
297
312
  return configAR.init();
298
313
  }
@@ -5,6 +5,7 @@ const scene_product_ar_1 = require("../../ar/scene-product-ar");
5
5
  const util_1 = require("../../util/util");
6
6
  const plattar_controller_1 = require("./plattar-controller");
7
7
  const configurator_ar_1 = require("../../ar/configurator-ar");
8
+ const scene_graph_ar_1 = require("../../ar/scene-graph-ar");
8
9
  /**
9
10
  * Manages an instance of the <plattar-configurator> HTML Element
10
11
  */
@@ -88,6 +89,7 @@ class LauncherController extends plattar_controller_1.PlattarController {
88
89
  const variationSKU = this.getAttribute("variation-sku");
89
90
  const arMode = this.getAttribute("ar-mode");
90
91
  const showBanner = this.getAttribute("show-ar-banner");
92
+ const sceneGraphID = this.getAttribute("scene-graph-id");
91
93
  // required attributes with defaults for plattar-launcher node
92
94
  const width = this.getAttribute("width") || "500px";
93
95
  const height = this.getAttribute("height") || "500px";
@@ -126,6 +128,9 @@ class LauncherController extends plattar_controller_1.PlattarController {
126
128
  viewer.setAttribute("config-state", encodedState);
127
129
  }
128
130
  }
131
+ if (sceneGraphID) {
132
+ viewer.setAttribute("scene-graph-id", sceneGraphID);
133
+ }
129
134
  return new Promise((accept, reject) => {
130
135
  this.append(viewer);
131
136
  if (configState) {
@@ -198,6 +203,16 @@ class LauncherController extends plattar_controller_1.PlattarController {
198
203
  if (!sceneID) {
199
204
  throw new Error("LauncherController.initAR() - generated AR minimum required attributes not set, use scene-id as a minimum");
200
205
  }
206
+ const graphID = this.getAttribute("scene-graph-id");
207
+ // use the scene-graph route if available
208
+ if (graphID) {
209
+ const configAR = new scene_graph_ar_1.SceneGraphAR({
210
+ useARBanner: this.getBooleanAttribute("show-ar-banner"),
211
+ id: graphID,
212
+ sceneID: sceneID
213
+ });
214
+ return configAR.init();
215
+ }
201
216
  const configAR = new configurator_ar_1.ConfiguratorAR({ state: await this.getConfiguratorState(), useARBanner: this.getBooleanAttribute("show-ar-banner") });
202
217
  return configAR.init();
203
218
  }
@@ -171,6 +171,7 @@ class PlattarController {
171
171
  const variationSKU = this.getAttribute("variation-sku");
172
172
  const arMode = this.getAttribute("ar-mode");
173
173
  const showBanner = this.getAttribute("show-ar-banner");
174
+ const sceneGraphID = this.getAttribute("scene-graph-id");
174
175
  try {
175
176
  configState = (await this.getConfiguratorState()).state.encode();
176
177
  }
@@ -205,6 +206,9 @@ class PlattarController {
205
206
  if (showBanner) {
206
207
  dst += "&show_ar_banner=" + showBanner;
207
208
  }
209
+ if (sceneGraphID) {
210
+ dst += "&scene_graph_id" + sceneGraphID;
211
+ }
208
212
  viewer.setAttribute("url", opt.url || dst);
209
213
  this._state = ControllerState.QRCode;
210
214
  this._prevQROpt = opt;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.180.1";
1
+ declare const _default: "1.183.1";
2
2
  export default _default;
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = "1.180.1";
3
+ exports.default = "1.183.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.180.1",
3
+ "version": "1.183.1",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -41,14 +41,14 @@
41
41
  "@plattar/plattar-api": "^1.178.1",
42
42
  "@plattar/plattar-qrcode": "1.178.1",
43
43
  "@plattar/plattar-services": "^1.157.1",
44
- "@plattar/plattar-web": "^1.178.2"
44
+ "@plattar/plattar-web": "^1.182.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.25.9",
48
- "@babel/core": "^7.26.0",
49
- "@babel/preset-env": "^7.26.0",
47
+ "@babel/cli": "^7.26.4",
48
+ "@babel/core": "^7.26.9",
49
+ "@babel/preset-env": "^7.26.9",
50
50
  "browserify": "^17.0.1",
51
- "typescript": "^5.7.2",
51
+ "typescript": "^5.7.3",
52
52
  "uglify-js": "^3.19.3"
53
53
  },
54
54
  "publishConfig": {