baseTexture.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. import { serialize, SerializationHelper } from "../../Misc/decorators";
  2. import { Observer, Observable } from "../../Misc/observable";
  3. import { Tools, IAnimatable } from "../../Misc/tools";
  4. import { CubeMapToSphericalPolynomialTools } from "../../Misc/HighDynamicRange/cubemapToSphericalPolynomial";
  5. import { Nullable } from "../../types";
  6. import { Scene } from "../../scene";
  7. import { Matrix, Size, ISize } from "../../Maths/math";
  8. import { SphericalPolynomial } from "../../Maths/sphericalPolynomial";
  9. import { EngineStore } from "../../Engines/engineStore";
  10. import { InternalTexture } from "../../Materials/Textures/internalTexture";
  11. import { _TimeToken } from "../../Instrumentation/timeToken";
  12. import { _DepthCullingState, _StencilState, _AlphaState } from "../../States/index";
  13. import { Constants } from "../../Engines/constants";
  14. declare type Animation = import("../../Animations/animation").Animation;
  15. /**
  16. * Base class of all the textures in babylon.
  17. * It groups all the common properties the materials, post process, lights... might need
  18. * in order to make a correct use of the texture.
  19. */
  20. export class BaseTexture implements IAnimatable {
  21. /**
  22. * Default anisotropic filtering level for the application.
  23. * It is set to 4 as a good tradeoff between perf and quality.
  24. */
  25. public static DEFAULT_ANISOTROPIC_FILTERING_LEVEL = 4;
  26. /**
  27. * Gets or sets the unique id of the texture
  28. */
  29. @serialize()
  30. public uniqueId: number;
  31. /**
  32. * Define the name of the texture.
  33. */
  34. @serialize()
  35. public name: string;
  36. /**
  37. * Gets or sets an object used to store user defined information.
  38. */
  39. @serialize()
  40. public metadata: any = null;
  41. /**
  42. * For internal use only. Please do not use.
  43. */
  44. public reservedDataStore: any = null;
  45. @serialize("hasAlpha")
  46. private _hasAlpha = false;
  47. /**
  48. * Define if the texture is having a usable alpha value (can be use for transparency or glossiness for instance).
  49. */
  50. public set hasAlpha(value: boolean) {
  51. if (this._hasAlpha === value) {
  52. return;
  53. }
  54. this._hasAlpha = value;
  55. if (this._scene) {
  56. this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag | Constants.MATERIAL_MiscDirtyFlag);
  57. }
  58. }
  59. public get hasAlpha(): boolean {
  60. return this._hasAlpha;
  61. }
  62. /**
  63. * Defines if the alpha value should be determined via the rgb values.
  64. * If true the luminance of the pixel might be used to find the corresponding alpha value.
  65. */
  66. @serialize()
  67. public getAlphaFromRGB = false;
  68. /**
  69. * Intensity or strength of the texture.
  70. * It is commonly used by materials to fine tune the intensity of the texture
  71. */
  72. @serialize()
  73. public level = 1;
  74. /**
  75. * Define the UV chanel to use starting from 0 and defaulting to 0.
  76. * This is part of the texture as textures usually maps to one uv set.
  77. */
  78. @serialize()
  79. public coordinatesIndex = 0;
  80. @serialize("coordinatesMode")
  81. private _coordinatesMode = Constants.TEXTURE_EXPLICIT_MODE;
  82. /**
  83. * How a texture is mapped.
  84. *
  85. * | Value | Type | Description |
  86. * | ----- | ----------------------------------- | ----------- |
  87. * | 0 | EXPLICIT_MODE | |
  88. * | 1 | SPHERICAL_MODE | |
  89. * | 2 | PLANAR_MODE | |
  90. * | 3 | CUBIC_MODE | |
  91. * | 4 | PROJECTION_MODE | |
  92. * | 5 | SKYBOX_MODE | |
  93. * | 6 | INVCUBIC_MODE | |
  94. * | 7 | EQUIRECTANGULAR_MODE | |
  95. * | 8 | FIXED_EQUIRECTANGULAR_MODE | |
  96. * | 9 | FIXED_EQUIRECTANGULAR_MIRRORED_MODE | |
  97. */
  98. public set coordinatesMode(value: number) {
  99. if (this._coordinatesMode === value) {
  100. return;
  101. }
  102. this._coordinatesMode = value;
  103. if (this._scene) {
  104. this._scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
  105. }
  106. }
  107. public get coordinatesMode(): number {
  108. return this._coordinatesMode;
  109. }
  110. /**
  111. * | Value | Type | Description |
  112. * | ----- | ------------------ | ----------- |
  113. * | 0 | CLAMP_ADDRESSMODE | |
  114. * | 1 | WRAP_ADDRESSMODE | |
  115. * | 2 | MIRROR_ADDRESSMODE | |
  116. */
  117. @serialize()
  118. public wrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;
  119. /**
  120. * | Value | Type | Description |
  121. * | ----- | ------------------ | ----------- |
  122. * | 0 | CLAMP_ADDRESSMODE | |
  123. * | 1 | WRAP_ADDRESSMODE | |
  124. * | 2 | MIRROR_ADDRESSMODE | |
  125. */
  126. @serialize()
  127. public wrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;
  128. /**
  129. * | Value | Type | Description |
  130. * | ----- | ------------------ | ----------- |
  131. * | 0 | CLAMP_ADDRESSMODE | |
  132. * | 1 | WRAP_ADDRESSMODE | |
  133. * | 2 | MIRROR_ADDRESSMODE | |
  134. */
  135. @serialize()
  136. public wrapR = Constants.TEXTURE_WRAP_ADDRESSMODE;
  137. /**
  138. * With compliant hardware and browser (supporting anisotropic filtering)
  139. * this defines the level of anisotropic filtering in the texture.
  140. * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.
  141. */
  142. @serialize()
  143. public anisotropicFilteringLevel = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL;
  144. /**
  145. * Define if the texture is a cube texture or if false a 2d texture.
  146. */
  147. @serialize()
  148. public get isCube(): boolean {
  149. if (!this._texture) {
  150. return false;
  151. }
  152. return this._texture.isCube;
  153. }
  154. public set isCube(value: boolean) {
  155. if (!this._texture) {
  156. return;
  157. }
  158. this._texture.isCube = value;
  159. }
  160. /**
  161. * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.
  162. */
  163. @serialize()
  164. public get is3D(): boolean {
  165. if (!this._texture) {
  166. return false;
  167. }
  168. return this._texture.is3D;
  169. }
  170. public set is3D(value: boolean) {
  171. if (!this._texture) {
  172. return;
  173. }
  174. this._texture.is3D = value;
  175. }
  176. /**
  177. * Define if the texture contains data in gamma space (most of the png/jpg aside bump).
  178. * HDR texture are usually stored in linear space.
  179. * This only impacts the PBR and Background materials
  180. */
  181. @serialize()
  182. public gammaSpace = true;
  183. /**
  184. * Gets whether or not the texture contains RGBD data.
  185. */
  186. public get isRGBD(): boolean {
  187. return this._texture != null && this._texture._isRGBD;
  188. }
  189. /**
  190. * Is Z inverted in the texture (useful in a cube texture).
  191. */
  192. @serialize()
  193. public invertZ = false;
  194. /**
  195. * Are mip maps generated for this texture or not.
  196. */
  197. public get noMipmap(): boolean {
  198. return false;
  199. }
  200. /**
  201. * @hidden
  202. */
  203. @serialize()
  204. public lodLevelInAlpha = false;
  205. /**
  206. * With prefiltered texture, defined the offset used during the prefiltering steps.
  207. */
  208. @serialize()
  209. public get lodGenerationOffset(): number {
  210. if (this._texture) { return this._texture._lodGenerationOffset; }
  211. return 0.0;
  212. }
  213. public set lodGenerationOffset(value: number) {
  214. if (this._texture) { this._texture._lodGenerationOffset = value; }
  215. }
  216. /**
  217. * With prefiltered texture, defined the scale used during the prefiltering steps.
  218. */
  219. @serialize()
  220. public get lodGenerationScale(): number {
  221. if (this._texture) { return this._texture._lodGenerationScale; }
  222. return 0.0;
  223. }
  224. public set lodGenerationScale(value: number) {
  225. if (this._texture) { this._texture._lodGenerationScale = value; }
  226. }
  227. /**
  228. * Define if the texture is a render target.
  229. */
  230. @serialize()
  231. public isRenderTarget = false;
  232. /**
  233. * Define the unique id of the texture in the scene.
  234. */
  235. public get uid(): string {
  236. if (!this._uid) {
  237. this._uid = Tools.RandomId();
  238. }
  239. return this._uid;
  240. }
  241. /**
  242. * Return a string representation of the texture.
  243. * @returns the texture as a string
  244. */
  245. public toString(): string {
  246. return this.name;
  247. }
  248. /**
  249. * Get the class name of the texture.
  250. * @returns "BaseTexture"
  251. */
  252. public getClassName(): string {
  253. return "BaseTexture";
  254. }
  255. /**
  256. * Define the list of animation attached to the texture.
  257. */
  258. public animations = new Array<Animation>();
  259. /**
  260. * An event triggered when the texture is disposed.
  261. */
  262. public onDisposeObservable = new Observable<BaseTexture>();
  263. private _onDisposeObserver: Nullable<Observer<BaseTexture>>;
  264. /**
  265. * Callback triggered when the texture has been disposed.
  266. * Kept for back compatibility, you can use the onDisposeObservable instead.
  267. */
  268. public set onDispose(callback: () => void) {
  269. if (this._onDisposeObserver) {
  270. this.onDisposeObservable.remove(this._onDisposeObserver);
  271. }
  272. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  273. }
  274. /**
  275. * Define the current state of the loading sequence when in delayed load mode.
  276. */
  277. public delayLoadState = Constants.DELAYLOADSTATE_NONE;
  278. private _scene: Nullable<Scene>;
  279. /** @hidden */
  280. public _texture: Nullable<InternalTexture>;
  281. private _uid: Nullable<string>;
  282. /**
  283. * Define if the texture is preventinga material to render or not.
  284. * If not and the texture is not ready, the engine will use a default black texture instead.
  285. */
  286. public get isBlocking(): boolean {
  287. return true;
  288. }
  289. /**
  290. * Instantiates a new BaseTexture.
  291. * Base class of all the textures in babylon.
  292. * It groups all the common properties the materials, post process, lights... might need
  293. * in order to make a correct use of the texture.
  294. * @param scene Define the scene the texture blongs to
  295. */
  296. constructor(scene: Nullable<Scene>) {
  297. this._scene = scene || EngineStore.LastCreatedScene;
  298. if (this._scene) {
  299. this.uniqueId = this._scene.getUniqueId();
  300. this._scene.addTexture(this);
  301. }
  302. this._uid = null;
  303. }
  304. /**
  305. * Get the scene the texture belongs to.
  306. * @returns the scene or null if undefined
  307. */
  308. public getScene(): Nullable<Scene> {
  309. return this._scene;
  310. }
  311. /**
  312. * Get the texture transform matrix used to offset tile the texture for istance.
  313. * @returns the transformation matrix
  314. */
  315. public getTextureMatrix(): Matrix {
  316. return <Matrix>Matrix.IdentityReadOnly;
  317. }
  318. /**
  319. * Get the texture reflection matrix used to rotate/transform the reflection.
  320. * @returns the reflection matrix
  321. */
  322. public getReflectionTextureMatrix(): Matrix {
  323. return <Matrix>Matrix.IdentityReadOnly;
  324. }
  325. /**
  326. * Get the underlying lower level texture from Babylon.
  327. * @returns the insternal texture
  328. */
  329. public getInternalTexture(): Nullable<InternalTexture> {
  330. return this._texture;
  331. }
  332. /**
  333. * Get if the texture is ready to be consumed (either it is ready or it is not blocking)
  334. * @returns true if ready or not blocking
  335. */
  336. public isReadyOrNotBlocking(): boolean {
  337. return !this.isBlocking || this.isReady();
  338. }
  339. /**
  340. * Get if the texture is ready to be used (downloaded, converted, mip mapped...).
  341. * @returns true if fully ready
  342. */
  343. public isReady(): boolean {
  344. if (this.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {
  345. this.delayLoad();
  346. return false;
  347. }
  348. if (this._texture) {
  349. return this._texture.isReady;
  350. }
  351. return false;
  352. }
  353. private _cachedSize: ISize = Size.Zero();
  354. /**
  355. * Get the size of the texture.
  356. * @returns the texture size.
  357. */
  358. public getSize(): ISize {
  359. if (this._texture) {
  360. if (this._texture.width) {
  361. this._cachedSize.width = this._texture.width;
  362. this._cachedSize.height = this._texture.height;
  363. return this._cachedSize;
  364. }
  365. if (this._texture._size) {
  366. this._cachedSize.width = this._texture._size;
  367. this._cachedSize.height = this._texture._size;
  368. return this._cachedSize;
  369. }
  370. }
  371. return this._cachedSize;
  372. }
  373. /**
  374. * Get the base size of the texture.
  375. * It can be different from the size if the texture has been resized for POT for instance
  376. * @returns the base size
  377. */
  378. public getBaseSize(): ISize {
  379. if (!this.isReady() || !this._texture) {
  380. return Size.Zero();
  381. }
  382. if (this._texture._size) {
  383. return new Size(this._texture._size, this._texture._size);
  384. }
  385. return new Size(this._texture.baseWidth, this._texture.baseHeight);
  386. }
  387. /**
  388. * Update the sampling mode of the texture.
  389. * Default is Trilinear mode.
  390. *
  391. * | Value | Type | Description |
  392. * | ----- | ------------------ | ----------- |
  393. * | 1 | NEAREST_SAMPLINGMODE or NEAREST_NEAREST_MIPLINEAR | Nearest is: mag = nearest, min = nearest, mip = linear |
  394. * | 2 | BILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPNEAREST | Bilinear is: mag = linear, min = linear, mip = nearest |
  395. * | 3 | TRILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPLINEAR | Trilinear is: mag = linear, min = linear, mip = linear |
  396. * | 4 | NEAREST_NEAREST_MIPNEAREST | |
  397. * | 5 | NEAREST_LINEAR_MIPNEAREST | |
  398. * | 6 | NEAREST_LINEAR_MIPLINEAR | |
  399. * | 7 | NEAREST_LINEAR | |
  400. * | 8 | NEAREST_NEAREST | |
  401. * | 9 | LINEAR_NEAREST_MIPNEAREST | |
  402. * | 10 | LINEAR_NEAREST_MIPLINEAR | |
  403. * | 11 | LINEAR_LINEAR | |
  404. * | 12 | LINEAR_NEAREST | |
  405. *
  406. * > _mag_: magnification filter (close to the viewer)
  407. * > _min_: minification filter (far from the viewer)
  408. * > _mip_: filter used between mip map levels
  409. *@param samplingMode Define the new sampling mode of the texture
  410. */
  411. public updateSamplingMode(samplingMode: number): void {
  412. if (!this._texture) {
  413. return;
  414. }
  415. let scene = this.getScene();
  416. if (!scene) {
  417. return;
  418. }
  419. scene.getEngine().updateTextureSamplingMode(samplingMode, this._texture);
  420. }
  421. /**
  422. * Scales the texture if is `canRescale()`
  423. * @param ratio the resize factor we want to use to rescale
  424. */
  425. public scale(ratio: number): void {
  426. }
  427. /**
  428. * Get if the texture can rescale.
  429. */
  430. public get canRescale(): boolean {
  431. return false;
  432. }
  433. /** @hidden */
  434. public _getFromCache(url: Nullable<string>, noMipmap: boolean, sampling?: number): Nullable<InternalTexture> {
  435. if (!this._scene) {
  436. return null;
  437. }
  438. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  439. for (var index = 0; index < texturesCache.length; index++) {
  440. var texturesCacheEntry = texturesCache[index];
  441. if (texturesCacheEntry.url === url && texturesCacheEntry.generateMipMaps === !noMipmap) {
  442. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  443. texturesCacheEntry.incrementReferences();
  444. return texturesCacheEntry;
  445. }
  446. }
  447. }
  448. return null;
  449. }
  450. /** @hidden */
  451. public _rebuild(): void {
  452. }
  453. /**
  454. * Triggers the load sequence in delayed load mode.
  455. */
  456. public delayLoad(): void {
  457. }
  458. /**
  459. * Clones the texture.
  460. * @returns the cloned texture
  461. */
  462. public clone(): Nullable<BaseTexture> {
  463. return null;
  464. }
  465. /**
  466. * Get the texture underlying type (INT, FLOAT...)
  467. */
  468. public get textureType(): number {
  469. if (!this._texture) {
  470. return Constants.TEXTURETYPE_UNSIGNED_INT;
  471. }
  472. return (this._texture.type !== undefined) ? this._texture.type : Constants.TEXTURETYPE_UNSIGNED_INT;
  473. }
  474. /**
  475. * Get the texture underlying format (RGB, RGBA...)
  476. */
  477. public get textureFormat(): number {
  478. if (!this._texture) {
  479. return Constants.TEXTUREFORMAT_RGBA;
  480. }
  481. return (this._texture.format !== undefined) ? this._texture.format : Constants.TEXTUREFORMAT_RGBA;
  482. }
  483. /**
  484. * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.
  485. * This will returns an RGBA array buffer containing either in values (0-255) or
  486. * float values (0-1) depending of the underlying buffer type.
  487. * @param faceIndex defines the face of the texture to read (in case of cube texture)
  488. * @param level defines the LOD level of the texture to read (in case of Mip Maps)
  489. * @param buffer defines a user defined buffer to fill with data (can be null)
  490. * @returns The Array buffer containing the pixels data.
  491. */
  492. public readPixels(faceIndex = 0, level = 0, buffer: Nullable<ArrayBufferView> = null): Nullable<ArrayBufferView> {
  493. if (!this._texture) {
  494. return null;
  495. }
  496. var size = this.getSize();
  497. var width = size.width;
  498. var height = size.height;
  499. let scene = this.getScene();
  500. if (!scene) {
  501. return null;
  502. }
  503. var engine = scene.getEngine();
  504. if (level != 0) {
  505. width = width / Math.pow(2, level);
  506. height = height / Math.pow(2, level);
  507. width = Math.round(width);
  508. height = Math.round(height);
  509. }
  510. if (this._texture.isCube) {
  511. return engine._readTexturePixels(this._texture, width, height, faceIndex, level, buffer);
  512. }
  513. return engine._readTexturePixels(this._texture, width, height, -1, level, buffer);
  514. }
  515. /**
  516. * Release and destroy the underlying lower level texture aka internalTexture.
  517. */
  518. public releaseInternalTexture(): void {
  519. if (this._texture) {
  520. this._texture.dispose();
  521. this._texture = null;
  522. }
  523. }
  524. /**
  525. * Get the polynomial representation of the texture data.
  526. * This is mainly use as a fast way to recover IBL Diffuse irradiance data.
  527. * @see https://learnopengl.com/PBR/IBL/Diffuse-irradiance
  528. */
  529. public get sphericalPolynomial(): Nullable<SphericalPolynomial> {
  530. if (!this._texture || !CubeMapToSphericalPolynomialTools || !this.isReady()) {
  531. return null;
  532. }
  533. if (!this._texture._sphericalPolynomial) {
  534. this._texture._sphericalPolynomial =
  535. CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this);
  536. }
  537. return this._texture._sphericalPolynomial;
  538. }
  539. public set sphericalPolynomial(value: Nullable<SphericalPolynomial>) {
  540. if (this._texture) {
  541. this._texture._sphericalPolynomial = value;
  542. }
  543. }
  544. /** @hidden */
  545. public get _lodTextureHigh(): Nullable<BaseTexture> {
  546. if (this._texture) {
  547. return this._texture._lodTextureHigh;
  548. }
  549. return null;
  550. }
  551. /** @hidden */
  552. public get _lodTextureMid(): Nullable<BaseTexture> {
  553. if (this._texture) {
  554. return this._texture._lodTextureMid;
  555. }
  556. return null;
  557. }
  558. /** @hidden */
  559. public get _lodTextureLow(): Nullable<BaseTexture> {
  560. if (this._texture) {
  561. return this._texture._lodTextureLow;
  562. }
  563. return null;
  564. }
  565. /**
  566. * Dispose the texture and release its associated resources.
  567. */
  568. public dispose(): void {
  569. if (!this._scene) {
  570. return;
  571. }
  572. // Animations
  573. this._scene.stopAnimation(this);
  574. // Remove from scene
  575. this._scene._removePendingData(this);
  576. var index = this._scene.textures.indexOf(this);
  577. if (index >= 0) {
  578. this._scene.textures.splice(index, 1);
  579. }
  580. this._scene.onTextureRemovedObservable.notifyObservers(this);
  581. if (this._texture === undefined) {
  582. return;
  583. }
  584. // Release
  585. this.releaseInternalTexture();
  586. // Callback
  587. this.onDisposeObservable.notifyObservers(this);
  588. this.onDisposeObservable.clear();
  589. }
  590. /**
  591. * Serialize the texture into a JSON representation that can be parsed later on.
  592. * @returns the JSON representation of the texture
  593. */
  594. public serialize(): any {
  595. if (!this.name) {
  596. return null;
  597. }
  598. var serializationObject = SerializationHelper.Serialize(this);
  599. // Animations
  600. SerializationHelper.AppendSerializedAnimations(this, serializationObject);
  601. return serializationObject;
  602. }
  603. /**
  604. * Helper function to be called back once a list of texture contains only ready textures.
  605. * @param textures Define the list of textures to wait for
  606. * @param callback Define the callback triggered once the entire list will be ready
  607. */
  608. public static WhenAllReady(textures: BaseTexture[], callback: () => void): void {
  609. let numRemaining = textures.length;
  610. if (numRemaining === 0) {
  611. callback();
  612. return;
  613. }
  614. for (var i = 0; i < textures.length; i++) {
  615. var texture = textures[i];
  616. if (texture.isReady()) {
  617. if (--numRemaining === 0) {
  618. callback();
  619. }
  620. }
  621. else {
  622. var onLoadObservable = (texture as any).onLoadObservable as Observable<BaseTexture>;
  623. let onLoadCallback = () => {
  624. onLoadObservable.removeCallback(onLoadCallback);
  625. if (--numRemaining === 0) {
  626. callback();
  627. }
  628. };
  629. onLoadObservable.add(onLoadCallback);
  630. }
  631. }
  632. }
  633. }