@3dsource/metabox-modular-configurator-api 3.0.19-dev.11 → 3.0.19-dev.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,19 +16,10 @@ TypeScript/JavaScript API for integrating Metabox Modular Configurator into web
16
16
  - [TypeScript/Angular/React](#typescriptangularreact)
17
17
  - [API Reference](#api-reference)
18
18
  - [System Terminology](#system-terminology)
19
- - [Building a Custom UI](#building-a-custom-ui)
20
- - [Core Integration](#core-integration)
21
- - [`integrateMetabox`](#integratemetabox)
19
+ - [Core Integration — `integrateMetabox()`](#core-integration--integratemetabox)
22
20
  - [Type Definitions](#type-definitions)
23
21
  - [Core Types](#core-types)
24
- - [`Communicator`](#communicator)
25
- - [`ModularConfiguratorEnvelope`](#modularconfiguratorenvelope)
26
- - [`ModularConfiguratorComponent`](#modularconfiguratorcomponent)
27
- - [`Material`](#material)
28
- - [`Environment`](#environment)
29
22
  - [Utility Types](#utility-types)
30
- - [`MimeType`](#mimetype)
31
- - [`ApplicationDeviceTypes`](#applicationdevicetypes)
32
23
  - [Command Classes](#command-classes)
33
24
  - [Component & Environment Management](#component--environment-management)
34
25
  - [UI Control](#ui-control)
@@ -37,16 +28,18 @@ TypeScript/JavaScript API for integrating Metabox Modular Configurator into web
37
28
  - [Measurement Tools](#measurement-tools)
38
29
  - [Stream Control](#stream-control)
39
30
  - [Export & Media](#export--media)
40
- - [Advanced Commands (Use with Caution)](#advanced-commands-use-with-caution)
41
- - [Event Handling](#event-handling)
42
- - [Available Events](#available-events)
43
- - [Event Examples](#event-examples)
31
+ - [Event Handling](#event-handling)
32
+ - [Available Events](#available-events)
33
+ - [Event Examples](#event-examples)
34
+ - [Standalone Mode](#standalone-mode)
35
+ - [Building a Custom UI](#building-a-custom-ui)
36
+ - [Building a Custom Menu (Preferred Approach)](#building-a-custom-menu-preferred-approach)
37
+ - [Export Configuration](#export-configuration)
44
38
  - [Troubleshooting](#troubleshooting)
45
39
  - [Common Issues](#common-issues)
46
- - [Configurator Not Loading](#configurator-not-loading)
47
- - [Commands Not Working](#commands-not-working)
48
- - [TypeScript Errors](#typescript-errors)
49
- - [Standalone Mode](#standalone-mode)
40
+ - [1. Configurator Not Loading](#1-configurator-not-loading)
41
+ - [2. Commands Not Working](#2-commands-not-working)
42
+ - [Tips & Tricks](#tips--tricks)
50
43
 
51
44
  ## Features
52
45
 
@@ -147,7 +140,7 @@ Create a container element where the configurator will be embedded:
147
140
 
148
141
  ```html
149
142
  <script type="module">
150
- import { GetPdf, GetScreenshot, GetCallToActionInformation, integrateMetabox, saveImage, SetComponent, SetComponentMaterial, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowOverlayInterface, ResetCamera, ApplyZoom } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm';
143
+ import { GetPdf, GetScreenshot, GetCallToActionInformation, integrateMetabox, saveImage, SetComponent, SetComponentMaterial, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowOverlayInterface } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm';
151
144
 
152
145
  // Replace it with your actual configurator ID (not a full URL)
153
146
  const configuratorId = 'configurator-id';
@@ -165,7 +158,7 @@ Create a container element where the configurator will be embedded:
165
158
  saveImage(data, 'configurator-screenshot.png');
166
159
  });
167
160
 
168
- // Set initial configuration
161
+ // Initial commands example
169
162
  api.sendCommandToMetabox(new SetComponent('componentId', 'typeId', true));
170
163
  api.sendCommandToMetabox(new SetEnvironment('environmentId'));
171
164
  api.sendCommandToMetabox(new SetComponentMaterial('componentId', 'slotId', 'materialId'));
@@ -295,33 +288,24 @@ configurator.changeMaterial('componentId', 'seat-fabric', 'leather-brown');
295
288
 
296
289
  ### System Terminology
297
290
 
298
- | Term | Description | Required | Context |
299
- | --------------------- | -------------------------------------------------------------- | -------- | ---------------------- |
300
- | **component** | Modular product part/assembly (e.g., wheel, bumper, seat) | Yes | Modular configurator |
301
- | **componentId** | Unique component identifier (system-generated UUID) | Yes | Component management |
302
- | **componentType** | Category/classification of component (e.g., "wheel", "bumper") | Yes | Component organization |
303
- | **environment** | 3D scene/room environment for product visualization | Yes | Visual context |
304
- | **environmentId** | Unique environment identifier (system-generated UUID) | Yes | Environment management |
305
- | **product** | Base 3D digital twin referenced by components | Yes | Component definition |
306
- | **productId** | Unique product identifier (system-generated UUID) | Yes | Product reference |
307
- | **externalId** | Custom SKU/identifier for external system integration | No | E-commerce integration |
308
- | **showcase** | Camera animation sequence attached to component | No | Component attribute |
309
- | **slotId** | Material slot identifier on component/environment | Yes | Material assignment |
310
- | **materialId** | Unique material identifier | Yes | Material assignment |
311
- | **configurationTree** | Hierarchical structure of component assembly | - | State representation |
312
-
313
- **Key Differences from Basic Configurator:**
314
-
315
- | Aspect | Basic Configurator | Modular Configurator |
316
- | ------------------------ | ---------------------------- | --------------------------------------- |
317
- | **Product Model** | Single monolithic product | Composed of multiple components |
318
- | **Configuration** | Select one product at a time | Assemble components by type |
319
- | **Material Application** | Per-product slots | Per-component and per-environment slots |
320
- | **State Complexity** | Flat structure | Hierarchical tree structure |
291
+ | Term | Description | Context |
292
+ | --------------------- | -------------------------------------------------------------- | ---------------------- |
293
+ | **component** | Modular product part/assembly (e.g., wheel, bumper, seat) | Modular configurator |
294
+ | **componentId** | Unique component identifier (system-generated UUID) | Component management |
295
+ | **componentType** | Category/classification of component (e.g., "wheel", "bumper") | Component organization |
296
+ | **environment** | 3D scene/room environment for product visualization | Visual context |
297
+ | **environmentId** | Unique environment identifier (system-generated UUID) | Environment management |
298
+ | **product** | Base 3D digital twin referenced by components | Component definition |
299
+ | **productId** | Unique product identifier (system-generated UUID) | Product reference |
300
+ | **externalId** | Custom SKU/identifier for external system integration | E-commerce integration |
301
+ | **showcase** | Camera animation sequence attached to component | Component attribute |
302
+ | **slotId** | Material slot identifier on component/environment | Material assignment |
303
+ | **materialId** | Unique material identifier | Material assignment |
304
+ | **configurationTree** | Hierarchical structure of component assembly | State representation |
321
305
 
322
306
  **E-Commerce Configurator (CTA Integration):**
323
307
 
324
- E-Com configurators extend Basic/Modular configurators with a call-to-action button.
308
+ E-Com configurators extend Modular configurators with a call-to-action button.
325
309
 
326
310
  **Configuration:**
327
311
 
@@ -344,59 +328,10 @@ User clicks CTA → Metabox POSTs config JSON → Backend processes → Returns
344
328
 
345
329
  **Use Cases:**
346
330
 
347
- - Generate configuration PDFs
348
- - Create a shopping cart with BOM (Bill of Materials)
349
331
  - Send lead to CRM with component details
350
332
  - Redirect to custom checkout with modular pricing
351
333
 
352
- ### Building a Custom UI
353
-
354
- To create a custom modular configurator interface:
355
-
356
- **1. Listen to Configuration State**
357
-
358
- ```typescript
359
- api.addEventListener('configuratorDataUpdated', (data: ModularConfiguratorEnvelope) => {
360
- // Update UI with component tree, materials, environment
361
- updateComponentSelector(data.componentsByComponentType);
362
- updateMaterialOptions(data.componentMaterialsIds);
363
- });
364
- ```
365
-
366
- **2. Hide Default UI Elements**
367
-
368
- ```typescript
369
- api.sendCommandToMetabox(new ShowEmbeddedMenu(false)); // Hide sidebar
370
- api.sendCommandToMetabox(new ShowOverlayInterface(false)); // Hide viewport controls
371
- ```
372
-
373
- **3. Control Component Assembly**
374
-
375
- ```typescript
376
- // Add root component
377
- api.sendCommandToMetabox(new SetComponent('component-id', 'wheel', true));
378
-
379
- // Add child components
380
- api.sendCommandToMetabox(new SetComponent('tire-id', 'tire', false));
381
-
382
- // Apply materials per component
383
- api.sendCommandToMetabox(new SetComponentMaterial('component-id', 'rim', 'chrome'));
384
-
385
- // Change environment
386
- api.sendCommandToMetabox(new SetEnvironment('environment-id'));
387
- ```
388
-
389
- **4. Export Configuration**
390
-
391
- ```typescript
392
- api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
393
- api.sendCommandToMetabox(new GetPdf());
394
- api.sendCommandToMetabox(new GetCallToActionInformation());
395
- ```
396
-
397
- ### Core Integration
398
-
399
- #### `integrateMetabox()`
334
+ ### Core Integration — `integrateMetabox()`
400
335
 
401
336
  Embeds the Metabox Modular Configurator iframe and establishes communication channel.
402
337
 
@@ -444,11 +379,7 @@ integrateMetabox(
444
379
  (api) => {
445
380
  console.log('Modular configurator ready');
446
381
 
447
- // Set root component
448
- api.sendCommandToMetabox(new SetComponent('comp-1', 'base', true));
449
-
450
- // Set environment
451
- api.sendCommandToMetabox(new SetEnvironment('env-1'));
382
+ // Work with API here, e.g., listen to events or send commands
452
383
  },
453
384
  {
454
385
  standalone: true,
@@ -718,14 +649,6 @@ Supported image formats for screenshots.
718
649
  type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
719
650
  ```
720
651
 
721
- ##### `ApplicationDeviceTypes`
722
-
723
- Device type options for responsive behavior.
724
-
725
- ```typescript
726
- type ApplicationDeviceTypes = 'deviceTypeAuto' | 'deviceTypeMobile' | 'deviceTypeDesktop';
727
- ```
728
-
729
652
  ### Command Classes
730
653
 
731
654
  Commands control configurator behavior. Send via `api.sendCommandToMetabox(new CommandName(...))`.
@@ -755,11 +678,12 @@ api.sendCommandToMetabox(new SetComponentMaterial('wheel-fr', 'rim', 'chrome'));
755
678
 
756
679
  #### UI Control
757
680
 
758
- | Command | Parameters | Description |
759
- | ---------------------- | ------------------------------------ | ------------------------------------ |
760
- | `ShowEmbeddedMenu` | `visible: boolean` | Show/hide right sidebar menu |
761
- | `ShowOverlayInterface` | `visible: boolean` | Show/hide viewport controls |
762
- | `ForceSetDeviceType` | `deviceType: ApplicationDeviceTypes` | Override responsive device detection |
681
+ - Note: ShowEmbeddedMenu and ShowOverlayInterface commands are ineffective in standalone mode.
682
+
683
+ | Command | Parameters | Description |
684
+ | ---------------------- | ------------------ | ---------------------------- |
685
+ | `ShowEmbeddedMenu` | `visible: boolean` | Show/hide right sidebar menu |
686
+ | `ShowOverlayInterface` | `visible: boolean` | Show/hide viewport controls |
763
687
 
764
688
  #### Camera Control
765
689
 
@@ -847,7 +771,7 @@ interface CameraCommandPayload {
847
771
  Notes:
848
772
 
849
773
  - Provide only the limits you want to enforce; unspecified values are left as currently configured by the viewer.
850
- - Rotation units are degrees; positive/negative values follow the viewer’s right‑handed coordinate system.
774
+ - Rotation units are degrees; positive/negative values follow the viewer's right‑handed coordinate system.
851
775
  - In `orbit` mode, distance limits are interpreted relative to the orbit pivot.
852
776
  - `ResetCamera` restores the default position/rotation/FOV defined by the current product or environment template.
853
777
 
@@ -890,7 +814,7 @@ api.sendCommandToMetabox(new ResumeStream());
890
814
 
891
815
  ##### `saveImage()`
892
816
 
893
- Triggers a browser download of an image from a data URL or blob URL.
817
+ Helper function: triggers a browser download of an image from a data URL or blob URL.
894
818
 
895
819
  **Signature:**
896
820
 
@@ -913,29 +837,6 @@ api.addEventListener('screenshotReady', (imageData) => {
913
837
  });
914
838
  ```
915
839
 
916
- #### Advanced Commands (Use with Caution)
917
-
918
- | Command | Parameters | Description |
919
- | --------------- | --------------------------------------------- | ----------------------------------- |
920
- | `UnrealCommand` | `payload: object` | Send raw command to Unreal Engine |
921
- | `MetaboxConfig` | `appId: string, config: MetaboxCommandConfig` | Internal initialization (auto-sent) |
922
-
923
- **Warning:** `UnrealCommand` bypasses API validation. Use only for custom Unreal-specific features.
924
-
925
- ```typescript
926
- // Example: Custom lighting control
927
- api.sendCommandToMetabox(
928
- new UnrealCommand({
929
- action: 'SetLightIntensity',
930
- lightId: 'keyLight',
931
- value: 2.5,
932
- }),
933
- );
934
-
935
- // Object-based command
936
- api.sendCommandToMetabox(new UnrealCommand({ action: 'SetSunTime', value: '14:30' }));
937
- ```
938
-
939
840
  ### Event Handling
940
841
 
941
842
  Event-driven architecture for reactive state management. Register listeners via `api.addEventListener(eventName, handler)`.
@@ -998,139 +899,82 @@ api.addEventListener('statusMessageChanged', (message: string | null) => {
998
899
  });
999
900
  ```
1000
901
 
1001
- ## Troubleshooting
1002
-
1003
- ### Common Issues
1004
-
1005
- #### Configurator Not Loading
1006
-
1007
- **Symptoms:** Blank screen, iframe not appearing, loading indefinitely
1008
-
1009
- **Root Causes & Solutions:**
1010
-
1011
- | Issue | Diagnostic | Solution |
1012
- | --------------------------- | ------------------------------------ | --------------------------------------------------------- |
1013
- | Invalid configurator ID | Browser console shows 404 errors | Verify modular configurator ID in Metabox admin |
1014
- | Container not found | `Error: Container element not found` | Ensure element exists before calling `integrateMetabox()` |
1015
- | HTTP instead of HTTPS | Mixed content warnings | Use HTTPS or test on localhost |
1016
- | Container has no dimensions | Invisible iframe (0x0) | Set explicit width/height on container element |
1017
- | CORS/iframe blocking | X-Frame-Options errors | Check domain allowlist in Metabox settings |
1018
-
1019
- **Diagnostic Code:**
902
+ **Showcase Control:**
1020
903
 
1021
904
  ```typescript
1022
- const containerId = 'embed3DSource';
1023
- const container = document.getElementById(containerId);
1024
-
1025
- if (!container) {
1026
- throw new Error(`Container #${containerId} not found`);
1027
- }
1028
-
1029
- // Verify container has dimensions
1030
- const rect = container.getBoundingClientRect();
1031
- if (rect.width === 0 || rect.height === 0) {
1032
- console.warn('⚠️ Container has no dimensions');
1033
- }
1034
-
1035
- if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
1036
- console.warn('⚠️ HTTPS required for Unreal Engine streaming');
1037
- }
1038
-
1039
- integrateMetabox('config-id', containerId, (api) => {
1040
- console.log('✅ Modular configurator loaded');
905
+ api.addEventListener('showcaseStatusChanged', (status: ShowCaseStatus) => {
906
+ const playButton = document.getElementById('play-btn');
907
+
908
+ switch (status) {
909
+ case 'play':
910
+ playButton.textContent = 'Pause';
911
+ break;
912
+ case 'pause':
913
+ case 'stop':
914
+ playButton.textContent = 'Play';
915
+ break;
916
+ }
1041
917
  });
1042
918
  ```
1043
919
 
1044
- #### Commands Not Working
1045
-
1046
- **Symptoms:** Commands sent but no visual changes in configurator
1047
-
1048
- **Common Mistakes:**
920
+ ### Utility Functions
1049
921
 
1050
- | Mistake | Problem | Solution |
1051
- | ------------------------ | ------------------- | ----------------------------------------------- |
1052
- | Sending before API ready | Commands ignored | Only send in `apiReadyCallback` |
1053
- | Wrong component IDs | Component not found | Verify IDs from `configuratorDataUpdated` event |
1054
- | Root component not set | Blank configuration | Set root component first with `isRoot: true` |
1055
- | Type mismatch | Component rejected | Ensure `typeId` matches available types |
922
+ #### `saveImage(imageUrl: string, filename: string): void`
1056
923
 
1057
- **Correct Pattern:**
924
+ Downloads base64-encoded image to user's device.
1058
925
 
1059
- ```typescript
1060
- integrateMetabox('config-id', 'container', (api) => {
1061
- // ✅ Correct: Commands sent after API ready
926
+ **Parameters:**
1062
927
 
1063
- // First: Set root component
1064
- api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
928
+ | Parameter | Type | Description |
929
+ | ---------- | -------- | --------------------------------------------------- |
930
+ | `imageUrl` | `string` | Base64 data URL (e.g., `data:image/png;base64,...`) |
931
+ | `filename` | `string` | Desired filename with extension |
1065
932
 
1066
- // Then: Add child components
1067
- api.sendCommandToMetabox(new SetComponent('comp-2', 'wheel', false));
933
+ **Example:**
1068
934
 
1069
- // Finally: Apply materials
1070
- api.sendCommandToMetabox(new SetComponentMaterial('comp-1', 'body', 'blue'));
935
+ ```typescript
936
+ api.addEventListener('screenshotReady', (imageData: string | null) => {
937
+ if (imageData) {
938
+ saveImage(imageData, `config-${Date.now()}.png`);
939
+ }
1071
940
  });
1072
-
1073
- // ❌ Wrong: Command sent too early
1074
- api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
1075
941
  ```
1076
942
 
1077
- #### TypeScript Errors
1078
-
1079
- **Problem:** Compilation errors with API types
1080
-
1081
- **Solutions:**
943
+ **Implementation Note:**
944
+ Creates a temporary anchor element with `download` attribute to trigger browser download.
1082
945
 
1083
- **Import types correctly:**
946
+ #### `fromCommunicatorEvent(target: Communicator, eventName: string): Observable`
1084
947
 
1085
- ```typescript
1086
- // ✅ Correct
1087
- import type { Communicator, ModularConfiguratorEnvelope, ModularConfiguratorComponent } from '@3dsource/metabox-modular-configurator-api';
1088
-
1089
- // ❌ Wrong
1090
- import { Communicator } from '@3dsource/metabox-modular-configurator-api/types';
1091
- ```
1092
-
1093
- **Update `tsconfig.json`:**
948
+ RxJS wrapper for Communicator events. Works like RxJS `fromEvent` — creates a typed Observable that emits each time the specified event fires. Alternative to `api.addEventListener()`.
1094
949
 
1095
- ```json
1096
- {
1097
- "compilerOptions": {
1098
- "moduleResolution": "node",
1099
- "esModuleInterop": true,
1100
- "skipLibCheck": true,
1101
- "strict": true
1102
- }
1103
- }
1104
- ```
950
+ **Parameters:**
1105
951
 
1106
- #### Component Tree Issues
952
+ | Parameter | Type | Description |
953
+ | ----------- | -------------- | -------------------------------------------- |
954
+ | `target` | `Communicator` | The Communicator instance to listen on |
955
+ | `eventName` | `string` | Event name (e.g., `configuratorDataUpdated`) |
1107
956
 
1108
- **Problem:** Components not appearing in correct hierarchy
957
+ **Returns:** `Observable<T>` — typed Observable matching the event payload.
1109
958
 
1110
- **Solution:** Understand component relationships
959
+ **Example:**
1111
960
 
1112
961
  ```typescript
1113
- // Component tree structure:
1114
- // Root (chassis)
1115
- // ├── Child (wheel-front-left)
1116
- // ├── Child (wheel-front-right)
1117
- // └── Child (engine)
1118
-
1119
- // Correct order:
1120
- api.sendCommandToMetabox(new SetComponent('chassis', 'base', true)); // Root first
1121
- api.sendCommandToMetabox(new SetComponent('wh-fl', 'wheel', false)); // Children after
1122
- api.sendCommandToMetabox(new SetComponent('wh-fr', 'wheel', false));
1123
- api.sendCommandToMetabox(new SetComponent('engine', 'engine', false));
1124
- ```
962
+ import { fromCommunicatorEvent } from '@3dsource/metabox-modular-configurator-api';
1125
963
 
1126
- ---
964
+ integrateMetabox('configurator-id', 'embed3DSource', (api) => {
965
+ fromCommunicatorEvent(api, 'configuratorDataUpdated').subscribe((data) => {
966
+ console.log('Components:', data.componentsByComponentType);
967
+ });
1127
968
 
1128
- For more examples and advanced usage, visit
1129
- our [documentation site](https://preview.3dsource.com/front-libraries/master/modular-configurator-api-doc/).
969
+ fromCommunicatorEvent(api, 'screenshotReady').subscribe((imageData) => {
970
+ if (imageData) saveImage(imageData, 'screenshot.png');
971
+ });
972
+ });
973
+ ```
1130
974
 
1131
975
  ## Standalone Mode
1132
976
 
1133
- Headless rendering mode for custom UI implementations. Disables all built-in Metabox UI elements.
977
+ Headless rendering mode for custom UI implementations. Disables all built-in Metabox UI elements. Pass `{ standalone: true }` as the config option to `integrateMetabox()`.
1134
978
 
1135
979
  ### When to Use Standalone Mode
1136
980
 
@@ -1163,26 +1007,15 @@ Headless rendering mode for custom UI implementations. Disables all built-in Met
1163
1007
  **TypeScript:**
1164
1008
 
1165
1009
  ```typescript
1166
- import { integrateMetabox, SetComponent, SetEnvironment, SetComponentMaterial } from '@3dsource/metabox-modular-configurator-api';
1010
+ import { integrateMetabox, Communicator } from '@3dsource/metabox-modular-configurator-api';
1167
1011
 
1168
1012
  integrateMetabox(
1169
1013
  'modular-config-id',
1170
1014
  'embed3DSource',
1171
- (api) => {
1172
- // REQUIRED: Set root component first
1173
- api.sendCommandToMetabox(new SetComponent('chassis-001', 'base', true));
1174
-
1175
- // Optional: Add child components
1176
- api.sendCommandToMetabox(new SetComponent('wheel-fl', 'wheel', false));
1177
- api.sendCommandToMetabox(new SetComponent('wheel-fr', 'wheel', false));
1178
-
1179
- // Optional: Set environment
1180
- api.sendCommandToMetabox(new SetEnvironment('studio-white'));
1181
-
1182
- // Optional: Apply initial materials
1183
- api.sendCommandToMetabox(new SetComponentMaterial('chassis-001', 'body', 'metallic-blue'));
1015
+ (api: Communicator) => {
1016
+ // Work with API here
1184
1017
  },
1185
- { standalone: true },
1018
+ { standalone: true }, // <- Enable standalone mode to disable default UI
1186
1019
  );
1187
1020
  ```
1188
1021
 
@@ -1190,70 +1023,263 @@ integrateMetabox(
1190
1023
 
1191
1024
  ```html
1192
1025
  <script type="module">
1193
- import { integrateMetabox, SetComponent, SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm';
1026
+ import { integrateMetabox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm';
1194
1027
 
1195
1028
  integrateMetabox(
1196
1029
  'config-id',
1197
1030
  'container-id',
1198
1031
  (api) => {
1199
- // Must set a root component
1200
- api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
1201
- api.sendCommandToMetabox(new SetEnvironment('env-1'));
1032
+ // Work with API here
1202
1033
  },
1203
- { standalone: true },
1034
+ { standalone: true }, // <- Enable standalone mode to disable default UI
1204
1035
  );
1205
1036
  </script>
1206
1037
  ```
1207
1038
 
1208
- ### Important Notes
1039
+ ## Building a Custom UI
1209
1040
 
1210
- ⚠️ **Critical:** Standalone mode starts with blank viewport. You **must** send `SetComponent` (with `isRoot: true`) and `SetEnvironment` commands to initialize.
1041
+ To create a custom modular configurator interface, use [standalone mode](#standalone-mode) and subscribe to events before sending commands.
1211
1042
 
1212
- ✅ **Working:**
1043
+ **Important:** The components menu approach below is used only for building a custom components menu. For building a custom environments menu, iterate `configurator.environments` directly and use `environmentMaterialsIds` to show active materials by slots.
1213
1044
 
1214
- - All events (`configuratorDataUpdated`, `screenshotReady`, etc.)
1215
- - All commands (component assembly, materials, environment)
1216
- - Screenshot and PDF export
1217
- - Validation (HTTPS enforcement, required parameters)
1218
-
1219
- 🎯 **Best Practice:**
1045
+ **Core Pattern:**
1220
1046
 
1221
1047
  ```typescript
1048
+ import { integrateMetabox, Communicator, ModularConfiguratorEnvelope } from '@3dsource/metabox-modular-configurator-api';
1049
+
1222
1050
  integrateMetabox(
1223
- 'id',
1224
- 'container',
1225
- (api) => {
1226
- // 1. Listen for state changes first
1227
- api.addEventListener('configuratorDataUpdated', (data) => {
1228
- updateCustomComponentTree(data.configurationTree);
1229
- updateMaterialSelectors(data.componentMaterialsIds);
1051
+ 'configurator-uuid',
1052
+ 'containerId',
1053
+ (api: Communicator) => {
1054
+ // 1. Subscribe to events BEFORE sending commands
1055
+ api.addEventListener('configuratorDataUpdated', (data: ModularConfiguratorEnvelope) => {
1056
+ // data.configurator.componentTypes — available component types
1057
+ // data.configurator.connectors — available connectors
1058
+ // data.configurator.environments — scene list
1059
+ // data.configurationTree — ordered tree of active components
1060
+ });
1061
+ api.addEventListener('viewportReady', (ready) => {
1062
+ /* gate UI on this */
1230
1063
  });
1231
1064
 
1232
- // 2. Set root component (mandatory)
1233
- api.sendCommandToMetabox(new SetComponent('root-1', 'base', true));
1234
-
1235
- // 3. Set environment
1236
- api.sendCommandToMetabox(new SetEnvironment('studio-env'));
1237
-
1238
- // 4. Build component tree
1239
- api.sendCommandToMetabox(new SetComponent('child-1', 'wheel', false));
1240
- api.sendCommandToMetabox(new SetComponent('child-2', 'wheel', false));
1065
+ // 2. Send commands via api.sendCommandToMetabox(new CommandClass(...args))
1241
1066
  },
1242
1067
  { standalone: true },
1243
1068
  );
1244
1069
  ```
1245
1070
 
1246
- ### Component Assembly in Standalone Mode
1071
+ ### Building a Custom Menu (Preferred Approach)
1072
+
1073
+ The menu **must** follow the `configurationTree` order — NOT iterate `componentTypes` or components as separate flat lists.
1074
+
1075
+ **Data Sources from `ModularConfiguratorEnvelope`:**
1076
+
1077
+ | Field | Type | Purpose |
1078
+ | --------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------- |
1079
+ | `configurationTree` | `ComponentWithParent[]` | Ordered tree of active component nodes (`id`, `componentTypeId`, `parentId`) |
1080
+ | `componentsByComponentType` | `Record<string, string>` | Maps `componentTypeId` → active `componentId` |
1081
+ | `componentMaterialsIds` | `SelectedIds` (`Record<string, Record<string, string>>`) | Maps `componentId` → `{ slotId: materialId }` |
1082
+ | `configurator` | `InitialModularConfigurator` | Catalog: all `componentTypes`, `components`, `environments`, `connectors` |
1083
+
1084
+ **Algorithm:**
1085
+
1086
+ Iterate `configurationTree` nodes. For each node:
1087
+
1088
+ 1. **Find the component type** — `configurator.componentTypes.find(t => t.id === node.componentTypeId)`
1089
+ 2. **Render a component selector** — show all components of that type (from `configurator.components` filtered by `componentType.id`). The active component is `componentsByComponentType[typeId]`.
1090
+ 3. **Render material slots** — for the active component, show its `product.slots` (filtered to those with `enabledMaterials.length > 0`). The selected material for each slot comes from `componentMaterialsIds[componentId][slotId]`.
1091
+
1092
+ This produces a single ordered list interleaved as: **Type1 selector → Type1 material slots → Type2 selector → Type2 material slots → …**
1093
+
1094
+ **Example (Angular Signals):**
1095
+
1096
+ ```typescript
1097
+ import { computed, signal } from '@angular/core';
1098
+ import type { Communicator, ModularConfiguratorEnvelope, ModularConfiguratorComponent, Slot } from '@3dsource/metabox-modular-configurator-api';
1099
+ import { fromCommunicatorEvent, SetComponent, SetComponentMaterial } from '@3dsource/metabox-modular-configurator-api';
1100
+
1101
+ // Store envelope data as a signal (updated on each configuratorDataUpdated event)
1102
+ const envelope = signal<ModularConfiguratorEnvelope | null>(null);
1103
+
1104
+ // Subscribe to API events
1105
+ function listenApi(api: Communicator) {
1106
+ fromCommunicatorEvent(api, 'configuratorDataUpdated').subscribe((data) => {
1107
+ envelope.set(data);
1108
+ });
1109
+ }
1110
+
1111
+ // Build menu tree as a computed signal following configurationTree order
1112
+ const menuTree = computed(() => {
1113
+ const data = envelope();
1114
+ if (!data) return [];
1115
+
1116
+ const { configurator, configurationTree, componentsByComponentType, componentMaterialsIds } = data;
1117
+ const menuItems: MenuEntry[] = [];
1118
+
1119
+ for (const node of configurationTree) {
1120
+ const ct = configurator.componentTypes.find((t) => t.id === node.componentTypeId);
1121
+ if (!ct) continue;
1122
+
1123
+ const components = configurator.components.filter((c) => c.componentType.id === ct.id).sort((a, b) => a.position - b.position);
1124
+ const activeComponentId = componentsByComponentType[ct.id];
1125
+ const activeComponent = components.find((c) => c.id === activeComponentId);
1126
+
1127
+ // 1. Component type selector
1128
+ menuItems.push({
1129
+ id: ct.id,
1130
+ category: ct.name,
1131
+ options: components.map((item) => ({
1132
+ label: item.name,
1133
+ id: item.id,
1134
+ image: item.product.thumbnailList[0]?.urlPath,
1135
+ action: () => api.sendCommandToMetabox(new SetComponent(item.id, ct.id, ct.isRoot)),
1136
+ })),
1137
+ selectedId: activeComponentId,
1138
+ selectedLabel: activeComponent?.name,
1139
+ });
1140
+
1141
+ // 2. Material slots for the active component
1142
+ if (activeComponent) {
1143
+ for (const slot of activeComponent.product.slots) {
1144
+ if (slot.enabledMaterials.length === 0) continue;
1145
+ const selectedMaterialId = componentMaterialsIds?.[activeComponent.id]?.[slot.id];
1146
+
1147
+ menuItems.push({
1148
+ id: `${activeComponent.id}:${slot.id}`,
1149
+ category: slot.label,
1150
+ options: slot.enabledMaterials.map((mat) => ({
1151
+ label: mat.title,
1152
+ id: mat.id,
1153
+ image: mat.thumbnailList[0]?.urlPath,
1154
+ action: () => api.sendCommandToMetabox(new SetComponentMaterial(activeComponent.id, slot.id, mat.id)),
1155
+ })),
1156
+ selectedId: selectedMaterialId,
1157
+ selectedLabel: slot.enabledMaterials.find((m) => m.id === selectedMaterialId)?.title,
1158
+ });
1159
+ }
1160
+ }
1161
+ }
1162
+
1163
+ return menuItems;
1164
+ });
1165
+ ```
1166
+
1167
+ **Commands for Selection:**
1168
+
1169
+ | Action | Command | Args |
1170
+ | ---------------- | ------------------------------------------------------- | -------------------------------------------------------------------------------------- |
1171
+ | Select component | `SetComponent(id, typeId, isRoot)` | `id`: component ID, `typeId`: component type ID, `isRoot`: from `componentType.isRoot` |
1172
+ | Select material | `SetComponentMaterial(componentId, slotId, materialId)` | all three IDs required |
1173
+
1174
+ **Anti-Patterns:**
1175
+
1176
+ - **DON'T** build two separate lists (component types + material slots) — this loses tree ordering
1177
+ - **DON'T** iterate `configurator.componentTypes` directly — use `configurationTree` to determine which types are active and their order
1178
+ - **DON'T** show all component types — only those present as keys in `componentsByComponentType` (i.e., matching `configurationTree` nodes)
1179
+
1180
+ ### Export Configuration
1181
+
1182
+ ```typescript
1183
+ api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
1184
+ api.sendCommandToMetabox(new GetPdf());
1185
+ api.sendCommandToMetabox(new GetCallToActionInformation());
1186
+ ```
1187
+
1188
+ ## Troubleshooting
1189
+
1190
+ ### Common Issues
1191
+
1192
+ #### 1. Configurator Not Loading
1193
+
1194
+ **Symptoms:** Blank screen, iframe not appearing, loading indefinitely
1195
+
1196
+ **Root Causes & Solutions:**
1197
+
1198
+ | Issue | Diagnostic | Solution |
1199
+ | --------------------------- | ------------------------------------ | --------------------------------------------------------- |
1200
+ | Invalid configurator ID | Browser console shows 404 errors | Verify modular configurator ID in Metabox admin |
1201
+ | Container not found | `Error: Container element not found` | Ensure element exists before calling `integrateMetabox()` |
1202
+ | HTTP instead of HTTPS | Mixed content warnings | Use HTTPS or test on localhost |
1203
+ | Container has no dimensions | Invisible iframe (0x0) | Set explicit width/height on container element |
1204
+ | CORS/iframe blocking | X-Frame-Options errors | Check domain allowlist in Metabox settings |
1205
+
1206
+ **Diagnostic Code:**
1207
+
1208
+ ```typescript
1209
+ const containerId = 'embed3DSource';
1210
+ const container = document.getElementById(containerId);
1211
+
1212
+ if (!container) {
1213
+ throw new Error(`Container #${containerId} not found`);
1214
+ }
1215
+
1216
+ // Verify container has dimensions
1217
+ const rect = container.getBoundingClientRect();
1218
+ if (rect.width === 0 || rect.height === 0) {
1219
+ console.warn('⚠️ Container has no dimensions');
1220
+ }
1221
+
1222
+ if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
1223
+ console.warn('⚠️ HTTPS required for Unreal Engine streaming');
1224
+ }
1225
+
1226
+ integrateMetabox('config-id', containerId, (api) => {
1227
+ console.log('✅ Modular configurator loaded');
1228
+ });
1229
+ ```
1230
+
1231
+ #### 2. Commands Not Working
1232
+
1233
+ **Symptoms:** Commands sent but no visual changes in configurator
1234
+
1235
+ **Common Mistakes:**
1236
+
1237
+ | Mistake | Problem | Solution |
1238
+ | ------------------------ | ------------------- | ----------------------------------------------- |
1239
+ | Sending before API ready | Commands ignored | Only send in `apiReadyCallback` |
1240
+ | Wrong component IDs | Component not found | Verify IDs from `configuratorDataUpdated` event |
1241
+ | Type mismatch | Component rejected | Ensure `typeId` matches available types |
1247
1242
 
1248
- **Key Requirement:** Always set a root component first:
1243
+ **Correct Pattern:**
1249
1244
 
1250
1245
  ```typescript
1251
- // ✅ Correct order
1252
- api.sendCommandToMetabox(new SetComponent('base', 'chassis', true)); // Root
1253
- api.sendCommandToMetabox(new SetComponent('wh1', 'wheel', false)); // Child 1
1254
- api.sendCommandToMetabox(new SetComponent('wh2', 'wheel', false)); // Child 2
1255
-
1256
- // ❌ Wrong: No root component
1257
- api.sendCommandToMetabox(new SetComponent('wh1', 'wheel', false));
1258
- // Result: Nothing will render
1246
+ integrateMetabox('config-id', 'container', (api) => {
1247
+ // ✅ Correct: Commands sent after API ready
1248
+
1249
+ // First: Set root component
1250
+ api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
1251
+
1252
+ // Then: Add child components
1253
+ api.sendCommandToMetabox(new SetComponent('comp-2', 'wheel', false));
1254
+
1255
+ // Finally: Apply materials
1256
+ api.sendCommandToMetabox(new SetComponentMaterial('comp-1', 'body', 'blue'));
1257
+ });
1258
+
1259
+ // ❌ Wrong: Command sent too early
1260
+ api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
1259
1261
  ```
1262
+
1263
+ ### Getting Help
1264
+
1265
+ If you're still experiencing issues:
1266
+
1267
+ 1. Check the browser console for error messages
1268
+ 2. Verify your configurator ID in a separate browser tab
1269
+ 3. Test with a minimal example to isolate the issue
1270
+ 4. Contact support with: browser version, configurator URL, console errors, and steps to reproduce
1271
+
1272
+ ## Tips & Tricks
1273
+
1274
+ - **Debounce rapid commands.** Avoid sending too many commands in quick succession — debounce material or component changes (e.g., 300 ms).
1275
+ - **Responsive container.** Set the configurator container to responsive dimensions (`width: 100%; height: 100%;`) and adjust with media queries for mobile.
1276
+ - **Events work in all modes.** `configuratorDataUpdated`, `screenshotReady`, and other events fire in both default and standalone mode — use them to keep your UI synchronized.
1277
+ - **Wait for API ready.** Only send commands inside the `apiReadyCallback`. Commands sent before initialization are silently ignored.
1278
+ - **Validate IDs from events.** Use the `configuratorDataUpdated` event payload to discover valid component, material, and slot IDs rather than hardcoding them.
1279
+ - **HTTPS is required.** The iframe URL enforces HTTPS. HTTP URLs will be rejected. Use `localhost` for local development.
1280
+ - **Pin CDN versions in production.** Replace `@latest` with a specific version to avoid unexpected breaking changes.
1281
+
1282
+ ---
1283
+
1284
+ For more examples and advanced usage, visit
1285
+ our [documentation site](https://preview.3dsource.com/front-libraries/master/modular-configurator-api-doc/).