@preference-sl/pref-viewer 2.10.0-beta.4 → 2.10.0-beta.5
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 +1 -1
- package/src/index.js +47 -23
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -232,17 +232,21 @@ class PrefViewer extends HTMLElement {
|
|
|
232
232
|
}
|
|
233
233
|
this.#data.options.camera.changed = options.camera && options.camera !== this.#data.options.camera.value ? true : false;
|
|
234
234
|
this.#data.options.camera.value = this.#data.options.camera.changed ? options.camera : this.#data.options.camera.value;
|
|
235
|
+
return this.#data.options.camera.changed;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
#checkMaterialsChanged(options) {
|
|
238
239
|
if (!options) {
|
|
239
240
|
return false;
|
|
240
241
|
}
|
|
242
|
+
let someChanged = false;
|
|
241
243
|
Object.keys(this.#data.options.materials).forEach((material) => {
|
|
242
244
|
const key = `${material}Material`;
|
|
243
245
|
this.#data.options.materials[material].changed = options[key] && options[key] !== this.#data.options.materials[material].value ? true : false;
|
|
244
246
|
this.#data.options.materials[material].value = this.#data.options.materials[material].changed ? options[key] : this.#data.options.materials[material].value;
|
|
247
|
+
someChanged = someChanged || this.#data.options.materials[material].changed;
|
|
245
248
|
});
|
|
249
|
+
return someChanged;
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
#storeChangedFlagsForContainer(container) {
|
|
@@ -474,37 +478,45 @@ class PrefViewer extends HTMLElement {
|
|
|
474
478
|
return false;
|
|
475
479
|
}
|
|
476
480
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
481
|
+
let someSetted = false;
|
|
482
|
+
containers.forEach((container) =>
|
|
483
|
+
container.meshes
|
|
484
|
+
.filter((meshToFilter) => meshToFilter.name.startsWith(optionMaterial.prefix))
|
|
485
|
+
.forEach((mesh) => {
|
|
486
|
+
mesh.material = material;
|
|
487
|
+
someSetted = true;
|
|
488
|
+
})
|
|
489
|
+
);
|
|
485
490
|
|
|
486
|
-
return
|
|
491
|
+
return someSetted;
|
|
487
492
|
}
|
|
488
493
|
|
|
489
494
|
#setOptionsMaterials() {
|
|
490
|
-
|
|
495
|
+
let someSetted = false;
|
|
496
|
+
Object.values(this.#data.options.materials).forEach((material) => {
|
|
497
|
+
let settedMaterial = this.#setOptionsMaterial(material);
|
|
498
|
+
someSetted = someSetted || settedMaterial;
|
|
499
|
+
});
|
|
500
|
+
return someSetted;
|
|
491
501
|
}
|
|
492
502
|
|
|
493
503
|
#setOptionsCamera() {
|
|
494
504
|
if (!this.#data.options.camera.value || (!this.#data.options.camera.changed && !this.#data.containers.model.assetContainer.changed)) {
|
|
495
505
|
return false;
|
|
496
506
|
}
|
|
507
|
+
|
|
497
508
|
let camera = this.#data.containers.model.assetContainer?.cameras.find((cam) => cam.name === this.#data.options.camera.value) || null;
|
|
498
509
|
if (!camera) {
|
|
499
|
-
|
|
500
|
-
} else {
|
|
501
|
-
camera.metadata = { locked: this.#data.options.camera.locked };
|
|
502
|
-
if (!this.#data.options.camera.locked) {
|
|
503
|
-
camera.attachControl(this.#canvas, true);
|
|
504
|
-
}
|
|
510
|
+
return false;
|
|
505
511
|
}
|
|
506
512
|
|
|
513
|
+
camera.metadata = { locked: this.#data.options.camera.locked };
|
|
514
|
+
if (!this.#data.options.camera.locked) {
|
|
515
|
+
camera.attachControl(this.#canvas, true);
|
|
516
|
+
}
|
|
507
517
|
this.#scene.activeCamera = camera;
|
|
518
|
+
|
|
519
|
+
return true;
|
|
508
520
|
}
|
|
509
521
|
|
|
510
522
|
#addContainer(container) {
|
|
@@ -657,7 +669,7 @@ class PrefViewer extends HTMLElement {
|
|
|
657
669
|
return false;
|
|
658
670
|
}
|
|
659
671
|
|
|
660
|
-
//
|
|
672
|
+
// Containers
|
|
661
673
|
this.#data.containers.model.storage = config.model?.storage || null;
|
|
662
674
|
this.#data.containers.model.show = config.model?.visible !== undefined ? config.model.visible : this.#data.containers.model.show;
|
|
663
675
|
this.#data.containers.environment.storage = config.scene?.storage || null;
|
|
@@ -673,6 +685,22 @@ class PrefViewer extends HTMLElement {
|
|
|
673
685
|
this.#initialized && this.#loadContainers(true, true, true);
|
|
674
686
|
}
|
|
675
687
|
|
|
688
|
+
setOptions(options) {
|
|
689
|
+
if (!options) {
|
|
690
|
+
return false;
|
|
691
|
+
}
|
|
692
|
+
let someSetted = false;
|
|
693
|
+
if (this.#checkCameraChanged(options)) {
|
|
694
|
+
someSetted = someSetted || this.#setOptionsCamera();
|
|
695
|
+
}
|
|
696
|
+
if (this.#checkMaterialsChanged(options)) {
|
|
697
|
+
someSetted = someSetted || this.#setOptionsMaterials();
|
|
698
|
+
}
|
|
699
|
+
this.#resetChangedFlags();
|
|
700
|
+
debugger;
|
|
701
|
+
return someSetted;
|
|
702
|
+
}
|
|
703
|
+
|
|
676
704
|
loadModel(model) {
|
|
677
705
|
model = typeof model === "string" ? JSON.parse(model) : model;
|
|
678
706
|
if (!model) {
|
|
@@ -717,9 +745,7 @@ class PrefViewer extends HTMLElement {
|
|
|
717
745
|
|
|
718
746
|
downloadModelGLB() {
|
|
719
747
|
const fileName = "model";
|
|
720
|
-
GLTF2Export.GLBAsync(this.#data.containers.model.assetContainer, fileName, { exportWithoutWaitingForScene: true }).then((glb) =>
|
|
721
|
-
glb.downloadFiles();
|
|
722
|
-
});
|
|
748
|
+
GLTF2Export.GLBAsync(this.#data.containers.model.assetContainer, fileName, { exportWithoutWaitingForScene: true }).then((glb) => glb.downloadFiles());
|
|
723
749
|
}
|
|
724
750
|
|
|
725
751
|
downloadModelUSDZ() {
|
|
@@ -742,9 +768,7 @@ class PrefViewer extends HTMLElement {
|
|
|
742
768
|
|
|
743
769
|
downloadModelAndSceneGLB() {
|
|
744
770
|
const fileName = "scene";
|
|
745
|
-
GLTF2Export.GLBAsync(this.#scene, fileName, { exportWithoutWaitingForScene: true }).then((glb) =>
|
|
746
|
-
glb.downloadFiles();
|
|
747
|
-
});
|
|
771
|
+
GLTF2Export.GLBAsync(this.#scene, fileName, { exportWithoutWaitingForScene: true }).then((glb) => glb.downloadFiles());
|
|
748
772
|
}
|
|
749
773
|
}
|
|
750
774
|
|