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