@3dsource/metabox-modular-configurator-api 0.0.1-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/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2025 3dsource
2
+ All Rights Reserved.
3
+
4
+ This software and associated documentation files (the “Software”) are proprietary
5
+ and confidential. Unauthorized copying, modification, distribution, or any other
6
+ use of the Software, in whole or in part, without the prior written consent of
7
+ the copyright holder is strictly prohibited.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,299 @@
1
+ # Metabox Modular Configurator API
2
+
3
+ This package provides an API for interacting with the Metabox Modular 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-modular-configurator-api --save
9
+ ```
10
+
11
+ then
12
+
13
+ ```typescript
14
+ import { FromMetaboxApiAction, GetScreenshot, GetPdf, integrateMetabox, saveImage, SetEnvironment, SetComponent, SetComponentMaterial, SetComponentType, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ModularConfiguratorEnvelope, ResetCamera, ApplyZoom, InitShowcase, PlayShowcase, PauseShowcase, StopShowcase, UnrealCommand, WatchCallbacks } from '@3dsource/metabox-modular-configurator-api';
15
+ ```
16
+
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):
19
+
20
+ ```javascript
21
+ import { FromMetaboxApiAction, GetScreenshot, GetPdf, integrateMetabox, saveImage, SetEnvironment, SetComponent, SetComponentMaterial, SetComponentType, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ModularConfiguratorEnvelope, ResetCamera, ApplyZoom, InitShowcase, PlayShowcase, PauseShowcase, StopShowcase, UnrealCommand, WatchCallbacks } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api';
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### 1. Create HTML Structure
27
+
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.
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
+
48
+ ```html
49
+ <script type="module">
50
+ import { integrateMetabox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetComponent, SetComponentMaterial, ShowEmbeddedMenu, GetScreenshot, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-modular-configurator-api';
51
+
52
+ class JsIntegrator {
53
+ constructor() {
54
+ const url = 'https://metabox.3dsource.com/metabox-configurator/modular/your-configurator-id?sidebar=false';
55
+ integrateMetabox(url, 'embed3DSource', (api) => this.apiReady(api));
56
+ }
57
+
58
+ apiReady(api) {
59
+ api.addEventListener('configuratorData', (data) => {
60
+ this.updateConfiguratorData(data);
61
+ });
62
+ api.addEventListener('screenshot', (data) => {
63
+ saveImage(data, 'Render.png');
64
+ });
65
+ this.setupInitialState(api);
66
+ }
67
+
68
+ updateConfiguratorData(data) {
69
+ // Use data on your own
70
+ }
71
+
72
+ setupInitialState(api) {
73
+ api.sendCommandToMetaBox(new SetComponent('componentId', 'typeId', true));
74
+ api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
75
+ api.sendCommandToMetaBox(new SetComponentMaterial('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());
80
+ api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
81
+ }
82
+ }
83
+
84
+ new JsIntegrator();
85
+ </script>
86
+ ```
87
+
88
+ TypeScript:
89
+
90
+ ```typescript
91
+ import { ModularConfiguratorEnvelope, integrateMetabox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetComponent, SetComponentMaterial, ShowEmbeddedMenu, GetScreenshot, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from '@3dsource/metabox-modular-configurator-api';
92
+
93
+ class TsIntegrator {
94
+ constructor() {
95
+ const url = 'https://metabox.3dsource.com/metabox-configurator/modular/your-configurator-id?sidebar=false';
96
+ integrateMetabox(url, 'embed3DSource', (api) => this.apiReady(api));
97
+ }
98
+
99
+ apiReady(api: Communicator) {
100
+ api.addEventListener('configuratorData', (data) => {
101
+ this.updateConfiguratorData(data);
102
+ });
103
+ api.addEventListener('screenshot', (data) => {
104
+ saveImage(data, 'Render.png');
105
+ });
106
+ this.setupInitialState(api);
107
+ }
108
+
109
+ updateConfiguratorData(data: ModularConfiguratorEnvelope) {
110
+ // Use data on your own
111
+ }
112
+
113
+ setupInitialState(api: Communicator) {
114
+ api.sendCommandToMetaBox(new SetComponent('componentId', 'typeId', true));
115
+ api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
116
+ api.sendCommandToMetaBox(new SetComponentMaterial('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 }));
122
+ }
123
+ }
124
+
125
+ new TsIntegrator();
126
+ ```
127
+
128
+ ### Documentation for current example
129
+
130
+ #### `integrateMetabox`
131
+
132
+ - **Description**: Integrates the Metabox modular configurator into the specified container.
133
+ - **Usage**:
134
+
135
+ ```typescript
136
+ integrateMetabox(configuratorUrl: string, containerId: string, apiReadyCallback: (api: Communicator) => void);
137
+ ```
138
+
139
+ #### `SetEnvironment`
140
+
141
+ - **Description**: Sets the environment by ID.
142
+ - **Usage**:
143
+
144
+ ```typescript
145
+ api.sendCommandToMetaBox(new SetEnvironment(environmentId: string));
146
+ ```
147
+
148
+ #### `SetComponent`
149
+
150
+ - **Description**: Sets a component by its data (ID, typeId, isRoot).
151
+ - **Usage**:
152
+
153
+ ```typescript
154
+ api.sendCommandToMetaBox(new SetComponent(id: string, typeId: string, isRoot: boolean));
155
+ ```
156
+
157
+ #### `SetComponentMaterial`
158
+
159
+ - **Description**: Sets the material for a given component slot.
160
+ - **Usage**:
161
+
162
+ ```typescript
163
+ api.sendCommandToMetaBox(new SetComponentMaterial(slotId: string, materialId: string));
164
+ ```
165
+
166
+ #### `SetEnvironmentMaterial`
167
+
168
+ - **Description**: Sets the material for a given environment slot.
169
+ - **Usage**:
170
+
171
+ ```typescript
172
+ api.sendCommandToMetaBox(new SetEnvironmentMaterial(slotId: string, materialId: string));
173
+ ```
174
+
175
+ #### `ShowEmbeddedMenu`
176
+
177
+ - **Description**: Toggles the embedded menu in the Metabox configurator.
178
+ - **Usage**:
179
+
180
+ ```typescript
181
+ api.sendCommandToMetaBox(new ShowEmbeddedMenu(visible: boolean));
182
+ ```
183
+
184
+ #### `ShowOverlayInterface`
185
+
186
+ - **Description**: Toggles the overlay interface over Unreal viewport.
187
+ - **Usage**:
188
+
189
+ ```typescript
190
+ api.sendCommandToMetaBox(new ShowOverlayInterface(visible: boolean));
191
+ ```
192
+
193
+ #### `GetScreenshot`
194
+
195
+ - **Description**: Retrieves a screenshot of the current view.
196
+ - **Usage**:
197
+
198
+ ```typescript
199
+ api.sendCommandToMetaBox(new GetScreenshot(mimeType: string, size?: { x: number, y: number }));
200
+ ```
201
+
202
+ #### `GetPdf`
203
+
204
+ - **Description**: Generates a PDF of the current view.
205
+ - **Usage**:
206
+
207
+ ```typescript
208
+ api.sendCommandToMetaBox(new GetPdf());
209
+ ```
210
+
211
+ #### `saveImage`
212
+
213
+ - **Description**: Saves the arrived rendered image to a file using utility function.
214
+ - **Usage**:
215
+
216
+ ```typescript
217
+ saveImage(renderData: string, fileName: string): void;
218
+ ```
219
+
220
+ #### `SetComponentType`
221
+
222
+ - **Description**: Sets the component type for a given component.
223
+ - **Usage**:
224
+
225
+ ```typescript
226
+ api.sendCommandToMetaBox(new SetComponentType(componentId: string, typeId: string));
227
+ ```
228
+
229
+ #### `ResetCamera`
230
+
231
+ - **Description**: Resets the camera to its default position and rotation.
232
+ - **Usage**:
233
+
234
+ ```typescript
235
+ api.sendCommandToMetaBox(new ResetCamera());
236
+ ```
237
+
238
+ #### `ApplyZoom`
239
+
240
+ - **Description**: Applies zoom to the camera view.
241
+ - **Usage**:
242
+
243
+ ```typescript
244
+ api.sendCommandToMetaBox(new ApplyZoom(zoomLevel: number));
245
+ ```
246
+
247
+ #### `InitShowcase`
248
+
249
+ - **Description**: Initializes a showcase with the given showcase ID.
250
+ - **Usage**:
251
+
252
+ ```typescript
253
+ api.sendCommandToMetaBox(new InitShowcase(showcaseId: string));
254
+ ```
255
+
256
+ #### `PlayShowcase`
257
+
258
+ - **Description**: Plays the currently loaded showcase.
259
+ - **Usage**:
260
+
261
+ ```typescript
262
+ api.sendCommandToMetaBox(new PlayShowcase());
263
+ ```
264
+
265
+ #### `PauseShowcase`
266
+
267
+ - **Description**: Pauses the currently playing showcase.
268
+ - **Usage**:
269
+
270
+ ```typescript
271
+ api.sendCommandToMetaBox(new PauseShowcase());
272
+ ```
273
+
274
+ #### `StopShowcase`
275
+
276
+ - **Description**: Stops the currently playing showcase.
277
+ - **Usage**:
278
+
279
+ ```typescript
280
+ api.sendCommandToMetaBox(new StopShowcase());
281
+ ```
282
+
283
+ #### `UnrealCommand`
284
+
285
+ - **Description**: Sends a custom command directly to the Unreal Engine.
286
+ - **Usage**:
287
+
288
+ ```typescript
289
+ api.sendCommandToMetaBox(new UnrealCommand(command: string));
290
+ ```
291
+
292
+ #### `WatchCallbacks`
293
+
294
+ - **Description**: Enables watching for callbacks from the Unreal Engine.
295
+ - **Usage**:
296
+
297
+ ```typescript
298
+ api.sendCommandToMetaBox(new WatchCallbacks());
299
+ ```