baseTexture.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. import { serialize, SerializationHelper, serializeAsTexture } from "../../Misc/decorators";
  2. import { Observer, Observable } from "../../Misc/observable";
  3. import { Nullable } from "../../types";
  4. import { Scene } from "../../scene";
  5. import { Matrix } from "../../Maths/math.vector";
  6. import { EngineStore } from "../../Engines/engineStore";
  7. import { InternalTexture } from "../../Materials/Textures/internalTexture";
  8. import { Constants } from "../../Engines/constants";
  9. import { IAnimatable } from '../../Animations/animatable.interface';
  10. import { GUID } from '../../Misc/guid';
  11. import "../../Misc/fileTools";
  12. import { ThinEngine } from '../../Engines/thinEngine';
  13. import { ThinTexture } from './thinTexture';
  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 extends ThinTexture 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. protected _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 get wrapU() {
  119. return this._wrapU;
  120. }
  121. public set wrapU(value: number) {
  122. this._wrapU = value;
  123. }
  124. /**
  125. * | Value | Type | Description |
  126. * | ----- | ------------------ | ----------- |
  127. * | 0 | CLAMP_ADDRESSMODE | |
  128. * | 1 | WRAP_ADDRESSMODE | |
  129. * | 2 | MIRROR_ADDRESSMODE | |
  130. */
  131. @serialize()
  132. public get wrapV() {
  133. return this._wrapV;
  134. }
  135. public set wrapV(value: number) {
  136. this._wrapV = value;
  137. }
  138. /**
  139. * | Value | Type | Description |
  140. * | ----- | ------------------ | ----------- |
  141. * | 0 | CLAMP_ADDRESSMODE | |
  142. * | 1 | WRAP_ADDRESSMODE | |
  143. * | 2 | MIRROR_ADDRESSMODE | |
  144. */
  145. @serialize()
  146. public wrapR = Constants.TEXTURE_WRAP_ADDRESSMODE;
  147. /**
  148. * With compliant hardware and browser (supporting anisotropic filtering)
  149. * this defines the level of anisotropic filtering in the texture.
  150. * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.
  151. */
  152. @serialize()
  153. public anisotropicFilteringLevel = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL;
  154. private _isCube = false;
  155. /**
  156. * Define if the texture is a cube texture or if false a 2d texture.
  157. */
  158. @serialize()
  159. public get isCube(): boolean {
  160. if (!this._texture) {
  161. return this._isCube;
  162. }
  163. return this._texture.isCube;
  164. }
  165. public set isCube(value: boolean) {
  166. if (!this._texture) {
  167. this._isCube = value;
  168. } else {
  169. this._texture.isCube = value;
  170. }
  171. }
  172. /**
  173. * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.
  174. */
  175. @serialize()
  176. public get is3D(): boolean {
  177. if (!this._texture) {
  178. return false;
  179. }
  180. return this._texture.is3D;
  181. }
  182. public set is3D(value: boolean) {
  183. if (!this._texture) {
  184. return;
  185. }
  186. this._texture.is3D = value;
  187. }
  188. /**
  189. * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.
  190. */
  191. @serialize()
  192. public get is2DArray(): boolean {
  193. if (!this._texture) {
  194. return false;
  195. }
  196. return this._texture.is2DArray;
  197. }
  198. public set is2DArray(value: boolean) {
  199. if (!this._texture) {
  200. return;
  201. }
  202. this._texture.is2DArray = value;
  203. }
  204. private _gammaSpace = true;
  205. /**
  206. * Define if the texture contains data in gamma space (most of the png/jpg aside bump).
  207. * HDR texture are usually stored in linear space.
  208. * This only impacts the PBR and Background materials
  209. */
  210. @serialize()
  211. public get gammaSpace(): boolean {
  212. if (!this._texture) {
  213. return this._gammaSpace;
  214. } else {
  215. if (this._texture._gammaSpace === null) {
  216. this._texture._gammaSpace = this._gammaSpace;
  217. }
  218. }
  219. return this._texture._gammaSpace;
  220. }
  221. public set gammaSpace(gamma: boolean) {
  222. if (!this._texture) {
  223. if (this._gammaSpace === gamma) {
  224. return;
  225. }
  226. this._gammaSpace = gamma;
  227. } else {
  228. if (this._texture._gammaSpace === gamma) {
  229. return;
  230. }
  231. this._texture._gammaSpace = gamma;
  232. }
  233. this._markAllSubMeshesAsTexturesDirty();
  234. }
  235. /**
  236. * Gets or sets whether or not the texture contains RGBD data.
  237. */
  238. public get isRGBD(): boolean {
  239. return this._texture != null && this._texture._isRGBD;
  240. }
  241. public set isRGBD(value: boolean) {
  242. if (this._texture) { this._texture._isRGBD = value; }
  243. }
  244. /**
  245. * Is Z inverted in the texture (useful in a cube texture).
  246. */
  247. @serialize()
  248. public invertZ = false;
  249. /**
  250. * Are mip maps generated for this texture or not.
  251. */
  252. public get noMipmap(): boolean {
  253. return false;
  254. }
  255. /**
  256. * @hidden
  257. */
  258. @serialize()
  259. public lodLevelInAlpha = false;
  260. /**
  261. * With prefiltered texture, defined the offset used during the prefiltering steps.
  262. */
  263. @serialize()
  264. public get lodGenerationOffset(): number {
  265. if (this._texture) { return this._texture._lodGenerationOffset; }
  266. return 0.0;
  267. }
  268. public set lodGenerationOffset(value: number) {
  269. if (this._texture) { this._texture._lodGenerationOffset = value; }
  270. }
  271. /**
  272. * With prefiltered texture, defined the scale used during the prefiltering steps.
  273. */
  274. @serialize()
  275. public get lodGenerationScale(): number {
  276. if (this._texture) { return this._texture._lodGenerationScale; }
  277. return 0.0;
  278. }
  279. public set lodGenerationScale(value: number) {
  280. if (this._texture) { this._texture._lodGenerationScale = value; }
  281. }
  282. /**
  283. * With prefiltered texture, defined if the specular generation is based on a linear ramp.
  284. * By default we are using a log2 of the linear roughness helping to keep a better resolution for
  285. * average roughness values.
  286. */
  287. @serialize()
  288. public get linearSpecularLOD(): boolean {
  289. if (this._texture) { return this._texture._linearSpecularLOD; }
  290. return false;
  291. }
  292. public set linearSpecularLOD(value: boolean) {
  293. if (this._texture) { this._texture._linearSpecularLOD = value; }
  294. }
  295. /**
  296. * In case a better definition than spherical harmonics is required for the diffuse part of the environment.
  297. * You can set the irradiance texture to rely on a texture instead of the spherical approach.
  298. * This texture need to have the same characteristics than its parent (Cube vs 2d, coordinates mode, Gamma/Linear, RGBD).
  299. */
  300. @serializeAsTexture()
  301. public get irradianceTexture(): Nullable<BaseTexture> {
  302. if (this._texture) { return this._texture._irradianceTexture; }
  303. return null;
  304. }
  305. public set irradianceTexture(value: Nullable<BaseTexture>) {
  306. if (this._texture) { this._texture._irradianceTexture = value; }
  307. }
  308. /**
  309. * Define if the texture is a render target.
  310. */
  311. @serialize()
  312. public isRenderTarget = false;
  313. /**
  314. * Define the unique id of the texture in the scene.
  315. */
  316. public get uid(): string {
  317. if (!this._uid) {
  318. this._uid = GUID.RandomId();
  319. }
  320. return this._uid;
  321. }
  322. /** @hidden */
  323. public _prefiltered: boolean = false;
  324. /**
  325. * Return a string representation of the texture.
  326. * @returns the texture as a string
  327. */
  328. public toString(): string {
  329. return this.name;
  330. }
  331. /**
  332. * Get the class name of the texture.
  333. * @returns "BaseTexture"
  334. */
  335. public getClassName(): string {
  336. return "BaseTexture";
  337. }
  338. /**
  339. * Define the list of animation attached to the texture.
  340. */
  341. public animations = new Array<Animation>();
  342. /**
  343. * An event triggered when the texture is disposed.
  344. */
  345. public onDisposeObservable = new Observable<BaseTexture>();
  346. private _onDisposeObserver: Nullable<Observer<BaseTexture>> = null;
  347. /**
  348. * Callback triggered when the texture has been disposed.
  349. * Kept for back compatibility, you can use the onDisposeObservable instead.
  350. */
  351. public set onDispose(callback: () => void) {
  352. if (this._onDisposeObserver) {
  353. this.onDisposeObservable.remove(this._onDisposeObserver);
  354. }
  355. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  356. }
  357. protected _scene: Nullable<Scene> = null;
  358. /** @hidden */
  359. public _texture: Nullable<InternalTexture> = null;
  360. private _uid: Nullable<string> = null;
  361. /**
  362. * Define if the texture is preventinga material to render or not.
  363. * If not and the texture is not ready, the engine will use a default black texture instead.
  364. */
  365. public get isBlocking(): boolean {
  366. return true;
  367. }
  368. /**
  369. * Instantiates a new BaseTexture.
  370. * Base class of all the textures in babylon.
  371. * It groups all the common properties the materials, post process, lights... might need
  372. * in order to make a correct use of the texture.
  373. * @param sceneOrEngine Define the scene or engine the texture blongs to
  374. */
  375. constructor(sceneOrEngine: Nullable<Scene | ThinEngine>) {
  376. super(null);
  377. if (sceneOrEngine) {
  378. if (BaseTexture._isScene(sceneOrEngine)) {
  379. this._scene = sceneOrEngine;
  380. }
  381. else {
  382. this._engine = sceneOrEngine;
  383. }
  384. }
  385. else {
  386. this._scene = EngineStore.LastCreatedScene;
  387. }
  388. if (this._scene) {
  389. this.uniqueId = this._scene.getUniqueId();
  390. this._scene.addTexture(this);
  391. this._engine = this._scene.getEngine();
  392. }
  393. this._uid = null;
  394. }
  395. /**
  396. * Get the scene the texture belongs to.
  397. * @returns the scene or null if undefined
  398. */
  399. public getScene(): Nullable<Scene> {
  400. return this._scene;
  401. }
  402. /** @hidden */
  403. protected _getEngine(): Nullable<ThinEngine> {
  404. return this._engine;
  405. }
  406. /**
  407. * Checks if the texture has the same transform matrix than another texture
  408. * @param texture texture to check against
  409. * @returns true if the transforms are the same, else false
  410. */
  411. public checkTransformsAreIdentical(texture: Nullable<BaseTexture>): boolean {
  412. return texture !== null;
  413. }
  414. /**
  415. * Get the texture transform matrix used to offset tile the texture for istance.
  416. * @returns the transformation matrix
  417. */
  418. public getTextureMatrix(): Matrix {
  419. return <Matrix>Matrix.IdentityReadOnly;
  420. }
  421. /**
  422. * Get the texture reflection matrix used to rotate/transform the reflection.
  423. * @returns the reflection matrix
  424. */
  425. public getReflectionTextureMatrix(): Matrix {
  426. return <Matrix>Matrix.IdentityReadOnly;
  427. }
  428. /**
  429. * Get if the texture is ready to be consumed (either it is ready or it is not blocking)
  430. * @returns true if ready or not blocking
  431. */
  432. public isReadyOrNotBlocking(): boolean {
  433. return !this.isBlocking || this.isReady();
  434. }
  435. /**
  436. * Scales the texture if is `canRescale()`
  437. * @param ratio the resize factor we want to use to rescale
  438. */
  439. public scale(ratio: number): void {
  440. }
  441. /**
  442. * Get if the texture can rescale.
  443. */
  444. public get canRescale(): boolean {
  445. return false;
  446. }
  447. /** @hidden */
  448. public _getFromCache(url: Nullable<string>, noMipmap: boolean, sampling?: number, invertY?: boolean): Nullable<InternalTexture> {
  449. const engine = this._getEngine();
  450. if (!engine) {
  451. return null;
  452. }
  453. var texturesCache = engine.getLoadedTexturesCache();
  454. for (var index = 0; index < texturesCache.length; index++) {
  455. var texturesCacheEntry = texturesCache[index];
  456. if (invertY === undefined || invertY === texturesCacheEntry.invertY) {
  457. if (texturesCacheEntry.url === url && texturesCacheEntry.generateMipMaps === !noMipmap) {
  458. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  459. texturesCacheEntry.incrementReferences();
  460. return texturesCacheEntry;
  461. }
  462. }
  463. }
  464. }
  465. return null;
  466. }
  467. /** @hidden */
  468. public _rebuild(): void {
  469. }
  470. /**
  471. * Clones the texture.
  472. * @returns the cloned texture
  473. */
  474. public clone(): Nullable<BaseTexture> {
  475. return null;
  476. }
  477. /**
  478. * Get the texture underlying type (INT, FLOAT...)
  479. */
  480. public get textureType(): number {
  481. if (!this._texture) {
  482. return Constants.TEXTURETYPE_UNSIGNED_INT;
  483. }
  484. return (this._texture.type !== undefined) ? this._texture.type : Constants.TEXTURETYPE_UNSIGNED_INT;
  485. }
  486. /**
  487. * Get the texture underlying format (RGB, RGBA...)
  488. */
  489. public get textureFormat(): number {
  490. if (!this._texture) {
  491. return Constants.TEXTUREFORMAT_RGBA;
  492. }
  493. return (this._texture.format !== undefined) ? this._texture.format : Constants.TEXTUREFORMAT_RGBA;
  494. }
  495. /**
  496. * Indicates that textures need to be re-calculated for all materials
  497. */
  498. protected _markAllSubMeshesAsTexturesDirty() {
  499. let scene = this.getScene();
  500. if (!scene) {
  501. return;
  502. }
  503. scene.markAllMaterialsAsDirty(Constants.MATERIAL_TextureDirtyFlag);
  504. }
  505. /**
  506. * Reads the pixels stored in the webgl texture and returns them as an ArrayBuffer.
  507. * This will returns an RGBA array buffer containing either in values (0-255) or
  508. * float values (0-1) depending of the underlying buffer type.
  509. * @param faceIndex defines the face of the texture to read (in case of cube texture)
  510. * @param level defines the LOD level of the texture to read (in case of Mip Maps)
  511. * @param buffer defines a user defined buffer to fill with data (can be null)
  512. * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
  513. * @returns The Array buffer promise containing the pixels data.
  514. */
  515. public readPixels(faceIndex = 0, level = 0, buffer: Nullable<ArrayBufferView> = null, flushRenderer = true): Nullable<Promise<ArrayBufferView>> {
  516. if (!this._texture) {
  517. return null;
  518. }
  519. var size = this.getSize();
  520. var width = size.width;
  521. var height = size.height;
  522. const engine = this._getEngine();
  523. if (!engine) {
  524. return null;
  525. }
  526. if (level != 0) {
  527. width = width / Math.pow(2, level);
  528. height = height / Math.pow(2, level);
  529. width = Math.round(width);
  530. height = Math.round(height);
  531. }
  532. try {
  533. if (this._texture.isCube) {
  534. return engine._readTexturePixels(this._texture, width, height, faceIndex, level, buffer, flushRenderer);
  535. }
  536. return engine._readTexturePixels(this._texture, width, height, -1, level, buffer, flushRenderer);
  537. } catch (e) {
  538. return null;
  539. }
  540. }
  541. /** @hidden */
  542. public _readPixelsSync(faceIndex = 0, level = 0, buffer: Nullable<ArrayBufferView> = null, flushRenderer = true): Nullable<ArrayBufferView> {
  543. if (!this._texture) {
  544. return null;
  545. }
  546. var size = this.getSize();
  547. var width = size.width;
  548. var height = size.height;
  549. const engine = this._getEngine();
  550. if (!engine) {
  551. return null;
  552. }
  553. if (level != 0) {
  554. width = width / Math.pow(2, level);
  555. height = height / Math.pow(2, level);
  556. width = Math.round(width);
  557. height = Math.round(height);
  558. }
  559. try {
  560. if (this._texture.isCube) {
  561. return engine._readTexturePixelsSync(this._texture, width, height, faceIndex, level, buffer, flushRenderer);
  562. }
  563. return engine._readTexturePixelsSync(this._texture, width, height, -1, level, buffer, flushRenderer);
  564. } catch (e) {
  565. return null;
  566. }
  567. }
  568. /** @hidden */
  569. public get _lodTextureHigh(): Nullable<BaseTexture> {
  570. if (this._texture) {
  571. return this._texture._lodTextureHigh;
  572. }
  573. return null;
  574. }
  575. /** @hidden */
  576. public get _lodTextureMid(): Nullable<BaseTexture> {
  577. if (this._texture) {
  578. return this._texture._lodTextureMid;
  579. }
  580. return null;
  581. }
  582. /** @hidden */
  583. public get _lodTextureLow(): Nullable<BaseTexture> {
  584. if (this._texture) {
  585. return this._texture._lodTextureLow;
  586. }
  587. return null;
  588. }
  589. /**
  590. * Dispose the texture and release its associated resources.
  591. */
  592. public dispose(): void {
  593. if (this._scene) {
  594. // Animations
  595. if (this._scene.stopAnimation) {
  596. this._scene.stopAnimation(this);
  597. }
  598. // Remove from scene
  599. this._scene._removePendingData(this);
  600. var index = this._scene.textures.indexOf(this);
  601. if (index >= 0) {
  602. this._scene.textures.splice(index, 1);
  603. }
  604. this._scene.onTextureRemovedObservable.notifyObservers(this);
  605. this._scene = null;
  606. }
  607. // Callback
  608. this.onDisposeObservable.notifyObservers(this);
  609. this.onDisposeObservable.clear();
  610. super.dispose();
  611. }
  612. /**
  613. * Serialize the texture into a JSON representation that can be parsed later on.
  614. * @returns the JSON representation of the texture
  615. */
  616. public serialize(): any {
  617. if (!this.name) {
  618. return null;
  619. }
  620. var serializationObject = SerializationHelper.Serialize(this);
  621. // Animations
  622. SerializationHelper.AppendSerializedAnimations(this, serializationObject);
  623. return serializationObject;
  624. }
  625. /**
  626. * Helper function to be called back once a list of texture contains only ready textures.
  627. * @param textures Define the list of textures to wait for
  628. * @param callback Define the callback triggered once the entire list will be ready
  629. */
  630. public static WhenAllReady(textures: BaseTexture[], callback: () => void): void {
  631. let numRemaining = textures.length;
  632. if (numRemaining === 0) {
  633. callback();
  634. return;
  635. }
  636. for (var i = 0; i < textures.length; i++) {
  637. var texture = textures[i];
  638. if (texture.isReady()) {
  639. if (--numRemaining === 0) {
  640. callback();
  641. }
  642. }
  643. else {
  644. var onLoadObservable = (texture as any).onLoadObservable as Observable<BaseTexture>;
  645. if (onLoadObservable) {
  646. onLoadObservable.addOnce(() => {
  647. if (--numRemaining === 0) {
  648. callback();
  649. }
  650. });
  651. }
  652. }
  653. }
  654. }
  655. private static _isScene(sceneOrEngine: Scene | ThinEngine): sceneOrEngine is Scene {
  656. return sceneOrEngine.getClassName() === "Scene";
  657. }
  658. }