@plattar/plattar-ar-adapter 1.123.6 → 1.128.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.
@@ -12,6 +12,14 @@ export declare class ConfiguratorController extends PlattarController {
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
14
  initAR(): Promise<LauncherAR>;
15
+ /**
16
+ * Private Function - This launches the Static/Inherited AR Mode
17
+ */
18
+ private _InitARInherited;
19
+ /**
20
+ * Private Function - This launches the Dynamic/Generated AR Mode
21
+ */
22
+ private _InitARGenerated;
15
23
  removeRenderer(): boolean;
16
24
  get element(): HTMLElement | null;
17
25
  }
@@ -4,6 +4,9 @@ exports.ConfiguratorController = void 0;
4
4
  const plattar_api_1 = require("@plattar/plattar-api");
5
5
  const plattar_services_1 = require("@plattar/plattar-services");
6
6
  const raw_ar_1 = require("../../ar/raw-ar");
7
+ const scene_ar_1 = require("../../ar/scene-ar");
8
+ const scene_product_ar_1 = require("../../ar/scene-product-ar");
9
+ const configurator_state_1 = require("../../util/configurator-state");
7
10
  const util_1 = require("../../util/util");
8
11
  const plattar_controller_1 = require("./plattar-controller");
9
12
  /**
@@ -109,59 +112,103 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
109
112
  if (!util_1.Util.canAugment()) {
110
113
  return reject(new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context"));
111
114
  }
112
- // if scene ID is available and the state is a configurator viewer
113
- // we can use the real-time configurator state to launch the AR view
114
- const viewer = this.element;
115
- const sceneID = this.getAttribute("scene-id");
116
- if (viewer && sceneID) {
117
- let output = "glb";
118
- if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
119
- output = "usdz";
115
+ const arMode = this.getAttribute("ar-mode") || "generated";
116
+ switch (arMode.toLowerCase()) {
117
+ case "inherited":
118
+ this._InitARInherited(accept, reject);
119
+ return;
120
+ case "generated":
121
+ default:
122
+ this._InitARGenerated(accept, reject);
123
+ }
124
+ });
125
+ }
126
+ /**
127
+ * Private Function - This launches the Static/Inherited AR Mode
128
+ */
129
+ _InitARInherited(accept, reject) {
130
+ const sceneID = this.getAttribute("scene-id");
131
+ const configState = this.getAttribute("config-state");
132
+ // use config-state if its available
133
+ if (sceneID && configState) {
134
+ const state = configurator_state_1.ConfiguratorState.decode(configState);
135
+ const first = state.first();
136
+ if (first) {
137
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
138
+ sceneProductAR.init().then(accept).catch(reject);
139
+ return;
140
+ }
141
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
142
+ }
143
+ // otherwise fallback to using scene
144
+ if (sceneID) {
145
+ configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
146
+ const first = state.first();
147
+ if (first) {
148
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
149
+ return sceneProductAR.init().then(accept).catch(reject);
120
150
  }
121
- return viewer.messenger.getARFile(output).then((result) => {
122
- const rawAR = new raw_ar_1.RawAR(result.filename);
123
- return rawAR.init().then(accept).catch(reject);
124
- }).catch(reject);
151
+ return reject(new Error("ConfiguratorController.initAR() - invalid Scene does not have any product states"));
152
+ }).catch(reject);
153
+ return;
154
+ }
155
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
156
+ }
157
+ /**
158
+ * Private Function - This launches the Dynamic/Generated AR Mode
159
+ */
160
+ _InitARGenerated(accept, reject) {
161
+ // if scene ID is available and the state is a configurator viewer
162
+ // we can use the real-time configurator state to launch the AR view
163
+ const viewer = this.element;
164
+ const sceneID = this.getAttribute("scene-id");
165
+ if (viewer && sceneID && viewer.messenger) {
166
+ let output = "glb";
167
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
168
+ output = "usdz";
125
169
  }
126
- const configState = this.getAttribute("config-state");
127
- // otherwise scene ID is available to the viewer is not launched
128
- // we can use the static configuration state to launch the AR view
129
- if (sceneID && configState) {
130
- try {
131
- const decodedb64State = atob(configState);
132
- const state = JSON.parse(decodedb64State);
133
- if (state.meta) {
134
- const sceneProductIndex = state.meta.scene_product_index || 0;
135
- const variationIndex = state.meta.product_variation_index || 1;
136
- const states = state.states || [];
137
- if (states.length > 0) {
138
- const configurator = new plattar_services_1.Configurator();
139
- states.forEach((productState) => {
140
- configurator.addSceneProduct(productState[sceneProductIndex], productState[variationIndex]);
141
- });
142
- if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
143
- configurator.output = "usdz";
144
- }
145
- if (util_1.Util.canSceneViewer()) {
146
- configurator.output = "glb";
147
- }
148
- const server = this.getAttribute("server") || "production";
149
- configurator.server = server;
150
- return configurator.get().then((result) => {
151
- const rawAR = new raw_ar_1.RawAR(result.filename);
152
- rawAR.init().then(accept).catch(reject);
153
- }).catch(reject);
154
- }
155
- return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
156
- }
157
- return reject(new Error("ConfiguratorController.initAR() - invalid config-state for configurator"));
170
+ viewer.messenger.getARFile(output).then((result) => {
171
+ const rawAR = new raw_ar_1.RawAR(result.filename);
172
+ return rawAR.init().then(accept).catch(reject);
173
+ }).catch(reject);
174
+ return;
175
+ }
176
+ const configState = this.getAttribute("config-state");
177
+ // otherwise scene ID is available to the viewer is not launched
178
+ // we can use the static configuration state to launch the AR view
179
+ if (sceneID && configState) {
180
+ const state = configurator_state_1.ConfiguratorState.decode(configState);
181
+ if (state.length > 0) {
182
+ const server = this.getAttribute("server") || "production";
183
+ const configurator = new plattar_services_1.Configurator();
184
+ configurator.server = server;
185
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
186
+ configurator.output = "usdz";
158
187
  }
159
- catch (err) {
160
- return reject(err);
188
+ if (util_1.Util.canSceneViewer()) {
189
+ configurator.output = "glb";
161
190
  }
191
+ state.forEach((productState) => {
192
+ if (productState.meta_data.augment === true) {
193
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
194
+ }
195
+ });
196
+ configurator.get().then((result) => {
197
+ const rawAR = new raw_ar_1.RawAR(result.filename);
198
+ rawAR.init().then(accept).catch(reject);
199
+ }).catch(reject);
200
+ return;
162
201
  }
163
- return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
164
- });
202
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
203
+ }
204
+ // otherwise no config-state or viewer is active
205
+ // fallback to using default SceneAR implementation
206
+ if (sceneID) {
207
+ const sceneAR = new scene_ar_1.SceneAR(sceneID);
208
+ sceneAR.init().then(accept).catch(reject);
209
+ return;
210
+ }
211
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
165
212
  }
166
213
  removeRenderer() {
167
214
  if (this._element) {
@@ -58,10 +58,14 @@ class ProductController extends plattar_controller_1.PlattarController {
58
58
  }
59
59
  // optional attributes
60
60
  const variationID = this.getAttribute("variation-id");
61
+ const showAR = this.getAttribute("show-ar");
61
62
  let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
62
63
  if (variationID) {
63
64
  dst += "&variation_id=" + variationID;
64
65
  }
66
+ if (showAR) {
67
+ dst += "&show_ar=" + showAR;
68
+ }
65
69
  viewer.setAttribute("url", opt.url || dst);
66
70
  viewer.onload = () => {
67
71
  return accept(viewer);
@@ -92,9 +96,13 @@ class ProductController extends plattar_controller_1.PlattarController {
92
96
  viewer.setAttribute("product-id", productID);
93
97
  // optional attributes
94
98
  const variationID = this.getAttribute("variation-id");
99
+ const showAR = this.getAttribute("show-ar");
95
100
  if (variationID) {
96
101
  viewer.setAttribute("variation-id", variationID);
97
102
  }
103
+ if (showAR) {
104
+ viewer.setAttribute("show-ar", showAR);
105
+ }
98
106
  viewer.onload = () => {
99
107
  return accept(viewer);
100
108
  };
@@ -4,6 +4,7 @@ exports.ViewerController = void 0;
4
4
  const plattar_api_1 = require("@plattar/plattar-api");
5
5
  const product_ar_1 = require("../../ar/product-ar");
6
6
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
7
+ const configurator_state_1 = require("../../util/configurator-state");
7
8
  const util_1 = require("../../util/util");
8
9
  const plattar_controller_1 = require("./plattar-controller");
9
10
  /**
@@ -62,12 +63,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
62
63
  // optional attributes
63
64
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
64
65
  const variationID = this.getAttribute("variation-id");
66
+ const showAR = this.getAttribute("show-ar");
65
67
  if (productID) {
66
68
  dst += "&productId=" + productID;
67
69
  }
68
70
  if (variationID) {
69
71
  dst += "&variationId=" + variationID;
70
72
  }
73
+ if (showAR) {
74
+ dst += "&show_ar=" + showAR;
75
+ }
71
76
  viewer.setAttribute("url", opt.url || dst);
72
77
  viewer.onload = () => {
73
78
  return accept(viewer);
@@ -99,12 +104,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
99
104
  // optional attributes
100
105
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
101
106
  const variationID = this.getAttribute("variation-id");
107
+ const showAR = this.getAttribute("show-ar");
102
108
  if (productID) {
103
109
  viewer.setAttribute("product-id", productID);
104
110
  }
105
111
  if (variationID) {
106
112
  viewer.setAttribute("variation-id", variationID);
107
113
  }
114
+ if (showAR) {
115
+ viewer.setAttribute("show-ar", showAR);
116
+ }
108
117
  viewer.onload = () => {
109
118
  return accept(viewer);
110
119
  };
@@ -136,11 +145,18 @@ class ViewerController extends plattar_controller_1.PlattarController {
136
145
  return product.init().then(accept).catch(reject);
137
146
  }
138
147
  const sceneID = this.getAttribute("scene-id");
139
- // otherwise, scene was set so use SceneAR
148
+ // use the first default product-variation id if available
140
149
  if (sceneID) {
141
- return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id or scene-product-id"));
150
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
151
+ const first = state.first();
152
+ if (first) {
153
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
154
+ return sceneProductAR.init().then(accept).catch(reject);
155
+ }
156
+ return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
157
+ }).catch(reject);
142
158
  }
143
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use product-id or scene-product-id as a minimum"));
159
+ return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
144
160
  });
145
161
  }
146
162
  removeRenderer() {
@@ -12,6 +12,14 @@ export declare class VTOController extends PlattarController {
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
14
  initAR(): Promise<LauncherAR>;
15
+ /**
16
+ * Private Function - This launches the Static/Inherited AR Mode
17
+ */
18
+ private _InitARInherited;
19
+ /**
20
+ * Private Function - This launches the Dynamic/Generated AR Mode
21
+ */
22
+ private _InitARGenerated;
15
23
  removeRenderer(): boolean;
16
24
  get element(): HTMLElement | null;
17
25
  }
@@ -113,46 +113,94 @@ class VTOController extends plattar_controller_1.PlattarController {
113
113
  if (!(util_1.Util.isSafari() || util_1.Util.isChromeOnIOS())) {
114
114
  return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR only available on IOS Mobile devices"));
115
115
  }
116
- // if scene ID is available and the state is a configurator viewer
117
- // we can use the real-time configurator state to launch the AR view
118
- const viewer = this.element;
119
- const sceneID = this.getAttribute("scene-id");
120
- if (viewer && sceneID) {
121
- return viewer.messenger.getARFile("vto").then((result) => {
122
- const rawAR = new raw_ar_1.RawAR(result.filename);
123
- return rawAR.init().then(accept).catch(reject);
124
- }).catch(reject);
116
+ const arMode = this.getAttribute("ar-mode") || "generated";
117
+ switch (arMode.toLowerCase()) {
118
+ case "inherited":
119
+ this._InitARInherited(accept, reject);
120
+ return;
121
+ case "generated":
122
+ default:
123
+ this._InitARGenerated(accept, reject);
125
124
  }
126
- const configState = this.getAttribute("config-state");
127
- // otherwise scene ID is available to the viewer is not launched
128
- // we can use the static configuration state to launch the AR view
129
- if (sceneID && configState) {
130
- const state = __1.ConfiguratorState.decode(configState);
131
- if (state.length > 0) {
132
- const server = this.getAttribute("server") || "production";
133
- const configurator = new plattar_services_1.Configurator();
134
- configurator.server = server;
135
- configurator.output = "vto";
136
- state.forEach((productState) => {
137
- if (productState.meta_data.augment === true) {
138
- configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
139
- }
140
- });
141
- return configurator.get().then((result) => {
142
- const rawAR = new raw_ar_1.RawAR(result.filename);
143
- rawAR.init().then(accept).catch(reject);
144
- }).catch(reject);
145
- }
146
- return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
125
+ });
126
+ }
127
+ /**
128
+ * Private Function - This launches the Static/Inherited AR Mode
129
+ */
130
+ _InitARInherited(accept, reject) {
131
+ const sceneID = this.getAttribute("scene-id");
132
+ const configState = this.getAttribute("config-state");
133
+ // use config-state if its available
134
+ if (sceneID && configState) {
135
+ const state = __1.ConfiguratorState.decode(configState);
136
+ const first = state.first();
137
+ if (first) {
138
+ const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
139
+ sceneProductAR.init().then(accept).catch(reject);
140
+ return;
147
141
  }
148
- // otherwise no config-state or viewer is active
149
- // fallback to using default SceneAR implementation
150
- if (sceneID) {
151
- const sceneAR = new __1.SceneAR(sceneID);
152
- return sceneAR.init().then(accept).catch(reject);
142
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
143
+ }
144
+ // otherwise fallback to using scene
145
+ if (sceneID) {
146
+ __1.ConfiguratorState.decodeScene(sceneID).then((state) => {
147
+ const first = state.first();
148
+ if (first) {
149
+ const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
150
+ return sceneProductAR.init().then(accept).catch(reject);
151
+ }
152
+ return reject(new Error("VTOController.initAR() - invalid Scene does not have any product states"));
153
+ }).catch(reject);
154
+ return;
155
+ }
156
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
157
+ }
158
+ /**
159
+ * Private Function - This launches the Dynamic/Generated AR Mode
160
+ */
161
+ _InitARGenerated(accept, reject) {
162
+ // if scene ID is available and the state is a configurator viewer
163
+ // we can use the real-time configurator state to launch the AR view
164
+ const viewer = this.element;
165
+ const sceneID = this.getAttribute("scene-id");
166
+ if (viewer && sceneID && viewer.messenger) {
167
+ viewer.messenger.getARFile("vto").then((result) => {
168
+ const rawAR = new raw_ar_1.RawAR(result.filename);
169
+ return rawAR.init().then(accept).catch(reject);
170
+ }).catch(reject);
171
+ return;
172
+ }
173
+ const configState = this.getAttribute("config-state");
174
+ // otherwise scene ID is available to the viewer is not launched
175
+ // we can use the static configuration state to launch the AR view
176
+ if (sceneID && configState) {
177
+ const state = __1.ConfiguratorState.decode(configState);
178
+ if (state.length > 0) {
179
+ const server = this.getAttribute("server") || "production";
180
+ const configurator = new plattar_services_1.Configurator();
181
+ configurator.server = server;
182
+ configurator.output = "vto";
183
+ state.forEach((productState) => {
184
+ if (productState.meta_data.augment === true) {
185
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
186
+ }
187
+ });
188
+ configurator.get().then((result) => {
189
+ const rawAR = new raw_ar_1.RawAR(result.filename);
190
+ rawAR.init().then(accept).catch(reject);
191
+ }).catch(reject);
192
+ return;
153
193
  }
154
- return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
155
- });
194
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
195
+ }
196
+ // otherwise no config-state or viewer is active
197
+ // fallback to using default SceneAR implementation
198
+ if (sceneID) {
199
+ const sceneAR = new __1.SceneAR(sceneID);
200
+ sceneAR.init().then(accept).catch(reject);
201
+ return;
202
+ }
203
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
156
204
  }
157
205
  removeRenderer() {
158
206
  if (this._element) {
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -8,6 +8,14 @@ export interface SceneProductData {
8
8
  export declare class ConfiguratorState {
9
9
  private readonly _state;
10
10
  constructor(state?: string | null | undefined);
11
+ /**
12
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
13
+ *
14
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
15
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
16
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
17
+ */
18
+ setSceneProduct(sceneProductID: string, productVariationID: string, metaData?: any | null | undefined): void;
11
19
  /**
12
20
  * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
13
21
  *
@@ -16,11 +24,44 @@ export declare class ConfiguratorState {
16
24
  * @param metaData - Arbitrary meta-data that can be used against certain operaions
17
25
  */
18
26
  addSceneProduct(sceneProductID: string, productVariationID: string, metaData?: any | null | undefined): void;
27
+ /**
28
+ * Search and return the data index reference for the provided Scene Product ID
29
+ * if not found, will return null
30
+ * @param sceneProductID
31
+ */
32
+ findSceneProductIndex(sceneProductID: string): any[] | null;
33
+ /**
34
+ * Search and return the data for the provided Scene Product ID
35
+ * if not found, will return null
36
+ * @param sceneProductID
37
+ */
38
+ findSceneProduct(sceneProductID: string): SceneProductData | null;
19
39
  /**
20
40
  * Iterate over the internal state data
21
41
  */
22
42
  forEach(callback: (data: SceneProductData) => void): void;
43
+ /**
44
+ * @returns Returns the first reference of data in the stack, otherwise returns null
45
+ */
46
+ first(): SceneProductData | null;
23
47
  get length(): number;
48
+ /**
49
+ * Decodes and returns an instance of ConfiguratorState from a previously
50
+ * encoded state
51
+ * @param state - The previously encoded state as a Base64 String
52
+ * @returns - ConfiguratorState instance
53
+ */
24
54
  static decode(state: string): ConfiguratorState;
55
+ /**
56
+ * Generates a new ConfiguratorState instance from all SceneProducts and default
57
+ * variations from the provided Scene ID
58
+ * @param sceneID - the Scene ID to generate
59
+ * @returns - Promise that resolves into a ConfiguratorState instance
60
+ */
61
+ static decodeScene(sceneID?: string | null | undefined): Promise<ConfiguratorState>;
62
+ /**
63
+ * Encode and return the internal ConfiguratorState as a Base64 String
64
+ * @returns - Base64 String
65
+ */
25
66
  encode(): string;
26
67
  }