@3dsource/metabox-front-api 3.0.0-dev.0 → 3.0.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 +284 -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,160 @@ 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
|
-
integrateMetaBox('https://metabox.3dsource.com/metabox-configurator/basic/your-id', 'embed3DSource', (api) => {
|
|
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
|
+
- `domain?`: Override domain (HTTPS enforced).
|
|
385
326
|
|
|
386
|
-
|
|
327
|
+
**Throws:** Error if `configuratorId` or `containerId` empty, container element missing, or generated URL not HTTPS.
|
|
387
328
|
|
|
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
|
|
329
|
+
Notes:
|
|
457
330
|
|
|
458
|
-
|
|
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.
|
|
459
333
|
|
|
460
|
-
|
|
334
|
+
**Example:**
|
|
461
335
|
|
|
462
336
|
```typescript
|
|
463
|
-
|
|
464
|
-
```
|
|
337
|
+
import { IntegrateMetaboxConfig } from '@3dsource/metabox-front-api';
|
|
465
338
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
##### `GetPdf`
|
|
472
|
-
|
|
473
|
-
Generates a PDF of the current view.
|
|
339
|
+
const config: IntegrateMetaboxConfig = {
|
|
340
|
+
introImage: 'https://example.com/intro.png',
|
|
341
|
+
loadingImage: 'https://example.com/loading.png',
|
|
342
|
+
standalone: false,
|
|
343
|
+
};
|
|
474
344
|
|
|
475
|
-
|
|
476
|
-
|
|
345
|
+
integrateMetabox(
|
|
346
|
+
'configurator-id',
|
|
347
|
+
'embed3DSource',
|
|
348
|
+
(api) => {
|
|
349
|
+
console.log('API ready!', api);
|
|
350
|
+
},
|
|
351
|
+
config,
|
|
352
|
+
);
|
|
477
353
|
```
|
|
478
354
|
|
|
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.
|
|
355
|
+
### Command Classes
|
|
482
356
|
|
|
483
|
-
|
|
357
|
+
All commands are sent using `api.sendCommandToMetabox(new SomeCommand(...))`.
|
|
484
358
|
|
|
485
|
-
|
|
486
|
-
- No parameters are required.
|
|
487
|
-
- Your backend must respond with a JSON object containing a redirectUrl field.
|
|
359
|
+
#### Command Payload Types (Internal)
|
|
488
360
|
|
|
489
361
|
```typescript
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
{
|
|
497
|
-
|
|
362
|
+
interface ToMetaboxMessagePayloads {
|
|
363
|
+
setProduct: { productId: string };
|
|
364
|
+
setEnvironment: { id: string };
|
|
365
|
+
getPdf: void;
|
|
366
|
+
getCallToActionInformation: void;
|
|
367
|
+
getScreenshot: { format: MimeType; size?: { x: number; y: number } };
|
|
368
|
+
setProductMaterialById: { slotId: string; materialId: string };
|
|
369
|
+
setEnvironmentMaterialById: { slotId: string; materialId: string };
|
|
370
|
+
showEmbeddedMenu: { visible: boolean };
|
|
371
|
+
showOverlayInterface: { visible: boolean };
|
|
372
|
+
forceSetDeviceType: { deviceType: ApplicationDeviceTypes };
|
|
373
|
+
resetCamera: void;
|
|
374
|
+
applyZoom: { zoom: number };
|
|
375
|
+
initShowcase: void;
|
|
376
|
+
playShowcase: void;
|
|
377
|
+
pauseShowcase: void;
|
|
378
|
+
stopShowcase: void;
|
|
379
|
+
sendCommandToUnreal: object; // arbitrary Unreal command payload
|
|
498
380
|
}
|
|
499
381
|
```
|
|
500
382
|
|
|
501
|
-
####
|
|
383
|
+
#### Product & Environment
|
|
502
384
|
|
|
503
|
-
|
|
385
|
+
- `SetProduct(productId: string)` – Select active product.
|
|
386
|
+
- `SetProductMaterial(slotId: string, materialId: string)` – Apply material to product slot.
|
|
387
|
+
- `SetEnvironment(id: string)` – Activate environment.
|
|
388
|
+
- `SetEnvironmentMaterial(slotId: string, materialId: string)` – Apply material to environment slot.
|
|
504
389
|
|
|
505
|
-
|
|
390
|
+
#### UI & Overlay
|
|
506
391
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
```
|
|
392
|
+
- `ShowEmbeddedMenu(visible: boolean)` – Toggle right sidebar menu.
|
|
393
|
+
- `ShowOverlayInterface(visible: boolean)` – Toggle viewport overlay UI.
|
|
510
394
|
|
|
511
|
-
|
|
395
|
+
#### Camera & View
|
|
512
396
|
|
|
513
|
-
|
|
397
|
+
- `ResetCamera()` – Reset camera to initial state.
|
|
398
|
+
- `ApplyZoom(zoom: number)` – Apply a zoom factor within allowed range.
|
|
514
399
|
|
|
515
|
-
|
|
516
|
-
api.sendCommandToMetaBox(new PlayShowcase());
|
|
517
|
-
```
|
|
400
|
+
#### Showcase Control
|
|
518
401
|
|
|
519
|
-
|
|
402
|
+
- `InitShowcase()` – Initialize a product showcase sequence.
|
|
403
|
+
- `PlayShowcase()` / `PauseShowcase()` / `StopShowcase()` – Control showcase playback.
|
|
520
404
|
|
|
521
|
-
|
|
405
|
+
#### Media & Export
|
|
522
406
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
407
|
+
- `GetScreenshot(format: MimeType, size?)` – Request a screenshot (listen to `screenshotReady`).
|
|
408
|
+
- `GetPdf()` – Request PDF generation (no dedicated event, handled internally server‑side; poll status messages if needed).
|
|
409
|
+
- `GetCallToActionInformation()` – Trigger CTA flow (backend must return `{ redirectUrl }`).
|
|
410
|
+
|
|
411
|
+
#### Advanced / Experimental
|
|
526
412
|
|
|
527
|
-
|
|
413
|
+
- `UnrealCommand(command: object)` – Send low‑level command to Unreal. Use cautiously.
|
|
414
|
+
- `MetaboxConfig(appId: string, partialConfig)` – Internal initialization command (auto‑sent on communicator creation).
|
|
528
415
|
|
|
529
|
-
|
|
416
|
+
Example:
|
|
530
417
|
|
|
531
418
|
```typescript
|
|
532
|
-
api
|
|
419
|
+
import { UnrealCommand } from '@3dsource/metabox-front-api';
|
|
420
|
+
api.sendCommandToMetabox(new UnrealCommand({ type: 'SetLightIntensity', value: 2.5 }));
|
|
533
421
|
```
|
|
534
422
|
|
|
535
423
|
### Event Handling
|
|
536
424
|
|
|
537
|
-
The API uses an event-driven architecture.
|
|
425
|
+
The API uses an event-driven architecture. Register listeners via `api.addEventListener(eventName, handler)`.
|
|
538
426
|
|
|
539
427
|
#### Available Events
|
|
540
428
|
|
|
541
|
-
| Event
|
|
542
|
-
|
|
|
543
|
-
| `configuratorDataUpdated`
|
|
544
|
-
| `
|
|
545
|
-
| `
|
|
546
|
-
| `viewportReady`
|
|
547
|
-
| `
|
|
548
|
-
|
|
549
|
-
|
|
429
|
+
| Event | Payload Type | Description |
|
|
430
|
+
| ----------------------------- | -------------------- | ---------------------------------------------------------- | ------ | -------------------------- |
|
|
431
|
+
| `configuratorDataUpdated` | ConfiguratorEnvelope | Product/environment/material selections changed. |
|
|
432
|
+
| `ecomConfiguratorDataUpdated` | EcomConfigurator | CTA config (label, callbackUrl) updated. |
|
|
433
|
+
| `dataChannelConnected` | boolean | Unreal data channel connectivity state. |
|
|
434
|
+
| `viewportReady` | boolean | Unreal viewport visibility and readiness. |
|
|
435
|
+
| `showcaseStatusChanged` | ShowCaseStatus | Showcase playback status: init/play/pause/stop. |
|
|
436
|
+
| `statusMessageChanged` | string \| null | Human‑readable loading/progress message. |
|
|
437
|
+
| `screenshotReady` | string \| null | Base64 image data from latest screenshot (null if failed). |
|
|
438
|
+
| `videoResolutionChanged` | { width: number | null; height: number | null } | Video stream size changes. |
|
|
550
439
|
|
|
551
|
-
|
|
440
|
+
#### Example: Basic State Listener
|
|
552
441
|
|
|
553
442
|
```typescript
|
|
554
|
-
api.addEventListener('configuratorDataUpdated', (data
|
|
555
|
-
console.log('
|
|
556
|
-
|
|
443
|
+
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
444
|
+
console.log('Product:', data.productId);
|
|
445
|
+
console.log('Product materials:', data.productMaterialsIds);
|
|
446
|
+
console.log('Environment:', data.environmentId);
|
|
447
|
+
console.log('Environment materials:', data.environmentMaterialsIds);
|
|
557
448
|
});
|
|
558
449
|
```
|
|
559
450
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
Fired when a screenshot or fast render is completed.
|
|
451
|
+
#### Screenshot
|
|
563
452
|
|
|
564
453
|
```typescript
|
|
565
|
-
api.addEventListener('screenshotReady', (
|
|
566
|
-
|
|
567
|
-
// imageData contains the base64 encoded image
|
|
568
|
-
saveImage(imageData, 'screenshot.png');
|
|
454
|
+
api.addEventListener('screenshotReady', (image) => {
|
|
455
|
+
if (!image) return;
|
|
569
456
|
});
|
|
570
457
|
```
|
|
571
458
|
|
|
@@ -614,18 +501,18 @@ Minimal example of triggering the Call‑To‑Action flow from your page once th
|
|
|
614
501
|
<button id="cta-btn" disabled>Send configuration (CTA)</button>
|
|
615
502
|
|
|
616
503
|
<script type="module">
|
|
617
|
-
import {
|
|
504
|
+
import { integrateMetabox, GetCallToActionInformation } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
618
505
|
|
|
619
506
|
let api = null;
|
|
620
507
|
|
|
621
|
-
|
|
508
|
+
integrateMetabox('configurator-id', 'metabox-container', (apiInstance) => {
|
|
622
509
|
api = apiInstance;
|
|
623
510
|
document.getElementById('cta-btn').disabled = false;
|
|
624
511
|
});
|
|
625
512
|
|
|
626
513
|
document.getElementById('cta-btn').addEventListener('click', () => {
|
|
627
514
|
// Triggers sending the current configuration to your CTA Callback URL
|
|
628
|
-
api.
|
|
515
|
+
api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
629
516
|
});
|
|
630
517
|
</script>
|
|
631
518
|
```
|
|
@@ -700,7 +587,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
700
587
|
</div>
|
|
701
588
|
|
|
702
589
|
<script type="module">
|
|
703
|
-
import {
|
|
590
|
+
import { integrateMetabox, SetProduct, SetProductMaterial, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
704
591
|
|
|
705
592
|
let api = null;
|
|
706
593
|
let isApiReady = false;
|
|
@@ -724,40 +611,41 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
724
611
|
|
|
725
612
|
// Initialize configurator with error handling
|
|
726
613
|
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
|
-
|
|
614
|
+
// Replace 'configurator-id' with your actual configurator ID from 3DSource
|
|
615
|
+
const configuratorId = 'configurator-id';
|
|
616
|
+
|
|
617
|
+
integrate -
|
|
618
|
+
metabox.ts(configuratorId, 'metabox-container', (apiInstance) => {
|
|
619
|
+
try {
|
|
620
|
+
api = apiInstance;
|
|
621
|
+
isApiReady = true;
|
|
622
|
+
setLoadingState(false);
|
|
623
|
+
console.log('Configurator ready!');
|
|
624
|
+
|
|
625
|
+
// Listen for configurator state changes
|
|
626
|
+
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
627
|
+
console.log('Configurator state updated:', data);
|
|
628
|
+
// You can update your UI based on the current state
|
|
629
|
+
// For example, update available materials, products, etc.
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// Listen for screenshot completion
|
|
633
|
+
api.addEventListener('screenshotReady', (imageData) => {
|
|
634
|
+
console.log('Screenshot captured successfully');
|
|
635
|
+
// Save the image with a timestamp
|
|
636
|
+
saveImage(imageData, `configurator-screenshot-${Date.now()}.png`);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// Listen for errors
|
|
640
|
+
api.addEventListener('error', (error) => {
|
|
641
|
+
console.error('Configurator error:', error);
|
|
642
|
+
showError('An error occurred in the configurator: ' + error.message);
|
|
643
|
+
});
|
|
644
|
+
} catch (error) {
|
|
645
|
+
console.error('Error setting up API:', error);
|
|
646
|
+
showError('Failed to initialize configurator API: ' + error.message);
|
|
647
|
+
}
|
|
648
|
+
});
|
|
761
649
|
} catch (error) {
|
|
762
650
|
console.error('Error initializing configurator:', error);
|
|
763
651
|
showError('Failed to load configurator: ' + error.message);
|
|
@@ -772,7 +660,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
772
660
|
|
|
773
661
|
try {
|
|
774
662
|
console.log(`Changing to product: ${productId}`);
|
|
775
|
-
api.
|
|
663
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
776
664
|
} catch (error) {
|
|
777
665
|
console.error('Error changing product:', error);
|
|
778
666
|
showError('Failed to change product: ' + error.message);
|
|
@@ -787,7 +675,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
787
675
|
|
|
788
676
|
try {
|
|
789
677
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
790
|
-
api.
|
|
678
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
791
679
|
} catch (error) {
|
|
792
680
|
console.error('Error applying material:', error);
|
|
793
681
|
showError('Failed to apply material: ' + error.message);
|
|
@@ -803,7 +691,7 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
803
691
|
try {
|
|
804
692
|
console.log('Taking screenshot...');
|
|
805
693
|
// Request high-quality screenshot in PNG format
|
|
806
|
-
api.
|
|
694
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
807
695
|
} catch (error) {
|
|
808
696
|
console.error('Error taking screenshot:', error);
|
|
809
697
|
showError('Failed to take screenshot: ' + error.message);
|
|
@@ -814,32 +702,14 @@ A complete HTML example showing how to integrate the Metabox configurator with v
|
|
|
814
702
|
</html>
|
|
815
703
|
```
|
|
816
704
|
|
|
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
705
|
### React Integration Example
|
|
834
706
|
|
|
835
|
-
A complete React component with TypeScript showing proper integration, error handling, and cleanup.
|
|
836
|
-
|
|
837
707
|
```tsx
|
|
838
708
|
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
|
839
|
-
import {
|
|
709
|
+
import { integrateMetabox, Communicator, ConfiguratorEnvelope, SetProduct, SetProductMaterial, GetScreenshot, saveImage } from '@3dsource/metabox-front-api';
|
|
840
710
|
|
|
841
711
|
interface MetaboxConfiguratorProps {
|
|
842
|
-
|
|
712
|
+
configuratorId: string;
|
|
843
713
|
onStateChange?: (data: ConfiguratorEnvelope) => void;
|
|
844
714
|
onError?: (error: string) => void;
|
|
845
715
|
className?: string;
|
|
@@ -851,7 +721,7 @@ interface ConfiguratorState {
|
|
|
851
721
|
isApiReady: boolean;
|
|
852
722
|
}
|
|
853
723
|
|
|
854
|
-
const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({
|
|
724
|
+
const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorId, onStateChange, onError, className }) => {
|
|
855
725
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
856
726
|
const [api, setApi] = useState<Communicator | null>(null);
|
|
857
727
|
const [state, setState] = useState<ConfiguratorState>({
|
|
@@ -886,7 +756,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
886
756
|
// Set the container ID
|
|
887
757
|
containerRef.current!.id = containerId.current;
|
|
888
758
|
|
|
889
|
-
|
|
759
|
+
integrateMetabox(configuratorId, containerId.current, (apiInstance) => {
|
|
890
760
|
if (!mounted) return; // Component was unmounted
|
|
891
761
|
|
|
892
762
|
try {
|
|
@@ -938,7 +808,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
938
808
|
console.log('Cleaning up Metabox Configurator');
|
|
939
809
|
}
|
|
940
810
|
};
|
|
941
|
-
}, [
|
|
811
|
+
}, [configuratorId, onStateChange, handleError, api]);
|
|
942
812
|
|
|
943
813
|
// Command methods with error handling
|
|
944
814
|
const changeProduct = useCallback(
|
|
@@ -950,7 +820,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
950
820
|
|
|
951
821
|
try {
|
|
952
822
|
console.log(`Changing to product: ${productId}`);
|
|
953
|
-
api.
|
|
823
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
954
824
|
} catch (error) {
|
|
955
825
|
handleError(`Failed to change product: ${error instanceof Error ? error.message : String(error)}`);
|
|
956
826
|
}
|
|
@@ -967,7 +837,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
967
837
|
|
|
968
838
|
try {
|
|
969
839
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
970
|
-
api.
|
|
840
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
971
841
|
} catch (error) {
|
|
972
842
|
handleError(`Failed to apply material: ${error instanceof Error ? error.message : String(error)}`);
|
|
973
843
|
}
|
|
@@ -983,7 +853,7 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
983
853
|
|
|
984
854
|
try {
|
|
985
855
|
console.log('Taking screenshot...');
|
|
986
|
-
api.
|
|
856
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
987
857
|
} catch (error) {
|
|
988
858
|
handleError(`Failed to take screenshot: ${error instanceof Error ? error.message : String(error)}`);
|
|
989
859
|
}
|
|
@@ -1142,61 +1012,12 @@ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorU
|
|
|
1142
1012
|
export default MetaboxConfigurator;
|
|
1143
1013
|
```
|
|
1144
1014
|
|
|
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
1015
|
### Angular Integration Example
|
|
1193
1016
|
|
|
1194
|
-
A complete Angular component with TypeScript showing proper integration, error handling, and lifecycle management.
|
|
1195
|
-
|
|
1196
1017
|
```typescript
|
|
1197
1018
|
// metabox-configurator.component.ts
|
|
1198
1019
|
import { Component, input, OnInit, output, signal } from '@angular/core';
|
|
1199
|
-
import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase,
|
|
1020
|
+
import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase, integrateMetabox, PauseShowcase, PlayShowcase, saveImage, SetProductMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase } from '@3dsource/metabox-front-api';
|
|
1200
1021
|
|
|
1201
1022
|
interface ConfiguratorState {
|
|
1202
1023
|
isLoading: boolean;
|
|
@@ -1238,7 +1059,7 @@ interface ConfiguratorState {
|
|
|
1238
1059
|
<div class="controls-title">Configurator Controls:</div>
|
|
1239
1060
|
<div class="controls-buttons">
|
|
1240
1061
|
<button (click)="changeProduct('541f46ab-a86c-48e3-bcfa-f92341483db3')" [disabled]="!_state.isApiReady" class="control-button">Product Change</button>
|
|
1241
|
-
<button (click)="initShowcase(
|
|
1062
|
+
<button (click)="initShowcase()" [disabled]="!_state.isApiReady" class="control-button">Init showcase</button>
|
|
1242
1063
|
<button (click)="stopShowcase()" [disabled]="!_state.isApiReady" class="control-button">Stop showcase</button>
|
|
1243
1064
|
<button (click)="playShowcase()" [disabled]="!_state.isApiReady" class="control-button">Play showcase</button>
|
|
1244
1065
|
<button (click)="pauseShowcase()" [disabled]="!_state.isApiReady" class="control-button">Pause showcase</button>
|
|
@@ -1393,7 +1214,7 @@ interface ConfiguratorState {
|
|
|
1393
1214
|
],
|
|
1394
1215
|
})
|
|
1395
1216
|
export class MetaboxConfiguratorComponent implements OnInit {
|
|
1396
|
-
|
|
1217
|
+
configuratorId = input.required<string>();
|
|
1397
1218
|
stateChange = output<ConfiguratorEnvelope>();
|
|
1398
1219
|
errorFired = output<string>();
|
|
1399
1220
|
state = signal<ConfiguratorState>({
|
|
@@ -1417,21 +1238,20 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1417
1238
|
|
|
1418
1239
|
try {
|
|
1419
1240
|
console.log(`Changing to product: ${productId}`);
|
|
1420
|
-
this.api.
|
|
1241
|
+
this.api.sendCommandToMetabox(new SetProduct(productId));
|
|
1421
1242
|
} catch (error) {
|
|
1422
1243
|
this.handleError(`Failed to change product: ${this.getErrorMessage(error)}`);
|
|
1423
1244
|
}
|
|
1424
1245
|
}
|
|
1425
1246
|
|
|
1426
|
-
initShowcase(
|
|
1247
|
+
initShowcase(): void {
|
|
1427
1248
|
if (!this.state().isApiReady || !this.api) {
|
|
1428
1249
|
console.warn('API not ready yet');
|
|
1429
1250
|
return;
|
|
1430
1251
|
}
|
|
1431
1252
|
|
|
1432
1253
|
try {
|
|
1433
|
-
|
|
1434
|
-
this.api.sendCommandToMetaBox(new InitShowcase(productId));
|
|
1254
|
+
this.api.sendCommandToMetabox(new InitShowcase());
|
|
1435
1255
|
} catch (error) {
|
|
1436
1256
|
this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
|
|
1437
1257
|
}
|
|
@@ -1445,7 +1265,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1445
1265
|
|
|
1446
1266
|
try {
|
|
1447
1267
|
console.log(`Stop showcase`);
|
|
1448
|
-
this.api.
|
|
1268
|
+
this.api.sendCommandToMetabox(new StopShowcase());
|
|
1449
1269
|
} catch (error) {
|
|
1450
1270
|
this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
|
|
1451
1271
|
}
|
|
@@ -1459,7 +1279,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1459
1279
|
|
|
1460
1280
|
try {
|
|
1461
1281
|
console.log(`Play showcase`);
|
|
1462
|
-
this.api.
|
|
1282
|
+
this.api.sendCommandToMetabox(new PlayShowcase());
|
|
1463
1283
|
} catch {
|
|
1464
1284
|
this.handleError(`Failed to play showcase`);
|
|
1465
1285
|
}
|
|
@@ -1473,7 +1293,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1473
1293
|
|
|
1474
1294
|
try {
|
|
1475
1295
|
console.log(`Pause showcase`);
|
|
1476
|
-
this.api.
|
|
1296
|
+
this.api.sendCommandToMetabox(new PauseShowcase());
|
|
1477
1297
|
} catch {
|
|
1478
1298
|
this.handleError(`Failed to pause showcase`);
|
|
1479
1299
|
}
|
|
@@ -1487,7 +1307,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1487
1307
|
|
|
1488
1308
|
try {
|
|
1489
1309
|
console.log(`Applying material ${materialId} to slot ${slotId}`);
|
|
1490
|
-
this.api.
|
|
1310
|
+
this.api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
1491
1311
|
} catch (error) {
|
|
1492
1312
|
this.handleError(`Failed to apply material: ${this.getErrorMessage(error)}`);
|
|
1493
1313
|
}
|
|
@@ -1501,7 +1321,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1501
1321
|
|
|
1502
1322
|
try {
|
|
1503
1323
|
console.log('Taking screenshot...');
|
|
1504
|
-
this.api.
|
|
1324
|
+
this.api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1505
1325
|
} catch (error) {
|
|
1506
1326
|
this.handleError(`Failed to take screenshot: ${this.getErrorMessage(error)}`);
|
|
1507
1327
|
}
|
|
@@ -1514,7 +1334,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1514
1334
|
}
|
|
1515
1335
|
try {
|
|
1516
1336
|
console.log('Generating cta information...');
|
|
1517
|
-
this.api.
|
|
1337
|
+
this.api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
1518
1338
|
} catch (error) {
|
|
1519
1339
|
this.handleError(`Failed to generating cta information: ${this.getErrorMessage(error)}`);
|
|
1520
1340
|
}
|
|
@@ -1528,7 +1348,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1528
1348
|
|
|
1529
1349
|
try {
|
|
1530
1350
|
console.log('Generating PDF...');
|
|
1531
|
-
this.api.
|
|
1351
|
+
this.api.sendCommandToMetabox(new GetPdf());
|
|
1532
1352
|
} catch (error) {
|
|
1533
1353
|
this.handleError(`Failed to generating pdf: ${this.getErrorMessage(error)}`);
|
|
1534
1354
|
}
|
|
@@ -1544,15 +1364,15 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1544
1364
|
return;
|
|
1545
1365
|
}
|
|
1546
1366
|
|
|
1547
|
-
this.api.
|
|
1548
|
-
this.api.
|
|
1367
|
+
this.api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
|
|
1368
|
+
this.api.sendCommandToMetabox(new ShowOverlayInterface(true));
|
|
1549
1369
|
}
|
|
1550
1370
|
|
|
1551
1371
|
private initializeConfigurator() {
|
|
1552
1372
|
try {
|
|
1553
1373
|
this.updateState({ isLoading: true, error: null });
|
|
1554
1374
|
|
|
1555
|
-
|
|
1375
|
+
integrateMetabox(this.configuratorId(), this.containerId(), (apiInstance) => {
|
|
1556
1376
|
try {
|
|
1557
1377
|
this.api = apiInstance;
|
|
1558
1378
|
this.updateState({ isLoading: false, isApiReady: true });
|
|
@@ -1580,7 +1400,7 @@ export class MetaboxConfiguratorComponent implements OnInit {
|
|
|
1580
1400
|
});
|
|
1581
1401
|
|
|
1582
1402
|
// Listen for screenshot completion
|
|
1583
|
-
this.api.addEventListener('
|
|
1403
|
+
this.api.addEventListener('screenshotReady', (imageData: string | null) => {
|
|
1584
1404
|
console.log(`Screenshot captured successfully ${imageData ?? ''}`);
|
|
1585
1405
|
saveImage(imageData ?? '', `configurator-screenshot-${Date.now()}.png`);
|
|
1586
1406
|
});
|
|
@@ -1628,7 +1448,7 @@ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
|
1628
1448
|
template: `
|
|
1629
1449
|
<div class="app-container">
|
|
1630
1450
|
<h1>My Product Configurator</h1>
|
|
1631
|
-
<app-metabox-configurator [
|
|
1451
|
+
<app-metabox-configurator [configuratorId]="configuratorId" (stateChange)="onConfiguratorStateChange($event)" (errorFired)="onConfiguratorError($event)"></app-metabox-configurator>
|
|
1632
1452
|
</div>
|
|
1633
1453
|
`,
|
|
1634
1454
|
styles: [
|
|
@@ -1642,7 +1462,7 @@ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
|
|
|
1642
1462
|
],
|
|
1643
1463
|
})
|
|
1644
1464
|
export class AppComponent {
|
|
1645
|
-
|
|
1465
|
+
configuratorId = 'configurator-id';
|
|
1646
1466
|
|
|
1647
1467
|
onConfiguratorStateChange(data: ConfiguratorEnvelope): void {
|
|
1648
1468
|
console.log('Configurator state changed:', data);
|
|
@@ -1660,7 +1480,7 @@ export class AppComponent {
|
|
|
1660
1480
|
|
|
1661
1481
|
1. Install the package: `npm install @3dsource/metabox-front-api`
|
|
1662
1482
|
2. Import the component in your Angular module
|
|
1663
|
-
3. Replace `'
|
|
1483
|
+
3. Replace `'configurator-id'` with your actual configurator ID
|
|
1664
1484
|
4. Replace placeholder IDs with your real product, material, and slot IDs
|
|
1665
1485
|
5. Customize the styling by modifying the component styles
|
|
1666
1486
|
|
|
@@ -1671,7 +1491,7 @@ export class AppComponent {
|
|
|
1671
1491
|
Always implement proper error handling when working with the API:
|
|
1672
1492
|
|
|
1673
1493
|
```typescript
|
|
1674
|
-
|
|
1494
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1675
1495
|
try {
|
|
1676
1496
|
// Set up event listeners with error handling
|
|
1677
1497
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
@@ -1683,7 +1503,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1683
1503
|
});
|
|
1684
1504
|
|
|
1685
1505
|
// Send commands with error handling
|
|
1686
|
-
api.
|
|
1506
|
+
api.sendCommandToMetabox(new SetProduct(productId));
|
|
1687
1507
|
} catch (error) {
|
|
1688
1508
|
console.error('Error initializing configurator:', error);
|
|
1689
1509
|
}
|
|
@@ -1725,7 +1545,7 @@ class ConfiguratorStateManager {
|
|
|
1725
1545
|
```typescript
|
|
1726
1546
|
// Debounce example
|
|
1727
1547
|
const debouncedMaterialChange = debounce((slotId, materialId) => {
|
|
1728
|
-
api.
|
|
1548
|
+
api.sendCommandToMetabox(new SetProductMaterial(slotId, materialId));
|
|
1729
1549
|
}, 300);
|
|
1730
1550
|
```
|
|
1731
1551
|
|
|
@@ -1762,7 +1582,7 @@ const hideLoadingState = () => {
|
|
|
1762
1582
|
document.getElementById('loading').style.display = 'none';
|
|
1763
1583
|
};
|
|
1764
1584
|
|
|
1765
|
-
|
|
1585
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1766
1586
|
hideLoadingState();
|
|
1767
1587
|
// Continue with initialization
|
|
1768
1588
|
});
|
|
@@ -1778,8 +1598,8 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1778
1598
|
|
|
1779
1599
|
**Solutions**:
|
|
1780
1600
|
|
|
1781
|
-
- Verify the configurator
|
|
1782
|
-
- Ensure the container element exists in the DOM before calling `
|
|
1601
|
+
- Verify the configurator ID is correct and accessible
|
|
1602
|
+
- Ensure the container element exists in the DOM before calling `integrateMetabox`
|
|
1783
1603
|
- Check that you're using HTTPS (required for Unreal Engine)
|
|
1784
1604
|
- Verify your configurator ID is valid
|
|
1785
1605
|
|
|
@@ -1810,7 +1630,7 @@ if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
|
|
|
1810
1630
|
```typescript
|
|
1811
1631
|
let apiReady = false;
|
|
1812
1632
|
|
|
1813
|
-
|
|
1633
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1814
1634
|
apiReady = true;
|
|
1815
1635
|
// Now it's safe to send commands
|
|
1816
1636
|
});
|
|
@@ -1818,7 +1638,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1818
1638
|
// Wait for API to be ready
|
|
1819
1639
|
const sendCommand = (command) => {
|
|
1820
1640
|
if (apiReady && api) {
|
|
1821
|
-
api.
|
|
1641
|
+
api.sendCommandToMetabox(command);
|
|
1822
1642
|
} else {
|
|
1823
1643
|
console.warn('API not ready yet');
|
|
1824
1644
|
}
|
|
@@ -1836,7 +1656,7 @@ const sendCommand = (command) => {
|
|
|
1836
1656
|
- Ensure the configurator is configured to send the expected events
|
|
1837
1657
|
|
|
1838
1658
|
```typescript
|
|
1839
|
-
|
|
1659
|
+
integrateMetabox(configuratorId, containerId, (api) => {
|
|
1840
1660
|
// Set up listeners immediately
|
|
1841
1661
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1842
1662
|
console.log('Event received:', data);
|
|
@@ -1845,7 +1665,7 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1845
1665
|
// Test if events are working
|
|
1846
1666
|
setTimeout(() => {
|
|
1847
1667
|
console.log('Testing event system...');
|
|
1848
|
-
api.
|
|
1668
|
+
api.sendCommandToMetabox(new SetProduct('test-product'));
|
|
1849
1669
|
}, 1000);
|
|
1850
1670
|
});
|
|
1851
1671
|
```
|
|
@@ -1865,39 +1685,17 @@ integrateMetaBox(configuratorUrl, containerId, (api) => {
|
|
|
1865
1685
|
api.addEventListener('configuratorDataUpdated', (data) => {
|
|
1866
1686
|
// Scene is loaded, safe to take screenshot
|
|
1867
1687
|
setTimeout(() => {
|
|
1868
|
-
api.
|
|
1688
|
+
api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
|
|
1869
1689
|
}, 500);
|
|
1870
1690
|
});
|
|
1871
1691
|
```
|
|
1872
1692
|
|
|
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
1693
|
### Getting Help
|
|
1896
1694
|
|
|
1897
1695
|
If you're still experiencing issues:
|
|
1898
1696
|
|
|
1899
1697
|
1. Check the browser console for error messages
|
|
1900
|
-
2. Verify your configurator
|
|
1698
|
+
2. Verify your configurator ID in a separate browser tab
|
|
1901
1699
|
3. Test with a minimal example to isolate the issue
|
|
1902
1700
|
4. Contact support with:
|
|
1903
1701
|
|
|
@@ -1925,37 +1723,59 @@ The Metabox Front API supports modern browsers with ES6 module support:
|
|
|
1925
1723
|
- **HTTPS**: Required for Unreal Engine integration
|
|
1926
1724
|
- **Modern JavaScript**: ES2017+ features are used
|
|
1927
1725
|
|
|
1928
|
-
##
|
|
1726
|
+
## Standalone Mode
|
|
1929
1727
|
|
|
1930
|
-
|
|
1728
|
+
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
1729
|
|
|
1932
|
-
|
|
1730
|
+
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
1731
|
|
|
1934
|
-
|
|
1935
|
-
2. Install dependencies: `npm install`
|
|
1936
|
-
3. Build the project: `npm run build`
|
|
1937
|
-
4. Run tests: `npm test`
|
|
1732
|
+
Key points:
|
|
1938
1733
|
|
|
1939
|
-
|
|
1734
|
+
- Purpose: use when you need a 100% custom interface and logic on the host page.
|
|
1735
|
+
- Behavior: Metabox default UI, embedded menu, and template logic are disabled on the iframe side.
|
|
1736
|
+
- Control: you drive everything with API commands and events.
|
|
1940
1737
|
|
|
1941
|
-
|
|
1942
|
-
- Add tests for new features
|
|
1943
|
-
- Update documentation for API changes
|
|
1944
|
-
- Use semantic commit messages
|
|
1738
|
+
How to enable
|
|
1945
1739
|
|
|
1946
|
-
|
|
1740
|
+
Pass as param to config with a standalone set to true when calling integrateMetabox.
|
|
1947
1741
|
|
|
1948
|
-
|
|
1742
|
+
TypeScript example:
|
|
1949
1743
|
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1744
|
+
```typescript
|
|
1745
|
+
import { integrateMetabox, Communicator, SetProduct, SetEnvironment } from '@3dsource/metabox-front-api';
|
|
1746
|
+
|
|
1747
|
+
integrateMetabox(
|
|
1748
|
+
'configurator-id',
|
|
1749
|
+
'embed3DSource',
|
|
1750
|
+
(api: Communicator) => {
|
|
1751
|
+
// Send your initial commands to establish state
|
|
1752
|
+
api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
1753
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
1754
|
+
},
|
|
1755
|
+
{ standalone: true },
|
|
1756
|
+
);
|
|
1757
|
+
```
|
|
1954
1758
|
|
|
1955
|
-
|
|
1759
|
+
JavaScript (CDN) example:
|
|
1956
1760
|
|
|
1957
|
-
|
|
1761
|
+
```html
|
|
1762
|
+
<script type="module">
|
|
1763
|
+
import { integrateMetabox, SetProduct, SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/+esm';
|
|
1764
|
+
|
|
1765
|
+
integrateMetabox(
|
|
1766
|
+
'configurator-id',
|
|
1767
|
+
'embed3DSource',
|
|
1768
|
+
(api) => {
|
|
1769
|
+
api.sendCommandToMetabox(new SetProduct('your-product-id'));
|
|
1770
|
+
api.sendCommandToMetabox(new SetEnvironment('your-environment-id'));
|
|
1771
|
+
},
|
|
1772
|
+
{ standalone: true },
|
|
1773
|
+
);
|
|
1774
|
+
</script>
|
|
1775
|
+
```
|
|
1958
1776
|
|
|
1959
|
-
|
|
1777
|
+
Notes and tips:
|
|
1960
1778
|
|
|
1961
|
-
|
|
1779
|
+
- 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.
|
|
1780
|
+
- All events (like configuratorDataUpdated, screenshotReady) still work; use them to keep your UI synchronized.
|
|
1781
|
+
- 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.
|