@3dsource/metabox-front-api 3.0.0-dev.0 → 3.0.1
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 +285 -464
- package/fesm2022/3dsource-metabox-front-api.mjs +122 -67
- package/fesm2022/3dsource-metabox-front-api.mjs.map +1 -1
- package/index.d.ts +105 -82
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,19 +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)
|
|
36
|
+
- [Standalone Mode](#standalone-mode)
|
|
20
37
|
- [Examples](#examples)
|
|
21
38
|
- [Best Practices](#best-practices)
|
|
22
39
|
- [Troubleshooting](#troubleshooting)
|
|
40
|
+
- [Common Issues](#common-issues)
|
|
23
41
|
- [Browser Compatibility](#browser-compatibility)
|
|
24
|
-
- [
|
|
42
|
+
- [Requirements](#requirements)
|
|
25
43
|
|
|
26
44
|
## Features
|
|
27
45
|
|
|
@@ -39,6 +57,8 @@ their material slots, and materials, environments.
|
|
|
39
57
|
- HTTPS connection (required for unreal engine)
|
|
40
58
|
- Valid Metabox basic configurator URL
|
|
41
59
|
|
|
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.
|
|
61
|
+
|
|
42
62
|
## Installation
|
|
43
63
|
|
|
44
64
|
### Method 1: NPM Package (Recommended)
|
|
@@ -46,25 +66,27 @@ their material slots, and materials, environments.
|
|
|
46
66
|
For use with frameworks like Angular, React, Vue, etc.:
|
|
47
67
|
|
|
48
68
|
```bash
|
|
49
|
-
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
|
|
50
72
|
```
|
|
51
73
|
|
|
52
74
|
Then import the required components:
|
|
53
75
|
|
|
54
76
|
```typescript
|
|
55
|
-
import {
|
|
77
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from '@3dsource/metabox-front-api';
|
|
56
78
|
```
|
|
57
79
|
|
|
58
80
|
### Method 2: CDN Import
|
|
59
81
|
|
|
60
82
|
Alternative CDN options:
|
|
61
83
|
|
|
62
|
-
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api
|
|
84
|
+
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm`
|
|
63
85
|
|
|
64
86
|
For quick prototyping or vanilla JavaScript projects:
|
|
65
87
|
|
|
66
88
|
```javascript
|
|
67
|
-
import {
|
|
89
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api';
|
|
68
90
|
```
|
|
69
91
|
|
|
70
92
|
## Quick Start
|
|
@@ -103,67 +125,28 @@ Create a container element where the Metabox Configurator will be embedded:
|
|
|
103
125
|
|
|
104
126
|
```html
|
|
105
127
|
<script type="module">
|
|
106
|
-
import {
|
|
107
|
-
|
|
108
|
-
class MetaboxIntegrator {
|
|
109
|
-
constructor() {
|
|
110
|
-
// Replace 'your-configurator-id' with your actual basic configurator ID
|
|
111
|
-
const configuratorUrl = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
|
|
112
|
-
|
|
113
|
-
// Initialize the configurator
|
|
114
|
-
integrateMetaBox(configuratorUrl, 'embed3DSource', (api) => {
|
|
115
|
-
this.onApiReady(api);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
128
|
+
import { integrateMetabox, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
118
129
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// Set up the initial configuration
|
|
135
|
-
this.configureInitialState(api);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
handleConfiguratorUpdate(data) {
|
|
139
|
-
// Handle configurator state changes
|
|
140
|
-
// You can update your UI, save state, etc.
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
configureInitialState(api) {
|
|
144
|
-
// Set the initial product
|
|
145
|
-
api.sendCommandToMetaBox(new SetProduct('your-product-id'));
|
|
146
|
-
|
|
147
|
-
// Set initial environment
|
|
148
|
-
api.sendCommandToMetaBox(new SetEnvironment('your-environment-id'));
|
|
149
|
-
|
|
150
|
-
// Apply material to a specific slot
|
|
151
|
-
api.sendCommandToMetaBox(new SetMaterial('slot-id', 'material-id'));
|
|
152
|
-
|
|
153
|
-
// Take a screenshot
|
|
154
|
-
api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Initialize the integrator
|
|
159
|
-
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
|
+
});
|
|
160
143
|
</script>
|
|
161
144
|
```
|
|
162
145
|
|
|
163
146
|
#### TypeScript Example
|
|
164
147
|
|
|
165
148
|
```typescript
|
|
166
|
-
import {
|
|
149
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, SetEnvironment, GetScreenshot, GetPdf, ShowEmbeddedMenu, ShowOverlayInterface, saveImage } from '@3dsource/metabox-front-api';
|
|
167
150
|
|
|
168
151
|
class MetaboxIntegrator {
|
|
169
152
|
private api: Communicator | null = null;
|
|
@@ -174,11 +157,11 @@ class MetaboxIntegrator {
|
|
|
174
157
|
|
|
175
158
|
private async initialize(): Promise<void> {
|
|
176
159
|
try {
|
|
177
|
-
// Replace '
|
|
178
|
-
const
|
|
160
|
+
// Replace 'configurator-id' with your actual configurator ID
|
|
161
|
+
const configuratorId = 'configurator-id';
|
|
179
162
|
|
|
180
163
|
// Initialize the configurator with type safety
|
|
181
|
-
|
|
164
|
+
integrateMetabox(configuratorId, 'embed3DSource', (api: Communicator) => {
|
|
182
165
|
this.onApiReady(api);
|
|
183
166
|
});
|
|
184
167
|
} catch (error) {
|
|
@@ -227,40 +210,40 @@ class MetaboxIntegrator {
|
|
|
227
210
|
if (!this.api) return;
|
|
228
211
|
|
|
229
212
|
// Set initial product
|
|
230
|
-
this.api.
|
|
213
|
+
this.api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
231
214
|
|
|
232
215
|
// Set initial environment
|
|
233
|
-
this.api.
|
|
216
|
+
this.api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
234
217
|
|
|
235
218
|
// Apply material to a specific slot
|
|
236
|
-
this.api.
|
|
219
|
+
this.api.sendCommandToMetabox(new SetProductMaterial('slot-id', 'material-id'));
|
|
237
220
|
|
|
238
221
|
// Configure UI visibility
|
|
239
|
-
this.api.
|
|
240
|
-
this.api.
|
|
222
|
+
this.api.sendCommandToMetabox(new ShowEmbeddedMenu(false));
|
|
223
|
+
this.api.sendCommandToMetabox(new ShowOverlayInterface(false));
|
|
241
224
|
|
|
242
225
|
// Generate initial screenshot
|
|
243
|
-
this.api.
|
|
226
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
244
227
|
}
|
|
245
228
|
|
|
246
229
|
// Public method to change product
|
|
247
230
|
public changeProduct(productId: string): void {
|
|
248
231
|
if (this.api) {
|
|
249
|
-
this.api.
|
|
232
|
+
this.api.sendCommandToMetabox(new SetProduct(productId));
|
|
250
233
|
}
|
|
251
234
|
}
|
|
252
235
|
|
|
253
236
|
// Public method to apply material
|
|
254
237
|
public applyMaterial(slotId: string, materialId: string): void {
|
|
255
238
|
if (this.api) {
|
|
256
|
-
this.api.
|
|
239
|
+
this.api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
257
240
|
}
|
|
258
241
|
}
|
|
259
242
|
|
|
260
243
|
// Public method to take screenshot
|
|
261
244
|
public takeScreenshot(width: number = 1024, height: number = 1024): void {
|
|
262
245
|
if (this.api) {
|
|
263
|
-
this.api.
|
|
246
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: width, y: height }));
|
|
264
247
|
}
|
|
265
248
|
}
|
|
266
249
|
}
|
|
@@ -301,14 +284,14 @@ const metaboxIntegrator = new MetaboxIntegrator();
|
|
|
301
284
|
- Your backend decides how to use the configuration JSON (e.g., generate a PDF or build a product list).
|
|
302
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.).
|
|
303
286
|
|
|
304
|
-
### Steps to build custom menu
|
|
287
|
+
### Steps to build a custom menu
|
|
305
288
|
|
|
306
|
-
- **configuratorDataUpdated** - add event listener to receive
|
|
307
|
-
- **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
|
|
308
291
|
- **showOverlayInterface** - hide viewport metabox actions if you want to add yours
|
|
309
292
|
- **setEnvironment** - set active environment when you want to change environment
|
|
310
293
|
- **setEnvironmentMaterialById** - set environment material by slot ID
|
|
311
|
-
- **setProduct** - set active product when you want to change product
|
|
294
|
+
- **setProduct** - set active product when you want to change the product
|
|
312
295
|
- **setProductMaterialById** - set product material by slot ID
|
|
313
296
|
- **getScreenshot** - get screenshot
|
|
314
297
|
- **getCallToActionInformation** - send call to action information to api endpoint provided in CTA configuration
|
|
@@ -316,256 +299,161 @@ const metaboxIntegrator = new MetaboxIntegrator();
|
|
|
316
299
|
|
|
317
300
|
### Core Functions
|
|
318
301
|
|
|
319
|
-
#### `
|
|
302
|
+
#### `integrateMetabox`
|
|
320
303
|
|
|
321
304
|
Integrates the Metabox configurator into the specified container element.
|
|
322
305
|
|
|
323
306
|
**TypeScript Signature:**
|
|
324
307
|
|
|
325
308
|
```typescript
|
|
326
|
-
function
|
|
309
|
+
function integrateMetabox(
|
|
310
|
+
configuratorId: string,
|
|
311
|
+
containerId?: string, // defaults to 'embed3DSource'
|
|
312
|
+
apiReadyCallback: (api: Communicator) => void, // required
|
|
313
|
+
config?: IntegrateMetaboxConfig,
|
|
314
|
+
): void;
|
|
327
315
|
```
|
|
328
316
|
|
|
329
317
|
**Parameters:**
|
|
330
318
|
|
|
331
|
-
- `
|
|
332
|
-
- `containerId` (string):
|
|
333
|
-
- `apiReadyCallback` (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
console.log('API ready!', api);
|
|
340
|
-
});
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
### Command Classes
|
|
344
|
-
|
|
345
|
-
All commands are sent to the configurator using the `api.sendCommandToMetaBox()` method.
|
|
346
|
-
|
|
347
|
-
#### Command Payload Types
|
|
348
|
-
|
|
349
|
-
All commands use strongly typed payloads defined in `ToMetaboxMessagePayloads`:
|
|
350
|
-
|
|
351
|
-
```typescript
|
|
352
|
-
interface ToMetaboxMessagePayloads {
|
|
353
|
-
[MetaboxBasicConfiguratorActions.getPdf]: void;
|
|
354
|
-
[MetaboxBasicConfiguratorActions.getCallToActionInformation]: void;
|
|
355
|
-
[MetaboxBasicConfiguratorActions.loadLevel]: { id: string };
|
|
356
|
-
[MetaboxBasicConfiguratorActions.setProduct]: { productId: string };
|
|
357
|
-
[MetaboxBasicConfiguratorActions.getScreenshot]: {
|
|
358
|
-
format: MimeType;
|
|
359
|
-
size?: { x: number; y: number };
|
|
360
|
-
};
|
|
361
|
-
[MetaboxBasicConfiguratorActions.setMaterialById]: {
|
|
362
|
-
slotId: string;
|
|
363
|
-
materialId: string;
|
|
364
|
-
};
|
|
365
|
-
[MetaboxBasicConfiguratorActions.setEnvironmentMaterialById]: {
|
|
366
|
-
slotId: string;
|
|
367
|
-
materialId: string;
|
|
368
|
-
};
|
|
369
|
-
[MetaboxBasicConfiguratorActions.showEmbeddedMenu]: { visible: boolean };
|
|
370
|
-
[MetaboxBasicConfiguratorActions.showOverlayInterface]: { visible: boolean };
|
|
371
|
-
[MetaboxBasicConfiguratorActions.forceSetDeviceType]: {
|
|
372
|
-
deviceType: ApplicationDeviceTypes;
|
|
373
|
-
};
|
|
374
|
-
[MetaboxBasicConfiguratorActions.resetCamera]: void;
|
|
375
|
-
[MetaboxBasicConfiguratorActions.applyZoom]: { zoom: number };
|
|
376
|
-
[MetaboxBasicConfiguratorActions.initShowcase]: { productId: string };
|
|
377
|
-
[MetaboxBasicConfiguratorActions.playShowcase]: void;
|
|
378
|
-
[MetaboxBasicConfiguratorActions.pauseShowcase]: void;
|
|
379
|
-
[MetaboxBasicConfiguratorActions.stopShowcase]: void;
|
|
380
|
-
[MetaboxBasicConfiguratorActions.sendCommandToUnreal]: object;
|
|
381
|
-
}
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
#### Product Configuration
|
|
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
|
+
- `state?`: Optional initial configurator state.
|
|
326
|
+
- `domain?`: Override domain (HTTPS enforced).
|
|
385
327
|
|
|
386
|
-
|
|
328
|
+
**Throws:** Error if `configuratorId` or `containerId` empty, container element missing, or generated URL not HTTPS.
|
|
387
329
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
```typescript
|
|
391
|
-
api.sendCommandToMetaBox(new SetProduct(productId));
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
##### `SetMaterial`
|
|
395
|
-
|
|
396
|
-
Applies a material to a specific product slot.
|
|
397
|
-
|
|
398
|
-
```typescript
|
|
399
|
-
api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
#### Environment Configuration
|
|
403
|
-
|
|
404
|
-
##### `SetEnvironment`
|
|
405
|
-
|
|
406
|
-
Changes the environment/background by ID.
|
|
407
|
-
|
|
408
|
-
```typescript
|
|
409
|
-
api.sendCommandToMetaBox(new SetEnvironment(environmentId));
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
##### `SetEnvironmentMaterial`
|
|
413
|
-
|
|
414
|
-
Applies a material to a specific environment slot.
|
|
415
|
-
|
|
416
|
-
```typescript
|
|
417
|
-
api.sendCommandToMetaBox(new SetEnvironmentMaterial(slotId, materialId));
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
#### Camera Controls
|
|
421
|
-
|
|
422
|
-
##### `ResetCamera`
|
|
423
|
-
|
|
424
|
-
Resets the camera to its default position and rotation.
|
|
425
|
-
|
|
426
|
-
```typescript
|
|
427
|
-
api.sendCommandToMetaBox(new ResetCamera());
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
##### `ApplyZoom`
|
|
431
|
-
|
|
432
|
-
Applies zoom to the camera view.
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
api.sendCommandToMetaBox(new ApplyZoom(zoom));
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
#### Interface Controls
|
|
439
|
-
|
|
440
|
-
##### `ShowEmbeddedMenu`
|
|
441
|
-
|
|
442
|
-
Toggles the visibility of the embedded menu in the configurator.
|
|
443
|
-
|
|
444
|
-
```typescript
|
|
445
|
-
api.sendCommandToMetaBox(new ShowEmbeddedMenu(visible));
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
##### `ShowOverlayInterface`
|
|
449
|
-
|
|
450
|
-
Toggles the overlay interface over the Unreal viewport.
|
|
451
|
-
|
|
452
|
-
```typescript
|
|
453
|
-
api.sendCommandToMetaBox(new ShowOverlayInterface(visible));
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
#### Media Generation
|
|
330
|
+
Notes:
|
|
457
331
|
|
|
458
|
-
|
|
332
|
+
- HTTPS is enforced: attempts to use non-HTTPS iframe URLs are rejected.
|
|
333
|
+
- If a previous iframe with id `embeddedContent` exists, it will be removed before inserting a new one.
|
|
459
334
|
|
|
460
|
-
|
|
335
|
+
**Example:**
|
|
461
336
|
|
|
462
337
|
```typescript
|
|
463
|
-
|
|
464
|
-
```
|
|
338
|
+
import { IntegrateMetaboxConfig } from '@3dsource/metabox-front-api';
|
|
465
339
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
##### `GetPdf`
|
|
472
|
-
|
|
473
|
-
Generates a PDF of the current view.
|
|
340
|
+
const config: IntegrateMetaboxConfig = {
|
|
341
|
+
introImage: 'https://example.com/intro.png',
|
|
342
|
+
loadingImage: 'https://example.com/loading.png',
|
|
343
|
+
standalone: false,
|
|
344
|
+
};
|
|
474
345
|
|
|
475
|
-
|
|
476
|
-
|
|
346
|
+
integrateMetabox(
|
|
347
|
+
'configurator-id',
|
|
348
|
+
'embed3DSource',
|
|
349
|
+
(api) => {
|
|
350
|
+
console.log('API ready!', api);
|
|
351
|
+
},
|
|
352
|
+
config,
|
|
353
|
+
);
|
|
477
354
|
```
|
|
478
355
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
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.
|
|
356
|
+
### Command Classes
|
|
482
357
|
|
|
483
|
-
|
|
358
|
+
All commands are sent using `api.sendCommandToMetabox(new SomeCommand(...))`.
|
|
484
359
|
|
|
485
|
-
|
|
486
|
-
- No parameters are required.
|
|
487
|
-
- Your backend must respond with a JSON object containing a redirectUrl field.
|
|
360
|
+
#### Command Payload Types (Internal)
|
|
488
361
|
|
|
489
362
|
```typescript
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
{
|
|
497
|
-
|
|
363
|
+
interface ToMetaboxMessagePayloads {
|
|
364
|
+
setProduct: { productId: string };
|
|
365
|
+
setEnvironment: { id: string };
|
|
366
|
+
getPdf: void;
|
|
367
|
+
getCallToActionInformation: void;
|
|
368
|
+
getScreenshot: { format: MimeType; size?: { x: number; y: number } };
|
|
369
|
+
setProductMaterialById: { slotId: string; materialId: string };
|
|
370
|
+
setEnvironmentMaterialById: { slotId: string; materialId: string };
|
|
371
|
+
showEmbeddedMenu: { visible: boolean };
|
|
372
|
+
showOverlayInterface: { visible: boolean };
|
|
373
|
+
forceSetDeviceType: { deviceType: ApplicationDeviceTypes };
|
|
374
|
+
resetCamera: void;
|
|
375
|
+
applyZoom: { zoom: number };
|
|
376
|
+
initShowcase: void;
|
|
377
|
+
playShowcase: void;
|
|
378
|
+
pauseShowcase: void;
|
|
379
|
+
stopShowcase: void;
|
|
380
|
+
sendCommandToUnreal: object; // arbitrary Unreal command payload
|
|
498
381
|
}
|
|
499
382
|
```
|
|
500
383
|
|
|
501
|
-
####
|
|
384
|
+
#### Product & Environment
|
|
502
385
|
|
|
503
|
-
|
|
386
|
+
- `SetProduct(productId: string)` – Select active product.
|
|
387
|
+
- `SetProductMaterial(slotId: string, materialId: string)` – Apply material to product slot.
|
|
388
|
+
- `SetEnvironment(id: string)` – Activate environment.
|
|
389
|
+
- `SetEnvironmentMaterial(slotId: string, materialId: string)` – Apply material to environment slot.
|
|
504
390
|
|
|
505
|
-
|
|
391
|
+
#### UI & Overlay
|
|
506
392
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
```
|
|
393
|
+
- `ShowEmbeddedMenu(visible: boolean)` – Toggle right sidebar menu.
|
|
394
|
+
- `ShowOverlayInterface(visible: boolean)` – Toggle viewport overlay UI.
|
|
510
395
|
|
|
511
|
-
|
|
396
|
+
#### Camera & View
|
|
512
397
|
|
|
513
|
-
|
|
398
|
+
- `ResetCamera()` – Reset camera to initial state.
|
|
399
|
+
- `ApplyZoom(zoom: number)` – Apply a zoom factor within allowed range.
|
|
514
400
|
|
|
515
|
-
|
|
516
|
-
api.sendCommandToMetaBox(new PlayShowcase());
|
|
517
|
-
```
|
|
401
|
+
#### Showcase Control
|
|
518
402
|
|
|
519
|
-
|
|
403
|
+
- `InitShowcase()` – Initialize a product showcase sequence.
|
|
404
|
+
- `PlayShowcase()` / `PauseShowcase()` / `StopShowcase()` – Control showcase playback.
|
|
520
405
|
|
|
521
|
-
|
|
406
|
+
#### Media & Export
|
|
522
407
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
408
|
+
- `GetScreenshot(format: MimeType, size?)` – Request a screenshot (listen to `screenshotReady`).
|
|
409
|
+
- `GetPdf()` – Request PDF generation (no dedicated event, handled internally server‑side; poll status messages if needed).
|
|
410
|
+
- `GetCallToActionInformation()` – Trigger CTA flow (backend must return `{ redirectUrl }`).
|
|
411
|
+
|
|
412
|
+
#### Advanced / Experimental
|
|
526
413
|
|
|
527
|
-
|
|
414
|
+
- `UnrealCommand(command: object)` – Send low‑level command to Unreal. Use cautiously.
|
|
415
|
+
- `MetaboxConfig(appId: string, partialConfig)` – Internal initialization command (auto‑sent on communicator creation).
|
|
528
416
|
|
|
529
|
-
|
|
417
|
+
Example:
|
|
530
418
|
|
|
531
419
|
```typescript
|
|
532
|
-
api
|
|
420
|
+
import { UnrealCommand } from '@3dsource/metabox-front-api';
|
|
421
|
+
api.sendCommandToMetabox(new UnrealCommand({ type: 'SetLightIntensity', value: 2.5 }));
|
|
533
422
|
```
|
|
534
423
|
|
|
535
424
|
### Event Handling
|
|
536
425
|
|
|
537
|
-
The API uses an event-driven architecture.
|
|
426
|
+
The API uses an event-driven architecture. Register listeners via `api.addEventListener(eventName, handler)`.
|
|
538
427
|
|
|
539
428
|
#### Available Events
|
|
540
429
|
|
|
541
|
-
| Event
|
|
542
|
-
|
|
|
543
|
-
| `configuratorDataUpdated`
|
|
544
|
-
| `
|
|
545
|
-
| `
|
|
546
|
-
| `viewportReady`
|
|
547
|
-
| `
|
|
548
|
-
|
|
549
|
-
|
|
430
|
+
| Event | Payload Type | Description |
|
|
431
|
+
| ----------------------------- | -------------------- | ---------------------------------------------------------- | ------ | -------------------------- |
|
|
432
|
+
| `configuratorDataUpdated` | ConfiguratorEnvelope | Product/environment/material selections changed. |
|
|
433
|
+
| `ecomConfiguratorDataUpdated` | EcomConfigurator | CTA config (label, callbackUrl) updated. |
|
|
434
|
+
| `dataChannelConnected` | boolean | Unreal data channel connectivity state. |
|
|
435
|
+
| `viewportReady` | boolean | Unreal viewport visibility and readiness. |
|
|
436
|
+
| `showcaseStatusChanged` | ShowCaseStatus | Showcase playback status: init/play/pause/stop. |
|
|
437
|
+
| `statusMessageChanged` | string \| null | Human‑readable loading/progress message. |
|
|
438
|
+
| `screenshotReady` | string \| null | Base64 image data from latest screenshot (null if failed). |
|
|
439
|
+
| `videoResolutionChanged` | { width: number | null; height: number | null } | Video stream size changes. |
|
|
550
440
|
|
|
551
|
-
|
|
441
|
+
#### Example: Basic State Listener
|
|
552
442
|
|
|
553
443
|
```typescript
|
|
554
|
-
api.addEventListener('configuratorDataUpdated', (data
|
|
555
|
-
console.log('
|
|
556
|
-
|
|
444
|
+
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
445
|
+
console.log('Product:', data.productId);
|
|
446
|
+
console.log('Product materials:', data.productMaterialsIds);
|
|
447
|
+
console.log('Environment:', data.environmentId);
|
|
448
|
+
console.log('Environment materials:', data.environmentMaterialsIds);
|
|
557
449
|
});
|
|
558
450
|
```
|
|
559
451
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
Fired when a screenshot or fast render is completed.
|
|
452
|
+
#### Screenshot
|
|
563
453
|
|
|
564
454
|
```typescript
|
|
565
|
-
api.addEventListener('screenshotReady', (
|
|
566
|
-
|
|
567
|
-
// imageData contains the base64 encoded image
|
|
568
|
-
saveImage(imageData, 'screenshot.png');
|
|
455
|
+
api.addEventListener('screenshotReady', (image) => {
|
|
456
|
+
if (!image) return;
|
|
569
457
|
});
|
|
570
458
|
```
|
|
571
459
|
|
|
@@ -614,18 +502,18 @@ Minimal example of triggering the Call‑To‑Action flow from your page once th
|
|
|
614
502
|
<button id="cta-btn" disabled>Send configuration (CTA)</button>
|
|
615
503
|
|
|
616
504
|
<script type="module">
|
|
617
|
-
import {
|
|
505
|
+
import { integrateMetabox, GetCallToActionInformation } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
618
506
|
|
|
619
507
|
let api = null;
|
|
620
508
|
|
|
621
|
-
|
|
509
|
+
integrateMetabox('configurator-id', 'metabox-container', (apiInstance) => {
|
|
622
510
|
api = apiInstance;
|
|
623
511
|
document.getElementById('cta-btn').disabled = false;
|
|
624
512
|
});
|
|
625
513
|
|
|
626
514
|
document.getElementById('cta-btn').addEventListener('click', () => {
|
|
627
515
|
// Triggers sending the current configuration to your CTA Callback URL
|
|
628
|
-
api.
|
|
516
|
+
api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
629
517
|
});
|
|
630
518
|
</script>
|
|
631
519
|
```
|
|
@@ -700,7 +588,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
700
588
|
</div>
|
|
701
589
|
|
|
702
590
|
<script type="module">
|
|
703
|
-
import {
|
|
591
|
+
import { integrateMetabox, SetProduct, SetProductMaterial, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
704
592
|
|
|
705
593
|
let api = null;
|
|
706
594
|
let isApiReady = false;
|
|
@@ -724,40 +612,41 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
724
612
|
|
|
725
613
|
// Initialize configurator with error handling
|
|
726
614
|
try {
|
|
727
|
-
// Replace '
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
615
|
+
// Replace 'configurator-id' with your actual configurator ID from 3DSource
|
|
616
|
+
const configuratorId = 'configurator-id';
|
|
617
|
+
|
|
618
|
+
integrate -
|
|
619
|
+
metabox.ts(configuratorId, 'metabox-container', (apiInstance) => {
|
|
620
|
+
try {
|
|
621
|
+
api = apiInstance;
|
|
622
|
+
isApiReady = true;
|
|
623
|
+
setLoadingState(false);
|
|
624
|
+
console.log('Configurator ready!');
|
|
625
|
+
|
|
626
|
+
// Listen for configurator state changes
|
|
627
|
+
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
628
|
+
console.log('Configurator state updated:', data);
|
|
629
|
+
// You can update your UI based on the current state
|
|
630
|
+
// For example, update available materials, products, etc.
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
// Listen for screenshot completion
|
|
634
|
+
api.addEventListener('screenshotReady', (imageData) => {
|
|
635
|
+
console.log('Screenshot captured successfully');
|
|
636
|
+
// Save the image with a timestamp
|
|
637
|
+
saveImage(imageData, `configurator-screenshot-${Date.now()}.png`);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// Listen for errors
|
|
641
|
+
api.addEventListener('error', (error) => {
|
|
642
|
+
console.error('Configurator error:', error);
|
|
643
|
+
showError('An error occurred in the configurator: ' + error.message);
|
|
644
|
+
});
|
|
645
|
+
} catch (error) {
|
|
646
|
+
console.error('Error setting up API:', error);
|
|
647
|
+
showError('Failed to initialize configurator API: ' + error.message);
|
|
648
|
+
}
|
|
649
|
+
});
|
|
761
650
|
} catch (error) {
|
|
762
651
|
console.error('Error initializing configurator:', error);
|
|
763
652
|
showError('Failed to load configurator: ' + error.message);
|
|
@@ -772,7 +661,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
772
661
|
|
|
773
662
|
try {
|
|
774
663
|
console.log(`Changing to product: ${productId}`);
|
|
775
|
-
api.
|
|
664
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
776
665
|
} catch (error) {
|
|
777
666
|
console.error('Error changing product:', error);
|
|
778
667
|
showError('Failed to change product: ' + error.message);
|
|
@@ -787,7 +676,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
787
676
|
|
|
788
677
|
try {
|
|
789
678
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
790
|
-
api.
|
|
679
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
791
680
|
} catch (error) {
|
|
792
681
|
console.error('Error applying material:', error);
|
|
793
682
|
showError('Failed to apply material: ' + error.message);
|
|
@@ -803,7 +692,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
803
692
|
try {
|
|
804
693
|
console.log('Taking screenshot...');
|
|
805
694
|
// Request high-quality screenshot in PNG format
|
|
806
|
-
api.
|
|
695
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
807
696
|
} catch (error) {
|
|
808
697
|
console.error('Error taking screenshot:', error);
|
|
809
698
|
showError('Failed to take screenshot: ' + error.message);
|
|
@@ -814,32 +703,14 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
814
703
|
</html>
|
|
815
704
|
```
|
|
816
705
|
|
|
817
|
-
**Key Features of this Example:**
|
|
818
|
-
|
|
819
|
-
- **Error Handling**: Comprehensive error handling for all API operations
|
|
820
|
-
- **Loading States**: Visual feedback while the configurator loads
|
|
821
|
-
- **Button States**: Buttons are disabled until the API is ready
|
|
822
|
-
- **Console Logging**: Detailed logging for debugging
|
|
823
|
-
- **Responsive Design**: Clean, responsive button layout
|
|
824
|
-
- **Latest CDN**: Uses `@latest` for the most recent version
|
|
825
|
-
|
|
826
|
-
**To Use This Example:**
|
|
827
|
-
|
|
828
|
-
1. Replace `'your-configurator-id'` with your actual configurator ID
|
|
829
|
-
2. Replace placeholder product IDs (`'product-1'`, `'product-2'`) with real product IDs
|
|
830
|
-
3. Replace placeholder material IDs (`'material-red'`, `'material-blue'`) with real material IDs
|
|
831
|
-
4. Replace placeholder slot ID (`'slot-1'`) with the actual slot ID from your configurator
|
|
832
|
-
|
|
833
706
|
### React Integration Example
|
|
834
707
|
|
|
835
|
-
A complete React component with TypeScript showing proper integration, error handling, and cleanup.
|
|
836
|
-
|
|
837
708
|
```tsx
|
|
838
709
|
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
|
839
|
-
import {
|
|
710
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, GetScreenshot, saveImage } from '@3dsource/metabox-front-api';
|
|
840
711
|
|
|
841
712
|
interface MetaboxConfiguratorProps {
|
|
842
|
-
|
|
713
|
+
configuratorId: string;
|
|
843
714
|
onStateChange?: (data: ConfiguratorEnvelope) => void;
|
|
844
715
|
onError?: (error: string) => void;
|
|
845
716
|
className?: string;
|
|
@@ -851,7 +722,7 @@ interface ConfiguratorState {
|
|
|
851
722
|
isApiReady: boolean;
|
|
852
723
|
}
|
|
853
724
|
|
|
854
|
-
const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({
|
|
725
|
+
const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorId, onStateChange, onError, className }) => {
|
|
855
726
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
856
727
|
const [api, setApi] = useState<Communicator | null>(null);
|
|
857
728
|
const [state, setState] = useState<ConfiguratorState>({
|
|
@@ -886,7 +757,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
886
757
|
// Set the container ID
|
|
887
758
|
containerRef.current!.id = containerId.current;
|
|
888
759
|
|
|
889
|
-
|
|
760
|
+
integrateMetabox(configuratorId, containerId.current, (apiInstance) => {
|
|
890
761
|
if (!mounted) return; // Component was unmounted
|
|
891
762
|
|
|
892
763
|
try {
|
|
@@ -938,7 +809,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
938
809
|
console.log('Cleaning up Metabox Configurator');
|
|
939
810
|
}
|
|
940
811
|
};
|
|
941
|
-
}, [
|
|
812
|
+
}, [configuratorId, onStateChange, handleError, api]);
|
|
942
813
|
|
|
943
814
|
// Command methods with error handling
|
|
944
815
|
const changeProduct = useCallback(
|
|
@@ -950,7 +821,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
950
821
|
|
|
951
822
|
try {
|
|
952
823
|
console.log(`Changing to product: ${productId}`);
|
|
953
|
-
api.
|
|
824
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
954
825
|
} catch (error) {
|
|
955
826
|
handleError(`Failed to change product: ${error instanceof Error ? error.message : String(error)}`);
|
|
956
827
|
}
|
|
@@ -967,7 +838,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
967
838
|
|
|
968
839
|
try {
|
|
969
840
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
970
|
-
api.
|
|
841
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
971
842
|
} catch (error) {
|
|
972
843
|
handleError(`Failed to apply material: ${error instanceof Error ? error.message : String(error)}`);
|
|
973
844
|
}
|
|
@@ -983,7 +854,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
983
854
|
|
|
984
855
|
try {
|
|
985
856
|
console.log('Taking screenshot...');
|
|
986
|
-
api.
|
|
857
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
987
858
|
} catch (error) {
|
|
988
859
|
handleError(`Failed to take screenshot: ${error instanceof Error ? error.message : String(error)}`);
|
|
989
860
|
}
|
|
@@ -1142,61 +1013,12 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
1142
1013
|
export default MetaboxConfigurator;
|
|
1143
1014
|
```
|
|
1144
1015
|
|
|
1145
|
-
**Key Features of this React Example:**
|
|
1146
|
-
|
|
1147
|
-
- **Proper TypeScript Integration**: Full type safety with proper interfaces
|
|
1148
|
-
- **Error Handling**: Comprehensive error states and user feedback
|
|
1149
|
-
- **Component Cleanup**: Proper unmounting and memory leak prevention
|
|
1150
|
-
- **Unique Container IDs**: Automatic ID generation to avoid conflicts
|
|
1151
|
-
- **Loading States**: Visual feedback during initialization
|
|
1152
|
-
- **Optimized Re-renders**: Uses useCallback to prevent unnecessary re-renders
|
|
1153
|
-
- **Responsive Design**: Flexible button layout with proper styling
|
|
1154
|
-
|
|
1155
|
-
**Usage Example:**
|
|
1156
|
-
|
|
1157
|
-
```tsx
|
|
1158
|
-
// App.tsx
|
|
1159
|
-
import React from 'react';
|
|
1160
|
-
import MetaboxConfigurator from './components/MetaboxConfigurator';
|
|
1161
|
-
import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
1162
|
-
|
|
1163
|
-
function App() {
|
|
1164
|
-
const handleStateChange = (data: ConfiguratorEnvelope) => {
|
|
1165
|
-
console.log('Configurator state changed:', data);
|
|
1166
|
-
// Update your application state based on configurator changes
|
|
1167
|
-
};
|
|
1168
|
-
|
|
1169
|
-
const handleError = (error: string) => {
|
|
1170
|
-
console.error('Configurator error:', error);
|
|
1171
|
-
// Handle errors (show notifications, log to analytics, etc.)
|
|
1172
|
-
};
|
|
1173
|
-
|
|
1174
|
-
return (
|
|
1175
|
-
<div className="App">
|
|
1176
|
-
<h1>My Product Configurator</h1>
|
|
1177
|
-
<MetaboxConfigurator configuratorUrl="https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id" onStateChange={handleStateChange} onError={handleError} className="my-configurator" />
|
|
1178
|
-
</div>
|
|
1179
|
-
);
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
export default App;
|
|
1183
|
-
```
|
|
1184
|
-
|
|
1185
|
-
**To Use This Component:**
|
|
1186
|
-
|
|
1187
|
-
1. Install the package: `npm install @3dsource/metabox-front-api`
|
|
1188
|
-
2. Replace `'your-configurator-id'` with your actual configurator ID
|
|
1189
|
-
3. Replace placeholder IDs in the component with your real product, material, and slot IDs
|
|
1190
|
-
4. Customize the styling by passing a `className` prop or modifying the inline styles
|
|
1191
|
-
|
|
1192
1016
|
### Angular Integration Example
|
|
1193
1017
|
|
|
1194
|
-
A complete Angular component with TypeScript showing proper integration, error handling, and lifecycle management.
|
|
1195
|
-
|
|
1196
1018
|
```typescript
|
|
1197
1019
|
// metabox-configurator.component.ts
|
|
1198
1020
|
import { Component, input, OnInit, output, signal } from '@angular/core';
|
|
1199
|
-
import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase,
|
|
1021
|
+
import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase, integrateMetabox, PauseShowcase, PlayShowcase, saveImage, SetProductMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase } from '@3dsource/metabox-front-api';
|
|
1200
1022
|
|
|
1201
1023
|
interface ConfiguratorState {
|
|
1202
1024
|
isLoading: boolean;
|
|
@@ -1238,7 +1060,7 @@ interface ConfiguratorState {
|
|
|
1238
1060
|
<div class="controls-title">Configurator Controls:</div>
|
|
1239
1061
|
<div class="controls-buttons">
|
|
1240
1062
|
<button (click)="changeProduct('541f46ab-a86c-48e3-bcfa-f92341483db3')" [disabled]="!_state.isApiReady" class="control-button">Product Change</button>
|
|
1241
|
-
<button (click)="initShowcase(
|
|
1063
|
+
<button (click)="initShowcase()" [disabled]="!_state.isApiReady" class="control-button">Init showcase</button>
|
|
1242
1064
|
<button (click)="stopShowcase()" [disabled]="!_state.isApiReady" class="control-button">Stop showcase</button>
|
|
1243
1065
|
<button (click)="playShowcase()" [disabled]="!_state.isApiReady" class="control-button">Play showcase</button>
|
|
1244
1066
|
<button (click)="pauseShowcase()" [disabled]="!_state.isApiReady" class="control-button">Pause showcase</button>
|
|
@@ -1393,7 +1215,7 @@ interface ConfiguratorState {
|
|
|
1393
1215
|
],
|
|
1394
1216
|
})
|
|
1395
1217
|
export class MetaboxConfiguratorComponent implements OnInit {
|
|
1396
|
-
|
|
1218
|
+
configuratorId = input.required<string>();
|
|
1397
1219
|
stateChange = output<ConfiguratorEnvelope>();
|
|
1398
1220
|
errorFired = output<string>();
|
|
1399
1221
|
state = signal<ConfiguratorState>({
|
|
@@ -1417,21 +1239,20 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1417
1239
|
|
|
1418
1240
|
try {
|
|
1419
1241
|
console.log(`Changing to product: ${productId}`);
|
|
1420
|
-
this.api.
|
|
1242
|
+
this.api.sendCommandToMetabox(new SetProduct(productId));
|
|
1421
1243
|
} catch (error) {
|
|
1422
1244
|
this.handleError(`Failed to change product: ${this.getErrorMessage(error)}`);
|
|
1423
1245
|
}
|
|
1424
1246
|
}
|
|
1425
1247
|
|
|
1426
|
-
initShowcase(
|
|
1248
|
+
initShowcase(): void {
|
|
1427
1249
|
if (!this.state().isApiReady || !this.api) {
|
|
1428
1250
|
console.warn('API not ready yet');
|
|
1429
1251
|
return;
|
|
1430
1252
|
}
|
|
1431
1253
|
|
|
1432
1254
|
try {
|
|
1433
|
-
|
|
1434
|
-
this.api.sendCommandToMetaBox(new InitShowcase(productId));
|
|
1255
|
+
this.api.sendCommandToMetabox(new InitShowcase());
|
|
1435
1256
|
} catch (error) {
|
|
1436
1257
|
this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
|
|
1437
1258
|
}
|
|
@@ -1445,7 +1266,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1445
1266
|
|
|
1446
1267
|
try {
|
|
1447
1268
|
console.log(`Stop showcase`);
|
|
1448
|
-
this.api.
|
|
1269
|
+
this.api.sendCommandToMetabox(new StopShowcase());
|
|
1449
1270
|
} catch (error) {
|
|
1450
1271
|
this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
|
|
1451
1272
|
}
|
|
@@ -1459,7 +1280,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1459
1280
|
|
|
1460
1281
|
try {
|
|
1461
1282
|
console.log(`Play showcase`);
|
|
1462
|
-
this.api.
|
|
1283
|
+
this.api.sendCommandToMetabox(new PlayShowcase());
|
|
1463
1284
|
} catch {
|
|
1464
1285
|
this.handleError(`Failed to play showcase`);
|
|
1465
1286
|
}
|
|
@@ -1473,7 +1294,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1473
1294
|
|
|
1474
1295
|
try {
|
|
1475
1296
|
console.log(`Pause showcase`);
|
|
1476
|
-
this.api.
|
|
1297
|
+
this.api.sendCommandToMetabox(new PauseShowcase());
|
|
1477
1298
|
} catch {
|
|
1478
1299
|
this.handleError(`Failed to pause showcase`);
|
|
1479
1300
|
}
|
|
@@ -1487,7 +1308,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1487
1308
|
|
|
1488
1309
|
try {
|
|
1489
1310
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
1490
|
-
this.api.
|
|
1311
|
+
this.api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
1491
1312
|
} catch (error) {
|
|
1492
1313
|
this.handleError(`Failed to apply material: ${this.getErrorMessage(error)}`);
|
|
1493
1314
|
}
|
|
@@ -1501,7 +1322,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1501
1322
|
|
|
1502
1323
|
try {
|
|
1503
1324
|
console.log('Taking screenshot...');
|
|
1504
|
-
this.api.
|
|
1325
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1505
1326
|
} catch (error) {
|
|
1506
1327
|
this.handleError(`Failed to take screenshot: ${this.getErrorMessage(error)}`);
|
|
1507
1328
|
}
|
|
@@ -1514,7 +1335,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1514
1335
|
}
|
|
1515
1336
|
try {
|
|
1516
1337
|
console.log('Generating cta information...');
|
|
1517
|
-
this.api.
|
|
1338
|
+
this.api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
1518
1339
|
} catch (error) {
|
|
1519
1340
|
this.handleError(`Failed to generating cta information: ${this.getErrorMessage(error)}`);
|
|
1520
1341
|
}
|
|
@@ -1528,7 +1349,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1528
1349
|
|
|
1529
1350
|
try {
|
|
1530
1351
|
console.log('Generating PDF...');
|
|
1531
|
-
this.api.
|
|
1352
|
+
this.api.sendCommandToMetabox(new GetPdf());
|
|
1532
1353
|
} catch (error) {
|
|
1533
1354
|
this.handleError(`Failed to generating pdf: ${this.getErrorMessage(error)}`);
|
|
1534
1355
|
}
|
|
@@ -1544,15 +1365,15 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1544
1365
|
return;
|
|
1545
1366
|
}
|
|
1546
1367
|
|
|
1547
|
-
this.api.
|
|
1548
|
-
this.api.
|
|
1368
|
+
this.api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
|
|
1369
|
+
this.api.sendCommandToMetabox(new ShowOverlayInterface(true));
|
|
1549
1370
|
}
|
|
1550
1371
|
|
|
1551
1372
|
private initializeConfigurator() {
|
|
1552
1373
|
try {
|
|
1553
1374
|
this.updateState({ isLoading: true, error: null });
|
|
1554
1375
|
|
|
1555
|
-
|
|
1376
|
+
integrateMetabox(this.configuratorId(), this.containerId(), (apiInstance) => {
|
|
1556
1377
|
try {
|
|
1557
1378
|
this.api = apiInstance;
|
|
1558
1379
|
this.updateState({ isLoading: false, isApiReady: true });
|
|
@@ -1580,7 +1401,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1580
1401
|
});
|
|
1581
1402
|
|
|
1582
1403
|
// Listen for screenshot completion
|
|
1583
|
-
this.api.addEventListener('
|
|
1404
|
+
this.api.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
1584
1405
|
console.log(`Screenshot captured successfully ${imageData ?? ''}`);
|
|
1585
1406
|
saveImage(imageData ?? '', `configurator-screenshot-${Date.now()}.png`);
|
|
1586
1407
|
});
|
|
@@ -1628,7 +1449,7 @@ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
|
1628
1449
|
template: `
|
|
1629
1450
|
<div class="app-container">
|
|
1630
1451
|
<h1>My Product Configurator</h1>
|
|
1631
|
-
<app-metabox-configurator [
|
|
1452
|
+
<app-metabox-configurator [configuratorId]="configuratorId" (stateChange)="onConfiguratorStateChange($event)" (errorFired)="onConfiguratorError($event)"></app-metabox-configurator>
|
|
1632
1453
|
</div>
|
|
1633
1454
|
`,
|
|
1634
1455
|
styles: [
|
|
@@ -1642,7 +1463,7 @@ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
|
1642
1463
|
],
|
|
1643
1464
|
})
|
|
1644
1465
|
export class AppComponent {
|
|
1645
|
-
|
|
1466
|
+
configuratorId = 'configurator-id';
|
|
1646
1467
|
|
|
1647
1468
|
onConfiguratorStateChange(data: ConfiguratorEnvelope): void {
|
|
1648
1469
|
console.log('Configurator state changed:', data);
|
|
@@ -1660,7 +1481,7 @@ export class AppComponent {
|
|
|
1660
1481
|
|
|
1661
1482
|
1. Install the package: `npm install @3dsource/metabox-front-api`
|
|
1662
1483
|
2. Import the component in your Angular module
|
|
1663
|
-
3. Replace `'
|
|
1484
|
+
3. Replace `'configurator-id'` with your actual configurator ID
|
|
1664
1485
|
4. Replace placeholder IDs with your real product, material, and slot IDs
|
|
1665
1486
|
5. Customize the styling by modifying the component styles
|
|
1666
1487
|
|
|
@@ -1671,7 +1492,7 @@ export class AppComponent {
|
|
|
1671
1492
|
Always implement proper error handling when working with the API:
|
|
1672
1493
|
|
|
1673
1494
|
```typescript
|
|
1674
|
-
|
|
1495
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1675
1496
|
try {
|
|
1676
1497
|
// Set up event listeners with error handling
|
|
1677
1498
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
@@ -1683,7 +1504,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1683
1504
|
});
|
|
1684
1505
|
|
|
1685
1506
|
// Send commands with error handling
|
|
1686
|
-
api.
|
|
1507
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
1687
1508
|
} catch (error) {
|
|
1688
1509
|
console.error('Error initializing configurator:', error);
|
|
1689
1510
|
}
|
|
@@ -1725,7 +1546,7 @@ class ConfiguratorStateManager {
|
|
|
1725
1546
|
```typescript
|
|
1726
1547
|
// Debounce example
|
|
1727
1548
|
const debouncedMaterialChange = debounce((slotId, materialId) => {
|
|
1728
|
-
api.
|
|
1549
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
1729
1550
|
}, 300);
|
|
1730
1551
|
```
|
|
1731
1552
|
|
|
@@ -1762,7 +1583,7 @@ const hideLoadingState = () => {
|
|
|
1762
1583
|
document.getElementById('loading').style.display = 'none';
|
|
1763
1584
|
};
|
|
1764
1585
|
|
|
1765
|
-
|
|
1586
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1766
1587
|
hideLoadingState();
|
|
1767
1588
|
// Continue with initialization
|
|
1768
1589
|
});
|
|
@@ -1778,8 +1599,8 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1778
1599
|
|
|
1779
1600
|
**Solutions**:
|
|
1780
1601
|
|
|
1781
|
-
- Verify the configurator
|
|
1782
|
-
- Ensure the container element exists in the DOM before calling `
|
|
1602
|
+
- Verify the configurator ID is correct and accessible
|
|
1603
|
+
- Ensure the container element exists in the DOM before calling `integrateMetabox`
|
|
1783
1604
|
- Check that you're using HTTPS (required for Unreal Engine)
|
|
1784
1605
|
- Verify your configurator ID is valid
|
|
1785
1606
|
|
|
@@ -1810,7 +1631,7 @@ if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
|
|
|
1810
1631
|
```typescript
|
|
1811
1632
|
let apiReady = false;
|
|
1812
1633
|
|
|
1813
|
-
|
|
1634
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1814
1635
|
apiReady = true;
|
|
1815
1636
|
// Now it's safe to send commands
|
|
1816
1637
|
});
|
|
@@ -1818,7 +1639,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1818
1639
|
// Wait for API to be ready
|
|
1819
1640
|
const sendCommand = (command) => {
|
|
1820
1641
|
if (apiReady && api) {
|
|
1821
|
-
api.
|
|
1642
|
+
api.sendCommandToMetabox(command);
|
|
1822
1643
|
} else {
|
|
1823
1644
|
console.warn('API not ready yet');
|
|
1824
1645
|
}
|
|
@@ -1836,7 +1657,7 @@ const sendCommand = (command) => {
|
|
|
1836
1657
|
- Ensure the configurator is configured to send the expected events
|
|
1837
1658
|
|
|
1838
1659
|
```typescript
|
|
1839
|
-
|
|
1660
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1840
1661
|
// Set up listeners immediately
|
|
1841
1662
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1842
1663
|
console.log('Event received:', data);
|
|
@@ -1845,7 +1666,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1845
1666
|
// Test if events are working
|
|
1846
1667
|
setTimeout(() => {
|
|
1847
1668
|
console.log('Testing event system...');
|
|
1848
|
-
api.
|
|
1669
|
+
api.sendCommandToMetabox(new SetProduct('test-product'));
|
|
1849
1670
|
}, 1000);
|
|
1850
1671
|
});
|
|
1851
1672
|
```
|
|
@@ -1865,39 +1686,17 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1865
1686
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1866
1687
|
// Scene is loaded, safe to take screenshot
|
|
1867
1688
|
setTimeout(() => {
|
|
1868
|
-
api.
|
|
1689
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1869
1690
|
}, 500);
|
|
1870
1691
|
});
|
|
1871
1692
|
```
|
|
1872
1693
|
|
|
1873
|
-
### Debug Mode
|
|
1874
|
-
|
|
1875
|
-
Enable debug logging to troubleshoot issues:
|
|
1876
|
-
|
|
1877
|
-
```typescript
|
|
1878
|
-
// Enable debug mode (if available)
|
|
1879
|
-
window.METABOX_DEBUG = true;
|
|
1880
|
-
|
|
1881
|
-
integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
1882
|
-
console.log('API initialized:', api);
|
|
1883
|
-
|
|
1884
|
-
// Log all events
|
|
1885
|
-
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1886
|
-
console.log('State update:', data);
|
|
1887
|
-
});
|
|
1888
|
-
|
|
1889
|
-
api.addEventListener('screenshotReady', (imageData) => {
|
|
1890
|
-
console.log('Render completed, data length:', imageData.length);
|
|
1891
|
-
});
|
|
1892
|
-
});
|
|
1893
|
-
```
|
|
1894
|
-
|
|
1895
1694
|
### Getting Help
|
|
1896
1695
|
|
|
1897
1696
|
If you're still experiencing issues:
|
|
1898
1697
|
|
|
1899
1698
|
1. Check the browser console for error messages
|
|
1900
|
-
2. Verify your configurator
|
|
1699
|
+
2. Verify your configurator ID in a separate browser tab
|
|
1901
1700
|
3. Test with a minimal example to isolate the issue
|
|
1902
1701
|
4. Contact support with:
|
|
1903
1702
|
|
|
@@ -1925,37 +1724,59 @@ The Metabox Front API supports modern browsers with ES6 module support:
|
|
|
1925
1724
|
- **HTTPS**: Required for Unreal Engine integration
|
|
1926
1725
|
- **Modern JavaScript**: ES2017+ features are used
|
|
1927
1726
|
|
|
1928
|
-
##
|
|
1727
|
+
## Standalone Mode
|
|
1929
1728
|
|
|
1930
|
-
|
|
1729
|
+
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.
|
|
1931
1730
|
|
|
1932
|
-
|
|
1731
|
+
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.
|
|
1933
1732
|
|
|
1934
|
-
|
|
1935
|
-
2. Install dependencies: `npm install`
|
|
1936
|
-
3. Build the project: `npm run build`
|
|
1937
|
-
4. Run tests: `npm test`
|
|
1733
|
+
Key points:
|
|
1938
1734
|
|
|
1939
|
-
|
|
1735
|
+
- Purpose: use when you need a 100% custom interface and logic on the host page.
|
|
1736
|
+
- Behavior: Metabox default UI, embedded menu, and template logic are disabled on the iframe side.
|
|
1737
|
+
- Control: you drive everything with API commands and events.
|
|
1940
1738
|
|
|
1941
|
-
|
|
1942
|
-
- Add tests for new features
|
|
1943
|
-
- Update documentation for API changes
|
|
1944
|
-
- Use semantic commit messages
|
|
1739
|
+
How to enable
|
|
1945
1740
|
|
|
1946
|
-
|
|
1741
|
+
Pass as param to config with a standalone set to true when calling integrateMetabox.
|
|
1947
1742
|
|
|
1948
|
-
|
|
1743
|
+
TypeScript example:
|
|
1949
1744
|
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1745
|
+
```typescript
|
|
1746
|
+
import { integrateMetabox, Communicator, SetProduct, SetEnvironment } from '@3dsource/metabox-front-api';
|
|
1747
|
+
|
|
1748
|
+
integrateMetabox(
|
|
1749
|
+
'configurator-id',
|
|
1750
|
+
'embed3DSource',
|
|
1751
|
+
(api: Communicator) => {
|
|
1752
|
+
// Send your initial commands to establish state
|
|
1753
|
+
api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
1754
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
1755
|
+
},
|
|
1756
|
+
{ standalone: true },
|
|
1757
|
+
);
|
|
1758
|
+
```
|
|
1954
1759
|
|
|
1955
|
-
|
|
1760
|
+
JavaScript (CDN) example:
|
|
1956
1761
|
|
|
1957
|
-
|
|
1762
|
+
```html
|
|
1763
|
+
<script type="module">
|
|
1764
|
+
import { integrateMetabox, SetProduct, SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
1765
|
+
|
|
1766
|
+
integrateMetabox(
|
|
1767
|
+
'configurator-id',
|
|
1768
|
+
'embed3DSource',
|
|
1769
|
+
(api) => {
|
|
1770
|
+
api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
1771
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
1772
|
+
},
|
|
1773
|
+
{ standalone: true },
|
|
1774
|
+
);
|
|
1775
|
+
</script>
|
|
1776
|
+
```
|
|
1958
1777
|
|
|
1959
|
-
|
|
1778
|
+
Notes and tips:
|
|
1960
1779
|
|
|
1961
|
-
|
|
1780
|
+
- 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.
|
|
1781
|
+
- All events (like configuratorDataUpdated, screenshotReady) still work; use them to keep your UI synchronized.
|
|
1782
|
+
- 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.
|