Options
All
  • Public
  • Public/Protected
  • All
Menu

Class for creating a cube texture

Hierarchy

Index

Constructors

  • new CubeTexture(rootUrl: string, sceneOrEngine: Scene | ThinEngine, extensions?: Nullable<string[]>, noMipmap?: boolean, files?: Nullable<string[]>, onLoad?: Nullable<(() => void)>, onError?: Nullable<((message?: string, exception?: any) => void)>, format?: number, prefiltered?: boolean, forcedExtension?: any, createPolynomials?: boolean, lodScale?: number, lodOffset?: number, loaderOptions?: any, useSRGBBuffer?: boolean): CubeTexture
  • Creates a cube texture to use with reflection for instance. It can be based upon dds or six images as well as prefiltered data.

    Parameters

    • rootUrl: string

      defines the url of the texture or the root name of the six images

    • sceneOrEngine: Scene | ThinEngine

      defines the scene or engine the texture is attached to

    • Optional extensions: Nullable<string[]>

      defines the suffixes add to the picture name in case six images are in use like _px.jpg...

    • Optional noMipmap: boolean

      defines if mipmaps should be created or not

    • Optional files: Nullable<string[]>

      defines the six files to load for the different faces in that order: px, py, pz, nx, ny, nz

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

      defines a callback triggered at the end of the file load if no errors occurred

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

      defines a callback triggered in case of error during load

    • Optional format: number

      defines the internal format to use for the texture once loaded

    • Optional prefiltered: boolean

      defines whether or not the texture is created from prefiltered data

    • Optional forcedExtension: any

      defines the extensions to use (force a special type of file to load) in case it is different from the file name

    • Optional createPolynomials: boolean

      defines whether or not to create polynomial harmonics from the texture data if necessary

    • Optional lodScale: number

      defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness

    • Optional lodOffset: number

      defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness

    • Optional loaderOptions: any

      options to be passed to the loader

    • Optional useSRGBBuffer: boolean

      Defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU) (default: false)

    Returns CubeTexture

    the cube texture

Properties

animations: Animation[]

Define the list of animation attached to the texture.

anisotropicFilteringLevel: number

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.

boundingBoxPosition: Vector3

Gets or sets the center of the bounding box associated with the cube texture. It must define where the camera used to render the texture was set

see

https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture#using-local-cubemap-mode

delayLoadState: number

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

invertZ: boolean

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

isRenderTarget: boolean

Define if the texture is a render target.

level: number

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

metadata: any

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<CubeTexture>

Observable triggered once the texture has been loaded.

optimizeUVAllocation: boolean

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

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.

see

https://learnopengl.com/PBR/IBL/Diffuse-irradiance

uniqueId: number

Gets or sets the unique id of the texture

url: string

The url of the texture

wrapR: number
ValueTypeDescription
0CLAMP_ADDRESSMODE
1WRAP_ADDRESSMODE
2MIRROR_ADDRESSMODE
DEFAULT_ANISOTROPIC_FILTERING_LEVEL: number

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

Accessors

  • get boundingBoxSize(): Vector3
  • set boundingBoxSize(value: Vector3): void
  • get canRescale(): boolean
  • Get if the texture can rescale.

    Returns boolean

  • get coordinatesIndex(): number
  • set coordinatesIndex(value: number): void
  • Define the UV channel to use starting from 0 and defaulting to 0. This is part of the texture as textures usually maps to one uv set.

    Returns number

  • Define the UV channel to use starting from 0 and defaulting to 0. This is part of the texture as textures usually maps to one uv set.

    Parameters

    • value: number

    Returns void

  • get coordinatesMode(): number
  • set coordinatesMode(value: number): void
  • How a texture is mapped.

    ValueTypeDescription
    0EXPLICIT_MODE
    1SPHERICAL_MODE
    2PLANAR_MODE
    3CUBIC_MODE
    4PROJECTION_MODE
    5SKYBOX_MODE
    6INVCUBIC_MODE
    7EQUIRECTANGULAR_MODE
    8FIXED_EQUIRECTANGULAR_MODE
    9FIXED_EQUIRECTANGULAR_MIRRORED_MODE

    Returns number

  • How a texture is mapped.

    ValueTypeDescription
    0EXPLICIT_MODE
    1SPHERICAL_MODE
    2PLANAR_MODE
    3CUBIC_MODE
    4PROJECTION_MODE
    5SKYBOX_MODE
    6INVCUBIC_MODE
    7EQUIRECTANGULAR_MODE
    8FIXED_EQUIRECTANGULAR_MODE
    9FIXED_EQUIRECTANGULAR_MIRRORED_MODE

    Parameters

    • value: number

    Returns void

  • get errorObject(): undefined | { exception?: any; message?: string }
  • If a loading error occurred this object will be populated with information about the error.

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

  • Gets the forced extension (if any)

    Returns Nullable<string>

  • get gammaSpace(): boolean
  • set gammaSpace(gamma: boolean): void
  • Define if the texture contains data in gamma space (most of the png/jpg aside bump). HDR texture are usually stored in linear space. This only impacts the PBR and Background materials

    Returns boolean

  • Define if the texture contains data in gamma space (most of the png/jpg aside bump). HDR texture are usually stored in linear space. This only impacts the PBR and Background materials

    Parameters

    • gamma: boolean

    Returns void

  • get getAlphaFromRGB(): boolean
  • set getAlphaFromRGB(value: boolean): void
  • Defines if the alpha value should be determined via the rgb values. If true the luminance of the pixel might be used to find the corresponding alpha value.

    Returns boolean

  • Defines if the alpha value should be determined via the rgb values. If true the luminance of the pixel might be used to find the corresponding alpha value.

    Parameters

    • value: boolean

    Returns void

  • get hasAlpha(): boolean
  • set hasAlpha(value: boolean): void
  • Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).

    Returns boolean

  • Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).

    Parameters

    • value: boolean

    Returns void

  • In case a better definition than spherical harmonics is required for the diffuse part of the environment. You can set the irradiance texture to rely on a texture instead of the spherical approach. This texture need to have the same characteristics than its parent (Cube vs 2d, coordinates mode, Gamma/Linear, RGBD).

    Returns Nullable<BaseTexture>

  • In case a better definition than spherical harmonics is required for the diffuse part of the environment. You can set the irradiance texture to rely on a texture instead of the spherical approach. This texture need to have the same characteristics than its parent (Cube vs 2d, coordinates mode, Gamma/Linear, RGBD).

    Parameters

    Returns void

  • get is2DArray(): boolean
  • set is2DArray(value: boolean): void
  • Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.

    Returns boolean

  • Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.

    Parameters

    • value: boolean

    Returns void

  • get is3D(): boolean
  • set is3D(value: boolean): void
  • Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.

    Returns boolean

  • Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.

    Parameters

    • value: boolean

    Returns void

  • 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

  • get isCube(): boolean
  • set isCube(value: boolean): void
  • Define if the texture is a cube texture or if false a 2d texture.

    Returns boolean

  • Define if the texture is a cube texture or if false a 2d texture.

    Parameters

    • value: boolean

    Returns void

  • get isRGBD(): boolean
  • set isRGBD(value: boolean): void
  • Gets or sets whether or not the texture contains RGBD data.

    Returns boolean

  • Gets or sets whether or not the texture contains RGBD data.

    Parameters

    • value: boolean

    Returns void

  • get linearSpecularLOD(): boolean
  • set linearSpecularLOD(value: boolean): void
  • With prefiltered texture, defined if the specular generation is based on a linear ramp. By default we are using a log2 of the linear roughness helping to keep a better resolution for average roughness values.

    Returns boolean

  • With prefiltered texture, defined if the specular generation is based on a linear ramp. By default we are using a log2 of the linear roughness helping to keep a better resolution for average roughness values.

    Parameters

    • value: boolean

    Returns void

  • get loadingError(): boolean
  • Was there any loading error?

    Returns boolean

  • get lodGenerationOffset(): number
  • set lodGenerationOffset(value: number): void
  • With prefiltered texture, defined the offset used during the prefiltering steps.

    Returns number

  • With prefiltered texture, defined the offset used during the prefiltering steps.

    Parameters

    • value: number

    Returns void

  • get lodGenerationScale(): number
  • set lodGenerationScale(value: number): void
  • With prefiltered texture, defined the scale used during the prefiltering steps.

    Returns number

  • With prefiltered texture, defined the scale used during the prefiltering steps.

    Parameters

    • value: number

    Returns void

  • get noMipmap(): boolean
  • Are mip maps generated for this texture or not.

    Returns boolean

  • 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)
        • (): void
        • Returns void

    Returns void

  • get rotationY(): number
  • set rotationY(value: number): void
  • Gets texture matrix rotation angle around Y axis radians.

    Returns number

  • Sets texture matrix rotation angle around Y axis in radians.

    Parameters

    • value: number

    Returns void

  • get samplingMode(): number
  • Get the current sampling mode associated with the texture.

    Returns number

  • get textureFormat(): number
  • Get the texture underlying format (RGB, RGBA...)

    Returns number

  • get textureType(): number
  • Get the texture underlying type (INT, FLOAT...)

    Returns number

  • get uid(): string
  • Define the unique id of the texture in the scene.

    Returns string

  • get wrapU(): number
  • set wrapU(value: number): void
  • ValueTypeDescription
    0CLAMP_ADDRESSMODE
    1WRAP_ADDRESSMODE
    2MIRROR_ADDRESSMODE

    Returns number

  • ValueTypeDescription
    0CLAMP_ADDRESSMODE
    1WRAP_ADDRESSMODE
    2MIRROR_ADDRESSMODE

    Parameters

    • value: number

    Returns void

  • get wrapV(): number
  • set wrapV(value: number): void
  • ValueTypeDescription
    0CLAMP_ADDRESSMODE
    1WRAP_ADDRESSMODE
    2MIRROR_ADDRESSMODE

    Returns number

  • ValueTypeDescription
    0CLAMP_ADDRESSMODE
    1WRAP_ADDRESSMODE
    2MIRROR_ADDRESSMODE

    Parameters

    • value: number

    Returns void

Methods

  • Checks if the texture has the same transform matrix than another texture

    Parameters

    Returns boolean

    true if the transforms are the same, else false

  • Makes a clone, or deep copy, of the cube texture

    Returns CubeTexture

    a new cube texture

  • delayLoad(forcedExtension?: string): void
  • Delays loading of the cube texture

    Parameters

    • Optional forcedExtension: string

      defines the extension to use

    Returns void

  • dispose(): void
  • Dispose the texture and release its associated resources.

    Returns void

  • forceSphericalPolynomialsRecompute(): void
  • Force recomputation of spherical polynomials. Can be useful if you generate a cubemap multiple times (from a probe for eg) and you need the proper polynomials each time

    Returns void

  • Get the base size of the texture. It can be different from the size if the texture has been resized for POT for instance

    Returns ISize

    the base size

  • getClassName(): string
  • Get the current class name of the texture useful for serialization or dynamic coding.

    Returns string

    "CubeTexture"

  • getReflectionTextureMatrix(): Matrix
  • getRefractionTextureMatrix(): Matrix
  • Gets a suitable rotate/transform matrix when the texture is used for refraction. There's a separate function from getReflectionTextureMatrix because refraction requires a special configuration of the matrix in right-handed mode.

    Returns Matrix

    The refraction matrix

  • Get the scene the texture belongs to.

    Returns Nullable<Scene>

    the scene or null if undefined

  • Get the size of the texture.

    Returns ISize

    the texture size.

  • Get the texture transform matrix used to offset tile the texture for instance.

    Returns Matrix

    the transformation matrix

  • isReady(): boolean
  • Get if the texture is ready to be used (downloaded, converted, mip mapped...).

    Returns boolean

    true if fully ready

  • isReadyOrNotBlocking(): boolean
  • Get if the texture is ready to be consumed (either it is ready or it is not blocking)

    Returns boolean

    true if ready, not blocking or if there was an error loading the texture

  • readPixels(faceIndex?: number, level?: number, buffer?: Nullable<ArrayBufferView>, flushRenderer?: boolean, noDataConversion?: boolean, x?: number, y?: number, width?: number, height?: number): Nullable<Promise<ArrayBufferView>>
  • 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.

    Parameters

    • Optional faceIndex: number

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

    • Optional level: number

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

    • Optional buffer: Nullable<ArrayBufferView>

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

    • Optional flushRenderer: boolean

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

    • Optional noDataConversion: boolean

      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

    • Optional x: number

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

    • Optional y: number

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

    • Optional width: number

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

    • Optional height: number

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

    Returns Nullable<Promise<ArrayBufferView>>

    The Array buffer promise containing the pixels data.

  • releaseInternalTexture(): void
  • Release and destroy the underlying lower level texture aka internalTexture.

    Returns void

  • scale(ratio: number): void
  • Scales the texture if is canRescale()

    Parameters

    • ratio: number

      the resize factor we want to use to rescale

    Returns void

  • serialize(allowEmptyName?: boolean): any
  • Serialize the texture into a JSON representation that can be parsed later on.

    Parameters

    • Optional allowEmptyName: boolean

      True to force serialization even if name is empty. Default: false

    Returns any

    the JSON representation of the texture

  • setReflectionTextureMatrix(value: Matrix): void
  • Sets the reflection texture matrix

    Parameters

    • value: Matrix

      Reflection texture matrix

    Returns void

  • toString(): string
  • Return a string representation of the texture.

    Returns string

    the texture as a string

  • updateSamplingMode(samplingMode: number): 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

    Returns void

  • updateURL(url: string, forcedExtension?: string, onLoad?: Nullable<(() => void)>, prefiltered?: boolean, onError?: Nullable<((message?: string, exception?: any) => void)>, extensions?: Nullable<string[]>, delayLoad?: boolean, files?: Nullable<string[]>): void
  • Update the url (and optional buffer) of this texture if url was null during construction.

    Parameters

    • url: string

      the url of the texture

    • Optional forcedExtension: string

      defines the extension to use

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

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

    • Optional prefiltered: boolean

      Defines whether the updated texture is prefiltered or not

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

      callback called if there was an error during the loading process (defaults to null)

    • Optional extensions: Nullable<string[]>

      defines the suffixes add to the picture name in case six images are in use like _px.jpg...

    • Optional delayLoad: boolean

      defines if the texture should be loaded now (false by default)

    • Optional files: Nullable<string[]>

      defines the six files to load for the different faces in that order: px, py, pz, nx, ny, nz

    Returns void

  • CreateFromImages(files: string[], scene: Scene, noMipmap?: boolean): CubeTexture
  • Creates a cube texture from an array of image urls

    Parameters

    • files: string[]

      defines an array of image urls

    • scene: Scene

      defines the hosting scene

    • Optional noMipmap: boolean

      specifies if mip maps are not used

    Returns CubeTexture

    a cube texture

  • CreateFromPrefilteredData(url: string, scene: Scene, forcedExtension?: any, createPolynomials?: boolean): CubeTexture
  • Creates and return a texture created from prefilterd data by tools like IBL Baker or Lys.

    Parameters

    • url: string

      defines the url of the prefiltered texture

    • scene: Scene

      defines the scene the texture is attached to

    • Optional forcedExtension: any

      defines the extension of the file if different from the url

    • Optional createPolynomials: boolean

      defines whether or not to create polynomial harmonics from the texture data if necessary

    Returns CubeTexture

    the prefiltered texture

  • Parses text to create a cube texture

    Parameters

    • parsedTexture: any

      define the serialized text to read from

    • scene: Scene

      defines the hosting scene

    • rootUrl: string

      defines the root url of the cube texture

    Returns CubeTexture

    a cube texture

  • WhenAllReady(textures: BaseTexture[], callback: (() => void)): void
  • Helper function to be called back once a list of texture contains only ready textures.

    Parameters

    • textures: BaseTexture[]

      Define the list of textures to wait for

    • callback: (() => void)

      Define the callback triggered once the entire list will be ready

        • (): void
        • Returns void

    Returns void

Legend

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

Settings

Theme