@3dsource/metabox-front-api 1.2.2-dev.5 → 1.2.3-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,272 +1,1828 @@
1
- # Metabox Basic Configurators API
2
-
3
- This package provides an API for interacting with the Metabox Basic Configurator using plain JavaScript.
4
-
5
- ### Installation (for using with frameworks like Angular, React, etc.) This is the recommended method
6
-
7
- ```sh
8
- npm install @3dsource/metabox-front-api@^1.2.1-dev.5 --save
1
+ # Metabox Basic Configurator API
2
+
3
+ A powerful TypeScript API for seamlessly integrating and controlling the Metabox Basic Configurator in your
4
+ web applications. This API provides full programmatic control over 3D product visualization, products,
5
+ their material slots, and materials, environments.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Features](#features)
10
+ - [Prerequisites](#prerequisites)
11
+ - [Installation](#installation)
12
+ - [Quick Start](#quick-start)
13
+ - [API Reference](#api-reference)
14
+ - [System Terminology](#system-terminology)
15
+ - [Core Functions](#core-functions)
16
+ - [Command Classes](#command-classes)
17
+ - [Event Handling](#event-handling)
18
+ - [Utility Functions](#utility-functions)
19
+ - [Examples](#examples)
20
+ - [Best Practices](#best-practices)
21
+ - [Troubleshooting](#troubleshooting)
22
+ - [Browser Compatibility](#browser-compatibility)
23
+ - [Contributing](#contributing)
24
+
25
+ ## Features
26
+
27
+ - 🚀 Easy integration with any web framework (Angular, React, Vue, etc.)
28
+ - 📱 Responsive design support
29
+ - 🎨 Full control over materials, environments, and products
30
+ - 📸 Screenshot and PDF generation
31
+ - 🎬 Showcase management
32
+ - 📦 TypeScript support with full type definitions
33
+ - 🌐 CDN support for quick prototyping
34
+
35
+ ## Prerequisites
36
+
37
+ - Modern web browser with ES6 module support
38
+ - HTTPS connection (required for unreal engine)
39
+ - Valid Metabox basic configurator URL
40
+
41
+ ## Installation
42
+
43
+ ### Method 1: NPM Package (Recommended)
44
+
45
+ For use with frameworks like Angular, React, Vue, etc.:
46
+
47
+ ```bash
48
+ npm install @3dsource/metabox-front-api@^1.2.2 --save
9
49
  ```
10
50
 
11
- then
51
+ Then import the required components:
12
52
 
13
53
  ```typescript
14
- import { FromMetaboxApiAction, GetScreenshot, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
54
+ import { integrateMetaBox, Communicator, ConfiguratorEnvelope, SetProduct, SetMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from '@3dsource/metabox-front-api';
15
55
  ```
16
56
 
17
- **OR** work with direct import from `NPM` using `CDN` network `unpkg.com` or `jsdelivr.net` (you can also download
18
- package and use it locally):
57
+ ### Method 2: CDN Import
58
+
59
+ Alternative CDN options:
60
+
61
+ - **jsDelivr**: `https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@^1.2.2/+esm`
62
+
63
+ For quick prototyping or vanilla JavaScript projects:
19
64
 
20
65
  ```javascript
21
- import { FromMetaboxApiAction, GetScreenshot, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ConfiguratorEnvelope } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.1-dev.5';
66
+ import { integrateMetaBox, Communicator, ConfiguratorEnvelope, SetProduct, SetMaterial, SetEnvironment, GetScreenshot, GetPdf, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api';
22
67
  ```
23
68
 
24
- ## Usage
69
+ ## Quick Start
25
70
 
26
- ### 1. Create HTML Structure
71
+ ### 1. HTML Setup
27
72
 
28
- Ensure your HTML page has the following structure, where the Metabox Configurator will be integrated.
29
- You **MUST** control CSS style of `embed3DSource` element to make the configurator responsive and fit your needs on your
30
- own.
73
+ Create a container element where the Metabox Configurator will be embedded:
31
74
 
32
75
  ```html
33
- <div id="embed3DSource">
34
- <!-- Your Configurator iframe will be embedded here -->
35
- </div>
76
+ <!DOCTYPE html>
77
+ <html lang="en">
78
+ <head>
79
+ <meta charset="UTF-8" />
80
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
81
+ <title>Metabox Configurator</title>
82
+ <style>
83
+ #embed3DSource {
84
+ width: 100%;
85
+ height: 600px;
86
+ border: 1px solid #ccc;
87
+ border-radius: 8px;
88
+ }
89
+ </style>
90
+ </head>
91
+ <body>
92
+ <div id="embed3DSource">
93
+ <!-- Metabox Configurator will be embedded here -->
94
+ </div>
95
+ </body>
96
+ </html>
36
97
  ```
37
98
 
38
- ### 2. Include Required Scripts
99
+ ### 2. Basic Integration
39
100
 
40
- Below is an example demonstrating how to use the Metabox API functions:
41
-
42
- Insert this code into your HTML file just before the closing `</body>` tag:
43
-
44
- **EXAMPLE:**
45
-
46
- HTML:
101
+ #### JavaScript Example
47
102
 
48
103
  ```html
49
104
  <script type="module">
50
- import { integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetScreenshot, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.1-dev.5';
105
+ import { integrateMetaBox, SetProduct, SetMaterial, SetEnvironment, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.2';
51
106
 
52
- class JsIntegrator {
107
+ class MetaboxIntegrator {
53
108
  constructor() {
54
- const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
55
- integrateMetaBox(url, 'embed3DSource', (api) => this.apiReady(api));
109
+ // Replace 'your-configurator-id' with your actual basic configurator ID
110
+ const configuratorUrl = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
111
+
112
+ // Initialize the configurator
113
+ integrateMetaBox(configuratorUrl, 'embed3DSource', (api) => {
114
+ this.onApiReady(api);
115
+ });
56
116
  }
57
117
 
58
- apiReady(api) {
59
- api.addEventListener('basicConfiguratorDataWithState', (data) => {
60
- this.updateConfiguratorData(data);
118
+ onApiReady(api) {
119
+ console.log('Metabox API is ready!');
120
+
121
+ // Listen for configurator data updates
122
+ api.addEventListener('configuratorDataUpdated', (data) => {
123
+ console.log('Configurator data updated:', data);
124
+ this.handleConfiguratorUpdate(data);
61
125
  });
62
- api.addEventListener('fastRender', (data) => {
63
- saveImage(data, 'Render.png');
126
+
127
+ // Listen for screenshot/render completion
128
+ api.addEventListener('screenshotReady', (imageData) => {
129
+ console.log('Screenshot ready');
130
+ saveImage(imageData, 'configurator-screenshot.png');
64
131
  });
65
- this.setupInitialState(api);
132
+
133
+ // Set up the initial configuration
134
+ this.configureInitialState(api);
66
135
  }
67
136
 
68
- updateConfiguratorData(data) {
69
- // Use data on your own
137
+ handleConfiguratorUpdate(data) {
138
+ // Handle configurator state changes
139
+ // You can update your UI, save state, etc.
70
140
  }
71
141
 
72
- setupInitialState(api) {
73
- api.sendCommandToMetaBox(new SetProduct('productId'));
74
- api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
75
- api.sendCommandToMetaBox(new SetMaterial('slotId', 'materialId'));
76
- api.sendCommandToMetaBox(new SetEnvironmentMaterial('slotId', 'materialId'));
77
- api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
78
- api.sendCommandToMetaBox(new ShowOverlayInterface(false));
79
- api.sendCommandToMetaBox(new GetPdf());
142
+ configureInitialState(api) {
143
+ // Set the initial product
144
+ api.sendCommandToMetaBox(new SetProduct('your-product-id'));
145
+
146
+ // Set initial environment
147
+ api.sendCommandToMetaBox(new SetEnvironment('your-environment-id'));
148
+
149
+ // Apply material to a specific slot
150
+ api.sendCommandToMetaBox(new SetMaterial('slot-id', 'material-id'));
151
+
152
+ // Take a screenshot
80
153
  api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
81
154
  }
82
155
  }
83
156
 
84
- new JsIntegrator();
157
+ // Initialize the integrator
158
+ new MetaboxIntegrator();
85
159
  </script>
86
160
  ```
87
161
 
88
- TypeScript:
162
+ #### TypeScript Example
89
163
 
90
164
  ```typescript
91
- import { ConfiguratorEnvelope, UniversalConfigurator, integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetScreenshot, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from '@3dsource/metabox-front-api';
165
+ import { integrateMetaBox, Communicator, ConfiguratorEnvelope, SetProduct, SetMaterial, SetEnvironment, GetScreenshot, GetPdf, ShowEmbeddedMenu, ShowOverlayInterface, saveImage } from '@3dsource/metabox-front-api';
166
+
167
+ class MetaboxIntegrator {
168
+ private api: Communicator | null = null;
92
169
 
93
- class TsIntegrator {
94
170
  constructor() {
95
- const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
96
- integrateMetaBox(url, 'embed3DSource', (api) => this.apiReady(api));
171
+ this.initialize();
97
172
  }
98
173
 
99
- apiReady(api: Communicator) {
100
- api.addEventListener('basicConfiguratorDataWithState', (data) => {
101
- this.updateConfiguratorData(data);
174
+ private async initialize(): Promise<void> {
175
+ try {
176
+ // Replace 'your-configurator-id' with your actual configurator ID
177
+ const configuratorUrl = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
178
+
179
+ // Initialize the configurator with type safety
180
+ integrateMetaBox(configuratorUrl, 'embed3DSource', (api: Communicator) => {
181
+ this.onApiReady(api);
182
+ });
183
+ } catch (error) {
184
+ console.error('Failed to initialize Metabox:', error);
185
+ }
186
+ }
187
+
188
+ private onApiReady(api: Communicator): void {
189
+ this.api = api;
190
+ console.log('Metabox API is ready!');
191
+
192
+ // Set up event listeners with proper typing
193
+ this.setupEventListeners();
194
+
195
+ // Configure initial state
196
+ this.configureInitialState();
197
+ }
198
+
199
+ private setupEventListeners(): void {
200
+ if (!this.api) return;
201
+
202
+ // Listen for configurator data updates
203
+ this.api.addEventListener('configuratorDataUpdated', (data: ConfiguratorEnvelope) => {
204
+ console.log('Configurator data updated:', data);
205
+ this.handleConfiguratorUpdate(data);
102
206
  });
103
- api.addEventListener('fastRender', (data) => {
104
- saveImage(data, 'Render.png');
207
+
208
+ // Listen for screenshot/render completion
209
+ this.api.addEventListener('screenshotReady', (imageData: string) => {
210
+ console.log('Screenshot ready');
211
+ saveImage(imageData, 'configurator-screenshot.png');
105
212
  });
106
- this.setupInitialState(api);
107
213
  }
108
214
 
109
- updateConfiguratorData(data: ConfiguratorEnvelope) {
110
- // Use data on your own
215
+ private handleConfiguratorUpdate(data: ConfiguratorEnvelope): void {
216
+ // Handle configurator state changes with full type safety
217
+ // Access ConfiguratorEnvelope properties.
218
+
219
+ // Example: Update UI based on current product
220
+ if (data) {
221
+ console.log('Current state:', data);
222
+ }
111
223
  }
112
224
 
113
- setupInitialState(api: Communicator) {
114
- api.sendCommandToMetaBox(new SetProduct('productId'));
115
- api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
116
- api.sendCommandToMetaBox(new SetMaterial('slotId', 'materialId'));
117
- api.sendCommandToMetaBox(new SetEnvironmentMaterial('slotId', 'materialId'));
118
- api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
119
- api.sendCommandToMetaBox(new ShowOverlayInterface(false));
120
- api.sendCommandToMetaBox(new GetPdf());
121
- api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
225
+ private configureInitialState(): void {
226
+ if (!this.api) return;
227
+
228
+ // Set initial product
229
+ this.api.sendCommandToMetaBox(new SetProduct('your-product-id'));
230
+
231
+ // Set initial environment
232
+ this.api.sendCommandToMetaBox(new SetEnvironment('your-environment-id'));
233
+
234
+ // Apply material to a specific slot
235
+ this.api.sendCommandToMetaBox(new SetMaterial('slot-id', 'material-id'));
236
+
237
+ // Configure UI visibility
238
+ this.api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
239
+ this.api.sendCommandToMetaBox(new ShowOverlayInterface(false));
240
+
241
+ // Generate initial screenshot
242
+ this.api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
243
+ }
244
+
245
+ // Public method to change product
246
+ public changeProduct(productId: string): void {
247
+ if (this.api) {
248
+ this.api.sendCommandToMetaBox(new SetProduct(productId));
249
+ }
250
+ }
251
+
252
+ // Public method to apply material
253
+ public applyMaterial(slotId: string, materialId: string): void {
254
+ if (this.api) {
255
+ this.api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
256
+ }
257
+ }
258
+
259
+ // Public method to take screenshot
260
+ public takeScreenshot(width: number = 1024, height: number = 1024): void {
261
+ if (this.api) {
262
+ this.api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: width, y: height }));
263
+ }
122
264
  }
123
265
  }
124
266
 
125
- new TsIntegrator();
267
+ // Initialize the integrator
268
+ const metaboxIntegrator = new MetaboxIntegrator();
269
+
270
+ // Example usage:
271
+ // metaboxIntegrator.changeProduct('new-product-id');
272
+ // metaboxIntegrator.applyMaterial('slot-1', 'material-2');
273
+ // metaboxIntegrator.takeScreenshot(1920, 1080);
126
274
  ```
127
275
 
128
- ### Documentation for current example
276
+ ## API Reference
277
+
278
+ ### System Terminology
279
+
280
+ - **product** - 3D digital twin of the actual physical product within a Metabox system; concept is used in Basic configurator.
281
+ - **productId** - Unique Product ID within the Metabox system; mandatory. Assigned by the Metabox system automatically after the product's 3D digital twin is uploaded into Metabox.
282
+ - **environment** - 3D digital twin of the actual environment (room scene or other) within a Metabox system.
283
+ - **environmentId** - Unique environment ID within the Metabox system; mandatory. Assigned by the Metabox system automatically after the environment's 3D digital twin is uploaded into Metabox.
284
+ - **externalId** - Product or Material ID assigned to product or material in Metabox; optional; can be a combination of letters or numbers or both. Should be identical to the product SKU number in any other non-Metabox e-commerce system that is used for managing products, so Metabox can be integrated with such a system.
285
+ - **showcase** - Exists as an attribute of product only; optional. If present, it means the product's digital twin contains a camera sequence that causes the video mode added automatically to the configurator by Metabox system to play this camera sequence.
286
+ - **component** - Product in the Modular configurator context.
287
+ - **componentId** - Unique Component ID within the Metabox system; mandatory. Assigned by the Metabox system automatically after the Modular configurator is created in Metabox.
288
+ - **componentType** - Exists in Modular Configurator only; the name of the type of the product component, which can include one or several separate products of the same category (examples of product component types: truck wheel, truck bumper). It is set by an unreal artist while creating the digital twin model and is automatically added to the Metabox system after this twin is uploaded to Metabox.
289
+
290
+ ### Core Functions
129
291
 
130
292
  #### `integrateMetaBox`
131
293
 
132
- - **Description**: Integrates the Metabox configurator into the specified container.
133
- - **Usage**:
294
+ Integrates the Metabox configurator into the specified container element.
295
+
296
+ **TypeScript Signature:**
297
+
298
+ ```typescript
299
+ function integrateMetaBox(configuratorUrl: string, containerId: string, apiReadyCallback: (api: Communicator) => void): void;
300
+ ```
301
+
302
+ **Parameters:**
303
+
304
+ - `configuratorUrl` (string): The URL of your Metabox basic configurator
305
+ - `containerId` (string): The ID of the HTML element where the configurator will be embedded
306
+ - `apiReadyCallback` (function): Callback function that receives the Communicator API instance
307
+
308
+ **Example:**
309
+
310
+ ```typescript
311
+ integrateMetaBox('https://metabox.3dsource.com/metabox-configurator/basic/your-id', 'embed3DSource', (api) => {
312
+ console.log('API ready!', api);
313
+ });
314
+ ```
315
+
316
+ ### Command Classes
317
+
318
+ All commands are sent to the configurator using the `api.sendCommandToMetaBox()` method.
319
+
320
+ #### Product Configuration
321
+
322
+ ##### `SetProduct`
323
+
324
+ Sets the active product by ID.
325
+
326
+ ```typescript
327
+ api.sendCommandToMetaBox(new SetProduct(productId));
328
+ ```
329
+
330
+ ##### `SetMaterial`
331
+
332
+ Applies a material to a specific product slot.
333
+
334
+ ```typescript
335
+ api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
336
+ ```
337
+
338
+ #### Environment Configuration
339
+
340
+ ##### `SetEnvironment`
341
+
342
+ Changes the environment/background by ID.
343
+
344
+ ```typescript
345
+ api.sendCommandToMetaBox(new SetEnvironment(environmentId));
346
+ ```
347
+
348
+ ##### `SetEnvironmentMaterial`
349
+
350
+ Applies a material to a specific environment slot.
351
+
352
+ ```typescript
353
+ api.sendCommandToMetaBox(new SetEnvironmentMaterial(slotId, materialId));
354
+ ```
355
+
356
+ #### Camera Controls
357
+
358
+ ##### `ResetCamera`
134
359
 
135
- ```typescript
136
- integrateMetaBox(configuratorUrl: string, containerId: string, apiReadyCallback: (api: Communicator) => void);
137
- ```
360
+ Resets the camera to its default position and rotation.
138
361
 
139
- #### `SetEnvironment`
362
+ ```typescript
363
+ api.sendCommandToMetaBox(new ResetCamera());
364
+ ```
365
+
366
+ ##### `ApplyZoom`
140
367
 
141
- - **Description**: Sets the environment by ID.
142
- - **Usage**:
368
+ Applies zoom to the camera view.
369
+
370
+ ```typescript
371
+ api.sendCommandToMetaBox(new ApplyZoom(zoom));
372
+ ```
373
+
374
+ #### Interface Controls
375
+
376
+ ##### `ShowEmbeddedMenu`
377
+
378
+ Toggles the visibility of the embedded menu in the configurator.
379
+
380
+ ```typescript
381
+ api.sendCommandToMetaBox(new ShowEmbeddedMenu(visible));
382
+ ```
143
383
 
144
- ```typescript
145
- api.sendCommandToMetaBox(new SetEnvironment(environmentId: string));
146
- ```
384
+ ##### `ShowOverlayInterface`
147
385
 
148
- #### `SetMaterial`
386
+ Toggles the overlay interface over the Unreal viewport.
149
387
 
150
- - **Description**: Sets the material for a given product slot.
151
- - **Usage**:
388
+ ```typescript
389
+ api.sendCommandToMetaBox(new ShowOverlayInterface(visible));
390
+ ```
152
391
 
153
- ```typescript
154
- api.sendCommandToMetaBox(new SetMaterial(slotId: string, materialId: string));
155
- ```
392
+ #### Media Generation
156
393
 
157
- #### `SetEnvironmentMaterial`
394
+ ##### `GetScreenshot`
158
395
 
159
- - **Description**: Sets the material for a given environment slot.
160
- - **Usage**:
396
+ Captures a screenshot/render of the current view.
161
397
 
162
- ```typescript
163
- api.sendCommandToMetaBox(new SetEnvironmentMaterial(slotId: string, materialId: string));
164
- ```
398
+ ```typescript
399
+ api.sendCommandToMetaBox(new GetScreenshot(mimeType, { x: 1920, y: 1080 }));
400
+ ```
165
401
 
166
- #### `SetProduct`
402
+ **Parameters:**
167
403
 
168
- - **Description**: Sets the product by ID.
169
- - **Usage**:
404
+ - `mimeType`: Image format ('image/png', 'image/jpeg', etc.)
405
+ - `size`: Optional dimensions object with x and y properties
170
406
 
171
- ```typescript
172
- api.sendCommandToMetaBox(new SetProduct(productId: string));
173
- ```
407
+ ##### `GetPdf`
174
408
 
175
- #### `ShowEmbeddedMenu`
409
+ Generates a PDF of the current view.
176
410
 
177
- - **Description**: Toggles the embedded menu in the Metabox configurator.
178
- - **Usage**:
411
+ ```typescript
412
+ api.sendCommandToMetaBox(new GetPdf());
413
+ ```
179
414
 
180
- ```typescript
181
- api.sendCommandToMetaBox(new ShowEmbeddedMenu(visible: boolean));
182
- ```
415
+ #### Showcase Management
183
416
 
184
- #### `ShowOverlayInterface`
417
+ ##### `InitShowcase`
185
418
 
186
- - **Description**: Toggles the overlay interface over Unreal viewport.
187
- - **Usage**:
419
+ Initializes a showcase with the given showcase ID.
188
420
 
189
- ```typescript
190
- api.sendCommandToMetaBox(new ShowOverlayInterface(visible: boolean));
191
- ```
421
+ ```typescript
422
+ api.sendCommandToMetaBox(new InitShowcase(showcaseId));
423
+ ```
192
424
 
193
- #### `GetScreenshot`
425
+ ##### `PlayShowcase`
194
426
 
195
- - **Description**: Retrieves a screenshot/render of the current view.
196
- - **Usage**:
427
+ Plays the currently loaded showcase.
197
428
 
198
- ```typescript
199
- api.sendCommandToMetaBox(new GetScreenshot(mimeType: string, size?: { x: number, y: number }));
200
- ```
429
+ ```typescript
430
+ api.sendCommandToMetaBox(new PlayShowcase());
431
+ ```
201
432
 
202
- #### `GetPdf`
433
+ ##### `PauseShowcase`
203
434
 
204
- - **Description**: Generates a PDF of the current view.
205
- - **Usage**:
435
+ Pauses the currently playing showcase.
436
+
437
+ ```typescript
438
+ api.sendCommandToMetaBox(new PauseShowcase());
439
+ ```
440
+
441
+ ##### `StopShowcase`
442
+
443
+ Stops the currently playing showcase and returns to the initial state.
444
+
445
+ ```typescript
446
+ api.sendCommandToMetaBox(new StopShowcase());
447
+ ```
448
+
449
+ ### Event Handling
450
+
451
+ The API uses an event-driven architecture. Listen for events using the `addEventListener` method:
452
+
453
+ #### Available Events
454
+
455
+ ##### `configuratorDataUpdated`
456
+
457
+ Fired when the configurator state changes (product, materials, environment, etc.).
458
+
459
+ ```typescript
460
+ api.addEventListener('configuratorDataUpdated', (data: ConfiguratorEnvelope) => {
461
+ console.log('Configurator state updated:', data);
462
+ // Access data.product, data.materials, data.environment, etc.
463
+ });
464
+ ```
465
+
466
+ ##### `screenshotReady`
467
+
468
+ Fired when a screenshot or fast render is completed.
469
+
470
+ ```typescript
471
+ api.addEventListener('screenshotReady', (imageData: string) => {
472
+ console.log('Render completed');
473
+ // imageData contains the base64 encoded image
474
+ saveImage(imageData, 'screenshot.png');
475
+ });
476
+ ```
206
477
 
207
- ```typescript
208
- api.sendCommandToMetaBox(new GetPdf());
209
- ```
478
+ ##### `pdfGenerated`
479
+
480
+ Fired when PDF generation is completed.
481
+
482
+ ```typescript
483
+ api.addEventListener('pdfGenerated', (pdfData: string) => {
484
+ console.log('PDF generated');
485
+ // Handle PDF data
486
+ });
487
+ ```
488
+
489
+ ### Utility Functions
210
490
 
211
491
  #### `saveImage`
212
492
 
213
- - **Description**: Saves the arrived rendered image to a file using utility function.
214
- - **Usage**:
493
+ Utility function to save rendered images to a file.
494
+
495
+ ```typescript
496
+ function saveImage(imageUrl: string, filename: string): void;
497
+ ```
498
+
499
+ **Parameters:**
500
+
501
+ - `imageUrl`: The URL of the image to save (can be base64 encoded image data)
502
+ - `filename`: The name of the file to save
503
+
504
+ **Example:**
505
+
506
+ ```typescript
507
+ api.addEventListener('screenshotReady', (imageData: string | null) => {
508
+ saveImage(imageData ?? '', 'my-render.png');
509
+ });
510
+ ```
511
+
512
+ ## Examples
513
+
514
+ ### Basic Product Configurator
515
+
516
+ A complete HTML example showing how to integrate the Metabox configurator with vanilla JavaScript.
517
+
518
+ ```html
519
+ <!DOCTYPE html>
520
+ <html lang="en">
521
+ <head>
522
+ <meta charset="UTF-8" />
523
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
524
+ <title>Product Configurator</title>
525
+ <style>
526
+ #metabox-container {
527
+ width: 100%;
528
+ height: 600px;
529
+ border: 1px solid #ddd;
530
+ border-radius: 8px;
531
+ }
532
+
533
+ .controls {
534
+ margin: 20px 0;
535
+ }
536
+
537
+ button {
538
+ margin: 5px;
539
+ padding: 10px 15px;
540
+ border: 1px solid #ccc;
541
+ border-radius: 4px;
542
+ background: #f5f5f5;
543
+ cursor: pointer;
544
+ }
545
+
546
+ button:hover {
547
+ background: #e5e5e5;
548
+ }
549
+
550
+ button:disabled {
551
+ opacity: 0.5;
552
+ cursor: not-allowed;
553
+ }
554
+
555
+ .loading {
556
+ text-align: center;
557
+ padding: 20px;
558
+ color: #666;
559
+ }
560
+
561
+ .error {
562
+ color: #d32f2f;
563
+ padding: 10px;
564
+ background: #ffebee;
565
+ border: 1px solid #ffcdd2;
566
+ border-radius: 4px;
567
+ margin: 10px 0;
568
+ }
569
+ </style>
570
+ </head>
571
+ <body>
572
+ <div id="loading" class="loading">Loading configurator...</div>
573
+ <div id="error" class="error" style="display: none;"></div>
574
+ <div id="metabox-container"></div>
575
+ <div class="controls">
576
+ <button id="product1-btn" onclick="changeProduct('product-1')" disabled>Product 1</button>
577
+ <button id="product2-btn" onclick="changeProduct('product-2')" disabled>Product 2</button>
578
+ <button id="red-material-btn" onclick="applyMaterial('slot-1', 'material-red')" disabled>Red Material</button>
579
+ <button id="blue-material-btn" onclick="applyMaterial('slot-1', 'material-blue')" disabled>Blue Material</button>
580
+ <button id="screenshot-btn" onclick="takeScreenshot()" disabled>Take Screenshot</button>
581
+ </div>
582
+
583
+ <script type="module">
584
+ import { integrateMetaBox, SetProduct, SetMaterial, GetScreenshot, saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
585
+
586
+ let api = null;
587
+ let isApiReady = false;
588
+
589
+ // Helper function to show/hide loading state
590
+ function setLoadingState(loading) {
591
+ const loadingEl = document.getElementById('loading');
592
+ const buttons = document.querySelectorAll('button');
593
+
594
+ loadingEl.style.display = loading ? 'block' : 'none';
595
+ buttons.forEach((btn) => (btn.disabled = loading || !isApiReady));
596
+ }
597
+
598
+ // Helper function to show error messages
599
+ function showError(message) {
600
+ const errorEl = document.getElementById('error');
601
+ errorEl.textContent = message;
602
+ errorEl.style.display = 'block';
603
+ setLoadingState(false);
604
+ }
605
+
606
+ // Initialize configurator with error handling
607
+ try {
608
+ // Replace 'your-configurator-id' with your actual configurator ID from 3DSource
609
+ const configuratorUrl = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id';
610
+
611
+ integrateMetaBox(configuratorUrl, 'metabox-container', (apiInstance) => {
612
+ try {
613
+ api = apiInstance;
614
+ isApiReady = true;
615
+ setLoadingState(false);
616
+ console.log('Configurator ready!');
617
+
618
+ // Listen for configurator state changes
619
+ api.addEventListener('configuratorDataUpdated', (data) => {
620
+ console.log('Configurator state updated:', data);
621
+ // You can update your UI based on the current state
622
+ // For example, update available materials, products, etc.
623
+ });
624
+
625
+ // Listen for screenshot completion
626
+ api.addEventListener('screenshotReady', (imageData) => {
627
+ console.log('Screenshot captured successfully');
628
+ // Save the image with a timestamp
629
+ saveImage(imageData, `configurator-screenshot-${Date.now()}.png`);
630
+ });
631
+
632
+ // Listen for errors
633
+ api.addEventListener('error', (error) => {
634
+ console.error('Configurator error:', error);
635
+ showError('An error occurred in the configurator: ' + error.message);
636
+ });
637
+ } catch (error) {
638
+ console.error('Error setting up API:', error);
639
+ showError('Failed to initialize configurator API: ' + error.message);
640
+ }
641
+ });
642
+ } catch (error) {
643
+ console.error('Error initializing configurator:', error);
644
+ showError('Failed to load configurator: ' + error.message);
645
+ }
646
+
647
+ // Global functions for button interactions
648
+ window.changeProduct = (productId) => {
649
+ if (!isApiReady || !api) {
650
+ console.warn('API not ready yet');
651
+ return;
652
+ }
653
+
654
+ try {
655
+ console.log(`Changing to product: ${productId}`);
656
+ api.sendCommandToMetaBox(new SetProduct(productId));
657
+ } catch (error) {
658
+ console.error('Error changing product:', error);
659
+ showError('Failed to change product: ' + error.message);
660
+ }
661
+ };
662
+
663
+ window.applyMaterial = (slotId, materialId) => {
664
+ if (!isApiReady || !api) {
665
+ console.warn('API not ready yet');
666
+ return;
667
+ }
668
+
669
+ try {
670
+ console.log(`Applying material ${materialId} to slot ${slotId}`);
671
+ api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
672
+ } catch (error) {
673
+ console.error('Error applying material:', error);
674
+ showError('Failed to apply material: ' + error.message);
675
+ }
676
+ };
677
+
678
+ window.takeScreenshot = () => {
679
+ if (!isApiReady || !api) {
680
+ console.warn('API not ready yet');
681
+ return;
682
+ }
683
+
684
+ try {
685
+ console.log('Taking screenshot...');
686
+ // Request high-quality screenshot in PNG format
687
+ api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
688
+ } catch (error) {
689
+ console.error('Error taking screenshot:', error);
690
+ showError('Failed to take screenshot: ' + error.message);
691
+ }
692
+ };
693
+ </script>
694
+ </body>
695
+ </html>
696
+ ```
697
+
698
+ **Key Features of this Example:**
699
+
700
+ - **Error Handling**: Comprehensive error handling for all API operations
701
+ - **Loading States**: Visual feedback while the configurator loads
702
+ - **Button States**: Buttons are disabled until the API is ready
703
+ - **Console Logging**: Detailed logging for debugging
704
+ - **Responsive Design**: Clean, responsive button layout
705
+ - **Latest CDN**: Uses `@latest` for the most recent version
706
+
707
+ **To Use This Example:**
708
+
709
+ 1. Replace `'your-configurator-id'` with your actual configurator ID
710
+ 2. Replace placeholder product IDs (`'product-1'`, `'product-2'`) with real product IDs
711
+ 3. Replace placeholder material IDs (`'material-red'`, `'material-blue'`) with real material IDs
712
+ 4. Replace placeholder slot ID (`'slot-1'`) with the actual slot ID from your configurator
713
+
714
+ ### React Integration Example
715
+
716
+ A complete React component with TypeScript showing proper integration, error handling, and cleanup.
717
+
718
+ ```tsx
719
+ import React, { useEffect, useRef, useState, useCallback } from 'react';
720
+ import { integrateMetaBox, Communicator, SetProduct, SetMaterial, GetScreenshot, saveImage, ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
721
+
722
+ interface MetaboxConfiguratorProps {
723
+ configuratorUrl: string;
724
+ onStateChange?: (data: ConfiguratorEnvelope) => void;
725
+ onError?: (error: string) => void;
726
+ className?: string;
727
+ }
728
+
729
+ interface ConfiguratorState {
730
+ isLoading: boolean;
731
+ error: string | null;
732
+ isApiReady: boolean;
733
+ }
734
+
735
+ const MetaboxConfigurator: React.FC<MetaboxConfiguratorProps> = ({ configuratorUrl, onStateChange, onError, className }) => {
736
+ const containerRef = useRef<HTMLDivElement>(null);
737
+ const [api, setApi] = useState<Communicator | null>(null);
738
+ const [state, setState] = useState<ConfiguratorState>({
739
+ isLoading: true,
740
+ error: null,
741
+ isApiReady: false,
742
+ });
743
+
744
+ // Generate unique container ID to avoid conflicts
745
+ const containerId = useRef(`metabox-container-${Math.random().toString(36).substr(2, 9)}`);
746
+
747
+ // Error handler
748
+ const handleError = useCallback(
749
+ (error: string) => {
750
+ setState((prev) => ({ ...prev, error, isLoading: false }));
751
+ onError?.(error);
752
+ console.error('Metabox Configurator Error:', error);
753
+ },
754
+ [onError],
755
+ );
756
+
757
+ // Initialize configurator
758
+ useEffect(() => {
759
+ if (!containerRef.current) return;
760
+
761
+ let mounted = true;
762
+
763
+ const initializeConfigurator = async () => {
764
+ try {
765
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
766
+
767
+ // Set the container ID
768
+ containerRef.current!.id = containerId.current;
769
+
770
+ integrateMetaBox(configuratorUrl, containerId.current, (apiInstance) => {
771
+ if (!mounted) return; // Component was unmounted
772
+
773
+ try {
774
+ setApi(apiInstance);
775
+ setState((prev) => ({ ...prev, isLoading: false, isApiReady: true }));
776
+
777
+ // Set up event listeners with proper typing
778
+ apiInstance.addEventListener('configuratorDataUpdated', (data: ConfiguratorEnvelope) => {
779
+ if (mounted) {
780
+ onStateChange?.(data);
781
+ }
782
+ });
783
+
784
+ apiInstance.addEventListener('screenshotReady', (imageData: string) => {
785
+ if (mounted) {
786
+ console.log('Screenshot captured successfully');
787
+ saveImage(imageData, `configurator-screenshot-${Date.now()}.png`);
788
+ }
789
+ });
790
+
791
+ // Listen for errors from the configurator
792
+ apiInstance.addEventListener('error', (error: any) => {
793
+ if (mounted) {
794
+ handleError(`Configurator error: ${error.message || error}`);
795
+ }
796
+ });
797
+
798
+ console.log('React Metabox Configurator initialized successfully');
799
+ } catch (error) {
800
+ if (mounted) {
801
+ handleError(`Failed to set up API: ${error instanceof Error ? error.message : String(error)}`);
802
+ }
803
+ }
804
+ });
805
+ } catch (error) {
806
+ if (mounted) {
807
+ handleError(`Failed to initialize configurator: ${error instanceof Error ? error.message : String(error)}`);
808
+ }
809
+ }
810
+ };
811
+
812
+ initializeConfigurator();
813
+
814
+ // Cleanup function
815
+ return () => {
816
+ mounted = false;
817
+ if (api) {
818
+ // Clean up any event listeners if the API provides cleanup methods
819
+ console.log('Cleaning up Metabox Configurator');
820
+ }
821
+ };
822
+ }, [configuratorUrl, onStateChange, handleError, api]);
823
+
824
+ // Command methods with error handling
825
+ const changeProduct = useCallback(
826
+ (productId: string) => {
827
+ if (!state.isApiReady || !api) {
828
+ console.warn('API not ready yet');
829
+ return;
830
+ }
831
+
832
+ try {
833
+ console.log(`Changing to product: ${productId}`);
834
+ api.sendCommandToMetaBox(new SetProduct(productId));
835
+ } catch (error) {
836
+ handleError(`Failed to change product: ${error instanceof Error ? error.message : String(error)}`);
837
+ }
838
+ },
839
+ [api, state.isApiReady, handleError],
840
+ );
841
+
842
+ const applyMaterial = useCallback(
843
+ (slotId: string, materialId: string) => {
844
+ if (!state.isApiReady || !api) {
845
+ console.warn('API not ready yet');
846
+ return;
847
+ }
848
+
849
+ try {
850
+ console.log(`Applying material ${materialId} to slot ${slotId}`);
851
+ api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
852
+ } catch (error) {
853
+ handleError(`Failed to apply material: ${error instanceof Error ? error.message : String(error)}`);
854
+ }
855
+ },
856
+ [api, state.isApiReady, handleError],
857
+ );
858
+
859
+ const takeScreenshot = useCallback(() => {
860
+ if (!state.isApiReady || !api) {
861
+ console.warn('API not ready yet');
862
+ return;
863
+ }
864
+
865
+ try {
866
+ console.log('Taking screenshot...');
867
+ api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
868
+ } catch (error) {
869
+ handleError(`Failed to take screenshot: ${error instanceof Error ? error.message : String(error)}`);
870
+ }
871
+ }, [api, state.isApiReady, handleError]);
872
+
873
+ // Render error state
874
+ if (state.error) {
875
+ return (
876
+ <div className={className}>
877
+ <div
878
+ style={{
879
+ color: '#d32f2f',
880
+ padding: '20px',
881
+ background: '#ffebee',
882
+ border: '1px solid #ffcdd2',
883
+ borderRadius: '4px',
884
+ textAlign: 'center',
885
+ }}
886
+ >
887
+ <h3>Configurator Error</h3>
888
+ <p>{state.error}</p>
889
+ <button
890
+ onClick={() => window.location.reload()}
891
+ style={{
892
+ padding: '10px 20px',
893
+ marginTop: '10px',
894
+ border: '1px solid #d32f2f',
895
+ background: '#fff',
896
+ color: '#d32f2f',
897
+ borderRadius: '4px',
898
+ cursor: 'pointer',
899
+ }}
900
+ >
901
+ Reload Page
902
+ </button>
903
+ </div>
904
+ </div>
905
+ );
906
+ }
907
+
908
+ return (
909
+ <div className={className}>
910
+ {/* Loading indicator */}
911
+ {state.isLoading && (
912
+ <div
913
+ style={{
914
+ textAlign: 'center',
915
+ padding: '40px',
916
+ color: '#666',
917
+ background: '#f5f5f5',
918
+ borderRadius: '8px',
919
+ }}
920
+ >
921
+ <div>Loading configurator...</div>
922
+ <div style={{ marginTop: '10px', fontSize: '14px' }}>Please wait while we initialize the 3D viewer</div>
923
+ </div>
924
+ )}
925
+
926
+ {/* Configurator container */}
927
+ <div
928
+ ref={containerRef}
929
+ style={{
930
+ width: '100%',
931
+ height: '600px',
932
+ border: '1px solid #ddd',
933
+ borderRadius: '8px',
934
+ display: state.isLoading ? 'none' : 'block',
935
+ }}
936
+ />
937
+
938
+ {/* Controls */}
939
+ {state.isApiReady && (
940
+ <div style={{ marginTop: '20px' }}>
941
+ <div style={{ marginBottom: '10px', fontWeight: 'bold', color: '#333' }}>Configurator Controls:</div>
942
+ <div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px' }}>
943
+ <button
944
+ onClick={() => changeProduct('product-1')}
945
+ disabled={!state.isApiReady}
946
+ style={{
947
+ padding: '10px 15px',
948
+ border: '1px solid #ccc',
949
+ borderRadius: '4px',
950
+ background: state.isApiReady ? '#f5f5f5' : '#e0e0e0',
951
+ cursor: state.isApiReady ? 'pointer' : 'not-allowed',
952
+ transition: 'background-color 0.2s',
953
+ }}
954
+ onMouseOver={(e) => {
955
+ if (state.isApiReady) e.currentTarget.style.background = '#e5e5e5';
956
+ }}
957
+ onMouseOut={(e) => {
958
+ if (state.isApiReady) e.currentTarget.style.background = '#f5f5f5';
959
+ }}
960
+ >
961
+ Product 1
962
+ </button>
963
+ <button
964
+ onClick={() => changeProduct('product-2')}
965
+ disabled={!state.isApiReady}
966
+ style={{
967
+ padding: '10px 15px',
968
+ border: '1px solid #ccc',
969
+ borderRadius: '4px',
970
+ background: state.isApiReady ? '#f5f5f5' : '#e0e0e0',
971
+ cursor: state.isApiReady ? 'pointer' : 'not-allowed',
972
+ }}
973
+ >
974
+ Product 2
975
+ </button>
976
+ <button
977
+ onClick={() => applyMaterial('slot-1', 'material-red')}
978
+ disabled={!state.isApiReady}
979
+ style={{
980
+ padding: '10px 15px',
981
+ border: '1px solid #ccc',
982
+ borderRadius: '4px',
983
+ background: state.isApiReady ? '#f5f5f5' : '#e0e0e0',
984
+ cursor: state.isApiReady ? 'pointer' : 'not-allowed',
985
+ }}
986
+ >
987
+ Red Material
988
+ </button>
989
+ <button
990
+ onClick={() => applyMaterial('slot-1', 'material-blue')}
991
+ disabled={!state.isApiReady}
992
+ style={{
993
+ padding: '10px 15px',
994
+ border: '1px solid #ccc',
995
+ borderRadius: '4px',
996
+ background: state.isApiReady ? '#f5f5f5' : '#e0e0e0',
997
+ cursor: state.isApiReady ? 'pointer' : 'not-allowed',
998
+ }}
999
+ >
1000
+ Blue Material
1001
+ </button>
1002
+ <button
1003
+ onClick={takeScreenshot}
1004
+ disabled={!state.isApiReady}
1005
+ style={{
1006
+ padding: '10px 15px',
1007
+ border: '1px solid #007bff',
1008
+ borderRadius: '4px',
1009
+ background: state.isApiReady ? '#007bff' : '#6c757d',
1010
+ color: 'white',
1011
+ cursor: state.isApiReady ? 'pointer' : 'not-allowed',
1012
+ }}
1013
+ >
1014
+ 📸 Take Screenshot
1015
+ </button>
1016
+ </div>
1017
+ </div>
1018
+ )}
1019
+ </div>
1020
+ );
1021
+ };
1022
+
1023
+ export default MetaboxConfigurator;
1024
+ ```
1025
+
1026
+ **Key Features of this React Example:**
1027
+
1028
+ - **Proper TypeScript Integration**: Full type safety with proper interfaces
1029
+ - **Error Handling**: Comprehensive error states and user feedback
1030
+ - **Component Cleanup**: Proper unmounting and memory leak prevention
1031
+ - **Unique Container IDs**: Automatic ID generation to avoid conflicts
1032
+ - **Loading States**: Visual feedback during initialization
1033
+ - **Optimized Re-renders**: Uses useCallback to prevent unnecessary re-renders
1034
+ - **Responsive Design**: Flexible button layout with proper styling
1035
+
1036
+ **Usage Example:**
1037
+
1038
+ ```tsx
1039
+ // App.tsx
1040
+ import React from 'react';
1041
+ import MetaboxConfigurator from './components/MetaboxConfigurator';
1042
+ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
1043
+
1044
+ function App() {
1045
+ const handleStateChange = (data: ConfiguratorEnvelope) => {
1046
+ console.log('Configurator state changed:', data);
1047
+ // Update your application state based on configurator changes
1048
+ };
1049
+
1050
+ const handleError = (error: string) => {
1051
+ console.error('Configurator error:', error);
1052
+ // Handle errors (show notifications, log to analytics, etc.)
1053
+ };
1054
+
1055
+ return (
1056
+ <div className="App">
1057
+ <h1>My Product Configurator</h1>
1058
+ <MetaboxConfigurator configuratorUrl="https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id" onStateChange={handleStateChange} onError={handleError} className="my-configurator" />
1059
+ </div>
1060
+ );
1061
+ }
1062
+
1063
+ export default App;
1064
+ ```
1065
+
1066
+ **To Use This Component:**
1067
+
1068
+ 1. Install the package: `npm install @3dsource/metabox-front-api`
1069
+ 2. Replace `'your-configurator-id'` with your actual configurator ID
1070
+ 3. Replace placeholder IDs in the component with your real product, material, and slot IDs
1071
+ 4. Customize the styling by passing a `className` prop or modifying the inline styles
1072
+
1073
+ ### Angular Integration Example
1074
+
1075
+ A complete Angular component with TypeScript showing proper integration, error handling, and lifecycle management.
1076
+
1077
+ ```typescript
1078
+ // metabox-configurator.component.ts
1079
+ import { Component, input, OnInit, output, signal } from '@angular/core';
1080
+ import { Communicator, ConfiguratorEnvelope, GetPdf, GetScreenshot, InitShowcase, integrateMetaBox, PauseShowcase, PlayShowcase, saveImage, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, StopShowcase } from '@3dsource/metabox-front-api';
1081
+
1082
+ interface ConfiguratorState {
1083
+ isLoading: boolean;
1084
+ error: string | null;
1085
+ isApiReady: boolean;
1086
+ }
1087
+
1088
+ @Component({
1089
+ selector: 'app-metabox-configurator',
1090
+ template: `
1091
+ @let _state = state();
1092
+ <div class="configurator-container">
1093
+ <!-- Loading State -->
1094
+ @if (_state.isLoading) {
1095
+ <div class="loading-container">
1096
+ <div class="loading-content">
1097
+ <div class="loading-spinner"></div>
1098
+ <div class="loading-text">Loading configurator...</div>
1099
+ <div class="loading-subtext">Please wait while we initialize the 3D viewer</div>
1100
+ </div>
1101
+ </div>
1102
+ }
1103
+
1104
+ <!-- Error State -->
1105
+ @if (_state.error) {
1106
+ <div class="error-container">
1107
+ <h3>Configurator Error</h3>
1108
+ <p>{{ _state.error }}</p>
1109
+ <button (click)="retryInitialization()" class="retry-button">Retry</button>
1110
+ </div>
1111
+ }
1112
+
1113
+ <!-- Configurator Container -->
1114
+ <div [id]="containerId()" class="configurator-viewport" [hidden]="_state.isLoading || _state.error"></div>
1115
+
1116
+ <!-- Controls -->
1117
+ @if (_state.isApiReady) {
1118
+ <div class="controls">
1119
+ <div class="controls-title">Configurator Controls:</div>
1120
+ <div class="controls-buttons">
1121
+ <button (click)="changeProduct('541f46ab-a86c-48e3-bcfa-f92341483db3')" [disabled]="!_state.isApiReady" class="control-button">Product Change</button>
1122
+ <button (click)="initShowcase('685e656f-32e4-4a63-a9f3-bf3c9e440906')" [disabled]="!_state.isApiReady" class="control-button">Init showcase</button>
1123
+ <button (click)="stopShowcase()" [disabled]="!_state.isApiReady" class="control-button">Stop showcase</button>
1124
+ <button (click)="playShowcase()" [disabled]="!_state.isApiReady" class="control-button">Play showcase</button>
1125
+ <button (click)="pauseShowcase()" [disabled]="!_state.isApiReady" class="control-button">Pause showcase</button>
1126
+ <button (click)="applyMaterial('slot-1', 'material-red')" [disabled]="!_state.isApiReady" class="control-button">Red Material</button>
1127
+ <button (click)="applyMaterial('slot-1', 'material-blue')" [disabled]="!_state.isApiReady" class="control-button">Blue Material</button>
1128
+ <button (click)="getPdf()" [disabled]="!_state.isApiReady" class="control-button">Get PDF</button>
1129
+ <button (click)="takeScreenshot()" [disabled]="!_state.isApiReady" class="control-button screenshot-button">📸 Take Screenshot</button>
1130
+ </div>
1131
+ </div>
1132
+ }
1133
+ </div>
1134
+ `,
1135
+ styles: [
1136
+ `
1137
+ .configurator-container {
1138
+ width: 100%;
1139
+ position: relative;
1140
+ }
1141
+
1142
+ .configurator-viewport {
1143
+ width: 100%;
1144
+ height: 600px;
1145
+ border: 1px solid #ddd;
1146
+ border-radius: 8px;
1147
+ }
1148
+
1149
+ .loading-container {
1150
+ display: flex;
1151
+ align-items: center;
1152
+ justify-content: center;
1153
+ height: 600px;
1154
+ background: #f5f5f5;
1155
+ border: 1px solid #ddd;
1156
+ border-radius: 8px;
1157
+ }
1158
+
1159
+ .loading-content {
1160
+ text-align: center;
1161
+ color: #666;
1162
+ }
1163
+
1164
+ .loading-spinner {
1165
+ width: 40px;
1166
+ height: 40px;
1167
+ border: 4px solid #f3f3f3;
1168
+ border-top: 4px solid #007bff;
1169
+ border-radius: 50%;
1170
+ animation: spin 1s linear infinite;
1171
+ margin: 0 auto 20px;
1172
+ }
1173
+
1174
+ @keyframes spin {
1175
+ 0% {
1176
+ transform: rotate(0deg);
1177
+ }
1178
+ 100% {
1179
+ transform: rotate(360deg);
1180
+ }
1181
+ }
1182
+
1183
+ .loading-text {
1184
+ font-size: 16px;
1185
+ font-weight: 500;
1186
+ margin-bottom: 8px;
1187
+ }
1188
+
1189
+ .loading-subtext {
1190
+ font-size: 14px;
1191
+ opacity: 0.8;
1192
+ }
1193
+
1194
+ .error-container {
1195
+ padding: 40px;
1196
+ text-align: center;
1197
+ background: #ffebee;
1198
+ border: 1px solid #ffcdd2;
1199
+ border-radius: 8px;
1200
+ color: #d32f2f;
1201
+ }
1202
+
1203
+ .error-container h3 {
1204
+ margin: 0 0 16px 0;
1205
+ font-size: 18px;
1206
+ }
1207
+
1208
+ .error-container p {
1209
+ margin: 0 0 20px 0;
1210
+ font-size: 14px;
1211
+ }
1212
+
1213
+ .retry-button {
1214
+ padding: 10px 20px;
1215
+ border: 1px solid #d32f2f;
1216
+ background: #fff;
1217
+ color: #d32f2f;
1218
+ border-radius: 4px;
1219
+ cursor: pointer;
1220
+ font-size: 14px;
1221
+ }
1222
+
1223
+ .retry-button:hover {
1224
+ background: #d32f2f;
1225
+ color: #fff;
1226
+ }
1227
+
1228
+ .controls {
1229
+ margin-top: 20px;
1230
+ }
1231
+
1232
+ .controls-title {
1233
+ font-weight: bold;
1234
+ color: #333;
1235
+ margin-bottom: 10px;
1236
+ }
1237
+
1238
+ .controls-buttons {
1239
+ display: flex;
1240
+ flex-wrap: wrap;
1241
+ gap: 10px;
1242
+ }
1243
+
1244
+ .control-button {
1245
+ padding: 10px 15px;
1246
+ border: 1px solid #ccc;
1247
+ border-radius: 4px;
1248
+ background: #f5f5f5;
1249
+ cursor: pointer;
1250
+ transition: all 0.2s;
1251
+ font-size: 14px;
1252
+ }
1253
+
1254
+ .control-button:hover:not(:disabled) {
1255
+ background: #e5e5e5;
1256
+ }
1257
+
1258
+ .control-button:disabled {
1259
+ opacity: 0.5;
1260
+ cursor: not-allowed;
1261
+ }
1262
+
1263
+ .screenshot-button {
1264
+ border-color: #007bff;
1265
+ background: #007bff;
1266
+ color: white;
1267
+ }
1268
+
1269
+ .screenshot-button:hover:not(:disabled) {
1270
+ background: #0056b3;
1271
+ }
1272
+ `,
1273
+ ],
1274
+ })
1275
+ export class MetaboxConfiguratorComponent implements OnInit {
1276
+ configuratorUrl = input.required<string>();
1277
+ stateChange = output<ConfiguratorEnvelope>();
1278
+ errorFired = output<string>();
1279
+ state = signal<ConfiguratorState>({
1280
+ isLoading: true,
1281
+ error: null,
1282
+ isApiReady: false,
1283
+ });
1284
+ containerId = signal(`metabox-container-${Math.random().toString(36).substring(2, 9)}`);
1285
+ private api: Communicator | null = null;
1286
+
1287
+ ngOnInit(): void {
1288
+ this.initializeConfigurator();
1289
+ }
1290
+
1291
+ // Public methods for external control
1292
+ changeProduct(productId: string): void {
1293
+ if (!this.state().isApiReady || !this.api) {
1294
+ console.warn('API not ready yet');
1295
+ return;
1296
+ }
1297
+
1298
+ try {
1299
+ console.log(`Changing to product: ${productId}`);
1300
+ this.api.sendCommandToMetaBox(new SetProduct(productId));
1301
+ } catch (error) {
1302
+ this.handleError(`Failed to change product: ${this.getErrorMessage(error)}`);
1303
+ }
1304
+ }
1305
+
1306
+ initShowcase(productId: string): void {
1307
+ if (!this.state().isApiReady || !this.api) {
1308
+ console.warn('API not ready yet');
1309
+ return;
1310
+ }
1311
+
1312
+ try {
1313
+ console.log(`Init showcase for product: ${productId}`);
1314
+ this.api.sendCommandToMetaBox(new InitShowcase(productId));
1315
+ } catch (error) {
1316
+ this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
1317
+ }
1318
+ }
1319
+
1320
+ stopShowcase(): void {
1321
+ if (!this.state().isApiReady || !this.api) {
1322
+ console.warn('API not ready yet');
1323
+ return;
1324
+ }
1325
+
1326
+ try {
1327
+ console.log(`Stop showcase`);
1328
+ this.api.sendCommandToMetaBox(new StopShowcase());
1329
+ } catch (error) {
1330
+ this.handleError(`Failed to init showcase for product: ${this.getErrorMessage(error)}`);
1331
+ }
1332
+ }
1333
+
1334
+ playShowcase(): void {
1335
+ if (!this.state().isApiReady || !this.api) {
1336
+ console.warn('API not ready yet');
1337
+ return;
1338
+ }
1339
+
1340
+ try {
1341
+ console.log(`Play showcase`);
1342
+ this.api.sendCommandToMetaBox(new PlayShowcase());
1343
+ } catch {
1344
+ this.handleError(`Failed to play showcase`);
1345
+ }
1346
+ }
1347
+
1348
+ pauseShowcase(): void {
1349
+ if (!this.state().isApiReady || !this.api) {
1350
+ console.warn('API not ready yet');
1351
+ return;
1352
+ }
1353
+
1354
+ try {
1355
+ console.log(`Pause showcase`);
1356
+ this.api.sendCommandToMetaBox(new PauseShowcase());
1357
+ } catch {
1358
+ this.handleError(`Failed to pause showcase`);
1359
+ }
1360
+ }
1361
+
1362
+ applyMaterial(slotId: string, materialId: string): void {
1363
+ if (!this.state().isApiReady || !this.api) {
1364
+ console.warn('API not ready yet');
1365
+ return;
1366
+ }
1367
+
1368
+ try {
1369
+ console.log(`Applying material ${materialId} to slot ${slotId}`);
1370
+ this.api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
1371
+ } catch (error) {
1372
+ this.handleError(`Failed to apply material: ${this.getErrorMessage(error)}`);
1373
+ }
1374
+ }
1375
+
1376
+ takeScreenshot(): void {
1377
+ if (!this.state().isApiReady || !this.api) {
1378
+ console.warn('API not ready yet');
1379
+ return;
1380
+ }
1381
+
1382
+ try {
1383
+ console.log('Taking screenshot...');
1384
+ this.api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
1385
+ } catch (error) {
1386
+ this.handleError(`Failed to take screenshot: ${this.getErrorMessage(error)}`);
1387
+ }
1388
+ }
1389
+
1390
+ getPdf(): void {
1391
+ if (!this.state().isApiReady || !this.api) {
1392
+ console.warn('API not ready yet');
1393
+ return;
1394
+ }
1395
+
1396
+ try {
1397
+ console.log('Generating PDF...');
1398
+ this.api.sendCommandToMetaBox(new GetPdf());
1399
+ } catch (error) {
1400
+ this.handleError(`Failed to generating pdf: ${this.getErrorMessage(error)}`);
1401
+ }
1402
+ }
1403
+
1404
+ retryInitialization(): void {
1405
+ this.updateState({ error: null });
1406
+ this.initializeConfigurator();
1407
+ }
1408
+
1409
+ sendInitCommands() {
1410
+ if (!this.api) {
1411
+ return;
1412
+ }
1413
+
1414
+ this.api.sendCommandToMetaBox(new ShowEmbeddedMenu(true));
1415
+ this.api.sendCommandToMetaBox(new ShowOverlayInterface(true));
1416
+ }
1417
+
1418
+ private initializeConfigurator() {
1419
+ try {
1420
+ this.updateState({ isLoading: true, error: null });
1421
+
1422
+ integrateMetaBox(this.configuratorUrl(), this.containerId(), (apiInstance) => {
1423
+ try {
1424
+ this.api = apiInstance;
1425
+ this.updateState({ isLoading: false, isApiReady: true });
1426
+ this.sendInitCommands();
1427
+ this.setupEventListeners();
1428
+
1429
+ console.log('Angular Metabox Configurator initialized successfully');
1430
+ } catch (error) {
1431
+ this.handleError(`Failed to set up API: ${this.getErrorMessage(error)}`);
1432
+ }
1433
+ });
1434
+ } catch (error) {
1435
+ this.handleError(`Failed to initialize configurator: ${this.getErrorMessage(error)}`);
1436
+ }
1437
+ }
1438
+
1439
+ private setupEventListeners(): void {
1440
+ if (!this.api) {
1441
+ return;
1442
+ }
1443
+ // Listen for configurator state changes
1444
+ this.api.addEventListener('configuratorDataUpdated', (data: ConfiguratorEnvelope) => {
1445
+ console.log('Configurator state updated:', data);
1446
+ this.stateChange.emit(data);
1447
+ });
1448
+
1449
+ // Listen for screenshot completion
1450
+ this.api.addEventListener('screenshot', (imageData: string | null) => {
1451
+ console.log(`Screenshot captured successfully ${imageData ?? ''}`);
1452
+ saveImage(imageData ?? '', `configurator-screenshot-${Date.now()}.png`);
1453
+ });
1454
+ }
1455
+
1456
+ private updateState(updates: Partial<ConfiguratorState>): void {
1457
+ this.state.set({ ...this.state(), ...updates });
1458
+ }
1459
+
1460
+ private handleError(errorMessage: string): void {
1461
+ console.error('Metabox Configurator Error:', errorMessage);
1462
+ this.updateState({ error: errorMessage, isLoading: false });
1463
+ this.errorFired.emit(errorMessage);
1464
+ }
1465
+
1466
+ private getErrorMessage(error: any): string {
1467
+ if (error instanceof Error) {
1468
+ return error.message;
1469
+ }
1470
+ return String(error);
1471
+ }
1472
+ }
1473
+ ```
1474
+
1475
+ **Key Features of this Angular Example:**
1476
+
1477
+ - **Comprehensive Error Handling**: Try-catch blocks and user-friendly error states
1478
+ - **Proper Lifecycle Management**: OnDestroy implementation with cleanup
1479
+ - **Loading States**: Visual feedback with spinner during initialization
1480
+ - **TypeScript Integration**: Full type safety with proper interfaces
1481
+ - **Unique Container IDs**: Automatic ID generation to avoid conflicts
1482
+ - **Event Outputs**: Emits state changes and errors to parent components
1483
+ - **Responsive Design**: Clean, accessible button layout with proper styling
1484
+ - **Component Cleanup**: Prevents memory leaks and handles component destruction
1485
+
1486
+ **Usage Example:**
1487
+
1488
+ ```typescript
1489
+ // app.component.ts
1490
+ import { Component } from '@angular/core';
1491
+ import { ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
1492
+
1493
+ @Component({
1494
+ selector: 'app-root',
1495
+ template: `
1496
+ <div class="app-container">
1497
+ <h1>My Product Configurator</h1>
1498
+ <app-metabox-configurator [configuratorUrl]="configuratorUrl" (stateChange)="onConfiguratorStateChange($event)" (errorFired)="onConfiguratorError($event)"></app-metabox-configurator>
1499
+ </div>
1500
+ `,
1501
+ styles: [
1502
+ `
1503
+ .app-container {
1504
+ max-width: 1200px;
1505
+ margin: 0 auto;
1506
+ padding: 20px;
1507
+ }
1508
+ `,
1509
+ ],
1510
+ })
1511
+ export class AppComponent {
1512
+ configuratorUrl = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id';
1513
+
1514
+ onConfiguratorStateChange(data: ConfiguratorEnvelope): void {
1515
+ console.log('Configurator state changed:', data);
1516
+ // Update your application state based on configurator changes
1517
+ }
1518
+
1519
+ onConfiguratorError(error: string): void {
1520
+ console.error('Configurator error:', error);
1521
+ // Handle errors (show notifications, log to analytics, etc.)
1522
+ }
1523
+ }
1524
+ ```
1525
+
1526
+ **To Use This Component:**
1527
+
1528
+ 1. Install the package: `npm install @3dsource/metabox-front-api`
1529
+ 2. Import the component in your Angular module
1530
+ 3. Replace `'your-configurator-id'` with your actual configurator ID
1531
+ 4. Replace placeholder IDs with your real product, material, and slot IDs
1532
+ 5. Customize the styling by modifying the component styles
1533
+
1534
+ ## Best Practices
1535
+
1536
+ ### 1. Error Handling
1537
+
1538
+ Always implement proper error handling when working with the API:
1539
+
1540
+ ```typescript
1541
+ integrateMetaBox(configuratorUrl, containerId, (api) => {
1542
+ try {
1543
+ // Set up event listeners with error handling
1544
+ api.addEventListener('configuratorDataUpdated', (data) => {
1545
+ try {
1546
+ handleConfiguratorUpdate(data);
1547
+ } catch (error) {
1548
+ console.error('Error handling configurator update:', error);
1549
+ }
1550
+ });
1551
+
1552
+ // Send commands with error handling
1553
+ api.sendCommandToMetaBox(new SetProduct(productId));
1554
+ } catch (error) {
1555
+ console.error('Error initializing configurator:', error);
1556
+ }
1557
+ });
1558
+ ```
1559
+
1560
+ ### 2. State Management
1561
+
1562
+ Keep track of the configurator state for a better user experience:
1563
+
1564
+ ```typescript
1565
+ class ConfiguratorStateManager {
1566
+ private currentState = {
1567
+ product: null,
1568
+ materials: {},
1569
+ environment: null,
1570
+ };
1571
+
1572
+ updateState(data) {
1573
+ this.currentState = { ...this.currentState, ...data };
1574
+ this.saveStateToLocalStorage();
1575
+ }
1576
+
1577
+ saveStateToLocalStorage() {
1578
+ localStorage.setItem('configuratorState', JSON.stringify(this.currentState));
1579
+ }
1580
+
1581
+ loadStateFromLocalStorage() {
1582
+ const saved = localStorage.getItem('configuratorState');
1583
+ return saved ? JSON.parse(saved) : null;
1584
+ }
1585
+ }
1586
+ ```
1587
+
1588
+ ### 3. Performance Optimization
1589
+
1590
+ - **Debounce rapid commands**: Avoid sending too many commands in quick succession
1591
+
1592
+ ```typescript
1593
+ // Debounce example
1594
+ const debouncedMaterialChange = debounce((slotId, materialId) => {
1595
+ api.sendCommandToMetaBox(new SetMaterial(slotId, materialId));
1596
+ }, 300);
1597
+ ```
1598
+
1599
+ ### 4. Responsive Design
1600
+
1601
+ Ensure the configurator works well on different screen sizes:
1602
+
1603
+ ```css
1604
+ #embed3DSource {
1605
+ width: 100%;
1606
+ height: 60vh;
1607
+ min-height: 400px;
1608
+ max-height: 800px;
1609
+ }
1610
+
1611
+ @media (max-width: 768px) {
1612
+ #embed3DSource {
1613
+ height: 50vh;
1614
+ min-height: 300px;
1615
+ }
1616
+ }
1617
+ ```
1618
+
1619
+ ### 5. Loading States
1620
+
1621
+ Provide feedback to users while the configurator loads:
1622
+
1623
+ ```typescript
1624
+ const showLoadingState = () => {
1625
+ document.getElementById('loading').style.display = 'block';
1626
+ };
1627
+
1628
+ const hideLoadingState = () => {
1629
+ document.getElementById('loading').style.display = 'none';
1630
+ };
1631
+
1632
+ integrateMetaBox(configuratorUrl, containerId, (api) => {
1633
+ hideLoadingState();
1634
+ // Continue with initialization
1635
+ });
1636
+ ```
1637
+
1638
+ ## Troubleshooting
1639
+
1640
+ ### Common Issues
1641
+
1642
+ #### 1. Configurator Not Loading
1643
+
1644
+ **Problem**: The configurator iframe doesn't appear or shows a blank screen.
1645
+
1646
+ **Solutions**:
1647
+
1648
+ - Verify the configurator URL is correct and accessible
1649
+ - Ensure the container element exists in the DOM before calling `integrateMetaBox`
1650
+ - Check that you're using HTTPS (required for Unreal Engine)
1651
+ - Verify your configurator ID is valid
1652
+
1653
+ ```typescript
1654
+ // Check if container exists
1655
+ const container = document.getElementById('embed3DSource');
1656
+ if (!container) {
1657
+ console.error('Container element not found');
1658
+ return;
1659
+ }
1660
+
1661
+ // Verify HTTPS
1662
+ if (location.protocol !== 'https:' && location.hostname !== 'localhost') {
1663
+ console.warn('HTTPS is required for Metabox configurator');
1664
+ }
1665
+ ```
1666
+
1667
+ #### 2. Commands Not Working
1668
+
1669
+ **Problem**: Commands sent to the configurator don't have any effect.
1670
+
1671
+ **Solutions**:
1672
+
1673
+ - Ensure the API is fully initialized before sending commands
1674
+ - Check that product/material/environment IDs are correct
1675
+ - Verify the configurator supports the specific command
1676
+
1677
+ ```typescript
1678
+ let apiReady = false;
1679
+
1680
+ integrateMetaBox(configuratorUrl, containerId, (api) => {
1681
+ apiReady = true;
1682
+ // Now it's safe to send commands
1683
+ });
1684
+
1685
+ // Wait for API to be ready
1686
+ const sendCommand = (command) => {
1687
+ if (apiReady && api) {
1688
+ api.sendCommandToMetaBox(command);
1689
+ } else {
1690
+ console.warn('API not ready yet');
1691
+ }
1692
+ };
1693
+ ```
1694
+
1695
+ #### 3. Events Not Firing
1696
+
1697
+ **Problem**: Event listeners don't receive events from the configurator.
1698
+
1699
+ **Solutions**:
1700
+
1701
+ - Set up event listeners immediately after API initialization
1702
+ - Check event names for typos
1703
+ - Ensure the configurator is configured to send the expected events
1704
+
1705
+ ```typescript
1706
+ integrateMetaBox(configuratorUrl, containerId, (api) => {
1707
+ // Set up listeners immediately
1708
+ api.addEventListener('configuratorDataUpdated', (data) => {
1709
+ console.log('Event received:', data);
1710
+ });
1711
+
1712
+ // Test if events are working
1713
+ setTimeout(() => {
1714
+ console.log('Testing event system...');
1715
+ api.sendCommandToMetaBox(new SetProduct('test-product'));
1716
+ }, 1000);
1717
+ });
1718
+ ```
1719
+
1720
+ #### 4. Screenshot/PDF Generation Issues
1721
+
1722
+ **Problem**: Screenshots or PDFs are not generated or are of poor quality.
1723
+
1724
+ **Solutions**:
1725
+
1726
+ - Wait for the scene to fully load before capturing
1727
+ - Use appropriate dimensions for your use case
1728
+ - Ensure the configurator viewport is visible (not hidden or zero-sized)
1729
+
1730
+ ```typescript
1731
+ // Wait for scene to load before screenshot
1732
+ api.addEventListener('configuratorDataUpdated', (data) => {
1733
+ // Scene is loaded, safe to take screenshot
1734
+ setTimeout(() => {
1735
+ api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1920, y: 1080 }));
1736
+ }, 500);
1737
+ });
1738
+ ```
1739
+
1740
+ ### Debug Mode
1741
+
1742
+ Enable debug logging to troubleshoot issues:
1743
+
1744
+ ```typescript
1745
+ // Enable debug mode (if available)
1746
+ window.METABOX_DEBUG = true;
1747
+
1748
+ integrateMetaBox(configuratorUrl, containerId, (api) => {
1749
+ console.log('API initialized:', api);
1750
+
1751
+ // Log all events
1752
+ api.addEventListener('configuratorDataUpdated', (data) => {
1753
+ console.log('State update:', data);
1754
+ });
1755
+
1756
+ api.addEventListener('screenshotReady', (imageData) => {
1757
+ console.log('Render completed, data length:', imageData.length);
1758
+ });
1759
+ });
1760
+ ```
1761
+
1762
+ ### Getting Help
1763
+
1764
+ If you're still experiencing issues:
1765
+
1766
+ 1. Check the browser console for error messages
1767
+ 2. Verify your configurator URL in a separate browser tab
1768
+ 3. Test with a minimal example to isolate the issue
1769
+ 4. Contact support with:
1770
+
1771
+ - Browser version and type
1772
+ - Configurator URL (if possible)
1773
+ - Console error messages
1774
+ - Steps to reproduce the issue
215
1775
 
216
- ```typescript
217
- saveImage(renderData: string, fileName: string): void;
218
- ```
1776
+ ## Browser Compatibility
219
1777
 
220
- #### `ResetCamera`
1778
+ ### Supported Browsers
221
1779
 
222
- - **Description**: Resets the camera to its default position and rotation.
223
- - **Usage**:
1780
+ The Metabox Front API supports modern browsers with ES6 module support:
224
1781
 
225
- ```typescript
226
- api.sendCommandToMetaBox(new ResetCamera());
227
- ```
1782
+ - **Chrome**: 61+ ✅
1783
+ - **Firefox**: 60+ ✅
1784
+ - **Safari**: 10.1+ ✅
1785
+ - **Edge**: 16+ ✅
1786
+ - **Opera**: 48+ ✅
228
1787
 
229
- #### `ApplyZoom`
1788
+ ### Requirements
230
1789
 
231
- - **Description**: Applies zoom to the camera view.
232
- - **Usage**:
1790
+ - **ES6 Modules**: Required for importing the API
1791
+ - **WebGL**: Required for 3D rendering
1792
+ - **HTTPS**: Required for Unreal Engine integration
1793
+ - **Modern JavaScript**: ES2017+ features are used
233
1794
 
234
- ```typescript
235
- api.sendCommandToMetaBox(new ApplyZoom(zoom: number));
236
- ```
1795
+ ## Contributing
237
1796
 
238
- #### `InitShowcase`
1797
+ We welcome contributions to improve the Metabox Front API! Here's how you can help:
239
1798
 
240
- - **Description**: Initializes a showcase with the given showcase ID.
241
- - **Usage**:
1799
+ ### Development Setup
242
1800
 
243
- ```typescript
244
- api.sendCommandToMetaBox(new InitShowcase(showcaseId: string));
245
- ```
1801
+ 1. Clone the repository
1802
+ 2. Install dependencies: `npm install`
1803
+ 3. Build the project: `npm run build`
1804
+ 4. Run tests: `npm test`
246
1805
 
247
- #### `PlayShowcase`
1806
+ ### Guidelines
248
1807
 
249
- - **Description**: Plays the currently loaded showcase.
250
- - **Usage**:
1808
+ - Follow TypeScript best practices
1809
+ - Add tests for new features
1810
+ - Update documentation for API changes
1811
+ - Use semantic commit messages
251
1812
 
252
- ```typescript
253
- api.sendCommandToMetaBox(new PlayShowcase());
254
- ```
1813
+ ### Reporting Issues
255
1814
 
256
- #### `PauseShowcase`
1815
+ When reporting issues, please include:
257
1816
 
258
- - **Description**: Pauses the currently playing showcase.
259
- - **Usage**:
1817
+ - Browser version and operating system
1818
+ - Minimal code example reproducing the issue
1819
+ - Expected vs actual behavior
1820
+ - Console error messages (if any)
260
1821
 
261
- ```typescript
262
- api.sendCommandToMetaBox(new PauseShowcase());
263
- ```
1822
+ ### Feature Requests
264
1823
 
265
- #### `StopShowcase`
1824
+ We're always looking to improve the API. Feel free to suggest new features or enhancements through our issue tracker.
266
1825
 
267
- - **Description**: Stops the currently playing showcase.
268
- - **Usage**:
1826
+ ---
269
1827
 
270
- ```typescript
271
- api.sendCommandToMetaBox(new StopShowcase());
272
- ```
1828
+ **Need help?** Contact our support team or check our documentation for more detailed guides and tutorials.