babylon.environmentHelper.ts 25 KB

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