babylon.environmentHelper.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. this.groundMirror.clearColor = new Color4(color.r, color.g, color.b, 1.0);
  375. }
  376. }
  377. /**
  378. * Setup the image processing according to the specified options.
  379. */
  380. private _setupImageProcessing(): void {
  381. if (this._options.setupImageProcessing) {
  382. this._scene.imageProcessingConfiguration.contrast = this._options.cameraContrast;
  383. this._scene.imageProcessingConfiguration.exposure = this._options.cameraExposure;
  384. this._scene.imageProcessingConfiguration.toneMappingEnabled = this._options.toneMappingEnabled;
  385. this._setupEnvironmentTexture();
  386. }
  387. }
  388. /**
  389. * Setup the environment texture according to the specified options.
  390. */
  391. private _setupEnvironmentTexture(): void {
  392. if (this._scene.environmentTexture) {
  393. return;
  394. }
  395. if (this._options.environmentTexture instanceof BaseTexture) {
  396. this._scene.environmentTexture = this._options.environmentTexture;
  397. return;
  398. }
  399. const environmentTexture = CubeTexture.CreateFromPrefilteredData(this._options.environmentTexture, this._scene);
  400. this._scene.environmentTexture = environmentTexture;
  401. }
  402. /**
  403. * Setup the background according to the specified options.
  404. */
  405. private _setupBackground(): void {
  406. if (!this._rootMesh) {
  407. this._rootMesh = new Mesh("BackgroundHelper", this._scene);
  408. }
  409. this._rootMesh.rotation.y = this._options.backgroundYRotation;
  410. const sceneSize = this._getSceneSize();
  411. if (this._options.createGround) {
  412. this._setupGround(sceneSize);
  413. this._setupGroundMaterial();
  414. this._setupGroundDiffuseTexture();
  415. if (this._options.enableGroundMirror) {
  416. this._setupGroundMirrorTexture(sceneSize);
  417. }
  418. this._setupMirrorInGroundMaterial();
  419. }
  420. if (this._options.createSkybox) {
  421. this._setupSkybox(sceneSize);
  422. this._setupSkyboxMaterial();
  423. this._setupSkyboxReflectionTexture();
  424. }
  425. this._rootMesh.position.x = sceneSize.rootPosition.x;
  426. this._rootMesh.position.z = sceneSize.rootPosition.z;
  427. this._rootMesh.position.y = sceneSize.rootPosition.y;
  428. }
  429. /**
  430. * Get the scene sizes according to the setup.
  431. */
  432. private _getSceneSize(): ISceneSize {
  433. let groundSize = this._options.groundSize;
  434. let skyboxSize = this._options.skyboxSize;
  435. let rootPosition = this._options.rootPosition;
  436. if (!this._scene.meshes || this._scene.meshes.length === 1) { // 1 only means the root of the helper.
  437. return { groundSize, skyboxSize, rootPosition };
  438. }
  439. const sceneExtends = this._scene.getWorldExtends((mesh) => {
  440. return (mesh !== this._ground && mesh !== this._rootMesh && mesh !== this._skybox);
  441. });
  442. const sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);
  443. if (this._options.sizeAuto) {
  444. if (this._scene.activeCamera instanceof ArcRotateCamera &&
  445. this._scene.activeCamera.upperRadiusLimit) {
  446. groundSize = this._scene.activeCamera.upperRadiusLimit * 2;
  447. skyboxSize = groundSize;
  448. }
  449. const sceneDiagonalLenght = sceneDiagonal.length();
  450. if (sceneDiagonalLenght > groundSize) {
  451. groundSize = sceneDiagonalLenght * 2;
  452. skyboxSize = groundSize;
  453. }
  454. // 10 % bigger.
  455. groundSize *= 1.1;
  456. skyboxSize *= 1.5;
  457. rootPosition = sceneExtends.min.add(sceneDiagonal.scale(0.5));
  458. rootPosition.y = sceneExtends.min.y - this._options.groundYBias;
  459. }
  460. return { groundSize, skyboxSize, rootPosition };
  461. }
  462. /**
  463. * Setup the ground according to the specified options.
  464. */
  465. private _setupGround(sceneSize: ISceneSize): void {
  466. if (!this._ground) {
  467. this._ground = Mesh.CreatePlane("BackgroundPlane", sceneSize.groundSize, this._scene);
  468. this._ground.rotation.x = Math.PI / 2; // Face up by default.
  469. this._ground.parent = this._rootMesh;
  470. this._ground.onDisposeObservable.add(() => { this._ground = null; });
  471. }
  472. this._ground.receiveShadows = this._options.enableGroundShadow;
  473. }
  474. /**
  475. * Setup the ground material according to the specified options.
  476. */
  477. private _setupGroundMaterial(): void {
  478. if (!this._groundMaterial) {
  479. this._groundMaterial = new BackgroundMaterial("BackgroundPlaneMaterial", this._scene);
  480. }
  481. this._groundMaterial.alpha = this._options.groundOpacity;
  482. this._groundMaterial.alphaMode = Engine.ALPHA_PREMULTIPLIED_PORTERDUFF;
  483. this._groundMaterial.shadowLevel = this._options.groundShadowLevel;
  484. this._groundMaterial.primaryColor = this._options.groundColor;
  485. this._groundMaterial.useRGBColor = false;
  486. this._groundMaterial.enableNoise = true;
  487. if (this._ground) {
  488. this._ground.material = this._groundMaterial;
  489. }
  490. }
  491. /**
  492. * Setup the ground diffuse texture according to the specified options.
  493. */
  494. private _setupGroundDiffuseTexture(): void {
  495. if (!this._groundMaterial) {
  496. return;
  497. }
  498. if (this._groundTexture) {
  499. return;
  500. }
  501. if (this._options.groundTexture instanceof BaseTexture) {
  502. this._groundMaterial.diffuseTexture = this._options.groundTexture;
  503. return;
  504. }
  505. const diffuseTexture = new Texture(this._options.groundTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);
  506. diffuseTexture.gammaSpace = false;
  507. diffuseTexture.hasAlpha = true;
  508. this._groundMaterial.diffuseTexture = diffuseTexture;
  509. }
  510. /**
  511. * Setup the ground mirror texture according to the specified options.
  512. */
  513. private _setupGroundMirrorTexture(sceneSize: ISceneSize): void {
  514. let wrapping = Texture.CLAMP_ADDRESSMODE;
  515. if (!this._groundMirror) {
  516. this._groundMirror = new MirrorTexture("BackgroundPlaneMirrorTexture",
  517. { ratio: this._options.groundMirrorSizeRatio },
  518. this._scene,
  519. false,
  520. this._options.groundMirrorTextureType,
  521. Texture.BILINEAR_SAMPLINGMODE,
  522. true);
  523. this._groundMirror.mirrorPlane = new Plane(0, -1, 0, sceneSize.rootPosition.y);
  524. this._groundMirror.anisotropicFilteringLevel = 1;
  525. this._groundMirror.wrapU = wrapping;
  526. this._groundMirror.wrapV = wrapping;
  527. this._groundMirror.gammaSpace = false;
  528. if (this._groundMirror.renderList) {
  529. for (let i = 0; i < this._scene.meshes.length; i++) {
  530. const mesh = this._scene.meshes[i];
  531. if (mesh !== this._ground &&
  532. mesh !== this._skybox &&
  533. mesh !== this._rootMesh) {
  534. this._groundMirror.renderList.push(mesh);
  535. }
  536. }
  537. }
  538. }
  539. this._groundMirror.clearColor = new Color4(
  540. this._options.groundColor.r,
  541. this._options.groundColor.g,
  542. this._options.groundColor.b,
  543. 1);
  544. this._groundMirror.adaptiveBlurKernel = this._options.groundMirrorBlurKernel;
  545. }
  546. /**
  547. * Setup the ground to receive the mirror texture.
  548. */
  549. private _setupMirrorInGroundMaterial(): void {
  550. if (this._groundMaterial) {
  551. this._groundMaterial.reflectionTexture = this._groundMirror;
  552. this._groundMaterial.reflectionFresnel = true;
  553. this._groundMaterial.reflectionAmount = this._options.groundMirrorAmount;
  554. this._groundMaterial.reflectionStandardFresnelWeight = this._options.groundMirrorFresnelWeight;
  555. this._groundMaterial.reflectionFalloffDistance = this._options.groundMirrorFallOffDistance;
  556. }
  557. }
  558. /**
  559. * Setup the skybox according to the specified options.
  560. */
  561. private _setupSkybox(sceneSize: ISceneSize): void {
  562. if (!this._skybox) {
  563. this._skybox = Mesh.CreateBox("BackgroundSkybox", sceneSize.skyboxSize, this._scene, undefined, Mesh.BACKSIDE);
  564. this._skybox.onDisposeObservable.add(() => { this._skybox = null; })
  565. }
  566. this._skybox.parent = this._rootMesh;
  567. }
  568. /**
  569. * Setup the skybox material according to the specified options.
  570. */
  571. private _setupSkyboxMaterial(): void {
  572. if (!this._skybox) {
  573. return;
  574. }
  575. if (!this._skyboxMaterial) {
  576. this._skyboxMaterial = new BackgroundMaterial("BackgroundSkyboxMaterial", this._scene);
  577. }
  578. this._skyboxMaterial.useRGBColor = false;
  579. this._skyboxMaterial.primaryColor = this._options.skyboxColor;
  580. this._skyboxMaterial.enableNoise = true;
  581. this._skybox.material = this._skyboxMaterial;
  582. }
  583. /**
  584. * Setup the skybox reflection texture according to the specified options.
  585. */
  586. private _setupSkyboxReflectionTexture(): void {
  587. if (!this._skyboxMaterial) {
  588. return;
  589. }
  590. if (this._skyboxTexture) {
  591. return;
  592. }
  593. if (this._options.skyboxTexture instanceof BaseTexture) {
  594. this._skyboxMaterial.reflectionTexture = this._skyboxTexture;
  595. return;
  596. }
  597. this._skyboxTexture = new CubeTexture(this._options.skyboxTexture, this._scene, undefined, undefined, undefined, undefined, this._errorHandler);
  598. this._skyboxTexture.coordinatesMode = Texture.SKYBOX_MODE;
  599. this._skyboxTexture.gammaSpace = false;
  600. this._skyboxMaterial.reflectionTexture = this._skyboxTexture;
  601. }
  602. private _errorHandler = (message?: string, exception?: any) => {
  603. this.onErrorObservable.notifyObservers({ message: message, exception: exception });
  604. }
  605. /**
  606. * Dispose all the elements created by the Helper.
  607. */
  608. public dispose(): void {
  609. if (this._groundMaterial) {
  610. this._groundMaterial.dispose(true, true);
  611. }
  612. if (this._skyboxMaterial) {
  613. this._skyboxMaterial.dispose(true, true);
  614. }
  615. this._rootMesh.dispose(false);
  616. }
  617. }
  618. }