tools.ts 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. import { Nullable, float } from "../types";
  2. import { Observable } from "./observable";
  3. import { DomManagement } from "./domManagement";
  4. import { Logger } from "./logger";
  5. import { _TypeStore } from "./typeStore";
  6. import { DeepCopier } from "./deepCopier";
  7. import { PrecisionDate } from './precisionDate';
  8. import { _DevTools } from './devTools';
  9. import { WebRequest } from './webRequest';
  10. import { IFileRequest } from './fileRequest';
  11. import { EngineStore } from '../Engines/engineStore';
  12. import { FileTools, ReadFileError } from './fileTools';
  13. import { IOfflineProvider } from '../Offline/IOfflineProvider';
  14. import { PromisePolyfill } from './promise';
  15. import { TimingTools } from './timingTools';
  16. import { InstantiationTools } from './instantiationTools';
  17. import { GUID } from './guid';
  18. import { IScreenshotSize } from './interfaces/screenshotSize';
  19. declare type Camera = import("../Cameras/camera").Camera;
  20. declare type Engine = import("../Engines/engine").Engine;
  21. interface IColor4Like {
  22. r: float;
  23. g: float;
  24. b: float;
  25. a: float;
  26. }
  27. /**
  28. * Class containing a set of static utilities functions
  29. */
  30. export class Tools {
  31. /**
  32. * Gets or sets the base URL to use to load assets
  33. */
  34. public static get BaseUrl() {
  35. return FileTools.BaseUrl;
  36. }
  37. public static set BaseUrl(value: string) {
  38. FileTools.BaseUrl = value;
  39. }
  40. /**
  41. * Enable/Disable Custom HTTP Request Headers globally.
  42. * default = false
  43. * @see CustomRequestHeaders
  44. */
  45. public static UseCustomRequestHeaders: boolean = false;
  46. /**
  47. * Custom HTTP Request Headers to be sent with XMLHttpRequests
  48. * i.e. when loading files, where the server/service expects an Authorization header
  49. */
  50. public static CustomRequestHeaders = WebRequest.CustomRequestHeaders;
  51. /**
  52. * Gets or sets the retry strategy to apply when an error happens while loading an asset
  53. */
  54. public static get DefaultRetryStrategy() {
  55. return FileTools.DefaultRetryStrategy;
  56. }
  57. public static set DefaultRetryStrategy(strategy: (url: string, request: WebRequest, retryIndex: number) => number) {
  58. FileTools.DefaultRetryStrategy = strategy;
  59. }
  60. /**
  61. * Default behaviour for cors in the application.
  62. * It can be a string if the expected behavior is identical in the entire app.
  63. * Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)
  64. */
  65. public static CorsBehavior: string | ((url: string | string[]) => string) = "anonymous";
  66. /**
  67. * Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded
  68. * @ignorenaming
  69. */
  70. public static get UseFallbackTexture() {
  71. return EngineStore.UseFallbackTexture;
  72. }
  73. public static set UseFallbackTexture(value: boolean) {
  74. EngineStore.UseFallbackTexture = value;
  75. }
  76. /**
  77. * Use this object to register external classes like custom textures or material
  78. * to allow the laoders to instantiate them
  79. */
  80. public static get RegisteredExternalClasses() {
  81. return InstantiationTools.RegisteredExternalClasses;
  82. }
  83. public static set RegisteredExternalClasses(classes: { [key: string]: Object }) {
  84. InstantiationTools.RegisteredExternalClasses = classes;
  85. }
  86. /**
  87. * Texture content used if a texture cannot loaded
  88. * @ignorenaming
  89. */
  90. public static get fallbackTexture() {
  91. return EngineStore.FallbackTexture;
  92. }
  93. public static set fallbackTexture(value: string) {
  94. EngineStore.FallbackTexture = value;
  95. }
  96. /**
  97. * Read the content of a byte array at a specified coordinates (taking in account wrapping)
  98. * @param u defines the coordinate on X axis
  99. * @param v defines the coordinate on Y axis
  100. * @param width defines the width of the source data
  101. * @param height defines the height of the source data
  102. * @param pixels defines the source byte array
  103. * @param color defines the output color
  104. */
  105. public static FetchToRef(u: number, v: number, width: number, height: number, pixels: Uint8Array, color: IColor4Like): void {
  106. let wrappedU = ((Math.abs(u) * width) % width) | 0;
  107. let wrappedV = ((Math.abs(v) * height) % height) | 0;
  108. let position = (wrappedU + wrappedV * width) * 4;
  109. color.r = pixels[position] / 255;
  110. color.g = pixels[position + 1] / 255;
  111. color.b = pixels[position + 2] / 255;
  112. color.a = pixels[position + 3] / 255;
  113. }
  114. /**
  115. * Interpolates between a and b via alpha
  116. * @param a The lower value (returned when alpha = 0)
  117. * @param b The upper value (returned when alpha = 1)
  118. * @param alpha The interpolation-factor
  119. * @return The mixed value
  120. */
  121. public static Mix(a: number, b: number, alpha: number): number {
  122. return a * (1 - alpha) + b * alpha;
  123. }
  124. /**
  125. * Tries to instantiate a new object from a given class name
  126. * @param className defines the class name to instantiate
  127. * @returns the new object or null if the system was not able to do the instantiation
  128. */
  129. public static Instantiate(className: string): any {
  130. return InstantiationTools.Instantiate(className);
  131. }
  132. /**
  133. * Provides a slice function that will work even on IE
  134. * @param data defines the array to slice
  135. * @param start defines the start of the data (optional)
  136. * @param end defines the end of the data (optional)
  137. * @returns the new sliced array
  138. */
  139. public static Slice<T>(data: T, start?: number, end?: number): T {
  140. if ((data as any).slice) {
  141. return (data as any).slice(start, end);
  142. }
  143. return Array.prototype.slice.call(data, start, end);
  144. }
  145. /**
  146. * Polyfill for setImmediate
  147. * @param action defines the action to execute after the current execution block
  148. */
  149. public static SetImmediate(action: () => void) {
  150. TimingTools.SetImmediate(action);
  151. }
  152. /**
  153. * Function indicating if a number is an exponent of 2
  154. * @param value defines the value to test
  155. * @returns true if the value is an exponent of 2
  156. */
  157. public static IsExponentOfTwo(value: number): boolean {
  158. var count = 1;
  159. do {
  160. count *= 2;
  161. } while (count < value);
  162. return count === value;
  163. }
  164. private static _tmpFloatArray = new Float32Array(1);
  165. /**
  166. * Returns the nearest 32-bit single precision float representation of a Number
  167. * @param value A Number. If the parameter is of a different type, it will get converted
  168. * to a number or to NaN if it cannot be converted
  169. * @returns number
  170. */
  171. public static FloatRound(value: number): number {
  172. if (Math.fround) {
  173. return Math.fround(value);
  174. }
  175. return (Tools._tmpFloatArray[0] = value);
  176. }
  177. /**
  178. * Extracts the filename from a path
  179. * @param path defines the path to use
  180. * @returns the filename
  181. */
  182. public static GetFilename(path: string): string {
  183. var index = path.lastIndexOf("/");
  184. if (index < 0) {
  185. return path;
  186. }
  187. return path.substring(index + 1);
  188. }
  189. /**
  190. * Extracts the "folder" part of a path (everything before the filename).
  191. * @param uri The URI to extract the info from
  192. * @param returnUnchangedIfNoSlash Do not touch the URI if no slashes are present
  193. * @returns The "folder" part of the path
  194. */
  195. public static GetFolderPath(uri: string, returnUnchangedIfNoSlash = false): string {
  196. var index = uri.lastIndexOf("/");
  197. if (index < 0) {
  198. if (returnUnchangedIfNoSlash) {
  199. return uri;
  200. }
  201. return "";
  202. }
  203. return uri.substring(0, index + 1);
  204. }
  205. /**
  206. * Extracts text content from a DOM element hierarchy
  207. * Back Compat only, please use DomManagement.GetDOMTextContent instead.
  208. */
  209. public static GetDOMTextContent = DomManagement.GetDOMTextContent;
  210. /**
  211. * Convert an angle in radians to degrees
  212. * @param angle defines the angle to convert
  213. * @returns the angle in degrees
  214. */
  215. public static ToDegrees(angle: number): number {
  216. return angle * 180 / Math.PI;
  217. }
  218. /**
  219. * Convert an angle in degrees to radians
  220. * @param angle defines the angle to convert
  221. * @returns the angle in radians
  222. */
  223. public static ToRadians(angle: number): number {
  224. return angle * Math.PI / 180;
  225. }
  226. /**
  227. * Returns an array if obj is not an array
  228. * @param obj defines the object to evaluate as an array
  229. * @param allowsNullUndefined defines a boolean indicating if obj is allowed to be null or undefined
  230. * @returns either obj directly if obj is an array or a new array containing obj
  231. */
  232. public static MakeArray(obj: any, allowsNullUndefined?: boolean): Nullable<Array<any>> {
  233. if (allowsNullUndefined !== true && (obj === undefined || obj == null)) {
  234. return null;
  235. }
  236. return Array.isArray(obj) ? obj : [obj];
  237. }
  238. /**
  239. * Gets the pointer prefix to use
  240. * @returns "pointer" if touch is enabled. Else returns "mouse"
  241. */
  242. public static GetPointerPrefix(): string {
  243. var eventPrefix = "pointer";
  244. // Check if pointer events are supported
  245. if (DomManagement.IsWindowObjectExist() && !window.PointerEvent && DomManagement.IsNavigatorAvailable() && !navigator.pointerEnabled) {
  246. eventPrefix = "mouse";
  247. }
  248. return eventPrefix;
  249. }
  250. /**
  251. * Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.
  252. * @param url define the url we are trying
  253. * @param element define the dom element where to configure the cors policy
  254. */
  255. public static SetCorsBehavior(url: string | string[], element: { crossOrigin: string | null }): void {
  256. FileTools.SetCorsBehavior(url, element);
  257. }
  258. // External files
  259. /**
  260. * Removes unwanted characters from an url
  261. * @param url defines the url to clean
  262. * @returns the cleaned url
  263. */
  264. public static CleanUrl(url: string): string {
  265. url = url.replace(/#/mg, "%23");
  266. return url;
  267. }
  268. /**
  269. * Gets or sets a function used to pre-process url before using them to load assets
  270. */
  271. public static get PreprocessUrl() {
  272. return FileTools.PreprocessUrl;
  273. }
  274. public static set PreprocessUrl(processor: (url: string) => string) {
  275. FileTools.PreprocessUrl = processor;
  276. }
  277. /**
  278. * Loads an image as an HTMLImageElement.
  279. * @param input url string, ArrayBuffer, or Blob to load
  280. * @param onLoad callback called when the image successfully loads
  281. * @param onError callback called when the image fails to load
  282. * @param offlineProvider offline provider for caching
  283. * @param mimeType optional mime type
  284. * @returns the HTMLImageElement of the loaded image
  285. */
  286. public static LoadImage(input: string | ArrayBuffer | Blob, onLoad: (img: HTMLImageElement | ImageBitmap) => void, onError: (message?: string, exception?: any) => void, offlineProvider: Nullable<IOfflineProvider>, mimeType?: string): Nullable<HTMLImageElement> {
  287. return FileTools.LoadImage(input, onLoad, onError, offlineProvider, mimeType);
  288. }
  289. /**
  290. * Loads a file from a url
  291. * @param url url string, ArrayBuffer, or Blob to load
  292. * @param onSuccess callback called when the file successfully loads
  293. * @param onProgress callback called while file is loading (if the server supports this mode)
  294. * @param offlineProvider defines the offline provider for caching
  295. * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer
  296. * @param onError callback called when the file fails to load
  297. * @returns a file request object
  298. */
  299. public 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 {
  300. return FileTools.LoadFile(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError);
  301. }
  302. /**
  303. * Loads a file from a url
  304. * @param url the file url to load
  305. * @returns a promise containing an ArrayBuffer corrisponding to the loaded file
  306. */
  307. public static LoadFileAsync(url: string): Promise<ArrayBuffer> {
  308. return new Promise((resolve, reject) => {
  309. FileTools.LoadFile(url, (data) => {
  310. resolve(data as ArrayBuffer);
  311. }, undefined, undefined, true, (request, exception) => {
  312. reject(exception);
  313. });
  314. });
  315. }
  316. /**
  317. * Load a script (identified by an url). When the url returns, the
  318. * content of this file is added into a new script element, attached to the DOM (body element)
  319. * @param scriptUrl defines the url of the script to laod
  320. * @param onSuccess defines the callback called when the script is loaded
  321. * @param onError defines the callback to call if an error occurs
  322. * @param scriptId defines the id of the script element
  323. */
  324. public static LoadScript(scriptUrl: string, onSuccess: () => void, onError?: (message?: string, exception?: any) => void, scriptId?: string) {
  325. if (!DomManagement.IsWindowObjectExist()) {
  326. return;
  327. }
  328. var head = document.getElementsByTagName('head')[0];
  329. var script = document.createElement('script');
  330. script.setAttribute('type', 'text/javascript');
  331. script.setAttribute('src', scriptUrl);
  332. if (scriptId) {
  333. script.id = scriptId;
  334. }
  335. script.onload = () => {
  336. if (onSuccess) {
  337. onSuccess();
  338. }
  339. };
  340. script.onerror = (e) => {
  341. if (onError) {
  342. onError(`Unable to load script '${scriptUrl}'`, e);
  343. }
  344. };
  345. head.appendChild(script);
  346. }
  347. /**
  348. * Load an asynchronous script (identified by an url). When the url returns, the
  349. * content of this file is added into a new script element, attached to the DOM (body element)
  350. * @param scriptUrl defines the url of the script to laod
  351. * @param scriptId defines the id of the script element
  352. * @returns a promise request object
  353. */
  354. public static LoadScriptAsync(scriptUrl: string, scriptId?: string): Promise<boolean> {
  355. return new Promise<boolean>((resolve, reject) => {
  356. if (!DomManagement.IsWindowObjectExist()) {
  357. resolve(false);
  358. return;
  359. }
  360. var head = document.getElementsByTagName('head')[0];
  361. var script = document.createElement('script');
  362. script.setAttribute('type', 'text/javascript');
  363. script.setAttribute('src', scriptUrl);
  364. if (scriptId) {
  365. script.id = scriptId;
  366. }
  367. script.onload = () => {
  368. resolve(true);
  369. };
  370. script.onerror = (e) => {
  371. resolve(false);
  372. };
  373. head.appendChild(script);
  374. });
  375. }
  376. /**
  377. * Loads a file from a blob
  378. * @param fileToLoad defines the blob to use
  379. * @param callback defines the callback to call when data is loaded
  380. * @param progressCallback defines the callback to call during loading process
  381. * @returns a file request object
  382. */
  383. public static ReadFileAsDataURL(fileToLoad: Blob, callback: (data: any) => void, progressCallback: (ev: ProgressEvent) => any): IFileRequest {
  384. let reader = new FileReader();
  385. let request: IFileRequest = {
  386. onCompleteObservable: new Observable<IFileRequest>(),
  387. abort: () => reader.abort(),
  388. };
  389. reader.onloadend = (e) => {
  390. request.onCompleteObservable.notifyObservers(request);
  391. };
  392. reader.onload = (e) => {
  393. //target doesn't have result from ts 1.3
  394. callback((<any>e.target)['result']);
  395. };
  396. reader.onprogress = progressCallback;
  397. reader.readAsDataURL(fileToLoad);
  398. return request;
  399. }
  400. /**
  401. * Reads a file from a File object
  402. * @param file defines the file to load
  403. * @param onSuccess defines the callback to call when data is loaded
  404. * @param onProgress defines the callback to call during loading process
  405. * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer
  406. * @param onError defines the callback to call when an error occurs
  407. * @returns a file request object
  408. */
  409. public static ReadFile(file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: ReadFileError) => void): IFileRequest {
  410. return FileTools.ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError);
  411. }
  412. /**
  413. * Creates a data url from a given string content
  414. * @param content defines the content to convert
  415. * @returns the new data url link
  416. */
  417. public static FileAsURL(content: string): string {
  418. var fileBlob = new Blob([content]);
  419. var url = window.URL || window.webkitURL;
  420. var link: string = url.createObjectURL(fileBlob);
  421. return link;
  422. }
  423. /**
  424. * Format the given number to a specific decimal format
  425. * @param value defines the number to format
  426. * @param decimals defines the number of decimals to use
  427. * @returns the formatted string
  428. */
  429. public static Format(value: number, decimals: number = 2): string {
  430. return value.toFixed(decimals);
  431. }
  432. /**
  433. * Tries to copy an object by duplicating every property
  434. * @param source defines the source object
  435. * @param destination defines the target object
  436. * @param doNotCopyList defines a list of properties to avoid
  437. * @param mustCopyList defines a list of properties to copy (even if they start with _)
  438. */
  439. public static DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void {
  440. DeepCopier.DeepCopy(source, destination, doNotCopyList, mustCopyList);
  441. }
  442. /**
  443. * Gets a boolean indicating if the given object has no own property
  444. * @param obj defines the object to test
  445. * @returns true if object has no own property
  446. */
  447. public static IsEmpty(obj: any): boolean {
  448. for (var i in obj) {
  449. if (obj.hasOwnProperty(i)) {
  450. return false;
  451. }
  452. }
  453. return true;
  454. }
  455. /**
  456. * Function used to register events at window level
  457. * @param windowElement defines the Window object to use
  458. * @param events defines the events to register
  459. */
  460. public static RegisterTopRootEvents(windowElement: Window, events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {
  461. for (var index = 0; index < events.length; index++) {
  462. var event = events[index];
  463. windowElement.addEventListener(event.name, <any>event.handler, false);
  464. try {
  465. if (window.parent) {
  466. window.parent.addEventListener(event.name, <any>event.handler, false);
  467. }
  468. } catch (e) {
  469. // Silently fails...
  470. }
  471. }
  472. }
  473. /**
  474. * Function used to unregister events from window level
  475. * @param windowElement defines the Window object to use
  476. * @param events defines the events to unregister
  477. */
  478. public static UnregisterTopRootEvents(windowElement: Window, events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {
  479. for (var index = 0; index < events.length; index++) {
  480. var event = events[index];
  481. windowElement.removeEventListener(event.name, <any>event.handler);
  482. try {
  483. if (windowElement.parent) {
  484. windowElement.parent.removeEventListener(event.name, <any>event.handler);
  485. }
  486. } catch (e) {
  487. // Silently fails...
  488. }
  489. }
  490. }
  491. /**
  492. * @ignore
  493. */
  494. public static _ScreenshotCanvas: HTMLCanvasElement;
  495. /**
  496. * Dumps the current bound framebuffer
  497. * @param width defines the rendering width
  498. * @param height defines the rendering height
  499. * @param engine defines the hosting engine
  500. * @param successCallback defines the callback triggered once the data are available
  501. * @param mimeType defines the mime type of the result
  502. * @param fileName defines the filename to download. If present, the result will automatically be downloaded
  503. */
  504. public static DumpFramebuffer(width: number, height: number, engine: Engine, successCallback?: (data: string) => void, mimeType: string = "image/png", fileName?: string): void {
  505. // Read the contents of the framebuffer
  506. var numberOfChannelsByLine = width * 4;
  507. var halfHeight = height / 2;
  508. //Reading datas from WebGL
  509. var data = engine.readPixels(0, 0, width, height);
  510. //To flip image on Y axis.
  511. for (var i = 0; i < halfHeight; i++) {
  512. for (var j = 0; j < numberOfChannelsByLine; j++) {
  513. var currentCell = j + i * numberOfChannelsByLine;
  514. var targetLine = height - i - 1;
  515. var targetCell = j + targetLine * numberOfChannelsByLine;
  516. var temp = data[currentCell];
  517. data[currentCell] = data[targetCell];
  518. data[targetCell] = temp;
  519. }
  520. }
  521. // Create a 2D canvas to store the result
  522. if (!Tools._ScreenshotCanvas) {
  523. Tools._ScreenshotCanvas = document.createElement('canvas');
  524. }
  525. Tools._ScreenshotCanvas.width = width;
  526. Tools._ScreenshotCanvas.height = height;
  527. var context = Tools._ScreenshotCanvas.getContext('2d');
  528. if (context) {
  529. // Copy the pixels to a 2D canvas
  530. var imageData = context.createImageData(width, height);
  531. var castData = <any>(imageData.data);
  532. castData.set(data);
  533. context.putImageData(imageData, 0, 0);
  534. Tools.EncodeScreenshotCanvasData(successCallback, mimeType, fileName);
  535. }
  536. }
  537. /**
  538. * Converts the canvas data to blob.
  539. * This acts as a polyfill for browsers not supporting the to blob function.
  540. * @param canvas Defines the canvas to extract the data from
  541. * @param successCallback Defines the callback triggered once the data are available
  542. * @param mimeType Defines the mime type of the result
  543. */
  544. static ToBlob(canvas: HTMLCanvasElement, successCallback: (blob: Nullable<Blob>) => void, mimeType: string = "image/png"): void {
  545. // We need HTMLCanvasElement.toBlob for HD screenshots
  546. if (!canvas.toBlob) {
  547. // low performance polyfill based on toDataURL (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob)
  548. canvas.toBlob = function(callback, type, quality) {
  549. setTimeout(() => {
  550. var binStr = atob(this.toDataURL(type, quality).split(',')[1]),
  551. len = binStr.length,
  552. arr = new Uint8Array(len);
  553. for (var i = 0; i < len; i++) {
  554. arr[i] = binStr.charCodeAt(i);
  555. }
  556. callback(new Blob([arr]));
  557. });
  558. };
  559. }
  560. canvas.toBlob(function(blob) {
  561. successCallback(blob);
  562. }, mimeType);
  563. }
  564. /**
  565. * Encodes the canvas data to base 64 or automatically download the result if filename is defined
  566. * @param successCallback defines the callback triggered once the data are available
  567. * @param mimeType defines the mime type of the result
  568. * @param fileName defines he filename to download. If present, the result will automatically be downloaded
  569. */
  570. static EncodeScreenshotCanvasData(successCallback?: (data: string) => void, mimeType: string = "image/png", fileName?: string): void {
  571. if (successCallback) {
  572. var base64Image = Tools._ScreenshotCanvas.toDataURL(mimeType);
  573. successCallback(base64Image);
  574. }
  575. else {
  576. this.ToBlob(Tools._ScreenshotCanvas, function(blob) {
  577. //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.
  578. if (("download" in document.createElement("a"))) {
  579. if (!fileName) {
  580. var date = new Date();
  581. var stringDate = (date.getFullYear() + "-" + (date.getMonth() + 1)).slice(2) + "-" + date.getDate() + "_" + date.getHours() + "-" + ('0' + date.getMinutes()).slice(-2);
  582. fileName = "screenshot_" + stringDate + ".png";
  583. }
  584. Tools.Download(blob!, fileName);
  585. }
  586. else {
  587. var url = URL.createObjectURL(blob);
  588. var newWindow = window.open("");
  589. if (!newWindow) { return; }
  590. var img = newWindow.document.createElement("img");
  591. img.onload = function() {
  592. // no longer need to read the blob so it's revoked
  593. URL.revokeObjectURL(url);
  594. };
  595. img.src = url;
  596. newWindow.document.body.appendChild(img);
  597. }
  598. }, mimeType);
  599. }
  600. }
  601. /**
  602. * Downloads a blob in the browser
  603. * @param blob defines the blob to download
  604. * @param fileName defines the name of the downloaded file
  605. */
  606. public static Download(blob: Blob, fileName: string): void {
  607. if (navigator && navigator.msSaveBlob) {
  608. navigator.msSaveBlob(blob, fileName);
  609. return;
  610. }
  611. var url = window.URL.createObjectURL(blob);
  612. var a = document.createElement("a");
  613. document.body.appendChild(a);
  614. a.style.display = "none";
  615. a.href = url;
  616. a.download = fileName;
  617. a.addEventListener("click", () => {
  618. if (a.parentElement) {
  619. a.parentElement.removeChild(a);
  620. }
  621. });
  622. a.click();
  623. window.URL.revokeObjectURL(url);
  624. }
  625. /**
  626. * Captures a screenshot of the current rendering
  627. * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
  628. * @param engine defines the rendering engine
  629. * @param camera defines the source camera
  630. * @param size This parameter can be set to a single number or to an object with the
  631. * following (optional) properties: precision, width, height. If a single number is passed,
  632. * it will be used for both width and height. If an object is passed, the screenshot size
  633. * will be derived from the parameters. The precision property is a multiplier allowing
  634. * rendering at a higher or lower resolution
  635. * @param successCallback defines the callback receives a single parameter which contains the
  636. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  637. * src parameter of an <img> to display it
  638. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  639. * Check your browser for supported MIME types
  640. */
  641. public static CreateScreenshot(engine: Engine, camera: Camera, size: IScreenshotSize | number, successCallback?: (data: string) => void, mimeType: string = "image/png"): void {
  642. throw _DevTools.WarnImport("ScreenshotTools");
  643. }
  644. /**
  645. * Captures a screenshot of the current rendering
  646. * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
  647. * @param engine defines the rendering engine
  648. * @param camera defines the source camera
  649. * @param size This parameter can be set to a single number or to an object with the
  650. * following (optional) properties: precision, width, height. If a single number is passed,
  651. * it will be used for both width and height. If an object is passed, the screenshot size
  652. * will be derived from the parameters. The precision property is a multiplier allowing
  653. * rendering at a higher or lower resolution
  654. * @param mimeType defines the MIME type of the screenshot image (default: image/png).
  655. * Check your browser for supported MIME types
  656. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  657. * to the src parameter of an <img> to display it
  658. */
  659. public static CreateScreenshotAsync(engine: Engine, camera: Camera, size: IScreenshotSize | number, mimeType: string = "image/png"): Promise<string> {
  660. throw _DevTools.WarnImport("ScreenshotTools");
  661. }
  662. /**
  663. * Generates an image screenshot from the specified camera.
  664. * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
  665. * @param engine The engine to use for rendering
  666. * @param camera The camera to use for rendering
  667. * @param size This parameter can be set to a single number or to an object with the
  668. * following (optional) properties: precision, width, height. If a single number is passed,
  669. * it will be used for both width and height. If an object is passed, the screenshot size
  670. * will be derived from the parameters. The precision property is a multiplier allowing
  671. * rendering at a higher or lower resolution
  672. * @param successCallback The callback receives a single parameter which contains the
  673. * screenshot as a string of base64-encoded characters. This string can be assigned to the
  674. * src parameter of an <img> to display it
  675. * @param mimeType The MIME type of the screenshot image (default: image/png).
  676. * Check your browser for supported MIME types
  677. * @param samples Texture samples (default: 1)
  678. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  679. * @param fileName A name for for the downloaded file.
  680. */
  681. public static CreateScreenshotUsingRenderTarget(engine: Engine, camera: Camera, size: IScreenshotSize | number, successCallback?: (data: string) => void, mimeType: string = "image/png", samples: number = 1, antialiasing: boolean = false, fileName?: string): void {
  682. throw _DevTools.WarnImport("ScreenshotTools");
  683. }
  684. /**
  685. * Generates an image screenshot from the specified camera.
  686. * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
  687. * @param engine The engine to use for rendering
  688. * @param camera The camera to use for rendering
  689. * @param size This parameter can be set to a single number or to an object with the
  690. * following (optional) properties: precision, width, height. If a single number is passed,
  691. * it will be used for both width and height. If an object is passed, the screenshot size
  692. * will be derived from the parameters. The precision property is a multiplier allowing
  693. * rendering at a higher or lower resolution
  694. * @param mimeType The MIME type of the screenshot image (default: image/png).
  695. * Check your browser for supported MIME types
  696. * @param samples Texture samples (default: 1)
  697. * @param antialiasing Whether antialiasing should be turned on or not (default: false)
  698. * @param fileName A name for for the downloaded file.
  699. * @returns screenshot as a string of base64-encoded characters. This string can be assigned
  700. * to the src parameter of an <img> to display it
  701. */
  702. public static CreateScreenshotUsingRenderTargetAsync(engine: Engine, camera: Camera, size: IScreenshotSize | number, mimeType: string = "image/png", samples: number = 1, antialiasing: boolean = false, fileName?: string): Promise<string> {
  703. throw _DevTools.WarnImport("ScreenshotTools");
  704. }
  705. /**
  706. * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
  707. * Be aware Math.random() could cause collisions, but:
  708. * "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"
  709. * @returns a pseudo random id
  710. */
  711. public static RandomId(): string {
  712. return GUID.RandomId();
  713. }
  714. /**
  715. * Test if the given uri is a base64 string
  716. * @param uri The uri to test
  717. * @return True if the uri is a base64 string or false otherwise
  718. */
  719. public static IsBase64(uri: string): boolean {
  720. return uri.length < 5 ? false : uri.substr(0, 5) === "data:";
  721. }
  722. /**
  723. * Decode the given base64 uri.
  724. * @param uri The uri to decode
  725. * @return The decoded base64 data.
  726. */
  727. public static DecodeBase64(uri: string): ArrayBuffer {
  728. const decodedString = atob(uri.split(",")[1]);
  729. const bufferLength = decodedString.length;
  730. const bufferView = new Uint8Array(new ArrayBuffer(bufferLength));
  731. for (let i = 0; i < bufferLength; i++) {
  732. bufferView[i] = decodedString.charCodeAt(i);
  733. }
  734. return bufferView.buffer;
  735. }
  736. /**
  737. * Gets the absolute url.
  738. * @param url the input url
  739. * @return the absolute url
  740. */
  741. public static GetAbsoluteUrl(url: string): string {
  742. const a = document.createElement("a");
  743. a.href = url;
  744. return a.href;
  745. }
  746. // Logs
  747. /**
  748. * No log
  749. */
  750. public static readonly NoneLogLevel = Logger.NoneLogLevel;
  751. /**
  752. * Only message logs
  753. */
  754. public static readonly MessageLogLevel = Logger.MessageLogLevel;
  755. /**
  756. * Only warning logs
  757. */
  758. public static readonly WarningLogLevel = Logger.WarningLogLevel;
  759. /**
  760. * Only error logs
  761. */
  762. public static readonly ErrorLogLevel = Logger.ErrorLogLevel;
  763. /**
  764. * All logs
  765. */
  766. public static readonly AllLogLevel = Logger.AllLogLevel;
  767. /**
  768. * Gets a value indicating the number of loading errors
  769. * @ignorenaming
  770. */
  771. public static get errorsCount(): number {
  772. return Logger.errorsCount;
  773. }
  774. /**
  775. * Callback called when a new log is added
  776. */
  777. public static OnNewCacheEntry: (entry: string) => void;
  778. /**
  779. * Log a message to the console
  780. * @param message defines the message to log
  781. */
  782. public static Log(message: string): void {
  783. Logger.Log(message);
  784. }
  785. /**
  786. * Write a warning message to the console
  787. * @param message defines the message to log
  788. */
  789. public static Warn(message: string): void {
  790. Logger.Warn(message);
  791. }
  792. /**
  793. * Write an error message to the console
  794. * @param message defines the message to log
  795. */
  796. public static Error(message: string): void {
  797. Logger.Error(message);
  798. }
  799. /**
  800. * Gets current log cache (list of logs)
  801. */
  802. public static get LogCache(): string {
  803. return Logger.LogCache;
  804. }
  805. /**
  806. * Clears the log cache
  807. */
  808. public static ClearLogCache(): void {
  809. Logger.ClearLogCache();
  810. }
  811. /**
  812. * Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)
  813. */
  814. public static set LogLevels(level: number) {
  815. Logger.LogLevels = level;
  816. }
  817. /**
  818. * Checks if the window object exists
  819. * Back Compat only, please use DomManagement.IsWindowObjectExist instead.
  820. */
  821. public static IsWindowObjectExist = DomManagement.IsWindowObjectExist;
  822. // Performances
  823. /**
  824. * No performance log
  825. */
  826. public static readonly PerformanceNoneLogLevel = 0;
  827. /**
  828. * Use user marks to log performance
  829. */
  830. public static readonly PerformanceUserMarkLogLevel = 1;
  831. /**
  832. * Log performance to the console
  833. */
  834. public static readonly PerformanceConsoleLogLevel = 2;
  835. private static _performance: Performance;
  836. /**
  837. * Sets the current performance log level
  838. */
  839. public static set PerformanceLogLevel(level: number) {
  840. if ((level & Tools.PerformanceUserMarkLogLevel) === Tools.PerformanceUserMarkLogLevel) {
  841. Tools.StartPerformanceCounter = Tools._StartUserMark;
  842. Tools.EndPerformanceCounter = Tools._EndUserMark;
  843. return;
  844. }
  845. if ((level & Tools.PerformanceConsoleLogLevel) === Tools.PerformanceConsoleLogLevel) {
  846. Tools.StartPerformanceCounter = Tools._StartPerformanceConsole;
  847. Tools.EndPerformanceCounter = Tools._EndPerformanceConsole;
  848. return;
  849. }
  850. Tools.StartPerformanceCounter = Tools._StartPerformanceCounterDisabled;
  851. Tools.EndPerformanceCounter = Tools._EndPerformanceCounterDisabled;
  852. }
  853. private static _StartPerformanceCounterDisabled(counterName: string, condition?: boolean): void {
  854. }
  855. private static _EndPerformanceCounterDisabled(counterName: string, condition?: boolean): void {
  856. }
  857. private static _StartUserMark(counterName: string, condition = true): void {
  858. if (!Tools._performance) {
  859. if (!DomManagement.IsWindowObjectExist()) {
  860. return;
  861. }
  862. Tools._performance = window.performance;
  863. }
  864. if (!condition || !Tools._performance.mark) {
  865. return;
  866. }
  867. Tools._performance.mark(counterName + "-Begin");
  868. }
  869. private static _EndUserMark(counterName: string, condition = true): void {
  870. if (!condition || !Tools._performance.mark) {
  871. return;
  872. }
  873. Tools._performance.mark(counterName + "-End");
  874. Tools._performance.measure(counterName, counterName + "-Begin", counterName + "-End");
  875. }
  876. private static _StartPerformanceConsole(counterName: string, condition = true): void {
  877. if (!condition) {
  878. return;
  879. }
  880. Tools._StartUserMark(counterName, condition);
  881. if (console.time) {
  882. console.time(counterName);
  883. }
  884. }
  885. private static _EndPerformanceConsole(counterName: string, condition = true): void {
  886. if (!condition) {
  887. return;
  888. }
  889. Tools._EndUserMark(counterName, condition);
  890. console.timeEnd(counterName);
  891. }
  892. /**
  893. * Starts a performance counter
  894. */
  895. public static StartPerformanceCounter: (counterName: string, condition?: boolean) => void = Tools._StartPerformanceCounterDisabled;
  896. /**
  897. * Ends a specific performance coutner
  898. */
  899. public static EndPerformanceCounter: (counterName: string, condition?: boolean) => void = Tools._EndPerformanceCounterDisabled;
  900. /**
  901. * Gets either window.performance.now() if supported or Date.now() else
  902. */
  903. public static get Now(): number {
  904. return PrecisionDate.Now;
  905. }
  906. /**
  907. * This method will return the name of the class used to create the instance of the given object.
  908. * It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator.
  909. * @param object the object to get the class name from
  910. * @param isType defines if the object is actually a type
  911. * @returns the name of the class, will be "object" for a custom data type not using the @className decorator
  912. */
  913. public static GetClassName(object: any, isType: boolean = false): string {
  914. let name = null;
  915. if (!isType && object.getClassName) {
  916. name = object.getClassName();
  917. } else {
  918. if (object instanceof Object) {
  919. let classObj = isType ? object : Object.getPrototypeOf(object);
  920. name = classObj.constructor["__bjsclassName__"];
  921. }
  922. if (!name) {
  923. name = typeof object;
  924. }
  925. }
  926. return name;
  927. }
  928. /**
  929. * Gets the first element of an array satisfying a given predicate
  930. * @param array defines the array to browse
  931. * @param predicate defines the predicate to use
  932. * @returns null if not found or the element
  933. */
  934. public static First<T>(array: Array<T>, predicate: (item: T) => boolean): Nullable<T> {
  935. for (let el of array) {
  936. if (predicate(el)) {
  937. return el;
  938. }
  939. }
  940. return null;
  941. }
  942. /**
  943. * This method will return the name of the full name of the class, including its owning module (if any).
  944. * 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).
  945. * @param object the object to get the class name from
  946. * @param isType defines if the object is actually a type
  947. * @return 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.
  948. * @ignorenaming
  949. */
  950. public static getFullClassName(object: any, isType: boolean = false): Nullable<string> {
  951. let className = null;
  952. let moduleName = null;
  953. if (!isType && object.getClassName) {
  954. className = object.getClassName();
  955. } else {
  956. if (object instanceof Object) {
  957. let classObj = isType ? object : Object.getPrototypeOf(object);
  958. className = classObj.constructor["__bjsclassName__"];
  959. moduleName = classObj.constructor["__bjsmoduleName__"];
  960. }
  961. if (!className) {
  962. className = typeof object;
  963. }
  964. }
  965. if (!className) {
  966. return null;
  967. }
  968. return ((moduleName != null) ? (moduleName + ".") : "") + className;
  969. }
  970. /**
  971. * Returns a promise that resolves after the given amount of time.
  972. * @param delay Number of milliseconds to delay
  973. * @returns Promise that resolves after the given amount of time
  974. */
  975. public static DelayAsync(delay: number): Promise<void> {
  976. return new Promise((resolve) => {
  977. setTimeout(() => {
  978. resolve();
  979. }, delay);
  980. });
  981. }
  982. }
  983. /**
  984. * Use this className as a decorator on a given class definition to add it a name and optionally its module.
  985. * You can then use the Tools.getClassName(obj) on an instance to retrieve its class name.
  986. * This method is the only way to get it done in all cases, even if the .js file declaring the class is minified
  987. * @param name The name of the class, case should be preserved
  988. * @param module The name of the Module hosting the class, optional, but strongly recommended to specify if possible. Case should be preserved.
  989. */
  990. export function className(name: string, module?: string): (target: Object) => void {
  991. return (target: Object) => {
  992. (<any>target)["__bjsclassName__"] = name;
  993. (<any>target)["__bjsmoduleName__"] = (module != null) ? module : null;
  994. };
  995. }
  996. /**
  997. * An implementation of a loop for asynchronous functions.
  998. */
  999. export class AsyncLoop {
  1000. /**
  1001. * Defines the current index of the loop.
  1002. */
  1003. public index: number;
  1004. private _done: boolean;
  1005. private _fn: (asyncLoop: AsyncLoop) => void;
  1006. private _successCallback: () => void;
  1007. /**
  1008. * Constructor.
  1009. * @param iterations the number of iterations.
  1010. * @param func the function to run each iteration
  1011. * @param successCallback the callback that will be called upon succesful execution
  1012. * @param offset starting offset.
  1013. */
  1014. constructor(
  1015. /**
  1016. * Defines the number of iterations for the loop
  1017. */
  1018. public iterations: number,
  1019. func: (asyncLoop: AsyncLoop) => void,
  1020. successCallback: () => void,
  1021. offset: number = 0) {
  1022. this.index = offset - 1;
  1023. this._done = false;
  1024. this._fn = func;
  1025. this._successCallback = successCallback;
  1026. }
  1027. /**
  1028. * Execute the next iteration. Must be called after the last iteration was finished.
  1029. */
  1030. public executeNext(): void {
  1031. if (!this._done) {
  1032. if (this.index + 1 < this.iterations) {
  1033. ++this.index;
  1034. this._fn(this);
  1035. } else {
  1036. this.breakLoop();
  1037. }
  1038. }
  1039. }
  1040. /**
  1041. * Break the loop and run the success callback.
  1042. */
  1043. public breakLoop(): void {
  1044. this._done = true;
  1045. this._successCallback();
  1046. }
  1047. /**
  1048. * Create and run an async loop.
  1049. * @param iterations the number of iterations.
  1050. * @param fn the function to run each iteration
  1051. * @param successCallback the callback that will be called upon succesful execution
  1052. * @param offset starting offset.
  1053. * @returns the created async loop object
  1054. */
  1055. public static Run(iterations: number, fn: (asyncLoop: AsyncLoop) => void, successCallback: () => void, offset: number = 0): AsyncLoop {
  1056. var loop = new AsyncLoop(iterations, fn, successCallback, offset);
  1057. loop.executeNext();
  1058. return loop;
  1059. }
  1060. /**
  1061. * A for-loop that will run a given number of iterations synchronous and the rest async.
  1062. * @param iterations total number of iterations
  1063. * @param syncedIterations number of synchronous iterations in each async iteration.
  1064. * @param fn the function to call each iteration.
  1065. * @param callback a success call back that will be called when iterating stops.
  1066. * @param breakFunction a break condition (optional)
  1067. * @param timeout timeout settings for the setTimeout function. default - 0.
  1068. * @returns the created async loop object
  1069. */
  1070. public static SyncAsyncForLoop(iterations: number, syncedIterations: number, fn: (iteration: number) => void, callback: () => void, breakFunction?: () => boolean, timeout: number = 0): AsyncLoop {
  1071. return AsyncLoop.Run(Math.ceil(iterations / syncedIterations), (loop: AsyncLoop) => {
  1072. if (breakFunction && breakFunction()) { loop.breakLoop(); }
  1073. else {
  1074. setTimeout(() => {
  1075. for (var i = 0; i < syncedIterations; ++i) {
  1076. var iteration = (loop.index * syncedIterations) + i;
  1077. if (iteration >= iterations) { break; }
  1078. fn(iteration);
  1079. if (breakFunction && breakFunction()) {
  1080. loop.breakLoop();
  1081. break;
  1082. }
  1083. }
  1084. loop.executeNext();
  1085. }, timeout);
  1086. }
  1087. }, callback);
  1088. }
  1089. }
  1090. // Will only be define if Tools is imported freeing up some space when only engine is required
  1091. EngineStore.FallbackTexture = "data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z";
  1092. // Register promise fallback for IE
  1093. PromisePolyfill.Apply();