@plattar/plattar-ar-adapter 1.188.2 → 1.188.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.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ConfiguratorAR = void 0;
7
7
  const plattar_analytics_1 = require("@plattar/plattar-analytics");
8
8
  const plattar_api_1 = require("@plattar/plattar-api");
9
- const plattar_services_1 = require("@plattar/plattar-services");
10
9
  const util_1 = require("../util/util");
11
10
  const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
12
11
  const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
@@ -58,31 +57,30 @@ class ConfiguratorAR extends launcher_ar_1.LauncherAR {
58
57
  * an AR File
59
58
  */
60
59
  async _Compose(output) {
61
- const objects = this._options.state.state.array();
62
- if (objects.length <= 0) {
63
- throw new Error("ConfiguratorAR.Compose() - cannot proceed as scene does not contain AR components");
64
- }
65
- // define our configurator
66
- const configurator = new plattar_services_1.Configurator();
67
- configurator.server = plattar_api_1.Server.location().type;
68
- configurator.output = output;
69
- let totalARObjectCount = 0;
70
- objects.forEach((object) => {
71
- if (object.meta_data.augment) {
72
- if (object.meta_data.type === "scenemodel") {
73
- configurator.addModel(object.scene_product_id);
74
- }
75
- else {
76
- configurator.addSceneProduct(object.scene_product_id, object.product_variation_id);
77
- }
78
- totalARObjectCount++;
60
+ const type = output === 'glb' ? "viewer" : "reality";
61
+ const url = `https://xrutils.plattar.com/v3/scene/${this._options.state.scene.id}/${type}`;
62
+ // grab our existing scene-graph from the saved API
63
+ try {
64
+ const response = await fetch(url, {
65
+ method: "POST",
66
+ headers: {
67
+ "Content-Type": "application/json"
68
+ },
69
+ body: JSON.stringify({
70
+ data: {
71
+ attributes: this._options.state.state.sceneGraph
72
+ }
73
+ })
74
+ });
75
+ if (!response.ok) {
76
+ throw new Error(`ConfiguratorAR - Fetching Existing Graph Error - network response was not ok ${response.status}`);
79
77
  }
80
- });
81
- if (totalARObjectCount <= 0) {
82
- throw new Error("ConfiguratorAR.Compose() - cannot proceed as scene does not contain any enabled AR components");
78
+ const data = await response.json();
79
+ return data.data.attributes.url;
80
+ }
81
+ catch (error) {
82
+ throw new Error(`ConfiguratorAR - Fetching Existing Graph Error - there was a request error to ${url}, error was ${error.message}`);
83
83
  }
84
- const results = await configurator.get();
85
- return results.filename;
86
84
  }
87
85
  /**
88
86
  * Initialise the SceneAR instance. This returns a Promise that resolves
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import { LauncherAR } from "../../ar/launcher-ar";
2
2
  import { DecodedConfiguratorState } from "../../util/configurator-state";
3
- import { PlattarController } from "./plattar-controller";
3
+ import { PlattarController, QRCodeOptions } from "./plattar-controller";
4
4
  /**
5
5
  * Manages an instance of the <plattar-configurator> HTML Element
6
6
  */
@@ -9,7 +9,7 @@ export declare class ConfiguratorController extends PlattarController {
9
9
  getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
10
  onAttributesUpdated(attributeName: string): Promise<void>;
11
11
  startARQRCode(options: any): Promise<HTMLElement>;
12
- startViewerQRCode(options: any): Promise<HTMLElement>;
12
+ startViewerQRCode(options: QRCodeOptions): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
14
  initAR(): Promise<LauncherAR>;
15
15
  /**
@@ -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
  */
@@ -89,8 +90,11 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
89
90
  return super.startARQRCode(options);
90
91
  }
91
92
  async startViewerQRCode(options) {
93
+ const opt = this._GetDefaultQROptions(options);
92
94
  // remove the old renderer instance if any
93
- this.removeRenderer();
95
+ if (!opt.detached) {
96
+ this.removeRenderer();
97
+ }
94
98
  const sceneID = this.getAttribute("scene-id");
95
99
  if (!sceneID) {
96
100
  throw new Error("ConfiguratorController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
@@ -120,9 +124,10 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
120
124
  // config state is not available
121
125
  configState = null;
122
126
  }
123
- const opt = options || this._GetDefaultQROptions();
124
127
  const viewer = document.createElement("plattar-qrcode");
125
- this._element = viewer;
128
+ if (!opt.detached) {
129
+ this._element = viewer;
130
+ }
126
131
  // required attributes with defaults for plattar-viewer node
127
132
  const width = this.getAttribute("width") || "500px";
128
133
  const height = this.getAttribute("height") || "500px";
@@ -142,6 +147,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
142
147
  const showAR = this.getAttribute("show-ar");
143
148
  const showUI = this.getAttribute("show-ui");
144
149
  const showBanner = this.getAttribute("show-ar-banner");
150
+ const sceneGraphID = this.getAttribute("scene-graph-id");
145
151
  if (showUI && showUI === "true") {
146
152
  dst = plattar_api_1.Server.location().base + "configurator/dist/index.html?scene_id=" + sceneID;
147
153
  }
@@ -154,14 +160,22 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
154
160
  if (showBanner) {
155
161
  dst += "&show_ar_banner=" + showBanner;
156
162
  }
163
+ if (sceneGraphID) {
164
+ dst += "&scene_graph_id=" + sceneGraphID;
165
+ }
157
166
  viewer.setAttribute("url", opt.url || dst);
158
- this._state = plattar_controller_1.ControllerState.QRCode;
159
167
  this._prevQROpt = opt;
168
+ if (!opt.detached) {
169
+ this._state = plattar_controller_1.ControllerState.QRCode;
170
+ return new Promise((accept, reject) => {
171
+ viewer.onload = () => {
172
+ return accept(viewer);
173
+ };
174
+ this.append(viewer);
175
+ });
176
+ }
160
177
  return new Promise((accept, reject) => {
161
- viewer.onload = () => {
162
- return accept(viewer);
163
- };
164
- this.append(viewer);
178
+ return accept(viewer);
165
179
  });
166
180
  }
167
181
  async startRenderer() {
@@ -293,6 +307,16 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
293
307
  if (!sceneID) {
294
308
  throw new Error("VTOController.initAR() - generated AR minimum required attributes not set, use scene-id as a minimum");
295
309
  }
310
+ const graphID = this.getAttribute("scene-graph-id");
311
+ // use the scene-graph route if available
312
+ if (graphID) {
313
+ const configAR = new scene_graph_ar_1.SceneGraphAR({
314
+ useARBanner: this.getBooleanAttribute("show-ar-banner"),
315
+ id: graphID,
316
+ sceneID: sceneID
317
+ });
318
+ return configAR.init();
319
+ }
296
320
  const configAR = new configurator_ar_1.ConfiguratorAR({ state: await this.getConfiguratorState(), useARBanner: this.getBooleanAttribute("show-ar-banner") });
297
321
  return configAR.init();
298
322
  }
@@ -1,6 +1,6 @@
1
1
  import { LauncherAR } from "../../ar/launcher-ar";
2
2
  import { DecodedConfiguratorState } from "../../util/configurator-state";
3
- import { PlattarController } from "./plattar-controller";
3
+ import { PlattarController, QRCodeOptions } from "./plattar-controller";
4
4
  /**
5
5
  * Manages an instance of the <plattar-configurator> HTML Element
6
6
  */
@@ -8,7 +8,7 @@ export declare class GalleryController extends PlattarController {
8
8
  private _cachedConfigState;
9
9
  getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
10
  onAttributesUpdated(attributeName: string): Promise<void>;
11
- startViewerQRCode(options: any): Promise<HTMLElement>;
11
+ startViewerQRCode(options: QRCodeOptions): Promise<HTMLElement>;
12
12
  startRenderer(): Promise<HTMLElement>;
13
13
  initAR(): Promise<LauncherAR>;
14
14
  get element(): HTMLElement | null;
@@ -43,15 +43,19 @@ class GalleryController extends plattar_controller_1.PlattarController {
43
43
  }
44
44
  }
45
45
  async startViewerQRCode(options) {
46
+ const opt = this._GetDefaultQROptions(options);
46
47
  // remove the old renderer instance if any
47
- this.removeRenderer();
48
+ if (!opt.detached) {
49
+ this.removeRenderer();
50
+ }
48
51
  const sceneID = this.getAttribute("scene-id");
49
52
  if (!sceneID) {
50
53
  throw new Error("GalleryController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
51
54
  }
52
- const opt = options || this._GetDefaultQROptions();
53
55
  const viewer = document.createElement("plattar-qrcode");
54
- this._element = viewer;
56
+ if (!opt.detached) {
57
+ this._element = viewer;
58
+ }
55
59
  // required attributes with defaults for plattar-viewer node
56
60
  const width = this.getAttribute("width") || "500px";
57
61
  const height = this.getAttribute("height") || "500px";
@@ -69,13 +73,18 @@ class GalleryController extends plattar_controller_1.PlattarController {
69
73
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
70
74
  const dst = plattar_api_1.Server.location().base + "renderer/gallery.html?scene_id=" + sceneID;
71
75
  viewer.setAttribute("url", opt.url || dst);
72
- this._state = plattar_controller_1.ControllerState.QRCode;
73
76
  this._prevQROpt = opt;
77
+ if (!opt.detached) {
78
+ this._state = plattar_controller_1.ControllerState.QRCode;
79
+ return new Promise((accept, reject) => {
80
+ viewer.onload = () => {
81
+ return accept(viewer);
82
+ };
83
+ this.append(viewer);
84
+ });
85
+ }
74
86
  return new Promise((accept, reject) => {
75
- viewer.onload = () => {
76
- return accept(viewer);
77
- };
78
- this.append(viewer);
87
+ return accept(viewer);
79
88
  });
80
89
  }
81
90
  async startRenderer() {
@@ -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";
@@ -120,10 +122,18 @@ class LauncherController extends plattar_controller_1.PlattarController {
120
122
  if (showBanner) {
121
123
  viewer.setAttribute("show-ar-banner", showBanner);
122
124
  }
123
- if (configState) {
124
- const encodedState = configState.state.encode();
125
- if (encodedState.length < 6000) {
126
- viewer.setAttribute("config-state", encodedState);
125
+ if (sceneGraphID) {
126
+ viewer.setAttribute("scene-graph-id", sceneGraphID);
127
+ }
128
+ else {
129
+ try {
130
+ const sceneGraphID = await (await this.getConfiguratorState()).state.encodeSceneGraphID();
131
+ viewer.setAttribute("scene-graph-id", sceneGraphID);
132
+ }
133
+ catch (_err) {
134
+ // scene graph ID not available for some reason
135
+ // we will generate a new one
136
+ console.error(_err);
127
137
  }
128
138
  }
129
139
  return new Promise((accept, reject) => {
@@ -198,6 +208,16 @@ class LauncherController extends plattar_controller_1.PlattarController {
198
208
  if (!sceneID) {
199
209
  throw new Error("LauncherController.initAR() - generated AR minimum required attributes not set, use scene-id as a minimum");
200
210
  }
211
+ const graphID = this.getAttribute("scene-graph-id");
212
+ // use the scene-graph route if available
213
+ if (graphID) {
214
+ const configAR = new scene_graph_ar_1.SceneGraphAR({
215
+ useARBanner: this.getBooleanAttribute("show-ar-banner"),
216
+ id: graphID,
217
+ sceneID: sceneID
218
+ });
219
+ return configAR.init();
220
+ }
201
221
  const configAR = new configurator_ar_1.ConfiguratorAR({ state: await this.getConfiguratorState(), useARBanner: this.getBooleanAttribute("show-ar-banner") });
202
222
  return configAR.init();
203
223
  }
@@ -6,6 +6,14 @@ export declare enum ControllerState {
6
6
  Renderer = 1,
7
7
  QRCode = 2
8
8
  }
9
+ export interface QRCodeOptions {
10
+ readonly color: string;
11
+ readonly qrType: string;
12
+ readonly shorten: boolean;
13
+ readonly margin: number;
14
+ readonly detached: boolean;
15
+ readonly url?: string | null;
16
+ }
9
17
  /**
10
18
  * All Plattar Controllers are derived from the same interface
11
19
  */
@@ -13,7 +21,7 @@ export declare abstract class PlattarController {
13
21
  /**
14
22
  * Default QR Code rendering options
15
23
  */
16
- protected _GetDefaultQROptions(): any;
24
+ protected _GetDefaultQROptions(opt?: QRCodeOptions | undefined | null): QRCodeOptions;
17
25
  private readonly _parent;
18
26
  protected _state: ControllerState;
19
27
  protected _element: HTMLElement | null;
@@ -56,19 +64,19 @@ export declare abstract class PlattarController {
56
64
  * Start Rendering a QR Code with the provided options
57
65
  * @param options (optional) - The QR Code Options
58
66
  */
59
- abstract startViewerQRCode(options: any | undefined | null): Promise<HTMLElement>;
67
+ abstract startViewerQRCode(options: QRCodeOptions | undefined | null): Promise<HTMLElement>;
60
68
  /**
61
69
  * Decide which QR Code to render according to the qr-type attribute
62
70
  * @param options
63
71
  * @returns
64
72
  */
65
- startQRCode(options: any): Promise<HTMLElement>;
73
+ startQRCode(options: QRCodeOptions): Promise<HTMLElement>;
66
74
  /**
67
75
  * Displays a QR Code that sends the user direct to AR
68
76
  * @param options
69
77
  * @returns
70
78
  */
71
- startARQRCode(options: any): Promise<HTMLElement>;
79
+ startARQRCode(options: QRCodeOptions): Promise<HTMLElement>;
72
80
  /**
73
81
  * Initialise and return a launcher that can be used to start AR
74
82
  */
@@ -16,12 +16,15 @@ class PlattarController {
16
16
  /**
17
17
  * Default QR Code rendering options
18
18
  */
19
- _GetDefaultQROptions() {
19
+ _GetDefaultQROptions(opt = null) {
20
+ const options = opt ?? {};
20
21
  return {
21
- color: this.getAttribute("qr-color") || "#101721",
22
- qrType: this.getAttribute("qr-style") || "default",
23
- shorten: this.getAttribute("qr-shorten") || true,
24
- margin: 0
22
+ color: options.color ?? (this.getAttribute("qr-color") || "#101721"),
23
+ qrType: options.qrType ?? (this.getAttribute("qr-style") || "default"),
24
+ shorten: options.shorten ?? (this.getBooleanAttribute("qr-shorten") || true),
25
+ margin: options.margin ?? 0,
26
+ detached: options.detached ?? (this.getBooleanAttribute("qr-detached") || false),
27
+ url: options.url ?? null
25
28
  };
26
29
  }
27
30
  ;
@@ -140,11 +143,13 @@ class PlattarController {
140
143
  * @returns
141
144
  */
142
145
  async startARQRCode(options) {
143
- // remove the old renderer instance if any
144
- this.removeRenderer();
145
- const opt = options || this._GetDefaultQROptions();
146
+ const opt = this._GetDefaultQROptions(options);
146
147
  const viewer = document.createElement("plattar-qrcode");
147
- this._element = viewer;
148
+ // remove the old renderer instance if any
149
+ if (!opt.detached) {
150
+ this.removeRenderer();
151
+ this._element = viewer;
152
+ }
148
153
  // required attributes with defaults for plattar-viewer node
149
154
  const width = this.getAttribute("width") || "500px";
150
155
  const height = this.getAttribute("height") || "500px";
@@ -154,7 +159,7 @@ class PlattarController {
154
159
  viewer.setAttribute("color", opt.color);
155
160
  }
156
161
  if (opt.margin) {
157
- viewer.setAttribute("margin", "" + opt.margin);
162
+ viewer.setAttribute("margin", `${opt.margin}`);
158
163
  }
159
164
  if (opt.qrType) {
160
165
  viewer.setAttribute("qr-type", opt.qrType);
@@ -162,7 +167,7 @@ class PlattarController {
162
167
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
163
168
  const qrOptions = btoa(JSON.stringify(opt));
164
169
  let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
165
- let configState = null;
170
+ //let configState: string | null = null;
166
171
  const sceneID = this.getAttribute("scene-id");
167
172
  const embedType = this.getAttribute("embed-type");
168
173
  const productID = this.getAttribute("product-id");
@@ -171,16 +176,7 @@ class PlattarController {
171
176
  const variationSKU = this.getAttribute("variation-sku");
172
177
  const arMode = this.getAttribute("ar-mode");
173
178
  const showBanner = this.getAttribute("show-ar-banner");
174
- try {
175
- configState = (await this.getConfiguratorState()).state.encode();
176
- }
177
- catch (_err) {
178
- // config state not available for some reason
179
- configState = null;
180
- }
181
- if (configState) {
182
- dst += "&config_state=" + configState;
183
- }
179
+ const sceneGraphID = this.getAttribute("scene-graph-id");
184
180
  if (embedType) {
185
181
  dst += "&embed_type=" + embedType;
186
182
  }
@@ -205,14 +201,33 @@ class PlattarController {
205
201
  if (showBanner) {
206
202
  dst += "&show_ar_banner=" + showBanner;
207
203
  }
204
+ if (sceneGraphID) {
205
+ dst += "&scene_graph_id" + sceneGraphID;
206
+ }
207
+ else {
208
+ try {
209
+ const sceneGraphID = await (await this.getConfiguratorState()).state.encodeSceneGraphID();
210
+ dst += "&scene_graph_id=" + sceneGraphID;
211
+ }
212
+ catch (_err) {
213
+ // scene graph ID not available for some reason
214
+ // we will generate a new one
215
+ console.error(_err);
216
+ }
217
+ }
208
218
  viewer.setAttribute("url", opt.url || dst);
209
- this._state = ControllerState.QRCode;
210
219
  this._prevQROpt = opt;
220
+ if (!opt.detached) {
221
+ this._state = ControllerState.QRCode;
222
+ return new Promise((accept, reject) => {
223
+ this.append(viewer);
224
+ viewer.onload = () => {
225
+ return accept(viewer);
226
+ };
227
+ });
228
+ }
211
229
  return new Promise((accept, reject) => {
212
- this.append(viewer);
213
- viewer.onload = () => {
214
- return accept(viewer);
215
- };
230
+ return accept(viewer);
216
231
  });
217
232
  }
218
233
  /**
@@ -1,6 +1,6 @@
1
1
  import { LauncherAR } from "../../ar/launcher-ar";
2
2
  import { DecodedConfiguratorState } from "../../util/configurator-state";
3
- import { PlattarController } from "./plattar-controller";
3
+ import { PlattarController, QRCodeOptions } from "./plattar-controller";
4
4
  /**
5
5
  * Manages an instance of the <plattar-configurator> HTML Element
6
6
  */
@@ -8,7 +8,7 @@ export declare class VTOController extends PlattarController {
8
8
  private _cachedConfigState;
9
9
  getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
10
  onAttributesUpdated(attributeName: string): Promise<void>;
11
- startViewerQRCode(options: any): Promise<HTMLElement>;
11
+ startViewerQRCode(options: QRCodeOptions): Promise<HTMLElement>;
12
12
  startRenderer(): Promise<HTMLElement>;
13
13
  initAR(): Promise<LauncherAR>;
14
14
  /**