@3dsource/metabox-modular-configurator-api 2.0.4 → 2.0.5-dev.0
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
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Metabox Modular Configurator API
|
|
2
2
|
|
|
3
|
+
**Current Version:** 2.0.4
|
|
4
|
+
**Runtime Requirements:** Node >= 20.19.3, npm > 9
|
|
5
|
+
**Default Domain:** `metabox.3dsource.com`
|
|
6
|
+
|
|
3
7
|
A powerful TypeScript API for integrating and controlling the Metabox Modular Configurator in web
|
|
4
8
|
applications. This package provides seamless communication with 3D configurators, allowing you to control environments,
|
|
5
9
|
components, component types, materials, and capture screenshots or PDFs.
|
|
@@ -9,18 +13,49 @@ components, component types, materials, and capture screenshots or PDFs.
|
|
|
9
13
|
- [Features](#features)
|
|
10
14
|
- [Prerequisites](#prerequisites)
|
|
11
15
|
- [Installation](#installation)
|
|
16
|
+
- [NPM Installation (Recommended)](#npm-installation-recommended)
|
|
17
|
+
- [CDN Installation](#cdn-installation)
|
|
12
18
|
- [Quick Start](#quick-start)
|
|
19
|
+
- [1. HTML Setup](#1-html-setup)
|
|
20
|
+
- [2. Basic Integration](#2-basic-integration)
|
|
21
|
+
- [JavaScript (ES6 Modules)](#javascript-es6-modules)
|
|
22
|
+
- [TypeScript/Angular/React](#typescriptangularreact)
|
|
13
23
|
- [API Reference](#api-reference)
|
|
14
24
|
- [System Terminology](#system-terminology)
|
|
15
|
-
- [Steps to build custom menu](#steps-to-build-custom-menu)
|
|
25
|
+
- [Steps to build a custom menu](#steps-to-build-a-custom-menu)
|
|
16
26
|
- [Core Integration](#core-integration)
|
|
27
|
+
- [`integrateMetabox`](#integratemetabox)
|
|
17
28
|
- [Type Definitions](#type-definitions)
|
|
29
|
+
- [Core Types](#core-types)
|
|
30
|
+
- [`Communicator`](#communicator)
|
|
31
|
+
- [`ModularConfiguratorEnvelope`](#modularconfiguratorenvelope)
|
|
32
|
+
- [`ModularConfiguratorComponent`](#modularconfiguratorcomponent)
|
|
33
|
+
- [`Material`](#material)
|
|
34
|
+
- [`Environment`](#environment)
|
|
35
|
+
- [Command Payload Types](#command-payload-types)
|
|
36
|
+
- [Utility Types](#utility-types)
|
|
37
|
+
- [`MimeType`](#mimetype)
|
|
38
|
+
- [`ApplicationDeviceTypes`](#applicationdevicetypes)
|
|
39
|
+
- [`Position` and `Rotation`](#position-and-rotation)
|
|
18
40
|
- [Command Classes](#command-classes)
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
41
|
+
- [Core Configuration Commands](#core-configuration-commands)
|
|
42
|
+
- [UI / Interface](#ui--interface)
|
|
43
|
+
- [Camera / View](#camera--view)
|
|
44
|
+
- [Showcase Control](#showcase-control)
|
|
45
|
+
- [Export / Media](#export--media)
|
|
46
|
+
- [Unreal / Advanced](#unreal--advanced)
|
|
47
|
+
- [Internal Message Payload Shape (Excerpt)](#internal-message-payload-shape-excerpt)
|
|
21
48
|
- [Event Handling](#event-handling)
|
|
49
|
+
- [Available Events](#available-events)
|
|
50
|
+
- [Event Examples](#event-examples)
|
|
22
51
|
- [Troubleshooting](#troubleshooting)
|
|
23
|
-
- [
|
|
52
|
+
- [Common Issues](#common-issues)
|
|
53
|
+
- [Configurator Not Loading](#configurator-not-loading)
|
|
54
|
+
- [Commands Not Working](#commands-not-working)
|
|
55
|
+
- [TypeScript Errors](#typescript-errors)
|
|
56
|
+
- [Performance Tips](#performance-tips)
|
|
57
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
58
|
+
- [Standalone Mode](#standalone-mode)
|
|
24
59
|
|
|
25
60
|
## Features
|
|
26
61
|
|
|
@@ -37,9 +72,9 @@ components, component types, materials, and capture screenshots or PDFs.
|
|
|
37
72
|
|
|
38
73
|
- Modern web browser with ES6 module support
|
|
39
74
|
- HTTPS connection (required for Unreal Engine)
|
|
40
|
-
- Valid Metabox
|
|
75
|
+
- Valid Metabox configurator ID (not a full URL)
|
|
41
76
|
|
|
42
|
-
Important:
|
|
77
|
+
Important: integrateMetabox validates inputs at runtime. It requires a non-empty configuratorId and a non-empty containerId. The iframe URL is constructed internally as `https://{domain}/metabox-configurator/modular/{configuratorId}` with optional query parameters (introImage, introVideo, loadingImage). HTTPS is enforced and non-HTTPS URLs are rejected. It will throw if the container element is not found.
|
|
43
78
|
|
|
44
79
|
## Installation
|
|
45
80
|
|
|
@@ -48,7 +83,7 @@ Important: Use an HTTPS configurator URL and a valid container element ID. integ
|
|
|
48
83
|
For use with modern frameworks like Angular, React, Vue, etc.:
|
|
49
84
|
|
|
50
85
|
```bash
|
|
51
|
-
npm install @3dsource/metabox-modular-configurator-api
|
|
86
|
+
npm install @3dsource/metabox-modular-configurator-api@latest --save
|
|
52
87
|
```
|
|
53
88
|
|
|
54
89
|
### CDN Installation
|
|
@@ -56,12 +91,12 @@ npm install @3dsource/metabox-modular-configurator-api@^2.0.1 --save
|
|
|
56
91
|
For direct browser usage without a build system:
|
|
57
92
|
|
|
58
93
|
```javascript
|
|
59
|
-
import { integrateMetabox, Communicator, SetEnvironment, SetComponent } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@
|
|
94
|
+
import { integrateMetabox, Communicator, SetEnvironment, SetComponent } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm';
|
|
60
95
|
```
|
|
61
96
|
|
|
62
97
|
Alternative CDN options:
|
|
63
98
|
|
|
64
|
-
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api
|
|
99
|
+
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@latest/+esm`
|
|
65
100
|
|
|
66
101
|
## Quick Start
|
|
67
102
|
|
|
@@ -101,12 +136,12 @@ Create a container element where the configurator will be embedded:
|
|
|
101
136
|
|
|
102
137
|
```html
|
|
103
138
|
<script type="module">
|
|
104
|
-
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@
|
|
139
|
+
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';
|
|
105
140
|
|
|
106
|
-
// Replace it with your actual configurator URL
|
|
107
|
-
const
|
|
141
|
+
// Replace it with your actual configurator ID (not a full URL)
|
|
142
|
+
const configuratorId = 'configurator-id';
|
|
108
143
|
|
|
109
|
-
integrateMetabox(
|
|
144
|
+
integrateMetabox(configuratorId, 'embed3DSource', (api) => {
|
|
110
145
|
console.log('Configurator API ready!');
|
|
111
146
|
|
|
112
147
|
// Listen for configurator data updates
|
|
@@ -120,15 +155,15 @@ Create a container element where the configurator will be embedded:
|
|
|
120
155
|
});
|
|
121
156
|
|
|
122
157
|
// Set initial configuration
|
|
123
|
-
api.
|
|
124
|
-
api.
|
|
125
|
-
api.
|
|
126
|
-
api.
|
|
127
|
-
api.
|
|
128
|
-
api.
|
|
129
|
-
api.
|
|
130
|
-
api.
|
|
131
|
-
api.
|
|
158
|
+
api.sendCommandToMetabox(new SetComponent('componentId', 'typeId', true));
|
|
159
|
+
api.sendCommandToMetabox(new SetEnvironment('environmentId'));
|
|
160
|
+
api.sendCommandToMetabox(new SetComponentMaterial('slotId', 'materialId'));
|
|
161
|
+
api.sendCommandToMetabox(new SetEnvironmentMaterial('slotId', 'materialId'));
|
|
162
|
+
api.sendCommandToMetabox(new ShowEmbeddedMenu(false));
|
|
163
|
+
api.sendCommandToMetabox(new ShowOverlayInterface(false));
|
|
164
|
+
api.sendCommandToMetabox(new GetPdf());
|
|
165
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
166
|
+
api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
132
167
|
});
|
|
133
168
|
</script>
|
|
134
169
|
```
|
|
@@ -140,15 +175,15 @@ import { integrateMetabox, Communicator, ModularConfiguratorEnvelope, SetEnviron
|
|
|
140
175
|
|
|
141
176
|
class ConfiguratorIntegration {
|
|
142
177
|
private api: Communicator | null = null;
|
|
143
|
-
private readonly
|
|
178
|
+
private readonly configuratorId: string;
|
|
144
179
|
|
|
145
|
-
constructor(
|
|
146
|
-
this.
|
|
180
|
+
constructor(configuratorId: string) {
|
|
181
|
+
this.configuratorId = configuratorId;
|
|
147
182
|
this.initialize();
|
|
148
183
|
}
|
|
149
184
|
|
|
150
185
|
private initialize(): void {
|
|
151
|
-
integrateMetabox(this.
|
|
186
|
+
integrateMetabox(this.configuratorId, 'embed3DSource', (api: Communicator) => {
|
|
152
187
|
this.api = api;
|
|
153
188
|
this.setupEventListeners();
|
|
154
189
|
this.setupInitialState();
|
|
@@ -184,10 +219,10 @@ class ConfiguratorIntegration {
|
|
|
184
219
|
if (!this.api) return;
|
|
185
220
|
|
|
186
221
|
// Configure initial environment and components
|
|
187
|
-
this.api.
|
|
188
|
-
this.api.
|
|
189
|
-
this.api.
|
|
190
|
-
this.api.
|
|
222
|
+
this.api.sendCommandToMetabox(new SetEnvironment('default-environment'));
|
|
223
|
+
this.api.sendCommandToMetabox(new SetComponent('main-product', 'chair', true));
|
|
224
|
+
this.api.sendCommandToMetabox(new ShowOverlayInterface(true));
|
|
225
|
+
this.api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
|
|
191
226
|
}
|
|
192
227
|
|
|
193
228
|
private handleConfiguratorData(data: ModularConfiguratorEnvelope): void {
|
|
@@ -211,19 +246,19 @@ class ConfiguratorIntegration {
|
|
|
211
246
|
// Public API methods
|
|
212
247
|
public takeScreenshot(format: MimeType = 'image/png', size?: { x: number; y: number }): void {
|
|
213
248
|
if (this.api) {
|
|
214
|
-
this.api.
|
|
249
|
+
this.api.sendCommandToMetabox(new GetScreenshot(format, size));
|
|
215
250
|
}
|
|
216
251
|
}
|
|
217
252
|
|
|
218
253
|
public changeMaterial(slotId: string, materialId: string): void {
|
|
219
254
|
if (this.api) {
|
|
220
|
-
this.api.
|
|
255
|
+
this.api.sendCommandToMetabox(new SetComponentMaterial(slotId, materialId));
|
|
221
256
|
}
|
|
222
257
|
}
|
|
223
258
|
|
|
224
259
|
public changeEnvironment(environmentId: string): void {
|
|
225
260
|
if (this.api) {
|
|
226
|
-
this.api.
|
|
261
|
+
this.api.sendCommandToMetabox(new SetEnvironment(environmentId));
|
|
227
262
|
}
|
|
228
263
|
}
|
|
229
264
|
|
|
@@ -234,7 +269,7 @@ class ConfiguratorIntegration {
|
|
|
234
269
|
}
|
|
235
270
|
|
|
236
271
|
// Usage example
|
|
237
|
-
const configurator = new ConfiguratorIntegration('
|
|
272
|
+
const configurator = new ConfiguratorIntegration('configurator-id');
|
|
238
273
|
|
|
239
274
|
// Take a high-resolution screenshot
|
|
240
275
|
configurator.takeScreenshot('image/png', { x: 1920, y: 1080 });
|
|
@@ -270,45 +305,65 @@ configurator.changeMaterial('seat-fabric', 'leather-brown');
|
|
|
270
305
|
- Your backend decides how to use the configuration JSON (e.g., generate a PDF or build a product list).
|
|
271
306
|
- After your endpoint responds with a JSON containing "redirectUrl", the user is redirected in a new browser tab to that URL (a non‑Metabox page on your side) to complete the flow (e.g., leave contact information, proceed to checkout, etc.).
|
|
272
307
|
|
|
273
|
-
### Steps to build custom menu
|
|
274
|
-
|
|
275
|
-
- **configuratorDataUpdated** - add event listener to receive get configurator data and then updates
|
|
276
|
-
- **showEmbeddedMenu** - hide embedded metabox right sidebar, but if you want to show it again, you can use this method
|
|
277
|
-
- **showOverlayInterface** - hide viewport metabox actions if you want to add yours
|
|
278
|
-
- **setEnvironment** - set active environment when you want to change environment
|
|
279
|
-
- **setEnvironmentMaterialById** - set environment material by slot ID
|
|
280
|
-
- **setComponentType** - set component type when you want to change component type !!!IMPORTANT!!!
|
|
281
|
-
- **setComponent** - set active component
|
|
282
|
-
- **setComponentMaterialById** - set component material by slot ID
|
|
283
|
-
- **getScreenshot** - get screenshot
|
|
284
|
-
- **getCallToActionInformation** - send call to action information to api endpoint provided in CTA configuration
|
|
285
|
-
- **getPdf** - get PDF.
|
|
308
|
+
### Steps to build a custom menu
|
|
286
309
|
|
|
287
|
-
|
|
310
|
+
Updated recommendations:
|
|
288
311
|
|
|
289
|
-
|
|
312
|
+
- Use `configuratorDataUpdated` to hydrate custom UI and subscribe for deltas.
|
|
313
|
+
- Hide built‑in menu: `ShowEmbeddedMenu(false)`; restore with `ShowEmbeddedMenu(true)`.
|
|
314
|
+
- Hide overlay elements if replacing viewport controls: `ShowOverlayInterface(false)`.
|
|
315
|
+
- Switch component type before presenting a list of components: `SetComponentType(typeId)`.
|
|
290
316
|
|
|
291
|
-
|
|
317
|
+
### Core Integration
|
|
292
318
|
|
|
293
|
-
|
|
319
|
+
#### `integrateMetabox`
|
|
294
320
|
|
|
295
|
-
|
|
296
|
-
- `containerId` (`string`): The ID of the HTML element where the configurator will be embedded
|
|
297
|
-
- `apiReadyCallback` (`(api: Communicator) => void`): Callback function that receives the API communicator instance
|
|
298
|
-
- `config` (Partial<MetaboxCommandConfig>, optional): Initial configuration for the integration. Set `standalone: true` to disable Metabox’s built-in UI/template logic and control everything from the host app. Other fields like `hostUrl` and `apiVersion` are populated automatically.
|
|
321
|
+
Integrates the Metabox Modular Configurator into the specified container element.
|
|
299
322
|
|
|
300
323
|
**TypeScript Signature:**
|
|
301
324
|
|
|
302
325
|
```typescript
|
|
303
|
-
function integrateMetabox(
|
|
326
|
+
function integrateMetabox(
|
|
327
|
+
configuratorId: string,
|
|
328
|
+
containerId: string, // defaults to 'embed3DSource'
|
|
329
|
+
apiReadyCallback: (api: Communicator) => void, // required
|
|
330
|
+
config?: IntegrateMetaboxConfig,
|
|
331
|
+
): void;
|
|
304
332
|
```
|
|
305
333
|
|
|
334
|
+
**Parameters:**
|
|
335
|
+
|
|
336
|
+
- `configuratorId` (required): Modular configurator ID (not full URL). Iframe src internally: `https://{domain}/metabox-configurator/modular/{configuratorId}`.
|
|
337
|
+
- `containerId` (optional): Host element id (default `embed3DSource`).
|
|
338
|
+
- `apiReadyCallback` (required): Called once the embedded app signals readiness (`appLoaded_v2`).
|
|
339
|
+
- `config` (optional):
|
|
340
|
+
- `standalone?`: Disable built‑in template / UI logic inside iframe.
|
|
341
|
+
- `introImage?`, `introVideo?`, `loadingImage?`: Optional URLs appended as query params when present.
|
|
342
|
+
- `domain?`: Override default domain (HTTPS enforced).
|
|
343
|
+
|
|
344
|
+
**Throws:** Error if IDs empty, container missing, or computed iframe URL not HTTPS.
|
|
345
|
+
|
|
346
|
+
**Notes:** A previous iframe with id `embeddedContent` is removed before adding a new one.
|
|
347
|
+
|
|
306
348
|
**Example:**
|
|
307
349
|
|
|
308
350
|
```typescript
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
351
|
+
import { IntegrateMetaboxConfig } from '@3dsource/metabox-modular-configurator-api';
|
|
352
|
+
|
|
353
|
+
const config: IntegrateMetaboxConfig = {
|
|
354
|
+
introImage: 'https://example.com/intro.png',
|
|
355
|
+
loadingImage: 'https://example.com/loading.png',
|
|
356
|
+
standalone: false,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
integrateMetabox(
|
|
360
|
+
'configurator-id',
|
|
361
|
+
'embed3DSource',
|
|
362
|
+
(api) => {
|
|
363
|
+
console.log('API ready!', api);
|
|
364
|
+
},
|
|
365
|
+
config,
|
|
366
|
+
);
|
|
312
367
|
```
|
|
313
368
|
|
|
314
369
|
### Type Definitions
|
|
@@ -323,7 +378,7 @@ The main API interface for sending commands and listening to events.
|
|
|
323
378
|
|
|
324
379
|
```typescript
|
|
325
380
|
interface Communicator {
|
|
326
|
-
|
|
381
|
+
sendCommandToMetabox<T extends keyof ToMetaboxMessagePayloads>(command: CommandBase<T>): void;
|
|
327
382
|
|
|
328
383
|
addEventListener<K extends keyof FromMetaboxMessagePayloads>(eventType: K, listener: (data: FromMetaboxMessagePayloads[K]) => void): void;
|
|
329
384
|
|
|
@@ -425,10 +480,11 @@ All commands use strongly typed payloads defined in `ToMetaboxMessagePayloads`:
|
|
|
425
480
|
|
|
426
481
|
```typescript
|
|
427
482
|
interface ToMetaboxMessagePayloads {
|
|
483
|
+
metaboxConfig: { appId: string; config: MetaboxCommandConfig };
|
|
428
484
|
setEnvironment: { id: string };
|
|
429
485
|
setEnvironmentMaterialById: { slotId: string; materialId: string };
|
|
430
|
-
setComponent: { id: string; typeId: string; isRoot: boolean };
|
|
431
486
|
setComponentType: { typeId: string };
|
|
487
|
+
setComponent: { id: string; typeId: string; isRoot: boolean };
|
|
432
488
|
setComponentMaterialById: { slotId: string; materialId: string };
|
|
433
489
|
getScreenshot: { format: MimeType; size?: { x: number; y: number } };
|
|
434
490
|
getCallToActionInformation: void;
|
|
@@ -484,590 +540,126 @@ interface Rotation {
|
|
|
484
540
|
|
|
485
541
|
### Command Classes
|
|
486
542
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
#### `SetEnvironment(environmentId)`
|
|
490
|
-
|
|
491
|
-
Sets the active environment/scene in the configurator.
|
|
492
|
-
|
|
493
|
-
**Parameters:**
|
|
494
|
-
|
|
495
|
-
- `environmentId` (string): The ID of the environment to activate
|
|
496
|
-
|
|
497
|
-
**Example:**
|
|
498
|
-
|
|
499
|
-
```typescript
|
|
500
|
-
api.sendCommandToMetaBox(new SetEnvironment('environment-001'));
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
#### `SetEnvironmentMaterial(slotId, materialId)`
|
|
504
|
-
|
|
505
|
-
Changes the material of an environment element.
|
|
506
|
-
|
|
507
|
-
**Parameters:**
|
|
508
|
-
|
|
509
|
-
- `slotId` (string): The slot identifier for the environment element
|
|
510
|
-
- `materialId` (string): The ID of the material to apply
|
|
511
|
-
|
|
512
|
-
**Example:**
|
|
513
|
-
|
|
514
|
-
```typescript
|
|
515
|
-
api.sendCommandToMetaBox(new SetEnvironmentMaterial('floor-slot', 'wood-material'));
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
### Component Management
|
|
519
|
-
|
|
520
|
-
#### `SetComponent(id, typeId, isRoot)`
|
|
521
|
-
|
|
522
|
-
Adds or updates a component in the configurator.
|
|
523
|
-
|
|
524
|
-
**Parameters:**
|
|
525
|
-
|
|
526
|
-
- `id` (string): Unique identifier for the component
|
|
527
|
-
- `typeId` (string): The type/category of the component
|
|
528
|
-
- `isRoot` (boolean): Whether this is a root component
|
|
529
|
-
|
|
530
|
-
**Example:**
|
|
531
|
-
|
|
532
|
-
```typescript
|
|
533
|
-
api.sendCommandToMetaBox(new SetComponent('chair-001', 'furniture', true));
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
#### `SetComponentType(componentId, typeId)`
|
|
537
|
-
|
|
538
|
-
Changes the type of the existing component.
|
|
539
|
-
|
|
540
|
-
**Parameters:**
|
|
541
|
-
|
|
542
|
-
- `componentId` (string): The ID of the component to modify
|
|
543
|
-
- `typeId` (string): The new type ID to assign
|
|
544
|
-
|
|
545
|
-
**Example:**
|
|
546
|
-
|
|
547
|
-
```typescript
|
|
548
|
-
api.sendCommandToMetaBox(new SetComponentType('chair-001', 'office-chair'));
|
|
549
|
-
```
|
|
550
|
-
|
|
551
|
-
#### `SetComponentMaterial(slotId, materialId)`
|
|
552
|
-
|
|
553
|
-
Applies a material to a component's material slot.
|
|
554
|
-
|
|
555
|
-
**Parameters:**
|
|
556
|
-
|
|
557
|
-
- `slotId` (string): The material slot identifier
|
|
558
|
-
- `materialId` (string): The ID of the material to apply
|
|
559
|
-
|
|
560
|
-
**Example:**
|
|
561
|
-
|
|
562
|
-
```typescript
|
|
563
|
-
api.sendCommandToMetaBox(new SetComponentMaterial('chair-fabric', 'leather-brown'));
|
|
564
|
-
```
|
|
565
|
-
|
|
566
|
-
### UI Control
|
|
567
|
-
|
|
568
|
-
#### `ShowEmbeddedMenu(visible)`
|
|
569
|
-
|
|
570
|
-
Controls the visibility of the embedded configurator menu (right sidebar).
|
|
571
|
-
|
|
572
|
-
**Parameters:**
|
|
573
|
-
|
|
574
|
-
- `visible` (boolean): `true` to show the built-in menu; `false` to hide it.
|
|
575
|
-
|
|
576
|
-
**Examples:**
|
|
577
|
-
|
|
578
|
-
```typescript
|
|
579
|
-
api.sendCommandToMetaBox(new ShowEmbeddedMenu(true)); // Show menu
|
|
580
|
-
api.sendCommandToMetaBox(new ShowEmbeddedMenu(false)); // Hide menu
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
#### `ShowOverlayInterface(visible)`
|
|
584
|
-
|
|
585
|
-
Controls the visibility of the overlay interface over the Unreal viewport (e.g., on‑viewport buttons, tooltips, hotspots).
|
|
586
|
-
|
|
587
|
-
**Parameters:**
|
|
588
|
-
|
|
589
|
-
- `visible` (boolean): `true` to show the overlay; `false` to hide it.
|
|
590
|
-
|
|
591
|
-
**Examples:**
|
|
592
|
-
|
|
593
|
-
```typescript
|
|
594
|
-
api.sendCommandToMetaBox(new ShowOverlayInterface(true)); // Show overlay
|
|
595
|
-
api.sendCommandToMetaBox(new ShowOverlayInterface(false)); // Hide overlay
|
|
596
|
-
```
|
|
597
|
-
|
|
598
|
-
### Camera Control
|
|
599
|
-
|
|
600
|
-
#### `ResetCamera()`
|
|
601
|
-
|
|
602
|
-
Resets the camera to its default position and rotation.
|
|
603
|
-
|
|
604
|
-
**Example:**
|
|
605
|
-
|
|
606
|
-
```typescript
|
|
607
|
-
api.sendCommandToMetaBox(new ResetCamera());
|
|
608
|
-
```
|
|
609
|
-
|
|
610
|
-
#### `ApplyZoom(zoom)`
|
|
611
|
-
|
|
612
|
-
Applies zoom to the camera view.
|
|
613
|
-
|
|
614
|
-
**Parameters:**
|
|
615
|
-
|
|
616
|
-
- `zoom` (number): Zoom level (typically between 0.1 and 3.0)
|
|
617
|
-
|
|
618
|
-
**Example:**
|
|
619
|
-
|
|
620
|
-
```typescript
|
|
621
|
-
api.sendCommandToMetaBox(new ApplyZoom(1.5)); // 150% zoom
|
|
622
|
-
```
|
|
623
|
-
|
|
624
|
-
### Export & Capture
|
|
625
|
-
|
|
626
|
-
#### `GetScreenshot(mimeType, size?)`
|
|
627
|
-
|
|
628
|
-
Captures a screenshot of the current configurator view.
|
|
629
|
-
|
|
630
|
-
**Parameters:**
|
|
631
|
-
|
|
632
|
-
- `mimeType` (`string`): Image format ('image/png', 'image/jpeg', 'image/webp')
|
|
633
|
-
- `size` (`{ x: number; y: number }`, optional): Screenshot dimensions in pixels
|
|
634
|
-
|
|
635
|
-
**TypeScript Interface:**
|
|
636
|
-
|
|
637
|
-
```typescript
|
|
638
|
-
interface ScreenshotSize {
|
|
639
|
-
x: number; // Width in pixels
|
|
640
|
-
y: number; // Height in pixels
|
|
641
|
-
}
|
|
642
|
-
```
|
|
643
|
-
|
|
644
|
-
**Example:**
|
|
645
|
-
|
|
646
|
-
```typescript
|
|
647
|
-
api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
648
|
-
```
|
|
649
|
-
|
|
650
|
-
#### `GetPdf()`
|
|
651
|
-
|
|
652
|
-
Generates a PDF document of the current configuration.
|
|
653
|
-
|
|
654
|
-
**Example:**
|
|
655
|
-
|
|
656
|
-
```typescript
|
|
657
|
-
api.sendCommandToMetaBox(new GetPdf());
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
### Commerce & CTA
|
|
661
|
-
|
|
662
|
-
#### `GetCallToActionInformation()`
|
|
663
|
-
|
|
664
|
-
Requests Call-To-Action information based on the current configuration. The configurator will compile CTA data and post it to the endpoint specified in the CTA configuration.
|
|
665
|
-
|
|
666
|
-
- No parameters.
|
|
667
|
-
- The response is delivered to the configured endpoint URL; listen to your backend or proxy endpoint to handle it.
|
|
668
|
-
|
|
669
|
-
**Example:**
|
|
543
|
+
All commands are dispatched via:
|
|
670
544
|
|
|
671
545
|
```typescript
|
|
672
|
-
api.
|
|
546
|
+
api.sendCommandToMetabox(new SomeCommand(...));
|
|
673
547
|
```
|
|
674
548
|
|
|
675
|
-
####
|
|
676
|
-
|
|
677
|
-
Utility function to save image data to a file.
|
|
549
|
+
#### Core Configuration Commands
|
|
678
550
|
|
|
679
|
-
|
|
551
|
+
- `SetComponent(id, typeId, isRoot)` – Add/select a component (root or child).
|
|
552
|
+
- `SetComponentType(typeId)` – Switch active component type context.
|
|
553
|
+
- `SetComponentMaterial(slotId, materialId)` – Apply material to a component slot.
|
|
554
|
+
- `SetEnvironment(id)` – Activate environment.
|
|
555
|
+
- `SetEnvironmentMaterial(slotId, materialId)` – Apply material to environment slot.
|
|
680
556
|
|
|
681
|
-
|
|
682
|
-
- `fileName` (string): Name for the downloaded file
|
|
557
|
+
#### UI / Interface
|
|
683
558
|
|
|
684
|
-
|
|
559
|
+
- `ShowEmbeddedMenu(visible)` – Toggle built‑in right sidebar menu.
|
|
560
|
+
- `ShowOverlayInterface(visible)` – Toggle overlay UI elements (hotspots / viewport controls).
|
|
561
|
+
- `forceSetDeviceType(deviceType)` – Force layout/device mode (desktop/tablet/mobile) without relying on viewport breakpoints.
|
|
685
562
|
|
|
686
|
-
|
|
687
|
-
saveImage(data, 'my-configuration.png');
|
|
688
|
-
```
|
|
563
|
+
#### Camera / View
|
|
689
564
|
|
|
690
|
-
|
|
565
|
+
- `ResetCamera()` – Reset to initial camera transform.
|
|
566
|
+
- `ApplyZoom(zoom)` – Apply zoom delta (positive/negative). Respect configured min/max.
|
|
691
567
|
|
|
692
|
-
####
|
|
568
|
+
#### Showcase Control
|
|
693
569
|
|
|
694
|
-
|
|
570
|
+
- `InitShowcase()` – Initialize a showcase sequence for current component/product context.
|
|
571
|
+
- `PlayShowcase()` / `PauseShowcase()` / `StopShowcase()` – Playback controls.
|
|
695
572
|
|
|
696
|
-
|
|
573
|
+
#### Export / Media
|
|
697
574
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
575
|
+
- `GetScreenshot(format, size?)` – Request ordered render; listen to `screenshotReady`.
|
|
576
|
+
- `GetPdf()` – Request PDF generation (no dedicated completion event; follow status messages).
|
|
577
|
+
- `GetCallToActionInformation()` – Trigger CTA flow; backend must respond with `{ redirectUrl }`.
|
|
701
578
|
|
|
702
|
-
####
|
|
579
|
+
#### Unreal / Advanced
|
|
703
580
|
|
|
704
|
-
|
|
581
|
+
- `UnrealCommand(command: object | string)` – Send custom Unreal engine command (low‑level; not guaranteed stable).
|
|
582
|
+
- `MetaboxConfig(appId, partialConfig)` – Initialization command auto‑sent internally.
|
|
583
|
+
- `forceSetDeviceType(deviceType)` – Force layout/device mode (desktop/tablet/mobile) without relying on viewport breakpoints.
|
|
705
584
|
|
|
706
585
|
**Examples:**
|
|
707
586
|
|
|
708
587
|
```typescript
|
|
709
|
-
|
|
710
|
-
api.
|
|
711
|
-
api.sendCommandToMetaBox(new StopShowcase()); // Stop and reset
|
|
712
|
-
```
|
|
713
|
-
|
|
714
|
-
### Advanced Features
|
|
715
|
-
|
|
716
|
-
#### `UnrealCommand(command)`
|
|
717
|
-
|
|
718
|
-
Sends custom commands directly to the Unreal Engine.
|
|
719
|
-
|
|
720
|
-
**Parameters:**
|
|
721
|
-
|
|
722
|
-
- `command` (string): Custom Unreal Engine command
|
|
723
|
-
|
|
724
|
-
**Example:**
|
|
725
|
-
|
|
726
|
-
```typescript
|
|
727
|
-
api.sendCommandToMetaBox(new UnrealCommand('SetLightIntensity 2.5'));
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
## Examples
|
|
731
|
-
|
|
732
|
-
### CTA Request Example
|
|
733
|
-
|
|
734
|
-
```typescript
|
|
735
|
-
import { integrateMetabox, Communicator, GetCallToActionInformation } from '@3dsource/metabox-modular-configurator-api';
|
|
736
|
-
|
|
737
|
-
integrateMetabox('https://metabox.3dsource.com/metabox-configurator/modular/your-configurator-id', 'embed3DSource', (api: Communicator) => {
|
|
738
|
-
// Request CTA data for the current configuration
|
|
739
|
-
api.sendCommandToMetaBox(new GetCallToActionInformation());
|
|
740
|
-
});
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
### Complete Product Configurator
|
|
744
|
-
|
|
745
|
-
```typescript
|
|
746
|
-
import { integrateMetabox, Communicator, ModularConfiguratorEnvelope, SetEnvironment, SetComponent, SetComponentMaterial, ShowOverlayInterface, GetScreenshot, ResetCamera } from '@3dsource/metabox-modular-configurator-api';
|
|
747
|
-
|
|
748
|
-
class ProductConfigurator {
|
|
749
|
-
private api: Communicator | null = null;
|
|
750
|
-
private currentConfig: ModularConfiguratorEnvelope | null = null;
|
|
751
|
-
|
|
752
|
-
constructor(configuratorUrl: string) {
|
|
753
|
-
integrateMetabox(configuratorUrl, 'embed3DSource', (api) => {
|
|
754
|
-
this.api = api;
|
|
755
|
-
this.setupEventListeners();
|
|
756
|
-
this.initializeProduct();
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
private setupEventListeners(): void {
|
|
761
|
-
if (!this.api) return;
|
|
762
|
-
|
|
763
|
-
this.api.addEventListener('configuratorDataUpdated', (data: ModularConfiguratorEnvelope) => {
|
|
764
|
-
this.currentConfig = data;
|
|
765
|
-
this.onConfigurationChange(data);
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
this.api.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
769
|
-
if (imageData) {
|
|
770
|
-
this.onScreenshotReady(imageData);
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
private initializeProduct(): void {
|
|
776
|
-
if (!this.api) return;
|
|
777
|
-
|
|
778
|
-
// Set up the initial environment
|
|
779
|
-
this.api.sendCommandToMetaBox(new SetEnvironment('showroom-001'));
|
|
588
|
+
// Force device type to mobile layout
|
|
589
|
+
api.sendCommandToMetabox(new ForceSetDeviceType('mobile'));
|
|
780
590
|
|
|
781
|
-
|
|
782
|
-
|
|
591
|
+
// Adjust zoom smoothly
|
|
592
|
+
api.sendCommandToMetabox(new ApplyZoom(0.25)); // zoom in
|
|
593
|
+
api.sendCommandToMetabox(new ApplyZoom(-0.25)); // zoom out
|
|
783
594
|
|
|
784
|
-
|
|
785
|
-
|
|
595
|
+
// Low-level Unreal command (example payload)
|
|
596
|
+
api.sendCommandToMetabox(new UnrealCommand({ action: 'SetLightIntensity', lightId: 'keyLight', value: 2.5 }));
|
|
786
597
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
public changeMaterial(slotId: string, materialId: string): void {
|
|
792
|
-
if (this.api) {
|
|
793
|
-
this.api.sendCommandToMetaBox(new SetComponentMaterial(slotId, materialId));
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
public takeProductPhoto(): void {
|
|
798
|
-
if (this.api) {
|
|
799
|
-
this.api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
private onConfigurationChange(data: ModularConfiguratorEnvelope): void {
|
|
804
|
-
console.log('Configuration updated:', data);
|
|
805
|
-
// Update your UI, save state, etc.
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
private onScreenshotReady(imageData: string): void {
|
|
809
|
-
// Create download link or display image
|
|
810
|
-
const link = document.createElement('a');
|
|
811
|
-
link.download = 'product-configuration.png';
|
|
812
|
-
link.href = imageData;
|
|
813
|
-
link.click();
|
|
814
|
-
}
|
|
815
|
-
}
|
|
598
|
+
// Simpler string-based Unreal command variant (if supported)
|
|
599
|
+
api.sendCommandToMetabox(new UnrealCommand('SetSunTime 14:30'));
|
|
816
600
|
```
|
|
817
601
|
|
|
818
|
-
|
|
602
|
+
#### Internal Message Payload Shape (Excerpt)
|
|
819
603
|
|
|
820
604
|
```typescript
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
configData: ModularConfiguratorEnvelope | null;
|
|
842
|
-
isLoading: boolean;
|
|
843
|
-
error: string | null;
|
|
844
|
-
// Actions
|
|
845
|
-
changeEnvironment: (environmentId: string) => void;
|
|
846
|
-
takeScreenshot: (format?: MimeType, size?: { x: number; y: number }) => void;
|
|
847
|
-
changeMaterial: (slotId: string, materialId: string) => void;
|
|
848
|
-
addComponent: (id: string, typeId: string, isRoot?: boolean) => void;
|
|
849
|
-
initialize: () => void;
|
|
850
|
-
destroy: () => void;
|
|
605
|
+
interface ToMetaboxMessagePayloads {
|
|
606
|
+
metaboxConfig: { appId: string; config: MetaboxCommandConfig };
|
|
607
|
+
setEnvironment: { id: string };
|
|
608
|
+
setEnvironmentMaterialById: { slotId: string; materialId: string };
|
|
609
|
+
setComponentType: { typeId: string };
|
|
610
|
+
setComponent: { id: string; typeId: string; isRoot: boolean };
|
|
611
|
+
setComponentMaterialById: { slotId: string; materialId: string };
|
|
612
|
+
getScreenshot: { format: MimeType; size?: { x: number; y: number } };
|
|
613
|
+
getCallToActionInformation: void;
|
|
614
|
+
getPdf: void;
|
|
615
|
+
showEmbeddedMenu: { visible: boolean };
|
|
616
|
+
showOverlayInterface: { visible: boolean };
|
|
617
|
+
forceSetDeviceType: { deviceType: ApplicationDeviceTypes };
|
|
618
|
+
resetCamera: void;
|
|
619
|
+
applyZoom: { zoom: number };
|
|
620
|
+
initShowcase: void;
|
|
621
|
+
playShowcase: void;
|
|
622
|
+
pauseShowcase: void;
|
|
623
|
+
stopShowcase: void;
|
|
624
|
+
sendCommandToUnreal: object;
|
|
851
625
|
}
|
|
852
|
-
|
|
853
|
-
export const useMetaboxConfigurator = ({
|
|
854
|
-
configuratorUrl,
|
|
855
|
-
autoInitialize = true,
|
|
856
|
-
}: UseMetaboxConfiguratorOptions): UseMetaboxConfiguratorReturn => {
|
|
857
|
-
const [api, setApi] = useState<Communicator | null>(null);
|
|
858
|
-
const [isReady, setIsReady] = useState<boolean>(false);
|
|
859
|
-
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
860
|
-
const [error, setError] = useState<string | null>(null);
|
|
861
|
-
const [configData, setConfigData] = useState<ModularConfiguratorEnvelope | null>(null);
|
|
862
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
863
|
-
|
|
864
|
-
const initialize = useCallback(() => {
|
|
865
|
-
if (!containerRef.current || !configuratorUrl || isLoading) return;
|
|
866
|
-
|
|
867
|
-
setIsLoading(true);
|
|
868
|
-
setError(null);
|
|
869
|
-
|
|
870
|
-
try {
|
|
871
|
-
const containerId = 'metabox-container-' + Date.now();
|
|
872
|
-
containerRef.current.id = containerId;
|
|
873
|
-
|
|
874
|
-
integrateMetabox(configuratorUrl, containerId, (apiInstance: Communicator) => {
|
|
875
|
-
setApi(apiInstance);
|
|
876
|
-
setIsReady(true);
|
|
877
|
-
setIsLoading(false);
|
|
878
|
-
|
|
879
|
-
// Set up event listeners
|
|
880
|
-
apiInstance.addEventListener('configuratorDataUpdated', (data: ModularConfiguratorEnvelope) => {
|
|
881
|
-
setConfigData(data);
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
apiInstance.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
885
|
-
// Handle screenshot data - could emit custom event or callback
|
|
886
|
-
if (imageData) {
|
|
887
|
-
console.log('Screenshot ready:', imageData);
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
apiInstance.addEventListener('pdfGenerating', (isGenerating: boolean) => {
|
|
892
|
-
// Handle PDF generation state
|
|
893
|
-
console.log('PDF generating:', isGenerating);
|
|
894
|
-
});
|
|
895
|
-
});
|
|
896
|
-
} catch (err) {
|
|
897
|
-
setError(err instanceof Error ? err.message : 'Failed to initialize configurator');
|
|
898
|
-
setIsLoading(false);
|
|
899
|
-
}
|
|
900
|
-
}, [configuratorUrl, isLoading]);
|
|
901
|
-
|
|
902
|
-
const destroy = useCallback(() => {
|
|
903
|
-
setApi(null);
|
|
904
|
-
setIsReady(false);
|
|
905
|
-
setIsLoading(false);
|
|
906
|
-
setConfigData(null);
|
|
907
|
-
setError(null);
|
|
908
|
-
}, []);
|
|
909
|
-
|
|
910
|
-
useEffect(() => {
|
|
911
|
-
if (autoInitialize) {
|
|
912
|
-
initialize();
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
return destroy;
|
|
916
|
-
}, [initialize, destroy, autoInitialize]);
|
|
917
|
-
|
|
918
|
-
// Action methods
|
|
919
|
-
const changeEnvironment = useCallback((environmentId: string) => {
|
|
920
|
-
if (api && isReady) {
|
|
921
|
-
api.sendCommandToMetaBox(new SetEnvironment(environmentId));
|
|
922
|
-
}
|
|
923
|
-
}, [api, isReady]);
|
|
924
|
-
|
|
925
|
-
const takeScreenshot = useCallback((
|
|
926
|
-
format: MimeType = 'image/png',
|
|
927
|
-
size?: { x: number; y: number },
|
|
928
|
-
) => {
|
|
929
|
-
if (api && isReady) {
|
|
930
|
-
api.sendCommandToMetaBox(new GetScreenshot(format, size));
|
|
931
|
-
}
|
|
932
|
-
}, [api, isReady]);
|
|
933
|
-
|
|
934
|
-
const changeMaterial = useCallback((slotId: string, materialId: string) => {
|
|
935
|
-
if (api && isReady) {
|
|
936
|
-
api.sendCommandToMetaBox(new SetComponentMaterial(slotId, materialId));
|
|
937
|
-
}
|
|
938
|
-
}, [api, isReady]);
|
|
939
|
-
|
|
940
|
-
const addComponent = useCallback((id: string, typeId: string, isRoot: boolean = false) => {
|
|
941
|
-
if (api && isReady) {
|
|
942
|
-
api.sendCommandToMetaBox(new SetComponent(id, typeId, isRoot));
|
|
943
|
-
}
|
|
944
|
-
}, [api, isReady]);
|
|
945
|
-
|
|
946
|
-
return {
|
|
947
|
-
containerRef,
|
|
948
|
-
api,
|
|
949
|
-
isReady,
|
|
950
|
-
configData,
|
|
951
|
-
isLoading,
|
|
952
|
-
error,
|
|
953
|
-
changeEnvironment,
|
|
954
|
-
takeScreenshot,
|
|
955
|
-
changeMaterial,
|
|
956
|
-
addComponent,
|
|
957
|
-
initialize,
|
|
958
|
-
destroy,
|
|
959
|
-
};
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
// Usage example in a React component
|
|
963
|
-
const ConfiguratorComponent: React.FC = () => {
|
|
964
|
-
const {
|
|
965
|
-
containerRef,
|
|
966
|
-
isReady,
|
|
967
|
-
isLoading,
|
|
968
|
-
error,
|
|
969
|
-
configData,
|
|
970
|
-
changeEnvironment,
|
|
971
|
-
takeScreenshot,
|
|
972
|
-
changeMaterial,
|
|
973
|
-
} = useMetaboxConfigurator({
|
|
974
|
-
configuratorUrl: 'https://metabox.3dsource.com/metabox-configurator/modular/your-id',
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
const handleEnvironmentChange = (envId: string) => {
|
|
978
|
-
changeEnvironment(envId);
|
|
979
|
-
};
|
|
980
|
-
|
|
981
|
-
const handleTakeScreenshot = () => {
|
|
982
|
-
takeScreenshot('image/png', { x: 1920, y: 1080 });
|
|
983
|
-
};
|
|
984
|
-
|
|
985
|
-
if (error) {
|
|
986
|
-
return <div className="error">Error loading configurator: {error}</div>;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
return (
|
|
990
|
-
<div className="configurator-wrapper">
|
|
991
|
-
{isLoading && <div className="loading">Loading configurator...</div>}
|
|
992
|
-
|
|
993
|
-
<div ref={containerRef} className="configurator-container" />
|
|
994
|
-
|
|
995
|
-
{isReady && (
|
|
996
|
-
<div className="controls">
|
|
997
|
-
<button onClick={() => handleEnvironmentChange('showroom-1')}>
|
|
998
|
-
Showroom Environment
|
|
999
|
-
</button>
|
|
1000
|
-
<button onClick={() => changeMaterial('seat', 'leather-brown')}>
|
|
1001
|
-
Brown Leather
|
|
1002
|
-
</button>
|
|
1003
|
-
<button onClick={handleTakeScreenshot}>
|
|
1004
|
-
Take Screenshot
|
|
1005
|
-
</button>
|
|
1006
|
-
</div>
|
|
1007
|
-
)}
|
|
1008
|
-
|
|
1009
|
-
{configData && (
|
|
1010
|
-
<div className="config-info">
|
|
1011
|
-
<p>Components: {configData.componentsByComponentType ? Object.keys(configData.componentsByComponentType).length : 0}</p>
|
|
1012
|
-
<p>Environment: {configData.environmentId}</p>
|
|
1013
|
-
</div>
|
|
1014
|
-
)}
|
|
1015
|
-
</div>
|
|
1016
|
-
);
|
|
1017
|
-
};
|
|
1018
626
|
```
|
|
1019
627
|
|
|
1020
|
-
|
|
628
|
+
### Event Handling
|
|
1021
629
|
|
|
1022
|
-
The
|
|
630
|
+
The below events originate from the embedded configurator (`FromMetaboxMessagePayloads`). Register via `api.addEventListener(name, handler)`.
|
|
1023
631
|
|
|
1024
632
|
### Available Events
|
|
1025
633
|
|
|
1026
|
-
| Event
|
|
1027
|
-
|
|
|
1028
|
-
| `configuratorDataUpdated` |
|
|
1029
|
-
| `
|
|
1030
|
-
| `showcaseStatusChanged`
|
|
1031
|
-
| `
|
|
1032
|
-
| `
|
|
634
|
+
| Event | Payload | Description |
|
|
635
|
+
| ----------------------------- | --------------------------- | --------------------------------------------------------------------- | ------ | -------------------------- | ------ |
|
|
636
|
+
| `configuratorDataUpdated` | ModularConfiguratorEnvelope | Any configuration change (components, types, materials, environment). |
|
|
637
|
+
| `ecomConfiguratorDataUpdated` | EcomConfigurator | CTA label/callback updates (E‑Com enabled). |
|
|
638
|
+
| `showcaseStatusChanged` | ShowCaseStatus | Showcase playback status: `init | play | pause | stop`. |
|
|
639
|
+
| `dataChannelConnected` | boolean | Unreal data channel connectivity (true = connected). |
|
|
640
|
+
| `viewportReady` | boolean | Unreal viewport visibility / readiness. |
|
|
641
|
+
| `statusMessageChanged` | string \| null | Loading / progress status messages. |
|
|
642
|
+
| `screenshotReady` | string \| null | Base64 image from latest screenshot (null if failed). |
|
|
643
|
+
| `videoResolutionChanged` | { width: number | null; height: number | null } | Stream resolution changed. |
|
|
1033
644
|
|
|
1034
|
-
### Event
|
|
645
|
+
### Event Examples
|
|
1035
646
|
|
|
1036
647
|
```typescript
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
console.log('
|
|
1040
|
-
|
|
1041
|
-
// Access specific data
|
|
1042
|
-
console.log('Configurator:', data.configurator);
|
|
1043
|
-
console.log('Configuration tree:', data.configurationTree);
|
|
1044
|
-
console.log('Components by type:', data.componentsByComponentType);
|
|
1045
|
-
console.log('Environment ID:', data.environmentId);
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
// Handle screenshot events
|
|
1049
|
-
api.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
1050
|
-
// imageData is a base64 encoded image
|
|
1051
|
-
if (!imageData) return;
|
|
1052
|
-
const img = document.createElement('img');
|
|
1053
|
-
img.src = imageData;
|
|
1054
|
-
document.body.appendChild(img);
|
|
648
|
+
api.addEventListener('configuratorDataUpdated', (env) => {
|
|
649
|
+
console.log('Active environment:', env.environmentId);
|
|
650
|
+
console.log('Components per type:', env.componentsByComponentType);
|
|
1055
651
|
});
|
|
1056
652
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
console.log('Showcase status:', status);
|
|
1060
|
-
// Handle play/pause/stop states
|
|
653
|
+
api.addEventListener('screenshotReady', (img) => {
|
|
654
|
+
if (img) saveImage(img, 'modular-configurator.png');
|
|
1061
655
|
});
|
|
1062
656
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
console.log('Viewport ready:', isReady);
|
|
657
|
+
api.addEventListener('dataChannelConnected', (connected) => {
|
|
658
|
+
console.log('Unreal channel connected?', connected);
|
|
1066
659
|
});
|
|
1067
660
|
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
console.log('Status message:', message);
|
|
661
|
+
api.addEventListener('videoResolutionChanged', (res) => {
|
|
662
|
+
console.log('Viewport resolution:', res.width, 'x', res.height);
|
|
1071
663
|
});
|
|
1072
664
|
```
|
|
1073
665
|
|
|
@@ -1081,14 +673,14 @@ api.addEventListener('statusMessageChanged', (message: string | null) => {
|
|
|
1081
673
|
|
|
1082
674
|
**Solutions**:
|
|
1083
675
|
|
|
1084
|
-
1. Verify the configurator
|
|
676
|
+
1. Verify the configurator ID is correct and accessible
|
|
1085
677
|
2. Check that the container element exists in the DOM
|
|
1086
678
|
3. Ensure the container has proper dimensions (width/height)
|
|
1087
679
|
4. Check the browser console for CORS or network errors
|
|
1088
680
|
|
|
1089
681
|
```typescript
|
|
1090
|
-
// Ensure the element exists and
|
|
1091
|
-
integrateMetabox(
|
|
682
|
+
// Ensure the element exists and ID is correct before calling
|
|
683
|
+
integrateMetabox(configuratorId, 'embed3DSource', (api) => {
|
|
1092
684
|
console.log('API ready!');
|
|
1093
685
|
});
|
|
1094
686
|
```
|
|
@@ -1105,9 +697,9 @@ integrateMetabox(configuratorUrl, 'embed3DSource', (api) => {
|
|
|
1105
697
|
|
|
1106
698
|
```typescript
|
|
1107
699
|
// Wait for API to be ready
|
|
1108
|
-
integrateMetabox(
|
|
700
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1109
701
|
// Only send commands after this callback
|
|
1110
|
-
api.
|
|
702
|
+
api.sendCommandToMetabox(new SetEnvironment('env-001'));
|
|
1111
703
|
});
|
|
1112
704
|
```
|
|
1113
705
|
|
|
@@ -1146,7 +738,7 @@ let timeoutId: NodeJS.Timeout;
|
|
|
1146
738
|
const debouncedMaterialChange = (slotId: string, materialId: string) => {
|
|
1147
739
|
clearTimeout(timeoutId);
|
|
1148
740
|
timeoutId = setTimeout(() => {
|
|
1149
|
-
api.
|
|
741
|
+
api.sendCommandToMetabox(new SetComponentMaterial(slotId, materialId));
|
|
1150
742
|
}, 300);
|
|
1151
743
|
};
|
|
1152
744
|
```
|
|
@@ -1157,17 +749,6 @@ const debouncedMaterialChange = (slotId: string, materialId: string) => {
|
|
|
1157
749
|
- **ES6 modules**: Required for CDN usage
|
|
1158
750
|
- **HTTPS**: Required for production deployments
|
|
1159
751
|
|
|
1160
|
-
## Contributing
|
|
1161
|
-
|
|
1162
|
-
We welcome contributions to improve the Metabox Modular Configurator API!
|
|
1163
|
-
|
|
1164
|
-
### Development Setup
|
|
1165
|
-
|
|
1166
|
-
1. Clone the repository
|
|
1167
|
-
2. Install dependencies: `npm install`
|
|
1168
|
-
3. Build the library: `npm run build`
|
|
1169
|
-
4. Run tests: `npm test`
|
|
1170
|
-
|
|
1171
752
|
---
|
|
1172
753
|
|
|
1173
754
|
For more examples and advanced usage, visit
|
|
@@ -1188,7 +769,7 @@ Key points:
|
|
|
1188
769
|
|
|
1189
770
|
How to enable
|
|
1190
771
|
|
|
1191
|
-
Pass
|
|
772
|
+
Pass as param to config with a standalone set to true when calling integrateMetabox.
|
|
1192
773
|
|
|
1193
774
|
TypeScript example:
|
|
1194
775
|
|
|
@@ -1196,12 +777,12 @@ TypeScript example:
|
|
|
1196
777
|
import { integrateMetabox, Communicator, SetComponent, SetEnvironment } from '@3dsource/metabox-modular-configurator-api';
|
|
1197
778
|
|
|
1198
779
|
integrateMetabox(
|
|
1199
|
-
'
|
|
780
|
+
'configurator-id',
|
|
1200
781
|
'embed3DSource',
|
|
1201
782
|
(api: Communicator) => {
|
|
1202
783
|
// Send your initial commands to establish state
|
|
1203
|
-
api.
|
|
1204
|
-
api.
|
|
784
|
+
api.sendCommandToMetabox(new SetComponent('your-component-id', 'your-type-id', true));
|
|
785
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
1205
786
|
},
|
|
1206
787
|
{ standalone: true },
|
|
1207
788
|
);
|
|
@@ -1214,11 +795,11 @@ JavaScript (CDN) example:
|
|
|
1214
795
|
import { integrateMetabox, SetComponent, SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api@2.0.1/+esm';
|
|
1215
796
|
|
|
1216
797
|
integrateMetabox(
|
|
1217
|
-
'
|
|
798
|
+
'configurator-id',
|
|
1218
799
|
'embed3DSource',
|
|
1219
800
|
(api) => {
|
|
1220
|
-
api.
|
|
1221
|
-
api.
|
|
801
|
+
api.sendCommandToMetabox(new SetComponent('your-component-id', 'your-type-id', true));
|
|
802
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
1222
803
|
},
|
|
1223
804
|
{ standalone: true },
|
|
1224
805
|
);
|
|
@@ -1229,4 +810,4 @@ Notes and tips
|
|
|
1229
810
|
|
|
1230
811
|
- In standalone mode, nothing will change until you send initial commands (e.g., set component/environment). If you see a blank/default view, ensure you dispatch the necessary SetComponent/SetEnvironment commands once api is ready.
|
|
1231
812
|
- All events (like configuratorDataUpdated, screenshotReady) still work; use them to keep your UI synchronized.
|
|
1232
|
-
- The config.hostUrl and config.apiVersion
|
|
813
|
+
- The library sets the config.hostUrl and config.apiVersion automatically; you typically don’t need to pass them.
|