@combeenation/3d-viewer 5.0.1 → 5.0.3-beta2

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 (109) hide show
  1. package/README.md +111 -114
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +187 -187
  6. package/dist/lib-cjs/api/classes/element.d.ts +139 -139
  7. package/dist/lib-cjs/api/classes/element.js +794 -794
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -0
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +135 -0
  11. package/dist/lib-cjs/api/classes/elementParameterizable.js.map +1 -0
  12. package/dist/lib-cjs/api/classes/event.d.ts +326 -326
  13. package/dist/lib-cjs/api/classes/event.js +371 -371
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  15. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +316 -259
  17. package/dist/lib-cjs/api/classes/parameter.js +451 -388
  18. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  20. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -101
  21. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  22. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  23. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +44 -44
  24. package/dist/lib-cjs/api/classes/placementAnimation.js +163 -163
  25. package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
  26. package/dist/lib-cjs/api/classes/variant.js +1154 -1154
  27. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
  28. package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
  29. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  30. package/dist/lib-cjs/api/classes/variantParameterizable.js +99 -99
  31. package/dist/lib-cjs/api/classes/viewer.d.ts +177 -175
  32. package/dist/lib-cjs/api/classes/viewer.js +717 -701
  33. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  34. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  35. package/dist/lib-cjs/api/classes/viewerLight.js +392 -392
  36. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  37. package/dist/lib-cjs/api/internal/debugViewer.js +86 -86
  38. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  39. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  40. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -10
  41. package/dist/lib-cjs/api/internal/sceneSetup.js +238 -234
  42. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  43. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  44. package/dist/lib-cjs/api/manager/animationManager.js +130 -130
  45. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
  46. package/dist/lib-cjs/api/manager/gltfExportManager.js +223 -222
  47. package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -32
  49. package/dist/lib-cjs/api/manager/sceneManager.js +153 -132
  50. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  51. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.js +335 -335
  53. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  54. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  55. package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -166
  56. package/dist/lib-cjs/api/util/babylonHelper.js +575 -497
  57. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  58. package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -356
  59. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  60. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -53
  61. package/dist/lib-cjs/api/util/resourceHelper.js +257 -242
  62. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  63. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  64. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  65. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  66. package/dist/lib-cjs/api/util/structureHelper.js +48 -44
  67. package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
  68. package/dist/lib-cjs/buildinfo.json +3 -3
  69. package/dist/lib-cjs/index.d.ts +49 -49
  70. package/dist/lib-cjs/index.js +89 -89
  71. package/dist/webpack-stats.json +0 -0
  72. package/package.json +87 -87
  73. package/src/api/classes/animationInterface.ts +10 -10
  74. package/src/api/classes/dottedPath.ts +181 -181
  75. package/src/api/classes/element.ts +690 -692
  76. package/src/api/classes/event.ts +367 -367
  77. package/src/api/classes/eventBroadcaster.ts +52 -52
  78. package/src/api/classes/parameter.ts +474 -405
  79. package/src/api/classes/parameterObservable.ts +100 -100
  80. package/src/api/classes/parameterizable.ts +87 -87
  81. package/src/api/classes/placementAnimation.ts +160 -160
  82. package/src/api/classes/variant.ts +845 -845
  83. package/src/api/classes/variantInstance.ts +97 -97
  84. package/src/api/classes/variantParameterizable.ts +85 -85
  85. package/src/api/classes/viewer.ts +650 -624
  86. package/src/api/classes/viewerLight.ts +334 -334
  87. package/src/api/internal/debugViewer.ts +90 -90
  88. package/src/api/internal/lensRendering.ts +10 -10
  89. package/src/api/internal/sceneSetup.ts +204 -201
  90. package/src/api/manager/animationManager.ts +142 -142
  91. package/src/api/manager/gltfExportManager.ts +191 -191
  92. package/src/api/manager/sceneManager.ts +128 -102
  93. package/src/api/manager/variantInstanceManager.ts +265 -265
  94. package/src/api/store/specStorage.ts +51 -51
  95. package/src/api/util/babylonHelper.ts +628 -538
  96. package/src/api/util/globalTypes.ts +413 -402
  97. package/src/api/util/resourceHelper.ts +189 -173
  98. package/src/api/util/stringHelper.ts +23 -23
  99. package/src/api/util/structureHelper.ts +49 -43
  100. package/src/buildinfo.json +3 -3
  101. package/src/commonjs.tsconfig.json +10 -10
  102. package/src/declaration.tsconfig.json +8 -8
  103. package/src/dev.ts +42 -42
  104. package/src/es6.tsconfig.json +10 -10
  105. package/src/index.ts +94 -94
  106. package/src/pagesconfig.json +77 -73
  107. package/src/tsconfig.json +32 -32
  108. package/src/tsconfig.types.json +9 -9
  109. package/src/types.d.ts +3 -3
@@ -1,702 +1,718 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Viewer = void 0;
4
- var tslib_1 = require("tslib");
5
- var arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
6
- var boundingInfo_1 = require("@babylonjs/core/Culling/boundingInfo");
7
- var engine_1 = require("@babylonjs/core/Engines/engine");
8
- var highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
9
- var standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
10
- var dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
11
- var math_color_1 = require("@babylonjs/core/Maths/math.color");
12
- var math_vector_1 = require("@babylonjs/core/Maths/math.vector");
13
- var mesh_1 = require("@babylonjs/core/Meshes/mesh");
14
- var screenshotTools_1 = require("@babylonjs/core/Misc/screenshotTools");
15
- var webXRSessionManager_1 = require("@babylonjs/core/XR/webXRSessionManager");
16
- var structureHelper_1 = require("../util/structureHelper");
17
- var lodash_es_1 = require("lodash-es");
18
- var buildinfo_json_1 = require("../../buildinfo.json");
19
- var sceneSetup_1 = require("../internal/sceneSetup");
20
- var animationManager_1 = require("../manager/animationManager");
21
- var gltfExportManager_1 = require("../manager/gltfExportManager");
22
- var sceneManager_1 = require("../manager/sceneManager");
23
- var variantInstanceManager_1 = require("../manager/variantInstanceManager");
24
- var specStorage_1 = require("../store/specStorage");
25
- var resourceHelper_1 = require("../util/resourceHelper");
26
- var event_1 = require("./event");
27
- var eventBroadcaster_1 = require("./eventBroadcaster");
28
- var parameter_1 = require("./parameter");
29
- var variant_1 = require("./variant");
30
- /**
31
- * The main exposed object. This is the entry point into the application
32
- *
33
- * ```js
34
- * const canvas = document.getElementById( 'babylon-canvas' );
35
- * const viewer = Viewer( canvas, '/path/to/index.json' );
36
- * ```
37
- * The class does nothing on its own and needs to {@link bootstrap}
38
- */
39
- var Viewer = /** @class */ (function (_super) {
40
- tslib_1.__extends(Viewer, _super);
41
- /**
42
- * Constructor
43
- */
44
- function Viewer(canvas, structureJson) {
45
- var _this = _super.call(this) || this;
46
- _this.canvas = canvas;
47
- _this.structureJson = structureJson;
48
- _this._scene = null;
49
- _this._animationManager = null;
50
- _this._sceneManager = null;
51
- _this._gltfExportManager = null;
52
- _this._variantInstances = null;
53
- // default value is `true` ATM for compatibility reasons
54
- // in the future material cloning should be the edge case
55
- _this._cloneMaterialsOnMutation = true;
56
- _this._isRenderLoopPaused = false;
57
- return _this;
58
- }
59
- Object.defineProperty(Viewer.prototype, "scene", {
60
- /**
61
- * Gets the BabylonJS Scene that is attached to the instance.
62
- *
63
- * @throws Error if the `scene` has not been initialized.
64
- */
65
- get: function () {
66
- if (!this._scene) {
67
- throw new Error("Scene has not been initialized.");
68
- }
69
- return this._scene;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
- Object.defineProperty(Viewer.prototype, "sceneManager", {
75
- /**
76
- * Gets the {@link SceneManager} attached to the viewer.
77
- *
78
- * @throws Error if the {@link SceneManager} has not been initialized.
79
- */
80
- get: function () {
81
- if (!this._sceneManager) {
82
- throw new Error("SceneManager has not been initialized.");
83
- }
84
- return this._sceneManager;
85
- },
86
- enumerable: false,
87
- configurable: true
88
- });
89
- Object.defineProperty(Viewer.prototype, "gltfExportManager", {
90
- /**
91
- * Gets the {@link GltfExportManager} attached to the viewer.
92
- *
93
- * @throws Error if the {@link GltfExportManager} has not been initialized.
94
- */
95
- get: function () {
96
- if (!this._gltfExportManager) {
97
- throw new Error("GltfExportManager has not been initialized.");
98
- }
99
- return this._gltfExportManager;
100
- },
101
- enumerable: false,
102
- configurable: true
103
- });
104
- Object.defineProperty(Viewer.prototype, "engine", {
105
- /**
106
- * Gets the BabylonJS Engine that is attached to the viewer.
107
- */
108
- get: function () {
109
- return this.scene.getEngine();
110
- },
111
- enumerable: false,
112
- configurable: true
113
- });
114
- Object.defineProperty(Viewer.prototype, "variantInstances", {
115
- /**
116
- * Gets the {@link VariantInstanceManager} attached to the viewer.
117
- *
118
- * @throws Error if the {@link VariantInstanceManager} has not been initialized.
119
- */
120
- get: function () {
121
- if (!this._variantInstances) {
122
- throw Error("There is no variantInstanceManager.");
123
- }
124
- return this._variantInstances;
125
- },
126
- enumerable: false,
127
- configurable: true
128
- });
129
- Object.defineProperty(Viewer.prototype, "animationManager", {
130
- /**
131
- * Gets the {@link AnimationManager} attached to the viewer.
132
- *
133
- * @throws Error if the {@link AnimationManager} has not been initialized.
134
- */
135
- get: function () {
136
- if (!this._animationManager) {
137
- throw new Error("There is no animationManager instance.");
138
- }
139
- return this._animationManager;
140
- },
141
- enumerable: false,
142
- configurable: true
143
- });
144
- Object.defineProperty(Viewer.prototype, "cloneMaterialsOnMutation", {
145
- /**
146
- * Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
147
- */
148
- get: function () {
149
- return this._cloneMaterialsOnMutation;
150
- },
151
- enumerable: false,
152
- configurable: true
153
- });
154
- /**
155
- * Starts the application. This will
156
- * * load the given "index" JSON file
157
- * * setup the scene with the "scene" JSON file
158
- * * create an (optional) default setup with different variant settings
159
- * * sets up resizing by attaching a debounced version of {@link resize}
160
- *
161
- * @throws Error if any of the files is not found/valid
162
- *
163
- * @emits {@link Event.BOOTSTRAP_START}
164
- * @emits {@link Event.BOOTSTRAP_END}
165
- */
166
- Viewer.prototype.bootstrap = function () {
167
- return tslib_1.__awaiter(this, void 0, void 0, function () {
168
- var indexJson, sceneJson, _a, rootVariant, _b, setupJson, _c;
169
- var _this = this;
170
- return tslib_1.__generator(this, function (_d) {
171
- switch (_d.label) {
172
- case 0:
173
- this.broadcastEvent(event_1.Event.BOOTSTRAP_START, this);
174
- if (!lodash_es_1.isString(this.structureJson)) return [3 /*break*/, 2];
175
- return [4 /*yield*/, resourceHelper_1.loadJson(this.structureJson)];
176
- case 1:
177
- indexJson = _d.sent();
178
- return [3 /*break*/, 3];
179
- case 2:
180
- indexJson = this.structureJson;
181
- _d.label = 3;
182
- case 3:
183
- if (!indexJson.scene) {
184
- throw new Error("No \"scene\" property found for bootstrapping.");
185
- }
186
- // fill spec store
187
- specStorage_1.SpecStorage.createFromSpec(indexJson);
188
- if (!lodash_es_1.isString(indexJson.scene)) return [3 /*break*/, 5];
189
- return [4 /*yield*/, resourceHelper_1.loadJson(indexJson.scene)];
190
- case 4:
191
- sceneJson = _d.sent();
192
- indexJson.scene = sceneJson;
193
- _d.label = 5;
194
- case 5:
195
- _a = this;
196
- return [4 /*yield*/, this.initScene()];
197
- case 6:
198
- _a._scene = _d.sent();
199
- return [4 /*yield*/, variant_1.Variant.create('_', indexJson, this)];
200
- case 7:
201
- rootVariant = _d.sent();
202
- _b = this;
203
- return [4 /*yield*/, variantInstanceManager_1.VariantInstanceManager.create(rootVariant)];
204
- case 8:
205
- _b._variantInstances = _d.sent();
206
- if (!indexJson.setup) return [3 /*break*/, 12];
207
- if (!lodash_es_1.isString(indexJson.setup)) return [3 /*break*/, 10];
208
- return [4 /*yield*/, resourceHelper_1.loadJson(indexJson.setup)];
209
- case 9:
210
- setupJson = _d.sent();
211
- indexJson.setup = setupJson;
212
- _d.label = 10;
213
- case 10: return [4 /*yield*/, this.createVariantInstances()];
214
- case 11:
215
- _d.sent();
216
- _d.label = 12;
217
- case 12:
218
- // create gltf export manager
219
- _c = this;
220
- return [4 /*yield*/, gltfExportManager_1.GltfExportManager.create(this)];
221
- case 13:
222
- // create gltf export manager
223
- _c._gltfExportManager = _d.sent();
224
- // resize handler
225
- window.addEventListener('resize', resourceHelper_1.debounce(this.resize.bind(this), 100));
226
- // wait until scene is completely ready
227
- return [4 /*yield*/, this.scene.whenReadyAsync()];
228
- case 14:
229
- // wait until scene is completely ready
230
- _d.sent();
231
- // event broadcasting
232
- this.broadcastEvent(event_1.Event.BOOTSTRAP_END, this);
233
- // render loop
234
- this.engine.runRenderLoop(function () {
235
- if (!_this._isRenderLoopPaused)
236
- _this.scene.render();
237
- });
238
- return [2 /*return*/, this];
239
- }
240
- });
241
- });
242
- };
243
- /**
244
- * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
245
- * Due to the enormous additional package size of the inspector, this feature is only available in development builds.
246
- */
247
- Viewer.prototype.enableDebugLayer = function (options) {
248
- var _a;
249
- return tslib_1.__awaiter(this, void 0, void 0, function () {
250
- return tslib_1.__generator(this, function (_b) {
251
- switch (_b.label) {
252
- case 0:
253
- if (!((_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('dev'))) return [3 /*break*/, 3];
254
- return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "debug-inspector" */ '@babylonjs/inspector'); })];
255
- case 1:
256
- _b.sent();
257
- return [4 /*yield*/, this.scene.debugLayer.show(options)];
258
- case 2:
259
- _b.sent();
260
- return [3 /*break*/, 4];
261
- case 3:
262
- console.warn('BabylonJS inspector is not supported in production builds!');
263
- _b.label = 4;
264
- case 4: return [2 /*return*/];
265
- }
266
- });
267
- });
268
- };
269
- /**
270
- * Destroys all registered {@link VariantInstance}s that are registered
271
- */
272
- Viewer.prototype.destroyVariantInstances = function () {
273
- var _this = this;
274
- this.variantInstances.all.forEach(function (variantInstance) {
275
- _this.variantInstances.destroy(variantInstance.name);
276
- });
277
- return this;
278
- };
279
- /**
280
- * Trigger a resize event for the `Engine`
281
- */
282
- Viewer.prototype.resize = function () {
283
- this.engine.resize();
284
- return this;
285
- };
286
- /**
287
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
288
- * {@link DottedPath}s.
289
- */
290
- Viewer.prototype.getNode = function (variantInstanceName, elementDottedPath, nodeDottedPath) {
291
- return tslib_1.__awaiter(this, void 0, void 0, function () {
292
- var variantInstance;
293
- return tslib_1.__generator(this, function (_a) {
294
- switch (_a.label) {
295
- case 0: return [4 /*yield*/, this.variantInstances.get(variantInstanceName)];
296
- case 1:
297
- variantInstance = _a.sent();
298
- return [2 /*return*/, variantInstance.getNode(elementDottedPath, nodeDottedPath)];
299
- }
300
- });
301
- });
302
- };
303
- /**
304
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
305
- * {@link DottedPath}s.
306
- */
307
- Viewer.prototype.getMesh = function (variantInstanceName, elementDottedPath, meshDottedPath) {
308
- return tslib_1.__awaiter(this, void 0, void 0, function () {
309
- var variantInstance;
310
- return tslib_1.__generator(this, function (_a) {
311
- switch (_a.label) {
312
- case 0: return [4 /*yield*/, this.variantInstances.get(variantInstanceName)];
313
- case 1:
314
- variantInstance = _a.sent();
315
- return [2 /*return*/, variantInstance.getMesh(elementDottedPath, meshDottedPath)];
316
- }
317
- });
318
- });
319
- };
320
- /**
321
- * Switches the camera
322
- *
323
- * @emits {@link Event.CAMERA_SWITCHED}
324
- */
325
- Viewer.prototype.switchCamera = function (newCamera, reset) {
326
- if (reset === void 0) { reset = true; }
327
- var camera = this.scene.getCameraByName(newCamera);
328
- if (camera) {
329
- var activeCamera = this.scene.activeCamera;
330
- if (activeCamera) {
331
- activeCamera.detachControl(this.engine.getRenderingCanvas());
332
- }
333
- if (reset) {
334
- camera.restoreState();
335
- }
336
- this.scene.setActiveCameraByName(newCamera);
337
- camera.attachControl(this.engine.getRenderingCanvas());
338
- this.broadcastEvent(event_1.Event.CAMERA_SWITCHED, camera);
339
- }
340
- else {
341
- throw new Error("Given camera \"" + newCamera + "\" not found.");
342
- }
343
- // TODO: put traceable observers to new camera (@see element)
344
- return this;
345
- };
346
- /**
347
- * Moves or animates the active camera to given `placement`.
348
- */
349
- Viewer.prototype.moveActiveCameraTo = function (placement, animation) {
350
- return tslib_1.__awaiter(this, void 0, void 0, function () {
351
- return tslib_1.__generator(this, function (_a) {
352
- return [2 /*return*/, this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation)];
353
- });
354
- });
355
- };
356
- /**
357
- * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
358
- */
359
- Viewer.prototype.screenshot = function (settings) {
360
- var _this = this;
361
- return new Promise(function (resolve, reject) {
362
- var _a, _b, _c, _d, _e, _f;
363
- if (!_this.engine) {
364
- return reject('Engine is null');
365
- }
366
- if (!_this.scene) {
367
- return reject('Scene is null');
368
- }
369
- _this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
370
- screenshotTools_1.ScreenshotTools.CreateScreenshotUsingRenderTarget(_this.engine, _this.sceneManager.activeCamera, (_a = settings === null || settings === void 0 ? void 0 : settings.size) !== null && _a !== void 0 ? _a : { width: _this.canvas.clientWidth, height: _this.canvas.clientHeight }, resolve, (_b = settings === null || settings === void 0 ? void 0 : settings.mimeType) !== null && _b !== void 0 ? _b : 'image/png', (_c = settings === null || settings === void 0 ? void 0 : settings.samples) !== null && _c !== void 0 ? _c : 1, (_d = settings === null || settings === void 0 ? void 0 : settings.antialiasing) !== null && _d !== void 0 ? _d : false, (_e = settings === null || settings === void 0 ? void 0 : settings.fileName) !== null && _e !== void 0 ? _e : 'screenshot.png', (_f = settings === null || settings === void 0 ? void 0 : settings.renderSprites) !== null && _f !== void 0 ? _f : false);
371
- });
372
- };
373
- /**
374
- * Checks whether the browser is capable of handling XR.
375
- */
376
- Viewer.prototype.isBrowserARCapable = function () {
377
- return tslib_1.__awaiter(this, void 0, void 0, function () {
378
- return tslib_1.__generator(this, function (_a) {
379
- switch (_a.label) {
380
- case 0: return [4 /*yield*/, webXRSessionManager_1.WebXRSessionManager.IsSessionSupportedAsync('immersive-ar')];
381
- case 1: return [2 /*return*/, _a.sent()];
382
- }
383
- });
384
- });
385
- };
386
- /**
387
- * Calculates the bounding box from all visible meshes on the scene.
388
- */
389
- Viewer.prototype.calculateBoundingBox = function (excludeGeometry) {
390
- return tslib_1.__awaiter(this, void 0, void 0, function () {
391
- var bbName, _a, max, min, boundingBox;
392
- return tslib_1.__generator(this, function (_b) {
393
- if (this.scene.meshes.length === 0) {
394
- throw new Error('There are currently no meshes on the scene.');
395
- }
396
- this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
397
- bbName = '__bounding_box__';
398
- _a = this.scene.meshes
399
- .filter(function (mesh) {
400
- var isEnabled = mesh.isEnabled();
401
- // ignore the existing bounding box mesh for calculating the current one
402
- var isNotBBoxMesh = bbName !== mesh.id;
403
- // ignore meshes with invalid bounding infos
404
- var hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
405
- // ignore excluded meshes
406
- var isExcluded = excludeGeometry ? structureHelper_1.isMeshIncludedInExclusionList(mesh, excludeGeometry) : false;
407
- return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !isExcluded;
408
- })
409
- .reduce(function (accBBoxMinMax, curMesh, idx) {
410
- var bBox = curMesh.getBoundingInfo().boundingBox;
411
- // use the first entry in the array as default value and get the resulting maximum/minimum values
412
- var max = idx === 0 ? bBox.maximumWorld : math_vector_1.Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
413
- var min = idx === 0 ? bBox.minimumWorld : math_vector_1.Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
414
- return { max: max, min: min };
415
- }, { max: new math_vector_1.Vector3(), min: new math_vector_1.Vector3() }), max = _a.max, min = _a.min;
416
- boundingBox = this.scene.getMeshByName(bbName);
417
- if (!boundingBox) {
418
- boundingBox = new mesh_1.Mesh(bbName, this.scene);
419
- }
420
- boundingBox.setBoundingInfo(new boundingInfo_1.BoundingInfo(min, max));
421
- return [2 /*return*/, boundingBox];
422
- });
423
- });
424
- };
425
- /**
426
- * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
427
- */
428
- Viewer.prototype.autofocusActiveCamera = function (settings) {
429
- return tslib_1.__awaiter(this, void 0, void 0, function () {
430
- var activeCamera, cameraClsName, boundingBox, helperCamera;
431
- return tslib_1.__generator(this, function (_a) {
432
- switch (_a.label) {
433
- case 0:
434
- activeCamera = this.scene.activeCamera;
435
- if (!activeCamera) {
436
- throw new Error('No active camera found when using autofocus feature.');
437
- }
438
- if (!(activeCamera instanceof arcRotateCamera_1.ArcRotateCamera)) {
439
- cameraClsName = activeCamera.getClassName();
440
- throw new Error("Camera of type \"" + cameraClsName + "\" is not implemented yet to use autofocus feature.");
441
- }
442
- return [4 /*yield*/, this.calculateBoundingBox(settings === null || settings === void 0 ? void 0 : settings.exclude)];
443
- case 1:
444
- boundingBox = _a.sent();
445
- helperCamera = this.getFocusedHelperCamera(boundingBox, settings);
446
- return [4 /*yield*/, this.applyFocusedHelperCameraData(activeCamera, helperCamera, settings)];
447
- case 2:
448
- _a.sent();
449
- // remove the helper camera
450
- helperCamera.dispose();
451
- return [2 /*return*/];
452
- }
453
- });
454
- });
455
- };
456
- /**
457
- * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
458
- * environment
459
- */
460
- Viewer.prototype.reset = function () {
461
- return tslib_1.__awaiter(this, void 0, void 0, function () {
462
- return tslib_1.__generator(this, function (_a) {
463
- switch (_a.label) {
464
- case 0: return [4 /*yield*/, this.destroy()];
465
- case 1:
466
- _a.sent();
467
- return [2 /*return*/, this.bootstrap()];
468
- }
469
- });
470
- });
471
- };
472
- /**
473
- * Destroys
474
- *
475
- * * all {@link VariantInstance}s using {@link destroyVariantInstances}
476
- * * calling `dispose` on the `Engine` and `Scene`
477
- */
478
- Viewer.prototype.destroy = function () {
479
- this.destroyVariantInstances();
480
- this.scene.dispose();
481
- specStorage_1.SpecStorage.destroy();
482
- return this;
483
- };
484
- /**
485
- * Show coordinate system with given dimension (for debugging purpose).
486
- */
487
- Viewer.prototype.showWorldCoordinates = function (dimension) {
488
- var scene = this.scene;
489
- var makeTextPlane = function (text, color, size) {
490
- var dynamicTexture = new dynamicTexture_1.DynamicTexture('DynamicTexture', 50, scene, true);
491
- dynamicTexture.hasAlpha = true;
492
- dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
493
- var plane = mesh_1.Mesh.CreatePlane('TextPlane', size, scene, true);
494
- plane.material = new standardMaterial_1.StandardMaterial('TextPlaneMaterial', scene);
495
- plane.material.backFaceCulling = false;
496
- // @ts-ignore
497
- plane.material.specularColor = new math_color_1.Color3(0, 0, 0);
498
- // @ts-ignore
499
- plane.material.diffuseTexture = dynamicTexture;
500
- return plane;
501
- };
502
- var axisX = mesh_1.Mesh.CreateLines('axisX', [
503
- math_vector_1.Vector3.Zero(),
504
- new math_vector_1.Vector3(dimension, 0, 0),
505
- new math_vector_1.Vector3(dimension * 0.95, 0.05 * dimension, 0),
506
- new math_vector_1.Vector3(dimension, 0, 0),
507
- new math_vector_1.Vector3(dimension * 0.95, -0.05 * dimension, 0),
508
- ], scene, false);
509
- axisX.color = new math_color_1.Color3(1, 0, 0);
510
- var xChar = makeTextPlane('X', 'red', dimension / 10);
511
- xChar.position = new math_vector_1.Vector3(0.9 * dimension, -0.05 * dimension, 0);
512
- var axisY = mesh_1.Mesh.CreateLines('axisY', [
513
- math_vector_1.Vector3.Zero(),
514
- new math_vector_1.Vector3(0, dimension, 0),
515
- new math_vector_1.Vector3(-0.05 * dimension, dimension * 0.95, 0),
516
- new math_vector_1.Vector3(0, dimension, 0),
517
- new math_vector_1.Vector3(0.05 * dimension, dimension * 0.95, 0),
518
- ], scene, false);
519
- axisY.color = new math_color_1.Color3(0, 1, 0);
520
- var yChar = makeTextPlane('Y', 'green', dimension / 10);
521
- yChar.position = new math_vector_1.Vector3(0, 0.9 * dimension, -0.05 * dimension);
522
- var axisZ = mesh_1.Mesh.CreateLines('axisZ', [
523
- math_vector_1.Vector3.Zero(),
524
- new math_vector_1.Vector3(0, 0, dimension),
525
- new math_vector_1.Vector3(0, -0.05 * dimension, dimension * 0.95),
526
- new math_vector_1.Vector3(0, 0, dimension),
527
- new math_vector_1.Vector3(0, 0.05 * dimension, dimension * 0.95),
528
- ], scene, false);
529
- axisZ.color = new math_color_1.Color3(0, 0, 1);
530
- var zChar = makeTextPlane('Z', 'blue', dimension / 10);
531
- zChar.position = new math_vector_1.Vector3(0, 0.05 * dimension, 0.9 * dimension);
532
- };
533
- /**
534
- * Pause render loop.
535
- */
536
- Viewer.prototype.pauseRendering = function () {
537
- this._isRenderLoopPaused = true;
538
- };
539
- /**
540
- * Resume render loop when paused.
541
- */
542
- Viewer.prototype.resumeRendering = function () {
543
- this._isRenderLoopPaused = false;
544
- };
545
- /**
546
- * @emits {@link Event.SCENE_PROCESSING_START}
547
- * @emits {@link Event.SCENE_PROCESSING_END}
548
- */
549
- Viewer.prototype.initScene = function () {
550
- var _a, _b, _c;
551
- return tslib_1.__awaiter(this, void 0, void 0, function () {
552
- var sceneJson, engine, scene, _d, _e;
553
- var _this = this;
554
- return tslib_1.__generator(this, function (_f) {
555
- switch (_f.label) {
556
- case 0:
557
- sceneJson = specStorage_1.SpecStorage.get('scene');
558
- this.broadcastEvent(event_1.Event.SCENE_PROCESSING_START, sceneJson);
559
- engine = new engine_1.Engine(this.canvas, (_b = (_a = sceneJson.engine) === null || _a === void 0 ? void 0 : _a.antialiasing) !== null && _b !== void 0 ? _b : false, (_c = sceneJson.engine) === null || _c === void 0 ? void 0 : _c.options);
560
- return [4 /*yield*/, sceneSetup_1.sceneSetup(engine, sceneJson)];
561
- case 1:
562
- scene = _f.sent();
563
- if (sceneJson.meshPicking) {
564
- new highlightLayer_1.HighlightLayer('default', scene);
565
- scene.onPointerPick = function (pointerEvent, pickInfo) {
566
- if (!pickInfo.hit) {
567
- return;
568
- }
569
- var mesh = pickInfo.pickedMesh;
570
- _this.broadcastEvent(event_1.Event.MESH_PICKED, mesh, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant);
571
- if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element) {
572
- _this.broadcastEvent(event_1.Event.ELEMENT_PICKED, mesh.metadata.element);
573
- }
574
- if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant) {
575
- if (mesh.metadata.variant.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
576
- mesh.metadata.variant.toggleHighlight();
577
- }
578
- _this.broadcastEvent(event_1.Event.VARIANT_PICKED, mesh.metadata.variant);
579
- }
580
- };
581
- }
582
- _d = this;
583
- return [4 /*yield*/, sceneManager_1.SceneManager.create(scene)];
584
- case 2:
585
- _d._sceneManager = _f.sent();
586
- _e = this;
587
- return [4 /*yield*/, animationManager_1.AnimationManager.create(scene)];
588
- case 3:
589
- _e._animationManager = _f.sent();
590
- if (sceneJson.cloneMaterialsOnMutation !== undefined) {
591
- this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
592
- }
593
- this.broadcastEvent(event_1.Event.SCENE_PROCESSING_END, scene);
594
- return [2 /*return*/, scene];
595
- }
596
- });
597
- });
598
- };
599
- /**
600
- * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
601
- */
602
- Viewer.prototype.createVariantInstances = function () {
603
- return tslib_1.__awaiter(this, void 0, void 0, function () {
604
- var setupJson, instances, _i, _a, instanceDefinition, _b, _c;
605
- return tslib_1.__generator(this, function (_d) {
606
- switch (_d.label) {
607
- case 0:
608
- setupJson = specStorage_1.SpecStorage.get('setup');
609
- instances = [];
610
- _i = 0, _a = setupJson.instances;
611
- _d.label = 1;
612
- case 1:
613
- if (!(_i < _a.length)) return [3 /*break*/, 4];
614
- instanceDefinition = _a[_i];
615
- if (instanceDefinition.lazy) {
616
- this.variantInstances.register(instanceDefinition);
617
- return [3 /*break*/, 3];
618
- }
619
- _c = (_b = instances).push;
620
- return [4 /*yield*/, this.variantInstances.create(instanceDefinition.variant, instanceDefinition.name, instanceDefinition.parameters)];
621
- case 2:
622
- _c.apply(_b, [_d.sent()]);
623
- _d.label = 3;
624
- case 3:
625
- _i++;
626
- return [3 /*break*/, 1];
627
- case 4: return [2 /*return*/, instances];
628
- }
629
- });
630
- });
631
- };
632
- /**
633
- * Help function for focusing a helper camera exactly onto the given bounding box
634
- */
635
- Viewer.prototype.getFocusedHelperCamera = function (boundingBox, settings) {
636
- var _a, _b;
637
- // use helper camera to get some default values and set the values of the real camera accordingly
638
- var helperCamera = new arcRotateCamera_1.ArcRotateCamera('__helper_camera__', 0, // camera angles will be overwritten after the target has been set
639
- 0, 0, // radius will be calculated, so we can set to 0 here
640
- math_vector_1.Vector3.Zero(), this.scene);
641
- // this is required for automatically calculating the `lowerRadiusLimit`, so that we don't "dive" into meshes
642
- // see https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior
643
- helperCamera.useFramingBehavior = true;
644
- // `minZ` is the camera distance beyond which the mesh will be clipped
645
- // this should be very low, but can't be zero
646
- // a good value seems to be 1% of the bounding box size (= radius), whereas the value shouldn't go above 1, which is also the default value
647
- var radius = boundingBox.getBoundingInfo().boundingSphere.radius;
648
- helperCamera.minZ = Math.min(radius / 100, 1);
649
- // set desired camera data, these won't be changed by the autofocus function!
650
- // default values should focus the element exactly from the front (= XY Plane)
651
- helperCamera.setTarget(boundingBox, true);
652
- helperCamera.alpha = ((_a = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _a !== void 0 ? _a : -90) * (Math.PI / 180);
653
- helperCamera.beta = ((_b = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _b !== void 0 ? _b : 90) * (Math.PI / 180);
654
- // finally zoom to the bounding box
655
- // also apply a zoom factor, this adjusts the borders around the model in the viewport
656
- helperCamera.zoomOnFactor = (settings === null || settings === void 0 ? void 0 : settings.radiusFactor) || 1;
657
- helperCamera.zoomOn([boundingBox], true);
658
- return helperCamera;
659
- };
660
- /**
661
- * Help function for applying the relevant data of the focused helper camera to the real camera
662
- */
663
- Viewer.prototype.applyFocusedHelperCameraData = function (activeCamera, helperCamera, settings) {
664
- return tslib_1.__awaiter(this, void 0, void 0, function () {
665
- var newCameraPosition;
666
- return tslib_1.__generator(this, function (_a) {
667
- switch (_a.label) {
668
- case 0:
669
- // limits
670
- activeCamera.minZ = helperCamera.minZ;
671
- activeCamera.maxZ = helperCamera.maxZ;
672
- activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
673
- activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
674
- // additional settings
675
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
676
- activeCamera.wheelPrecision = helperCamera.wheelPrecision;
677
- }
678
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
679
- activeCamera.panningSensibility = helperCamera.panningSensibility;
680
- }
681
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
682
- activeCamera.pinchPrecision = helperCamera.pinchPrecision;
683
- }
684
- newCameraPosition = {
685
- alpha: helperCamera.alpha,
686
- beta: helperCamera.beta,
687
- radius: helperCamera.radius,
688
- target: helperCamera.target,
689
- };
690
- return [4 /*yield*/, this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.animation)];
691
- case 1:
692
- _a.sent();
693
- return [2 /*return*/];
694
- }
695
- });
696
- });
697
- };
698
- Viewer.version = buildinfo_json_1.version;
699
- return Viewer;
700
- }(eventBroadcaster_1.EventBroadcaster));
701
- exports.Viewer = Viewer;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Viewer = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
6
+ var boundingInfo_1 = require("@babylonjs/core/Culling/boundingInfo");
7
+ var engine_1 = require("@babylonjs/core/Engines/engine");
8
+ var highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
9
+ var standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
10
+ var dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
11
+ var math_color_1 = require("@babylonjs/core/Maths/math.color");
12
+ var math_vector_1 = require("@babylonjs/core/Maths/math.vector");
13
+ var mesh_1 = require("@babylonjs/core/Meshes/mesh");
14
+ var screenshotTools_1 = require("@babylonjs/core/Misc/screenshotTools");
15
+ var webXRSessionManager_1 = require("@babylonjs/core/XR/webXRSessionManager");
16
+ var structureHelper_1 = require("../util/structureHelper");
17
+ var lodash_es_1 = require("lodash-es");
18
+ var buildinfo_json_1 = require("../../buildinfo.json");
19
+ var sceneSetup_1 = require("../internal/sceneSetup");
20
+ var animationManager_1 = require("../manager/animationManager");
21
+ var gltfExportManager_1 = require("../manager/gltfExportManager");
22
+ var sceneManager_1 = require("../manager/sceneManager");
23
+ var variantInstanceManager_1 = require("../manager/variantInstanceManager");
24
+ var specStorage_1 = require("../store/specStorage");
25
+ var resourceHelper_1 = require("../util/resourceHelper");
26
+ var event_1 = require("./event");
27
+ var eventBroadcaster_1 = require("./eventBroadcaster");
28
+ var parameter_1 = require("./parameter");
29
+ var variant_1 = require("./variant");
30
+ var debugLayer_1 = require("@babylonjs/core/Debug/debugLayer");
31
+ var babylonHelper_1 = require("../util/babylonHelper");
32
+ /**
33
+ * The main exposed object. This is the entry point into the application
34
+ *
35
+ * ```js
36
+ * const canvas = document.getElementById( 'babylon-canvas' );
37
+ * const viewer = Viewer( canvas, '/path/to/index.json' );
38
+ * ```
39
+ * The class does nothing on its own and needs to {@link bootstrap}
40
+ */
41
+ var Viewer = /** @class */ (function (_super) {
42
+ tslib_1.__extends(Viewer, _super);
43
+ /**
44
+ * Constructor
45
+ */
46
+ function Viewer(canvas, structureJson) {
47
+ var _this = _super.call(this) || this;
48
+ _this.canvas = canvas;
49
+ _this.structureJson = structureJson;
50
+ _this._scene = null;
51
+ _this._animationManager = null;
52
+ _this._sceneManager = null;
53
+ _this._gltfExportManager = null;
54
+ _this._variantInstances = null;
55
+ // default value is `true` ATM for compatibility reasons
56
+ // in the future material cloning should be the edge case
57
+ _this._cloneMaterialsOnMutation = true;
58
+ _this._isRenderLoopPaused = false;
59
+ _this._inspectorLoaded = false;
60
+ return _this;
61
+ }
62
+ Object.defineProperty(Viewer.prototype, "scene", {
63
+ /**
64
+ * Gets the BabylonJS Scene that is attached to the instance.
65
+ *
66
+ * @throws Error if the `scene` has not been initialized.
67
+ */
68
+ get: function () {
69
+ if (!this._scene) {
70
+ throw new Error("Scene has not been initialized.");
71
+ }
72
+ return this._scene;
73
+ },
74
+ enumerable: false,
75
+ configurable: true
76
+ });
77
+ Object.defineProperty(Viewer.prototype, "sceneManager", {
78
+ /**
79
+ * Gets the {@link SceneManager} attached to the viewer.
80
+ *
81
+ * @throws Error if the {@link SceneManager} has not been initialized.
82
+ */
83
+ get: function () {
84
+ if (!this._sceneManager) {
85
+ throw new Error("SceneManager has not been initialized.");
86
+ }
87
+ return this._sceneManager;
88
+ },
89
+ enumerable: false,
90
+ configurable: true
91
+ });
92
+ Object.defineProperty(Viewer.prototype, "gltfExportManager", {
93
+ /**
94
+ * Gets the {@link GltfExportManager} attached to the viewer.
95
+ *
96
+ * @throws Error if the {@link GltfExportManager} has not been initialized.
97
+ */
98
+ get: function () {
99
+ if (!this._gltfExportManager) {
100
+ throw new Error("GltfExportManager has not been initialized.");
101
+ }
102
+ return this._gltfExportManager;
103
+ },
104
+ enumerable: false,
105
+ configurable: true
106
+ });
107
+ Object.defineProperty(Viewer.prototype, "engine", {
108
+ /**
109
+ * Gets the BabylonJS Engine that is attached to the viewer.
110
+ */
111
+ get: function () {
112
+ return this.scene.getEngine();
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Object.defineProperty(Viewer.prototype, "variantInstances", {
118
+ /**
119
+ * Gets the {@link VariantInstanceManager} attached to the viewer.
120
+ *
121
+ * @throws Error if the {@link VariantInstanceManager} has not been initialized.
122
+ */
123
+ get: function () {
124
+ if (!this._variantInstances) {
125
+ throw Error("There is no variantInstanceManager.");
126
+ }
127
+ return this._variantInstances;
128
+ },
129
+ enumerable: false,
130
+ configurable: true
131
+ });
132
+ Object.defineProperty(Viewer.prototype, "animationManager", {
133
+ /**
134
+ * Gets the {@link AnimationManager} attached to the viewer.
135
+ *
136
+ * @throws Error if the {@link AnimationManager} has not been initialized.
137
+ */
138
+ get: function () {
139
+ if (!this._animationManager) {
140
+ throw new Error("There is no animationManager instance.");
141
+ }
142
+ return this._animationManager;
143
+ },
144
+ enumerable: false,
145
+ configurable: true
146
+ });
147
+ Object.defineProperty(Viewer.prototype, "cloneMaterialsOnMutation", {
148
+ /**
149
+ * Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
150
+ */
151
+ get: function () {
152
+ return this._cloneMaterialsOnMutation;
153
+ },
154
+ enumerable: false,
155
+ configurable: true
156
+ });
157
+ /**
158
+ * Starts the application. This will
159
+ * * load the given "index" JSON file
160
+ * * setup the scene with the "scene" JSON file
161
+ * * create an (optional) default setup with different variant settings
162
+ * * sets up resizing by attaching a debounced version of {@link resize}
163
+ *
164
+ * @throws Error if any of the files is not found/valid
165
+ *
166
+ * @emits {@link Event.BOOTSTRAP_START}
167
+ * @emits {@link Event.BOOTSTRAP_END}
168
+ */
169
+ Viewer.prototype.bootstrap = function () {
170
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
171
+ var indexJson, sceneJson, _a, rootVariant, _b, setupJson, _c;
172
+ var _this = this;
173
+ return tslib_1.__generator(this, function (_d) {
174
+ switch (_d.label) {
175
+ case 0:
176
+ this.broadcastEvent(event_1.Event.BOOTSTRAP_START, this);
177
+ if (!lodash_es_1.isString(this.structureJson)) return [3 /*break*/, 2];
178
+ return [4 /*yield*/, resourceHelper_1.loadJson(this.structureJson)];
179
+ case 1:
180
+ indexJson = _d.sent();
181
+ return [3 /*break*/, 3];
182
+ case 2:
183
+ indexJson = this.structureJson;
184
+ _d.label = 3;
185
+ case 3:
186
+ if (!indexJson.scene) {
187
+ throw new Error("No \"scene\" property found for bootstrapping.");
188
+ }
189
+ // fill spec store
190
+ specStorage_1.SpecStorage.createFromSpec(indexJson);
191
+ if (!lodash_es_1.isString(indexJson.scene)) return [3 /*break*/, 5];
192
+ return [4 /*yield*/, resourceHelper_1.loadJson(indexJson.scene)];
193
+ case 4:
194
+ sceneJson = _d.sent();
195
+ indexJson.scene = sceneJson;
196
+ _d.label = 5;
197
+ case 5:
198
+ _a = this;
199
+ return [4 /*yield*/, this.initScene()];
200
+ case 6:
201
+ _a._scene = _d.sent();
202
+ return [4 /*yield*/, variant_1.Variant.create('_', indexJson, this)];
203
+ case 7:
204
+ rootVariant = _d.sent();
205
+ _b = this;
206
+ return [4 /*yield*/, variantInstanceManager_1.VariantInstanceManager.create(rootVariant)];
207
+ case 8:
208
+ _b._variantInstances = _d.sent();
209
+ if (!indexJson.setup) return [3 /*break*/, 12];
210
+ if (!lodash_es_1.isString(indexJson.setup)) return [3 /*break*/, 10];
211
+ return [4 /*yield*/, resourceHelper_1.loadJson(indexJson.setup)];
212
+ case 9:
213
+ setupJson = _d.sent();
214
+ indexJson.setup = setupJson;
215
+ _d.label = 10;
216
+ case 10: return [4 /*yield*/, this.createVariantInstances()];
217
+ case 11:
218
+ _d.sent();
219
+ _d.label = 12;
220
+ case 12:
221
+ // create gltf export manager
222
+ _c = this;
223
+ return [4 /*yield*/, gltfExportManager_1.GltfExportManager.create(this)];
224
+ case 13:
225
+ // create gltf export manager
226
+ _c._gltfExportManager = _d.sent();
227
+ // resize handler
228
+ window.addEventListener('resize', resourceHelper_1.debounce(this.resize.bind(this), 100));
229
+ // wait until scene is completely ready
230
+ return [4 /*yield*/, this.scene.whenReadyAsync()];
231
+ case 14:
232
+ // wait until scene is completely ready
233
+ _d.sent();
234
+ // event broadcasting
235
+ this.broadcastEvent(event_1.Event.BOOTSTRAP_END, this);
236
+ // render loop
237
+ this.engine.runRenderLoop(function () {
238
+ if (!_this._isRenderLoopPaused)
239
+ _this.scene.render();
240
+ });
241
+ return [2 /*return*/, this];
242
+ }
243
+ });
244
+ });
245
+ };
246
+ /**
247
+ * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
248
+ * Due to the additional size of the inspector, the CDN version is used instead of shipping the required code with the viewer.\
249
+ * This means that the code will be downloaded only when needed and calling `enableDebugLayer` can take a little while depending on your internet connection etc.
250
+ */
251
+ Viewer.prototype.enableDebugLayer = function (options) {
252
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
253
+ return tslib_1.__generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0:
256
+ if (!!this._inspectorLoaded) return [3 /*break*/, 2];
257
+ // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
258
+ return [4 /*yield*/, resourceHelper_1.loadJavascript('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js')];
259
+ case 1:
260
+ // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
261
+ _a.sent();
262
+ debugLayer_1.DebugLayer.InspectorURL =
263
+ 'https://cdn.jsdelivr.net/npm/babylonjs-inspector@5.6.0/babylon.inspector.bundle.max.min.js';
264
+ this._inspectorLoaded = true;
265
+ _a.label = 2;
266
+ case 2: return [4 /*yield*/, this.scene.debugLayer.show(options)];
267
+ case 3:
268
+ _a.sent();
269
+ return [2 /*return*/];
270
+ }
271
+ });
272
+ });
273
+ };
274
+ /**
275
+ * Destroys all registered {@link VariantInstance}s that are registered
276
+ */
277
+ Viewer.prototype.destroyVariantInstances = function () {
278
+ var _this = this;
279
+ this.variantInstances.all.forEach(function (variantInstance) {
280
+ _this.variantInstances.destroy(variantInstance.name);
281
+ });
282
+ return this;
283
+ };
284
+ /**
285
+ * Trigger a resize event for the `Engine`
286
+ */
287
+ Viewer.prototype.resize = function () {
288
+ this.engine.resize();
289
+ return this;
290
+ };
291
+ /**
292
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
293
+ * {@link DottedPath}s.
294
+ */
295
+ Viewer.prototype.getNode = function (variantInstanceName, elementDottedPath, nodeDottedPath) {
296
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
297
+ var variantInstance;
298
+ return tslib_1.__generator(this, function (_a) {
299
+ switch (_a.label) {
300
+ case 0: return [4 /*yield*/, this.variantInstances.get(variantInstanceName)];
301
+ case 1:
302
+ variantInstance = _a.sent();
303
+ return [2 /*return*/, variantInstance.getNode(elementDottedPath, nodeDottedPath)];
304
+ }
305
+ });
306
+ });
307
+ };
308
+ /**
309
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
310
+ * {@link DottedPath}s.
311
+ */
312
+ Viewer.prototype.getMesh = function (variantInstanceName, elementDottedPath, meshDottedPath) {
313
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
314
+ var variantInstance;
315
+ return tslib_1.__generator(this, function (_a) {
316
+ switch (_a.label) {
317
+ case 0: return [4 /*yield*/, this.variantInstances.get(variantInstanceName)];
318
+ case 1:
319
+ variantInstance = _a.sent();
320
+ return [2 /*return*/, variantInstance.getMesh(elementDottedPath, meshDottedPath)];
321
+ }
322
+ });
323
+ });
324
+ };
325
+ /**
326
+ * Switches the camera
327
+ *
328
+ * @emits {@link Event.CAMERA_SWITCHED}
329
+ */
330
+ Viewer.prototype.switchCamera = function (newCamera, reset) {
331
+ if (reset === void 0) { reset = true; }
332
+ var camera = this.scene.getCameraByName(newCamera);
333
+ if (camera) {
334
+ var activeCamera = this.scene.activeCamera;
335
+ if (activeCamera) {
336
+ activeCamera.detachControl(this.engine.getRenderingCanvas());
337
+ }
338
+ if (reset) {
339
+ camera.restoreState();
340
+ }
341
+ this.scene.setActiveCameraByName(newCamera);
342
+ camera.attachControl(this.engine.getRenderingCanvas());
343
+ this.broadcastEvent(event_1.Event.CAMERA_SWITCHED, camera);
344
+ }
345
+ else {
346
+ throw new Error("Given camera \"" + newCamera + "\" not found.");
347
+ }
348
+ // TODO: put traceable observers to new camera (@see element)
349
+ return this;
350
+ };
351
+ /**
352
+ * Moves or animates the active camera to given `placement`.
353
+ */
354
+ Viewer.prototype.moveActiveCameraTo = function (placement, animation) {
355
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
356
+ return tslib_1.__generator(this, function (_a) {
357
+ return [2 /*return*/, this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation)];
358
+ });
359
+ });
360
+ };
361
+ /**
362
+ * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
363
+ */
364
+ Viewer.prototype.screenshot = function (settings) {
365
+ var _this = this;
366
+ return new Promise(function (resolve, reject) {
367
+ var _a, _b, _c, _d, _e, _f;
368
+ if (!_this.engine) {
369
+ return reject('Engine is null');
370
+ }
371
+ if (!_this.scene) {
372
+ return reject('Scene is null');
373
+ }
374
+ _this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
375
+ screenshotTools_1.ScreenshotTools.CreateScreenshotUsingRenderTarget(_this.engine, _this.sceneManager.activeCamera, (_a = settings === null || settings === void 0 ? void 0 : settings.size) !== null && _a !== void 0 ? _a : { width: _this.canvas.clientWidth, height: _this.canvas.clientHeight }, resolve, (_b = settings === null || settings === void 0 ? void 0 : settings.mimeType) !== null && _b !== void 0 ? _b : 'image/png', (_c = settings === null || settings === void 0 ? void 0 : settings.samples) !== null && _c !== void 0 ? _c : 1, (_d = settings === null || settings === void 0 ? void 0 : settings.antialiasing) !== null && _d !== void 0 ? _d : false, (_e = settings === null || settings === void 0 ? void 0 : settings.fileName) !== null && _e !== void 0 ? _e : 'screenshot.png', (_f = settings === null || settings === void 0 ? void 0 : settings.renderSprites) !== null && _f !== void 0 ? _f : false);
376
+ });
377
+ };
378
+ /**
379
+ * Checks whether the browser is capable of handling XR.
380
+ */
381
+ Viewer.prototype.isBrowserARCapable = function () {
382
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
383
+ return tslib_1.__generator(this, function (_a) {
384
+ switch (_a.label) {
385
+ case 0: return [4 /*yield*/, webXRSessionManager_1.WebXRSessionManager.IsSessionSupportedAsync('immersive-ar')];
386
+ case 1: return [2 /*return*/, _a.sent()];
387
+ }
388
+ });
389
+ });
390
+ };
391
+ /**
392
+ * Calculates the bounding box from all visible meshes on the scene.
393
+ */
394
+ Viewer.prototype.calculateBoundingBox = function (excludeGeometry) {
395
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
396
+ var bbName, _a, max, min, boundingBox;
397
+ return tslib_1.__generator(this, function (_b) {
398
+ if (this.scene.meshes.length === 0) {
399
+ throw new Error('There are currently no meshes on the scene.');
400
+ }
401
+ this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
402
+ bbName = '__bounding_box__';
403
+ _a = this.scene.meshes
404
+ .filter(function (mesh) {
405
+ var isEnabled = mesh.isEnabled();
406
+ // ignore the existing bounding box mesh for calculating the current one
407
+ var isNotBBoxMesh = bbName !== mesh.id;
408
+ // ignore meshes with invalid bounding infos
409
+ var hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
410
+ // ignore excluded meshes
411
+ var isExcluded = excludeGeometry ? structureHelper_1.isMeshIncludedInExclusionList(mesh, excludeGeometry) : false;
412
+ return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !isExcluded;
413
+ })
414
+ .reduce(function (accBBoxMinMax, curMesh, idx) {
415
+ var bBox = curMesh.getBoundingInfo().boundingBox;
416
+ // use the first entry in the array as default value and get the resulting maximum/minimum values
417
+ var max = idx === 0 ? bBox.maximumWorld : math_vector_1.Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
418
+ var min = idx === 0 ? bBox.minimumWorld : math_vector_1.Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
419
+ return { max: max, min: min };
420
+ }, { max: new math_vector_1.Vector3(), min: new math_vector_1.Vector3() }), max = _a.max, min = _a.min;
421
+ boundingBox = this.scene.getMeshByName(bbName);
422
+ if (!boundingBox) {
423
+ boundingBox = new mesh_1.Mesh(bbName, this.scene);
424
+ }
425
+ boundingBox.setBoundingInfo(new boundingInfo_1.BoundingInfo(min, max));
426
+ return [2 /*return*/, boundingBox];
427
+ });
428
+ });
429
+ };
430
+ /**
431
+ * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
432
+ */
433
+ Viewer.prototype.autofocusActiveCamera = function (settings) {
434
+ var _a;
435
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
436
+ var activeCamera, cameraClsName, exclude, photoDome, photoDomeMeshes, envHelper, boundingBox, helperCamera;
437
+ return tslib_1.__generator(this, function (_b) {
438
+ switch (_b.label) {
439
+ case 0:
440
+ activeCamera = this.scene.activeCamera;
441
+ if (!activeCamera) {
442
+ throw new Error('No active camera found when using autofocus feature.');
443
+ }
444
+ if (!(activeCamera instanceof arcRotateCamera_1.ArcRotateCamera)) {
445
+ cameraClsName = activeCamera.getClassName();
446
+ throw new Error("Camera of type \"" + cameraClsName + "\" is not implemented yet to use autofocus feature.");
447
+ }
448
+ exclude = (settings === null || settings === void 0 ? void 0 : settings.exclude) || [];
449
+ photoDome = this.scene.getNodeByName(babylonHelper_1.backgroundDomeName);
450
+ photoDomeMeshes = photoDome === null || photoDome === void 0 ? void 0 : photoDome.getChildMeshes();
451
+ if (photoDomeMeshes === null || photoDomeMeshes === void 0 ? void 0 : photoDomeMeshes.length) {
452
+ exclude = tslib_1.__spreadArrays(exclude, photoDomeMeshes);
453
+ }
454
+ envHelper = (_a = this.scene.metadata) === null || _a === void 0 ? void 0 : _a[babylonHelper_1.envHelperMetadataName];
455
+ if (envHelper === null || envHelper === void 0 ? void 0 : envHelper.rootMesh) {
456
+ exclude = tslib_1.__spreadArrays(exclude, [envHelper.rootMesh]);
457
+ }
458
+ return [4 /*yield*/, this.calculateBoundingBox(exclude)];
459
+ case 1:
460
+ boundingBox = _b.sent();
461
+ helperCamera = this.getFocusedHelperCamera(boundingBox, settings);
462
+ return [4 /*yield*/, this.applyFocusedHelperCameraData(activeCamera, helperCamera, settings)];
463
+ case 2:
464
+ _b.sent();
465
+ // remove the helper camera
466
+ helperCamera.dispose();
467
+ return [2 /*return*/];
468
+ }
469
+ });
470
+ });
471
+ };
472
+ /**
473
+ * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
474
+ * environment
475
+ */
476
+ Viewer.prototype.reset = function () {
477
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
478
+ return tslib_1.__generator(this, function (_a) {
479
+ switch (_a.label) {
480
+ case 0: return [4 /*yield*/, this.destroy()];
481
+ case 1:
482
+ _a.sent();
483
+ return [2 /*return*/, this.bootstrap()];
484
+ }
485
+ });
486
+ });
487
+ };
488
+ /**
489
+ * Destroys
490
+ *
491
+ * * all {@link VariantInstance}s using {@link destroyVariantInstances}
492
+ * * calling `dispose` on the `Engine` and `Scene`
493
+ */
494
+ Viewer.prototype.destroy = function () {
495
+ this.destroyVariantInstances();
496
+ this.scene.dispose();
497
+ specStorage_1.SpecStorage.destroy();
498
+ return this;
499
+ };
500
+ /**
501
+ * Show coordinate system with given dimension (for debugging purpose).
502
+ */
503
+ Viewer.prototype.showWorldCoordinates = function (dimension) {
504
+ var scene = this.scene;
505
+ var makeTextPlane = function (text, color, size) {
506
+ var dynamicTexture = new dynamicTexture_1.DynamicTexture('DynamicTexture', 50, scene, true);
507
+ dynamicTexture.hasAlpha = true;
508
+ dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
509
+ var plane = mesh_1.Mesh.CreatePlane('TextPlane', size, scene, true);
510
+ plane.material = new standardMaterial_1.StandardMaterial('TextPlaneMaterial', scene);
511
+ plane.material.backFaceCulling = false;
512
+ // @ts-ignore
513
+ plane.material.specularColor = new math_color_1.Color3(0, 0, 0);
514
+ // @ts-ignore
515
+ plane.material.diffuseTexture = dynamicTexture;
516
+ return plane;
517
+ };
518
+ var axisX = mesh_1.Mesh.CreateLines('axisX', [
519
+ math_vector_1.Vector3.Zero(),
520
+ new math_vector_1.Vector3(dimension, 0, 0),
521
+ new math_vector_1.Vector3(dimension * 0.95, 0.05 * dimension, 0),
522
+ new math_vector_1.Vector3(dimension, 0, 0),
523
+ new math_vector_1.Vector3(dimension * 0.95, -0.05 * dimension, 0),
524
+ ], scene, false);
525
+ axisX.color = new math_color_1.Color3(1, 0, 0);
526
+ var xChar = makeTextPlane('X', 'red', dimension / 10);
527
+ xChar.position = new math_vector_1.Vector3(0.9 * dimension, -0.05 * dimension, 0);
528
+ var axisY = mesh_1.Mesh.CreateLines('axisY', [
529
+ math_vector_1.Vector3.Zero(),
530
+ new math_vector_1.Vector3(0, dimension, 0),
531
+ new math_vector_1.Vector3(-0.05 * dimension, dimension * 0.95, 0),
532
+ new math_vector_1.Vector3(0, dimension, 0),
533
+ new math_vector_1.Vector3(0.05 * dimension, dimension * 0.95, 0),
534
+ ], scene, false);
535
+ axisY.color = new math_color_1.Color3(0, 1, 0);
536
+ var yChar = makeTextPlane('Y', 'green', dimension / 10);
537
+ yChar.position = new math_vector_1.Vector3(0, 0.9 * dimension, -0.05 * dimension);
538
+ var axisZ = mesh_1.Mesh.CreateLines('axisZ', [
539
+ math_vector_1.Vector3.Zero(),
540
+ new math_vector_1.Vector3(0, 0, dimension),
541
+ new math_vector_1.Vector3(0, -0.05 * dimension, dimension * 0.95),
542
+ new math_vector_1.Vector3(0, 0, dimension),
543
+ new math_vector_1.Vector3(0, 0.05 * dimension, dimension * 0.95),
544
+ ], scene, false);
545
+ axisZ.color = new math_color_1.Color3(0, 0, 1);
546
+ var zChar = makeTextPlane('Z', 'blue', dimension / 10);
547
+ zChar.position = new math_vector_1.Vector3(0, 0.05 * dimension, 0.9 * dimension);
548
+ };
549
+ /**
550
+ * Pause render loop.
551
+ */
552
+ Viewer.prototype.pauseRendering = function () {
553
+ this._isRenderLoopPaused = true;
554
+ };
555
+ /**
556
+ * Resume render loop when paused.
557
+ */
558
+ Viewer.prototype.resumeRendering = function () {
559
+ this._isRenderLoopPaused = false;
560
+ };
561
+ /**
562
+ * @emits {@link Event.SCENE_PROCESSING_START}
563
+ * @emits {@link Event.SCENE_PROCESSING_END}
564
+ */
565
+ Viewer.prototype.initScene = function () {
566
+ var _a, _b, _c;
567
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
568
+ var sceneJson, engine, scene, _d, _e;
569
+ var _this = this;
570
+ return tslib_1.__generator(this, function (_f) {
571
+ switch (_f.label) {
572
+ case 0:
573
+ sceneJson = specStorage_1.SpecStorage.get('scene');
574
+ this.broadcastEvent(event_1.Event.SCENE_PROCESSING_START, sceneJson);
575
+ engine = new engine_1.Engine(this.canvas, (_b = (_a = sceneJson.engine) === null || _a === void 0 ? void 0 : _a.antialiasing) !== null && _b !== void 0 ? _b : false, (_c = sceneJson.engine) === null || _c === void 0 ? void 0 : _c.options);
576
+ return [4 /*yield*/, sceneSetup_1.sceneSetup(engine, sceneJson)];
577
+ case 1:
578
+ scene = _f.sent();
579
+ if (sceneJson.meshPicking) {
580
+ new highlightLayer_1.HighlightLayer('default', scene);
581
+ scene.onPointerPick = function (pointerEvent, pickInfo) {
582
+ if (!pickInfo.hit) {
583
+ return;
584
+ }
585
+ var mesh = pickInfo.pickedMesh;
586
+ _this.broadcastEvent(event_1.Event.MESH_PICKED, mesh, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant);
587
+ if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element) {
588
+ _this.broadcastEvent(event_1.Event.ELEMENT_PICKED, mesh.metadata.element);
589
+ }
590
+ if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant) {
591
+ if (mesh.metadata.variant.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
592
+ mesh.metadata.variant.toggleHighlight();
593
+ }
594
+ _this.broadcastEvent(event_1.Event.VARIANT_PICKED, mesh.metadata.variant);
595
+ }
596
+ };
597
+ }
598
+ _d = this;
599
+ return [4 /*yield*/, sceneManager_1.SceneManager.create(scene)];
600
+ case 2:
601
+ _d._sceneManager = _f.sent();
602
+ _e = this;
603
+ return [4 /*yield*/, animationManager_1.AnimationManager.create(scene)];
604
+ case 3:
605
+ _e._animationManager = _f.sent();
606
+ if (sceneJson.cloneMaterialsOnMutation !== undefined) {
607
+ this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
608
+ }
609
+ this.broadcastEvent(event_1.Event.SCENE_PROCESSING_END, scene);
610
+ return [2 /*return*/, scene];
611
+ }
612
+ });
613
+ });
614
+ };
615
+ /**
616
+ * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
617
+ */
618
+ Viewer.prototype.createVariantInstances = function () {
619
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
620
+ var setupJson, instances, _i, _a, instanceDefinition, _b, _c;
621
+ return tslib_1.__generator(this, function (_d) {
622
+ switch (_d.label) {
623
+ case 0:
624
+ setupJson = specStorage_1.SpecStorage.get('setup');
625
+ instances = [];
626
+ _i = 0, _a = setupJson.instances;
627
+ _d.label = 1;
628
+ case 1:
629
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
630
+ instanceDefinition = _a[_i];
631
+ if (instanceDefinition.lazy) {
632
+ this.variantInstances.register(instanceDefinition);
633
+ return [3 /*break*/, 3];
634
+ }
635
+ _c = (_b = instances).push;
636
+ return [4 /*yield*/, this.variantInstances.create(instanceDefinition.variant, instanceDefinition.name, instanceDefinition.parameters)];
637
+ case 2:
638
+ _c.apply(_b, [_d.sent()]);
639
+ _d.label = 3;
640
+ case 3:
641
+ _i++;
642
+ return [3 /*break*/, 1];
643
+ case 4: return [2 /*return*/, instances];
644
+ }
645
+ });
646
+ });
647
+ };
648
+ /**
649
+ * Help function for focusing a helper camera exactly onto the given bounding box
650
+ */
651
+ Viewer.prototype.getFocusedHelperCamera = function (boundingBox, settings) {
652
+ var _a, _b;
653
+ // use helper camera to get some default values and set the values of the real camera accordingly
654
+ var helperCamera = new arcRotateCamera_1.ArcRotateCamera('__helper_camera__', 0, // camera angles will be overwritten after the target has been set
655
+ 0, 0, // radius will be calculated, so we can set to 0 here
656
+ math_vector_1.Vector3.Zero(), this.scene);
657
+ // this is required for automatically calculating the `lowerRadiusLimit`, so that we don't "dive" into meshes
658
+ // see https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior
659
+ helperCamera.useFramingBehavior = true;
660
+ // `minZ` is the camera distance beyond which the mesh will be clipped
661
+ // this should be very low, but can't be zero
662
+ // a good value seems to be 1% of the bounding box size (= radius), whereas the value shouldn't go above 1, which is also the default value
663
+ var radius = boundingBox.getBoundingInfo().boundingSphere.radius;
664
+ helperCamera.minZ = Math.min(radius / 100, 1);
665
+ // set desired camera data, these won't be changed by the autofocus function!
666
+ // default values should focus the element exactly from the front (= XY Plane)
667
+ helperCamera.setTarget(boundingBox, true);
668
+ helperCamera.alpha = ((_a = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _a !== void 0 ? _a : -90) * (Math.PI / 180);
669
+ helperCamera.beta = ((_b = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _b !== void 0 ? _b : 90) * (Math.PI / 180);
670
+ // finally zoom to the bounding box
671
+ // also apply a zoom factor, this adjusts the borders around the model in the viewport
672
+ helperCamera.zoomOnFactor = (settings === null || settings === void 0 ? void 0 : settings.radiusFactor) || 1;
673
+ helperCamera.zoomOn([boundingBox], true);
674
+ return helperCamera;
675
+ };
676
+ /**
677
+ * Help function for applying the relevant data of the focused helper camera to the real camera
678
+ */
679
+ Viewer.prototype.applyFocusedHelperCameraData = function (activeCamera, helperCamera, settings) {
680
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
681
+ var newCameraPosition;
682
+ return tslib_1.__generator(this, function (_a) {
683
+ switch (_a.label) {
684
+ case 0:
685
+ // limits
686
+ activeCamera.minZ = helperCamera.minZ;
687
+ activeCamera.maxZ = helperCamera.maxZ;
688
+ activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
689
+ activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
690
+ // additional settings
691
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
692
+ activeCamera.wheelPrecision = helperCamera.wheelPrecision;
693
+ }
694
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
695
+ activeCamera.panningSensibility = helperCamera.panningSensibility;
696
+ }
697
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
698
+ activeCamera.pinchPrecision = helperCamera.pinchPrecision;
699
+ }
700
+ newCameraPosition = {
701
+ alpha: helperCamera.alpha,
702
+ beta: helperCamera.beta,
703
+ radius: helperCamera.radius,
704
+ target: helperCamera.target,
705
+ };
706
+ return [4 /*yield*/, this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.animation)];
707
+ case 1:
708
+ _a.sent();
709
+ return [2 /*return*/];
710
+ }
711
+ });
712
+ });
713
+ };
714
+ Viewer.version = buildinfo_json_1.version;
715
+ return Viewer;
716
+ }(eventBroadcaster_1.EventBroadcaster));
717
+ exports.Viewer = Viewer;
702
718
  //# sourceMappingURL=viewer.js.map