assetsManager.d.ts 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. import type { Scene } from "../scene";
  2. import type { AbstractMesh } from "../Meshes/abstractMesh";
  3. import type { TransformNode } from "../Meshes/transformNode";
  4. import type { IParticleSystem } from "../Particles/IParticleSystem";
  5. import type { Skeleton } from "../Bones/skeleton";
  6. import { Observable } from "./observable";
  7. import type { BaseTexture } from "../Materials/Textures/baseTexture";
  8. import { Texture } from "../Materials/Textures/texture";
  9. import { CubeTexture } from "../Materials/Textures/cubeTexture";
  10. import { HDRCubeTexture } from "../Materials/Textures/hdrCubeTexture";
  11. import { EquiRectangularCubeTexture } from "../Materials/Textures/equiRectangularCubeTexture";
  12. import type { Animatable } from "../Animations/animatable";
  13. import type { AnimationGroup } from "../Animations/animationGroup";
  14. import type { AssetContainer } from "../assetContainer";
  15. import type { Nullable } from "../types";
  16. /**
  17. * Defines the list of states available for a task inside a AssetsManager
  18. */
  19. export declare enum AssetTaskState {
  20. /**
  21. * Initialization
  22. */
  23. INIT = 0,
  24. /**
  25. * Running
  26. */
  27. RUNNING = 1,
  28. /**
  29. * Done
  30. */
  31. DONE = 2,
  32. /**
  33. * Error
  34. */
  35. ERROR = 3
  36. }
  37. /**
  38. * Define an abstract asset task used with a AssetsManager class to load assets into a scene
  39. */
  40. export declare abstract class AbstractAssetTask {
  41. /**
  42. * Task name
  43. */ name: string;
  44. /**
  45. * Callback called when the task is successful
  46. */
  47. onSuccess: (task: any) => void;
  48. /**
  49. * Callback called when the task is not successful
  50. */
  51. onError: (task: any, message?: string, exception?: any) => void;
  52. /**
  53. * Creates a new AssetsManager
  54. * @param name defines the name of the task
  55. */
  56. constructor(
  57. /**
  58. * Task name
  59. */ name: string);
  60. private _isCompleted;
  61. private _taskState;
  62. private _errorObject;
  63. /**
  64. * Get if the task is completed
  65. */
  66. get isCompleted(): boolean;
  67. /**
  68. * Gets the current state of the task
  69. */
  70. get taskState(): AssetTaskState;
  71. /**
  72. * Gets the current error object (if task is in error)
  73. */
  74. get errorObject(): {
  75. message?: string;
  76. exception?: any;
  77. };
  78. /**
  79. * Internal only
  80. * @internal
  81. */
  82. _setErrorObject(message?: string, exception?: any): void;
  83. /**
  84. * Execute the current task
  85. * @param scene defines the scene where you want your assets to be loaded
  86. * @param onSuccess is a callback called when the task is successfully executed
  87. * @param onError is a callback called if an error occurs
  88. */
  89. run(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  90. /**
  91. * Execute the current task
  92. * @param scene defines the scene where you want your assets to be loaded
  93. * @param onSuccess is a callback called when the task is successfully executed
  94. * @param onError is a callback called if an error occurs
  95. */
  96. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  97. /**
  98. * Reset will set the task state back to INIT, so the next load call of the assets manager will execute this task again.
  99. * This can be used with failed tasks that have the reason for failure fixed.
  100. */
  101. reset(): void;
  102. private _onErrorCallback;
  103. private _onDoneCallback;
  104. }
  105. /**
  106. * Define the interface used by progress events raised during assets loading
  107. */
  108. export interface IAssetsProgressEvent {
  109. /**
  110. * Defines the number of remaining tasks to process
  111. */
  112. remainingCount: number;
  113. /**
  114. * Defines the total number of tasks
  115. */
  116. totalCount: number;
  117. /**
  118. * Defines the task that was just processed
  119. */
  120. task: AbstractAssetTask;
  121. }
  122. /**
  123. * Class used to share progress information about assets loading
  124. */
  125. export declare class AssetsProgressEvent implements IAssetsProgressEvent {
  126. /**
  127. * Defines the number of remaining tasks to process
  128. */
  129. remainingCount: number;
  130. /**
  131. * Defines the total number of tasks
  132. */
  133. totalCount: number;
  134. /**
  135. * Defines the task that was just processed
  136. */
  137. task: AbstractAssetTask;
  138. /**
  139. * Creates a AssetsProgressEvent
  140. * @param remainingCount defines the number of remaining tasks to process
  141. * @param totalCount defines the total number of tasks
  142. * @param task defines the task that was just processed
  143. */
  144. constructor(remainingCount: number, totalCount: number, task: AbstractAssetTask);
  145. }
  146. /**
  147. * Define a task used by AssetsManager to load assets into a container
  148. */
  149. export declare class ContainerAssetTask extends AbstractAssetTask {
  150. /**
  151. * Defines the name of the task
  152. */
  153. name: string;
  154. /**
  155. * Defines the list of mesh's names you want to load
  156. */
  157. meshesNames: any;
  158. /**
  159. * Defines the root url to use as a base to load your meshes and associated resources
  160. */
  161. rootUrl: string;
  162. /**
  163. * Defines the filename or File of the scene to load from
  164. */
  165. sceneFilename: string | File;
  166. /**
  167. * Defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  168. */
  169. extension?: string | undefined;
  170. /**
  171. * Get the loaded asset container
  172. */
  173. loadedContainer: AssetContainer;
  174. /**
  175. * Gets the list of loaded transforms
  176. */
  177. loadedTransformNodes: Array<TransformNode>;
  178. /**
  179. * Gets the list of loaded meshes
  180. */
  181. loadedMeshes: Array<AbstractMesh>;
  182. /**
  183. * Gets the list of loaded particle systems
  184. */
  185. loadedParticleSystems: Array<IParticleSystem>;
  186. /**
  187. * Gets the list of loaded skeletons
  188. */
  189. loadedSkeletons: Array<Skeleton>;
  190. /**
  191. * Gets the list of loaded animation groups
  192. */
  193. loadedAnimationGroups: Array<AnimationGroup>;
  194. /**
  195. * Callback called when the task is successful
  196. */
  197. onSuccess: (task: ContainerAssetTask) => void;
  198. /**
  199. * Callback called when the task is successful
  200. */
  201. onError: (task: ContainerAssetTask, message?: string, exception?: any) => void;
  202. /**
  203. * Creates a new ContainerAssetTask
  204. * @param name defines the name of the task
  205. * @param meshesNames defines the list of mesh's names you want to load
  206. * @param rootUrl defines the root url to use as a base to load your meshes and associated resources
  207. * @param sceneFilename defines the filename or File of the scene to load from
  208. * @param extension defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  209. */
  210. constructor(
  211. /**
  212. * Defines the name of the task
  213. */
  214. name: string,
  215. /**
  216. * Defines the list of mesh's names you want to load
  217. */
  218. meshesNames: any,
  219. /**
  220. * Defines the root url to use as a base to load your meshes and associated resources
  221. */
  222. rootUrl: string,
  223. /**
  224. * Defines the filename or File of the scene to load from
  225. */
  226. sceneFilename: string | File,
  227. /**
  228. * Defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  229. */
  230. extension?: string | undefined);
  231. /**
  232. * Execute the current task
  233. * @param scene defines the scene where you want your assets to be loaded
  234. * @param onSuccess is a callback called when the task is successfully executed
  235. * @param onError is a callback called if an error occurs
  236. */
  237. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  238. }
  239. /**
  240. * Define a task used by AssetsManager to load meshes
  241. */
  242. export declare class MeshAssetTask extends AbstractAssetTask {
  243. /**
  244. * Defines the name of the task
  245. */
  246. name: string;
  247. /**
  248. * Defines the list of mesh's names you want to load
  249. */
  250. meshesNames: any;
  251. /**
  252. * Defines the root url to use as a base to load your meshes and associated resources
  253. */
  254. rootUrl: string;
  255. /**
  256. * Defines the filename or File of the scene to load from
  257. */
  258. sceneFilename: string | File;
  259. /**
  260. * Defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  261. */
  262. extension?: string | undefined;
  263. /**
  264. * Gets the list of loaded transforms
  265. */
  266. loadedTransformNodes: Array<TransformNode>;
  267. /**
  268. * Gets the list of loaded meshes
  269. */
  270. loadedMeshes: Array<AbstractMesh>;
  271. /**
  272. * Gets the list of loaded particle systems
  273. */
  274. loadedParticleSystems: Array<IParticleSystem>;
  275. /**
  276. * Gets the list of loaded skeletons
  277. */
  278. loadedSkeletons: Array<Skeleton>;
  279. /**
  280. * Gets the list of loaded animation groups
  281. */
  282. loadedAnimationGroups: Array<AnimationGroup>;
  283. /**
  284. * Callback called when the task is successful
  285. */
  286. onSuccess: (task: MeshAssetTask) => void;
  287. /**
  288. * Callback called when the task is successful
  289. */
  290. onError: (task: MeshAssetTask, message?: string, exception?: any) => void;
  291. /**
  292. * Creates a new MeshAssetTask
  293. * @param name defines the name of the task
  294. * @param meshesNames defines the list of mesh's names you want to load
  295. * @param rootUrl defines the root url to use as a base to load your meshes and associated resources
  296. * @param sceneFilename defines the filename or File of the scene to load from
  297. * @param extension defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  298. */
  299. constructor(
  300. /**
  301. * Defines the name of the task
  302. */
  303. name: string,
  304. /**
  305. * Defines the list of mesh's names you want to load
  306. */
  307. meshesNames: any,
  308. /**
  309. * Defines the root url to use as a base to load your meshes and associated resources
  310. */
  311. rootUrl: string,
  312. /**
  313. * Defines the filename or File of the scene to load from
  314. */
  315. sceneFilename: string | File,
  316. /**
  317. * Defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  318. */
  319. extension?: string | undefined);
  320. /**
  321. * Execute the current task
  322. * @param scene defines the scene where you want your assets to be loaded
  323. * @param onSuccess is a callback called when the task is successfully executed
  324. * @param onError is a callback called if an error occurs
  325. */
  326. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  327. }
  328. /**
  329. * Define a task used by AssetsManager to load animations
  330. */
  331. export declare class AnimationAssetTask extends AbstractAssetTask {
  332. /**
  333. * Defines the name of the task
  334. */
  335. name: string;
  336. /**
  337. * Defines the root url to use as a base to load your meshes and associated resources
  338. */
  339. rootUrl: string;
  340. /**
  341. * Defines the filename to load from
  342. */
  343. filename: string | File;
  344. /**
  345. * Defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)
  346. */
  347. targetConverter?: Nullable<(target: any) => any> | undefined;
  348. /**
  349. * Defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  350. */
  351. extension?: string | undefined;
  352. /**
  353. * Gets the list of loaded animation groups
  354. */
  355. loadedAnimationGroups: Array<AnimationGroup>;
  356. /**
  357. * Gets the list of loaded animatables
  358. */
  359. loadedAnimatables: Array<Animatable>;
  360. /**
  361. * Callback called when the task is successful
  362. */
  363. onSuccess: (task: AnimationAssetTask) => void;
  364. /**
  365. * Callback called when the task is successful
  366. */
  367. onError: (task: AnimationAssetTask, message?: string, exception?: any) => void;
  368. /**
  369. * Creates a new AnimationAssetTask
  370. * @param name defines the name of the task
  371. * @param rootUrl defines the root url to use as a base to load your meshes and associated resources
  372. * @param filename defines the filename or File of the scene to load from
  373. * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)
  374. * @param extension defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  375. */
  376. constructor(
  377. /**
  378. * Defines the name of the task
  379. */
  380. name: string,
  381. /**
  382. * Defines the root url to use as a base to load your meshes and associated resources
  383. */
  384. rootUrl: string,
  385. /**
  386. * Defines the filename to load from
  387. */
  388. filename: string | File,
  389. /**
  390. * Defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)
  391. */
  392. targetConverter?: Nullable<(target: any) => any> | undefined,
  393. /**
  394. * Defines the extension to use to load the scene (if not defined, ".babylon" will be used)
  395. */
  396. extension?: string | undefined);
  397. /**
  398. * Execute the current task
  399. * @param scene defines the scene where you want your assets to be loaded
  400. * @param onSuccess is a callback called when the task is successfully executed
  401. * @param onError is a callback called if an error occurs
  402. */
  403. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  404. }
  405. /**
  406. * Define a task used by AssetsManager to load text content
  407. */
  408. export declare class TextFileAssetTask extends AbstractAssetTask {
  409. /**
  410. * Defines the name of the task
  411. */
  412. name: string;
  413. /**
  414. * Defines the location of the file to load
  415. */
  416. url: string;
  417. /**
  418. * Gets the loaded text string
  419. */
  420. text: string;
  421. /**
  422. * Callback called when the task is successful
  423. */
  424. onSuccess: (task: TextFileAssetTask) => void;
  425. /**
  426. * Callback called when the task is successful
  427. */
  428. onError: (task: TextFileAssetTask, message?: string, exception?: any) => void;
  429. /**
  430. * Creates a new TextFileAssetTask object
  431. * @param name defines the name of the task
  432. * @param url defines the location of the file to load
  433. */
  434. constructor(
  435. /**
  436. * Defines the name of the task
  437. */
  438. name: string,
  439. /**
  440. * Defines the location of the file to load
  441. */
  442. url: string);
  443. /**
  444. * Execute the current task
  445. * @param scene defines the scene where you want your assets to be loaded
  446. * @param onSuccess is a callback called when the task is successfully executed
  447. * @param onError is a callback called if an error occurs
  448. */
  449. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  450. }
  451. /**
  452. * Define a task used by AssetsManager to load binary data
  453. */
  454. export declare class BinaryFileAssetTask extends AbstractAssetTask {
  455. /**
  456. * Defines the name of the task
  457. */
  458. name: string;
  459. /**
  460. * Defines the location of the file to load
  461. */
  462. url: string;
  463. /**
  464. * Gets the loaded data (as an array buffer)
  465. */
  466. data: ArrayBuffer;
  467. /**
  468. * Callback called when the task is successful
  469. */
  470. onSuccess: (task: BinaryFileAssetTask) => void;
  471. /**
  472. * Callback called when the task is successful
  473. */
  474. onError: (task: BinaryFileAssetTask, message?: string, exception?: any) => void;
  475. /**
  476. * Creates a new BinaryFileAssetTask object
  477. * @param name defines the name of the new task
  478. * @param url defines the location of the file to load
  479. */
  480. constructor(
  481. /**
  482. * Defines the name of the task
  483. */
  484. name: string,
  485. /**
  486. * Defines the location of the file to load
  487. */
  488. url: string);
  489. /**
  490. * Execute the current task
  491. * @param scene defines the scene where you want your assets to be loaded
  492. * @param onSuccess is a callback called when the task is successfully executed
  493. * @param onError is a callback called if an error occurs
  494. */
  495. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  496. }
  497. /**
  498. * Define a task used by AssetsManager to load images
  499. */
  500. export declare class ImageAssetTask extends AbstractAssetTask {
  501. /**
  502. * Defines the name of the task
  503. */
  504. name: string;
  505. /**
  506. * Defines the location of the image to load
  507. */
  508. url: string;
  509. /**
  510. * Gets the loaded images
  511. */
  512. image: HTMLImageElement;
  513. /**
  514. * Callback called when the task is successful
  515. */
  516. onSuccess: (task: ImageAssetTask) => void;
  517. /**
  518. * Callback called when the task is successful
  519. */
  520. onError: (task: ImageAssetTask, message?: string, exception?: any) => void;
  521. /**
  522. * Creates a new ImageAssetTask
  523. * @param name defines the name of the task
  524. * @param url defines the location of the image to load
  525. */
  526. constructor(
  527. /**
  528. * Defines the name of the task
  529. */
  530. name: string,
  531. /**
  532. * Defines the location of the image to load
  533. */
  534. url: string);
  535. /**
  536. * Execute the current task
  537. * @param scene defines the scene where you want your assets to be loaded
  538. * @param onSuccess is a callback called when the task is successfully executed
  539. * @param onError is a callback called if an error occurs
  540. */
  541. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  542. }
  543. /**
  544. * Defines the interface used by texture loading tasks
  545. */
  546. export interface ITextureAssetTask<TEX extends BaseTexture> {
  547. /**
  548. * Gets the loaded texture
  549. */
  550. texture: TEX;
  551. }
  552. /**
  553. * Define a task used by AssetsManager to load 2D textures
  554. */
  555. export declare class TextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<Texture> {
  556. /**
  557. * Defines the name of the task
  558. */
  559. name: string;
  560. /**
  561. * Defines the location of the file to load
  562. */
  563. url: string;
  564. /**
  565. * Defines if mipmap should not be generated (default is false)
  566. */
  567. noMipmap?: boolean | undefined;
  568. /**
  569. * Defines if texture must be inverted on Y axis (default is true)
  570. */
  571. invertY: boolean;
  572. /**
  573. * Defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)
  574. */
  575. samplingMode: number;
  576. /**
  577. * Gets the loaded texture
  578. */
  579. texture: Texture;
  580. /**
  581. * Callback called when the task is successful
  582. */
  583. onSuccess: (task: TextureAssetTask) => void;
  584. /**
  585. * Callback called when the task is successful
  586. */
  587. onError: (task: TextureAssetTask, message?: string, exception?: any) => void;
  588. /**
  589. * Creates a new TextureAssetTask object
  590. * @param name defines the name of the task
  591. * @param url defines the location of the file to load
  592. * @param noMipmap defines if mipmap should not be generated (default is false)
  593. * @param invertY defines if texture must be inverted on Y axis (default is true)
  594. * @param samplingMode defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)
  595. */
  596. constructor(
  597. /**
  598. * Defines the name of the task
  599. */
  600. name: string,
  601. /**
  602. * Defines the location of the file to load
  603. */
  604. url: string,
  605. /**
  606. * Defines if mipmap should not be generated (default is false)
  607. */
  608. noMipmap?: boolean | undefined,
  609. /**
  610. * Defines if texture must be inverted on Y axis (default is true)
  611. */
  612. invertY?: boolean,
  613. /**
  614. * Defines the sampling mode to use (default is Texture.TRILINEAR_SAMPLINGMODE)
  615. */
  616. samplingMode?: number);
  617. /**
  618. * Execute the current task
  619. * @param scene defines the scene where you want your assets to be loaded
  620. * @param onSuccess is a callback called when the task is successfully executed
  621. * @param onError is a callback called if an error occurs
  622. */
  623. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  624. }
  625. /**
  626. * Define a task used by AssetsManager to load cube textures
  627. */
  628. export declare class CubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<CubeTexture> {
  629. /**
  630. * Defines the name of the task
  631. */
  632. name: string;
  633. /**
  634. * Defines the location of the files to load (You have to specify the folder where the files are + filename with no extension)
  635. */
  636. url: string;
  637. /**
  638. * Defines the extensions to use to load files (["_px", "_py", "_pz", "_nx", "_ny", "_nz"] by default)
  639. */
  640. extensions?: string[] | undefined;
  641. /**
  642. * Defines if mipmaps should not be generated (default is false)
  643. */
  644. noMipmap?: boolean | undefined;
  645. /**
  646. * Defines the explicit list of files (undefined by default)
  647. */
  648. files?: string[] | undefined;
  649. /**
  650. * Defines the prefiltered texture option (default is false)
  651. */
  652. prefiltered?: boolean | undefined;
  653. /**
  654. * Gets the loaded texture
  655. */
  656. texture: CubeTexture;
  657. /**
  658. * Callback called when the task is successful
  659. */
  660. onSuccess: (task: CubeTextureAssetTask) => void;
  661. /**
  662. * Callback called when the task is successful
  663. */
  664. onError: (task: CubeTextureAssetTask, message?: string, exception?: any) => void;
  665. /**
  666. * Creates a new CubeTextureAssetTask
  667. * @param name defines the name of the task
  668. * @param url defines the location of the files to load (You have to specify the folder where the files are + filename with no extension)
  669. * @param extensions defines the extensions to use to load files (["_px", "_py", "_pz", "_nx", "_ny", "_nz"] by default)
  670. * @param noMipmap defines if mipmaps should not be generated (default is false)
  671. * @param files defines the explicit list of files (undefined by default)
  672. * @param prefiltered
  673. */
  674. constructor(
  675. /**
  676. * Defines the name of the task
  677. */
  678. name: string,
  679. /**
  680. * Defines the location of the files to load (You have to specify the folder where the files are + filename with no extension)
  681. */
  682. url: string,
  683. /**
  684. * Defines the extensions to use to load files (["_px", "_py", "_pz", "_nx", "_ny", "_nz"] by default)
  685. */
  686. extensions?: string[] | undefined,
  687. /**
  688. * Defines if mipmaps should not be generated (default is false)
  689. */
  690. noMipmap?: boolean | undefined,
  691. /**
  692. * Defines the explicit list of files (undefined by default)
  693. */
  694. files?: string[] | undefined,
  695. /**
  696. * Defines the prefiltered texture option (default is false)
  697. */
  698. prefiltered?: boolean | undefined);
  699. /**
  700. * Execute the current task
  701. * @param scene defines the scene where you want your assets to be loaded
  702. * @param onSuccess is a callback called when the task is successfully executed
  703. * @param onError is a callback called if an error occurs
  704. */
  705. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  706. }
  707. /**
  708. * Define a task used by AssetsManager to load HDR cube textures
  709. */
  710. export declare class HDRCubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<HDRCubeTexture> {
  711. /**
  712. * Defines the name of the task
  713. */
  714. name: string;
  715. /**
  716. * Defines the location of the file to load
  717. */
  718. url: string;
  719. /**
  720. * Defines the desired size (the more it increases the longer the generation will be)
  721. */
  722. size: number;
  723. /**
  724. * Defines if mipmaps should not be generated (default is false)
  725. */
  726. noMipmap: boolean;
  727. /**
  728. * Specifies whether you want to extract the polynomial harmonics during the generation process (default is true)
  729. */
  730. generateHarmonics: boolean;
  731. /**
  732. * Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
  733. */
  734. gammaSpace: boolean;
  735. /**
  736. * Internal Use Only
  737. */
  738. reserved: boolean;
  739. /**
  740. * Gets the loaded texture
  741. */
  742. texture: HDRCubeTexture;
  743. /**
  744. * Callback called when the task is successful
  745. */
  746. onSuccess: (task: HDRCubeTextureAssetTask) => void;
  747. /**
  748. * Callback called when the task is successful
  749. */
  750. onError: (task: HDRCubeTextureAssetTask, message?: string, exception?: any) => void;
  751. /**
  752. * Creates a new HDRCubeTextureAssetTask object
  753. * @param name defines the name of the task
  754. * @param url defines the location of the file to load
  755. * @param size defines the desired size (the more it increases the longer the generation will be) If the size is omitted this implies you are using a preprocessed cubemap.
  756. * @param noMipmap defines if mipmaps should not be generated (default is false)
  757. * @param generateHarmonics specifies whether you want to extract the polynomial harmonics during the generation process (default is true)
  758. * @param gammaSpace specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
  759. * @param reserved Internal use only
  760. */
  761. constructor(
  762. /**
  763. * Defines the name of the task
  764. */
  765. name: string,
  766. /**
  767. * Defines the location of the file to load
  768. */
  769. url: string,
  770. /**
  771. * Defines the desired size (the more it increases the longer the generation will be)
  772. */
  773. size: number,
  774. /**
  775. * Defines if mipmaps should not be generated (default is false)
  776. */
  777. noMipmap?: boolean,
  778. /**
  779. * Specifies whether you want to extract the polynomial harmonics during the generation process (default is true)
  780. */
  781. generateHarmonics?: boolean,
  782. /**
  783. * Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
  784. */
  785. gammaSpace?: boolean,
  786. /**
  787. * Internal Use Only
  788. */
  789. reserved?: boolean);
  790. /**
  791. * Execute the current task
  792. * @param scene defines the scene where you want your assets to be loaded
  793. * @param onSuccess is a callback called when the task is successfully executed
  794. * @param onError is a callback called if an error occurs
  795. */
  796. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  797. }
  798. /**
  799. * Define a task used by AssetsManager to load Equirectangular cube textures
  800. */
  801. export declare class EquiRectangularCubeTextureAssetTask extends AbstractAssetTask implements ITextureAssetTask<EquiRectangularCubeTexture> {
  802. /**
  803. * Defines the name of the task
  804. */
  805. name: string;
  806. /**
  807. * Defines the location of the file to load
  808. */
  809. url: string;
  810. /**
  811. * Defines the desired size (the more it increases the longer the generation will be)
  812. */
  813. size: number;
  814. /**
  815. * Defines if mipmaps should not be generated (default is false)
  816. */
  817. noMipmap: boolean;
  818. /**
  819. * Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space,
  820. * but the standard material would require them in Gamma space) (default is true)
  821. */
  822. gammaSpace: boolean;
  823. /**
  824. * Gets the loaded texture
  825. */
  826. texture: EquiRectangularCubeTexture;
  827. /**
  828. * Callback called when the task is successful
  829. */
  830. onSuccess: (task: EquiRectangularCubeTextureAssetTask) => void;
  831. /**
  832. * Callback called when the task is successful
  833. */
  834. onError: (task: EquiRectangularCubeTextureAssetTask, message?: string, exception?: any) => void;
  835. /**
  836. * Creates a new EquiRectangularCubeTextureAssetTask object
  837. * @param name defines the name of the task
  838. * @param url defines the location of the file to load
  839. * @param size defines the desired size (the more it increases the longer the generation will be)
  840. * If the size is omitted this implies you are using a preprocessed cubemap.
  841. * @param noMipmap defines if mipmaps should not be generated (default is false)
  842. * @param gammaSpace specifies if the texture will be used in gamma or linear space
  843. * (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)
  844. * (default is true)
  845. */
  846. constructor(
  847. /**
  848. * Defines the name of the task
  849. */
  850. name: string,
  851. /**
  852. * Defines the location of the file to load
  853. */
  854. url: string,
  855. /**
  856. * Defines the desired size (the more it increases the longer the generation will be)
  857. */
  858. size: number,
  859. /**
  860. * Defines if mipmaps should not be generated (default is false)
  861. */
  862. noMipmap?: boolean,
  863. /**
  864. * Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space,
  865. * but the standard material would require them in Gamma space) (default is true)
  866. */
  867. gammaSpace?: boolean);
  868. /**
  869. * Execute the current task
  870. * @param scene defines the scene where you want your assets to be loaded
  871. * @param onSuccess is a callback called when the task is successfully executed
  872. * @param onError is a callback called if an error occurs
  873. */
  874. runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void): void;
  875. }
  876. /**
  877. * This class can be used to easily import assets into a scene
  878. * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/assetManager
  879. */
  880. export declare class AssetsManager {
  881. private _scene;
  882. private _isLoading;
  883. protected _tasks: AbstractAssetTask[];
  884. protected _waitingTasksCount: number;
  885. protected _totalTasksCount: number;
  886. /**
  887. * Callback called when all tasks are processed
  888. */
  889. onFinish: (tasks: AbstractAssetTask[]) => void;
  890. /**
  891. * Callback called when a task is successful
  892. */
  893. onTaskSuccess: (task: AbstractAssetTask) => void;
  894. /**
  895. * Callback called when a task had an error
  896. */
  897. onTaskError: (task: AbstractAssetTask) => void;
  898. /**
  899. * Callback called when a task is done (whatever the result is)
  900. */
  901. onProgress: (remainingCount: number, totalCount: number, task: AbstractAssetTask) => void;
  902. /**
  903. * Observable called when all tasks are processed
  904. */
  905. onTaskSuccessObservable: Observable<AbstractAssetTask>;
  906. /**
  907. * Observable called when a task had an error
  908. */
  909. onTaskErrorObservable: Observable<AbstractAssetTask>;
  910. /**
  911. * Observable called when all tasks were executed
  912. */
  913. onTasksDoneObservable: Observable<AbstractAssetTask[]>;
  914. /**
  915. * Observable called when a task is done (whatever the result is)
  916. */
  917. onProgressObservable: Observable<IAssetsProgressEvent>;
  918. /**
  919. * Gets or sets a boolean defining if the AssetsManager should use the default loading screen
  920. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/customLoadingScreen
  921. */
  922. useDefaultLoadingScreen: boolean;
  923. /**
  924. * Gets or sets a boolean defining if the AssetsManager should automatically hide the loading screen
  925. * when all assets have been downloaded.
  926. * If set to false, you need to manually call in hideLoadingUI() once your scene is ready.
  927. */
  928. autoHideLoadingUI: boolean;
  929. /**
  930. * Creates a new AssetsManager
  931. * @param scene defines the scene to work on
  932. */
  933. constructor(scene?: Scene);
  934. /**
  935. * Add a ContainerAssetTask to the list of active tasks
  936. * @param taskName defines the name of the new task
  937. * @param meshesNames defines the name of meshes to load
  938. * @param rootUrl defines the root url to use to locate files
  939. * @param sceneFilename defines the filename of the scene file or the File itself
  940. * @param extension defines the extension to use to load the file
  941. * @returns a new ContainerAssetTask object
  942. */
  943. addContainerTask(taskName: string, meshesNames: any, rootUrl: string, sceneFilename: string | File, extension?: string): ContainerAssetTask;
  944. /**
  945. * Add a MeshAssetTask to the list of active tasks
  946. * @param taskName defines the name of the new task
  947. * @param meshesNames defines the name of meshes to load
  948. * @param rootUrl defines the root url to use to locate files
  949. * @param sceneFilename defines the filename of the scene file or the File itself
  950. * @param extension defines the extension to use to load the file
  951. * @returns a new MeshAssetTask object
  952. */
  953. addMeshTask(taskName: string, meshesNames: any, rootUrl: string, sceneFilename: string | File, extension?: string): MeshAssetTask;
  954. /**
  955. * Add a TextFileAssetTask to the list of active tasks
  956. * @param taskName defines the name of the new task
  957. * @param url defines the url of the file to load
  958. * @returns a new TextFileAssetTask object
  959. */
  960. addTextFileTask(taskName: string, url: string): TextFileAssetTask;
  961. /**
  962. * Add a BinaryFileAssetTask to the list of active tasks
  963. * @param taskName defines the name of the new task
  964. * @param url defines the url of the file to load
  965. * @returns a new BinaryFileAssetTask object
  966. */
  967. addBinaryFileTask(taskName: string, url: string): BinaryFileAssetTask;
  968. /**
  969. * Add a ImageAssetTask to the list of active tasks
  970. * @param taskName defines the name of the new task
  971. * @param url defines the url of the file to load
  972. * @returns a new ImageAssetTask object
  973. */
  974. addImageTask(taskName: string, url: string): ImageAssetTask;
  975. /**
  976. * Add a TextureAssetTask to the list of active tasks
  977. * @param taskName defines the name of the new task
  978. * @param url defines the url of the file to load
  979. * @param noMipmap defines if the texture must not receive mipmaps (false by default)
  980. * @param invertY defines if you want to invert Y axis of the loaded texture (true by default)
  981. * @param samplingMode defines the sampling mode to use (Texture.TRILINEAR_SAMPLINGMODE by default)
  982. * @returns a new TextureAssetTask object
  983. */
  984. addTextureTask(taskName: string, url: string, noMipmap?: boolean, invertY?: boolean, samplingMode?: number): TextureAssetTask;
  985. /**
  986. * Add a CubeTextureAssetTask to the list of active tasks
  987. * @param taskName defines the name of the new task
  988. * @param url defines the url of the file to load
  989. * @param extensions defines the extension to use to load the cube map (can be null)
  990. * @param noMipmap defines if the texture must not receive mipmaps (false by default)
  991. * @param files defines the list of files to load (can be null)
  992. * @param prefiltered defines the prefiltered texture option (default is false)
  993. * @returns a new CubeTextureAssetTask object
  994. */
  995. addCubeTextureTask(taskName: string, url: string, extensions?: string[], noMipmap?: boolean, files?: string[], prefiltered?: boolean): CubeTextureAssetTask;
  996. /**
  997. *
  998. * Add a HDRCubeTextureAssetTask to the list of active tasks
  999. * @param taskName defines the name of the new task
  1000. * @param url defines the url of the file to load
  1001. * @param size defines the size you want for the cubemap (can be null)
  1002. * @param noMipmap defines if the texture must not receive mipmaps (false by default)
  1003. * @param generateHarmonics defines if you want to automatically generate (true by default)
  1004. * @param gammaSpace specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space) (default is false)
  1005. * @param reserved Internal use only
  1006. * @returns a new HDRCubeTextureAssetTask object
  1007. */
  1008. addHDRCubeTextureTask(taskName: string, url: string, size: number, noMipmap?: boolean, generateHarmonics?: boolean, gammaSpace?: boolean, reserved?: boolean): HDRCubeTextureAssetTask;
  1009. /**
  1010. *
  1011. * Add a EquiRectangularCubeTextureAssetTask to the list of active tasks
  1012. * @param taskName defines the name of the new task
  1013. * @param url defines the url of the file to load
  1014. * @param size defines the size you want for the cubemap (can be null)
  1015. * @param noMipmap defines if the texture must not receive mipmaps (false by default)
  1016. * @param gammaSpace Specifies if the texture will be used in gamma or linear space
  1017. * (the PBR material requires those textures in linear space, but the standard material would require them in Gamma space)
  1018. * @returns a new EquiRectangularCubeTextureAssetTask object
  1019. */
  1020. addEquiRectangularCubeTextureAssetTask(taskName: string, url: string, size: number, noMipmap?: boolean, gammaSpace?: boolean): EquiRectangularCubeTextureAssetTask;
  1021. /**
  1022. * Remove a task from the assets manager.
  1023. * @param task the task to remove
  1024. */
  1025. removeTask(task: AbstractAssetTask): void;
  1026. private _decreaseWaitingTasksCount;
  1027. private _runTask;
  1028. private _formatTaskErrorMessage;
  1029. /**
  1030. * Reset the AssetsManager and remove all tasks
  1031. * @returns the current instance of the AssetsManager
  1032. */
  1033. reset(): AssetsManager;
  1034. /**
  1035. * Start the loading process
  1036. * @returns the current instance of the AssetsManager
  1037. */
  1038. load(): AssetsManager;
  1039. /**
  1040. * Start the loading process as an async operation
  1041. * @returns a promise returning the list of failed tasks
  1042. */
  1043. loadAsync(): Promise<void>;
  1044. }