@preference-sl/pref-viewer 2.10.0-beta.19 → 2.10.0-beta.20
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 +49 -11
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -332,10 +332,12 @@ class PrefViewer extends HTMLElement {
|
|
|
332
332
|
if (!options || !options.camera) {
|
|
333
333
|
return false;
|
|
334
334
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.#data.options.camera.
|
|
338
|
-
|
|
335
|
+
|
|
336
|
+
const changed = options.camera !== this.#data.options.camera.value;
|
|
337
|
+
this.#data.options.camera.changed = changed ? { oldValue: this.#data.options.camera.value, oldLocked: this.#data.options.camera.locked, success: false } : false;
|
|
338
|
+
if (changed) this.#data.options.camera.value = options.camera;
|
|
339
|
+
|
|
340
|
+
return changed;
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
#checkMaterialsChanged(options) {
|
|
@@ -368,6 +370,8 @@ class PrefViewer extends HTMLElement {
|
|
|
368
370
|
// Babylon.js
|
|
369
371
|
async #initializeBabylon() {
|
|
370
372
|
this.#engine = new Engine(this.#canvas, true, { alpha: true });
|
|
373
|
+
this.#engine.disableUniformBuffers = true; // <- evita el límite de GL_MAX_*_UNIFORM_BUFFERS // PROVISIONAL, YA QUE ESTO ES UN POCO OVERKILL
|
|
374
|
+
|
|
371
375
|
this.#scene = new Scene(this.#engine);
|
|
372
376
|
this.#scene.clearColor = new Color4(1, 1, 1, 1);
|
|
373
377
|
this.#createCamera();
|
|
@@ -487,6 +491,8 @@ class PrefViewer extends HTMLElement {
|
|
|
487
491
|
|
|
488
492
|
#disposeEngine() {
|
|
489
493
|
if (!this.#engine) return;
|
|
494
|
+
this.#shadowGen?.dispose();
|
|
495
|
+
this.#scene?.lights?.slice().forEach(l => l.dispose());
|
|
490
496
|
this.#engine.dispose();
|
|
491
497
|
this.#engine = this.#scene = this.#camera = null;
|
|
492
498
|
this.#hemiLight = this.#dirLight = this.#cameraLight = null;
|
|
@@ -537,7 +543,7 @@ class PrefViewer extends HTMLElement {
|
|
|
537
543
|
try {
|
|
538
544
|
JSON.parse(decoded);
|
|
539
545
|
isJson = true;
|
|
540
|
-
} catch {}
|
|
546
|
+
} catch { }
|
|
541
547
|
extension = isJson ? ".gltf" : ".glb";
|
|
542
548
|
const type = isJson ? "model/gltf+json" : "model/gltf-binary";
|
|
543
549
|
const array = Uint8Array.from(decoded, (c) => c.charCodeAt(0));
|
|
@@ -619,9 +625,9 @@ class PrefViewer extends HTMLElement {
|
|
|
619
625
|
let camera = this.#data.containers.model.assetContainer?.cameras.find((thisCamera) => thisCamera.name === this.#data.options.camera.value) || this.#data.containers.environment.assetContainer?.cameras.find((thisCamera) => thisCamera.name === this.#data.options.camera.value) || null;
|
|
620
626
|
if (!camera) {
|
|
621
627
|
if (this.#data.options.camera.changed?.oldValue && this.#data.options.camera.changed?.oldValue !== this.#data.options.camera.value) {
|
|
622
|
-
camera = this.#data.containers.model.assetContainer?.cameras.find((thisCamera) => thisCamera.name === this.#data.options.camera.changed.oldValue) || this.#data.containers.environment.assetContainer?.cameras.find((thisCamera) => thisCamera.name ===
|
|
628
|
+
camera = this.#data.containers.model.assetContainer?.cameras.find((thisCamera) => thisCamera.name === this.#data.options.camera.changed.oldValue) || this.#data.containers.environment.assetContainer?.cameras.find((thisCamera) => thisCamera.name === this.#data.options.camera.changed.oldValue) || null;
|
|
623
629
|
}
|
|
624
|
-
if (camera){
|
|
630
|
+
if (camera) {
|
|
625
631
|
camera.metadata = { locked: this.#data.options.camera.changed.oldLocked };
|
|
626
632
|
this.#data.options.camera.value = this.#data.options.camera.changed.oldValue;
|
|
627
633
|
this.#data.options.camera.locked = this.#data.options.camera.changed.oldLocked;
|
|
@@ -656,13 +662,34 @@ class PrefViewer extends HTMLElement {
|
|
|
656
662
|
}
|
|
657
663
|
|
|
658
664
|
#replaceContainer(container, newAssetContainer) {
|
|
659
|
-
|
|
665
|
+
// 1) quita y destruye el anterior si existía
|
|
666
|
+
const old = container.assetContainer;
|
|
667
|
+
if (old) {
|
|
668
|
+
if (container.visible) { old.removeAllFromScene(); }
|
|
669
|
+
old.dispose(); // <- importante
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// 2) asigna el nuevo y prepara
|
|
660
673
|
container.assetContainer = newAssetContainer;
|
|
661
|
-
|
|
674
|
+
|
|
675
|
+
// Opcional: limitar luces por material para ganar margen
|
|
676
|
+
container.assetContainer.materials?.forEach(m => {
|
|
677
|
+
if ("maxSimultaneousLights" in m) {
|
|
678
|
+
m.maxSimultaneousLights = 2; // 2–3 suele ir bien
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
// 3) sombras solo para los meshes que te interesen (mejor que todos)
|
|
683
|
+
container.assetContainer.meshes.forEach(mesh => {
|
|
662
684
|
mesh.receiveShadows = true;
|
|
663
685
|
this.#shadowGen.addShadowCaster(mesh, true);
|
|
664
686
|
});
|
|
687
|
+
|
|
688
|
+
// 4) añade a escena
|
|
665
689
|
this.#addContainer(container);
|
|
690
|
+
|
|
691
|
+
// 5) fuerza recompilación con defines correctos del nuevo estado
|
|
692
|
+
this.#scene.getEngine().releaseEffects();
|
|
666
693
|
}
|
|
667
694
|
|
|
668
695
|
async #loadAssetContainer(container) {
|
|
@@ -706,7 +733,7 @@ class PrefViewer extends HTMLElement {
|
|
|
706
733
|
} else {
|
|
707
734
|
const extMatch = source.match(/\.(gltf|glb)(\?|#|$)/i);
|
|
708
735
|
extension = extMatch ? `.${extMatch[1].toLowerCase()}` : ".gltf";
|
|
709
|
-
const [fileSize, fileTimeStamp
|
|
736
|
+
const [fileSize, fileTimeStamp] = await this.#getServerFileDataHeader(source);
|
|
710
737
|
if (container.size === fileSize && container.timeStamp === fileTimeStamp) {
|
|
711
738
|
return false;
|
|
712
739
|
} else {
|
|
@@ -727,7 +754,7 @@ class PrefViewer extends HTMLElement {
|
|
|
727
754
|
return LoadAssetContainerAsync(file || source, this.#scene, options);
|
|
728
755
|
}
|
|
729
756
|
|
|
730
|
-
async #loadContainers(loadModel = true, loadEnvironment = true, loadMaterials = true) {
|
|
757
|
+
async #loadContainers(loadModel = true, loadEnvironment = true, loadMaterials = true) {
|
|
731
758
|
const promiseArray = [];
|
|
732
759
|
promiseArray.push(loadModel ? this.#loadAssetContainer(this.#data.containers.model) : false);
|
|
733
760
|
promiseArray.push(loadEnvironment ? this.#loadAssetContainer(this.#data.containers.environment) : false);
|
|
@@ -742,6 +769,7 @@ class PrefViewer extends HTMLElement {
|
|
|
742
769
|
const materialsContainer = values[2];
|
|
743
770
|
|
|
744
771
|
if (modelContainer.status === "fulfilled" && modelContainer.value) {
|
|
772
|
+
this.#stripImportedLights(modelContainer.value);
|
|
745
773
|
this.#replaceContainer(this.#data.containers.model, modelContainer.value);
|
|
746
774
|
this.#storeChangedFlagsForContainer(this.#data.containers.model);
|
|
747
775
|
} else {
|
|
@@ -749,6 +777,7 @@ class PrefViewer extends HTMLElement {
|
|
|
749
777
|
}
|
|
750
778
|
|
|
751
779
|
if (environmentContainer.status === "fulfilled" && environmentContainer.value) {
|
|
780
|
+
this.#stripImportedLights(environmentContainer.value);
|
|
752
781
|
this.#replaceContainer(this.#data.containers.environment, environmentContainer.value);
|
|
753
782
|
this.#storeChangedFlagsForContainer(this.#data.containers.environment);
|
|
754
783
|
} else {
|
|
@@ -756,6 +785,7 @@ class PrefViewer extends HTMLElement {
|
|
|
756
785
|
}
|
|
757
786
|
|
|
758
787
|
if (materialsContainer.status === "fulfilled" && materialsContainer.value) {
|
|
788
|
+
this.#stripImportedLights(materialsContainer.value);
|
|
759
789
|
this.#replaceContainer(this.#data.containers.materials, materialsContainer.value);
|
|
760
790
|
this.#storeChangedFlagsForContainer(this.#data.containers.materials);
|
|
761
791
|
}
|
|
@@ -780,6 +810,14 @@ class PrefViewer extends HTMLElement {
|
|
|
780
810
|
});
|
|
781
811
|
}
|
|
782
812
|
|
|
813
|
+
#stripImportedLights(container) {
|
|
814
|
+
// El glTF puede traer KHR_lights_punctual: bórralas antes de añadir a la escena
|
|
815
|
+
if (container?.lights?.length) {
|
|
816
|
+
// Clonar para no mutar mientras iteras
|
|
817
|
+
container.lights.slice().forEach(l => l.dispose());
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
783
821
|
// Public Methods
|
|
784
822
|
loadConfig(config) {
|
|
785
823
|
config = typeof config === "string" ? JSON.parse(config) : config;
|