screenshotTools.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import type { Camera } from "../Cameras/camera";
  2. import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  3. import type { IScreenshotSize } from "./interfaces/screenshotSize";
  4. import type { Engine } from "../Engines/engine";
  5. /**
  6. * Captures a screenshot of the current rendering
  7. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  8. * @param engine defines the rendering engine
  9. * @param camera defines the source camera
  10. * @param size This parameter can be set to a single number or to an object with the
  11. * following (optional) properties: precision, width, height. If a single number is passed,
  12. * it will be used for both width and height. If an object is passed, the screenshot size
  13. * will be derived from the parameters. The precision property is a multiplier allowing
  14. * rendering at a higher or lower resolution
  15. * @param successCallback defines the callback receives a single parameter which contains the
  16. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  17. * src parameter of an <img> to display it
  18. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  19. * Check your browser for supported MIME types
  20. * @param forceDownload force the system to download the image even if a successCallback is provided
  21. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  22. */
  23. export declare function CreateScreenshot(engine: Engine, camera: Camera, size: IScreenshotSize | number, successCallback?: (data: string) => void, mimeType?: string, forceDownload?: boolean, quality?: number): void;
  24. /**
  25. * Captures a screenshot of the current rendering
  26. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  27. * @param engine defines the rendering engine
  28. * @param camera defines the source camera
  29. * @param size This parameter can be set to a single number or to an object with the
  30. * following (optional) properties: precision, width, height. If a single number is passed,
  31. * it will be used for both width and height. If an object is passed, the screenshot size
  32. * will be derived from the parameters. The precision property is a multiplier allowing
  33. * rendering at a higher or lower resolution
  34. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  35. * Check your browser for supported MIME types
  36. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  37. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  38. * to the src parameter of an <img> to display it
  39. */
  40. export declare function CreateScreenshotAsync(engine: Engine, camera: Camera, size: IScreenshotSize | number, mimeType?: string, quality?: number): Promise<string>;
  41. /**
  42. * Captures a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)
  43. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  44. * @param engine defines the rendering engine
  45. * @param camera defines the source camera
  46. * @param width defines the expected width
  47. * @param height defines the expected height
  48. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  49. * Check your browser for supported MIME types
  50. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  51. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  52. * to the src parameter of an <img> to display it
  53. */
  54. export declare function CreateScreenshotWithResizeAsync(engine: Engine, camera: Camera, width: number, height: number, mimeType?: string, quality?: number): Promise<void>;
  55. /**
  56. * Generates an image screenshot from the specified camera.
  57. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  58. * @param engine The engine to use for rendering
  59. * @param camera The camera to use for rendering
  60. * @param size This parameter can be set to a single number or to an object with the
  61. * following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,
  62. * it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size
  63. * will be derived from the parameters. The precision property is a multiplier allowing
  64. * rendering at a higher or lower resolution
  65. * @param successCallback The callback receives a single parameter which contains the
  66. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  67. * src parameter of an <img> to display it
  68. * @param mimeType The MIME type of the screenshot image (default: image/png).
  69. * Check your browser for supported MIME types
  70. * @param samples Texture samples (default: 1)
  71. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  72. * @param fileName A name for for the downloaded file.
  73. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  74. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  75. * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
  76. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  77. * @param customizeTexture An optional callback that can be used to modify the render target texture before taking the screenshot. This can be used, for instance, to enable camera post-processes before taking the screenshot.
  78. */
  79. export declare function CreateScreenshotUsingRenderTarget(engine: Engine, camera: Camera, size: IScreenshotSize | number, successCallback?: (data: string) => void, mimeType?: string, samples?: number, antialiasing?: boolean, fileName?: string, renderSprites?: boolean, enableStencilBuffer?: boolean, useLayerMask?: boolean, quality?: number, customizeTexture?: (texture: RenderTargetTexture) => void): void;
  80. /**
  81. * Generates an image screenshot from the specified camera.
  82. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  83. * @param engine The engine to use for rendering
  84. * @param camera The camera to use for rendering
  85. * @param size This parameter can be set to a single number or to an object with the
  86. * following (optional) properties: precision, width, height. If a single number is passed,
  87. * it will be used for both width and height. If an object is passed, the screenshot size
  88. * will be derived from the parameters. The precision property is a multiplier allowing
  89. * rendering at a higher or lower resolution
  90. * @param mimeType The MIME type of the screenshot image (default: image/png).
  91. * Check your browser for supported MIME types
  92. * @param samples Texture samples (default: 1)
  93. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  94. * @param fileName A name for for the downloaded file.
  95. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  96. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  97. * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
  98. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  99. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  100. * to the src parameter of an <img> to display it
  101. */
  102. export declare function CreateScreenshotUsingRenderTargetAsync(engine: Engine, camera: Camera, size: IScreenshotSize | number, mimeType?: string, samples?: number, antialiasing?: boolean, fileName?: string, renderSprites?: boolean, enableStencilBuffer?: boolean, useLayerMask?: boolean, quality?: number): Promise<string>;
  103. /**
  104. * Class containing a set of static utilities functions for screenshots
  105. */
  106. export declare const ScreenshotTools: {
  107. /**
  108. * Captures a screenshot of the current rendering
  109. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  110. * @param engine defines the rendering engine
  111. * @param camera defines the source camera
  112. * @param size This parameter can be set to a single number or to an object with the
  113. * following (optional) properties: precision, width, height. If a single number is passed,
  114. * it will be used for both width and height. If an object is passed, the screenshot size
  115. * will be derived from the parameters. The precision property is a multiplier allowing
  116. * rendering at a higher or lower resolution
  117. * @param successCallback defines the callback receives a single parameter which contains the
  118. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  119. * src parameter of an <img> to display it
  120. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  121. * Check your browser for supported MIME types
  122. * @param forceDownload force the system to download the image even if a successCallback is provided
  123. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  124. */
  125. CreateScreenshot: typeof CreateScreenshot;
  126. /**
  127. * Captures a screenshot of the current rendering
  128. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  129. * @param engine defines the rendering engine
  130. * @param camera defines the source camera
  131. * @param size This parameter can be set to a single number or to an object with the
  132. * following (optional) properties: precision, width, height. If a single number is passed,
  133. * it will be used for both width and height. If an object is passed, the screenshot size
  134. * will be derived from the parameters. The precision property is a multiplier allowing
  135. * rendering at a higher or lower resolution
  136. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  137. * Check your browser for supported MIME types
  138. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  139. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  140. * to the src parameter of an <img> to display it
  141. */
  142. CreateScreenshotAsync: typeof CreateScreenshotAsync;
  143. /**
  144. * Captures a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)
  145. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  146. * @param engine defines the rendering engine
  147. * @param camera defines the source camera
  148. * @param width defines the expected width
  149. * @param height defines the expected height
  150. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  151. * Check your browser for supported MIME types
  152. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  153. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  154. * to the src parameter of an <img> to display it
  155. */
  156. CreateScreenshotWithResizeAsync: typeof CreateScreenshotWithResizeAsync;
  157. /**
  158. * Generates an image screenshot from the specified camera.
  159. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  160. * @param engine The engine to use for rendering
  161. * @param camera The camera to use for rendering
  162. * @param size This parameter can be set to a single number or to an object with the
  163. * following (optional) properties: precision, width, height. If a single number is passed,
  164. * it will be used for both width and height. If an object is passed, the screenshot size
  165. * will be derived from the parameters. The precision property is a multiplier allowing
  166. * rendering at a higher or lower resolution
  167. * @param successCallback The callback receives a single parameter which contains the
  168. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  169. * src parameter of an <img> to display it
  170. * @param mimeType The MIME type of the screenshot image (default: image/png).
  171. * Check your browser for supported MIME types
  172. * @param samples Texture samples (default: 1)
  173. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  174. * @param fileName A name for for the downloaded file.
  175. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  176. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  177. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  178. */
  179. CreateScreenshotUsingRenderTarget: typeof CreateScreenshotUsingRenderTarget;
  180. /**
  181. * Generates an image screenshot from the specified camera.
  182. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  183. * @param engine The engine to use for rendering
  184. * @param camera The camera to use for rendering
  185. * @param size This parameter can be set to a single number or to an object with the
  186. * following (optional) properties: precision, width, height. If a single number is passed,
  187. * it will be used for both width and height. If an object is passed, the screenshot size
  188. * will be derived from the parameters. The precision property is a multiplier allowing
  189. * rendering at a higher or lower resolution
  190. * @param mimeType The MIME type of the screenshot image (default: image/png).
  191. * Check your browser for supported MIME types
  192. * @param samples Texture samples (default: 1)
  193. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  194. * @param fileName A name for for the downloaded file.
  195. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  196. * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
  197. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  198. * to the src parameter of an <img> to display it
  199. */
  200. CreateScreenshotUsingRenderTargetAsync: typeof CreateScreenshotUsingRenderTargetAsync;
  201. };