UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

67 lines (66 loc) 4.1 kB
import { type ImageSource } from "../../types.js"; import { type Scene } from "../../scene.js"; import { RawTexture2DArray } from "./rawTexture2DArray.js"; /** * These helpers populate 2D array texture layers from decoded image sources. * They rely on the AbstractEngine.updateTextureArrayLayerFromImageSource engine extension, which is * an opt-in side effect. Register it before use by importing the matching module for your backend: * - WebGL2: import "../../Engines/Extensions/engine.texture2DArrayImageSource.js"; * - WebGPU: import "../../Engines/WebGPU/Extensions/engine.texture2DArrayImageSource.js"; * (the full Engine build does not register it by default to keep it out of every engine bundle). * * Consuming the result: the built-in way to sample a chosen layer is Node Material's Texture block, * which exposes a `layer` input (feed it a Float) and samples the array at that layer for you — no * custom shader code required. If you instead write your own shader, declare a `sampler2DArray` * (GLSL) / `texture_2d_array<f32>` (WGSL) uniform and sample it with an explicit integer layer index; * the classic StandardMaterial / PBRMaterial texture slots are plain 2D and cannot read an array layer. */ /** * Options controlling how an image source is uploaded into a 2D array texture layer. */ export interface IUploadImageToTexture2DArrayLayerOptions { /** Defines if the source must be stored with the Y axis inverted (false by default) */ invertY?: boolean; /** Defines if the source alpha must be premultiplied (false by default) */ premultiplyAlpha?: boolean; } /** * Options controlling the creation of a 2D array texture from a list of image urls. */ export interface ICreateTexture2DArrayFromImageUrlsOptions extends IUploadImageToTexture2DArrayLayerOptions { /** Defines if mip levels should be generated (true by default) */ generateMipMaps?: boolean; /** Defines the sampling mode to use (Texture.TRILINEAR_SAMPLINGMODE by default) */ samplingMode?: number; /** Defines the texture type (Constants.TEXTURETYPE_UNSIGNED_BYTE by default) */ textureType?: number; /** Options forwarded to createImageBitmap when decoding each url */ imageBitmapOptions?: ImageBitmapOptions; } /** * Uploads a decoded image source (ImageBitmap, canvas, video, image element...) into a single layer of a 2D array texture. * This is the image-source counterpart to RawTexture2DArray.update, which only accepts raw bytes. * @param texture defines the 2D array texture to upload into * @param source defines the image source to upload * @param layer defines the array layer to upload into * @param options defines optional upload settings (invertY, premultiplyAlpha) */ export declare function UploadImageToTexture2DArrayLayer(texture: RawTexture2DArray, source: ImageSource, layer: number, options?: IUploadImageToTexture2DArrayLayerOptions): void; /** * Fetches an image from a url, decodes it and uploads it into a single layer of a 2D array texture. * @param texture defines the 2D array texture to upload into * @param url defines the url of the image to load * @param layer defines the array layer to upload into * @param options defines optional upload settings (invertY, premultiplyAlpha) * @returns a promise resolved once the layer has been uploaded */ export declare function LoadImageToTexture2DArrayLayerAsync(texture: RawTexture2DArray, url: string, layer: number, options?: IUploadImageToTexture2DArrayLayerOptions): Promise<void>; /** * Creates a 2D array texture and fills each layer from a list of image urls. * All images must share the same dimensions. * @param scene defines the hosting scene * @param urls defines the url of the image for each layer (at least one) * @param options defines optional creation and upload settings * @returns a promise resolved with the created RawTexture2DArray */ export declare function CreateTexture2DArrayFromImageUrlsAsync(scene: Scene, urls: readonly [string, ...string[]], options?: ICreateTexture2DArrayFromImageUrlsOptions): Promise<RawTexture2DArray>;