viewer.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. import { viewerManager } from './viewerManager';
  2. import { SceneManager } from '../managers/sceneManager';
  3. import { ConfigurationLoader } from '../configuration/loader';
  4. import { Skeleton, AnimationGroup, ParticleSystem, CubeTexture, Color3, IEnvironmentHelperOptions, EnvironmentHelper, Effect, SceneOptimizer, SceneOptimizerOptions, Observable, Engine, Scene, ArcRotateCamera, Vector3, SceneLoader, AbstractMesh, Mesh, HemisphericLight, Database, SceneLoaderProgressEvent, ISceneLoaderPlugin, ISceneLoaderPluginAsync, Quaternion, Light, ShadowLight, ShadowGenerator, Tags, AutoRotationBehavior, BouncingBehavior, FramingBehavior, Behavior, Tools, RenderingManager } from 'babylonjs';
  5. import { ViewerConfiguration, ISceneConfiguration, ISceneOptimizerConfiguration, IObserversConfiguration, IModelConfiguration, ISkyboxConfiguration, IGroundConfiguration, ILightConfiguration, ICameraConfiguration } from '../configuration/';
  6. import { ViewerModel } from '../model/viewerModel';
  7. import { GroupModelAnimation } from '../model/modelAnimation';
  8. import { ModelLoader } from '../loader/modelLoader';
  9. import { CameraBehavior } from '../interfaces';
  10. import { viewerGlobals } from '../configuration/globals';
  11. import { extendClassWithConfig } from '../helper';
  12. import { telemetryManager } from '../managers/telemetryManager';
  13. import { deepmerge } from '../helper/';
  14. import { ObservablesManager } from '../managers/observablesManager';
  15. import { ConfigurationContainer } from '../configuration/configurationContainer';
  16. import { TemplateManager } from '../templating/templateManager';
  17. /**
  18. * The AbstractViewr is the center of Babylon's viewer.
  19. * It is the basic implementation of the default viewer and is responsible of loading and showing the model and the templates
  20. */
  21. export abstract class AbstractViewer {
  22. /**
  23. * The corresponsing template manager of this viewer.
  24. */
  25. public templateManager: TemplateManager;
  26. // TODO get the template manager to the default viewer, if no one is extending the abstract viewer
  27. /**
  28. * Babylon Engine corresponding with this viewer
  29. */
  30. public engine: Engine;
  31. /**
  32. * The ID of this viewer. it will be generated randomly or use the HTML Element's ID.
  33. */
  34. public readonly baseId: string;
  35. /**
  36. * The last loader used to load a model.
  37. * @deprecated
  38. */
  39. public lastUsedLoader: ISceneLoaderPlugin | ISceneLoaderPluginAsync;
  40. /**
  41. * The ModelLoader instance connected with this viewer.
  42. */
  43. public modelLoader: ModelLoader;
  44. /**
  45. * A flag that controls whether or not the render loop should be executed
  46. */
  47. public runRenderLoop: boolean = true;
  48. /**
  49. * The scene manager connected with this viewer instance
  50. */
  51. public sceneManager: SceneManager;
  52. // observables
  53. /**
  54. * Will notify when the scene was initialized
  55. */
  56. public get onSceneInitObservable(): Observable<Scene> {
  57. return this.observablesManager.onSceneInitObservable;
  58. }
  59. /**
  60. * will notify when the engine was initialized
  61. */
  62. public get onEngineInitObservable(): Observable<Engine> {
  63. return this.observablesManager.onEngineInitObservable;
  64. }
  65. /**
  66. * Will notify when a new model was added to the scene.
  67. * Note that added does not neccessarily mean loaded!
  68. */
  69. public get onModelAddedObservable(): Observable<ViewerModel> {
  70. return this.observablesManager.onModelAddedObservable;
  71. }
  72. /**
  73. * will notify after every model load
  74. */
  75. public get onModelLoadedObservable(): Observable<ViewerModel> {
  76. return this.observablesManager.onModelLoadedObservable;
  77. }
  78. /**
  79. * will notify when any model notify of progress
  80. */
  81. public get onModelLoadProgressObservable(): Observable<SceneLoaderProgressEvent> {
  82. return this.observablesManager.onModelLoadProgressObservable;
  83. }
  84. /**
  85. * will notify when any model load failed.
  86. */
  87. public get onModelLoadErrorObservable(): Observable<{ message: string; exception: any }> {
  88. return this.observablesManager.onModelLoadErrorObservable;
  89. }
  90. /**
  91. * Will notify when a model was removed from the scene;
  92. */
  93. public get onModelRemovedObservable(): Observable<ViewerModel> {
  94. return this.observablesManager.onModelRemovedObservable;
  95. }
  96. /**
  97. * will notify when a new loader was initialized.
  98. * Used mainly to know when a model starts loading.
  99. */
  100. public get onLoaderInitObservable(): Observable<ISceneLoaderPlugin | ISceneLoaderPluginAsync> {
  101. return this.observablesManager.onLoaderInitObservable;
  102. }
  103. /**
  104. * Observers registered here will be executed when the entire load process has finished.
  105. */
  106. public get onInitDoneObservable(): Observable<AbstractViewer> {
  107. return this.observablesManager.onViewerInitDoneObservable;
  108. }
  109. /**
  110. * Functions added to this observable will be executed on each frame rendered.
  111. */
  112. public get onFrameRenderedObservable(): Observable<AbstractViewer> {
  113. return this.observablesManager.onFrameRenderedObservable;
  114. }
  115. public observablesManager: ObservablesManager;
  116. /**
  117. * The canvas associated with this viewer
  118. */
  119. protected _canvas: HTMLCanvasElement;
  120. /**
  121. * The (single) canvas of this viewer
  122. */
  123. public get canvas(): HTMLCanvasElement {
  124. return this._canvas;
  125. }
  126. /**
  127. * is this viewer disposed?
  128. */
  129. protected _isDisposed: boolean = false;
  130. /**
  131. * registered onBeforeRender functions.
  132. * This functions are also registered at the native scene. The reference can be used to unregister them.
  133. */
  134. protected _registeredOnBeforeRenderFunctions: Array<() => void>;
  135. /**
  136. * The configuration loader of this viewer
  137. */
  138. protected _configurationLoader: ConfigurationLoader;
  139. /**
  140. * Is the viewer already initialized. for internal use.
  141. */
  142. protected _isInit: boolean;
  143. protected _configurationContainer: ConfigurationContainer;
  144. public get configurationContainer() {
  145. return this._configurationContainer;
  146. }
  147. constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
  148. // if exists, use the container id. otherwise, generate a random string.
  149. if (containerElement.id) {
  150. this.baseId = containerElement.id;
  151. } else {
  152. this.baseId = containerElement.id = 'bjs' + Math.random().toString(32).substr(2, 8);
  153. }
  154. this._registeredOnBeforeRenderFunctions = [];
  155. this._configurationContainer = new ConfigurationContainer();
  156. // add this viewer to the viewer manager
  157. viewerManager.addViewer(this);
  158. this.observablesManager = new ObservablesManager();
  159. this.modelLoader = new ModelLoader(this.observablesManager, this._configurationContainer);
  160. RenderingManager.AUTOCLEAR = false;
  161. // extend the configuration
  162. this._configurationLoader = new ConfigurationLoader();
  163. this._configurationLoader.loadConfiguration(initialConfiguration, (configuration) => {
  164. this._onConfigurationLoaded(configuration);
  165. });
  166. this.onSceneInitObservable.add(() => {
  167. this.updateConfiguration();
  168. });
  169. this.onInitDoneObservable.add(() => {
  170. this._isInit = true;
  171. this.engine.runRenderLoop(this._render);
  172. });
  173. this._prepareContainerElement();
  174. }
  175. /**
  176. * get the baseId of this viewer
  177. */
  178. public getBaseId(): string {
  179. return this.baseId;
  180. }
  181. /**
  182. * Do we have a canvas to render on, and is it a part of the scene
  183. */
  184. public isCanvasInDOM(): boolean {
  185. return !!this._canvas && !!this._canvas.parentElement;
  186. }
  187. /**
  188. * Is the engine currently set to rende even when the page is in background
  189. */
  190. public get renderInBackground() {
  191. return this.engine && this.engine.renderEvenInBackground;
  192. }
  193. /**
  194. * Set the viewer's background rendering flag.
  195. */
  196. public set renderInBackground(value: boolean) {
  197. if (this.engine) {
  198. this.engine.renderEvenInBackground = value;
  199. }
  200. }
  201. /**
  202. * Get the configuration object. This is a reference only.
  203. * The configuration can ONLY be updated using the updateConfiguration function.
  204. * changing this object will have no direct effect on the scene.
  205. */
  206. public get configuration(): ViewerConfiguration {
  207. return this._configurationContainer.configuration;
  208. }
  209. /**
  210. * force resizing the engine.
  211. */
  212. public forceResize() {
  213. this._resize();
  214. }
  215. protected _hdToggled: boolean = false;
  216. public toggleHD() {
  217. this._hdToggled = !this._hdToggled;
  218. var scale = this._hdToggled ? Math.max(0.5, 1 / (window.devicePixelRatio || 2)) : 1;
  219. this.engine.setHardwareScalingLevel(scale);
  220. }
  221. /**
  222. * The resize function that will be registered with the window object
  223. */
  224. protected _resize = (): void => {
  225. // Only resize if Canvas is in the DOM
  226. if (!this.isCanvasInDOM()) {
  227. return;
  228. }
  229. if (this.canvas.clientWidth <= 0 || this.canvas.clientHeight <= 0) {
  230. return;
  231. }
  232. if (this.configuration.engine && this.configuration.engine.disableResize) {
  233. return;
  234. }
  235. this.engine.resize();
  236. }
  237. protected _onConfigurationLoaded(configuration: ViewerConfiguration) {
  238. this._configurationContainer.configuration = deepmerge(this.configuration || {}, configuration);
  239. if (this.configuration.observers) {
  240. this._configureObservers(this.configuration.observers);
  241. }
  242. // TODO remove this after testing, as this is done in the updateCOnfiguration as well.
  243. if (this.configuration.loaderPlugins) {
  244. Object.keys(this.configuration.loaderPlugins).forEach((name => {
  245. if (this.configuration.loaderPlugins && this.configuration.loaderPlugins[name]) {
  246. this.modelLoader.addPlugin(name);
  247. }
  248. }))
  249. }
  250. this.templateManager = new TemplateManager(this.containerElement);
  251. }
  252. /**
  253. * Force a single render loop execution.
  254. */
  255. public forceRender() {
  256. this._render(true);
  257. }
  258. /**
  259. * render loop that will be executed by the engine
  260. */
  261. protected _render = (force: boolean = false): void => {
  262. if (force || (this.sceneManager.scene && this.sceneManager.scene.activeCamera)) {
  263. if (this.runRenderLoop || force) {
  264. this.engine.performanceMonitor.enable();
  265. this.sceneManager.scene.render();
  266. this.onFrameRenderedObservable.notifyObservers(this);
  267. } else {
  268. this.engine.performanceMonitor.disable();
  269. // update camera instead of rendering
  270. this.sceneManager.scene.activeCamera && this.sceneManager.scene.activeCamera.update();
  271. }
  272. }
  273. }
  274. /**
  275. * Takes a screenshot of the scene and returns it as a base64 encoded png.
  276. * @param callback optional callback that will be triggered when screenshot is done.
  277. * @param width Optional screenshot width (default to 512).
  278. * @param height Optional screenshot height (default to 512).
  279. * @returns a promise with the screenshot data
  280. */
  281. public takeScreenshot(callback?: (data: string) => void, width = 0, height = 0): Promise<string> {
  282. width = width || this.canvas.clientWidth;
  283. height = height || this.canvas.clientHeight;
  284. // Create the screenshot
  285. return new Promise<string>((resolve, reject) => {
  286. try {
  287. BABYLON.Tools.CreateScreenshot(this.engine, this.sceneManager.camera, { width, height }, (data) => {
  288. if (callback) {
  289. callback(data);
  290. }
  291. resolve(data);
  292. });
  293. } catch (e) {
  294. reject(e);
  295. }
  296. });
  297. }
  298. /**
  299. * Update the current viewer configuration with new values.
  300. * Only provided information will be updated, old configuration values will be kept.
  301. * If this.configuration was manually changed, you can trigger this function with no parameters,
  302. * and the entire configuration will be updated.
  303. * @param newConfiguration the partial configuration to update
  304. *
  305. */
  306. public updateConfiguration(newConfiguration: Partial<ViewerConfiguration> = this.configuration) {
  307. // update this.configuration with the new data
  308. this._configurationContainer.configuration = deepmerge(this.configuration || {}, newConfiguration);
  309. this.sceneManager.updateConfiguration(newConfiguration);
  310. // observers in configuration
  311. if (newConfiguration.observers) {
  312. this._configureObservers(newConfiguration.observers);
  313. }
  314. if (newConfiguration.loaderPlugins) {
  315. Object.keys(newConfiguration.loaderPlugins).forEach((name => {
  316. if (newConfiguration.loaderPlugins && newConfiguration.loaderPlugins[name]) {
  317. this.modelLoader.addPlugin(name);
  318. }
  319. }));
  320. }
  321. }
  322. /**
  323. * this is used to register native functions using the configuration object.
  324. * This will configure the observers.
  325. * @param observersConfiguration observers configuration
  326. */
  327. protected _configureObservers(observersConfiguration: IObserversConfiguration) {
  328. if (observersConfiguration.onEngineInit) {
  329. this.onEngineInitObservable.add(window[observersConfiguration.onEngineInit]);
  330. } else {
  331. if (observersConfiguration.onEngineInit === '' && this.configuration.observers && this.configuration.observers!.onEngineInit) {
  332. this.onEngineInitObservable.removeCallback(window[this.configuration.observers!.onEngineInit!]);
  333. }
  334. }
  335. if (observersConfiguration.onSceneInit) {
  336. this.onSceneInitObservable.add(window[observersConfiguration.onSceneInit]);
  337. } else {
  338. if (observersConfiguration.onSceneInit === '' && this.configuration.observers && this.configuration.observers!.onSceneInit) {
  339. this.onSceneInitObservable.removeCallback(window[this.configuration.observers!.onSceneInit!]);
  340. }
  341. }
  342. if (observersConfiguration.onModelLoaded) {
  343. this.onModelLoadedObservable.add(window[observersConfiguration.onModelLoaded]);
  344. } else {
  345. if (observersConfiguration.onModelLoaded === '' && this.configuration.observers && this.configuration.observers!.onModelLoaded) {
  346. this.onModelLoadedObservable.removeCallback(window[this.configuration.observers!.onModelLoaded!]);
  347. }
  348. }
  349. }
  350. /**
  351. * Dispoe the entire viewer including the scene and the engine
  352. */
  353. public dispose() {
  354. if (this._isDisposed) {
  355. return;
  356. }
  357. window.removeEventListener('resize', this._resize);
  358. if (this.sceneManager) {
  359. if (this.sceneManager.scene && this.sceneManager.scene.activeCamera) {
  360. this.sceneManager.scene.activeCamera.detachControl(this.canvas);
  361. }
  362. this.sceneManager.dispose();
  363. }
  364. this._fpsTimeoutInterval && clearInterval(this._fpsTimeoutInterval);
  365. this.observablesManager.dispose();
  366. this.modelLoader.dispose();
  367. if (this.engine) {
  368. this.engine.dispose();
  369. }
  370. viewerManager.removeViewer(this);
  371. this._isDisposed = true;
  372. }
  373. /**
  374. * This will prepare the container element for the viewer
  375. */
  376. protected abstract _prepareContainerElement();
  377. /**
  378. * This function will execute when the HTML templates finished initializing.
  379. * It should initialize the engine and continue execution.
  380. *
  381. * @returns {Promise<AbstractViewer>} The viewer object will be returned after the object was loaded.
  382. */
  383. protected _onTemplatesLoaded(): Promise<AbstractViewer> {
  384. return Promise.resolve(this);
  385. }
  386. /**
  387. * This will force the creation of an engine and a scene.
  388. * It will also load a model if preconfigured.
  389. * But first - it will load the extendible onTemplateLoaded()!
  390. */
  391. protected _onTemplateLoaded(): Promise<AbstractViewer> {
  392. // check if viewer was disposed right after created
  393. if (this._isDisposed) {
  394. return Promise.reject("viewer was disposed");
  395. }
  396. return this._onTemplatesLoaded().then(() => {
  397. let autoLoad = typeof this.configuration.model === 'string' || (this.configuration.model && this.configuration.model.url);
  398. return this._initEngine().then((engine) => {
  399. return this.onEngineInitObservable.notifyObserversWithPromise(engine);
  400. }).then(() => {
  401. this._initTelemetryEvents();
  402. if (autoLoad) {
  403. return this.loadModel(this.configuration.model!).catch(e => { }).then(() => { return this.sceneManager.scene });
  404. } else {
  405. return this.sceneManager.scene || this.sceneManager.initScene(this.configuration.scene);
  406. }
  407. }).then(() => {
  408. return this.onInitDoneObservable.notifyObserversWithPromise(this);
  409. }).catch(e => {
  410. Tools.Warn(e.toString());
  411. return this;
  412. });
  413. })
  414. }
  415. /**
  416. * Initialize the engine. Retruns a promise in case async calls are needed.
  417. *
  418. * @protected
  419. * @returns {Promise<Engine>}
  420. * @memberof Viewer
  421. */
  422. protected _initEngine(): Promise<Engine> {
  423. // init custom shaders
  424. this._injectCustomShaders();
  425. //let canvasElement = this.templateManager.getCanvas();
  426. if (!this.canvas) {
  427. return Promise.reject('Canvas element not found!');
  428. }
  429. let config = this.configuration.engine || {};
  430. // TDO enable further configuration
  431. // check for webgl2 support, force-disable if needed.
  432. if (viewerGlobals.disableWebGL2Support) {
  433. config.engineOptions = config.engineOptions || {};
  434. config.engineOptions.disableWebGL2Support = true;
  435. }
  436. this.engine = new Engine(this.canvas, !!config.antialiasing, config.engineOptions);
  437. // Disable manifest checking
  438. Database.IDBStorageEnabled = false;
  439. if (!config.disableResize) {
  440. window.addEventListener('resize', this._resize);
  441. }
  442. if (this.configuration.engine) {
  443. if (this.configuration.engine.adaptiveQuality) {
  444. var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
  445. this.engine.setHardwareScalingLevel(scale);
  446. }
  447. if (this.configuration.engine.hdEnabled) {
  448. this.toggleHD();
  449. }
  450. }
  451. // create a new template manager for this viewer
  452. this.sceneManager = new SceneManager(this.engine, this._configurationContainer, this.observablesManager);
  453. return Promise.resolve(this.engine);
  454. }
  455. private _isLoading: boolean;
  456. /**
  457. * Initialize a model loading. The returned object (a ViewerModel object) will be loaded in the background.
  458. * The difference between this and loadModel is that loadModel will fulfill the promise when the model finished loading.
  459. *
  460. * @param modelConfig model configuration to use when loading the model.
  461. * @param clearScene should the scene be cleared before loading this model
  462. * @returns a ViewerModel object that is not yet fully loaded.
  463. */
  464. public initModel(modelConfig: string | File | IModelConfiguration, clearScene: boolean = true): ViewerModel {
  465. let configuration: IModelConfiguration;
  466. if (typeof modelConfig === 'string') {
  467. configuration = {
  468. url: modelConfig
  469. }
  470. } else if (modelConfig instanceof File) {
  471. configuration = {
  472. file: modelConfig,
  473. root: "file:"
  474. }
  475. } else {
  476. configuration = modelConfig
  477. }
  478. if (!configuration.url && !configuration.file) {
  479. throw new Error("no model provided");
  480. }
  481. if (clearScene) {
  482. this.sceneManager.clearScene(true, false);
  483. }
  484. //merge the configuration for future models:
  485. if (this.configuration.model && typeof this.configuration.model === 'object') {
  486. let globalConfig = deepmerge({}, this.configuration.model)
  487. configuration = deepmerge(globalConfig, configuration);
  488. if (modelConfig instanceof File) {
  489. configuration.file = modelConfig;
  490. }
  491. } else {
  492. this.configuration.model = configuration;
  493. }
  494. this._isLoading = true;
  495. let model = this.modelLoader.load(configuration);
  496. this.lastUsedLoader = model.loader;
  497. model.onLoadErrorObservable.add((errorObject) => {
  498. this.onModelLoadErrorObservable.notifyObserversWithPromise(errorObject);
  499. });
  500. model.onLoadProgressObservable.add((progressEvent) => {
  501. this.onModelLoadProgressObservable.notifyObserversWithPromise(progressEvent);
  502. });
  503. this.onLoaderInitObservable.notifyObserversWithPromise(this.lastUsedLoader);
  504. model.onLoadedObservable.add(() => {
  505. this._isLoading = false;
  506. });
  507. return model;
  508. }
  509. /**
  510. * load a model using the provided configuration.
  511. * This function, as opposed to initModel, will return a promise that resolves when the model is loaded, and rejects with error.
  512. * If you want to attach to the observables of the model, use initModle instead.
  513. *
  514. * @param modelConfig the model configuration or URL to load.
  515. * @param clearScene Should the scene be cleared before loading the model
  516. * @returns a Promise the fulfills when the model finished loading successfully.
  517. */
  518. public loadModel(modelConfig: string | File | IModelConfiguration, clearScene: boolean = true): Promise<ViewerModel> {
  519. if (this._isLoading) {
  520. // We can decide here whether or not to cancel the lst load, but the developer can do that.
  521. return Promise.reject("another model is curently being loaded.");
  522. }
  523. return Promise.resolve(this.sceneManager.scene).then((scene) => {
  524. if (!scene) return this.sceneManager.initScene(this.configuration.scene, this.configuration.optimizer);
  525. return scene;
  526. }).then(() => {
  527. let model = this.initModel(modelConfig, clearScene);
  528. return new Promise<ViewerModel>((resolve, reject) => {
  529. // at this point, configuration.model is an object, not a string
  530. model.onLoadedObservable.add(() => {
  531. resolve(model);
  532. });
  533. model.onLoadErrorObservable.add((error) => {
  534. reject(error);
  535. });
  536. });
  537. })
  538. }
  539. private _fpsTimeoutInterval: number;
  540. protected _initTelemetryEvents() {
  541. telemetryManager.broadcast("Engine Capabilities", this.baseId, this.engine.getCaps());
  542. telemetryManager.broadcast("Platform Details", this.baseId, {
  543. userAgent: navigator.userAgent,
  544. platform: navigator.platform
  545. });
  546. telemetryManager.flushWebGLErrors(this.engine, this.baseId);
  547. let trackFPS: Function = () => {
  548. telemetryManager.broadcast("Current FPS", this.baseId, { fps: this.engine.getFps() });
  549. };
  550. trackFPS();
  551. // Track the FPS again after 60 seconds
  552. this._fpsTimeoutInterval = window.setInterval(trackFPS, 60 * 1000);
  553. }
  554. /**
  555. * Injects all the spectre shader in the babylon shader store
  556. */
  557. protected _injectCustomShaders(): void {
  558. let customShaders = this.configuration.customShaders;
  559. // Inject all the spectre shader in the babylon shader store.
  560. if (!customShaders) {
  561. return;
  562. }
  563. if (customShaders.shaders) {
  564. Object.keys(customShaders.shaders).forEach(key => {
  565. // typescript considers a callback "unsafe", so... '!'
  566. Effect.ShadersStore[key] = customShaders!.shaders![key];
  567. });
  568. }
  569. if (customShaders.includes) {
  570. Object.keys(customShaders.includes).forEach(key => {
  571. // typescript considers a callback "unsafe", so... '!'
  572. Effect.IncludesShadersStore[key] = customShaders!.includes![key];
  573. });
  574. }
  575. }
  576. }