import type { Size, TypedArray } from '../../types/CommonTypes'; import { type HdriFormatEnum } from '../definitions/HdriFormat'; import type { Engine } from '../system/Engine'; import { AbstractTexture } from './AbstractTexture'; /** * A cube texture class that represents a cubemap texture for 3D rendering. * Cube textures are commonly used for environment mapping, skyboxes, and reflection mapping. * This class extends AbstractTexture and provides functionality to load cube textures from various sources * including files, Basis compressed textures, and typed arrays. * * @example * ```typescript * // Load cube texture from files * const cubeTexture = await CubeTexture.loadFromUrl({ * baseUrl: 'path/to/cubemap', * mipmapLevelNumber: 1, * isNamePosNeg: true, * hdriFormat: HdriFormat.LDR_SRGB * }); * * // Create a simple 1x1 cube texture * const simpleCube = new CubeTexture(); * simpleCube.load1x1Texture('rgba(255,0,0,1)'); * ``` */ export declare class CubeTexture extends AbstractTexture implements Disposable { /** The number of mipmap levels for this cube texture */ mipmapLevelNumber: number; /** The HDRI format used for this cube texture */ hdriFormat: import("..").EnumIO; /** * Registry for automatic cleanup of cube texture resources when objects are garbage collected. * This helps prevent memory leaks by automatically releasing WebGL/WebGPU resources. */ private static managedRegistry; /** * Sets the texture resource UID and registers the texture for automatic cleanup. * This is an internal method used by the loading methods. * * @param textureResourceUid - The unique identifier for the texture resource * @param uniqueName - A unique name for the texture used in logging * @private */ private __setTextureResourceUid; /** * Loads cube texture images from files asynchronously. * This method loads six cube faces from image files and creates a cube texture. * * @param options - Configuration options for loading the cube texture * @param options.baseUrl - Base URL path to the cube texture files * @param options.mipmapLevelNumber - Number of mipmap levels to generate * @param options.isNamePosNeg - Whether to use positive/negative naming convention (posX, negX, etc.) * @param options.hdriFormat - The HDRI format to use for the texture * * @example * ```typescript * const cubeTexture = new CubeTexture(); * await cubeTexture.loadTextureImages({ * baseUrl: 'textures/skybox', * mipmapLevelNumber: 1, * isNamePosNeg: true, * hdriFormat: HdriFormat.LDR_SRGB * }); * ``` */ loadTextureImages({ baseUrl, mipmapLevelNumber, isNamePosNeg, hdriFormat, }: { baseUrl: string; mipmapLevelNumber: number; isNamePosNeg: boolean; hdriFormat: HdriFormatEnum; }): Promise; /** * Loads cube texture from Basis compressed texture data. * Basis is a universal texture compression format that can be transcoded to various GPU formats. * * @param uint8Array - The Basis compressed texture data as a Uint8Array * @param options - Optional texture parameters for filtering and wrapping * @param options.magFilter - Magnification filter (default: Linear) * @param options.minFilter - Minification filter (default: LinearMipmapLinear) * @param options.wrapS - Texture wrapping mode for S coordinate (default: Repeat) * @param options.wrapT - Texture wrapping mode for T coordinate (default: Repeat) * * @throws Will log an error if BASIS transcoder is not available * * @example * ```typescript * const cubeTexture = new CubeTexture(); * const basisData = new Uint8Array(basisFileBuffer); * cubeTexture.loadTextureImagesFromBasis(basisData, { * magFilter: TextureParameter.Linear, * minFilter: TextureParameter.LinearMipmapLinear * }); * ``` */ loadTextureImagesFromBasis(uint8Array: Uint8Array, { magFilter, minFilter, wrapS, wrapT, }?: { magFilter?: import("..").TextureParameterEnum | undefined; minFilter?: import("..").TextureParameterEnum | undefined; wrapS?: import("..").TextureParameterEnum | undefined; wrapT?: import("..").TextureParameterEnum | undefined; }): void; /** * Creates a simple 1x1 pixel cube texture with a solid color. * This is useful for creating placeholder textures or solid color cube maps. * * @param rgbaStr - CSS color string in rgba format (default: 'rgba(0,0,0,1)' for black) * * @example * ```typescript * const cubeTexture = new CubeTexture(); * cubeTexture.load1x1Texture('rgba(255,255,255,1)'); // White cube texture * cubeTexture.load1x1Texture('rgba(0,128,255,1)'); // Blue cube texture * ``` */ load1x1Texture(rgbaStr?: string): void; /** * Generates a cube texture from typed arrays containing raw image data. * This method allows creating cube textures from pre-processed image data with multiple mipmap levels. * * @param typedArrayImages - Array of typed array objects for cubemap textures. * Each element represents a mipmap level (index 0 is the base level). * Each object contains six faces: posX, negX, posY, negY, posZ, negZ. * @param baseLevelWidth - Width of the base level texture (mipmap level 0) * @param baseLevelHeight - Height of the base level texture (mipmap level 0) * * @example * ```typescript * const cubeTexture = new CubeTexture(); * const imageData = [{ * posX: new Uint8Array(imageDataPosX), * negX: new Uint8Array(imageDataNegX), * posY: new Uint8Array(imageDataPosY), * negY: new Uint8Array(imageDataNegY), * posZ: new Uint8Array(imageDataPosZ), * negZ: new Uint8Array(imageDataNegZ) * }]; * cubeTexture.generateTextureFromTypedArrays(imageData, 512, 512); * ``` */ generateTextureFromTypedArrays(typedArrayImages: Array<{ posX: TypedArray; negX: TypedArray; posY: TypedArray; negY: TypedArray; posZ: TypedArray; negZ: TypedArray; }>, baseLevelWidth: Size, baseLevelHeight: Size): void; /** * Imports an existing WebGL texture directly into this CubeTexture instance. * This method allows wrapping existing WebGL textures without creating new ones. * * @param webGLTexture - The existing WebGL texture object to import * @param width - Optional width of the texture (default: 0) * @param height - Optional height of the texture (default: 0) * * @example * ```typescript * const cubeTexture = new CubeTexture(); * const existingTexture = gl.createTexture(); // Assume this is configured * cubeTexture.importWebGLTextureDirectly(existingTexture, 512, 512); * ``` */ importWebGLTextureDirectly(webGLTexture: WebGLTexture, width?: number, height?: number): void; /** * Deletes the internal texture resource from the graphics API. * This is a static utility method used internally for cleanup. * * @param engine - The engine instance * @param textureResourceUid - The unique identifier of the texture resource to delete * @private */ private static __deleteInternalTexture; /** * Destroys the 3D API resources associated with this cube texture. * This method releases the texture from GPU memory and resets the texture state. * After calling this method, the texture cannot be used for rendering until reloaded. */ destroy3DAPIResources(): void; /** * Implements the Disposable interface for automatic resource cleanup. * This method is called when using the 'using' statement in TypeScript. * * @example * ```typescript * using cubeTexture = new CubeTexture(); * // Texture will be automatically disposed when going out of scope * ``` */ [Symbol.dispose](): void; /** * Retrieves the pixel data from a specific face of the cube texture. * This operation reads back the texture data from GPU memory to CPU memory. * * @param faceIndex - Index of the cube face (0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z) * @returns A promise that resolves to a Uint8Array containing the RGBA pixel data * * @example * ```typescript * const cubeTexture = new CubeTexture(engine); * // ... load texture ... * const posXData = await cubeTexture.getCubeFacePixelData(0); // Get +X face * const negYData = await cubeTexture.getCubeFacePixelData(3); // Get -Y face * ``` */ getCubeFacePixelData(faceIndex: number): Promise; /** * Retrieves the pixel data from all six faces of the cube texture. * This operation reads back all face data from GPU memory to CPU memory. * * @returns A promise that resolves to an object containing Uint8Arrays for each face * * @example * ```typescript * const cubeTexture = new CubeTexture(engine); * // ... load texture ... * const allFaces = await cubeTexture.getAllCubeFacePixelData(); * console.log(allFaces.posX); // +X face data * console.log(allFaces.negZ); // -Z face data * ``` */ getAllCubeFacePixelData(): Promise<{ posX: Uint8Array; negX: Uint8Array; posY: Uint8Array; negY: Uint8Array; posZ: Uint8Array; negZ: Uint8Array; }>; /** * Completely destroys this cube texture and releases all associated resources. * This method should be called when the texture is no longer needed to prevent memory leaks. * After calling destroy(), this texture instance should not be used. */ destroy(): void; /** * Static factory method to create and load a cube texture from URL in one step. * This is a convenience method that combines instantiation and loading. * * @param options - Configuration options for loading the cube texture * @param options.baseUrl - Base URL path to the cube texture files * @param options.mipmapLevelNumber - Number of mipmap levels to generate * @param options.isNamePosNeg - Whether to use positive/negative naming convention * @param options.hdriFormat - The HDRI format to use for the texture * @returns Promise that resolves to a loaded CubeTexture instance * * @example * ```typescript * const cubeTexture = await CubeTexture.loadFromUrl({ * baseUrl: 'assets/skybox/sunset', * mipmapLevelNumber: 1, * isNamePosNeg: true, * hdriFormat: HdriFormat.RGBE_PNG * }); * ``` */ static loadFromUrl(engine: Engine, { baseUrl, mipmapLevelNumber, isNamePosNeg, hdriFormat, }: { baseUrl: string; mipmapLevelNumber: number; isNamePosNeg: boolean; hdriFormat: HdriFormatEnum; }): Promise; }