@preference-sl/pref-viewer 2.11.0-beta.1 → 2.11.0-beta.11
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/package.json +12 -8
- package/src/babylonjs-animation-controller.js +235 -0
- package/src/babylonjs-animation-opening-menu.js +360 -0
- package/src/babylonjs-animation-opening.js +496 -0
- package/src/babylonjs-controller.js +343 -86
- package/src/css/pref-viewer-2d.css +39 -0
- package/src/css/pref-viewer-3d.css +28 -0
- package/src/css/pref-viewer-dialog.css +105 -0
- package/src/css/pref-viewer.css +11 -0
- package/src/file-storage.js +166 -39
- package/src/index.js +318 -81
- package/src/pref-viewer-2d.js +67 -47
- package/src/pref-viewer-3d.js +328 -84
- package/src/pref-viewer-dialog.js +140 -0
package/src/pref-viewer-3d.js
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
|
-
import { ContainerData, MaterialData
|
|
1
|
+
import { CameraData, ContainerData, MaterialData } from "./pref-viewer-3d-data.js";
|
|
2
2
|
import BabylonJSController from "./babylonjs-controller.js";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* PrefViewer3D - Custom Web Component for interactive 3D visualization and configuration.
|
|
6
|
+
*
|
|
7
|
+
* Overview:
|
|
8
|
+
* - Encapsulates a Babylon.js-powered 3D viewer for displaying models, environments, and materials.
|
|
9
|
+
* - Manages internal state for containers (model, environment, materials) and options (camera, materials).
|
|
10
|
+
* - Handles asset loading, configuration, and option updates through attributes and public methods.
|
|
11
|
+
* - Provides API for showing/hiding the viewer, model, and environment, and for downloading assets.
|
|
12
|
+
* - Emits custom events for loading, loaded, and option-setting states.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* - Use as a custom HTML element: <pref-viewer-3d ...>
|
|
16
|
+
* - Configure via attributes (config, options, show-model, show-scene, visible).
|
|
17
|
+
* - Control viewer state and assets via public methods.
|
|
18
|
+
*
|
|
19
|
+
* Observed Attributes:
|
|
20
|
+
* - show-model: Show or hide the 3D model ("true"/"false").
|
|
21
|
+
* - show-scene: Show or hide the 3D environment ("true"/"false").
|
|
22
|
+
* - visible: Show or hide the entire viewer ("true"/"false").
|
|
23
|
+
*
|
|
24
|
+
* Public Methods:
|
|
25
|
+
* - show(): Shows the 3D viewer component.
|
|
26
|
+
* - hide(): Hides the 3D viewer component.
|
|
27
|
+
* - load(config): Loads the provided configuration into the viewer.
|
|
28
|
+
* - setOptions(options): Sets viewer options such as camera and materials.
|
|
29
|
+
* - showModel(): Shows the 3D model.
|
|
30
|
+
* - hideModel(): Hides the 3D model.
|
|
31
|
+
* - showEnvironment(): Shows the 3D environment/scene.
|
|
32
|
+
* - hideEnvironment(): Hides the 3D environment/scene.
|
|
33
|
+
* - downloadModelGLB(): Downloads the current 3D model as a GLB file.
|
|
34
|
+
* - downloadModelGLTF(): Downloads the current 3D model as a glTF ZIP file.
|
|
35
|
+
* - downloadModelUSDZ(): Downloads the current 3D model as a USDZ file.
|
|
36
|
+
* - downloadModelAndSceneGLB(): Downloads both the model and scene as a GLB file.
|
|
37
|
+
* - downloadModelAndSceneGLTF(): Downloads both the model and scene as a glTF ZIP file.
|
|
38
|
+
* - downloadModelAndSceneUSDZ(): Downloads both the model and scene as a USDZ file.
|
|
39
|
+
* - downloadSceneGLB(): Downloads the environment as a GLB file.
|
|
40
|
+
* - downloadSceneGLTF(): Downloads the environment as a glTF ZIP file.
|
|
41
|
+
* - downloadSceneUSDZ(): Downloads the environment as a USDZ file.
|
|
42
|
+
*
|
|
43
|
+
* Public Properties:
|
|
44
|
+
* - isInitialized: Indicates whether the component has completed initialization.
|
|
45
|
+
* - isLoaded: Indicates whether the GLTF/GLB content is loaded and ready.
|
|
46
|
+
* - isVisible: Indicates whether the component is currently visible.
|
|
47
|
+
*
|
|
48
|
+
* Events:
|
|
49
|
+
* - "scene-loading": Dispatched when a loading operation starts.
|
|
50
|
+
* - "scene-loaded": Dispatched when a loading operation completes.
|
|
51
|
+
* - "scene-setting-options": Dispatched when viewer options are being set.
|
|
52
|
+
* - "scene-set-options": Dispatched when viewer options have been set.
|
|
53
|
+
*
|
|
54
|
+
* Notes:
|
|
55
|
+
* - Internal state and heavy initialization are handled in connectedCallback.
|
|
56
|
+
* - Designed for extensibility and integration in product configurators and visualization tools.
|
|
57
|
+
* - All resource management and rendering operations are performed asynchronously for performance.
|
|
58
|
+
*/
|
|
4
59
|
export class PrefViewer3D extends HTMLElement {
|
|
5
60
|
// State flags
|
|
6
61
|
#isInitialized = false;
|
|
@@ -15,7 +70,7 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
15
70
|
#babylonJSController = null; // BabylonJSController instance
|
|
16
71
|
|
|
17
72
|
/**
|
|
18
|
-
* Create a new instance of the
|
|
73
|
+
* Create a new instance of the 3D viewer component.
|
|
19
74
|
* The constructor only calls super(); heavy initialization happens in connectedCallback.
|
|
20
75
|
*/
|
|
21
76
|
constructor() {
|
|
@@ -27,31 +82,22 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
27
82
|
* @returns {string[]} Array of attribute names that trigger attributeChangedCallback.
|
|
28
83
|
*/
|
|
29
84
|
static get observedAttributes() {
|
|
30
|
-
return ["
|
|
85
|
+
return ["show-model", "show-scene", "visible"];
|
|
31
86
|
}
|
|
32
87
|
|
|
33
88
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param {string} name -
|
|
36
|
-
* @param {string|null} _old -
|
|
37
|
-
* @param {string|null} value -
|
|
89
|
+
* Handles changes to observed attributes and updates the component state accordingly.
|
|
90
|
+
* @param {string} name - The name of the changed attribute.
|
|
91
|
+
* @param {string|null} _old - The previous value of the attribute.
|
|
92
|
+
* @param {string|null} value - The new value of the attribute.
|
|
38
93
|
* @returns {void}
|
|
39
94
|
* @description
|
|
40
|
-
* - "
|
|
95
|
+
* - "show-model": shows or hides the model according to the attribute value ("true"/"false").
|
|
96
|
+
* - "show-scene": shows or hides the scene according to the attribute value ("true"/"false").
|
|
41
97
|
* - "visible": shows or hides the component according to the attribute value ("true"/"false").
|
|
42
98
|
*/
|
|
43
99
|
attributeChangedCallback(name, _old, value) {
|
|
44
100
|
switch (name) {
|
|
45
|
-
case "visible":
|
|
46
|
-
if (_old === value) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (value === "true" && this.#isVisible === false) {
|
|
50
|
-
this.show();
|
|
51
|
-
} else if (value === "false" && this.#isVisible === true) {
|
|
52
|
-
this.hide();
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
101
|
case "show-model":
|
|
56
102
|
if (_old === value) {
|
|
57
103
|
return;
|
|
@@ -66,12 +112,23 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
66
112
|
const showScene = value.toLowerCase?.() === "true";
|
|
67
113
|
showScene ? this.showEnvironment() : this.hideEnvironment();
|
|
68
114
|
break;
|
|
115
|
+
case "visible":
|
|
116
|
+
if (_old === value) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (value === "true" && this.#isVisible === false) {
|
|
120
|
+
this.show();
|
|
121
|
+
} else if (value === "false" && this.#isVisible === true) {
|
|
122
|
+
this.hide();
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
69
125
|
}
|
|
70
126
|
}
|
|
71
127
|
|
|
72
128
|
/**
|
|
73
|
-
* Called when the element is
|
|
74
|
-
*
|
|
129
|
+
* Called when the element is added to the DOM.
|
|
130
|
+
* Creates the DOM structure, sets initial visibility, initializes component data, and sets up the BabylonJSController.
|
|
131
|
+
* Performs heavy initialization tasks required for the 3D viewer.
|
|
75
132
|
* @returns {void}
|
|
76
133
|
*/
|
|
77
134
|
connectedCallback() {
|
|
@@ -81,6 +138,11 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
81
138
|
this.#initializeBabylonJS();
|
|
82
139
|
}
|
|
83
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Called when the element is removed from the DOM.
|
|
143
|
+
* Disables the BabylonJSController to clean up resources and event listeners associated with the 3D viewer.
|
|
144
|
+
* @returns {void}
|
|
145
|
+
*/
|
|
84
146
|
disconnectedCallback() {
|
|
85
147
|
if (this.#babylonJSController) {
|
|
86
148
|
this.#babylonJSController.disable();
|
|
@@ -98,7 +160,8 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
98
160
|
this.#canvas = document.createElement("canvas");
|
|
99
161
|
this.#wrapper.appendChild(this.#canvas);
|
|
100
162
|
const style = document.createElement("style");
|
|
101
|
-
|
|
163
|
+
const cssUrl = new URL("./css/pref-viewer-3d.css", import.meta.url);
|
|
164
|
+
style.textContent = `@import "${cssUrl}";`;
|
|
102
165
|
this.append(style);
|
|
103
166
|
}
|
|
104
167
|
|
|
@@ -113,6 +176,12 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
113
176
|
visible ? this.show() : this.hide();
|
|
114
177
|
}
|
|
115
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Initializes the internal data structure for containers and options used by the 3D viewer.
|
|
181
|
+
* Sets up default states for model, environment, materials, camera, and material options.
|
|
182
|
+
* @private
|
|
183
|
+
* @returns {void}
|
|
184
|
+
*/
|
|
116
185
|
#initializeData() {
|
|
117
186
|
this.#data = {
|
|
118
187
|
containers: {
|
|
@@ -132,17 +201,34 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
132
201
|
};
|
|
133
202
|
}
|
|
134
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Initializes the BabylonJSController and enables the Babylon.js engine for rendering.
|
|
206
|
+
* @private
|
|
207
|
+
* @returns {void}
|
|
208
|
+
*/
|
|
135
209
|
#initializeBabylonJS() {
|
|
136
210
|
this.#babylonJSController = new BabylonJSController(this.#canvas, this.#data.containers, this.#data.options);
|
|
137
211
|
this.#babylonJSController.enable();
|
|
138
212
|
}
|
|
139
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Resets update flags for all containers and material/camera options after loading or setting options.
|
|
216
|
+
* @private
|
|
217
|
+
* @returns {void}
|
|
218
|
+
*/
|
|
140
219
|
#resetUpdateFlags() {
|
|
141
|
-
Object.values(this.#data.containers).forEach(container => container.reset());
|
|
142
|
-
Object.values(this.#data.options.materials).forEach(material => material.reset());
|
|
220
|
+
Object.values(this.#data.containers).forEach((container) => container.reset());
|
|
221
|
+
Object.values(this.#data.options.materials).forEach((material) => material.reset());
|
|
143
222
|
this.#data.options.camera.reset();
|
|
144
223
|
}
|
|
145
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Checks if any container (model, environment, materials) needs to be updated based on the provided config.
|
|
227
|
+
* Sets pending state for containers if storage or visibility changes are detected.
|
|
228
|
+
* @private
|
|
229
|
+
* @param {object} config - Configuration object containing model, scene, and materials info.
|
|
230
|
+
* @returns {void}
|
|
231
|
+
*/
|
|
146
232
|
#checkNeedToUpdateContainers(config) {
|
|
147
233
|
const modelState = this.#data.containers.model;
|
|
148
234
|
const modelHasStorage = !!config.model?.storage;
|
|
@@ -170,6 +256,13 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
170
256
|
}
|
|
171
257
|
}
|
|
172
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Checks if the camera option needs to be updated based on the provided options.
|
|
261
|
+
* Sets pending state for the camera if a change is detected.
|
|
262
|
+
* @private
|
|
263
|
+
* @param {object} options - Options object containing camera info.
|
|
264
|
+
* @returns {boolean} True if camera needs update, false otherwise.
|
|
265
|
+
*/
|
|
173
266
|
#checkNeedToUpdateCamera(options) {
|
|
174
267
|
if (!options || options.camera === undefined || options.camera === "") {
|
|
175
268
|
return false;
|
|
@@ -182,6 +275,13 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
182
275
|
return needUpdate;
|
|
183
276
|
}
|
|
184
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Checks if any material option needs to be updated based on the provided options.
|
|
280
|
+
* Sets pending state for materials if changes are detected.
|
|
281
|
+
* @private
|
|
282
|
+
* @param {object} options - Options object containing material info.
|
|
283
|
+
* @returns {boolean} True if any material needs update, false otherwise.
|
|
284
|
+
*/
|
|
185
285
|
#checkNeedToUpdateMaterials(options) {
|
|
186
286
|
if (!options) {
|
|
187
287
|
return false;
|
|
@@ -201,24 +301,34 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
201
301
|
return someNeedUpdate;
|
|
202
302
|
}
|
|
203
303
|
|
|
204
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Dispatches a "prefviewer3d-loading" event and updates loading state attributes.
|
|
306
|
+
* Used internally when a loading operation starts.
|
|
307
|
+
* @private
|
|
308
|
+
* @returns {void}
|
|
309
|
+
*/
|
|
205
310
|
#onLoading() {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
311
|
+
const customEventOptions = {
|
|
312
|
+
bubbles: true, // indicates whether the event bubbles up through the DOM tree or not
|
|
313
|
+
cancelable: true, // indicates whether the event can be canceled, and therefore prevented as if the event never happened
|
|
314
|
+
composed: false, // indicates whether or not the event will propagate across the shadow DOM boundary into the standard DOM
|
|
315
|
+
};
|
|
316
|
+
this.dispatchEvent(new CustomEvent("scene-loading", customEventOptions));
|
|
317
|
+
|
|
214
318
|
this.removeAttribute("loaded");
|
|
215
319
|
this.setAttribute("loading", "");
|
|
216
|
-
|
|
320
|
+
|
|
217
321
|
if (this.#isLoaded === true) {
|
|
218
322
|
this.#isLoaded = false;
|
|
219
323
|
}
|
|
220
324
|
}
|
|
221
|
-
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Dispatches a "prefviewer3d-loaded" event with details about what was loaded and updates state attributes.
|
|
328
|
+
* Used internally when a loading operation completes.
|
|
329
|
+
* @private
|
|
330
|
+
* @returns {object} Detail object describing what was tried and what succeeded.
|
|
331
|
+
*/
|
|
222
332
|
#onLoaded() {
|
|
223
333
|
const toLoadDetail = {
|
|
224
334
|
container_model: this.#data.containers.model.isPending,
|
|
@@ -245,42 +355,52 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
245
355
|
success: loadedDetail,
|
|
246
356
|
};
|
|
247
357
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
358
|
+
const customEventOptions = {
|
|
359
|
+
bubbles: true,
|
|
360
|
+
cancelable: true,
|
|
361
|
+
composed: false,
|
|
362
|
+
detail: detail,
|
|
363
|
+
};
|
|
364
|
+
this.dispatchEvent(new CustomEvent("scene-loaded", customEventOptions));
|
|
365
|
+
|
|
257
366
|
this.removeAttribute("loading");
|
|
258
367
|
this.setAttribute("loaded", "");
|
|
259
|
-
|
|
368
|
+
|
|
260
369
|
this.#resetUpdateFlags();
|
|
261
370
|
this.#isLoaded = true;
|
|
262
371
|
|
|
263
372
|
return detail;
|
|
264
373
|
}
|
|
265
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Dispatches a "prefviewer3d-setting-options" event and updates loading state attributes.
|
|
377
|
+
* Used internally when options are being set.
|
|
378
|
+
* @private
|
|
379
|
+
* @returns {void}
|
|
380
|
+
*/
|
|
266
381
|
#onSettingOptions() {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
382
|
+
const customEventOptions = {
|
|
383
|
+
bubbles: true,
|
|
384
|
+
cancelable: true,
|
|
385
|
+
composed: false,
|
|
386
|
+
};
|
|
387
|
+
this.dispatchEvent(new CustomEvent("scene-setting-options", customEventOptions));
|
|
388
|
+
|
|
275
389
|
this.removeAttribute("loaded");
|
|
276
390
|
this.setAttribute("loading", "");
|
|
277
|
-
|
|
391
|
+
|
|
278
392
|
if (this.#isLoaded === true) {
|
|
279
393
|
this.#isLoaded = false;
|
|
280
394
|
}
|
|
281
395
|
}
|
|
282
|
-
|
|
283
|
-
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Dispatches a "prefviewer3d-loaded" event with details about what options were set and updates state attributes.
|
|
399
|
+
* Used internally when options have been set.
|
|
400
|
+
* @private
|
|
401
|
+
* @returns {object} Detail object describing what was tried and what succeeded.
|
|
402
|
+
*/
|
|
403
|
+
#onSetOptions() {
|
|
284
404
|
const toSetDetail = {
|
|
285
405
|
camera: this.#data.options.camera.isPending,
|
|
286
406
|
innerWallMaterial: this.#data.options.materials.innerWall.isPending,
|
|
@@ -299,19 +419,18 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
299
419
|
tried: toSetDetail,
|
|
300
420
|
success: settedDetail,
|
|
301
421
|
};
|
|
302
|
-
|
|
303
|
-
this.dispatchEvent(
|
|
304
|
-
new CustomEvent("prefviewer3d-loaded", {
|
|
305
|
-
bubbles: true,
|
|
306
|
-
cancelable: false,
|
|
307
|
-
composed: true,
|
|
308
|
-
detail: detail,
|
|
309
|
-
})
|
|
310
|
-
);
|
|
311
422
|
|
|
423
|
+
const customEventOptions = {
|
|
424
|
+
bubbles: true,
|
|
425
|
+
cancelable: true,
|
|
426
|
+
composed: false,
|
|
427
|
+
detail: detail,
|
|
428
|
+
};
|
|
429
|
+
this.dispatchEvent(new CustomEvent("scene-set-options", customEventOptions));
|
|
430
|
+
|
|
312
431
|
this.removeAttribute("loading");
|
|
313
432
|
this.setAttribute("loaded", "");
|
|
314
|
-
|
|
433
|
+
|
|
315
434
|
this.#resetUpdateFlags();
|
|
316
435
|
this.#isLoaded = true;
|
|
317
436
|
|
|
@@ -322,22 +441,40 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
322
441
|
* ---------------------------
|
|
323
442
|
* Public methods
|
|
324
443
|
* ---------------------------
|
|
325
|
-
|
|
444
|
+
*/
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Hides the 3D viewer component by updating its visibility state and DOM attribute.
|
|
448
|
+
* @public
|
|
449
|
+
* @returns {void}
|
|
450
|
+
*/
|
|
326
451
|
hide() {
|
|
327
|
-
|
|
328
|
-
|
|
452
|
+
this.#isVisible = false;
|
|
453
|
+
this.setAttribute("visible", "false");
|
|
329
454
|
}
|
|
330
|
-
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Shows the 3D viewer component by updating its visibility state and DOM attribute.
|
|
458
|
+
* @public
|
|
459
|
+
* @returns {void}
|
|
460
|
+
*/
|
|
331
461
|
show() {
|
|
332
462
|
this.#isVisible = true;
|
|
333
463
|
this.setAttribute("visible", "true");
|
|
334
464
|
}
|
|
335
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Loads the provided configuration into the 3D viewer.
|
|
468
|
+
* Updates containers and options, triggers loading events, and returns the loading result.
|
|
469
|
+
* @public
|
|
470
|
+
* @param {object} config - Configuration object containing containers and options.
|
|
471
|
+
* @returns {Promise<object>} Resolves with an object containing success and error status and loading details.
|
|
472
|
+
*/
|
|
336
473
|
async load(config) {
|
|
337
474
|
if (!this.#babylonJSController) {
|
|
338
475
|
return;
|
|
339
476
|
}
|
|
340
|
-
|
|
477
|
+
|
|
341
478
|
this.#onLoading();
|
|
342
479
|
|
|
343
480
|
// Containers
|
|
@@ -349,11 +486,18 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
349
486
|
this.#checkNeedToUpdateMaterials(config.options);
|
|
350
487
|
}
|
|
351
488
|
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
return {
|
|
489
|
+
const loadDetail = await this.#babylonJSController.load();
|
|
490
|
+
|
|
491
|
+
return { ...loadDetail, load: this.#onLoaded() };
|
|
355
492
|
}
|
|
356
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Sets viewer options such as camera and materials.
|
|
496
|
+
* Updates internal states, triggers option setting events, and returns the result.
|
|
497
|
+
* @public
|
|
498
|
+
* @param {object} options - Options object containing camera and material settings.
|
|
499
|
+
* @returns {object} Object containing success status and details of set options.
|
|
500
|
+
*/
|
|
357
501
|
setOptions(options) {
|
|
358
502
|
if (!this.#babylonJSController) {
|
|
359
503
|
return;
|
|
@@ -368,10 +512,15 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
368
512
|
if (this.#checkNeedToUpdateMaterials(options)) {
|
|
369
513
|
someSetted = someSetted || this.#babylonJSController.setMaterialOptions();
|
|
370
514
|
}
|
|
371
|
-
const detail = this.#
|
|
372
|
-
return {success: someSetted, detail: detail};
|
|
515
|
+
const detail = this.#onSetOptions();
|
|
516
|
+
return { success: someSetted, detail: detail };
|
|
373
517
|
}
|
|
374
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Shows the 3D model within the viewer.
|
|
521
|
+
* @public
|
|
522
|
+
* @returns {void}
|
|
523
|
+
*/
|
|
375
524
|
showModel() {
|
|
376
525
|
if (!this.#babylonJSController) {
|
|
377
526
|
return;
|
|
@@ -379,6 +528,11 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
379
528
|
this.#babylonJSController.setContainerVisibility("model", true);
|
|
380
529
|
}
|
|
381
530
|
|
|
531
|
+
/**
|
|
532
|
+
* Hides the 3D model within the viewer.
|
|
533
|
+
* @public
|
|
534
|
+
* @returns {void}
|
|
535
|
+
*/
|
|
382
536
|
hideModel() {
|
|
383
537
|
if (!this.#babylonJSController) {
|
|
384
538
|
return;
|
|
@@ -386,6 +540,11 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
386
540
|
this.#babylonJSController.setContainerVisibility("model", false);
|
|
387
541
|
}
|
|
388
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Shows the 3D environment/scene within the viewer.
|
|
545
|
+
* @public
|
|
546
|
+
* @returns {void}
|
|
547
|
+
*/
|
|
389
548
|
showEnvironment() {
|
|
390
549
|
if (!this.#babylonJSController) {
|
|
391
550
|
return;
|
|
@@ -393,6 +552,11 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
393
552
|
this.#babylonJSController.setContainerVisibility("environment", true);
|
|
394
553
|
}
|
|
395
554
|
|
|
555
|
+
/**
|
|
556
|
+
* Hides the 3D environment/scene within the viewer.
|
|
557
|
+
* @public
|
|
558
|
+
* @returns {void}
|
|
559
|
+
*/
|
|
396
560
|
hideEnvironment() {
|
|
397
561
|
if (!this.#babylonJSController) {
|
|
398
562
|
return;
|
|
@@ -400,32 +564,112 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
400
564
|
this.#babylonJSController.setContainerVisibility("environment", false);
|
|
401
565
|
}
|
|
402
566
|
|
|
567
|
+
/**
|
|
568
|
+
* Downloads the current 3D model as a GLB file.
|
|
569
|
+
* @public
|
|
570
|
+
* @returns {void}
|
|
571
|
+
*/
|
|
403
572
|
downloadModelGLB() {
|
|
404
573
|
if (!this.#babylonJSController) {
|
|
405
574
|
return;
|
|
406
575
|
}
|
|
407
|
-
this.#babylonJSController.
|
|
576
|
+
this.#babylonJSController.downloadGLB(1);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Downloads the current 3D model as a glTF file (ZIP with gltf and all resources (textures, buffers, etc.)).
|
|
581
|
+
* @public
|
|
582
|
+
* @returns {void}
|
|
583
|
+
*/
|
|
584
|
+
downloadModelGLTF() {
|
|
585
|
+
if (!this.#babylonJSController) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
this.#babylonJSController.downloadGLTF(1);
|
|
408
589
|
}
|
|
409
590
|
|
|
591
|
+
/**
|
|
592
|
+
* Downloads the current 3D model as a USDZ file.
|
|
593
|
+
* @public
|
|
594
|
+
* @returns {void}
|
|
595
|
+
*/
|
|
410
596
|
downloadModelUSDZ() {
|
|
411
597
|
if (!this.#babylonJSController) {
|
|
412
598
|
return;
|
|
413
599
|
}
|
|
414
|
-
this.#babylonJSController.
|
|
600
|
+
this.#babylonJSController.downloadUSDZ(1);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Downloads the current 3D complete scene (model and environment) as a GLB file.
|
|
605
|
+
* @public
|
|
606
|
+
* @returns {void}
|
|
607
|
+
*/
|
|
608
|
+
downloadModelAndSceneGLB() {
|
|
609
|
+
if (!this.#babylonJSController) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
this.#babylonJSController.downloadModelGLB(0);
|
|
415
613
|
}
|
|
416
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Downloads the current 3D complete scene (model and environment) as a glTF file (ZIP with gltf and all resources (textures, buffers, etc.)).
|
|
617
|
+
* @public
|
|
618
|
+
* @returns {void}
|
|
619
|
+
*/
|
|
620
|
+
downloadModelAndSceneGLTF() {
|
|
621
|
+
if (!this.#babylonJSController) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
this.#babylonJSController.downloadGLTF(0);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Downloads the current 3D complete scene (model and environment) as a USDZ file.
|
|
629
|
+
* @public
|
|
630
|
+
* @returns {void}
|
|
631
|
+
*/
|
|
417
632
|
downloadModelAndSceneUSDZ() {
|
|
418
633
|
if (!this.#babylonJSController) {
|
|
419
634
|
return;
|
|
420
635
|
}
|
|
421
|
-
this.#babylonJSController.
|
|
636
|
+
this.#babylonJSController.downloadUSDZ(0);
|
|
422
637
|
}
|
|
423
638
|
|
|
424
|
-
|
|
639
|
+
/**
|
|
640
|
+
* Downloads the current 3D environment as a GLB file.
|
|
641
|
+
* @public
|
|
642
|
+
* @returns {void}
|
|
643
|
+
*/
|
|
644
|
+
downloadSceneGLB() {
|
|
645
|
+
if (!this.#babylonJSController) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
this.#babylonJSController.downloadGLB(2);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Downloads the current 3D environment as a glTF file (ZIP with gltf and all resources (textures, buffers, etc.)).
|
|
653
|
+
* @public
|
|
654
|
+
* @returns {void}
|
|
655
|
+
*/
|
|
656
|
+
downloadSceneGLTF() {
|
|
657
|
+
if (!this.#babylonJSController) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
this.#babylonJSController.downloadGLTF(2);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Downloads the current 3D environment as a USDZ file.
|
|
665
|
+
* @public
|
|
666
|
+
* @returns {void}
|
|
667
|
+
*/
|
|
668
|
+
downloadSceneUSDZ() {
|
|
425
669
|
if (!this.#babylonJSController) {
|
|
426
670
|
return;
|
|
427
671
|
}
|
|
428
|
-
this.#babylonJSController.
|
|
672
|
+
this.#babylonJSController.downloadUSDZ(2);
|
|
429
673
|
}
|
|
430
674
|
|
|
431
675
|
/**
|
|
@@ -433,7 +677,7 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
433
677
|
* @public
|
|
434
678
|
* @returns {boolean} True if the component is initialized; otherwise, false.
|
|
435
679
|
*/
|
|
436
|
-
get
|
|
680
|
+
get isInitialized() {
|
|
437
681
|
return this.#isInitialized;
|
|
438
682
|
}
|
|
439
683
|
|
|
@@ -442,7 +686,7 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
442
686
|
* @public
|
|
443
687
|
* @returns {boolean} True if the GLTF/GLB is loaded; otherwise, false.
|
|
444
688
|
*/
|
|
445
|
-
get
|
|
689
|
+
get isLoaded() {
|
|
446
690
|
return this.#isLoaded;
|
|
447
691
|
}
|
|
448
692
|
|
|
@@ -451,7 +695,7 @@ export class PrefViewer3D extends HTMLElement {
|
|
|
451
695
|
* @public
|
|
452
696
|
* @returns {boolean} True if the component is visible; otherwise, false.
|
|
453
697
|
*/
|
|
454
|
-
get
|
|
698
|
+
get isVisible() {
|
|
455
699
|
return this.#isVisible;
|
|
456
700
|
}
|
|
457
|
-
}
|
|
701
|
+
}
|