API

Class DynamicTexture

A class extending Texture allowing drawing on a texture

Hierarchy (View Summary)

Index
animations: Animation[] = []

Define the list of animation attached to the texture.

anisotropicFilteringLevel: number = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL

With compliant hardware and browser (supporting anisotropic filtering) this defines the level of anisotropic filtering in the texture. The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.

delayLoadState: number = Constants.DELAYLOADSTATE_NONE

Define the current state of the loading sequence when in delayed load mode.

displayName: string

Define the display name of the texture, which is used as tree item name of the dedicated node in the inspector

homogeneousRotationInUVTransform: boolean = false

Sets this property to true to avoid deformations when rotating the texture with non-uniform scaling

inspectableCustomProperties: Nullable<IInspectable[]> = null

List of inspectable custom properties (used by the Inspector)

invertZ: boolean = false

Is Z inverted in the texture (useful in a cube texture).

isRenderTarget: boolean = false

Define if the texture is a render target.

level: number = 1

Intensity or strength of the texture. It is commonly used by materials to fine tune the intensity of the texture

metadata: any = null

Gets or sets an object used to store user defined information.

name: string

Define the name of the texture.

onDisposeObservable: Observable<BaseTexture> = ...

An event triggered when the texture is disposed.

onLoadObservable: Observable<Texture> = ...

Observable triggered once the texture has been loaded.

optimizeUVAllocation: boolean = true

Gets or sets a boolean indicating that the texture should try to reduce shader code if there is no UV manipulation. (ie. when texture.getTextureMatrix().isIdentityAs3x2() returns true)

reservedDataStore: any = null

For internal use only. Please do not use.

sphericalPolynomial: Nullable<SphericalPolynomial>

Get the polynomial representation of the texture data. This is mainly use as a fast way to recover IBL Diffuse irradiance data.

uAng: number = 0

Define an offset on the texture to rotate around the u coordinates of the UVs The angle is defined in radians.

uniqueId: number

Gets or sets the unique id of the texture

uOffset: number = 0

Define an offset on the texture to offset the u coordinates of the UVs

url: Nullable<string> = null

Define the url of the texture.

uRotationCenter: number = 0.5

Defines the center of rotation (U)

uScale: number = 1.0

Define an offset on the texture to scale the u coordinates of the UVs

vAng: number = 0

Define an offset on the texture to rotate around the v coordinates of the UVs The angle is defined in radians.

vOffset: number = 0

Define an offset on the texture to offset the v coordinates of the UVs

vRotationCenter: number = 0.5

Defines the center of rotation (V)

vScale: number = 1.0

Define an offset on the texture to scale the v coordinates of the UVs

wAng: number = 0

Define an offset on the texture to rotate around the w coordinates of the UVs (in case of 3d texture) The angle is defined in radians.

wrapR: number = Constants.TEXTURE_WRAP_ADDRESSMODE
ValueTypeDescription
0CLAMP_ADDRESSMODE
1WRAP_ADDRESSMODE
2MIRROR_ADDRESSMODE
wRotationCenter: number = 0.5

Defines the center of rotation (W)

BILINEAR_SAMPLINGMODE: 2 = Constants.TEXTURE_BILINEAR_SAMPLINGMODE

Bilinear is mag = linear and min = linear and no mip

CLAMP_ADDRESSMODE: 0 = Constants.TEXTURE_CLAMP_ADDRESSMODE

Texture is not repeating outside of 0..1 UVs

CUBIC_MODE: 3 = Constants.TEXTURE_CUBIC_MODE

Cubic coordinates mode

DEFAULT_ANISOTROPIC_FILTERING_LEVEL: number = 4

Default anisotropic filtering level for the application. It is set to 4 as a good tradeoff between perf and quality.

EQUIRECTANGULAR_MODE: 7 = Constants.TEXTURE_EQUIRECTANGULAR_MODE

Equirectangular coordinates mode

EXPLICIT_MODE: 0 = Constants.TEXTURE_EXPLICIT_MODE

Explicit coordinates mode

FIXED_EQUIRECTANGULAR_MIRRORED_MODE: 9 = Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE

Equirectangular Fixed Mirrored coordinates mode

FIXED_EQUIRECTANGULAR_MODE: 8 = Constants.TEXTURE_FIXED_EQUIRECTANGULAR_MODE

Equirectangular Fixed coordinates mode

ForceSerializeBuffers: boolean = false

Gets or sets a general boolean used to indicate that texture buffers must be saved as part of the serialization process. If no buffer exists, one will be created as base64 string from the internal webgl data.

INVCUBIC_MODE: 6 = Constants.TEXTURE_INVCUBIC_MODE

Inverse Cubic coordinates mode

LINEAR_LINEAR: 2 = Constants.TEXTURE_LINEAR_LINEAR

mag = linear and min = linear and mip = none

LINEAR_LINEAR_MIPLINEAR: 3 = Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR

Trilinear is mag = linear and min = linear and mip = linear

LINEAR_LINEAR_MIPNEAREST: 11 = Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST

Bilinear is mag = linear and min = linear and mip = nearest

LINEAR_NEAREST: 12 = Constants.TEXTURE_LINEAR_NEAREST

mag = linear and min = nearest and mip = none

LINEAR_NEAREST_MIPLINEAR: 10 = Constants.TEXTURE_LINEAR_NEAREST_MIPLINEAR

mag = linear and min = nearest and mip = linear

LINEAR_NEAREST_MIPNEAREST: 9 = Constants.TEXTURE_LINEAR_NEAREST_MIPNEAREST

mag = linear and min = nearest and mip = nearest

MIRROR_ADDRESSMODE: 2 = Constants.TEXTURE_MIRROR_ADDRESSMODE

Texture is repeating and mirrored

NEAREST_LINEAR: 7 = Constants.TEXTURE_NEAREST_LINEAR

mag = nearest and min = linear and mip = none

NEAREST_LINEAR_MIPLINEAR: 6 = Constants.TEXTURE_NEAREST_LINEAR_MIPLINEAR

mag = nearest and min = linear and mip = linear

NEAREST_LINEAR_MIPNEAREST: 5 = Constants.TEXTURE_NEAREST_LINEAR_MIPNEAREST

mag = nearest and min = linear and mip = nearest

NEAREST_NEAREST: 1 = Constants.TEXTURE_NEAREST_NEAREST

mag = nearest and min = nearest and mip = none

NEAREST_NEAREST_MIPLINEAR: 8 = Constants.TEXTURE_NEAREST_NEAREST_MIPLINEAR

nearest is mag = nearest and min = nearest and mip = linear

NEAREST_NEAREST_MIPNEAREST: 4 = Constants.TEXTURE_NEAREST_NEAREST_MIPNEAREST

mag = nearest and min = nearest and mip = nearest

NEAREST_SAMPLINGMODE: 1 = Constants.TEXTURE_NEAREST_SAMPLINGMODE

nearest is mag = nearest and min = nearest and no mip

OnTextureLoadErrorObservable: Observable<BaseTexture> = ...

This observable will notify when any texture had a loading error

PLANAR_MODE: 2 = Constants.TEXTURE_PLANAR_MODE

Planar coordinates mode

PROJECTION_MODE: 4 = Constants.TEXTURE_PROJECTION_MODE

Projection coordinates mode

SerializeBuffers: boolean = true

Gets or sets a general boolean used to indicate that textures containing direct data (buffers) must be saved as part of the serialization process

SKYBOX_MODE: 5 = Constants.TEXTURE_SKYBOX_MODE

Inverse Cubic coordinates mode

SPHERICAL_MODE: 1 = Constants.TEXTURE_SPHERICAL_MODE

Spherical coordinates mode

TRILINEAR_SAMPLINGMODE: 3 = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE

Trilinear is mag = linear and min = linear and mip = linear

UseSerializedUrlIfAny: boolean = false

Gets or sets a boolean which defines if the texture url must be build from the serialized URL instead of just using the name and loading them side by side with the scene file

WRAP_ADDRESSMODE: 1 = Constants.TEXTURE_WRAP_ADDRESSMODE

Texture is repeating outside of 0..1 UVs

  • get errorObject(): { exception?: any; message?: string } | undefined

    If a loading error occurred this object will be populated with information about the error.

    Returns { exception?: any; message?: string } | undefined

  • get isBlocking(): boolean

    Define if the texture is preventing a material to render or not. If not and the texture is not ready, the engine will use a default black texture instead.

    Returns boolean

  • set isBlocking(value: boolean): void

    Is the texture preventing material to render while loading. If false, a default texture will be used instead of the loading one during the preparation step.

    Parameters

    • value: boolean

    Returns void

  • set onDispose(callback: () => void): void

    Callback triggered when the texture has been disposed. Kept for back compatibility, you can use the onDisposeObservable instead.

    Parameters

    • callback: () => void

    Returns void

  • Draws text onto the texture

    Parameters

    • text: string

      defines the text to be drawn

    • x: number | null | undefined

      defines the placement of the text from the left

    • y: number | null | undefined

      defines the placement of the text from the top when invertY is true and from the bottom when false

    • font: string

      defines the font to be used with font-style, font-size, font-name

    • color: string | null

      defines the color used for the text

    • fillColor: string | null

      defines the color for the canvas, use null to not overwrite canvas (this blends with the background to replace, use the clear function)

    • OptionalinvertY: boolean

      defines the direction for the Y axis (default is true - y increases downwards)

    • update: boolean = true

      defines whether texture is immediately update (default is true)

    Returns void

  • Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer. This will returns an RGBA array buffer containing either in values (0-255) or float values (0-1) depending of the underlying buffer type. Note that you can use GetTextureDataAsync instead, which will also support reading from a compressed texture (by rendering it to an intermediate RGBA texture and retrieving the bytes from it).

    Parameters

    • faceIndex: number = 0

      defines the face of the texture to read (in case of cube texture)

    • level: number = 0

      defines the LOD level of the texture to read (in case of Mip Maps)

    • buffer: Nullable<ArrayBufferView<ArrayBufferLike>> = null

      defines a user defined buffer to fill with data (can be null)

    • flushRenderer: boolean = true

      true to flush the renderer from the pending commands before reading the pixels

    • noDataConversion: boolean = false

      false to convert the data to Uint8Array (if texture type is UNSIGNED_BYTE) or to Float32Array (if texture type is anything but UNSIGNED_BYTE). If true, the type of the generated buffer (if buffer==null) will depend on the type of the texture

    • x: number = 0

      defines the region x coordinates to start reading from (default to 0)

    • y: number = 0

      defines the region y coordinates to start reading from (default to 0)

    • width: number = Number.MAX_VALUE

      defines the region width to read from (default to the texture size at level)

    • height: number = Number.MAX_VALUE

      defines the region width to read from (default to the texture size at level)

    Returns Nullable<Promise<ArrayBufferView<ArrayBufferLike>>>

    The Array buffer promise containing the pixels data.

  • Updates the texture

    Parameters

    • OptionalinvertY: boolean

      defines the direction for the Y axis (default is true - y increases downwards)

    • premulAlpha: boolean = false

      defines if alpha is stored as premultiplied (default is false)

    • allowGPUOptimization: boolean = false

      true to allow some specific GPU optimizations (subject to engine feature "allowGPUOptimizationsForGUI" being true)

    Returns void

  • Update the sampling mode of the texture. Default is Trilinear mode.

    ValueTypeDescription
    1NEAREST_SAMPLINGMODE or NEAREST_NEAREST_MIPLINEARNearest is: mag = nearest, min = nearest, mip = linear
    2BILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPNEARESTBilinear is: mag = linear, min = linear, mip = nearest
    3TRILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPLINEARTrilinear is: mag = linear, min = linear, mip = linear
    4NEAREST_NEAREST_MIPNEAREST
    5NEAREST_LINEAR_MIPNEAREST
    6NEAREST_LINEAR_MIPLINEAR
    7NEAREST_LINEAR
    8NEAREST_NEAREST
    9LINEAR_NEAREST_MIPNEAREST
    10LINEAR_NEAREST_MIPLINEAR
    11LINEAR_LINEAR
    12LINEAR_NEAREST

    mag: magnification filter (close to the viewer) min: minification filter (far from the viewer) mip: filter used between mip map levels

    Parameters

    • samplingMode: number

      Define the new sampling mode of the texture

    • generateMipMaps: boolean = false

      Define if the texture should generate mip maps or not. Default is false.

    Returns void

  • Update the url (and optional buffer) of this texture if url was null during construction.

    Parameters

    • url: string

      the url of the texture

    • buffer: Nullable<
          | string
          | ArrayBuffer
          | ArrayBufferView<ArrayBufferLike>
          | HTMLImageElement
          | ImageBitmap
          | Blob,
      > = null

      the buffer of the texture (defaults to null)

    • OptionalonLoad: () => void

      callback called when the texture is loaded (defaults to null)

    • OptionalforcedExtension: string

      defines the extension to use to pick the right loader

    Returns void

  • Creates a texture from its base 64 representation.

    Parameters

    • data: string

      Define the base64 payload without the data: prefix

    • name: string

      Define the name of the texture in the scene useful fo caching purpose for instance

    • scene: Scene

      Define the scene the texture should belong to

    • OptionalnoMipmapOrOptions: boolean | ITextureCreationOptions

      defines if the texture will require mip maps or not or set of all options to create the texture

    • OptionalinvertY: boolean

      define if the texture needs to be inverted on the y axis during loading

    • samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE

      define the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)

    • onLoad: Nullable<() => void> = null

      define a callback triggered when the texture has been loaded

    • onError: Nullable<() => void> = null

      define a callback triggered when an error occurred during the loading session

    • format: number = Constants.TEXTUREFORMAT_RGBA

      define the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)

    • OptionalcreationFlags: number

      specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)

    • OptionalforcedExtension: string

      defines the extension to use to pick the right loader

    Returns Texture

    the created texture

  • Creates a texture from its data: representation. (data: will be added in case only the payload has been passed in)

    Parameters

    • name: string

      Define the name of the texture in the scene useful fo caching purpose for instance

    • buffer: any

      define the buffer to load the texture from in case the texture is loaded from a buffer representation

    • scene: Scene

      Define the scene the texture should belong to

    • deleteBuffer: boolean = false

      define if the buffer we are loading the texture from should be deleted after load

    • OptionalnoMipmapOrOptions: boolean | ITextureCreationOptions

      defines if the texture will require mip maps or not or set of all options to create the texture

    • invertY: boolean = true

      define if the texture needs to be inverted on the y axis during loading

    • samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE

      define the sampling mode we want for the texture while fetching from it (Texture.NEAREST_SAMPLINGMODE...)

    • onLoad: Nullable<() => void> = null

      define a callback triggered when the texture has been loaded

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

      define a callback triggered when an error occurred during the loading session

    • format: number = Constants.TEXTUREFORMAT_RGBA

      define the format of the texture we are trying to load (Engine.TEXTUREFORMAT_RGBA...)

    • OptionalcreationFlags: number

      specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)

    • OptionalforcedExtension: string

      defines the extension to use to pick the right loader

    Returns Texture

    the created texture