@preference-sl/pref-viewer 2.16.0-beta.1 → 2.16.0-beta.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preference-sl/pref-viewer",
3
- "version": "2.16.0-beta.1",
3
+ "version": "2.16.0-beta.2",
4
4
  "description": "Web Component to preview GLTF models with Babylon.js",
5
5
  "author": "Alex Moreno Palacio <amoreno@preference.es>",
6
6
  "scripts": {
@@ -167,6 +167,7 @@ export default class BabylonJSController {
167
167
  #prefViewer = undefined;
168
168
  #modelFirstPaintedEmitted = false;
169
169
  #modelFirstPaintedLoadToken = 0;
170
+ #pendingModelReplacementCleanup = null;
170
171
 
171
172
  // Babylon.js core objects
172
173
  #engine = null;
@@ -2590,7 +2591,20 @@ export default class BabylonJSController {
2590
2591
  * @returns {boolean} True if the container was replaced and added, false otherwise.
2591
2592
  */
2592
2593
  #replaceContainer(container, newAssetContainer, { releaseEffects = true } = {}) {
2594
+ const keepPreviousVisibleUntilPaint = container.state.name === "model" && container.assetContainer && container.state.isVisible;
2595
+ if (this.#pendingModelReplacementCleanup && container.state.name === "model") {
2596
+ this.#finalizePendingModelReplacement();
2597
+ }
2593
2598
  if (container.assetContainer) {
2599
+ if (keepPreviousVisibleUntilPaint) {
2600
+ if (this.#pendingModelReplacementCleanup) {
2601
+ this.#finalizePendingModelReplacement();
2602
+ }
2603
+ const oldAssetContainer = container.assetContainer;
2604
+ container.assetContainer = newAssetContainer;
2605
+ this.#pendingModelReplacementCleanup = { container, oldAssetContainer, releaseEffects };
2606
+ return true;
2607
+ }
2594
2608
  this.#removeContainer(container, false);
2595
2609
  container.assetContainer.dispose();
2596
2610
  container.assetContainer = null;
@@ -2613,6 +2627,63 @@ export default class BabylonJSController {
2613
2627
  return this.#addContainer(container, false);
2614
2628
  }
2615
2629
 
2630
+ /**
2631
+ * Finalizes a deferred model replacement by disposing the previously visible model container.
2632
+ * @private
2633
+ * @returns {void}
2634
+ */
2635
+ #finalizePendingModelReplacement() {
2636
+ if (!this.#pendingModelReplacementCleanup) {
2637
+ return;
2638
+ }
2639
+ const { container, oldAssetContainer } = this.#pendingModelReplacementCleanup;
2640
+ this.#pendingModelReplacementCleanup = null;
2641
+ if (!oldAssetContainer) {
2642
+ return;
2643
+ }
2644
+ const stagedAssetContainer = container?.assetContainer ?? null;
2645
+ if (stagedAssetContainer) {
2646
+ try {
2647
+ stagedAssetContainer.meshes?.forEach((mesh) => {
2648
+ mesh.visibility = 0;
2649
+ });
2650
+ } catch {
2651
+ // ignore
2652
+ }
2653
+ try {
2654
+ container.state.visible = false;
2655
+ this.#addContainer(container, false);
2656
+ } catch {
2657
+ // ignore
2658
+ }
2659
+ }
2660
+ try {
2661
+ oldAssetContainer.removeAllFromScene();
2662
+ } catch {
2663
+ // ignore
2664
+ }
2665
+ try {
2666
+ oldAssetContainer.dispose();
2667
+ } catch {
2668
+ // ignore
2669
+ }
2670
+ if (stagedAssetContainer) {
2671
+ try {
2672
+ stagedAssetContainer.meshes?.forEach((mesh) => {
2673
+ mesh.visibility = 1;
2674
+ });
2675
+ this.#setVisibilityOfWallAndFloorInModel();
2676
+ } catch {
2677
+ // ignore
2678
+ }
2679
+ }
2680
+ this.#requestRender({
2681
+ frames: 3,
2682
+ continuousMs: this.#config.render.interactionMs,
2683
+ force: true,
2684
+ });
2685
+ }
2686
+
2616
2687
  /**
2617
2688
  * Stops every animation group on the provided asset container to guarantee new loads start from a clean state.
2618
2689
  * @private
@@ -3450,6 +3521,7 @@ export default class BabylonJSController {
3450
3521
  this.#disablingPromises.general = (async () => {
3451
3522
  this.#disableInteraction();
3452
3523
  this.#disposeAnimationController();
3524
+ this.#finalizePendingModelReplacement();
3453
3525
  this.#disposeGLTFResolver();
3454
3526
  try {
3455
3527
  await this.#disposeXRExperience();
@@ -3837,6 +3909,7 @@ export default class BabylonJSController {
3837
3909
  tAfterMerge: Math.round(tAfterMerge),
3838
3910
  tAfterPaint: Math.round(performance.now()),
3839
3911
  });
3912
+ this.#finalizePendingModelReplacement();
3840
3913
  }
3841
3914
  })();
3842
3915
  }