@3dsource/metabox-front-api 0.0.16 → 0.0.18
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 +202 -203
- package/dist/actions/GetFastRender.d.ts +1 -1
- package/dist/actions/GetPdf.d.ts +1 -1
- package/dist/actions/SetEnvironment.d.ts +1 -1
- package/dist/actions/SetEnvironmentMaterial.d.ts +1 -1
- package/dist/actions/SetMaterial.d.ts +1 -1
- package/dist/actions/SetProduct.d.ts +1 -1
- package/dist/actions/ShowEmbeddedMenu.d.ts +1 -1
- package/dist/actions/ShowOverlayInterface.d.ts +1 -1
- package/dist/index.esm.js +18 -117
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +18 -117
- package/dist/index.umd.js.map +1 -1
- package/dist/interfaces/FromMetaboxMessagePayloads.d.ts +11 -11
- package/dist/interfaces/ToMetaboxMessagePayloads.d.ts +4 -2
- package/dist/interfaces/application-device-types.d.ts +1 -1
- package/dist/lib/integrateMetaBox.d.ts +1 -1
- package/package.json +48 -45
package/README.md
CHANGED
|
@@ -1,203 +1,202 @@
|
|
|
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 recommended method
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install @3dsource/metabox-front-api --save
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
then
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from '@3dsource/metabox-front-api';
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
**OR** work with direct import from `NPM` using `CDN` network `unpkg.com` or `jsdelivr.net` (you can also download package and use it locally):
|
|
18
|
-
|
|
19
|
-
```javascript
|
|
20
|
-
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
**We strongly recommend using the first option with npm and locking it to the latest version at the time of integration, as the second option can change rapidly and may cause unexpected behavior in your existing code.**
|
|
24
|
-
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
### 1. Create HTML Structure
|
|
28
|
-
|
|
29
|
-
Ensure your HTML page has the following structure, where the MetaBox Configurator will be integrated.
|
|
30
|
-
You **MUST** control CSS style of `embed3DSource` element to make the configurator responsive and fit your needs on your own.
|
|
31
|
-
|
|
32
|
-
```html
|
|
33
|
-
<div id="embed3DSource">
|
|
34
|
-
<!-- Your Configurator iframe will be embedded here -->
|
|
35
|
-
</div>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### 2. Include Required Scripts
|
|
39
|
-
|
|
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
|
|
47
|
-
<script type="module">
|
|
48
|
-
import { integrateMetaBox, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
window.env3DSource =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* @
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
* @
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
- **
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- **
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- **
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
- **
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
- **
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
- **
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
- **
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
- **
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
- **
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
- **
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
```
|
|
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 recommended method
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @3dsource/metabox-front-api --save
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
then
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from '@3dsource/metabox-front-api';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**OR** work with direct import from `NPM` using `CDN` network `unpkg.com` or `jsdelivr.net` (you can also download package and use it locally):
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**We strongly recommend using the first option with npm and locking it to the latest version at the time of integration, as the second option can change rapidly and may cause unexpected behavior in your existing code.**
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### 1. Create HTML Structure
|
|
28
|
+
|
|
29
|
+
Ensure your HTML page has the following structure, where the MetaBox Configurator will be integrated.
|
|
30
|
+
You **MUST** control CSS style of `embed3DSource` element to make the configurator responsive and fit your needs on your own.
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<div id="embed3DSource">
|
|
34
|
+
<!-- Your Configurator iframe will be embedded here -->
|
|
35
|
+
</div>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. Include Required Scripts
|
|
39
|
+
|
|
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
|
|
47
|
+
<script type="module">
|
|
48
|
+
import { integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest';
|
|
49
|
+
// Expose API
|
|
50
|
+
window.env3DSource = { ...window.env3DSource };
|
|
51
|
+
window.env3DSource.apiReady = (api) => {
|
|
52
|
+
api.addEventListener('metaboxData', (data) => {
|
|
53
|
+
const { action, payload, eventType } = data;
|
|
54
|
+
if (action !== FromMetaboxApiAction.bridge) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (eventType === 'basicConfiguratorDataWithState') {
|
|
59
|
+
updateConfiguratorData(data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (eventType === 'fastRender') {
|
|
63
|
+
//Catches the render image
|
|
64
|
+
saveImage(payload, 'Render.png');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
setupInitialState();
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @see examples, @see documentation
|
|
72
|
+
* @param data
|
|
73
|
+
*/
|
|
74
|
+
function updateConfiguratorData(data) {
|
|
75
|
+
//Use data on your own
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Setup initial state,
|
|
80
|
+
* Executes additional commands as example
|
|
81
|
+
*/
|
|
82
|
+
function setupInitialState() {
|
|
83
|
+
// All commands can be used at any time from the moment api is ready and will be buffered automatically
|
|
84
|
+
// i.e. GetFastRender and GetPdf will be executed when the viewport is ready
|
|
85
|
+
|
|
86
|
+
// Set product
|
|
87
|
+
new SetProduct('productId');
|
|
88
|
+
|
|
89
|
+
// Set environment
|
|
90
|
+
new SetEnvironment('environmentId');
|
|
91
|
+
|
|
92
|
+
// Set material
|
|
93
|
+
new SetMaterial('productId', 'slotId', 'materialId');
|
|
94
|
+
|
|
95
|
+
// Set environment material
|
|
96
|
+
new SetEnvironmentMaterial('productId', 'slotId', 'materialId');
|
|
97
|
+
|
|
98
|
+
// Toggle embedded menu
|
|
99
|
+
new ShowEmbeddedMenu(false);
|
|
100
|
+
|
|
101
|
+
// Toggle overlay interface
|
|
102
|
+
new ShowOverlayInterface(false);
|
|
103
|
+
|
|
104
|
+
//Request Pdf, Will execute as stream is ready, will be auto-downloaded
|
|
105
|
+
new GetPdf();
|
|
106
|
+
|
|
107
|
+
//Request Fast Render, Will execute as stream is ready, will be sent back as a callback
|
|
108
|
+
new GetFastRender('image/png', { x: 1024, y: 1024 });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Integrate the 3D configurator into your page
|
|
112
|
+
/**
|
|
113
|
+
* Additional url parameters:
|
|
114
|
+
* @see integrateMetaBox
|
|
115
|
+
* @type {string}
|
|
116
|
+
*/
|
|
117
|
+
const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
|
|
118
|
+
integrateMetaBox(url, 'embed3DSource');
|
|
119
|
+
</script>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Documentation for current example
|
|
123
|
+
|
|
124
|
+
### `integrateMetaBox`
|
|
125
|
+
|
|
126
|
+
- **Description**: Integrates the MetaBox configurator into the specified container.
|
|
127
|
+
- **Usage**:
|
|
128
|
+
```typescript
|
|
129
|
+
integrateMetaBox(configuratorUrl: string, containerId: string): void;
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `SetEnvironment`
|
|
133
|
+
|
|
134
|
+
- **Description**: Sets the environment by ID.
|
|
135
|
+
- **Constructor**:
|
|
136
|
+
```typescript
|
|
137
|
+
new SetEnvironment(environmentId: string);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### `SetMaterial`
|
|
141
|
+
|
|
142
|
+
- **Description**: Sets the material for a given product slot.
|
|
143
|
+
- **Constructor**:
|
|
144
|
+
```typescript
|
|
145
|
+
new SetMaterial(productId: string, slotId: string, materialId: string);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `SetEnvironmentMaterial`
|
|
149
|
+
|
|
150
|
+
- **Description**: Sets the material for a given environment slot.
|
|
151
|
+
- **Constructor**:
|
|
152
|
+
```typescript
|
|
153
|
+
new SetEnvironmentMaterial(productId: string, slotId: string, materialId: string);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `SetProduct`
|
|
157
|
+
|
|
158
|
+
- **Description**: Sets the product by ID.
|
|
159
|
+
- **Constructor**:
|
|
160
|
+
```typescript
|
|
161
|
+
new SetProduct(productId: string);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `ShowEmbeddedMenu`
|
|
165
|
+
|
|
166
|
+
- **Description**: Toggles the embedded menu in the MetaBox configurator.
|
|
167
|
+
- **Constructor**:
|
|
168
|
+
```typescript
|
|
169
|
+
new ShowEmbeddedMenu(visible: boolean);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### `ShowOverlayInterface`
|
|
173
|
+
|
|
174
|
+
- **Description**: Toggles the overlay interface over Unreal viewport.
|
|
175
|
+
- **Constructor**:
|
|
176
|
+
```typescript
|
|
177
|
+
new ShowOverlayInterface(visible: boolean);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `GetFastRender`
|
|
181
|
+
|
|
182
|
+
- **Description**: Retrieves a fast render of the current view.
|
|
183
|
+
- **Usage**:
|
|
184
|
+
```typescript
|
|
185
|
+
new GetFastRender(mimeType: string, size?: { x: number, y: number });
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `GetPdf`
|
|
189
|
+
|
|
190
|
+
- **Description**: Generates a PDF of the current view.
|
|
191
|
+
- **Usage**:
|
|
192
|
+
```typescript
|
|
193
|
+
new GetPdf();
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### `saveImage`
|
|
197
|
+
|
|
198
|
+
- **Description**: Saves the arrived rendered image to a file using utility function.
|
|
199
|
+
- **Usage**:
|
|
200
|
+
```typescript
|
|
201
|
+
saveImage(renderData: string, fileName: string): void;
|
|
202
|
+
```
|
|
@@ -15,7 +15,7 @@ export type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
|
15
15
|
* **Important**: Invoking this action will buffer it until the viewport is ready. Only then will the request be processed.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
-
* import { GetFastRender,saveImage } from 'https://
|
|
18
|
+
* import { GetFastRender,saveImage } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
19
19
|
* window.env3DSource.apiReady = (api) => {
|
|
20
20
|
* // Listen for events from the MetaBox API
|
|
21
21
|
* api.addEventListener('metaboxData', (data) => {
|
package/dist/actions/GetPdf.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { ApiAction } from './ApiAction';
|
|
|
10
10
|
* **Important**: Invoking this action will buffer it until the viewport is ready. Only then will the request be processed.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* import { GetPdf } from 'https://
|
|
13
|
+
* import { GetPdf } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
14
14
|
* window.env3DSource.apiReady = (api) => {
|
|
15
15
|
* new GetPdf();
|
|
16
16
|
* };
|
|
@@ -7,7 +7,7 @@ import { ApiAction } from './ApiAction';
|
|
|
7
7
|
* This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* import { SetEnvironment } from 'https://
|
|
10
|
+
* import { SetEnvironment } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
11
11
|
* window.env3DSource.apiReady = (api) => {
|
|
12
12
|
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
13
13
|
* new SetEnvironment('55555555-1234-1234-1234-01234567890');
|
|
@@ -8,7 +8,7 @@ import { ApiAction } from './ApiAction';
|
|
|
8
8
|
* This action sends a message to the MetaBox API to update the material on a specific environment slot using the provided identifiers.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* import { SetEnvironmentMaterial } from 'https://
|
|
11
|
+
* import { SetEnvironmentMaterial } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
12
12
|
* window.env3DSource.apiReady = (api) => {
|
|
13
13
|
* new SetEnvironmentMaterial(
|
|
14
14
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
@@ -8,7 +8,7 @@ import { ApiAction } from './ApiAction';
|
|
|
8
8
|
* This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* import { SetMaterial } from 'https://
|
|
11
|
+
* import { SetMaterial } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
12
12
|
* window.env3DSource.apiReady = (api) => {
|
|
13
13
|
* new SetMaterial(
|
|
14
14
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
@@ -8,7 +8,7 @@ import { ApiAction } from './ApiAction';
|
|
|
8
8
|
* This action sends a message to the MetaBox API to set a product using the provided product ID.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* import { SetProduct } from 'https://
|
|
11
|
+
* import { SetProduct } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
12
12
|
* window.env3DSource.apiReady = (api) => {
|
|
13
13
|
* new SetProduct(
|
|
14
14
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3'
|
|
@@ -8,7 +8,7 @@ import { ApiAction } from './ApiAction';
|
|
|
8
8
|
* This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* import { ShowEmbeddedMenu } from 'https://
|
|
11
|
+
* import { ShowEmbeddedMenu } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
12
12
|
* window.env3DSource.apiReady = (api) => {
|
|
13
13
|
* new ShowEmbeddedMenu(true);
|
|
14
14
|
* };
|
|
@@ -8,7 +8,7 @@ import { ApiAction } from './ApiAction';
|
|
|
8
8
|
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* import { ShowOverlayInterface } from 'https://
|
|
11
|
+
* import { ShowOverlayInterface } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
12
12
|
* window.env3DSource.apiReady = (api) => {
|
|
13
13
|
* new ShowOverlayInterface(true);
|
|
14
14
|
* };
|