@combeenation/3d-viewer 14.0.1-rc1 → 15.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.
- package/README.md +9 -9
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +51 -62
- package/dist/lib-cjs/index.js +84 -94
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
- package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
- package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js.map +1 -1
- package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
- package/dist/lib-cjs/internal/cloning-helper.js +163 -163
- package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
- package/dist/lib-cjs/internal/device-helper.js +24 -24
- package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
- package/dist/lib-cjs/internal/geometry-helper.js +145 -145
- package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
- package/dist/lib-cjs/internal/metadata-helper.js +50 -50
- package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
- package/dist/lib-cjs/internal/paintable-helper.js +234 -286
- package/dist/lib-cjs/internal/paintable-helper.js.map +1 -1
- package/dist/lib-cjs/internal/svg-helper.d.ts +4 -0
- package/dist/lib-cjs/internal/svg-helper.js +67 -0
- package/dist/lib-cjs/internal/svg-helper.js.map +1 -0
- package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
- package/dist/lib-cjs/internal/tags-helper.js +39 -37
- package/dist/lib-cjs/internal/tags-helper.js.map +1 -1
- package/dist/lib-cjs/internal/texture-parameter-helper.d.ts +37 -0
- package/dist/lib-cjs/internal/texture-parameter-helper.js +287 -0
- package/dist/lib-cjs/internal/texture-parameter-helper.js.map +1 -0
- package/dist/lib-cjs/manager/camera-manager.d.ts +110 -110
- package/dist/lib-cjs/manager/camera-manager.js +209 -206
- package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
- package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
- package/dist/lib-cjs/manager/debug-manager.js +217 -217
- package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
- package/dist/lib-cjs/manager/event-manager.js +71 -71
- package/dist/lib-cjs/manager/gltf-export-manager.d.ts +75 -84
- package/dist/lib-cjs/manager/gltf-export-manager.js +286 -290
- package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
- package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
- package/dist/lib-cjs/manager/material-manager.js +125 -125
- package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
- package/dist/lib-cjs/manager/model-manager.js +382 -382
- package/dist/lib-cjs/manager/parameter-manager.d.ts +228 -210
- package/dist/lib-cjs/manager/parameter-manager.js +573 -514
- package/dist/lib-cjs/manager/parameter-manager.js.map +1 -1
- package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
- package/dist/lib-cjs/manager/scene-manager.js +64 -64
- package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
- package/dist/lib-cjs/manager/texture-manager.js +43 -43
- package/dist/lib-cjs/viewer-error.d.ts +49 -48
- package/dist/lib-cjs/viewer-error.js +61 -60
- package/dist/lib-cjs/viewer-error.js.map +1 -1
- package/dist/lib-cjs/viewer.d.ts +115 -115
- package/dist/lib-cjs/viewer.js +217 -217
- package/dist/lib-cjs/viewer.js.map +1 -1
- package/package.json +94 -91
- package/src/buildinfo.json +3 -3
- package/src/dev.ts +47 -47
- package/src/global-types.d.ts +39 -39
- package/src/index.ts +71 -81
- package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
- package/src/internal/cloning-helper.ts +225 -225
- package/src/internal/device-helper.ts +25 -25
- package/src/internal/geometry-helper.ts +181 -181
- package/src/internal/metadata-helper.ts +63 -63
- package/src/internal/paintable-helper.ts +258 -310
- package/src/internal/svg-helper.ts +52 -0
- package/src/internal/tags-helper.ts +43 -41
- package/src/internal/texture-parameter-helper.ts +353 -0
- package/src/manager/camera-manager.ts +368 -365
- package/src/manager/debug-manager.ts +245 -245
- package/src/manager/event-manager.ts +72 -72
- package/src/manager/gltf-export-manager.ts +356 -357
- package/src/manager/material-manager.ts +135 -135
- package/src/manager/model-manager.ts +458 -458
- package/src/manager/parameter-manager.ts +730 -652
- package/src/manager/scene-manager.ts +101 -101
- package/src/manager/texture-manager.ts +32 -32
- package/src/viewer-error.ts +69 -68
- package/src/viewer.ts +290 -290
|
@@ -1,515 +1,574 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ParameterManager = exports.BuiltInParameter = void 0;
|
|
13
|
-
const index_1 = require("../index");
|
|
14
|
-
const metadata_helper_1 = require("../internal/metadata-helper");
|
|
15
|
-
const paintable_helper_1 = require("../internal/paintable-helper");
|
|
16
|
-
const tags_helper_1 = require("../internal/tags-helper");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
// TODO WTT: enable setting
|
|
107
|
-
/**
|
|
108
|
-
* Parses a string of format `'
|
|
109
|
-
*/
|
|
110
|
-
static
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
return
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
*
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
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
|
-
this.
|
|
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
|
-
const
|
|
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
|
-
this.setParameterObserver(exports.BuiltInParameter.
|
|
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
|
-
if (
|
|
467
|
-
|
|
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
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ParameterManager = exports.LegacyParameter = exports.BuiltInParameter = void 0;
|
|
13
|
+
const index_1 = require("../index");
|
|
14
|
+
const metadata_helper_1 = require("../internal/metadata-helper");
|
|
15
|
+
const paintable_helper_1 = require("../internal/paintable-helper");
|
|
16
|
+
const tags_helper_1 = require("../internal/tags-helper");
|
|
17
|
+
const texture_parameter_helper_1 = require("../internal/texture-parameter-helper");
|
|
18
|
+
const lodash_es_1 = require("lodash-es");
|
|
19
|
+
/**
|
|
20
|
+
* Parameters with a built in observer implementation
|
|
21
|
+
*/
|
|
22
|
+
exports.BuiltInParameter = {
|
|
23
|
+
Visible: 'visible',
|
|
24
|
+
Material: 'material',
|
|
25
|
+
Position: 'position',
|
|
26
|
+
Rotation: 'rotation',
|
|
27
|
+
Scaling: 'scaling',
|
|
28
|
+
Color: 'color',
|
|
29
|
+
Roughness: 'roughness',
|
|
30
|
+
Metallic: 'metallic',
|
|
31
|
+
/**
|
|
32
|
+
* Texture parameters are always a combination of the channel (e.g. `albedoTexture`) and a sub parameter
|
|
33
|
+
* (e.g. `uScale`). Use this function to create the parameter accordingly
|
|
34
|
+
* (e.g. createTextureParameter("albedoTexture", "uScale")).
|
|
35
|
+
*/
|
|
36
|
+
createTextureParameter: (channel, parameter) => `${channel}.${parameter}`,
|
|
37
|
+
UseDetailmap: 'useDetailmap',
|
|
38
|
+
};
|
|
39
|
+
/** @ignore @deprected Use "texture parameters" {@link BuiltInParameter}.`createTextureParameter` instead */
|
|
40
|
+
exports.LegacyParameter = {
|
|
41
|
+
Paintable: 'paintable',
|
|
42
|
+
};
|
|
43
|
+
const isTagParameterSubject = (subject) => 'tagName' in subject && !!subject.tagName;
|
|
44
|
+
const isNodeParameterSubject = (subject) => 'nodeName' in subject && !!subject.nodeName;
|
|
45
|
+
const isMaterialParameterSubject = (subject) => 'materialName' in subject && !!subject.materialName;
|
|
46
|
+
class ParameterManager {
|
|
47
|
+
constructor(viewer) {
|
|
48
|
+
this.viewer = viewer;
|
|
49
|
+
this._parameterEntries = [];
|
|
50
|
+
this._parameterObserver = {};
|
|
51
|
+
this._addBuiltInParameterObservers();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parses and converts input to a boolean value, valid values are:
|
|
55
|
+
* - true / false
|
|
56
|
+
* - 1 / 0
|
|
57
|
+
*/
|
|
58
|
+
static parseBoolean(value) {
|
|
59
|
+
if (value.toString() === 'true' || value.toString() === '1') {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
else if (value.toString() === 'false' || value.toString() === '0') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
throw new index_1.ViewerError({
|
|
66
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
67
|
+
message: `Unable to parse "${value}" to a boolean`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parses and converts input to a number value
|
|
72
|
+
*/
|
|
73
|
+
static parseNumber(value) {
|
|
74
|
+
return parseFloat(value.toString());
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parses and converts input to a string value
|
|
78
|
+
*/
|
|
79
|
+
static parseString(value) {
|
|
80
|
+
return value.toString();
|
|
81
|
+
}
|
|
82
|
+
// TODO WTT: enable setting Vector3 on the input directly
|
|
83
|
+
/**
|
|
84
|
+
* Parses a string of format "(x,y,z)"" to a "Vector3".
|
|
85
|
+
*/
|
|
86
|
+
static parseVector(value) {
|
|
87
|
+
if (!(0, lodash_es_1.isString)(value)) {
|
|
88
|
+
throw new index_1.ViewerError({
|
|
89
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
90
|
+
message: `Unable to parse "${value}" to a vector: not a string`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
let cleanedValue = value.split(' ').join('');
|
|
94
|
+
if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
|
|
95
|
+
cleanedValue = cleanedValue.substring(1, cleanedValue.length - 1);
|
|
96
|
+
const [x, y, z] = cleanedValue.split(',').map(value => parseFloat(value));
|
|
97
|
+
return new index_1.Vector3(x, y, z);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new index_1.ViewerError({
|
|
101
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
102
|
+
message: `Unable to parse "${value}" to a vector: expected "(x,y,z)"`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// TODO WTT: enable setting Vector3 on the input directly (maybe quaternion as well)
|
|
107
|
+
/**
|
|
108
|
+
* Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
|
|
109
|
+
*/
|
|
110
|
+
static parseRotation(value) {
|
|
111
|
+
const rotation = ParameterManager.parseVector(value);
|
|
112
|
+
const deg2rad = (deg) => {
|
|
113
|
+
return (deg * Math.PI) / 180;
|
|
114
|
+
};
|
|
115
|
+
return rotation.set(deg2rad(rotation.x), deg2rad(rotation.y), deg2rad(rotation.z));
|
|
116
|
+
}
|
|
117
|
+
// TODO WTT: enable setting Color3 on the input directly
|
|
118
|
+
/**
|
|
119
|
+
* Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
|
|
120
|
+
*/
|
|
121
|
+
static parseColor(value) {
|
|
122
|
+
const cleanedValue = value.toString().split(' ').join('');
|
|
123
|
+
if (cleanedValue.startsWith('#')) {
|
|
124
|
+
return index_1.Color3.FromHexString(value.toString());
|
|
125
|
+
}
|
|
126
|
+
if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
|
|
127
|
+
const rgb = cleanedValue.substring(1, cleanedValue.length - 1);
|
|
128
|
+
const [r, g, b] = rgb.split(',').map(value => parseFloat(value));
|
|
129
|
+
return index_1.Color3.FromInts(r, g, b);
|
|
130
|
+
}
|
|
131
|
+
const humanReadable = (0, lodash_es_1.capitalize)(cleanedValue);
|
|
132
|
+
if (Object.prototype.hasOwnProperty.call(index_1.Color3, humanReadable)) {
|
|
133
|
+
return index_1.Color3[humanReadable]();
|
|
134
|
+
}
|
|
135
|
+
throw new index_1.ViewerError({
|
|
136
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
137
|
+
message: `Unable to parse "${value}" to a color: expected "#rrggbb", "(r,g,b)" or any human readable (e.g. Red) property implemented in Color3`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Set parameter value for a certain node and calls the corresponding observer if the value has changed
|
|
142
|
+
*
|
|
143
|
+
* @returns "true" if parameter value has changed
|
|
144
|
+
*/
|
|
145
|
+
setNodeParameterValue(nodeName, parameterName, value) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const valueChanged = this._addParameterValue({ nodeName }, parameterName, value);
|
|
148
|
+
if (valueChanged) {
|
|
149
|
+
yield this._applyParameterValue({ nodeName }, parameterName);
|
|
150
|
+
}
|
|
151
|
+
return valueChanged;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Set parameter value for a certain material and calls the corresponding observer if the value has changed
|
|
156
|
+
*
|
|
157
|
+
* @returns "true" if parameter value has changed
|
|
158
|
+
*/
|
|
159
|
+
setMaterialParameterValue(materialName, parameterName, value) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const valueChanged = this._addParameterValue({ materialName }, parameterName, value);
|
|
162
|
+
if (valueChanged) {
|
|
163
|
+
yield this._applyParameterValue({ materialName }, parameterName);
|
|
164
|
+
}
|
|
165
|
+
return valueChanged;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Set parameter value for a certain tag and calls the corresponding observer if the value has changed.\
|
|
170
|
+
* Setting a parameter value on a tag can affect multiple nodes and tags, depending which of these objects contains
|
|
171
|
+
* the desired tag.
|
|
172
|
+
*
|
|
173
|
+
* @returns "true" if parameter value has changed
|
|
174
|
+
*/
|
|
175
|
+
setTagParameterValue(tagName, parameterName, value) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
const valueChanged = this._addParameterValue({ tagName }, parameterName, value);
|
|
178
|
+
if (valueChanged) {
|
|
179
|
+
yield this._applyParameterValue({ tagName }, parameterName);
|
|
180
|
+
}
|
|
181
|
+
return valueChanged;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Set multiple parameter values simultaniously.\
|
|
186
|
+
* Tag parameters are applied before node and material parameters, node and materials are more specific and should
|
|
187
|
+
* have priority.
|
|
188
|
+
*
|
|
189
|
+
* @returns Array of parameters, which have changed values
|
|
190
|
+
*/
|
|
191
|
+
setParameterValues(values) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const parameterEntries = values.map(valueEntry => {
|
|
194
|
+
const subject = isNodeParameterSubject(valueEntry)
|
|
195
|
+
? { nodeName: valueEntry.nodeName }
|
|
196
|
+
: isMaterialParameterSubject(valueEntry)
|
|
197
|
+
? { materialName: valueEntry.materialName }
|
|
198
|
+
: { tagName: valueEntry.tagName };
|
|
199
|
+
return { subject, parameterName: valueEntry.parameterName, value: valueEntry.value, oldValue: undefined };
|
|
200
|
+
});
|
|
201
|
+
const changedParameterEntries = parameterEntries.filter(paramEntry => this._addParameterValue(paramEntry.subject, paramEntry.parameterName, paramEntry.value));
|
|
202
|
+
yield this._applyParameterValues(changedParameterEntries);
|
|
203
|
+
// convert back to original typing
|
|
204
|
+
const changedParameterValues = changedParameterEntries.map(paramEntry => {
|
|
205
|
+
return Object.assign(Object.assign({}, paramEntry.subject), { parameterName: paramEntry.parameterName, value: paramEntry.value });
|
|
206
|
+
});
|
|
207
|
+
return changedParameterValues;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* @returns desired parameter value or "undefined" if parameter entry is not available.
|
|
212
|
+
*/
|
|
213
|
+
getParameterValue(subject, parameterName) {
|
|
214
|
+
const entry = this._getEntry(subject, parameterName);
|
|
215
|
+
return entry === null || entry === void 0 ? void 0 : entry.value;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Define observer callback for certain parameter.\
|
|
219
|
+
* There can only be one observer for a certain parameter name.\
|
|
220
|
+
* Parameter observers can not be overwritten once they are defined, this also includes system observers for
|
|
221
|
+
* {@link BuiltInParameter}.
|
|
222
|
+
*/
|
|
223
|
+
setParameterObserver(parameterName, observer) {
|
|
224
|
+
if (this._parameterObserver[parameterName]) {
|
|
225
|
+
console.warn(`Observer for parameter "${parameterName}" already set`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this._parameterObserver[parameterName] = observer;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Print all parameter entries in table format into the console
|
|
232
|
+
*/
|
|
233
|
+
printAllParameters() {
|
|
234
|
+
const printable = this._parameterEntries.map(entry => (Object.assign(Object.assign({}, entry), { subject: JSON.stringify(entry.subject) })));
|
|
235
|
+
console.table(printable);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Applies all existing parameter entries to a certain "model", as defined in the {@link ModelManager}.\
|
|
239
|
+
* This can be usefull when updating the model before showing it in the scene.
|
|
240
|
+
*
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
243
|
+
applyAllParameterValuesToModel(model) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
const parameterEntriesToApply = this._parameterEntries;
|
|
246
|
+
yield this._applyParameterValues(parameterEntriesToApply, model);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Applies all parameter values which are targeting a material.\
|
|
251
|
+
* This can be usefull when updating a material definition before creating it.
|
|
252
|
+
*
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
applyParameterValuesToMaterial(material) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const tags = (0, tags_helper_1.getTags)(material);
|
|
258
|
+
const parameterEntriesToApply = [];
|
|
259
|
+
tags.forEach(tagName => {
|
|
260
|
+
const tagParamEntries = this._getEntriesOfSubject({ tagName });
|
|
261
|
+
parameterEntriesToApply.push(...tagParamEntries);
|
|
262
|
+
});
|
|
263
|
+
const materialParamEntries = this._getEntriesOfSubject({ materialName: material.id });
|
|
264
|
+
parameterEntriesToApply.push(...materialParamEntries);
|
|
265
|
+
yield this._applyParameterValues(parameterEntriesToApply);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Applies subset of texture parameter values which are targeting a certain texture channel in a material.\
|
|
270
|
+
* This can be useful when updating texture settings (e.g. uScale) before the texture is actually created.
|
|
271
|
+
*
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
applyTextureSettingsParameter(material, channel) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
const tags = (0, tags_helper_1.getTags)(material);
|
|
277
|
+
const parameterEntriesToApply = [];
|
|
278
|
+
tags.forEach(tagName => {
|
|
279
|
+
const tagParamEntries = this._getEntriesOfSubject({ tagName });
|
|
280
|
+
parameterEntriesToApply.push(...tagParamEntries);
|
|
281
|
+
});
|
|
282
|
+
const materialParamEntries = this._getEntriesOfSubject({ materialName: material.id });
|
|
283
|
+
parameterEntriesToApply.push(...materialParamEntries);
|
|
284
|
+
const textureParameterEntriesToApply = parameterEntriesToApply.filter(parameterEntry => {
|
|
285
|
+
const paramPath = parameterEntry.parameterName.split('.');
|
|
286
|
+
// find texture parameters of this channel, e.g. "albedoTexture.uScale"
|
|
287
|
+
// "image" should not be applied here as this is part of the texture initialization anyway
|
|
288
|
+
const isTextureParamOfChannel = paramPath.length === 2 && paramPath[0] === channel && paramPath[1] !== texture_parameter_helper_1.BuiltInTextureParameter.image;
|
|
289
|
+
return isTextureParamOfChannel;
|
|
290
|
+
});
|
|
291
|
+
yield this._applyParameterValues(textureParameterEntriesToApply);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @returns Desired parameter value of a certain node.
|
|
296
|
+
* Tags are considered as well but have lower priority than node parameters, as these are more specific.
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
getParameterValueOfNode(node, parameterName) {
|
|
301
|
+
const nodeParamValue = this.getParameterValue({ nodeName: node.name }, parameterName);
|
|
302
|
+
if (nodeParamValue !== undefined) {
|
|
303
|
+
return nodeParamValue;
|
|
304
|
+
}
|
|
305
|
+
const tags = (0, tags_helper_1.getTags)(node);
|
|
306
|
+
const tagParamValue = tags.reduce((accValue, curTag) => {
|
|
307
|
+
// NOTE: it is possible that values are available for multiple tags
|
|
308
|
+
// in this case the resulting parameter value is quite "random" as the last tag in the tag string of the node has
|
|
309
|
+
// priority
|
|
310
|
+
const tagParamValue = this.getParameterValue({ tagName: curTag }, parameterName);
|
|
311
|
+
return accValue !== null && accValue !== void 0 ? accValue : tagParamValue;
|
|
312
|
+
}, undefined);
|
|
313
|
+
return tagParamValue;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @returns Desired parameter value of a certain material.
|
|
317
|
+
* Tags are considered as well but have lower priority than material parameters, as these are more specific.
|
|
318
|
+
* Unused ATM, but added for consistency as counter part for {@link getParameterValueOfNode}
|
|
319
|
+
*
|
|
320
|
+
* @internal
|
|
321
|
+
*/
|
|
322
|
+
getParameterValueOfMaterial(material, parameterName) {
|
|
323
|
+
const materialParamValue = this.getParameterValue({ materialName: material.name }, parameterName);
|
|
324
|
+
if (materialParamValue !== undefined) {
|
|
325
|
+
return materialParamValue;
|
|
326
|
+
}
|
|
327
|
+
const tags = (0, tags_helper_1.getTags)(material);
|
|
328
|
+
const tagParamValue = tags.reduce((accValue, curTag) => {
|
|
329
|
+
const tagParamValue = this.getParameterValue({ tagName: curTag }, parameterName);
|
|
330
|
+
return accValue !== null && accValue !== void 0 ? accValue : tagParamValue;
|
|
331
|
+
}, undefined);
|
|
332
|
+
return tagParamValue;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Parameter observer implementation of default parameters
|
|
336
|
+
*/
|
|
337
|
+
_addBuiltInParameterObservers() {
|
|
338
|
+
this.setParameterObserver(exports.BuiltInParameter.Visible, ({ nodes, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
339
|
+
const visible = ParameterManager.parseBoolean(newValue);
|
|
340
|
+
for (const node of nodes) {
|
|
341
|
+
if (visible) {
|
|
342
|
+
// if a mesh gets visible by this operation we have to activate the assigned material which is stored in the
|
|
343
|
+
// internal metadata
|
|
344
|
+
// => consider child meshes as well (CB-10143)
|
|
345
|
+
const activatedNodes = [node, ...node.getChildMeshes(false)];
|
|
346
|
+
for (const activatedNode of activatedNodes) {
|
|
347
|
+
const deferredMaterial = (0, metadata_helper_1.getInternalMetadataValue)(activatedNode, 'deferredMaterial');
|
|
348
|
+
if (deferredMaterial) {
|
|
349
|
+
yield this.viewer.materialManager.setMaterialOnMesh(deferredMaterial,
|
|
350
|
+
// this cast is fine, as deferred material can only be set on meshes
|
|
351
|
+
activatedNode);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
node.setEnabled(true);
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
node.setEnabled(false);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
361
|
+
this.setParameterObserver(exports.BuiltInParameter.Material, ({ nodes, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
const material = ParameterManager.parseString(newValue);
|
|
363
|
+
for (const node of nodes) {
|
|
364
|
+
// NOTE: don't use node.isEnabled() as visibility observer is probably called in same cycle but later
|
|
365
|
+
// however the parameter value is already correct at this stage
|
|
366
|
+
// we have to go through all parents as well, because a parent may have been set to false, which also disables
|
|
367
|
+
// this child node
|
|
368
|
+
let curNode = node;
|
|
369
|
+
let visibleByParameter = undefined;
|
|
370
|
+
while (curNode && visibleByParameter !== false) {
|
|
371
|
+
const curNodeVisibleByParameter = this.getParameterValueOfNode(curNode, exports.BuiltInParameter.Visible);
|
|
372
|
+
if (curNodeVisibleByParameter !== undefined) {
|
|
373
|
+
visibleByParameter = curNodeVisibleByParameter;
|
|
374
|
+
}
|
|
375
|
+
curNode = curNode.parent;
|
|
376
|
+
}
|
|
377
|
+
// parameter visibility has priority, but if the visiblity is not controlled by the parameter use the plain
|
|
378
|
+
// Babylon.js isEnabled() check
|
|
379
|
+
const visible = visibleByParameter !== undefined ? ParameterManager.parseBoolean(visibleByParameter) : node.isEnabled();
|
|
380
|
+
if (visible) {
|
|
381
|
+
// TODO WTT: check mesh type and throw error if it doesn't fit
|
|
382
|
+
// think of creating a framework with type guards (isMesh, canHaveMaterial, ...) around this
|
|
383
|
+
yield this.viewer.materialManager.setMaterialOnMesh(material, node);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
(0, metadata_helper_1.setInternalMetadataValue)(node, 'deferredMaterial', material);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}));
|
|
390
|
+
this.setParameterObserver(exports.BuiltInParameter.Position, ({ nodes, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
391
|
+
const position = ParameterManager.parseVector(newValue);
|
|
392
|
+
for (const node of nodes) {
|
|
393
|
+
node.position = position;
|
|
394
|
+
}
|
|
395
|
+
}));
|
|
396
|
+
this.setParameterObserver(exports.BuiltInParameter.Rotation, ({ nodes, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
397
|
+
const rotation = ParameterManager.parseRotation(newValue);
|
|
398
|
+
for (const node of nodes) {
|
|
399
|
+
node.rotation = rotation;
|
|
400
|
+
}
|
|
401
|
+
}));
|
|
402
|
+
this.setParameterObserver(exports.BuiltInParameter.Scaling, ({ nodes, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
const scaling = ParameterManager.parseVector(newValue);
|
|
404
|
+
for (const node of nodes) {
|
|
405
|
+
node.scaling = scaling;
|
|
406
|
+
}
|
|
407
|
+
}));
|
|
408
|
+
this.setParameterObserver(exports.BuiltInParameter.Color, ({ materials, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
409
|
+
const color = ParameterManager.parseColor(newValue);
|
|
410
|
+
for (const material of materials) {
|
|
411
|
+
const materialCls = material.getClassName();
|
|
412
|
+
switch (materialCls) {
|
|
413
|
+
case 'PBRMaterial':
|
|
414
|
+
material.albedoColor = color.toLinearSpace();
|
|
415
|
+
break;
|
|
416
|
+
case 'StandardMaterial':
|
|
417
|
+
material.diffuseColor = color;
|
|
418
|
+
break;
|
|
419
|
+
default:
|
|
420
|
+
throw new Error(`Setting color for material of instance "${materialCls}" not implemented`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}));
|
|
424
|
+
this.setParameterObserver(exports.BuiltInParameter.Roughness, ({ materials, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
const roughness = ParameterManager.parseNumber(newValue);
|
|
426
|
+
for (const material of materials) {
|
|
427
|
+
const materialCls = material.getClassName();
|
|
428
|
+
switch (materialCls) {
|
|
429
|
+
case 'PBRMaterial':
|
|
430
|
+
material.roughness = roughness;
|
|
431
|
+
break;
|
|
432
|
+
case 'StandardMaterial':
|
|
433
|
+
material.roughness = roughness;
|
|
434
|
+
break;
|
|
435
|
+
default:
|
|
436
|
+
throw new Error(`Setting rougness for material of instance "${materialCls}" not implemented`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}));
|
|
440
|
+
this.setParameterObserver(exports.BuiltInParameter.Metallic, ({ materials, newValue }) => __awaiter(this, void 0, void 0, function* () {
|
|
441
|
+
const metallic = ParameterManager.parseNumber(newValue);
|
|
442
|
+
for (const material of materials) {
|
|
443
|
+
const materialCls = material.getClassName();
|
|
444
|
+
switch (materialCls) {
|
|
445
|
+
case 'PBRMaterial':
|
|
446
|
+
material.metallic = metallic;
|
|
447
|
+
break;
|
|
448
|
+
default:
|
|
449
|
+
throw new Error(`Setting metallic for material of instance "${materialCls}" not implemented`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}));
|
|
453
|
+
this.setParameterObserver(exports.LegacyParameter.Paintable, ({ newValue, materials }) => __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
(0, paintable_helper_1.paintableParameterObserver)(newValue, materials, this.viewer.scene);
|
|
455
|
+
}));
|
|
456
|
+
// texture parameter use a more generic approach (`channel`.`parameter`) and are therefore coded in a dedicated file
|
|
457
|
+
(0, texture_parameter_helper_1.createBuiltInTextureParameter)(this, this.viewer.scene);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Change parameter value in array of existing parameter entries or create a new entry
|
|
461
|
+
*
|
|
462
|
+
* @returns "true" if parameter has changed or wasn't available before
|
|
463
|
+
*/
|
|
464
|
+
_addParameterValue(subject, parameterName, value) {
|
|
465
|
+
const existingEntry = this._getEntry(subject, parameterName);
|
|
466
|
+
if ((existingEntry === null || existingEntry === void 0 ? void 0 : existingEntry.value) === value) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
if (existingEntry) {
|
|
470
|
+
existingEntry.oldValue = existingEntry.value;
|
|
471
|
+
existingEntry.value = value;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
this._parameterEntries.push({ subject, parameterName, value, oldValue: undefined });
|
|
475
|
+
}
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Call parameter observer of desired parameter which usually apply the new values to the scene.
|
|
480
|
+
*
|
|
481
|
+
* @param assetContainer Asset container in which to look for the paramter entries subjects (e.g. the nodes and
|
|
482
|
+
* materials to which the parameter values should be applied to).\
|
|
483
|
+
* Defaults to `viewer.scene`.
|
|
484
|
+
*/
|
|
485
|
+
_applyParameterValues(parameterEntries, assetContainer) {
|
|
486
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
+
const tagParamEntries = parameterEntries.filter(entry => isTagParameterSubject(entry.subject));
|
|
488
|
+
const nonTagParamEntries = parameterEntries.filter(entry => !isTagParameterSubject(entry.subject));
|
|
489
|
+
for (const entry of tagParamEntries) {
|
|
490
|
+
yield this._applyParameterValue(entry.subject, entry.parameterName, assetContainer);
|
|
491
|
+
}
|
|
492
|
+
for (const entry of nonTagParamEntries) {
|
|
493
|
+
yield this._applyParameterValue(entry.subject, entry.parameterName, assetContainer);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Call parameter observer of desired parameter
|
|
499
|
+
*
|
|
500
|
+
* @param assetContainer Optionally add an "asset container", which actually represents a model in the
|
|
501
|
+
* {@link ModelManager}. Viewer scene is used if left empty.
|
|
502
|
+
*/
|
|
503
|
+
_applyParameterValue(subject, parameterName, assetContainer) {
|
|
504
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
+
const parameterEntry = this._getEntry(subject, parameterName);
|
|
506
|
+
const observer = this._parameterObserver[parameterName];
|
|
507
|
+
if (!parameterEntry || !observer) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const nodes = this._getAffectedNodes(subject, assetContainer);
|
|
511
|
+
const materials = this._getAffectedMaterials(subject, assetContainer);
|
|
512
|
+
yield observer({
|
|
513
|
+
subject,
|
|
514
|
+
newValue: parameterEntry.value,
|
|
515
|
+
oldValue: parameterEntry.oldValue,
|
|
516
|
+
nodes,
|
|
517
|
+
materials,
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
_getAffectedMaterials(subject, assetContainer) {
|
|
522
|
+
assetContainer = assetContainer !== null && assetContainer !== void 0 ? assetContainer : this.viewer.scene;
|
|
523
|
+
let materials = [];
|
|
524
|
+
// materials have priority over tags
|
|
525
|
+
if (isMaterialParameterSubject(subject)) {
|
|
526
|
+
materials = assetContainer.materials.filter(material => material.name === subject.materialName);
|
|
527
|
+
if (materials.length > 1) {
|
|
528
|
+
console.warn(`Multiple materials for material name "${subject.materialName}" have been found`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else if (isTagParameterSubject(subject)) {
|
|
532
|
+
materials = assetContainer.materials.filter(material => (0, tags_helper_1.hasTag)(material, subject.tagName));
|
|
533
|
+
}
|
|
534
|
+
return materials;
|
|
535
|
+
}
|
|
536
|
+
_getAffectedNodes(subject, assetContainer) {
|
|
537
|
+
assetContainer = assetContainer !== null && assetContainer !== void 0 ? assetContainer : this.viewer.scene;
|
|
538
|
+
const allNodes = [...assetContainer.meshes, ...assetContainer.transformNodes];
|
|
539
|
+
let nodes = [];
|
|
540
|
+
// nodes have priority over tags
|
|
541
|
+
if (isNodeParameterSubject(subject)) {
|
|
542
|
+
nodes = allNodes.filter(node => node.name === subject.nodeName);
|
|
543
|
+
if (nodes.length > 1) {
|
|
544
|
+
console.warn(`Multiple nodes for node name "${subject.nodeName}" have been found`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else if (isTagParameterSubject(subject)) {
|
|
548
|
+
nodes = allNodes.filter(node => (0, tags_helper_1.hasTag)(node, subject.tagName));
|
|
549
|
+
}
|
|
550
|
+
return nodes;
|
|
551
|
+
}
|
|
552
|
+
_getEntry(subject, parameterName) {
|
|
553
|
+
const entriesOfSubject = this._getEntriesOfSubject(subject);
|
|
554
|
+
const entry = entriesOfSubject.find(entry => entry.parameterName === parameterName);
|
|
555
|
+
return entry;
|
|
556
|
+
}
|
|
557
|
+
_getEntriesOfSubject(subject) {
|
|
558
|
+
const entries = this._parameterEntries.filter(entry => {
|
|
559
|
+
const nodeNameMatches = isNodeParameterSubject(entry.subject) &&
|
|
560
|
+
isNodeParameterSubject(subject) &&
|
|
561
|
+
entry.subject.nodeName === subject.nodeName;
|
|
562
|
+
const materialNameMatches = isMaterialParameterSubject(entry.subject) &&
|
|
563
|
+
isMaterialParameterSubject(subject) &&
|
|
564
|
+
entry.subject.materialName === subject.materialName;
|
|
565
|
+
const tagNameMatches = isTagParameterSubject(entry.subject) &&
|
|
566
|
+
isTagParameterSubject(subject) &&
|
|
567
|
+
entry.subject.tagName === subject.tagName;
|
|
568
|
+
return nodeNameMatches || materialNameMatches || tagNameMatches;
|
|
569
|
+
});
|
|
570
|
+
return entries;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
exports.ParameterManager = ParameterManager;
|
|
515
574
|
//# sourceMappingURL=parameter-manager.js.map
|