tools.d.ts 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. import type { Nullable } from "../types";
  2. import { GetDOMTextContent, IsWindowObjectExist } from "./domManagement";
  3. import { WebRequest } from "./webRequest";
  4. import type { IFileRequest } from "./fileRequest";
  5. import type { ReadFileError } from "./fileTools";
  6. import type { IOfflineProvider } from "../Offline/IOfflineProvider";
  7. import type { IScreenshotSize } from "./interfaces/screenshotSize";
  8. import type { Camera } from "../Cameras/camera";
  9. import type { IColor4Like } from "../Maths/math.like";
  10. import type { AbstractEngine } from "../Engines/abstractEngine";
  11. /**
  12. * Class containing a set of static utilities functions
  13. */
  14. export declare class Tools {
  15. /**
  16. * Gets or sets the base URL to use to load assets
  17. */
  18. static get BaseUrl(): string;
  19. static set BaseUrl(value: string);
  20. /**
  21. * This function checks whether a URL is absolute or not.
  22. * It will also detect data and blob URLs
  23. * @param url the url to check
  24. * @returns is the url absolute or relative
  25. */
  26. static IsAbsoluteUrl(url: string): boolean;
  27. /**
  28. * Sets the base URL to use to load scripts
  29. */
  30. static set ScriptBaseUrl(value: string);
  31. static get ScriptBaseUrl(): string;
  32. /**
  33. * Sets a preprocessing function to run on a source URL before importing it
  34. * Note that this function will execute AFTER the base URL is appended to the URL
  35. */
  36. static set ScriptPreprocessUrl(func: (source: string) => string);
  37. static get ScriptPreprocessUrl(): (source: string) => string;
  38. /**
  39. * Enable/Disable Custom HTTP Request Headers globally.
  40. * default = false
  41. * @see CustomRequestHeaders
  42. */
  43. static UseCustomRequestHeaders: boolean;
  44. /**
  45. * Custom HTTP Request Headers to be sent with XMLHttpRequests
  46. * i.e. when loading files, where the server/service expects an Authorization header
  47. */
  48. static CustomRequestHeaders: {
  49. [key: string]: string;
  50. };
  51. /**
  52. * Gets or sets the retry strategy to apply when an error happens while loading an asset
  53. */
  54. static get DefaultRetryStrategy(): (url: string, request: WebRequest, retryIndex: number) => number;
  55. static set DefaultRetryStrategy(strategy: (url: string, request: WebRequest, retryIndex: number) => number);
  56. /**
  57. * Default behavior for cors in the application.
  58. * It can be a string if the expected behavior is identical in the entire app.
  59. * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)
  60. */
  61. static get CorsBehavior(): string | ((url: string | string[]) => string);
  62. static set CorsBehavior(value: string | ((url: string | string[]) => string));
  63. /**
  64. * Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded
  65. * @ignorenaming
  66. */
  67. static get UseFallbackTexture(): boolean;
  68. static set UseFallbackTexture(value: boolean);
  69. /**
  70. * Use this object to register external classes like custom textures or material
  71. * to allow the loaders to instantiate them
  72. */
  73. static get RegisteredExternalClasses(): {
  74. [key: string]: Object;
  75. };
  76. static set RegisteredExternalClasses(classes: {
  77. [key: string]: Object;
  78. });
  79. /**
  80. * Texture content used if a texture cannot loaded
  81. * @ignorenaming
  82. */
  83. static get fallbackTexture(): string;
  84. static set fallbackTexture(value: string);
  85. /**
  86. * Read the content of a byte array at a specified coordinates (taking in account wrapping)
  87. * @param u defines the coordinate on X axis
  88. * @param v defines the coordinate on Y axis
  89. * @param width defines the width of the source data
  90. * @param height defines the height of the source data
  91. * @param pixels defines the source byte array
  92. * @param color defines the output color
  93. */
  94. static FetchToRef(u: number, v: number, width: number, height: number, pixels: Uint8Array, color: IColor4Like): void;
  95. /**
  96. * Interpolates between a and b via alpha
  97. * @param a The lower value (returned when alpha = 0)
  98. * @param b The upper value (returned when alpha = 1)
  99. * @param alpha The interpolation-factor
  100. * @returns The mixed value
  101. */
  102. static Mix(a: number, b: number, alpha: number): number;
  103. /**
  104. * Tries to instantiate a new object from a given class name
  105. * @param className defines the class name to instantiate
  106. * @returns the new object or null if the system was not able to do the instantiation
  107. */
  108. static Instantiate(className: string): any;
  109. /**
  110. * Polyfill for setImmediate
  111. * @param action defines the action to execute after the current execution block
  112. */
  113. static SetImmediate(action: () => void): void;
  114. /**
  115. * Function indicating if a number is an exponent of 2
  116. * @param value defines the value to test
  117. * @returns true if the value is an exponent of 2
  118. */
  119. static IsExponentOfTwo(value: number): boolean;
  120. /**
  121. * Returns the nearest 32-bit single precision float representation of a Number
  122. * @param value A Number. If the parameter is of a different type, it will get converted
  123. * to a number or to NaN if it cannot be converted
  124. * @returns number
  125. */
  126. static FloatRound(value: number): number;
  127. /**
  128. * Extracts the filename from a path
  129. * @param path defines the path to use
  130. * @returns the filename
  131. */
  132. static GetFilename(path: string): string;
  133. /**
  134. * Extracts the "folder" part of a path (everything before the filename).
  135. * @param uri The URI to extract the info from
  136. * @param returnUnchangedIfNoSlash Do not touch the URI if no slashes are present
  137. * @returns The "folder" part of the path
  138. */
  139. static GetFolderPath(uri: string, returnUnchangedIfNoSlash?: boolean): string;
  140. /**
  141. * Extracts text content from a DOM element hierarchy
  142. * Back Compat only, please use GetDOMTextContent instead.
  143. */
  144. static GetDOMTextContent: typeof GetDOMTextContent;
  145. /**
  146. * Convert an angle in radians to degrees
  147. * @param angle defines the angle to convert
  148. * @returns the angle in degrees
  149. */
  150. static ToDegrees(angle: number): number;
  151. /**
  152. * Convert an angle in degrees to radians
  153. * @param angle defines the angle to convert
  154. * @returns the angle in radians
  155. */
  156. static ToRadians(angle: number): number;
  157. /**
  158. * Smooth angle changes (kind of low-pass filter), in particular for device orientation "shaking"
  159. * Use trigonometric functions to avoid discontinuity (0/360, -180/180)
  160. * @param previousAngle defines last angle value, in degrees
  161. * @param newAngle defines new angle value, in degrees
  162. * @param smoothFactor defines smoothing sensitivity; min 0: no smoothing, max 1: new data ignored
  163. * @returns the angle in degrees
  164. */
  165. static SmoothAngleChange(previousAngle: number, newAngle: number, smoothFactor?: number): number;
  166. /**
  167. * Returns an array if obj is not an array
  168. * @param obj defines the object to evaluate as an array
  169. * @param allowsNullUndefined defines a boolean indicating if obj is allowed to be null or undefined
  170. * @returns either obj directly if obj is an array or a new array containing obj
  171. */
  172. static MakeArray(obj: any, allowsNullUndefined?: boolean): Nullable<Array<any>>;
  173. /**
  174. * Gets the pointer prefix to use
  175. * @param engine defines the engine we are finding the prefix for
  176. * @returns "pointer" if touch is enabled. Else returns "mouse"
  177. */
  178. static GetPointerPrefix(engine: AbstractEngine): string;
  179. /**
  180. * Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.
  181. * @param url define the url we are trying
  182. * @param element define the dom element where to configure the cors policy
  183. * @param element.crossOrigin
  184. */
  185. static SetCorsBehavior(url: string | string[], element: {
  186. crossOrigin: string | null;
  187. }): void;
  188. /**
  189. * Sets the referrerPolicy behavior on a dom element.
  190. * @param referrerPolicy define the referrer policy to use
  191. * @param element define the dom element where to configure the referrer policy
  192. * @param element.referrerPolicy
  193. */
  194. static SetReferrerPolicyBehavior(referrerPolicy: Nullable<ReferrerPolicy>, element: {
  195. referrerPolicy: string | null;
  196. }): void;
  197. /**
  198. * Removes unwanted characters from an url
  199. * @param url defines the url to clean
  200. * @returns the cleaned url
  201. */
  202. static CleanUrl(url: string): string;
  203. /**
  204. * Gets or sets a function used to pre-process url before using them to load assets
  205. */
  206. static get PreprocessUrl(): (url: string) => string;
  207. static set PreprocessUrl(processor: (url: string) => string);
  208. /**
  209. * Loads an image as an HTMLImageElement.
  210. * @param input url string, ArrayBuffer, or Blob to load
  211. * @param onLoad callback called when the image successfully loads
  212. * @param onError callback called when the image fails to load
  213. * @param offlineProvider offline provider for caching
  214. * @param mimeType optional mime type
  215. * @param imageBitmapOptions optional the options to use when creating an ImageBitmap
  216. * @returns the HTMLImageElement of the loaded image
  217. */
  218. static LoadImage(input: string | ArrayBuffer | Blob, onLoad: (img: HTMLImageElement | ImageBitmap) => void, onError: (message?: string, exception?: any) => void, offlineProvider: Nullable<IOfflineProvider>, mimeType?: string, imageBitmapOptions?: ImageBitmapOptions): Nullable<HTMLImageElement>;
  219. /**
  220. * Loads a file from a url
  221. * @param url url string, ArrayBuffer, or Blob to load
  222. * @param onSuccess callback called when the file successfully loads
  223. * @param onProgress callback called while file is loading (if the server supports this mode)
  224. * @param offlineProvider defines the offline provider for caching
  225. * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer
  226. * @param onError callback called when the file fails to load
  227. * @returns a file request object
  228. */
  229. static LoadFile(url: string, onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void, onProgress?: (data: any) => void, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean, onError?: (request?: WebRequest, exception?: any) => void): IFileRequest;
  230. static LoadFileAsync(url: string, useArrayBuffer?: true): Promise<ArrayBuffer>;
  231. static LoadFileAsync(url: string, useArrayBuffer?: false): Promise<string>;
  232. /**
  233. * @internal
  234. */
  235. static _DefaultCdnUrl: string;
  236. /**
  237. * Get a script URL including preprocessing
  238. * @param scriptUrl the script Url to process
  239. * @param forceAbsoluteUrl force the script to be an absolute url (adding the current base url if necessary)
  240. * @returns a modified URL to use
  241. */
  242. static GetBabylonScriptURL(scriptUrl: Nullable<string>, forceAbsoluteUrl?: boolean): string;
  243. /**
  244. * This function is used internally by babylon components to load a script (identified by an url). When the url returns, the
  245. * content of this file is added into a new script element, attached to the DOM (body element)
  246. * @param scriptUrl defines the url of the script to load
  247. * @param onSuccess defines the callback called when the script is loaded
  248. * @param onError defines the callback to call if an error occurs
  249. * @param scriptId defines the id of the script element
  250. */
  251. static LoadBabylonScript(scriptUrl: string, onSuccess: () => void, onError?: (message?: string, exception?: any) => void, scriptId?: string): void;
  252. /**
  253. * Load an asynchronous script (identified by an url). When the url returns, the
  254. * content of this file is added into a new script element, attached to the DOM (body element)
  255. * @param scriptUrl defines the url of the script to laod
  256. * @returns a promise request object
  257. */
  258. static LoadBabylonScriptAsync(scriptUrl: string): Promise<void>;
  259. /**
  260. * This function is used internally by babylon components to load a script (identified by an url). When the url returns, the
  261. * content of this file is added into a new script element, attached to the DOM (body element)
  262. * @param scriptUrl defines the url of the script to load
  263. * @param onSuccess defines the callback called when the script is loaded
  264. * @param onError defines the callback to call if an error occurs
  265. * @param scriptId defines the id of the script element
  266. */
  267. static LoadScript(scriptUrl: string, onSuccess: () => void, onError?: (message?: string, exception?: any) => void, scriptId?: string): void;
  268. /**
  269. * Load an asynchronous script (identified by an url). When the url returns, the
  270. * content of this file is added into a new script element, attached to the DOM (body element)
  271. * @param scriptUrl defines the url of the script to load
  272. * @param scriptId defines the id of the script element
  273. * @returns a promise request object
  274. */
  275. static LoadScriptAsync(scriptUrl: string, scriptId?: string): Promise<void>;
  276. /**
  277. * Loads a file from a blob
  278. * @param fileToLoad defines the blob to use
  279. * @param callback defines the callback to call when data is loaded
  280. * @param progressCallback defines the callback to call during loading process
  281. * @returns a file request object
  282. */
  283. static ReadFileAsDataURL(fileToLoad: Blob, callback: (data: any) => void, progressCallback: (ev: ProgressEvent) => any): IFileRequest;
  284. /**
  285. * Reads a file from a File object
  286. * @param file defines the file to load
  287. * @param onSuccess defines the callback to call when data is loaded
  288. * @param onProgress defines the callback to call during loading process
  289. * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer
  290. * @param onError defines the callback to call when an error occurs
  291. * @returns a file request object
  292. */
  293. static ReadFile(file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: ReadFileError) => void): IFileRequest;
  294. /**
  295. * Creates a data url from a given string content
  296. * @param content defines the content to convert
  297. * @returns the new data url link
  298. */
  299. static FileAsURL(content: string): string;
  300. /**
  301. * Format the given number to a specific decimal format
  302. * @param value defines the number to format
  303. * @param decimals defines the number of decimals to use
  304. * @returns the formatted string
  305. */
  306. static Format(value: number, decimals?: number): string;
  307. /**
  308. * Tries to copy an object by duplicating every property
  309. * @param source defines the source object
  310. * @param destination defines the target object
  311. * @param doNotCopyList defines a list of properties to avoid
  312. * @param mustCopyList defines a list of properties to copy (even if they start with _)
  313. */
  314. static DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void;
  315. /**
  316. * Gets a boolean indicating if the given object has no own property
  317. * @param obj defines the object to test
  318. * @returns true if object has no own property
  319. */
  320. static IsEmpty(obj: any): boolean;
  321. /**
  322. * Function used to register events at window level
  323. * @param windowElement defines the Window object to use
  324. * @param events defines the events to register
  325. */
  326. static RegisterTopRootEvents(windowElement: Window, events: {
  327. name: string;
  328. handler: Nullable<(e: FocusEvent) => any>;
  329. }[]): void;
  330. /**
  331. * Function used to unregister events from window level
  332. * @param windowElement defines the Window object to use
  333. * @param events defines the events to unregister
  334. */
  335. static UnregisterTopRootEvents(windowElement: Window, events: {
  336. name: string;
  337. handler: Nullable<(e: FocusEvent) => any>;
  338. }[]): void;
  339. /**
  340. * Dumps the current bound framebuffer
  341. * @param width defines the rendering width
  342. * @param height defines the rendering height
  343. * @param engine defines the hosting engine
  344. * @param successCallback defines the callback triggered once the data are available
  345. * @param mimeType defines the mime type of the result
  346. * @param fileName defines the filename to download. If present, the result will automatically be downloaded
  347. * @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.
  348. * @returns a void promise
  349. */
  350. static DumpFramebuffer(width: number, height: number, engine: AbstractEngine, successCallback?: (data: string) => void, mimeType?: string, fileName?: string, quality?: number): Promise<void>;
  351. /**
  352. * Dumps an array buffer
  353. * @param width defines the rendering width
  354. * @param height defines the rendering height
  355. * @param data the data array
  356. * @param successCallback defines the callback triggered once the data are available
  357. * @param mimeType defines the mime type of the result
  358. * @param fileName defines the filename to download. If present, the result will automatically be downloaded
  359. * @param invertY true to invert the picture in the Y dimension
  360. * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
  361. * @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.
  362. */
  363. static DumpData(width: number, height: number, data: ArrayBufferView, successCallback?: (data: string | ArrayBuffer) => void, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): void;
  364. /**
  365. * Dumps an array buffer
  366. * @param width defines the rendering width
  367. * @param height defines the rendering height
  368. * @param data the data array
  369. * @param mimeType defines the mime type of the result
  370. * @param fileName defines the filename to download. If present, the result will automatically be downloaded
  371. * @param invertY true to invert the picture in the Y dimension
  372. * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string
  373. * @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.
  374. * @returns a promise that resolve to the final data
  375. */
  376. static DumpDataAsync(width: number, height: number, data: ArrayBufferView, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): Promise<string | ArrayBuffer>;
  377. private static _IsOffScreenCanvas;
  378. /**
  379. * Converts the canvas data to blob.
  380. * This acts as a polyfill for browsers not supporting the to blob function.
  381. * @param canvas Defines the canvas to extract the data from (can be an offscreen canvas)
  382. * @param successCallback Defines the callback triggered once the data are available
  383. * @param mimeType Defines the mime type of the result
  384. * @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.
  385. */
  386. static ToBlob(canvas: HTMLCanvasElement | OffscreenCanvas, successCallback: (blob: Nullable<Blob>) => void, mimeType?: string, quality?: number): void;
  387. /**
  388. * Download a Blob object
  389. * @param blob the Blob object
  390. * @param fileName the file name to download
  391. */
  392. static DownloadBlob(blob: Blob, fileName?: string): void;
  393. /**
  394. * Encodes the canvas data to base 64, or automatically downloads the result if `fileName` is defined.
  395. * @param canvas The canvas to get the data from, which can be an offscreen canvas.
  396. * @param successCallback The callback which is triggered once the data is available. If `fileName` is defined, the callback will be invoked after the download occurs, and the `data` argument will be an empty string.
  397. * @param mimeType The mime type of the result.
  398. * @param fileName The name of the file to download. If defined, the result will automatically be downloaded. If not defined, and `successCallback` is also not defined, the result will automatically be downloaded with an auto-generated file name.
  399. * @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.
  400. */
  401. static EncodeScreenshotCanvasData(canvas: HTMLCanvasElement | OffscreenCanvas, successCallback?: (data: string) => void, mimeType?: string, fileName?: string, quality?: number): void;
  402. /**
  403. * Downloads a blob in the browser
  404. * @param blob defines the blob to download
  405. * @param fileName defines the name of the downloaded file
  406. */
  407. static Download(blob: Blob, fileName: string): void;
  408. /**
  409. * Will return the right value of the noPreventDefault variable
  410. * Needed to keep backwards compatibility to the old API.
  411. *
  412. * @param args arguments passed to the attachControl function
  413. * @returns the correct value for noPreventDefault
  414. */
  415. static BackCompatCameraNoPreventDefault(args: IArguments): boolean;
  416. /**
  417. * Captures a screenshot of the current rendering
  418. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  419. * @param engine defines the rendering engine
  420. * @param camera defines the source camera
  421. * @param size This parameter can be set to a single number or to an object with the
  422. * following (optional) properties: precision, width, height. If a single number is passed,
  423. * it will be used for both width and height. If an object is passed, the screenshot size
  424. * will be derived from the parameters. The precision property is a multiplier allowing
  425. * rendering at a higher or lower resolution
  426. * @param successCallback defines the callback receives a single parameter which contains the
  427. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  428. * src parameter of an <img> to display it
  429. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  430. * Check your browser for supported MIME types
  431. * @param forceDownload force the system to download the image even if a successCallback is provided
  432. * @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.
  433. */
  434. static CreateScreenshot(engine: AbstractEngine, camera: Camera, size: IScreenshotSize | number, successCallback?: (data: string) => void, mimeType?: string, forceDownload?: boolean, quality?: number): void;
  435. /**
  436. * Captures a screenshot of the current rendering
  437. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  438. * @param engine defines the rendering engine
  439. * @param camera defines the source camera
  440. * @param size This parameter can be set to a single number or to an object with the
  441. * following (optional) properties: precision, width, height. If a single number is passed,
  442. * it will be used for both width and height. If an object is passed, the screenshot size
  443. * will be derived from the parameters. The precision property is a multiplier allowing
  444. * rendering at a higher or lower resolution
  445. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  446. * Check your browser for supported MIME types
  447. * @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.
  448. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  449. * to the src parameter of an <img> to display it
  450. */
  451. static CreateScreenshotAsync(engine: AbstractEngine, camera: Camera, size: IScreenshotSize | number, mimeType?: string, quality?: number): Promise<string>;
  452. /**
  453. * Generates an image screenshot from the specified camera.
  454. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  455. * @param engine The engine to use for rendering
  456. * @param camera The camera to use for rendering
  457. * @param size This parameter can be set to a single number or to an object with the
  458. * following (optional) properties: precision, width, height. If a single number is passed,
  459. * it will be used for both width and height. If an object is passed, the screenshot size
  460. * will be derived from the parameters. The precision property is a multiplier allowing
  461. * rendering at a higher or lower resolution
  462. * @param successCallback The callback receives a single parameter which contains the
  463. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  464. * src parameter of an <img> to display it
  465. * @param mimeType The MIME type of the screenshot image (default: image/png).
  466. * Check your browser for supported MIME types
  467. * @param samples Texture samples (default: 1)
  468. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  469. * @param fileName A name for for the downloaded file.
  470. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  471. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  472. * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
  473. * @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.
  474. */
  475. static CreateScreenshotUsingRenderTarget(engine: AbstractEngine, 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): void;
  476. /**
  477. * Generates an image screenshot from the specified camera.
  478. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
  479. * @param engine The engine to use for rendering
  480. * @param camera The camera to use for rendering
  481. * @param size This parameter can be set to a single number or to an object with the
  482. * following (optional) properties: precision, width, height. If a single number is passed,
  483. * it will be used for both width and height. If an object is passed, the screenshot size
  484. * will be derived from the parameters. The precision property is a multiplier allowing
  485. * rendering at a higher or lower resolution
  486. * @param mimeType The MIME type of the screenshot image (default: image/png).
  487. * Check your browser for supported MIME types
  488. * @param samples Texture samples (default: 1)
  489. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  490. * @param fileName A name for for the downloaded file.
  491. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  492. * @param renderSprites Whether the sprites should be rendered or not (default: false)
  493. * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)
  494. * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
  495. * @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.
  496. * to the src parameter of an <img> to display it
  497. */
  498. static CreateScreenshotUsingRenderTargetAsync(engine: AbstractEngine, camera: Camera, size: IScreenshotSize | number, mimeType?: string, samples?: number, antialiasing?: boolean, fileName?: string, renderSprites?: boolean, enableStencilBuffer?: boolean, useLayerMask?: boolean, quality?: number): Promise<string>;
  499. /**
  500. * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
  501. * Be aware Math.random() could cause collisions, but:
  502. * "All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide"
  503. * @returns a pseudo random id
  504. */
  505. static RandomId(): string;
  506. /**
  507. * Test if the given uri is a base64 string
  508. * @deprecated Please use FileTools.IsBase64DataUrl instead.
  509. * @param uri The uri to test
  510. * @returns True if the uri is a base64 string or false otherwise
  511. */
  512. static IsBase64(uri: string): boolean;
  513. /**
  514. * Decode the given base64 uri.
  515. * @deprecated Please use FileTools.DecodeBase64UrlToBinary instead.
  516. * @param uri The uri to decode
  517. * @returns The decoded base64 data.
  518. */
  519. static DecodeBase64(uri: string): ArrayBuffer;
  520. /**
  521. * @returns the absolute URL of a given (relative) url
  522. */
  523. static GetAbsoluteUrl: (url: string) => string;
  524. /**
  525. * No log
  526. */
  527. static readonly NoneLogLevel = 0;
  528. /**
  529. * Only message logs
  530. */
  531. static readonly MessageLogLevel = 1;
  532. /**
  533. * Only warning logs
  534. */
  535. static readonly WarningLogLevel = 2;
  536. /**
  537. * Only error logs
  538. */
  539. static readonly ErrorLogLevel = 4;
  540. /**
  541. * All logs
  542. */
  543. static readonly AllLogLevel = 7;
  544. /**
  545. * Gets a value indicating the number of loading errors
  546. * @ignorenaming
  547. */
  548. static get errorsCount(): number;
  549. /**
  550. * Callback called when a new log is added
  551. */
  552. static OnNewCacheEntry: (entry: string) => void;
  553. /**
  554. * Log a message to the console
  555. * @param message defines the message to log
  556. */
  557. static Log(message: string): void;
  558. /**
  559. * Write a warning message to the console
  560. * @param message defines the message to log
  561. */
  562. static Warn(message: string): void;
  563. /**
  564. * Write an error message to the console
  565. * @param message defines the message to log
  566. */
  567. static Error(message: string): void;
  568. /**
  569. * Gets current log cache (list of logs)
  570. */
  571. static get LogCache(): string;
  572. /**
  573. * Clears the log cache
  574. */
  575. static ClearLogCache(): void;
  576. /**
  577. * Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)
  578. */
  579. static set LogLevels(level: number);
  580. /**
  581. * Checks if the window object exists
  582. * Back Compat only, please use IsWindowObjectExist instead.
  583. */
  584. static IsWindowObjectExist: typeof IsWindowObjectExist;
  585. /**
  586. * No performance log
  587. */
  588. static readonly PerformanceNoneLogLevel = 0;
  589. /**
  590. * Use user marks to log performance
  591. */
  592. static readonly PerformanceUserMarkLogLevel = 1;
  593. /**
  594. * Log performance to the console
  595. */
  596. static readonly PerformanceConsoleLogLevel = 2;
  597. private static _Performance;
  598. /**
  599. * Sets the current performance log level
  600. */
  601. static set PerformanceLogLevel(level: number);
  602. private static _StartPerformanceCounterDisabled;
  603. private static _EndPerformanceCounterDisabled;
  604. private static _StartUserMark;
  605. private static _EndUserMark;
  606. private static _StartPerformanceConsole;
  607. private static _EndPerformanceConsole;
  608. /**
  609. * Starts a performance counter
  610. */
  611. static StartPerformanceCounter: (counterName: string, condition?: boolean) => void;
  612. /**
  613. * Ends a specific performance counter
  614. */
  615. static EndPerformanceCounter: (counterName: string, condition?: boolean) => void;
  616. /**
  617. * Gets either window.performance.now() if supported or Date.now() else
  618. */
  619. static get Now(): number;
  620. /**
  621. * This method will return the name of the class used to create the instance of the given object.
  622. * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator.
  623. * @param object the object to get the class name from
  624. * @param isType defines if the object is actually a type
  625. * @returns the name of the class, will be "object" for a custom data type not using the @className decorator
  626. */
  627. static GetClassName(object: any, isType?: boolean): string;
  628. /**
  629. * Gets the first element of an array satisfying a given predicate
  630. * @param array defines the array to browse
  631. * @param predicate defines the predicate to use
  632. * @returns null if not found or the element
  633. */
  634. static First<T>(array: Array<T>, predicate: (item: T) => boolean): Nullable<T>;
  635. /**
  636. * This method will return the name of the full name of the class, including its owning module (if any).
  637. * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator or implementing a method getClassName():string (in which case the module won't be specified).
  638. * @param object the object to get the class name from
  639. * @param isType defines if the object is actually a type
  640. * @returns a string that can have two forms: "moduleName.className" if module was specified when the class' Name was registered or "className" if there was not module specified.
  641. * @ignorenaming
  642. */
  643. static getFullClassName(object: any, isType?: boolean): Nullable<string>;
  644. /**
  645. * Returns a promise that resolves after the given amount of time.
  646. * @param delay Number of milliseconds to delay
  647. * @returns Promise that resolves after the given amount of time
  648. */
  649. static DelayAsync(delay: number): Promise<void>;
  650. /**
  651. * Utility function to detect if the current user agent is Safari
  652. * @returns whether or not the current user agent is safari
  653. */
  654. static IsSafari(): boolean;
  655. }
  656. /**
  657. * Use this className as a decorator on a given class definition to add it a name and optionally its module.
  658. * You can then use the Tools.getClassName(obj) on an instance to retrieve its class name.
  659. * This method is the only way to get it done in all cases, even if the .js file declaring the class is minified
  660. * @param name The name of the class, case should be preserved
  661. * @param module The name of the Module hosting the class, optional, but strongly recommended to specify if possible. Case should be preserved.
  662. * @returns a decorator function to apply on the class definition.
  663. */
  664. export declare function className(name: string, module?: string): (target: Object) => void;
  665. /**
  666. * An implementation of a loop for asynchronous functions.
  667. */
  668. export declare class AsyncLoop {
  669. /**
  670. * Defines the number of iterations for the loop
  671. */
  672. iterations: number;
  673. /**
  674. * Defines the current index of the loop.
  675. */
  676. index: number;
  677. private _done;
  678. private _fn;
  679. private _successCallback;
  680. /**
  681. * Constructor.
  682. * @param iterations the number of iterations.
  683. * @param func the function to run each iteration
  684. * @param successCallback the callback that will be called upon successful execution
  685. * @param offset starting offset.
  686. */
  687. constructor(
  688. /**
  689. * Defines the number of iterations for the loop
  690. */
  691. iterations: number, func: (asyncLoop: AsyncLoop) => void, successCallback: () => void, offset?: number);
  692. /**
  693. * Execute the next iteration. Must be called after the last iteration was finished.
  694. */
  695. executeNext(): void;
  696. /**
  697. * Break the loop and run the success callback.
  698. */
  699. breakLoop(): void;
  700. /**
  701. * Create and run an async loop.
  702. * @param iterations the number of iterations.
  703. * @param fn the function to run each iteration
  704. * @param successCallback the callback that will be called upon successful execution
  705. * @param offset starting offset.
  706. * @returns the created async loop object
  707. */
  708. static Run(iterations: number, fn: (asyncLoop: AsyncLoop) => void, successCallback: () => void, offset?: number): AsyncLoop;
  709. /**
  710. * A for-loop that will run a given number of iterations synchronous and the rest async.
  711. * @param iterations total number of iterations
  712. * @param syncedIterations number of synchronous iterations in each async iteration.
  713. * @param fn the function to call each iteration.
  714. * @param callback a success call back that will be called when iterating stops.
  715. * @param breakFunction a break condition (optional)
  716. * @param timeout timeout settings for the setTimeout function. default - 0.
  717. * @returns the created async loop object
  718. */
  719. static SyncAsyncForLoop(iterations: number, syncedIterations: number, fn: (iteration: number) => void, callback: () => void, breakFunction?: () => boolean, timeout?: number): AsyncLoop;
  720. }