Tools

Class containing a set of static utilities functions

Hierarchy

  • Tools

Index

Properties

Static AllLogLevel

Find examples in Playground
AllLogLevel: number

All logs

Static BaseUrl

Find examples in Playground
BaseUrl: string

Gets or sets the base URL to use to load assets

Static CorsBehavior

Find examples in Playground
CorsBehavior: string | function

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)

Static CustomRequestHeaders

Find examples in Playground
CustomRequestHeaders: object

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

Static DefaultRetryStrategy

Find examples in Playground
DefaultRetryStrategy: function

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

Type declaration

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

      • url: string
      • request: WebRequest
      • retryIndex: number

      Returns number

Static EndPerformanceCounter

Find examples in Playground
EndPerformanceCounter: function

Ends a specific performance coutner

Type declaration

    • (counterName: string, condition?: boolean): void
    • Parameters

      • counterName: string
      • Optional condition: boolean

      Returns void

Static ErrorLogLevel

Find examples in Playground
ErrorLogLevel: number

Only error logs

Static GetDOMTextContent

Find examples in Playground
GetDOMTextContent: GetDOMTextContent

Extracts text content from a DOM element hierarchy Back Compat only, please use DomManagement.GetDOMTextContent instead.

Static IsWindowObjectExist

Find examples in Playground
IsWindowObjectExist: IsWindowObjectExist

Checks if the window object exists Back Compat only, please use DomManagement.IsWindowObjectExist instead.

Static LogCache

Find examples in Playground
LogCache: string

Gets current log cache (list of logs)

Static LogLevels

Find examples in Playground
LogLevels: number

Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)

Static MessageLogLevel

Find examples in Playground
MessageLogLevel: number

Only message logs

Static NoneLogLevel

Find examples in Playground
NoneLogLevel: number

No log

Static Now

Find examples in Playground
Now: number

Gets either window.performance.now() if supported or Date.now() else

Static OnNewCacheEntry

Find examples in Playground
OnNewCacheEntry: function

Callback called when a new log is added

Type declaration

    • (entry: string): void
    • Parameters

      • entry: string

      Returns void

Static PerformanceConsoleLogLevel

Find examples in Playground
PerformanceConsoleLogLevel: number

Log performance to the console

Static PerformanceLogLevel

Find examples in Playground
PerformanceLogLevel: number

Sets the current performance log level

Static PerformanceNoneLogLevel

Find examples in Playground
PerformanceNoneLogLevel: number

No performance log

Static PerformanceUserMarkLogLevel

Find examples in Playground
PerformanceUserMarkLogLevel: number

Use user marks to log performance

Static PreprocessUrl

Find examples in Playground
PreprocessUrl: function

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

Type declaration

    • (url: string): string
    • Parameters

      • url: string

      Returns string

Static RegisteredExternalClasses

Find examples in Playground
RegisteredExternalClasses: object

Use this object to register external classes like custom textures or material to allow the laoders to instantiate them

Type declaration

  • [key: string]: Object

Static StartPerformanceCounter

Find examples in Playground
StartPerformanceCounter: function

Starts a performance counter

Type declaration

    • (counterName: string, condition?: boolean): void
    • Parameters

      • counterName: string
      • Optional condition: boolean

      Returns void

Static UseCustomRequestHeaders

Find examples in Playground
UseCustomRequestHeaders: boolean

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

see

CustomRequestHeaders

Static UseFallbackTexture

Find examples in Playground
UseFallbackTexture: boolean

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

ignorenaming

Static WarningLogLevel

Find examples in Playground
WarningLogLevel: number

Only warning logs

Static errorsCount

Find examples in Playground
errorsCount: number

Gets a value indicating the number of loading errors

ignorenaming

Static fallbackTexture

Find examples in Playground
fallbackTexture: string

Texture content used if a texture cannot loaded

ignorenaming

Methods

Static CleanUrl

Find examples in Playground
  • CleanUrl(url: string): string
  • Removes unwanted characters from an url

    Parameters

    • url: string

      defines the url to clean

    Returns string

    the cleaned url

Static ClearLogCache

Find examples in Playground
  • ClearLogCache(): void
  • Clears the log cache

    Returns void

Static CreateScreenshot

Find examples in Playground
  • CreateScreenshot(engine: Engine, camera: Camera, size: IScreenshotSize | number, successCallback?: function, mimeType?: string): void
  • Captures a screenshot of the current rendering

    see

    http://doc.babylonjs.com/how_to/render_scene_on_a_png

    Parameters

    • engine: Engine

      defines the rendering engine

    • camera: Camera

      defines the source camera

    • size: IScreenshotSize | number

      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: function

      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

    Returns void

Static CreateScreenshotAsync

Find examples in Playground
  • Captures a screenshot of the current rendering

    see

    http://doc.babylonjs.com/how_to/render_scene_on_a_png

    Parameters

    • engine: Engine

      defines the rendering engine

    • camera: Camera

      defines the source camera

    • size: IScreenshotSize | number

      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

    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

Static CreateScreenshotUsingRenderTarget

Find examples in Playground
  • CreateScreenshotUsingRenderTarget(engine: Engine, camera: Camera, size: IScreenshotSize | number, successCallback?: function, mimeType?: string, samples?: number, antialiasing?: boolean, fileName?: string): void
  • Generates an image screenshot from the specified camera.

    see

    http://doc.babylonjs.com/how_to/render_scene_on_a_png

    Parameters

    • engine: Engine

      The engine to use for rendering

    • camera: Camera

      The camera to use for rendering

    • size: IScreenshotSize | number

      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: function

      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.

    Returns void

Static CreateScreenshotUsingRenderTargetAsync

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

    see

    http://doc.babylonjs.com/how_to/render_scene_on_a_png

    Parameters

    • engine: Engine

      The engine to use for rendering

    • camera: Camera

      The camera to use for rendering

    • size: IScreenshotSize | number

      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.

    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

Static DecodeBase64

Find examples in Playground
  • DecodeBase64(uri: string): ArrayBuffer
  • Decode the given base64 uri.

    Parameters

    • uri: string

      The uri to decode

    Returns ArrayBuffer

    The decoded base64 data.

Static DeepCopy

Find examples in Playground
  • 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

Static DelayAsync

Find examples in Playground
  • 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

Static Download

Find examples in Playground
  • 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

Static DumpFramebuffer

Find examples in Playground
  • DumpFramebuffer(width: number, height: number, engine: Engine, successCallback?: function, mimeType?: string, fileName?: string): 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: function

      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

    Returns void

Static EncodeArrayBufferTobase64

Find examples in Playground
  • EncodeArrayBufferTobase64(buffer: ArrayBuffer): string
  • Encode a buffer to a base64 string

    Parameters

    • buffer: ArrayBuffer

      defines the buffer to encode

    Returns string

    the encoded string

Static EncodeScreenshotCanvasData

Find examples in Playground
  • EncodeScreenshotCanvasData(successCallback?: function, mimeType?: string, fileName?: string): void
  • Encodes the canvas data to base 64 or automatically download the result if filename is defined

    Parameters

    • Optional successCallback: function

      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 he filename to download. If present, the result will automatically be downloaded

    Returns void

Static Error

Find examples in Playground
  • Error(message: string): void
  • Write an error message to the console

    Parameters

    • message: string

      defines the message to log

    Returns void

Static FetchToRef

Find examples in Playground
  • 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

Static FileAsURL

Find examples in Playground
  • 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

Static First

Find examples in Playground
  • First<T>(array: Array<T>, predicate: function): Nullable<T>
  • Gets the first element of an array satisfying a given predicate

    Type parameters

    • T

    Parameters

    • array: Array<T>

      defines the array to browse

    • predicate: function

      defines the predicate to use

        • (item: T): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns Nullable<T>

    null if not found or the element

Static FloatRound

Find examples in Playground
  • 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

Static Format

Find examples in Playground
  • 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

Static GetAbsoluteUrl

Find examples in Playground
  • GetAbsoluteUrl(url: string): string
  • Gets the absolute url.

    Parameters

    • url: string

      the input url

    Returns string

    the absolute url

Static GetClassName

Find examples in Playground
  • 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

Static GetFilename

Find examples in Playground
  • GetFilename(path: string): string
  • Extracts the filename from a path

    Parameters

    • path: string

      defines the path to use

    Returns string

    the filename

Static GetFolderPath

Find examples in Playground
  • 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

Static GetPointerPrefix

Find examples in Playground
  • GetPointerPrefix(): string
  • Gets the pointer prefix to use

    Returns string

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

Static Instantiate

Find examples in Playground
  • 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

Static IsBase64

Find examples in Playground
  • IsBase64(uri: string): boolean
  • Test if the given uri is a base64 string

    Parameters

    • uri: string

      The uri to test

    Returns boolean

    True if the uri is a base64 string or false otherwise

Static IsEmpty

Find examples in Playground
  • 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

Static IsExponentOfTwo

Find examples in Playground
  • 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

Static LoadFile

Find examples in Playground
  • LoadFile(url: string, onSuccess: function, onProgress?: function, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean, onError?: function): IFileRequest
  • Loads a file

    Parameters

    • url: string

      url string, ArrayBuffer, or Blob to load

    • onSuccess: function

      callback called when the file successfully loads

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

          • data: string | ArrayBuffer
          • Optional responseURL: string

          Returns void

    • Optional onProgress: function

      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: function

      callback called when the file fails to load

        • Parameters

          • Optional request: WebRequest
          • Optional exception: any

          Returns void

    Returns IFileRequest

    a file request object

Static LoadFileAsync

Find examples in Playground
  • LoadFileAsync(url: string): Promise<ArrayBuffer>
  • Loads a file from a url

    Parameters

    • url: string

      the file url to load

    Returns Promise<ArrayBuffer>

    a promise containing an ArrayBuffer corrisponding to the loaded file

Static LoadImage

Find examples in Playground
  • LoadImage(input: string | ArrayBuffer | Blob, onLoad: function, onError: function, offlineProvider: Nullable<IOfflineProvider>): HTMLImageElement
  • Loads an image as an HTMLImageElement.

    Parameters

    • input: string | ArrayBuffer | Blob

      url string, ArrayBuffer, or Blob to load

    • onLoad: function

      callback called when the image successfully loads

        • (img: HTMLImageElement): void
        • Parameters

          • img: HTMLImageElement

          Returns void

    • onError: function

      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

    Returns HTMLImageElement

    the HTMLImageElement of the loaded image

Static LoadScript

Find examples in Playground
  • LoadScript(scriptUrl: string, onSuccess: function, onError?: function, 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: function

      defines the callback called when the script is loaded

        • (): void
        • Returns void

    • Optional onError: function

      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

Static LoadScriptAsync

Find examples in Playground
  • LoadScriptAsync(scriptUrl: string, scriptId?: string): Promise<boolean>
  • 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

    • Optional scriptId: string

      defines the id of the script element

    Returns Promise<boolean>

    a promise request object

Static Log

Find examples in Playground
  • Log(message: string): void
  • Log a message to the console

    Parameters

    • message: string

      defines the message to log

    Returns void

Static MakeArray

Find examples in Playground
  • MakeArray(obj: any, allowsNullUndefined?: boolean): Nullable<Array<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<Array<any>>

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

Static Mix

Find examples in Playground
  • 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

Static RandomId

Find examples in Playground
  • RandomId(): string

Static ReadFile

Find examples in Playground
  • ReadFile(fileToLoad: File, callback: function, progressCallBack?: function, useArrayBuffer?: boolean): IFileRequest
  • Loads a file

    Parameters

    • fileToLoad: File

      defines the file to load

    • callback: function

      defines the callback to call when data is loaded

        • (data: any): void
        • Parameters

          • data: any

          Returns void

    • Optional progressCallBack: function

      defines the callback to call during loading process

        • (ev: ProgressEvent): any
        • Parameters

          • ev: ProgressEvent

          Returns any

    • Optional useArrayBuffer: boolean

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

    Returns IFileRequest

    a file request object

Static ReadFileAsDataURL

Find examples in Playground
  • ReadFileAsDataURL(fileToLoad: Blob, callback: function, progressCallback: function): IFileRequest
  • Loads a file from a blob

    Parameters

    • fileToLoad: Blob

      defines the blob to use

    • callback: function

      defines the callback to call when data is loaded

        • (data: any): void
        • Parameters

          • data: any

          Returns void

    • progressCallback: function

      defines the callback to call during loading process

        • (ev: ProgressEvent): any
        • Parameters

          • ev: ProgressEvent

          Returns any

    Returns IFileRequest

    a file request object

Static RegisterTopRootEvents

Find examples in Playground
  • RegisterTopRootEvents(windowElement: Window, events: object[]): void
  • Function used to register events at window level

    Parameters

    • windowElement: Window

      defines the Window object to use

    • events: object[]

      defines the events to register

    Returns void

Static SetCorsBehavior

Find examples in Playground
  • SetCorsBehavior(url: string | string[], element: object): 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: object

      define the dom element where to configure the cors policy

      • crossOrigin: string | null

    Returns void

Static SetImmediate

Find examples in Playground
  • SetImmediate(action: function): void
  • Polyfill for setImmediate

    Parameters

    • action: function

      defines the action to execute after the current execution block

        • (): void
        • Returns void

    Returns void

Static Slice

Find examples in Playground
  • Slice<T>(data: T, start?: number, end?: number): T
  • Provides a slice function that will work even on IE

    Type parameters

    • T

    Parameters

    • data: T

      defines the array to slice

    • Optional start: number

      defines the start of the data (optional)

    • Optional end: number

      defines the end of the data (optional)

    Returns T

    the new sliced array

Static ToBlob

Find examples in Playground
  • ToBlob(canvas: HTMLCanvasElement, successCallback: function, mimeType?: string): void
  • Converts the canvas data to blob. This acts as a polyfill for browsers not supporting the to blob function.

    Parameters

    • canvas: HTMLCanvasElement

      Defines the canvas to extract the data from

    • successCallback: function

      Defines the callback triggered once the data are available

    • Optional mimeType: string

      Defines the mime type of the result

    Returns void

Static ToDegrees

Find examples in Playground
  • 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

Static ToRadians

Find examples in Playground
  • 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

Static UnregisterTopRootEvents

Find examples in Playground
  • UnregisterTopRootEvents(windowElement: Window, events: object[]): void
  • Function used to unregister events from window level

    Parameters

    • windowElement: Window

      defines the Window object to use

    • events: object[]

      defines the events to unregister

    Returns void

Static Warn

Find examples in Playground
  • Warn(message: string): void
  • Write a warning message to the console

    Parameters

    • message: string

      defines the message to log

    Returns void

Static getFullClassName

Find examples in Playground
  • 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.

Generated using TypeDoc