@3dsource/metabox-front-api 2.0.2 → 2.0.4-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 +257 -512
- package/fesm2022/3dsource-metabox-front-api.mjs +85 -52
- package/fesm2022/3dsource-metabox-front-api.mjs.map +1 -1
- package/index.d.ts +70 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,20 +9,37 @@ their material slots, and materials, environments.
|
|
|
9
9
|
- [Features](#features)
|
|
10
10
|
- [Prerequisites](#prerequisites)
|
|
11
11
|
- [Installation](#installation)
|
|
12
|
+
- [Method 1: NPM Package (Recommended)](#method-1-npm-package-recommended)
|
|
13
|
+
- [Method 2: CDN Import](#method-2-cdn-import)
|
|
12
14
|
- [Quick Start](#quick-start)
|
|
15
|
+
- [1. HTML Setup](#1-html-setup)
|
|
16
|
+
- [2. Basic Integration](#2-basic-integration)
|
|
17
|
+
- [JavaScript Example](#javascript-example)
|
|
18
|
+
- [TypeScript Example](#typescript-example)
|
|
13
19
|
- [API Reference](#api-reference)
|
|
14
|
-
- [Steps to build custom menu](#steps-to-build-custom-menu)
|
|
15
20
|
- [System Terminology](#system-terminology)
|
|
21
|
+
- [Steps to build a custom menu](#steps-to-build-a-custom-menu)
|
|
16
22
|
- [Core Functions](#core-functions)
|
|
23
|
+
- [`integrateMetabox`](#integratemetabox)
|
|
17
24
|
- [Command Classes](#command-classes)
|
|
25
|
+
- [Command Payload Types (Internal)](#command-payload-types-internal)
|
|
26
|
+
- [Product & Environment](#product--environment)
|
|
27
|
+
- [UI & Overlay](#ui--overlay)
|
|
28
|
+
- [Camera & View](#camera--view)
|
|
29
|
+
- [Showcase Control](#showcase-control)
|
|
30
|
+
- [Media & Export](#media--export)
|
|
31
|
+
- [Advanced / Experimental](#advanced--experimental)
|
|
18
32
|
- [Event Handling](#event-handling)
|
|
33
|
+
- [Available Events](#available-events)
|
|
34
|
+
- [Example: Basic State Listener](#example-basic-state-listener)
|
|
19
35
|
- [Utility Functions](#utility-functions)
|
|
20
36
|
- [Standalone Mode](#standalone-mode)
|
|
21
37
|
- [Examples](#examples)
|
|
22
38
|
- [Best Practices](#best-practices)
|
|
23
39
|
- [Troubleshooting](#troubleshooting)
|
|
40
|
+
- [Common Issues](#common-issues)
|
|
24
41
|
- [Browser Compatibility](#browser-compatibility)
|
|
25
|
-
- [
|
|
42
|
+
- [Requirements](#requirements)
|
|
26
43
|
|
|
27
44
|
## Features
|
|
28
45
|
|
|
@@ -40,7 +57,7 @@ their material slots, and materials, environments.
|
|
|
40
57
|
- HTTPS connection (required for unreal engine)
|
|
41
58
|
- Valid Metabox basic configurator URL
|
|
42
59
|
|
|
43
|
-
Important:
|
|
60
|
+
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/basic/{configuratorId}` with optional query parameters (introImage, introVideo, loadingImage). HTTPS is enforced and non-HTTPS URLs are rejected.
|
|
44
61
|
|
|
45
62
|
## Installation
|
|
46
63
|
|
|
@@ -49,25 +66,27 @@ Important: integrateMetaBox validates inputs at runtime. It requires a non-empty
|
|
|
49
66
|
For use with frameworks like Angular, React, Vue, etc.:
|
|
50
67
|
|
|
51
68
|
```bash
|
|
52
|
-
npm install @3dsource/metabox-front-api
|
|
69
|
+
npm install @3dsource/metabox-front-api@latest --save
|
|
70
|
+
# or pin a specific version
|
|
71
|
+
# npm install @3dsource/metabox-front-api@latest --save
|
|
53
72
|
```
|
|
54
73
|
|
|
55
74
|
Then import the required components:
|
|
56
75
|
|
|
57
76
|
```typescript
|
|
58
|
-
import {
|
|
77
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from '@3dsource/metabox-front-api';
|
|
59
78
|
```
|
|
60
79
|
|
|
61
80
|
### Method 2: CDN Import
|
|
62
81
|
|
|
63
82
|
Alternative CDN options:
|
|
64
83
|
|
|
65
|
-
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api
|
|
84
|
+
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm`
|
|
66
85
|
|
|
67
86
|
For quick prototyping or vanilla JavaScript projects:
|
|
68
87
|
|
|
69
88
|
```javascript
|
|
70
|
-
import {
|
|
89
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api';
|
|
71
90
|
```
|
|
72
91
|
|
|
73
92
|
## Quick Start
|
|
@@ -106,67 +125,28 @@ Create a container element where the Metabox Configurator will be embedded:
|
|
|
106
125
|
|
|
107
126
|
```html
|
|
108
127
|
<script type="module">
|
|
109
|
-
import {
|
|
128
|
+
import { integrateMetabox, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
110
129
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// Listen for configurator data updates
|
|
126
|
-
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
127
|
-
console.log('Configurator data updated:', data);
|
|
128
|
-
this.handleConfiguratorUpdate(data);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// Listen for screenshot/render completion
|
|
132
|
-
api.addEventListener('screenshotReady', (imageData) => {
|
|
133
|
-
console.log('Screenshot ready');
|
|
134
|
-
saveImage(imageData, 'configurator-screenshot.png');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Set up the initial configuration
|
|
138
|
-
this.configureInitialState(api);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
handleConfiguratorUpdate(data) {
|
|
142
|
-
// Handle configurator state changes
|
|
143
|
-
// You can update your UI, save state, etc.
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
configureInitialState(api) {
|
|
147
|
-
// Set the initial product
|
|
148
|
-
api.sendCommandToMetaBox(new SetProduct('your-product-id'));
|
|
149
|
-
|
|
150
|
-
// Set initial environment
|
|
151
|
-
api.sendCommandToMetaBox(new SetEnvironment('your-environment-id'));
|
|
152
|
-
|
|
153
|
-
// Apply material to a specific slot
|
|
154
|
-
api.sendCommandToMetaBox(new SetMaterial('slot-id', 'material-id'));
|
|
155
|
-
|
|
156
|
-
// Take a screenshot
|
|
157
|
-
api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Initialize the integrator
|
|
162
|
-
new MetaboxIntegrator();
|
|
130
|
+
const configuratorId = 'configurator-id'; // your actual configurator id
|
|
131
|
+
// Ensure a container with id embed3DSource exists (see HTML Setup)
|
|
132
|
+
integrateMetabox(configuratorId, 'embed3DSource', (api) => {
|
|
133
|
+
api.addEventListener('configuratorDataUpdated', (env) => {
|
|
134
|
+
console.log('State updated:', env.productId, env.environmentId);
|
|
135
|
+
});
|
|
136
|
+
api.addEventListener('screenshotReady', (image) => {
|
|
137
|
+
if (image) saveImage(image, `configurator-${Date.now()}.png`);
|
|
138
|
+
});
|
|
139
|
+
// Initial commands
|
|
140
|
+
api.sendCommandToMetabox(new SetProduct('product-1'));
|
|
141
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1280, y: 720 }));
|
|
142
|
+
});
|
|
163
143
|
</script>
|
|
164
144
|
```
|
|
165
145
|
|
|
166
146
|
#### TypeScript Example
|
|
167
147
|
|
|
168
148
|
```typescript
|
|
169
|
-
import {
|
|
149
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, ShowEmbeddedMenu, ShowOverlayInterface, saveImage } from '@3dsource/metabox-front-api';
|
|
170
150
|
|
|
171
151
|
class MetaboxIntegrator {
|
|
172
152
|
private api: Communicator | null = null;
|
|
@@ -177,11 +157,11 @@ class MetaboxIntegrator {
|
|
|
177
157
|
|
|
178
158
|
private async initialize(): Promise<void> {
|
|
179
159
|
try {
|
|
180
|
-
// Replace '
|
|
181
|
-
const
|
|
160
|
+
// Replace 'configurator-id' with your actual configurator ID
|
|
161
|
+
const configuratorId = 'configurator-id';
|
|
182
162
|
|
|
183
163
|
// Initialize the configurator with type safety
|
|
184
|
-
|
|
164
|
+
integrateMetabox(configuratorId, 'embed3DSource', (api: Communicator) => {
|
|
185
165
|
this.onApiReady(api);
|
|
186
166
|
});
|
|
187
167
|
} catch (error) {
|
|
@@ -230,40 +210,40 @@ class MetaboxIntegrator {
|
|
|
230
210
|
if (!this.api) return;
|
|
231
211
|
|
|
232
212
|
// Set initial product
|
|
233
|
-
this.api.
|
|
213
|
+
this.api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
234
214
|
|
|
235
215
|
// Set initial environment
|
|
236
|
-
this.api.
|
|
216
|
+
this.api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
237
217
|
|
|
238
218
|
// Apply material to a specific slot
|
|
239
|
-
this.api.
|
|
219
|
+
this.api.sendCommandToMetabox(new SetProductMaterial('slot-id', 'material-id'));
|
|
240
220
|
|
|
241
221
|
// Configure UI visibility
|
|
242
|
-
this.api.
|
|
243
|
-
this.api.
|
|
222
|
+
this.api.sendCommandToMetabox(new ShowEmbeddedMenu(false));
|
|
223
|
+
this.api.sendCommandToMetabox(new ShowOverlayInterface(false));
|
|
244
224
|
|
|
245
225
|
// Generate initial screenshot
|
|
246
|
-
this.api.
|
|
226
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
247
227
|
}
|
|
248
228
|
|
|
249
229
|
// Public method to change product
|
|
250
230
|
public changeProduct(productId: string): void {
|
|
251
231
|
if (this.api) {
|
|
252
|
-
this.api.
|
|
232
|
+
this.api.sendCommandToMetabox(new SetProduct(productId));
|
|
253
233
|
}
|
|
254
234
|
}
|
|
255
235
|
|
|
256
236
|
// Public method to apply material
|
|
257
237
|
public applyMaterial(slotId: string, materialId: string): void {
|
|
258
238
|
if (this.api) {
|
|
259
|
-
this.api.
|
|
239
|
+
this.api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
260
240
|
}
|
|
261
241
|
}
|
|
262
242
|
|
|
263
243
|
// Public method to take screenshot
|
|
264
244
|
public takeScreenshot(width: number = 1024, height: number = 1024): void {
|
|
265
245
|
if (this.api) {
|
|
266
|
-
this.api.
|
|
246
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: width, y: height }));
|
|
267
247
|
}
|
|
268
248
|
}
|
|
269
249
|
}
|
|
@@ -304,14 +284,14 @@ const metaboxIntegrator = new MetaboxIntegrator();
|
|
|
304
284
|
- Your backend decides how to use the configuration JSON (e.g., generate a PDF or build a product list).
|
|
305
285
|
- 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.).
|
|
306
286
|
|
|
307
|
-
### Steps to build custom menu
|
|
287
|
+
### Steps to build a custom menu
|
|
308
288
|
|
|
309
|
-
- **configuratorDataUpdated** - add event listener to receive
|
|
310
|
-
- **showEmbeddedMenu** - hide embedded metabox right sidebar
|
|
289
|
+
- **configuratorDataUpdated** - add event listener to receive configurator data and updates
|
|
290
|
+
- **showEmbeddedMenu** - hide embedded metabox right sidebar; show again with the command
|
|
311
291
|
- **showOverlayInterface** - hide viewport metabox actions if you want to add yours
|
|
312
292
|
- **setEnvironment** - set active environment when you want to change environment
|
|
313
293
|
- **setEnvironmentMaterialById** - set environment material by slot ID
|
|
314
|
-
- **setProduct** - set active product when you want to change product
|
|
294
|
+
- **setProduct** - set active product when you want to change the product
|
|
315
295
|
- **setProductMaterialById** - set product material by slot ID
|
|
316
296
|
- **getScreenshot** - get screenshot
|
|
317
297
|
- **getCallToActionInformation** - send call to action information to api endpoint provided in CTA configuration
|
|
@@ -319,276 +299,164 @@ const metaboxIntegrator = new MetaboxIntegrator();
|
|
|
319
299
|
|
|
320
300
|
### Core Functions
|
|
321
301
|
|
|
322
|
-
#### `
|
|
302
|
+
#### `integrateMetabox`
|
|
323
303
|
|
|
324
304
|
Integrates the Metabox configurator into the specified container element.
|
|
325
305
|
|
|
326
306
|
**TypeScript Signature:**
|
|
327
307
|
|
|
328
308
|
```typescript
|
|
329
|
-
function
|
|
330
|
-
|
|
331
|
-
containerId
|
|
332
|
-
apiReadyCallback: (api: Communicator) => void,
|
|
333
|
-
config?:
|
|
309
|
+
function integrateMetabox(
|
|
310
|
+
configuratorId: string,
|
|
311
|
+
containerId?: string, // defaults to 'embed3DSource'
|
|
312
|
+
apiReadyCallback: (api: Communicator) => void, // required
|
|
313
|
+
config?: IntegrateMetaboxConfig,
|
|
334
314
|
): void;
|
|
335
315
|
```
|
|
336
316
|
|
|
337
317
|
**Parameters:**
|
|
338
318
|
|
|
339
|
-
- `
|
|
340
|
-
- `containerId` (string):
|
|
341
|
-
- `apiReadyCallback` (
|
|
342
|
-
- `config` (
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
integrateMetaBox('https://metabox.3dsource.com/metabox-configurator/basic/your-id', 'embed3DSource', (api) => {
|
|
348
|
-
console.log('API ready!', api);
|
|
349
|
-
});
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### Command Classes
|
|
353
|
-
|
|
354
|
-
All commands are sent to the configurator using the `api.sendCommandToMetaBox()` method.
|
|
355
|
-
|
|
356
|
-
#### Command Payload Types
|
|
357
|
-
|
|
358
|
-
All commands use strongly typed payloads defined in `ToMetaboxMessagePayloads`:
|
|
359
|
-
|
|
360
|
-
```typescript
|
|
361
|
-
interface ToMetaboxMessagePayloads {
|
|
362
|
-
[MetaboxBasicConfiguratorActions.getPdf]: void;
|
|
363
|
-
[MetaboxBasicConfiguratorActions.getCallToActionInformation]: void;
|
|
364
|
-
[MetaboxBasicConfiguratorActions.loadLevel]: { id: string };
|
|
365
|
-
[MetaboxBasicConfiguratorActions.setProduct]: { productId: string };
|
|
366
|
-
[MetaboxBasicConfiguratorActions.getScreenshot]: {
|
|
367
|
-
format: MimeType;
|
|
368
|
-
size?: { x: number; y: number };
|
|
369
|
-
};
|
|
370
|
-
[MetaboxBasicConfiguratorActions.setMaterialById]: {
|
|
371
|
-
slotId: string;
|
|
372
|
-
materialId: string;
|
|
373
|
-
};
|
|
374
|
-
[MetaboxBasicConfiguratorActions.setEnvironmentMaterialById]: {
|
|
375
|
-
slotId: string;
|
|
376
|
-
materialId: string;
|
|
377
|
-
};
|
|
378
|
-
[MetaboxBasicConfiguratorActions.showEmbeddedMenu]: { visible: boolean };
|
|
379
|
-
[MetaboxBasicConfiguratorActions.showOverlayInterface]: { visible: boolean };
|
|
380
|
-
[MetaboxBasicConfiguratorActions.forceSetDeviceType]: {
|
|
381
|
-
deviceType: ApplicationDeviceTypes;
|
|
382
|
-
};
|
|
383
|
-
[MetaboxBasicConfiguratorActions.resetCamera]: void;
|
|
384
|
-
[MetaboxBasicConfiguratorActions.applyZoom]: { zoom: number };
|
|
385
|
-
[MetaboxBasicConfiguratorActions.initShowcase]: void;
|
|
386
|
-
[MetaboxBasicConfiguratorActions.playShowcase]: void;
|
|
387
|
-
[MetaboxBasicConfiguratorActions.pauseShowcase]: void;
|
|
388
|
-
[MetaboxBasicConfiguratorActions.stopShowcase]: void;
|
|
389
|
-
[MetaboxBasicConfiguratorActions.sendCommandToUnreal]: object;
|
|
390
|
-
}
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
#### Product Configuration
|
|
394
|
-
|
|
395
|
-
##### `SetProduct`
|
|
396
|
-
|
|
397
|
-
Sets the active product by ID.
|
|
398
|
-
|
|
399
|
-
```typescript
|
|
400
|
-
api.sendCommandToMetaBox(new SetProduct(productId));
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
##### `SetMaterial`
|
|
404
|
-
|
|
405
|
-
Applies a material to a specific product slot.
|
|
406
|
-
|
|
407
|
-
```typescript
|
|
408
|
-
api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
#### Environment Configuration
|
|
412
|
-
|
|
413
|
-
##### `SetEnvironment`
|
|
319
|
+
- `configuratorId` (string, required): Basic Configurator ID (not a full URL). Internal iframe src: `https://{domain}/metabox-configurator/basic/{configuratorId}`.
|
|
320
|
+
- `containerId` (string, optional): Host element id. Defaults to `embed3DSource`.
|
|
321
|
+
- `apiReadyCallback` (required): Invoked once Metabox signals readiness.
|
|
322
|
+
- `config` (optional):
|
|
323
|
+
- `standalone?`: Disable built‑in UI/template logic inside iframe.
|
|
324
|
+
- `introImage?`, `introVideo?`, `loadingImage?`: Optional URLs appended as query params.
|
|
325
|
+
- `domain?`: Override domain (HTTPS enforced).
|
|
414
326
|
|
|
415
|
-
|
|
327
|
+
**Throws:** Error if `configuratorId` or `containerId` empty, container element missing, or generated URL not HTTPS.
|
|
416
328
|
|
|
417
|
-
|
|
418
|
-
api.sendCommandToMetaBox(new SetEnvironment(environmentId));
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
##### `SetEnvironmentMaterial`
|
|
422
|
-
|
|
423
|
-
Applies a material to a specific environment slot.
|
|
424
|
-
|
|
425
|
-
```typescript
|
|
426
|
-
api.sendCommandToMetaBox(new SetEnvironmentMaterial(slotId, materialId));
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
#### Camera Controls
|
|
430
|
-
|
|
431
|
-
##### `ResetCamera`
|
|
432
|
-
|
|
433
|
-
Resets the camera to its default position and rotation.
|
|
434
|
-
|
|
435
|
-
```typescript
|
|
436
|
-
api.sendCommandToMetaBox(new ResetCamera());
|
|
437
|
-
```
|
|
438
|
-
|
|
439
|
-
##### `ApplyZoom`
|
|
440
|
-
|
|
441
|
-
Applies zoom to the camera view.
|
|
442
|
-
|
|
443
|
-
```typescript
|
|
444
|
-
api.sendCommandToMetaBox(new ApplyZoom(zoom));
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
#### Interface Controls
|
|
448
|
-
|
|
449
|
-
##### `ShowEmbeddedMenu(visible)`
|
|
450
|
-
|
|
451
|
-
Controls the visibility of the embedded configurator menu (right sidebar).
|
|
452
|
-
|
|
453
|
-
Parameters:
|
|
454
|
-
|
|
455
|
-
- `visible` (boolean): `true` to show the built-in menu; `false` to hide it.
|
|
456
|
-
|
|
457
|
-
Examples:
|
|
458
|
-
|
|
459
|
-
```typescript
|
|
460
|
-
api.sendCommandToMetaBox(new ShowEmbeddedMenu(true)); // Show menu
|
|
461
|
-
api.sendCommandToMetaBox(new ShowEmbeddedMenu(false)); // Hide menu
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
##### `ShowOverlayInterface(visible)`
|
|
465
|
-
|
|
466
|
-
Controls the visibility of the overlay interface over the Unreal viewport (e.g., on‑viewport buttons, tooltips, hotspots).
|
|
467
|
-
|
|
468
|
-
Parameters:
|
|
469
|
-
|
|
470
|
-
- `visible` (boolean): `true` to show the overlay; `false` to hide it.
|
|
471
|
-
|
|
472
|
-
Examples:
|
|
473
|
-
|
|
474
|
-
```typescript
|
|
475
|
-
api.sendCommandToMetaBox(new ShowOverlayInterface(true)); // Show overlay
|
|
476
|
-
api.sendCommandToMetaBox(new ShowOverlayInterface(false)); // Hide overlay
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
#### Media Generation
|
|
329
|
+
Notes:
|
|
480
330
|
|
|
481
|
-
|
|
331
|
+
- HTTPS is enforced: attempts to use non-HTTPS iframe URLs are rejected.
|
|
332
|
+
- If a previous iframe with id `embeddedContent` exists, it will be removed before inserting a new one.
|
|
482
333
|
|
|
483
|
-
|
|
334
|
+
**Example:**
|
|
484
335
|
|
|
485
336
|
```typescript
|
|
486
|
-
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
**Parameters:**
|
|
490
|
-
|
|
491
|
-
- `mimeType`: Image format ('image/png', 'image/jpeg', etc.)
|
|
492
|
-
- `size`: Optional dimensions object with x and y properties
|
|
337
|
+
import { IntegrateMetaboxConfig } from '@3dsource/metabox-front-api';
|
|
493
338
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
339
|
+
const config: IntegrateMetaboxConfig = {
|
|
340
|
+
introImage: 'https://example.com/intro.png',
|
|
341
|
+
loadingImage: 'https://example.com/loading.png',
|
|
342
|
+
standalone: false,
|
|
343
|
+
};
|
|
497
344
|
|
|
498
|
-
|
|
499
|
-
|
|
345
|
+
integrateMetabox(
|
|
346
|
+
'configurator-id',
|
|
347
|
+
'embed3DSource',
|
|
348
|
+
(api) => {
|
|
349
|
+
console.log('API ready!', api);
|
|
350
|
+
},
|
|
351
|
+
config,
|
|
352
|
+
);
|
|
500
353
|
```
|
|
501
354
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
Triggers the CTA flow for E‑Com Configurators. This command sends the current configuration to the CTA callback URL configured in Metabox and, upon a successful response from your backend, opens the returned redirectUrl in a new browser tab.
|
|
355
|
+
### Command Classes
|
|
505
356
|
|
|
506
|
-
|
|
357
|
+
All commands are sent using `api.sendCommandToMetabox(new SomeCommand(...))`.
|
|
507
358
|
|
|
508
|
-
|
|
509
|
-
- No parameters are required.
|
|
510
|
-
- Your backend must respond with a JSON object containing a redirectUrl field.
|
|
359
|
+
#### Command Payload Types (Internal)
|
|
511
360
|
|
|
512
361
|
```typescript
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
362
|
+
interface ToMetaboxMessagePayloads {
|
|
363
|
+
metaboxConfig: { appId: string; config: MetaboxCommandConfig };
|
|
364
|
+
setProduct: { productId: string };
|
|
365
|
+
setEnvironment: { id: string };
|
|
366
|
+
getPdf: void;
|
|
367
|
+
getCallToActionInformation: void;
|
|
368
|
+
watchCallbacks: void; // enables experimental unrealCallback events
|
|
369
|
+
getScreenshot: { format: MimeType; size?: { x: number; y: number } };
|
|
370
|
+
setProductMaterialById: { slotId: string; materialId: string };
|
|
371
|
+
setEnvironmentMaterialById: { slotId: string; materialId: string };
|
|
372
|
+
showEmbeddedMenu: { visible: boolean };
|
|
373
|
+
showOverlayInterface: { visible: boolean };
|
|
374
|
+
forceSetDeviceType: { deviceType: ApplicationDeviceTypes };
|
|
375
|
+
resetCamera: void;
|
|
376
|
+
applyZoom: { zoom: number };
|
|
377
|
+
initShowcase: void;
|
|
378
|
+
playShowcase: void;
|
|
379
|
+
pauseShowcase: void;
|
|
380
|
+
stopShowcase: void;
|
|
381
|
+
sendCommandToUnreal: object; // arbitrary Unreal command payload
|
|
521
382
|
}
|
|
522
383
|
```
|
|
523
384
|
|
|
524
|
-
####
|
|
385
|
+
#### Product & Environment
|
|
525
386
|
|
|
526
|
-
|
|
387
|
+
- `SetProduct(productId: string)` – Select active product.
|
|
388
|
+
- `SetProductMaterial(slotId: string, materialId: string)` – Apply material to product slot.
|
|
389
|
+
- `SetEnvironment(id: string)` – Activate environment.
|
|
390
|
+
- `SetEnvironmentMaterial(slotId: string, materialId: string)` – Apply material to environment slot.
|
|
527
391
|
|
|
528
|
-
|
|
392
|
+
#### UI & Overlay
|
|
529
393
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
```
|
|
394
|
+
- `ShowEmbeddedMenu(visible: boolean)` – Toggle right sidebar menu.
|
|
395
|
+
- `ShowOverlayInterface(visible: boolean)` – Toggle viewport overlay UI.
|
|
533
396
|
|
|
534
|
-
|
|
397
|
+
#### Camera & View
|
|
535
398
|
|
|
536
|
-
|
|
399
|
+
- `ResetCamera()` – Reset camera to initial state.
|
|
400
|
+
- `ApplyZoom(zoom: number)` – Apply a zoom factor within allowed range.
|
|
537
401
|
|
|
538
|
-
|
|
539
|
-
api.sendCommandToMetaBox(new PlayShowcase());
|
|
540
|
-
```
|
|
402
|
+
#### Showcase Control
|
|
541
403
|
|
|
542
|
-
|
|
404
|
+
- `InitShowcase()` – Initialize a product showcase sequence.
|
|
405
|
+
- `PlayShowcase()` / `PauseShowcase()` / `StopShowcase()` – Control showcase playback.
|
|
543
406
|
|
|
544
|
-
|
|
407
|
+
#### Media & Export
|
|
545
408
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
409
|
+
- `GetScreenshot(format: MimeType, size?)` – Request a screenshot (listen to `screenshotReady`).
|
|
410
|
+
- `GetPdf()` – Request PDF generation (no dedicated event, handled internally server‑side; poll status messages if needed).
|
|
411
|
+
- `GetCallToActionInformation()` – Trigger CTA flow (backend must return `{ redirectUrl }`).
|
|
549
412
|
|
|
550
|
-
|
|
413
|
+
#### Advanced / Experimental
|
|
551
414
|
|
|
552
|
-
|
|
415
|
+
- `UnrealCommand(command: object)` – Send low‑level command to Unreal. Use cautiously.
|
|
416
|
+
- `WatchCallbacks()` – Enable reception of `unrealCallback` events. Experimental / not guaranteed.
|
|
417
|
+
- `MetaboxConfig(appId: string, partialConfig)` – Internal initialization command (auto‑sent on communicator creation).
|
|
418
|
+
|
|
419
|
+
Example:
|
|
553
420
|
|
|
554
421
|
```typescript
|
|
555
|
-
api
|
|
422
|
+
import { UnrealCommand } from '@3dsource/metabox-front-api';
|
|
423
|
+
api.sendCommandToMetabox(new UnrealCommand({ type: 'SetLightIntensity', value: 2.5 }));
|
|
556
424
|
```
|
|
557
425
|
|
|
558
426
|
### Event Handling
|
|
559
427
|
|
|
560
|
-
The API uses an event-driven architecture.
|
|
428
|
+
The API uses an event-driven architecture. Register listeners via `api.addEventListener(eventName, handler)`.
|
|
561
429
|
|
|
562
430
|
#### Available Events
|
|
563
431
|
|
|
564
|
-
| Event
|
|
565
|
-
|
|
|
566
|
-
| `configuratorDataUpdated`
|
|
567
|
-
| `
|
|
568
|
-
| `
|
|
569
|
-
| `viewportReady`
|
|
570
|
-
| `
|
|
571
|
-
|
|
572
|
-
|
|
432
|
+
| Event | Payload Type | Description |
|
|
433
|
+
| ----------------------------- | -------------------- | ---------------------------------------------------------- | ------ | -------------------------- |
|
|
434
|
+
| `configuratorDataUpdated` | ConfiguratorEnvelope | Product/environment/material selections changed. |
|
|
435
|
+
| `ecomConfiguratorDataUpdated` | EcomConfigurator | CTA config (label, callbackUrl) updated. |
|
|
436
|
+
| `dataChannelConnected` | boolean | Unreal data channel connectivity state. |
|
|
437
|
+
| `viewportReady` | boolean | Unreal viewport visibility and readiness. |
|
|
438
|
+
| `showcaseStatusChanged` | ShowCaseStatus | Showcase playback status: init/play/pause/stop. |
|
|
439
|
+
| `statusMessageChanged` | string \| null | Human‑readable loading/progress message. |
|
|
440
|
+
| `screenshotReady` | string \| null | Base64 image data from latest screenshot (null if failed). |
|
|
441
|
+
| `videoResolutionChanged` | { width: number | null; height: number | null } | Video stream size changes. |
|
|
442
|
+
| `unrealCallback` | { json: object } | Unreal callback (requires WatchCallbacks; experimental). |
|
|
573
443
|
|
|
574
|
-
|
|
444
|
+
#### Example: Basic State Listener
|
|
575
445
|
|
|
576
446
|
```typescript
|
|
577
|
-
api.addEventListener('configuratorDataUpdated', (data
|
|
578
|
-
console.log('
|
|
579
|
-
|
|
447
|
+
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
448
|
+
console.log('Product:', data.productId);
|
|
449
|
+
console.log('Product materials:', data.productMaterialsIds);
|
|
450
|
+
console.log('Environment:', data.environmentId);
|
|
451
|
+
console.log('Environment materials:', data.environmentMaterialsIds);
|
|
580
452
|
});
|
|
581
453
|
```
|
|
582
454
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
Fired when a screenshot or fast render is completed.
|
|
455
|
+
#### Screenshot
|
|
586
456
|
|
|
587
457
|
```typescript
|
|
588
|
-
api.addEventListener('screenshotReady', (
|
|
589
|
-
|
|
590
|
-
// imageData contains the base64 encoded image
|
|
591
|
-
saveImage(imageData, 'screenshot.png');
|
|
458
|
+
api.addEventListener('screenshotReady', (image) => {
|
|
459
|
+
if (!image) return;
|
|
592
460
|
});
|
|
593
461
|
```
|
|
594
462
|
|
|
@@ -637,18 +505,18 @@ Minimal example of triggering the Call‑To‑Action flow from your page once th
|
|
|
637
505
|
<button id="cta-btn" disabled>Send configuration (CTA)</button>
|
|
638
506
|
|
|
639
507
|
<script type="module">
|
|
640
|
-
import {
|
|
508
|
+
import { integrateMetabox, GetCallToActionInformation } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
641
509
|
|
|
642
510
|
let api = null;
|
|
643
511
|
|
|
644
|
-
|
|
512
|
+
integrateMetabox('configurator-id', 'metabox-container', (apiInstance) => {
|
|
645
513
|
api = apiInstance;
|
|
646
514
|
document.getElementById('cta-btn').disabled = false;
|
|
647
515
|
});
|
|
648
516
|
|
|
649
517
|
document.getElementById('cta-btn').addEventListener('click', () => {
|
|
650
518
|
// Triggers sending the current configuration to your CTA Callback URL
|
|
651
|
-
api.
|
|
519
|
+
api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
652
520
|
});
|
|
653
521
|
</script>
|
|
654
522
|
```
|
|
@@ -723,7 +591,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
723
591
|
</div>
|
|
724
592
|
|
|
725
593
|
<script type="module">
|
|
726
|
-
import {
|
|
594
|
+
import { integrateMetabox, SetProduct, SetProductMaterial, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
727
595
|
|
|
728
596
|
let api = null;
|
|
729
597
|
let isApiReady = false;
|
|
@@ -747,40 +615,41 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
747
615
|
|
|
748
616
|
// Initialize configurator with error handling
|
|
749
617
|
try {
|
|
750
|
-
// Replace '
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
618
|
+
// Replace 'configurator-id' with your actual configurator ID from 3DSource
|
|
619
|
+
const configuratorId = 'configurator-id';
|
|
620
|
+
|
|
621
|
+
integrate -
|
|
622
|
+
metabox.ts(configuratorId, 'metabox-container', (apiInstance) => {
|
|
623
|
+
try {
|
|
624
|
+
api = apiInstance;
|
|
625
|
+
isApiReady = true;
|
|
626
|
+
setLoadingState(false);
|
|
627
|
+
console.log('Configurator ready!');
|
|
628
|
+
|
|
629
|
+
// Listen for configurator state changes
|
|
630
|
+
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
631
|
+
console.log('Configurator state updated:', data);
|
|
632
|
+
// You can update your UI based on the current state
|
|
633
|
+
// For example, update available materials, products, etc.
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
// Listen for screenshot completion
|
|
637
|
+
api.addEventListener('screenshotReady', (imageData) => {
|
|
638
|
+
console.log('Screenshot captured successfully');
|
|
639
|
+
// Save the image with a timestamp
|
|
640
|
+
saveImage(imageData, `configurator-screenshot-${Date.now()}.png`);
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
// Listen for errors
|
|
644
|
+
api.addEventListener('error', (error) => {
|
|
645
|
+
console.error('Configurator error:', error);
|
|
646
|
+
showError('An error occurred in the configurator: ' + error.message);
|
|
647
|
+
});
|
|
648
|
+
} catch (error) {
|
|
649
|
+
console.error('Error setting up API:', error);
|
|
650
|
+
showError('Failed to initialize configurator API: ' + error.message);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
784
653
|
} catch (error) {
|
|
785
654
|
console.error('Error initializing configurator:', error);
|
|
786
655
|
showError('Failed to load configurator: ' + error.message);
|
|
@@ -795,7 +664,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
795
664
|
|
|
796
665
|
try {
|
|
797
666
|
console.log(`Changing to product: ${productId}`);
|
|
798
|
-
api.
|
|
667
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
799
668
|
} catch (error) {
|
|
800
669
|
console.error('Error changing product:', error);
|
|
801
670
|
showError('Failed to change product: ' + error.message);
|
|
@@ -810,7 +679,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
810
679
|
|
|
811
680
|
try {
|
|
812
681
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
813
|
-
api.
|
|
682
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
814
683
|
} catch (error) {
|
|
815
684
|
console.error('Error applying material:', error);
|
|
816
685
|
showError('Failed to apply material: ' + error.message);
|
|
@@ -826,7 +695,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
826
695
|
try {
|
|
827
696
|
console.log('Taking screenshot...');
|
|
828
697
|
// Request high-quality screenshot in PNG format
|
|
829
|
-
api.
|
|
698
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
830
699
|
} catch (error) {
|
|
831
700
|
console.error('Error taking screenshot:', error);
|
|
832
701
|
showError('Failed to take screenshot: ' + error.message);
|
|
@@ -837,32 +706,14 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
837
706
|
</html>
|
|
838
707
|
```
|
|
839
708
|
|
|
840
|
-
**Key Features of this Example:**
|
|
841
|
-
|
|
842
|
-
- **Error Handling**: Comprehensive error handling for all API operations
|
|
843
|
-
- **Loading States**: Visual feedback while the configurator loads
|
|
844
|
-
- **Button States**: Buttons are disabled until the API is ready
|
|
845
|
-
- **Console Logging**: Detailed logging for debugging
|
|
846
|
-
- **Responsive Design**: Clean, responsive button layout
|
|
847
|
-
- **Latest CDN**: Uses `@latest` for the most recent version
|
|
848
|
-
|
|
849
|
-
**To Use This Example:**
|
|
850
|
-
|
|
851
|
-
1. Replace `'your-configurator-id'` with your actual configurator ID
|
|
852
|
-
2. Replace placeholder product IDs (`'product-1'`, `'product-2'`) with real product IDs
|
|
853
|
-
3. Replace placeholder material IDs (`'material-red'`, `'material-blue'`) with real material IDs
|
|
854
|
-
4. Replace placeholder slot ID (`'slot-1'`) with the actual slot ID from your configurator
|
|
855
|
-
|
|
856
709
|
### React Integration Example
|
|
857
710
|
|
|
858
|
-
A complete React component with TypeScript showing proper integration, error handling, and cleanup.
|
|
859
|
-
|
|
860
711
|
```tsx
|
|
861
712
|
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
|
862
|
-
import {
|
|
713
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, GetScreenshot, saveImage } from '@3dsource/metabox-front-api';
|
|
863
714
|
|
|
864
715
|
interface MetaboxConfiguratorProps {
|
|
865
|
-
|
|
716
|
+
configuratorId: string;
|
|
866
717
|
onStateChange?: (data: ConfiguratorEnvelope) => void;
|
|
867
718
|
onError?: (error: string) => void;
|
|
868
719
|
className?: string;
|
|
@@ -874,7 +725,7 @@ interface ConfiguratorState {
|
|
|
874
725
|
isApiReady: boolean;
|
|
875
726
|
}
|
|
876
727
|
|
|
877
|
-
const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({
|
|
728
|
+
const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorId, onStateChange, onError, className }) => {
|
|
878
729
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
879
730
|
const [api, setApi] = useState<Communicator | null>(null);
|
|
880
731
|
const [state, setState] = useState<ConfiguratorState>({
|
|
@@ -909,7 +760,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
909
760
|
// Set the container ID
|
|
910
761
|
containerRef.current!.id = containerId.current;
|
|
911
762
|
|
|
912
|
-
|
|
763
|
+
integrateMetabox(configuratorId, containerId.current, (apiInstance) => {
|
|
913
764
|
if (!mounted) return; // Component was unmounted
|
|
914
765
|
|
|
915
766
|
try {
|
|
@@ -961,7 +812,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
961
812
|
console.log('Cleaning up Metabox Configurator');
|
|
962
813
|
}
|
|
963
814
|
};
|
|
964
|
-
}, [
|
|
815
|
+
}, [configuratorId, onStateChange, handleError, api]);
|
|
965
816
|
|
|
966
817
|
// Command methods with error handling
|
|
967
818
|
const changeProduct = useCallback(
|
|
@@ -973,7 +824,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
973
824
|
|
|
974
825
|
try {
|
|
975
826
|
console.log(`Changing to product: ${productId}`);
|
|
976
|
-
api.
|
|
827
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
977
828
|
} catch (error) {
|
|
978
829
|
handleError(`Failed to change product: ${error instanceof Error ? error.message : String(error)}`);
|
|
979
830
|
}
|
|
@@ -990,7 +841,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
990
841
|
|
|
991
842
|
try {
|
|
992
843
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
993
|
-
api.
|
|
844
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
994
845
|
} catch (error) {
|
|
995
846
|
handleError(`Failed to apply material: ${error instanceof Error ? error.message : String(error)}`);
|
|
996
847
|
}
|
|
@@ -1006,7 +857,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
1006
857
|
|
|
1007
858
|
try {
|
|
1008
859
|
console.log('Taking screenshot...');
|
|
1009
|
-
api.
|
|
860
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1010
861
|
} catch (error) {
|
|
1011
862
|
handleError(`Failed to take screenshot: ${error instanceof Error ? error.message : String(error)}`);
|
|
1012
863
|
}
|
|
@@ -1165,61 +1016,12 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
1165
1016
|
export default MetaboxConfigurator;
|
|
1166
1017
|
```
|
|
1167
1018
|
|
|
1168
|
-
**Key Features of this React Example:**
|
|
1169
|
-
|
|
1170
|
-
- **Proper TypeScript Integration**: Full type safety with proper interfaces
|
|
1171
|
-
- **Error Handling**: Comprehensive error states and user feedback
|
|
1172
|
-
- **Component Cleanup**: Proper unmounting and memory leak prevention
|
|
1173
|
-
- **Unique Container IDs**: Automatic ID generation to avoid conflicts
|
|
1174
|
-
- **Loading States**: Visual feedback during initialization
|
|
1175
|
-
- **Optimized Re-renders**: Uses useCallback to prevent unnecessary re-renders
|
|
1176
|
-
- **Responsive Design**: Flexible button layout with proper styling
|
|
1177
|
-
|
|
1178
|
-
**Usage Example:**
|
|
1179
|
-
|
|
1180
|
-
```tsx
|
|
1181
|
-
// App.tsx
|
|
1182
|
-
import React from 'react';
|
|
1183
|
-
import MetaboxConfigurator from './components/MetaboxConfigurator';
|
|
1184
|
-
import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
1185
|
-
|
|
1186
|
-
function App() {
|
|
1187
|
-
const handleStateChange = (data: ConfiguratorEnvelope) => {
|
|
1188
|
-
console.log('Configurator state changed:', data);
|
|
1189
|
-
// Update your application state based on configurator changes
|
|
1190
|
-
};
|
|
1191
|
-
|
|
1192
|
-
const handleError = (error: string) => {
|
|
1193
|
-
console.error('Configurator error:', error);
|
|
1194
|
-
// Handle errors (show notifications, log to analytics, etc.)
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
return (
|
|
1198
|
-
<div className="App">
|
|
1199
|
-
<h1>My Product Configurator</h1>
|
|
1200
|
-
<MetaboxConfigurator configuratorUrl="https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id" onStateChange={handleStateChange} onError={handleError} className="my-configurator" />
|
|
1201
|
-
</div>
|
|
1202
|
-
);
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
export default App;
|
|
1206
|
-
```
|
|
1207
|
-
|
|
1208
|
-
**To Use This Component:**
|
|
1209
|
-
|
|
1210
|
-
1. Install the package: `npm install @3dsource/metabox-front-api`
|
|
1211
|
-
2. Replace `'your-configurator-id'` with your actual configurator ID
|
|
1212
|
-
3. Replace placeholder IDs in the component with your real product, material, and slot IDs
|
|
1213
|
-
4. Customize the styling by passing a `className` prop or modifying the inline styles
|
|
1214
|
-
|
|
1215
1019
|
### Angular Integration Example
|
|
1216
1020
|
|
|
1217
|
-
A complete Angular component with TypeScript showing proper integration, error handling, and lifecycle management.
|
|
1218
|
-
|
|
1219
1021
|
```typescript
|
|
1220
1022
|
// metabox-configurator.component.ts
|
|
1221
1023
|
import { Component, input, OnInit, output, signal } from '@angular/core';
|
|
1222
|
-
import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase,
|
|
1024
|
+
import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase, integrateMetabox, PauseShowcase, PlayShowcase, saveImage, SetProductMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase } from '@3dsource/metabox-front-api';
|
|
1223
1025
|
|
|
1224
1026
|
interface ConfiguratorState {
|
|
1225
1027
|
isLoading: boolean;
|
|
@@ -1416,7 +1218,7 @@ interface ConfiguratorState {
|
|
|
1416
1218
|
],
|
|
1417
1219
|
})
|
|
1418
1220
|
export class MetaboxConfiguratorComponent implements OnInit {
|
|
1419
|
-
|
|
1221
|
+
configuratorId = input.required<string>();
|
|
1420
1222
|
stateChange = output<ConfiguratorEnvelope>();
|
|
1421
1223
|
errorFired = output<string>();
|
|
1422
1224
|
state = signal<ConfiguratorState>({
|
|
@@ -1440,7 +1242,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1440
1242
|
|
|
1441
1243
|
try {
|
|
1442
1244
|
console.log(`Changing to product: ${productId}`);
|
|
1443
|
-
this.api.
|
|
1245
|
+
this.api.sendCommandToMetabox(new SetProduct(productId));
|
|
1444
1246
|
} catch (error) {
|
|
1445
1247
|
this.handleError(`Failed to change product: ${this.getErrorMessage(error)}`);
|
|
1446
1248
|
}
|
|
@@ -1453,7 +1255,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1453
1255
|
}
|
|
1454
1256
|
|
|
1455
1257
|
try {
|
|
1456
|
-
this.api.
|
|
1258
|
+
this.api.sendCommandToMetabox(new InitShowcase());
|
|
1457
1259
|
} catch (error) {
|
|
1458
1260
|
this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
|
|
1459
1261
|
}
|
|
@@ -1467,7 +1269,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1467
1269
|
|
|
1468
1270
|
try {
|
|
1469
1271
|
console.log(`Stop showcase`);
|
|
1470
|
-
this.api.
|
|
1272
|
+
this.api.sendCommandToMetabox(new StopShowcase());
|
|
1471
1273
|
} catch (error) {
|
|
1472
1274
|
this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
|
|
1473
1275
|
}
|
|
@@ -1481,7 +1283,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1481
1283
|
|
|
1482
1284
|
try {
|
|
1483
1285
|
console.log(`Play showcase`);
|
|
1484
|
-
this.api.
|
|
1286
|
+
this.api.sendCommandToMetabox(new PlayShowcase());
|
|
1485
1287
|
} catch {
|
|
1486
1288
|
this.handleError(`Failed to play showcase`);
|
|
1487
1289
|
}
|
|
@@ -1495,7 +1297,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1495
1297
|
|
|
1496
1298
|
try {
|
|
1497
1299
|
console.log(`Pause showcase`);
|
|
1498
|
-
this.api.
|
|
1300
|
+
this.api.sendCommandToMetabox(new PauseShowcase());
|
|
1499
1301
|
} catch {
|
|
1500
1302
|
this.handleError(`Failed to pause showcase`);
|
|
1501
1303
|
}
|
|
@@ -1509,7 +1311,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1509
1311
|
|
|
1510
1312
|
try {
|
|
1511
1313
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
1512
|
-
this.api.
|
|
1314
|
+
this.api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
1513
1315
|
} catch (error) {
|
|
1514
1316
|
this.handleError(`Failed to apply material: ${this.getErrorMessage(error)}`);
|
|
1515
1317
|
}
|
|
@@ -1523,7 +1325,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1523
1325
|
|
|
1524
1326
|
try {
|
|
1525
1327
|
console.log('Taking screenshot...');
|
|
1526
|
-
this.api.
|
|
1328
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1527
1329
|
} catch (error) {
|
|
1528
1330
|
this.handleError(`Failed to take screenshot: ${this.getErrorMessage(error)}`);
|
|
1529
1331
|
}
|
|
@@ -1536,7 +1338,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1536
1338
|
}
|
|
1537
1339
|
try {
|
|
1538
1340
|
console.log('Generating cta information...');
|
|
1539
|
-
this.api.
|
|
1341
|
+
this.api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
1540
1342
|
} catch (error) {
|
|
1541
1343
|
this.handleError(`Failed to generating cta information: ${this.getErrorMessage(error)}`);
|
|
1542
1344
|
}
|
|
@@ -1550,7 +1352,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1550
1352
|
|
|
1551
1353
|
try {
|
|
1552
1354
|
console.log('Generating PDF...');
|
|
1553
|
-
this.api.
|
|
1355
|
+
this.api.sendCommandToMetabox(new GetPdf());
|
|
1554
1356
|
} catch (error) {
|
|
1555
1357
|
this.handleError(`Failed to generating pdf: ${this.getErrorMessage(error)}`);
|
|
1556
1358
|
}
|
|
@@ -1566,15 +1368,15 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1566
1368
|
return;
|
|
1567
1369
|
}
|
|
1568
1370
|
|
|
1569
|
-
this.api.
|
|
1570
|
-
this.api.
|
|
1371
|
+
this.api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
|
|
1372
|
+
this.api.sendCommandToMetabox(new ShowOverlayInterface(true));
|
|
1571
1373
|
}
|
|
1572
1374
|
|
|
1573
1375
|
private initializeConfigurator() {
|
|
1574
1376
|
try {
|
|
1575
1377
|
this.updateState({ isLoading: true, error: null });
|
|
1576
1378
|
|
|
1577
|
-
|
|
1379
|
+
integrateMetabox(this.configuratorId(), this.containerId(), (apiInstance) => {
|
|
1578
1380
|
try {
|
|
1579
1381
|
this.api = apiInstance;
|
|
1580
1382
|
this.updateState({ isLoading: false, isApiReady: true });
|
|
@@ -1602,7 +1404,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1602
1404
|
});
|
|
1603
1405
|
|
|
1604
1406
|
// Listen for screenshot completion
|
|
1605
|
-
this.api.addEventListener('
|
|
1407
|
+
this.api.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
1606
1408
|
console.log(`Screenshot captured successfully ${imageData ?? ''}`);
|
|
1607
1409
|
saveImage(imageData ?? '', `configurator-screenshot-${Date.now()}.png`);
|
|
1608
1410
|
});
|
|
@@ -1650,7 +1452,7 @@ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
|
1650
1452
|
template: `
|
|
1651
1453
|
<div class="app-container">
|
|
1652
1454
|
<h1>My Product Configurator</h1>
|
|
1653
|
-
<app-metabox-configurator [
|
|
1455
|
+
<app-metabox-configurator [configuratorId]="configuratorId" (stateChange)="onConfiguratorStateChange($event)" (errorFired)="onConfiguratorError($event)"></app-metabox-configurator>
|
|
1654
1456
|
</div>
|
|
1655
1457
|
`,
|
|
1656
1458
|
styles: [
|
|
@@ -1664,7 +1466,7 @@ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
|
1664
1466
|
],
|
|
1665
1467
|
})
|
|
1666
1468
|
export class AppComponent {
|
|
1667
|
-
|
|
1469
|
+
configuratorId = 'configurator-id';
|
|
1668
1470
|
|
|
1669
1471
|
onConfiguratorStateChange(data: ConfiguratorEnvelope): void {
|
|
1670
1472
|
console.log('Configurator state changed:', data);
|
|
@@ -1682,7 +1484,7 @@ export class AppComponent {
|
|
|
1682
1484
|
|
|
1683
1485
|
1. Install the package: `npm install @3dsource/metabox-front-api`
|
|
1684
1486
|
2. Import the component in your Angular module
|
|
1685
|
-
3. Replace `'
|
|
1487
|
+
3. Replace `'configurator-id'` with your actual configurator ID
|
|
1686
1488
|
4. Replace placeholder IDs with your real product, material, and slot IDs
|
|
1687
1489
|
5. Customize the styling by modifying the component styles
|
|
1688
1490
|
|
|
@@ -1693,7 +1495,7 @@ export class AppComponent {
|
|
|
1693
1495
|
Always implement proper error handling when working with the API:
|
|
1694
1496
|
|
|
1695
1497
|
```typescript
|
|
1696
|
-
|
|
1498
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1697
1499
|
try {
|
|
1698
1500
|
// Set up event listeners with error handling
|
|
1699
1501
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
@@ -1705,7 +1507,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1705
1507
|
});
|
|
1706
1508
|
|
|
1707
1509
|
// Send commands with error handling
|
|
1708
|
-
api.
|
|
1510
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
1709
1511
|
} catch (error) {
|
|
1710
1512
|
console.error('Error initializing configurator:', error);
|
|
1711
1513
|
}
|
|
@@ -1747,7 +1549,7 @@ class ConfiguratorStateManager {
|
|
|
1747
1549
|
```typescript
|
|
1748
1550
|
// Debounce example
|
|
1749
1551
|
const debouncedMaterialChange = debounce((slotId, materialId) => {
|
|
1750
|
-
api.
|
|
1552
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
1751
1553
|
}, 300);
|
|
1752
1554
|
```
|
|
1753
1555
|
|
|
@@ -1784,7 +1586,7 @@ const hideLoadingState = () => {
|
|
|
1784
1586
|
document.getElementById('loading').style.display = 'none';
|
|
1785
1587
|
};
|
|
1786
1588
|
|
|
1787
|
-
|
|
1589
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1788
1590
|
hideLoadingState();
|
|
1789
1591
|
// Continue with initialization
|
|
1790
1592
|
});
|
|
@@ -1800,8 +1602,8 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1800
1602
|
|
|
1801
1603
|
**Solutions**:
|
|
1802
1604
|
|
|
1803
|
-
- Verify the configurator
|
|
1804
|
-
- Ensure the container element exists in the DOM before calling `
|
|
1605
|
+
- Verify the configurator ID is correct and accessible
|
|
1606
|
+
- Ensure the container element exists in the DOM before calling `integrateMetabox`
|
|
1805
1607
|
- Check that you're using HTTPS (required for Unreal Engine)
|
|
1806
1608
|
- Verify your configurator ID is valid
|
|
1807
1609
|
|
|
@@ -1832,7 +1634,7 @@ if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
|
|
|
1832
1634
|
```typescript
|
|
1833
1635
|
let apiReady = false;
|
|
1834
1636
|
|
|
1835
|
-
|
|
1637
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1836
1638
|
apiReady = true;
|
|
1837
1639
|
// Now it's safe to send commands
|
|
1838
1640
|
});
|
|
@@ -1840,7 +1642,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1840
1642
|
// Wait for API to be ready
|
|
1841
1643
|
const sendCommand = (command) => {
|
|
1842
1644
|
if (apiReady && api) {
|
|
1843
|
-
api.
|
|
1645
|
+
api.sendCommandToMetabox(command);
|
|
1844
1646
|
} else {
|
|
1845
1647
|
console.warn('API not ready yet');
|
|
1846
1648
|
}
|
|
@@ -1858,7 +1660,7 @@ const sendCommand = (command) => {
|
|
|
1858
1660
|
- Ensure the configurator is configured to send the expected events
|
|
1859
1661
|
|
|
1860
1662
|
```typescript
|
|
1861
|
-
|
|
1663
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1862
1664
|
// Set up listeners immediately
|
|
1863
1665
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1864
1666
|
console.log('Event received:', data);
|
|
@@ -1867,7 +1669,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1867
1669
|
// Test if events are working
|
|
1868
1670
|
setTimeout(() => {
|
|
1869
1671
|
console.log('Testing event system...');
|
|
1870
|
-
api.
|
|
1672
|
+
api.sendCommandToMetabox(new SetProduct('test-product'));
|
|
1871
1673
|
}, 1000);
|
|
1872
1674
|
});
|
|
1873
1675
|
```
|
|
@@ -1887,39 +1689,17 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1887
1689
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1888
1690
|
// Scene is loaded, safe to take screenshot
|
|
1889
1691
|
setTimeout(() => {
|
|
1890
|
-
api.
|
|
1692
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1891
1693
|
}, 500);
|
|
1892
1694
|
});
|
|
1893
1695
|
```
|
|
1894
1696
|
|
|
1895
|
-
### Debug Mode
|
|
1896
|
-
|
|
1897
|
-
Enable debug logging to troubleshoot issues:
|
|
1898
|
-
|
|
1899
|
-
```typescript
|
|
1900
|
-
// Enable debug mode (if available)
|
|
1901
|
-
window.METABOX_DEBUG = true;
|
|
1902
|
-
|
|
1903
|
-
integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
1904
|
-
console.log('API initialized:', api);
|
|
1905
|
-
|
|
1906
|
-
// Log all events
|
|
1907
|
-
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1908
|
-
console.log('State update:', data);
|
|
1909
|
-
});
|
|
1910
|
-
|
|
1911
|
-
api.addEventListener('screenshotReady', (imageData) => {
|
|
1912
|
-
console.log('Render completed, data length:', imageData.length);
|
|
1913
|
-
});
|
|
1914
|
-
});
|
|
1915
|
-
```
|
|
1916
|
-
|
|
1917
1697
|
### Getting Help
|
|
1918
1698
|
|
|
1919
1699
|
If you're still experiencing issues:
|
|
1920
1700
|
|
|
1921
1701
|
1. Check the browser console for error messages
|
|
1922
|
-
2. Verify your configurator
|
|
1702
|
+
2. Verify your configurator ID in a separate browser tab
|
|
1923
1703
|
3. Test with a minimal example to isolate the issue
|
|
1924
1704
|
4. Contact support with:
|
|
1925
1705
|
|
|
@@ -1947,42 +1727,6 @@ The Metabox Front API supports modern browsers with ES6 module support:
|
|
|
1947
1727
|
- **HTTPS**: Required for Unreal Engine integration
|
|
1948
1728
|
- **Modern JavaScript**: ES2017+ features are used
|
|
1949
1729
|
|
|
1950
|
-
## Contributing
|
|
1951
|
-
|
|
1952
|
-
We welcome contributions to improve the Metabox Front API! Here's how you can help:
|
|
1953
|
-
|
|
1954
|
-
### Development Setup
|
|
1955
|
-
|
|
1956
|
-
1. Clone the repository
|
|
1957
|
-
2. Install dependencies: `npm install`
|
|
1958
|
-
3. Build the project: `npm run build`
|
|
1959
|
-
4. Run tests: `npm test`
|
|
1960
|
-
|
|
1961
|
-
### Guidelines
|
|
1962
|
-
|
|
1963
|
-
- Follow TypeScript best practices
|
|
1964
|
-
- Add tests for new features
|
|
1965
|
-
- Update documentation for API changes
|
|
1966
|
-
- Use semantic commit messages
|
|
1967
|
-
|
|
1968
|
-
### Reporting Issues
|
|
1969
|
-
|
|
1970
|
-
When reporting issues, please include:
|
|
1971
|
-
|
|
1972
|
-
- Browser version and operating system
|
|
1973
|
-
- Minimal code example reproducing the issue
|
|
1974
|
-
- Expected vs actual behavior
|
|
1975
|
-
- Console error messages (if any)
|
|
1976
|
-
|
|
1977
|
-
### Feature Requests
|
|
1978
|
-
|
|
1979
|
-
We're always looking to improve the API. Feel free to suggest new features or enhancements through our issue tracker.
|
|
1980
|
-
|
|
1981
|
-
---
|
|
1982
|
-
|
|
1983
|
-
**Need help?** Contact our support team or check our documentation for more detailed guides and tutorials.
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
1730
|
## Standalone Mode
|
|
1987
1731
|
|
|
1988
1732
|
Standalone mode lets you embed the Metabox renderer without the built‑in Metabox UI and template logic. This is ideal when you want to build a fully custom UI (menus, buttons, flows) and drive the configurator entirely through this API.
|
|
@@ -1990,29 +1734,30 @@ Standalone mode lets you embed the Metabox renderer without the built‑in Metab
|
|
|
1990
1734
|
When standalone is enabled, the embedded page does not render Metabox’s internal menus, overlays, or template logic. You are responsible for sending commands (e.g., setProduct, setMaterial, setEnvironment) and listening to events to keep your UI in sync.
|
|
1991
1735
|
|
|
1992
1736
|
Key points:
|
|
1737
|
+
|
|
1993
1738
|
- Purpose: use when you need a 100% custom interface and logic on the host page.
|
|
1994
|
-
- Behavior: Metabox default UI, embedded menu and template logic are disabled on the iframe side.
|
|
1739
|
+
- Behavior: Metabox default UI, embedded menu, and template logic are disabled on the iframe side.
|
|
1995
1740
|
- Control: you drive everything with API commands and events.
|
|
1996
|
-
- Availability: supported since v2 of the API
|
|
1741
|
+
- Availability: supported since v2 of the API.
|
|
1997
1742
|
|
|
1998
1743
|
How to enable
|
|
1999
1744
|
|
|
2000
|
-
Pass
|
|
1745
|
+
Pass as param to config with a standalone set to true when calling integrateMetabox.
|
|
2001
1746
|
|
|
2002
1747
|
TypeScript example:
|
|
2003
1748
|
|
|
2004
1749
|
```typescript
|
|
2005
|
-
import {
|
|
1750
|
+
import { integrateMetabox, Communicator, SetProduct, SetEnvironment } from '@3dsource/metabox-front-api';
|
|
2006
1751
|
|
|
2007
|
-
|
|
2008
|
-
'
|
|
1752
|
+
integrateMetabox(
|
|
1753
|
+
'configurator-id',
|
|
2009
1754
|
'embed3DSource',
|
|
2010
1755
|
(api: Communicator) => {
|
|
2011
1756
|
// Send your initial commands to establish state
|
|
2012
|
-
api.
|
|
2013
|
-
api.
|
|
1757
|
+
api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
1758
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
2014
1759
|
},
|
|
2015
|
-
{ standalone: true }
|
|
1760
|
+
{ standalone: true },
|
|
2016
1761
|
);
|
|
2017
1762
|
```
|
|
2018
1763
|
|
|
@@ -2020,22 +1765,22 @@ JavaScript (CDN) example:
|
|
|
2020
1765
|
|
|
2021
1766
|
```html
|
|
2022
1767
|
<script type="module">
|
|
2023
|
-
import {
|
|
1768
|
+
import { integrateMetabox, SetProduct, SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
2024
1769
|
|
|
2025
|
-
|
|
2026
|
-
'
|
|
1770
|
+
integrateMetabox(
|
|
1771
|
+
'configurator-id',
|
|
2027
1772
|
'embed3DSource',
|
|
2028
1773
|
(api) => {
|
|
2029
|
-
api.
|
|
2030
|
-
api.
|
|
1774
|
+
api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
1775
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
2031
1776
|
},
|
|
2032
|
-
{ standalone: true }
|
|
1777
|
+
{ standalone: true },
|
|
2033
1778
|
);
|
|
2034
1779
|
</script>
|
|
2035
1780
|
```
|
|
2036
1781
|
|
|
2037
|
-
Notes and tips
|
|
1782
|
+
Notes and tips:
|
|
2038
1783
|
|
|
2039
1784
|
- In standalone mode, nothing will change until you send initial commands (e.g., set product/environment). If you see a blank/default view, ensure you dispatch the necessary SetProduct/SetEnvironment commands once api is ready.
|
|
2040
1785
|
- All events (like configuratorDataUpdated, screenshotReady) still work; use them to keep your UI synchronized.
|
|
2041
|
-
- Runtime validation still applies:
|
|
1786
|
+
- Runtime validation still applies: configuratorId and containerId must be non-empty. HTTPS is enforced for the internally constructed iframe URL. The hostUrl and apiVersion values are handled internally; you do not need to pass them.
|