Protected
Optional
__canvasProtected
__formatProtected
__hasProtected
__heightProtected
Optional
__htmlProtected
Optional
__htmlProtected
Optional
__imgProtected
__internalProtected
__isProtected
__levelProtected
__mipProtected
__nameProtected
__startedProtected
__typeProtected
Optional
__uriProtected
__widthOptional
_recommendedCollection of tags associated with this object
Whether to automatically detect transparency in loaded images
Static
Readonly
InvalidInvalid object UID constant
Static
currentCurrent maximum object count for UID generation
Gets the height of the texture in pixels.
The texture height
Sets the height of the texture in pixels.
The new height value
Gets or creates an HTML canvas element with the texture content. If an image element exists, it will be drawn onto the canvas.
The HTML canvas element containing the texture data
Gets the HTML image element associated with this texture.
The HTML image element or undefined if not available
Checks if the texture is ready for use.
True if the texture is ready, false otherwise
Checks if the texture contains transparent pixels.
True if the texture has transparency, false otherwise
Gets the name of the texture.
The texture name
Sets the name of the texture.
The new texture name
Gets the unique object identifier
The object's UID
Checks if the texture has started loading.
True if loading has started, false otherwise
Gets the unique identifier for this texture.
The unique texture UID
Gets the unique name of this object
The unique name string
Gets the URI/URL of the texture source.
The texture URI or undefined if not set
Gets the width of the texture in pixels.
The texture width
Sets the width of the texture in pixels.
The new width value
Internal
Copies tag data from another RnObject instance to this object
The source RnObject to copy tags from
Allocates an empty texture with specified dimensions and format. The texture can be filled with data later using loadImageToMipLevel.
Texture allocation descriptor
Texture format
Texture height in pixels
Optional
mipNumber of mip levels (auto-calculated if not provided)
Texture width in pixels
Generates a 1x1 pixel texture with a solid color. Useful for creating placeholder textures or solid color materials.
CSS color string in rgba format (default: 'rgba(255,255,255,1)')
Promise that resolves when texture is ready
Generates a compressed texture from raw typed array data.
The compressed texture data
Texture width in pixels
Texture height in pixels
Type of compression used
Promise that resolves when texture is ready
Generates a compressed texture with mipmaps from an array of texture data. Each TextureData object represents a different mip level.
Array of texture data for different mip levels
Type of compression used
Promise that resolves when texture is ready
Error if level 0 texture data is not found
const texture = new Texture();
const mipmapData = [
{ level: 0, width: 512, height: 512, buffer: level0Data },
{ level: 1, width: 256, height: 256, buffer: level1Data },
// ... more levels
];
await texture.generateCompressedTextureWithMipmapFromTypedArray(
mipmapData,
CompressionTextureType.S3TC_DXT1
);
Generates a texture from Basis Universal compressed data. Basis Universal is a supercompressed GPU texture codec that supports multiple formats.
The Basis Universal compressed data
Configuration options for texture generation
Optional
format?: EnumIOPixel format (default: RGBA)
Optional
generateWhether to generate mipmaps (default: true)
Optional
internalInternal texture format (default: RGBA8)
Optional
level?: numberMip level (default: 0)
Optional
type?: ComponentTypeEnumComponent type (default: UnsignedByte)
Promise that resolves when texture is ready
Generates a texture from an HTML image element.
The HTML image element to create texture from
Configuration options for texture generation
Pixel format (default: RGBA)
Whether to generate mipmaps (default: true)
Internal texture format (default: RGBA8)
Mip level (default: 0)
Component type (default: UnsignedByte)
Promise that resolves when texture is ready
Generates a texture from KTX2 compressed data. KTX2 is a container format for GPU textures that supports various compression formats.
The KTX2 compressed data
Promise that resolves when texture is ready
Generates a texture by loading an image from a URL. Supports both regular URLs and data URIs. For external URLs, CORS is handled automatically.
The URL or data URI of the image to load
Configuration options for texture generation
Pixel format (default: RGBA)
Whether to generate mipmaps (default: true)
Internal texture format (default: RGBA8)
Mip level (default: 0)
Component type (default: UnsignedByte)
Promise that resolves when texture is loaded and ready
Retrieves image data from a rectangular region of the texture. Creates an internal canvas context if one doesn't exist.
The x-coordinate of the top-left corner
The y-coordinate of the top-left corner
The width of the region
The height of the region
ImageData object containing the pixel data
Gets a single pixel value at the specified coordinates as a specific type. Supports various color and vector types for different use cases.
The x-coordinate of the pixel
The y-coordinate of the pixel
The class type to return the pixel as (ColorRgb, ColorRgba, Vector3, etc.)
An instance of the specified type containing the pixel data
Gets the pixel data at the specified coordinates as a raw Uint8ClampedArray. This provides direct access to the RGBA values as 8-bit integers.
The x-coordinate of the pixel
The y-coordinate of the pixel
A Uint8ClampedArray containing the RGBA pixel data
Converts the texture data to a TextureDataFloat object with the specified number of channels. This is useful for processing texture data in floating-point format.
The number of channels to include in the output (1-4)
A TextureDataFloat object containing the converted pixel data
Imports an existing WebGL texture directly without copying data. This is useful for integrating with external WebGL code or libraries.
The WebGL texture object to import
Texture width in pixels (default: 0)
Texture height in pixels (default: 0)
Loads image data to a specific mip level of an allocated texture. The texture must be allocated first using the allocate method.
Descriptor containing image data and target location
Promise that resolves when data is loaded
Checks if this object has all the specified tags with exactly matching values
Object containing tag names as keys and expected values
True if all specified tags exist with matching values, false otherwise
Checks if the object's combined tag string contains all the provided search strings. This allows for flexible searching within tag names and values.
Array of strings that must all be present in the combined tag string
True if all strings are found in the combined tag string, false otherwise
Sets a pixel value at the specified coordinates using a color or vector object. Automatically determines the number of components based on the input type.
The x-coordinate of the pixel
The y-coordinate of the pixel
The color or vector value to set
Sets a specific channel value for a pixel at the given coordinates. Useful for modifying individual color channels (R, G, B, A).
The x-coordinate of the pixel
The y-coordinate of the pixel
The channel index (0=R, 1=G, 2=B, 3=A)
The new value for the channel (0-255)
Attempts to set a tag on this object. If the tag already exists, it will be replaced.
The tag object containing the name and value to set
True if the tag was successfully set, false if the tag name contains invalid characters
Attempts to set a unique name for this object
The desired unique name
If true, appends UID to make name unique when conflicts occur; if false, fails on conflict
True if the name was successfully set, false if there was a conflict and toAddNameIfConflict was false
Static
_resetStatic
getStatic
getStatic
loadStatic factory method to create and load a texture from a URL. This is a convenience method that combines texture creation and loading.
The URL or data URI of the image to load
Configuration options for texture generation
Pixel format (default: RGBA)
Whether to generate mipmaps (default: true)
Internal texture format (default: RGBA8)
Mip level (default: 0)
Component type (default: UnsignedByte)
Promise that resolves to the loaded texture
Static
searchSearches for the first object that has a specific tag with the given value
The tag name to search for
The tag value to match
WeakRef to the first matching object, or undefined if not found
A 2D texture class that extends AbstractTexture and provides functionality for creating, loading, and managing textures from various sources including images, compressed formats (Basis, KTX2), and raw data.
This class supports:
Example