import { type BasisMode } from './basis'; import type { ModelImage } from './model'; import { type MipChain } from './mips'; /** * Texture handling for item-lod/1. A level texture is never larger than the source image it came from by construction: * - a source image whose longest edge is already within the level's cap is reused byte for byte; * - a larger one is resampled (Lanczos) to the cap and encoded as KTX2, choosing per texture between ETC1S, RDO-tuned * UASTC and plain UASTC: the smallest whose decoded pixels stay above a PSNR floor (plain UASTC is always acceptable), * unless that is larger than the source image, in which case a coarser encode above a lower PSNR minimum wins. */ export declare const ITEM_LOD_MAX_SOURCE_PIXELS: number; /** Decoded-vs-resampled PSNR (dB) a lossy candidate must reach. Colour maps hide more error than normal, roughness and occlusion maps. */ export declare const PSNR_FLOOR: { readonly color: 30; readonly data: 34; }; /** Lowest PSNR accepted when the only way to keep a texture no larger than its source is a coarser encode. */ export declare const PSNR_MINIMUM: { readonly color: 25; readonly data: 30; }; export interface DecodedImage { data: Uint8Array; width: number; height: number; } /** * The edge lengths a texture is resampled to: scaled so its longest edge is at most `maxEdge`, then each edge snapped to * the nearest power of two (never above `maxEdge`) so mip chains and block compression stay clean on every GPU. */ export declare function levelTextureSize(width: number, height: number, maxEdge: number): { width: number; height: number; }; /** Pixel size of an encoded image without decoding it (KTX2 header, else the image header). */ export declare function imageSize(image: ModelImage): Promise<{ width: number; height: number; }>; /** RGBA pixels resampled for a level (Lanczos). */ export declare function resampleImage(image: ModelImage, maxEdge: number): Promise; /** How a level texture came to be: the source bytes untouched, or one of the three Basis modes. */ export type TextureMethod = 'reused' | BasisMode; export interface EncodedTexture { bytes: Uint8Array; width: number; height: number; mimeType: 'image/ktx2' | 'image/png' | 'image/jpeg' | 'image/webp'; method: TextureMethod; /** Source image bytes, to show what the level texture cost against what it replaced. */ sourceBytes: number; /** Decoded-vs-resampled PSNR for a lossy Basis encode; null when the source bytes were reused. */ psnr: number | null; } /** * Encodes RGBA pixels as the smallest acceptable KTX2: ETC1S, then RDO UASTC, then plain UASTC, each only if its decoded pixels * clear the PSNR floor. `limitBytes` is what the texture must not exceed (the image or images it replaces); when the acceptable * encoding is larger, the smallest lossy candidate that is within the limit and clears the minimum wins. A limit of 0 means * there is nothing to compare against (an atlas of factor swatches) and the rule does not apply. `weights` (one per pixel) turns the * PSNR into a surface-weighted one (see `basisPsnr`). */ export declare function encodeLevelPixels(pixels: DecodedImage, color: boolean, limitBytes: number, weights?: Float32Array): Promise; /** Per-compile cache so a texture shared by several materials, or by LOD1 and the capture, is resampled once. */ export declare class TextureCache { private readonly encoded; private readonly means; private readonly chains; private readonly sizes; /** Decoded RGBA pixels with a mip chain, shared by every atlas bake of this compile. */ mips(image: ModelImage): Promise; size(image: ModelImage): Promise<{ width: number; height: number; }>; /** * The texture for a level whose longest edge may not exceed `maxEdge`. Reuses the source bytes when they already fit; * otherwise downscales and keeps the smallest KTX2 candidate that holds its PSNR floor. */ level(image: ModelImage, maxEdge: number, color: boolean): Promise; /** Plain PNG for the impostor capture page (the page needs no Basis transcoder for it). */ png(image: ModelImage, maxEdge: number): Promise; /** Mean RGBA (0..1) of a texture; used to fold a dropped metallic-roughness map into the material's factors. */ mean(image: ModelImage): Promise<[number, number, number, number]>; } /** * GPU-resident size of a level texture with its mip chain: a Basis file transcodes to a 1 byte per texel block format * (BC7/ASTC), an image decoded by the browser is RGBA8. */ export declare function residentTextureBytes(width: number, height: number, compressed?: boolean): number;