baseTexture.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. import { Observable } from "../../Misc/observable";
  2. import type { Nullable } from "../../types";
  3. import type { Scene } from "../../scene";
  4. import { Matrix } from "../../Maths/math.vector";
  5. import type { InternalTexture } from "../../Materials/Textures/internalTexture";
  6. import type { IAnimatable } from "../../Animations/animatable.interface";
  7. import "../../Misc/fileTools";
  8. import type { AbstractEngine } from "../../Engines/abstractEngine";
  9. import { ThinTexture } from "./thinTexture";
  10. import type { AbstractScene } from "../../abstractScene";
  11. import type { Animation } from "../../Animations/animation";
  12. /**
  13. * Base class of all the textures in babylon.
  14. * It groups all the common properties the materials, post process, lights... might need
  15. * in order to make a correct use of the texture.
  16. */
  17. export declare class BaseTexture extends ThinTexture implements IAnimatable {
  18. /**
  19. * Default anisotropic filtering level for the application.
  20. * It is set to 4 as a good tradeoff between perf and quality.
  21. */
  22. static DEFAULT_ANISOTROPIC_FILTERING_LEVEL: number;
  23. /**
  24. * Gets or sets the unique id of the texture
  25. */
  26. uniqueId: number;
  27. /**
  28. * Define the name of the texture.
  29. */
  30. name: string;
  31. /**
  32. * Gets or sets an object used to store user defined information.
  33. */
  34. metadata: any;
  35. /** @internal */
  36. _internalMetadata: any;
  37. /**
  38. * For internal use only. Please do not use.
  39. */
  40. reservedDataStore: any;
  41. private _hasAlpha;
  42. /**
  43. * Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).
  44. */
  45. set hasAlpha(value: boolean);
  46. get hasAlpha(): boolean;
  47. private _getAlphaFromRGB;
  48. /**
  49. * Defines if the alpha value should be determined via the rgb values.
  50. * If true the luminance of the pixel might be used to find the corresponding alpha value.
  51. */
  52. set getAlphaFromRGB(value: boolean);
  53. get getAlphaFromRGB(): boolean;
  54. /**
  55. * Intensity or strength of the texture.
  56. * It is commonly used by materials to fine tune the intensity of the texture
  57. */
  58. level: number;
  59. protected _coordinatesIndex: number;
  60. /**
  61. * Gets or sets a boolean indicating that the texture should try to reduce shader code if there is no UV manipulation.
  62. * (ie. when texture.getTextureMatrix().isIdentityAs3x2() returns true)
  63. */
  64. optimizeUVAllocation: boolean;
  65. /**
  66. * Define the UV channel to use starting from 0 and defaulting to 0.
  67. * This is part of the texture as textures usually maps to one uv set.
  68. */
  69. set coordinatesIndex(value: number);
  70. get coordinatesIndex(): number;
  71. protected _coordinatesMode: number;
  72. /**
  73. * How a texture is mapped.
  74. *
  75. * | Value | Type | Description |
  76. * | ----- | ----------------------------------- | ----------- |
  77. * | 0 | EXPLICIT_MODE | |
  78. * | 1 | SPHERICAL_MODE | |
  79. * | 2 | PLANAR_MODE | |
  80. * | 3 | CUBIC_MODE | |
  81. * | 4 | PROJECTION_MODE | |
  82. * | 5 | SKYBOX_MODE | |
  83. * | 6 | INVCUBIC_MODE | |
  84. * | 7 | EQUIRECTANGULAR_MODE | |
  85. * | 8 | FIXED_EQUIRECTANGULAR_MODE | |
  86. * | 9 | FIXED_EQUIRECTANGULAR_MIRRORED_MODE | |
  87. */
  88. set coordinatesMode(value: number);
  89. get coordinatesMode(): number;
  90. /**
  91. * | Value | Type | Description |
  92. * | ----- | ------------------ | ----------- |
  93. * | 0 | CLAMP_ADDRESSMODE | |
  94. * | 1 | WRAP_ADDRESSMODE | |
  95. * | 2 | MIRROR_ADDRESSMODE | |
  96. */
  97. get wrapU(): number;
  98. set wrapU(value: number);
  99. /**
  100. * | Value | Type | Description |
  101. * | ----- | ------------------ | ----------- |
  102. * | 0 | CLAMP_ADDRESSMODE | |
  103. * | 1 | WRAP_ADDRESSMODE | |
  104. * | 2 | MIRROR_ADDRESSMODE | |
  105. */
  106. get wrapV(): number;
  107. set wrapV(value: number);
  108. /**
  109. * | Value | Type | Description |
  110. * | ----- | ------------------ | ----------- |
  111. * | 0 | CLAMP_ADDRESSMODE | |
  112. * | 1 | WRAP_ADDRESSMODE | |
  113. * | 2 | MIRROR_ADDRESSMODE | |
  114. */
  115. wrapR: number;
  116. /**
  117. * With compliant hardware and browser (supporting anisotropic filtering)
  118. * this defines the level of anisotropic filtering in the texture.
  119. * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.
  120. */
  121. anisotropicFilteringLevel: number;
  122. /** @internal */
  123. _isCube: boolean;
  124. /**
  125. * Define if the texture is a cube texture or if false a 2d texture.
  126. */
  127. get isCube(): boolean;
  128. protected set isCube(value: boolean);
  129. /**
  130. * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.
  131. */
  132. get is3D(): boolean;
  133. protected set is3D(value: boolean);
  134. /**
  135. * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.
  136. */
  137. get is2DArray(): boolean;
  138. protected set is2DArray(value: boolean);
  139. /** @internal */
  140. protected _gammaSpace: boolean;
  141. /**
  142. * Define if the texture contains data in gamma space (most of the png/jpg aside bump).
  143. * HDR texture are usually stored in linear space.
  144. * This only impacts the PBR and Background materials
  145. */
  146. get gammaSpace(): boolean;
  147. set gammaSpace(gamma: boolean);
  148. /**
  149. * Gets or sets whether or not the texture contains RGBD data.
  150. */
  151. get isRGBD(): boolean;
  152. set isRGBD(value: boolean);
  153. /**
  154. * Is Z inverted in the texture (useful in a cube texture).
  155. */
  156. invertZ: boolean;
  157. /**
  158. * Are mip maps generated for this texture or not.
  159. */
  160. get noMipmap(): boolean;
  161. /**
  162. * @internal
  163. */
  164. lodLevelInAlpha: boolean;
  165. /**
  166. * With prefiltered texture, defined the offset used during the prefiltering steps.
  167. */
  168. get lodGenerationOffset(): number;
  169. set lodGenerationOffset(value: number);
  170. /**
  171. * With prefiltered texture, defined the scale used during the prefiltering steps.
  172. */
  173. get lodGenerationScale(): number;
  174. set lodGenerationScale(value: number);
  175. /**
  176. * With prefiltered texture, defined if the specular generation is based on a linear ramp.
  177. * By default we are using a log2 of the linear roughness helping to keep a better resolution for
  178. * average roughness values.
  179. */
  180. get linearSpecularLOD(): boolean;
  181. set linearSpecularLOD(value: boolean);
  182. /**
  183. * In case a better definition than spherical harmonics is required for the diffuse part of the environment.
  184. * You can set the irradiance texture to rely on a texture instead of the spherical approach.
  185. * This texture need to have the same characteristics than its parent (Cube vs 2d, coordinates mode, Gamma/Linear, RGBD).
  186. */
  187. get irradianceTexture(): Nullable<BaseTexture>;
  188. set irradianceTexture(value: Nullable<BaseTexture>);
  189. /**
  190. * Define if the texture is a render target.
  191. */
  192. isRenderTarget: boolean;
  193. /**
  194. * Define the unique id of the texture in the scene.
  195. */
  196. get uid(): string;
  197. /** @internal */
  198. _prefiltered: boolean;
  199. /** @internal */
  200. _forceSerialize: boolean;
  201. /**
  202. * Return a string representation of the texture.
  203. * @returns the texture as a string
  204. */
  205. toString(): string;
  206. /**
  207. * Get the class name of the texture.
  208. * @returns "BaseTexture"
  209. */
  210. getClassName(): string;
  211. /**
  212. * Define the list of animation attached to the texture.
  213. */
  214. animations: Animation[];
  215. /**
  216. * An event triggered when the texture is disposed.
  217. */
  218. onDisposeObservable: Observable<BaseTexture>;
  219. private _onDisposeObserver;
  220. /**
  221. * Callback triggered when the texture has been disposed.
  222. * Kept for back compatibility, you can use the onDisposeObservable instead.
  223. */
  224. set onDispose(callback: () => void);
  225. protected _scene: Nullable<Scene>;
  226. /** @internal */
  227. private _uid;
  228. /**
  229. * Define if the texture is preventing a material to render or not.
  230. * If not and the texture is not ready, the engine will use a default black texture instead.
  231. */
  232. get isBlocking(): boolean;
  233. /** @internal */
  234. _parentContainer: Nullable<AbstractScene>;
  235. protected _loadingError: boolean;
  236. protected _errorObject?: {
  237. message?: string;
  238. exception?: any;
  239. };
  240. /**
  241. * Was there any loading error?
  242. */
  243. get loadingError(): boolean;
  244. /**
  245. * If a loading error occurred this object will be populated with information about the error.
  246. */
  247. get errorObject(): {
  248. message?: string;
  249. exception?: any;
  250. } | undefined;
  251. /**
  252. * Instantiates a new BaseTexture.
  253. * Base class of all the textures in babylon.
  254. * It groups all the common properties the materials, post process, lights... might need
  255. * in order to make a correct use of the texture.
  256. * @param sceneOrEngine Define the scene or engine the texture belongs to
  257. * @param internalTexture Define the internal texture associated with the texture
  258. */
  259. constructor(sceneOrEngine?: Nullable<Scene | AbstractEngine>, internalTexture?: Nullable<InternalTexture>);
  260. /**
  261. * Get the scene the texture belongs to.
  262. * @returns the scene or null if undefined
  263. */
  264. getScene(): Nullable<Scene>;
  265. /** @internal */
  266. protected _getEngine(): Nullable<AbstractEngine>;
  267. /**
  268. * Get the texture transform matrix used to offset tile the texture for instance.
  269. * @returns the transformation matrix
  270. */
  271. getTextureMatrix(): Matrix;
  272. /**
  273. * Get the texture reflection matrix used to rotate/transform the reflection.
  274. * @returns the reflection matrix
  275. */
  276. getReflectionTextureMatrix(): Matrix;
  277. /**
  278. * Gets a suitable rotate/transform matrix when the texture is used for refraction.
  279. * There's a separate function from getReflectionTextureMatrix because refraction requires a special configuration of the matrix in right-handed mode.
  280. * @returns The refraction matrix
  281. */
  282. getRefractionTextureMatrix(): Matrix;
  283. /**
  284. * Get if the texture is ready to be consumed (either it is ready or it is not blocking)
  285. * @returns true if ready, not blocking or if there was an error loading the texture
  286. */
  287. isReadyOrNotBlocking(): boolean;
  288. /**
  289. * Scales the texture if is `canRescale()`
  290. * @param ratio the resize factor we want to use to rescale
  291. */
  292. scale(ratio: number): void;
  293. /**
  294. * Get if the texture can rescale.
  295. */
  296. get canRescale(): boolean;
  297. /**
  298. * @internal
  299. */
  300. _getFromCache(url: Nullable<string>, noMipmap: boolean, sampling?: number, invertY?: boolean, useSRGBBuffer?: boolean, isCube?: boolean): Nullable<InternalTexture>;
  301. /** @internal */
  302. _rebuild(_fromContextLost?: boolean): void;
  303. /**
  304. * Clones the texture.
  305. * @returns the cloned texture
  306. */
  307. clone(): Nullable<BaseTexture>;
  308. /**
  309. * Get the texture underlying type (INT, FLOAT...)
  310. */
  311. get textureType(): number;
  312. /**
  313. * Get the texture underlying format (RGB, RGBA...)
  314. */
  315. get textureFormat(): number;
  316. /**
  317. * Indicates that textures need to be re-calculated for all materials
  318. */
  319. protected _markAllSubMeshesAsTexturesDirty(): void;
  320. /**
  321. * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.
  322. * This will returns an RGBA array buffer containing either in values (0-255) or
  323. * float values (0-1) depending of the underlying buffer type.
  324. * @param faceIndex defines the face of the texture to read (in case of cube texture)
  325. * @param level defines the LOD level of the texture to read (in case of Mip Maps)
  326. * @param buffer defines a user defined buffer to fill with data (can be null)
  327. * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
  328. * @param noDataConversion false to convert the data to Uint8Array (if texture type is UNSIGNED_BYTE) or to Float32Array (if texture type is anything but UNSIGNED_BYTE). If true, the type of the generated buffer (if buffer==null) will depend on the type of the texture
  329. * @param x defines the region x coordinates to start reading from (default to 0)
  330. * @param y defines the region y coordinates to start reading from (default to 0)
  331. * @param width defines the region width to read from (default to the texture size at level)
  332. * @param height defines the region width to read from (default to the texture size at level)
  333. * @returns The Array buffer promise containing the pixels data.
  334. */
  335. readPixels(faceIndex?: number, level?: number, buffer?: Nullable<ArrayBufferView>, flushRenderer?: boolean, noDataConversion?: boolean, x?: number, y?: number, width?: number, height?: number): Nullable<Promise<ArrayBufferView>>;
  336. /**
  337. * @internal
  338. */
  339. _readPixelsSync(faceIndex?: number, level?: number, buffer?: Nullable<ArrayBufferView>, flushRenderer?: boolean, noDataConversion?: boolean): Nullable<ArrayBufferView>;
  340. /** @internal */
  341. get _lodTextureHigh(): Nullable<BaseTexture>;
  342. /** @internal */
  343. get _lodTextureMid(): Nullable<BaseTexture>;
  344. /** @internal */
  345. get _lodTextureLow(): Nullable<BaseTexture>;
  346. /**
  347. * Dispose the texture and release its associated resources.
  348. */
  349. dispose(): void;
  350. /**
  351. * Serialize the texture into a JSON representation that can be parsed later on.
  352. * @param allowEmptyName True to force serialization even if name is empty. Default: false
  353. * @returns the JSON representation of the texture
  354. */
  355. serialize(allowEmptyName?: boolean): any;
  356. /**
  357. * Helper function to be called back once a list of texture contains only ready textures.
  358. * @param textures Define the list of textures to wait for
  359. * @param callback Define the callback triggered once the entire list will be ready
  360. */
  361. static WhenAllReady(textures: BaseTexture[], callback: () => void): void;
  362. private static _IsScene;
  363. }