-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathCesium3DTileset.js
1990 lines (1777 loc) · 80.8 KB
/
Cesium3DTileset.js
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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define([
'../Core/Cartesian2',
'../Core/Cartesian3',
'../Core/Cartographic',
'../Core/Check',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/deprecationWarning',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/DoublyLinkedList',
'../Core/Ellipsoid',
'../Core/Event',
'../Core/getMagic',
'../Core/JulianDate',
'../Core/ManagedArray',
'../Core/Math',
'../Core/Matrix4',
'../Core/Resource',
'../Core/RuntimeError',
'../Renderer/ClearCommand',
'../Renderer/Pass',
'../ThirdParty/when',
'./Axis',
'./Cesium3DTile',
'./Cesium3DTileColorBlendMode',
'./Cesium3DTileContentState',
'./Cesium3DTileOptimizations',
'./Cesium3DTilesetStatistics',
'./Cesium3DTilesetTraversal',
'./Cesium3DTileStyleEngine',
'./ClippingPlaneCollection',
'./LabelCollection',
'./PointCloudEyeDomeLighting',
'./PointCloudShading',
'./SceneMode',
'./ShadowMode',
'./TileBoundingRegion',
'./TileBoundingSphere',
'./TileOrientedBoundingBox'
], function(
Cartesian2,
Cartesian3,
Cartographic,
Check,
defaultValue,
defined,
defineProperties,
deprecationWarning,
destroyObject,
DeveloperError,
DoublyLinkedList,
Ellipsoid,
Event,
getMagic,
JulianDate,
ManagedArray,
CesiumMath,
Matrix4,
Resource,
RuntimeError,
ClearCommand,
Pass,
when,
Axis,
Cesium3DTile,
Cesium3DTileColorBlendMode,
Cesium3DTileContentState,
Cesium3DTileOptimizations,
Cesium3DTilesetStatistics,
Cesium3DTilesetTraversal,
Cesium3DTileStyleEngine,
ClippingPlaneCollection,
LabelCollection,
PointCloudEyeDomeLighting,
PointCloudShading,
SceneMode,
ShadowMode,
TileBoundingRegion,
TileBoundingSphere,
TileOrientedBoundingBox) {
'use strict';
/**
* A {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles tileset},
* used for streaming massive heterogeneous 3D geospatial datasets.
*
* @alias Cesium3DTileset
* @constructor
*
* @param {Object} options Object with the following properties:
* @param {Resource|String|Promise<Resource>|Promise<String>} options.url The url to a tileset JSON file.
* @param {Boolean} [options.show=true] Determines if the tileset will be shown.
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] A 4x4 transformation matrix that transforms the tileset's root tile.
* @param {ShadowMode} [options.shadows=ShadowMode.ENABLED] Determines whether the tileset casts or receives shadows from each light source.
* @param {Number} [options.maximumScreenSpaceError=16] The maximum screen space error used to drive level of detail refinement.
* @param {Number} [options.maximumMemoryUsage=512] The maximum amount of memory in MB that can be used by the tileset.
* @param {Boolean} [options.cullWithChildrenBounds=true] Optimization option. Whether to cull tiles using the union of their children bounding volumes.
* @param {Boolean} [options.dynamicScreenSpaceError=false] Optimization option. Reduce the screen space error for tiles that are further away from the camera.
* @param {Number} [options.dynamicScreenSpaceErrorDensity=0.00278] Density used to adjust the dynamic screen space error, similar to fog density.
* @param {Number} [options.dynamicScreenSpaceErrorFactor=4.0] A factor used to increase the computed dynamic screen space error.
* @param {Number} [options.dynamicScreenSpaceErrorHeightFalloff=0.25] A ratio of the tileset's height at which the density starts to falloff.
* @param {Boolean} [options.skipLevelOfDetail=true] Optimization option. Determines if level of detail skipping should be applied during the traversal.
* @param {Number} [options.baseScreenSpaceError=1024] When <code>skipLevelOfDetail</code> is <code>true</code>, the screen space error that must be reached before skipping levels of detail.
* @param {Number} [options.skipScreenSpaceErrorFactor=16] When <code>skipLevelOfDetail</code> is <code>true</code>, a multiplier defining the minimum screen space error to skip. Used in conjunction with <code>skipLevels</code> to determine which tiles to load.
* @param {Number} [options.skipLevels=1] When <code>skipLevelOfDetail</code> is <code>true</code>, a constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped. Used in conjunction with <code>skipScreenSpaceErrorFactor</code> to determine which tiles to load.
* @param {Boolean} [options.immediatelyLoadDesiredLevelOfDetail=false] When <code>skipLevelOfDetail</code> is <code>true</code>, only tiles that meet the maximum screen space error will ever be downloaded. Skipping factors are ignored and just the desired tiles are loaded.
* @param {Boolean} [options.loadSiblings=false] When <code>skipLevelOfDetail</code> is <code>true</code>, determines whether siblings of visible tiles are always downloaded during traversal.
* @param {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.
* @param {ClassificationType} [options.classificationType] Determines whether terrain, 3D Tiles or both will be classified by this tileset. See {@link Cesium3DTileset#classificationType} for details about restrictions and limitations.
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid determining the size and shape of the globe.
* @param {Object} [options.pointCloudShading] Options for constructing a {@link PointCloudShading} object to control point attenuation based on geometric error and lighting.
* @param {Boolean} [options.debugFreezeFrame=false] For debugging only. Determines if only the tiles from last frame should be used for rendering.
* @param {Boolean} [options.debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile.
* @param {Boolean} [options.debugWireframe=false] For debugging only. When true, render's each tile's content as a wireframe.
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile.
* @param {Boolean} [options.debugShowContentBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile's content.
* @param {Boolean} [options.debugShowViewerRequestVolume=false] For debugging only. When true, renders the viewer request volume for each tile.
* @param {Boolean} [options.debugShowGeometricError=false] For debugging only. When true, draws labels to indicate the geometric error of each tile.
* @param {Boolean} [options.debugShowRenderingStatistics=false] For debugging only. When true, draws labels to indicate the number of commands, points, triangles and features for each tile.
* @param {Boolean} [options.debugShowMemoryUsage=false] For debugging only. When true, draws labels to indicate the texture and geometry memory in megabytes used by each tile.
* @param {Boolean} [options.debugShowUrl=false] For debugging only. When true, draws labels to indicate the url of each tile.
*
* @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0. See {@link https://github.com/AnalyticalGraphicsInc/3d-tiles#spec-status}
*
* @example
* var tileset = scene.primitives.add(new Cesium.Cesium3DTileset({
* url : 'http://localhost:8002/tilesets/Seattle/tileset.json'
* }));
*
* @example
* // Common setting for the skipLevelOfDetail optimization
* var tileset = scene.primitives.add(new Cesium.Cesium3DTileset({
* url : 'http://localhost:8002/tilesets/Seattle/tileset.json',
* skipLevelOfDetail : true,
* baseScreenSpaceError : 1024,
* skipScreenSpaceErrorFactor : 16,
* skipLevels : 1,
* immediatelyLoadDesiredLevelOfDetail : false,
* loadSiblings : false,
* cullWithChildrenBounds : true
* }));
*
* @example
* // Common settings for the dynamicScreenSpaceError optimization
* var tileset = scene.primitives.add(new Cesium.Cesium3DTileset({
* url : 'http://localhost:8002/tilesets/Seattle/tileset.json',
* dynamicScreenSpaceError : true,
* dynamicScreenSpaceErrorDensity : 0.00278,
* dynamicScreenSpaceErrorFactor : 4.0,
* dynamicScreenSpaceErrorHeightFalloff : 0.25
* }));
*
* @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles specification}
*/
function Cesium3DTileset(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
//>>includeStart('debug', pragmas.debug);
Check.defined('options.url', options.url);
//>>includeEnd('debug');
this._url = undefined;
this._basePath = undefined;
this._root = undefined;
this._asset = undefined; // Metadata for the entire tileset
this._properties = undefined; // Metadata for per-model/point/etc properties
this._geometricError = undefined; // Geometric error when the tree is not rendered at all
this._extensionsUsed = undefined;
this._gltfUpAxis = undefined;
this._processingQueue = [];
this._selectedTiles = [];
this._requestedTiles = [];
this._desiredTiles = new ManagedArray();
this._selectedTilesToStyle = [];
this._loadTimestamp = undefined;
this._timeSinceLoad = 0.0;
var replacementList = new DoublyLinkedList();
// [head, sentinel) -> tiles that weren't selected this frame and may be replaced
// (sentinel, tail] -> tiles that were selected this frame
this._replacementList = replacementList; // Tiles with content loaded. For cache management.
this._replacementSentinel = replacementList.add();
this._trimTiles = false;
this._cullWithChildrenBounds = defaultValue(options.cullWithChildrenBounds, true);
this._hasMixedContent = false;
this._baseTraversal = new Cesium3DTilesetTraversal.BaseTraversal();
this._skipTraversal = new Cesium3DTilesetTraversal.SkipTraversal({
selectionHeuristic : selectionHeuristic
});
this._backfaceCommands = new ManagedArray();
this._maximumScreenSpaceError = defaultValue(options.maximumScreenSpaceError, 16);
this._maximumMemoryUsage = defaultValue(options.maximumMemoryUsage, 512);
this._styleEngine = new Cesium3DTileStyleEngine();
this._modelMatrix = defined(options.modelMatrix) ? Matrix4.clone(options.modelMatrix) : Matrix4.clone(Matrix4.IDENTITY);
this._statistics = new Cesium3DTilesetStatistics();
this._statisticsLastColor = new Cesium3DTilesetStatistics();
this._statisticsLastPick = new Cesium3DTilesetStatistics();
this._tilesLoaded = false;
this._tileDebugLabels = undefined;
this._readyPromise = when.defer();
this._classificationType = options.classificationType;
this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
/**
* Optimization option. Whether the tileset should refine based on a dynamic screen space error. Tiles that are further
* away will be rendered with lower detail than closer tiles. This improves performance by rendering fewer
* tiles and making less requests, but may result in a slight drop in visual quality for tiles in the distance.
* The algorithm is biased towards "street views" where the camera is close to the ground plane of the tileset and looking
* at the horizon. In addition results are more accurate for tightly fitting bounding volumes like box and region.
*
* @type {Boolean}
* @default false
*/
this.dynamicScreenSpaceError = defaultValue(options.dynamicScreenSpaceError, false);
/**
* A scalar that determines the density used to adjust the dynamic screen space error, similar to {@link Fog}. Increasing this
* value has the effect of increasing the maximum screen space error for all tiles, but in a non-linear fashion.
* The error starts at 0.0 and increases exponentially until a midpoint is reached, and then approaches 1.0 asymptotically.
* This has the effect of keeping high detail in the closer tiles and lower detail in the further tiles, with all tiles
* beyond a certain distance all roughly having an error of 1.0.
* <p>
* The dynamic error is in the range [0.0, 1.0) and is multiplied by <code>dynamicScreenSpaceErrorFactor</code> to produce the
* final dynamic error. This dynamic error is then subtracted from the tile's actual screen space error.
* </p>
* <p>
* Increasing <code>dynamicScreenSpaceErrorDensity</code> has the effect of moving the error midpoint closer to the camera.
* It is analogous to moving fog closer to the camera.
* </p>
*
* @type {Number}
* @default 0.00278
*/
this.dynamicScreenSpaceErrorDensity = 0.00278;
/**
* A factor used to increase the screen space error of tiles for dynamic screen space error. As this value increases less tiles
* are requested for rendering and tiles in the distance will have lower detail. If set to zero, the feature will be disabled.
*
* @type {Number}
* @default 4.0
*/
this.dynamicScreenSpaceErrorFactor = 4.0;
/**
* A ratio of the tileset's height at which the density starts to falloff. If the camera is below this height the
* full computed density is applied, otherwise the density falls off. This has the effect of higher density at
* street level views.
* <p>
* Valid values are between 0.0 and 1.0.
* </p>
*
* @type {Number}
* @default 0.25
*/
this.dynamicScreenSpaceErrorHeightFalloff = 0.25;
this._dynamicScreenSpaceErrorComputedDensity = 0.0; // Updated based on the camera position and direction
/**
* Determines whether the tileset casts or receives shadows from each light source.
* <p>
* Enabling shadows has a performance impact. A tileset that casts shadows must be rendered twice, once from the camera and again from the light's point of view.
* </p>
* <p>
* Shadows are rendered only when {@link Viewer#shadows} is <code>true</code>.
* </p>
*
* @type {ShadowMode}
* @default ShadowMode.ENABLED
*/
this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED);
/**
* Determines if the tileset will be shown.
*
* @type {Boolean}
* @default true
*/
this.show = defaultValue(options.show, true);
/**
* Defines how per-feature colors set from the Cesium API or declarative styling blend with the source colors from
* the original feature, e.g. glTF material or per-point color in the tile.
*
* @type {Cesium3DTileColorBlendMode}
* @default Cesium3DTileColorBlendMode.HIGHLIGHT
*/
this.colorBlendMode = Cesium3DTileColorBlendMode.HIGHLIGHT;
/**
* Defines the value used to linearly interpolate between the source color and feature color when the {@link Cesium3DTileset#colorBlendMode} is <code>MIX</code>.
* A value of 0.0 results in the source color while a value of 1.0 results in the feature color, with any value in-between
* resulting in a mix of the source color and feature color.
*
* @type {Number}
* @default 0.5
*/
this.colorBlendAmount = 0.5;
/**
* Options for controlling point size based on geometric error and eye dome lighting.
* @type {PointCloudShading}
*/
this.pointCloudShading = new PointCloudShading(options.pointCloudShading);
this._pointCloudEyeDomeLighting = new PointCloudEyeDomeLighting();
/**
* The event fired to indicate progress of loading new tiles. This event is fired when a new tile
* is requested, when a requested tile is finished downloading, and when a downloaded tile has been
* processed and is ready to render.
* <p>
* The number of pending tile requests, <code>numberOfPendingRequests</code>, and number of tiles
* processing, <code>numberOfTilesProcessing</code> are passed to the event listener.
* </p>
* <p>
* This event is fired at the end of the frame after the scene is rendered.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.loadProgress.addEventListener(function(numberOfPendingRequests, numberOfTilesProcessing) {
* if ((numberOfPendingRequests === 0) && (numberOfTilesProcessing === 0)) {
* console.log('Stopped loading');
* return;
* }
*
* console.log('Loading: requests: ' + numberOfPendingRequests + ', processing: ' + numberOfTilesProcessing);
* });
*/
this.loadProgress = new Event();
/**
* The event fired to indicate that all tiles that meet the screen space error this frame are loaded. The tileset
* is completely loaded for this view.
* <p>
* This event is fired at the end of the frame after the scene is rendered.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.allTilesLoaded.addEventListener(function() {
* console.log('All tiles are loaded');
* });
*
* @see Cesium3DTileset#tilesLoaded
*/
this.allTilesLoaded = new Event();
/**
* The event fired to indicate that a tile's content was loaded.
* <p>
* The loaded {@link Cesium3DTile} is passed to the event listener.
* </p>
* <p>
* This event is fired during the tileset traversal while the frame is being rendered
* so that updates to the tile take effect in the same frame. Do not create or modify
* Cesium entities or primitives during the event listener.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.tileLoad.addEventListener(function(tile) {
* console.log('A tile was loaded.');
* });
*/
this.tileLoad = new Event();
/**
* The event fired to indicate that a tile's content was unloaded.
* <p>
* The unloaded {@link Cesium3DTile} is passed to the event listener.
* </p>
* <p>
* This event is fired immediately before the tile's content is unloaded while the frame is being
* rendered so that the event listener has access to the tile's content. Do not create
* or modify Cesium entities or primitives during the event listener.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.tileUnload.addEventListener(function(tile) {
* console.log('A tile was unloaded from the cache.');
* });
*
* @see Cesium3DTileset#maximumMemoryUsage
* @see Cesium3DTileset#trimLoadedTiles
*/
this.tileUnload = new Event();
/**
* The event fired to indicate that a tile's content failed to load.
* <p>
* If there are no event listeners, error messages will be logged to the console.
* </p>
* <p>
* The error object passed to the listener contains two properties:
* <ul>
* <li><code>url</code>: the url of the failed tile.</li>
* <li><code>message</code>: the error message.</li>
* </ul>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.tileFailed.addEventListener(function(error) {
* console.log('An error occurred loading tile: ' + error.url);
* console.log('Error: ' + error.message);
* });
*/
this.tileFailed = new Event();
/**
* This event fires once for each visible tile in a frame. This can be used to manually
* style a tileset.
* <p>
* The visible {@link Cesium3DTile} is passed to the event listener.
* </p>
* <p>
* This event is fired during the tileset traversal while the frame is being rendered
* so that updates to the tile take effect in the same frame. Do not create or modify
* Cesium entities or primitives during the event listener.
* </p>
*
* @type {Event}
* @default new Event()
*
* @example
* tileset.tileVisible.addEventListener(function(tile) {
* if (tile.content instanceof Cesium.Batched3DModel3DTileContent) {
* console.log('A Batched 3D Model tile is visible.');
* }
* });
*
* @example
* // Apply a red style and then manually set random colors for every other feature when the tile becomes visible.
* tileset.style = new Cesium.Cesium3DTileStyle({
* color : 'color("red")'
* });
* tileset.tileVisible.addEventListener(function(tile) {
* var content = tile.content;
* var featuresLength = content.featuresLength;
* for (var i = 0; i < featuresLength; i+=2) {
* content.getFeature(i).color = Cesium.Color.fromRandom();
* }
* });
*/
this.tileVisible = new Event();
/**
* Optimization option. Determines if level of detail skipping should be applied during the traversal.
* <p>
* The common strategy for replacement-refinement traversal is to store all levels of the tree in memory and require
* all children to be loaded before the parent can refine. With this optimization levels of the tree can be skipped
* entirely and children can be rendered alongside their parents. The tileset requires significantly less memory when
* using this optimization.
* </p>
*
* @type {Boolean}
* @default true
*/
this.skipLevelOfDetail = defaultValue(options.skipLevelOfDetail, true);
this._skipLevelOfDetail = this.skipLevelOfDetail;
this._disableSkipLevelOfDetail = false;
/**
* The screen space error that must be reached before skipping levels of detail.
* <p>
* Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
* </p>
*
* @type {Number}
* @default 1024
*/
this.baseScreenSpaceError = defaultValue(options.baseScreenSpaceError, 1024);
/**
* Multiplier defining the minimum screen space error to skip.
* For example, if a tile has screen space error of 100, no tiles will be loaded unless they
* are leaves or have a screen space error <code><= 100 / skipScreenSpaceErrorFactor</code>.
* <p>
* Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
* </p>
*
* @type {Number}
* @default 16
*/
this.skipScreenSpaceErrorFactor = defaultValue(options.skipScreenSpaceErrorFactor, 16);
/**
* Constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped.
* For example, if a tile is level 1, no tiles will be loaded unless they are at level greater than 2.
* <p>
* Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
* </p>
*
* @type {Number}
* @default 1
*/
this.skipLevels = defaultValue(options.skipLevels, 1);
/**
* When true, only tiles that meet the maximum screen space error will ever be downloaded.
* Skipping factors are ignored and just the desired tiles are loaded.
* <p>
* Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
* </p>
*
* @type {Boolean}
* @default false
*/
this.immediatelyLoadDesiredLevelOfDetail = defaultValue(options.immediatelyLoadDesiredLevelOfDetail, false);
/**
* Determines whether siblings of visible tiles are always downloaded during traversal.
* This may be useful for ensuring that tiles are already available when the viewer turns left/right.
* <p>
* Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
* </p>
*
* @type {Boolean}
* @default false
*/
this.loadSiblings = defaultValue(options.loadSiblings, false);
this._clippingPlanes = undefined;
this.clippingPlanes = options.clippingPlanes;
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* Determines if only the tiles from last frame should be used for rendering. This
* effectively "freezes" the tileset to the previous frame so it is possible to zoom
* out and see what was rendered.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugFreezeFrame = defaultValue(options.debugFreezeFrame, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, assigns a random color to each tile. This is useful for visualizing
* what features belong to what tiles, especially with additive refinement where features
* from parent tiles may be interleaved with features from child tiles.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugColorizeTiles = defaultValue(options.debugColorizeTiles, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, renders each tile's content as a wireframe.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugWireframe = defaultValue(options.debugWireframe, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, renders the bounding volume for each visible tile. The bounding volume is
* white if the tile has a content bounding volume; otherwise, it is red. Tiles that don't meet the
* screen space error and are still refining to their descendants are yellow.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowBoundingVolume = defaultValue(options.debugShowBoundingVolume, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, renders the bounding volume for each visible tile's content. The bounding volume is
* blue if the tile has a content bounding volume; otherwise it is red.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowContentBoundingVolume = defaultValue(options.debugShowContentBoundingVolume, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, renders the viewer request volume for each tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowViewerRequestVolume = defaultValue(options.debugShowViewerRequestVolume, false);
this._tileDebugLabels = undefined;
this.debugPickedTileLabelOnly = false;
this.debugPickedTile = undefined;
this.debugPickPosition = undefined;
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, draws labels to indicate the geometric error of each tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowGeometricError = defaultValue(options.debugShowGeometricError, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, draws labels to indicate the number of commands, points, triangles and features of each tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowRenderingStatistics = defaultValue(options.debugShowRenderingStatistics, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, draws labels to indicate the geometry and texture memory usage of each tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowMemoryUsage = defaultValue(options.debugShowMemoryUsage, false);
/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, draws labels to indicate the url of each tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowUrl = defaultValue(options.debugShowUrl, false);
// A bunch of tilesets were generated that have a leading / in front of all URLs in the tileset JSON file. If the tiles aren't
// at the root of the domain they will not load anymore. If we find a b3dm file with a leading slash, we test load a tile.
// If it succeeds we continue on. If it fails, we set this to true so we know to strip the slash when loading tiles.
this._brokenUrlWorkaround = false;
this._credits = undefined;
var that = this;
var resource;
when(options.url)
.then(function(url) {
var basePath;
resource = Resource.createIfNeeded(url);
// ion resources have a credits property we can use for additional attribution.
that._credits = resource.credits;
if (resource.extension === 'json') {
basePath = resource.getBaseUri(true);
} else if (resource.isDataUri) {
basePath = '';
}
that._url = resource.url;
that._basePath = basePath;
// We don't know the distance of the tileset until tileset JSON file is loaded, so use the default distance for now
return Cesium3DTileset.loadJson(resource);
})
.then(function(tilesetJson) {
return detectBrokenUrlWorkaround(that, resource, tilesetJson);
})
.then(function(tilesetJson) {
if (that._brokenUrlWorkaround) {
deprecationWarning('Cesium3DTileset.leadingSlash', 'Having a leading slash in a tile URL that is actually relative to the tileset JSON file is deprecated.');
}
that._root = that.loadTileset(resource, tilesetJson);
var gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis) ? Axis.fromName(tilesetJson.asset.gltfUpAxis) : Axis.Y;
that._asset = tilesetJson.asset;
that._properties = tilesetJson.properties;
that._geometricError = tilesetJson.geometricError;
that._extensionsUsed = tilesetJson.extensionsUsed;
that._gltfUpAxis = gltfUpAxis;
that._readyPromise.resolve(that);
}).otherwise(function(error) {
that._readyPromise.reject(error);
});
}
function detectBrokenUrlWorkaround(tileset, resource, tilesetJson) {
var testUrl = findBrokenUrl(tilesetJson.root);
// If it's an empty string, we are good to load the tileset.
if (!defined(testUrl) || (testUrl.length === 0)) {
return tilesetJson;
}
var testResource = resource.getDerivedResource({
url : testUrl
});
return testResource.fetchArrayBuffer()
.then(function(buffer) {
var uint8Array = new Uint8Array(buffer);
var magic = getMagic(uint8Array);
// If its not a b3dm file, then use workaround
// This accounts for servers that return an error page with a 200 status code
tileset._brokenUrlWorkaround = (magic !== 'b3dm');
return tilesetJson;
})
.otherwise(function() {
// Tile failed to load, so use the workaround
tileset._brokenUrlWorkaround = true;
return tilesetJson;
});
}
var brokenUrlRegex = /^\/.+\.b3dm$/;
function findBrokenUrl(node) {
var content = node.content;
if (defined(content) && defined(content.url)) {
if (brokenUrlRegex.test(content.url)) {
return content.url;
}
return '';
}
var children = node.children;
if (defined(children)) {
var count = children.length;
for (var i = 0; i < count; ++i) {
var result = findBrokenUrl(children[i]);
if (defined(result)) {
return result;
}
}
}
}
defineProperties(Cesium3DTileset.prototype, {
/**
* Gets the tileset's asset object property, which contains metadata about the tileset.
* <p>
* See the {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/schema/asset.schema.json|asset schema}
* in the 3D Tiles spec for the full set of properties.
* </p>
*
* @memberof Cesium3DTileset.prototype
*
* @type {Object}
* @readonly
*
* @exception {DeveloperError} The tileset is not loaded. Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.
*/
asset : {
get : function() {
//>>includeStart('debug', pragmas.debug);
if (!this.ready) {
throw new DeveloperError('The tileset is not loaded. Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.');
}
//>>includeEnd('debug');
return this._asset;
}
},
/**
* The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.
*
* @memberof Cesium3DTileset.prototype
*
* @type {ClippingPlaneCollection}
*/
clippingPlanes : {
get : function() {
return this._clippingPlanes;
},
set : function(value) {
ClippingPlaneCollection.setOwner(value, this, '_clippingPlanes');
}
},
/**
* Gets the tileset's properties dictionary object, which contains metadata about per-feature properties.
* <p>
* See the {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/schema/properties.schema.json|properties schema}
* in the 3D Tiles spec for the full set of properties.
* </p>
*
* @memberof Cesium3DTileset.prototype
*
* @type {Object}
* @readonly
*
* @exception {DeveloperError} The tileset is not loaded. Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.
*
* @example
* console.log('Maximum building height: ' + tileset.properties.height.maximum);
* console.log('Minimum building height: ' + tileset.properties.height.minimum);
*
* @see Cesium3DTileFeature#getProperty
* @see Cesium3DTileFeature#setProperty
*/
properties : {
get : function() {
//>>includeStart('debug', pragmas.debug);
if (!this.ready) {
throw new DeveloperError('The tileset is not loaded. Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.');
}
//>>includeEnd('debug');
return this._properties;
}
},
/**
* When <code>true</code>, the tileset's root tile is loaded and the tileset is ready to render.
* This is set to <code>true</code> right before {@link Cesium3DTileset#readyPromise} is resolved.
*
* @memberof Cesium3DTileset.prototype
*
* @type {Boolean}
* @readonly
*
* @default false
*/
ready : {
get : function() {
return defined(this._root);
}
},
/**
* Gets the promise that will be resolved when the tileset's root tile is loaded and the tileset is ready to render.
* <p>
* This promise is resolved at the end of the frame before the first frame the tileset is rendered in.
* </p>
*
* @memberof Cesium3DTileset.prototype
*
* @type {Promise.<Cesium3DTileset>}
* @readonly
*
* @example
* tileset.readyPromise.then(function(tileset) {
* // tile.properties is not defined until readyPromise resolves.
* var properties = tileset.properties;
* if (Cesium.defined(properties)) {
* for (var name in properties) {
* console.log(properties[name]);
* }
* }
* });
*/
readyPromise : {
get : function() {
return this._readyPromise.promise;
}
},
/**
* When <code>true</code>, all tiles that meet the screen space error this frame are loaded. The tileset is
* completely loaded for this view.
*
* @memberof Cesium3DTileset.prototype
*
* @type {Boolean}
* @readonly
*
* @default false
*
* @see Cesium3DTileset#allTilesLoaded
*/
tilesLoaded : {
get : function() {
return this._tilesLoaded;
}
},
/**
* The url to a tileset JSON file.
*
* @memberof Cesium3DTileset.prototype
*
* @type {String}
* @readonly
*/
url : {
get : function() {
return this._url;
}
},
/**
* The base path that non-absolute paths in tileset JSON file are relative to.
*
* @memberof Cesium3DTileset.prototype
*
* @type {String}
* @readonly
* @deprecated
*/
basePath : {
get : function() {
deprecationWarning('Cesium3DTileset.basePath', 'Cesium3DTileset.basePath has been deprecated. All tiles are relative to the url of the tileset JSON file that contains them. Use the url property instead.');
return this._basePath;
}
},
/**
* The style, defined using the
* {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling|3D Tiles Styling language},
* applied to each feature in the tileset.
* <p>
* Assign <code>undefined</code> to remove the style, which will restore the visual
* appearance of the tileset to its default when no style was applied.
* </p>
* <p>
* The style is applied to a tile before the {@link Cesium3DTileset#tileVisible}
* event is raised, so code in <code>tileVisible</code> can manually set a feature's
* properties (e.g. color and show) after the style is applied. When
* a new style is assigned any manually set properties are overwritten.
* </p>
*
* @memberof Cesium3DTileset.prototype
*
* @type {Cesium3DTileStyle}
*
* @default undefined
*
* @example
* tileset.style = new Cesium.Cesium3DTileStyle({
* color : {
* conditions : [
* ['${Height} >= 100', 'color("purple", 0.5)'],
* ['${Height} >= 50', 'color("red")'],
* ['true', 'color("blue")']
* ]
* },
* show : '${Height} > 0',
* meta : {
* description : '"Building id ${id} has height ${Height}."'
* }
* });
*
* @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling|3D Tiles Styling language}
*/
style : {
get : function() {
return this._styleEngine.style;
},
set : function(value) {
this._styleEngine.style = value;
}
},
/**
* The maximum screen space error used to drive level of detail refinement. This value helps determine when a tile
* refines to its descendants, and therefore plays a major role in balancing performance with visual quality.
* <p>