-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
786 lines (712 loc) · 26.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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
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
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>xeokit simple viewer</title>
<link href="https://xeokit.github.io/xeokit-sdk/examples/css/pageStyle.css" rel="stylesheet" />
<style>
#myNavCubeCanvas {
position: absolute;
width: 250px;
height: 250px;
bottom: 50px;
right: 10px;
z-index: 200000;
}
#treeViewContainer {
pointer-events: all;
height: 100%;
overflow-y: scroll;
overflow-x: hidden;
position: absolute;
background-color: rgba(255, 255, 255, 0.2);
color: black;
top: 0;
z-index: 200000;
float: left;
left: 0;
padding-left: 10px;
font-family: 'Roboto', sans-serif;
font-size: 15px;
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
width: 250px;
}
#treeViewContainer ul {
list-style: none;
padding-left: 1.75em;
pointer-events: none;
}
#treeViewContainer ul li {
position: relative;
width: 200px;
pointer-events: none;
padding-top: 3px;
padding-bottom: 3px;
vertical-align: middle;
}
#treeViewContainer ul li a {
background-color: #eee;
border-radius: 50%;
color: #000;
display: inline-block;
height: 1.5em;
left: -1.5em;
position: absolute;
text-align: center;
text-decoration: none;
width: 1.5em;
pointer-events: all;
}
#treeViewContainer ul li a.plus {
background-color: #ded;
pointer-events: all;
}
#treeViewContainer ul li a.minus {
background-color: #eee;
pointer-events: all;
}
#treeViewContainer ul li a:active {
top: 1px;
pointer-events: all;
}
#treeViewContainer ul li span:hover {
color: white;
cursor: pointer;
background: black;
padding-left: 2px;
pointer-events: all;
}
#treeViewContainer ul li span {
display: inline-block;
width: calc(100% - 50px);
padding-left: 2px;
pointer-events: all;
height: 23px;
}
#treeViewContainer .highlighted-node {
border: black solid 1px;
background: yellow;
color: black;
padding-left: 1px;
padding-right: 5px;
pointer-events: all;
}
.xeokit-context-menu {
font-family: 'Roboto', sans-serif;
font-size: 15px;
display: none;
z-index: 300000;
background: rgba(255, 255, 255, 0.46);
border: 1px solid black;
border-radius: 6px;
padding: 0;
width: 200px;
}
.xeokit-context-menu ul {
list-style: none;
margin-left: 0;
padding: 0;
}
.xeokit-context-menu-item {
list-style-type: none;
padding-left: 10px;
padding-right: 20px;
padding-top: 4px;
padding-bottom: 4px;
color: black;
background: rgba(255, 255, 255, 0.46);
cursor: pointer;
width: calc(100% - 30px);
}
.xeokit-context-menu-item:hover {
background: black;
color: white;
font-weight: normal;
}
.xeokit-context-menu-item span {
display: inline-block;
}
.xeokit-context-menu .disabled {
display: inline-block;
color: gray;
cursor: default;
font-weight: normal;
}
.xeokit-context-menu .disabled:hover {
color: gray;
cursor: default;
background: #eeeeee;
font-weight: normal;
}
.xeokit-context-menu-item-separator {
background: rgba(0, 0, 0, 1);
height: 1px;
width: 100%;
}
.buttons {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
margin: 0;
position: absolute;
left: 40px;
top: 40px;
}
#myNavCubeCanvas {
position: absolute;
width: 250px;
height: 250px;
bottom: 50px;
right: 10px;
z-index: 200000;
}
#footer {
position: absolute;
bottom: 0;
right: 0;
width: 100%;
padding: 5px;
text-align: right;
}
</style>
</head>
<body>
<input type="checkbox" id="info-button" />
<label for="info-button" class="info-button">
<i class="far fa-3x fa-question-circle"></i>
</label>
<canvas id="myCanvas"></canvas>
<canvas id="myNavCubeCanvas"></canvas>
<div id="stats"></div>
<div id="treeViewContainer"></div>
<div id="footer"></div>
</body>
<script type="module">
// parse query params
const urlParams = new URLSearchParams(window.location.search);
const xeokitVersion = urlParams.get('xeokit') ?? 'latest';
const xeokitUrl = `https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk@${xeokitVersion}/dist/xeokit-sdk.min.es.js`
const xeokitModelUrl = urlParams.get('url') ?? 'https://xeokit.github.io/xeokit-sdk/assets/models/xkt/v8/ifc/Schependomlaan.ifc.xkt';
const xeokitModelType = urlParams.get('type') ?? 'xkt';
const xeokitRotation = urlParams.get('rotation') ? urlParams.get('rotation').split(',').map(v => parseInt(v)) : [-90, 0, 0];
const xeokitBoundingBox = urlParams.get('boundingBox') ? urlParams.get('boundingBox') === '1' || urlParams.get('boundingBox') === 'true' : false;
const xeokitEdges = urlParams.get('edges') ? urlParams.get('edges') === '1' || urlParams.get('edges') === 'true' : true;
const xeokitColorTextureEnabled = urlParams.get('colorTextureEnabled') ? urlParams.get('colorTextureEnabled') === '1' || urlParams.get('colorTextureEnabled') === 'true' : true;
const xeokitDtxEnabled = urlParams.get('dtxEnabled') ? urlParams.get('dtxEnabled') === '1' || urlParams.get('dtxEnabled') === 'true' : true;
const xeokitTreeViewEnabled = urlParams.get('treeViewEnabled') ? urlParams.get('treeViewEnabled') === '1' || urlParams.get('treeViewEnabled') === 'true' : true;
const xeokitTransparent = urlParams.get('transparent') ? urlParams.get('transparent') === '1' || urlParams.get('transparent') === 'true' : true;
const xeokitBackfaces = urlParams.get('backfaces') ? urlParams.get('backfaces') === '1' || urlParams.get('backfaces') === 'true' : true;
const xeokitTreeViewHierarchy = urlParams.get('treeViewHierarchy') ? urlParams.get('treeViewHierarchy') : "containment"; // containment | types | storeys
const xeokitSaoEnabled = urlParams.get('saoEnabled') ? urlParams.get('saoEnabled') === '1' || urlParams.get('saoEnabled') === 'true' : true;
const xeokitFP64 = urlParams.get('fp64') ? urlParams.get('fp64') === '1' || urlParams.get('fp64') === 'true' : true;
const xeokitCacheBuster = urlParams.get('cacheBuster') ? urlParams.get('cacheBuster') === '1' || urlParams.get('cacheBuster') === 'true' : false;
// stats
const script = document.createElement('script');
script.onload = function() {
const stats = new Stats({
trackGPU: true,
trackHz: true,
trackCPT: true,
logsPerSecond: 4,
graphsPerSecond: 30,
samplesLog: 40,
samplesGraph: 100,
precision: 2,
horizontal: false,
minimal: false,
mode: 1,
});
stats.dom.style = 'position: fixed; top: 0px; right: 0px; cursor: pointer; opacity: 0.9; z-index: 10000;'
const statsElement = document.getElementById('stats');
statsElement.appendChild(stats.dom);
requestAnimationFrame(function loop() {
stats.update();
requestAnimationFrame(loop);
});
};
script.src='https://mrdoob.github.io/stats.js/build/stats.min.js';
document.head.appendChild(script);
class ImportError extends Error {}
const loadModule = async (modulePath) => {
try {
return await import(modulePath)
} catch (e) {
console.log({e});
alert(e.message);
throw new ImportError(e.message);
}
}
// xeokit
const {
Mesh,
ReadableGeometry,
PhongMaterial,
buildBoxLinesGeometryFromAABB,
NavCubePlugin,
Viewer,
XKTLoaderPlugin,
XKTDefaultDataSource,
LASLoaderPlugin,
LASDefaultDataSource,
ILASDefaultDataSourceOptions,
ILASDefaultDataSource,
OBJLoaderPlugin,
STLLoaderPlugin,
STLDefaultDataSource,
GLTFLoaderPlugin,
GLTFDefaultDataSource,
DotBIMLoaderPlugin,
DotBIMDefaultDataSource,
TreeViewPlugin,
ContextMenu,
PointerLens,
DistanceMeasurementsPlugin,
DistanceMeasurementsMouseControl,
DistanceMeasurementEditMouseControl,
os
} = await loadModule(xeokitUrl);
const viewer = new Viewer({
canvasId: "myCanvas",
transparent: xeokitTransparent,
dtxEnabled: xeokitDtxEnabled,
colorTextureEnabled: xeokitColorTextureEnabled,
});
viewer.scene.camera.eye = [26.543735598689356, 29.295147183337072, 36.20021104566069];
viewer.scene.camera.look = [-23.51624377290216, -8.263137541594404, -21.650089870476542];
viewer.scene.camera.up = [-0.2883721466119999, 0.897656342963939, -0.3332485483764247];
new NavCubePlugin(viewer, {
canvasId: "myNavCubeCanvas",
visible: true,
size: 250,
alignment: "bottomRight",
bottomMargin: 100,
rightMargin: 10
});
viewer.scene.xrayMaterial.fill = true;
viewer.scene.xrayMaterial.fillAlpha = 0.1;
viewer.scene.xrayMaterial.fillColor = [0, 0, 0];
viewer.scene.xrayMaterial.edgeAlpha = 0.3;
viewer.scene.xrayMaterial.edgeColor = [0, 0, 0];
viewer.scene.highlightMaterial.fill = true;
viewer.scene.highlightMaterial.edges = true;
viewer.scene.highlightMaterial.fillAlpha = 0.1;
viewer.scene.highlightMaterial.edgeAlpha = 0.1;
viewer.scene.highlightMaterial.edgeColor = [1, 1, 0];
viewer.scene.selectedMaterial.fill = true;
viewer.scene.selectedMaterial.edges = true;
viewer.scene.selectedMaterial.fillAlpha = 0.5;
viewer.scene.selectedMaterial.edgeAlpha = 0.6;
viewer.scene.selectedMaterial.edgeColor = [0, 1, 1];
viewer.cameraControl.navMode = "orbit";
viewer.cameraControl.followPointer = true;
const getCanvasPosFromEvent = function (event) {
const canvasPos = [];
if (!event) {
event = window.event;
canvasPos[0] = event.x;
canvasPos[1] = event.y;
} else {
let element = event.target;
let totalOffsetLeft = 0;
let totalOffsetTop = 0;
let totalScrollX = 0;
let totalScrollY = 0;
while (element.offsetParent) {
totalOffsetLeft += element.offsetLeft;
totalOffsetTop += element.offsetTop;
totalScrollX += element.scrollLeft;
totalScrollY += element.scrollTop;
element = element.offsetParent;
}
canvasPos[0] = event.pageX + totalScrollX - totalOffsetLeft;
canvasPos[1] = event.pageY + totalScrollY - totalOffsetTop;
}
return canvasPos;
};
function removeModelBoundingBox(viewer, sceneModelId) {
if (!viewer) return;
if (viewer.scene.objects[`${sceneModelId}#boundingBox`]) {
viewer.scene.objects[`${sceneModelId}#boundingBox`].destroy();
}
}
function drawModelBoundingBox(viewer, sceneModelId, aabb) {
if (!viewer) return;
if (!viewer.scene.objects[`${sceneModelId}#boundingBox`]) {
new Mesh(viewer.scene, {
id: `${sceneModelId}#boundingBox`,
isObject: true,
geometry: new ReadableGeometry(viewer.scene, buildBoxLinesGeometryFromAABB({ aabb })),
material: new PhongMaterial(viewer.scene, { ambient: [255, 0, 0] }),
});
}
}
//----------------------------------------------------------------------------------------------------------------------
// Load a BIM model comprised of multiple XKT files
// The manifest of XKT files is given in model.xkt.manifest.json
// This will create a single SceneModel and MetaModel that contains the combined content of all the XKT files
//----------------------------------------------------------------------------------------------------------------------
let loader = null;
let sceneModel = null;
if (xeokitModelType === 'xkt') {
loader = new XKTLoaderPlugin(viewer, {
dataSource: new XKTDefaultDataSource({
cacheBuster: xeokitCacheBuster,
})
});
sceneModel = loader.load({
id: "myModel",
src: xeokitModelUrl,
edges: xeokitEdges,
backfaces: xeokitBackfaces
});
} else if (xeokitModelType === 'las' || xeokitModelType === 'laz') {
loader = new LASLoaderPlugin(viewer, {
fp64: xeokitFP64,
//skip: 1,
colorDepth: 'auto', // Whether colors encoded using 8 or 16 bits - accepted values are "auto", 8 and 16
// dataSource: new LASDefaultDataSource({
// cacheBuster: xeokitCacheBuster,
// })
});
sceneModel = loader.load({
id: "myModel",
src: xeokitModelUrl,
rotation: xeokitRotation,
});
} else if (xeokitModelType === 'obj') {
loader = new OBJLoaderPlugin(viewer);
sceneModel = loader.load({
id: "myModel",
src: xeokitModelUrl,
edges: xeokitEdges
});
} else if (xeokitModelType === 'stl') {
loader = new STLLoaderPlugin(viewer, {
dataSource: new STLDefaultDataSource({
cacheBuster: xeokitCacheBuster,
})
});
sceneModel = loader.load({
id: "myModel",
src: xeokitModelUrl,
smoothNormals: true
});
} else if (xeokitModelType === 'glb' || xeokitModelType === 'gltf') {
loader = new GLTFLoaderPlugin(viewer, {
dataSource: new GLTFDefaultDataSource({
cacheBuster: xeokitCacheBuster,
})
});
sceneModel = loader.load({
id: "myModel",
src: xeokitModelUrl,
colorTextureEnabled: xeokitColorTextureEnabled,
autoMetaModel: true,
saoEnabled: xeokitSaoEnabled,
edges: xeokitEdges,
dtxEnabled: xeokitDtxEnabled
});
} else if (xeokitModelType === 'bim') {
loader = new DotBIMLoaderPlugin(viewer, {
dataSource: new DotBIMDefaultDataSource({
cacheBuster: xeokitCacheBuster,
})
});
sceneModel = loader.load({
id: "myModel",
src: xeokitModelUrl,
saoEnabled: xeokitSaoEnabled,
edges: xeokitEdges,
rotation: xeokitRotation
});
}
const t0 = performance.now();
sceneModel.on("loaded", function () {
const t1 = performance.now();
console.log(`Model loaded in ${ Math.floor(t1 - t0) / 1000.0 } seconds, Objects: ${ sceneModel.numEntities }`);
document.getElementById('footer').innerText = `Model loaded in ${ Math.floor(t1 - t0) / 1000.0 } seconds, Objects: ${ sceneModel.numEntities }`;
viewer.cameraFlight.jumpTo({
projection: "perspective",
aabb: viewer.scene.getAABB({}),
//duration: 0.5
});
if (xeokitBoundingBox) {
const model = viewer.scene.models['myModel'];
drawModelBoundingBox(viewer, 'myModel', model.aabb);
}
});
//----------------------------------------------------------------------------------------------------------------------
// Create a tree view
//----------------------------------------------------------------------------------------------------------------------
if (xeokitTreeViewEnabled) {
const treeView = new TreeViewPlugin(viewer, {
containerElement: document.getElementById("treeViewContainer"),
hierarchy: xeokitTreeViewHierarchy,
autoExpandDepth: 1
});
const treeViewContextMenu = new ContextMenu({
items: [
[
{
title: "View Fit",
doAction: function (context) {
const scene = context.viewer.scene;
const objectIds = [];
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
objectIds.push(treeViewNode.objectId);
}
});
scene.setObjectsVisible(objectIds, true);
scene.setObjectsHighlighted(objectIds, true);
context.viewer.cameraFlight.flyTo({
projection: "perspective",
aabb: scene.getAABB(objectIds),
duration: 0.5
}, () => {
setTimeout(function () {
scene.setObjectsHighlighted(scene.highlightedObjectIds, false);
}, 500);
});
}
},
{
title: "View Fit All",
doAction: function (context) {
const scene = context.viewer.scene;
context.viewer.cameraFlight.flyTo({
projection: "perspective",
aabb: scene.getAABB({}),
duration: 0.5
});
}
}
],
[
{
title: "Hide",
doAction: function (context) {
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = context.viewer.scene.objects[treeViewNode.objectId];
if (entity) {
entity.visible = false;
}
}
});
}
},
{
title: "Hide Others",
doAction: function (context) {
const scene = context.viewer.scene;
scene.setObjectsVisible(scene.visibleObjectIds, false);
scene.setObjectsXRayed(scene.xrayedObjectIds, false);
scene.setObjectsSelected(scene.selectedObjectIds, false);
scene.setObjectsHighlighted(scene.highlightedObjectIds, false);
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = scene.objects[treeViewNode.objectId];
if (entity) {
entity.visible = true;
}
}
});
}
},
{
title: "Hide All",
getEnabled: function (context) {
return (context.viewer.scene.visibleObjectIds.length > 0);
},
doAction: function (context) {
context.viewer.scene.setObjectsVisible(context.viewer.scene.visibleObjectIds, false);
}
}
],
[
{
title: "Show",
doAction: function (context) {
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = context.viewer.scene.objects[treeViewNode.objectId];
if (entity) {
entity.visible = true;
entity.xrayed = false;
entity.selected = false;
}
}
});
}
},
{
title: "Show Others",
doAction: function (context) {
const scene = context.viewer.scene;
scene.setObjectsVisible(scene.objectIds, true);
scene.setObjectsXRayed(scene.xrayedObjectIds, false);
scene.setObjectsSelected(scene.selectedObjectIds, false);
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = scene.objects[treeViewNode.objectId];
if (entity) {
entity.visible = false;
}
}
});
}
},
{
title: "Show All",
getEnabled: function (context) {
const scene = context.viewer.scene;
return (scene.numVisibleObjects < scene.numObjects);
},
doAction: function (context) {
const scene = context.viewer.scene;
scene.setObjectsVisible(scene.objectIds, true);
scene.setObjectsXRayed(scene.xrayedObjectIds, false);
scene.setObjectsSelected(scene.selectedObjectIds, false);
}
}
],
[
{
title: "X-Ray",
doAction: function (context) {
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = context.viewer.scene.objects[treeViewNode.objectId];
if (entity) {
entity.xrayed = true;
entity.visible = true;
}
}
});
}
},
{
title: "Undo X-Ray",
doAction: function (context) {
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = context.viewer.scene.objects[treeViewNode.objectId];
if (entity) {
entity.xrayed = false;
}
}
});
}
},
{
title: "X-Ray Others",
doAction: function (context) {
const scene = context.viewer.scene;
scene.setObjectsVisible(scene.objectIds, true);
scene.setObjectsXRayed(scene.objectIds, true);
scene.setObjectsSelected(scene.selectedObjectIds, false);
scene.setObjectsHighlighted(scene.highlightedObjectIds, false);
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = scene.objects[treeViewNode.objectId];
if (entity) {
entity.xrayed = false;
}
}
});
}
},
{
title: "Reset X-Ray",
getEnabled: function (context) {
return (context.viewer.scene.numXRayedObjects > 0);
},
doAction: function (context) {
context.viewer.scene.setObjectsXRayed(context.viewer.scene.xrayedObjectIds, false);
}
}
],
[
{
title: "Select",
doAction: function (context) {
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = context.viewer.scene.objects[treeViewNode.objectId];
if (entity) {
entity.selected = true;
entity.visible = true;
}
}
});
}
},
{
title: "Deselect",
doAction: function (context) {
context.treeViewPlugin.withNodeTree(context.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
const entity = context.viewer.scene.objects[treeViewNode.objectId];
if (entity) {
entity.selected = false;
}
}
});
}
},
{
title: "Clear Selection",
getEnabled: function (context) {
return (context.viewer.scene.numSelectedObjects > 0);
},
doAction: function (context) {
context.viewer.scene.setObjectsSelected(context.viewer.scene.selectedObjectIds, false);
}
}
]
]
});
// Right-clicking on a tree node shows the context menu for that node
treeView.on("contextmenu", (e) => {
treeViewContextMenu.context = { // Must set context before opening menu
viewer: e.viewer,
treeViewPlugin: e.treeViewPlugin,
treeViewNode: e.treeViewNode,
entity: e.viewer.scene.objects[e.treeViewNode.objectId] // Only defined if tree node is a leaf node
};
treeViewContextMenu.show(e.event.pageX, e.event.pageY);
});
// Left-clicking on a tree node isolates that object in the 3D view
treeView.on("nodeTitleClicked", (e) => {
const scene = viewer.scene;
const objectIds = [];
e.treeViewPlugin.withNodeTree(e.treeViewNode, (treeViewNode) => {
if (treeViewNode.objectId) {
objectIds.push(treeViewNode.objectId);
}
});
e.treeViewPlugin.unShowNode();
scene.setObjectsXRayed(scene.objectIds, true);
scene.setObjectsVisible(scene.objectIds, true);
scene.setObjectsXRayed(objectIds, false);
viewer.cameraFlight.flyTo({
aabb: scene.getAABB(objectIds),
duration: 0.5
}, () => {
setTimeout(function () {
scene.setObjectsVisible(scene.xrayedObjectIds, false);
scene.setObjectsXRayed(scene.xrayedObjectIds, false);
}, 500);
});
});
}
window.viewer = viewer;
</script>
</html>