tools.ts 51 KB

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