@3dsource/metabox-modular-configurator-api 3.0.19-dev.8 → 3.0.19
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,36 +16,30 @@ 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
|
-
- [
|
|
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)
|
|
35
26
|
- [Camera Control](#camera-control)
|
|
36
27
|
- [Showcase/Animation Control](#showcaseanimation-control)
|
|
37
28
|
- [Measurement Tools](#measurement-tools)
|
|
29
|
+
- [Stream Control](#stream-control)
|
|
38
30
|
- [Export & Media](#export--media)
|
|
39
|
-
|
|
40
|
-
- [
|
|
41
|
-
|
|
42
|
-
|
|
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)
|
|
43
38
|
- [Troubleshooting](#troubleshooting)
|
|
44
39
|
- [Common Issues](#common-issues)
|
|
45
|
-
- [Configurator Not Loading](#configurator-not-loading)
|
|
46
|
-
- [Commands Not Working](#commands-not-working)
|
|
47
|
-
|
|
48
|
-
- [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)
|
|
49
43
|
|
|
50
44
|
## Features
|
|
51
45
|
|
|
@@ -146,7 +140,7 @@ Create a container element where the configurator will be embedded:
|
|
|
146
140
|
|
|
147
141
|
```html
|
|
148
142
|
<script type="module">
|
|
149
|
-
import { GetPdf, GetScreenshot, GetCallToActionInformation, integrateMetabox, saveImage, SetComponent, SetComponentMaterial, SetEnvironment, SetEnvironmentMaterial, ShowEmbeddedMenu, ShowOverlayInterface
|
|
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';
|
|
150
144
|
|
|
151
145
|
// Replace it with your actual configurator ID (not a full URL)
|
|
152
146
|
const configuratorId = 'configurator-id';
|
|
@@ -164,7 +158,7 @@ Create a container element where the configurator will be embedded:
|
|
|
164
158
|
saveImage(data, 'configurator-screenshot.png');
|
|
165
159
|
});
|
|
166
160
|
|
|
167
|
-
//
|
|
161
|
+
// Initial commands example
|
|
168
162
|
api.sendCommandToMetabox(new SetComponent('componentId', 'typeId', true));
|
|
169
163
|
api.sendCommandToMetabox(new SetEnvironment('environmentId'));
|
|
170
164
|
api.sendCommandToMetabox(new SetComponentMaterial('componentId', 'slotId', 'materialId'));
|
|
@@ -294,33 +288,24 @@ configurator.changeMaterial('componentId', 'seat-fabric', 'leather-brown');
|
|
|
294
288
|
|
|
295
289
|
### System Terminology
|
|
296
290
|
|
|
297
|
-
| Term | Description |
|
|
298
|
-
| --------------------- | -------------------------------------------------------------- |
|
|
299
|
-
| **component** | Modular product part/assembly (e.g., wheel, bumper, seat) |
|
|
300
|
-
| **componentId** | Unique component identifier (system-generated UUID) |
|
|
301
|
-
| **componentType** | Category/classification of component (e.g., "wheel", "bumper") |
|
|
302
|
-
| **environment** | 3D scene/room environment for product visualization |
|
|
303
|
-
| **environmentId** | Unique environment identifier (system-generated UUID) |
|
|
304
|
-
| **product** | Base 3D digital twin referenced by components |
|
|
305
|
-
| **productId** | Unique product identifier (system-generated UUID) |
|
|
306
|
-
| **externalId** | Custom SKU/identifier for external system integration |
|
|
307
|
-
| **showcase** | Camera animation sequence attached to component |
|
|
308
|
-
| **slotId** | Material slot identifier on component/environment |
|
|
309
|
-
| **materialId** | Unique material identifier |
|
|
310
|
-
| **configurationTree** | Hierarchical structure of component assembly |
|
|
311
|
-
|
|
312
|
-
**Key Differences from Basic Configurator:**
|
|
313
|
-
|
|
314
|
-
| Aspect | Basic Configurator | Modular Configurator |
|
|
315
|
-
| ------------------------ | ---------------------------- | --------------------------------------- |
|
|
316
|
-
| **Product Model** | Single monolithic product | Composed of multiple components |
|
|
317
|
-
| **Configuration** | Select one product at a time | Assemble components by type |
|
|
318
|
-
| **Material Application** | Per-product slots | Per-component and per-environment slots |
|
|
319
|
-
| **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 |
|
|
320
305
|
|
|
321
306
|
**E-Commerce Configurator (CTA Integration):**
|
|
322
307
|
|
|
323
|
-
E-Com configurators extend
|
|
308
|
+
E-Com configurators extend Modular configurators with a call-to-action button.
|
|
324
309
|
|
|
325
310
|
**Configuration:**
|
|
326
311
|
|
|
@@ -343,76 +328,27 @@ User clicks CTA → Metabox POSTs config JSON → Backend processes → Returns
|
|
|
343
328
|
|
|
344
329
|
**Use Cases:**
|
|
345
330
|
|
|
346
|
-
- Generate configuration PDFs
|
|
347
|
-
- Create a shopping cart with BOM (Bill of Materials)
|
|
348
331
|
- Send lead to CRM with component details
|
|
349
332
|
- Redirect to custom checkout with modular pricing
|
|
350
333
|
|
|
351
|
-
###
|
|
352
|
-
|
|
353
|
-
To create a custom modular configurator interface:
|
|
354
|
-
|
|
355
|
-
**1. Listen to Configuration State**
|
|
356
|
-
|
|
357
|
-
```typescript
|
|
358
|
-
api.addEventListener('configuratorDataUpdated', (data: ModularConfiguratorEnvelope) => {
|
|
359
|
-
// Update UI with component tree, materials, environment
|
|
360
|
-
updateComponentSelector(data.componentsByComponentType);
|
|
361
|
-
updateMaterialOptions(data.componentMaterialsIds);
|
|
362
|
-
});
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
**2. Hide Default UI Elements**
|
|
366
|
-
|
|
367
|
-
```typescript
|
|
368
|
-
api.sendCommandToMetabox(new ShowEmbeddedMenu(false)); // Hide sidebar
|
|
369
|
-
api.sendCommandToMetabox(new ShowOverlayInterface(false)); // Hide viewport controls
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
**3. Control Component Assembly**
|
|
373
|
-
|
|
374
|
-
```typescript
|
|
375
|
-
// Add root component
|
|
376
|
-
api.sendCommandToMetabox(new SetComponent('component-id', 'wheel', true));
|
|
377
|
-
|
|
378
|
-
// Add child components
|
|
379
|
-
api.sendCommandToMetabox(new SetComponent('tire-id', 'tire', false));
|
|
380
|
-
|
|
381
|
-
// Apply materials per component
|
|
382
|
-
api.sendCommandToMetabox(new SetComponentMaterial('component-id', 'rim', 'chrome'));
|
|
383
|
-
|
|
384
|
-
// Change environment
|
|
385
|
-
api.sendCommandToMetabox(new SetEnvironment('environment-id'));
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
**4. Export Configuration**
|
|
389
|
-
|
|
390
|
-
```typescript
|
|
391
|
-
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
392
|
-
api.sendCommandToMetabox(new GetPdf());
|
|
393
|
-
api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
### Core Integration
|
|
397
|
-
|
|
398
|
-
#### `integrateMetabox()`
|
|
334
|
+
### Core Integration — `integrateMetabox()`
|
|
399
335
|
|
|
400
336
|
Embeds the Metabox Modular Configurator iframe and establishes communication channel.
|
|
401
337
|
|
|
402
338
|
**Signature:**
|
|
403
339
|
|
|
404
340
|
```typescript
|
|
405
|
-
function integrateMetabox(configuratorId: string, containerId
|
|
341
|
+
function integrateMetabox(configuratorId: string, containerId: string, apiReadyCallback: (api: Communicator) => void, config?: IntegrateMetaboxConfig): void;
|
|
406
342
|
```
|
|
407
343
|
|
|
408
344
|
**Parameters:**
|
|
409
345
|
|
|
410
|
-
| Parameter | Type | Required | Default
|
|
411
|
-
| ------------------ | ------------------------ | -------- |
|
|
412
|
-
| `configuratorId` | `string` | ✅ | -
|
|
413
|
-
| `containerId` | `string` |
|
|
414
|
-
| `apiReadyCallback` | `function` | ✅ | -
|
|
415
|
-
| `config` | `IntegrateMetaboxConfig` | ❌ | `{}`
|
|
346
|
+
| Parameter | Type | Required | Default | Description |
|
|
347
|
+
| ------------------ | ------------------------ | -------- | ------- | ---------------------------------------- |
|
|
348
|
+
| `configuratorId` | `string` | ✅ | - | Modular configurator UUID (not full URL) |
|
|
349
|
+
| `containerId` | `string` | ✅ | - | DOM container element ID |
|
|
350
|
+
| `apiReadyCallback` | `function` | ✅ | - | Callback invoked when API is ready |
|
|
351
|
+
| `config` | `IntegrateMetaboxConfig` | ❌ | `{}` | Additional configuration options |
|
|
416
352
|
|
|
417
353
|
**Config Options (`IntegrateMetaboxConfig`):**
|
|
418
354
|
|
|
@@ -422,7 +358,7 @@ interface IntegrateMetaboxConfig {
|
|
|
422
358
|
introImage?: string; // URL for intro image
|
|
423
359
|
introVideo?: string; // URL for intro video
|
|
424
360
|
loadingImage?: string; // URL for loading spinner
|
|
425
|
-
state?:
|
|
361
|
+
state?: string; // Initial component tree state (rison format)
|
|
426
362
|
domain?: string; // Override domain (HTTPS only)
|
|
427
363
|
}
|
|
428
364
|
```
|
|
@@ -443,11 +379,7 @@ integrateMetabox(
|
|
|
443
379
|
(api) => {
|
|
444
380
|
console.log('Modular configurator ready');
|
|
445
381
|
|
|
446
|
-
//
|
|
447
|
-
api.sendCommandToMetabox(new SetComponent('comp-1', 'base', true));
|
|
448
|
-
|
|
449
|
-
// Set environment
|
|
450
|
-
api.sendCommandToMetabox(new SetEnvironment('env-1'));
|
|
382
|
+
// Work with API here, e.g., listen to events or send commands
|
|
451
383
|
},
|
|
452
384
|
{
|
|
453
385
|
standalone: true,
|
|
@@ -467,10 +399,10 @@ The API provides comprehensive TypeScript support with the following key interfa
|
|
|
467
399
|
The main API interface for sending commands and listening to events.
|
|
468
400
|
|
|
469
401
|
```typescript
|
|
470
|
-
|
|
471
|
-
sendCommandToMetabox<T extends
|
|
472
|
-
addEventListener<
|
|
473
|
-
removeEventListener<
|
|
402
|
+
class Communicator extends EventDispatcher {
|
|
403
|
+
sendCommandToMetabox<T extends CommandBase>(command: T): void;
|
|
404
|
+
addEventListener<T extends FromMetaBoxApiEvents>(messageType: T, callback: (data: FromMetaboxMessagePayloads[T]) => void): this;
|
|
405
|
+
removeEventListener<T extends FromMetaBoxApiEvents>(messageType: T, callback: (data: FromMetaboxMessagePayloads[T]) => void): this;
|
|
474
406
|
}
|
|
475
407
|
```
|
|
476
408
|
|
|
@@ -562,22 +494,159 @@ interface Environment {
|
|
|
562
494
|
}
|
|
563
495
|
```
|
|
564
496
|
|
|
565
|
-
|
|
497
|
+
##### `InitialModularConfigurator`
|
|
566
498
|
|
|
567
|
-
|
|
499
|
+
The full configurator definition containing all available components, environments, and component types.
|
|
568
500
|
|
|
569
|
-
|
|
501
|
+
```typescript
|
|
502
|
+
interface InitialModularConfigurator {
|
|
503
|
+
/** Unique identifier for the configurator. */
|
|
504
|
+
id: string;
|
|
505
|
+
/** The name of the configurator. */
|
|
506
|
+
name: string;
|
|
507
|
+
/** A list of components for the configurator. */
|
|
508
|
+
components: ModularConfiguratorComponent[];
|
|
509
|
+
/** A list of available environments. */
|
|
510
|
+
environments: ModularConfiguratorEnvironment[];
|
|
511
|
+
/** A list of component types for the configurator. */
|
|
512
|
+
componentTypes: ModularConfiguratorComponentType[];
|
|
513
|
+
/** Indicates if the configurator is active. */
|
|
514
|
+
isActive: boolean;
|
|
515
|
+
/** Indicates if the CTA in ecom configurator is enabled. */
|
|
516
|
+
ctaEnabled: boolean;
|
|
517
|
+
/** A list of connectors showing connections between component types. */
|
|
518
|
+
connectors: ModularConfiguratorConnector[];
|
|
519
|
+
__typename: 'ModularConfigurator';
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
##### `ModularConfiguratorComponentType`
|
|
524
|
+
|
|
525
|
+
Represents a component category/classification (e.g., "wheel", "bumper", "seat").
|
|
570
526
|
|
|
571
527
|
```typescript
|
|
572
|
-
|
|
528
|
+
interface ModularConfiguratorComponentType {
|
|
529
|
+
/** Display name for the component type. */
|
|
530
|
+
name: string;
|
|
531
|
+
/** Position index of the component type. */
|
|
532
|
+
position: number;
|
|
533
|
+
/** Is root component type. */
|
|
534
|
+
isRoot: boolean;
|
|
535
|
+
/** Is required component type. */
|
|
536
|
+
isRequired: boolean;
|
|
537
|
+
/** Unique identifier. */
|
|
538
|
+
id: string;
|
|
539
|
+
__typename: 'ModularConfiguratorComponentType';
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
##### `Product`
|
|
544
|
+
|
|
545
|
+
Base 3D digital twin referenced by each component.
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
interface Product {
|
|
549
|
+
/** The title of the product. */
|
|
550
|
+
title: string;
|
|
551
|
+
/** List of thumbnails for the product. */
|
|
552
|
+
thumbnailList: Thumbnail[];
|
|
553
|
+
/** Available material slots for the product. */
|
|
554
|
+
slots: Slot[];
|
|
555
|
+
/** List of meta properties for the product. */
|
|
556
|
+
metaProperties: MetaProperty[];
|
|
557
|
+
/** Unique identifier for the product. */
|
|
558
|
+
id: string;
|
|
559
|
+
/** External SKU/identifier for ERP/PIM integration. */
|
|
560
|
+
externalId: string;
|
|
561
|
+
/** Showcase animation details (optional). */
|
|
562
|
+
showcase?: Showcase;
|
|
563
|
+
__typename: 'Product';
|
|
564
|
+
}
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
##### `Slot`
|
|
568
|
+
|
|
569
|
+
A material slot on a component or environment — a customizable surface.
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
interface Slot {
|
|
573
|
+
/** Unique identifier for the slot. */
|
|
574
|
+
id: string;
|
|
575
|
+
/** Display label for the slot. */
|
|
576
|
+
label: string;
|
|
577
|
+
/** Available materials for this slot. */
|
|
578
|
+
enabledMaterials: Material[];
|
|
579
|
+
__typename: 'Slot';
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
##### `ModularConfiguratorEnvironment`
|
|
584
|
+
|
|
585
|
+
Environment wrapper containing position and label for environment selector UIs.
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
interface ModularConfiguratorEnvironment {
|
|
589
|
+
/** Unique identifier for the environment. */
|
|
590
|
+
environmentId: string;
|
|
591
|
+
/** Position index of the environment. */
|
|
592
|
+
position: number;
|
|
593
|
+
/** Display label for the environment. */
|
|
594
|
+
label: string;
|
|
595
|
+
/** Detailed environment configuration. */
|
|
596
|
+
environment: Environment;
|
|
597
|
+
__typename: 'ModularConfiguratorEnvironment';
|
|
598
|
+
}
|
|
573
599
|
```
|
|
574
600
|
|
|
575
|
-
##### `
|
|
601
|
+
##### `ComponentWithParent`
|
|
576
602
|
|
|
577
|
-
|
|
603
|
+
Represents a node in the component assembly tree hierarchy.
|
|
578
604
|
|
|
579
605
|
```typescript
|
|
580
|
-
|
|
606
|
+
interface ComponentWithParent {
|
|
607
|
+
id: string;
|
|
608
|
+
componentTypeId: string;
|
|
609
|
+
parentId: string | null;
|
|
610
|
+
}
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
##### `SelectedIds`
|
|
614
|
+
|
|
615
|
+
Record type tracking currently selected material/component IDs.
|
|
616
|
+
|
|
617
|
+
```typescript
|
|
618
|
+
type SelectedIds = Record<string, Record<string, string>>;
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
##### `ShowCaseStatus`
|
|
622
|
+
|
|
623
|
+
Showcase animation playback status.
|
|
624
|
+
|
|
625
|
+
```typescript
|
|
626
|
+
type ShowCaseStatus = 'init' | 'play' | 'pause' | 'stop';
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
##### `ModularConfiguratorConnector`
|
|
630
|
+
|
|
631
|
+
Defines connection rules between component types for modular assembly.
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
interface ModularConfiguratorConnector {
|
|
635
|
+
id: string;
|
|
636
|
+
componentTypeId1: string;
|
|
637
|
+
componentTypeId2: string;
|
|
638
|
+
__typename: 'ModularConfiguratorConnector';
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
#### Utility Types
|
|
643
|
+
|
|
644
|
+
##### `MimeType`
|
|
645
|
+
|
|
646
|
+
Supported image formats for screenshots.
|
|
647
|
+
|
|
648
|
+
```typescript
|
|
649
|
+
type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
581
650
|
```
|
|
582
651
|
|
|
583
652
|
### Command Classes
|
|
@@ -609,6 +678,8 @@ api.sendCommandToMetabox(new SetComponentMaterial('wheel-fr', 'rim', 'chrome'));
|
|
|
609
678
|
|
|
610
679
|
#### UI Control
|
|
611
680
|
|
|
681
|
+
- Note: ShowEmbeddedMenu and ShowOverlayInterface commands are ineffective in standalone mode.
|
|
682
|
+
|
|
612
683
|
| Command | Parameters | Description |
|
|
613
684
|
| ---------------------- | ------------------ | ---------------------------- |
|
|
614
685
|
| `ShowEmbeddedMenu` | `visible: boolean` | Show/hide right sidebar menu |
|
|
@@ -626,8 +697,8 @@ api.sendCommandToMetabox(new SetComponentMaterial('wheel-fr', 'rim', 'chrome'));
|
|
|
626
697
|
**Example:**
|
|
627
698
|
|
|
628
699
|
```typescript
|
|
629
|
-
api.sendCommandToMetabox(new ApplyZoom(
|
|
630
|
-
api.sendCommandToMetabox(new ApplyZoom(-
|
|
700
|
+
api.sendCommandToMetabox(new ApplyZoom(50)); // Zoom in
|
|
701
|
+
api.sendCommandToMetabox(new ApplyZoom(-25)); // Zoom out
|
|
631
702
|
api.sendCommandToMetabox(new ResetCamera()); // Reset view
|
|
632
703
|
api.sendCommandToMetabox(
|
|
633
704
|
new SetCamera({
|
|
@@ -700,7 +771,7 @@ interface CameraCommandPayload {
|
|
|
700
771
|
Notes:
|
|
701
772
|
|
|
702
773
|
- Provide only the limits you want to enforce; unspecified values are left as currently configured by the viewer.
|
|
703
|
-
- Rotation units are degrees; positive/negative values follow the viewer
|
|
774
|
+
- Rotation units are degrees; positive/negative values follow the viewer's right‑handed coordinate system.
|
|
704
775
|
- In `orbit` mode, distance limits are interpreted relative to the orbit pivot.
|
|
705
776
|
- `ResetCamera` restores the default position/rotation/FOV defined by the current product or environment template.
|
|
706
777
|
|
|
@@ -720,6 +791,19 @@ Notes:
|
|
|
720
791
|
| `ShowMeasurement` | None | Display component dimensions |
|
|
721
792
|
| `HideMeasurement` | None | Hide dimension overlay |
|
|
722
793
|
|
|
794
|
+
#### Stream Control
|
|
795
|
+
|
|
796
|
+
| Command | Parameters | Description |
|
|
797
|
+
| -------------- | ---------- | ----------------------------------------------------------- |
|
|
798
|
+
| `ResumeStream` | None | Resume pixel streaming session after pause or disconnection |
|
|
799
|
+
|
|
800
|
+
**Example:**
|
|
801
|
+
|
|
802
|
+
```typescript
|
|
803
|
+
// Resume the stream after an idle timeout or network interruption
|
|
804
|
+
api.sendCommandToMetabox(new ResumeStream());
|
|
805
|
+
```
|
|
806
|
+
|
|
723
807
|
#### Export & Media
|
|
724
808
|
|
|
725
809
|
| Command | Parameters | Description | Event Triggered |
|
|
@@ -728,37 +812,29 @@ Notes:
|
|
|
728
812
|
| `GetPdf` | None | Generate PDF export | Server-side (no event) |
|
|
729
813
|
| `GetCallToActionInformation` | None | Trigger CTA workflow | Backend redirect |
|
|
730
814
|
|
|
731
|
-
|
|
815
|
+
##### `saveImage()`
|
|
732
816
|
|
|
733
|
-
|
|
734
|
-
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 2048, y: 2048 }));
|
|
817
|
+
Helper function: triggers a browser download of an image from a data URL or blob URL.
|
|
735
818
|
|
|
736
|
-
|
|
737
|
-
saveImage(imageData, 'assembly.png');
|
|
738
|
-
});
|
|
739
|
-
```
|
|
819
|
+
**Signature:**
|
|
740
820
|
|
|
741
|
-
|
|
821
|
+
```typescript
|
|
822
|
+
function saveImage(imageUrl: string, filename: string): void;
|
|
823
|
+
```
|
|
742
824
|
|
|
743
|
-
|
|
|
744
|
-
|
|
|
745
|
-
| `
|
|
746
|
-
| `
|
|
825
|
+
| Parameter | Type | Description |
|
|
826
|
+
| ---------- | -------- | ----------------------------------- |
|
|
827
|
+
| `imageUrl` | `string` | Base64 data URL or blob URL to save |
|
|
828
|
+
| `filename` | `string` | Suggested filename for the download |
|
|
747
829
|
|
|
748
|
-
**
|
|
830
|
+
**Screenshot Example:**
|
|
749
831
|
|
|
750
832
|
```typescript
|
|
751
|
-
|
|
752
|
-
api.sendCommandToMetabox(
|
|
753
|
-
new UnrealCommand({
|
|
754
|
-
action: 'SetLightIntensity',
|
|
755
|
-
lightId: 'keyLight',
|
|
756
|
-
value: 2.5,
|
|
757
|
-
}),
|
|
758
|
-
);
|
|
833
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 2048, y: 2048 }));
|
|
759
834
|
|
|
760
|
-
|
|
761
|
-
|
|
835
|
+
api.addEventListener('screenshotReady', (imageData) => {
|
|
836
|
+
saveImage(imageData, 'assembly.png');
|
|
837
|
+
});
|
|
762
838
|
```
|
|
763
839
|
|
|
764
840
|
### Event Handling
|
|
@@ -823,139 +899,82 @@ api.addEventListener('statusMessageChanged', (message: string | null) => {
|
|
|
823
899
|
});
|
|
824
900
|
```
|
|
825
901
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
### Common Issues
|
|
829
|
-
|
|
830
|
-
#### Configurator Not Loading
|
|
831
|
-
|
|
832
|
-
**Symptoms:** Blank screen, iframe not appearing, loading indefinitely
|
|
833
|
-
|
|
834
|
-
**Root Causes & Solutions:**
|
|
835
|
-
|
|
836
|
-
| Issue | Diagnostic | Solution |
|
|
837
|
-
| --------------------------- | ------------------------------------ | --------------------------------------------------------- |
|
|
838
|
-
| Invalid configurator ID | Browser console shows 404 errors | Verify modular configurator ID in Metabox admin |
|
|
839
|
-
| Container not found | `Error: Container element not found` | Ensure element exists before calling `integrateMetabox()` |
|
|
840
|
-
| HTTP instead of HTTPS | Mixed content warnings | Use HTTPS or test on localhost |
|
|
841
|
-
| Container has no dimensions | Invisible iframe (0x0) | Set explicit width/height on container element |
|
|
842
|
-
| CORS/iframe blocking | X-Frame-Options errors | Check domain allowlist in Metabox settings |
|
|
843
|
-
|
|
844
|
-
**Diagnostic Code:**
|
|
902
|
+
**Showcase Control:**
|
|
845
903
|
|
|
846
904
|
```typescript
|
|
847
|
-
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
|
|
861
|
-
console.warn('⚠️ HTTPS required for Unreal Engine streaming');
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
integrateMetabox('config-id', containerId, (api) => {
|
|
865
|
-
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
|
+
}
|
|
866
917
|
});
|
|
867
918
|
```
|
|
868
919
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
**Symptoms:** Commands sent but no visual changes in configurator
|
|
872
|
-
|
|
873
|
-
**Common Mistakes:**
|
|
920
|
+
### Utility Functions
|
|
874
921
|
|
|
875
|
-
|
|
876
|
-
| ------------------------ | ------------------- | ----------------------------------------------- |
|
|
877
|
-
| Sending before API ready | Commands ignored | Only send in `apiReadyCallback` |
|
|
878
|
-
| Wrong component IDs | Component not found | Verify IDs from `configuratorDataUpdated` event |
|
|
879
|
-
| Root component not set | Blank configuration | Set root component first with `isRoot: true` |
|
|
880
|
-
| Type mismatch | Component rejected | Ensure `typeId` matches available types |
|
|
922
|
+
#### `saveImage(imageUrl: string, filename: string): void`
|
|
881
923
|
|
|
882
|
-
|
|
924
|
+
Downloads base64-encoded image to user's device.
|
|
883
925
|
|
|
884
|
-
|
|
885
|
-
integrateMetabox('config-id', 'container', (api) => {
|
|
886
|
-
// ✅ Correct: Commands sent after API ready
|
|
926
|
+
**Parameters:**
|
|
887
927
|
|
|
888
|
-
|
|
889
|
-
|
|
928
|
+
| Parameter | Type | Description |
|
|
929
|
+
| ---------- | -------- | --------------------------------------------------- |
|
|
930
|
+
| `imageUrl` | `string` | Base64 data URL (e.g., `data:image/png;base64,...`) |
|
|
931
|
+
| `filename` | `string` | Desired filename with extension |
|
|
890
932
|
|
|
891
|
-
|
|
892
|
-
api.sendCommandToMetabox(new SetComponent('comp-2', 'wheel', false));
|
|
933
|
+
**Example:**
|
|
893
934
|
|
|
894
|
-
|
|
895
|
-
|
|
935
|
+
```typescript
|
|
936
|
+
api.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
937
|
+
if (imageData) {
|
|
938
|
+
saveImage(imageData, `config-${Date.now()}.png`);
|
|
939
|
+
}
|
|
896
940
|
});
|
|
897
|
-
|
|
898
|
-
// ❌ Wrong: Command sent too early
|
|
899
|
-
api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
|
|
900
941
|
```
|
|
901
942
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
**Problem:** Compilation errors with API types
|
|
905
|
-
|
|
906
|
-
**Solutions:**
|
|
943
|
+
**Implementation Note:**
|
|
944
|
+
Creates a temporary anchor element with `download` attribute to trigger browser download.
|
|
907
945
|
|
|
908
|
-
|
|
946
|
+
#### `fromCommunicatorEvent(target: Communicator, eventName: string): Observable`
|
|
909
947
|
|
|
910
|
-
|
|
911
|
-
// ✅ Correct
|
|
912
|
-
import type { Communicator, ModularConfiguratorEnvelope, ModularConfiguratorComponent } from '@3dsource/metabox-modular-configurator-api';
|
|
913
|
-
|
|
914
|
-
// ❌ Wrong
|
|
915
|
-
import { Communicator } from '@3dsource/metabox-modular-configurator-api/types';
|
|
916
|
-
```
|
|
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()`.
|
|
917
949
|
|
|
918
|
-
**
|
|
919
|
-
|
|
920
|
-
```json
|
|
921
|
-
{
|
|
922
|
-
"compilerOptions": {
|
|
923
|
-
"moduleResolution": "node",
|
|
924
|
-
"esModuleInterop": true,
|
|
925
|
-
"skipLibCheck": true,
|
|
926
|
-
"strict": true
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
```
|
|
950
|
+
**Parameters:**
|
|
930
951
|
|
|
931
|
-
|
|
952
|
+
| Parameter | Type | Description |
|
|
953
|
+
| ----------- | -------------- | -------------------------------------------- |
|
|
954
|
+
| `target` | `Communicator` | The Communicator instance to listen on |
|
|
955
|
+
| `eventName` | `string` | Event name (e.g., `configuratorDataUpdated`) |
|
|
932
956
|
|
|
933
|
-
**
|
|
957
|
+
**Returns:** `Observable<T>` — typed Observable matching the event payload.
|
|
934
958
|
|
|
935
|
-
**
|
|
959
|
+
**Example:**
|
|
936
960
|
|
|
937
961
|
```typescript
|
|
938
|
-
|
|
939
|
-
// Root (chassis)
|
|
940
|
-
// ├── Child (wheel-front-left)
|
|
941
|
-
// ├── Child (wheel-front-right)
|
|
942
|
-
// └── Child (engine)
|
|
943
|
-
|
|
944
|
-
// Correct order:
|
|
945
|
-
api.sendCommandToMetabox(new SetComponent('chassis', 'base', true)); // Root first
|
|
946
|
-
api.sendCommandToMetabox(new SetComponent('wh-fl', 'wheel', false)); // Children after
|
|
947
|
-
api.sendCommandToMetabox(new SetComponent('wh-fr', 'wheel', false));
|
|
948
|
-
api.sendCommandToMetabox(new SetComponent('engine', 'engine', false));
|
|
949
|
-
```
|
|
962
|
+
import { fromCommunicatorEvent } from '@3dsource/metabox-modular-configurator-api';
|
|
950
963
|
|
|
951
|
-
|
|
964
|
+
integrateMetabox('configurator-id', 'embed3DSource', (api) => {
|
|
965
|
+
fromCommunicatorEvent(api, 'configuratorDataUpdated').subscribe((data) => {
|
|
966
|
+
console.log('Components:', data.componentsByComponentType);
|
|
967
|
+
});
|
|
952
968
|
|
|
953
|
-
|
|
954
|
-
|
|
969
|
+
fromCommunicatorEvent(api, 'screenshotReady').subscribe((imageData) => {
|
|
970
|
+
if (imageData) saveImage(imageData, 'screenshot.png');
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
```
|
|
955
974
|
|
|
956
975
|
## Standalone Mode
|
|
957
976
|
|
|
958
|
-
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()`.
|
|
959
978
|
|
|
960
979
|
### When to Use Standalone Mode
|
|
961
980
|
|
|
@@ -988,26 +1007,15 @@ Headless rendering mode for custom UI implementations. Disables all built-in Met
|
|
|
988
1007
|
**TypeScript:**
|
|
989
1008
|
|
|
990
1009
|
```typescript
|
|
991
|
-
import { integrateMetabox,
|
|
1010
|
+
import { integrateMetabox, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
992
1011
|
|
|
993
1012
|
integrateMetabox(
|
|
994
1013
|
'modular-config-id',
|
|
995
1014
|
'embed3DSource',
|
|
996
|
-
(api) => {
|
|
997
|
-
//
|
|
998
|
-
api.sendCommandToMetabox(new SetComponent('chassis-001', 'base', true));
|
|
999
|
-
|
|
1000
|
-
// Optional: Add child components
|
|
1001
|
-
api.sendCommandToMetabox(new SetComponent('wheel-fl', 'wheel', false));
|
|
1002
|
-
api.sendCommandToMetabox(new SetComponent('wheel-fr', 'wheel', false));
|
|
1003
|
-
|
|
1004
|
-
// Optional: Set environment
|
|
1005
|
-
api.sendCommandToMetabox(new SetEnvironment('studio-white'));
|
|
1006
|
-
|
|
1007
|
-
// Optional: Apply initial materials
|
|
1008
|
-
api.sendCommandToMetabox(new SetComponentMaterial('chassis-001', 'body', 'metallic-blue'));
|
|
1015
|
+
(api: Communicator) => {
|
|
1016
|
+
// Work with API here
|
|
1009
1017
|
},
|
|
1010
|
-
{ standalone: true },
|
|
1018
|
+
{ standalone: true }, // <- Enable standalone mode to disable default UI
|
|
1011
1019
|
);
|
|
1012
1020
|
```
|
|
1013
1021
|
|
|
@@ -1015,70 +1023,263 @@ integrateMetabox(
|
|
|
1015
1023
|
|
|
1016
1024
|
```html
|
|
1017
1025
|
<script type="module">
|
|
1018
|
-
import { integrateMetabox
|
|
1026
|
+
import { integrateMetabox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm';
|
|
1019
1027
|
|
|
1020
1028
|
integrateMetabox(
|
|
1021
1029
|
'config-id',
|
|
1022
1030
|
'container-id',
|
|
1023
1031
|
(api) => {
|
|
1024
|
-
//
|
|
1025
|
-
api.sendCommandToMetabox(new SetComponent('comp-1', 'chassis', true));
|
|
1026
|
-
api.sendCommandToMetabox(new SetEnvironment('env-1'));
|
|
1032
|
+
// Work with API here
|
|
1027
1033
|
},
|
|
1028
|
-
{ standalone: true },
|
|
1034
|
+
{ standalone: true }, // <- Enable standalone mode to disable default UI
|
|
1029
1035
|
);
|
|
1030
1036
|
</script>
|
|
1031
1037
|
```
|
|
1032
1038
|
|
|
1033
|
-
|
|
1039
|
+
## Building a Custom UI
|
|
1034
1040
|
|
|
1035
|
-
|
|
1041
|
+
To create a custom modular configurator interface, use [standalone mode](#standalone-mode) and subscribe to events before sending commands.
|
|
1036
1042
|
|
|
1037
|
-
|
|
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.
|
|
1038
1044
|
|
|
1039
|
-
|
|
1040
|
-
- All commands (component assembly, materials, environment)
|
|
1041
|
-
- Screenshot and PDF export
|
|
1042
|
-
- Validation (HTTPS enforcement, required parameters)
|
|
1043
|
-
|
|
1044
|
-
🎯 **Best Practice:**
|
|
1045
|
+
**Core Pattern:**
|
|
1045
1046
|
|
|
1046
1047
|
```typescript
|
|
1048
|
+
import { integrateMetabox, Communicator, ModularConfiguratorEnvelope } from '@3dsource/metabox-modular-configurator-api';
|
|
1049
|
+
|
|
1047
1050
|
integrateMetabox(
|
|
1048
|
-
'
|
|
1049
|
-
'
|
|
1050
|
-
(api) => {
|
|
1051
|
-
// 1.
|
|
1052
|
-
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1053
|
-
|
|
1054
|
-
|
|
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 */
|
|
1055
1063
|
});
|
|
1056
1064
|
|
|
1057
|
-
// 2.
|
|
1058
|
-
api.sendCommandToMetabox(new SetComponent('root-1', 'base', true));
|
|
1059
|
-
|
|
1060
|
-
// 3. Set environment
|
|
1061
|
-
api.sendCommandToMetabox(new SetEnvironment('studio-env'));
|
|
1062
|
-
|
|
1063
|
-
// 4. Build component tree
|
|
1064
|
-
api.sendCommandToMetabox(new SetComponent('child-1', 'wheel', false));
|
|
1065
|
-
api.sendCommandToMetabox(new SetComponent('child-2', 'wheel', false));
|
|
1065
|
+
// 2. Send commands via api.sendCommandToMetabox(new CommandClass(...args))
|
|
1066
1066
|
},
|
|
1067
1067
|
{ standalone: true },
|
|
1068
1068
|
);
|
|
1069
1069
|
```
|
|
1070
1070
|
|
|
1071
|
-
###
|
|
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` |
|
|
1072
1083
|
|
|
1073
|
-
**
|
|
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):**
|
|
1074
1095
|
|
|
1075
1096
|
```typescript
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
//
|
|
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
|
+
});
|
|
1084
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 |
|
|
1242
|
+
|
|
1243
|
+
**Correct Pattern:**
|
|
1244
|
+
|
|
1245
|
+
```typescript
|
|
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));
|
|
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/).
|