@combeenation/3d-viewer 7.1.1 → 7.1.2

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