layer.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { Observable } from "../Misc/observable";
  2. import type { Nullable } from "../types";
  3. import type { Scene } from "../scene";
  4. import { Vector2 } from "../Maths/math.vector";
  5. import { Color4 } from "../Maths/math.color";
  6. import type { BaseTexture } from "../Materials/Textures/baseTexture";
  7. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  8. import "../Shaders/layer.fragment";
  9. import "../Shaders/layer.vertex";
  10. /**
  11. * This represents a full screen 2d layer.
  12. * This can be useful to display a picture in the background of your scene for instance.
  13. * @see https://www.babylonjs-playground.com/#08A2BS#1
  14. */
  15. export declare class Layer {
  16. /**
  17. * Define the name of the layer.
  18. */
  19. name: string;
  20. /**
  21. * Define the texture the layer should display.
  22. */
  23. texture: Nullable<BaseTexture>;
  24. /**
  25. * Is the layer in background or foreground.
  26. */
  27. isBackground: boolean;
  28. private _applyPostProcess;
  29. /**
  30. * Determines if the layer is drawn before (true) or after (false) post-processing.
  31. * If the layer is background, it is always before.
  32. */
  33. set applyPostProcess(value: boolean);
  34. get applyPostProcess(): boolean;
  35. /**
  36. * Define the color of the layer (instead of texture).
  37. */
  38. color: Color4;
  39. /**
  40. * Define the scale of the layer in order to zoom in out of the texture.
  41. */
  42. scale: Vector2;
  43. /**
  44. * Define an offset for the layer in order to shift the texture.
  45. */
  46. offset: Vector2;
  47. /**
  48. * Define the alpha blending mode used in the layer in case the texture or color has an alpha.
  49. */
  50. alphaBlendingMode: number;
  51. /**
  52. * Define if the layer should alpha test or alpha blend with the rest of the scene.
  53. * Alpha test will not mix with the background color in case of transparency.
  54. * It will either use the texture color or the background depending on the alpha value of the current pixel.
  55. */
  56. alphaTest: boolean;
  57. /**
  58. * Define a mask to restrict the layer to only some of the scene cameras.
  59. */
  60. layerMask: number;
  61. /**
  62. * Define the list of render target the layer is visible into.
  63. */
  64. renderTargetTextures: RenderTargetTexture[];
  65. /**
  66. * Define if the layer is only used in renderTarget or if it also
  67. * renders in the main frame buffer of the canvas.
  68. */
  69. renderOnlyInRenderTargetTextures: boolean;
  70. /**
  71. * Define if the layer is enabled (ie. should be displayed). Default: true
  72. */
  73. isEnabled: boolean;
  74. private _scene;
  75. private _vertexBuffers;
  76. private _indexBuffer;
  77. private _drawWrapper;
  78. private _previousDefines;
  79. /**
  80. * An event triggered when the layer is disposed.
  81. */
  82. onDisposeObservable: Observable<Layer>;
  83. private _onDisposeObserver;
  84. /**
  85. * Back compatibility with callback before the onDisposeObservable existed.
  86. * The set callback will be triggered when the layer has been disposed.
  87. */
  88. set onDispose(callback: () => void);
  89. /**
  90. * An event triggered before rendering the scene
  91. */
  92. onBeforeRenderObservable: Observable<Layer>;
  93. private _onBeforeRenderObserver;
  94. /**
  95. * Back compatibility with callback before the onBeforeRenderObservable existed.
  96. * The set callback will be triggered just before rendering the layer.
  97. */
  98. set onBeforeRender(callback: () => void);
  99. /**
  100. * An event triggered after rendering the scene
  101. */
  102. onAfterRenderObservable: Observable<Layer>;
  103. private _onAfterRenderObserver;
  104. /**
  105. * Back compatibility with callback before the onAfterRenderObservable existed.
  106. * The set callback will be triggered just after rendering the layer.
  107. */
  108. set onAfterRender(callback: () => void);
  109. /**
  110. * Instantiates a new layer.
  111. * This represents a full screen 2d layer.
  112. * This can be useful to display a picture in the background of your scene for instance.
  113. * @see https://www.babylonjs-playground.com/#08A2BS#1
  114. * @param name Define the name of the layer in the scene
  115. * @param imgUrl Define the url of the texture to display in the layer
  116. * @param scene Define the scene the layer belongs to
  117. * @param isBackground Defines whether the layer is displayed in front or behind the scene
  118. * @param color Defines a color for the layer
  119. */
  120. constructor(
  121. /**
  122. * Define the name of the layer.
  123. */
  124. name: string, imgUrl: Nullable<string>, scene: Nullable<Scene>, isBackground?: boolean, color?: Color4);
  125. private _createIndexBuffer;
  126. /** @internal */
  127. _rebuild(): void;
  128. /**
  129. * Checks if the layer is ready to be rendered
  130. * @returns true if the layer is ready. False otherwise.
  131. */
  132. isReady(): boolean | undefined;
  133. /**
  134. * Renders the layer in the scene.
  135. */
  136. render(): void;
  137. /**
  138. * Disposes and releases the associated resources.
  139. */
  140. dispose(): void;
  141. }