@plattar/plattar-ar-adapter 1.123.1 → 1.123.2

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.
@@ -1,6 +1,13 @@
1
1
  export declare abstract class LauncherAR {
2
2
  constructor();
3
3
  abstract init(): Promise<LauncherAR>;
4
- abstract launch(): Promise<void>;
5
4
  abstract start(): void;
5
+ abstract canQuicklook(): boolean;
6
+ abstract canRealityViewer(): boolean;
7
+ abstract canSceneViewer(): boolean;
8
+ /**
9
+ * Initialise and launch with a single function call. this is mostly for convenience.
10
+ * Use .init() and .start() separately for fine-grained control
11
+ */
12
+ launch(): Promise<void>;
6
13
  }
@@ -3,5 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LauncherAR = void 0;
4
4
  class LauncherAR {
5
5
  constructor() { }
6
+ /**
7
+ * Initialise and launch with a single function call. this is mostly for convenience.
8
+ * Use .init() and .start() separately for fine-grained control
9
+ */
10
+ launch() {
11
+ return new Promise((accept, reject) => {
12
+ this.init().then((value) => {
13
+ value.start();
14
+ return accept();
15
+ }).catch(reject);
16
+ });
17
+ }
6
18
  }
7
19
  exports.LauncherAR = LauncherAR;
@@ -17,11 +17,6 @@ export declare class ModelAR extends LauncherAR {
17
17
  * cannot be performed.
18
18
  */
19
19
  init(): Promise<LauncherAR>;
20
- /**
21
- * Initialise and launch with a single function call. this is mostly for convenience.
22
- * Use .init() and .start() separately for fine-grained control
23
- */
24
- launch(): Promise<void>;
25
20
  /**
26
21
  * Launches the internal AR instance using an appropriate version of AR Viewers
27
22
  */
@@ -35,6 +35,7 @@ class ModelAR extends launcher_ar_1.LauncherAR {
35
35
  if (project) {
36
36
  analytics = new plattar_analytics_1.Analytics(project.id);
37
37
  analytics.origin = plattar_api_1.Server.location().type;
38
+ analytics.data.push("type", "model-ar");
38
39
  analytics.data.push("applicationId", project.id);
39
40
  analytics.data.push("applicationTitle", project.attributes.title);
40
41
  analytics.data.push("modelId", model.id);
@@ -89,18 +90,6 @@ class ModelAR extends launcher_ar_1.LauncherAR {
89
90
  }).catch(reject);
90
91
  });
91
92
  }
92
- /**
93
- * Initialise and launch with a single function call. this is mostly for convenience.
94
- * Use .init() and .start() separately for fine-grained control
95
- */
96
- launch() {
97
- return new Promise((accept, reject) => {
98
- this.init().then((value) => {
99
- value.start();
100
- return accept();
101
- }).catch(reject);
102
- });
103
- }
104
93
  /**
105
94
  * Launches the internal AR instance using an appropriate version of AR Viewers
106
95
  */
@@ -10,7 +10,7 @@ export declare class ProductAR extends LauncherAR {
10
10
  constructor(productID?: string | undefined | null, variationID?: string | undefined | null);
11
11
  get productID(): string;
12
12
  get variationID(): string;
13
- private _setupAnalytics;
13
+ private _SetupAnalytics;
14
14
  /**
15
15
  * Initialise the ProductAR instance. This returns a Promise that resolves
16
16
  * successfully if initialisation is successful, otherwise it will fail.
@@ -19,11 +19,6 @@ export declare class ProductAR extends LauncherAR {
19
19
  * cannot be performed.
20
20
  */
21
21
  init(): Promise<LauncherAR>;
22
- /**
23
- * Initialise and launch with a single function call. this is mostly for convenience.
24
- * Use .init() and .start() separately for fine-grained control
25
- */
26
- launch(): Promise<void>;
27
22
  /**
28
23
  * Launches the internal AR instance using an appropriate version of AR Viewers
29
24
  */
@@ -32,7 +32,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
32
32
  get variationID() {
33
33
  return this._variationID;
34
34
  }
35
- _setupAnalytics(product, variation) {
35
+ _SetupAnalytics(product, variation) {
36
36
  let analytics = null;
37
37
  const scene = product.relationships.find(plattar_api_1.Scene);
38
38
  // setup scene stuff (if any)
@@ -40,6 +40,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
40
40
  analytics = new plattar_analytics_1.Analytics(scene.attributes.application_id);
41
41
  analytics.origin = plattar_api_1.Server.location().type;
42
42
  this._analytics = analytics;
43
+ analytics.data.push("type", "product-ar");
43
44
  analytics.data.push("sceneId", scene.id);
44
45
  analytics.data.push("sceneTitle", scene.attributes.title);
45
46
  const application = scene.relationships.find(plattar_api_1.Project);
@@ -100,7 +101,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
100
101
  if (!model) {
101
102
  return reject(new Error("ProductAR.init() - cannot proceed as ModelFile for selected variation is corrupt"));
102
103
  }
103
- this._setupAnalytics(product, variation);
104
+ this._SetupAnalytics(product, variation);
104
105
  // we need to define our AR module here
105
106
  // we are in Safari/Quicklook mode here
106
107
  if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
@@ -131,18 +132,6 @@ class ProductAR extends launcher_ar_1.LauncherAR {
131
132
  }).catch(reject);
132
133
  });
133
134
  }
134
- /**
135
- * Initialise and launch with a single function call. this is mostly for convenience.
136
- * Use .init() and .start() separately for fine-grained control
137
- */
138
- launch() {
139
- return new Promise((accept, reject) => {
140
- this.init().then((value) => {
141
- value.start();
142
- return accept();
143
- }).catch(reject);
144
- });
145
- }
146
135
  /**
147
136
  * Launches the internal AR instance using an appropriate version of AR Viewers
148
137
  */
@@ -15,11 +15,6 @@ export declare class RawAR extends LauncherAR {
15
15
  * cannot be performed.
16
16
  */
17
17
  init(): Promise<LauncherAR>;
18
- /**
19
- * Initialise and launch with a single function call. this is mostly for convenience.
20
- * Use .init() and .start() separately for fine-grained control
21
- */
22
- launch(): Promise<void>;
23
18
  /**
24
19
  * Launches the internal AR instance using an appropriate version of AR Viewers
25
20
  */
package/dist/ar/raw-ar.js CHANGED
@@ -75,18 +75,6 @@ class RawAR extends launcher_ar_1.LauncherAR {
75
75
  return reject(new Error("RawAR.init() - could not initialise AR correctly, check values"));
76
76
  });
77
77
  }
78
- /**
79
- * Initialise and launch with a single function call. this is mostly for convenience.
80
- * Use .init() and .start() separately for fine-grained control
81
- */
82
- launch() {
83
- return new Promise((accept, reject) => {
84
- this.init().then((value) => {
85
- value.start();
86
- return accept();
87
- }).catch(reject);
88
- });
89
- }
90
78
  /**
91
79
  * Launches the internal AR instance using an appropriate version of AR Viewers
92
80
  */
@@ -3,7 +3,27 @@ import { LauncherAR } from "./launcher-ar";
3
3
  * Performs AR functionality related to Plattar Scenes
4
4
  */
5
5
  export declare class SceneAR extends LauncherAR {
6
+ private _analytics;
7
+ private readonly _sceneID;
8
+ private _ar;
9
+ constructor(sceneID?: string | undefined | null);
10
+ get sceneID(): string;
11
+ private _SetupAnalytics;
12
+ /**
13
+ * Composes a Scene into an AR Model (remote operation) that can be used to launch
14
+ * an AR File
15
+ */
16
+ private _ComposeScene;
17
+ /**
18
+ * Initialise the SceneAR instance. This returns a Promise that resolves
19
+ * successfully if initialisation is successful, otherwise it will fail.
20
+ *
21
+ * filure can occur for a number of reasons but it generally means that AR
22
+ * cannot be performed.
23
+ */
6
24
  init(): Promise<LauncherAR>;
7
- launch(): Promise<void>;
8
25
  start(): void;
26
+ canQuicklook(): boolean;
27
+ canRealityViewer(): boolean;
28
+ canSceneViewer(): boolean;
9
29
  }
@@ -1,19 +1,162 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SceneAR = void 0;
7
+ const plattar_analytics_1 = require("@plattar/plattar-analytics");
8
+ const plattar_api_1 = require("@plattar/plattar-api");
9
+ const plattar_services_1 = require("@plattar/plattar-services");
10
+ const util_1 = require("../util/util");
11
+ const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
12
+ const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
13
+ const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
4
14
  const launcher_ar_1 = require("./launcher-ar");
5
15
  /**
6
16
  * Performs AR functionality related to Plattar Scenes
7
17
  */
8
18
  class SceneAR extends launcher_ar_1.LauncherAR {
9
- init() {
10
- throw new Error("Method not implemented.");
19
+ constructor(sceneID = null) {
20
+ super();
21
+ // analytics instance
22
+ this._analytics = null;
23
+ if (!sceneID) {
24
+ throw new Error("SceneAR.constructor(sceneID) - sceneID must be defined");
25
+ }
26
+ this._sceneID = sceneID;
27
+ this._ar = null;
28
+ }
29
+ get sceneID() {
30
+ return this._sceneID;
31
+ }
32
+ _SetupAnalytics(scene) {
33
+ let analytics = null;
34
+ // setup scene stuff (if any)
35
+ if (scene) {
36
+ analytics = new plattar_analytics_1.Analytics(scene.attributes.application_id);
37
+ analytics.origin = plattar_api_1.Server.location().type;
38
+ this._analytics = analytics;
39
+ analytics.data.push("type", "scene-ar");
40
+ analytics.data.push("sceneId", scene.id);
41
+ analytics.data.push("sceneTitle", scene.attributes.title);
42
+ const application = scene.relationships.find(plattar_api_1.Project);
43
+ // setup application stuff (if any)
44
+ if (application) {
45
+ analytics.data.push("applicationId", application.id);
46
+ analytics.data.push("applicationTitle", application.attributes.title);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Composes a Scene into an AR Model (remote operation) that can be used to launch
52
+ * an AR File
53
+ */
54
+ _ComposeScene(scene, output) {
55
+ return new Promise((accept, reject) => {
56
+ const sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct);
57
+ // nothing to do if no AR components can be found
58
+ if (sceneProducts.length <= 0) {
59
+ return reject(new Error("SceneAR.ComposeScene() - cannot proceed as scene does not contain AR components"));
60
+ }
61
+ // define our configurator
62
+ const configurator = new plattar_services_1.Configurator();
63
+ configurator.server = plattar_api_1.Server.location().type;
64
+ configurator.output = output;
65
+ // add out scene models
66
+ sceneProducts.forEach((sceneProduct) => {
67
+ const product = sceneProduct.relationships.find(plattar_api_1.Product);
68
+ if (product && product.attributes.product_variation_id) {
69
+ configurator.addSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
70
+ }
71
+ });
72
+ return configurator.get().then((result) => {
73
+ accept(result.filename);
74
+ }).catch(reject);
75
+ });
11
76
  }
12
- launch() {
13
- throw new Error("Method not implemented.");
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
+ init() {
85
+ return new Promise((accept, reject) => {
86
+ if (!util_1.Util.canAugment()) {
87
+ return reject(new Error("SceneAR.init() - cannot proceed as AR not available in context"));
88
+ }
89
+ const scene = new plattar_api_1.Scene(this.sceneID);
90
+ scene.include(plattar_api_1.Project);
91
+ scene.include(plattar_api_1.SceneProduct);
92
+ scene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product));
93
+ scene.get().then((scene) => {
94
+ this._SetupAnalytics(scene);
95
+ const sceneOpt = scene.attributes.custom_json || {};
96
+ // we need to define our AR module here
97
+ // we are in Safari/Quicklook mode here
98
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
99
+ // we need to launch a VTO experience here
100
+ // VTO requires Reality Support
101
+ if (sceneOpt.anchor === "face") {
102
+ if (util_1.Util.canRealityViewer()) {
103
+ return this._ComposeScene(scene, "vto").then((modelUrl) => {
104
+ this._ar = new reality_viewer_1.default();
105
+ this._ar.modelUrl = modelUrl;
106
+ return accept(this);
107
+ }).catch(reject);
108
+ }
109
+ else {
110
+ return reject(new Error("SceneAR.init() - cannot proceed as VTO AR requires Reality Viewer support"));
111
+ }
112
+ }
113
+ // otherwise, load the USDZ stuff second if available
114
+ if (util_1.Util.canQuicklook()) {
115
+ return this._ComposeScene(scene, "usdz").then((modelUrl) => {
116
+ this._ar = new quicklook_viewer_1.default();
117
+ this._ar.modelUrl = modelUrl;
118
+ return accept(this);
119
+ }).catch(reject);
120
+ }
121
+ return reject(new Error("SceneAR.init() - cannot proceed as IOS device does not support AR Mode"));
122
+ }
123
+ // check android
124
+ if (util_1.Util.canSceneViewer()) {
125
+ return this._ComposeScene(scene, "glb").then((modelUrl) => {
126
+ this._ar = new scene_viewer_1.default();
127
+ this._ar.modelUrl = modelUrl;
128
+ return accept(this);
129
+ }).catch(reject);
130
+ }
131
+ // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
132
+ // earlier in the process
133
+ return reject(new Error("SceneAR.init() - could not initialise AR correctly, check values"));
134
+ }).catch(reject);
135
+ });
14
136
  }
15
137
  start() {
16
- throw new Error("Method not implemented.");
138
+ if (!this._ar) {
139
+ throw new Error("SceneAR.start() - cannot proceed as AR instance is null");
140
+ }
141
+ const analytics = this._analytics;
142
+ if (analytics) {
143
+ analytics.data.push("device", this._ar.device);
144
+ analytics.data.push("eventCategory", this._ar.nodeType);
145
+ analytics.data.push("eventAction", "Start Scene Augment");
146
+ analytics.write();
147
+ analytics.startRecordEngagement();
148
+ }
149
+ // this was initialised via the init() function
150
+ this._ar.start();
151
+ }
152
+ canQuicklook() {
153
+ return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
154
+ }
155
+ canRealityViewer() {
156
+ return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
157
+ }
158
+ canSceneViewer() {
159
+ return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
17
160
  }
18
161
  }
19
162
  exports.SceneAR = SceneAR;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export * as PlattarWeb from "@plattar/plattar-web";
2
2
  export * as PlattarQRCode from "@plattar/plattar-qrcode";
3
3
  export * as version from "./version";
4
- export { ConfiguratorAR } from "./ar/configurator-ar";
5
4
  export { ProductAR } from "./ar/product-ar";
6
5
  export { SceneAR } from "./ar/scene-ar";
7
6
  export { ModelAR } from "./ar/model-ar";
package/dist/index.js CHANGED
@@ -22,12 +22,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
26
26
  exports.PlattarWeb = __importStar(require("@plattar/plattar-web"));
27
27
  exports.PlattarQRCode = __importStar(require("@plattar/plattar-qrcode"));
28
28
  exports.version = __importStar(require("./version"));
29
- var configurator_ar_1 = require("./ar/configurator-ar");
30
- Object.defineProperty(exports, "ConfiguratorAR", { enumerable: true, get: function () { return configurator_ar_1.ConfiguratorAR; } });
31
29
  var product_ar_1 = require("./ar/product-ar");
32
30
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
33
31
  var scene_ar_1 = require("./ar/scene-ar");
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.123.1";
1
+ declare const _default: "1.123.2";
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.123.1";
3
+ exports.default = "1.123.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.123.1",
3
+ "version": "1.123.2",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -1,9 +0,0 @@
1
- import { LauncherAR } from "./launcher-ar";
2
- /**
3
- * Performs AR related to Plattar Configurator functionalities
4
- */
5
- export declare class ConfiguratorAR extends LauncherAR {
6
- init(): Promise<LauncherAR>;
7
- launch(): Promise<void>;
8
- start(): void;
9
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfiguratorAR = void 0;
4
- const launcher_ar_1 = require("./launcher-ar");
5
- /**
6
- * Performs AR related to Plattar Configurator functionalities
7
- */
8
- class ConfiguratorAR extends launcher_ar_1.LauncherAR {
9
- init() {
10
- throw new Error("Method not implemented.");
11
- }
12
- launch() {
13
- throw new Error("Method not implemented.");
14
- }
15
- start() {
16
- throw new Error("Method not implemented.");
17
- }
18
- }
19
- exports.ConfiguratorAR = ConfiguratorAR;