tools.ts 52 KB

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