@3dsource/metabox-front-api 3.0.16-dev.6 → 3.0.16-dev.8

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
@@ -7,17 +7,16 @@ TypeScript/JavaScript API for integrating Metabox Basic Configurator into web ap
7
7
  - [Features](#features)
8
8
  - [Prerequisites](#prerequisites)
9
9
  - [Installation](#installation)
10
- - [Method 1: NPM Package (Recommended)](#method-1-npm-package-recommended)
11
- - [Method 2: CDN Import (Quick Prototyping)](#method-2-cdn-import-quick-prototyping)
10
+ - [NPM Installation (Recommended)](#npm-installation-recommended)
11
+ - [CDN Installation (Quick Prototyping)](#cdn-installation-quick-prototyping)
12
12
  - [Quick Start](#quick-start)
13
13
  - [1. HTML Setup](#1-html-setup)
14
14
  - [2. Basic Integration](#2-basic-integration)
15
- - [JavaScript Example](#javascript-example)
16
- - [TypeScript Example](#typescript-example)
15
+ - [JavaScript (ES6 Modules)](#javascript-es6-modules)
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 Functions](#core-functions)
19
+ - [Core Integration — `integrateMetabox()`](#core-integration--integratemetabox)
21
20
  - [Command Classes](#command-classes)
22
21
  - [Product & Environment Management](#product--environment-management)
23
22
  - [UI Control](#ui-control)
@@ -26,16 +25,21 @@ TypeScript/JavaScript API for integrating Metabox Basic Configurator into web ap
26
25
  - [Measurement Tools](#measurement-tools)
27
26
  - [Stream Control](#stream-control)
28
27
  - [Export & Media](#export--media)
29
- - [Advanced Commands (Use with Caution)](#advanced-commands-use-with-caution)
30
28
  - [Event Handling](#event-handling)
31
29
  - [Available Events](#available-events)
32
30
  - [Event Examples](#event-examples)
33
31
  - [Utility Functions](#utility-functions)
34
32
  - [Standalone Mode](#standalone-mode)
33
+ - [When to Use Standalone Mode](#when-to-use-standalone-mode)
34
+ - [Behavior Changes](#behavior-changes)
35
+ - [Implementation](#implementation)
36
+ - [Building a Custom UI](#building-a-custom-ui)
35
37
  - [Examples](#examples)
36
- - [Best Practices](#best-practices)
37
38
  - [Troubleshooting](#troubleshooting)
38
39
  - [Common Issues](#common-issues)
40
+ - [1. Configurator Not Loading](#1-configurator-not-loading)
41
+ - [2. Commands Not Working](#2-commands-not-working)
42
+ - [Tips & Tricks](#tips--tricks)
39
43
 
40
44
  ## Features
41
45
 
@@ -71,7 +75,7 @@ TypeScript/JavaScript API for integrating Metabox Basic Configurator into web ap
71
75
 
72
76
  ## Installation
73
77
 
74
- ### Method 1: NPM Package (Recommended)
78
+ ### NPM Installation (Recommended)
75
79
 
76
80
  **Installation:**
77
81
 
@@ -85,7 +89,7 @@ npm install @3dsource/metabox-front-api@latest --save
85
89
  import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from '@3dsource/metabox-front-api';
86
90
  ```
87
91
 
88
- ### Method 2: CDN Import (Quick Prototyping)
92
+ ### CDN Installation (Quick Prototyping)
89
93
 
90
94
  **jsDelivr:**
91
95
 
@@ -99,7 +103,7 @@ import { integrateMetabox, SetProduct, SetProductMaterial, GetScreenshot, saveIm
99
103
 
100
104
  ### 1. HTML Setup
101
105
 
102
- Create a container element where the Metabox Configurator will be embedded:
106
+ Ensure your HTML page has the following structure, where the Metabox Configurator will be integrated. You must provide CSS for the #embed3DSource element to make the configurator responsive and fit your layout needs. Create a container element where the configurator will be embedded:
103
107
 
104
108
  ```html
105
109
  <!DOCTYPE html>
@@ -127,7 +131,7 @@ Create a container element where the Metabox Configurator will be embedded:
127
131
 
128
132
  ### 2. Basic Integration
129
133
 
130
- #### JavaScript Example
134
+ #### JavaScript (ES6 Modules)
131
135
 
132
136
  ```html
133
137
  <script type="module">
@@ -142,148 +146,139 @@ Create a container element where the Metabox Configurator will be embedded:
142
146
  api.addEventListener('screenshotReady', (image) => {
143
147
  if (image) saveImage(image, `configurator-${Date.now()}.png`);
144
148
  });
145
- // Initial commands
149
+ // Initial commands example
146
150
  api.sendCommandToMetabox(new SetProduct('product-1'));
147
151
  api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1280, y: 720 }));
148
152
  });
149
153
  </script>
150
154
  ```
151
155
 
152
- #### TypeScript Example
156
+ #### TypeScript/Angular/React
153
157
 
154
158
  ```typescript
155
- import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, ShowEmbeddedMenu, ShowOverlayInterface, saveImage } from '@3dsource/metabox-front-api';
159
+ import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, ShowEmbeddedMenu, ShowOverlayInterface, saveImage, type MimeType } from '@3dsource/metabox-front-api';
156
160
 
157
161
  class MetaboxIntegrator {
158
162
  private api: Communicator | null = null;
163
+ private readonly configuratorId: string;
159
164
 
160
- constructor() {
165
+ constructor(configuratorId: string) {
166
+ this.configuratorId = configuratorId;
161
167
  this.initialize();
162
168
  }
163
169
 
164
- private async initialize(): Promise<void> {
165
- try {
166
- // Replace 'configurator-id' with your actual configurator ID
167
- const configuratorId = 'configurator-id';
168
-
169
- // Initialize the configurator with type safety
170
- integrateMetabox(configuratorId, 'embed3DSource', (api: Communicator) => {
171
- this.onApiReady(api);
172
- });
173
- } catch (error) {
174
- console.error('Failed to initialize Metabox:', error);
175
- }
176
- }
177
-
178
- private onApiReady(api: Communicator): void {
179
- this.api = api;
180
- console.log('Metabox API is ready!');
181
-
182
- // Set up event listeners with proper typing
183
- this.setupEventListeners();
184
-
185
- // Configure initial state
186
- this.configureInitialState();
170
+ private initialize(): void {
171
+ integrateMetabox(this.configuratorId, 'embed3DSource', (api: Communicator) => {
172
+ this.api = api;
173
+ this.setupEventListeners();
174
+ this.setupInitialState();
175
+ });
187
176
  }
188
177
 
189
178
  private setupEventListeners(): void {
190
179
  if (!this.api) return;
191
180
 
192
- // Listen for configurator data updates
181
+ // Listen for configuration data changes
193
182
  this.api.addEventListener('configuratorDataUpdated', (data: ConfiguratorEnvelope) => {
194
183
  console.log('Configurator data updated:', data);
195
- this.handleConfiguratorUpdate(data);
184
+ this.handleConfiguratorData(data);
196
185
  });
197
186
 
198
- // Listen for screenshot/render completion
199
- this.api.addEventListener('screenshotReady', (imageData: string) => {
200
- console.log('Screenshot ready');
201
- saveImage(imageData, 'configurator-screenshot.png');
187
+ // Handle screenshot events
188
+ this.api.addEventListener('screenshotReady', (imageData: string | null) => {
189
+ saveImage(imageData ?? '', 'configurator-render.png');
202
190
  });
203
- }
204
191
 
205
- private handleConfiguratorUpdate(data: ConfiguratorEnvelope): void {
206
- // Handle configurator state changes with full type safety
207
- // Access ConfiguratorEnvelope properties.
192
+ // Handle viewport ready events
193
+ this.api.addEventListener('viewportReady', (isReady: boolean) => {
194
+ console.log('Viewport ready:', isReady);
195
+ });
208
196
 
209
- // Example: Update UI based on current product
210
- if (data) {
211
- console.log('Current state:', data);
212
- }
197
+ // Handle status messages
198
+ this.api.addEventListener('statusMessageChanged', (message: string | null) => {
199
+ console.log('Status message:', message);
200
+ });
213
201
  }
214
202
 
215
- private configureInitialState(): void {
203
+ private setupInitialState(): void {
216
204
  if (!this.api) return;
217
205
 
218
- // Set initial product
206
+ // Configure initial product and environment
219
207
  this.api.sendCommandToMetabox(new SetProduct('your-product-id'));
220
-
221
- // Set initial environment
222
208
  this.api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
209
+ this.api.sendCommandToMetabox(new ShowOverlayInterface(true));
210
+ this.api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
211
+ }
223
212
 
224
- // Apply material to a specific slot
225
- this.api.sendCommandToMetabox(new SetProductMaterial('slot-id', 'material-id'));
213
+ private handleConfiguratorData(data: ConfiguratorEnvelope): void {
214
+ // Access typed data properties
215
+ console.log('Product:', data.productId);
216
+ console.log('Materials:', data.productMaterialsIds);
217
+ console.log('Environment:', data.environmentId);
226
218
 
227
- // Configure UI visibility
228
- this.api.sendCommandToMetabox(new ShowEmbeddedMenu(false));
229
- this.api.sendCommandToMetabox(new ShowOverlayInterface(false));
219
+ // Process configurator data according to your needs
220
+ this.updateUI(data);
221
+ }
230
222
 
231
- // Generate initial screenshot
232
- this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
223
+ private updateUI(data: ConfiguratorEnvelope): void {
224
+ // Update your application UI based on configurator state
225
+ // This method would contain your specific UI update logic
233
226
  }
234
227
 
235
- // Public method to change product
236
- public changeProduct(productId: string): void {
228
+ // Public API methods
229
+ public takeScreenshot(format: MimeType = 'image/png', size?: { x: number; y: number }): void {
237
230
  if (this.api) {
238
- this.api.sendCommandToMetabox(new SetProduct(productId));
231
+ this.api.sendCommandToMetabox(new GetScreenshot(format, size));
239
232
  }
240
233
  }
241
234
 
242
- // Public method to apply material
243
- public applyMaterial(slotId: string, materialId: string): void {
235
+ public changeMaterial(slotId: string, materialId: string): void {
244
236
  if (this.api) {
245
237
  this.api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
246
238
  }
247
239
  }
248
240
 
249
- // Public method to take screenshot
250
- public takeScreenshot(width: number = 1024, height: number = 1024): void {
241
+ public changeEnvironment(environmentId: string): void {
251
242
  if (this.api) {
252
- this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: width, y: height }));
243
+ this.api.sendCommandToMetabox(new SetEnvironment(environmentId));
253
244
  }
254
245
  }
246
+
247
+ public destroy(): void {
248
+ this.api = null;
249
+ }
255
250
  }
256
251
 
257
- // Initialize the integrator
258
- const metaboxIntegrator = new MetaboxIntegrator();
252
+ // Usage example
253
+ const configurator = new MetaboxIntegrator('configurator-id');
254
+
255
+ // Take a high-resolution screenshot
256
+ configurator.takeScreenshot('image/png', { x: 1920, y: 1080 });
259
257
 
260
- // Example usage:
261
- // metaboxIntegrator.changeProduct('new-product-id');
262
- // metaboxIntegrator.applyMaterial('slot-1', 'material-2');
263
- // metaboxIntegrator.takeScreenshot(1920, 1080);
258
+ // Change material
259
+ configurator.changeMaterial('seat-fabric', 'leather-brown');
264
260
  ```
265
261
 
266
262
  ## API Reference
267
263
 
268
264
  ### System Terminology
269
265
 
270
- | Term | Description | Required | Context |
271
- | ----------------- | ----------------------------------------------------------- | -------- | ------------------------- |
272
- | **product** | 3D digital twin of physical product in Metabox system | Yes | Basic configurator |
273
- | **productId** | Unique product identifier (system-generated UUID) | Yes | All contexts |
274
- | **environment** | 3D scene/room environment for product visualization | Yes | Visual context |
275
- | **environmentId** | Unique environment identifier (system-generated UUID) | Yes | Environment management |
276
- | **externalId** | Custom SKU/identifier for integration with external systems | No | E-commerce integration |
277
- | **showcase** | Camera animation sequence attached to product | No | Product attribute |
278
- | **component** | Product in modular configurator context | - | Modular configurator only |
279
- | **componentId** | Unique component identifier (system-generated UUID) | Yes | Modular configurator only |
280
- | **componentType** | Category/type of component (e.g., "wheel", "bumper") | Yes | Modular configurator only |
281
- | **slotId** | Material slot identifier on product/environment | Yes | Material assignment |
282
- | **materialId** | Unique material identifier | Yes | Material assignment |
266
+ | Term | Description | Context |
267
+ | ----------------- | ----------------------------------------------------------- | ------------------------- |
268
+ | **product** | 3D digital twin of physical product in Metabox system | Basic configurator |
269
+ | **productId** | Unique product identifier (system-generated UUID) | All contexts |
270
+ | **environment** | 3D scene/room environment for product visualization | Visual context |
271
+ | **environmentId** | Unique environment identifier (system-generated UUID) | Environment management |
272
+ | **externalId** | Custom SKU/identifier for integration with external systems | E-commerce integration |
273
+ | **showcase** | Camera animation sequence attached to product | Product attribute |
274
+ | **slotId** | Material slot identifier on product/environment | Material assignment |
275
+ | **materialId** | Unique material identifier | Material assignment |
283
276
 
284
277
  **E-Commerce Configurator (CTA Integration):**
285
278
 
286
- E-Com configurators extend Basic/Modular configurators with a call-to-action button. Configuration:
279
+ E-Com configurators extend Basic configurators with a call-to-action button. Configuration:
280
+
281
+ **Configuration:**
287
282
 
288
283
  1. **CTA Button Label:** Custom text (e.g., "Get Quote", "Add to Cart")
289
284
  2. **Callback URL:** HTTP POST endpoint that receives configuration data
@@ -309,44 +304,7 @@ User clicks CTA → Metabox POSTs config JSON → Your backend processes → Ret
309
304
  - Send lead information to CRM
310
305
  - Redirect to custom checkout flow
311
306
 
312
- ### Building a Custom UI
313
-
314
- To create a custom configurator interface, follow these steps:
315
-
316
- **1. Listen to State Changes**
317
-
318
- ```typescript
319
- api.addEventListener('configuratorDataUpdated', (data) => {
320
- // Update your UI based on configurator state
321
- });
322
- ```
323
-
324
- **2. Hide Default UI Elements**
325
-
326
- ```typescript
327
- api.sendCommandToMetabox(new ShowEmbeddedMenu(false)); // Hide sidebar
328
- api.sendCommandToMetabox(new ShowOverlayInterface(false)); // Hide viewport controls
329
- ```
330
-
331
- **3. Control Product Configuration**
332
-
333
- ```typescript
334
- api.sendCommandToMetabox(new SetProduct('product-id')); // Change product
335
- api.sendCommandToMetabox(new SetProductMaterial('slot-id', 'material-id')); // Apply material
336
- api.sendCommandToMetabox(new SetEnvironment('environment-id')); // Change environment
337
- ```
338
-
339
- **4. Export Functionality**
340
-
341
- ```typescript
342
- api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
343
- api.sendCommandToMetabox(new GetPdf());
344
- api.sendCommandToMetabox(new GetCallToActionInformation());
345
- ```
346
-
347
- ### Core Functions
348
-
349
- #### `integrateMetabox()`
307
+ ### Core Integration — `integrateMetabox()`
350
308
 
351
309
  Embeds the Metabox configurator iframe and establishes communication channel.
352
310
 
@@ -424,6 +382,8 @@ api.sendCommandToMetabox(new SetProductMaterial('body', 'red-metallic'));
424
382
 
425
383
  #### UI Control
426
384
 
385
+ - Note: ShowEmbeddedMenu and ShowOverlayInterface commands are ineffective in standalone mode.
386
+
427
387
  | Command | Parameters | Description |
428
388
  | ---------------------- | ------------------ | --------------------------- |
429
389
  | `ShowEmbeddedMenu` | `visible: boolean` | Show/hide right sidebar |
@@ -572,25 +532,6 @@ api.addEventListener('screenshotReady', (imageData) => {
572
532
  });
573
533
  ```
574
534
 
575
- #### Advanced Commands (Use with Caution)
576
-
577
- | Command | Parameters | Description |
578
- | --------------- | ------------------------------- | ----------------------------------- |
579
- | `UnrealCommand` | `payload: object` | Send raw command to Unreal Engine |
580
- | `MetaboxConfig` | `appId: string, config: object` | Internal initialization (auto-sent) |
581
-
582
- **Warning:** `UnrealCommand` bypasses API validation. Use only for custom Unreal-specific features.
583
-
584
- ```typescript
585
- // Example: Custom lighting control
586
- api.sendCommandToMetabox(
587
- new UnrealCommand({
588
- type: 'SetLightIntensity',
589
- value: 2.5,
590
- }),
591
- );
592
- ```
593
-
594
535
  ### Event Handling
595
536
 
596
537
  Event-driven architecture for reactive state management. Register listeners via `api.addEventListener(eventName, handler)`.
@@ -637,20 +578,19 @@ api.addEventListener('screenshotReady', (imageData: string | null) => {
637
578
  });
638
579
  ```
639
580
 
640
- **Loading State Management:**
581
+ **Loading State:**
641
582
 
642
583
  ```typescript
643
- api.addEventListener('statusMessageChanged', (message: string | null) => {
644
- const loader = document.getElementById('loader-text');
645
- loader.textContent = message || 'Loading...';
646
- });
647
-
648
584
  api.addEventListener('viewportReady', (isReady: boolean) => {
649
585
  if (isReady) {
650
- hideLoadingOverlay();
651
- enableUserControls();
586
+ hideLoadingSpinner();
587
+ enableComponentSelectors();
652
588
  }
653
589
  });
590
+
591
+ api.addEventListener('statusMessageChanged', (message: string | null) => {
592
+ document.getElementById('status-text').textContent = message || '';
593
+ });
654
594
  ```
655
595
 
656
596
  **Showcase Control:**
@@ -697,6 +637,126 @@ api.addEventListener('screenshotReady', (imageData: string | null) => {
697
637
  **Implementation Note:**
698
638
  Creates a temporary anchor element with `download` attribute to trigger browser download.
699
639
 
640
+ #### `fromCommunicatorEvent(target: Communicator, eventName: string): Observable`
641
+
642
+ 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()`.
643
+
644
+ **Parameters:**
645
+
646
+ | Parameter | Type | Description |
647
+ | ----------- | -------------- | -------------------------------------------- |
648
+ | `target` | `Communicator` | The Communicator instance to listen on |
649
+ | `eventName` | `string` | Event name (e.g., `configuratorDataUpdated`) |
650
+
651
+ **Returns:** `Observable<T>` — typed Observable matching the event payload.
652
+
653
+ **Example:**
654
+
655
+ ```typescript
656
+ import { fromCommunicatorEvent } from '@3dsource/metabox-front-api';
657
+
658
+ integrateMetabox('configurator-id', 'embed3DSource', (api) => {
659
+ fromCommunicatorEvent(api, 'configuratorDataUpdated').subscribe((data) => {
660
+ console.log('Product:', data.productId);
661
+ });
662
+
663
+ fromCommunicatorEvent(api, 'screenshotReady').subscribe((imageData) => {
664
+ if (imageData) saveImage(imageData, 'screenshot.png');
665
+ });
666
+ });
667
+ ```
668
+
669
+ ## Standalone Mode
670
+
671
+ Headless rendering mode for custom UI implementations. Disables all built-in Metabox UI elements.
672
+
673
+ ### When to Use Standalone Mode
674
+
675
+ ✅ **Use When:**
676
+
677
+ - Building a fully custom configurator interface
678
+ - Implementing brand-specific product selection UX
679
+ - Integrating into existing design systems
680
+ - Requiring complete control over configuration flow
681
+
682
+ ❌ **Don't Use When:**
683
+
684
+ - Quick prototyping with default UI is sufficient
685
+ - Minimal customization needed
686
+ - Limited development resources
687
+
688
+ ### Behavior Changes
689
+
690
+ | Feature | Default Mode | Standalone Mode |
691
+ | ------------------ | ------------ | --------------- |
692
+ | Right sidebar menu | Visible | Hidden |
693
+ | Viewport overlays | Visible | Hidden |
694
+ | Template logic | Active | Disabled |
695
+ | API control | Partial | Full |
696
+ | Event system | Available | Available |
697
+
698
+ ### Implementation
699
+
700
+ **TypeScript:**
701
+
702
+ ```typescript
703
+ import { integrateMetabox, Communicator, SetProduct, SetEnvironment } from '@3dsource/metabox-front-api';
704
+
705
+ integrateMetabox(
706
+ 'configurator-id',
707
+ 'embed3DSource',
708
+ (api: Communicator) => {
709
+ // Work with API here
710
+ },
711
+ { standalone: true }, // <- Enable standalone mode to disable default UI
712
+ );
713
+ ```
714
+
715
+ **JavaScript (CDN):**
716
+
717
+ ```html
718
+ <script type="module">
719
+ import { integrateMetabox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
720
+
721
+ integrateMetabox(
722
+ 'configurator-id',
723
+ 'embed3DSource',
724
+ (api) => {
725
+ // Work with API here
726
+ },
727
+ { standalone: true }, // <- Enable standalone mode to disable default UI
728
+ );
729
+ </script>
730
+ ```
731
+
732
+ ## Building a Custom UI
733
+
734
+ To create a custom configurator interface, use [standalone mode](#standalone-mode) and subscribe to events before sending commands, then follow these steps:
735
+
736
+ **1. Listen to State Changes**
737
+
738
+ ```typescript
739
+ api.addEventListener('configuratorDataUpdated', (data) => {
740
+ // Update your UI based on configurator state
741
+ });
742
+ ```
743
+
744
+ **2. Control Product Configuration**
745
+
746
+ ```typescript
747
+ api.sendCommandToMetabox(new SetProduct('product-id')); // Change product
748
+ api.sendCommandToMetabox(new SetProductMaterial('slot-id', 'material-id')); // Apply material
749
+ api.sendCommandToMetabox(new SetEnvironment('environment-id')); // Change environment
750
+ ```
751
+
752
+ **3. Export Configuration**
753
+
754
+ ```typescript
755
+ api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
756
+ api.sendCommandToMetabox(new GetPdf());
757
+ api.sendCommandToMetabox(new GetCallToActionInformation());
758
+ ```
759
+
700
760
  ## Examples
701
761
 
702
762
  ### E‑Com CTA example
@@ -1675,210 +1735,72 @@ export class AppComponent {
1675
1735
  4. Replace placeholder IDs with your real product, material, and slot IDs
1676
1736
  5. Customize the styling by modifying the component styles
1677
1737
 
1678
- ## Best Practices
1738
+ ## Troubleshooting
1679
1739
 
1680
- ### 1. Error Handling
1740
+ ### Common Issues
1681
1741
 
1682
- Always implement proper error handling when working with the API:
1742
+ #### 1. Configurator Not Loading
1683
1743
 
1684
- ```typescript
1685
- integrateMetabox(configuratorId, containerId, (api) => {
1686
- try {
1687
- // Set up event listeners with error handling
1688
- api.addEventListener('configuratorDataUpdated', (data) => {
1689
- try {
1690
- handleConfiguratorUpdate(data);
1691
- } catch (error) {
1692
- console.error('Error handling configurator update:', error);
1693
- }
1694
- });
1744
+ **Symptoms:** Blank screen, iframe not appearing, loading indefinitely
1695
1745
 
1696
- // Send commands with error handling
1697
- api.sendCommandToMetabox(new SetProduct(productId));
1698
- } catch (error) {
1699
- console.error('Error initializing configurator:', error);
1700
- }
1701
- });
1702
- ```
1746
+ **Root Causes & Solutions:**
1703
1747
 
1704
- ### 2. State Management
1748
+ | Issue | Diagnostic | Solution |
1749
+ | --------------------------- | ------------------------------------ | --------------------------------------------------------- |
1750
+ | Invalid configurator ID | Browser console shows 404 errors | Verify configurator ID in Metabox admin |
1751
+ | Container not found | `Error: Container element not found` | Ensure element exists before calling `integrateMetabox()` |
1752
+ | HTTP instead of HTTPS | Mixed content warnings | Use HTTPS or test on localhost |
1753
+ | Container has no dimensions | Invisible iframe (0x0) | Set explicit width/height on container element |
1754
+ | CORS/iframe blocking | X-Frame-Options errors | Check domain allowlist in Metabox settings |
1705
1755
 
1706
- Keep track of the configurator state for a better user experience:
1756
+ **Diagnostic Code:**
1707
1757
 
1708
1758
  ```typescript
1709
- class ConfiguratorStateManager {
1710
- private currentState = {
1711
- product: null,
1712
- materials: {},
1713
- environment: null,
1714
- };
1759
+ const containerId = 'embed3DSource';
1760
+ const container = document.getElementById(containerId);
1715
1761
 
1716
- updateState(data) {
1717
- this.currentState = { ...this.currentState, ...data };
1718
- this.saveStateToLocalStorage();
1719
- }
1720
-
1721
- saveStateToLocalStorage() {
1722
- localStorage.setItem('configuratorState', JSON.stringify(this.currentState));
1723
- }
1724
-
1725
- loadStateFromLocalStorage() {
1726
- const saved = localStorage.getItem('configuratorState');
1727
- return saved ? JSON.parse(saved) : null;
1728
- }
1762
+ if (!container) {
1763
+ throw new Error(`Container #${containerId} not found`);
1729
1764
  }
1730
- ```
1731
-
1732
- ### 3. Performance Optimization
1733
1765
 
1734
- - **Debounce rapid commands**: Avoid sending too many commands in quick succession
1735
-
1736
- ```typescript
1737
- // Debounce example
1738
- const debouncedMaterialChange = debounce((slotId, materialId) => {
1739
- api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
1740
- }, 300);
1741
- ```
1742
-
1743
- ### 4. Responsive Design
1744
-
1745
- Ensure the configurator works well on different screen sizes:
1746
-
1747
- ```css
1748
- #embed3DSource {
1749
- width: 100%;
1750
- height: 60vh;
1751
- min-height: 400px;
1752
- max-height: 800px;
1766
+ // Verify container has dimensions
1767
+ const rect = container.getBoundingClientRect();
1768
+ if (rect.width === 0 || rect.height === 0) {
1769
+ console.warn('⚠️ Container has no dimensions');
1753
1770
  }
1754
1771
 
1755
- @media (max-width: 768px) {
1756
- #embed3DSource {
1757
- height: 50vh;
1758
- min-height: 300px;
1759
- }
1772
+ if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
1773
+ console.warn('⚠️ HTTPS required for Unreal Engine streaming');
1760
1774
  }
1761
- ```
1762
-
1763
- ### 5. Loading States
1764
-
1765
- Provide feedback to users while the configurator loads:
1766
-
1767
- ```typescript
1768
- const showLoadingState = () => {
1769
- document.getElementById('loading').style.display = 'block';
1770
- };
1771
-
1772
- const hideLoadingState = () => {
1773
- document.getElementById('loading').style.display = 'none';
1774
- };
1775
1775
 
1776
- integrateMetabox(configuratorId, containerId, (api) => {
1777
- hideLoadingState();
1778
- // Continue with initialization
1776
+ integrateMetabox('configurator-id', containerId, (api) => {
1777
+ console.log('✅ Configurator loaded');
1779
1778
  });
1780
1779
  ```
1781
1780
 
1782
- ## Troubleshooting
1783
-
1784
- ### Common Issues
1785
-
1786
- #### 1. Configurator Not Loading
1787
-
1788
- **Problem**: The configurator iframe doesn't appear or shows a blank screen.
1789
-
1790
- **Solutions**:
1791
-
1792
- - Verify the configurator ID is correct and accessible
1793
- - Ensure the container element exists in the DOM before calling `integrateMetabox`
1794
- - Check that you're using HTTPS (required for Unreal Engine)
1795
- - Verify your configurator ID is valid
1796
-
1797
- ```typescript
1798
- // Check if container exists
1799
- const container = document.getElementById('embed3DSource');
1800
- if (!container) {
1801
- console.error('Container element not found');
1802
- return;
1803
- }
1804
-
1805
- // Verify HTTPS
1806
- if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
1807
- console.warn('HTTPS is required for Metabox configurator');
1808
- }
1809
- ```
1810
-
1811
1781
  #### 2. Commands Not Working
1812
1782
 
1813
- **Problem**: Commands sent to the configurator don't have any effect.
1814
-
1815
- **Solutions**:
1816
-
1817
- - Ensure the API is fully initialized before sending commands
1818
- - Check that product/material/environment IDs are correct
1819
- - Verify the configurator supports the specific command
1820
-
1821
- ```typescript
1822
- let apiReady = false;
1823
-
1824
- integrateMetabox(configuratorId, containerId, (api) => {
1825
- apiReady = true;
1826
- // Now it's safe to send commands
1827
- });
1828
-
1829
- // Wait for API to be ready
1830
- const sendCommand = (command) => {
1831
- if (apiReady && api) {
1832
- api.sendCommandToMetabox(command);
1833
- } else {
1834
- console.warn('API not ready yet');
1835
- }
1836
- };
1837
- ```
1838
-
1839
- #### 3. Events Not Firing
1783
+ **Symptoms:** Commands sent but no visual changes in configurator
1840
1784
 
1841
- **Problem**: Event listeners don't receive events from the configurator.
1785
+ **Common Mistakes:**
1842
1786
 
1843
- **Solutions**:
1787
+ | Mistake | Problem | Solution |
1788
+ | -------------------------- | ----------------- | ----------------------------------------------- |
1789
+ | Sending before API ready | Commands ignored | Only send in `apiReadyCallback` |
1790
+ | Wrong product/material IDs | Entity not found | Verify IDs from `configuratorDataUpdated` event |
1791
+ | Wrong slot ID | Material rejected | Verify slot IDs from configurator data |
1844
1792
 
1845
- - Set up event listeners immediately after API initialization
1846
- - Check event names for typos
1847
- - Ensure the configurator is configured to send the expected events
1793
+ **Correct Pattern:**
1848
1794
 
1849
1795
  ```typescript
1850
- integrateMetabox(configuratorId, containerId, (api) => {
1851
- // Set up listeners immediately
1852
- api.addEventListener('configuratorDataUpdated', (data) => {
1853
- console.log('Event received:', data);
1854
- });
1855
-
1856
- // Test if events are working
1857
- setTimeout(() => {
1858
- console.log('Testing event system...');
1859
- api.sendCommandToMetabox(new SetProduct('test-product'));
1860
- }, 1000);
1796
+ integrateMetabox('configurator-id', 'container', (api) => {
1797
+ // ✅ Correct: Commands sent after API ready
1798
+ api.sendCommandToMetabox(new SetProduct('product-id'));
1799
+ api.sendCommandToMetabox(new SetProductMaterial('slot-id', 'material-id'));
1861
1800
  });
1862
- ```
1863
1801
 
1864
- #### 4. Screenshot/PDF Generation Issues
1865
-
1866
- **Problem**: Screenshots or PDFs are not generated or are of poor quality.
1867
-
1868
- **Solutions**:
1869
-
1870
- - Wait for the scene to fully load before capturing
1871
- - Use appropriate dimensions for your use case
1872
- - Ensure the configurator viewport is visible (not hidden or zero-sized)
1873
-
1874
- ```typescript
1875
- // Wait for scene to load before screenshot
1876
- api.addEventListener('configuratorDataUpdated', (data) => {
1877
- // Scene is loaded, safe to take screenshot
1878
- setTimeout(() => {
1879
- api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
1880
- }, 500);
1881
- });
1802
+ // ❌ Wrong: Command sent too early
1803
+ // api.sendCommandToMetabox(new SetProduct('product-id'));
1882
1804
  ```
1883
1805
 
1884
1806
  ### Getting Help
@@ -1888,66 +1810,19 @@ If you're still experiencing issues:
1888
1810
  1. Check the browser console for error messages
1889
1811
  2. Verify your configurator ID in a separate browser tab
1890
1812
  3. Test with a minimal example to isolate the issue
1891
- 4. Contact support with:
1813
+ 4. Contact support with: browser version, configurator URL, console errors, and steps to reproduce
1892
1814
 
1893
- - Browser version and type
1894
- - Configurator URL (if possible)
1895
- - Console error messages
1896
- - Steps to reproduce the issue
1815
+ ## Tips & Tricks
1897
1816
 
1898
- ## Standalone Mode
1899
-
1900
- Standalone mode lets you embed the Metabox renderer without the built‑in Metabox UI and template logic. This is ideal when you want to build a fully custom UI (menus, buttons, flows) and drive the configurator entirely through this API.
1901
-
1902
- When standalone is enabled, the embedded page does not render Metabox’s internal menus, overlays, or template logic. You are responsible for sending commands (e.g., `SetProduct`, `SetProductMaterial`, `SetEnvironment`) and listening to events to keep your UI in sync.
1903
-
1904
- Key points:
1905
-
1906
- - Purpose: use when you need a 100% custom interface and logic on the host page.
1907
- - Behavior: Metabox default UI, embedded menu, and template logic are disabled on the iframe side.
1908
- - Control: you drive everything with API commands and events.
1909
-
1910
- How to enable
1911
-
1912
- Pass as param to config with a standalone set to true when calling integrateMetabox.
1913
-
1914
- TypeScript example:
1915
-
1916
- ```typescript
1917
- import { integrateMetabox, Communicator, SetProduct, SetEnvironment } from '@3dsource/metabox-front-api';
1918
-
1919
- integrateMetabox(
1920
- 'configurator-id',
1921
- 'embed3DSource',
1922
- (api: Communicator) => {
1923
- // Send your initial commands to establish state
1924
- api.sendCommandToMetabox(new SetProduct('your-product-id'));
1925
- api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
1926
- },
1927
- { standalone: true },
1928
- );
1929
- ```
1930
-
1931
- JavaScript (CDN) example:
1932
-
1933
- ```html
1934
- <script type="module">
1935
- import { integrateMetabox, SetProduct, SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
1936
-
1937
- integrateMetabox(
1938
- 'configurator-id',
1939
- 'embed3DSource',
1940
- (api) => {
1941
- api.sendCommandToMetabox(new SetProduct('your-product-id'));
1942
- api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
1943
- },
1944
- { standalone: true },
1945
- );
1946
- </script>
1947
- ```
1817
+ - **Debounce rapid commands.** Avoid sending too many commands in quick succession — debounce material or product changes (e.g., 300 ms).
1818
+ - **Responsive container.** Set the configurator container to responsive dimensions (`width: 100%; height: 100%;`) and adjust with media queries for mobile.
1819
+ - **Events work in all modes.** `configuratorDataUpdated`, `screenshotReady`, and other events fire in both default and standalone mode — use them to keep your UI synchronized.
1820
+ - **Wait for API ready.** Only send commands inside the `apiReadyCallback`. Commands sent before initialization are silently ignored.
1821
+ - **Validate IDs from events.** Use the `configuratorDataUpdated` event payload to discover valid product, material, and slot IDs rather than hardcoding them.
1822
+ - **HTTPS is required.** The iframe URL enforces HTTPS. HTTP URLs will be rejected. Use `localhost` for local development.
1823
+ - **Pin CDN versions in production.** Replace `@latest` with a specific version to avoid unexpected breaking changes.
1948
1824
 
1949
- Notes and tips:
1825
+ ---
1950
1826
 
1951
- - In standalone mode, nothing will change until you send initial commands (e.g., set product/environment). If you see a blank/default view, ensure you dispatch the necessary SetProduct/SetEnvironment commands once api is ready.
1952
- - All events (like configuratorDataUpdated, screenshotReady) still work; use them to keep your UI synchronized.
1953
- - Runtime validation still applies: configuratorId and containerId must be non-empty. HTTPS is enforced for the internally constructed iframe URL. The hostUrl and apiVersion values are handled internally; you do not need to pass them.
1827
+ For more examples and advanced usage, visit
1828
+ our [documentation site](https://preview.3dsource.com/front-libraries/master/basic-configurator-api-doc/).