@3dsource/metabox-front-api 1.2.1-dev.4 → 1.2.2-dev.0
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.
- package/README.md +80 -24
- package/fesm2022/3dsource-metabox-front-api.mjs +301 -138
- package/fesm2022/3dsource-metabox-front-api.mjs.map +1 -1
- package/index.d.ts +576 -404
- package/package.json +3 -3
|
@@ -1,95 +1,258 @@
|
|
|
1
1
|
import { fromEvent } from 'rxjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Base class for commands sent to the
|
|
4
|
+
* Base class for commands sent to the Metabox API.
|
|
5
5
|
*/
|
|
6
6
|
class CommandBase {
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Wrapper helper function to use it with rxJs the same as `fromEvent` to listen to events from the Communicator.
|
|
11
|
+
* @param {Communicator} target
|
|
12
|
+
* @param eventName
|
|
13
|
+
*/
|
|
14
|
+
function fromCommunicatorEvent(target, eventName) {
|
|
15
|
+
return fromEvent(target, eventName);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const MetaboxBasicConfiguratorActions = {
|
|
19
|
+
loadLevel: 'loadLevel',
|
|
20
|
+
setEnvironmentMaterialById: 'setEnvironmentMaterialById',
|
|
21
|
+
setProduct: 'setProduct',
|
|
22
|
+
setMaterialById: 'setMaterialById',
|
|
23
|
+
sendCommandToUnreal: 'sendCommandToUnreal',
|
|
24
|
+
getPdf: 'getPdf',
|
|
25
|
+
getScreenshot: 'getScreenshot',
|
|
26
|
+
getFastRender: 'getFastRender', // @deprecated, use 'getScreenshot'
|
|
27
|
+
showEmbeddedMenu: 'showEmbeddedMenu',
|
|
28
|
+
forceSetDeviceType: 'forceSetDeviceType',
|
|
29
|
+
showOverlayInterface: 'showOverlayInterface',
|
|
30
|
+
resetCamera: 'resetCamera',
|
|
31
|
+
applyZoom: 'applyZoom',
|
|
32
|
+
initShowcase: 'initShowcase',
|
|
33
|
+
playShowcase: 'playShowcase',
|
|
34
|
+
pauseShowcase: 'pauseShowcase',
|
|
35
|
+
stopShowcase: 'stopShowcase',
|
|
36
|
+
watchCallbacks: 'watchCallbacks',
|
|
37
|
+
addResponse: 'addResponse', // @deprecated, use 'watchCallbacks' ;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Represents a command to get a PDF from Metabox.
|
|
42
|
+
* @remarks
|
|
43
|
+
* This class sends a message to the Metabox API to generate a PDF based on the current configuration.
|
|
44
|
+
* This action does not require any parameters.
|
|
45
|
+
*
|
|
46
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
11
47
|
*
|
|
48
|
+
* @example
|
|
49
|
+
* import { GetPdf, Communicator } from '@3dsource/metabox-front-api';
|
|
50
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
51
|
+
* api.sendCommandToMetaBox(new GetPdf());
|
|
52
|
+
* };
|
|
53
|
+
*/
|
|
54
|
+
class GetPdf extends CommandBase {
|
|
55
|
+
/**
|
|
56
|
+
* Creates an instance of GetPdf.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* This constructor does not require any parameters.
|
|
60
|
+
*/
|
|
61
|
+
constructor() {
|
|
62
|
+
super();
|
|
63
|
+
this.data = { action: MetaboxBasicConfiguratorActions.getPdf };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Represents a command to send to unreal and reset camera to initial.
|
|
12
69
|
* @remarks
|
|
13
|
-
* This
|
|
70
|
+
* This class sends a message to the Metabox API to reset the camera on a scene.
|
|
71
|
+
* This action does not require any parameters.
|
|
72
|
+
*
|
|
73
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
14
74
|
*
|
|
15
75
|
* @example
|
|
16
|
-
* import {
|
|
76
|
+
* import { ResetCamera, Communicator } from '@3dsource/metabox-front-api';
|
|
77
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
78
|
+
* api.sendCommandToMetaBox(new ResetCamera());
|
|
79
|
+
* };
|
|
80
|
+
*/
|
|
81
|
+
class ResetCamera extends CommandBase {
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of ResetCamera.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* This constructor does not require any parameters.
|
|
87
|
+
*/
|
|
88
|
+
constructor() {
|
|
89
|
+
super();
|
|
90
|
+
this.data = { action: MetaboxBasicConfiguratorActions.resetCamera };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Represents a command to ApplyZoom and change zoom camera on a scene.
|
|
96
|
+
* @remarks
|
|
97
|
+
* This class sends a command to the Metabox API to change zoom on a scene.
|
|
17
98
|
*
|
|
18
|
-
*
|
|
99
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* import { ApplyZoom, Communicator } from '@3dsource/metabox-front-api';
|
|
19
103
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
20
|
-
*
|
|
104
|
+
* api.sendCommandToMetaBox(new ApplyZoom(10));
|
|
105
|
+
* api.sendCommandToMetaBox(new ApplyZoom(-10));
|
|
21
106
|
* };
|
|
22
107
|
*/
|
|
23
|
-
class
|
|
108
|
+
class ApplyZoom extends CommandBase {
|
|
24
109
|
/**
|
|
25
|
-
* Creates an instance of
|
|
110
|
+
* Creates an instance of ApplyZoom.
|
|
26
111
|
*
|
|
27
|
-
* @param
|
|
112
|
+
* @param {...number} zoom
|
|
28
113
|
*/
|
|
29
|
-
constructor(
|
|
114
|
+
constructor(zoom) {
|
|
30
115
|
super();
|
|
31
116
|
this.data = {
|
|
32
|
-
action:
|
|
33
|
-
payload: {
|
|
34
|
-
visible,
|
|
35
|
-
},
|
|
117
|
+
action: MetaboxBasicConfiguratorActions.applyZoom,
|
|
118
|
+
payload: { zoom },
|
|
36
119
|
};
|
|
37
120
|
}
|
|
38
121
|
}
|
|
39
122
|
|
|
40
123
|
/**
|
|
41
|
-
* Represents a command to
|
|
124
|
+
* Represents a command to Init Showcase for a product on a scene and start a sequence for the product.
|
|
125
|
+
* @remarks
|
|
126
|
+
* This class sends a command to the Metabox API to init showcase if the product has a sequence.
|
|
42
127
|
*
|
|
43
|
-
*
|
|
44
|
-
* import { ShowEmbeddedMenu,Communicator } from '@3dsource/metabox-front-api';
|
|
128
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
45
129
|
*
|
|
46
|
-
*
|
|
130
|
+
* @example
|
|
131
|
+
* import { InitShowcase, Communicator } from '@3dsource/metabox-front-api';
|
|
47
132
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
48
|
-
*
|
|
133
|
+
* api.sendCommandToMetaBox(new InitShowcase('ffea6b5c-3a8a-4f56-9417-e605acb5cca3');
|
|
49
134
|
* };
|
|
50
135
|
*/
|
|
51
|
-
class
|
|
136
|
+
class InitShowcase extends CommandBase {
|
|
52
137
|
/**
|
|
53
|
-
* Creates an instance of
|
|
138
|
+
* Creates an instance of InitShowcase.
|
|
54
139
|
*
|
|
55
|
-
* @param
|
|
140
|
+
* @param {string} productId
|
|
56
141
|
*/
|
|
57
|
-
constructor(
|
|
142
|
+
constructor(productId) {
|
|
58
143
|
super();
|
|
59
144
|
this.data = {
|
|
60
|
-
action:
|
|
61
|
-
payload: {
|
|
62
|
-
visible,
|
|
63
|
-
},
|
|
145
|
+
action: MetaboxBasicConfiguratorActions.initShowcase,
|
|
146
|
+
payload: { productId },
|
|
64
147
|
};
|
|
65
148
|
}
|
|
66
149
|
}
|
|
67
150
|
|
|
68
151
|
/**
|
|
69
|
-
* Represents a command to
|
|
152
|
+
* Represents a command to Play Showcase for a product when it already init, and you call pause, for example, before it.
|
|
153
|
+
* @remarks
|
|
154
|
+
* This class sends a command to the Metabox API to play showcase for a product if it is already initialized and pause.
|
|
155
|
+
*
|
|
156
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
70
157
|
*
|
|
71
158
|
* @example
|
|
72
|
-
* import {
|
|
159
|
+
* import { PlayShowcase, Communicator } from '@3dsource/metabox-front-api';
|
|
160
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
161
|
+
* api.sendCommandToMetaBox(new PlayShowcase());
|
|
162
|
+
* };
|
|
163
|
+
*/
|
|
164
|
+
class PlayShowcase extends CommandBase {
|
|
165
|
+
/**
|
|
166
|
+
* Creates an instance of PlayShowcase.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* This constructor does not require any parameters.
|
|
170
|
+
*/
|
|
171
|
+
constructor() {
|
|
172
|
+
super();
|
|
173
|
+
this.data = { action: MetaboxBasicConfiguratorActions.playShowcase };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Represents a command to Pause Showcase for a product when it already init and play, and you call pause.
|
|
179
|
+
* @remarks
|
|
180
|
+
* This class sends a command to the Metabox API to pause showcase for a product if it is already initialized and play.
|
|
73
181
|
*
|
|
74
|
-
*
|
|
182
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* import { PauseShowcase, Communicator } from '@3dsource/metabox-front-api';
|
|
75
186
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
76
|
-
*
|
|
77
|
-
* api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
187
|
+
* api.sendCommandToMetaBox(new PauseShowcase());
|
|
78
188
|
* };
|
|
79
189
|
*/
|
|
80
|
-
class
|
|
190
|
+
class PauseShowcase extends CommandBase {
|
|
81
191
|
/**
|
|
82
|
-
* Creates an instance of
|
|
192
|
+
* Creates an instance of PauseShowcase.
|
|
83
193
|
*
|
|
84
|
-
* @
|
|
194
|
+
* @remarks
|
|
195
|
+
* This constructor does not require any parameters.
|
|
85
196
|
*/
|
|
86
|
-
constructor(
|
|
197
|
+
constructor() {
|
|
198
|
+
super();
|
|
199
|
+
this.data = { action: MetaboxBasicConfiguratorActions.pauseShowcase };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Represents a command to Stop Showcase for a product when it already init, and you want to destroy it.
|
|
205
|
+
* @remarks
|
|
206
|
+
* This class sends a command to the Metabox API to Stop showcase for a product if it is already initialized.
|
|
207
|
+
*
|
|
208
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* import { StopShowcase, Communicator } from '@3dsource/metabox-front-api';
|
|
212
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
213
|
+
* api.sendCommandToMetaBox(new StopShowcase());
|
|
214
|
+
* };
|
|
215
|
+
*/
|
|
216
|
+
class StopShowcase extends CommandBase {
|
|
217
|
+
/**
|
|
218
|
+
* Creates an instance of StopShowcase.
|
|
219
|
+
*
|
|
220
|
+
* @remarks
|
|
221
|
+
* This constructor does not require any parameters.
|
|
222
|
+
*/
|
|
223
|
+
constructor() {
|
|
224
|
+
super();
|
|
225
|
+
this.data = { action: MetaboxBasicConfiguratorActions.stopShowcase };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Represents a command to get a screenshot.
|
|
231
|
+
*
|
|
232
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* import { GetScreenshot, Communicator, saveImage } from '@3dsource/metabox-front-api';
|
|
236
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
237
|
+
* // Listen for events from to the Metabox API
|
|
238
|
+
* api.addEventListener('screenshot', (data) => {
|
|
239
|
+
* // Process the get screenshot response
|
|
240
|
+
* saveImage(data, 'Render.png');
|
|
241
|
+
* });
|
|
242
|
+
* api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
243
|
+
* };
|
|
244
|
+
*/
|
|
245
|
+
class GetScreenshot extends CommandBase {
|
|
246
|
+
/**
|
|
247
|
+
* Constructs an instance of GetScreenshot.
|
|
248
|
+
* @param {MimeType} mimeType - The output format.
|
|
249
|
+
* @param {{ x: number; y: number }} [size] - Optional size in pixels.
|
|
250
|
+
*/
|
|
251
|
+
constructor(mimeType, size) {
|
|
87
252
|
super();
|
|
88
253
|
this.data = {
|
|
89
|
-
payload: {
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
action: 'loadLevel',
|
|
254
|
+
payload: { format: mimeType, size },
|
|
255
|
+
action: MetaboxBasicConfiguratorActions.getScreenshot,
|
|
93
256
|
};
|
|
94
257
|
}
|
|
95
258
|
}
|
|
@@ -98,10 +261,10 @@ class SetEnvironment extends CommandBase {
|
|
|
98
261
|
* Represents a command to set a product by its ID.
|
|
99
262
|
*
|
|
100
263
|
* @remarks
|
|
101
|
-
* This action sends a message to the
|
|
264
|
+
* This action sends a message to the Metabox API to set a product using the provided product ID.
|
|
102
265
|
*
|
|
103
266
|
* @example
|
|
104
|
-
* import { SetProduct,Communicator } from '@3dsource/metabox-front-api';
|
|
267
|
+
* import { SetProduct, Communicator } from '@3dsource/metabox-front-api';
|
|
105
268
|
*
|
|
106
269
|
* //...Assume that the integration is already implemented
|
|
107
270
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
@@ -114,86 +277,79 @@ class SetProduct extends CommandBase {
|
|
|
114
277
|
/**
|
|
115
278
|
* Creates an instance of SetProduct.
|
|
116
279
|
*
|
|
117
|
-
* @param productId - The product ID.
|
|
280
|
+
* @param {string} productId - The product ID.
|
|
118
281
|
*/
|
|
119
282
|
constructor(productId) {
|
|
120
283
|
super();
|
|
121
284
|
this.data = {
|
|
122
|
-
payload: {
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
action: 'setProduct',
|
|
285
|
+
payload: { productId },
|
|
286
|
+
action: MetaboxBasicConfiguratorActions.setProduct,
|
|
126
287
|
};
|
|
127
288
|
}
|
|
128
289
|
}
|
|
129
290
|
|
|
130
291
|
/**
|
|
131
|
-
* Represents a command to
|
|
132
|
-
* @remarks
|
|
133
|
-
* This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
|
|
134
|
-
* This action does not require any parameters.
|
|
135
|
-
*
|
|
136
|
-
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
292
|
+
* Represents a command to set a material by its slot ID and Material ID.
|
|
137
293
|
*
|
|
138
294
|
* @example
|
|
139
|
-
* import {
|
|
295
|
+
* import { SetMaterial, Communicator } from '@3dsource/metabox-front-api';
|
|
296
|
+
*
|
|
297
|
+
* //...Assume that the integration is already implemented
|
|
140
298
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
141
|
-
*
|
|
299
|
+
* api.sendCommandToMetaBox(new SetMaterial(
|
|
300
|
+
* 'carpaint',
|
|
301
|
+
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
302
|
+
* ));
|
|
142
303
|
* };
|
|
143
304
|
*/
|
|
144
|
-
class
|
|
305
|
+
class SetMaterial extends CommandBase {
|
|
145
306
|
/**
|
|
146
|
-
* Creates an instance of
|
|
307
|
+
* Creates an instance of SetMaterial.
|
|
147
308
|
*
|
|
148
|
-
* @
|
|
149
|
-
*
|
|
309
|
+
* @param {string} slotId - The slot ID.
|
|
310
|
+
* @param {string} materialId - The material ID.
|
|
150
311
|
*/
|
|
151
|
-
constructor() {
|
|
312
|
+
constructor(slotId, materialId) {
|
|
152
313
|
super();
|
|
153
314
|
this.data = {
|
|
154
|
-
|
|
315
|
+
payload: { slotId, materialId },
|
|
316
|
+
action: MetaboxBasicConfiguratorActions.setMaterialById,
|
|
155
317
|
};
|
|
156
318
|
}
|
|
157
319
|
}
|
|
158
320
|
|
|
159
321
|
/**
|
|
160
|
-
* Represents a command to set
|
|
322
|
+
* Represents a command to set the environment by its ID.
|
|
161
323
|
*
|
|
162
324
|
* @example
|
|
163
|
-
* import {
|
|
325
|
+
* import { SetEnvironment, Communicator } from '@3dsource/metabox-front-api';
|
|
164
326
|
*
|
|
165
327
|
* //...Assume that the integration is already implemented
|
|
166
328
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
170
|
-
* ));
|
|
329
|
+
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
330
|
+
* api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
171
331
|
* };
|
|
172
332
|
*/
|
|
173
|
-
class
|
|
333
|
+
class SetEnvironment extends CommandBase {
|
|
174
334
|
/**
|
|
175
|
-
* Creates an instance of
|
|
335
|
+
* Creates an instance of SetEnvironment.
|
|
176
336
|
*
|
|
177
|
-
* @param
|
|
178
|
-
* @param materialId - The material ID.
|
|
337
|
+
* @param {string} environmentId - The environment ID.
|
|
179
338
|
*/
|
|
180
|
-
constructor(
|
|
339
|
+
constructor(environmentId) {
|
|
181
340
|
super();
|
|
182
341
|
this.data = {
|
|
183
|
-
payload: {
|
|
184
|
-
|
|
185
|
-
materialId,
|
|
186
|
-
},
|
|
187
|
-
action: 'setMaterialById',
|
|
342
|
+
payload: { id: environmentId },
|
|
343
|
+
action: MetaboxBasicConfiguratorActions.loadLevel,
|
|
188
344
|
};
|
|
189
345
|
}
|
|
190
346
|
}
|
|
191
347
|
|
|
192
348
|
/**
|
|
193
|
-
* Represents a command to set an environment material by its ID.
|
|
349
|
+
* Represents a command to set an environment material by its slot ID and Material ID.
|
|
194
350
|
*
|
|
195
351
|
* @example
|
|
196
|
-
* import { SetEnvironmentMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
352
|
+
* import { SetEnvironmentMaterial, Communicator } from '@3dsource/metabox-front-api';
|
|
197
353
|
*
|
|
198
354
|
* //...Assume that the integration is already implemented
|
|
199
355
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
@@ -207,51 +363,69 @@ class SetEnvironmentMaterial extends CommandBase {
|
|
|
207
363
|
/**
|
|
208
364
|
* Creates an instance of SetEnvironmentMaterial.
|
|
209
365
|
*
|
|
210
|
-
* @param slotId - The slot ID.
|
|
211
|
-
* @param materialId - The material ID.
|
|
366
|
+
* @param {string} slotId - The slot ID.
|
|
367
|
+
* @param {string} materialId - The material ID.
|
|
212
368
|
*/
|
|
213
369
|
constructor(slotId, materialId) {
|
|
214
370
|
super();
|
|
215
371
|
this.data = {
|
|
216
|
-
payload: {
|
|
217
|
-
|
|
218
|
-
materialId,
|
|
219
|
-
},
|
|
220
|
-
action: 'setEnvironmentMaterialById',
|
|
372
|
+
payload: { slotId, materialId },
|
|
373
|
+
action: MetaboxBasicConfiguratorActions.setEnvironmentMaterialById,
|
|
221
374
|
};
|
|
222
375
|
}
|
|
223
376
|
}
|
|
224
377
|
|
|
225
378
|
/**
|
|
226
|
-
* Represents a command to
|
|
379
|
+
* Represents a command to toggle the Embedded to the Metabox Menu.
|
|
227
380
|
*
|
|
228
|
-
*
|
|
381
|
+
* @example
|
|
382
|
+
* import { ShowEmbeddedMenu, Communicator } from '@3dsource/metabox-front-api';
|
|
383
|
+
*
|
|
384
|
+
* //...Assume that the integration is already implemented
|
|
385
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
386
|
+
* api.setCommandToMetaBox(new ShowEmbeddedMenu(true));
|
|
387
|
+
* };
|
|
388
|
+
*/
|
|
389
|
+
class ShowEmbeddedMenu extends CommandBase {
|
|
390
|
+
/**
|
|
391
|
+
* Creates an instance of ShowEmbeddedMenu.
|
|
392
|
+
*
|
|
393
|
+
* @param {boolean} visible - A flag indicating whether the embedded menu should be visible.
|
|
394
|
+
*/
|
|
395
|
+
constructor(visible) {
|
|
396
|
+
super();
|
|
397
|
+
this.data = {
|
|
398
|
+
action: MetaboxBasicConfiguratorActions.showEmbeddedMenu,
|
|
399
|
+
payload: { visible },
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Represents a command to toggle the Unreal Overlay Interface Menu.
|
|
406
|
+
*
|
|
407
|
+
* @remarks
|
|
408
|
+
* This action sends a message to the Metabox API to toggle the visibility of the Unreal overlay UI.
|
|
229
409
|
*
|
|
230
410
|
* @example
|
|
231
|
-
* import {
|
|
411
|
+
* import { ShowOverlayInterface, Communicator } from '@3dsource/metabox-front-api';
|
|
412
|
+
*
|
|
413
|
+
* //...Assume that the integration is already implemented
|
|
232
414
|
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
233
|
-
*
|
|
234
|
-
* api.addEventListener('screenshot', (data) => {
|
|
235
|
-
* // Process the fast render response
|
|
236
|
-
* saveImage(data, 'Render.png');
|
|
237
|
-
* });
|
|
238
|
-
* api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
415
|
+
* api.setCommandToMetaBox(new ShowOverlayInterface(true));
|
|
239
416
|
* };
|
|
240
417
|
*/
|
|
241
|
-
class
|
|
418
|
+
class ShowOverlayInterface extends CommandBase {
|
|
242
419
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* @param
|
|
420
|
+
* Creates an instance of ShowOverlayInterface.
|
|
421
|
+
*
|
|
422
|
+
* @param {boolean} visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
246
423
|
*/
|
|
247
|
-
constructor(
|
|
424
|
+
constructor(visible) {
|
|
248
425
|
super();
|
|
249
426
|
this.data = {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
size,
|
|
253
|
-
},
|
|
254
|
-
action: 'getScreenshot',
|
|
427
|
+
action: MetaboxBasicConfiguratorActions.showOverlayInterface,
|
|
428
|
+
payload: { visible },
|
|
255
429
|
};
|
|
256
430
|
}
|
|
257
431
|
}
|
|
@@ -266,7 +440,7 @@ class UnrealCommand extends CommandBase {
|
|
|
266
440
|
super();
|
|
267
441
|
this.data = {
|
|
268
442
|
payload,
|
|
269
|
-
action:
|
|
443
|
+
action: MetaboxBasicConfiguratorActions.sendCommandToUnreal,
|
|
270
444
|
};
|
|
271
445
|
}
|
|
272
446
|
}
|
|
@@ -292,9 +466,7 @@ class WatchCallbacks extends CommandBase {
|
|
|
292
466
|
*/
|
|
293
467
|
constructor() {
|
|
294
468
|
super();
|
|
295
|
-
this.data = {
|
|
296
|
-
action: 'watchCallbacks',
|
|
297
|
-
};
|
|
469
|
+
this.data = { action: MetaboxBasicConfiguratorActions.watchCallbacks };
|
|
298
470
|
}
|
|
299
471
|
}
|
|
300
472
|
|
|
@@ -346,7 +518,7 @@ class EventDispatcher {
|
|
|
346
518
|
}
|
|
347
519
|
|
|
348
520
|
/**
|
|
349
|
-
* Handles messaging between the host page and embedded
|
|
521
|
+
* Handles messaging between the host page and embedded Metabox content.
|
|
350
522
|
* @internal Use {@link Communicator.createInstance} or the {@link integrateMetaBox} helper to instantiate.
|
|
351
523
|
*/
|
|
352
524
|
class Communicator extends EventDispatcher {
|
|
@@ -369,8 +541,8 @@ class Communicator extends EventDispatcher {
|
|
|
369
541
|
window.addEventListener('message', this.binder);
|
|
370
542
|
}
|
|
371
543
|
/**
|
|
372
|
-
* Listens for
|
|
373
|
-
* @param apiReadyCallback - Called with the new Communicator once
|
|
544
|
+
* Listens for Metabox to signal readiness, then initializes communicator.
|
|
545
|
+
* @param apiReadyCallback - Called with the new Communicator once to the Metabox is loaded.
|
|
374
546
|
*/
|
|
375
547
|
static createInstance(apiReadyCallback) {
|
|
376
548
|
const startHandler = (event) => {
|
|
@@ -390,14 +562,14 @@ class Communicator extends EventDispatcher {
|
|
|
390
562
|
window.removeEventListener('message', this.binder);
|
|
391
563
|
}
|
|
392
564
|
/**
|
|
393
|
-
* Posts a command to the
|
|
565
|
+
* Posts a command to the Metabox iframe.
|
|
394
566
|
* @param command - An action command containing data to send.
|
|
395
567
|
*/
|
|
396
568
|
sendCommandToMetaBox(command) {
|
|
397
569
|
const { data } = command;
|
|
398
570
|
const iframe = document.getElementById('embeddedContent');
|
|
399
571
|
if (!iframe?.contentWindow) {
|
|
400
|
-
console.warn('
|
|
572
|
+
console.warn('to the Metabox IFrame not found or not ready.');
|
|
401
573
|
return;
|
|
402
574
|
}
|
|
403
575
|
const message = {
|
|
@@ -408,7 +580,7 @@ class Communicator extends EventDispatcher {
|
|
|
408
580
|
iframe.contentWindow.postMessage(message, '*');
|
|
409
581
|
}
|
|
410
582
|
/**
|
|
411
|
-
* Registers an event listener for messages dispatched by
|
|
583
|
+
* Registers an event listener for messages dispatched by to the Metabox.
|
|
412
584
|
* @override
|
|
413
585
|
*/
|
|
414
586
|
addEventListener(messageType, callback) {
|
|
@@ -429,9 +601,9 @@ class Communicator extends EventDispatcher {
|
|
|
429
601
|
return super.removeEventListener(messageType, callback);
|
|
430
602
|
}
|
|
431
603
|
/**
|
|
432
|
-
* Filters and dispatches incoming messages from
|
|
433
|
-
* @param messageType - Expected message type for filtering ('metaboxData').
|
|
434
|
-
* @param event - The postMessage event received on window.
|
|
604
|
+
* Filters and dispatches incoming messages from to the Metabox.
|
|
605
|
+
* @param {FromMetaBoxApiEvents | 'metaboxData' } messageType - Expected message type for filtering ('metaboxData').
|
|
606
|
+
* @param {MessageEvent} event - The postMessage event received on a window.
|
|
435
607
|
*/
|
|
436
608
|
handleMessageReceived(messageType, event) {
|
|
437
609
|
// Optionally validate event.origin for security.
|
|
@@ -444,21 +616,21 @@ class Communicator extends EventDispatcher {
|
|
|
444
616
|
}
|
|
445
617
|
|
|
446
618
|
/**
|
|
447
|
-
* Integrates
|
|
619
|
+
* Integrates Metabox Basic Configurator into the provided layout.
|
|
448
620
|
*
|
|
449
621
|
* @remarks
|
|
450
622
|
* This function injects an iframe into a specified container element in the DOM and initializes
|
|
451
|
-
* the communicator for interacting with the
|
|
623
|
+
* the communicator for interacting with the Metabox embedded content.
|
|
452
624
|
*
|
|
453
|
-
* @param iframeSrc - The source URL of the
|
|
625
|
+
* @param {string} iframeSrc - The source URL of the Metabox iframe.
|
|
454
626
|
* Additional url parameters:
|
|
455
627
|
* ```javascript
|
|
456
|
-
* sidebar=false - disables the internal
|
|
628
|
+
* sidebar=false - disables the internal Metabox menu
|
|
457
629
|
* introImage=https://example.com/image.png - sets the intro image
|
|
458
630
|
* ```
|
|
459
|
-
* i.e
|
|
631
|
+
* i.e., a final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
|
|
460
632
|
*
|
|
461
|
-
* @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
|
|
633
|
+
* @param {string} containerId - The ID of the layout element. Defaults to 'embed3DSource'.
|
|
462
634
|
* @param apiReadyCallback
|
|
463
635
|
* @throws Error if the container element with the specified ID is not found.
|
|
464
636
|
*
|
|
@@ -499,15 +671,6 @@ function integrateMetaBox(iframeSrc, containerId = 'embed3DSource', apiReadyCall
|
|
|
499
671
|
container.appendChild(iframe);
|
|
500
672
|
}
|
|
501
673
|
|
|
502
|
-
/**
|
|
503
|
-
* Wrapper helper function to use it with rxJs the same as `fromEvent` to listen to events from the Communicator.
|
|
504
|
-
* @param target
|
|
505
|
-
* @param eventName
|
|
506
|
-
*/
|
|
507
|
-
function fromCommunicatorEvent(target, eventName) {
|
|
508
|
-
return fromEvent(target, eventName);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
674
|
/**
|
|
512
675
|
* Saves an image by triggering a download.
|
|
513
676
|
*
|
|
@@ -515,8 +678,8 @@ function fromCommunicatorEvent(target, eventName) {
|
|
|
515
678
|
* This function creates an anchor element, sets its `href` attribute to the provided image URL,
|
|
516
679
|
* and triggers a click event to initiate a download with the specified filename.
|
|
517
680
|
*
|
|
518
|
-
* @param imageUrl - The URL of the image to save.
|
|
519
|
-
* @param filename - The name of the file to save.
|
|
681
|
+
* @param {string} imageUrl - The URL of the image to save.
|
|
682
|
+
* @param {string} filename - The name of the file to save.
|
|
520
683
|
*/
|
|
521
684
|
function saveImage(imageUrl, filename) {
|
|
522
685
|
const a = document.createElement('a');
|
|
@@ -533,7 +696,7 @@ function saveImage(imageUrl, filename) {
|
|
|
533
696
|
* @remarks
|
|
534
697
|
* This function returns a promise that resolves after the given number of milliseconds.
|
|
535
698
|
*
|
|
536
|
-
* @param time - The time to sleep in milliseconds.
|
|
699
|
+
* @param {number} time - The time to sleep in milliseconds.
|
|
537
700
|
* @returns A promise that resolves after the specified duration.
|
|
538
701
|
*/
|
|
539
702
|
function sleep(time) {
|
|
@@ -546,7 +709,7 @@ function sleep(time) {
|
|
|
546
709
|
* @remarks
|
|
547
710
|
* This function updates the current URL by replacing its search parameters with the key-value pairs from the provided state object.
|
|
548
711
|
*
|
|
549
|
-
* @param state - An object containing key-value pairs to set as URL parameters.
|
|
712
|
+
* @param {Record<string, string>} state - An object containing key-value pairs to set as URL parameters.
|
|
550
713
|
*/
|
|
551
714
|
function setUrlParams(state) {
|
|
552
715
|
const url = new URL(window.location.href);
|
|
@@ -577,5 +740,5 @@ function getUrlParams() {
|
|
|
577
740
|
* Generated bundle index. Do not edit.
|
|
578
741
|
*/
|
|
579
742
|
|
|
580
|
-
export { CommandBase, Communicator, GetPdf, GetScreenshot,
|
|
743
|
+
export { ApplyZoom, CommandBase, Communicator, EventDispatcher, GetPdf, GetScreenshot, InitShowcase, MetaboxBasicConfiguratorActions, PauseShowcase, PlayShowcase, ResetCamera, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase, UnrealCommand, WatchCallbacks, fromCommunicatorEvent, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
|
|
581
744
|
//# sourceMappingURL=3dsource-metabox-front-api.mjs.map
|