@babylonjs/gui 5.0.0-alpha.60 → 5.0.0-alpha.64

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.
Files changed (44) hide show
  1. package/2D/advancedDynamicTexture.d.ts +153 -135
  2. package/2D/advancedDynamicTexture.js +258 -157
  3. package/2D/advancedDynamicTexture.js.map +1 -1
  4. package/2D/controls/container.js +2 -2
  5. package/2D/controls/container.js.map +1 -1
  6. package/2D/controls/control.d.ts +66 -32
  7. package/2D/controls/control.js +180 -76
  8. package/2D/controls/control.js.map +1 -1
  9. package/2D/controls/grid.d.ts +5 -3
  10. package/2D/controls/grid.js +48 -21
  11. package/2D/controls/grid.js.map +1 -1
  12. package/2D/controls/inputText.js +1 -1
  13. package/2D/controls/inputText.js.map +1 -1
  14. package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
  15. package/2D/controls/stackPanel.d.ts +7 -1
  16. package/2D/controls/stackPanel.js +29 -7
  17. package/2D/controls/stackPanel.js.map +1 -1
  18. package/2D/controls/textBlock.js +5 -5
  19. package/2D/controls/textBlock.js.map +1 -1
  20. package/2D/math2D.d.ts +5 -0
  21. package/2D/math2D.js +12 -0
  22. package/2D/math2D.js.map +1 -1
  23. package/2D/valueAndUnit.d.ts +21 -6
  24. package/2D/valueAndUnit.js +57 -13
  25. package/2D/valueAndUnit.js.map +1 -1
  26. package/3D/controls/button3D.js +8 -1
  27. package/3D/controls/button3D.js.map +1 -1
  28. package/3D/controls/control3D.d.ts +2 -0
  29. package/3D/controls/control3D.js +3 -0
  30. package/3D/controls/control3D.js.map +1 -1
  31. package/3D/controls/holographicButton.js +9 -8
  32. package/3D/controls/holographicButton.js.map +1 -1
  33. package/3D/controls/holographicSlate.js +11 -6
  34. package/3D/controls/holographicSlate.js.map +1 -1
  35. package/3D/controls/nearMenu.js +1 -1
  36. package/3D/controls/nearMenu.js.map +1 -1
  37. package/3D/controls/touchHolographicButton.js +12 -12
  38. package/3D/controls/touchHolographicButton.js.map +1 -1
  39. package/3D/controls/touchHolographicMenu.js +13 -11
  40. package/3D/controls/touchHolographicMenu.js.map +1 -1
  41. package/3D/gui3DManager.d.ts +10 -0
  42. package/3D/gui3DManager.js +43 -0
  43. package/3D/gui3DManager.js.map +1 -1
  44. package/package.json +2 -2
@@ -2,7 +2,7 @@ import { __extends } from "tslib";
2
2
  import { Observable } from "@babylonjs/core/Misc/observable.js";
3
3
  import { Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
4
  import { Tools } from "@babylonjs/core/Misc/tools.js";
5
- import { PointerEventTypes } from '@babylonjs/core/Events/pointerEvents.js';
5
+ import { PointerEventTypes } from "@babylonjs/core/Events/pointerEvents.js";
6
6
  import { ClipboardEventTypes, ClipboardInfo } from "@babylonjs/core/Events/clipboardEvents.js";
7
7
  import { KeyboardEventTypes } from "@babylonjs/core/Events/keyboardEvents.js";
8
8
  import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
@@ -13,26 +13,26 @@ import { Container } from "./controls/container.js";
13
13
  import { Control } from "./controls/control.js";
14
14
  import { Style } from "./style.js";
15
15
  import { Measure } from "./measure.js";
16
- import { Constants } from '@babylonjs/core/Engines/constants.js';
17
- import { Viewport } from '@babylonjs/core/Maths/math.viewport.js';
18
- import { Color3 } from '@babylonjs/core/Maths/math.color.js';
16
+ import { Constants } from "@babylonjs/core/Engines/constants.js";
17
+ import { Viewport } from "@babylonjs/core/Maths/math.viewport.js";
18
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
19
19
  import { WebRequest } from "@babylonjs/core/Misc/webRequest.js";
20
20
  /**
21
- * Class used to create texture to support 2D GUI elements
22
- * @see https://doc.babylonjs.com/how_to/gui
23
- */
21
+ * Class used to create texture to support 2D GUI elements
22
+ * @see https://doc.babylonjs.com/how_to/gui
23
+ */
24
24
  var AdvancedDynamicTexture = /** @class */ (function (_super) {
25
25
  __extends(AdvancedDynamicTexture, _super);
26
26
  /**
27
- * Creates a new AdvancedDynamicTexture
28
- * @param name defines the name of the texture
29
- * @param width defines the width of the texture
30
- * @param height defines the height of the texture
31
- * @param scene defines the hosting scene
32
- * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
33
- * @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
34
- * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
35
- */
27
+ * Creates a new AdvancedDynamicTexture
28
+ * @param name defines the name of the texture
29
+ * @param width defines the width of the texture
30
+ * @param height defines the height of the texture
31
+ * @param scene defines the hosting scene
32
+ * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
33
+ * @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
34
+ * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
35
+ */
36
36
  function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode, invertY) {
37
37
  if (width === void 0) { width = 0; }
38
38
  if (height === void 0) { height = 0; }
@@ -66,37 +66,37 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
66
66
  /** @hidden */
67
67
  _this._numRenderCalls = 0;
68
68
  /**
69
- * Define type to string to ensure compatibility across browsers
70
- * Safari doesn't support DataTransfer constructor
71
- */
69
+ * Define type to string to ensure compatibility across browsers
70
+ * Safari doesn't support DataTransfer constructor
71
+ */
72
72
  _this._clipboardData = "";
73
73
  /**
74
- * Observable event triggered each time an clipboard event is received from the rendering canvas
75
- */
74
+ * Observable event triggered each time an clipboard event is received from the rendering canvas
75
+ */
76
76
  _this.onClipboardObservable = new Observable();
77
77
  /**
78
- * Observable event triggered each time a pointer down is intercepted by a control
79
- */
78
+ * Observable event triggered each time a pointer down is intercepted by a control
79
+ */
80
80
  _this.onControlPickedObservable = new Observable();
81
81
  /**
82
- * Observable event triggered before layout is evaluated
83
- */
82
+ * Observable event triggered before layout is evaluated
83
+ */
84
84
  _this.onBeginLayoutObservable = new Observable();
85
85
  /**
86
- * Observable event triggered after the layout was evaluated
87
- */
86
+ * Observable event triggered after the layout was evaluated
87
+ */
88
88
  _this.onEndLayoutObservable = new Observable();
89
89
  /**
90
- * Observable event triggered before the texture is rendered
91
- */
90
+ * Observable event triggered before the texture is rendered
91
+ */
92
92
  _this.onBeginRenderObservable = new Observable();
93
93
  /**
94
- * Observable event triggered after the texture was rendered
95
- */
94
+ * Observable event triggered after the texture was rendered
95
+ */
96
96
  _this.onEndRenderObservable = new Observable();
97
97
  /**
98
- * Gets or sets a boolean defining if alpha is stored as premultiplied
99
- */
98
+ * Gets or sets a boolean defining if alpha is stored as premultiplied
99
+ */
100
100
  _this.premulAlpha = false;
101
101
  /**
102
102
  * Gets or sets a boolean indicating that the canvas must be reverted on Y when updating the texture
@@ -170,9 +170,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
170
170
  });
171
171
  Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
172
172
  /**
173
- * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
174
- * Useful when you want more antialiasing
175
- */
173
+ * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
174
+ * Useful when you want more antialiasing
175
+ */
176
176
  get: function () {
177
177
  return this._renderScale;
178
178
  },
@@ -203,10 +203,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
203
203
  });
204
204
  Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
205
205
  /**
206
- * Gets or sets the ideal width used to design controls.
207
- * The GUI will then rescale everything accordingly
208
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
209
- */
206
+ * Gets or sets the ideal width used to design controls.
207
+ * The GUI will then rescale everything accordingly
208
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
209
+ */
210
210
  get: function () {
211
211
  return this._idealWidth;
212
212
  },
@@ -223,10 +223,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
223
223
  });
224
224
  Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
225
225
  /**
226
- * Gets or sets the ideal height used to design controls.
227
- * The GUI will then rescale everything accordingly
228
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
229
- */
226
+ * Gets or sets the ideal height used to design controls.
227
+ * The GUI will then rescale everything accordingly
228
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
229
+ */
230
230
  get: function () {
231
231
  return this._idealHeight;
232
232
  },
@@ -243,9 +243,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
243
243
  });
244
244
  Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
245
245
  /**
246
- * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
247
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
248
- */
246
+ * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
247
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
248
+ */
249
249
  get: function () {
250
250
  return this._useSmallestIdeal;
251
251
  },
@@ -262,9 +262,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
262
262
  });
263
263
  Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
264
264
  /**
265
- * Gets or sets a boolean indicating if adaptive scaling must be used
266
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
267
- */
265
+ * Gets or sets a boolean indicating if adaptive scaling must be used
266
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
267
+ */
268
268
  get: function () {
269
269
  return this._renderAtIdealSize;
270
270
  },
@@ -281,24 +281,26 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
281
281
  Object.defineProperty(AdvancedDynamicTexture.prototype, "idealRatio", {
282
282
  /**
283
283
  * Gets the ratio used when in "ideal mode"
284
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
284
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
285
285
  * */
286
286
  get: function () {
287
287
  var rwidth = 0;
288
288
  var rheight = 0;
289
289
  if (this._idealWidth) {
290
- rwidth = (this.getSize().width) / this._idealWidth;
290
+ rwidth = this.getSize().width / this._idealWidth;
291
291
  }
292
292
  if (this._idealHeight) {
293
- rheight = (this.getSize().height) / this._idealHeight;
293
+ rheight = this.getSize().height / this._idealHeight;
294
294
  }
295
295
  if (this._useSmallestIdeal && this._idealWidth && this._idealHeight) {
296
296
  return window.innerWidth < window.innerHeight ? rwidth : rheight;
297
297
  }
298
- if (this._idealWidth) { // horizontal
298
+ if (this._idealWidth) {
299
+ // horizontal
299
300
  return rwidth;
300
301
  }
301
- if (this._idealHeight) { // vertical
302
+ if (this._idealHeight) {
303
+ // vertical
302
304
  return rheight;
303
305
  }
304
306
  return 1;
@@ -308,8 +310,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
308
310
  });
309
311
  Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
310
312
  /**
311
- * Gets the underlying layer used to render the texture when in fullscreen mode
312
- */
313
+ * Gets the underlying layer used to render the texture when in fullscreen mode
314
+ */
313
315
  get: function () {
314
316
  return this._layerToDispose;
315
317
  },
@@ -318,8 +320,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
318
320
  });
319
321
  Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
320
322
  /**
321
- * Gets the root container control
322
- */
323
+ * Gets the root container control
324
+ */
323
325
  get: function () {
324
326
  return this._rootContainer;
325
327
  },
@@ -327,35 +329,35 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
327
329
  configurable: true
328
330
  });
329
331
  /**
330
- * Returns an array containing the root container.
331
- * This is mostly used to let the Inspector introspects the ADT
332
- * @returns an array containing the rootContainer
333
- */
332
+ * Returns an array containing the root container.
333
+ * This is mostly used to let the Inspector introspects the ADT
334
+ * @returns an array containing the rootContainer
335
+ */
334
336
  AdvancedDynamicTexture.prototype.getChildren = function () {
335
337
  return [this._rootContainer];
336
338
  };
337
339
  /**
338
- * Will return all controls that are inside this texture
339
- * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
340
- * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
341
- * @return all child controls
342
- */
340
+ * Will return all controls that are inside this texture
341
+ * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
342
+ * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
343
+ * @return all child controls
344
+ */
343
345
  AdvancedDynamicTexture.prototype.getDescendants = function (directDescendantsOnly, predicate) {
344
346
  return this._rootContainer.getDescendants(directDescendantsOnly, predicate);
345
347
  };
346
348
  /**
347
- * Will return all controls with the given type name
348
- * @param typeName defines the type name to search for
349
- * @returns an array of all controls found
350
- */
349
+ * Will return all controls with the given type name
350
+ * @param typeName defines the type name to search for
351
+ * @returns an array of all controls found
352
+ */
351
353
  AdvancedDynamicTexture.prototype.getControlsByType = function (typeName) {
352
354
  return this._rootContainer.getDescendants(false, function (control) { return control.typeName === typeName; });
353
355
  };
354
356
  /**
355
- * Will return the first control with the given name
356
- * @param name defines the name to search for
357
- * @return the first control found or null
358
- */
357
+ * Will return the first control with the given name
358
+ * @param name defines the name to search for
359
+ * @return the first control found or null
360
+ */
359
361
  AdvancedDynamicTexture.prototype.getControlByName = function (name) {
360
362
  return this._getControlByKey("name", name);
361
363
  };
@@ -364,8 +366,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
364
366
  };
365
367
  Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
366
368
  /**
367
- * Gets or sets the current focused control
368
- */
369
+ * Gets or sets the current focused control
370
+ */
369
371
  get: function () {
370
372
  return this._focusedControl;
371
373
  },
@@ -386,13 +388,13 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
386
388
  });
387
389
  Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
388
390
  /**
389
- * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
390
- */
391
+ * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
392
+ */
391
393
  get: function () {
392
394
  if (!this.layer) {
393
395
  return true;
394
396
  }
395
- return (!this.layer.isBackground);
397
+ return !this.layer.isBackground;
396
398
  },
397
399
  set: function (value) {
398
400
  if (!this.layer) {
@@ -408,8 +410,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
408
410
  });
409
411
  Object.defineProperty(AdvancedDynamicTexture.prototype, "clipboardData", {
410
412
  /**
411
- * Gets or set information about clipboardData
412
- */
413
+ * Gets or set information about clipboardData
414
+ */
413
415
  get: function () {
414
416
  return this._clipboardData;
415
417
  },
@@ -420,17 +422,17 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
420
422
  configurable: true
421
423
  });
422
424
  /**
423
- * Get the current class name of the texture useful for serialization or dynamic coding.
424
- * @returns "AdvancedDynamicTexture"
425
- */
425
+ * Get the current class name of the texture useful for serialization or dynamic coding.
426
+ * @returns "AdvancedDynamicTexture"
427
+ */
426
428
  AdvancedDynamicTexture.prototype.getClassName = function () {
427
429
  return "AdvancedDynamicTexture";
428
430
  };
429
431
  /**
430
- * Function used to execute a function on all controls
431
- * @param func defines the function to execute
432
- * @param container defines the container where controls belong. If null the root container will be used
433
- */
432
+ * Function used to execute a function on all controls
433
+ * @param func defines the function to execute
434
+ * @param container defines the container where controls belong. If null the root container will be used
435
+ */
434
436
  AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
435
437
  if (!container) {
436
438
  container = this._rootContainer;
@@ -483,40 +485,83 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
483
485
  }
484
486
  };
485
487
  /**
486
- * Marks the texture as dirty forcing a complete update
487
- */
488
+ * Marks the texture as dirty forcing a complete update
489
+ */
488
490
  AdvancedDynamicTexture.prototype.markAsDirty = function () {
489
491
  this._isDirty = true;
490
492
  };
491
493
  /**
492
- * Helper function used to create a new style
493
- * @returns a new style
494
- * @see https://doc.babylonjs.com/how_to/gui#styles
495
- */
494
+ * Helper function used to create a new style
495
+ * @returns a new style
496
+ * @see https://doc.babylonjs.com/how_to/gui#styles
497
+ */
496
498
  AdvancedDynamicTexture.prototype.createStyle = function () {
497
499
  return new Style(this);
498
500
  };
499
501
  /**
500
- * Adds a new control to the root container
501
- * @param control defines the control to add
502
- * @returns the current texture
503
- */
502
+ * Adds a new control to the root container
503
+ * @param control defines the control to add
504
+ * @returns the current texture
505
+ */
504
506
  AdvancedDynamicTexture.prototype.addControl = function (control) {
505
507
  this._rootContainer.addControl(control);
506
508
  return this;
507
509
  };
508
510
  /**
509
- * Removes a control from the root container
510
- * @param control defines the control to remove
511
- * @returns the current texture
512
- */
511
+ * Removes a control from the root container
512
+ * @param control defines the control to remove
513
+ * @returns the current texture
514
+ */
513
515
  AdvancedDynamicTexture.prototype.removeControl = function (control) {
514
516
  this._rootContainer.removeControl(control);
515
517
  return this;
516
518
  };
517
519
  /**
518
- * Release all resources
519
- */
520
+ * Moves overlapped controls towards a position where it is not overlapping anymore.
521
+ * Please note that this method alters linkOffsetXInPixels and linkOffsetYInPixels.
522
+ * @param overlapGroup the overlap group which will be processed or undefined to process all overlap groups
523
+ * @param deltaStep the step size (speed) to reach the target non overlapping position (default 0.1)
524
+ * @param repelFactor how much is the control repelled by other controls
525
+ */
526
+ AdvancedDynamicTexture.prototype.moveToNonOverlappedPosition = function (overlapGroup, deltaStep, repelFactor) {
527
+ if (deltaStep === void 0) { deltaStep = 1; }
528
+ if (repelFactor === void 0) { repelFactor = 1; }
529
+ var controlsForGroup;
530
+ if (Array.isArray(overlapGroup)) {
531
+ controlsForGroup = overlapGroup;
532
+ }
533
+ else {
534
+ var descendants = this.getDescendants(true);
535
+ // get only the controls with an overlapGroup property set
536
+ // if the overlapGroup parameter is set, filter the controls and get only the controls belonging to that overlapGroup
537
+ controlsForGroup = overlapGroup === undefined ? descendants.filter(function (c) { return c.overlapGroup !== undefined; }) : descendants.filter(function (c) { return c.overlapGroup === overlapGroup; });
538
+ }
539
+ controlsForGroup.forEach(function (control1) {
540
+ var _a;
541
+ var velocity = Vector2.Zero();
542
+ var center = new Vector2(control1.centerX, control1.centerY);
543
+ controlsForGroup.forEach(function (control2) {
544
+ if (control1 !== control2 && AdvancedDynamicTexture._Overlaps(control1, control2)) {
545
+ // if the two controls overlaps get a direction vector from one control's center to another control's center
546
+ var diff = center.subtract(new Vector2(control2.centerX, control2.centerY));
547
+ var diffLength = diff.length();
548
+ if (diffLength > 0) {
549
+ // calculate the velocity
550
+ velocity = velocity.add(diff.normalize().scale(repelFactor / diffLength));
551
+ }
552
+ }
553
+ });
554
+ if (velocity.length() > 0) {
555
+ // move the control along the direction vector away from the overlapping control
556
+ velocity = velocity.normalize().scale(deltaStep * ((_a = control1.overlapDeltaMultiplier) !== null && _a !== void 0 ? _a : 1));
557
+ control1.linkOffsetXInPixels += velocity.x;
558
+ control1.linkOffsetYInPixels += velocity.y;
559
+ }
560
+ });
561
+ };
562
+ /**
563
+ * Release all resources
564
+ */
520
565
  AdvancedDynamicTexture.prototype.dispose = function () {
521
566
  var scene = this.getScene();
522
567
  if (!scene) {
@@ -588,24 +633,31 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
588
633
  /** @hidden */
589
634
  AdvancedDynamicTexture.prototype._getGlobalViewport = function () {
590
635
  var size = this.getSize();
591
- return this._fullscreenViewport.toGlobal(size.width, size.height);
636
+ var globalViewPort = this._fullscreenViewport.toGlobal(size.width, size.height);
637
+ var targetX = Math.round(globalViewPort.width * (1 / this.rootContainer.scaleX));
638
+ var targetY = Math.round(globalViewPort.height * (1 / this.rootContainer.scaleY));
639
+ globalViewPort.x += (globalViewPort.width - targetX) / 2;
640
+ globalViewPort.y += (globalViewPort.height - targetY) / 2;
641
+ globalViewPort.width = targetX;
642
+ globalViewPort.height = targetY;
643
+ return globalViewPort;
592
644
  };
593
645
  /**
594
- * Get screen coordinates for a vector3
595
- * @param position defines the position to project
596
- * @param worldMatrix defines the world matrix to use
597
- * @returns the projected position
598
- */
646
+ * Get screen coordinates for a vector3
647
+ * @param position defines the position to project
648
+ * @param worldMatrix defines the world matrix to use
649
+ * @returns the projected position
650
+ */
599
651
  AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
600
652
  var result = this.getProjectedPositionWithZ(position, worldMatrix);
601
653
  return new Vector2(result.x, result.y);
602
654
  };
603
655
  /**
604
- * Get screen coordinates for a vector3
605
- * @param position defines the position to project
606
- * @param worldMatrix defines the world matrix to use
607
- * @returns the projected position with Z
608
- */
656
+ * Get screen coordinates for a vector3
657
+ * @param position defines the position to project
658
+ * @param worldMatrix defines the world matrix to use
659
+ * @returns the projected position with Z
660
+ */
609
661
  AdvancedDynamicTexture.prototype.getProjectedPositionWithZ = function (position, worldMatrix) {
610
662
  var scene = this.getScene();
611
663
  if (!scene) {
@@ -657,7 +709,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
657
709
  }
658
710
  this._isDirty = false;
659
711
  this._render();
660
- this.update(this.applyYInversionOnUpdate, this.premulAlpha);
712
+ this.update(this.applyYInversionOnUpdate, this.premulAlpha, AdvancedDynamicTexture.AllowGPUOptimizations);
661
713
  };
662
714
  AdvancedDynamicTexture.prototype._render = function () {
663
715
  var textureSize = this.getSize();
@@ -769,13 +821,13 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
769
821
  }
770
822
  var tempViewport = new Viewport(0, 0, 0, 0);
771
823
  this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
772
- if (scene.isPointerCaptured((pi.event).pointerId)) {
824
+ if (scene.isPointerCaptured(pi.event.pointerId)) {
773
825
  return;
774
826
  }
775
- if (pi.type !== PointerEventTypes.POINTERMOVE
776
- && pi.type !== PointerEventTypes.POINTERUP
777
- && pi.type !== PointerEventTypes.POINTERDOWN
778
- && pi.type !== PointerEventTypes.POINTERWHEEL) {
827
+ if (pi.type !== PointerEventTypes.POINTERMOVE &&
828
+ pi.type !== PointerEventTypes.POINTERUP &&
829
+ pi.type !== PointerEventTypes.POINTERDOWN &&
830
+ pi.type !== PointerEventTypes.POINTERWHEEL) {
779
831
  return;
780
832
  }
781
833
  if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
@@ -783,6 +835,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
783
835
  }
784
836
  var camera = scene.cameraToUseForPointers || scene.activeCamera;
785
837
  var engine = scene.getEngine();
838
+ var originalCameraToUseForPointers = scene.cameraToUseForPointers;
786
839
  if (!camera) {
787
840
  tempViewport.x = 0;
788
841
  tempViewport.y = 0;
@@ -790,7 +843,31 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
790
843
  tempViewport.height = engine.getRenderHeight();
791
844
  }
792
845
  else {
793
- camera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), tempViewport);
846
+ if (camera.rigCameras.length) {
847
+ // rig camera - we need to find the camera to use for this event
848
+ var rigViewport_1 = new Viewport(0, 0, 1, 1);
849
+ camera.rigCameras.forEach(function (rigCamera) {
850
+ // generate the viewport of this camera
851
+ rigCamera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), rigViewport_1);
852
+ var x = scene.pointerX / engine.getHardwareScalingLevel() - rigViewport_1.x;
853
+ var y = scene.pointerY / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - rigViewport_1.y - rigViewport_1.height);
854
+ // check if the pointer is in the camera's viewport
855
+ if (x < 0 || y < 0 || x > rigViewport_1.width || y > rigViewport_1.height) {
856
+ // out of viewport - don't use this camera
857
+ return;
858
+ }
859
+ // set the camera to use for pointers until this pointer loop is over
860
+ scene.cameraToUseForPointers = rigCamera;
861
+ // set the viewport
862
+ tempViewport.x = rigViewport_1.x;
863
+ tempViewport.y = rigViewport_1.y;
864
+ tempViewport.width = rigViewport_1.width;
865
+ tempViewport.height = rigViewport_1.height;
866
+ });
867
+ }
868
+ else {
869
+ camera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), tempViewport);
870
+ }
794
871
  }
795
872
  var x = scene.pointerX / engine.getHardwareScalingLevel() - tempViewport.x;
796
873
  var y = scene.pointerY / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - tempViewport.y - tempViewport.height);
@@ -802,13 +879,15 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
802
879
  if (_this._shouldBlockPointer) {
803
880
  pi.skipOnPointerObservable = _this._shouldBlockPointer;
804
881
  }
882
+ // if overridden by a rig camera - reset back to the original value
883
+ scene.cameraToUseForPointers = originalCameraToUseForPointers;
805
884
  });
806
885
  this._attachToOnPointerOut(scene);
807
886
  this._attachToOnBlur(scene);
808
887
  };
809
888
  /**
810
- * Register the clipboard Events onto the canvas
811
- */
889
+ * Register the clipboard Events onto the canvas
890
+ */
812
891
  AdvancedDynamicTexture.prototype.registerClipboardEvents = function () {
813
892
  self.addEventListener("copy", this.onClipboardCopy, false);
814
893
  self.addEventListener("cut", this.onClipboardCut, false);
@@ -823,10 +902,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
823
902
  self.removeEventListener("paste", this.onClipboardPaste);
824
903
  };
825
904
  /**
826
- * Connect the texture to a hosting mesh to enable interactions
827
- * @param mesh defines the mesh to attach to
828
- * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
829
- */
905
+ * Connect the texture to a hosting mesh to enable interactions
906
+ * @param mesh defines the mesh to attach to
907
+ * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
908
+ */
830
909
  AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
831
910
  var _this = this;
832
911
  if (supportPointerMove === void 0) { supportPointerMove = true; }
@@ -835,10 +914,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
835
914
  return;
836
915
  }
837
916
  this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
838
- if (pi.type !== PointerEventTypes.POINTERMOVE
839
- && pi.type !== PointerEventTypes.POINTERUP
840
- && pi.type !== PointerEventTypes.POINTERDOWN
841
- && pi.type !== PointerEventTypes.POINTERWHEEL) {
917
+ if (pi.type !== PointerEventTypes.POINTERMOVE &&
918
+ pi.type !== PointerEventTypes.POINTERUP &&
919
+ pi.type !== PointerEventTypes.POINTERDOWN &&
920
+ pi.type !== PointerEventTypes.POINTERWHEEL) {
842
921
  return;
843
922
  }
844
923
  if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
@@ -849,7 +928,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
849
928
  var uv = pi.pickInfo.getTextureCoordinates();
850
929
  if (uv) {
851
930
  var size = _this.getSize();
852
- _this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ? (1.0 - uv.y) : uv.y) * size.height, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
931
+ _this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ? 1.0 - uv.y : uv.y) * size.height, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
853
932
  }
854
933
  }
855
934
  else if (pi.type === PointerEventTypes.POINTERUP) {
@@ -892,9 +971,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
892
971
  this._attachToOnBlur(scene);
893
972
  };
894
973
  /**
895
- * Move the focus to a specific control
896
- * @param control defines the control which will receive the focus
897
- */
974
+ * Move the focus to a specific control
975
+ * @param control defines the control which will receive the focus
976
+ */
898
977
  AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
899
978
  this.focusedControl = control;
900
979
  this._lastPickedControl = control;
@@ -964,7 +1043,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
964
1043
  if (scaleToSize) {
965
1044
  var width = serializedObject.width;
966
1045
  var height = serializedObject.height;
967
- if (typeof (width) === "number" && typeof (height) === "number" && width >= 0 && height >= 0) {
1046
+ if (typeof width === "number" && typeof height === "number" && width >= 0 && height >= 0) {
968
1047
  this.scaleTo(width, height);
969
1048
  }
970
1049
  }
@@ -1001,11 +1080,11 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
1001
1080
  });
1002
1081
  };
1003
1082
  /**
1004
- * Recreate the content of the ADT from a url json
1005
- * @param url defines the url to load
1006
- * @param scaleToSize defines whether to scale to texture to the saved size
1007
- * @returns a promise that will resolve on success
1008
- */
1083
+ * Recreate the content of the ADT from a url json
1084
+ * @param url defines the url to load
1085
+ * @param scaleToSize defines whether to scale to texture to the saved size
1086
+ * @returns a promise that will resolve on success
1087
+ */
1009
1088
  AdvancedDynamicTexture.prototype.parseFromURLAsync = function (url, scaleToSize) {
1010
1089
  var _this = this;
1011
1090
  if (url === "") {
@@ -1031,6 +1110,18 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
1031
1110
  });
1032
1111
  };
1033
1112
  // Statics
1113
+ /**
1114
+ * Compares two rectangle based controls for pixel overlap
1115
+ * @param control1 The first control to compare
1116
+ * @param control2 The second control to compare
1117
+ * @returns true if overlaps, otherwise false
1118
+ */
1119
+ AdvancedDynamicTexture._Overlaps = function (control1, control2) {
1120
+ return !(control1.centerX > control2.centerX + control2.widthInPixels ||
1121
+ control1.centerX + control1.widthInPixels < control2.centerX ||
1122
+ control1.centerY + control1.heightInPixels < control2.centerY ||
1123
+ control1.centerY > control2.centerY + control2.heightInPixels);
1124
+ };
1034
1125
  /**
1035
1126
  * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
1036
1127
  * @param mesh defines the mesh which will receive the texture
@@ -1082,33 +1173,43 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
1082
1173
  return result;
1083
1174
  };
1084
1175
  /**
1085
- * Creates a new AdvancedDynamicTexture in fullscreen mode.
1086
- * In this mode the texture will rely on a layer for its rendering.
1087
- * This allows it to be treated like any other layer.
1088
- * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
1089
- * LayerMask is set through advancedTexture.layer.layerMask
1090
- * @param name defines name for the texture
1091
- * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
1092
- * @param scene defines the hosting scene
1093
- * @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
1094
- * @returns a new AdvancedDynamicTexture
1095
- */
1096
- AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
1176
+ * Creates a new AdvancedDynamicTexture in fullscreen mode.
1177
+ * In this mode the texture will rely on a layer for its rendering.
1178
+ * This allows it to be treated like any other layer.
1179
+ * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
1180
+ * LayerMask is set through advancedTexture.layer.layerMask
1181
+ * @param name defines name for the texture
1182
+ * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
1183
+ * @param scene defines the hosting scene
1184
+ * @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
1185
+ * @param adaptiveScaling defines whether to automatically scale root to match hardwarescaling (false by default)
1186
+ * @returns a new AdvancedDynamicTexture
1187
+ */
1188
+ AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling, adaptiveScaling) {
1097
1189
  if (foreground === void 0) { foreground = true; }
1098
1190
  if (scene === void 0) { scene = null; }
1099
1191
  if (sampling === void 0) { sampling = Texture.BILINEAR_SAMPLINGMODE; }
1192
+ if (adaptiveScaling === void 0) { adaptiveScaling = false; }
1100
1193
  var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
1101
1194
  // Display
1102
- var layer = new Layer(name + "_layer", null, scene, !foreground);
1195
+ var resultScene = result.getScene();
1196
+ var layer = new Layer(name + "_layer", null, resultScene, !foreground);
1103
1197
  layer.texture = result;
1104
1198
  result._layerToDispose = layer;
1105
1199
  result._isFullscreen = true;
1200
+ if (adaptiveScaling && resultScene) {
1201
+ var newScale = 1 / resultScene.getEngine().getHardwareScalingLevel();
1202
+ result._rootContainer.scaleX = newScale;
1203
+ result._rootContainer.scaleY = newScale;
1204
+ }
1106
1205
  // Attach
1107
1206
  result.attach();
1108
1207
  return result;
1109
1208
  };
1110
1209
  /** Define the Uurl to load snippets */
1111
1210
  AdvancedDynamicTexture.SnippetUrl = "https://snippet.babylonjs.com";
1211
+ /** Indicates if some optimizations can be performed in GUI GPU management (the downside is additional memory/GPU texture memory used) */
1212
+ AdvancedDynamicTexture.AllowGPUOptimizations = true;
1112
1213
  return AdvancedDynamicTexture;
1113
1214
  }(DynamicTexture));
1114
1215
  export { AdvancedDynamicTexture };