environmentHelper.d.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import { Observable } from "../Misc/observable";
  2. import type { Nullable } from "../types";
  3. import type { Scene } from "../scene";
  4. import { Vector3 } from "../Maths/math.vector";
  5. import { Color3 } from "../Maths/math.color";
  6. import type { AbstractMesh } from "../Meshes/abstractMesh";
  7. import { Mesh } from "../Meshes/mesh";
  8. import { BaseTexture } from "../Materials/Textures/baseTexture";
  9. import { MirrorTexture } from "../Materials/Textures/mirrorTexture";
  10. import { BackgroundMaterial } from "../Materials/Background/backgroundMaterial";
  11. /**
  12. * Represents the different options available during the creation of
  13. * a Environment helper.
  14. *
  15. * This can control the default ground, skybox and image processing setup of your scene.
  16. */
  17. export interface IEnvironmentHelperOptions {
  18. /**
  19. * Specifies whether or not to create a ground.
  20. * True by default.
  21. */
  22. createGround: boolean;
  23. /**
  24. * Specifies the ground size.
  25. * 15 by default.
  26. */
  27. groundSize: number;
  28. /**
  29. * The texture used on the ground for the main color.
  30. * Comes from the BabylonJS CDN by default.
  31. *
  32. * Remarks: Can be either a texture or a url.
  33. */
  34. groundTexture: string | BaseTexture;
  35. /**
  36. * The color mixed in the ground texture by default.
  37. * BabylonJS clearColor by default.
  38. */
  39. groundColor: Color3;
  40. /**
  41. * Specifies the ground opacity.
  42. * 1 by default.
  43. */
  44. groundOpacity: number;
  45. /**
  46. * Enables the ground to receive shadows.
  47. * True by default.
  48. */
  49. enableGroundShadow: boolean;
  50. /**
  51. * Helps preventing the shadow to be fully black on the ground.
  52. * 0.5 by default.
  53. */
  54. groundShadowLevel: number;
  55. /**
  56. * Creates a mirror texture attach to the ground.
  57. * false by default.
  58. */
  59. enableGroundMirror: boolean;
  60. /**
  61. * Specifies the ground mirror size ratio.
  62. * 0.3 by default as the default kernel is 64.
  63. */
  64. groundMirrorSizeRatio: number;
  65. /**
  66. * Specifies the ground mirror blur kernel size.
  67. * 64 by default.
  68. */
  69. groundMirrorBlurKernel: number;
  70. /**
  71. * Specifies the ground mirror visibility amount.
  72. * 1 by default
  73. */
  74. groundMirrorAmount: number;
  75. /**
  76. * Specifies the ground mirror reflectance weight.
  77. * This uses the standard weight of the background material to setup the fresnel effect
  78. * of the mirror.
  79. * 1 by default.
  80. */
  81. groundMirrorFresnelWeight: number;
  82. /**
  83. * Specifies the ground mirror Falloff distance.
  84. * This can helps reducing the size of the reflection.
  85. * 0 by Default.
  86. */
  87. groundMirrorFallOffDistance: number;
  88. /**
  89. * Specifies the ground mirror texture type.
  90. * Unsigned Int by Default.
  91. */
  92. groundMirrorTextureType: number;
  93. /**
  94. * Specifies a bias applied to the ground vertical position to prevent z-fighting with
  95. * the shown objects.
  96. */
  97. groundYBias: number;
  98. /**
  99. * Specifies whether or not to create a skybox.
  100. * True by default.
  101. */
  102. createSkybox: boolean;
  103. /**
  104. * Specifies the skybox size.
  105. * 20 by default.
  106. */
  107. skyboxSize: number;
  108. /**
  109. * The texture used on the skybox for the main color.
  110. * Comes from the BabylonJS CDN by default.
  111. *
  112. * Remarks: Can be either a texture or a url.
  113. */
  114. skyboxTexture: string | BaseTexture;
  115. /**
  116. * The color mixed in the skybox texture by default.
  117. * BabylonJS clearColor by default.
  118. */
  119. skyboxColor: Color3;
  120. /**
  121. * The background rotation around the Y axis of the scene.
  122. * This helps aligning the key lights of your scene with the background.
  123. * 0 by default.
  124. */
  125. backgroundYRotation: number;
  126. /**
  127. * Compute automatically the size of the elements to best fit with the scene.
  128. */
  129. sizeAuto: boolean;
  130. /**
  131. * Default position of the rootMesh if autoSize is not true.
  132. */
  133. rootPosition: Vector3;
  134. /**
  135. * Sets up the image processing in the scene.
  136. * true by default.
  137. */
  138. setupImageProcessing: boolean;
  139. /**
  140. * The texture used as your environment texture in the scene.
  141. * Comes from the BabylonJS CDN by default and in use if setupImageProcessing is true.
  142. *
  143. * Remarks: Can be either a texture or a url.
  144. */
  145. environmentTexture: string | BaseTexture;
  146. /**
  147. * The value of the exposure to apply to the scene.
  148. * 0.6 by default if setupImageProcessing is true.
  149. */
  150. cameraExposure: number;
  151. /**
  152. * The value of the contrast to apply to the scene.
  153. * 1.6 by default if setupImageProcessing is true.
  154. */
  155. cameraContrast: number;
  156. /**
  157. * Specifies whether or not tonemapping should be enabled in the scene.
  158. * true by default if setupImageProcessing is true.
  159. */
  160. toneMappingEnabled: boolean;
  161. }
  162. /**
  163. * The EnvironmentHelper class can be used to add a fully featured non-expensive background to your scene.
  164. * It includes by default a skybox and a ground relying on the BackgroundMaterial.
  165. * It also helps with the default setup of your ImageProcessingConfiguration.
  166. */
  167. export declare class EnvironmentHelper {
  168. /**
  169. * Default ground texture URL.
  170. */
  171. private static _GroundTextureCDNUrl;
  172. /**
  173. * Default skybox texture URL.
  174. */
  175. private static _SkyboxTextureCDNUrl;
  176. /**
  177. * Default environment texture URL.
  178. */
  179. private static _EnvironmentTextureCDNUrl;
  180. /**
  181. * Creates the default options for the helper.
  182. * @param scene The scene the environment helper belongs to.
  183. * @returns default options for the helper.
  184. */
  185. private static _GetDefaultOptions;
  186. private _rootMesh;
  187. /**
  188. * Gets the root mesh created by the helper.
  189. */
  190. get rootMesh(): Mesh;
  191. private _skybox;
  192. /**
  193. * Gets the skybox created by the helper.
  194. */
  195. get skybox(): Nullable<Mesh>;
  196. private _skyboxTexture;
  197. /**
  198. * Gets the skybox texture created by the helper.
  199. */
  200. get skyboxTexture(): Nullable<BaseTexture>;
  201. private _skyboxMaterial;
  202. /**
  203. * Gets the skybox material created by the helper.
  204. */
  205. get skyboxMaterial(): Nullable<BackgroundMaterial>;
  206. private _ground;
  207. /**
  208. * Gets the ground mesh created by the helper.
  209. */
  210. get ground(): Nullable<Mesh>;
  211. private _groundTexture;
  212. /**
  213. * Gets the ground texture created by the helper.
  214. */
  215. get groundTexture(): Nullable<BaseTexture>;
  216. private _groundMirror;
  217. /**
  218. * Gets the ground mirror created by the helper.
  219. */
  220. get groundMirror(): Nullable<MirrorTexture>;
  221. /**
  222. * Gets the ground mirror render list to helps pushing the meshes
  223. * you wish in the ground reflection.
  224. */
  225. get groundMirrorRenderList(): Nullable<AbstractMesh[]>;
  226. private _groundMaterial;
  227. /**
  228. * Gets the ground material created by the helper.
  229. */
  230. get groundMaterial(): Nullable<BackgroundMaterial>;
  231. /**
  232. * Stores the creation options.
  233. */
  234. private readonly _scene;
  235. private _options;
  236. /**
  237. * This observable will be notified with any error during the creation of the environment,
  238. * mainly texture creation errors.
  239. */
  240. onErrorObservable: Observable<{
  241. message?: string;
  242. exception?: any;
  243. }>;
  244. /**
  245. * constructor
  246. * @param options Defines the options we want to customize the helper
  247. * @param scene The scene to add the material to
  248. */
  249. constructor(options: Partial<IEnvironmentHelperOptions>, scene: Scene);
  250. /**
  251. * Updates the environment according to the new options
  252. * @param options options to configure the helper (IEnvironmentHelperOptions)
  253. */
  254. updateOptions(options: Partial<IEnvironmentHelperOptions>): void;
  255. /**
  256. * Sets the primary color of all the available elements.
  257. * @param color the main color to affect to the ground and the background
  258. */
  259. setMainColor(color: Color3): void;
  260. /**
  261. * Setup the image processing according to the specified options.
  262. */
  263. private _setupImageProcessing;
  264. /**
  265. * Setup the environment texture according to the specified options.
  266. */
  267. private _setupEnvironmentTexture;
  268. /**
  269. * Setup the background according to the specified options.
  270. */
  271. private _setupBackground;
  272. /**
  273. * Get the scene sizes according to the setup.
  274. * @returns the different ground and skybox sizes.
  275. */
  276. private _getSceneSize;
  277. /**
  278. * Setup the ground according to the specified options.
  279. * @param sceneSize
  280. */
  281. private _setupGround;
  282. /**
  283. * Setup the ground material according to the specified options.
  284. */
  285. private _setupGroundMaterial;
  286. /**
  287. * Setup the ground diffuse texture according to the specified options.
  288. */
  289. private _setupGroundDiffuseTexture;
  290. /**
  291. * Setup the ground mirror texture according to the specified options.
  292. * @param sceneSize
  293. */
  294. private _setupGroundMirrorTexture;
  295. /**
  296. * Setup the ground to receive the mirror texture.
  297. */
  298. private _setupMirrorInGroundMaterial;
  299. /**
  300. * Setup the skybox according to the specified options.
  301. * @param sceneSize
  302. */
  303. private _setupSkybox;
  304. /**
  305. * Setup the skybox material according to the specified options.
  306. */
  307. private _setupSkyboxMaterial;
  308. /**
  309. * Setup the skybox reflection texture according to the specified options.
  310. */
  311. private _setupSkyboxReflectionTexture;
  312. private _errorHandler;
  313. /**
  314. * Dispose all the elements created by the Helper.
  315. */
  316. dispose(): void;
  317. }