Options
All
  • Public
  • Public/Protected
  • All
Menu

Class containing a set of static utilities functions

Hierarchy

  • Tools

Index

Constructors

Properties

AllLogLevel: 7 = 7

All logs

CustomRequestHeaders: {}

Custom HTTP Request Headers to be sent with XMLHttpRequests i.e. when loading files, where the server/service expects an Authorization header

Type declaration

  • [key: string]: string
EndPerformanceCounter: ((counterName: string, condition?: boolean) => void)

Type declaration

    • (counterName: string, condition?: boolean): void
    • Ends a specific performance counter

      Parameters

      • counterName: string
      • Optional condition: boolean

      Returns void

ErrorLogLevel: 4 = 4

Only error logs

GetAbsoluteUrl: ((url: string) => string)

Type declaration

    • (url: string): string
    • Parameters

      • url: string

      Returns string

GetDOMTextContent: ((element: HTMLElement) => string)

Type declaration

    • (element: HTMLElement): string
    • Extracts text content from a DOM element hierarchy

      Parameters

      • element: HTMLElement

        defines the root element

      Returns string

      a string

IsWindowObjectExist: (() => boolean)

Type declaration

    • (): boolean
    • Checks if the window object exists

      Returns boolean

      true if the window object exists

MessageLogLevel: 1 = 1

Only message logs

NoneLogLevel: 0 = 0

No log

OnNewCacheEntry: ((entry: string) => void)

Type declaration

    • (entry: string): void
    • Callback called when a new log is added

      Parameters

      • entry: string

      Returns void

PerformanceConsoleLogLevel: 2 = 2

Log performance to the console

PerformanceNoneLogLevel: 0 = 0

No performance log

PerformanceUserMarkLogLevel: 1 = 1

Use user marks to log performance

StartPerformanceCounter: ((counterName: string, condition?: boolean) => void)

Type declaration

    • (counterName: string, condition?: boolean): void
    • Starts a performance counter

      Parameters

      • counterName: string
      • Optional condition: boolean

      Returns void

UseCustomRequestHeaders: boolean

Enable/Disable Custom HTTP Request Headers globally. default = false

see

CustomRequestHeaders

WarningLogLevel: 2 = 2

Only warning logs

Accessors

  • get BaseUrl(): string
  • set BaseUrl(value: string): void
  • Gets or sets the base URL to use to load assets

    Returns string

  • Gets or sets the base URL to use to load assets

    Parameters

    • value: string

    Returns void

  • get CorsBehavior(): string | ((url: string | string[]) => string)
  • set CorsBehavior(value: string | ((url: string | string[]) => string)): void
  • Default behaviour for cors in the application. It can be a string if the expected behavior is identical in the entire app. Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)

    Returns string | ((url: string | string[]) => string)

  • Default behaviour for cors in the application. It can be a string if the expected behavior is identical in the entire app. Or a callback to be able to set it per url or on a group of them (in case of Video source for instance)

    Parameters

    • value: string | ((url: string | string[]) => string)

    Returns void

  • get DefaultRetryStrategy(): ((url: string, request: WebRequest, retryIndex: number) => number)
  • set DefaultRetryStrategy(strategy: ((url: string, request: WebRequest, retryIndex: number) => number)): void
  • Gets or sets the retry strategy to apply when an error happens while loading an asset

    Returns ((url: string, request: WebRequest, retryIndex: number) => number)

      • (url: string, request: WebRequest, retryIndex: number): number
      • Gets or sets the retry strategy to apply when an error happens while loading an asset

        Parameters

        Returns number

  • Gets or sets the retry strategy to apply when an error happens while loading an asset

    Parameters

    • strategy: ((url: string, request: WebRequest, retryIndex: number) => number)
        • (url: string, request: WebRequest, retryIndex: number): number
        • Parameters

          Returns number

    Returns void

  • get LogCache(): string
  • Gets current log cache (list of logs)

    Returns string

  • set LogLevels(level: number): void
  • Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)

    Parameters

    • level: number

    Returns void

  • get Now(): number
  • Gets either window.performance.now() if supported or Date.now() else

    Returns number

  • set PerformanceLogLevel(level: number): void
  • Sets the current performance log level

    Parameters

    • level: number

    Returns void

  • get PreprocessUrl(): ((url: string) => string)
  • set PreprocessUrl(processor: ((url: string) => string)): void
  • Gets or sets a function used to pre-process url before using them to load assets

    Returns ((url: string) => string)

      • (url: string): string
      • Gets or sets a function used to pre-process url before using them to load assets

        Parameters

        • url: string

        Returns string

  • Gets or sets a function used to pre-process url before using them to load assets

    Parameters

    • processor: ((url: string) => string)
        • (url: string): string
        • Parameters

          • url: string

          Returns string

    Returns void

  • get RegisteredExternalClasses(): {}
  • set RegisteredExternalClasses(classes: {}): void
  • Use this object to register external classes like custom textures or material to allow the loaders to instantiate them

    Returns {}

    • [key: string]: Object
  • Use this object to register external classes like custom textures or material to allow the loaders to instantiate them

    Parameters

    • classes: {}
      • [key: string]: Object

    Returns void

  • get UseFallbackTexture(): boolean
  • set UseFallbackTexture(value: boolean): void
  • Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded

    ignorenaming

    Returns boolean

  • Gets or sets a global variable indicating if fallback texture must be used when a texture cannot be loaded

    ignorenaming

    Parameters

    • value: boolean

    Returns void

  • get errorsCount(): number
  • Gets a value indicating the number of loading errors

    ignorenaming

    Returns number

  • get fallbackTexture(): string
  • set fallbackTexture(value: string): void
  • Texture content used if a texture cannot loaded

    ignorenaming

    Returns string

  • Texture content used if a texture cannot loaded

    ignorenaming

    Parameters

    • value: string

    Returns void

Methods

  • BackCompatCameraNoPreventDefault(args: IArguments): boolean
  • Will return the right value of the noPreventDefault variable Needed to keep backwards compatibility to the old API.

    Parameters

    • args: IArguments

      arguments passed to the attachControl function

    Returns boolean

    the correct value for noPreventDefault

  • CleanUrl(url: string): string
  • Removes unwanted characters from an url

    Parameters

    • url: string

      defines the url to clean

    Returns string

    the cleaned url

  • ClearLogCache(): void
  • Clears the log cache

    Returns void

  • CreateScreenshot(engine: Engine, camera: Camera, size: number | IScreenshotSize, successCallback?: ((data: string) => void), mimeType?: string, forceDownload?: boolean, quality?: number): void
  • Captures a screenshot of the current rendering

    see

    https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG

    Parameters

    • engine: Engine

      defines the rendering engine

    • camera: Camera

      defines the source camera

    • size: number | IScreenshotSize

      This parameter can be set to a single number or to an object with the following (optional) properties: precision, width, height. If a single number is passed, it will be used for both width and height. If an object is passed, the screenshot size will be derived from the parameters. The precision property is a multiplier allowing rendering at a higher or lower resolution

    • Optional successCallback: ((data: string) => void)

      defines the callback receives a single parameter which contains the screenshot as a string of base64-encoded characters. This string can be assigned to the src parameter of an to display it

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    • Optional mimeType: string

      defines the MIME type of the screenshot image (default: image/png). Check your browser for supported MIME types

    • Optional forceDownload: boolean

      force the system to download the image even if a successCallback is provided

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns void

  • CreateScreenshotAsync(engine: Engine, camera: Camera, size: number | IScreenshotSize, mimeType?: string, quality?: number): Promise<string>
  • Captures a screenshot of the current rendering

    see

    https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG

    Parameters

    • engine: Engine

      defines the rendering engine

    • camera: Camera

      defines the source camera

    • size: number | IScreenshotSize

      This parameter can be set to a single number or to an object with the following (optional) properties: precision, width, height. If a single number is passed, it will be used for both width and height. If an object is passed, the screenshot size will be derived from the parameters. The precision property is a multiplier allowing rendering at a higher or lower resolution

    • Optional mimeType: string

      defines the MIME type of the screenshot image (default: image/png). Check your browser for supported MIME types

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns Promise<string>

    screenshot as a string of base64-encoded characters. This string can be assigned to the src parameter of an to display it

  • CreateScreenshotUsingRenderTarget(engine: Engine, camera: Camera, size: number | IScreenshotSize, successCallback?: ((data: string) => void), mimeType?: string, samples?: number, antialiasing?: boolean, fileName?: string, renderSprites?: boolean, enableStencilBuffer?: boolean, useLayerMask?: boolean, quality?: number): void
  • Generates an image screenshot from the specified camera.

    see

    https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG

    Parameters

    • engine: Engine

      The engine to use for rendering

    • camera: Camera

      The camera to use for rendering

    • size: number | IScreenshotSize

      This parameter can be set to a single number or to an object with the following (optional) properties: precision, width, height. If a single number is passed, it will be used for both width and height. If an object is passed, the screenshot size will be derived from the parameters. The precision property is a multiplier allowing rendering at a higher or lower resolution

    • Optional successCallback: ((data: string) => void)

      The callback receives a single parameter which contains the screenshot as a string of base64-encoded characters. This string can be assigned to the src parameter of an to display it

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    • Optional mimeType: string

      The MIME type of the screenshot image (default: image/png). Check your browser for supported MIME types

    • Optional samples: number

      Texture samples (default: 1)

    • Optional antialiasing: boolean

      Whether antialiasing should be turned on or not (default: false)

    • Optional fileName: string

      A name for for the downloaded file.

    • Optional renderSprites: boolean

      Whether the sprites should be rendered or not (default: false)

    • Optional enableStencilBuffer: boolean

      Whether the stencil buffer should be enabled or not (default: false)

    • Optional useLayerMask: boolean

      if the camera's layer mask should be used to filter what should be rendered (default: true)

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns void

  • CreateScreenshotUsingRenderTargetAsync(engine: Engine, camera: Camera, size: number | IScreenshotSize, mimeType?: string, samples?: number, antialiasing?: boolean, fileName?: string, renderSprites?: boolean, enableStencilBuffer?: boolean, useLayerMask?: boolean, quality?: number): Promise<string>
  • Generates an image screenshot from the specified camera.

    see

    https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG

    Parameters

    • engine: Engine

      The engine to use for rendering

    • camera: Camera

      The camera to use for rendering

    • size: number | IScreenshotSize

      This parameter can be set to a single number or to an object with the following (optional) properties: precision, width, height. If a single number is passed, it will be used for both width and height. If an object is passed, the screenshot size will be derived from the parameters. The precision property is a multiplier allowing rendering at a higher or lower resolution

    • Optional mimeType: string

      The MIME type of the screenshot image (default: image/png). Check your browser for supported MIME types

    • Optional samples: number

      Texture samples (default: 1)

    • Optional antialiasing: boolean

      Whether antialiasing should be turned on or not (default: false)

    • Optional fileName: string

      A name for for the downloaded file.

    • Optional renderSprites: boolean

      Whether the sprites should be rendered or not (default: false)

    • Optional enableStencilBuffer: boolean

      Whether the stencil buffer should be enabled or not (default: false)

    • Optional useLayerMask: boolean

      if the camera's layer mask should be used to filter what should be rendered (default: true)

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter. to the src parameter of an to display it

    Returns Promise<string>

    screenshot as a string of base64-encoded characters. This string can be assigned

  • DecodeBase64(uri: string): ArrayBuffer
  • Decode the given base64 uri.

    deprecated

    Please use FileTools.DecodeBase64UrlToBinary instead.

    Parameters

    • uri: string

      The uri to decode

    Returns ArrayBuffer

    The decoded base64 data.

  • DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void
  • Tries to copy an object by duplicating every property

    Parameters

    • source: any

      defines the source object

    • destination: any

      defines the target object

    • Optional doNotCopyList: string[]

      defines a list of properties to avoid

    • Optional mustCopyList: string[]

      defines a list of properties to copy (even if they start with _)

    Returns void

  • DelayAsync(delay: number): Promise<void>
  • Returns a promise that resolves after the given amount of time.

    Parameters

    • delay: number

      Number of milliseconds to delay

    Returns Promise<void>

    Promise that resolves after the given amount of time

  • Download(blob: Blob, fileName: string): void
  • Downloads a blob in the browser

    Parameters

    • blob: Blob

      defines the blob to download

    • fileName: string

      defines the name of the downloaded file

    Returns void

  • DownloadBlob(blob: Blob, fileName?: string): void
  • Download a Blob object

    Parameters

    • blob: Blob

      the Blob object

    • Optional fileName: string

      the file name to download

    Returns void

  • DumpData(width: number, height: number, data: ArrayBufferView, successCallback?: ((data: string | ArrayBuffer) => void), mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): void
  • Dumps an array buffer

    Parameters

    • width: number

      defines the rendering width

    • height: number

      defines the rendering height

    • data: ArrayBufferView

      the data array

    • Optional successCallback: ((data: string | ArrayBuffer) => void)

      defines the callback triggered once the data are available

        • (data: string | ArrayBuffer): void
        • Parameters

          • data: string | ArrayBuffer

          Returns void

    • Optional mimeType: string

      defines the mime type of the result

    • Optional fileName: string

      defines the filename to download. If present, the result will automatically be downloaded

    • Optional invertY: boolean

      true to invert the picture in the Y dimension

    • Optional toArrayBuffer: boolean

      true to convert the data to an ArrayBuffer (encoded as mimeType) instead of a base64 string

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns void

  • DumpDataAsync(width: number, height: number, data: ArrayBufferView, mimeType?: string, fileName?: string, invertY?: boolean, toArrayBuffer?: boolean, quality?: number): Promise<string | ArrayBuffer>
  • Dumps an array buffer

    Parameters

    • width: number

      defines the rendering width

    • height: number

      defines the rendering height

    • data: ArrayBufferView

      the data array

    • Optional mimeType: string

      defines the mime type of the result

    • Optional fileName: string

      defines the filename to download. If present, the result will automatically be downloaded

    • Optional invertY: boolean

      true to invert the picture in the Y dimension

    • Optional toArrayBuffer: boolean

      true to convert the data to an ArrayBuffer (encoded as mimeType) instead of a base64 string

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns Promise<string | ArrayBuffer>

    a promise that resolve to the final data

  • DumpFramebuffer(width: number, height: number, engine: Engine, successCallback?: ((data: string) => void), mimeType?: string, fileName?: string, quality?: number): Promise<void>
  • Dumps the current bound framebuffer

    Parameters

    • width: number

      defines the rendering width

    • height: number

      defines the rendering height

    • engine: Engine

      defines the hosting engine

    • Optional successCallback: ((data: string) => void)

      defines the callback triggered once the data are available

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    • Optional mimeType: string

      defines the mime type of the result

    • Optional fileName: string

      defines the filename to download. If present, the result will automatically be downloaded

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns Promise<void>

    a void promise

  • EncodeScreenshotCanvasData(canvas: HTMLCanvasElement | OffscreenCanvas, successCallback?: ((data: string) => void), mimeType?: string, fileName?: string, quality?: number): void
  • Encodes the canvas data to base 64, or automatically downloads the result if fileName is defined.

    Parameters

    • canvas: HTMLCanvasElement | OffscreenCanvas

      The canvas to get the data from, which can be an offscreen canvas.

    • Optional successCallback: ((data: string) => void)

      The callback which is triggered once the data is available. If fileName is defined, the callback will be invoked after the download occurs, and the data argument will be an empty string.

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    • Optional mimeType: string

      The mime type of the result.

    • Optional fileName: string

      The name of the file to download. If defined, the result will automatically be downloaded. If not defined, and successCallback is also not defined, the result will automatically be downloaded with an auto-generated file name.

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns void

  • Error(message: string): void
  • Write an error message to the console

    Parameters

    • message: string

      defines the message to log

    Returns void

  • FetchToRef(u: number, v: number, width: number, height: number, pixels: Uint8Array, color: IColor4Like): void
  • Read the content of a byte array at a specified coordinates (taking in account wrapping)

    Parameters

    • u: number

      defines the coordinate on X axis

    • v: number

      defines the coordinate on Y axis

    • width: number

      defines the width of the source data

    • height: number

      defines the height of the source data

    • pixels: Uint8Array

      defines the source byte array

    • color: IColor4Like

      defines the output color

    Returns void

  • FileAsURL(content: string): string
  • Creates a data url from a given string content

    Parameters

    • content: string

      defines the content to convert

    Returns string

    the new data url link

  • First<T>(array: T[], predicate: ((item: T) => boolean)): Nullable<T>
  • Gets the first element of an array satisfying a given predicate

    Type Parameters

    • T

    Parameters

    • array: T[]

      defines the array to browse

    • predicate: ((item: T) => boolean)

      defines the predicate to use

        • (item: T): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns Nullable<T>

    null if not found or the element

  • FloatRound(value: number): number
  • Returns the nearest 32-bit single precision float representation of a Number

    Parameters

    • value: number

      A Number. If the parameter is of a different type, it will get converted to a number or to NaN if it cannot be converted

    Returns number

    number

  • Format(value: number, decimals?: number): string
  • Format the given number to a specific decimal format

    Parameters

    • value: number

      defines the number to format

    • Optional decimals: number

      defines the number of decimals to use

    Returns string

    the formatted string

  • GetClassName(object: any, isType?: boolean): string
  • This method will return the name of the class used to create the instance of the given object. It will works only on Javascript basic data types (number, string, ...) and instance of class declared with the @className decorator.

    Parameters

    • object: any

      the object to get the class name from

    • Optional isType: boolean

      defines if the object is actually a type

    Returns string

    the name of the class, will be "object" for a custom data type not using the @className decorator

  • GetFilename(path: string): string
  • Extracts the filename from a path

    Parameters

    • path: string

      defines the path to use

    Returns string

    the filename

  • GetFolderPath(uri: string, returnUnchangedIfNoSlash?: boolean): string
  • Extracts the "folder" part of a path (everything before the filename).

    Parameters

    • uri: string

      The URI to extract the info from

    • Optional returnUnchangedIfNoSlash: boolean

      Do not touch the URI if no slashes are present

    Returns string

    The "folder" part of the path

  • GetPointerPrefix(engine: Engine): string
  • Gets the pointer prefix to use

    Parameters

    • engine: Engine

      defines the engine we are finding the prefix for

    Returns string

    "pointer" if touch is enabled. Else returns "mouse"

  • Instantiate(className: string): any
  • Tries to instantiate a new object from a given class name

    Parameters

    • className: string

      defines the class name to instantiate

    Returns any

    the new object or null if the system was not able to do the instantiation

  • IsBase64(uri: string): boolean
  • Test if the given uri is a base64 string

    deprecated

    Please use FileTools.IsBase64DataUrl instead.

    Parameters

    • uri: string

      The uri to test

    Returns boolean

    True if the uri is a base64 string or false otherwise

  • IsEmpty(obj: any): boolean
  • Gets a boolean indicating if the given object has no own property

    Parameters

    • obj: any

      defines the object to test

    Returns boolean

    true if object has no own property

  • IsExponentOfTwo(value: number): boolean
  • Function indicating if a number is an exponent of 2

    Parameters

    • value: number

      defines the value to test

    Returns boolean

    true if the value is an exponent of 2

  • IsSafari(): boolean
  • Utility function to detect if the current user agent is Safari

    Returns boolean

    whether or not the current user agent is safari

  • 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
  • Loads a file from a url

    Parameters

    • url: string

      url string, ArrayBuffer, or Blob to load

    • onSuccess: ((data: string | ArrayBuffer, responseURL?: string) => void)

      callback called when the file successfully loads

        • (data: string | ArrayBuffer, responseURL?: string): void
        • Parameters

          • data: string | ArrayBuffer
          • Optional responseURL: string

          Returns void

    • Optional onProgress: ((data: any) => void)

      callback called while file is loading (if the server supports this mode)

        • (data: any): void
        • Parameters

          • data: any

          Returns void

    • Optional offlineProvider: IOfflineProvider

      defines the offline provider for caching

    • Optional useArrayBuffer: boolean

      defines a boolean indicating that date must be returned as ArrayBuffer

    • Optional onError: ((request?: WebRequest, exception?: any) => void)

      callback called when the file fails to load

        • Parameters

          • Optional request: WebRequest
          • Optional exception: any

          Returns void

    Returns IFileRequest

    a file request object

  • LoadFileAsync(url: string, useArrayBuffer?: boolean): Promise<string | ArrayBuffer>
  • Loads a file from a url

    Parameters

    • url: string

      the file url to load

    • Optional useArrayBuffer: boolean

      defines a boolean indicating that date must be returned as ArrayBuffer

    Returns Promise<string | ArrayBuffer>

    a promise containing an ArrayBuffer corresponding to the loaded file

  • LoadImage(input: string | Blob | ArrayBuffer, onLoad: ((img: HTMLImageElement | ImageBitmap) => void), onError: ((message?: string, exception?: any) => void), offlineProvider: Nullable<IOfflineProvider>, mimeType?: string, imageBitmapOptions?: ImageBitmapOptions): Nullable<HTMLImageElement>
  • Loads an image as an HTMLImageElement.

    Parameters

    • input: string | Blob | ArrayBuffer

      url string, ArrayBuffer, or Blob to load

    • onLoad: ((img: HTMLImageElement | ImageBitmap) => void)

      callback called when the image successfully loads

        • (img: HTMLImageElement | ImageBitmap): void
        • Parameters

          • img: HTMLImageElement | ImageBitmap

          Returns void

    • onError: ((message?: string, exception?: any) => void)

      callback called when the image fails to load

        • (message?: string, exception?: any): void
        • Parameters

          • Optional message: string
          • Optional exception: any

          Returns void

    • offlineProvider: Nullable<IOfflineProvider>

      offline provider for caching

    • Optional mimeType: string

      optional mime type

    • Optional imageBitmapOptions: ImageBitmapOptions

      optional the options to use when creating an ImageBitmap

    Returns Nullable<HTMLImageElement>

    the HTMLImageElement of the loaded image

  • LoadScript(scriptUrl: string, onSuccess: (() => void), onError?: ((message?: string, exception?: any) => void), scriptId?: string): void
  • Load a script (identified by an url). When the url returns, the content of this file is added into a new script element, attached to the DOM (body element)

    Parameters

    • scriptUrl: string

      defines the url of the script to laod

    • onSuccess: (() => void)

      defines the callback called when the script is loaded

        • (): void
        • Returns void

    • Optional onError: ((message?: string, exception?: any) => void)

      defines the callback to call if an error occurs

        • (message?: string, exception?: any): void
        • Parameters

          • Optional message: string
          • Optional exception: any

          Returns void

    • Optional scriptId: string

      defines the id of the script element

    Returns void

  • LoadScriptAsync(scriptUrl: string): Promise<void>
  • Load an asynchronous script (identified by an url). When the url returns, the content of this file is added into a new script element, attached to the DOM (body element)

    Parameters

    • scriptUrl: string

      defines the url of the script to laod

    Returns Promise<void>

    a promise request object

  • Log(message: string): void
  • Log a message to the console

    Parameters

    • message: string

      defines the message to log

    Returns void

  • MakeArray(obj: any, allowsNullUndefined?: boolean): Nullable<any[]>
  • Returns an array if obj is not an array

    Parameters

    • obj: any

      defines the object to evaluate as an array

    • Optional allowsNullUndefined: boolean

      defines a boolean indicating if obj is allowed to be null or undefined

    Returns Nullable<any[]>

    either obj directly if obj is an array or a new array containing obj

  • Mix(a: number, b: number, alpha: number): number
  • Interpolates between a and b via alpha

    Parameters

    • a: number

      The lower value (returned when alpha = 0)

    • b: number

      The upper value (returned when alpha = 1)

    • alpha: number

      The interpolation-factor

    Returns number

    The mixed value

  • RandomId(): string
  • ReadFile(file: File, onSuccess: ((data: any) => void), onProgress?: ((ev: ProgressEvent<EventTarget>) => any), useArrayBuffer?: boolean, onError?: ((error: ReadFileError) => void)): IFileRequest
  • Reads a file from a File object

    Parameters

    • file: File

      defines the file to load

    • onSuccess: ((data: any) => void)

      defines the callback to call when data is loaded

        • (data: any): void
        • Parameters

          • data: any

          Returns void

    • Optional onProgress: ((ev: ProgressEvent<EventTarget>) => any)

      defines the callback to call during loading process

        • (ev: ProgressEvent<EventTarget>): any
        • Parameters

          • ev: ProgressEvent<EventTarget>

          Returns any

    • Optional useArrayBuffer: boolean

      defines a boolean indicating that data must be returned as an ArrayBuffer

    • Optional onError: ((error: ReadFileError) => void)

      defines the callback to call when an error occurs

        • (error: ReadFileError): void
        • Parameters

          • error: ReadFileError

          Returns void

    Returns IFileRequest

    a file request object

  • ReadFileAsDataURL(fileToLoad: Blob, callback: ((data: any) => void), progressCallback: ((ev: ProgressEvent<EventTarget>) => any)): IFileRequest
  • Loads a file from a blob

    Parameters

    • fileToLoad: Blob

      defines the blob to use

    • callback: ((data: any) => void)

      defines the callback to call when data is loaded

        • (data: any): void
        • Parameters

          • data: any

          Returns void

    • progressCallback: ((ev: ProgressEvent<EventTarget>) => any)

      defines the callback to call during loading process

        • (ev: ProgressEvent<EventTarget>): any
        • Parameters

          • ev: ProgressEvent<EventTarget>

          Returns any

    Returns IFileRequest

    a file request object

  • RegisterTopRootEvents(windowElement: Window, events: { handler: Nullable<((e: FocusEvent) => any)>; name: string }[]): void
  • Function used to register events at window level

    Parameters

    • windowElement: Window

      defines the Window object to use

    • events: { handler: Nullable<((e: FocusEvent) => any)>; name: string }[]

      defines the events to register

    Returns void

  • SetCorsBehavior(url: string | string[], element: { crossOrigin: null | string }): void
  • Sets the cors behavior on a dom element. This will add the required Tools.CorsBehavior to the element.

    Parameters

    • url: string | string[]

      define the url we are trying

    • element: { crossOrigin: null | string }

      define the dom element where to configure the cors policy

      • crossOrigin: null | string

    Returns void

  • SetImmediate(action: (() => void)): void
  • Polyfill for setImmediate

    Parameters

    • action: (() => void)

      defines the action to execute after the current execution block

        • (): void
        • Returns void

    Returns void

  • SetReferrerPolicyBehavior(referrerPolicy: Nullable<ReferrerPolicy>, element: { referrerPolicy: null | string }): void
  • Sets the referrerPolicy behavior on a dom element.

    Parameters

    • referrerPolicy: Nullable<ReferrerPolicy>

      define the referrer policy to use

    • element: { referrerPolicy: null | string }

      define the dom element where to configure the referrer policy

      • referrerPolicy: null | string

    Returns void

  • SmoothAngleChange(previousAngle: number, newAngle: number, smoothFactor?: number): number
  • Smooth angle changes (kind of low-pass filter), in particular for device orientation "shaking" Use trigonometric functions to avoid discontinuity (0/360, -180/180)

    Parameters

    • previousAngle: number

      defines last angle value, in degrees

    • newAngle: number

      defines new angle value, in degrees

    • Optional smoothFactor: number

      defines smoothing sensitivity; min 0: no smoothing, max 1: new data ignored

    Returns number

    the angle in degrees

  • ToBlob(canvas: HTMLCanvasElement | OffscreenCanvas, successCallback: ((blob: Nullable<Blob>) => void), mimeType?: string, quality?: number): void
  • Converts the canvas data to blob. This acts as a polyfill for browsers not supporting the to blob function.

    Parameters

    • canvas: HTMLCanvasElement | OffscreenCanvas

      Defines the canvas to extract the data from (can be an offscreen canvas)

    • successCallback: ((blob: Nullable<Blob>) => void)

      Defines the callback triggered once the data are available

    • Optional mimeType: string

      Defines the mime type of the result

    • Optional quality: number

      The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See HTMLCanvasElement.toBlob()'s quality parameter.

    Returns void

  • ToDegrees(angle: number): number
  • Convert an angle in radians to degrees

    Parameters

    • angle: number

      defines the angle to convert

    Returns number

    the angle in degrees

  • ToRadians(angle: number): number
  • Convert an angle in degrees to radians

    Parameters

    • angle: number

      defines the angle to convert

    Returns number

    the angle in radians

  • UnregisterTopRootEvents(windowElement: Window, events: { handler: Nullable<((e: FocusEvent) => any)>; name: string }[]): void
  • Function used to unregister events from window level

    Parameters

    • windowElement: Window

      defines the Window object to use

    • events: { handler: Nullable<((e: FocusEvent) => any)>; name: string }[]

      defines the events to unregister

    Returns void

  • Warn(message: string): void
  • Write a warning message to the console

    Parameters

    • message: string

      defines the message to log

    Returns void

  • getFullClassName(object: any, isType?: boolean): Nullable<string>
  • This method will return the name of the full name of the class, including its owning module (if any). 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).

    ignorenaming

    Parameters

    • object: any

      the object to get the class name from

    • Optional isType: boolean

      defines if the object is actually a type

    Returns Nullable<string>

    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.

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static property
  • Static method

Settings

Theme