@babylonjs/viewer 7.21.0-alpha → 7.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/configuration/configuration.d.ts +107 -0
  2. package/configuration/configuration.js +16 -0
  3. package/configuration/configuration.js.map +1 -0
  4. package/configuration/configurationCompatibility.d.ts +8 -0
  5. package/configuration/configurationCompatibility.js +66 -0
  6. package/configuration/configurationCompatibility.js.map +1 -0
  7. package/configuration/configurationContainer.d.ts +10 -0
  8. package/configuration/configurationContainer.js +10 -0
  9. package/configuration/configurationContainer.js.map +1 -0
  10. package/configuration/globals.d.ts +6 -0
  11. package/configuration/globals.js +18 -0
  12. package/configuration/globals.js.map +1 -0
  13. package/configuration/index.d.ts +2 -0
  14. package/configuration/index.js +4 -0
  15. package/configuration/index.js.map +1 -0
  16. package/configuration/interfaces/cameraConfiguration.d.ts +31 -0
  17. package/configuration/interfaces/cameraConfiguration.js +2 -0
  18. package/configuration/interfaces/cameraConfiguration.js.map +1 -0
  19. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -0
  20. package/configuration/interfaces/colorGradingConfiguration.js +2 -0
  21. package/configuration/interfaces/colorGradingConfiguration.js.map +1 -0
  22. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -0
  23. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +2 -0
  24. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -0
  25. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -0
  26. package/configuration/interfaces/environmentMapConfiguration.js +2 -0
  27. package/configuration/interfaces/environmentMapConfiguration.js.map +1 -0
  28. package/configuration/interfaces/groundConfiguration.d.ts +24 -0
  29. package/configuration/interfaces/groundConfiguration.js +2 -0
  30. package/configuration/interfaces/groundConfiguration.js.map +1 -0
  31. package/configuration/interfaces/imageProcessingConfiguration.d.ts +45 -0
  32. package/configuration/interfaces/imageProcessingConfiguration.js +2 -0
  33. package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -0
  34. package/configuration/interfaces/index.d.ts +15 -0
  35. package/configuration/interfaces/index.js +16 -0
  36. package/configuration/interfaces/index.js.map +1 -0
  37. package/configuration/interfaces/lightConfiguration.d.ts +60 -0
  38. package/configuration/interfaces/lightConfiguration.js +2 -0
  39. package/configuration/interfaces/lightConfiguration.js.map +1 -0
  40. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -0
  41. package/configuration/interfaces/modelAnimationConfiguration.js +2 -0
  42. package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -0
  43. package/configuration/interfaces/modelConfiguration.d.ts +65 -0
  44. package/configuration/interfaces/modelConfiguration.js +2 -0
  45. package/configuration/interfaces/modelConfiguration.js.map +1 -0
  46. package/configuration/interfaces/observersConfiguration.d.ts +5 -0
  47. package/configuration/interfaces/observersConfiguration.js +2 -0
  48. package/configuration/interfaces/observersConfiguration.js.map +1 -0
  49. package/configuration/interfaces/sceneConfiguration.d.ts +48 -0
  50. package/configuration/interfaces/sceneConfiguration.js +2 -0
  51. package/configuration/interfaces/sceneConfiguration.js.map +1 -0
  52. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -0
  53. package/configuration/interfaces/sceneOptimizerConfiguration.js +2 -0
  54. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -0
  55. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -0
  56. package/configuration/interfaces/skyboxConfiguration.js +2 -0
  57. package/configuration/interfaces/skyboxConfiguration.js.map +1 -0
  58. package/configuration/interfaces/templateConfiguration.d.ts +67 -0
  59. package/configuration/interfaces/templateConfiguration.js +2 -0
  60. package/configuration/interfaces/templateConfiguration.js.map +1 -0
  61. package/configuration/interfaces/vrConfiguration.d.ts +16 -0
  62. package/configuration/interfaces/vrConfiguration.js +2 -0
  63. package/configuration/interfaces/vrConfiguration.js.map +1 -0
  64. package/configuration/loader.d.ts +4 -0
  65. package/configuration/loader.js +17 -0
  66. package/configuration/loader.js.map +1 -0
  67. package/configuration/mappers.d.ts +43 -0
  68. package/configuration/mappers.js +192 -0
  69. package/configuration/mappers.js.map +1 -0
  70. package/configuration/renderOnlyLoader.d.ts +33 -0
  71. package/configuration/renderOnlyLoader.js +162 -0
  72. package/configuration/renderOnlyLoader.js.map +1 -0
  73. package/configuration/types/default.d.ts +6 -0
  74. package/configuration/types/default.js +121 -0
  75. package/configuration/types/default.js.map +1 -0
  76. package/configuration/types/environmentMap.d.ts +5 -0
  77. package/configuration/types/environmentMap.js +14 -0
  78. package/configuration/types/environmentMap.js.map +1 -0
  79. package/configuration/types/extended.d.ts +6 -0
  80. package/configuration/types/extended.js +317 -0
  81. package/configuration/types/extended.js.map +1 -0
  82. package/configuration/types/index.d.ts +14 -0
  83. package/configuration/types/index.js +51 -0
  84. package/configuration/types/index.js.map +1 -0
  85. package/configuration/types/minimal.d.ts +6 -0
  86. package/configuration/types/minimal.js +43 -0
  87. package/configuration/types/minimal.js.map +1 -0
  88. package/configuration/types/renderOnlyDefault.d.ts +30 -0
  89. package/configuration/types/renderOnlyDefault.js +31 -0
  90. package/configuration/types/renderOnlyDefault.js.map +1 -0
  91. package/configuration/types/shadowLight.d.ts +9 -0
  92. package/configuration/types/shadowLight.js +64 -0
  93. package/configuration/types/shadowLight.js.map +1 -0
  94. package/helper/index.d.ts +29 -0
  95. package/helper/index.js +66 -0
  96. package/helper/index.js.map +1 -0
  97. package/index.d.ts +30 -0
  98. package/index.js +46 -0
  99. package/index.js.map +1 -0
  100. package/initializer.d.ts +11 -0
  101. package/initializer.js +35 -0
  102. package/initializer.js.map +1 -0
  103. package/interfaces.d.ts +5 -0
  104. package/interfaces.js +7 -0
  105. package/interfaces.js.map +1 -0
  106. package/labs/environmentSerializer.d.ts +126 -0
  107. package/labs/environmentSerializer.js +191 -0
  108. package/labs/environmentSerializer.js.map +1 -0
  109. package/labs/texture.d.ts +183 -0
  110. package/labs/texture.js +351 -0
  111. package/labs/texture.js.map +1 -0
  112. package/labs/viewerLabs.d.ts +51 -0
  113. package/labs/viewerLabs.js +134 -0
  114. package/labs/viewerLabs.js.map +1 -0
  115. package/loader/modelLoader.d.ts +56 -0
  116. package/loader/modelLoader.js +199 -0
  117. package/loader/modelLoader.js.map +1 -0
  118. package/loader/plugins/applyMaterialConfig.d.ts +12 -0
  119. package/loader/plugins/applyMaterialConfig.js +16 -0
  120. package/loader/plugins/applyMaterialConfig.js.map +1 -0
  121. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -0
  122. package/loader/plugins/extendedMaterialLoaderPlugin.js +16 -0
  123. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -0
  124. package/loader/plugins/index.d.ts +19 -0
  125. package/loader/plugins/index.js +44 -0
  126. package/loader/plugins/index.js.map +1 -0
  127. package/loader/plugins/loaderPlugin.d.ts +24 -0
  128. package/loader/plugins/loaderPlugin.js +2 -0
  129. package/loader/plugins/loaderPlugin.js.map +1 -0
  130. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -0
  131. package/loader/plugins/msftLodLoaderPlugin.js +21 -0
  132. package/loader/plugins/msftLodLoaderPlugin.js.map +1 -0
  133. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -0
  134. package/loader/plugins/telemetryLoaderPlugin.js +36 -0
  135. package/loader/plugins/telemetryLoaderPlugin.js.map +1 -0
  136. package/managers/observablesManager.d.ts +66 -0
  137. package/managers/observablesManager.js +35 -0
  138. package/managers/observablesManager.js.map +1 -0
  139. package/managers/sceneManager.d.ts +245 -0
  140. package/managers/sceneManager.js +1375 -0
  141. package/managers/sceneManager.js.map +1 -0
  142. package/managers/telemetryManager.d.ts +78 -0
  143. package/managers/telemetryManager.js +117 -0
  144. package/managers/telemetryManager.js.map +1 -0
  145. package/model/modelAnimation.d.ts +215 -0
  146. package/model/modelAnimation.js +237 -0
  147. package/model/modelAnimation.js.map +1 -0
  148. package/model/viewerModel.d.ts +233 -0
  149. package/model/viewerModel.js +673 -0
  150. package/model/viewerModel.js.map +1 -0
  151. package/optimizer/custom/extended.d.ts +13 -0
  152. package/optimizer/custom/extended.js +101 -0
  153. package/optimizer/custom/extended.js.map +1 -0
  154. package/optimizer/custom/index.d.ts +9 -0
  155. package/optimizer/custom/index.js +26 -0
  156. package/optimizer/custom/index.js.map +1 -0
  157. package/package.json +29 -16
  158. package/readme.md +21 -35
  159. package/renderOnlyIndex.d.ts +11 -0
  160. package/renderOnlyIndex.js +18 -0
  161. package/renderOnlyIndex.js.map +1 -0
  162. package/templating/eventManager.d.ts +35 -0
  163. package/templating/eventManager.js +66 -0
  164. package/templating/eventManager.js.map +1 -0
  165. package/templating/plugins/hdButtonPlugin.d.ts +9 -0
  166. package/templating/plugins/hdButtonPlugin.js +21 -0
  167. package/templating/plugins/hdButtonPlugin.js.map +1 -0
  168. package/templating/plugins/printButton.d.ts +9 -0
  169. package/templating/plugins/printButton.js +40 -0
  170. package/templating/plugins/printButton.js.map +1 -0
  171. package/templating/templateManager.d.ts +197 -0
  172. package/templating/templateManager.js +561 -0
  173. package/templating/templateManager.js.map +1 -0
  174. package/templating/viewerTemplatePlugin.d.ts +21 -0
  175. package/templating/viewerTemplatePlugin.js +69 -0
  176. package/templating/viewerTemplatePlugin.js.map +1 -0
  177. package/viewer/defaultViewer.d.ts +130 -0
  178. package/viewer/defaultViewer.js +675 -0
  179. package/viewer/defaultViewer.js.map +1 -0
  180. package/viewer/renderOnlyViewer.d.ts +9 -0
  181. package/viewer/renderOnlyViewer.js +46 -0
  182. package/viewer/renderOnlyViewer.js.map +1 -0
  183. package/viewer/viewer.d.ts +258 -0
  184. package/viewer/viewer.js +783 -0
  185. package/viewer/viewer.js.map +1 -0
  186. package/viewer/viewerManager.d.ts +58 -0
  187. package/viewer/viewerManager.js +91 -0
  188. package/viewer/viewerManager.js.map +1 -0
  189. package/viewer/viewerWithTemplate.d.ts +9 -0
  190. package/viewer/viewerWithTemplate.js +20 -0
  191. package/viewer/viewerWithTemplate.js.map +1 -0
  192. package/dist/babylon-viewer.esm.js +0 -112518
  193. package/dist/babylon-viewer.esm.js.map +0 -1
  194. package/dist/babylon-viewer.esm.min.js +0 -2
  195. package/dist/babylon-viewer.esm.min.js.map +0 -1
  196. package/lib/index.d.ts +0 -132
  197. package/lib/index.js +0 -348
  198. package/lib/index.js.map +0 -1
@@ -0,0 +1,1375 @@
1
+ import { getConfigurationKey } from "../configuration/configuration.js";
2
+ import { ModelState } from "../model/viewerModel.js";
3
+ import { extendClassWithConfig, deepmerge } from "../helper/index.js";
4
+ import { ViewerLabs } from "../labs/viewerLabs.js";
5
+ import { getCustomOptimizerByName } from "../optimizer/custom/index.js";
6
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
7
+ import { SceneOptimizer, SceneOptimizerOptions } from "@babylonjs/core/Misc/sceneOptimizer.js";
8
+ import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera.js";
9
+ import { Light } from "@babylonjs/core/Lights/light.js";
10
+ import { EnvironmentHelper } from "@babylonjs/core/Helpers/environmentHelper.js";
11
+ import { Color3, Quaternion, Vector3, Axis, Matrix } from "@babylonjs/core/Maths/math.js";
12
+ import { DefaultRenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js";
13
+ import { Animation } from "@babylonjs/core/Animations/index.js";
14
+ import { AnimationPropertiesOverride } from "@babylonjs/core/Animations/animationPropertiesOverride.js";
15
+ import { RenderTargetTexture } from "@babylonjs/core/Materials/Textures/renderTargetTexture.js";
16
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
17
+ import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
18
+ import { CubeTexture } from "@babylonjs/core/Materials/Textures/cubeTexture.js";
19
+ import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight.js";
20
+ import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
21
+ import { CreatePlane } from "@babylonjs/core/Meshes/Builders/planeBuilder.js";
22
+ import { Tags } from "@babylonjs/core/Misc/tags.js";
23
+ import { Scene } from "@babylonjs/core/scene.js";
24
+ import { ShadowGenerator } from "@babylonjs/core/Lights/Shadows/shadowGenerator.js";
25
+ import { Constants } from "@babylonjs/core/Engines/constants.js";
26
+ import "@babylonjs/core/Audio/audioSceneComponent.js";
27
+ import "@babylonjs/core/Helpers/sceneHelpers.js";
28
+ import "@babylonjs/core/Misc/observable.extensions.js";
29
+ var SceneManager = /** @class */ (function () {
30
+ function SceneManager(_engine, _configurationContainer, _observablesManager) {
31
+ var _this = this;
32
+ this._engine = _engine;
33
+ this._configurationContainer = _configurationContainer;
34
+ this._observablesManager = _observablesManager;
35
+ this._white = Color3.White();
36
+ this._forceShadowUpdate = false;
37
+ this._processShadows = true;
38
+ this._groundEnabled = true;
39
+ this._groundMirrorEnabled = true;
40
+ this._defaultRenderingPipelineEnabled = false;
41
+ this._globalConfiguration = {};
42
+ this._defaultRenderingPipelineShouldBuild = true;
43
+ // default from rendering pipeline
44
+ this._bloomEnabled = false;
45
+ // default from rendering pipeline
46
+ this._fxaaEnabled = false;
47
+ this._focusOnModel = function (model) {
48
+ var boundingInfo = model.rootMesh.getHierarchyBoundingVectors(true);
49
+ var sizeVec = boundingInfo.max.subtract(boundingInfo.min);
50
+ var halfSizeVec = sizeVec.scale(0.5);
51
+ var center = boundingInfo.min.add(halfSizeVec);
52
+ _this.camera.setTarget(center);
53
+ _this.camera.alpha = (_this._globalConfiguration.camera && _this._globalConfiguration.camera.alpha) || _this.camera.alpha;
54
+ _this.camera.beta = (_this._globalConfiguration.camera && _this._globalConfiguration.camera.beta) || _this.camera.beta;
55
+ _this.camera.radius = (_this._globalConfiguration.camera && _this._globalConfiguration.camera.radius) || _this.camera.radius;
56
+ var sceneDiagonalLenght = sizeVec.length();
57
+ if (isFinite(sceneDiagonalLenght)) {
58
+ _this.camera.upperRadiusLimit = sceneDiagonalLenght * 4;
59
+ }
60
+ if (_this._configurationContainer.configuration) {
61
+ _this._configureEnvironment(_this._configurationContainer.configuration.skybox, _this._configurationContainer.configuration.ground);
62
+ }
63
+ /*this.scene.lights.filter(light => light instanceof ShadowLight).forEach(light => {
64
+ // casting ais safe, due to the constraints tested before
65
+ (<ShadowLight>light).setDirectionToTarget(center);
66
+ });*/
67
+ };
68
+ this._cameraBehaviorMapping = {};
69
+ this.models = [];
70
+ this.onCameraConfiguredObservable = new Observable();
71
+ this.onLightsConfiguredObservable = new Observable();
72
+ this.onModelsConfiguredObservable = new Observable();
73
+ this.onSceneConfiguredObservable = new Observable();
74
+ this.onSceneInitObservable = new Observable(undefined, true);
75
+ this.onSceneOptimizerConfiguredObservable = new Observable();
76
+ this.onEnvironmentConfiguredObservable = new Observable();
77
+ this.onVRConfiguredObservable = new Observable();
78
+ //this._viewer.onEngineInitObservable.add(() => {
79
+ this._handleHardwareLimitations();
80
+ //});
81
+ this.onSceneInitObservable.add(function (scene) {
82
+ _this.scene.animationPropertiesOverride = _this.scene.animationPropertiesOverride || new AnimationPropertiesOverride();
83
+ _this.labs = new ViewerLabs(scene);
84
+ var updateShadows = function () {
85
+ for (var _i = 0, _a = _this.scene.lights; _i < _a.length; _i++) {
86
+ var light = _a[_i];
87
+ var generators = light.getShadowGenerators();
88
+ if (generators) {
89
+ // Processing shadows if animates
90
+ var iterator = generators.values();
91
+ for (var key = iterator.next(); key.done !== true; key = iterator.next()) {
92
+ var generator = key.value;
93
+ var shadowMap = generator.getShadowMap();
94
+ if (shadowMap) {
95
+ shadowMap.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ };
101
+ scene.registerBeforeRender(function () {
102
+ if (_this._forceShadowUpdate || (scene.animatables && scene.animatables.length > 0)) {
103
+ // make sure all models are loaded
104
+ updateShadows();
105
+ _this._forceShadowUpdate = false;
106
+ }
107
+ else if (!_this.models.every(function (model) {
108
+ if (!model.shadowsRenderedAfterLoad) {
109
+ model.shadowsRenderedAfterLoad = true;
110
+ return false;
111
+ }
112
+ return model.state === ModelState.COMPLETE && !model.currentAnimation;
113
+ })) {
114
+ updateShadows();
115
+ }
116
+ });
117
+ return _this._observablesManager && _this._observablesManager.onSceneInitObservable.notifyObserversWithPromise(_this.scene);
118
+ });
119
+ if (this._observablesManager) {
120
+ this._observablesManager.onModelLoadedObservable.add(function (model) {
121
+ for (var _i = 0, _a = _this.scene.lights; _i < _a.length; _i++) {
122
+ var light = _a[_i];
123
+ var generators = light.getShadowGenerators();
124
+ if (generators) {
125
+ // Processing shadows if animates
126
+ var iterator = generators.values();
127
+ for (var key = iterator.next(); key.done !== true; key = iterator.next()) {
128
+ var generator = key.value;
129
+ var shadowMap = generator.getShadowMap();
130
+ if (shadowMap) {
131
+ shadowMap.refreshRate = RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ _this._focusOnModel(model);
137
+ });
138
+ this._observablesManager.onModelAddedObservable.add(function (model) {
139
+ _this.models.push(model);
140
+ });
141
+ this._observablesManager.onModelRemovedObservable.add(function (model) {
142
+ _this.models.splice(_this.models.indexOf(model), 1);
143
+ });
144
+ }
145
+ }
146
+ Object.defineProperty(SceneManager.prototype, "defaultRenderingPipeline", {
147
+ get: function () {
148
+ return this._defaultRenderingPipeline;
149
+ },
150
+ enumerable: false,
151
+ configurable: true
152
+ });
153
+ Object.defineProperty(SceneManager.prototype, "vrHelper", {
154
+ get: function () {
155
+ return this._vrHelper;
156
+ },
157
+ enumerable: false,
158
+ configurable: true
159
+ });
160
+ Object.defineProperty(SceneManager.prototype, "isHdrSupported", {
161
+ /**
162
+ * Returns a boolean representing HDR support
163
+ */
164
+ get: function () {
165
+ return this._hdrSupport;
166
+ },
167
+ enumerable: false,
168
+ configurable: true
169
+ });
170
+ Object.defineProperty(SceneManager.prototype, "mainColor", {
171
+ /**
172
+ * Return the main color defined in the configuration.
173
+ */
174
+ get: function () {
175
+ return this._configurationContainer.mainColor;
176
+ },
177
+ enumerable: false,
178
+ configurable: true
179
+ });
180
+ Object.defineProperty(SceneManager.prototype, "reflectionColor", {
181
+ get: function () {
182
+ return this._configurationContainer.reflectionColor;
183
+ },
184
+ enumerable: false,
185
+ configurable: true
186
+ });
187
+ Object.defineProperty(SceneManager.prototype, "animationBlendingEnabled", {
188
+ get: function () {
189
+ return this.scene && this.scene.animationPropertiesOverride.enableBlending;
190
+ },
191
+ set: function (value) {
192
+ this.scene.animationPropertiesOverride.enableBlending = value;
193
+ },
194
+ enumerable: false,
195
+ configurable: true
196
+ });
197
+ Object.defineProperty(SceneManager.prototype, "observablesManager", {
198
+ get: function () {
199
+ return this._observablesManager;
200
+ },
201
+ enumerable: false,
202
+ configurable: true
203
+ });
204
+ Object.defineProperty(SceneManager.prototype, "processShadows", {
205
+ /**
206
+ * The flag defining whether shadows are rendered constantly or once.
207
+ */
208
+ get: function () {
209
+ return this._processShadows;
210
+ },
211
+ /**
212
+ * Should shadows be rendered every frame, or only once and stop.
213
+ * This can be used to optimize a scene.
214
+ *
215
+ * Not that the shadows will NOT disapear but will remain in place.
216
+ * @param process if true shadows will be updated once every frame. if false they will stop being updated.
217
+ */
218
+ set: function (process) {
219
+ var refreshType = process ? RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME : RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
220
+ for (var _i = 0, _a = this.scene.lights; _i < _a.length; _i++) {
221
+ var light = _a[_i];
222
+ var generators = light.getShadowGenerators();
223
+ if (generators) {
224
+ var iterator = generators.values();
225
+ for (var key = iterator.next(); key.done !== true; key = iterator.next()) {
226
+ var generator = key.value;
227
+ var shadowMap = generator.getShadowMap();
228
+ if (shadowMap) {
229
+ shadowMap.refreshRate = refreshType;
230
+ }
231
+ }
232
+ }
233
+ }
234
+ this._processShadows = process;
235
+ },
236
+ enumerable: false,
237
+ configurable: true
238
+ });
239
+ Object.defineProperty(SceneManager.prototype, "groundEnabled", {
240
+ get: function () {
241
+ return this._groundEnabled;
242
+ },
243
+ set: function (newValue) {
244
+ if (newValue === this._groundEnabled) {
245
+ return;
246
+ }
247
+ this._groundEnabled = newValue;
248
+ if (this.environmentHelper && this.environmentHelper.ground) {
249
+ this.environmentHelper.ground.setEnabled(this._groundEnabled);
250
+ }
251
+ },
252
+ enumerable: false,
253
+ configurable: true
254
+ });
255
+ Object.defineProperty(SceneManager.prototype, "groundMirrorEnabled", {
256
+ /**
257
+ * gets whether the reflection is disabled.
258
+ */
259
+ get: function () {
260
+ return this._groundMirrorEnabled;
261
+ },
262
+ /**
263
+ * sets whether the reflection is disabled.
264
+ */
265
+ set: function (value) {
266
+ if (this._groundMirrorEnabled === value) {
267
+ return;
268
+ }
269
+ this._groundMirrorEnabled = value;
270
+ if (this.environmentHelper && this.environmentHelper.groundMaterial && this.environmentHelper.groundMirror) {
271
+ if (!value) {
272
+ this.environmentHelper.groundMaterial.reflectionTexture = null;
273
+ }
274
+ else {
275
+ this.environmentHelper.groundMaterial.reflectionTexture = this.environmentHelper.groundMirror;
276
+ }
277
+ }
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
282
+ Object.defineProperty(SceneManager.prototype, "defaultRenderingPipelineEnabled", {
283
+ get: function () {
284
+ return this._defaultRenderingPipelineEnabled;
285
+ },
286
+ set: function (value) {
287
+ if (value === this._defaultRenderingPipelineEnabled) {
288
+ return;
289
+ }
290
+ this._defaultRenderingPipelineEnabled = value;
291
+ this._rebuildPostprocesses();
292
+ if (this._defaultRenderingPipeline) {
293
+ this._defaultRenderingPipelineShouldBuild = false;
294
+ this._defaultRenderingPipeline.prepare();
295
+ this.scene.imageProcessingConfiguration.applyByPostProcess = true;
296
+ }
297
+ },
298
+ enumerable: false,
299
+ configurable: true
300
+ });
301
+ /**
302
+ * Sets the engine flags to unlock all babylon features.
303
+ * Can also be configured using the scene.flags configuration object
304
+ */
305
+ SceneManager.prototype.unlockBabylonFeatures = function () {
306
+ this.scene.shadowsEnabled = true;
307
+ this.scene.particlesEnabled = true;
308
+ this.scene.postProcessesEnabled = true;
309
+ this.scene.collisionsEnabled = true;
310
+ this.scene.lightsEnabled = true;
311
+ this.scene.texturesEnabled = true;
312
+ this.scene.lensFlaresEnabled = true;
313
+ this.scene.proceduralTexturesEnabled = true;
314
+ this.scene.renderTargetsEnabled = true;
315
+ this.scene.spritesEnabled = true;
316
+ this.scene.skeletonsEnabled = true;
317
+ this.scene.audioEnabled = true;
318
+ };
319
+ /**
320
+ * initialize the scene. Calling this function again will dispose the old scene, if exists.
321
+ * @param sceneConfiguration the configuration of the scene
322
+ * @returns a promise that resolves when the scene is ready
323
+ */
324
+ SceneManager.prototype.initScene = function (sceneConfiguration) {
325
+ if (sceneConfiguration === void 0) { sceneConfiguration = {}; }
326
+ // if the scene exists, dispose it.
327
+ if (this.scene) {
328
+ this.scene.dispose();
329
+ }
330
+ // create a new scene
331
+ this.scene = new Scene(this._engine);
332
+ this._configurationContainer.scene = this.scene;
333
+ // set a default PBR material
334
+ if (!sceneConfiguration.defaultMaterial) {
335
+ var defaultMaterial = new PBRMaterial("defaultMaterial", this.scene);
336
+ defaultMaterial.reflectivityColor = new Color3(0.1, 0.1, 0.1);
337
+ defaultMaterial.microSurface = 0.6;
338
+ if (this.scene.defaultMaterial) {
339
+ this.scene.defaultMaterial.dispose();
340
+ }
341
+ this.scene.defaultMaterial = defaultMaterial;
342
+ }
343
+ this.scene.animationPropertiesOverride = new AnimationPropertiesOverride();
344
+ Animation.AllowMatricesInterpolation = true;
345
+ /*if (sceneConfiguration.glow) {
346
+ let options: Partial<IGlowLayerOptions> = {
347
+ mainTextureFixedSize: 512
348
+ };
349
+ if (typeof sceneConfiguration.glow === 'object') {
350
+ options = sceneConfiguration.glow
351
+ }
352
+ var gl = new GlowLayer("glow", this.scene, options);
353
+ }*/
354
+ return this.onSceneInitObservable.notifyObserversWithPromise(this.scene);
355
+ };
356
+ SceneManager.prototype.clearScene = function (clearModels, clearLights) {
357
+ if (clearModels === void 0) { clearModels = true; }
358
+ if (clearLights === void 0) { clearLights = false; }
359
+ if (clearModels) {
360
+ this.models.forEach(function (m) { return m.dispose(); });
361
+ this.models.length = 0;
362
+ }
363
+ if (clearLights) {
364
+ this.scene.lights.forEach(function (l) { return l.dispose(); });
365
+ }
366
+ };
367
+ /**
368
+ * This will update the scene's configuration, including camera, lights, environment.
369
+ * @param newConfiguration the delta that should be configured. This includes only the changes
370
+ */
371
+ SceneManager.prototype.updateConfiguration = function (newConfiguration) {
372
+ var _this = this;
373
+ if (this._configurationContainer) {
374
+ this._globalConfiguration = this._configurationContainer.configuration;
375
+ }
376
+ else {
377
+ this._globalConfiguration = newConfiguration;
378
+ }
379
+ // update scene configuration
380
+ if (newConfiguration.scene) {
381
+ this._configureScene(newConfiguration.scene);
382
+ }
383
+ // optimizer
384
+ if (newConfiguration.optimizer !== undefined) {
385
+ this._configureOptimizer(newConfiguration.optimizer);
386
+ }
387
+ // configure model
388
+ /*if (newConfiguration.model && typeof newConfiguration.model === 'object') {
389
+ this._configureModel(newConfiguration.model);
390
+ }*/
391
+ // lights
392
+ this._configureLights(newConfiguration.lights);
393
+ // environment
394
+ if (newConfiguration.skybox !== undefined || newConfiguration.ground !== undefined) {
395
+ this._configureEnvironment(newConfiguration.skybox, newConfiguration.ground);
396
+ }
397
+ // camera
398
+ this._configureCamera(newConfiguration.camera);
399
+ if (newConfiguration.environmentMap !== undefined) {
400
+ this._configureEnvironmentMap(newConfiguration.environmentMap);
401
+ }
402
+ if (newConfiguration.vr !== undefined) {
403
+ this._configureVR(newConfiguration.vr);
404
+ }
405
+ if (newConfiguration.lab) {
406
+ // rendering pipelines
407
+ if (newConfiguration.lab.defaultRenderingPipelines) {
408
+ var pipelineConfig = newConfiguration.lab.defaultRenderingPipelines;
409
+ if (typeof pipelineConfig === "boolean") {
410
+ this.defaultRenderingPipelineEnabled = pipelineConfig;
411
+ }
412
+ else {
413
+ this.defaultRenderingPipelineEnabled = true;
414
+ }
415
+ }
416
+ if (this.environmentHelper && newConfiguration.lab.environmentMainColor) {
417
+ var mainColor = new Color3(newConfiguration.lab.environmentMainColor.r, newConfiguration.lab.environmentMainColor.g, newConfiguration.lab.environmentMainColor.b);
418
+ this.environmentHelper.setMainColor(mainColor);
419
+ }
420
+ if (newConfiguration.lab.globalLightRotation !== undefined) {
421
+ // rotate all lights that are shadow lights
422
+ this.scene.lights
423
+ .filter(function (light) { return light instanceof ShadowLight; })
424
+ .forEach(function (light) {
425
+ // casting and '!' are safe, due to the constraints tested before
426
+ _this.labs.rotateShadowLight(light, newConfiguration.lab.globalLightRotation);
427
+ });
428
+ this._forceShadowUpdate = true;
429
+ }
430
+ }
431
+ if (this._defaultRenderingPipeline && this._defaultRenderingPipeline.imageProcessing) {
432
+ this._defaultRenderingPipeline.imageProcessing.fromLinearSpace = true;
433
+ }
434
+ if (this._defaultRenderingPipelineShouldBuild && this._defaultRenderingPipeline) {
435
+ this._defaultRenderingPipelineShouldBuild = false;
436
+ this._defaultRenderingPipeline.prepare();
437
+ }
438
+ };
439
+ SceneManager.prototype._rebuildPostprocesses = function (configuration) {
440
+ if (!this._defaultRenderingPipelineEnabled || !getConfigurationKey("scene.imageProcessingConfiguration.isEnabled", this._globalConfiguration)) {
441
+ if (this._defaultRenderingPipeline) {
442
+ this._defaultRenderingPipeline.dispose();
443
+ this._defaultRenderingPipeline = null;
444
+ this.scene.autoClearDepthAndStencil = true;
445
+ this.scene.autoClear = true;
446
+ this.scene.imageProcessingConfiguration.applyByPostProcess = false;
447
+ }
448
+ return;
449
+ }
450
+ var pipelineConfig = configuration || (this._globalConfiguration.lab && this._globalConfiguration.lab.defaultRenderingPipelines);
451
+ if (pipelineConfig) {
452
+ if (!this._defaultRenderingPipeline) {
453
+ // Create pipeline in manual mode to avoid triggering multiple shader compilations
454
+ this._defaultRenderingPipeline = new DefaultRenderingPipeline("default rendering pipeline", this._hdrSupport, this.scene, [this.camera], false);
455
+ }
456
+ this.scene.autoClear = false;
457
+ this.scene.autoClearDepthAndStencil = false;
458
+ this._defaultRenderingPipelineShouldBuild = true;
459
+ var bloomEnabled = this._bloomEnabled;
460
+ if (typeof pipelineConfig !== "boolean") {
461
+ extendClassWithConfig(this._defaultRenderingPipeline, pipelineConfig);
462
+ this._bloomEnabled = !!pipelineConfig.bloomEnabled;
463
+ this._fxaaEnabled = !!pipelineConfig.fxaaEnabled;
464
+ bloomEnabled = this._bloomEnabled && pipelineConfig.bloomWeight !== undefined && pipelineConfig.bloomWeight > 0;
465
+ this._defaultRenderingPipeline.bloomWeight = (pipelineConfig.bloomWeight !== undefined && pipelineConfig.bloomWeight) || this._defaultRenderingPipeline.bloomWeight;
466
+ }
467
+ this._defaultRenderingPipeline.bloomEnabled = bloomEnabled;
468
+ this._defaultRenderingPipeline.fxaaEnabled = this.fxaaEnabled;
469
+ }
470
+ };
471
+ Object.defineProperty(SceneManager.prototype, "bloomEnabled", {
472
+ get: function () {
473
+ return this._bloomEnabled;
474
+ },
475
+ set: function (value) {
476
+ if (this._bloomEnabled === value) {
477
+ return;
478
+ }
479
+ this._bloomEnabled = value;
480
+ this._rebuildPostprocesses();
481
+ if (this._defaultRenderingPipeline) {
482
+ this._defaultRenderingPipelineShouldBuild = false;
483
+ this._defaultRenderingPipeline.prepare();
484
+ this.scene.imageProcessingConfiguration.applyByPostProcess = true;
485
+ }
486
+ },
487
+ enumerable: false,
488
+ configurable: true
489
+ });
490
+ Object.defineProperty(SceneManager.prototype, "fxaaEnabled", {
491
+ get: function () {
492
+ return this._fxaaEnabled;
493
+ },
494
+ set: function (value) {
495
+ if (this._fxaaEnabled === value) {
496
+ return;
497
+ }
498
+ this._fxaaEnabled = value;
499
+ this._rebuildPostprocesses();
500
+ if (this._defaultRenderingPipeline) {
501
+ this._defaultRenderingPipelineShouldBuild = false;
502
+ this._defaultRenderingPipeline.prepare();
503
+ this.scene.imageProcessingConfiguration.applyByPostProcess = true;
504
+ }
505
+ },
506
+ enumerable: false,
507
+ configurable: true
508
+ });
509
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
510
+ SceneManager.prototype.setDefaultMaterial = function (sceneConfig) { };
511
+ /**
512
+ * internally configure the scene using the provided configuration.
513
+ * The scene will not be recreated, but just updated.
514
+ * @param sceneConfig the (new) scene configuration
515
+ */
516
+ SceneManager.prototype._configureScene = function (sceneConfig) {
517
+ // sanity check!
518
+ if (!this.scene) {
519
+ return;
520
+ }
521
+ var cc = sceneConfig.clearColor;
522
+ var oldcc = this.scene.clearColor;
523
+ if (cc) {
524
+ if (cc.r !== undefined) {
525
+ oldcc.r = cc.r;
526
+ }
527
+ if (cc.g !== undefined) {
528
+ oldcc.g = cc.g;
529
+ }
530
+ if (cc.b !== undefined) {
531
+ oldcc.b = cc.b;
532
+ }
533
+ if (cc.a !== undefined) {
534
+ oldcc.a = cc.a;
535
+ }
536
+ }
537
+ if (sceneConfig.assetsRootURL) {
538
+ this._assetsRootURL = sceneConfig.assetsRootURL;
539
+ }
540
+ // image processing configuration - optional.
541
+ if (sceneConfig.imageProcessingConfiguration) {
542
+ extendClassWithConfig(this.scene.imageProcessingConfiguration, sceneConfig.imageProcessingConfiguration);
543
+ }
544
+ //animation properties override
545
+ if (sceneConfig.animationPropertiesOverride) {
546
+ extendClassWithConfig(this.scene.animationPropertiesOverride, sceneConfig.animationPropertiesOverride);
547
+ }
548
+ if (sceneConfig.environmentTexture) {
549
+ if (!(this.scene.environmentTexture && this.scene.environmentTexture.url === sceneConfig.environmentTexture)) {
550
+ if (this.scene.environmentTexture && this.scene.environmentTexture.dispose) {
551
+ this.scene.environmentTexture.dispose();
552
+ }
553
+ var environmentTexture = CubeTexture.CreateFromPrefilteredData(sceneConfig.environmentTexture, this.scene);
554
+ this.scene.environmentTexture = environmentTexture;
555
+ }
556
+ }
557
+ if (sceneConfig.debug === true) {
558
+ this.scene.debugLayer.show();
559
+ }
560
+ else if (sceneConfig.debug === false) {
561
+ if (this.scene.debugLayer.isVisible()) {
562
+ this.scene.debugLayer.hide();
563
+ }
564
+ }
565
+ if (sceneConfig.disableHdr) {
566
+ this._handleHardwareLimitations(false);
567
+ }
568
+ else {
569
+ this._handleHardwareLimitations(true);
570
+ }
571
+ if (sceneConfig.renderInBackground !== undefined) {
572
+ this._engine.renderEvenInBackground = !!sceneConfig.renderInBackground;
573
+ }
574
+ var canvas = this._engine.getInputElement();
575
+ if (canvas) {
576
+ if (this.camera && sceneConfig.disableCameraControl) {
577
+ this.camera.detachControl();
578
+ }
579
+ else if (this.camera && sceneConfig.disableCameraControl === false) {
580
+ this.camera.attachControl();
581
+ }
582
+ }
583
+ this.setDefaultMaterial(sceneConfig);
584
+ if (sceneConfig.flags) {
585
+ extendClassWithConfig(this.scene, sceneConfig.flags);
586
+ }
587
+ this.onSceneConfiguredObservable.notifyObservers({
588
+ sceneManager: this,
589
+ object: this.scene,
590
+ newConfiguration: sceneConfig,
591
+ });
592
+ };
593
+ /**
594
+ * Configure the scene optimizer.
595
+ * The existing scene optimizer will be disposed and a new one will be created.
596
+ * @param optimizerConfig the (new) optimizer configuration
597
+ */
598
+ SceneManager.prototype._configureOptimizer = function (optimizerConfig) {
599
+ var _this = this;
600
+ if (typeof optimizerConfig === "boolean") {
601
+ if (this.sceneOptimizer) {
602
+ this.sceneOptimizer.stop();
603
+ this.sceneOptimizer.dispose();
604
+ delete this.sceneOptimizer;
605
+ }
606
+ if (optimizerConfig) {
607
+ this.sceneOptimizer = new SceneOptimizer(this.scene);
608
+ this.sceneOptimizer.start();
609
+ }
610
+ }
611
+ else {
612
+ var optimizerOptions = new SceneOptimizerOptions(optimizerConfig.targetFrameRate, optimizerConfig.trackerDuration);
613
+ // check for degradation
614
+ if (optimizerConfig.degradation) {
615
+ switch (optimizerConfig.degradation) {
616
+ case "low":
617
+ optimizerOptions = SceneOptimizerOptions.LowDegradationAllowed(optimizerConfig.targetFrameRate);
618
+ break;
619
+ case "moderate":
620
+ optimizerOptions = SceneOptimizerOptions.ModerateDegradationAllowed(optimizerConfig.targetFrameRate);
621
+ break;
622
+ case "hight":
623
+ optimizerOptions = SceneOptimizerOptions.HighDegradationAllowed(optimizerConfig.targetFrameRate);
624
+ break;
625
+ }
626
+ }
627
+ if (this.sceneOptimizer) {
628
+ this.sceneOptimizer.stop();
629
+ this.sceneOptimizer.dispose();
630
+ }
631
+ if (optimizerConfig.custom) {
632
+ var customOptimizer_1 = getCustomOptimizerByName(optimizerConfig.custom, optimizerConfig.improvementMode);
633
+ if (customOptimizer_1) {
634
+ optimizerOptions.addCustomOptimization(function () {
635
+ return customOptimizer_1(_this);
636
+ }, function () {
637
+ return "Babylon Viewer ".concat(optimizerConfig.custom, " custom optimization");
638
+ });
639
+ }
640
+ }
641
+ this.sceneOptimizer = new SceneOptimizer(this.scene, optimizerOptions, optimizerConfig.autoGeneratePriorities, optimizerConfig.improvementMode);
642
+ this.sceneOptimizer.start();
643
+ }
644
+ this.onSceneOptimizerConfiguredObservable.notifyObservers({
645
+ sceneManager: this,
646
+ object: this.sceneOptimizer,
647
+ newConfiguration: optimizerConfig,
648
+ });
649
+ };
650
+ /**
651
+ * configure all models using the configuration.
652
+ * @param modelConfiguration the configuration to use to reconfigure the models
653
+ */
654
+ /*protected _configureModel(modelConfiguration: Partial<IModelConfiguration>) {
655
+ this.models.forEach(model => {
656
+ model.updateConfiguration(modelConfiguration);
657
+ });
658
+
659
+ this.onModelsConfiguredObservable.notifyObservers({
660
+ sceneManager: this,
661
+ object: this.models,
662
+ newConfiguration: modelConfiguration
663
+ });
664
+ }*/
665
+ SceneManager.prototype._configureVR = function (vrConfig) {
666
+ var _this = this;
667
+ if (vrConfig.disabled) {
668
+ if (this._vrHelper) {
669
+ if (this._vrHelper.isInVRMode) {
670
+ this._vrHelper.exitVR();
671
+ }
672
+ this._vrHelper.dispose();
673
+ this._vrHelper = undefined;
674
+ }
675
+ return;
676
+ }
677
+ var vrOptions = deepmerge({
678
+ useCustomVRButton: true,
679
+ createDeviceOrientationCamera: false,
680
+ trackPosition: true,
681
+ }, vrConfig.vrOptions || {});
682
+ this._vrHelper = this.scene.createDefaultVRExperience(vrOptions);
683
+ if (!vrConfig.disableInteractions) {
684
+ this._vrHelper.enableInteractions();
685
+ }
686
+ if (!vrConfig.disableTeleportation) {
687
+ var floorMeshName = vrConfig.overrideFloorMeshName || "BackgroundPlane";
688
+ this._vrHelper.enableTeleportation({
689
+ floorMeshName: floorMeshName,
690
+ });
691
+ }
692
+ this._vrHelper.onEnteringVRObservable.add(function () {
693
+ if (_this._observablesManager) {
694
+ _this._observablesManager.onEnteringVRObservable.notifyObservers(_this);
695
+ }
696
+ });
697
+ this._vrHelper.onExitingVRObservable.add(function () {
698
+ if (_this._observablesManager) {
699
+ _this._observablesManager.onExitingVRObservable.notifyObservers(_this);
700
+ }
701
+ });
702
+ this.onVRConfiguredObservable.notifyObservers({
703
+ sceneManager: this,
704
+ object: this._vrHelper,
705
+ newConfiguration: vrConfig,
706
+ });
707
+ };
708
+ SceneManager.prototype._configureEnvironmentMap = function (environmentMapConfiguration) {
709
+ if (environmentMapConfiguration.texture) {
710
+ this.scene.environmentTexture = new CubeTexture(this._getAssetUrl(environmentMapConfiguration.texture), this.scene);
711
+ }
712
+ //sanity check
713
+ if (this.scene.environmentTexture) {
714
+ var rotatquatRotationionY = Quaternion.RotationAxis(Axis.Y, environmentMapConfiguration.rotationY || 0);
715
+ Matrix.FromQuaternionToRef(rotatquatRotationionY, this.scene.environmentTexture.getReflectionTextureMatrix());
716
+ }
717
+ // process mainColor changes:
718
+ if (environmentMapConfiguration.mainColor) {
719
+ this._configurationContainer.mainColor = this.mainColor || Color3.White();
720
+ var mc = environmentMapConfiguration.mainColor;
721
+ if (mc.r !== undefined) {
722
+ this.mainColor.r = mc.r;
723
+ }
724
+ if (mc.g !== undefined) {
725
+ this.mainColor.g = mc.g;
726
+ }
727
+ if (mc.b !== undefined) {
728
+ this.mainColor.b = mc.b;
729
+ }
730
+ this.reflectionColor.copyFrom(this.mainColor);
731
+ var environmentTint = getConfigurationKey("environmentMap.tintLevel", this._globalConfiguration) || 0;
732
+ // reflection color
733
+ this.reflectionColor.toLinearSpaceToRef(this.reflectionColor);
734
+ this.reflectionColor.scaleToRef(1 / this.scene.imageProcessingConfiguration.exposure, this.reflectionColor);
735
+ var tmpColor3 = Color3.Lerp(this._white, this.reflectionColor, environmentTint);
736
+ this.reflectionColor.copyFrom(tmpColor3);
737
+ //update the environment, if exists
738
+ if (this.environmentHelper) {
739
+ if (this.environmentHelper.groundMaterial) {
740
+ this.environmentHelper.groundMaterial._perceptualColor = this.mainColor;
741
+ }
742
+ if (this.environmentHelper.skyboxMaterial) {
743
+ this.environmentHelper.skyboxMaterial._perceptualColor = this.mainColor;
744
+ }
745
+ }
746
+ }
747
+ };
748
+ /**
749
+ * (Re) configure the camera. The camera will only be created once and from this point will only be reconfigured.
750
+ * @param cameraConfig the new camera configuration
751
+ */
752
+ SceneManager.prototype._configureCamera = function (cameraConfig) {
753
+ var _this = this;
754
+ if (cameraConfig === void 0) { cameraConfig = {}; }
755
+ if (!this.scene.activeCamera) {
756
+ // Inline scene.createDefaultCamera to reduce file size
757
+ // Dispose existing camera in replace mode.
758
+ if (this.scene.activeCamera) {
759
+ this.scene.activeCamera.dispose();
760
+ this.scene.activeCamera = null;
761
+ }
762
+ // Camera
763
+ if (!this.scene.activeCamera) {
764
+ var worldExtends = this.scene.getWorldExtends();
765
+ var worldSize = worldExtends.max.subtract(worldExtends.min);
766
+ var worldCenter = worldExtends.min.add(worldSize.scale(0.5));
767
+ var radius = worldSize.length() * 1.5;
768
+ // empty scene scenario!
769
+ if (!isFinite(radius)) {
770
+ radius = 1;
771
+ worldCenter.copyFromFloats(0, 0, 0);
772
+ }
773
+ var arcRotateCamera = new ArcRotateCamera("default camera", -(Math.PI / 2), Math.PI / 2, radius, worldCenter, this.scene);
774
+ arcRotateCamera.lowerRadiusLimit = radius * 0.01;
775
+ arcRotateCamera.wheelPrecision = 100 / radius;
776
+ var camera = arcRotateCamera;
777
+ camera.minZ = radius * 0.01;
778
+ camera.maxZ = radius * 1000;
779
+ camera.speed = radius * 0.2;
780
+ this.scene.activeCamera = camera;
781
+ }
782
+ var canvas = this.scene.getEngine().getInputElement();
783
+ if (canvas) {
784
+ this.scene.activeCamera.attachControl();
785
+ }
786
+ this.camera = this.scene.activeCamera;
787
+ this.camera.setTarget(Vector3.Zero());
788
+ }
789
+ if (!this.camera) {
790
+ this.camera = this.scene.activeCamera;
791
+ }
792
+ if (cameraConfig.position) {
793
+ var newPosition = this.camera.position.clone();
794
+ extendClassWithConfig(newPosition, cameraConfig.position);
795
+ this.camera.setPosition(newPosition);
796
+ }
797
+ if (cameraConfig.target) {
798
+ var newTarget = this.camera.target.clone();
799
+ extendClassWithConfig(newTarget, cameraConfig.target);
800
+ this.camera.setTarget(newTarget);
801
+ } /*else if (this.models.length && !cameraConfig.disableAutoFocus) {
802
+ this._focusOnModel(this.models[0]);
803
+ }*/
804
+ if (cameraConfig.rotation) {
805
+ this.camera.rotationQuaternion = new Quaternion(cameraConfig.rotation.x || 0, cameraConfig.rotation.y || 0, cameraConfig.rotation.z || 0, cameraConfig.rotation.w || 0);
806
+ }
807
+ if (cameraConfig.behaviors) {
808
+ for (var name_1 in cameraConfig.behaviors) {
809
+ if (cameraConfig.behaviors[name_1] !== undefined) {
810
+ this._setCameraBehavior(name_1, cameraConfig.behaviors[name_1]);
811
+ }
812
+ }
813
+ }
814
+ var sceneExtends = this.scene.getWorldExtends(function (mesh) {
815
+ return !_this.environmentHelper || (mesh !== _this.environmentHelper.ground && mesh !== _this.environmentHelper.rootMesh && mesh !== _this.environmentHelper.skybox);
816
+ });
817
+ var sceneDiagonal = sceneExtends.max.subtract(sceneExtends.min);
818
+ var sceneDiagonalLength = sceneDiagonal.length();
819
+ if (isFinite(sceneDiagonalLength)) {
820
+ this.camera.upperRadiusLimit = sceneDiagonalLength * 4;
821
+ }
822
+ // sanity check!
823
+ if (this.scene.imageProcessingConfiguration) {
824
+ this.scene.imageProcessingConfiguration.colorCurvesEnabled = true;
825
+ this.scene.imageProcessingConfiguration.vignetteEnabled = true;
826
+ this.scene.imageProcessingConfiguration.toneMappingEnabled = !!getConfigurationKey("camera.toneMappingEnabled", this._globalConfiguration);
827
+ }
828
+ extendClassWithConfig(this.camera, cameraConfig);
829
+ this.onCameraConfiguredObservable.notifyObservers({
830
+ sceneManager: this,
831
+ object: this.camera,
832
+ newConfiguration: cameraConfig,
833
+ });
834
+ };
835
+ SceneManager.prototype._configureEnvironment = function (skyboxConifguration, groundConfiguration) {
836
+ var _this = this;
837
+ if (!skyboxConifguration && !groundConfiguration) {
838
+ if (this.environmentHelper) {
839
+ this.environmentHelper.dispose();
840
+ this.environmentHelper = undefined;
841
+ }
842
+ }
843
+ else {
844
+ var options = {
845
+ createGround: !!groundConfiguration && this._groundEnabled,
846
+ createSkybox: !!skyboxConifguration,
847
+ setupImageProcessing: false, // will be done at the scene level!,
848
+ };
849
+ // will that cause problems with model ground configuration?
850
+ /*if (model) {
851
+ const boundingInfo = model.rootMesh.getHierarchyBoundingVectors(true);
852
+ const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
853
+ const halfSizeVec = sizeVec.scale(0.5);
854
+ const center = boundingInfo.min.add(halfSizeVec);
855
+ options.groundYBias = -center.y;
856
+ }*/
857
+ if (groundConfiguration) {
858
+ var groundConfig_1 = typeof groundConfiguration === "boolean" ? {} : groundConfiguration;
859
+ var groundSize = groundConfig_1.size || (typeof skyboxConifguration === "object" && skyboxConifguration.scale);
860
+ if (groundSize) {
861
+ options.groundSize = groundSize;
862
+ }
863
+ options.enableGroundShadow = groundConfiguration === true || groundConfig_1.receiveShadows;
864
+ if (groundConfig_1.shadowLevel !== undefined) {
865
+ options.groundShadowLevel = groundConfig_1.shadowLevel;
866
+ }
867
+ options.enableGroundMirror = !!groundConfig_1.mirror && this.groundMirrorEnabled;
868
+ if (groundConfig_1.texture) {
869
+ options.groundTexture = this._getAssetUrl(groundConfig_1.texture);
870
+ }
871
+ if (groundConfig_1.color) {
872
+ options.groundColor = new Color3(groundConfig_1.color.r, groundConfig_1.color.g, groundConfig_1.color.b);
873
+ }
874
+ if (groundConfig_1.opacity !== undefined) {
875
+ options.groundOpacity = groundConfig_1.opacity;
876
+ }
877
+ if (groundConfig_1.mirror) {
878
+ options.enableGroundMirror = true;
879
+ // to prevent undefines
880
+ if (typeof groundConfig_1.mirror === "object") {
881
+ if (groundConfig_1.mirror.amount !== undefined) {
882
+ options.groundMirrorAmount = groundConfig_1.mirror.amount;
883
+ }
884
+ if (groundConfig_1.mirror.sizeRatio !== undefined) {
885
+ options.groundMirrorSizeRatio = groundConfig_1.mirror.sizeRatio;
886
+ }
887
+ if (groundConfig_1.mirror.blurKernel !== undefined) {
888
+ options.groundMirrorBlurKernel = groundConfig_1.mirror.blurKernel;
889
+ }
890
+ if (groundConfig_1.mirror.fresnelWeight !== undefined) {
891
+ options.groundMirrorFresnelWeight = groundConfig_1.mirror.fresnelWeight;
892
+ }
893
+ if (groundConfig_1.mirror.fallOffDistance !== undefined) {
894
+ options.groundMirrorFallOffDistance = groundConfig_1.mirror.fallOffDistance;
895
+ }
896
+ if (this._defaultPipelineTextureType !== undefined) {
897
+ options.groundMirrorTextureType = this._defaultPipelineTextureType;
898
+ }
899
+ }
900
+ }
901
+ }
902
+ var postInitSkyboxMaterial = false;
903
+ if (skyboxConifguration) {
904
+ var conf = skyboxConifguration === true ? {} : skyboxConifguration;
905
+ if (conf.material && conf.material.imageProcessingConfiguration) {
906
+ options.setupImageProcessing = false; // will be configured later manually.
907
+ }
908
+ var skyboxSize = conf.scale;
909
+ if (skyboxSize) {
910
+ options.skyboxSize = skyboxSize;
911
+ }
912
+ options.sizeAuto = !options.skyboxSize;
913
+ if (conf.color) {
914
+ options.skyboxColor = new Color3(conf.color.r, conf.color.g, conf.color.b);
915
+ }
916
+ if (conf.cubeTexture && conf.cubeTexture.url) {
917
+ if (typeof conf.cubeTexture.url === "string") {
918
+ options.skyboxTexture = this._getAssetUrl(conf.cubeTexture.url);
919
+ }
920
+ else {
921
+ // init later!
922
+ postInitSkyboxMaterial = true;
923
+ }
924
+ }
925
+ if (conf.material) {
926
+ postInitSkyboxMaterial = true;
927
+ }
928
+ }
929
+ options.setupImageProcessing = false; // TMP
930
+ if (!this.environmentHelper) {
931
+ this.environmentHelper = new EnvironmentHelper(options, this.scene);
932
+ }
933
+ else {
934
+ // unlikely, but there might be a new scene! we need to dispose.
935
+ // get the scene used by the envHelper
936
+ var scene = this.environmentHelper.rootMesh.getScene();
937
+ // is it a different scene? Oh no!
938
+ if (scene !== this.scene) {
939
+ this.environmentHelper.dispose();
940
+ this.environmentHelper = new EnvironmentHelper(options, this.scene);
941
+ }
942
+ else {
943
+ // recreate the ground
944
+ if (this.environmentHelper.ground) {
945
+ this.environmentHelper.ground.dispose();
946
+ }
947
+ // recreate the skybox
948
+ if (this.environmentHelper.skybox) {
949
+ this.environmentHelper.skybox.dispose();
950
+ }
951
+ this.environmentHelper.updateOptions(options);
952
+ // update doesn't change the size of the skybox and ground, so we have to recreate!
953
+ //this.environmentHelper.dispose();
954
+ //this.environmentHelper = new EnvironmentHelper(options, this.scene);
955
+ }
956
+ }
957
+ if (this.environmentHelper.rootMesh && this._globalConfiguration.scene && this._globalConfiguration.scene.environmentRotationY !== undefined) {
958
+ this.environmentHelper.rootMesh.rotation.y = this._globalConfiguration.scene.environmentRotationY;
959
+ }
960
+ var groundConfig = typeof groundConfiguration === "boolean" ? {} : groundConfiguration;
961
+ if (this.environmentHelper.groundMaterial && groundConfig) {
962
+ this.environmentHelper.groundMaterial._perceptualColor = this.mainColor;
963
+ if (groundConfig.material) {
964
+ extendClassWithConfig(this.environmentHelper.groundMaterial, groundConfig.material);
965
+ }
966
+ if (this.environmentHelper.groundMirror) {
967
+ var mirrorClearColor = this.environmentHelper.groundMaterial._perceptualColor.toLinearSpace();
968
+ // TODO user camera exposure value to set the mirror clear color
969
+ var exposure = Math.pow(2.0, -this.scene.imageProcessingConfiguration.exposure) * Math.PI;
970
+ mirrorClearColor.scaleToRef(1 / exposure, mirrorClearColor);
971
+ this.environmentHelper.groundMirror.clearColor.r = Scalar.Clamp(mirrorClearColor.r);
972
+ this.environmentHelper.groundMirror.clearColor.g = Scalar.Clamp(mirrorClearColor.g);
973
+ this.environmentHelper.groundMirror.clearColor.b = Scalar.Clamp(mirrorClearColor.b);
974
+ this.environmentHelper.groundMirror.clearColor.a = 1;
975
+ if (!this.groundMirrorEnabled) {
976
+ this.environmentHelper.groundMaterial.reflectionTexture = null;
977
+ }
978
+ }
979
+ }
980
+ var skyboxMaterial = this.environmentHelper.skyboxMaterial;
981
+ if (skyboxMaterial) {
982
+ skyboxMaterial._perceptualColor = this.mainColor;
983
+ if (postInitSkyboxMaterial) {
984
+ if (typeof skyboxConifguration === "object" && skyboxConifguration.material) {
985
+ extendClassWithConfig(skyboxMaterial, skyboxConifguration.material);
986
+ }
987
+ }
988
+ }
989
+ }
990
+ this._observablesManager &&
991
+ this._observablesManager.onModelLoadedObservable.add(function (model) {
992
+ _this._updateGroundMirrorRenderList(model);
993
+ });
994
+ this.onEnvironmentConfiguredObservable.notifyObservers({
995
+ sceneManager: this,
996
+ object: this.environmentHelper,
997
+ newConfiguration: {
998
+ skybox: skyboxConifguration,
999
+ ground: groundConfiguration,
1000
+ },
1001
+ });
1002
+ };
1003
+ /**
1004
+ * configure the lights.
1005
+ * @param lightsConfiguration the (new) light(s) configuration
1006
+ */
1007
+ SceneManager.prototype._configureLights = function (lightsConfiguration) {
1008
+ var _this = this;
1009
+ if (lightsConfiguration === void 0) { lightsConfiguration = {}; }
1010
+ // sanity check!
1011
+ var lightKeys = Object.keys(lightsConfiguration).filter(function (name) { return name !== "globalRotation"; });
1012
+ if (!lightKeys.length) {
1013
+ if (!this.scene.lights.length) {
1014
+ new HemisphericLight("default light", Vector3.Up(), this.scene);
1015
+ }
1016
+ }
1017
+ else {
1018
+ var lightsAvailable_1 = this.scene.lights.map(function (light) { return light.name; });
1019
+ // compare to the global (!) configuration object and dispose unneeded:
1020
+ var lightsToConfigure_1 = Object.keys(this._globalConfiguration.lights || []);
1021
+ if (Object.keys(lightsToConfigure_1).length !== lightsAvailable_1.length) {
1022
+ lightsAvailable_1.forEach(function (lName) {
1023
+ if (lightsToConfigure_1.indexOf(lName) === -1) {
1024
+ _this.scene.getLightByName(lName).dispose();
1025
+ }
1026
+ });
1027
+ }
1028
+ lightKeys.forEach(function (name) {
1029
+ var lightConfig = { type: 0 };
1030
+ if (typeof lightsConfiguration[name] === "object") {
1031
+ lightConfig = lightsConfiguration[name];
1032
+ }
1033
+ if (typeof lightsConfiguration[name] === "number") {
1034
+ lightConfig.type = lightsConfiguration[name];
1035
+ }
1036
+ lightConfig.name = name;
1037
+ var light;
1038
+ // light is not already available
1039
+ if (lightsAvailable_1.indexOf(name) === -1) {
1040
+ var constructor = Light.GetConstructorFromName(lightConfig.type, lightConfig.name, _this.scene);
1041
+ if (!constructor) {
1042
+ return;
1043
+ }
1044
+ light = constructor();
1045
+ }
1046
+ else {
1047
+ // available? get it from the scene
1048
+ light = _this.scene.getLightByName(name);
1049
+ if (typeof lightsConfiguration[name] === "boolean") {
1050
+ lightConfig.type = light.getTypeID();
1051
+ }
1052
+ lightsAvailable_1 = lightsAvailable_1.filter(function (ln) { return ln !== name; });
1053
+ if (lightConfig.type !== undefined && light.getTypeID() !== lightConfig.type) {
1054
+ light.dispose();
1055
+ var constructor = Light.GetConstructorFromName(lightConfig.type, lightConfig.name, _this.scene);
1056
+ if (!constructor) {
1057
+ return;
1058
+ }
1059
+ light = constructor();
1060
+ }
1061
+ }
1062
+ // if config set the light to false, dispose it.
1063
+ if (lightsConfiguration[name] === false) {
1064
+ light.dispose();
1065
+ return;
1066
+ }
1067
+ //enabled
1068
+ var enabled = lightConfig.enabled !== undefined ? lightConfig.enabled : !lightConfig.disabled;
1069
+ light.setEnabled(enabled);
1070
+ extendClassWithConfig(light, lightConfig);
1071
+ //position. Some lights don't support shadows
1072
+ if (light instanceof ShadowLight) {
1073
+ // set default values
1074
+ light.shadowMinZ = light.shadowMinZ || 0.2;
1075
+ light.shadowMaxZ = Math.min(10, light.shadowMaxZ || 10); //large far clips reduce shadow depth precision
1076
+ if (lightConfig.target) {
1077
+ if (light.setDirectionToTarget) {
1078
+ var target = Vector3.Zero().copyFromFloats(lightConfig.target.x, lightConfig.target.y, lightConfig.target.z);
1079
+ light.setDirectionToTarget(target);
1080
+ }
1081
+ }
1082
+ else if (lightConfig.direction) {
1083
+ var direction = Vector3.Zero().copyFromFloats(lightConfig.direction.x, lightConfig.direction.y, lightConfig.direction.z);
1084
+ light.direction = direction;
1085
+ }
1086
+ var isShadowEnabled = false;
1087
+ if (light.getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {
1088
+ light.shadowFrustumSize = lightConfig.shadowFrustumSize || 2;
1089
+ isShadowEnabled = true;
1090
+ }
1091
+ else if (light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT) {
1092
+ var spotLight = light;
1093
+ if (lightConfig.spotAngle !== undefined) {
1094
+ spotLight.angle = (lightConfig.spotAngle * Math.PI) / 180;
1095
+ }
1096
+ if (spotLight.angle && lightConfig.shadowFieldOfView) {
1097
+ spotLight.shadowAngleScale = lightConfig.shadowFieldOfView / spotLight.angle;
1098
+ }
1099
+ isShadowEnabled = true;
1100
+ }
1101
+ else if (light.getTypeID() === Light.LIGHTTYPEID_POINTLIGHT) {
1102
+ if (lightConfig.shadowFieldOfView) {
1103
+ light.shadowAngle = (lightConfig.shadowFieldOfView * Math.PI) / 180;
1104
+ }
1105
+ isShadowEnabled = true;
1106
+ }
1107
+ var shadowGenerator_1 = light.getShadowGenerator();
1108
+ if (isShadowEnabled && lightConfig.shadowEnabled && _this._maxShadows) {
1109
+ var bufferSize = lightConfig.shadowBufferSize || 256;
1110
+ if (!shadowGenerator_1) {
1111
+ shadowGenerator_1 = new ShadowGenerator(bufferSize, light);
1112
+ }
1113
+ var blurKernel = _this.getBlurKernel(light, bufferSize);
1114
+ shadowGenerator_1.bias = _this._shadowGeneratorBias;
1115
+ shadowGenerator_1.blurKernel = blurKernel;
1116
+ //override defaults
1117
+ extendClassWithConfig(shadowGenerator_1, lightConfig.shadowConfig || {});
1118
+ // add the focus meshes to the shadow list
1119
+ _this._observablesManager &&
1120
+ _this._observablesManager.onModelLoadedObservable.add(function (model) {
1121
+ _this._updateShadowRenderList(shadowGenerator_1, model);
1122
+ });
1123
+ //if (model) {
1124
+ _this._updateShadowRenderList(shadowGenerator_1);
1125
+ //}
1126
+ }
1127
+ else if (shadowGenerator_1) {
1128
+ shadowGenerator_1.dispose();
1129
+ }
1130
+ }
1131
+ });
1132
+ // render priority
1133
+ var globalLightsConfiguration = this._globalConfiguration.lights || {};
1134
+ Object.keys(globalLightsConfiguration)
1135
+ .sort()
1136
+ .forEach(function (name, idx) {
1137
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1138
+ // const configuration = globalLightsConfiguration[name];
1139
+ var light = _this.scene.getLightByName(name);
1140
+ // sanity check
1141
+ if (!light) {
1142
+ return;
1143
+ }
1144
+ light.renderPriority = -idx;
1145
+ });
1146
+ }
1147
+ this.onLightsConfiguredObservable.notifyObservers({
1148
+ sceneManager: this,
1149
+ object: this.scene.lights,
1150
+ newConfiguration: lightsConfiguration,
1151
+ });
1152
+ };
1153
+ SceneManager.prototype._updateShadowRenderList = function (shadowGenerator, model, resetList) {
1154
+ var focusMeshes = model ? model.meshes : this.scene.meshes;
1155
+ // add the focus meshes to the shadow list
1156
+ var shadownMap = shadowGenerator.getShadowMap();
1157
+ if (!shadownMap) {
1158
+ return;
1159
+ }
1160
+ if (resetList && shadownMap.renderList) {
1161
+ shadownMap.renderList.length = 0;
1162
+ }
1163
+ else {
1164
+ shadownMap.renderList = shadownMap.renderList || [];
1165
+ }
1166
+ for (var index = 0; index < focusMeshes.length; index++) {
1167
+ var mesh = focusMeshes[index];
1168
+ if (Tags.MatchesQuery(mesh, "castShadow") && shadownMap.renderList.indexOf(mesh) === -1) {
1169
+ shadownMap.renderList.push(mesh);
1170
+ }
1171
+ }
1172
+ if (!this._shadowGroundPlane) {
1173
+ if (shadowGenerator.useBlurCloseExponentialShadowMap) {
1174
+ var shadowGroundPlane = CreatePlane("shadowGroundPlane", { size: 100 }, this.scene);
1175
+ shadowGroundPlane.useVertexColors = false;
1176
+ //material isn't ever used in rendering, just used to set back face culling
1177
+ shadowGroundPlane.material = new PBRMaterial("shadowGroundPlaneMaterial", this.scene);
1178
+ shadowGroundPlane.material.backFaceCulling = false;
1179
+ shadowGroundPlane.rotation.x = Math.PI * 0.5;
1180
+ shadowGroundPlane.freezeWorldMatrix();
1181
+ this._shadowGroundPlane = shadowGroundPlane;
1182
+ this.scene.removeMesh(shadowGroundPlane);
1183
+ }
1184
+ }
1185
+ else {
1186
+ if (!shadowGenerator.useBlurCloseExponentialShadowMap) {
1187
+ this._shadowGroundPlane.dispose();
1188
+ this._shadowGroundPlane = null;
1189
+ }
1190
+ }
1191
+ if (this._shadowGroundPlane && shadownMap.renderList.indexOf(this._shadowGroundPlane) === -1) {
1192
+ shadownMap.renderList.push(this._shadowGroundPlane);
1193
+ }
1194
+ };
1195
+ SceneManager.prototype._updateGroundMirrorRenderList = function (model, resetList) {
1196
+ if (this.environmentHelper && this.environmentHelper.groundMirror && this.environmentHelper.groundMirror.renderList) {
1197
+ var focusMeshes = model ? model.meshes : this.scene.meshes;
1198
+ var renderList = this.environmentHelper.groundMirror.renderList;
1199
+ if (resetList) {
1200
+ renderList.length = 0;
1201
+ }
1202
+ for (var index = 0; index < focusMeshes.length; index++) {
1203
+ var mesh = focusMeshes[index];
1204
+ if (renderList.indexOf(mesh) === -1) {
1205
+ renderList.push(mesh);
1206
+ }
1207
+ }
1208
+ }
1209
+ };
1210
+ /**
1211
+ * Gets the shadow map blur kernel according to the light configuration.
1212
+ * @param light The light used to generate the shadows
1213
+ * @param bufferSize The size of the shadow map
1214
+ * @returns the kernel blur size
1215
+ */
1216
+ SceneManager.prototype.getBlurKernel = function (light, bufferSize) {
1217
+ var normalizedBlurKernel = 0.05; // TODO Should come from the config.
1218
+ if (light.getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT) {
1219
+ normalizedBlurKernel = normalizedBlurKernel / light.shadowFrustumSize;
1220
+ }
1221
+ else if (light.getTypeID() === Light.LIGHTTYPEID_POINTLIGHT) {
1222
+ normalizedBlurKernel = normalizedBlurKernel / light.shadowAngle;
1223
+ }
1224
+ else if (light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT) {
1225
+ normalizedBlurKernel = normalizedBlurKernel / (light.angle * light.shadowAngleScale);
1226
+ }
1227
+ var minimumBlurKernel = 5 / (bufferSize / 256); //magic number that aims to keep away sawtooth shadows
1228
+ var blurKernel = Math.max(bufferSize * normalizedBlurKernel, minimumBlurKernel);
1229
+ return blurKernel;
1230
+ };
1231
+ /**
1232
+ * Alters render settings to reduce features based on hardware feature limitations
1233
+ * @param enableHDR Allows the viewer to run in HDR mode.
1234
+ */
1235
+ SceneManager.prototype._handleHardwareLimitations = function (enableHDR) {
1236
+ if (enableHDR === void 0) { enableHDR = true; }
1237
+ //flip rendering settings switches based on hardware support
1238
+ var maxVaryingRows = this._engine.getCaps().maxVaryingVectors;
1239
+ var maxFragmentSamplers = this._engine.getCaps().maxTexturesImageUnits;
1240
+ //shadows are disabled if there's not enough varyings for a single shadow
1241
+ if (maxVaryingRows < 8 || maxFragmentSamplers < 8) {
1242
+ this._maxShadows = 0;
1243
+ }
1244
+ else {
1245
+ this._maxShadows = 3;
1246
+ }
1247
+ //can we render to any >= 16-bit targets (required for HDR)
1248
+ var caps = this._engine.getCaps();
1249
+ var linearHalfFloatTargets = caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering;
1250
+ var linearFloatTargets = caps.textureFloatRender && caps.textureFloatLinearFiltering;
1251
+ this._hdrSupport = enableHDR && !!(linearFloatTargets || linearHalfFloatTargets);
1252
+ if (linearHalfFloatTargets) {
1253
+ this._defaultHighpTextureType = Constants.TEXTURETYPE_HALF_FLOAT;
1254
+ this._shadowGeneratorBias = 0.002;
1255
+ }
1256
+ else if (linearFloatTargets) {
1257
+ this._defaultHighpTextureType = Constants.TEXTURETYPE_FLOAT;
1258
+ this._shadowGeneratorBias = 0.001;
1259
+ }
1260
+ else {
1261
+ this._defaultHighpTextureType = Constants.TEXTURETYPE_UNSIGNED_INT;
1262
+ this._shadowGeneratorBias = 0.001;
1263
+ }
1264
+ this._defaultPipelineTextureType = this._hdrSupport ? this._defaultHighpTextureType : Constants.TEXTURETYPE_UNSIGNED_INT;
1265
+ };
1266
+ /**
1267
+ * Dispose the entire viewer including the scene and the engine
1268
+ */
1269
+ SceneManager.prototype.dispose = function () {
1270
+ // this.onCameraConfiguredObservable.clear();
1271
+ this.onEnvironmentConfiguredObservable.clear();
1272
+ this.onLightsConfiguredObservable.clear();
1273
+ this.onModelsConfiguredObservable.clear();
1274
+ this.onSceneConfiguredObservable.clear();
1275
+ this.onSceneInitObservable.clear();
1276
+ this.onSceneOptimizerConfiguredObservable.clear();
1277
+ this.onVRConfiguredObservable.clear();
1278
+ if (this.sceneOptimizer) {
1279
+ this.sceneOptimizer.stop();
1280
+ this.sceneOptimizer.dispose();
1281
+ }
1282
+ if (this.environmentHelper) {
1283
+ this.environmentHelper.dispose();
1284
+ }
1285
+ this.models.forEach(function (model) {
1286
+ model.dispose();
1287
+ });
1288
+ if (this._defaultRenderingPipeline) {
1289
+ this._defaultRenderingPipeline.dispose();
1290
+ }
1291
+ this.models.length = 0;
1292
+ if (this.scene) {
1293
+ this.scene.dispose();
1294
+ }
1295
+ };
1296
+ /**
1297
+ * Get an environment asset url by using the configuration if the path is not absolute.
1298
+ * @param url Asset url
1299
+ * @returns The Asset url using the `environmentAssetsRootURL` if the url is not an absolute path.
1300
+ */
1301
+ SceneManager.prototype._getAssetUrl = function (url) {
1302
+ var returnUrl = url;
1303
+ if (url && url.toLowerCase().indexOf("//") === -1) {
1304
+ if (!this._assetsRootURL) {
1305
+ // Tools.Warn("Please, specify the root url of your assets before loading the configuration (labs.environmentAssetsRootURL) or disable the background through the viewer options.");
1306
+ return url;
1307
+ }
1308
+ returnUrl = this._assetsRootURL + returnUrl;
1309
+ }
1310
+ return returnUrl;
1311
+ };
1312
+ SceneManager.prototype._setCameraBehavior = function (name, behaviorConfig) {
1313
+ var behavior;
1314
+ var type;
1315
+ if (typeof behaviorConfig === "object") {
1316
+ type = behaviorConfig.type;
1317
+ }
1318
+ else if (typeof behaviorConfig === "number") {
1319
+ type = behaviorConfig;
1320
+ }
1321
+ else {
1322
+ type = this._cameraBehaviorMapping[name];
1323
+ }
1324
+ if (type === undefined) {
1325
+ return;
1326
+ }
1327
+ var config = typeof behaviorConfig === "object" ? behaviorConfig : {};
1328
+ var enabled = true;
1329
+ if (typeof behaviorConfig === "boolean") {
1330
+ enabled = behaviorConfig;
1331
+ }
1332
+ // constructing behavior
1333
+ switch (type) {
1334
+ case 0 /* CameraBehavior.AUTOROTATION */:
1335
+ this.camera.useAutoRotationBehavior = enabled;
1336
+ behavior = this.camera.autoRotationBehavior;
1337
+ break;
1338
+ case 1 /* CameraBehavior.BOUNCING */:
1339
+ this.camera.useBouncingBehavior = enabled;
1340
+ behavior = this.camera.bouncingBehavior;
1341
+ break;
1342
+ case 2 /* CameraBehavior.FRAMING */:
1343
+ this.camera.useFramingBehavior = enabled;
1344
+ behavior = this.camera.framingBehavior;
1345
+ break;
1346
+ default:
1347
+ behavior = null;
1348
+ break;
1349
+ }
1350
+ if (behavior) {
1351
+ this._cameraBehaviorMapping[name] = type;
1352
+ if (typeof behaviorConfig === "object") {
1353
+ extendClassWithConfig(behavior, behaviorConfig);
1354
+ }
1355
+ }
1356
+ // post attach configuration. Some functionalities require the attached camera.
1357
+ switch (type) {
1358
+ case 0 /* CameraBehavior.AUTOROTATION */:
1359
+ break;
1360
+ case 1 /* CameraBehavior.BOUNCING */:
1361
+ break;
1362
+ case 2 /* CameraBehavior.FRAMING */:
1363
+ this._observablesManager &&
1364
+ this._observablesManager.onModelLoadedObservable.add(function (model) {
1365
+ if (config.zoomOnBoundingInfo) {
1366
+ behavior.zoomOnMeshHierarchy(model.rootMesh);
1367
+ }
1368
+ });
1369
+ break;
1370
+ }
1371
+ };
1372
+ return SceneManager;
1373
+ }());
1374
+ export { SceneManager };
1375
+ //# sourceMappingURL=sceneManager.js.map