sceneLoader.ts 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. import { Tools } from "../Misc/tools";
  2. import { Observable } from "../Misc/observable";
  3. import { FilesInputStore } from "../Misc/filesInputStore";
  4. import { Nullable } from "../types";
  5. import { Scene } from "../scene";
  6. import { Engine } from "../Engines/engine";
  7. import { EngineStore } from "../Engines/engineStore";
  8. import { AbstractMesh } from "../Meshes/abstractMesh";
  9. import { AnimationGroup } from "../Animations/animationGroup";
  10. import { _TimeToken } from "../Instrumentation/timeToken";
  11. import { AssetContainer } from "../assetContainer";
  12. import { IParticleSystem } from "../Particles/IParticleSystem";
  13. import { Skeleton } from "../Bones/skeleton";
  14. import { Logger } from "../Misc/logger";
  15. import { Constants } from "../Engines/constants";
  16. import { SceneLoaderFlags } from "./sceneLoaderFlags";
  17. import { IFileRequest } from "../Misc/fileRequest";
  18. import { WebRequest } from "../Misc/webRequest";
  19. import { RequestFileError, ReadFileError } from '../Misc/fileTools';
  20. import { Animation } from '../Animations';
  21. /**
  22. * Class used to represent data loading progression
  23. */
  24. export class SceneLoaderProgressEvent {
  25. /**
  26. * Create a new progress event
  27. * @param lengthComputable defines if data length to load can be evaluated
  28. * @param loaded defines the loaded data length
  29. * @param total defines the data length to load
  30. */
  31. constructor(
  32. /** defines if data length to load can be evaluated */
  33. public readonly lengthComputable: boolean,
  34. /** defines the loaded data length */
  35. public readonly loaded: number,
  36. /** defines the data length to load */
  37. public readonly total: number) {
  38. }
  39. /**
  40. * Creates a new SceneLoaderProgressEvent from a ProgressEvent
  41. * @param event defines the source event
  42. * @returns a new SceneLoaderProgressEvent
  43. */
  44. public static FromProgressEvent(event: ProgressEvent): SceneLoaderProgressEvent {
  45. return new SceneLoaderProgressEvent(event.lengthComputable, event.loaded, event.total);
  46. }
  47. }
  48. /**
  49. * Interface used by SceneLoader plugins to define supported file extensions
  50. */
  51. export interface ISceneLoaderPluginExtensions {
  52. /**
  53. * Defines the list of supported extensions
  54. */
  55. [extension: string]: {
  56. isBinary: boolean;
  57. };
  58. }
  59. /**
  60. * Interface used by SceneLoader plugin factory
  61. */
  62. export interface ISceneLoaderPluginFactory {
  63. /**
  64. * Defines the name of the factory
  65. */
  66. name: string;
  67. /**
  68. * Function called to create a new plugin
  69. * @return the new plugin
  70. */
  71. createPlugin(): ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  72. /**
  73. * The callback that returns true if the data can be directly loaded.
  74. * @param data string containing the file data
  75. * @returns if the data can be loaded directly
  76. */
  77. canDirectLoad?(data: string): boolean;
  78. }
  79. /**
  80. * Interface used to define the base of ISceneLoaderPlugin and ISceneLoaderPluginAsync
  81. */
  82. export interface ISceneLoaderPluginBase {
  83. /**
  84. * The friendly name of this plugin.
  85. */
  86. name: string;
  87. /**
  88. * The file extensions supported by this plugin.
  89. */
  90. extensions: string | ISceneLoaderPluginExtensions;
  91. /**
  92. * The callback called when loading from a url.
  93. * @param scene scene loading this url
  94. * @param url url to load
  95. * @param onSuccess callback called when the file successfully loads
  96. * @param onProgress callback called while file is loading (if the server supports this mode)
  97. * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer
  98. * @param onError callback called when the file fails to load
  99. * @returns a file request object
  100. */
  101. requestFile?(scene: Scene, url: string, onSuccess: (data: any, request?: WebRequest) => void, onProgress?: (ev: ProgressEvent) => void, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  102. /**
  103. * The callback called when loading from a file object.
  104. * @param scene scene loading this file
  105. * @param file defines the file to load
  106. * @param onSuccess defines the callback to call when data is loaded
  107. * @param onProgress defines the callback to call during loading process
  108. * @param useArrayBuffer defines a boolean indicating that data must be returned as an ArrayBuffer
  109. * @param onError defines the callback to call when an error occurs
  110. * @returns a file request object
  111. */
  112. readFile?(scene: Scene, file: File, onSuccess: (data: any) => void, onProgress?: (ev: ProgressEvent) => any, useArrayBuffer?: boolean, onError?: (error: any) => void): IFileRequest;
  113. /**
  114. * The callback that returns true if the data can be directly loaded.
  115. * @param data string containing the file data
  116. * @returns if the data can be loaded directly
  117. */
  118. canDirectLoad?(data: string): boolean;
  119. /**
  120. * The callback that returns the data to pass to the plugin if the data can be directly loaded.
  121. * @param scene scene loading this data
  122. * @param data string containing the data
  123. * @returns data to pass to the plugin
  124. */
  125. directLoad?(scene: Scene, data: string): any;
  126. /**
  127. * The callback that allows custom handling of the root url based on the response url.
  128. * @param rootUrl the original root url
  129. * @param responseURL the response url if available
  130. * @returns the new root url
  131. */
  132. rewriteRootURL?(rootUrl: string, responseURL?: string): string;
  133. }
  134. /**
  135. * Interface used to define a SceneLoader plugin
  136. */
  137. export interface ISceneLoaderPlugin extends ISceneLoaderPluginBase {
  138. /**
  139. * Import meshes into a scene.
  140. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  141. * @param scene The scene to import into
  142. * @param data The data to import
  143. * @param rootUrl The root url for scene and resources
  144. * @param meshes The meshes array to import into
  145. * @param particleSystems The particle systems array to import into
  146. * @param skeletons The skeletons array to import into
  147. * @param onError The callback when import fails
  148. * @returns True if successful or false otherwise
  149. */
  150. importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: AbstractMesh[], particleSystems: IParticleSystem[], skeletons: Skeleton[], onError?: (message: string, exception?: any) => void): boolean;
  151. /**
  152. * Load into a scene.
  153. * @param scene The scene to load into
  154. * @param data The data to import
  155. * @param rootUrl The root url for scene and resources
  156. * @param onError The callback when import fails
  157. * @returns True if successful or false otherwise
  158. */
  159. load(scene: Scene, data: any, rootUrl: string, onError?: (message: string, exception?: any) => void): boolean;
  160. /**
  161. * Load into an asset container.
  162. * @param scene The scene to load into
  163. * @param data The data to import
  164. * @param rootUrl The root url for scene and resources
  165. * @param onError The callback when import fails
  166. * @returns The loaded asset container
  167. */
  168. loadAssetContainer(scene: Scene, data: any, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer;
  169. }
  170. /**
  171. * Interface used to define an async SceneLoader plugin
  172. */
  173. export interface ISceneLoaderPluginAsync extends ISceneLoaderPluginBase {
  174. /**
  175. * Import meshes into a scene.
  176. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  177. * @param scene The scene to import into
  178. * @param data The data to import
  179. * @param rootUrl The root url for scene and resources
  180. * @param onProgress The callback when the load progresses
  181. * @param fileName Defines the name of the file to load
  182. * @returns The loaded meshes, particle systems, skeletons, and animation groups
  183. */
  184. importMeshAsync(meshesNames: any, scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<{ meshes: AbstractMesh[], particleSystems: IParticleSystem[], skeletons: Skeleton[], animationGroups: AnimationGroup[] }>;
  185. /**
  186. * Load into a scene.
  187. * @param scene The scene to load into
  188. * @param data The data to import
  189. * @param rootUrl The root url for scene and resources
  190. * @param onProgress The callback when the load progresses
  191. * @param fileName Defines the name of the file to load
  192. * @returns Nothing
  193. */
  194. loadAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
  195. /**
  196. * Load into an asset container.
  197. * @param scene The scene to load into
  198. * @param data The data to import
  199. * @param rootUrl The root url for scene and resources
  200. * @param onProgress The callback when the load progresses
  201. * @param fileName Defines the name of the file to load
  202. * @returns The loaded asset container
  203. */
  204. loadAssetContainerAsync(scene: Scene, data: any, rootUrl: string, onProgress?: (event: SceneLoaderProgressEvent) => void, fileName?: string): Promise<AssetContainer>;
  205. }
  206. /**
  207. * Mode that determines how to handle old animation groups before loading new ones.
  208. */
  209. export enum SceneLoaderAnimationGroupLoadingMode {
  210. /**
  211. * Reset all old animations to initial state then dispose them.
  212. */
  213. CLEAN = 0,
  214. /**
  215. * Stop all old animations.
  216. */
  217. STOP = 1,
  218. /**
  219. * Restart old animations from first frame.
  220. */
  221. SYNC = 2,
  222. /**
  223. * Old animations remains untouched.
  224. */
  225. NOSYNC = 3
  226. }
  227. /**
  228. * Defines a plugin registered by the SceneLoader
  229. */
  230. interface IRegisteredPlugin {
  231. /**
  232. * Defines the plugin to use
  233. */
  234. plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory;
  235. /**
  236. * Defines if the plugin supports binary data
  237. */
  238. isBinary: boolean;
  239. }
  240. /**
  241. * Defines file information
  242. */
  243. interface IFileInfo {
  244. /**
  245. * Gets the file url
  246. */
  247. url: string;
  248. /**
  249. * Gets the root url
  250. */
  251. rootUrl: string;
  252. /**
  253. * Gets filename
  254. */
  255. name: string;
  256. /**
  257. * Gets the file
  258. */
  259. file: Nullable<File>;
  260. }
  261. /**
  262. * Class used to load scene from various file formats using registered plugins
  263. * @see http://doc.babylonjs.com/how_to/load_from_any_file_type
  264. */
  265. export class SceneLoader {
  266. /**
  267. * No logging while loading
  268. */
  269. public static readonly NO_LOGGING = Constants.SCENELOADER_NO_LOGGING;
  270. /**
  271. * Minimal logging while loading
  272. */
  273. public static readonly MINIMAL_LOGGING = Constants.SCENELOADER_MINIMAL_LOGGING;
  274. /**
  275. * Summary logging while loading
  276. */
  277. public static readonly SUMMARY_LOGGING = Constants.SCENELOADER_SUMMARY_LOGGING;
  278. /**
  279. * Detailled logging while loading
  280. */
  281. public static readonly DETAILED_LOGGING = Constants.SCENELOADER_DETAILED_LOGGING;
  282. /**
  283. * Gets or sets a boolean indicating if entire scene must be loaded even if scene contains incremental data
  284. */
  285. public static get ForceFullSceneLoadingForIncremental() {
  286. return SceneLoaderFlags.ForceFullSceneLoadingForIncremental;
  287. }
  288. public static set ForceFullSceneLoadingForIncremental(value: boolean) {
  289. SceneLoaderFlags.ForceFullSceneLoadingForIncremental = value;
  290. }
  291. /**
  292. * Gets or sets a boolean indicating if loading screen must be displayed while loading a scene
  293. */
  294. public static get ShowLoadingScreen(): boolean {
  295. return SceneLoaderFlags.ShowLoadingScreen;
  296. }
  297. public static set ShowLoadingScreen(value: boolean) {
  298. SceneLoaderFlags.ShowLoadingScreen = value;
  299. }
  300. /**
  301. * Defines the current logging level (while loading the scene)
  302. * @ignorenaming
  303. */
  304. public static get loggingLevel(): number {
  305. return SceneLoaderFlags.loggingLevel;
  306. }
  307. public static set loggingLevel(value: number) {
  308. SceneLoaderFlags.loggingLevel = value;
  309. }
  310. /**
  311. * Gets or set a boolean indicating if matrix weights must be cleaned upon loading
  312. */
  313. public static get CleanBoneMatrixWeights(): boolean {
  314. return SceneLoaderFlags.CleanBoneMatrixWeights;
  315. }
  316. public static set CleanBoneMatrixWeights(value: boolean) {
  317. SceneLoaderFlags.CleanBoneMatrixWeights = value;
  318. }
  319. // Members
  320. /**
  321. * Event raised when a plugin is used to load a scene
  322. */
  323. public static OnPluginActivatedObservable = new Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync>();
  324. private static _registeredPlugins: { [extension: string]: IRegisteredPlugin } = {};
  325. private static _getDefaultPlugin(): IRegisteredPlugin {
  326. return SceneLoader._registeredPlugins[".babylon"];
  327. }
  328. private static _getPluginForExtension(extension: string): IRegisteredPlugin {
  329. var registeredPlugin = SceneLoader._registeredPlugins[extension];
  330. if (registeredPlugin) {
  331. return registeredPlugin;
  332. }
  333. Logger.Warn("Unable to find a plugin to load " + extension + " files. Trying to use .babylon default plugin. To load from a specific filetype (eg. gltf) see: http://doc.babylonjs.com/how_to/load_from_any_file_type");
  334. return SceneLoader._getDefaultPlugin();
  335. }
  336. private static _getPluginForDirectLoad(data: string): IRegisteredPlugin {
  337. for (var extension in SceneLoader._registeredPlugins) {
  338. var plugin = SceneLoader._registeredPlugins[extension].plugin;
  339. if (plugin.canDirectLoad && plugin.canDirectLoad(data)) {
  340. return SceneLoader._registeredPlugins[extension];
  341. }
  342. }
  343. return SceneLoader._getDefaultPlugin();
  344. }
  345. private static _getPluginForFilename(sceneFilename: string): IRegisteredPlugin {
  346. var queryStringPosition = sceneFilename.indexOf("?");
  347. if (queryStringPosition !== -1) {
  348. sceneFilename = sceneFilename.substring(0, queryStringPosition);
  349. }
  350. var dotPosition = sceneFilename.lastIndexOf(".");
  351. var extension = sceneFilename.substring(dotPosition, sceneFilename.length).toLowerCase();
  352. return SceneLoader._getPluginForExtension(extension);
  353. }
  354. private static _getDirectLoad(sceneFilename: string): Nullable<string> {
  355. if (sceneFilename.substr(0, 5) === "data:") {
  356. return sceneFilename.substr(5);
  357. }
  358. return null;
  359. }
  360. private static _loadData(fileInfo: IFileInfo, scene: Scene, onSuccess: (plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync, data: any, responseURL?: string) => void, onProgress: ((event: SceneLoaderProgressEvent) => void) | undefined, onError: (message: string, exception?: any) => void, onDispose: () => void, pluginExtension: Nullable<string>): Nullable<ISceneLoaderPlugin | ISceneLoaderPluginAsync> {
  361. const directLoad = SceneLoader._getDirectLoad(fileInfo.name);
  362. const registeredPlugin = pluginExtension ? SceneLoader._getPluginForExtension(pluginExtension) : (directLoad ? SceneLoader._getPluginForDirectLoad(fileInfo.name) : SceneLoader._getPluginForFilename(fileInfo.name));
  363. let plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  364. if ((registeredPlugin.plugin as ISceneLoaderPluginFactory).createPlugin) {
  365. plugin = (registeredPlugin.plugin as ISceneLoaderPluginFactory).createPlugin();
  366. }
  367. else {
  368. plugin = <any>registeredPlugin.plugin;
  369. }
  370. if (!plugin) {
  371. throw "The loader plugin corresponding to the file type you are trying to load has not been found. If using es6, please import the plugin you wish to use before.";
  372. }
  373. SceneLoader.OnPluginActivatedObservable.notifyObservers(plugin);
  374. if (directLoad) {
  375. onSuccess(plugin, plugin.directLoad ? plugin.directLoad(scene, directLoad) : directLoad);
  376. return plugin;
  377. }
  378. const useArrayBuffer = registeredPlugin.isBinary;
  379. const dataCallback = (data: any, responseURL?: string) => {
  380. if (scene.isDisposed) {
  381. onError("Scene has been disposed");
  382. return;
  383. }
  384. onSuccess(plugin, data, responseURL);
  385. };
  386. let request: Nullable<IFileRequest> = null;
  387. let pluginDisposed = false;
  388. const onDisposeObservable = (plugin as any).onDisposeObservable as Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync>;
  389. if (onDisposeObservable) {
  390. onDisposeObservable.add(() => {
  391. pluginDisposed = true;
  392. if (request) {
  393. request.abort();
  394. request = null;
  395. }
  396. onDispose();
  397. });
  398. }
  399. const progressCallback = onProgress ? (event: ProgressEvent) => {
  400. onProgress(SceneLoaderProgressEvent.FromProgressEvent(event));
  401. } : undefined;
  402. const manifestChecked = () => {
  403. if (pluginDisposed) {
  404. return;
  405. }
  406. const successCallback = (data: string | ArrayBuffer, request?: WebRequest) => {
  407. dataCallback(data, request ? request.responseURL : undefined);
  408. };
  409. const errorCallback = (error: RequestFileError) => {
  410. onError(error.message, error);
  411. };
  412. request = plugin.requestFile
  413. ? plugin.requestFile(scene, fileInfo.url, successCallback, progressCallback, useArrayBuffer, errorCallback)
  414. : scene._requestFile(fileInfo.url, successCallback, progressCallback, true, useArrayBuffer, errorCallback);
  415. };
  416. const file = fileInfo.file || FilesInputStore.FilesToLoad[fileInfo.name.toLowerCase()];
  417. if (fileInfo.rootUrl.indexOf("file:") === -1 || (fileInfo.rootUrl.indexOf("file:") !== -1 && !file)) {
  418. const engine = scene.getEngine();
  419. let canUseOfflineSupport = engine.enableOfflineSupport;
  420. if (canUseOfflineSupport) {
  421. // Also check for exceptions
  422. let exceptionFound = false;
  423. for (var regex of scene.disableOfflineSupportExceptionRules) {
  424. if (regex.test(fileInfo.url)) {
  425. exceptionFound = true;
  426. break;
  427. }
  428. }
  429. canUseOfflineSupport = !exceptionFound;
  430. }
  431. if (canUseOfflineSupport && Engine.OfflineProviderFactory) {
  432. // Checking if a manifest file has been set for this scene and if offline mode has been requested
  433. scene.offlineProvider = Engine.OfflineProviderFactory(fileInfo.url, manifestChecked, engine.disableManifestCheck);
  434. }
  435. else {
  436. manifestChecked();
  437. }
  438. }
  439. // Loading file from disk via input file or drag'n'drop
  440. else {
  441. if (file) {
  442. const errorCallback = (error: ReadFileError) => {
  443. onError(error.message, error);
  444. };
  445. request = plugin.readFile
  446. ? plugin.readFile(scene, file, dataCallback, progressCallback, useArrayBuffer, errorCallback)
  447. : scene._readFile(file, dataCallback, progressCallback, useArrayBuffer, errorCallback);
  448. } else {
  449. onError("Unable to find file named " + fileInfo.name);
  450. }
  451. }
  452. return plugin;
  453. }
  454. private static _getFileInfo(rootUrl: string, sceneFilename: string | File): Nullable<IFileInfo> {
  455. let url: string;
  456. let name: string;
  457. let file: Nullable<File> = null;
  458. if (!sceneFilename) {
  459. url = rootUrl;
  460. name = Tools.GetFilename(rootUrl);
  461. rootUrl = Tools.GetFolderPath(rootUrl);
  462. }
  463. else if ((sceneFilename as File).name) {
  464. const sceneFile = sceneFilename as File;
  465. url = rootUrl + sceneFile.name;
  466. name = sceneFile.name;
  467. file = sceneFile;
  468. }
  469. else {
  470. const filename = sceneFilename as string;
  471. if (filename.substr(0, 1) === "/") {
  472. Tools.Error("Wrong sceneFilename parameter");
  473. return null;
  474. }
  475. url = rootUrl + filename;
  476. name = filename;
  477. }
  478. return {
  479. url: url,
  480. rootUrl: rootUrl,
  481. name: name,
  482. file: file
  483. };
  484. }
  485. // Public functions
  486. /**
  487. * Gets a plugin that can load the given extension
  488. * @param extension defines the extension to load
  489. * @returns a plugin or null if none works
  490. */
  491. public static GetPluginForExtension(extension: string): ISceneLoaderPlugin | ISceneLoaderPluginAsync | ISceneLoaderPluginFactory {
  492. return SceneLoader._getPluginForExtension(extension).plugin;
  493. }
  494. /**
  495. * Gets a boolean indicating that the given extension can be loaded
  496. * @param extension defines the extension to load
  497. * @returns true if the extension is supported
  498. */
  499. public static IsPluginForExtensionAvailable(extension: string): boolean {
  500. return !!SceneLoader._registeredPlugins[extension];
  501. }
  502. /**
  503. * Adds a new plugin to the list of registered plugins
  504. * @param plugin defines the plugin to add
  505. */
  506. public static RegisterPlugin(plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync): void {
  507. if (typeof plugin.extensions === "string") {
  508. var extension = <string>plugin.extensions;
  509. SceneLoader._registeredPlugins[extension.toLowerCase()] = {
  510. plugin: plugin,
  511. isBinary: false
  512. };
  513. }
  514. else {
  515. var extensions = <ISceneLoaderPluginExtensions>plugin.extensions;
  516. Object.keys(extensions).forEach((extension) => {
  517. SceneLoader._registeredPlugins[extension.toLowerCase()] = {
  518. plugin: plugin,
  519. isBinary: extensions[extension].isBinary
  520. };
  521. });
  522. }
  523. }
  524. /**
  525. * Import meshes into a scene
  526. * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  527. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  528. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  529. * @param scene the instance of BABYLON.Scene to append to
  530. * @param onSuccess a callback with a list of imported meshes, particleSystems, and skeletons when import succeeds
  531. * @param onProgress a callback with a progress event for each file being loaded
  532. * @param onError a callback with the scene, a message, and possibly an exception when import fails
  533. * @param pluginExtension the extension used to determine the plugin
  534. * @returns The loaded plugin
  535. */
  536. public static ImportMesh(meshNames: any, rootUrl: string, sceneFilename: string | File = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, onSuccess: Nullable<(meshes: AbstractMesh[], particleSystems: IParticleSystem[], skeletons: Skeleton[], animationGroups: AnimationGroup[]) => void> = null, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null, pluginExtension: Nullable<string> = null): Nullable<ISceneLoaderPlugin | ISceneLoaderPluginAsync> {
  537. if (!scene) {
  538. Logger.Error("No scene available to import mesh to");
  539. return null;
  540. }
  541. const fileInfo = SceneLoader._getFileInfo(rootUrl, sceneFilename);
  542. if (!fileInfo) {
  543. return null;
  544. }
  545. var loadingToken = {};
  546. scene._addPendingData(loadingToken);
  547. var disposeHandler = () => {
  548. scene._removePendingData(loadingToken);
  549. };
  550. var errorHandler = (message: string, exception?: any) => {
  551. let errorMessage = "Unable to import meshes from " + fileInfo.url + ": " + message;
  552. if (onError) {
  553. onError(scene, errorMessage, exception);
  554. } else {
  555. Logger.Error(errorMessage);
  556. // should the exception be thrown?
  557. }
  558. disposeHandler();
  559. };
  560. var progressHandler = onProgress ? (event: SceneLoaderProgressEvent) => {
  561. try {
  562. onProgress(event);
  563. }
  564. catch (e) {
  565. errorHandler("Error in onProgress callback: " + e, e);
  566. }
  567. } : undefined;
  568. var successHandler = (meshes: AbstractMesh[], particleSystems: IParticleSystem[], skeletons: Skeleton[], animationGroups: AnimationGroup[]) => {
  569. scene.importedMeshesFiles.push(fileInfo.url);
  570. if (onSuccess) {
  571. try {
  572. onSuccess(meshes, particleSystems, skeletons, animationGroups);
  573. }
  574. catch (e) {
  575. errorHandler("Error in onSuccess callback: " + e, e);
  576. }
  577. }
  578. scene._removePendingData(loadingToken);
  579. };
  580. return SceneLoader._loadData(fileInfo, scene, (plugin, data, responseURL) => {
  581. if (plugin.rewriteRootURL) {
  582. fileInfo.rootUrl = plugin.rewriteRootURL(fileInfo.rootUrl, responseURL);
  583. }
  584. if ((<any>plugin).importMesh) {
  585. var syncedPlugin = <ISceneLoaderPlugin>plugin;
  586. var meshes = new Array<AbstractMesh>();
  587. var particleSystems = new Array<IParticleSystem>();
  588. var skeletons = new Array<Skeleton>();
  589. if (!syncedPlugin.importMesh(meshNames, scene, data, fileInfo.rootUrl, meshes, particleSystems, skeletons, errorHandler)) {
  590. return;
  591. }
  592. scene.loadingPluginName = plugin.name;
  593. successHandler(meshes, particleSystems, skeletons, []);
  594. }
  595. else {
  596. var asyncedPlugin = <ISceneLoaderPluginAsync>plugin;
  597. asyncedPlugin.importMeshAsync(meshNames, scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name).then((result) => {
  598. scene.loadingPluginName = plugin.name;
  599. successHandler(result.meshes, result.particleSystems, result.skeletons, result.animationGroups);
  600. }).catch((error) => {
  601. errorHandler(error.message, error);
  602. });
  603. }
  604. }, progressHandler, errorHandler, disposeHandler, pluginExtension);
  605. }
  606. /**
  607. * Import meshes into a scene
  608. * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  609. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  610. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  611. * @param scene the instance of BABYLON.Scene to append to
  612. * @param onProgress a callback with a progress event for each file being loaded
  613. * @param pluginExtension the extension used to determine the plugin
  614. * @returns The loaded list of imported meshes, particle systems, skeletons, and animation groups
  615. */
  616. public static ImportMeshAsync(meshNames: any, rootUrl: string, sceneFilename: string | File = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, pluginExtension: Nullable<string> = null): Promise<{ meshes: AbstractMesh[], particleSystems: IParticleSystem[], skeletons: Skeleton[], animationGroups: AnimationGroup[] }> {
  617. return new Promise((resolve, reject) => {
  618. SceneLoader.ImportMesh(meshNames, rootUrl, sceneFilename, scene, (meshes, particleSystems, skeletons, animationGroups) => {
  619. resolve({
  620. meshes: meshes,
  621. particleSystems: particleSystems,
  622. skeletons: skeletons,
  623. animationGroups: animationGroups
  624. });
  625. }, onProgress, (scene, message, exception) => {
  626. reject(exception || new Error(message));
  627. },
  628. pluginExtension);
  629. });
  630. }
  631. /**
  632. * Load a scene
  633. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  634. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  635. * @param engine is the instance of BABYLON.Engine to use to create the scene
  636. * @param onSuccess a callback with the scene when import succeeds
  637. * @param onProgress a callback with a progress event for each file being loaded
  638. * @param onError a callback with the scene, a message, and possibly an exception when import fails
  639. * @param pluginExtension the extension used to determine the plugin
  640. * @returns The loaded plugin
  641. */
  642. public static Load(rootUrl: string, sceneFilename: string | File = "", engine: Nullable<Engine> = EngineStore.LastCreatedEngine, onSuccess: Nullable<(scene: Scene) => void> = null, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null, pluginExtension: Nullable<string> = null): Nullable<ISceneLoaderPlugin | ISceneLoaderPluginAsync> {
  643. if (!engine) {
  644. Tools.Error("No engine available");
  645. return null;
  646. }
  647. return SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension);
  648. }
  649. /**
  650. * Load a scene
  651. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  652. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  653. * @param engine is the instance of BABYLON.Engine to use to create the scene
  654. * @param onProgress a callback with a progress event for each file being loaded
  655. * @param pluginExtension the extension used to determine the plugin
  656. * @returns The loaded scene
  657. */
  658. public static LoadAsync(rootUrl: string, sceneFilename: string | File = "", engine: Nullable<Engine> = EngineStore.LastCreatedEngine, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, pluginExtension: Nullable<string> = null): Promise<Scene> {
  659. return new Promise((resolve, reject) => {
  660. SceneLoader.Load(rootUrl, sceneFilename, engine, (scene) => {
  661. resolve(scene);
  662. }, onProgress, (scene, message, exception) => {
  663. reject(exception || new Error(message));
  664. }, pluginExtension);
  665. });
  666. }
  667. /**
  668. * Append a scene
  669. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  670. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  671. * @param scene is the instance of BABYLON.Scene to append to
  672. * @param onSuccess a callback with the scene when import succeeds
  673. * @param onProgress a callback with a progress event for each file being loaded
  674. * @param onError a callback with the scene, a message, and possibly an exception when import fails
  675. * @param pluginExtension the extension used to determine the plugin
  676. * @returns The loaded plugin
  677. */
  678. public static Append(rootUrl: string, sceneFilename: string | File = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, onSuccess: Nullable<(scene: Scene) => void> = null, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null, pluginExtension: Nullable<string> = null): Nullable<ISceneLoaderPlugin | ISceneLoaderPluginAsync> {
  679. if (!scene) {
  680. Logger.Error("No scene available to append to");
  681. return null;
  682. }
  683. const fileInfo = SceneLoader._getFileInfo(rootUrl, sceneFilename);
  684. if (!fileInfo) {
  685. return null;
  686. }
  687. if (SceneLoader.ShowLoadingScreen) {
  688. scene.getEngine().displayLoadingUI();
  689. }
  690. var loadingToken = {};
  691. scene._addPendingData(loadingToken);
  692. var disposeHandler = () => {
  693. scene._removePendingData(loadingToken);
  694. scene.getEngine().hideLoadingUI();
  695. };
  696. var errorHandler = (message: Nullable<string>, exception?: any) => {
  697. let errorMessage = "Unable to load from " + fileInfo.url + (message ? ": " + message : "");
  698. if (onError) {
  699. onError(scene, errorMessage, exception);
  700. } else {
  701. Logger.Error(errorMessage);
  702. // should the exception be thrown?
  703. }
  704. disposeHandler();
  705. };
  706. var progressHandler = onProgress ? (event: SceneLoaderProgressEvent) => {
  707. try {
  708. onProgress(event);
  709. }
  710. catch (e) {
  711. errorHandler("Error in onProgress callback", e);
  712. }
  713. } : undefined;
  714. var successHandler = () => {
  715. if (onSuccess) {
  716. try {
  717. onSuccess(scene);
  718. }
  719. catch (e) {
  720. errorHandler("Error in onSuccess callback", e);
  721. }
  722. }
  723. scene._removePendingData(loadingToken);
  724. };
  725. return SceneLoader._loadData(fileInfo, scene, (plugin, data) => {
  726. if ((<any>plugin).load) {
  727. var syncedPlugin = <ISceneLoaderPlugin>plugin;
  728. if (!syncedPlugin.load(scene, data, fileInfo.rootUrl, errorHandler)) {
  729. return;
  730. }
  731. scene.loadingPluginName = plugin.name;
  732. successHandler();
  733. } else {
  734. var asyncedPlugin = <ISceneLoaderPluginAsync>plugin;
  735. asyncedPlugin.loadAsync(scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name).then(() => {
  736. scene.loadingPluginName = plugin.name;
  737. successHandler();
  738. }).catch((error) => {
  739. errorHandler(error.message, error);
  740. });
  741. }
  742. if (SceneLoader.ShowLoadingScreen) {
  743. scene.executeWhenReady(() => {
  744. scene.getEngine().hideLoadingUI();
  745. });
  746. }
  747. }, progressHandler, errorHandler, disposeHandler, pluginExtension);
  748. }
  749. /**
  750. * Append a scene
  751. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  752. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  753. * @param scene is the instance of BABYLON.Scene to append to
  754. * @param onProgress a callback with a progress event for each file being loaded
  755. * @param pluginExtension the extension used to determine the plugin
  756. * @returns The given scene
  757. */
  758. public static AppendAsync(rootUrl: string, sceneFilename: string | File = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, pluginExtension: Nullable<string> = null): Promise<Scene> {
  759. return new Promise((resolve, reject) => {
  760. SceneLoader.Append(rootUrl, sceneFilename, scene, (scene) => {
  761. resolve(scene);
  762. }, onProgress, (scene, message, exception) => {
  763. reject(exception || new Error(message));
  764. }, pluginExtension);
  765. });
  766. }
  767. /**
  768. * Load a scene into an asset container
  769. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  770. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  771. * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)
  772. * @param onSuccess a callback with the scene when import succeeds
  773. * @param onProgress a callback with a progress event for each file being loaded
  774. * @param onError a callback with the scene, a message, and possibly an exception when import fails
  775. * @param pluginExtension the extension used to determine the plugin
  776. * @returns The loaded plugin
  777. */
  778. public static LoadAssetContainer(
  779. rootUrl: string,
  780. sceneFilename: string | File = "",
  781. scene: Nullable<Scene> = EngineStore.LastCreatedScene,
  782. onSuccess: Nullable<(assets: AssetContainer) => void> = null,
  783. onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null,
  784. onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null,
  785. pluginExtension: Nullable<string> = null
  786. ): Nullable<ISceneLoaderPlugin | ISceneLoaderPluginAsync> {
  787. if (!scene) {
  788. Logger.Error("No scene available to load asset container to");
  789. return null;
  790. }
  791. const fileInfo = SceneLoader._getFileInfo(rootUrl, sceneFilename);
  792. if (!fileInfo) {
  793. return null;
  794. }
  795. var loadingToken = {};
  796. scene._addPendingData(loadingToken);
  797. var disposeHandler = () => {
  798. scene._removePendingData(loadingToken);
  799. };
  800. var errorHandler = (message: Nullable<string>, exception?: any) => {
  801. let errorMessage = "Unable to load assets from " + fileInfo.url + (message ? ": " + message : "");
  802. if (exception && exception.message) {
  803. errorMessage += ` (${exception.message})`;
  804. }
  805. if (onError) {
  806. onError(scene, errorMessage, exception);
  807. } else {
  808. Logger.Error(errorMessage);
  809. // should the exception be thrown?
  810. }
  811. disposeHandler();
  812. };
  813. var progressHandler = onProgress ? (event: SceneLoaderProgressEvent) => {
  814. try {
  815. onProgress(event);
  816. }
  817. catch (e) {
  818. errorHandler("Error in onProgress callback", e);
  819. }
  820. } : undefined;
  821. var successHandler = (assets: AssetContainer) => {
  822. if (onSuccess) {
  823. try {
  824. onSuccess(assets);
  825. }
  826. catch (e) {
  827. errorHandler("Error in onSuccess callback", e);
  828. }
  829. }
  830. scene._removePendingData(loadingToken);
  831. };
  832. return SceneLoader._loadData(fileInfo, scene, (plugin, data) => {
  833. if ((<any>plugin).loadAssetContainer) {
  834. var syncedPlugin = <ISceneLoaderPlugin>plugin;
  835. var assetContainer = syncedPlugin.loadAssetContainer(scene, data, fileInfo.rootUrl, errorHandler);
  836. if (!assetContainer) {
  837. return;
  838. }
  839. scene.loadingPluginName = plugin.name;
  840. successHandler(assetContainer);
  841. } else if ((<any>plugin).loadAssetContainerAsync) {
  842. var asyncedPlugin = <ISceneLoaderPluginAsync>plugin;
  843. asyncedPlugin.loadAssetContainerAsync(scene, data, fileInfo.rootUrl, progressHandler, fileInfo.name).then((assetContainer) => {
  844. scene.loadingPluginName = plugin.name;
  845. successHandler(assetContainer);
  846. }).catch((error) => {
  847. errorHandler(error.message, error);
  848. });
  849. } else {
  850. errorHandler("LoadAssetContainer is not supported by this plugin. Plugin did not provide a loadAssetContainer or loadAssetContainerAsync method.");
  851. }
  852. if (SceneLoader.ShowLoadingScreen) {
  853. scene.executeWhenReady(() => {
  854. scene.getEngine().hideLoadingUI();
  855. });
  856. }
  857. }, progressHandler, errorHandler, disposeHandler, pluginExtension);
  858. }
  859. /**
  860. * Load a scene into an asset container
  861. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  862. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene (default: empty string)
  863. * @param scene is the instance of Scene to append to
  864. * @param onProgress a callback with a progress event for each file being loaded
  865. * @param pluginExtension the extension used to determine the plugin
  866. * @returns The loaded asset container
  867. */
  868. public static LoadAssetContainerAsync(rootUrl: string, sceneFilename: string = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, pluginExtension: Nullable<string> = null): Promise<AssetContainer> {
  869. return new Promise((resolve, reject) => {
  870. SceneLoader.LoadAssetContainer(rootUrl, sceneFilename, scene, (assetContainer) => {
  871. resolve(assetContainer);
  872. }, onProgress, (scene, message, exception) => {
  873. reject(exception || new Error(message));
  874. }, pluginExtension);
  875. });
  876. }
  877. /**
  878. * Import animations from a file into a scene
  879. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  880. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  881. * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)
  882. * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise
  883. * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones
  884. * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)
  885. * @param onSuccess a callback with the scene when import succeeds
  886. * @param onProgress a callback with a progress event for each file being loaded
  887. * @param onError a callback with the scene, a message, and possibly an exception when import fails
  888. */
  889. public static ImportAnimations(rootUrl: string, sceneFilename: string | File = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = SceneLoaderAnimationGroupLoadingMode.CLEAN, targetConverter: Nullable<(target: any) => any> = null, onSuccess: Nullable<(scene: Scene) => void> = null, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null): void {
  890. if (!scene) {
  891. Logger.Error("No scene available to load animations to");
  892. return;
  893. }
  894. let onAssetContainerLoaded = (container: AssetContainer) => {
  895. container.MergeAnimationsTo(scene, targetConverter);
  896. container.dispose();
  897. scene.onAnimationFileImportedObservable.notifyObservers(scene);
  898. if (onSuccess) {
  899. onSuccess(scene);
  900. }
  901. };
  902. if (overwriteAnimations) {
  903. // Reset, stop and dispose all animations before loading new ones
  904. for (let animatable of scene.animatables) {
  905. animatable.reset();
  906. }
  907. scene.stopAllAnimations();
  908. scene.animationGroups.slice().forEach(animationGroup => {
  909. animationGroup.dispose();
  910. });
  911. let nodes = scene.getNodes();
  912. nodes.forEach(node => {
  913. node.animations = new Array<Animation>();
  914. });
  915. }
  916. else {
  917. switch (animationGroupLoadingMode) {
  918. case SceneLoaderAnimationGroupLoadingMode.CLEAN:
  919. scene.animationGroups.slice().forEach(animationGroup => {
  920. animationGroup.dispose();
  921. });
  922. break;
  923. case SceneLoaderAnimationGroupLoadingMode.STOP:
  924. scene.animationGroups.forEach(animationGroup => {
  925. animationGroup.stop();
  926. });
  927. break;
  928. case SceneLoaderAnimationGroupLoadingMode.SYNC:
  929. scene.animationGroups.forEach(animationGroup => {
  930. animationGroup.reset();
  931. animationGroup.restart();
  932. });
  933. break;
  934. case SceneLoaderAnimationGroupLoadingMode.NOSYNC:
  935. // nothing to do
  936. break;
  937. default:
  938. Logger.Error("Unknown animation group loading mode value '" + animationGroupLoadingMode + "'");
  939. return;
  940. }
  941. }
  942. this.LoadAssetContainer(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError);
  943. }
  944. /**
  945. * Import animations from a file into a scene
  946. * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
  947. * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
  948. * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)
  949. * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise
  950. * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones
  951. * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)
  952. * @param onSuccess a callback with the scene when import succeeds
  953. * @param onProgress a callback with a progress event for each file being loaded
  954. * @param onError a callback with the scene, a message, and possibly an exception when import fails
  955. */
  956. public static ImportAnimationsAsync(rootUrl: string, sceneFilename: string | File = "", scene: Nullable<Scene> = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = SceneLoaderAnimationGroupLoadingMode.CLEAN, targetConverter: Nullable<(target: any) => any> = null, onSuccess: Nullable<(scene: Scene) => void> = null, onProgress: Nullable<(event: SceneLoaderProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null): Promise<Scene> {
  957. return new Promise((resolve, reject) => {
  958. SceneLoader.ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, (_scene: Scene) => {
  959. resolve(_scene);
  960. }, onProgress, (_scene: Scene, message: string, exception: any) => {
  961. reject(exception || new Error(message));
  962. });
  963. });
  964. }
  965. }