@babylonjs/viewer 5.0.0 → 5.0.3

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 (127) hide show
  1. package/configuration/configuration.d.ts +107 -107
  2. package/configuration/configuration.js +15 -15
  3. package/configuration/configurationCompatibility.d.ts +8 -8
  4. package/configuration/configurationCompatibility.js +65 -65
  5. package/configuration/configurationContainer.d.ts +10 -10
  6. package/configuration/configurationContainer.js +9 -9
  7. package/configuration/globals.d.ts +6 -6
  8. package/configuration/globals.js +17 -17
  9. package/configuration/index.d.ts +2 -2
  10. package/configuration/index.js +3 -3
  11. package/configuration/interfaces/cameraConfiguration.d.ts +31 -31
  12. package/configuration/interfaces/cameraConfiguration.js +1 -1
  13. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -81
  14. package/configuration/interfaces/colorGradingConfiguration.js +1 -1
  15. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -20
  16. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +1 -1
  17. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -22
  18. package/configuration/interfaces/environmentMapConfiguration.js +1 -1
  19. package/configuration/interfaces/groundConfiguration.d.ts +24 -24
  20. package/configuration/interfaces/groundConfiguration.js +1 -1
  21. package/configuration/interfaces/imageProcessingConfiguration.d.ts +43 -43
  22. package/configuration/interfaces/imageProcessingConfiguration.js +1 -1
  23. package/configuration/interfaces/index.d.ts +15 -15
  24. package/configuration/interfaces/index.js +15 -15
  25. package/configuration/interfaces/lightConfiguration.d.ts +60 -60
  26. package/configuration/interfaces/lightConfiguration.js +1 -1
  27. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -26
  28. package/configuration/interfaces/modelAnimationConfiguration.js +1 -1
  29. package/configuration/interfaces/modelConfiguration.d.ts +65 -65
  30. package/configuration/interfaces/modelConfiguration.js +1 -1
  31. package/configuration/interfaces/observersConfiguration.d.ts +5 -5
  32. package/configuration/interfaces/observersConfiguration.js +1 -1
  33. package/configuration/interfaces/sceneConfiguration.d.ts +48 -48
  34. package/configuration/interfaces/sceneConfiguration.js +1 -1
  35. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -23
  36. package/configuration/interfaces/sceneOptimizerConfiguration.js +1 -1
  37. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -21
  38. package/configuration/interfaces/skyboxConfiguration.js +1 -1
  39. package/configuration/interfaces/templateConfiguration.d.ts +67 -67
  40. package/configuration/interfaces/templateConfiguration.js +1 -1
  41. package/configuration/interfaces/vrConfiguration.d.ts +16 -16
  42. package/configuration/interfaces/vrConfiguration.js +1 -1
  43. package/configuration/loader.d.ts +4 -4
  44. package/configuration/loader.js +16 -16
  45. package/configuration/mappers.d.ts +42 -42
  46. package/configuration/mappers.js +190 -190
  47. package/configuration/renderOnlyLoader.d.ts +33 -33
  48. package/configuration/renderOnlyLoader.js +161 -161
  49. package/configuration/types/default.d.ts +6 -6
  50. package/configuration/types/default.js +120 -120
  51. package/configuration/types/environmentMap.d.ts +5 -5
  52. package/configuration/types/environmentMap.js +13 -13
  53. package/configuration/types/extended.d.ts +6 -6
  54. package/configuration/types/extended.js +316 -316
  55. package/configuration/types/index.d.ts +13 -13
  56. package/configuration/types/index.js +49 -49
  57. package/configuration/types/minimal.d.ts +6 -6
  58. package/configuration/types/minimal.js +42 -42
  59. package/configuration/types/renderOnlyDefault.d.ts +30 -30
  60. package/configuration/types/renderOnlyDefault.js +30 -30
  61. package/configuration/types/shadowLight.d.ts +9 -9
  62. package/configuration/types/shadowLight.js +63 -63
  63. package/helper/index.d.ts +26 -26
  64. package/helper/index.js +62 -62
  65. package/index.d.ts +30 -30
  66. package/index.js +45 -45
  67. package/initializer.d.ts +11 -11
  68. package/initializer.js +34 -34
  69. package/interfaces.d.ts +5 -5
  70. package/interfaces.js +1 -1
  71. package/labs/environmentSerializer.d.ts +126 -126
  72. package/labs/environmentSerializer.js +190 -190
  73. package/labs/texture.d.ts +183 -183
  74. package/labs/texture.js +300 -300
  75. package/labs/viewerLabs.d.ts +51 -51
  76. package/labs/viewerLabs.js +133 -133
  77. package/loader/modelLoader.d.ts +47 -47
  78. package/loader/modelLoader.js +189 -189
  79. package/loader/plugins/applyMaterialConfig.d.ts +12 -12
  80. package/loader/plugins/applyMaterialConfig.js +15 -15
  81. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -9
  82. package/loader/plugins/extendedMaterialLoaderPlugin.js +15 -15
  83. package/loader/plugins/index.d.ts +18 -18
  84. package/loader/plugins/index.js +42 -42
  85. package/loader/plugins/loaderPlugin.d.ts +24 -24
  86. package/loader/plugins/loaderPlugin.js +1 -1
  87. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -12
  88. package/loader/plugins/msftLodLoaderPlugin.js +20 -20
  89. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -12
  90. package/loader/plugins/telemetryLoaderPlugin.js +35 -35
  91. package/managers/observablesManager.d.ts +66 -66
  92. package/managers/observablesManager.js +34 -34
  93. package/managers/sceneManager.d.ts +243 -243
  94. package/managers/sceneManager.js +1388 -1388
  95. package/managers/telemetryManager.d.ts +57 -57
  96. package/managers/telemetryManager.js +113 -113
  97. package/model/modelAnimation.d.ts +215 -215
  98. package/model/modelAnimation.js +232 -232
  99. package/model/viewerModel.d.ts +228 -228
  100. package/model/viewerModel.js +669 -669
  101. package/optimizer/custom/extended.d.ts +11 -11
  102. package/optimizer/custom/extended.js +98 -98
  103. package/optimizer/custom/index.d.ts +8 -8
  104. package/optimizer/custom/index.js +24 -24
  105. package/package.json +5 -5
  106. package/renderOnlyIndex.d.ts +11 -11
  107. package/renderOnlyIndex.js +17 -17
  108. package/templating/eventManager.d.ts +35 -35
  109. package/templating/eventManager.js +65 -65
  110. package/templating/plugins/hdButtonPlugin.d.ts +9 -9
  111. package/templating/plugins/hdButtonPlugin.js +21 -21
  112. package/templating/plugins/printButton.d.ts +9 -9
  113. package/templating/plugins/printButton.js +40 -40
  114. package/templating/templateManager.d.ts +190 -190
  115. package/templating/templateManager.js +553 -553
  116. package/templating/viewerTemplatePlugin.d.ts +21 -21
  117. package/templating/viewerTemplatePlugin.js +68 -68
  118. package/viewer/defaultViewer.d.ts +122 -122
  119. package/viewer/defaultViewer.js +665 -665
  120. package/viewer/renderOnlyViewer.d.ts +8 -8
  121. package/viewer/renderOnlyViewer.js +43 -43
  122. package/viewer/viewer.d.ts +254 -254
  123. package/viewer/viewer.js +777 -777
  124. package/viewer/viewerManager.d.ts +55 -55
  125. package/viewer/viewerManager.js +87 -87
  126. package/viewer/viewerWithTemplate.d.ts +9 -9
  127. package/viewer/viewerWithTemplate.js +19 -19
@@ -1,666 +1,666 @@
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 };
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 };
666
666
  //# sourceMappingURL=defaultViewer.js.map