tools.ts 52 KB

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