UNPKG

nanogl-gltf

Version:
103 lines (102 loc) 4.11 kB
import BufferView from './BufferView'; import Gltf2 from '../types/Gltf2'; import GltfLoader from '../io/GltfLoader'; import GltfTypes from '../types/GltfTypes'; import { IElement } from '../types/Elements'; import { AbortSignalLike } from '@azure/abort-controller'; import Texture2D from 'nanogl/texture-2d'; import { GLContext } from 'nanogl/types'; /** * Check if a minFilter mode needs mipmaps. * Returns false if the minFilter is GL_NEAREST or GL_LINEAR. * @param filter Filtering mode to check */ export declare function filterHasMipmap(filter: GLenum): boolean; /** * Check if a wrap mode requires the texture to be a POT (Power Of Two) texture. * Returns true if the wrap mode is GL_REPEAT or GL_MIRRORED_REPEAT. * @param wrap Wrap mode to check */ export declare function wrapRequirePot(wrap: GLenum): boolean; /** * Check if a number is a power of 2, useful for texture resize before GPU upload as GPUs usually prefer POT (Power Of Two) textures. * @param n Number to check */ export declare function isPowerOf2(n: number): boolean; /** * The Image element represents a basic image, contains the image data, used to store textures. * Provides a method to setup a Texture2D with the image data, to be used in a WebGL context. */ export default class Image implements IElement { readonly gltftype: GltfTypes.IMAGE; name: undefined | string; extras: any; /** * URI to the image data, or base64-encoded data URI */ uri?: string; /** * Absolute path to the image data, used for file fetching */ resolvedUri?: string; /** * Image's mimeType (PNG or JPEG) */ mimeType?: Gltf2.ImageMimeType; /** * Associated BufferView element containing the image data, if provided */ bufferView?: BufferView; /** * Image data, ready to be used by a Texture */ texImageSource: TexImageSource; /** * Check if the mimeType is not JPEG, used for texture allocation */ get hasAlpha(): boolean; /** * Parse the Image data, and load the image, storing it in the texImageSource attribute. * If a BufferView is provided, the image data is loaded from it, otherwise it is loaded from the uri. * * Is async as it needs to wait for the image to be loaded by the GLTFLoader. * @param gltfLoader GLTFLoader to use * @param data Data to parse */ parse(gltfLoader: GltfLoader, data: Gltf2.IImage): Promise<any>; /** * Load the image data and stores it in the texImageSource attribute. * * Is async as it needs to wait for the image to be loaded by the GLTFLoader. * @param gltfLoader GLTFLoader to use for loading */ protected loadImage(gltfLoader: GltfLoader): Promise<void>; /** * Load the image data from the uri (external image path or base64-encoded data) or from the provided BufferView, * and return it as a Blob. * * Is async as it needs to wait for the image to be fetched (in case it don't use a BufferView). * @param abortSignal Abort signal for cancellation */ protected loadImageBlob(abortSignal: AbortSignalLike): Promise<Blob>; /** * Setup the provided Texture2D with the image data, with provided wrap and filter modes, by binding it to the GPU. * Called by the Texture element during allocation. * * Is async as it can need to wait for the image to be resized to a POT (Power Of Two) texture. * @param texture Texture to setup * @param wrapS Horizontal texture wrap * @param wrapT Vertical texture wrap * @param minFilter Minification filter * @param magFilter Magnification filter */ setupTexture(texture: Texture2D, wrapS: GLenum, wrapT: GLenum, minFilter: GLenum, magFilter: GLenum): Promise<void>; /** * Resize the provided image to the nearest Power Of Two size. * * Is async as it can need to wait for createImageBitmap. * @param source Image to resize * @param gl GL context, unused here */ resizeToPOT(source: TexImageSource, gl: GLContext): Promise<TexImageSource>; }