@combeenation/3d-viewer 7.0.0 → 7.1.0

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