@babylonjs/viewer 5.0.0-rc.3 → 5.0.1

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 (192) hide show
  1. package/configuration/configuration.d.ts +107 -107
  2. package/configuration/configuration.js +15 -15
  3. package/configuration/configuration.js.map +1 -1
  4. package/configuration/configurationCompatibility.d.ts +8 -8
  5. package/configuration/configurationCompatibility.js +65 -65
  6. package/configuration/configurationCompatibility.js.map +1 -1
  7. package/configuration/configurationContainer.d.ts +10 -10
  8. package/configuration/configurationContainer.js +9 -9
  9. package/configuration/configurationContainer.js.map +1 -1
  10. package/configuration/globals.d.ts +6 -6
  11. package/configuration/globals.js +17 -17
  12. package/configuration/globals.js.map +1 -1
  13. package/configuration/index.d.ts +2 -2
  14. package/configuration/index.js +3 -2
  15. package/configuration/index.js.map +1 -1
  16. package/configuration/interfaces/cameraConfiguration.d.ts +31 -31
  17. package/configuration/interfaces/cameraConfiguration.js +1 -1
  18. package/configuration/interfaces/cameraConfiguration.js.map +1 -1
  19. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -81
  20. package/configuration/interfaces/colorGradingConfiguration.js +1 -1
  21. package/configuration/interfaces/colorGradingConfiguration.js.map +1 -1
  22. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -20
  23. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +1 -1
  24. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -1
  25. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -22
  26. package/configuration/interfaces/environmentMapConfiguration.js +1 -1
  27. package/configuration/interfaces/environmentMapConfiguration.js.map +1 -1
  28. package/configuration/interfaces/groundConfiguration.d.ts +24 -24
  29. package/configuration/interfaces/groundConfiguration.js +1 -1
  30. package/configuration/interfaces/groundConfiguration.js.map +1 -1
  31. package/configuration/interfaces/imageProcessingConfiguration.d.ts +43 -43
  32. package/configuration/interfaces/imageProcessingConfiguration.js +1 -1
  33. package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -1
  34. package/configuration/interfaces/index.d.ts +15 -15
  35. package/configuration/interfaces/index.js +15 -15
  36. package/configuration/interfaces/index.js.map +1 -1
  37. package/configuration/interfaces/lightConfiguration.d.ts +60 -60
  38. package/configuration/interfaces/lightConfiguration.js +1 -1
  39. package/configuration/interfaces/lightConfiguration.js.map +1 -1
  40. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -26
  41. package/configuration/interfaces/modelAnimationConfiguration.js +1 -1
  42. package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -1
  43. package/configuration/interfaces/modelConfiguration.d.ts +65 -65
  44. package/configuration/interfaces/modelConfiguration.js +1 -1
  45. package/configuration/interfaces/modelConfiguration.js.map +1 -1
  46. package/configuration/interfaces/observersConfiguration.d.ts +5 -5
  47. package/configuration/interfaces/observersConfiguration.js +1 -1
  48. package/configuration/interfaces/observersConfiguration.js.map +1 -1
  49. package/configuration/interfaces/sceneConfiguration.d.ts +48 -48
  50. package/configuration/interfaces/sceneConfiguration.js +1 -1
  51. package/configuration/interfaces/sceneConfiguration.js.map +1 -1
  52. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -23
  53. package/configuration/interfaces/sceneOptimizerConfiguration.js +1 -1
  54. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -1
  55. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -21
  56. package/configuration/interfaces/skyboxConfiguration.js +1 -1
  57. package/configuration/interfaces/skyboxConfiguration.js.map +1 -1
  58. package/configuration/interfaces/templateConfiguration.d.ts +67 -67
  59. package/configuration/interfaces/templateConfiguration.js +1 -1
  60. package/configuration/interfaces/templateConfiguration.js.map +1 -1
  61. package/configuration/interfaces/vrConfiguration.d.ts +16 -16
  62. package/configuration/interfaces/vrConfiguration.js +1 -1
  63. package/configuration/interfaces/vrConfiguration.js.map +1 -1
  64. package/configuration/loader.d.ts +4 -4
  65. package/configuration/loader.js +16 -28
  66. package/configuration/loader.js.map +1 -1
  67. package/configuration/mappers.d.ts +42 -42
  68. package/configuration/mappers.js +190 -189
  69. package/configuration/mappers.js.map +1 -1
  70. package/configuration/renderOnlyLoader.d.ts +33 -33
  71. package/configuration/renderOnlyLoader.js +161 -158
  72. package/configuration/renderOnlyLoader.js.map +1 -1
  73. package/configuration/types/default.d.ts +6 -6
  74. package/configuration/types/default.js +120 -119
  75. package/configuration/types/default.js.map +1 -1
  76. package/configuration/types/environmentMap.d.ts +5 -5
  77. package/configuration/types/environmentMap.js +13 -13
  78. package/configuration/types/environmentMap.js.map +1 -1
  79. package/configuration/types/extended.d.ts +6 -6
  80. package/configuration/types/extended.js +316 -316
  81. package/configuration/types/extended.js.map +1 -1
  82. package/configuration/types/index.d.ts +13 -13
  83. package/configuration/types/index.js +49 -48
  84. package/configuration/types/index.js.map +1 -1
  85. package/configuration/types/minimal.d.ts +6 -6
  86. package/configuration/types/minimal.js +42 -42
  87. package/configuration/types/minimal.js.map +1 -1
  88. package/configuration/types/renderOnlyDefault.d.ts +30 -30
  89. package/configuration/types/renderOnlyDefault.js +30 -30
  90. package/configuration/types/renderOnlyDefault.js.map +1 -1
  91. package/configuration/types/shadowLight.d.ts +9 -9
  92. package/configuration/types/shadowLight.js +63 -63
  93. package/configuration/types/shadowLight.js.map +1 -1
  94. package/helper/index.d.ts +26 -26
  95. package/helper/index.js +62 -56
  96. package/helper/index.js.map +1 -1
  97. package/index.d.ts +30 -30
  98. package/index.js +45 -41
  99. package/index.js.map +1 -1
  100. package/initializer.d.ts +11 -11
  101. package/initializer.js +34 -33
  102. package/initializer.js.map +1 -1
  103. package/interfaces.d.ts +5 -5
  104. package/interfaces.js +1 -1
  105. package/interfaces.js.map +1 -1
  106. package/labs/environmentSerializer.d.ts +126 -126
  107. package/labs/environmentSerializer.js +190 -186
  108. package/labs/environmentSerializer.js.map +1 -1
  109. package/labs/texture.d.ts +183 -184
  110. package/labs/texture.js +300 -297
  111. package/labs/texture.js.map +1 -1
  112. package/labs/viewerLabs.d.ts +51 -51
  113. package/labs/viewerLabs.js +133 -131
  114. package/labs/viewerLabs.js.map +1 -1
  115. package/license.md +71 -0
  116. package/loader/modelLoader.d.ts +47 -44
  117. package/loader/modelLoader.js +189 -182
  118. package/loader/modelLoader.js.map +1 -1
  119. package/loader/plugins/applyMaterialConfig.d.ts +12 -12
  120. package/loader/plugins/applyMaterialConfig.js +15 -15
  121. package/loader/plugins/applyMaterialConfig.js.map +1 -1
  122. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -9
  123. package/loader/plugins/extendedMaterialLoaderPlugin.js +15 -15
  124. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -1
  125. package/loader/plugins/index.d.ts +18 -17
  126. package/loader/plugins/index.js +42 -41
  127. package/loader/plugins/index.js.map +1 -1
  128. package/loader/plugins/loaderPlugin.d.ts +24 -24
  129. package/loader/plugins/loaderPlugin.js +1 -1
  130. package/loader/plugins/loaderPlugin.js.map +1 -1
  131. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -12
  132. package/loader/plugins/msftLodLoaderPlugin.js +20 -19
  133. package/loader/plugins/msftLodLoaderPlugin.js.map +1 -1
  134. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -12
  135. package/loader/plugins/telemetryLoaderPlugin.js +35 -35
  136. package/loader/plugins/telemetryLoaderPlugin.js.map +1 -1
  137. package/managers/observablesManager.d.ts +66 -66
  138. package/managers/observablesManager.js +34 -34
  139. package/managers/observablesManager.js.map +1 -1
  140. package/managers/sceneManager.d.ts +243 -245
  141. package/managers/sceneManager.js +1388 -1387
  142. package/managers/sceneManager.js.map +1 -1
  143. package/managers/telemetryManager.d.ts +57 -57
  144. package/managers/telemetryManager.js +113 -113
  145. package/managers/telemetryManager.js.map +1 -1
  146. package/model/modelAnimation.d.ts +215 -215
  147. package/model/modelAnimation.js +232 -232
  148. package/model/modelAnimation.js.map +1 -1
  149. package/model/viewerModel.d.ts +228 -236
  150. package/model/viewerModel.js +669 -664
  151. package/model/viewerModel.js.map +1 -1
  152. package/optimizer/custom/extended.d.ts +11 -13
  153. package/optimizer/custom/extended.js +98 -100
  154. package/optimizer/custom/extended.js.map +1 -1
  155. package/optimizer/custom/index.d.ts +8 -8
  156. package/optimizer/custom/index.js +24 -24
  157. package/optimizer/custom/index.js.map +1 -1
  158. package/package.json +41 -215
  159. package/readme.md +12 -8
  160. package/renderOnlyIndex.d.ts +11 -11
  161. package/renderOnlyIndex.js +17 -15
  162. package/renderOnlyIndex.js.map +1 -1
  163. package/templating/eventManager.d.ts +35 -35
  164. package/templating/eventManager.js +65 -63
  165. package/templating/eventManager.js.map +1 -1
  166. package/templating/plugins/hdButtonPlugin.d.ts +9 -9
  167. package/templating/plugins/hdButtonPlugin.js +21 -34
  168. package/templating/plugins/hdButtonPlugin.js.map +1 -1
  169. package/templating/plugins/printButton.d.ts +9 -10
  170. package/templating/plugins/printButton.js +40 -53
  171. package/templating/plugins/printButton.js.map +1 -1
  172. package/templating/templateManager.d.ts +190 -189
  173. package/templating/templateManager.js +553 -543
  174. package/templating/templateManager.js.map +1 -1
  175. package/templating/viewerTemplatePlugin.d.ts +21 -21
  176. package/templating/viewerTemplatePlugin.js +68 -68
  177. package/templating/viewerTemplatePlugin.js.map +1 -1
  178. package/viewer/defaultViewer.d.ts +122 -116
  179. package/viewer/defaultViewer.js +665 -670
  180. package/viewer/defaultViewer.js.map +1 -1
  181. package/viewer/renderOnlyViewer.d.ts +8 -8
  182. package/viewer/renderOnlyViewer.js +43 -50
  183. package/viewer/renderOnlyViewer.js.map +1 -1
  184. package/viewer/viewer.d.ts +254 -253
  185. package/viewer/viewer.js +777 -763
  186. package/viewer/viewer.js.map +1 -1
  187. package/viewer/viewerManager.d.ts +55 -55
  188. package/viewer/viewerManager.js +87 -86
  189. package/viewer/viewerManager.js.map +1 -1
  190. package/viewer/viewerWithTemplate.d.ts +9 -9
  191. package/viewer/viewerWithTemplate.js +19 -32
  192. package/viewer/viewerWithTemplate.js.map +1 -1
@@ -1,671 +1,666 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- import { FilesInput } from '@babylonjs/core/Misc/filesInput.js';
17
- import { SpotLight } from '@babylonjs/core/Lights/spotLight.js';
18
- import { Vector3 } from '@babylonjs/core/Maths/math.js';
19
- import { TemplateManager } from '../templating/templateManager.js';
20
- import { AbstractViewerWithTemplate } from './viewerWithTemplate.js';
21
- import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial.js';
22
- import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial.js';
23
- import { extendClassWithConfig } from '../helper/index.js';
24
- import { AnimationState } from '../model/modelAnimation.js';
25
- import { HDButtonPlugin } from '../templating/plugins/hdButtonPlugin.js';
26
- import { PrintButtonPlugin } from '../templating/plugins/printButton.js';
27
- /**
28
- * The Default viewer is the default implementation of the AbstractViewer.
29
- * It uses the templating system to render a new canvas and controls.
30
- */
31
- var DefaultViewer = /** @class */ (function (_super) {
32
- __extends(DefaultViewer, _super);
33
- /**
34
- * Create a new default viewer
35
- * @param containerElement the element in which the templates will be rendered
36
- * @param initialConfiguration the initial configuration. Defaults to extending the default configuration
37
- */
38
- function DefaultViewer(containerElement, initialConfiguration) {
39
- if (initialConfiguration === void 0) { initialConfiguration = { extends: 'default' }; }
40
- var _this = _super.call(this, containerElement, initialConfiguration) || this;
41
- _this.containerElement = containerElement;
42
- _this._registeredPlugins = [];
43
- _this._handlePointerClick = function (event) {
44
- var pointerDown = event.event;
45
- if (pointerDown.button !== 0) {
46
- return;
47
- }
48
- var element = event.event.target;
49
- if (!element) {
50
- return;
51
- }
52
- var parentClasses = element.parentElement.classList;
53
- var elementClasses = element.classList;
54
- var elementName = "";
55
- for (var i = 0; i < elementClasses.length; ++i) {
56
- var className = elementClasses[i];
57
- if (className.indexOf("-button") !== -1 || className.indexOf("-wrapper") !== -1) {
58
- elementName = className;
59
- break;
60
- }
61
- }
62
- switch (elementName) {
63
- case "speed-button":
64
- case "types-button":
65
- if (parentClasses.contains("open")) {
66
- parentClasses.remove("open");
67
- }
68
- else {
69
- parentClasses.add("open");
70
- }
71
- break;
72
- case "play-pause-button":
73
- _this._togglePlayPause();
74
- break;
75
- case "label-option-button":
76
- var value = element.dataset["value"];
77
- var label = element.querySelector("span.animation-label");
78
- if (label && value) {
79
- _this._updateAnimationType({ value: value.trim(), label: label.innerHTML });
80
- }
81
- break;
82
- case "speed-option-button":
83
- if (!_this._currentAnimation) {
84
- return;
85
- }
86
- var speed = element.dataset["value"];
87
- if (speed) {
88
- _this._updateAnimationSpeed(speed);
89
- }
90
- break;
91
- case "progress-wrapper":
92
- _this._resumePlay = !_this._isAnimationPaused;
93
- if (_this._resumePlay) {
94
- _this._togglePlayPause(true);
95
- }
96
- break;
97
- case "fullscreen-button":
98
- _this.toggleFullscreen();
99
- break;
100
- case "vr-button":
101
- _this.toggleVR();
102
- break;
103
- default:
104
- return;
105
- }
106
- };
107
- /**
108
- * Plays or Pauses animation
109
- */
110
- _this._togglePlayPause = function (noUiUpdate) {
111
- if (!_this._currentAnimation) {
112
- return;
113
- }
114
- if (_this._isAnimationPaused) {
115
- _this._currentAnimation.restart();
116
- }
117
- else {
118
- _this._currentAnimation.pause();
119
- }
120
- _this._isAnimationPaused = !_this._isAnimationPaused;
121
- if (noUiUpdate) {
122
- return;
123
- }
124
- var navbar = _this.templateManager.getTemplate('navBar');
125
- if (!navbar) {
126
- return;
127
- }
128
- navbar.updateParams({
129
- paused: _this._isAnimationPaused,
130
- });
131
- };
132
- /**
133
- * Control progress bar position based on animation current frame
134
- */
135
- _this._updateProgressBar = function () {
136
- var navbar = _this.templateManager.getTemplate('navBar');
137
- if (!navbar) {
138
- return;
139
- }
140
- var progressSlider = navbar.parent.querySelector("input.progress-wrapper");
141
- if (progressSlider && _this._currentAnimation) {
142
- var progress = _this._currentAnimation.currentFrame / _this._currentAnimation.frames * 100;
143
- var currentValue = progressSlider.valueAsNumber;
144
- if (Math.abs(currentValue - progress) > 0.5) { // Only move if greater than a 1% change
145
- progressSlider.value = '' + progress;
146
- }
147
- if (_this._currentAnimation.state === AnimationState.PLAYING) {
148
- if (_this.sceneManager.camera.autoRotationBehavior && !_this._oldIdleRotationValue) {
149
- _this._oldIdleRotationValue = _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed;
150
- _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed = 0;
151
- }
152
- }
153
- else {
154
- if (_this.sceneManager.camera.autoRotationBehavior && _this._oldIdleRotationValue) {
155
- _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed = _this._oldIdleRotationValue;
156
- _this._oldIdleRotationValue = 0;
157
- }
158
- }
159
- }
160
- };
161
- /**
162
- * Update Current Animation Speed
163
- */
164
- _this._updateAnimationSpeed = function (speed, paramsObject) {
165
- var navbar = _this.templateManager.getTemplate('navBar');
166
- if (!navbar) {
167
- return;
168
- }
169
- if (speed && _this._currentAnimation) {
170
- _this._currentAnimation.speedRatio = parseFloat(speed);
171
- if (!_this._isAnimationPaused) {
172
- _this._currentAnimation.restart();
173
- }
174
- if (paramsObject) {
175
- paramsObject.selectedSpeed = speed + "x";
176
- }
177
- else {
178
- navbar.updateParams({
179
- selectedSpeed: speed + "x",
180
- });
181
- }
182
- }
183
- };
184
- /**
185
- * Update Current Animation Type
186
- */
187
- _this._updateAnimationType = function (data, paramsObject) {
188
- var navbar = _this.templateManager.getTemplate('navBar');
189
- if (!navbar) {
190
- return;
191
- }
192
- if (data) {
193
- _this._currentAnimation = _this.sceneManager.models[0].setCurrentAnimationByName(data.value);
194
- }
195
- if (paramsObject) {
196
- paramsObject.selectedAnimation = (_this._animationList.indexOf(data.value) + 1);
197
- paramsObject.selectedAnimationName = data.label;
198
- }
199
- else {
200
- navbar.updateParams({
201
- selectedAnimation: (_this._animationList.indexOf(data.value) + 1),
202
- selectedAnimationName: data.label
203
- });
204
- }
205
- _this._updateAnimationSpeed("1.0", paramsObject);
206
- };
207
- /**
208
- * Toggle fullscreen of the entire viewer
209
- */
210
- _this.toggleFullscreen = function () {
211
- var viewerTemplate = _this.templateManager.getTemplate('viewer');
212
- var viewerElement = viewerTemplate && viewerTemplate.parent;
213
- var fullscreenElement = _this.fullscreenElement || viewerElement;
214
- if (fullscreenElement) {
215
- var currentElement = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
216
- if (!currentElement) {
217
- var requestFullScreen = fullscreenElement.requestFullscreen || fullscreenElement.webkitRequestFullscreen || fullscreenElement.msRequestFullscreen || fullscreenElement.mozRequestFullScreen;
218
- requestFullScreen.call(fullscreenElement);
219
- if (viewerElement) {
220
- viewerElement.classList.add("in-fullscreen");
221
- }
222
- }
223
- else {
224
- var exitFullscreen = document.exitFullscreen || document.webkitExitFullscreen || document.msExitFullscreen || document.mozCancelFullScreen;
225
- exitFullscreen.call(document);
226
- if (viewerElement) {
227
- viewerElement.classList.remove("in-fullscreen");
228
- }
229
- }
230
- }
231
- };
232
- _this._onModelLoaded = function (model) {
233
- _this._configureTemplate(model);
234
- // with a short timeout, making sure everything is there already.
235
- var hideLoadingDelay = 20;
236
- if (_this.configuration.lab && _this.configuration.lab.hideLoadingDelay !== undefined) {
237
- hideLoadingDelay = _this.configuration.lab.hideLoadingDelay;
238
- }
239
- setTimeout(function () {
240
- _this.sceneManager.scene.executeWhenReady(function () {
241
- _this.hideLoadingScreen();
242
- });
243
- }, hideLoadingDelay);
244
- return;
245
- };
246
- _this.onModelLoadedObservable.add(_this._onModelLoaded);
247
- _this.onModelRemovedObservable.add(function () {
248
- _this._configureTemplate();
249
- });
250
- _this.onEngineInitObservable.add(function () {
251
- _this.sceneManager.onLightsConfiguredObservable.add(function (data) {
252
- _this._configureLights();
253
- });
254
- });
255
- _this.onInitDoneObservable.add(function () {
256
- _this.sceneManager.setDefaultMaterial = function (sceneConfig) {
257
- var conf = sceneConfig.defaultMaterial;
258
- if (!conf) {
259
- return;
260
- }
261
- if ((conf.materialType === 'standard' && this.scene.defaultMaterial.getClassName() !== 'StandardMaterial') ||
262
- (conf.materialType === 'pbr' && this.scene.defaultMaterial.getClassName() !== 'PBRMaterial')) {
263
- this.scene.defaultMaterial.dispose();
264
- if (conf.materialType === 'standard') {
265
- this.scene.defaultMaterial = new StandardMaterial("defaultMaterial", this.scene);
266
- }
267
- else {
268
- this.scene.defaultMaterial = new PBRMaterial("defaultMaterial", this.scene);
269
- }
270
- }
271
- extendClassWithConfig(this.scene.defaultMaterial, conf);
272
- };
273
- if (!_this.sceneManager.models.length) {
274
- _this.hideLoadingScreen();
275
- }
276
- });
277
- return _this;
278
- }
279
- DefaultViewer.prototype.registerTemplatePlugin = function (plugin) {
280
- var _this = this;
281
- //validate
282
- if (!plugin.templateName) {
283
- throw new Error("No template name provided");
284
- }
285
- this._registeredPlugins.push(plugin);
286
- var template = this.templateManager.getTemplate(plugin.templateName);
287
- if (!template) {
288
- throw new Error("Template ".concat(plugin.templateName, " not found"));
289
- }
290
- if (plugin.addHTMLTemplate) {
291
- template.onHTMLRendered.add(function (tmpl) {
292
- plugin.addHTMLTemplate(tmpl);
293
- });
294
- template.redraw();
295
- }
296
- if (plugin.eventsToAttach) {
297
- plugin.eventsToAttach.forEach(function (eventName) {
298
- plugin.onEvent && _this.templateManager.eventManager.registerCallback(plugin.templateName, function (event) {
299
- if (plugin.onEvent && plugin.interactionPredicate(event)) {
300
- plugin.onEvent(event);
301
- }
302
- }, eventName);
303
- });
304
- }
305
- };
306
- /**
307
- * This will be executed when the templates initialize.
308
- */
309
- DefaultViewer.prototype._onTemplatesLoaded = function () {
310
- var _this = this;
311
- this.showLoadingScreen();
312
- // navbar
313
- this._initNavbar();
314
- // close overlay button
315
- var template = this.templateManager.getTemplate('overlay');
316
- if (template) {
317
- var closeButton = template.parent.querySelector('.close-button');
318
- if (closeButton) {
319
- closeButton.addEventListener('pointerdown', function () {
320
- _this.hideOverlayScreen();
321
- });
322
- }
323
- }
324
- if (this.configuration.templates && this.configuration.templates.viewer) {
325
- if (this.configuration.templates.viewer.params && this.configuration.templates.viewer.params.enableDragAndDrop) {
326
- this.onSceneInitObservable.addOnce(function () {
327
- var filesInput = new FilesInput(_this.engine, _this.sceneManager.scene, function () {
328
- }, function () {
329
- }, function () {
330
- }, function () {
331
- }, function () {
332
- }, function (file) {
333
- _this.loadModel(file);
334
- }, function () {
335
- });
336
- filesInput.monitorElementForDragNDrop(_this.templateManager.getCanvas());
337
- });
338
- }
339
- }
340
- return _super.prototype._onTemplatesLoaded.call(this);
341
- };
342
- DefaultViewer.prototype._initNavbar = function () {
343
- var _this = this;
344
- var navbar = this.templateManager.getTemplate('navBar');
345
- if (navbar) {
346
- this.onFrameRenderedObservable.add(this._updateProgressBar);
347
- this.templateManager.eventManager.registerCallback('navBar', this._handlePointerClick, 'click');
348
- // an example how to trigger the help button. publiclly available
349
- this.templateManager.eventManager.registerCallback("navBar", function () {
350
- // do your thing
351
- }, "pointerdown", ".help-button");
352
- this.templateManager.eventManager.registerCallback("navBar", function (event) {
353
- var evt = event.event;
354
- var element = (evt.target);
355
- if (!_this._currentAnimation) {
356
- return;
357
- }
358
- var gotoFrame = +element.value / 100 * _this._currentAnimation.frames;
359
- if (isNaN(gotoFrame)) {
360
- return;
361
- }
362
- _this._currentAnimation.goToFrame(gotoFrame);
363
- }, "input");
364
- this.templateManager.eventManager.registerCallback("navBar", function () {
365
- if (_this._resumePlay) {
366
- _this._togglePlayPause(true);
367
- }
368
- _this._resumePlay = false;
369
- }, "pointerup", ".progress-wrapper");
370
- if (window.devicePixelRatio === 1 && navbar.configuration.params && !navbar.configuration.params.hideHdButton) {
371
- navbar.updateParams({
372
- hideHdButton: true
373
- });
374
- }
375
- this.registerTemplatePlugin(new HDButtonPlugin(this));
376
- this.registerTemplatePlugin(new PrintButtonPlugin(this));
377
- }
378
- };
379
- DefaultViewer.prototype._initVR = function () {
380
- var _this = this;
381
- this.engine.onVRDisplayChangedObservable.add(function () {
382
- var viewerTemplate = _this.templateManager.getTemplate('viewer');
383
- var viewerElement = viewerTemplate && viewerTemplate.parent;
384
- if (viewerElement) {
385
- if (_this.sceneManager.vrHelper.isInVRMode) {
386
- viewerElement.classList.add("in-vr");
387
- }
388
- else {
389
- viewerElement.classList.remove("in-vr");
390
- }
391
- }
392
- });
393
- if (this.sceneManager.vrHelper) {
394
- // due to the way the experience helper is exisintg VR, this must be added.
395
- this.sceneManager.vrHelper.onExitingVR.add(function () {
396
- var viewerTemplate = _this.templateManager.getTemplate('viewer');
397
- var viewerElement = viewerTemplate && viewerTemplate.parent;
398
- if (viewerElement) {
399
- viewerElement.classList.remove("in-vr");
400
- }
401
- });
402
- }
403
- _super.prototype._initVR.call(this);
404
- };
405
- /**
406
- * Preparing the container element to present the viewer
407
- */
408
- DefaultViewer.prototype._prepareContainerElement = function () {
409
- var htmlElement = this.containerElement;
410
- if (htmlElement.style) {
411
- htmlElement.style.position = 'relative';
412
- htmlElement.style.height = '100%';
413
- htmlElement.style.display = 'flex';
414
- }
415
- };
416
- /**
417
- * This function will configure the templates and update them after a model was loaded
418
- * It is mainly responsible to changing the title and subtitle etc'.
419
- * @param model the model to be used to configure the templates by
420
- */
421
- DefaultViewer.prototype._configureTemplate = function (model) {
422
- var navbar = this.templateManager.getTemplate('navBar');
423
- if (!navbar) {
424
- return;
425
- }
426
- var newParams = navbar.configuration.params || {};
427
- if (!model) {
428
- newParams.animations = null;
429
- }
430
- else {
431
- var animationNames = model.getAnimationNames();
432
- newParams.animations = animationNames.map(function (a) { return { label: a, value: a }; });
433
- if (animationNames.length) {
434
- this._isAnimationPaused = (model.configuration.animation && !model.configuration.animation.autoStart) || !model.configuration.animation;
435
- this._animationList = animationNames;
436
- newParams.paused = this._isAnimationPaused;
437
- var animationIndex = 0;
438
- if (model.configuration.animation && typeof model.configuration.animation.autoStart === 'string') {
439
- animationIndex = animationNames.indexOf(model.configuration.animation.autoStart);
440
- if (animationIndex === -1) {
441
- animationIndex = 0;
442
- }
443
- }
444
- this._updateAnimationType(newParams.animations[animationIndex], newParams);
445
- }
446
- else {
447
- newParams.animations = null;
448
- }
449
- if (model.configuration.thumbnail) {
450
- newParams.logoImage = model.configuration.thumbnail;
451
- }
452
- }
453
- navbar.updateParams(newParams, false);
454
- };
455
- /**
456
- * This will load a new model to the default viewer
457
- * overriding the AbstractViewer's loadModel.
458
- * The scene will automatically be cleared of the old models, if exist.
459
- * @param model the configuration object (or URL) to load.
460
- */
461
- DefaultViewer.prototype.loadModel = function (model) {
462
- var _this = this;
463
- if (!model) {
464
- model = this.configuration.model;
465
- }
466
- this.showLoadingScreen();
467
- return _super.prototype.loadModel.call(this, model, true).catch(function (error) {
468
- console.log(error);
469
- _this.hideLoadingScreen();
470
- _this.showOverlayScreen('error');
471
- return Promise.reject(error);
472
- });
473
- };
474
- /**
475
- * Show the overlay and the defined sub-screen.
476
- * Mainly used for help and errors
477
- * @param subScreen the name of the subScreen. Those can be defined in the configuration object
478
- */
479
- DefaultViewer.prototype.showOverlayScreen = function (subScreen) {
480
- var _this = this;
481
- var template = this.templateManager.getTemplate('overlay');
482
- if (!template) {
483
- return Promise.resolve('Overlay template not found');
484
- }
485
- return template.show((function (template) {
486
- var canvasRect = _this.containerElement.getBoundingClientRect();
487
- template.parent.style.display = 'flex';
488
- template.parent.style.width = canvasRect.width + "px";
489
- template.parent.style.height = canvasRect.height + "px";
490
- template.parent.style.opacity = "1";
491
- var subTemplate = _this.templateManager.getTemplate(subScreen);
492
- if (!subTemplate) {
493
- return Promise.reject(subScreen + ' template not found');
494
- }
495
- return subTemplate.show((function (template) {
496
- template.parent.style.display = 'flex';
497
- return Promise.resolve(template);
498
- }));
499
- }));
500
- };
501
- /**
502
- * Hide the overlay screen.
503
- */
504
- DefaultViewer.prototype.hideOverlayScreen = function () {
505
- var template = this.templateManager.getTemplate('overlay');
506
- if (!template) {
507
- return Promise.resolve('Overlay template not found');
508
- }
509
- return template.hide((function (template) {
510
- template.parent.style.opacity = "0";
511
- var onTransitionEnd = function () {
512
- template.parent.removeEventListener("transitionend", onTransitionEnd);
513
- template.parent.style.display = 'none';
514
- };
515
- template.parent.addEventListener("transitionend", onTransitionEnd);
516
- var overlays = template.parent.querySelectorAll('.overlay');
517
- if (overlays) {
518
- for (var i = 0; i < overlays.length; ++i) {
519
- var htmlElement = overlays.item(i);
520
- htmlElement.style.display = 'none';
521
- }
522
- }
523
- return Promise.resolve(template);
524
- }));
525
- };
526
- /**
527
- * show the viewer (in case it was hidden)
528
- *
529
- * @param visibilityFunction an optional function to execute in order to show the container
530
- */
531
- DefaultViewer.prototype.show = function (visibilityFunction) {
532
- var template = this.templateManager.getTemplate('main');
533
- //not possible, but yet:
534
- if (!template) {
535
- return Promise.reject('Main template not found');
536
- }
537
- return template.show(visibilityFunction);
538
- };
539
- /**
540
- * hide the viewer (in case it is visible)
541
- *
542
- * @param visibilityFunction an optional function to execute in order to hide the container
543
- */
544
- DefaultViewer.prototype.hide = function (visibilityFunction) {
545
- var template = this.templateManager.getTemplate('main');
546
- //not possible, but yet:
547
- if (!template) {
548
- return Promise.reject('Main template not found');
549
- }
550
- return template.hide(visibilityFunction);
551
- };
552
- /**
553
- * Show the loading screen.
554
- * The loading screen can be configured using the configuration object
555
- */
556
- DefaultViewer.prototype.showLoadingScreen = function () {
557
- var _this = this;
558
- var template = this.templateManager.getTemplate('loadingScreen');
559
- if (!template) {
560
- return Promise.resolve('Loading Screen template not found');
561
- }
562
- return template.show((function (template) {
563
- var canvasRect = _this.containerElement.getBoundingClientRect();
564
- // var canvasPositioning = window.getComputedStyle(this.containerElement).position;
565
- template.parent.style.display = 'flex';
566
- template.parent.style.width = canvasRect.width + "px";
567
- template.parent.style.height = canvasRect.height + "px";
568
- template.parent.style.opacity = "1";
569
- // from the configuration!!!
570
- var color = "black";
571
- if (_this.configuration.templates && _this.configuration.templates.loadingScreen) {
572
- color = (_this.configuration.templates.loadingScreen.params &&
573
- _this.configuration.templates.loadingScreen.params.backgroundColor) || color;
574
- }
575
- template.parent.style.backgroundColor = color;
576
- return Promise.resolve(template);
577
- }));
578
- };
579
- /**
580
- * Hide the loading screen
581
- */
582
- DefaultViewer.prototype.hideLoadingScreen = function () {
583
- var template = this.templateManager.getTemplate('loadingScreen');
584
- if (!template) {
585
- return Promise.resolve('Loading Screen template not found');
586
- }
587
- return template.hide((function (template) {
588
- template.parent.style.opacity = "0";
589
- var onTransitionEnd = function () {
590
- template.parent.removeEventListener("transitionend", onTransitionEnd);
591
- template.parent.style.display = 'none';
592
- };
593
- template.parent.addEventListener("transitionend", onTransitionEnd);
594
- return Promise.resolve(template);
595
- }));
596
- };
597
- DefaultViewer.prototype.dispose = function () {
598
- this.templateManager.dispose();
599
- _super.prototype.dispose.call(this);
600
- };
601
- DefaultViewer.prototype._onConfigurationLoaded = function (configuration) {
602
- var _this = this;
603
- _super.prototype._onConfigurationLoaded.call(this, configuration);
604
- this.templateManager = new TemplateManager(this.containerElement);
605
- // initialize the templates
606
- var templateConfiguration = this.configuration.templates || {};
607
- this.templateManager.initTemplate(templateConfiguration);
608
- // when done, execute onTemplatesLoaded()
609
- this.templateManager.onAllLoaded.add(function () {
610
- var canvas = _this.templateManager.getCanvas();
611
- if (canvas) {
612
- _this._canvas = canvas;
613
- }
614
- _this._onTemplateLoaded();
615
- });
616
- };
617
- /**
618
- * An extension of the light configuration of the abstract viewer.
619
- * @param lightsConfiguration the light configuration to use
620
- * @param model the model that will be used to configure the lights (if the lights are model-dependant)
621
- */
622
- DefaultViewer.prototype._configureLights = function () {
623
- var _this = this;
624
- // labs feature - flashlight
625
- if (this.configuration.lab && this.configuration.lab.flashlight) {
626
- var lightTarget_1;
627
- var angle = 0.5;
628
- var exponent = Math.PI / 2;
629
- if (typeof this.configuration.lab.flashlight === "object") {
630
- exponent = this.configuration.lab.flashlight.exponent || exponent;
631
- angle = this.configuration.lab.flashlight.angle || angle;
632
- }
633
- var flashlight = new SpotLight("flashlight", Vector3.Zero(), Vector3.Zero(), exponent, angle, this.sceneManager.scene);
634
- if (typeof this.configuration.lab.flashlight === "object") {
635
- flashlight.intensity = this.configuration.lab.flashlight.intensity || flashlight.intensity;
636
- if (this.configuration.lab.flashlight.diffuse) {
637
- flashlight.diffuse.r = this.configuration.lab.flashlight.diffuse.r;
638
- flashlight.diffuse.g = this.configuration.lab.flashlight.diffuse.g;
639
- flashlight.diffuse.b = this.configuration.lab.flashlight.diffuse.b;
640
- }
641
- if (this.configuration.lab.flashlight.specular) {
642
- flashlight.specular.r = this.configuration.lab.flashlight.specular.r;
643
- flashlight.specular.g = this.configuration.lab.flashlight.specular.g;
644
- flashlight.specular.b = this.configuration.lab.flashlight.specular.b;
645
- }
646
- }
647
- this.sceneManager.scene.constantlyUpdateMeshUnderPointer = true;
648
- this.sceneManager.scene.onPointerObservable.add(function (eventData) {
649
- if (eventData.type === 4 && eventData.pickInfo) {
650
- lightTarget_1 = (eventData.pickInfo.pickedPoint);
651
- }
652
- else {
653
- lightTarget_1 = undefined;
654
- }
655
- });
656
- var updateFlashlightFunction = function () {
657
- if (_this.sceneManager.camera && flashlight) {
658
- flashlight.position.copyFrom(_this.sceneManager.camera.position);
659
- if (lightTarget_1) {
660
- lightTarget_1.subtractToRef(flashlight.position, flashlight.direction);
661
- }
662
- }
663
- };
664
- this.sceneManager.scene.registerBeforeRender(updateFlashlightFunction);
665
- this._registeredOnBeforeRenderFunctions.push(updateFlashlightFunction);
666
- }
667
- };
668
- return DefaultViewer;
669
- }(AbstractViewerWithTemplate));
670
- export { DefaultViewer };
1
+ import { __extends } from "tslib";
2
+ import { TemplateManager } from "../templating/templateManager.js";
3
+ import { FilesInput } from "@babylonjs/core/Misc/filesInput.js";
4
+ import { SpotLight } from "@babylonjs/core/Lights/spotLight.js";
5
+ import { Vector3 } from "@babylonjs/core/Maths/math.js";
6
+ import { AbstractViewerWithTemplate } from "./viewerWithTemplate.js";
7
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
8
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
9
+ // eslint-disable-next-line import/no-internal-modules
10
+ import { extendClassWithConfig } from "../helper/index.js";
11
+ import { AnimationState } from "../model/modelAnimation.js";
12
+ import { HDButtonPlugin } from "../templating/plugins/hdButtonPlugin.js";
13
+ import { PrintButtonPlugin } from "../templating/plugins/printButton.js";
14
+ import "@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent.js";
15
+ /**
16
+ * The Default viewer is the default implementation of the AbstractViewer.
17
+ * It uses the templating system to render a new canvas and controls.
18
+ */
19
+ var DefaultViewer = /** @class */ (function (_super) {
20
+ __extends(DefaultViewer, _super);
21
+ /**
22
+ * Create a new default viewer
23
+ * @param containerElement the element in which the templates will be rendered
24
+ * @param initialConfiguration the initial configuration. Defaults to extending the default configuration
25
+ */
26
+ function DefaultViewer(containerElement, initialConfiguration) {
27
+ if (initialConfiguration === void 0) { initialConfiguration = { extends: "default" }; }
28
+ var _this = _super.call(this, containerElement, initialConfiguration) || this;
29
+ _this.containerElement = containerElement;
30
+ _this._registeredPlugins = [];
31
+ _this._handlePointerClick = function (event) {
32
+ var pointerDown = event.event;
33
+ if (pointerDown.button !== 0) {
34
+ return;
35
+ }
36
+ var element = event.event.target;
37
+ if (!element) {
38
+ return;
39
+ }
40
+ var parentClasses = element.parentElement.classList;
41
+ var elementClasses = element.classList;
42
+ var elementName = "";
43
+ for (var i = 0; i < elementClasses.length; ++i) {
44
+ var className = elementClasses[i];
45
+ if (className.indexOf("-button") !== -1 || className.indexOf("-wrapper") !== -1) {
46
+ elementName = className;
47
+ break;
48
+ }
49
+ }
50
+ switch (elementName) {
51
+ case "speed-button":
52
+ case "types-button":
53
+ if (parentClasses.contains("open")) {
54
+ parentClasses.remove("open");
55
+ }
56
+ else {
57
+ parentClasses.add("open");
58
+ }
59
+ break;
60
+ case "play-pause-button":
61
+ _this._togglePlayPause();
62
+ break;
63
+ case "label-option-button": {
64
+ var value = element.dataset["value"];
65
+ var label = element.querySelector("span.animation-label");
66
+ if (label && value) {
67
+ _this._updateAnimationType({ value: value.trim(), label: label.innerHTML });
68
+ }
69
+ break;
70
+ }
71
+ case "speed-option-button": {
72
+ if (!_this._currentAnimation) {
73
+ return;
74
+ }
75
+ var speed = element.dataset["value"];
76
+ if (speed) {
77
+ _this._updateAnimationSpeed(speed);
78
+ }
79
+ break;
80
+ }
81
+ case "progress-wrapper":
82
+ _this._resumePlay = !_this._isAnimationPaused;
83
+ if (_this._resumePlay) {
84
+ _this._togglePlayPause(true);
85
+ }
86
+ break;
87
+ case "fullscreen-button":
88
+ _this.toggleFullscreen();
89
+ break;
90
+ case "vr-button":
91
+ _this.toggleVR();
92
+ break;
93
+ default:
94
+ return;
95
+ }
96
+ };
97
+ /**
98
+ * Plays or Pauses animation
99
+ * @param noUiUpdate
100
+ */
101
+ _this._togglePlayPause = function (noUiUpdate) {
102
+ if (!_this._currentAnimation) {
103
+ return;
104
+ }
105
+ if (_this._isAnimationPaused) {
106
+ _this._currentAnimation.restart();
107
+ }
108
+ else {
109
+ _this._currentAnimation.pause();
110
+ }
111
+ _this._isAnimationPaused = !_this._isAnimationPaused;
112
+ if (noUiUpdate) {
113
+ return;
114
+ }
115
+ var navbar = _this.templateManager.getTemplate("navBar");
116
+ if (!navbar) {
117
+ return;
118
+ }
119
+ navbar.updateParams({
120
+ paused: _this._isAnimationPaused,
121
+ });
122
+ };
123
+ /**
124
+ * Control progress bar position based on animation current frame
125
+ */
126
+ _this._updateProgressBar = function () {
127
+ var navbar = _this.templateManager.getTemplate("navBar");
128
+ if (!navbar) {
129
+ return;
130
+ }
131
+ var progressSlider = navbar.parent.querySelector("input.progress-wrapper");
132
+ if (progressSlider && _this._currentAnimation) {
133
+ var progress = (_this._currentAnimation.currentFrame / _this._currentAnimation.frames) * 100;
134
+ var currentValue = progressSlider.valueAsNumber;
135
+ if (Math.abs(currentValue - progress) > 0.5) {
136
+ // Only move if greater than a 1% change
137
+ progressSlider.value = "" + progress;
138
+ }
139
+ if (_this._currentAnimation.state === AnimationState.PLAYING) {
140
+ if (_this.sceneManager.camera.autoRotationBehavior && !_this._oldIdleRotationValue) {
141
+ _this._oldIdleRotationValue = _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed;
142
+ _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed = 0;
143
+ }
144
+ }
145
+ else {
146
+ if (_this.sceneManager.camera.autoRotationBehavior && _this._oldIdleRotationValue) {
147
+ _this.sceneManager.camera.autoRotationBehavior.idleRotationSpeed = _this._oldIdleRotationValue;
148
+ _this._oldIdleRotationValue = 0;
149
+ }
150
+ }
151
+ }
152
+ };
153
+ /**
154
+ * Update Current Animation Speed
155
+ * @param speed
156
+ * @param paramsObject
157
+ */
158
+ _this._updateAnimationSpeed = function (speed, paramsObject) {
159
+ var navbar = _this.templateManager.getTemplate("navBar");
160
+ if (!navbar) {
161
+ return;
162
+ }
163
+ if (speed && _this._currentAnimation) {
164
+ _this._currentAnimation.speedRatio = parseFloat(speed);
165
+ if (!_this._isAnimationPaused) {
166
+ _this._currentAnimation.restart();
167
+ }
168
+ if (paramsObject) {
169
+ paramsObject.selectedSpeed = speed + "x";
170
+ }
171
+ else {
172
+ navbar.updateParams({
173
+ selectedSpeed: speed + "x",
174
+ });
175
+ }
176
+ }
177
+ };
178
+ /**
179
+ * Update Current Animation Type
180
+ * @param data
181
+ * @param data.label
182
+ * @param data.value
183
+ * @param paramsObject
184
+ */
185
+ _this._updateAnimationType = function (data, paramsObject) {
186
+ var navbar = _this.templateManager.getTemplate("navBar");
187
+ if (!navbar) {
188
+ return;
189
+ }
190
+ if (data) {
191
+ _this._currentAnimation = _this.sceneManager.models[0].setCurrentAnimationByName(data.value);
192
+ }
193
+ if (paramsObject) {
194
+ paramsObject.selectedAnimation = _this._animationList.indexOf(data.value) + 1;
195
+ paramsObject.selectedAnimationName = data.label;
196
+ }
197
+ else {
198
+ navbar.updateParams({
199
+ selectedAnimation: _this._animationList.indexOf(data.value) + 1,
200
+ selectedAnimationName: data.label,
201
+ });
202
+ }
203
+ _this._updateAnimationSpeed("1.0", paramsObject);
204
+ };
205
+ /**
206
+ * Toggle fullscreen of the entire viewer
207
+ */
208
+ _this.toggleFullscreen = function () {
209
+ var viewerTemplate = _this.templateManager.getTemplate("viewer");
210
+ var viewerElement = viewerTemplate && viewerTemplate.parent;
211
+ var fullscreenElement = _this.fullscreenElement || viewerElement;
212
+ if (fullscreenElement) {
213
+ var currentElement = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
214
+ if (!currentElement) {
215
+ var requestFullScreen = fullscreenElement.requestFullscreen ||
216
+ fullscreenElement.webkitRequestFullscreen ||
217
+ fullscreenElement.msRequestFullscreen ||
218
+ fullscreenElement.mozRequestFullScreen;
219
+ requestFullScreen.call(fullscreenElement);
220
+ if (viewerElement) {
221
+ viewerElement.classList.add("in-fullscreen");
222
+ }
223
+ }
224
+ else {
225
+ var exitFullscreen = document.exitFullscreen || document.webkitExitFullscreen || document.msExitFullscreen || document.mozCancelFullScreen;
226
+ exitFullscreen.call(document);
227
+ if (viewerElement) {
228
+ viewerElement.classList.remove("in-fullscreen");
229
+ }
230
+ }
231
+ }
232
+ };
233
+ _this._onModelLoaded = function (model) {
234
+ _this._configureTemplate(model);
235
+ // with a short timeout, making sure everything is there already.
236
+ var hideLoadingDelay = 20;
237
+ if (_this.configuration.lab && _this.configuration.lab.hideLoadingDelay !== undefined) {
238
+ hideLoadingDelay = _this.configuration.lab.hideLoadingDelay;
239
+ }
240
+ setTimeout(function () {
241
+ _this.sceneManager.scene.executeWhenReady(function () {
242
+ _this.hideLoadingScreen();
243
+ });
244
+ }, hideLoadingDelay);
245
+ return;
246
+ };
247
+ _this.onModelLoadedObservable.add(_this._onModelLoaded);
248
+ _this.onModelRemovedObservable.add(function () {
249
+ _this._configureTemplate();
250
+ });
251
+ _this.onEngineInitObservable.add(function () {
252
+ _this.sceneManager.onLightsConfiguredObservable.add(function () {
253
+ _this._configureLights();
254
+ });
255
+ });
256
+ _this.onInitDoneObservable.add(function () {
257
+ _this.sceneManager.setDefaultMaterial = function (sceneConfig) {
258
+ var conf = sceneConfig.defaultMaterial;
259
+ if (!conf) {
260
+ return;
261
+ }
262
+ if ((conf.materialType === "standard" && this.scene.defaultMaterial.getClassName() !== "StandardMaterial") ||
263
+ (conf.materialType === "pbr" && this.scene.defaultMaterial.getClassName() !== "PBRMaterial")) {
264
+ this.scene.defaultMaterial.dispose();
265
+ if (conf.materialType === "standard") {
266
+ this.scene.defaultMaterial = new StandardMaterial("defaultMaterial", this.scene);
267
+ }
268
+ else {
269
+ this.scene.defaultMaterial = new PBRMaterial("defaultMaterial", this.scene);
270
+ }
271
+ }
272
+ extendClassWithConfig(this.scene.defaultMaterial, conf);
273
+ };
274
+ if (!_this.sceneManager.models.length) {
275
+ _this.hideLoadingScreen();
276
+ }
277
+ });
278
+ return _this;
279
+ }
280
+ DefaultViewer.prototype.registerTemplatePlugin = function (plugin) {
281
+ var _this = this;
282
+ //validate
283
+ if (!plugin.templateName) {
284
+ throw new Error("No template name provided");
285
+ }
286
+ this._registeredPlugins.push(plugin);
287
+ var template = this.templateManager.getTemplate(plugin.templateName);
288
+ if (!template) {
289
+ throw new Error("Template ".concat(plugin.templateName, " not found"));
290
+ }
291
+ if (plugin.addHTMLTemplate) {
292
+ template.onHTMLRendered.add(function (tmpl) {
293
+ plugin.addHTMLTemplate(tmpl);
294
+ });
295
+ template.redraw();
296
+ }
297
+ if (plugin.eventsToAttach) {
298
+ plugin.eventsToAttach.forEach(function (eventName) {
299
+ plugin.onEvent &&
300
+ _this.templateManager.eventManager.registerCallback(plugin.templateName, function (event) {
301
+ if (plugin.onEvent && plugin.interactionPredicate(event)) {
302
+ plugin.onEvent(event);
303
+ }
304
+ }, eventName);
305
+ });
306
+ }
307
+ };
308
+ /**
309
+ * This will be executed when the templates initialize.
310
+ */
311
+ DefaultViewer.prototype._onTemplatesLoaded = function () {
312
+ var _this = this;
313
+ this.showLoadingScreen();
314
+ // navbar
315
+ this._initNavbar();
316
+ // close overlay button
317
+ var template = this.templateManager.getTemplate("overlay");
318
+ if (template) {
319
+ var closeButton = template.parent.querySelector(".close-button");
320
+ if (closeButton) {
321
+ closeButton.addEventListener("pointerdown", function () {
322
+ _this.hideOverlayScreen();
323
+ });
324
+ }
325
+ }
326
+ if (this.configuration.templates && this.configuration.templates.viewer) {
327
+ if (this.configuration.templates.viewer.params && this.configuration.templates.viewer.params.enableDragAndDrop) {
328
+ this.onSceneInitObservable.addOnce(function () {
329
+ var filesInput = new FilesInput(_this.engine, _this.sceneManager.scene, function () { }, function () { }, function () { }, function () { }, function () { }, function (file) {
330
+ _this.loadModel(file);
331
+ }, function () { });
332
+ filesInput.monitorElementForDragNDrop(_this.templateManager.getCanvas());
333
+ });
334
+ }
335
+ }
336
+ return _super.prototype._onTemplatesLoaded.call(this);
337
+ };
338
+ DefaultViewer.prototype._initNavbar = function () {
339
+ var _this = this;
340
+ var navbar = this.templateManager.getTemplate("navBar");
341
+ if (navbar) {
342
+ this.onFrameRenderedObservable.add(this._updateProgressBar);
343
+ this.templateManager.eventManager.registerCallback("navBar", this._handlePointerClick, "click");
344
+ // an example how to trigger the help button. publiclly available
345
+ this.templateManager.eventManager.registerCallback("navBar", function () {
346
+ // do your thing
347
+ }, "pointerdown", ".help-button");
348
+ this.templateManager.eventManager.registerCallback("navBar", function (event) {
349
+ var evt = event.event;
350
+ var element = evt.target;
351
+ if (!_this._currentAnimation) {
352
+ return;
353
+ }
354
+ var gotoFrame = (+element.value / 100) * _this._currentAnimation.frames;
355
+ if (isNaN(gotoFrame)) {
356
+ return;
357
+ }
358
+ _this._currentAnimation.goToFrame(gotoFrame);
359
+ }, "input");
360
+ this.templateManager.eventManager.registerCallback("navBar", function () {
361
+ if (_this._resumePlay) {
362
+ _this._togglePlayPause(true);
363
+ }
364
+ _this._resumePlay = false;
365
+ }, "pointerup", ".progress-wrapper");
366
+ if (window.devicePixelRatio === 1 && navbar.configuration.params && !navbar.configuration.params.hideHdButton) {
367
+ navbar.updateParams({
368
+ hideHdButton: true,
369
+ });
370
+ }
371
+ this.registerTemplatePlugin(new HDButtonPlugin(this));
372
+ this.registerTemplatePlugin(new PrintButtonPlugin(this));
373
+ }
374
+ };
375
+ DefaultViewer.prototype._initVR = function () {
376
+ var _this = this;
377
+ this.engine.onVRDisplayChangedObservable.add(function () {
378
+ var viewerTemplate = _this.templateManager.getTemplate("viewer");
379
+ var viewerElement = viewerTemplate && viewerTemplate.parent;
380
+ if (viewerElement) {
381
+ if (_this.sceneManager.vrHelper.isInVRMode) {
382
+ viewerElement.classList.add("in-vr");
383
+ }
384
+ else {
385
+ viewerElement.classList.remove("in-vr");
386
+ }
387
+ }
388
+ });
389
+ if (this.sceneManager.vrHelper) {
390
+ // due to the way the experience helper is exisintg VR, this must be added.
391
+ this.sceneManager.vrHelper.onExitingVR.add(function () {
392
+ var viewerTemplate = _this.templateManager.getTemplate("viewer");
393
+ var viewerElement = viewerTemplate && viewerTemplate.parent;
394
+ if (viewerElement) {
395
+ viewerElement.classList.remove("in-vr");
396
+ }
397
+ });
398
+ }
399
+ _super.prototype._initVR.call(this);
400
+ };
401
+ /**
402
+ * Preparing the container element to present the viewer
403
+ */
404
+ DefaultViewer.prototype._prepareContainerElement = function () {
405
+ var htmlElement = this.containerElement;
406
+ if (htmlElement.style) {
407
+ htmlElement.style.position = "relative";
408
+ htmlElement.style.height = "100%";
409
+ htmlElement.style.display = "flex";
410
+ }
411
+ };
412
+ /**
413
+ * This function will configure the templates and update them after a model was loaded
414
+ * It is mainly responsible to changing the title and subtitle etc'.
415
+ * @param model the model to be used to configure the templates by
416
+ */
417
+ DefaultViewer.prototype._configureTemplate = function (model) {
418
+ var navbar = this.templateManager.getTemplate("navBar");
419
+ if (!navbar) {
420
+ return;
421
+ }
422
+ var newParams = navbar.configuration.params || {};
423
+ if (!model) {
424
+ newParams.animations = null;
425
+ }
426
+ else {
427
+ var animationNames = model.getAnimationNames();
428
+ newParams.animations = animationNames.map(function (a) {
429
+ return { label: a, value: a };
430
+ });
431
+ if (animationNames.length) {
432
+ this._isAnimationPaused = (model.configuration.animation && !model.configuration.animation.autoStart) || !model.configuration.animation;
433
+ this._animationList = animationNames;
434
+ newParams.paused = this._isAnimationPaused;
435
+ var animationIndex = 0;
436
+ if (model.configuration.animation && typeof model.configuration.animation.autoStart === "string") {
437
+ animationIndex = animationNames.indexOf(model.configuration.animation.autoStart);
438
+ if (animationIndex === -1) {
439
+ animationIndex = 0;
440
+ }
441
+ }
442
+ this._updateAnimationType(newParams.animations[animationIndex], newParams);
443
+ }
444
+ else {
445
+ newParams.animations = null;
446
+ }
447
+ if (model.configuration.thumbnail) {
448
+ newParams.logoImage = model.configuration.thumbnail;
449
+ }
450
+ }
451
+ navbar.updateParams(newParams, false);
452
+ };
453
+ /**
454
+ * This will load a new model to the default viewer
455
+ * overriding the AbstractViewer's loadModel.
456
+ * The scene will automatically be cleared of the old models, if exist.
457
+ * @param model the configuration object (or URL) to load.
458
+ */
459
+ DefaultViewer.prototype.loadModel = function (model) {
460
+ var _this = this;
461
+ if (!model) {
462
+ model = this.configuration.model;
463
+ }
464
+ this.showLoadingScreen();
465
+ return _super.prototype.loadModel.call(this, model, true).catch(function (error) {
466
+ console.log(error);
467
+ _this.hideLoadingScreen();
468
+ _this.showOverlayScreen("error");
469
+ return Promise.reject(error);
470
+ });
471
+ };
472
+ /**
473
+ * Show the overlay and the defined sub-screen.
474
+ * Mainly used for help and errors
475
+ * @param subScreen the name of the subScreen. Those can be defined in the configuration object
476
+ */
477
+ DefaultViewer.prototype.showOverlayScreen = function (subScreen) {
478
+ var _this = this;
479
+ var template = this.templateManager.getTemplate("overlay");
480
+ if (!template) {
481
+ return Promise.resolve("Overlay template not found");
482
+ }
483
+ return template.show(function (template) {
484
+ var canvasRect = _this.containerElement.getBoundingClientRect();
485
+ template.parent.style.display = "flex";
486
+ template.parent.style.width = canvasRect.width + "px";
487
+ template.parent.style.height = canvasRect.height + "px";
488
+ template.parent.style.opacity = "1";
489
+ var subTemplate = _this.templateManager.getTemplate(subScreen);
490
+ if (!subTemplate) {
491
+ return Promise.reject(subScreen + " template not found");
492
+ }
493
+ return subTemplate.show(function (template) {
494
+ template.parent.style.display = "flex";
495
+ return Promise.resolve(template);
496
+ });
497
+ });
498
+ };
499
+ /**
500
+ * Hide the overlay screen.
501
+ */
502
+ DefaultViewer.prototype.hideOverlayScreen = function () {
503
+ var template = this.templateManager.getTemplate("overlay");
504
+ if (!template) {
505
+ return Promise.resolve("Overlay template not found");
506
+ }
507
+ return template.hide(function (template) {
508
+ template.parent.style.opacity = "0";
509
+ var onTransitionEnd = function () {
510
+ template.parent.removeEventListener("transitionend", onTransitionEnd);
511
+ template.parent.style.display = "none";
512
+ };
513
+ template.parent.addEventListener("transitionend", onTransitionEnd);
514
+ var overlays = template.parent.querySelectorAll(".overlay");
515
+ if (overlays) {
516
+ for (var i = 0; i < overlays.length; ++i) {
517
+ var htmlElement = overlays.item(i);
518
+ htmlElement.style.display = "none";
519
+ }
520
+ }
521
+ return Promise.resolve(template);
522
+ });
523
+ };
524
+ /**
525
+ * show the viewer (in case it was hidden)
526
+ *
527
+ * @param visibilityFunction an optional function to execute in order to show the container
528
+ */
529
+ DefaultViewer.prototype.show = function (visibilityFunction) {
530
+ var template = this.templateManager.getTemplate("main");
531
+ //not possible, but yet:
532
+ if (!template) {
533
+ return Promise.reject("Main template not found");
534
+ }
535
+ return template.show(visibilityFunction);
536
+ };
537
+ /**
538
+ * hide the viewer (in case it is visible)
539
+ *
540
+ * @param visibilityFunction an optional function to execute in order to hide the container
541
+ */
542
+ DefaultViewer.prototype.hide = function (visibilityFunction) {
543
+ var template = this.templateManager.getTemplate("main");
544
+ //not possible, but yet:
545
+ if (!template) {
546
+ return Promise.reject("Main template not found");
547
+ }
548
+ return template.hide(visibilityFunction);
549
+ };
550
+ /**
551
+ * Show the loading screen.
552
+ * The loading screen can be configured using the configuration object
553
+ */
554
+ DefaultViewer.prototype.showLoadingScreen = function () {
555
+ var _this = this;
556
+ var template = this.templateManager.getTemplate("loadingScreen");
557
+ if (!template) {
558
+ return Promise.resolve("Loading Screen template not found");
559
+ }
560
+ return template.show(function (template) {
561
+ var canvasRect = _this.containerElement.getBoundingClientRect();
562
+ // var canvasPositioning = window.getComputedStyle(this.containerElement).position;
563
+ template.parent.style.display = "flex";
564
+ template.parent.style.width = canvasRect.width + "px";
565
+ template.parent.style.height = canvasRect.height + "px";
566
+ template.parent.style.opacity = "1";
567
+ // from the configuration!!!
568
+ var color = "black";
569
+ if (_this.configuration.templates && _this.configuration.templates.loadingScreen) {
570
+ color = (_this.configuration.templates.loadingScreen.params && _this.configuration.templates.loadingScreen.params.backgroundColor) || color;
571
+ }
572
+ template.parent.style.backgroundColor = color;
573
+ return Promise.resolve(template);
574
+ });
575
+ };
576
+ /**
577
+ * Hide the loading screen
578
+ */
579
+ DefaultViewer.prototype.hideLoadingScreen = function () {
580
+ var template = this.templateManager.getTemplate("loadingScreen");
581
+ if (!template) {
582
+ return Promise.resolve("Loading Screen template not found");
583
+ }
584
+ return template.hide(function (template) {
585
+ template.parent.style.opacity = "0";
586
+ var onTransitionEnd = function () {
587
+ template.parent.removeEventListener("transitionend", onTransitionEnd);
588
+ template.parent.style.display = "none";
589
+ };
590
+ template.parent.addEventListener("transitionend", onTransitionEnd);
591
+ return Promise.resolve(template);
592
+ });
593
+ };
594
+ DefaultViewer.prototype.dispose = function () {
595
+ this.templateManager.dispose();
596
+ _super.prototype.dispose.call(this);
597
+ };
598
+ DefaultViewer.prototype._onConfigurationLoaded = function (configuration) {
599
+ var _this = this;
600
+ _super.prototype._onConfigurationLoaded.call(this, configuration);
601
+ this.templateManager = new TemplateManager(this.containerElement);
602
+ // initialize the templates
603
+ var templateConfiguration = this.configuration.templates || {};
604
+ this.templateManager.initTemplate(templateConfiguration);
605
+ // when done, execute onTemplatesLoaded()
606
+ this.templateManager.onAllLoaded.add(function () {
607
+ var canvas = _this.templateManager.getCanvas();
608
+ if (canvas) {
609
+ _this._canvas = canvas;
610
+ }
611
+ _this._onTemplateLoaded();
612
+ });
613
+ };
614
+ /**
615
+ * An extension of the light configuration of the abstract viewer.
616
+ */
617
+ DefaultViewer.prototype._configureLights = function () {
618
+ var _this = this;
619
+ // labs feature - flashlight
620
+ if (this.configuration.lab && this.configuration.lab.flashlight) {
621
+ var lightTarget_1;
622
+ var angle = 0.5;
623
+ var exponent = Math.PI / 2;
624
+ if (typeof this.configuration.lab.flashlight === "object") {
625
+ exponent = this.configuration.lab.flashlight.exponent || exponent;
626
+ angle = this.configuration.lab.flashlight.angle || angle;
627
+ }
628
+ var flashlight_1 = new SpotLight("flashlight", Vector3.Zero(), Vector3.Zero(), exponent, angle, this.sceneManager.scene);
629
+ if (typeof this.configuration.lab.flashlight === "object") {
630
+ flashlight_1.intensity = this.configuration.lab.flashlight.intensity || flashlight_1.intensity;
631
+ if (this.configuration.lab.flashlight.diffuse) {
632
+ flashlight_1.diffuse.r = this.configuration.lab.flashlight.diffuse.r;
633
+ flashlight_1.diffuse.g = this.configuration.lab.flashlight.diffuse.g;
634
+ flashlight_1.diffuse.b = this.configuration.lab.flashlight.diffuse.b;
635
+ }
636
+ if (this.configuration.lab.flashlight.specular) {
637
+ flashlight_1.specular.r = this.configuration.lab.flashlight.specular.r;
638
+ flashlight_1.specular.g = this.configuration.lab.flashlight.specular.g;
639
+ flashlight_1.specular.b = this.configuration.lab.flashlight.specular.b;
640
+ }
641
+ }
642
+ this.sceneManager.scene.constantlyUpdateMeshUnderPointer = true;
643
+ this.sceneManager.scene.onPointerObservable.add(function (eventData) {
644
+ if (eventData.type === 4 && eventData.pickInfo) {
645
+ lightTarget_1 = eventData.pickInfo.pickedPoint;
646
+ }
647
+ else {
648
+ lightTarget_1 = undefined;
649
+ }
650
+ });
651
+ var updateFlashlightFunction = function () {
652
+ if (_this.sceneManager.camera && flashlight_1) {
653
+ flashlight_1.position.copyFrom(_this.sceneManager.camera.position);
654
+ if (lightTarget_1) {
655
+ lightTarget_1.subtractToRef(flashlight_1.position, flashlight_1.direction);
656
+ }
657
+ }
658
+ };
659
+ this.sceneManager.scene.registerBeforeRender(updateFlashlightFunction);
660
+ this._registeredOnBeforeRenderFunctions.push(updateFlashlightFunction);
661
+ }
662
+ };
663
+ return DefaultViewer;
664
+ }(AbstractViewerWithTemplate));
665
+ export { DefaultViewer };
671
666
  //# sourceMappingURL=defaultViewer.js.map