@combeenation/3d-viewer 6.5.0 → 7.0.0-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 (118) hide show
  1. package/README.md +111 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
  6. package/dist/lib-cjs/api/classes/element.d.ts +153 -149
  7. package/dist/lib-cjs/api/classes/element.js +670 -669
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/event.d.ts +396 -342
  10. package/dist/lib-cjs/api/classes/event.js +419 -365
  11. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  13. package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
  14. package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -0
  15. package/dist/lib-cjs/api/classes/fuzzyMap.js +22 -0
  16. package/dist/lib-cjs/api/classes/fuzzyMap.js.map +1 -0
  17. package/dist/lib-cjs/api/classes/parameter.d.ts +351 -339
  18. package/dist/lib-cjs/api/classes/parameter.js +517 -464
  19. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  20. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  21. package/dist/lib-cjs/api/classes/parameterObservable.js +72 -97
  22. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  23. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  24. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  25. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  26. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  27. package/dist/lib-cjs/api/classes/variant.d.ts +253 -234
  28. package/dist/lib-cjs/api/classes/variant.js +843 -818
  29. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -44
  31. package/dist/lib-cjs/api/classes/variantInstance.js +125 -105
  32. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  34. package/dist/lib-cjs/api/classes/variantParameterizable.js +88 -88
  35. package/dist/lib-cjs/api/classes/viewer.d.ts +199 -185
  36. package/dist/lib-cjs/api/classes/viewer.js +670 -619
  37. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  38. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  39. package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
  40. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  41. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  42. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  43. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
  44. package/dist/lib-cjs/api/internal/sceneSetup.js +226 -226
  45. package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
  46. package/dist/lib-cjs/api/manager/animationManager.js +126 -126
  47. package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +78 -78
  49. package/dist/lib-cjs/api/manager/gltfExportManager.js +241 -241
  50. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
  51. package/dist/lib-cjs/api/manager/sceneManager.js +130 -130
  52. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  53. package/dist/lib-cjs/api/manager/tagManager.d.ts +108 -0
  54. package/dist/lib-cjs/api/manager/tagManager.js +420 -0
  55. package/dist/lib-cjs/api/manager/tagManager.js.map +1 -0
  56. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
  57. package/dist/lib-cjs/api/manager/textureLoadManager.js +97 -97
  58. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +102 -92
  59. package/dist/lib-cjs/api/manager/variantInstanceManager.js +284 -260
  60. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
  61. package/dist/lib-cjs/api/store/specStorage.d.ts +32 -24
  62. package/dist/lib-cjs/api/store/specStorage.js +65 -50
  63. package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
  64. package/dist/lib-cjs/api/util/babylonHelper.d.ts +235 -206
  65. package/dist/lib-cjs/api/util/babylonHelper.js +745 -668
  66. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  67. package/dist/lib-cjs/api/util/globalTypes.d.ts +432 -387
  68. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  69. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  70. package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
  71. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +44 -43
  72. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +173 -155
  73. package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +1 -1
  74. package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
  75. package/dist/lib-cjs/api/util/stringHelper.js +32 -32
  76. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  77. package/dist/lib-cjs/api/util/structureHelper.js +48 -48
  78. package/dist/lib-cjs/buildinfo.json +3 -3
  79. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  80. package/dist/lib-cjs/index.d.ts +53 -52
  81. package/dist/lib-cjs/index.js +114 -112
  82. package/dist/lib-cjs/index.js.map +1 -1
  83. package/package.json +81 -81
  84. package/src/api/classes/animationInterface.ts +10 -10
  85. package/src/api/classes/dottedPath.ts +181 -181
  86. package/src/api/classes/element.ts +731 -717
  87. package/src/api/classes/event.ts +452 -385
  88. package/src/api/classes/eventBroadcaster.ts +52 -52
  89. package/src/api/classes/fuzzyMap.ts +21 -0
  90. package/src/api/classes/parameter.ts +554 -497
  91. package/src/api/classes/parameterObservable.ts +73 -100
  92. package/src/api/classes/parameterizable.ts +87 -87
  93. package/src/api/classes/placementAnimation.ts +162 -162
  94. package/src/api/classes/variant.ts +933 -884
  95. package/src/api/classes/variantInstance.ts +123 -97
  96. package/src/api/classes/variantParameterizable.ts +85 -85
  97. package/src/api/classes/viewer.ts +743 -691
  98. package/src/api/classes/viewerLight.ts +339 -339
  99. package/src/api/internal/debugViewer.ts +90 -90
  100. package/src/api/internal/lensRendering.ts +9 -9
  101. package/src/api/internal/sceneSetup.ts +205 -205
  102. package/src/api/manager/animationManager.ts +143 -143
  103. package/src/api/manager/gltfExportManager.ts +236 -236
  104. package/src/api/manager/sceneManager.ts +136 -132
  105. package/src/api/manager/tagManager.ts +451 -0
  106. package/src/api/manager/textureLoadManager.ts +95 -95
  107. package/src/api/manager/variantInstanceManager.ts +297 -265
  108. package/src/api/store/specStorage.ts +68 -51
  109. package/src/api/util/babylonHelper.ts +817 -739
  110. package/src/api/util/globalTypes.ts +499 -437
  111. package/src/api/util/resourceHelper.ts +191 -191
  112. package/src/api/util/sceneLoaderHelper.ts +170 -151
  113. package/src/api/util/stringHelper.ts +30 -30
  114. package/src/api/util/structureHelper.ts +49 -49
  115. package/src/buildinfo.json +3 -3
  116. package/src/dev.ts +62 -60
  117. package/src/index.ts +100 -98
  118. package/src/types.d.ts +35 -28
@@ -1,620 +1,671 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Viewer = void 0;
16
- const buildinfo_json_1 = __importDefault(require("../../buildinfo.json"));
17
- const sceneSetup_1 = require("../internal/sceneSetup");
18
- const animationManager_1 = require("../manager/animationManager");
19
- const gltfExportManager_1 = require("../manager/gltfExportManager");
20
- const sceneManager_1 = require("../manager/sceneManager");
21
- const variantInstanceManager_1 = require("../manager/variantInstanceManager");
22
- const specStorage_1 = require("../store/specStorage");
23
- const babylonHelper_1 = require("../util/babylonHelper");
24
- const resourceHelper_1 = require("../util/resourceHelper");
25
- const sceneLoaderHelper_1 = require("../util/sceneLoaderHelper");
26
- const stringHelper_1 = require("../util/stringHelper");
27
- const structureHelper_1 = require("../util/structureHelper");
28
- const event_1 = require("./event");
29
- const eventBroadcaster_1 = require("./eventBroadcaster");
30
- const parameter_1 = require("./parameter");
31
- const variant_1 = require("./variant");
32
- const arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
33
- const boundingInfo_1 = require("@babylonjs/core/Culling/boundingInfo");
34
- const debugLayer_1 = require("@babylonjs/core/Debug/debugLayer");
35
- const engine_1 = require("@babylonjs/core/Engines/engine");
36
- const highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
37
- const sceneLoader_1 = require("@babylonjs/core/Loading/sceneLoader");
38
- const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
39
- const standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
40
- const math_color_1 = require("@babylonjs/core/Maths/math.color");
41
- const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
42
- const mesh_1 = require("@babylonjs/core/Meshes/mesh");
43
- const screenshotTools_1 = require("@babylonjs/core/Misc/screenshotTools");
44
- const webXRSessionManager_1 = require("@babylonjs/core/XR/webXRSessionManager");
45
- const lodash_es_1 = require("lodash-es");
46
- /**
47
- * The main exposed object. This is the entry point into the application
48
- *
49
- * ```js
50
- * const canvas = document.getElementById( 'babylon-canvas' );
51
- * const viewer = Viewer( canvas, '/path/to/index.json' );
52
- * ```
53
- * The class does nothing on its own and needs to {@link bootstrap}
54
- */
55
- class Viewer extends eventBroadcaster_1.EventBroadcaster {
56
- /**
57
- * Constructor
58
- */
59
- constructor(canvas, structureJson) {
60
- super();
61
- this.canvas = canvas;
62
- this.structureJson = structureJson;
63
- this._scene = null;
64
- this._animationManager = null;
65
- this._sceneManager = null;
66
- this._gltfExportManager = null;
67
- this._variantInstances = null;
68
- // default value is `true` ATM for compatibility reasons
69
- // in the future material cloning should be the edge case
70
- this._cloneMaterialsOnMutation = true;
71
- this._isRenderLoopPaused = false;
72
- this._inspectorLoaded = false;
73
- }
74
- /**
75
- * Help function for automatically creating a valid Spec from a list of variant names and dedicated GLB/Babylon URLs.
76
- * This data is most likely coming from babylon assets from the Combeenation system but other sources are also valid.
77
- */
78
- static generateSpec(genData) {
79
- // dots in the variant name indicate inheritance, but this should not be the case for an auto-generated spec
80
- // therefore dots are exchanged with slashes
81
- const safeGenData = genData.map(data => (Object.assign(Object.assign({}, data), { name: (0, stringHelper_1.replaceDots)(data.name) })));
82
- const spec = {
83
- // common scene settings as suggested in the viewer docs
84
- scene: {
85
- engine: {
86
- antialiasing: true,
87
- options: {
88
- preserveDrawingBuffer: true,
89
- stencil: true,
90
- xrCompatible: false,
91
- },
92
- },
93
- scene: {
94
- globals: {},
95
- },
96
- },
97
- setup: {
98
- // create one instance for each input entry
99
- // name and variant are named accordingly from the input, instance will be hidden by default and lazy loading
100
- // is activated
101
- instances: safeGenData.map(instanceData => ({
102
- name: instanceData.name,
103
- variant: instanceData.name,
104
- lazy: true,
105
- parameters: {
106
- [parameter_1.Parameter.VISIBLE]: false,
107
- },
108
- })),
109
- },
110
- // variants definition is also mapped to the input array, using the name as key and url as glTF source
111
- // no elements are created here, since this should be done automatically from the system
112
- // => create one element which contains all root nodes of the imported 3d file (GLB or Babylon)
113
- variants: safeGenData.reduce((accVariants, curVariant) => {
114
- accVariants[curVariant.name] = {
115
- glTF: curVariant.url,
116
- };
117
- return accVariants;
118
- }, {}),
119
- };
120
- return spec;
121
- }
122
- /**
123
- * Gets the BabylonJS Scene that is attached to the instance.
124
- *
125
- * @throws Error if the `scene` has not been initialized.
126
- */
127
- get scene() {
128
- if (!this._scene) {
129
- throw new Error(`Scene has not been initialized.`);
130
- }
131
- return this._scene;
132
- }
133
- /**
134
- * Gets the {@link SceneManager} attached to the viewer.
135
- *
136
- * @throws Error if the {@link SceneManager} has not been initialized.
137
- */
138
- get sceneManager() {
139
- if (!this._sceneManager) {
140
- throw new Error(`SceneManager has not been initialized.`);
141
- }
142
- return this._sceneManager;
143
- }
144
- /**
145
- * Gets the {@link GltfExportManager} attached to the viewer.
146
- *
147
- * @throws Error if the {@link GltfExportManager} has not been initialized.
148
- */
149
- get gltfExportManager() {
150
- if (!this._gltfExportManager) {
151
- throw new Error(`GltfExportManager has not been initialized.`);
152
- }
153
- return this._gltfExportManager;
154
- }
155
- /**
156
- * Gets the BabylonJS Engine that is attached to the viewer.
157
- */
158
- get engine() {
159
- return this.scene.getEngine();
160
- }
161
- /**
162
- * Gets the {@link VariantInstanceManager} attached to the viewer.
163
- *
164
- * @throws Error if the {@link VariantInstanceManager} has not been initialized.
165
- */
166
- get variantInstances() {
167
- if (!this._variantInstances) {
168
- throw Error(`There is no variantInstanceManager.`);
169
- }
170
- return this._variantInstances;
171
- }
172
- /**
173
- * Gets the {@link AnimationManager} attached to the viewer.
174
- *
175
- * @throws Error if the {@link AnimationManager} has not been initialized.
176
- */
177
- get animationManager() {
178
- if (!this._animationManager) {
179
- throw new Error(`There is no animationManager instance.`);
180
- }
181
- return this._animationManager;
182
- }
183
- /**
184
- * Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
185
- */
186
- get cloneMaterialsOnMutation() {
187
- return this._cloneMaterialsOnMutation;
188
- }
189
- /**
190
- * Starts the application. This will
191
- * * load the given "index" JSON file
192
- * * setup the scene with the "scene" JSON file
193
- * * create an (optional) default setup with different variant settings
194
- * * sets up resizing by attaching a debounced version of {@link resize}
195
- *
196
- * @throws Error if any of the files is not found/valid
197
- *
198
- * @emits {@link Event.BOOTSTRAP_START}
199
- * @emits {@link Event.BOOTSTRAP_END}
200
- */
201
- bootstrap() {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- this.broadcastEvent(event_1.Event.BOOTSTRAP_START, this);
204
- let indexJson;
205
- if ((0, lodash_es_1.isString)(this.structureJson)) {
206
- indexJson = yield (0, resourceHelper_1.loadJson)(this.structureJson);
207
- }
208
- else {
209
- indexJson = this.structureJson;
210
- }
211
- if (!indexJson.scene) {
212
- throw new Error(`No "scene" property found for bootstrapping.`);
213
- }
214
- // fill spec store
215
- specStorage_1.SpecStorage.createFromSpec(indexJson);
216
- this.initCbnBabylonLoaderPlugin();
217
- // load scene
218
- if ((0, lodash_es_1.isString)(indexJson.scene)) {
219
- const sceneJson = yield (0, resourceHelper_1.loadJson)(indexJson.scene);
220
- indexJson.scene = sceneJson;
221
- }
222
- this._scene = yield this.initScene();
223
- // create instance manager
224
- const rootVariant = yield variant_1.Variant.create('_', indexJson, this);
225
- this._variantInstances = yield variantInstanceManager_1.VariantInstanceManager.create(rootVariant);
226
- // create optional default instances
227
- if (indexJson.setup) {
228
- if ((0, lodash_es_1.isString)(indexJson.setup)) {
229
- const setupJson = yield (0, resourceHelper_1.loadJson)(indexJson.setup);
230
- indexJson.setup = setupJson;
231
- }
232
- yield this.createVariantInstances();
233
- }
234
- // create gltf export manager
235
- this._gltfExportManager = yield gltfExportManager_1.GltfExportManager.create(this);
236
- // resize handler
237
- window.addEventListener('resize', (0, resourceHelper_1.debounce)(this.resize.bind(this), 100));
238
- // wait until scene is completely ready
239
- yield this.scene.whenReadyAsync();
240
- // event broadcasting
241
- this.broadcastEvent(event_1.Event.BOOTSTRAP_END, this);
242
- // render loop
243
- this.engine.runRenderLoop(() => {
244
- if (!this._isRenderLoopPaused)
245
- this.scene.render();
246
- });
247
- return this;
248
- });
249
- }
250
- /**
251
- * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
252
- * Due to the additional size of the inspector, the CDN version is used instead of shipping the required code with
253
- * the viewer.\
254
- * This means that the code will be downloaded only when needed and calling `enableDebugLayer` can take a little while
255
- * depending on your internet connection etc.
256
- */
257
- enableDebugLayer(options) {
258
- return __awaiter(this, void 0, void 0, function* () {
259
- if (!this._inspectorLoaded) {
260
- // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
261
- yield (0, resourceHelper_1.loadJavascript)('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js');
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
- }
266
- yield this.scene.debugLayer.show(options);
267
- });
268
- }
269
- /**
270
- * Destroys all registered {@link VariantInstance}s that are registered
271
- */
272
- destroyVariantInstances() {
273
- this.variantInstances.all.forEach(variantInstance => {
274
- this.variantInstances.destroy(variantInstance.name);
275
- });
276
- return this;
277
- }
278
- /**
279
- * Trigger a resize event for the `Engine`
280
- */
281
- resize() {
282
- this.engine.resize();
283
- return this;
284
- }
285
- /**
286
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
287
- * {@link DottedPath}s.
288
- */
289
- getNode(variantInstanceName, elementDottedPath, nodeDottedPath) {
290
- return __awaiter(this, void 0, void 0, function* () {
291
- const variantInstance = yield this.variantInstances.get(variantInstanceName);
292
- return variantInstance.getNode(elementDottedPath, nodeDottedPath);
293
- });
294
- }
295
- /**
296
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
297
- * {@link DottedPath}s.
298
- */
299
- getMesh(variantInstanceName, elementDottedPath, meshDottedPath) {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- const variantInstance = yield this.variantInstances.get(variantInstanceName);
302
- return variantInstance.getMesh(elementDottedPath, meshDottedPath);
303
- });
304
- }
305
- /**
306
- * Switches the camera
307
- *
308
- * @emits {@link Event.CAMERA_SWITCHED}
309
- */
310
- switchCamera(newCamera, reset = true) {
311
- const camera = this.scene.getCameraByName(newCamera);
312
- if (camera) {
313
- const activeCamera = this.scene.activeCamera;
314
- if (activeCamera) {
315
- activeCamera.detachControl(this.engine.getRenderingCanvas());
316
- }
317
- if (reset) {
318
- camera.restoreState();
319
- }
320
- this.scene.setActiveCameraByName(newCamera);
321
- camera.attachControl(this.engine.getRenderingCanvas());
322
- this.broadcastEvent(event_1.Event.CAMERA_SWITCHED, camera);
323
- }
324
- else {
325
- throw new Error(`Given camera "${newCamera}" not found.`);
326
- }
327
- // TODO: put traceable observers to new camera (@see element)
328
- return this;
329
- }
330
- /**
331
- * Moves or animates the active camera to given `placement`.
332
- */
333
- moveActiveCameraTo(placement, animation) {
334
- return __awaiter(this, void 0, void 0, function* () {
335
- return this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation);
336
- });
337
- }
338
- /**
339
- * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
340
- */
341
- screenshot(settings) {
342
- return new Promise((resolve, reject) => {
343
- var _a, _b, _c, _d, _e, _f;
344
- if (!this.engine) {
345
- return reject('Engine is null');
346
- }
347
- if (!this.scene) {
348
- return reject('Scene is null');
349
- }
350
- this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
351
- 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);
352
- });
353
- }
354
- /**
355
- * Checks whether the browser is capable of handling XR.
356
- */
357
- isBrowserARCapable() {
358
- return __awaiter(this, void 0, void 0, function* () {
359
- return yield webXRSessionManager_1.WebXRSessionManager.IsSessionSupportedAsync('immersive-ar');
360
- });
361
- }
362
- /**
363
- * Calculates the bounding box from all visible meshes on the scene.
364
- */
365
- calculateBoundingBox(excludeGeometry) {
366
- return __awaiter(this, void 0, void 0, function* () {
367
- if (this.scene.meshes.length === 0) {
368
- throw new Error('There are currently no meshes on the scene.');
369
- }
370
- this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
371
- const bbName = '__bounding_box__';
372
- const { max, min } = this.scene.meshes
373
- .filter(mesh => {
374
- const isEnabled = mesh.isEnabled();
375
- // ignore the existing bounding box mesh for calculating the current one
376
- const isNotBBoxMesh = bbName !== mesh.id;
377
- // ignore meshes with invalid bounding infos
378
- const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
379
- // ignore excluded meshes
380
- const isExcluded = excludeGeometry ? (0, structureHelper_1.isMeshIncludedInExclusionList)(mesh, excludeGeometry) : false;
381
- return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !isExcluded;
382
- })
383
- .reduce((accBBoxMinMax, curMesh, idx) => {
384
- const bBox = curMesh.getBoundingInfo().boundingBox;
385
- // use the first entry in the array as default value and get the resulting maximum/minimum values
386
- const max = idx === 0 ? bBox.maximumWorld : math_vector_1.Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
387
- const min = idx === 0 ? bBox.minimumWorld : math_vector_1.Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
388
- return { max, min };
389
- }, { max: new math_vector_1.Vector3(), min: new math_vector_1.Vector3() });
390
- let boundingBox = this.scene.getMeshByName(bbName);
391
- if (!boundingBox) {
392
- boundingBox = new mesh_1.Mesh(bbName, this.scene);
393
- }
394
- boundingBox.setBoundingInfo(new boundingInfo_1.BoundingInfo(min, max));
395
- return boundingBox;
396
- });
397
- }
398
- /**
399
- * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
400
- */
401
- autofocusActiveCamera(settings) {
402
- var _a, _b, _c, _d;
403
- return __awaiter(this, void 0, void 0, function* () {
404
- // first check some preconditions
405
- const activeCamera = this.scene.activeCamera;
406
- if (!activeCamera) {
407
- throw new Error('No active camera found when using autofocus feature.');
408
- }
409
- if (!(activeCamera instanceof arcRotateCamera_1.ArcRotateCamera)) {
410
- const cameraClsName = activeCamera.getClassName();
411
- throw new Error(`Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.`);
412
- }
413
- let exclude = (settings === null || settings === void 0 ? void 0 : settings.exclude) || [];
414
- // Exclude shown photo dome or environment helper from bounding box calculation
415
- const photoDome = this.scene.getNodeByName(babylonHelper_1.backgroundDomeName);
416
- const photoDomeMeshes = photoDome === null || photoDome === void 0 ? void 0 : photoDome.getChildMeshes();
417
- if (photoDomeMeshes === null || photoDomeMeshes === void 0 ? void 0 : photoDomeMeshes.length) {
418
- exclude = [...exclude, ...photoDomeMeshes];
419
- }
420
- const envHelper = (_a = this.scene.metadata) === null || _a === void 0 ? void 0 : _a[babylonHelper_1.envHelperMetadataName];
421
- if (envHelper === null || envHelper === void 0 ? void 0 : envHelper.rootMesh) {
422
- exclude = [...exclude, envHelper.rootMesh];
423
- }
424
- // get bounding box of all visible meshes, this is the base for the autofocus algorithm
425
- const boundingBox = yield this.calculateBoundingBox(exclude);
426
- const radius = boundingBox.getBoundingInfo().boundingSphere.radius;
427
- const center = boundingBox.getBoundingInfo().boundingSphere.center;
428
- const diameter = radius * 2;
429
- // set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
430
- activeCamera.lowerRadiusLimit = radius;
431
- // additional settings
432
- // constants for division are taken directly from BabylonJS repository
433
- activeCamera.minZ = Math.min(radius / Viewer._autofocusConstants.minZ, 1);
434
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
435
- activeCamera.wheelPrecision = Viewer._autofocusConstants.wheelPrecision / radius;
436
- }
437
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
438
- activeCamera.panningSensibility = Viewer._autofocusConstants.panningSensibility / diameter;
439
- }
440
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
441
- activeCamera.pinchPrecision = Viewer._autofocusConstants.pinchPrecision / radius;
442
- }
443
- const radiusFactor = (_b = settings === null || settings === void 0 ? void 0 : settings.radiusFactor) !== null && _b !== void 0 ? _b : 1;
444
- const alpha = ((_c = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _c !== void 0 ? _c : -90) * (Math.PI / 180);
445
- const beta = ((_d = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _d !== void 0 ? _d : 90) * (Math.PI / 180);
446
- const newCameraPosition = {
447
- alpha: alpha,
448
- beta: beta,
449
- // this calculation is a bit "simplified", as it doesn't consider the viewport ratio or the frustum angle
450
- // but it's also done this way in the BabylonJs repository, so it should be fine for us
451
- radius: diameter * radiusFactor,
452
- target: center,
453
- };
454
- yield this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.animation);
455
- });
456
- }
457
- /**
458
- * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
459
- * environment
460
- */
461
- reset() {
462
- return __awaiter(this, void 0, void 0, function* () {
463
- yield this.destroy();
464
- return this.bootstrap();
465
- });
466
- }
467
- /**
468
- * Destroys
469
- *
470
- * * all {@link VariantInstance}s using {@link destroyVariantInstances}
471
- * * calling `dispose` on the `Engine` and `Scene`
472
- */
473
- destroy() {
474
- this.destroyVariantInstances();
475
- this.scene.dispose();
476
- specStorage_1.SpecStorage.destroy();
477
- return this;
478
- }
479
- /**
480
- * Show coordinate system with given dimension (for debugging purpose).
481
- */
482
- showWorldCoordinates(dimension) {
483
- const scene = this.scene;
484
- const makeTextPlane = function (text, color, size) {
485
- const dynamicTexture = new dynamicTexture_1.DynamicTexture('DynamicTexture', 50, scene, true);
486
- dynamicTexture.hasAlpha = true;
487
- dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
488
- const plane = mesh_1.Mesh.CreatePlane('TextPlane', size, scene, true);
489
- plane.material = new standardMaterial_1.StandardMaterial('TextPlaneMaterial', scene);
490
- plane.material.backFaceCulling = false;
491
- plane.material.specularColor = new math_color_1.Color3(0, 0, 0);
492
- plane.material.diffuseTexture = dynamicTexture;
493
- return plane;
494
- };
495
- const axisX = mesh_1.Mesh.CreateLines('axisX', [
496
- math_vector_1.Vector3.Zero(),
497
- new math_vector_1.Vector3(dimension, 0, 0),
498
- new math_vector_1.Vector3(dimension * 0.95, 0.05 * dimension, 0),
499
- new math_vector_1.Vector3(dimension, 0, 0),
500
- new math_vector_1.Vector3(dimension * 0.95, -0.05 * dimension, 0),
501
- ], scene, false);
502
- axisX.color = new math_color_1.Color3(1, 0, 0);
503
- const xChar = makeTextPlane('X', 'red', dimension / 10);
504
- xChar.position = new math_vector_1.Vector3(0.9 * dimension, -0.05 * dimension, 0);
505
- const axisY = mesh_1.Mesh.CreateLines('axisY', [
506
- math_vector_1.Vector3.Zero(),
507
- new math_vector_1.Vector3(0, dimension, 0),
508
- new math_vector_1.Vector3(-0.05 * dimension, dimension * 0.95, 0),
509
- new math_vector_1.Vector3(0, dimension, 0),
510
- new math_vector_1.Vector3(0.05 * dimension, dimension * 0.95, 0),
511
- ], scene, false);
512
- axisY.color = new math_color_1.Color3(0, 1, 0);
513
- const yChar = makeTextPlane('Y', 'green', dimension / 10);
514
- yChar.position = new math_vector_1.Vector3(0, 0.9 * dimension, -0.05 * dimension);
515
- const axisZ = mesh_1.Mesh.CreateLines('axisZ', [
516
- math_vector_1.Vector3.Zero(),
517
- new math_vector_1.Vector3(0, 0, dimension),
518
- new math_vector_1.Vector3(0, -0.05 * dimension, dimension * 0.95),
519
- new math_vector_1.Vector3(0, 0, dimension),
520
- new math_vector_1.Vector3(0, 0.05 * dimension, dimension * 0.95),
521
- ], scene, false);
522
- axisZ.color = new math_color_1.Color3(0, 0, 1);
523
- const zChar = makeTextPlane('Z', 'blue', dimension / 10);
524
- zChar.position = new math_vector_1.Vector3(0, 0.05 * dimension, 0.9 * dimension);
525
- }
526
- /**
527
- * Pause render loop.
528
- */
529
- pauseRendering() {
530
- this._isRenderLoopPaused = true;
531
- }
532
- /**
533
- * Resume render loop when paused.
534
- */
535
- resumeRendering() {
536
- this._isRenderLoopPaused = false;
537
- }
538
- /**
539
- * @emits {@link Event.SCENE_PROCESSING_START}
540
- * @emits {@link Event.SCENE_PROCESSING_END}
541
- */
542
- initScene() {
543
- var _a, _b, _c;
544
- return __awaiter(this, void 0, void 0, function* () {
545
- const sceneJson = specStorage_1.SpecStorage.get('scene');
546
- this.broadcastEvent(event_1.Event.SCENE_PROCESSING_START, sceneJson);
547
- const 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);
548
- const scene = yield (0, sceneSetup_1.sceneSetup)(engine, sceneJson);
549
- if (sceneJson.meshPicking) {
550
- new highlightLayer_1.HighlightLayer('default', scene);
551
- scene.onPointerPick = (pointerEvent, pickInfo) => {
552
- if (!pickInfo.hit) {
553
- return;
554
- }
555
- const mesh = pickInfo.pickedMesh;
556
- 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);
557
- if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element) {
558
- this.broadcastEvent(event_1.Event.ELEMENT_PICKED, mesh.metadata.element);
559
- }
560
- if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant) {
561
- if (mesh.metadata.variant.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
562
- mesh.metadata.variant.toggleHighlight();
563
- }
564
- this.broadcastEvent(event_1.Event.VARIANT_PICKED, mesh.metadata.variant);
565
- }
566
- };
567
- }
568
- this._sceneManager = yield sceneManager_1.SceneManager.create(scene);
569
- this._animationManager = yield animationManager_1.AnimationManager.create(scene);
570
- if (sceneJson.cloneMaterialsOnMutation !== undefined) {
571
- this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
572
- }
573
- this.broadcastEvent(event_1.Event.SCENE_PROCESSING_END, scene);
574
- return scene;
575
- });
576
- }
577
- /**
578
- * Register custom file loader for babylon files which adds "missing-material" metadata to meshes which reference
579
- * materials that are not present in the `materials` section of the given babylon file.
580
- *
581
- * Required for babylon files & materials loaded from "Combeenation configurator assets".
582
- */
583
- initCbnBabylonLoaderPlugin() {
584
- const previousLoaderPlugin = sceneLoader_1.SceneLoader.GetPluginForExtension('babylon');
585
- const customLoaderPlugin = (0, sceneLoaderHelper_1.getCustomCbnBabylonLoaderPlugin)(previousLoaderPlugin);
586
- sceneLoader_1.SceneLoader.RegisterPlugin(customLoaderPlugin);
587
- }
588
- /**
589
- * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
590
- */
591
- createVariantInstances() {
592
- var _a;
593
- return __awaiter(this, void 0, void 0, function* () {
594
- const setupJson = specStorage_1.SpecStorage.get('setup');
595
- const instances = [];
596
- for (const instanceDefinition of setupJson.instances) {
597
- // don't create the instance right away if `lazy` is set, register it for later creation (on first usage) instead
598
- // however if the variant should be `visible` by default, `lazy` loading doesn't make sense and should therefore
599
- // be overruled by the `visible` flag
600
- if (instanceDefinition.lazy && ((_a = instanceDefinition.parameters) === null || _a === void 0 ? void 0 : _a.visible) !== true) {
601
- this.variantInstances.register(instanceDefinition);
602
- continue;
603
- }
604
- instances.push(yield this.variantInstances.create(instanceDefinition.variant, instanceDefinition.name, instanceDefinition.parameters));
605
- }
606
- return instances;
607
- });
608
- }
609
- }
610
- exports.Viewer = Viewer;
611
- Viewer.version = buildinfo_json_1.default.version;
612
- // these are constants for calculating the camera settings, depending on the bounding box size of the meshes to zoom
613
- // the algorithms and constant values are directly taken from the BabylonJS repository
614
- Viewer._autofocusConstants = {
615
- minZ: 100,
616
- wheelPrecision: 100,
617
- panningSensibility: 5000,
618
- pinchPrecision: 200,
619
- };
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Viewer = void 0;
16
+ const buildinfo_json_1 = __importDefault(require("../../buildinfo.json"));
17
+ const sceneSetup_1 = require("../internal/sceneSetup");
18
+ const animationManager_1 = require("../manager/animationManager");
19
+ const gltfExportManager_1 = require("../manager/gltfExportManager");
20
+ const sceneManager_1 = require("../manager/sceneManager");
21
+ const tagManager_1 = require("../manager/tagManager");
22
+ const variantInstanceManager_1 = require("../manager/variantInstanceManager");
23
+ const specStorage_1 = require("../store/specStorage");
24
+ const babylonHelper_1 = require("../util/babylonHelper");
25
+ const resourceHelper_1 = require("../util/resourceHelper");
26
+ const sceneLoaderHelper_1 = require("../util/sceneLoaderHelper");
27
+ const stringHelper_1 = require("../util/stringHelper");
28
+ const structureHelper_1 = require("../util/structureHelper");
29
+ const event_1 = require("./event");
30
+ const eventBroadcaster_1 = require("./eventBroadcaster");
31
+ const parameter_1 = require("./parameter");
32
+ const arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
33
+ const boundingInfo_1 = require("@babylonjs/core/Culling/boundingInfo");
34
+ const debugLayer_1 = require("@babylonjs/core/Debug/debugLayer");
35
+ const engine_1 = require("@babylonjs/core/Engines/engine");
36
+ const highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
37
+ const sceneLoader_1 = require("@babylonjs/core/Loading/sceneLoader");
38
+ const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
39
+ const standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
40
+ const math_color_1 = require("@babylonjs/core/Maths/math.color");
41
+ const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
42
+ const mesh_1 = require("@babylonjs/core/Meshes/mesh");
43
+ const screenshotTools_1 = require("@babylonjs/core/Misc/screenshotTools");
44
+ const webXRSessionManager_1 = require("@babylonjs/core/XR/webXRSessionManager");
45
+ const lodash_es_1 = require("lodash-es");
46
+ /**
47
+ * The main exposed object. This is the entry point into the application
48
+ *
49
+ * ```js
50
+ * const canvas = document.getElementById( 'babylon-canvas' );
51
+ * const viewer = Viewer( canvas, '/path/to/index.json' );
52
+ * ```
53
+ * The class does nothing on its own and needs to {@link bootstrap}
54
+ */
55
+ class Viewer extends eventBroadcaster_1.EventBroadcaster {
56
+ /**
57
+ * Constructor
58
+ */
59
+ constructor(canvas, structureJson) {
60
+ super();
61
+ this.canvas = canvas;
62
+ this.structureJson = structureJson;
63
+ this._scene = null;
64
+ this._animationManager = null;
65
+ this._sceneManager = null;
66
+ this._tagManager = null;
67
+ this._gltfExportManager = null;
68
+ this._variantInstances = null;
69
+ // defaults to `false` as material cloning should be the edge case
70
+ this._cloneMaterialsOnMutation = false;
71
+ this._isRenderLoopPaused = false;
72
+ this._inspectorLoaded = false;
73
+ this._nodeNamingStrategyHandler = null;
74
+ this._tagManager = new tagManager_1.TagManager(this);
75
+ this._nodeNamingStrategyHandler = (node, payload) => {
76
+ var _a;
77
+ const suffix = [];
78
+ if (payload.variant.elements.length > 0) {
79
+ const nodeElements = payload.variant.elements.filter(e => e.nodesFlat.filter(n => { var _a, _b; return ((_b = (_a = n.metadata) === null || _a === void 0 ? void 0 : _a.cloneSource) === null || _b === void 0 ? void 0 : _b.id) === node.id; }).length > 0);
80
+ if (nodeElements.length > 0) {
81
+ suffix.push(payload.variantParameterizable.name);
82
+ }
83
+ }
84
+ const variantInstances = this.variantInstances.allWithVariantName(payload.variant.name);
85
+ if (variantInstances.length > 0) {
86
+ suffix.push(payload.variantInstance.name);
87
+ }
88
+ const originalName = ((_a = node.metadata) === null || _a === void 0 ? void 0 : _a.originalName) || node.name;
89
+ return [originalName, ...suffix.filter(s => !!s)].join('.');
90
+ };
91
+ }
92
+ /**
93
+ * Help function for automatically creating a valid Spec from a list of variant names and dedicated GLB/babylon URLs.
94
+ * This data is most likely coming from babylon assets from the Combeenation system but other sources are also valid.
95
+ */
96
+ static generateSpec(genData) {
97
+ // dots in the variant name indicate inheritance, but this should not be the case for an auto-generated spec
98
+ // therefore dots are exchanged with slashes
99
+ const safeGenData = genData.map(data => (Object.assign(Object.assign({}, data), { name: (0, stringHelper_1.replaceDots)(data.name) })));
100
+ const spec = {
101
+ // common scene settings as suggested in the viewer docs
102
+ scene: {
103
+ engine: {
104
+ antialiasing: true,
105
+ options: {
106
+ preserveDrawingBuffer: true,
107
+ stencil: true,
108
+ xrCompatible: false,
109
+ },
110
+ },
111
+ scene: {
112
+ globals: {},
113
+ },
114
+ },
115
+ setup: {
116
+ // create one instance for each input entry
117
+ // name and variant are named accordingly from the input, instance will be hidden by default and lazy loading
118
+ // is activated
119
+ instances: safeGenData.map(instanceData => ({
120
+ name: instanceData.name,
121
+ variant: instanceData.name,
122
+ lazy: true,
123
+ parameters: {
124
+ [parameter_1.Parameter.VISIBLE]: false,
125
+ },
126
+ })),
127
+ },
128
+ // variants definition is also mapped to the input array, using the name as key and url as glTF source
129
+ // no elements are created here, since this should be done automatically from the system
130
+ // => create one element which contains all root nodes of the imported 3d file (GLB or babylon)
131
+ variants: safeGenData.reduce((accVariants, curVariant) => {
132
+ accVariants[curVariant.name] = {
133
+ glTF: curVariant.url,
134
+ };
135
+ return accVariants;
136
+ }, {}),
137
+ };
138
+ return spec;
139
+ }
140
+ /**
141
+ * Gets the Babylon.js Scene that is attached to the instance.
142
+ *
143
+ * @throws Error if the `scene` has not been initialized.
144
+ */
145
+ get scene() {
146
+ if (!this._scene) {
147
+ throw new Error(`Scene has not been initialized.`);
148
+ }
149
+ return this._scene;
150
+ }
151
+ /**
152
+ * Gets the {@link SceneManager} attached to the viewer.
153
+ *
154
+ * @throws Error if the {@link SceneManager} has not been initialized.
155
+ */
156
+ get sceneManager() {
157
+ if (!this._sceneManager) {
158
+ throw new Error(`SceneManager has not been initialized.`);
159
+ }
160
+ return this._sceneManager;
161
+ }
162
+ /**
163
+ * Gets the {@link GltfExportManager} attached to the viewer.
164
+ *
165
+ * @throws Error if the {@link GltfExportManager} has not been initialized.
166
+ */
167
+ get gltfExportManager() {
168
+ if (!this._gltfExportManager) {
169
+ throw new Error(`GltfExportManager has not been initialized.`);
170
+ }
171
+ return this._gltfExportManager;
172
+ }
173
+ /**
174
+ * Gets the Babylon.js Engine that is attached to the viewer.
175
+ */
176
+ get engine() {
177
+ return this.scene.getEngine();
178
+ }
179
+ /**
180
+ * Gets the {@link VariantInstanceManager} attached to the viewer.
181
+ *
182
+ * @throws Error if the {@link VariantInstanceManager} has not been initialized.
183
+ */
184
+ get variantInstances() {
185
+ if (!this._variantInstances) {
186
+ throw Error(`There is no variantInstanceManager.`);
187
+ }
188
+ return this._variantInstances;
189
+ }
190
+ /**
191
+ * Gets the {@link AnimationManager} attached to the viewer.
192
+ *
193
+ * @throws Error if the {@link AnimationManager} has not been initialized.
194
+ */
195
+ get animationManager() {
196
+ if (!this._animationManager) {
197
+ throw new Error(`There is no animationManager instance.`);
198
+ }
199
+ return this._animationManager;
200
+ }
201
+ get tagManager() {
202
+ if (!this._tagManager) {
203
+ throw new Error(`There is no tagManager instance.`);
204
+ }
205
+ return this._tagManager;
206
+ }
207
+ /**
208
+ * Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
209
+ */
210
+ get cloneMaterialsOnMutation() {
211
+ return this._cloneMaterialsOnMutation;
212
+ }
213
+ /**
214
+ * Gets the strategy handler for naming cloned nodes.
215
+ */
216
+ get nodeNamingStrategyHandler() {
217
+ if (!this._nodeNamingStrategyHandler) {
218
+ throw new Error(`The NodeNamingStrategyHandler has not been registered yet.`);
219
+ }
220
+ return this._nodeNamingStrategyHandler;
221
+ }
222
+ /**
223
+ * Sets the strategy handler for naming cloned nodes.\
224
+ * Check the docs of the tag managers [renaming](https://3dviewer.docs.combeenation.com/pages/documentation/Tag-Manager.html#uniqueness-of-node-and-tag-names)
225
+ * chapter for further details.
226
+ */
227
+ set nodeNamingStrategyHandler(value) {
228
+ if (!value || typeof value !== 'function') {
229
+ throw new Error(`The NodeNamingStrategyHandler is not a callable function.`);
230
+ }
231
+ this._nodeNamingStrategyHandler = value;
232
+ }
233
+ /**
234
+ * Starts the application. This will
235
+ * * load the given "index" JSON file
236
+ * * setup the scene with the "scene" JSON file
237
+ * * create an (optional) default setup with different variant settings
238
+ * * sets up resizing by attaching a debounced version of {@link resize}
239
+ *
240
+ * @throws Error if any of the files is not found/valid
241
+ *
242
+ * @emits {@link Event.BOOTSTRAP_START}
243
+ * @emits {@link Event.BOOTSTRAP_END}
244
+ */
245
+ bootstrap(tagManagerParameterValues) {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ this.broadcastEvent(event_1.Event.BOOTSTRAP_START, this);
248
+ let indexJson;
249
+ if ((0, lodash_es_1.isString)(this.structureJson)) {
250
+ indexJson = yield (0, resourceHelper_1.loadJson)(this.structureJson);
251
+ }
252
+ else {
253
+ indexJson = this.structureJson;
254
+ }
255
+ if (!indexJson.scene) {
256
+ throw new Error(`No "scene" property found for bootstrapping.`);
257
+ }
258
+ // fill spec store
259
+ specStorage_1.SpecStorage.createFromSpec(indexJson);
260
+ // init custom loader plugin
261
+ this.initCbnBabylonLoaderPlugin();
262
+ // load scene
263
+ if ((0, lodash_es_1.isString)(indexJson.scene)) {
264
+ const sceneJson = yield (0, resourceHelper_1.loadJson)(indexJson.scene);
265
+ indexJson.scene = sceneJson;
266
+ }
267
+ this._scene = yield this.initScene();
268
+ // create instance manager
269
+ this._variantInstances = yield variantInstanceManager_1.VariantInstanceManager.create(this);
270
+ // create optional default instances
271
+ if (indexJson.setup) {
272
+ if ((0, lodash_es_1.isString)(indexJson.setup)) {
273
+ const setupJson = yield (0, resourceHelper_1.loadJson)(indexJson.setup);
274
+ indexJson.setup = setupJson;
275
+ }
276
+ yield this.createVariantInstances();
277
+ }
278
+ this.broadcastEvent(event_1.Event.VARIANT_INSTANCES_READY, this);
279
+ // create gltf export manager
280
+ this._gltfExportManager = yield gltfExportManager_1.GltfExportManager.create(this);
281
+ // resize handler
282
+ window.addEventListener('resize', (0, resourceHelper_1.debounce)(this.resize.bind(this), 100));
283
+ // wait until scene is completely ready
284
+ yield this.scene.whenReadyAsync();
285
+ // set tag manager values
286
+ if (tagManagerParameterValues) {
287
+ yield this.tagManager.setParameterValues(tagManagerParameterValues);
288
+ }
289
+ // event broadcasting
290
+ this.broadcastEvent(event_1.Event.BOOTSTRAP_END, this);
291
+ // render loop
292
+ this.engine.runRenderLoop(() => {
293
+ if (!this._isRenderLoopPaused)
294
+ this.scene.render();
295
+ });
296
+ return this;
297
+ });
298
+ }
299
+ /**
300
+ * Enables the Babylon.js [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
301
+ * Due to the additional size of the inspector, the CDN version is used instead of shipping the required code with
302
+ * the viewer.\
303
+ * This means that the code will be downloaded only when needed and calling `enableDebugLayer` can take a little while
304
+ * depending on your internet connection etc.
305
+ */
306
+ enableDebugLayer(options) {
307
+ return __awaiter(this, void 0, void 0, function* () {
308
+ if (!this._inspectorLoaded) {
309
+ // CDN version of inspector requires the Babylon.js core to be available as CDN module as well
310
+ yield (0, resourceHelper_1.loadJavascript)('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js');
311
+ debugLayer_1.DebugLayer.InspectorURL =
312
+ 'https://cdn.jsdelivr.net/npm/babylonjs-inspector@5.6.0/babylon.inspector.bundle.max.min.js';
313
+ this._inspectorLoaded = true;
314
+ }
315
+ yield this.scene.debugLayer.show(options);
316
+ });
317
+ }
318
+ /**
319
+ * Destroys all registered {@link VariantInstance}s that are registered
320
+ */
321
+ destroyVariantInstances() {
322
+ this.variantInstances.all.forEach(variantInstance => {
323
+ this.variantInstances.destroy(variantInstance.name);
324
+ });
325
+ return this;
326
+ }
327
+ /**
328
+ * Trigger a resize event for the `Engine`
329
+ */
330
+ resize() {
331
+ this.engine.resize();
332
+ return this;
333
+ }
334
+ /**
335
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
336
+ * {@link DottedPath}s.
337
+ */
338
+ getNode(variantInstanceName, elementDottedPath, nodeDottedPath) {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ const variantInstance = yield this.variantInstances.get(variantInstanceName);
341
+ return variantInstance.getNode(elementDottedPath, nodeDottedPath);
342
+ });
343
+ }
344
+ /**
345
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
346
+ * {@link DottedPath}s.
347
+ */
348
+ getMesh(variantInstanceName, elementDottedPath, meshDottedPath) {
349
+ return __awaiter(this, void 0, void 0, function* () {
350
+ const variantInstance = yield this.variantInstances.get(variantInstanceName);
351
+ return variantInstance.getMesh(elementDottedPath, meshDottedPath);
352
+ });
353
+ }
354
+ /**
355
+ * Switches the camera
356
+ *
357
+ * @emits {@link Event.CAMERA_SWITCHED}
358
+ */
359
+ switchCamera(newCamera, reset = true) {
360
+ const camera = this.scene.getCameraByName(newCamera);
361
+ if (camera) {
362
+ const activeCamera = this.scene.activeCamera;
363
+ if (activeCamera) {
364
+ activeCamera.detachControl(this.engine.getRenderingCanvas());
365
+ }
366
+ if (reset) {
367
+ camera.restoreState();
368
+ }
369
+ this.scene.setActiveCameraByName(newCamera);
370
+ camera.attachControl(this.engine.getRenderingCanvas());
371
+ this.broadcastEvent(event_1.Event.CAMERA_SWITCHED, camera);
372
+ }
373
+ else {
374
+ throw new Error(`Given camera "${newCamera}" not found.`);
375
+ }
376
+ // TODO: put traceable observers to new camera (@see element)
377
+ return this;
378
+ }
379
+ /**
380
+ * Moves or animates the active camera to given `placement`.
381
+ */
382
+ moveActiveCameraTo(placement, animation) {
383
+ return __awaiter(this, void 0, void 0, function* () {
384
+ return this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation);
385
+ });
386
+ }
387
+ /**
388
+ * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
389
+ */
390
+ screenshot(settings) {
391
+ return new Promise((resolve, reject) => {
392
+ var _a, _b, _c, _d, _e, _f;
393
+ if (!this.engine) {
394
+ return reject('Engine is null');
395
+ }
396
+ if (!this.scene) {
397
+ return reject('Scene is null');
398
+ }
399
+ this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
400
+ 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);
401
+ });
402
+ }
403
+ /**
404
+ * Checks whether the browser is capable of handling XR.
405
+ */
406
+ isBrowserARCapable() {
407
+ return __awaiter(this, void 0, void 0, function* () {
408
+ return yield webXRSessionManager_1.WebXRSessionManager.IsSessionSupportedAsync('immersive-ar');
409
+ });
410
+ }
411
+ /**
412
+ * Calculates the bounding box from all visible meshes on the scene.
413
+ */
414
+ calculateBoundingBox(excludeGeometry) {
415
+ return __awaiter(this, void 0, void 0, function* () {
416
+ if (this.scene.meshes.length === 0) {
417
+ throw new Error('There are currently no meshes on the scene.');
418
+ }
419
+ this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
420
+ const bbName = '__bounding_box__';
421
+ const { max, min } = this.scene.meshes
422
+ .filter(mesh => {
423
+ const isEnabled = mesh.isEnabled();
424
+ // ignore the existing bounding box mesh for calculating the current one
425
+ const isNotBBoxMesh = bbName !== mesh.id;
426
+ // ignore meshes with invalid bounding infos
427
+ const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
428
+ // ignore excluded meshes
429
+ const isExcluded = excludeGeometry ? (0, structureHelper_1.isMeshIncludedInExclusionList)(mesh, excludeGeometry) : false;
430
+ return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !isExcluded;
431
+ })
432
+ .reduce((accBBoxMinMax, curMesh, idx) => {
433
+ const bBox = curMesh.getBoundingInfo().boundingBox;
434
+ // use the first entry in the array as default value and get the resulting maximum/minimum values
435
+ const max = idx === 0 ? bBox.maximumWorld : math_vector_1.Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
436
+ const min = idx === 0 ? bBox.minimumWorld : math_vector_1.Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
437
+ return { max, min };
438
+ }, { max: new math_vector_1.Vector3(), min: new math_vector_1.Vector3() });
439
+ let boundingBox = this.scene.getMeshByName(bbName);
440
+ if (!boundingBox) {
441
+ boundingBox = new mesh_1.Mesh(bbName, this.scene);
442
+ }
443
+ boundingBox.setBoundingInfo(new boundingInfo_1.BoundingInfo(min, max));
444
+ return boundingBox;
445
+ });
446
+ }
447
+ /**
448
+ * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
449
+ */
450
+ autofocusActiveCamera(settings) {
451
+ var _a, _b, _c, _d;
452
+ return __awaiter(this, void 0, void 0, function* () {
453
+ // first check some preconditions
454
+ const activeCamera = this.scene.activeCamera;
455
+ if (!activeCamera) {
456
+ throw new Error('No active camera found when using autofocus feature.');
457
+ }
458
+ if (!(activeCamera instanceof arcRotateCamera_1.ArcRotateCamera)) {
459
+ const cameraClsName = activeCamera.getClassName();
460
+ throw new Error(`Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.`);
461
+ }
462
+ let exclude = (settings === null || settings === void 0 ? void 0 : settings.exclude) || [];
463
+ // Exclude shown photo dome or environment helper from bounding box calculation
464
+ const photoDome = this.scene.getNodeByName(babylonHelper_1.backgroundDomeName);
465
+ const photoDomeMeshes = photoDome === null || photoDome === void 0 ? void 0 : photoDome.getChildMeshes();
466
+ if (photoDomeMeshes === null || photoDomeMeshes === void 0 ? void 0 : photoDomeMeshes.length) {
467
+ exclude = [...exclude, ...photoDomeMeshes];
468
+ }
469
+ const envHelper = (_a = this.scene.metadata) === null || _a === void 0 ? void 0 : _a[babylonHelper_1.envHelperMetadataName];
470
+ if (envHelper === null || envHelper === void 0 ? void 0 : envHelper.rootMesh) {
471
+ exclude = [...exclude, envHelper.rootMesh];
472
+ }
473
+ // get bounding box of all visible meshes, this is the base for the autofocus algorithm
474
+ const boundingBox = yield this.calculateBoundingBox(exclude);
475
+ const radius = boundingBox.getBoundingInfo().boundingSphere.radius;
476
+ const center = boundingBox.getBoundingInfo().boundingSphere.center;
477
+ const diameter = radius * 2;
478
+ // set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
479
+ activeCamera.lowerRadiusLimit = radius;
480
+ // additional settings
481
+ // constants for division are taken directly from Babylon.js repository
482
+ activeCamera.minZ = Math.min(radius / Viewer._autofocusConstants.minZ, 1);
483
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
484
+ activeCamera.wheelPrecision = Viewer._autofocusConstants.wheelPrecision / radius;
485
+ }
486
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
487
+ activeCamera.panningSensibility = Viewer._autofocusConstants.panningSensibility / diameter;
488
+ }
489
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
490
+ activeCamera.pinchPrecision = Viewer._autofocusConstants.pinchPrecision / radius;
491
+ }
492
+ const radiusFactor = (_b = settings === null || settings === void 0 ? void 0 : settings.radiusFactor) !== null && _b !== void 0 ? _b : 1.5;
493
+ const alpha = ((_c = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _c !== void 0 ? _c : -90) * (Math.PI / 180);
494
+ const beta = ((_d = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _d !== void 0 ? _d : 90) * (Math.PI / 180);
495
+ const newCameraPosition = {
496
+ alpha: alpha,
497
+ beta: beta,
498
+ // this calculation is a bit "simplified", as it doesn't consider the viewport ratio or the frustum angle
499
+ // but it's also done this way in the Babylon.js repository, so it should be fine for us
500
+ radius: diameter * radiusFactor,
501
+ target: center,
502
+ };
503
+ yield this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.animation);
504
+ });
505
+ }
506
+ /**
507
+ * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
508
+ * environment
509
+ */
510
+ reset() {
511
+ return __awaiter(this, void 0, void 0, function* () {
512
+ yield this.destroy();
513
+ return this.bootstrap();
514
+ });
515
+ }
516
+ /**
517
+ * Destroys
518
+ *
519
+ * * all {@link VariantInstance}s using {@link destroyVariantInstances}
520
+ * * calling `dispose` on the `Engine` and `Scene`
521
+ */
522
+ destroy() {
523
+ this.destroyVariantInstances();
524
+ this.scene.dispose();
525
+ specStorage_1.SpecStorage.destroy();
526
+ return this;
527
+ }
528
+ /**
529
+ * Show coordinate system with given dimension (for debugging purpose).
530
+ */
531
+ showWorldCoordinates(dimension) {
532
+ const scene = this.scene;
533
+ const makeTextPlane = function (text, color, size) {
534
+ const dynamicTexture = new dynamicTexture_1.DynamicTexture('DynamicTexture', 50, scene, true);
535
+ dynamicTexture.hasAlpha = true;
536
+ dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
537
+ const plane = mesh_1.Mesh.CreatePlane('TextPlane', size, scene, true);
538
+ plane.material = new standardMaterial_1.StandardMaterial('TextPlaneMaterial', scene);
539
+ plane.material.backFaceCulling = false;
540
+ plane.material.specularColor = new math_color_1.Color3(0, 0, 0);
541
+ plane.material.diffuseTexture = dynamicTexture;
542
+ return plane;
543
+ };
544
+ const axisX = mesh_1.Mesh.CreateLines('axisX', [
545
+ math_vector_1.Vector3.Zero(),
546
+ new math_vector_1.Vector3(dimension, 0, 0),
547
+ new math_vector_1.Vector3(dimension * 0.95, 0.05 * dimension, 0),
548
+ new math_vector_1.Vector3(dimension, 0, 0),
549
+ new math_vector_1.Vector3(dimension * 0.95, -0.05 * dimension, 0),
550
+ ], scene, false);
551
+ axisX.color = new math_color_1.Color3(1, 0, 0);
552
+ const xChar = makeTextPlane('X', 'red', dimension / 10);
553
+ xChar.position = new math_vector_1.Vector3(0.9 * dimension, -0.05 * dimension, 0);
554
+ const axisY = mesh_1.Mesh.CreateLines('axisY', [
555
+ math_vector_1.Vector3.Zero(),
556
+ new math_vector_1.Vector3(0, dimension, 0),
557
+ new math_vector_1.Vector3(-0.05 * dimension, dimension * 0.95, 0),
558
+ new math_vector_1.Vector3(0, dimension, 0),
559
+ new math_vector_1.Vector3(0.05 * dimension, dimension * 0.95, 0),
560
+ ], scene, false);
561
+ axisY.color = new math_color_1.Color3(0, 1, 0);
562
+ const yChar = makeTextPlane('Y', 'green', dimension / 10);
563
+ yChar.position = new math_vector_1.Vector3(0, 0.9 * dimension, -0.05 * dimension);
564
+ const axisZ = mesh_1.Mesh.CreateLines('axisZ', [
565
+ math_vector_1.Vector3.Zero(),
566
+ new math_vector_1.Vector3(0, 0, dimension),
567
+ new math_vector_1.Vector3(0, -0.05 * dimension, dimension * 0.95),
568
+ new math_vector_1.Vector3(0, 0, dimension),
569
+ new math_vector_1.Vector3(0, 0.05 * dimension, dimension * 0.95),
570
+ ], scene, false);
571
+ axisZ.color = new math_color_1.Color3(0, 0, 1);
572
+ const zChar = makeTextPlane('Z', 'blue', dimension / 10);
573
+ zChar.position = new math_vector_1.Vector3(0, 0.05 * dimension, 0.9 * dimension);
574
+ }
575
+ /**
576
+ * Pause render loop.
577
+ */
578
+ pauseRendering() {
579
+ this._isRenderLoopPaused = true;
580
+ }
581
+ /**
582
+ * Resume render loop when paused.
583
+ */
584
+ resumeRendering() {
585
+ this._isRenderLoopPaused = false;
586
+ }
587
+ /**
588
+ * @emits {@link Event.SCENE_PROCESSING_START}
589
+ * @emits {@link Event.SCENE_PROCESSING_END}
590
+ */
591
+ initScene() {
592
+ var _a, _b, _c;
593
+ return __awaiter(this, void 0, void 0, function* () {
594
+ const sceneJson = specStorage_1.SpecStorage.get('scene');
595
+ this.broadcastEvent(event_1.Event.SCENE_PROCESSING_START, sceneJson);
596
+ const 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);
597
+ const scene = yield (0, sceneSetup_1.sceneSetup)(engine, sceneJson);
598
+ if (sceneJson.meshPicking) {
599
+ new highlightLayer_1.HighlightLayer('default', scene);
600
+ scene.onPointerPick = (pointerEvent, pickInfo) => {
601
+ if (!pickInfo.hit) {
602
+ return;
603
+ }
604
+ const mesh = pickInfo.pickedMesh;
605
+ 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);
606
+ if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element) {
607
+ this.broadcastEvent(event_1.Event.ELEMENT_PICKED, mesh.metadata.element);
608
+ }
609
+ if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant) {
610
+ if (mesh.metadata.variant.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
611
+ mesh.metadata.variant.toggleHighlight();
612
+ }
613
+ this.broadcastEvent(event_1.Event.VARIANT_PICKED, mesh.metadata.variant);
614
+ }
615
+ };
616
+ }
617
+ this._sceneManager = yield sceneManager_1.SceneManager.create(scene);
618
+ this._animationManager = yield animationManager_1.AnimationManager.create(scene);
619
+ if (sceneJson.cloneMaterialsOnMutation !== undefined) {
620
+ this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
621
+ }
622
+ // register observers for tag manager
623
+ this.tagManager.registerNewTransformNodeObservers(scene);
624
+ this.broadcastEvent(event_1.Event.SCENE_PROCESSING_END, scene);
625
+ return scene;
626
+ });
627
+ }
628
+ /**
629
+ * Register custom file loader for babylon files which adds "missing-material" metadata to meshes which reference
630
+ * materials that are not present in the `materials` section of the given babylon file.
631
+ *
632
+ * Required for babylon files & materials loaded from "Combeenation configurator assets".
633
+ */
634
+ initCbnBabylonLoaderPlugin() {
635
+ const previousLoaderPlugin = sceneLoader_1.SceneLoader.GetPluginForExtension('babylon');
636
+ const customLoaderPlugin = (0, sceneLoaderHelper_1.getCustomCbnBabylonLoaderPlugin)(previousLoaderPlugin);
637
+ sceneLoader_1.SceneLoader.RegisterPlugin(customLoaderPlugin);
638
+ }
639
+ /**
640
+ * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
641
+ */
642
+ createVariantInstances() {
643
+ var _a;
644
+ return __awaiter(this, void 0, void 0, function* () {
645
+ const setupJson = specStorage_1.SpecStorage.get('setup');
646
+ const instances = [];
647
+ for (const instanceDefinition of setupJson.instances) {
648
+ // don't create the instance right away if `lazy` is set, register it for later creation (on first usage) instead
649
+ // however if the variant should be `visible` by default, `lazy` loading doesn't make sense and should therefore
650
+ // be overruled by the `visible` flag
651
+ if (instanceDefinition.lazy && ((_a = instanceDefinition.parameters) === null || _a === void 0 ? void 0 : _a.visible) !== true) {
652
+ this.variantInstances.register(instanceDefinition);
653
+ continue;
654
+ }
655
+ instances.push(yield this.variantInstances.create(instanceDefinition.variant, instanceDefinition.name, instanceDefinition.parameters));
656
+ }
657
+ return instances;
658
+ });
659
+ }
660
+ }
661
+ exports.Viewer = Viewer;
662
+ Viewer.version = buildinfo_json_1.default.version;
663
+ // these are constants for calculating the camera settings, depending on the bounding box size of the meshes to zoom
664
+ // the algorithms and constant values are directly taken from the Babylon.js repository
665
+ Viewer._autofocusConstants = {
666
+ minZ: 100,
667
+ wheelPrecision: 100,
668
+ panningSensibility: 5000,
669
+ pinchPrecision: 200,
670
+ };
620
671
  //# sourceMappingURL=viewer.js.map