sceneLoader.ts 49 KB

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