@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 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
- import { ShowOverlayInterface } from './ShowOverlayInterface';
50
- // Expose API
51
- window.env3DSource = { ...window.env3DSource };
52
- window.env3DSource.apiReady = (api) => {
53
- api.addEventListener('metaboxData', (data) => {
54
- const { action, payload, eventType } = data;
55
- if (action !== FromMetaboxApiAction.bridge) {
56
- return;
57
- }
58
-
59
- if (eventType === 'basicConfiguratorDataWithState') {
60
- updateConfiguratorData(data);
61
- }
62
-
63
- if (eventType === 'fastRender') {
64
- //Catches the render image
65
- saveImage(payload, 'Render.png');
66
- }
67
- });
68
- setupInitialState();
69
- };
70
-
71
- /**
72
- * @see examples, @see documentation
73
- * @param data
74
- */
75
- function updateConfiguratorData(data) {
76
- //Use data on your own
77
- }
78
-
79
- /**
80
- * Setup initial state,
81
- * Executes additional commands as example
82
- */
83
- function setupInitialState() {
84
- // All commands can be used at any time from the moment api is ready and will be buffered automatically
85
- // i.e. GetFastRender and GetPdf will be executed when the viewport is ready
86
-
87
- // Set product
88
- new SetProduct('productId');
89
-
90
- // Set environment
91
- new SetEnvironment('environmentId');
92
-
93
- // Set material
94
- new SetMaterial('productId', 'slotId', 'materialId');
95
-
96
- // Set environment material
97
- new SetEnvironmentMaterial('productId', 'slotId', 'materialId');
98
-
99
- // Toggle embedded menu
100
- new ShowEmbeddedMenu(false);
101
-
102
- // Toggle overlay interface
103
- new ShowOverlayInterface(false);
104
-
105
- //Request Pdf, Will execute as stream is ready, will be auto-downloaded
106
- new GetPdf();
107
-
108
- //Request Fast Render, Will execute as stream is ready, will be sent back as a callback
109
- new GetFastRender('image/png', { x: 1024, y: 1024 });
110
- }
111
-
112
- // Integrate the 3D configurator into your page
113
- /**
114
- * Additional url parameters:
115
- * @see integrateMetaBox
116
- * @type {string}
117
- */
118
- const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
119
- integrateMetaBox(url, 'embed3DSource');
120
- </script>
121
- ```
122
-
123
- ### Documentation for current example
124
-
125
- ### `integrateMetaBox`
126
-
127
- - **Description**: Integrates the MetaBox configurator into the specified container.
128
- - **Usage**:
129
- ```typescript
130
- integrateMetaBox(configuratorUrl: string, containerId: string): void;
131
- ```
132
-
133
- ### `SetEnvironment`
134
-
135
- - **Description**: Sets the environment by ID.
136
- - **Constructor**:
137
- ```typescript
138
- new SetEnvironment(environmentId: string);
139
- ```
140
-
141
- ### `SetMaterial`
142
-
143
- - **Description**: Sets the material for a given product slot.
144
- - **Constructor**:
145
- ```typescript
146
- new SetMaterial(productId: string, slotId: string, materialId: string);
147
- ```
148
-
149
- ### `SetEnvironmentMaterial`
150
-
151
- - **Description**: Sets the material for a given environment slot.
152
- - **Constructor**:
153
- ```typescript
154
- new SetEnvironmentMaterial(productId: string, slotId: string, materialId: string);
155
- ```
156
-
157
- ### `SetProduct`
158
-
159
- - **Description**: Sets the product by ID.
160
- - **Constructor**:
161
- ```typescript
162
- new SetProduct(productId: string);
163
- ```
164
-
165
- ### `ShowEmbeddedMenu`
166
-
167
- - **Description**: Toggles the embedded menu in the MetaBox configurator.
168
- - **Constructor**:
169
- ```typescript
170
- new ShowEmbeddedMenu(visible: boolean);
171
- ```
172
-
173
- ### `ShowOverlayInterface`
174
-
175
- - **Description**: Toggles the overlay interface over Unreal viewport.
176
- - **Constructor**:
177
- ```typescript
178
- new ShowOverlayInterface(visible: boolean);
179
- ```
180
-
181
- ### `GetFastRender`
182
-
183
- - **Description**: Retrieves a fast render of the current view.
184
- - **Usage**:
185
- ```typescript
186
- new GetFastRender(mimeType: string, size?: { x: number, y: number });
187
- ```
188
-
189
- ### `GetPdf`
190
-
191
- - **Description**: Generates a PDF of the current view.
192
- - **Usage**:
193
- ```typescript
194
- new GetPdf();
195
- ```
196
-
197
- ### `saveImage`
198
-
199
- - **Description**: Saves the arrived rendered image to a file using utility function.
200
- - **Usage**:
201
- ```typescript
202
- saveImage(renderData: string, fileName: string): void;
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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) => {
@@ -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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
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
  * };