sceneManager.d.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { Scene, ArcRotateCamera, Light, SceneOptimizer, EnvironmentHelper, Color3, Observable, DefaultRenderingPipeline, Nullable } from 'babylonjs';
  2. import { AbstractViewer } from './viewer';
  3. import { ILightConfiguration, ISceneConfiguration, ISceneOptimizerConfiguration, ICameraConfiguration, ISkyboxConfiguration, ViewerConfiguration, IGroundConfiguration, IModelConfiguration } from '../configuration/configuration';
  4. import { ViewerModel } from '../model/viewerModel';
  5. import { ViewerLabs } from '../labs/viewerLabs';
  6. /**
  7. * This interface describes the structure of the variable sent with the configuration observables of the scene manager.
  8. * O - the type of object we are dealing with (Light, ArcRotateCamera, Scene, etc')
  9. * T - the configuration type
  10. */
  11. export interface IPostConfigurationCallback<OBJ, CONF> {
  12. newConfiguration: CONF;
  13. sceneManager: SceneManager;
  14. object: OBJ;
  15. model?: ViewerModel;
  16. }
  17. export declare class SceneManager {
  18. private _viewer;
  19. /**
  20. * Will notify when the scene was initialized
  21. */
  22. onSceneInitObservable: Observable<Scene>;
  23. /**
  24. * Will notify after the scene was configured. Can be used to further configure the scene
  25. */
  26. onSceneConfiguredObservable: Observable<IPostConfigurationCallback<Scene, ISceneConfiguration>>;
  27. /**
  28. * Will notify after the scene optimized was configured. Can be used to further configure the scene optimizer
  29. */
  30. onSceneOptimizerConfiguredObservable: Observable<IPostConfigurationCallback<SceneOptimizer, ISceneOptimizerConfiguration | boolean>>;
  31. /**
  32. * Will notify after the camera was configured. Can be used to further configure the camera
  33. */
  34. onCameraConfiguredObservable: Observable<IPostConfigurationCallback<ArcRotateCamera, ICameraConfiguration>>;
  35. /**
  36. * Will notify after the lights were configured. Can be used to further configure lights
  37. */
  38. onLightsConfiguredObservable: Observable<IPostConfigurationCallback<Array<Light>, {
  39. [name: string]: ILightConfiguration | boolean | number;
  40. }>>;
  41. /**
  42. * Will notify after the model(s) were configured. Can be used to further configure models
  43. */
  44. onModelsConfiguredObservable: Observable<IPostConfigurationCallback<Array<ViewerModel>, IModelConfiguration>>;
  45. /**
  46. * Will notify after the envirnoment was configured. Can be used to further configure the environment
  47. */
  48. onEnvironmentConfiguredObservable: Observable<IPostConfigurationCallback<EnvironmentHelper, {
  49. skybox?: ISkyboxConfiguration | boolean;
  50. ground?: IGroundConfiguration | boolean;
  51. }>>;
  52. /**
  53. * The Babylon Scene of this viewer
  54. */
  55. scene: Scene;
  56. /**
  57. * The camera used in this viewer
  58. */
  59. camera: ArcRotateCamera;
  60. /**
  61. * Babylon's scene optimizer
  62. */
  63. sceneOptimizer: SceneOptimizer;
  64. /**
  65. * Models displayed in this viewer.
  66. */
  67. models: Array<ViewerModel>;
  68. /**
  69. * Babylon's environment helper of this viewer
  70. */
  71. environmentHelper: EnvironmentHelper;
  72. private _animationBlendingEnabled;
  73. protected _defaultHighpTextureType: number;
  74. protected _shadowGeneratorBias: number;
  75. protected _defaultPipelineTextureType: number;
  76. /**
  77. * The maximum number of shadows supported by the curent viewer
  78. */
  79. protected _maxShadows: number;
  80. /**
  81. * is HDR supported?
  82. */
  83. private _hdrSupport;
  84. private _mainColor;
  85. private _reflectionColor;
  86. private readonly _white;
  87. private _forceShadowUpdate;
  88. /**
  89. * The labs variable consists of objects that will have their API change.
  90. * Please be careful when using labs in production.
  91. */
  92. labs: ViewerLabs;
  93. private _defaultRenderingPipeline;
  94. readonly defaultRenderingPipeline: Nullable<DefaultRenderingPipeline>;
  95. constructor(_viewer: AbstractViewer);
  96. /**
  97. * Returns a boolean representing HDR support
  98. */
  99. readonly isHdrSupported: boolean;
  100. /**
  101. * Return the main color defined in the configuration.
  102. */
  103. readonly mainColor: Color3;
  104. readonly reflectionColor: Color3;
  105. animationBlendingEnabled: boolean;
  106. private _processShadows;
  107. /**
  108. * The flag defining whether shadows are rendered constantly or once.
  109. */
  110. /**
  111. * Should shadows be rendered every frame, or only once and stop.
  112. * This can be used to optimize a scene.
  113. *
  114. * Not that the shadows will NOT disapear but will remain in place.
  115. * @param process if true shadows will be updated once every frame. if false they will stop being updated.
  116. */
  117. processShadows: boolean;
  118. private _groundEnabled;
  119. groundEnabled: boolean;
  120. private _groundMirrorEnabled;
  121. /**
  122. * gets wether the reflection is disabled.
  123. */
  124. /**
  125. * sets wether the reflection is disabled.
  126. */
  127. groundMirrorEnabled: boolean;
  128. private _defaultRenderingPipelineEnabled;
  129. defaultRenderingPipelineEnabled: boolean;
  130. /**
  131. * Sets the engine flags to unlock all babylon features.
  132. * Can also be configured using the scene.flags configuration object
  133. */
  134. unlockBabylonFeatures(): void;
  135. /**
  136. * initialize the scene. Calling this function again will dispose the old scene, if exists.
  137. */
  138. initScene(sceneConfiguration?: ISceneConfiguration, optimizerConfiguration?: boolean | ISceneOptimizerConfiguration): Promise<Scene>;
  139. clearScene(clearModels?: boolean, clearLights?: boolean): void;
  140. /**
  141. * This will update the scene's configuration, including camera, lights, environment.
  142. * @param newConfiguration the delta that should be configured. This includes only the changes
  143. * @param globalConfiguration The global configuration object, after the new configuration was merged into it
  144. */
  145. updateConfiguration(newConfiguration: Partial<ViewerConfiguration>, globalConfiguration: ViewerConfiguration): void;
  146. private _defaultRenderingPipelineShouldBuild;
  147. private _rebuildPostprocesses(configuration?);
  148. private _bloomEnabled;
  149. bloomEnabled: boolean;
  150. private _fxaaEnabled;
  151. fxaaEnabled: boolean;
  152. /**
  153. * internally configure the scene using the provided configuration.
  154. * The scene will not be recreated, but just updated.
  155. * @param sceneConfig the (new) scene configuration
  156. */
  157. protected _configureScene(sceneConfig: ISceneConfiguration): void;
  158. /**
  159. * Configure the scene optimizer.
  160. * The existing scene optimizer will be disposed and a new one will be created.
  161. * @param optimizerConfig the (new) optimizer configuration
  162. */
  163. protected _configureOptimizer(optimizerConfig: ISceneOptimizerConfiguration | boolean): void;
  164. /**
  165. * configure all models using the configuration.
  166. * @param modelConfiguration the configuration to use to reconfigure the models
  167. */
  168. /**
  169. * (Re) configure the camera. The camera will only be created once and from this point will only be reconfigured.
  170. * @param cameraConfig the new camera configuration
  171. * @param model optionally use the model to configure the camera.
  172. */
  173. protected _configureCamera(cameraConfig?: ICameraConfiguration): void;
  174. private _focusOnModel;
  175. protected _configureEnvironment(skyboxConifguration?: ISkyboxConfiguration | boolean, groundConfiguration?: IGroundConfiguration | boolean): void;
  176. /**
  177. * configure the lights.
  178. *
  179. * @param lightsConfiguration the (new) light(s) configuration
  180. * @param model optionally use the model to configure the camera.
  181. */
  182. protected _configureLights(lightsConfiguration?: {
  183. [name: string]: ILightConfiguration | boolean | number;
  184. }): void;
  185. private _shadowGroundPlane;
  186. private _updateShadowRenderList(shadowGenerator, model?, resetList?);
  187. private _updateGroundMirrorRenderList(model?, resetList?);
  188. /**
  189. * Gets the shadow map blur kernel according to the light configuration.
  190. * @param light The light used to generate the shadows
  191. * @param bufferSize The size of the shadow map
  192. * @return the kernel blur size
  193. */
  194. getBlurKernel(light: BABYLON.IShadowLight, bufferSize: number): number;
  195. /**
  196. * Alters render settings to reduce features based on hardware feature limitations
  197. * @param enableHDR Allows the viewer to run in HDR mode.
  198. */
  199. protected _handleHardwareLimitations(enableHDR?: boolean): void;
  200. /**
  201. * Dispoe the entire viewer including the scene and the engine
  202. */
  203. dispose(): void;
  204. private _cameraBehaviorMapping;
  205. private _setCameraBehavior(name, behaviorConfig, payload?);
  206. }