babylon.environmentHelper.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. module BABYLON {
  2. /**
  3. * Represents the different options available during the creation of
  4. * a Environment helper.
  5. *
  6. * This can control the default ground, skybox and image processing setup of your scene.
  7. */
  8. export interface IEnvironmentHelperOptions {
  9. /**
  10. * Specifies wether or not to create a ground.
  11. * True by default.
  12. */
  13. createGround: boolean;
  14. /**
  15. * Specifies the ground size.
  16. * 15 by default.
  17. */
  18. groundSize: number;
  19. /**
  20. * The texture used on the ground for the main color.
  21. * Comes from the BabylonJS CDN by default.
  22. *
  23. * Remarks: Can be either a texture or a url.
  24. */
  25. groundTexture: string | BaseTexture;
  26. /**
  27. * The color mixed in the ground texture by default.
  28. * BabylonJS clearColor by default.
  29. */
  30. groundColor: Color3;
  31. /**
  32. * Specifies the ground opacity.
  33. * 1 by default.
  34. */
  35. groundOpacity: number;
  36. /**
  37. * Enables the ground to receive shadows.
  38. * True by default.
  39. */
  40. enableGroundShadow: boolean;
  41. /**
  42. * Helps preventing the shadow to be fully black on the ground.
  43. * 0.5 by default.
  44. */
  45. groundShadowLevel: number;
  46. /**
  47. * Creates a mirror texture attach to the ground.
  48. * false by default.
  49. */
  50. enableGroundMirror: boolean;
  51. /**
  52. * Specifies the ground mirror size ratio.
  53. * 0.3 by default as the default kernel is 64.
  54. */
  55. groundMirrorSizeRatio: number;
  56. /**
  57. * Specifies the ground mirror blur kernel size.
  58. * 64 by default.
  59. */
  60. groundMirrorBlurKernel: number;
  61. /**
  62. * Specifies the ground mirror visibility amount.
  63. * 1 by default
  64. */
  65. groundMirrorAmount: number;
  66. /**
  67. * Specifies the ground mirror reflectance weight.
  68. * This uses the standard weight of the background material to setup the fresnel effect
  69. * of the mirror.
  70. * 1 by default.
  71. */
  72. groundMirrorFresnelWeight: number;
  73. /**
  74. * Specifies the ground mirror Falloff distance.
  75. * This can helps reducing the size of the reflection.
  76. * 0 by Default.
  77. */
  78. groundMirrorFallOffDistance: number;
  79. /**
  80. * Specifies the ground mirror texture type.
  81. * Unsigned Int by Default.
  82. */
  83. groundMirrorTextureType: number;
  84. /**
  85. * Specifies a bias applied to the ground vertical position to prevent z-fighyting with
  86. * the shown objects.
  87. */
  88. groundYBias: number;
  89. /**
  90. * Specifies wether or not to create a skybox.
  91. * True by default.
  92. */
  93. createSkybox: boolean;
  94. /**
  95. * Specifies the skybox size.
  96. * 20 by default.
  97. */
  98. skyboxSize: number;
  99. /**
  100. * The texture used on the skybox for the main color.
  101. * Comes from the BabylonJS CDN by default.
  102. *
  103. * Remarks: Can be either a texture or a url.
  104. */
  105. skyboxTexture: string | BaseTexture;
  106. /**
  107. * The color mixed in the skybox texture by default.
  108. * BabylonJS clearColor by default.
  109. */
  110. skyboxColor: Color3;
  111. /**
  112. * The background rotation around the Y axis of the scene.
  113. * This helps aligning the key lights of your scene with the background.
  114. * 0 by default.
  115. */
  116. backgroundYRotation: number;
  117. /**
  118. * Compute automatically the size of the elements to best fit with the scene.
  119. */
  120. sizeAuto: boolean;
  121. /**
  122. * Default position of the rootMesh if autoSize is not true.
  123. */
  124. rootPosition: Vector3;
  125. /**
  126. * Sets up the image processing in the scene.
  127. * true by default.
  128. */
  129. setupImageProcessing: boolean;
  130. /**
  131. * The texture used as your environment texture in the scene.
  132. * Comes from the BabylonJS CDN by default and in use if setupImageProcessing is true.
  133. *
  134. * Remarks: Can be either a texture or a url.
  135. */
  136. environmentTexture: string | BaseTexture;
  137. /**
  138. * The value of the exposure to apply to the scene.
  139. * 0.6 by default if setupImageProcessing is true.
  140. */
  141. cameraExposure: number;
  142. /**
  143. * The value of the contrast to apply to the scene.
  144. * 1.6 by default if setupImageProcessing is true.
  145. */
  146. cameraContrast: number;
  147. /**
  148. * Specifies wether or not tonemapping should be enabled in the scene.
  149. * true by default if setupImageProcessing is true.
  150. */
  151. toneMappingEnabled: boolean;
  152. }
  153. interface ISceneSize {
  154. groundSize: number,
  155. skyboxSize: number,
  156. rootPosition: Vector3
  157. }
  158. /**
  159. * The Environment helper class can be used to add a fully featuread none expensive background to your scene.
  160. * It includes by default a skybox and a ground relying on the BackgroundMaterial.
  161. * It also helps with the default setup of your imageProcessing configuration.
  162. */
  163. export class EnvironmentHelper {
  164. /**
  165. * Default ground texture URL.
  166. */
  167. private static _groundTextureCDNUrl = "https://assets.babylonjs.com/environments/backgroundGround.png";
  168. /**
  169. * Default skybox texture URL.
  170. */
  171. private static _skyboxTextureCDNUrl = "https://assets.babylonjs.com/environments/backgroundSkybox.dds";
  172. /**
  173. * Default environment texture URL.
  174. */
  175. private static _environmentTextureCDNUrl = "https://assets.babylonjs.com/environments/environmentSpecular.dds";
  176. /**
  177. * Creates the default options for the helper.
  178. */
  179. private static _getDefaultOptions(): IEnvironmentHelperOptions {
  180. return {
  181. createGround: true,
  182. groundSize: 15,
  183. groundTexture: this._groundTextureCDNUrl,
  184. groundColor: new Color3(0.2, 0.2, 0.3).toLinearSpace().scale(3),
  185. groundOpacity: 0.9,
  186. enableGroundShadow: true,
  187. groundShadowLevel: 0.5,
  188. enableGroundMirror: false,
  189. groundMirrorSizeRatio: 0.3,
  190. groundMirrorBlurKernel: 64,
  191. groundMirrorAmount: 1,
  192. groundMirrorFresnelWeight: 1,
  193. groundMirrorFallOffDistance: 0,
  194. groundMirrorTextureType: Engine.TEXTURETYPE_UNSIGNED_INT,
  195. groundYBias: 0.00001,
  196. createSkybox: true,
  197. skyboxSize: 20,
  198. skyboxTexture: this._skyboxTextureCDNUrl,
  199. skyboxColor: new Color3(0.2, 0.2, 0.3).toLinearSpace().scale(3),
  200. backgroundYRotation: 0,
  201. sizeAuto: true,
  202. rootPosition: Vector3.Zero(),
  203. setupImageProcessing: true,
  204. environmentTexture: this._environmentTextureCDNUrl,
  205. cameraExposure: 0.8,
  206. cameraContrast: 1.2,
  207. toneMappingEnabled: true,
  208. };
  209. }
  210. private _rootMesh: Mesh;
  211. /**
  212. * Gets the root mesh created by the helper.
  213. */
  214. public get rootMesh(): Mesh {
  215. return this._rootMesh;
  216. }
  217. private _skybox: Nullable<Mesh>;
  218. /**
  219. * Gets the skybox created by the helper.
  220. */
  221. public get skybox(): Nullable<Mesh> {
  222. return this._skybox;
  223. }
  224. private _skyboxTexture: Nullable<BaseTexture>;
  225. /**
  226. * Gets the skybox texture created by the helper.
  227. */
  228. public get skyboxTexture(): Nullable<BaseTexture> {
  229. return this._skyboxTexture;
  230. }
  231. private _skyboxMaterial: Nullable<BackgroundMaterial>;
  232. /**
  233. * Gets the skybox material created by the helper.
  234. */
  235. public get skyboxMaterial(): Nullable<BackgroundMaterial> {
  236. return this._skyboxMaterial;
  237. }
  238. private _ground: Nullable<Mesh>;
  239. /**
  240. * Gets the ground mesh created by the helper.
  241. */
  242. public get ground(): Nullable<Mesh> {
  243. return this._ground;
  244. }
  245. private _groundTexture: Nullable<BaseTexture>;
  246. /**
  247. * Gets the ground texture created by the helper.
  248. */
  249. public get groundTexture(): Nullable<BaseTexture> {
  250. return this._groundTexture;
  251. }
  252. private _groundMirror: Nullable<MirrorTexture>;
  253. /**
  254. * Gets the ground mirror created by the helper.
  255. */
  256. public get groundMirror(): Nullable<MirrorTexture> {
  257. return this._groundMirror;
  258. }
  259. /**
  260. * Gets the ground mirror render list to helps pushing the meshes
  261. * you wish in the ground reflection.
  262. */
  263. public get groundMirrorRenderList(): Nullable<AbstractMesh[]> {
  264. if (this._groundMirror) {
  265. return this._groundMirror.renderList;
  266. }
  267. return null;
  268. }
  269. private _groundMaterial: Nullable<BackgroundMaterial>;
  270. /**
  271. * Gets the ground material created by the helper.
  272. */
  273. public get groundMaterial(): Nullable<BackgroundMaterial> {
  274. return this._groundMaterial;
  275. }
  276. /**
  277. * Stores the creation options.
  278. */
  279. private readonly _scene: Scene;
  280. private _options: IEnvironmentHelperOptions;
  281. /**
  282. * This observable will be notified with any error during the creation of the environment,
  283. * mainly texture creation errors.
  284. */
  285. public onErrorObservable: Observable<{ message?: string, exception?: any }>;
  286. /**
  287. * constructor
  288. * @param options
  289. * @param scene The scene to add the material to
  290. */
  291. constructor(options: Partial<IEnvironmentHelperOptions>, scene: Scene) {
  292. this._options = {
  293. ...EnvironmentHelper._getDefaultOptions(),
  294. ...options
  295. }
  296. this._scene = scene;
  297. this.onErrorObservable = new Observable();
  298. this._setupBackground();
  299. this._setupImageProcessing();
  300. }
  301. /**
  302. * Updates the background according to the new options
  303. * @param options
  304. */
  305. public updateOptions(options: Partial<IEnvironmentHelperOptions>) {
  306. const newOptions = {
  307. ...this._options,
  308. ...options
  309. }
  310. if (this._ground && !newOptions.createGround) {
  311. this._ground.dispose();
  312. this._ground = null;
  313. }
  314. if (this._groundMaterial && !newOptions.createGround) {
  315. this._groundMaterial.dispose();
  316. this._groundMaterial = null;
  317. }
  318. if (this._groundTexture) {
  319. if (this._options.groundTexture != newOptions.groundTexture) {
  320. this._groundTexture.dispose();
  321. this._groundTexture = null;
  322. }
  323. }
  324. if (this._skybox && !newOptions.createSkybox) {
  325. this._skybox.dispose();
  326. this._skybox = null;
  327. }
  328. if (this._skyboxMaterial && !newOptions.createSkybox) {
  329. this._skyboxMaterial.dispose();
  330. this._skyboxMaterial = null;
  331. }
  332. if (this._skyboxTexture) {
  333. if (this._options.skyboxTexture != newOptions.skyboxTexture) {
  334. this._skyboxTexture.dispose();
  335. this._skyboxTexture = null;
  336. }
  337. }
  338. if (this._groundMirror && !newOptions.enableGroundMirror) {
  339. this._groundMirror.dispose();
  340. this._groundMirror = null;
  341. }
  342. if (this._scene.environmentTexture) {
  343. if (this._options.environmentTexture != newOptions.environmentTexture) {
  344. this._scene.environmentTexture.dispose();
  345. }
  346. }
  347. this._options = newOptions;
  348. this._setupBackground();
  349. this._setupImageProcessing();
  350. }
  351. /**
  352. * Sets the primary color of all the available elements.
  353. * @param color the main color to affect to the ground and the background
  354. * @param perceptual Specifies wether the chosen color has been set as intented to be seen e.g. in gamma space not accounting for exposure and tone mapping
  355. */
  356. public setMainColor(color: Color3, perceptual = false): void {
  357. if (this.groundMaterial) {
  358. if (perceptual) {
  359. this.groundMaterial.perceptualColor = color;
  360. }
  361. else {
  362. this.groundMaterial.primaryColor = color;
  363. }
  364. }
  365. if (this.skyboxMaterial) {
  366. if (perceptual) {
  367. this.skyboxMaterial.perceptualColor = color;
  368. }
  369. else {
  370. this.skyboxMaterial.primaryColor = color;
  371. }
  372. }
  373. if (this.groundMirror) {
  374. if (perceptual && this.groundMaterial) {
  375. this.groundMirror.clearColor = new Color4(this.groundMaterial.primaryColor.r,
  376. this.groundMaterial.primaryColor.g,
  377. this.groundMaterial.primaryColor.b,
  378. 1.0);
  379. }
  380. else {
  381. this.groundMirror.clearColor = new Color4(color.r, color.g, color.b, 1.0);
  382. }
  383. }
  384. }
  385. /**
  386. * Setup the image processing according to the specified options.
  387. */
  388. private _setupImageProcessing(): void {
  389. if (this._options.setupImageProcessing) {
  390. this._scene.imageProcessingConfiguration.contrast = this._options.cameraContrast;
  391. this._scene.imageProcessingConfiguration.exposure = this._options.cameraExposure;
  392. this._scene.imageProcessingConfiguration.toneMappingEnabled = this._options.toneMappingEnabled;
  393. this._setupEnvironmentTexture();
  394. }
  395. }
  396. /**
  397. * Setup the environment texture according to the specified options.
  398. */
  399. private _setupEnvironmentTexture(): void {
  400. if (this._scene.environmentTexture) {
  401. return;
  402. }
  403. if (this._options.environmentTexture instanceof BaseTexture) {
  404. this._scene.environmentTexture = this._options.environmentTexture;
  405. return;
  406. }
  407. const environmentTexture = CubeTexture.CreateFromPrefilteredData(this._options.environmentTexture, this._scene);
  408. this._scene.environmentTexture = environmentTexture;
  409. }
  410. /**
  411. * Setup the background according to the specified options.
  412. */
  413. private _setupBackground(): void {
  414. if (!this._rootMesh) {
  415. this._rootMesh = new Mesh("BackgroundHelper", this._scene);
  416. }
  417. this._rootMesh.rotation.y = this._options.backgroundYRotation;
  418. const sceneSize = this._getSceneSize();
  419. if (this._options.createGround) {
  420. this._setupGround(sceneSize);
  421. this._setupGroundMaterial();
  422. this._setupGroundDiffuseTexture();
  423. if (this._options.enableGroundMirror) {
  424. this._setupGroundMirrorTexture(sceneSize);
  425. }
  426. this._setupMirrorInGroundMaterial();
  427. }
  428. if (this._options.createSkybox) {
  429. this._setupSkybox(sceneSize);
  430. this._setupSkyboxMaterial();
  431. this._setupSkyboxReflectionTexture();
  432. }
  433. this._rootMesh.position.x = sceneSize.rootPosition.x;
  434. this._rootMesh.position.z = sceneSize.rootPosition.z;
  435. this._rootMesh.position.y = sceneSize.rootPosition.y;
  436. }
  437. /**
  438. * Get the scene sizes according to the setup.
  439. */
  440. private _getSceneSize(): ISceneSize {
  441. let groundSize = this._options.groundSize;
  442. let skyboxSize = this._options.skyboxSize;
  443. let rootPosition = this._options.rootPosition;
  444. if (!this._scene.meshes || this._scene.meshes.length === 1) { // 1 only means the root of the helper.
  445. return { groundSize, skyboxSize, rootPosition };
  446. }
  447. const sceneExtends = this._scene.getWorldExtends((mesh) => {
  448. return (mesh !== this._ground && mesh !== this._rootMesh && mesh !== this._skybox);
  449. });
  450. const sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);
  451. if (this._options.sizeAuto) {
  452. if (this._scene.activeCamera instanceof ArcRotateCamera &&
  453. this._scene.activeCamera.upperRadiusLimit) {
  454. groundSize = this._scene.activeCamera.upperRadiusLimit * 2;
  455. skyboxSize = groundSize;
  456. }
  457. const sceneDiagonalLenght = sceneDiagonal.length();
  458. if (sceneDiagonalLenght > groundSize) {
  459. groundSize = sceneDiagonalLenght * 2;
  460. skyboxSize = groundSize;
  461. }
  462. // 10 % bigger.
  463. groundSize *= 1.1;
  464. skyboxSize *= 1.5;
  465. rootPosition = sceneExtends.min.add(sceneDiagonal.scale(0.5));
  466. rootPosition.y = sceneExtends.min.y - this._options.groundYBias;
  467. }
  468. return { groundSize, skyboxSize, rootPosition };
  469. }
  470. /**
  471. * Setup the ground according to the specified options.
  472. */
  473. private _setupGround(sceneSize: ISceneSize): void {
  474. if (!this._ground) {
  475. this._ground = Mesh.CreatePlane("BackgroundPlane", sceneSize.groundSize, this._scene);
  476. this._ground.rotation.x = Math.PI / 2; // Face up by default.
  477. this._ground.parent = this._rootMesh;
  478. this._ground.onDisposeObservable.add(() => { this._ground = null; });
  479. }
  480. this._ground.receiveShadows = this._options.enableGroundShadow;
  481. }
  482. /**
  483. * Setup the ground material according to the specified options.
  484. */
  485. private _setupGroundMaterial(): void {
  486. if (!this._groundMaterial) {
  487. this._groundMaterial = new BackgroundMaterial("BackgroundPlaneMaterial", this._scene);
  488. }
  489. this._groundMaterial.alpha = this._options.groundOpacity;
  490. this._groundMaterial.alphaMode = Engine.ALPHA_PREMULTIPLIED_PORTERDUFF;
  491. this._groundMaterial.shadowLevel = this._options.groundShadowLevel;
  492. this._groundMaterial.primaryColor = this._options.groundColor;
  493. this._groundMaterial.useRGBColor = false;
  494. this._groundMaterial.enableNoise = true;
  495. if (this._ground) {
  496. this._ground.material = this._groundMaterial;
  497. }
  498. }
  499. /**
  500. * Setup the ground diffuse texture according to the specified options.
  501. */
  502. private _setupGroundDiffuseTexture(): void {
  503. if (!this._groundMaterial) {
  504. return;
  505. }
  506. if (this._groundTexture) {
  507. return;
  508. }
  509. if (this._options.groundTexture instanceof BaseTexture) {
  510. this._groundMaterial.diffuseTexture = this._options.groundTexture;
  511. return;
  512. }
  513. const diffuseTexture = new Texture(this._options.groundTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);
  514. diffuseTexture.gammaSpace = false;
  515. diffuseTexture.hasAlpha = true;
  516. this._groundMaterial.diffuseTexture = diffuseTexture;
  517. }
  518. /**
  519. * Setup the ground mirror texture according to the specified options.
  520. */
  521. private _setupGroundMirrorTexture(sceneSize: ISceneSize): void {
  522. let wrapping = Texture.CLAMP_ADDRESSMODE;
  523. if (!this._groundMirror) {
  524. this._groundMirror = new MirrorTexture("BackgroundPlaneMirrorTexture",
  525. { ratio: this._options.groundMirrorSizeRatio },
  526. this._scene,
  527. false,
  528. this._options.groundMirrorTextureType,
  529. Texture.BILINEAR_SAMPLINGMODE,
  530. true);
  531. this._groundMirror.mirrorPlane = new Plane(0, -1, 0, sceneSize.rootPosition.y);
  532. this._groundMirror.anisotropicFilteringLevel = 1;
  533. this._groundMirror.wrapU = wrapping;
  534. this._groundMirror.wrapV = wrapping;
  535. this._groundMirror.gammaSpace = false;
  536. if (this._groundMirror.renderList) {
  537. for (let i = 0; i < this._scene.meshes.length; i++) {
  538. const mesh = this._scene.meshes[i];
  539. if (mesh !== this._ground &&
  540. mesh !== this._skybox &&
  541. mesh !== this._rootMesh) {
  542. this._groundMirror.renderList.push(mesh);
  543. }
  544. }
  545. }
  546. }
  547. this._groundMirror.clearColor = new Color4(
  548. this._options.groundColor.r,
  549. this._options.groundColor.g,
  550. this._options.groundColor.b,
  551. 1);
  552. this._groundMirror.adaptiveBlurKernel = this._options.groundMirrorBlurKernel;
  553. }
  554. /**
  555. * Setup the ground to receive the mirror texture.
  556. */
  557. private _setupMirrorInGroundMaterial(): void {
  558. if (this._groundMaterial) {
  559. this._groundMaterial.reflectionTexture = this._groundMirror;
  560. this._groundMaterial.reflectionFresnel = true;
  561. this._groundMaterial.reflectionAmount = this._options.groundMirrorAmount;
  562. this._groundMaterial.reflectionStandardFresnelWeight = this._options.groundMirrorFresnelWeight;
  563. this._groundMaterial.reflectionFalloffDistance = this._options.groundMirrorFallOffDistance;
  564. }
  565. }
  566. /**
  567. * Setup the skybox according to the specified options.
  568. */
  569. private _setupSkybox(sceneSize: ISceneSize): void {
  570. if (!this._skybox) {
  571. this._skybox = Mesh.CreateBox("BackgroundSkybox", sceneSize.skyboxSize, this._scene, undefined, Mesh.BACKSIDE);
  572. this._skybox.onDisposeObservable.add(() => { this._skybox = null; })
  573. }
  574. this._skybox.parent = this._rootMesh;
  575. }
  576. /**
  577. * Setup the skybox material according to the specified options.
  578. */
  579. private _setupSkyboxMaterial(): void {
  580. if (!this._skybox) {
  581. return;
  582. }
  583. if (!this._skyboxMaterial) {
  584. this._skyboxMaterial = new BackgroundMaterial("BackgroundSkyboxMaterial", this._scene);
  585. }
  586. this._skyboxMaterial.useRGBColor = false;
  587. this._skyboxMaterial.primaryColor = this._options.skyboxColor;
  588. this._skyboxMaterial.enableNoise = true;
  589. this._skybox.material = this._skyboxMaterial;
  590. }
  591. /**
  592. * Setup the skybox reflection texture according to the specified options.
  593. */
  594. private _setupSkyboxReflectionTexture(): void {
  595. if (!this._skyboxMaterial) {
  596. return;
  597. }
  598. if (this._skyboxTexture) {
  599. return;
  600. }
  601. if (this._options.skyboxTexture instanceof BaseTexture) {
  602. this._skyboxMaterial.reflectionTexture = this._skyboxTexture;
  603. return;
  604. }
  605. this._skyboxTexture = new CubeTexture(this._options.skyboxTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);
  606. this._skyboxTexture.coordinatesMode = Texture.SKYBOX_MODE;
  607. this._skyboxTexture.gammaSpace = false;
  608. this._skyboxMaterial.reflectionTexture = this._skyboxTexture;
  609. }
  610. private _errorHandler = (message?: string, exception?: any) => {
  611. this.onErrorObservable.notifyObservers({ message: message, exception: exception });
  612. }
  613. /**
  614. * Dispose all the elements created by the Helper.
  615. */
  616. public dispose(): void {
  617. if (this._groundMaterial) {
  618. this._groundMaterial.dispose(true, true);
  619. }
  620. if (this._skyboxMaterial) {
  621. this._skyboxMaterial.dispose(true, true);
  622. }
  623. this._rootMesh.dispose(false);
  624. }
  625. }
  626. }