@plattar/plattar-ar-adapter 1.120.1 → 1.120.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.
@@ -0,0 +1,32 @@
1
+ import { LauncherAR } from "./launcher-ar";
2
+ /**
3
+ * Performs AT Functionality using Plattar FileModel types
4
+ */
5
+ export declare class ModelAR extends LauncherAR {
6
+ private _analytics;
7
+ private readonly _modelID;
8
+ private _ar;
9
+ constructor(modelID?: string | undefined | null);
10
+ get modelID(): string;
11
+ private _SetupAnalytics;
12
+ /**
13
+ * Initialise the ModelAR instance. This returns a Promise that resolves
14
+ * successfully if initialisation is successful, otherwise it will fail.
15
+ *
16
+ * filure can occur for a number of reasons but it generally means that AR
17
+ * cannot be performed.
18
+ */
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
+ /**
26
+ * Launches the internal AR instance using an appropriate version of AR Viewers
27
+ */
28
+ start(): void;
29
+ canQuicklook(): boolean;
30
+ canRealityViewer(): boolean;
31
+ canSceneViewer(): boolean;
32
+ }
@@ -0,0 +1,132 @@
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.ModelAR = void 0;
7
+ const plattar_api_1 = require("@plattar/plattar-api");
8
+ const plattar_analytics_1 = require("@plattar/plattar-analytics");
9
+ const util_1 = require("../util/util");
10
+ const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
11
+ const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
12
+ const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
13
+ const launcher_ar_1 = require("./launcher-ar");
14
+ /**
15
+ * Performs AT Functionality using Plattar FileModel types
16
+ */
17
+ class ModelAR extends launcher_ar_1.LauncherAR {
18
+ constructor(modelID = null) {
19
+ super();
20
+ // analytics instance
21
+ this._analytics = null;
22
+ if (!modelID) {
23
+ throw new Error("ModelAR.constructor(modelID) - modelID must be defined");
24
+ }
25
+ this._modelID = modelID;
26
+ this._ar = null;
27
+ }
28
+ get modelID() {
29
+ return this._modelID;
30
+ }
31
+ _SetupAnalytics(model) {
32
+ let analytics = null;
33
+ const project = model.relationships.find(plattar_api_1.Project);
34
+ // setup scene stuff (if any)
35
+ if (project) {
36
+ analytics = new plattar_analytics_1.Analytics(project.id);
37
+ analytics.origin = plattar_api_1.Server.location().type;
38
+ analytics.data.push("applicationId", project.id);
39
+ analytics.data.push("applicationTitle", project.attributes.title);
40
+ analytics.data.push("modelId", model.id);
41
+ analytics.data.push("modelTitle", model.attributes.title);
42
+ this._analytics = analytics;
43
+ }
44
+ }
45
+ /**
46
+ * Initialise the ModelAR instance. This returns a Promise that resolves
47
+ * successfully if initialisation is successful, otherwise it will fail.
48
+ *
49
+ * filure can occur for a number of reasons but it generally means that AR
50
+ * cannot be performed.
51
+ */
52
+ init() {
53
+ return new Promise((accept, reject) => {
54
+ if (!util_1.Util.canAugment()) {
55
+ return reject(new Error("ModelAR.init() - cannot proceed as AR not available in context"));
56
+ }
57
+ const model = new plattar_api_1.FileModel(this.modelID);
58
+ model.include(plattar_api_1.Project);
59
+ model.get().then((model) => {
60
+ // setup the analytics data
61
+ this._SetupAnalytics(model);
62
+ // we need to define our AR module here
63
+ // we are in Safari/Quicklook mode here
64
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
65
+ // model needs to have either USDZ or REALITY files defined
66
+ // we load REALITY stuff first if available
67
+ if (model.attributes.reality_filename && util_1.Util.canRealityViewer()) {
68
+ this._ar = new reality_viewer_1.default();
69
+ this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.reality_filename;
70
+ return accept(this);
71
+ }
72
+ // otherwise, load the USDZ stuff second if available
73
+ if (model.attributes.usdz_filename && util_1.Util.canQuicklook()) {
74
+ this._ar = new quicklook_viewer_1.default();
75
+ this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.usdz_filename;
76
+ return accept(this);
77
+ }
78
+ return reject(new Error("ModelAR.init() - cannot proceed as ModelFile does not have a defined .usdz or .reality file"));
79
+ }
80
+ // check android
81
+ if (util_1.Util.canSceneViewer()) {
82
+ this._ar = new scene_viewer_1.default();
83
+ this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
84
+ return accept(this);
85
+ }
86
+ // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
87
+ // earlier in the process
88
+ return reject(new Error("ModelAR.init() - could not initialise AR correctly, check values"));
89
+ }).catch(reject);
90
+ });
91
+ }
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
+ /**
105
+ * Launches the internal AR instance using an appropriate version of AR Viewers
106
+ */
107
+ start() {
108
+ if (!this._ar) {
109
+ throw new Error("ModelAR.start() - cannot proceed as AR instance is null");
110
+ }
111
+ const analytics = this._analytics;
112
+ if (analytics) {
113
+ analytics.data.push("device", this._ar.device);
114
+ analytics.data.push("eventCategory", this._ar.nodeType);
115
+ analytics.data.push("eventAction", "Start Model Augment");
116
+ analytics.write();
117
+ analytics.startRecordEngagement();
118
+ }
119
+ // this was initialised via the init() function
120
+ this._ar.start();
121
+ }
122
+ canQuicklook() {
123
+ return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
124
+ }
125
+ canRealityViewer() {
126
+ return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
127
+ }
128
+ canSceneViewer() {
129
+ return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
130
+ }
131
+ }
132
+ exports.ModelAR = ModelAR;
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export * as version from "./version";
4
4
  export { ConfiguratorAR } from "./ar/configurator-ar";
5
5
  export { ProductAR } from "./ar/product-ar";
6
6
  export { SceneAR } from "./ar/scene-ar";
7
+ export { ModelAR } from "./ar/model-ar";
7
8
  export { Util } from "./util/util";
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ 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.SceneAR = exports.ProductAR = exports.ConfiguratorAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.Util = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = 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"));
@@ -32,6 +32,8 @@ var product_ar_1 = require("./ar/product-ar");
32
32
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
33
33
  var scene_ar_1 = require("./ar/scene-ar");
34
34
  Object.defineProperty(exports, "SceneAR", { enumerable: true, get: function () { return scene_ar_1.SceneAR; } });
35
+ var model_ar_1 = require("./ar/model-ar");
36
+ Object.defineProperty(exports, "ModelAR", { enumerable: true, get: function () { return model_ar_1.ModelAR; } });
35
37
  var util_1 = require("./util/util");
36
38
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
37
39
  const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.120.1";
1
+ declare const _default: "1.120.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.120.1";
3
+ exports.default = "1.120.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.120.1",
3
+ "version": "1.120.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",