@babylonjs/gui 5.41.0 → 5.42.1

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.
@@ -34,6 +34,7 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
34
34
  private _canvasPointerOutObserver;
35
35
  private _canvasBlurObserver;
36
36
  private _controlAddedObserver;
37
+ private _controlRemovedObserver;
37
38
  private _background;
38
39
  /** @internal */
39
40
  _rootContainer: Container;
@@ -69,6 +70,7 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
69
70
  private _rootElement;
70
71
  private _cursorChanged;
71
72
  private _defaultMousePointerId;
73
+ private _rootChildrenHaveChanged;
72
74
  /** @internal */
73
75
  _capturedPointerIds: Set<number>;
74
76
  /** @internal */
@@ -56,6 +56,7 @@ export class AdvancedDynamicTexture extends DynamicTexture {
56
56
  this._renderScale = 1;
57
57
  this._cursorChanged = false;
58
58
  this._defaultMousePointerId = 0;
59
+ this._rootChildrenHaveChanged = false;
59
60
  /** @internal */
60
61
  this._capturedPointerIds = new Set();
61
62
  /** @internal */
@@ -151,9 +152,15 @@ export class AdvancedDynamicTexture extends DynamicTexture {
151
152
  this.applyYInversionOnUpdate = invertY;
152
153
  this._rootElement = scene.getEngine().getInputElement();
153
154
  this._renderObserver = scene.onBeforeCameraRenderObservable.add((camera) => this._checkUpdate(camera));
155
+ /** Whenever a control is added or removed to the root, we have to recheck the camera projection as it can have changed */
154
156
  this._controlAddedObserver = this._rootContainer.onControlAddedObservable.add((control) => {
155
- if (control && this._scene && this._scene.activeCamera) {
156
- this._checkUpdate(this._scene.activeCamera);
157
+ if (control) {
158
+ this._rootChildrenHaveChanged = true;
159
+ }
160
+ });
161
+ this._controlRemovedObserver = this._rootContainer.onControlRemovedObservable.add((control) => {
162
+ if (control) {
163
+ this._rootChildrenHaveChanged = true;
157
164
  }
158
165
  });
159
166
  this._preKeyboardObserver = scene.onPreKeyboardObservable.add((info) => {
@@ -551,6 +558,9 @@ export class AdvancedDynamicTexture extends DynamicTexture {
551
558
  if (this._controlAddedObserver) {
552
559
  this._rootContainer.onControlAddedObservable.remove(this._controlAddedObserver);
553
560
  }
561
+ if (this._controlRemovedObserver) {
562
+ this._rootContainer.onControlRemovedObservable.remove(this._controlRemovedObserver);
563
+ }
554
564
  if (this._layerToDispose) {
555
565
  this._layerToDispose.texture = null;
556
566
  this._layerToDispose.dispose();
@@ -631,7 +641,7 @@ export class AdvancedDynamicTexture extends DynamicTexture {
631
641
  const projectedPosition = Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
632
642
  return new Vector3(projectedPosition.x, projectedPosition.y, projectedPosition.z);
633
643
  }
634
- _checkUpdate(camera) {
644
+ _checkUpdate(camera, skipUpdate) {
635
645
  if (this._layerToDispose) {
636
646
  if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
637
647
  return;
@@ -671,16 +681,27 @@ export class AdvancedDynamicTexture extends DynamicTexture {
671
681
  return;
672
682
  }
673
683
  this._isDirty = false;
674
- this._render();
675
- this.update(this.applyYInversionOnUpdate, this.premulAlpha, AdvancedDynamicTexture.AllowGPUOptimizations);
684
+ this._render(skipUpdate);
685
+ if (!skipUpdate) {
686
+ this.update(this.applyYInversionOnUpdate, this.premulAlpha, AdvancedDynamicTexture.AllowGPUOptimizations);
687
+ }
676
688
  }
677
- _render() {
689
+ _render(skipRender) {
690
+ var _a;
678
691
  const textureSize = this.getSize();
679
692
  const renderWidth = textureSize.width;
680
693
  const renderHeight = textureSize.height;
681
694
  const context = this.getContext();
682
695
  context.font = "18px Arial";
683
696
  context.strokeStyle = "white";
697
+ /** We have to recheck the camera projection in the case the root control's children have changed */
698
+ if (this._rootChildrenHaveChanged) {
699
+ const camera = (_a = this.getScene()) === null || _a === void 0 ? void 0 : _a.activeCamera;
700
+ if (camera) {
701
+ this._rootChildrenHaveChanged = false;
702
+ this._checkUpdate(camera, true);
703
+ }
704
+ }
684
705
  // Layout
685
706
  this.onBeginLayoutObservable.notifyObservers(this);
686
707
  const measure = new Measure(0, 0, renderWidth, renderHeight);
@@ -688,6 +709,9 @@ export class AdvancedDynamicTexture extends DynamicTexture {
688
709
  this._rootContainer._layout(measure, context);
689
710
  this.onEndLayoutObservable.notifyObservers(this);
690
711
  this._isDirty = false; // Restoring the dirty state that could have been set by controls during layout processing
712
+ if (skipRender) {
713
+ return;
714
+ }
691
715
  // Clear
692
716
  if (this._invalidatedRectangle) {
693
717
  this._clearMeasure.copyFrom(this._invalidatedRectangle);