@3dsource/metabox-modular-configurator-api 3.0.19-dev.10 → 3.0.19-dev.12
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.
|
@@ -2,6 +2,19 @@ import { fromEvent } from 'rxjs';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Base class for commands sent to the Metabox API.
|
|
5
|
+
*
|
|
6
|
+
* ### What does it unlock?
|
|
7
|
+
* Base class that all other commands inherit from in a class hierarchy. Provides common properties
|
|
8
|
+
* and methods that are automatically available to all command subclasses.
|
|
9
|
+
*
|
|
10
|
+
* ### Practical Application
|
|
11
|
+
* Base class all commands inherit from. Never instantiate directly — use specific subclasses like
|
|
12
|
+
* SetProduct, SetCamera, etc. All commands are sent via `api.sendCommandToMetabox(new CommandName(...))`.
|
|
13
|
+
*
|
|
14
|
+
* ### AI Coding Best Practices
|
|
15
|
+
* Never construct a generic CommandBase. Always use the specific typed command class. When generating
|
|
16
|
+
* dynamic command dispatch, use a switch/map pattern matching command names to their constructors.
|
|
17
|
+
*
|
|
5
18
|
* @internal
|
|
6
19
|
* @hidden
|
|
7
20
|
*/
|
|
@@ -9,18 +22,48 @@ class CommandBase {
|
|
|
9
22
|
}
|
|
10
23
|
|
|
11
24
|
/**
|
|
12
|
-
* Wrapper helper function to use
|
|
25
|
+
* Wrapper helper function to use with RxJS the same way as `fromEvent`, to listen to events from the Communicator.
|
|
26
|
+
*
|
|
27
|
+
* ### What does it unlock?
|
|
28
|
+
* Function that creates an event listener subscription. Allows developers to subscribe to specific events from the Communicator.
|
|
29
|
+
*
|
|
30
|
+
* ### Practical Application
|
|
31
|
+
* Function that creates event listener subscriptions. Alternative to api.addEventListener() — both subscribe
|
|
32
|
+
* to configurator events. Use to react to state changes, screenshot readiness, viewport loading, showcase status, etc.
|
|
13
33
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
34
|
+
* ### AI Coding Best Practices
|
|
35
|
+
* Prefer api.addEventListener() directly from the Communicator object. If using fromCommunicatorEvent, pass the
|
|
36
|
+
* event name and handler. Key events: configuratorDataUpdated, viewportReady, screenshotReady, showcaseStatusChanged,
|
|
37
|
+
* getCameraResult. Always subscribe BEFORE sending commands that trigger responses.
|
|
38
|
+
*
|
|
39
|
+
* @param {Communicator} target - The Communicator instance to listen on.
|
|
40
|
+
* @param {T} eventName - The event name from {@link FromMetaBoxApiEvents} to subscribe to.
|
|
41
|
+
* @returns An Observable that emits the typed payload each time the event fires.
|
|
16
42
|
* @internal
|
|
17
43
|
*/
|
|
18
44
|
function fromCommunicatorEvent(target, eventName) {
|
|
19
45
|
return fromEvent(target, eventName);
|
|
20
46
|
}
|
|
21
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Registry of all action identifiers that can be sent from the host application to the Metabox Modular Configurator.
|
|
50
|
+
* Each key maps to a string used as the `action` field in the postMessage envelope.
|
|
51
|
+
*
|
|
52
|
+
* ### What does it unlock?
|
|
53
|
+
* Variable containing all available action names. Interface listing all actions that the modular configurator supports.
|
|
54
|
+
*
|
|
55
|
+
* ### Practical Application
|
|
56
|
+
* Master action registry object — all supported configurator action names. Invaluable reference for building
|
|
57
|
+
* admin dashboards, permission systems, or feature-availability displays.
|
|
58
|
+
*
|
|
59
|
+
* ### AI Coding Best Practices
|
|
60
|
+
* Iterate this object to dynamically build action dropdowns, command palettes, or feature checklists in admin tools.
|
|
61
|
+
* Each key is an action name, value is its description. Excellent reference for AI coding agents to understand
|
|
62
|
+
* the full command vocabulary available.
|
|
63
|
+
*/
|
|
22
64
|
const MetaboxModularConfiguratorActions = {
|
|
23
65
|
metaboxConfig: 'metaboxConfig',
|
|
66
|
+
resumeStream: 'resumeStream',
|
|
24
67
|
setEnvironment: 'setEnvironment',
|
|
25
68
|
setEnvironmentMaterialById: 'setEnvironmentMaterialById',
|
|
26
69
|
setComponent: 'setComponent',
|
|
@@ -45,19 +88,28 @@ const MetaboxModularConfiguratorActions = {
|
|
|
45
88
|
};
|
|
46
89
|
|
|
47
90
|
/**
|
|
48
|
-
* Represents a command to send Metabox Config to Metabox
|
|
49
|
-
*
|
|
50
|
-
*
|
|
91
|
+
* Represents a command to send Metabox Config to Metabox Modular Configurator.
|
|
92
|
+
*
|
|
93
|
+
* ### What does it unlock?
|
|
94
|
+
* Configuration object passed to MetaBox during initialization. Specifies domain, host, standalone mode,
|
|
95
|
+
* and other parameters that control how the configurator behaves.
|
|
96
|
+
*
|
|
97
|
+
* ### Practical Application
|
|
98
|
+
* Internal configuration object auto-sent during initialization. Contains appId and config.
|
|
99
|
+
* DO NOT call directly — integrateMetabox() handles this automatically as part of its setup sequence.
|
|
100
|
+
*
|
|
101
|
+
* ### AI Coding Best Practices
|
|
102
|
+
* NEVER instantiate or send MetaboxConfig manually. It is auto-sent by integrateMetabox().
|
|
103
|
+
* Use the IntegrateMetaboxConfig parameter of integrateMetabox() instead for setting domain, standalone,
|
|
104
|
+
* loadingImage, introImage, state, etc.
|
|
51
105
|
*
|
|
52
106
|
* @internal
|
|
53
107
|
* Automatically sent when the Communicator instance is ready.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} appId - The unique identifier for the Communicator Instance
|
|
110
|
+
* @param {MetaboxCommandConfig} config - optional initial config: standalone - if true - disable metabox custom template and all logic
|
|
54
111
|
*/
|
|
55
112
|
class MetaboxConfig extends CommandBase {
|
|
56
|
-
/**
|
|
57
|
-
* Creates an instance of MetaboxConfig.
|
|
58
|
-
* @param {string} appId - The unique identifier for the Communicator Instance
|
|
59
|
-
* @param {MetaboxCommandConfig} config - optional initial config: standalone - if true - disable metabox custom template and all logic
|
|
60
|
-
*/
|
|
61
113
|
constructor(appId, config) {
|
|
62
114
|
super();
|
|
63
115
|
this.data = {
|
|
@@ -68,27 +120,28 @@ class MetaboxConfig extends CommandBase {
|
|
|
68
120
|
}
|
|
69
121
|
|
|
70
122
|
/**
|
|
71
|
-
* Represents a command to get a PDF from Metabox
|
|
72
|
-
* @remarks
|
|
123
|
+
* Represents a command to get a PDF from Metabox Modular Configurator.
|
|
73
124
|
* This class sends a message to the Metabox API to generate a PDF based on the current configuration.
|
|
74
|
-
* **Important**: No need to listen to any events to see changes.
|
|
75
|
-
*
|
|
125
|
+
* **Important**: No need to listen to any events to see changes. Pdf will be downloaded automatically once it's ready.
|
|
126
|
+
*
|
|
127
|
+
* ### What does it unlock?
|
|
128
|
+
* Generates a native MetaBox PDF document. No subscription required — it executes independently.
|
|
129
|
+
*
|
|
130
|
+
* ### Practical Application
|
|
131
|
+
* Generates a branded PDF from the current configurator state server-side. No event subscription needed.
|
|
132
|
+
* Use for B2B quote workflows, downloadable spec sheets, or emailing configured product summaries to prospects.
|
|
133
|
+
*
|
|
134
|
+
* ### AI Coding Best Practices
|
|
135
|
+
* Simply call `api.sendCommandToMetabox(new GetPdf())`. No parameters or event subscription required.
|
|
136
|
+
* The PDF generates inside MetaBox application.
|
|
76
137
|
*
|
|
77
138
|
* @example
|
|
78
139
|
* import { GetPdf, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
79
|
-
*
|
|
80
|
-
* @param {Communicator} api - communicator instance api
|
|
81
140
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
82
141
|
* api.sendCommandToMetabox(new GetPdf());
|
|
83
142
|
* };
|
|
84
143
|
*/
|
|
85
144
|
class GetPdf extends CommandBase {
|
|
86
|
-
/**
|
|
87
|
-
* Creates an instance of GetPdf.
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
* This constructor does not require any parameters.
|
|
91
|
-
*/
|
|
92
145
|
constructor() {
|
|
93
146
|
super();
|
|
94
147
|
this.data = { action: MetaboxModularConfiguratorActions.getPdf };
|
|
@@ -96,40 +149,38 @@ class GetPdf extends CommandBase {
|
|
|
96
149
|
}
|
|
97
150
|
|
|
98
151
|
/**
|
|
99
|
-
* Represents a command to get a Call To Action Information from Metabox
|
|
100
|
-
*
|
|
101
|
-
*
|
|
152
|
+
* Represents a command to get a Call To Action Information from Metabox Modular Configurator.
|
|
153
|
+
* This class sends a message to the Metabox API to generate Call To Action information based on the current
|
|
154
|
+
* configuration and sends it to the endpoint URL from the CTA information.
|
|
102
155
|
*
|
|
103
156
|
* To listen for changes after sending this command, listen to the 'ecomConfiguratorDataUpdated' event.
|
|
104
|
-
* //...Assume that the integration is already implemented (only once)
|
|
105
|
-
* @example
|
|
106
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
107
157
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @param {EcomConfigurator} data - description for all ecom configurator params
|
|
111
|
-
* api.addEventListener('ecomConfiguratorDataUpdated', (data) => {
|
|
112
|
-
* console.log('Ecom configurator params:', data);
|
|
113
|
-
* });
|
|
114
|
-
* };
|
|
158
|
+
* ### What does it unlock?
|
|
159
|
+
* Retrieves information about call-to-action that were added to the configurator. Requires subscription to receive data.
|
|
115
160
|
*
|
|
116
|
-
*
|
|
161
|
+
* ### Practical Application
|
|
162
|
+
* Triggers the CTA (Call-to-Action) workflow configured in MetaBox admin. The CTA label and callback URL are set in admin.
|
|
163
|
+
* When invoked, MetaBox POSTs the full configuration JSON (including BOM) to your callback URL endpoint, which returns a { redirectUrl }.
|
|
117
164
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
165
|
+
* ### AI Coding Best Practices
|
|
166
|
+
* Call only after user completes configuration. Subscribe to ecomConfiguratorDataUpdated to get CTA label/URL for building
|
|
167
|
+
* custom CTA buttons in your UI. The POST payload includes the full bill of materials — your backend endpoint processes it
|
|
168
|
+
* and returns a redirect URL.
|
|
120
169
|
*
|
|
121
|
-
* @
|
|
170
|
+
* @example
|
|
171
|
+
* import { Communicator, EcomConfigurator, GetCallToActionInformation } from '@3dsource/metabox-modular-configurator-api';
|
|
122
172
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
173
|
+
*
|
|
174
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
175
|
+
* api.addEventListener('ecomConfiguratorDataUpdated', (data:EcomConfigurator) => {
|
|
176
|
+
* console.log('Ecom configurator params:', data);
|
|
177
|
+
* });
|
|
178
|
+
*
|
|
179
|
+
* // Send the command to get Call To Action information from Metabox Modular Configurator
|
|
123
180
|
* api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
124
181
|
* };
|
|
125
182
|
*/
|
|
126
183
|
class GetCallToActionInformation extends CommandBase {
|
|
127
|
-
/**
|
|
128
|
-
* Creates an instance of GetCallToActionInformation.
|
|
129
|
-
*
|
|
130
|
-
* @remarks
|
|
131
|
-
* This constructor does not require any parameters.
|
|
132
|
-
*/
|
|
133
184
|
constructor() {
|
|
134
185
|
super();
|
|
135
186
|
this.data = {
|
|
@@ -140,38 +191,35 @@ class GetCallToActionInformation extends CommandBase {
|
|
|
140
191
|
|
|
141
192
|
/**
|
|
142
193
|
* Represents a command to get the camera configuration from Unreal.
|
|
143
|
-
* @remarks
|
|
144
194
|
* This class sends a message to the Metabox API to get the camera from a scene.
|
|
145
|
-
*
|
|
146
195
|
* To listen for changes after sending this command, listen to the 'getCameraResult' event.
|
|
147
|
-
* //...Assume that the integration is already implemented (only once)
|
|
148
|
-
* @example
|
|
149
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
150
196
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @param {CameraCommandPayload} data - camera params
|
|
154
|
-
* api.addEventListener('getCameraResult', (data) => {
|
|
155
|
-
* console.log('Camera params after get camera command:', data);
|
|
156
|
-
* });
|
|
157
|
-
* };
|
|
197
|
+
* ### What does it unlock?
|
|
198
|
+
* Retrieves camera presets for the configurator; allowing extraction and application of saved camera positions.
|
|
158
199
|
*
|
|
159
|
-
*
|
|
200
|
+
* ### Practical Application
|
|
201
|
+
* Requests current camera state — returns asynchronously via the getCameraResult event. Returns a CameraCommandPayload
|
|
202
|
+
* with fov, mode, position, rotation, and restrictions. Use to save camera positions, create shareable view links,
|
|
203
|
+
* or build 'save this angle' features.
|
|
204
|
+
*
|
|
205
|
+
* ### AI Coding Best Practices
|
|
206
|
+
* ALWAYS subscribe to getCameraResult BEFORE calling GetCamera(). Pattern: `api.addEventListener('getCameraResult', handler);`
|
|
207
|
+
* then `api.sendCommandToMetabox(new GetCamera())`. The returned CameraCommandPayload can be fed directly back into
|
|
208
|
+
* SetCamera to restore the view.
|
|
160
209
|
*
|
|
161
210
|
* @example
|
|
162
|
-
* import {
|
|
163
|
-
* @param {Communicator} api - communicator instance api
|
|
211
|
+
* import { Communicator, CameraCommandPayload, GetCamera } from '@3dsource/metabox-modular-configurator-api';
|
|
164
212
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
213
|
+
*
|
|
214
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
215
|
+
* api.addEventListener('getCameraResult', (data:CameraCommandPayload) => {
|
|
216
|
+
* console.log('Camera params after get camera command:', data);
|
|
217
|
+
* });
|
|
218
|
+
*
|
|
165
219
|
* api.sendCommandToMetabox(new GetCamera());
|
|
166
220
|
* };
|
|
167
221
|
*/
|
|
168
222
|
class GetCamera extends CommandBase {
|
|
169
|
-
/**
|
|
170
|
-
* Creates an instance of GetCamera.
|
|
171
|
-
*
|
|
172
|
-
* @remarks
|
|
173
|
-
* This constructor does not require any parameters.
|
|
174
|
-
*/
|
|
175
223
|
constructor() {
|
|
176
224
|
super();
|
|
177
225
|
this.data = { action: MetaboxModularConfiguratorActions.getCamera };
|
|
@@ -180,14 +228,24 @@ class GetCamera extends CommandBase {
|
|
|
180
228
|
|
|
181
229
|
/**
|
|
182
230
|
* Represents a command to set the camera configuration.
|
|
183
|
-
* @remarks
|
|
184
231
|
* This class sends a message to the Metabox API to set the camera on a scene.
|
|
185
232
|
* **Important**: No need to listen to any events to see changes.
|
|
186
|
-
*
|
|
233
|
+
*
|
|
234
|
+
* ### What does it unlock?
|
|
235
|
+
* Sets camera presets with restriction parameters (FOV, rotation, position).
|
|
236
|
+
*
|
|
237
|
+
* ### Practical Application
|
|
238
|
+
* Sets camera with precise control: fov (degrees), mode ('orbit'|'fps'), position ({x,y,z}),
|
|
239
|
+
* rotation ({horizontal,vertical}), and restrictions (min/max distance, FOV, rotation bounds).
|
|
240
|
+
* Use for guided tours, preset view buttons, or restricting camera to prevent users seeing behind the product.
|
|
241
|
+
*
|
|
242
|
+
* ### AI Coding Best Practices
|
|
243
|
+
* Only include fields you want to change — omitted values keep current settings. Use orbit mode for typical product viewing,
|
|
244
|
+
* fps for walkthrough/room scenes. Apply restrictions to prevent bad angles. Full interface:
|
|
245
|
+
* `{fov?, mode?, position?, rotation?, restrictions?}`.
|
|
187
246
|
*
|
|
188
247
|
* @example
|
|
189
248
|
* import { SetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
190
|
-
* @param {Communicator} api - communicator instance api
|
|
191
249
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
192
250
|
* api.sendCommandToMetabox(new SetCamera({
|
|
193
251
|
* fov: 45,
|
|
@@ -203,16 +261,13 @@ class GetCamera extends CommandBase {
|
|
|
203
261
|
* minFov: 0,
|
|
204
262
|
* minHorizontalRotation: 0,
|
|
205
263
|
* minVerticalRotation: 0,
|
|
206
|
-
*
|
|
264
|
+
* },
|
|
207
265
|
* }));
|
|
208
266
|
* };
|
|
267
|
+
*
|
|
268
|
+
* @param {CameraCommandPayload} camera - The camera configuration.
|
|
209
269
|
*/
|
|
210
270
|
class SetCamera extends CommandBase {
|
|
211
|
-
/**
|
|
212
|
-
* Creates an instance of SetCamera.
|
|
213
|
-
*
|
|
214
|
-
* @param {CameraCommandPayload} camera - The camera configuration.
|
|
215
|
-
*/
|
|
216
271
|
constructor(camera) {
|
|
217
272
|
super();
|
|
218
273
|
this.data = {
|
|
@@ -224,25 +279,26 @@ class SetCamera extends CommandBase {
|
|
|
224
279
|
|
|
225
280
|
/**
|
|
226
281
|
* Represents a command to reset the camera to its initial position.
|
|
227
|
-
* @remarks
|
|
228
282
|
* This class sends a message to the Metabox API to reset the camera on a scene.
|
|
229
|
-
*
|
|
230
|
-
*
|
|
283
|
+
*
|
|
284
|
+
* ### What does it unlock?
|
|
285
|
+
* Resets the camera to its default state and position. Used to return camera to initial configuration after user manipulation.
|
|
286
|
+
*
|
|
287
|
+
* ### Practical Application
|
|
288
|
+
* Resets camera to the default position defined in the component/environment template. Essential for 'Reset View' buttons.
|
|
289
|
+
* Also, useful after programmatic camera moves to return to a known starting state.
|
|
290
|
+
*
|
|
291
|
+
* ### AI Coding Best Practices
|
|
292
|
+
* Call `api.sendCommandToMetabox(new ResetCamera())`. No parameters. Restores template defaults — not the last user position.
|
|
293
|
+
* Good practice to call after SetComponent changes that may shift the focal point of the assembly.
|
|
231
294
|
*
|
|
232
295
|
* @example
|
|
233
296
|
* import { ResetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
234
|
-
* @param {Communicator} api - communicator instance api
|
|
235
297
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
236
298
|
* api.sendCommandToMetabox(new ResetCamera());
|
|
237
299
|
* };
|
|
238
300
|
*/
|
|
239
301
|
class ResetCamera extends CommandBase {
|
|
240
|
-
/**
|
|
241
|
-
* Creates an instance of ResetCamera.
|
|
242
|
-
*
|
|
243
|
-
* @remarks
|
|
244
|
-
* This constructor does not require any parameters.
|
|
245
|
-
*/
|
|
246
302
|
constructor() {
|
|
247
303
|
super();
|
|
248
304
|
this.data = { action: MetaboxModularConfiguratorActions.resetCamera };
|
|
@@ -251,26 +307,30 @@ class ResetCamera extends CommandBase {
|
|
|
251
307
|
|
|
252
308
|
/**
|
|
253
309
|
* Represents a command to apply zoom and change the camera zoom on a scene.
|
|
254
|
-
* @remarks
|
|
255
310
|
* This class sends a command to the Metabox API to change zoom on a scene.
|
|
256
|
-
*
|
|
257
|
-
*
|
|
311
|
+
*
|
|
312
|
+
* ### What does it unlock?
|
|
313
|
+
* Controls zoom functionality for the configurator; allowing users to adjust the zoom level of 3D objects and camera presets.
|
|
314
|
+
*
|
|
315
|
+
* ### Practical Application
|
|
316
|
+
* Implements programmatic zoom on the pixel-streamed viewport. Use to build zoom slider controls, pinch-to-zoom on mobile,
|
|
317
|
+
* or 'zoom to detail' buttons. Takes a numeric delta: positive zooms in, negative zooms out
|
|
318
|
+
* (e.g., ApplyZoom(50) zooms in, ApplyZoom(-50) zooms out).
|
|
319
|
+
*
|
|
320
|
+
* ### AI Coding Best Practices
|
|
321
|
+
* Always use numeric delta values, not absolute zoom levels. Pair with a UI slider that sends incremental values.
|
|
322
|
+
* Debounce zoom input to ~100ms intervals to prevent overwhelming the Unreal stream.
|
|
323
|
+
* Pattern: `api.sendCommandToMetabox(new ApplyZoom(50))`.
|
|
258
324
|
*
|
|
259
325
|
* @example
|
|
260
326
|
* import { ApplyZoom, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
261
|
-
*
|
|
262
|
-
* @param {Communicator} api - communicator instance api
|
|
263
327
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
264
|
-
* api.sendCommandToMetabox(new ApplyZoom(
|
|
265
|
-
* api.sendCommandToMetabox(new ApplyZoom(-10));
|
|
328
|
+
* api.sendCommandToMetabox(new ApplyZoom(50));
|
|
266
329
|
* };
|
|
330
|
+
*
|
|
331
|
+
* @param {number} zoom - The zoom value to apply.
|
|
267
332
|
*/
|
|
268
333
|
class ApplyZoom extends CommandBase {
|
|
269
|
-
/**
|
|
270
|
-
* Creates an instance of ApplyZoom.
|
|
271
|
-
*
|
|
272
|
-
* @param {number} zoom - The zoom value to apply.
|
|
273
|
-
*/
|
|
274
334
|
constructor(zoom) {
|
|
275
335
|
super();
|
|
276
336
|
this.data = {
|
|
@@ -281,54 +341,36 @@ class ApplyZoom extends CommandBase {
|
|
|
281
341
|
}
|
|
282
342
|
|
|
283
343
|
/**
|
|
284
|
-
* Represents a command to initialize Showcase for a
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* To check this, find the showcase property in the current product and listen to the 'configuratorDataUpdated' event.
|
|
288
|
-
* //...Assume that the integration is already implemented (only once)
|
|
289
|
-
* @example
|
|
290
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
291
|
-
*
|
|
292
|
-
* @param {Communicator} api - communicator instance api
|
|
293
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
294
|
-
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
295
|
-
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
296
|
-
* console.log('State updated after applied new environment:', data);
|
|
297
|
-
* });
|
|
298
|
-
* };
|
|
299
|
-
*
|
|
344
|
+
* Represents a command to initialize Showcase for a component scene and start a sequence for the component.
|
|
345
|
+
* This class sends a command to the Metabox API to initialize showcase if the component has a sequence.
|
|
346
|
+
* To check this, find the showcase property in the current component and listen to the 'configuratorDataUpdated' event.
|
|
300
347
|
* If this property exists, you can send the init showcase command.
|
|
301
348
|
*
|
|
302
349
|
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
303
|
-
* //...Assume that the integration is already implemented (only once)
|
|
304
|
-
* @example
|
|
305
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
306
350
|
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @param {ShowCaseStatus} data - showcase status value
|
|
310
|
-
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
311
|
-
* console.log('Showcase status value after changed:', data);
|
|
312
|
-
* });
|
|
313
|
-
* };
|
|
351
|
+
* ### What does it unlock?
|
|
352
|
+
* Initializes and displays the showcase/demo view for the configurator. Used when transitioning into presentation or demo mode.
|
|
314
353
|
*
|
|
315
|
-
*
|
|
354
|
+
* ### Practical Application
|
|
355
|
+
* Loads the showcase/animation sequence attached to the current component. Must be called BEFORE PlayShowcase.
|
|
356
|
+
* Use to initialize auto-playing product demos, trade show presentations, or hero section animations on landing pages.
|
|
316
357
|
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
358
|
+
* ### AI Coding Best Practices
|
|
359
|
+
* ALWAYS call InitShowcase() before PlayShowcase(). Required sequence: InitShowcase → PlayShowcase → PauseShowcase/StopShowcase.
|
|
360
|
+
* Subscribe to showcaseStatusChanged to track playback state ('playing'/'paused'/'stopped').
|
|
319
361
|
*
|
|
320
|
-
* @
|
|
362
|
+
* @example
|
|
363
|
+
* import { Communicator, ShowCaseStatus, InitShowcase } from '@3dsource/metabox-modular-configurator-api';
|
|
321
364
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
365
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
366
|
+
* api.addEventListener('showcaseStatusChanged', (data:ShowCaseStatus) => {
|
|
367
|
+
* console.log('Showcase status value after changed:', data);
|
|
368
|
+
* });
|
|
369
|
+
*
|
|
322
370
|
* api.sendCommandToMetabox(new InitShowcase());
|
|
323
371
|
* };
|
|
324
372
|
*/
|
|
325
373
|
class InitShowcase extends CommandBase {
|
|
326
|
-
/**
|
|
327
|
-
* Creates an instance of InitShowcase.
|
|
328
|
-
*
|
|
329
|
-
* @remarks
|
|
330
|
-
* This constructor does not require any parameters.
|
|
331
|
-
*/
|
|
332
374
|
constructor() {
|
|
333
375
|
super();
|
|
334
376
|
this.data = {
|
|
@@ -338,40 +380,35 @@ class InitShowcase extends CommandBase {
|
|
|
338
380
|
}
|
|
339
381
|
|
|
340
382
|
/**
|
|
341
|
-
* Represents a command to play Showcase for a
|
|
342
|
-
*
|
|
343
|
-
* This class sends a command to the Metabox API to play showcase for a product if it is already initialized and paused.
|
|
383
|
+
* Represents a command to play Showcase for a component when it is already initialized and paused.
|
|
384
|
+
* This class sends a command to the Metabox API to play showcase for a component if it is already initialized and paused.
|
|
344
385
|
*
|
|
345
386
|
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
346
|
-
* //...Assume that the integration is already implemented (only once)
|
|
347
|
-
* @example
|
|
348
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
349
387
|
*
|
|
350
|
-
*
|
|
388
|
+
* ### What does it unlock?
|
|
389
|
+
* Starts or resumes the showcase/timeline playback. Executes the internal MetaBox play command internally.
|
|
390
|
+
*
|
|
391
|
+
* ### Practical Application
|
|
392
|
+
* Starts or resumes showcase playback. Use for 'Play Demo' buttons on landing pages, auto-play on page load,
|
|
393
|
+
* or resuming demos after inactivity timeout on kiosk displays.
|
|
394
|
+
*
|
|
395
|
+
* ### AI Coding Best Practices
|
|
396
|
+
* Call `api.sendCommandToMetabox(new PlayShowcase())`. Must call InitShowcase() first or it won't play.
|
|
397
|
+
* Subscribe to showcaseStatusChanged to track state. Auto-play pattern: wait for viewportReady → InitShowcase →
|
|
398
|
+
* PlayShowcase.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* import { Communicator, PlayShowcase } from '@3dsource/metabox-modular-configurator-api';
|
|
351
402
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
352
|
-
*
|
|
403
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
353
404
|
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
354
405
|
* console.log('Showcase status value after changed:', data);
|
|
355
406
|
* });
|
|
356
|
-
* };
|
|
357
|
-
*
|
|
358
|
-
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
359
407
|
*
|
|
360
|
-
* @example
|
|
361
|
-
* import { PlayShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
362
|
-
*
|
|
363
|
-
* @param {Communicator} api - communicator instance api
|
|
364
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
365
408
|
* api.sendCommandToMetabox(new PlayShowcase());
|
|
366
409
|
* };
|
|
367
410
|
*/
|
|
368
411
|
class PlayShowcase extends CommandBase {
|
|
369
|
-
/**
|
|
370
|
-
* Creates an instance of PlayShowcase.
|
|
371
|
-
*
|
|
372
|
-
* @remarks
|
|
373
|
-
* This constructor does not require any parameters.
|
|
374
|
-
*/
|
|
375
412
|
constructor() {
|
|
376
413
|
super();
|
|
377
414
|
this.data = { action: MetaboxModularConfiguratorActions.playShowcase };
|
|
@@ -394,40 +431,35 @@ class UnrealCommand extends CommandBase {
|
|
|
394
431
|
}
|
|
395
432
|
|
|
396
433
|
/**
|
|
397
|
-
* Represents a command to pause Showcase for a
|
|
398
|
-
*
|
|
399
|
-
* This class sends a command to the Metabox API to pause showcase for a product if it is already initialized and playing.
|
|
434
|
+
* Represents a command to pause Showcase for a component when it is already initialized and playing.
|
|
435
|
+
* This class sends a command to the Metabox API to pause showcase for a component if it is already initialized and playing.
|
|
400
436
|
*
|
|
401
437
|
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
402
|
-
* //...Assume that the integration is already implemented (only once)
|
|
403
|
-
* @example
|
|
404
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
405
438
|
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* @param {ShowCaseStatus} data - showcase status value
|
|
409
|
-
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
410
|
-
* console.log('Showcase status value after changed:', data);
|
|
411
|
-
* });
|
|
412
|
-
* };
|
|
439
|
+
* ### What does it unlock?
|
|
440
|
+
* Pauses the showcase/timeline playback. Can be called independently without requiring any flag parameters.
|
|
413
441
|
*
|
|
414
|
-
*
|
|
442
|
+
* ### Practical Application
|
|
443
|
+
* Pauses showcase animation playback. The showcase remains initialized and can be resumed with
|
|
444
|
+
* PlayShowcase. Use when you need to temporarily freeze the animation (e.g., on a "Pause" button click).
|
|
415
445
|
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
446
|
+
* ### AI Coding Best Practices
|
|
447
|
+
* Call `api.sendCommandToMetabox(new PauseShowcase())`. No parameters. Subscribe to showcaseStatusChanged
|
|
448
|
+
* to confirm 'pause' state. Use PlayShowcase to resume or StopShowcase to reset.
|
|
418
449
|
*
|
|
419
|
-
* @
|
|
450
|
+
* @example
|
|
451
|
+
* import { Communicator, ShowCaseStatus, PauseShowcase } from '@3dsource/metabox-modular-configurator-api';
|
|
420
452
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
421
|
-
*
|
|
453
|
+
*
|
|
454
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
455
|
+
* api.addEventListener('showcaseStatusChanged', (data:ShowCaseStatus) => {
|
|
456
|
+
* console.log('Showcase status value after changed:', data);
|
|
457
|
+
* });
|
|
458
|
+
*
|
|
459
|
+
* api.sendCommandToMetabox(new PauseShowcase());
|
|
422
460
|
* };
|
|
423
461
|
*/
|
|
424
462
|
class PauseShowcase extends CommandBase {
|
|
425
|
-
/**
|
|
426
|
-
* Creates an instance of PauseShowcase.
|
|
427
|
-
*
|
|
428
|
-
* @remarks
|
|
429
|
-
* This constructor does not require any parameters.
|
|
430
|
-
*/
|
|
431
463
|
constructor() {
|
|
432
464
|
super();
|
|
433
465
|
this.data = { action: MetaboxModularConfiguratorActions.pauseShowcase };
|
|
@@ -435,40 +467,36 @@ class PauseShowcase extends CommandBase {
|
|
|
435
467
|
}
|
|
436
468
|
|
|
437
469
|
/**
|
|
438
|
-
* Represents a command to stop Showcase for a
|
|
439
|
-
*
|
|
440
|
-
* This class sends a command to the Metabox API to stop showcase for a product if it is already initialized.
|
|
470
|
+
* Represents a command to stop Showcase for a component when it is already initialized, and you want to destroy it.
|
|
471
|
+
* This class sends a command to the Metabox API to stop showcase for a component if it is already initialized.
|
|
441
472
|
*
|
|
442
473
|
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
443
|
-
* //...Assume that the integration is already implemented (only once)
|
|
444
|
-
* @example
|
|
445
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
446
474
|
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
* @param {ShowCaseStatus} data - showcase status value
|
|
450
|
-
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
451
|
-
* console.log('Showcase status value after changed:', data);
|
|
452
|
-
* });
|
|
453
|
-
* };
|
|
475
|
+
* ### What does it unlock?
|
|
476
|
+
* Stops the showcase/timeline playback and closes the showcase mode. Returns to normal configurator view.
|
|
454
477
|
*
|
|
455
|
-
*
|
|
478
|
+
* ### Practical Application
|
|
479
|
+
* Stops showcase playback and exits showcase mode entirely. Returns to normal interactive configurator view.
|
|
480
|
+
* Use for 'Exit Demo' buttons or auto-trigger when the user starts actively configuring the product.
|
|
456
481
|
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
482
|
+
* ### AI Coding Best Practices
|
|
483
|
+
* Call `api.sendCommandToMetabox(new StopShowcase())`. Fully resets the showcase state. Subscribe to
|
|
484
|
+
* showcaseStatusChanged to confirm 'stopped' status. After stopping, the configurator returns to full
|
|
485
|
+
* interactive mode — re-enable configuration controls.
|
|
459
486
|
*
|
|
460
|
-
* @
|
|
487
|
+
* @example
|
|
488
|
+
* import { Communicator, ShowCaseStatus } from '@3dsource/metabox-modular-configurator-api';
|
|
461
489
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
462
|
-
*
|
|
490
|
+
*
|
|
491
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
492
|
+
* api.addEventListener('showcaseStatusChanged', (data:ShowCaseStatus) => {
|
|
493
|
+
* console.log('Showcase status value after changed:', data);
|
|
494
|
+
* });
|
|
495
|
+
*
|
|
496
|
+
* api.sendCommandToMetabox(new StopShowcase());
|
|
463
497
|
* };
|
|
464
498
|
*/
|
|
465
499
|
class StopShowcase extends CommandBase {
|
|
466
|
-
/**
|
|
467
|
-
* Creates an instance of StopShowcase.
|
|
468
|
-
*
|
|
469
|
-
* @remarks
|
|
470
|
-
* This constructor does not require any parameters.
|
|
471
|
-
*/
|
|
472
500
|
constructor() {
|
|
473
501
|
super();
|
|
474
502
|
this.data = { action: MetaboxModularConfiguratorActions.stopShowcase };
|
|
@@ -477,37 +505,42 @@ class StopShowcase extends CommandBase {
|
|
|
477
505
|
|
|
478
506
|
/**
|
|
479
507
|
* Represents a command to get a screenshot.
|
|
480
|
-
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
481
508
|
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
509
|
+
* To listen for changes after sending this command, listen to the 'screenshot' event before command is sent.
|
|
510
|
+
*
|
|
511
|
+
* ### What does it unlock?
|
|
512
|
+
* Takes a screenshot on the server side (Unreal Engine) of the 3D scene. Returns high-quality image.
|
|
513
|
+
* Requires subscription to the screenshotReady event to receive the rendered image.
|
|
514
|
+
*
|
|
515
|
+
* ### Practical Application
|
|
516
|
+
* Renders a high-res screenshot on the Unreal Engine server. Takes format ('image/png'|'image/jpeg'|'image/webp')
|
|
517
|
+
* and optional size ({x, y}). Returns base64 data via screenshotReady event. Use for thumbnails, social sharing,
|
|
518
|
+
* saving config snapshots, or attaching images to quotes.
|
|
487
519
|
*
|
|
488
|
-
*
|
|
520
|
+
* ### AI Coding Best Practices
|
|
521
|
+
* Subscribe to screenshotReady BEFORE sending GetScreenshot. Pattern:
|
|
522
|
+
* `api.addEventListener('screenshotReady', (data) => { if(data) saveImage(data, 'name.png'); })`.
|
|
523
|
+
* Specify size for consistent outputs: `new GetScreenshot('image/png', {x:2048, y:2048})`.
|
|
524
|
+
* Use saveImage() helper to convert base64 to downloadable file.
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* import { Communicator, saveImage, GetScreenshot } from '@3dsource/metabox-modular-configurator-api';
|
|
489
528
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
490
|
-
*
|
|
491
|
-
*
|
|
529
|
+
*
|
|
530
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
531
|
+
* api.addEventListener('screenshot', (data:string) => {
|
|
532
|
+
* // The data is a base64 string of the image. You can use it to display the image or save it as a file.
|
|
492
533
|
* console.log('Get screenshot here:', data);
|
|
493
534
|
* saveImage(data, 'Render.png');
|
|
494
535
|
* });
|
|
495
|
-
* };
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* import { GetScreenshot, Communicator, saveImage } from '@3dsource/metabox-modular-configurator-api';
|
|
499
536
|
*
|
|
500
|
-
*
|
|
501
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
502
|
-
* api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
537
|
+
* api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
503
538
|
* };
|
|
539
|
+
*
|
|
540
|
+
* @param {MimeType} mimeType - The output format.
|
|
541
|
+
* @param {{ x: number; y: number }} [size] - Optional size in pixels.
|
|
504
542
|
*/
|
|
505
543
|
class GetScreenshot extends CommandBase {
|
|
506
|
-
/**
|
|
507
|
-
* Constructs an instance of GetScreenshot.
|
|
508
|
-
* @param {MimeType} mimeType - The output format.
|
|
509
|
-
* @param {{ x: number; y: number }} [size] - Optional size in pixels.
|
|
510
|
-
*/
|
|
511
544
|
constructor(mimeType, size) {
|
|
512
545
|
super();
|
|
513
546
|
this.data = {
|
|
@@ -519,38 +552,41 @@ class GetScreenshot extends CommandBase {
|
|
|
519
552
|
|
|
520
553
|
/**
|
|
521
554
|
* Represents a command to set a component by its data (ID, typeId).
|
|
522
|
-
*
|
|
523
|
-
* @remarks
|
|
555
|
+
* This action sends a message to the Metabox API to set a component using the provided data.
|
|
524
556
|
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
525
|
-
* //...Assume that the integration is already implemented (only once)
|
|
526
|
-
* @example
|
|
527
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
528
557
|
*
|
|
529
|
-
*
|
|
558
|
+
* ### What does it unlock?
|
|
559
|
+
* Sets a component during initialization, which triggers the reconstruction of the component tree structure.
|
|
560
|
+
* Simulates clicking a component in the menu.
|
|
561
|
+
*
|
|
562
|
+
* ### Practical Application
|
|
563
|
+
* Selects a component in the modular assembly. Takes componentId (UUID), typeId (category string).
|
|
564
|
+
* CRITICAL: Always set root component (isRoot:true) FIRST — nothing renders without it. Then add children (isRoot:false).
|
|
565
|
+
* Simulates clicking a component in the menu.
|
|
566
|
+
*
|
|
567
|
+
* ### AI Coding Best Practices
|
|
568
|
+
* ALWAYS set root first: `new SetComponent('id', 'type', true)`. Then children: `new SetComponent('childId', 'childType', false)`.
|
|
569
|
+
* Get valid IDs from configuratorDataUpdated event data — the configurator definition contains all available components and types.
|
|
570
|
+
* Wrong order = blank viewport. The typeId must match componentType values from the configurator.
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* import { Communicator, ModularConfiguratorEnvelope, SetComponent } from '@3dsource/metabox-modular-configurator-api';
|
|
530
574
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
531
|
-
*
|
|
532
|
-
*
|
|
575
|
+
*
|
|
576
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
577
|
+
* api.addEventListener('configuratorDataUpdated', (data:ModularConfiguratorEnvelope) => {
|
|
533
578
|
* console.log('State updated after applied new component:', data);
|
|
534
579
|
* });
|
|
535
|
-
* };
|
|
536
|
-
*
|
|
537
|
-
* @example
|
|
538
|
-
* import { SetComponent, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
539
580
|
*
|
|
540
|
-
*
|
|
541
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
542
|
-
* api.sendCommandToMetabox(new SetComponent(
|
|
581
|
+
* api.sendCommandToMetabox(new SetComponent(
|
|
543
582
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3', 'typeId'
|
|
544
583
|
* ));
|
|
545
584
|
* };
|
|
585
|
+
*
|
|
586
|
+
* @param {string} id - The component ID.
|
|
587
|
+
* @param {string} typeId - The component type ID.
|
|
546
588
|
*/
|
|
547
589
|
class SetComponent extends CommandBase {
|
|
548
|
-
/**
|
|
549
|
-
* Creates an instance of SetComponent.
|
|
550
|
-
*
|
|
551
|
-
* @param {string} id - The component ID.
|
|
552
|
-
* @param {string} typeId - The component type ID.
|
|
553
|
-
*/
|
|
554
590
|
constructor(id, typeId) {
|
|
555
591
|
super();
|
|
556
592
|
this.data = {
|
|
@@ -562,41 +598,42 @@ class SetComponent extends CommandBase {
|
|
|
562
598
|
|
|
563
599
|
/**
|
|
564
600
|
* Represents a command to set component material by its slot ID and Material ID.
|
|
565
|
-
*
|
|
566
|
-
* @remarks
|
|
567
601
|
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
568
|
-
* //...Assume that the integration is already implemented (only once)
|
|
569
|
-
* @example
|
|
570
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
571
602
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
575
|
-
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
576
|
-
* console.log('State updated after applied new product:', data);
|
|
577
|
-
* });
|
|
578
|
-
* };
|
|
603
|
+
* ### What does it unlock?
|
|
604
|
+
* Sets a material variant for a component. Simulates selecting a different material from the menu for a specific component.
|
|
579
605
|
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
606
|
+
* ### Practical Application
|
|
607
|
+
* Applies a material to a specific slot on a component. Takes componentId (UUID), slotId (string), and materialId (UUID).
|
|
608
|
+
* Use to build swatch pickers, apply preset themes/bundles, or sync material selections from an external
|
|
609
|
+
* PIM/ERP system via externalId mapping.
|
|
582
610
|
*
|
|
583
|
-
*
|
|
611
|
+
* ### AI Coding Best Practices
|
|
612
|
+
* Get valid slotId and materialId values from the configuratorDataUpdated envelope —
|
|
613
|
+
* check component slot definitions and material lists. Pattern:
|
|
614
|
+
* `new SetComponentMaterial('component-uuid', 'slot-name', 'material-uuid')`. The referenced component must already be set in the tree.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* import { Communicator, ModularConfiguratorEnvelope, SetComponentMaterial } from '@3dsource/metabox-modular-configurator-api';
|
|
584
618
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
585
|
-
*
|
|
619
|
+
*
|
|
620
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
621
|
+
* api.addEventListener('configuratorDataUpdated', (data:ModularConfiguratorEnvelope) => {
|
|
622
|
+
* console.log('State updated after applied new material:', data);
|
|
623
|
+
* });
|
|
624
|
+
*
|
|
625
|
+
* api.sendCommandToMetabox(new SetComponentMaterial(
|
|
586
626
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
587
627
|
* 'carpaint',
|
|
588
628
|
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
589
629
|
* ));
|
|
590
630
|
* };
|
|
631
|
+
*
|
|
632
|
+
* @param {string} componentId - The component ID.
|
|
633
|
+
* @param {string} slotId - The slot ID.
|
|
634
|
+
* @param {string} materialId - The material ID.
|
|
591
635
|
*/
|
|
592
636
|
class SetComponentMaterial extends CommandBase {
|
|
593
|
-
/**
|
|
594
|
-
* Creates an instance of SetComponentMaterial.
|
|
595
|
-
*
|
|
596
|
-
* @param {string} componentId - The component ID.
|
|
597
|
-
* @param {string} slotId - The slot ID.
|
|
598
|
-
* @param {string} materialId - The material ID.
|
|
599
|
-
*/
|
|
600
637
|
constructor(componentId, slotId, materialId) {
|
|
601
638
|
super();
|
|
602
639
|
this.data = {
|
|
@@ -608,35 +645,35 @@ class SetComponentMaterial extends CommandBase {
|
|
|
608
645
|
|
|
609
646
|
/**
|
|
610
647
|
* Represents a command to set the environment by its ID.
|
|
611
|
-
*
|
|
612
|
-
* @remarks
|
|
613
648
|
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
614
|
-
* //...Assume that the integration is already implemented (only once)
|
|
615
|
-
* @example
|
|
616
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
617
649
|
*
|
|
618
|
-
*
|
|
650
|
+
* ### What does it unlock?
|
|
651
|
+
* Sets environmental/lighting settings for the scene. Controls factors like lighting conditions and environmental appearance.
|
|
652
|
+
*
|
|
653
|
+
* ### Practical Application
|
|
654
|
+
* Changes the 3D scene/environment (studio, showroom, outdoor, etc.). Takes an environmentId UUID.
|
|
655
|
+
* Environments include lighting, backdrop, and optionally dynamic sky (udsEnabled) with time-of-day (udsHour) control.
|
|
656
|
+
*
|
|
657
|
+
* ### AI Coding Best Practices
|
|
658
|
+
* Call `api.sendCommandToMetabox(new SetEnvironment('env-uuid'))`. Get valid environment IDs from the configurator
|
|
659
|
+
* definition in configuratorDataUpdated. Set environment after root component during initialization. Each environment has
|
|
660
|
+
* its own material slots, thumbnails, and lighting properties.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* import { Communicator, ModularConfiguratorEnvelope } from '@3dsource/metabox-modular-configurator-api';
|
|
619
664
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
620
|
-
*
|
|
621
|
-
*
|
|
665
|
+
*
|
|
666
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
667
|
+
* api.addEventListener('configuratorDataUpdated', (data:ModularConfiguratorEnvelope) => {
|
|
622
668
|
* console.log('State updated after applied new environment:', data);
|
|
623
669
|
* });
|
|
624
|
-
* };
|
|
625
|
-
*
|
|
626
|
-
* @example
|
|
627
|
-
* import { SetEnvironment, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
628
670
|
*
|
|
629
|
-
*
|
|
630
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
631
|
-
* api.sendCommandToMetabox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
671
|
+
* api.sendCommandToMetabox(new SetEnvironment('55555555-1234-1234-1234-01234567890'))
|
|
632
672
|
* };
|
|
673
|
+
*
|
|
674
|
+
* @param {string} environmentId - The environment ID.
|
|
633
675
|
*/
|
|
634
676
|
class SetEnvironment extends CommandBase {
|
|
635
|
-
/**
|
|
636
|
-
* Creates an instance of SetEnvironment.
|
|
637
|
-
*
|
|
638
|
-
* @param {string} environmentId - The environment ID.
|
|
639
|
-
*/
|
|
640
677
|
constructor(environmentId) {
|
|
641
678
|
super();
|
|
642
679
|
this.data = {
|
|
@@ -648,39 +685,40 @@ class SetEnvironment extends CommandBase {
|
|
|
648
685
|
|
|
649
686
|
/**
|
|
650
687
|
* Represents a command to set an environment material by its slot ID and Material ID.
|
|
651
|
-
*
|
|
652
|
-
* @remarks
|
|
653
688
|
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
654
|
-
* //...Assume that the integration is already implemented (only once)
|
|
655
|
-
* @example
|
|
656
|
-
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
657
689
|
*
|
|
658
|
-
*
|
|
690
|
+
* ### What does it unlock?
|
|
691
|
+
* Sets environmental material properties such as textures and appearance attributes for the scene environment.
|
|
692
|
+
*
|
|
693
|
+
* ### Practical Application
|
|
694
|
+
* Applies materials to environment slots (floor, walls, backdrop textures). Takes slotId and materialId.
|
|
695
|
+
* Use for scene-based configurators where the environment is also customizable — kitchen visualizers,
|
|
696
|
+
* room planners, trade show booth designers.
|
|
697
|
+
*
|
|
698
|
+
* ### AI Coding Best Practices
|
|
699
|
+
* Pattern: `new SetEnvironmentMaterial('floor-slot-id', 'material-uuid')`. Get valid slot and material IDs from
|
|
700
|
+
* the environment definition's slots array in configuratorDataUpdated. Only useful when the active environment
|
|
701
|
+
* has configurable material slots.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* import { Communicator, ModularConfiguratorEnvelope } from '@3dsource/metabox-modular-configurator-api';
|
|
659
705
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
660
|
-
*
|
|
661
|
-
*
|
|
706
|
+
*
|
|
707
|
+
* //Subscribe to the event before sending the command to ensure you capture the response
|
|
708
|
+
* api.addEventListener('configuratorDataUpdated', (data:ModularConfiguratorEnvelope) => {
|
|
662
709
|
* console.log('State updated after applied new environment material:', data);
|
|
663
710
|
* });
|
|
664
|
-
* };
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* import { SetEnvironmentMaterial, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
668
711
|
*
|
|
669
|
-
*
|
|
670
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
671
|
-
* api.sendCommandToMetabox(new SetEnvironmentMaterial(
|
|
712
|
+
* api.sendCommandToMetabox(new SetEnvironmentMaterial(
|
|
672
713
|
* 'carpaint',
|
|
673
714
|
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
674
715
|
* ));
|
|
675
716
|
* };
|
|
717
|
+
*
|
|
718
|
+
* @param {string} slotId - The slot ID.
|
|
719
|
+
* @param {string} materialId - The material ID.
|
|
676
720
|
*/
|
|
677
721
|
class SetEnvironmentMaterial extends CommandBase {
|
|
678
|
-
/**
|
|
679
|
-
* Creates an instance of SetEnvironmentMaterial.
|
|
680
|
-
*
|
|
681
|
-
* @param {string} slotId - The slot ID.
|
|
682
|
-
* @param {string} materialId - The material ID.
|
|
683
|
-
*/
|
|
684
722
|
constructor(slotId, materialId) {
|
|
685
723
|
super();
|
|
686
724
|
this.data = {
|
|
@@ -692,24 +730,30 @@ class SetEnvironmentMaterial extends CommandBase {
|
|
|
692
730
|
|
|
693
731
|
/**
|
|
694
732
|
* Represents a command to toggle the embedded Metabox menu.
|
|
695
|
-
* @remarks
|
|
696
733
|
* This command can only be used when using the metabox menu.
|
|
697
|
-
*
|
|
734
|
+
*
|
|
735
|
+
* ### What does it unlock?
|
|
736
|
+
* Shows the embedded menu interface. Only works when using the MetaBox native menu (not in standalone/custom menu
|
|
737
|
+
* mode).
|
|
738
|
+
*
|
|
739
|
+
* ### Practical Application
|
|
740
|
+
* Toggles the native MetaBox right sidebar menu. Takes a boolean parameter. Pass false to hide when building custom UI.
|
|
741
|
+
* In standalone mode, the menu is already hidden — this is only relevant in default (non-standalone) mode.
|
|
742
|
+
*
|
|
743
|
+
* ### AI Coding Best Practices
|
|
744
|
+
* In standalone mode (`{standalone:true}`), this is unnecessary (menu already hidden). In default mode,
|
|
745
|
+
* call `new ShowEmbeddedMenu(false)` early in initialization to hide built-in UI before rendering custom controls.
|
|
746
|
+
* Pattern for custom UI: `ShowEmbeddedMenu(false)` + `ShowOverlayInterface(false)`.
|
|
698
747
|
*
|
|
699
748
|
* @example
|
|
700
749
|
* import { ShowEmbeddedMenu, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
701
|
-
*
|
|
702
|
-
* @param {Communicator} api - communicator instance api
|
|
703
750
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
704
751
|
* api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
|
|
705
752
|
* };
|
|
753
|
+
*
|
|
754
|
+
* @param {boolean} visible - A flag indicating whether the embedded menu should be visible.
|
|
706
755
|
*/
|
|
707
756
|
class ShowEmbeddedMenu extends CommandBase {
|
|
708
|
-
/**
|
|
709
|
-
* Creates an instance of ShowEmbeddedMenu.
|
|
710
|
-
*
|
|
711
|
-
* @param {boolean} visible - A flag indicating whether the embedded menu should be visible.
|
|
712
|
-
*/
|
|
713
757
|
constructor(visible) {
|
|
714
758
|
super();
|
|
715
759
|
this.data = {
|
|
@@ -721,25 +765,30 @@ class ShowEmbeddedMenu extends CommandBase {
|
|
|
721
765
|
|
|
722
766
|
/**
|
|
723
767
|
* Represents a command to toggle the Unreal Overlay Interface Menu.
|
|
724
|
-
*
|
|
725
|
-
* @remarks
|
|
726
768
|
* This action sends a message to the Metabox API to toggle the visibility of the Unreal overlay UI.
|
|
727
|
-
*
|
|
769
|
+
*
|
|
770
|
+
* ### What does it unlock?
|
|
771
|
+
* Shows the overlay interface elements. Displays UI controls and buttons overlaid on the 3D scene.
|
|
772
|
+
*
|
|
773
|
+
* ### Practical Application
|
|
774
|
+
* Toggles viewport overlay controls (buttons overlaid on the 3D scene). Takes a boolean.
|
|
775
|
+
* Use `ShowOverlayInterface(false)` alongside `ShowEmbeddedMenu(false)` when building fully custom UI
|
|
776
|
+
* that replaces all native MetaBox controls.
|
|
777
|
+
*
|
|
778
|
+
* ### AI Coding Best Practices
|
|
779
|
+
* In standalone mode, overlays are already hidden. In default mode, call `new ShowOverlayInterface(false)`
|
|
780
|
+
* early in initialization to prevent flash of native UI. Always pair with `ShowEmbeddedMenu(false)` for clean custom UI.
|
|
781
|
+
* Pass true to restore if entering a mode that uses native controls.
|
|
728
782
|
*
|
|
729
783
|
* @example
|
|
730
784
|
* import { ShowOverlayInterface, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
731
|
-
*
|
|
732
|
-
* @param {Communicator} api - communicator instance api
|
|
733
785
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
734
|
-
* api.
|
|
786
|
+
* api.sendCommandToMetabox(new ShowOverlayInterface(true));
|
|
735
787
|
* };
|
|
788
|
+
*
|
|
789
|
+
* @param {boolean} visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
736
790
|
*/
|
|
737
791
|
class ShowOverlayInterface extends CommandBase {
|
|
738
|
-
/**
|
|
739
|
-
* Creates an instance of ShowOverlayInterface.
|
|
740
|
-
*
|
|
741
|
-
* @param {boolean} visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
742
|
-
*/
|
|
743
792
|
constructor(visible) {
|
|
744
793
|
super();
|
|
745
794
|
this.data = {
|
|
@@ -751,26 +800,26 @@ class ShowOverlayInterface extends CommandBase {
|
|
|
751
800
|
|
|
752
801
|
/**
|
|
753
802
|
* Represents a command to show measurement for a product when it is already loaded.
|
|
754
|
-
* @remarks
|
|
755
803
|
* This class sends a command to the Metabox API to show measurement for a product if it is already initialized.
|
|
756
|
-
*
|
|
757
|
-
*
|
|
804
|
+
*
|
|
805
|
+
* ### What does it unlock?
|
|
806
|
+
* Shows the measurement overlay. Works as a toggle with HideMeasurement to control visibility.
|
|
807
|
+
*
|
|
808
|
+
* ### Practical Application
|
|
809
|
+
* Shows the measurement/dimension overlay tools on the 3D viewport. Use for B2B or technical applications
|
|
810
|
+
* where buyers need to verify product dimensions, check fit specifications, or confirm measurements during procurement.
|
|
811
|
+
*
|
|
812
|
+
* ### AI Coding Best Practices
|
|
813
|
+
* Call `api.sendCommandToMetabox(new ShowMeasurement())`. No parameters. Pair with HideMeasurement for toggle behavior.
|
|
814
|
+
* Track visibility state in your app to keep toggle buttons in sync.
|
|
758
815
|
*
|
|
759
816
|
* @example
|
|
760
817
|
* import { ShowMeasurement, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
761
|
-
*
|
|
762
|
-
* @param {Communicator} api - communicator instance api
|
|
763
818
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
764
819
|
* api.sendCommandToMetabox(new ShowMeasurement());
|
|
765
820
|
* };
|
|
766
821
|
*/
|
|
767
822
|
class ShowMeasurement extends CommandBase {
|
|
768
|
-
/**
|
|
769
|
-
* Creates an instance of ShowMeasurement.
|
|
770
|
-
*
|
|
771
|
-
* @remarks
|
|
772
|
-
* This constructor does not require any parameters.
|
|
773
|
-
*/
|
|
774
823
|
constructor() {
|
|
775
824
|
super();
|
|
776
825
|
this.data = { action: MetaboxModularConfiguratorActions.showMeasurement };
|
|
@@ -779,26 +828,26 @@ class ShowMeasurement extends CommandBase {
|
|
|
779
828
|
|
|
780
829
|
/**
|
|
781
830
|
* Represents a command to hide measurement for a product when it is already loaded.
|
|
782
|
-
* @remarks
|
|
783
831
|
* This class sends a command to the Metabox API to hide measurement for a product if it is already initialized.
|
|
784
|
-
*
|
|
785
|
-
*
|
|
832
|
+
*
|
|
833
|
+
* ### What does it unlock?
|
|
834
|
+
* Hides the measurement overlay. Executes unconditionally to hide the UI controls.
|
|
835
|
+
*
|
|
836
|
+
* ### Practical Application
|
|
837
|
+
* Hides the measurement/dimension overlay. Use when transitioning from a technical spec view back to a clean
|
|
838
|
+
* product presentation, or to keep consumer-facing configurators visually clean.
|
|
839
|
+
*
|
|
840
|
+
* ### AI Coding Best Practices
|
|
841
|
+
* Call `api.sendCommandToMetabox(new HideMeasurement())`. No parameters. Pair with ShowMeasurement as a toggle.
|
|
842
|
+
* Track visibility state in your app state to keep toggle buttons in sync.
|
|
786
843
|
*
|
|
787
844
|
* @example
|
|
788
845
|
* import { HideMeasurement, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
789
|
-
*
|
|
790
|
-
* @param {Communicator} api - communicator instance api
|
|
791
846
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
792
847
|
* api.sendCommandToMetabox(new HideMeasurement());
|
|
793
848
|
* };
|
|
794
849
|
*/
|
|
795
850
|
class HideMeasurement extends CommandBase {
|
|
796
|
-
/**
|
|
797
|
-
* Creates an instance of HideMeasurement.
|
|
798
|
-
*
|
|
799
|
-
* @remarks
|
|
800
|
-
* This constructor does not require any parameters.
|
|
801
|
-
*/
|
|
802
851
|
constructor() {
|
|
803
852
|
super();
|
|
804
853
|
this.data = { action: MetaboxModularConfiguratorActions.hideMeasurement };
|
|
@@ -807,26 +856,29 @@ class HideMeasurement extends CommandBase {
|
|
|
807
856
|
|
|
808
857
|
/**
|
|
809
858
|
* Represents a command to force set the device type.
|
|
810
|
-
*
|
|
811
|
-
* @remarks
|
|
812
859
|
* This class sends a message to the Metabox API to force set the device type.
|
|
813
|
-
*
|
|
814
|
-
*
|
|
860
|
+
*
|
|
861
|
+
* ### What does it unlock?
|
|
862
|
+
* Forces the specification of device type (desktop or mobile) for the MetaBox configurator. Possibly deprecated.
|
|
863
|
+
*
|
|
864
|
+
* ### Practical Application
|
|
865
|
+
* Forces device type override (desktop/tablet/mobile). Likely deprecated — MetaBox auto-detects via ApplicationDeviceTypes.
|
|
866
|
+
* Only relevant for kiosk or showroom setups where you need to force a specific rendering mode.
|
|
867
|
+
*
|
|
868
|
+
* ### AI Coding Best Practices
|
|
869
|
+
* Avoid unless you have a confirmed kiosk/showroom use case. If needed, set it once during initialization only.
|
|
870
|
+
* Prefer letting MetaBox handle device detection automatically.
|
|
815
871
|
*
|
|
816
872
|
* @example
|
|
817
873
|
* import { ForceSetDeviceType, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
818
874
|
*
|
|
819
|
-
* @param {Communicator} api - communicator instance api
|
|
820
875
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
821
876
|
* api.sendCommandToMetabox(new ForceSetDeviceType('desktop'));
|
|
822
877
|
* };
|
|
878
|
+
*
|
|
879
|
+
* @param {ApplicationDeviceTypes} deviceType - The device type to force set.
|
|
823
880
|
*/
|
|
824
881
|
class ForceSetDeviceType extends CommandBase {
|
|
825
|
-
/**
|
|
826
|
-
* Creates an instance of ForceSetDeviceType.
|
|
827
|
-
*
|
|
828
|
-
* @param {ApplicationDeviceTypes} deviceType - The device type to force set.
|
|
829
|
-
*/
|
|
830
882
|
constructor(deviceType) {
|
|
831
883
|
super();
|
|
832
884
|
this.data = {
|
|
@@ -836,8 +888,47 @@ class ForceSetDeviceType extends CommandBase {
|
|
|
836
888
|
}
|
|
837
889
|
}
|
|
838
890
|
|
|
891
|
+
/**
|
|
892
|
+
* Represents a command to resume the pixel streaming session.
|
|
893
|
+
* This class sends a message to the Metabox API to resume a paused or disconnected stream.
|
|
894
|
+
*
|
|
895
|
+
* ### What does it unlock?
|
|
896
|
+
* Resumes the Unreal Engine pixel streaming connection after it has been paused, disconnected, or stopped due to inactivity (AFK timeout).
|
|
897
|
+
*
|
|
898
|
+
* ### Practical Application
|
|
899
|
+
* Used to reconnect the 3D streaming session without a full page reload. Essential for 'Reconnect' or 'Resume' buttons
|
|
900
|
+
* shown when the stream is interrupted, e.g., after an idle timeout or network disruption.
|
|
901
|
+
*
|
|
902
|
+
* ### AI Coding Best Practices
|
|
903
|
+
* Call `api.sendCommandToMetabox(new ResumeStream())`. No parameters. Resumes the existing streaming session —
|
|
904
|
+
* does not reinitialize the configurator or reset component/environment state.
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* import { ResumeStream, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
908
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
909
|
+
* api.sendCommandToMetabox(new ResumeStream());
|
|
910
|
+
* };
|
|
911
|
+
*/
|
|
912
|
+
class ResumeStream extends CommandBase {
|
|
913
|
+
constructor() {
|
|
914
|
+
super();
|
|
915
|
+
this.data = { action: MetaboxModularConfiguratorActions.resumeStream };
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
839
919
|
/**
|
|
840
920
|
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
921
|
+
*
|
|
922
|
+
* ### What does it unlock?
|
|
923
|
+
* Parent class of Communicator that dispatches commands. Acts as an event dispatcher that routes command messages internally.
|
|
924
|
+
*
|
|
925
|
+
* ### Practical Application
|
|
926
|
+
* Internal event routing layer — parent class of Communicator. Routes postMessage commands between your app
|
|
927
|
+
* and the Unreal Engine pixel stream. Not used directly but understanding it helps debug message delivery issues.
|
|
928
|
+
*
|
|
929
|
+
* ### AI Coding Best Practices
|
|
930
|
+
* Do not reference or extend EventDispatcher in application code. Use only the Communicator interface methods.
|
|
931
|
+
* If debugging communication failures, check browser console for postMessage errors related to this layer.
|
|
841
932
|
*/
|
|
842
933
|
class EventDispatcher {
|
|
843
934
|
constructor() {
|
|
@@ -846,6 +937,10 @@ class EventDispatcher {
|
|
|
846
937
|
*/
|
|
847
938
|
this.listeners = [];
|
|
848
939
|
}
|
|
940
|
+
/**
|
|
941
|
+
* Removes all registered listeners. Subclasses override this to perform additional cleanup.
|
|
942
|
+
* @param key - Instance key (used by subclass overrides for registry cleanup).
|
|
943
|
+
*/
|
|
849
944
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
850
945
|
destroy(key) {
|
|
851
946
|
this.listeners = [];
|
|
@@ -887,13 +982,72 @@ class EventDispatcher {
|
|
|
887
982
|
/**
|
|
888
983
|
* @internal
|
|
889
984
|
* @hidden
|
|
890
|
-
*
|
|
891
|
-
|
|
892
|
-
|
|
985
|
+
* Core constants used for host-to-iframe communication and URL construction.
|
|
986
|
+
*/
|
|
987
|
+
/**
|
|
988
|
+
* Storage key for the Metabox Communicator instance registry.
|
|
989
|
+
*
|
|
990
|
+
* ### What does it unlock?
|
|
991
|
+
* Constant string identifier for MetaBox version. Used internally to reference the MetaBox system and versioning.
|
|
992
|
+
*
|
|
993
|
+
* ### Practical Application
|
|
994
|
+
* Internal system reference for versioning.
|
|
995
|
+
* Not needed in front-end application code.
|
|
996
|
+
*
|
|
997
|
+
* ### AI Coding Best Practices
|
|
998
|
+
* Skip in application code. This constant is for internal MetaBox system identification only.
|
|
999
|
+
*
|
|
1000
|
+
* @internal
|
|
893
1001
|
*/
|
|
894
1002
|
const Metabox = 'metabox';
|
|
1003
|
+
/**
|
|
1004
|
+
* Identifier used as the `host` field in postMessage envelopes sent to the iframe.
|
|
1005
|
+
*
|
|
1006
|
+
* ### What does it unlock?
|
|
1007
|
+
* Constant for the MetaBox host connection point. Specifies endpoint for MetaBox connections.
|
|
1008
|
+
*
|
|
1009
|
+
* ### Practical Application
|
|
1010
|
+
* MetaBox endpoint constant. The host the configurator iframe connects to for Unreal Engine pixel streaming.
|
|
1011
|
+
* Not needed in front-end application code.
|
|
1012
|
+
*
|
|
1013
|
+
* ### AI Coding Best Practices
|
|
1014
|
+
* Skip in application code. This constant is for internal MetaBox system identification only.
|
|
1015
|
+
*
|
|
1016
|
+
* @internal
|
|
1017
|
+
*/
|
|
895
1018
|
const MetaboxHost = 'metaboxHost';
|
|
1019
|
+
/**
|
|
1020
|
+
* Action string dispatched by the iframe when the configurator app has loaded.
|
|
1021
|
+
*
|
|
1022
|
+
* ### What does it unlock?
|
|
1023
|
+
* App initialization flag variable. Signals when MetaBox has completed loading.
|
|
1024
|
+
*
|
|
1025
|
+
* ### Practical Application
|
|
1026
|
+
* Use the viewportReady event (more reliable) to gate your UI rendering — don't show controls until MetaBox confirms it's ready.
|
|
1027
|
+
*
|
|
1028
|
+
* ### AI Coding Best Practices
|
|
1029
|
+
* Prefer the viewportReady event over this variable: `api.addEventListener('viewportReady', (ready) => { if(ready) enableUI(); })`.
|
|
1030
|
+
* viewportReady is the reliable signal that MetaBox is ready to accept commands.
|
|
1031
|
+
*
|
|
1032
|
+
* @internal
|
|
1033
|
+
*/
|
|
896
1034
|
const AppLoaded = 'appLoaded';
|
|
1035
|
+
/**
|
|
1036
|
+
* Default MetaBox domain for production environments.
|
|
1037
|
+
*
|
|
1038
|
+
* ### What does it unlock?
|
|
1039
|
+
* Constant for the standard default MetaBox domain. Used as the primary domain for connecting to MetaBox server.
|
|
1040
|
+
*
|
|
1041
|
+
* ### Practical Application
|
|
1042
|
+
* Default MetaBox domain constant (HTTPS). The base domain used when no override is specified.
|
|
1043
|
+
* Override only via IntegrateMetaboxConfig.domain if connecting to a custom or self-hosted MetaBox instance.
|
|
1044
|
+
*
|
|
1045
|
+
* ### AI Coding Best Practices
|
|
1046
|
+
* Let integrateMetabox() use the default. Override only if needed:
|
|
1047
|
+
* `integrateMetabox(id, container, callback, { domain: 'https://custom.domain.com' })`. HTTPS is mandatory.
|
|
1048
|
+
*
|
|
1049
|
+
* @internal
|
|
1050
|
+
*/
|
|
897
1051
|
/**
|
|
898
1052
|
* @deprecated
|
|
899
1053
|
*/
|
|
@@ -907,20 +1061,47 @@ const MetaboxHost_V3 = 'metaboxHost_v3';
|
|
|
907
1061
|
*/
|
|
908
1062
|
const AppLoaded_V3 = 'appLoaded_v3';
|
|
909
1063
|
const MetaboxDomain = 'metabox.3dsource.com';
|
|
1064
|
+
/**
|
|
1065
|
+
* Base route URL segment for the Modular Configurator.
|
|
1066
|
+
*
|
|
1067
|
+
* ### What does it unlock?
|
|
1068
|
+
* Base route URL constant used for loading the configurator. Standard path endpoint for accessing the modular configurator.
|
|
1069
|
+
*
|
|
1070
|
+
* ### Practical Application
|
|
1071
|
+
* The modular configurator URL format is: `https://{domain}/metabox-configurator/modular/{configuratorId}`.
|
|
1072
|
+
* Automatically constructed by integrateMetabox().
|
|
1073
|
+
*
|
|
1074
|
+
* ### AI Coding Best Practices
|
|
1075
|
+
* Let integrateMetabox() handle URL construction. Only reference if building URLs manually
|
|
1076
|
+
* (e.g., QR codes, email links, server-side rendering). The modular path is `/modular/{id}`.
|
|
1077
|
+
*
|
|
1078
|
+
* @internal
|
|
1079
|
+
*/
|
|
910
1080
|
const BasicRouteUrl = 'metabox-configurator/modular';
|
|
911
1081
|
|
|
912
|
-
const VERSION = '3.0.19-dev.
|
|
1082
|
+
const VERSION = '3.0.19-dev.12';
|
|
913
1083
|
|
|
914
1084
|
const communicatorMap = new Map();
|
|
915
1085
|
/**
|
|
916
|
-
* Handles messaging between the host page and embedded
|
|
1086
|
+
* Handles messaging between the host page and embedded Metabox content.
|
|
1087
|
+
*
|
|
1088
|
+
* ### What does it unlock?
|
|
1089
|
+
* Internal class that creates a proxy/communication layer between the API and MetaBox.
|
|
1090
|
+
* Handles reading and sending commands through the established connection.
|
|
1091
|
+
*
|
|
1092
|
+
* ### Practical Application
|
|
1093
|
+
* The API handle returned in the integrateMetabox callback. Provides sendCommandToMetabox() to send commands,
|
|
1094
|
+
* and addEventListener()/removeEventListener() for event subscriptions. This is your entire interface to
|
|
1095
|
+
* the MetaBox Unreal Engine stream.
|
|
1096
|
+
*
|
|
1097
|
+
* ### AI Coding Best Practices
|
|
1098
|
+
* Store the Communicator reference from the apiReadyCallback in a module-scoped variable or state store.
|
|
1099
|
+
* NEVER send commands before this callback fires. All commands and event listeners go through this single
|
|
1100
|
+
* api object. Clean up listeners with removeEventListener on component unmount.
|
|
1101
|
+
*
|
|
917
1102
|
* @internal Use {@link Communicator.createInstance} or the {@link integrateMetabox} helper to instantiate.
|
|
918
1103
|
*/
|
|
919
1104
|
class Communicator extends EventDispatcher {
|
|
920
|
-
/**
|
|
921
|
-
* Singleton reference to the current communicator instance.
|
|
922
|
-
*/
|
|
923
|
-
static { this.instance = null; }
|
|
924
1105
|
/**
|
|
925
1106
|
* Constructs a Communicator, replacing any existing instance, and begins listening for messages.
|
|
926
1107
|
* @internal
|
|
@@ -944,7 +1125,7 @@ class Communicator extends EventDispatcher {
|
|
|
944
1125
|
}
|
|
945
1126
|
/**
|
|
946
1127
|
* Listens for Metabox to signal readiness, then initializes communicator.
|
|
947
|
-
* @param apiReadyCallback - Called with the new Communicator once
|
|
1128
|
+
* @param apiReadyCallback - Called with the new Communicator once the Metabox is loaded.
|
|
948
1129
|
* @param {MetaboxEnvironment} environment - The environment in which the Communicator is running.
|
|
949
1130
|
* @param {MetaboxCommandConfig} config - optional initial config: standalone - if true - disable metabox custom template and all logic
|
|
950
1131
|
*/
|
|
@@ -965,6 +1146,7 @@ class Communicator extends EventDispatcher {
|
|
|
965
1146
|
super.destroy(key);
|
|
966
1147
|
window.removeEventListener('message', this.binder);
|
|
967
1148
|
}
|
|
1149
|
+
/** Destroys all active Communicator instances and clears the internal registry. */
|
|
968
1150
|
static clearAll() {
|
|
969
1151
|
if (communicatorMap.size === 0) {
|
|
970
1152
|
return;
|
|
@@ -972,6 +1154,10 @@ class Communicator extends EventDispatcher {
|
|
|
972
1154
|
communicatorMap.forEach((value, key) => value.instance.destroy(key));
|
|
973
1155
|
communicatorMap.clear();
|
|
974
1156
|
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Retrieves a registered Communicator instance by its key.
|
|
1159
|
+
* @param key - The composite key (`version_environment_appId`) identifying the instance.
|
|
1160
|
+
*/
|
|
975
1161
|
static getCommunicator(key) {
|
|
976
1162
|
return communicatorMap.get(key);
|
|
977
1163
|
}
|
|
@@ -997,7 +1183,9 @@ class Communicator extends EventDispatcher {
|
|
|
997
1183
|
iframe.contentWindow.postMessage(toMetaboxMessage, '*');
|
|
998
1184
|
}
|
|
999
1185
|
/**
|
|
1000
|
-
* Registers an event listener for messages dispatched by Metabox.
|
|
1186
|
+
* Registers an event listener for messages dispatched by the Metabox.
|
|
1187
|
+
* @param messageType - The event name to listen for (e.g. `'configuratorDataUpdated'`).
|
|
1188
|
+
* @param callback - Handler invoked with the typed payload when the event fires.
|
|
1001
1189
|
* @override
|
|
1002
1190
|
*/
|
|
1003
1191
|
addEventListener(messageType, callback) {
|
|
@@ -1005,6 +1193,8 @@ class Communicator extends EventDispatcher {
|
|
|
1005
1193
|
}
|
|
1006
1194
|
/**
|
|
1007
1195
|
* Dispatches a typed event to all registered listeners.
|
|
1196
|
+
* @param messageType - The event name to dispatch.
|
|
1197
|
+
* @param data - The payload to pass to each listener.
|
|
1008
1198
|
* @override
|
|
1009
1199
|
*/
|
|
1010
1200
|
dispatchEvent(messageType, data) {
|
|
@@ -1012,6 +1202,8 @@ class Communicator extends EventDispatcher {
|
|
|
1012
1202
|
}
|
|
1013
1203
|
/**
|
|
1014
1204
|
* Removes a previously registered event listener.
|
|
1205
|
+
* @param messageType - The event name the listener was registered for.
|
|
1206
|
+
* @param callback - The same function reference that was passed to {@link addEventListener}.
|
|
1015
1207
|
* @override
|
|
1016
1208
|
*/
|
|
1017
1209
|
removeEventListener(messageType, callback) {
|
|
@@ -1026,13 +1218,26 @@ class Communicator extends EventDispatcher {
|
|
|
1026
1218
|
return;
|
|
1027
1219
|
}
|
|
1028
1220
|
const data = event.data?.envelope;
|
|
1029
|
-
this.dispatchEvent(data?.eventType, data
|
|
1221
|
+
this.dispatchEvent(data?.eventType, data?.payload);
|
|
1030
1222
|
}
|
|
1031
1223
|
}
|
|
1032
1224
|
|
|
1033
1225
|
/**
|
|
1226
|
+
* Constructs the iframe source URL for the Metabox Modular Configurator.
|
|
1227
|
+
*
|
|
1228
|
+
* ### What does it unlock?
|
|
1229
|
+
* Utility function that prepares the iframe source URL. Constructs the proper URL with parameters
|
|
1230
|
+
* for loading the MetaBox configurator.
|
|
1231
|
+
*
|
|
1232
|
+
* ### Practical Application
|
|
1233
|
+
* Utility function that constructs the iframe source URL with proper parameters.
|
|
1234
|
+
* URL format: `https://{domain}/metabox-configurator/modular/{configuratorId}`.
|
|
1235
|
+
* Called internally by integrateMetabox() — use directly only for manual URL construction.
|
|
1236
|
+
*
|
|
1237
|
+
* ### AI Coding Best Practices
|
|
1238
|
+
* Usually called internally. Use directly only for pre-constructing embed URLs (QR codes, email links,
|
|
1239
|
+
* preview URLs). Verify output is HTTPS. Remember modular configurators use `/modular/` path.
|
|
1034
1240
|
*
|
|
1035
|
-
* @remarks
|
|
1036
1241
|
* @internal
|
|
1037
1242
|
* @hidden
|
|
1038
1243
|
*
|
|
@@ -1062,11 +1267,27 @@ const prepareIframeSrc = (configuratorId, config) => {
|
|
|
1062
1267
|
* Integrates the Metabox Modular Configurator into the page by injecting an iframe and
|
|
1063
1268
|
* initializing a Communicator instance for host-to-iframe messaging.
|
|
1064
1269
|
*
|
|
1065
|
-
* @remarks
|
|
1066
1270
|
* - Builds a secure iframe URL using the provided configuratorId and config options.
|
|
1067
1271
|
* - Ensures the resulting URL uses HTTPS and that the target container exists.
|
|
1068
1272
|
* - Removes any previously embedded iframe with id "embeddedContent" before inserting a new one.
|
|
1069
1273
|
*
|
|
1274
|
+
* ### What does it unlock?
|
|
1275
|
+
* Main initialization function for MetaBox integration. Initializes the configurator, receives an API handle,
|
|
1276
|
+
* and sets up all configurations.
|
|
1277
|
+
*
|
|
1278
|
+
* ### Practical Application
|
|
1279
|
+
* THE entry point function. Creates the configurator iframe, establishes postMessage communication, and returns
|
|
1280
|
+
* the Communicator api handle via callback. Call ONCE per configurator. Params: configuratorId (modular UUID),
|
|
1281
|
+
* containerId (DOM element ID, default 'embed3DSource'), apiReadyCallback, config (IntegrateMetaboxConfig).
|
|
1282
|
+
*
|
|
1283
|
+
* ### AI Coding Best Practices
|
|
1284
|
+
* Pattern: `integrateMetabox('uuid', 'div-id', (api) => {
|
|
1285
|
+
* setup listeners, then set root component, then environment, then children
|
|
1286
|
+
* }, { standalone: true })`.
|
|
1287
|
+
* Ensure container div exists in DOM with non-zero dimensions. HTTPS required.
|
|
1288
|
+
* Inside callback: 1) addEventListener for configuratorDataUpdated, 2) SetComponent root, 3) SetEnvironment,
|
|
1289
|
+
* 4) SetComponent children, 5) SetComponentMaterial.
|
|
1290
|
+
*
|
|
1070
1291
|
* @param {string} configuratorId - The Modular Configurator ID (not a full URL). It is appended to
|
|
1071
1292
|
* `https://{domain}/metabox-configurator/modular/{configuratorId}` to form the iframe src.
|
|
1072
1293
|
*
|
|
@@ -1155,10 +1376,22 @@ function integrateMetabox(configuratorId, containerId, apiReadyCallback, config)
|
|
|
1155
1376
|
/**
|
|
1156
1377
|
* Saves an image by triggering a download.
|
|
1157
1378
|
*
|
|
1158
|
-
* @remarks
|
|
1159
1379
|
* This function creates an anchor element, sets its `href` attribute to the provided image URL,
|
|
1160
1380
|
* and triggers a click event to initiate a download with the specified filename.
|
|
1161
1381
|
*
|
|
1382
|
+
* ### What does it unlock?
|
|
1383
|
+
* Main exported function to save images from the configurator. Converts base64 image data to actual image
|
|
1384
|
+
* files and saves them to the local filesystem.
|
|
1385
|
+
*
|
|
1386
|
+
* ### Practical Application
|
|
1387
|
+
* Exported utility function that converts base64 screenshot data (from screenshotReady event) to a downloadable
|
|
1388
|
+
* image file. Handles the base64 → blob → browser download flow. Import directly from the API package.
|
|
1389
|
+
*
|
|
1390
|
+
* ### AI Coding Best Practices
|
|
1391
|
+
* Pattern: `api.addEventListener('screenshotReady', (data) => { if(data) saveImage(data, 'config-screenshot.png'); })`.
|
|
1392
|
+
* Filename extension should match the MimeType passed to GetScreenshot.
|
|
1393
|
+
* Import: `import { saveImage } from '@3dsource/metabox-modular-configurator-api'`.
|
|
1394
|
+
*
|
|
1162
1395
|
* @param {string} imageUrl - The URL of the image to save.
|
|
1163
1396
|
* @param {string} filename - The name of the file to save.
|
|
1164
1397
|
*/
|
|
@@ -1175,5 +1408,5 @@ function saveImage(imageUrl, filename) {
|
|
|
1175
1408
|
* Generated bundle index. Do not edit.
|
|
1176
1409
|
*/
|
|
1177
1410
|
|
|
1178
|
-
export { AppLoaded, AppLoaded_V3, ApplyZoom, BasicRouteUrl, CommandBase, Communicator, EventDispatcher, ForceSetDeviceType, GetCallToActionInformation, GetCamera, GetPdf, GetScreenshot, HideMeasurement, InitShowcase, Metabox, MetaboxConfig, MetaboxDomain, MetaboxHost, MetaboxHost_V3, MetaboxModularConfiguratorActions, Metabox_V3, PauseShowcase, PlayShowcase, ResetCamera, SetCamera, SetComponent, SetComponentMaterial, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowMeasurement, ShowOverlayInterface, StopShowcase, UnrealCommand, VERSION, fromCommunicatorEvent, integrateMetabox, prepareIframeSrc, saveImage };
|
|
1411
|
+
export { AppLoaded, AppLoaded_V3, ApplyZoom, BasicRouteUrl, CommandBase, Communicator, EventDispatcher, ForceSetDeviceType, GetCallToActionInformation, GetCamera, GetPdf, GetScreenshot, HideMeasurement, InitShowcase, Metabox, MetaboxConfig, MetaboxDomain, MetaboxHost, MetaboxHost_V3, MetaboxModularConfiguratorActions, Metabox_V3, PauseShowcase, PlayShowcase, ResetCamera, ResumeStream, SetCamera, SetComponent, SetComponentMaterial, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowMeasurement, ShowOverlayInterface, StopShowcase, UnrealCommand, VERSION, fromCommunicatorEvent, integrateMetabox, prepareIframeSrc, saveImage };
|
|
1179
1412
|
//# sourceMappingURL=3dsource-metabox-modular-configurator-api.mjs.map
|