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