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