@babylonjs/viewer 7.21.5-alpha → 7.21.5
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.
- package/configuration/configuration.d.ts +107 -0
- package/configuration/configuration.js +16 -0
- package/configuration/configuration.js.map +1 -0
- package/configuration/configurationCompatibility.d.ts +8 -0
- package/configuration/configurationCompatibility.js +66 -0
- package/configuration/configurationCompatibility.js.map +1 -0
- package/configuration/configurationContainer.d.ts +10 -0
- package/configuration/configurationContainer.js +10 -0
- package/configuration/configurationContainer.js.map +1 -0
- package/configuration/globals.d.ts +6 -0
- package/configuration/globals.js +18 -0
- package/configuration/globals.js.map +1 -0
- package/configuration/index.d.ts +2 -0
- package/configuration/index.js +4 -0
- package/configuration/index.js.map +1 -0
- package/configuration/interfaces/cameraConfiguration.d.ts +31 -0
- package/configuration/interfaces/cameraConfiguration.js +2 -0
- package/configuration/interfaces/cameraConfiguration.js.map +1 -0
- package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -0
- package/configuration/interfaces/colorGradingConfiguration.js +2 -0
- package/configuration/interfaces/colorGradingConfiguration.js.map +1 -0
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -0
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +2 -0
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -0
- package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -0
- package/configuration/interfaces/environmentMapConfiguration.js +2 -0
- package/configuration/interfaces/environmentMapConfiguration.js.map +1 -0
- package/configuration/interfaces/groundConfiguration.d.ts +24 -0
- package/configuration/interfaces/groundConfiguration.js +2 -0
- package/configuration/interfaces/groundConfiguration.js.map +1 -0
- package/configuration/interfaces/imageProcessingConfiguration.d.ts +45 -0
- package/configuration/interfaces/imageProcessingConfiguration.js +2 -0
- package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -0
- package/configuration/interfaces/index.d.ts +15 -0
- package/configuration/interfaces/index.js +16 -0
- package/configuration/interfaces/index.js.map +1 -0
- package/configuration/interfaces/lightConfiguration.d.ts +60 -0
- package/configuration/interfaces/lightConfiguration.js +2 -0
- package/configuration/interfaces/lightConfiguration.js.map +1 -0
- package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -0
- package/configuration/interfaces/modelAnimationConfiguration.js +2 -0
- package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -0
- package/configuration/interfaces/modelConfiguration.d.ts +65 -0
- package/configuration/interfaces/modelConfiguration.js +2 -0
- package/configuration/interfaces/modelConfiguration.js.map +1 -0
- package/configuration/interfaces/observersConfiguration.d.ts +5 -0
- package/configuration/interfaces/observersConfiguration.js +2 -0
- package/configuration/interfaces/observersConfiguration.js.map +1 -0
- package/configuration/interfaces/sceneConfiguration.d.ts +48 -0
- package/configuration/interfaces/sceneConfiguration.js +2 -0
- package/configuration/interfaces/sceneConfiguration.js.map +1 -0
- package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -0
- package/configuration/interfaces/sceneOptimizerConfiguration.js +2 -0
- package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -0
- package/configuration/interfaces/skyboxConfiguration.d.ts +21 -0
- package/configuration/interfaces/skyboxConfiguration.js +2 -0
- package/configuration/interfaces/skyboxConfiguration.js.map +1 -0
- package/configuration/interfaces/templateConfiguration.d.ts +67 -0
- package/configuration/interfaces/templateConfiguration.js +2 -0
- package/configuration/interfaces/templateConfiguration.js.map +1 -0
- package/configuration/interfaces/vrConfiguration.d.ts +16 -0
- package/configuration/interfaces/vrConfiguration.js +2 -0
- package/configuration/interfaces/vrConfiguration.js.map +1 -0
- package/configuration/loader.d.ts +4 -0
- package/configuration/loader.js +17 -0
- package/configuration/loader.js.map +1 -0
- package/configuration/mappers.d.ts +43 -0
- package/configuration/mappers.js +192 -0
- package/configuration/mappers.js.map +1 -0
- package/configuration/renderOnlyLoader.d.ts +33 -0
- package/configuration/renderOnlyLoader.js +162 -0
- package/configuration/renderOnlyLoader.js.map +1 -0
- package/configuration/types/default.d.ts +6 -0
- package/configuration/types/default.js +121 -0
- package/configuration/types/default.js.map +1 -0
- package/configuration/types/environmentMap.d.ts +5 -0
- package/configuration/types/environmentMap.js +14 -0
- package/configuration/types/environmentMap.js.map +1 -0
- package/configuration/types/extended.d.ts +6 -0
- package/configuration/types/extended.js +317 -0
- package/configuration/types/extended.js.map +1 -0
- package/configuration/types/index.d.ts +14 -0
- package/configuration/types/index.js +51 -0
- package/configuration/types/index.js.map +1 -0
- package/configuration/types/minimal.d.ts +6 -0
- package/configuration/types/minimal.js +43 -0
- package/configuration/types/minimal.js.map +1 -0
- package/configuration/types/renderOnlyDefault.d.ts +30 -0
- package/configuration/types/renderOnlyDefault.js +31 -0
- package/configuration/types/renderOnlyDefault.js.map +1 -0
- package/configuration/types/shadowLight.d.ts +9 -0
- package/configuration/types/shadowLight.js +64 -0
- package/configuration/types/shadowLight.js.map +1 -0
- package/helper/index.d.ts +29 -0
- package/helper/index.js +66 -0
- package/helper/index.js.map +1 -0
- package/index.d.ts +30 -0
- package/index.js +46 -0
- package/index.js.map +1 -0
- package/initializer.d.ts +11 -0
- package/initializer.js +35 -0
- package/initializer.js.map +1 -0
- package/interfaces.d.ts +5 -0
- package/interfaces.js +7 -0
- package/interfaces.js.map +1 -0
- package/labs/environmentSerializer.d.ts +126 -0
- package/labs/environmentSerializer.js +191 -0
- package/labs/environmentSerializer.js.map +1 -0
- package/labs/texture.d.ts +183 -0
- package/labs/texture.js +351 -0
- package/labs/texture.js.map +1 -0
- package/labs/viewerLabs.d.ts +51 -0
- package/labs/viewerLabs.js +134 -0
- package/labs/viewerLabs.js.map +1 -0
- package/loader/modelLoader.d.ts +56 -0
- package/loader/modelLoader.js +199 -0
- package/loader/modelLoader.js.map +1 -0
- package/loader/plugins/applyMaterialConfig.d.ts +12 -0
- package/loader/plugins/applyMaterialConfig.js +16 -0
- package/loader/plugins/applyMaterialConfig.js.map +1 -0
- package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -0
- package/loader/plugins/extendedMaterialLoaderPlugin.js +16 -0
- package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -0
- package/loader/plugins/index.d.ts +19 -0
- package/loader/plugins/index.js +44 -0
- package/loader/plugins/index.js.map +1 -0
- package/loader/plugins/loaderPlugin.d.ts +24 -0
- package/loader/plugins/loaderPlugin.js +2 -0
- package/loader/plugins/loaderPlugin.js.map +1 -0
- package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -0
- package/loader/plugins/msftLodLoaderPlugin.js +21 -0
- package/loader/plugins/msftLodLoaderPlugin.js.map +1 -0
- package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -0
- package/loader/plugins/telemetryLoaderPlugin.js +36 -0
- package/loader/plugins/telemetryLoaderPlugin.js.map +1 -0
- package/managers/observablesManager.d.ts +66 -0
- package/managers/observablesManager.js +35 -0
- package/managers/observablesManager.js.map +1 -0
- package/managers/sceneManager.d.ts +245 -0
- package/managers/sceneManager.js +1375 -0
- package/managers/sceneManager.js.map +1 -0
- package/managers/telemetryManager.d.ts +78 -0
- package/managers/telemetryManager.js +117 -0
- package/managers/telemetryManager.js.map +1 -0
- package/model/modelAnimation.d.ts +215 -0
- package/model/modelAnimation.js +237 -0
- package/model/modelAnimation.js.map +1 -0
- package/model/viewerModel.d.ts +233 -0
- package/model/viewerModel.js +673 -0
- package/model/viewerModel.js.map +1 -0
- package/optimizer/custom/extended.d.ts +13 -0
- package/optimizer/custom/extended.js +101 -0
- package/optimizer/custom/extended.js.map +1 -0
- package/optimizer/custom/index.d.ts +9 -0
- package/optimizer/custom/index.js +26 -0
- package/optimizer/custom/index.js.map +1 -0
- package/package.json +29 -16
- package/readme.md +21 -35
- package/renderOnlyIndex.d.ts +11 -0
- package/renderOnlyIndex.js +18 -0
- package/renderOnlyIndex.js.map +1 -0
- package/templating/eventManager.d.ts +35 -0
- package/templating/eventManager.js +66 -0
- package/templating/eventManager.js.map +1 -0
- package/templating/plugins/hdButtonPlugin.d.ts +9 -0
- package/templating/plugins/hdButtonPlugin.js +21 -0
- package/templating/plugins/hdButtonPlugin.js.map +1 -0
- package/templating/plugins/printButton.d.ts +9 -0
- package/templating/plugins/printButton.js +40 -0
- package/templating/plugins/printButton.js.map +1 -0
- package/templating/templateManager.d.ts +197 -0
- package/templating/templateManager.js +561 -0
- package/templating/templateManager.js.map +1 -0
- package/templating/viewerTemplatePlugin.d.ts +21 -0
- package/templating/viewerTemplatePlugin.js +69 -0
- package/templating/viewerTemplatePlugin.js.map +1 -0
- package/viewer/defaultViewer.d.ts +130 -0
- package/viewer/defaultViewer.js +675 -0
- package/viewer/defaultViewer.js.map +1 -0
- package/viewer/renderOnlyViewer.d.ts +9 -0
- package/viewer/renderOnlyViewer.js +46 -0
- package/viewer/renderOnlyViewer.js.map +1 -0
- package/viewer/viewer.d.ts +258 -0
- package/viewer/viewer.js +783 -0
- package/viewer/viewer.js.map +1 -0
- package/viewer/viewerManager.d.ts +58 -0
- package/viewer/viewerManager.js +91 -0
- package/viewer/viewerManager.js.map +1 -0
- package/viewer/viewerWithTemplate.d.ts +9 -0
- package/viewer/viewerWithTemplate.js +20 -0
- package/viewer/viewerWithTemplate.js.map +1 -0
- package/dist/babylon-viewer.esm.js +0 -114635
- package/dist/babylon-viewer.esm.js.map +0 -1
- package/dist/babylon-viewer.esm.min.js +0 -2
- package/dist/babylon-viewer.esm.min.js.map +0 -1
- package/lib/index.d.ts +0 -132
- package/lib/index.js +0 -369
- package/lib/index.js.map +0 -1
package/viewer/viewer.js
ADDED
|
@@ -0,0 +1,783 @@
|
|
|
1
|
+
import { Engine } from "@babylonjs/core/Engines/engine.js";
|
|
2
|
+
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
|
3
|
+
import { RenderingManager } from "@babylonjs/core/Rendering/renderingManager.js";
|
|
4
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
5
|
+
import { Effect } from "@babylonjs/core/Materials/effect.js";
|
|
6
|
+
import { processConfigurationCompatibility } from "../configuration/configurationCompatibility.js";
|
|
7
|
+
import { ConfigurationContainer } from "../configuration/configurationContainer.js";
|
|
8
|
+
import { viewerGlobals } from "../configuration/globals.js";
|
|
9
|
+
import { RenderOnlyConfigurationLoader } from "../configuration/renderOnlyLoader.js";
|
|
10
|
+
// eslint-disable-next-line import/no-internal-modules
|
|
11
|
+
import { deepmerge } from "../helper/index.js";
|
|
12
|
+
import { ModelLoader } from "../loader/modelLoader.js";
|
|
13
|
+
import { ObservablesManager } from "../managers/observablesManager.js";
|
|
14
|
+
import { SceneManager } from "../managers/sceneManager.js";
|
|
15
|
+
import { telemetryManager } from "../managers/telemetryManager.js";
|
|
16
|
+
import { viewerManager } from "./viewerManager.js";
|
|
17
|
+
import "@babylonjs/core/Misc/observable.extensions.js";
|
|
18
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
19
|
+
/**
|
|
20
|
+
* The AbstractViewer is the center of Babylon's viewer.
|
|
21
|
+
* It is the basic implementation of the default viewer and is responsible of loading and showing the model and the templates
|
|
22
|
+
*/
|
|
23
|
+
var AbstractViewer = /** @class */ (function () {
|
|
24
|
+
function AbstractViewer(containerElement, initialConfiguration) {
|
|
25
|
+
if (initialConfiguration === void 0) { initialConfiguration = {}; }
|
|
26
|
+
var _this = this;
|
|
27
|
+
this.containerElement = containerElement;
|
|
28
|
+
/**
|
|
29
|
+
* A flag that controls whether or not the render loop should be executed
|
|
30
|
+
*/
|
|
31
|
+
this.runRenderLoop = true;
|
|
32
|
+
/**
|
|
33
|
+
* is this viewer disposed?
|
|
34
|
+
*/
|
|
35
|
+
this._isDisposed = false;
|
|
36
|
+
this._hdToggled = false;
|
|
37
|
+
this._vrToggled = false;
|
|
38
|
+
this._vrModelRepositioning = 0;
|
|
39
|
+
this._vrScale = 1;
|
|
40
|
+
this._vrInit = false;
|
|
41
|
+
/**
|
|
42
|
+
* The resize function that will be registered with the window object
|
|
43
|
+
*/
|
|
44
|
+
this._resize = function () {
|
|
45
|
+
// Only resize if Canvas is in the DOM
|
|
46
|
+
if (!_this.isCanvasInDOM()) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (_this.canvas.clientWidth <= 0 || _this.canvas.clientHeight <= 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (_this.configuration.engine && _this.configuration.engine.disableResize) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
_this.engine.resize();
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* render loop that will be executed by the engine
|
|
59
|
+
* @param force
|
|
60
|
+
*/
|
|
61
|
+
this._render = function (force) {
|
|
62
|
+
if (force === void 0) { force = false; }
|
|
63
|
+
if (force || (_this.sceneManager.scene && _this.sceneManager.scene.activeCamera)) {
|
|
64
|
+
if (_this.runRenderLoop || force) {
|
|
65
|
+
_this.engine.performanceMonitor.enable();
|
|
66
|
+
_this.sceneManager.scene.render();
|
|
67
|
+
_this.onFrameRenderedObservable.notifyObservers(_this);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
_this.engine.performanceMonitor.disable();
|
|
71
|
+
// update camera instead of rendering
|
|
72
|
+
_this.sceneManager.scene.activeCamera && _this.sceneManager.scene.activeCamera.update();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// if exists, use the container id. otherwise, generate a random string.
|
|
77
|
+
if (containerElement.id) {
|
|
78
|
+
this.baseId = containerElement.id;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.baseId = containerElement.id = "bjs" + Math.random().toString(32).substr(2, 8);
|
|
82
|
+
}
|
|
83
|
+
this._registeredOnBeforeRenderFunctions = [];
|
|
84
|
+
this._configurationContainer = new ConfigurationContainer();
|
|
85
|
+
this.observablesManager = new ObservablesManager();
|
|
86
|
+
this.modelLoader = new ModelLoader(this.observablesManager, this._configurationContainer);
|
|
87
|
+
RenderingManager.AUTOCLEAR = false;
|
|
88
|
+
// extend the configuration
|
|
89
|
+
this._configurationLoader = this.getConfigurationLoader();
|
|
90
|
+
this._configurationLoader.loadConfiguration(initialConfiguration, function (configuration) {
|
|
91
|
+
_this._onConfigurationLoaded(configuration);
|
|
92
|
+
});
|
|
93
|
+
this.onSceneInitObservable.add(function () {
|
|
94
|
+
_this.updateConfiguration();
|
|
95
|
+
});
|
|
96
|
+
this.onInitDoneObservable.add(function () {
|
|
97
|
+
_this._isInit = true;
|
|
98
|
+
_this.engine.runRenderLoop(_this._render);
|
|
99
|
+
});
|
|
100
|
+
this._prepareContainerElement();
|
|
101
|
+
// add this viewer to the viewer manager
|
|
102
|
+
viewerManager.addViewer(this);
|
|
103
|
+
}
|
|
104
|
+
Object.defineProperty(AbstractViewer.prototype, "onSceneInitObservable", {
|
|
105
|
+
// observables
|
|
106
|
+
/**
|
|
107
|
+
* Will notify when the scene was initialized
|
|
108
|
+
*/
|
|
109
|
+
get: function () {
|
|
110
|
+
return this.observablesManager.onSceneInitObservable;
|
|
111
|
+
},
|
|
112
|
+
enumerable: false,
|
|
113
|
+
configurable: true
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(AbstractViewer.prototype, "onEngineInitObservable", {
|
|
116
|
+
/**
|
|
117
|
+
* will notify when the engine was initialized
|
|
118
|
+
*/
|
|
119
|
+
get: function () {
|
|
120
|
+
return this.observablesManager.onEngineInitObservable;
|
|
121
|
+
},
|
|
122
|
+
enumerable: false,
|
|
123
|
+
configurable: true
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(AbstractViewer.prototype, "onModelAddedObservable", {
|
|
126
|
+
/**
|
|
127
|
+
* Will notify when a new model was added to the scene.
|
|
128
|
+
* Note that added does not necessarily mean loaded!
|
|
129
|
+
*/
|
|
130
|
+
get: function () {
|
|
131
|
+
return this.observablesManager.onModelAddedObservable;
|
|
132
|
+
},
|
|
133
|
+
enumerable: false,
|
|
134
|
+
configurable: true
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(AbstractViewer.prototype, "onModelLoadedObservable", {
|
|
137
|
+
/**
|
|
138
|
+
* will notify after every model load
|
|
139
|
+
*/
|
|
140
|
+
get: function () {
|
|
141
|
+
return this.observablesManager.onModelLoadedObservable;
|
|
142
|
+
},
|
|
143
|
+
enumerable: false,
|
|
144
|
+
configurable: true
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(AbstractViewer.prototype, "onModelLoadProgressObservable", {
|
|
147
|
+
/**
|
|
148
|
+
* will notify when any model notify of progress
|
|
149
|
+
*/
|
|
150
|
+
get: function () {
|
|
151
|
+
return this.observablesManager.onModelLoadProgressObservable;
|
|
152
|
+
},
|
|
153
|
+
enumerable: false,
|
|
154
|
+
configurable: true
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(AbstractViewer.prototype, "onModelLoadErrorObservable", {
|
|
157
|
+
/**
|
|
158
|
+
* will notify when any model load failed.
|
|
159
|
+
*/
|
|
160
|
+
get: function () {
|
|
161
|
+
return this.observablesManager.onModelLoadErrorObservable;
|
|
162
|
+
},
|
|
163
|
+
enumerable: false,
|
|
164
|
+
configurable: true
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(AbstractViewer.prototype, "onModelRemovedObservable", {
|
|
167
|
+
/**
|
|
168
|
+
* Will notify when a model was removed from the scene;
|
|
169
|
+
*/
|
|
170
|
+
get: function () {
|
|
171
|
+
return this.observablesManager.onModelRemovedObservable;
|
|
172
|
+
},
|
|
173
|
+
enumerable: false,
|
|
174
|
+
configurable: true
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(AbstractViewer.prototype, "onLoaderInitObservable", {
|
|
177
|
+
/**
|
|
178
|
+
* will notify when a new loader was initialized.
|
|
179
|
+
* Used mainly to know when a model starts loading.
|
|
180
|
+
*/
|
|
181
|
+
get: function () {
|
|
182
|
+
return this.observablesManager.onLoaderInitObservable;
|
|
183
|
+
},
|
|
184
|
+
enumerable: false,
|
|
185
|
+
configurable: true
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(AbstractViewer.prototype, "onInitDoneObservable", {
|
|
188
|
+
/**
|
|
189
|
+
* Observers registered here will be executed when the entire load process has finished.
|
|
190
|
+
*/
|
|
191
|
+
get: function () {
|
|
192
|
+
return this.observablesManager.onViewerInitDoneObservable;
|
|
193
|
+
},
|
|
194
|
+
enumerable: false,
|
|
195
|
+
configurable: true
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(AbstractViewer.prototype, "onFrameRenderedObservable", {
|
|
198
|
+
/**
|
|
199
|
+
* Functions added to this observable will be executed on each frame rendered.
|
|
200
|
+
*/
|
|
201
|
+
get: function () {
|
|
202
|
+
return this.observablesManager.onFrameRenderedObservable;
|
|
203
|
+
},
|
|
204
|
+
enumerable: false,
|
|
205
|
+
configurable: true
|
|
206
|
+
});
|
|
207
|
+
Object.defineProperty(AbstractViewer.prototype, "onEnteringVRObservable", {
|
|
208
|
+
/**
|
|
209
|
+
* Observers registered here will be executed when VR more is entered.
|
|
210
|
+
*/
|
|
211
|
+
get: function () {
|
|
212
|
+
return this.observablesManager.onEnteringVRObservable;
|
|
213
|
+
},
|
|
214
|
+
enumerable: false,
|
|
215
|
+
configurable: true
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(AbstractViewer.prototype, "onExitingVRObservable", {
|
|
218
|
+
/**
|
|
219
|
+
* Observers registered here will be executed when VR mode is exited.
|
|
220
|
+
*/
|
|
221
|
+
get: function () {
|
|
222
|
+
return this.observablesManager.onExitingVRObservable;
|
|
223
|
+
},
|
|
224
|
+
enumerable: false,
|
|
225
|
+
configurable: true
|
|
226
|
+
});
|
|
227
|
+
Object.defineProperty(AbstractViewer.prototype, "canvas", {
|
|
228
|
+
/**
|
|
229
|
+
* The (single) canvas of this viewer
|
|
230
|
+
*/
|
|
231
|
+
get: function () {
|
|
232
|
+
return this._canvas;
|
|
233
|
+
},
|
|
234
|
+
enumerable: false,
|
|
235
|
+
configurable: true
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(AbstractViewer.prototype, "configurationContainer", {
|
|
238
|
+
get: function () {
|
|
239
|
+
return this._configurationContainer;
|
|
240
|
+
},
|
|
241
|
+
enumerable: false,
|
|
242
|
+
configurable: true
|
|
243
|
+
});
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
245
|
+
AbstractViewer.prototype.getConfigurationLoader = function () {
|
|
246
|
+
return new RenderOnlyConfigurationLoader();
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* get the baseId of this viewer
|
|
250
|
+
* @returns the baseId of this viewer
|
|
251
|
+
*/
|
|
252
|
+
AbstractViewer.prototype.getBaseId = function () {
|
|
253
|
+
return this.baseId;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Do we have a canvas to render on, and is it a part of the scene
|
|
257
|
+
* @returns true if the canvas is in the DOM
|
|
258
|
+
*/
|
|
259
|
+
AbstractViewer.prototype.isCanvasInDOM = function () {
|
|
260
|
+
return !!this._canvas && !!this._canvas.parentElement;
|
|
261
|
+
};
|
|
262
|
+
Object.defineProperty(AbstractViewer.prototype, "renderInBackground", {
|
|
263
|
+
/**
|
|
264
|
+
* Is the engine currently set to render even when the page is in background
|
|
265
|
+
*/
|
|
266
|
+
get: function () {
|
|
267
|
+
return this.engine && this.engine.renderEvenInBackground;
|
|
268
|
+
},
|
|
269
|
+
/**
|
|
270
|
+
* Set the viewer's background rendering flag.
|
|
271
|
+
*/
|
|
272
|
+
set: function (value) {
|
|
273
|
+
if (this.engine) {
|
|
274
|
+
this.engine.renderEvenInBackground = value;
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
enumerable: false,
|
|
278
|
+
configurable: true
|
|
279
|
+
});
|
|
280
|
+
Object.defineProperty(AbstractViewer.prototype, "configuration", {
|
|
281
|
+
/**
|
|
282
|
+
* Get the configuration object. This is a reference only.
|
|
283
|
+
* The configuration can ONLY be updated using the updateConfiguration function.
|
|
284
|
+
* changing this object will have no direct effect on the scene.
|
|
285
|
+
*/
|
|
286
|
+
get: function () {
|
|
287
|
+
return this._configurationContainer.configuration;
|
|
288
|
+
},
|
|
289
|
+
enumerable: false,
|
|
290
|
+
configurable: true
|
|
291
|
+
});
|
|
292
|
+
/**
|
|
293
|
+
* force resizing the engine.
|
|
294
|
+
*/
|
|
295
|
+
AbstractViewer.prototype.forceResize = function () {
|
|
296
|
+
this._resize();
|
|
297
|
+
};
|
|
298
|
+
AbstractViewer.prototype.toggleHD = function () {
|
|
299
|
+
this._hdToggled = !this._hdToggled;
|
|
300
|
+
var scale = this._hdToggled ? Math.max(0.5, 1 / (window.devicePixelRatio || 2)) : 1;
|
|
301
|
+
this.engine.setHardwareScalingLevel(scale);
|
|
302
|
+
};
|
|
303
|
+
AbstractViewer.prototype.toggleVR = function () {
|
|
304
|
+
if (!this._vrInit) {
|
|
305
|
+
this._initVR();
|
|
306
|
+
}
|
|
307
|
+
if (this.sceneManager.vrHelper && !this.sceneManager.vrHelper.isInVRMode) {
|
|
308
|
+
// make sure the floor is set
|
|
309
|
+
if (this.sceneManager.environmentHelper && this.sceneManager.environmentHelper.ground) {
|
|
310
|
+
this.sceneManager.vrHelper.addFloorMesh(this.sceneManager.environmentHelper.ground);
|
|
311
|
+
}
|
|
312
|
+
this._vrToggled = true;
|
|
313
|
+
this.sceneManager.vrHelper.enterVR();
|
|
314
|
+
// position the vr camera to be in front of the object or wherever the user has configured it to be
|
|
315
|
+
if (this.sceneManager.vrHelper.currentVRCamera && this.sceneManager.vrHelper.currentVRCamera !== this.sceneManager.camera) {
|
|
316
|
+
if (this.configuration.vr && this.configuration.vr.cameraPosition !== undefined) {
|
|
317
|
+
this.sceneManager.vrHelper.currentVRCamera.position.copyFromFloats(this.configuration.vr.cameraPosition.x, this.configuration.vr.cameraPosition.y, this.configuration.vr.cameraPosition.z);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
this.sceneManager.vrHelper.currentVRCamera.position.copyFromFloats(0, this.sceneManager.vrHelper.currentVRCamera.position.y, -1);
|
|
321
|
+
}
|
|
322
|
+
this.sceneManager.vrHelper.currentVRCamera.rotationQuaternion &&
|
|
323
|
+
this.sceneManager.vrHelper.currentVRCamera.rotationQuaternion.copyFromFloats(0, 0, 0, 1);
|
|
324
|
+
// set the height of the model to be what the user has configured, or floating by default
|
|
325
|
+
if (this.configuration.vr && this.configuration.vr.modelHeightCorrection !== undefined) {
|
|
326
|
+
if (typeof this.configuration.vr.modelHeightCorrection === "number") {
|
|
327
|
+
this._vrModelRepositioning = this.configuration.vr.modelHeightCorrection;
|
|
328
|
+
}
|
|
329
|
+
else if (this.configuration.vr.modelHeightCorrection) {
|
|
330
|
+
this._vrModelRepositioning = this.sceneManager.vrHelper.currentVRCamera.position.y / 2;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
this._vrModelRepositioning = 0;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// scale the model
|
|
337
|
+
if (this.sceneManager.models.length) {
|
|
338
|
+
var boundingVectors = this.sceneManager.models[0].rootMesh.getHierarchyBoundingVectors();
|
|
339
|
+
var sizeVec = boundingVectors.max.subtract(boundingVectors.min);
|
|
340
|
+
var maxDimension = Math.max(sizeVec.x, sizeVec.y, sizeVec.z);
|
|
341
|
+
this._vrScale = 1 / maxDimension;
|
|
342
|
+
if (this.configuration.vr && this.configuration.vr.objectScaleFactor) {
|
|
343
|
+
this._vrScale *= this.configuration.vr.objectScaleFactor;
|
|
344
|
+
}
|
|
345
|
+
this.sceneManager.models[0].rootMesh.scaling.scaleInPlace(this._vrScale);
|
|
346
|
+
// reposition the object to "float" in front of the user
|
|
347
|
+
this.sceneManager.models[0].rootMesh.position.y += this._vrModelRepositioning;
|
|
348
|
+
this.sceneManager.models[0].rootMesh.rotationQuaternion = null;
|
|
349
|
+
}
|
|
350
|
+
// scale the environment to match the model
|
|
351
|
+
if (this.sceneManager.environmentHelper) {
|
|
352
|
+
this.sceneManager.environmentHelper.ground && this.sceneManager.environmentHelper.ground.scaling.scaleInPlace(this._vrScale);
|
|
353
|
+
this.sceneManager.environmentHelper.skybox && this.sceneManager.environmentHelper.skybox.scaling.scaleInPlace(this._vrScale);
|
|
354
|
+
}
|
|
355
|
+
// post processing
|
|
356
|
+
if (this.sceneManager.defaultRenderingPipelineEnabled && this.sceneManager.defaultRenderingPipeline) {
|
|
357
|
+
this.sceneManager.defaultRenderingPipeline.imageProcessingEnabled = false;
|
|
358
|
+
this.sceneManager.defaultRenderingPipeline.prepare();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
this._vrModelRepositioning = 0;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
if (this.sceneManager.vrHelper) {
|
|
367
|
+
this.sceneManager.vrHelper.exitVR();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
AbstractViewer.prototype._initVR = function () {
|
|
372
|
+
var _this = this;
|
|
373
|
+
if (this.sceneManager.vrHelper) {
|
|
374
|
+
this.observablesManager.onExitingVRObservable.add(function () {
|
|
375
|
+
if (_this._vrToggled) {
|
|
376
|
+
_this._vrToggled = false;
|
|
377
|
+
// undo the scaling of the model
|
|
378
|
+
if (_this.sceneManager.models.length) {
|
|
379
|
+
_this.sceneManager.models[0].rootMesh.scaling.scaleInPlace(1 / _this._vrScale);
|
|
380
|
+
_this.sceneManager.models[0].rootMesh.position.y -= _this._vrModelRepositioning;
|
|
381
|
+
}
|
|
382
|
+
// undo the scaling of the environment
|
|
383
|
+
if (_this.sceneManager.environmentHelper) {
|
|
384
|
+
_this.sceneManager.environmentHelper.ground && _this.sceneManager.environmentHelper.ground.scaling.scaleInPlace(1 / _this._vrScale);
|
|
385
|
+
_this.sceneManager.environmentHelper.skybox && _this.sceneManager.environmentHelper.skybox.scaling.scaleInPlace(1 / _this._vrScale);
|
|
386
|
+
}
|
|
387
|
+
// post processing
|
|
388
|
+
if (_this.sceneManager.defaultRenderingPipelineEnabled && _this.sceneManager.defaultRenderingPipeline) {
|
|
389
|
+
_this.sceneManager.defaultRenderingPipeline.imageProcessingEnabled = true;
|
|
390
|
+
_this.sceneManager.defaultRenderingPipeline.prepare();
|
|
391
|
+
}
|
|
392
|
+
// clear set height and width
|
|
393
|
+
_this.canvas.removeAttribute("height");
|
|
394
|
+
_this.canvas.removeAttribute("width");
|
|
395
|
+
_this.engine.resize();
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
this._vrInit = true;
|
|
400
|
+
};
|
|
401
|
+
AbstractViewer.prototype._onConfigurationLoaded = function (configuration) {
|
|
402
|
+
var _this = this;
|
|
403
|
+
this._configurationContainer.configuration = deepmerge(this.configuration || {}, configuration);
|
|
404
|
+
if (this.configuration.observers) {
|
|
405
|
+
this._configureObservers(this.configuration.observers);
|
|
406
|
+
}
|
|
407
|
+
// TODO remove this after testing, as this is done in the updateConfiguration as well.
|
|
408
|
+
if (this.configuration.loaderPlugins) {
|
|
409
|
+
Object.keys(this.configuration.loaderPlugins).forEach(function (name) {
|
|
410
|
+
if (_this.configuration.loaderPlugins && _this.configuration.loaderPlugins[name]) {
|
|
411
|
+
_this.modelLoader.addPlugin(name);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
this.observablesManager.onViewerInitStartedObservable.notifyObservers(this);
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* Force a single render loop execution.
|
|
419
|
+
*/
|
|
420
|
+
AbstractViewer.prototype.forceRender = function () {
|
|
421
|
+
this._render(true);
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Takes a screenshot of the scene and returns it as a base64 encoded png.
|
|
425
|
+
* @param callback optional callback that will be triggered when screenshot is done.
|
|
426
|
+
* @param width Optional screenshot width (default to 512).
|
|
427
|
+
* @param height Optional screenshot height (default to 512).
|
|
428
|
+
* @returns a promise with the screenshot data
|
|
429
|
+
*/
|
|
430
|
+
AbstractViewer.prototype.takeScreenshot = function (callback, width, height) {
|
|
431
|
+
var _this = this;
|
|
432
|
+
if (width === void 0) { width = 0; }
|
|
433
|
+
if (height === void 0) { height = 0; }
|
|
434
|
+
width = width || this.canvas.clientWidth;
|
|
435
|
+
height = height || this.canvas.clientHeight;
|
|
436
|
+
// Create the screenshot
|
|
437
|
+
return new Promise(function (resolve, reject) {
|
|
438
|
+
try {
|
|
439
|
+
Tools.CreateScreenshot(_this.engine, _this.sceneManager.camera, { width: width, height: height }, function (data) {
|
|
440
|
+
if (callback) {
|
|
441
|
+
callback(data);
|
|
442
|
+
}
|
|
443
|
+
resolve(data);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
catch (e) {
|
|
447
|
+
reject(e);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Update the current viewer configuration with new values.
|
|
453
|
+
* Only provided information will be updated, old configuration values will be kept.
|
|
454
|
+
* If this.configuration was manually changed, you can trigger this function with no parameters,
|
|
455
|
+
* and the entire configuration will be updated.
|
|
456
|
+
* @param newConfiguration the partial configuration to update or a URL to a JSON holding the updated configuration
|
|
457
|
+
*
|
|
458
|
+
*/
|
|
459
|
+
AbstractViewer.prototype.updateConfiguration = function (newConfiguration) {
|
|
460
|
+
var _this = this;
|
|
461
|
+
if (newConfiguration === void 0) { newConfiguration = this.configuration; }
|
|
462
|
+
if (typeof newConfiguration === "string") {
|
|
463
|
+
Tools.LoadFile(newConfiguration, function (data) {
|
|
464
|
+
try {
|
|
465
|
+
var newData = JSON.parse(data.toString());
|
|
466
|
+
return _this.updateConfiguration(newData);
|
|
467
|
+
}
|
|
468
|
+
catch (e) {
|
|
469
|
+
Logger.Log("Error parsing file " + newConfiguration);
|
|
470
|
+
}
|
|
471
|
+
}, undefined, undefined, undefined, function (error) {
|
|
472
|
+
Logger.Log(["Error parsing file " + newConfiguration, error]);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
//backcompat
|
|
477
|
+
processConfigurationCompatibility(newConfiguration);
|
|
478
|
+
// update this.configuration with the new data
|
|
479
|
+
this._configurationContainer.configuration = deepmerge(this.configuration || {}, newConfiguration);
|
|
480
|
+
this.sceneManager.updateConfiguration(newConfiguration);
|
|
481
|
+
// observers in configuration
|
|
482
|
+
if (newConfiguration.observers) {
|
|
483
|
+
this._configureObservers(newConfiguration.observers);
|
|
484
|
+
}
|
|
485
|
+
if (newConfiguration.loaderPlugins) {
|
|
486
|
+
Object.keys(newConfiguration.loaderPlugins).forEach(function (name) {
|
|
487
|
+
if (newConfiguration.loaderPlugins && newConfiguration.loaderPlugins[name]) {
|
|
488
|
+
_this.modelLoader.addPlugin(name);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* this is used to register native functions using the configuration object.
|
|
496
|
+
* This will configure the observers.
|
|
497
|
+
* @param observersConfiguration observers configuration
|
|
498
|
+
*/
|
|
499
|
+
AbstractViewer.prototype._configureObservers = function (observersConfiguration) {
|
|
500
|
+
if (observersConfiguration.onEngineInit) {
|
|
501
|
+
this.onEngineInitObservable.add(window[observersConfiguration.onEngineInit]);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
if (observersConfiguration.onEngineInit === "" && this.configuration.observers && this.configuration.observers.onEngineInit) {
|
|
505
|
+
this.onEngineInitObservable.removeCallback(window[this.configuration.observers.onEngineInit]);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (observersConfiguration.onSceneInit) {
|
|
509
|
+
this.onSceneInitObservable.add(window[observersConfiguration.onSceneInit]);
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
if (observersConfiguration.onSceneInit === "" && this.configuration.observers && this.configuration.observers.onSceneInit) {
|
|
513
|
+
this.onSceneInitObservable.removeCallback(window[this.configuration.observers.onSceneInit]);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (observersConfiguration.onModelLoaded) {
|
|
517
|
+
this.onModelLoadedObservable.add(window[observersConfiguration.onModelLoaded]);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
if (observersConfiguration.onModelLoaded === "" && this.configuration.observers && this.configuration.observers.onModelLoaded) {
|
|
521
|
+
this.onModelLoadedObservable.removeCallback(window[this.configuration.observers.onModelLoaded]);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* Dispose the entire viewer including the scene and the engine
|
|
527
|
+
*/
|
|
528
|
+
AbstractViewer.prototype.dispose = function () {
|
|
529
|
+
if (this._isDisposed) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
window.removeEventListener("resize", this._resize);
|
|
533
|
+
if (this.sceneManager) {
|
|
534
|
+
if (this.sceneManager.scene && this.sceneManager.scene.activeCamera) {
|
|
535
|
+
this.sceneManager.scene.activeCamera.detachControl();
|
|
536
|
+
}
|
|
537
|
+
this.sceneManager.dispose();
|
|
538
|
+
}
|
|
539
|
+
this._fpsTimeoutInterval && clearInterval(this._fpsTimeoutInterval);
|
|
540
|
+
this.observablesManager.dispose();
|
|
541
|
+
this.modelLoader.dispose();
|
|
542
|
+
if (this.engine) {
|
|
543
|
+
this.engine.dispose();
|
|
544
|
+
}
|
|
545
|
+
viewerManager.removeViewer(this);
|
|
546
|
+
this._isDisposed = true;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* This function will execute when the HTML templates finished initializing.
|
|
550
|
+
* It should initialize the engine and continue execution.
|
|
551
|
+
*
|
|
552
|
+
* @returns The viewer object will be returned after the object was loaded.
|
|
553
|
+
*/
|
|
554
|
+
AbstractViewer.prototype._onTemplatesLoaded = function () {
|
|
555
|
+
return Promise.resolve(this);
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* This will force the creation of an engine and a scene.
|
|
559
|
+
* It will also load a model if preconfigured.
|
|
560
|
+
* But first - it will load the extendible onTemplateLoaded()!
|
|
561
|
+
* @returns A promise that will resolve when the template was loaded
|
|
562
|
+
*/
|
|
563
|
+
AbstractViewer.prototype._onTemplateLoaded = function () {
|
|
564
|
+
var _this = this;
|
|
565
|
+
// check if viewer was disposed right after created
|
|
566
|
+
if (this._isDisposed) {
|
|
567
|
+
return Promise.reject("viewer was disposed");
|
|
568
|
+
}
|
|
569
|
+
return this._onTemplatesLoaded().then(function () {
|
|
570
|
+
var autoLoad = typeof _this.configuration.model === "string" || (_this.configuration.model && _this.configuration.model.url);
|
|
571
|
+
return _this._initEngine()
|
|
572
|
+
.then(function (engine) {
|
|
573
|
+
return _this.onEngineInitObservable.notifyObserversWithPromise(engine);
|
|
574
|
+
})
|
|
575
|
+
.then(function () {
|
|
576
|
+
_this._initTelemetryEvents();
|
|
577
|
+
if (autoLoad) {
|
|
578
|
+
return _this.loadModel(_this.configuration.model)
|
|
579
|
+
.catch(function () { })
|
|
580
|
+
.then(function () {
|
|
581
|
+
return _this.sceneManager.scene;
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
return _this.sceneManager.scene || _this.sceneManager.initScene(_this.configuration.scene);
|
|
586
|
+
}
|
|
587
|
+
})
|
|
588
|
+
.then(function () {
|
|
589
|
+
return _this.onInitDoneObservable.notifyObserversWithPromise(_this);
|
|
590
|
+
})
|
|
591
|
+
.catch(function (e) {
|
|
592
|
+
Tools.Warn(e.toString());
|
|
593
|
+
return _this;
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
/**
|
|
598
|
+
* Initialize the engine. Returns a promise in case async calls are needed.
|
|
599
|
+
*
|
|
600
|
+
* @protected
|
|
601
|
+
* @returns {Promise<Engine>}
|
|
602
|
+
* @memberof Viewer
|
|
603
|
+
*/
|
|
604
|
+
AbstractViewer.prototype._initEngine = function () {
|
|
605
|
+
// init custom shaders
|
|
606
|
+
this._injectCustomShaders();
|
|
607
|
+
//let canvasElement = this.templateManager.getCanvas();
|
|
608
|
+
if (!this.canvas) {
|
|
609
|
+
return Promise.reject("Canvas element not found!");
|
|
610
|
+
}
|
|
611
|
+
var config = this.configuration.engine || {};
|
|
612
|
+
// TDO enable further configuration
|
|
613
|
+
// check for webgl2 support, force-disable if needed.
|
|
614
|
+
if (viewerGlobals.disableWebGL2Support) {
|
|
615
|
+
config.engineOptions = config.engineOptions || {};
|
|
616
|
+
config.engineOptions.disableWebGL2Support = true;
|
|
617
|
+
}
|
|
618
|
+
if (this.configuration["3dCommerceCertified"]) {
|
|
619
|
+
config.engineOptions = config.engineOptions || {};
|
|
620
|
+
config.engineOptions.forceSRGBBufferSupportState = true;
|
|
621
|
+
var loader = SceneLoader.GetPluginForExtension(".gltf");
|
|
622
|
+
if (loader) {
|
|
623
|
+
loader.transparencyAsCoverage = true;
|
|
624
|
+
}
|
|
625
|
+
SceneLoader.OnPluginActivatedObservable.add(function (plugin) {
|
|
626
|
+
if (plugin.name === "gltf") {
|
|
627
|
+
var loader_1 = plugin;
|
|
628
|
+
loader_1.transparencyAsCoverage = true;
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
this.engine = new Engine(this.canvas, !!config.antialiasing, config.engineOptions);
|
|
633
|
+
if (!config.disableResize) {
|
|
634
|
+
window.addEventListener("resize", this._resize);
|
|
635
|
+
}
|
|
636
|
+
if (this.configuration.engine) {
|
|
637
|
+
if (this.configuration.engine.adaptiveQuality) {
|
|
638
|
+
var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
|
|
639
|
+
this.engine.setHardwareScalingLevel(scale);
|
|
640
|
+
}
|
|
641
|
+
if (this.configuration.engine.hdEnabled) {
|
|
642
|
+
this.toggleHD();
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
// create a new template manager for this viewer
|
|
646
|
+
this.sceneManager = new SceneManager(this.engine, this._configurationContainer, this.observablesManager);
|
|
647
|
+
return Promise.resolve(this.engine);
|
|
648
|
+
};
|
|
649
|
+
/**
|
|
650
|
+
* Initialize a model loading. The returned object (a ViewerModel object) will be loaded in the background.
|
|
651
|
+
* The difference between this and loadModel is that loadModel will fulfill the promise when the model finished loading.
|
|
652
|
+
*
|
|
653
|
+
* @param modelConfig model configuration to use when loading the model.
|
|
654
|
+
* @param clearScene should the scene be cleared before loading this model
|
|
655
|
+
* @returns a ViewerModel object that is not yet fully loaded.
|
|
656
|
+
*/
|
|
657
|
+
AbstractViewer.prototype.initModel = function (modelConfig, clearScene) {
|
|
658
|
+
var _this = this;
|
|
659
|
+
if (clearScene === void 0) { clearScene = true; }
|
|
660
|
+
var configuration;
|
|
661
|
+
if (typeof modelConfig === "string") {
|
|
662
|
+
configuration = {
|
|
663
|
+
url: modelConfig,
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
else if (modelConfig instanceof File) {
|
|
667
|
+
configuration = {
|
|
668
|
+
file: modelConfig,
|
|
669
|
+
root: "file:",
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
configuration = modelConfig;
|
|
674
|
+
}
|
|
675
|
+
if (!configuration.url && !configuration.file) {
|
|
676
|
+
throw new Error("no model provided");
|
|
677
|
+
}
|
|
678
|
+
if (clearScene) {
|
|
679
|
+
this.sceneManager.clearScene(true, false);
|
|
680
|
+
}
|
|
681
|
+
//merge the configuration for future models:
|
|
682
|
+
if (this.configuration.model && typeof this.configuration.model === "object") {
|
|
683
|
+
var globalConfig = deepmerge({}, this.configuration.model);
|
|
684
|
+
configuration = deepmerge(globalConfig, configuration);
|
|
685
|
+
if (modelConfig instanceof File) {
|
|
686
|
+
configuration.file = modelConfig;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
this.configuration.model = configuration;
|
|
691
|
+
}
|
|
692
|
+
this._isLoading = true;
|
|
693
|
+
var model = this.modelLoader.load(configuration);
|
|
694
|
+
this.lastUsedLoader = model.loader;
|
|
695
|
+
model.onLoadErrorObservable.add(function (errorObject) {
|
|
696
|
+
_this.onModelLoadErrorObservable.notifyObserversWithPromise(errorObject);
|
|
697
|
+
});
|
|
698
|
+
model.onLoadProgressObservable.add(function (progressEvent) {
|
|
699
|
+
_this.onModelLoadProgressObservable.notifyObserversWithPromise(progressEvent);
|
|
700
|
+
});
|
|
701
|
+
this.onLoaderInitObservable.notifyObserversWithPromise(this.lastUsedLoader);
|
|
702
|
+
model.onLoadedObservable.add(function () {
|
|
703
|
+
_this._isLoading = false;
|
|
704
|
+
});
|
|
705
|
+
return model;
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* load a model using the provided configuration.
|
|
709
|
+
* This function, as opposed to initModel, will return a promise that resolves when the model is loaded, and rejects with error.
|
|
710
|
+
* If you want to attach to the observables of the model, use initModel instead.
|
|
711
|
+
*
|
|
712
|
+
* @param modelConfig the model configuration or URL to load.
|
|
713
|
+
* @param clearScene Should the scene be cleared before loading the model
|
|
714
|
+
* @returns a Promise the fulfills when the model finished loading successfully.
|
|
715
|
+
*/
|
|
716
|
+
AbstractViewer.prototype.loadModel = function (modelConfig, clearScene) {
|
|
717
|
+
var _this = this;
|
|
718
|
+
if (clearScene === void 0) { clearScene = true; }
|
|
719
|
+
if (this._isLoading) {
|
|
720
|
+
// We can decide here whether or not to cancel the lst load, but the developer can do that.
|
|
721
|
+
return Promise.reject("another model is curently being loaded.");
|
|
722
|
+
}
|
|
723
|
+
return Promise.resolve(this.sceneManager.scene)
|
|
724
|
+
.then(function (scene) {
|
|
725
|
+
if (!scene) {
|
|
726
|
+
return _this.sceneManager.initScene(_this.configuration.scene);
|
|
727
|
+
}
|
|
728
|
+
return scene;
|
|
729
|
+
})
|
|
730
|
+
.then(function () {
|
|
731
|
+
var model = _this.initModel(modelConfig, clearScene);
|
|
732
|
+
return new Promise(function (resolve, reject) {
|
|
733
|
+
// at this point, configuration.model is an object, not a string
|
|
734
|
+
model.onLoadedObservable.add(function () {
|
|
735
|
+
resolve(model);
|
|
736
|
+
});
|
|
737
|
+
model.onLoadErrorObservable.add(function (error) {
|
|
738
|
+
reject(error);
|
|
739
|
+
});
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
AbstractViewer.prototype._initTelemetryEvents = function () {
|
|
744
|
+
var _this = this;
|
|
745
|
+
telemetryManager.broadcast("Engine Capabilities", this.baseId, this.engine.getCaps());
|
|
746
|
+
telemetryManager.broadcast("Platform Details", this.baseId, {
|
|
747
|
+
userAgent: navigator.userAgent,
|
|
748
|
+
platform: navigator.platform,
|
|
749
|
+
});
|
|
750
|
+
telemetryManager.flushWebGLErrors(this.engine, this.baseId);
|
|
751
|
+
var trackFPS = function () {
|
|
752
|
+
telemetryManager.broadcast("Current FPS", _this.baseId, { fps: _this.engine.getFps() });
|
|
753
|
+
};
|
|
754
|
+
trackFPS();
|
|
755
|
+
// Track the FPS again after 60 seconds
|
|
756
|
+
this._fpsTimeoutInterval = window.setInterval(trackFPS, 60 * 1000);
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* Injects all the spectre shader in the babylon shader store
|
|
760
|
+
*/
|
|
761
|
+
AbstractViewer.prototype._injectCustomShaders = function () {
|
|
762
|
+
var customShaders = this.configuration.customShaders;
|
|
763
|
+
// Inject all the spectre shader in the babylon shader store.
|
|
764
|
+
if (!customShaders) {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (customShaders.shaders) {
|
|
768
|
+
Object.keys(customShaders.shaders).forEach(function (key) {
|
|
769
|
+
// typescript considers a callback "unsafe", so... '!'
|
|
770
|
+
Effect.ShadersStore[key] = customShaders.shaders[key];
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
if (customShaders.includes) {
|
|
774
|
+
Object.keys(customShaders.includes).forEach(function (key) {
|
|
775
|
+
// typescript considers a callback "unsafe", so... '!'
|
|
776
|
+
Effect.IncludesShadersStore[key] = customShaders.includes[key];
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
return AbstractViewer;
|
|
781
|
+
}());
|
|
782
|
+
export { AbstractViewer };
|
|
783
|
+
//# sourceMappingURL=viewer.js.map
|