-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Cesium3DTilesetSpec.js
7477 lines (6507 loc) · 264 KB
/
Cesium3DTilesetSpec.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
import {
Axis,
Camera,
Cartesian2,
Cartesian3,
Cartesian4,
Cartographic,
Cesium3DTile,
Cesium3DTileColorBlendMode,
Cesium3DTileContentState,
Cesium3DTilePass,
Cesium3DTilePassState,
Cesium3DTileRefine,
Cesium3DTileset,
Cesium3DTileStyle,
ClearCommand,
ClippingPlane,
ClippingPlaneCollection,
ClippingPolygon,
ClippingPolygonCollection,
Color,
ContextLimits,
Credit,
CullFace,
CullingVolume,
defer,
defined,
findTileMetadata,
findContentMetadata,
getAbsoluteUri,
getJsonFromTypedArray,
HeadingPitchRange,
HeadingPitchRoll,
ImageBasedLighting,
Intersect,
JulianDate,
Math as CesiumMath,
Matrix4,
PerspectiveFrustum,
PrimitiveType,
Ray,
RequestScheduler,
Resource,
ResourceCache,
RuntimeError,
Transforms,
} from "../../index.js";
import Cesium3DTilesTester from "../../../../Specs/Cesium3DTilesTester.js";
import createScene from "../../../../Specs/createScene.js";
import generateJsonBuffer from "../../../../Specs/generateJsonBuffer.js";
import pollToPromise from "../../../../Specs/pollToPromise.js";
import Ellipsoid from "../../Source/Core/Ellipsoid.js";
describe(
"Scene/Cesium3DTileset",
function () {
// It's not easily possible to mock the most detailed pick functions
// so don't run those tests when using the WebGL stub
const webglStub = !!window.webglStub;
let scene;
const centerLongitude = -1.31968;
const centerLatitude = 0.698874;
let options;
// Parent tile with content and four child tiles with content
const tilesetUrl = "Data/Cesium3DTiles/Tilesets/Tileset/tileset.json";
// Parent tile with no content and four child tiles with content
const tilesetEmptyRootUrl =
"Data/Cesium3DTiles/Tilesets/TilesetEmptyRoot/tileset.json";
// Tileset with 3 levels of uniform subdivision
const tilesetUniform =
"Data/Cesium3DTiles/Tilesets/TilesetUniform/tileset.json";
const tilesetReplacement1Url =
"Data/Cesium3DTiles/Tilesets/TilesetReplacement1/tileset.json";
const tilesetReplacement2Url =
"Data/Cesium3DTiles/Tilesets/TilesetReplacement2/tileset.json";
const tilesetReplacement3Url =
"Data/Cesium3DTiles/Tilesets/TilesetReplacement3/tileset.json";
// 3 level tree with mix of additive and replacement refinement
const tilesetRefinementMix =
"Data/Cesium3DTiles/Tilesets/TilesetRefinementMix/tileset.json";
// tileset.json : root content points to tiles2.json
// tiles2.json: root with b3dm content, three children with b3dm content, one child points to tiles3.json
// tiles3.json: root with b3dm content
const tilesetOfTilesetsUrl =
"Data/Cesium3DTiles/Tilesets/TilesetOfTilesets/tileset.json";
// A tileset that refers to 4 GLB files which share two (external) textures
const tilesetUrlWithSharedTextures =
"Data/Cesium3DTiles/Tilesets/TilesetWithSharedTextures/tileset.json";
const withoutBatchTableUrl =
"Data/Cesium3DTiles/Batched/BatchedWithoutBatchTable/tileset.json";
const withBatchTableUrl =
"Data/Cesium3DTiles/Batched/BatchedWithBatchTable/tileset.json";
const noBatchIdsUrl =
"Data/Cesium3DTiles/Batched/BatchedNoBatchIds/tileset.json";
const withBatchTableHierarchyUrl =
"Data/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json";
const withTransformBoxUrl =
"Data/Cesium3DTiles/Batched/BatchedWithTransformBox/tileset.json";
const withTransformSphereUrl =
"Data/Cesium3DTiles/Batched/BatchedWithTransformSphere/tileset.json";
const withTransformRegionUrl =
"Data/Cesium3DTiles/Batched/BatchedWithTransformRegion/tileset.json";
const withBoundingSphereUrl =
"Data/Cesium3DTiles/Batched/BatchedWithBoundingSphere/tileset.json";
const compositeUrl = "Data/Cesium3DTiles/Composite/Composite/tileset.json";
const instancedUrl =
"Data/Cesium3DTiles/Instanced/InstancedWithBatchTable/tileset.json";
const instancedRedMaterialUrl =
"Data/Cesium3DTiles/Instanced/InstancedRedMaterial/tileset.json";
const instancedAnimationUrl =
"Data/Cesium3DTiles/Instanced/InstancedAnimated/tileset.json";
const gltfContentUrl = "Data/Cesium3DTiles/GltfContent/glTF/tileset.json";
const glbContentUrl = "Data/Cesium3DTiles/GltfContent/glb/tileset.json";
const gltfContentWithCopyrightUrl =
"Data/Cesium3DTiles/GltfContentWithCopyright/glTF/tileset.json";
const gltfContentWithRepeatedCopyrightsUrl =
"Data/Cesium3DTiles/GltfContentWithRepeatedCopyrights/glTF/tileset.json";
// 1 tile where each feature is a different source color
const colorsUrl = "Data/Cesium3DTiles/Batched/BatchedColors/tileset.json";
// 1 tile where each feature has a reddish texture
const texturedUrl =
"Data/Cesium3DTiles/Batched/BatchedTextured/tileset.json";
// 1 tile with translucent features
const translucentUrl =
"Data/Cesium3DTiles/Batched/BatchedTranslucent/tileset.json";
// 1 tile with opaque and translucent features
const translucentOpaqueMixUrl =
"Data/Cesium3DTiles/Batched/BatchedTranslucentOpaqueMix/tileset.json";
// Root tile is transformed from local space to wgs84, child tile is rotated, scaled, and translated locally
const tilesetWithTransformsUrl =
"Data/Cesium3DTiles/Tilesets/TilesetWithTransforms/tileset.json";
// Root tile with 4 b3dm children and 1 pnts child with a viewer request volume
const tilesetWithViewerRequestVolumeUrl =
"Data/Cesium3DTiles/Tilesets/TilesetWithViewerRequestVolume/tileset.json";
// Parent tile with content and four child tiles with content with viewer request volume for each child
const tilesetReplacementWithViewerRequestVolumeUrl =
"Data/Cesium3DTiles/Tilesets/TilesetReplacementWithViewerRequestVolume/tileset.json";
const tilesetWithExternalResourcesUrl =
"Data/Cesium3DTiles/Tilesets/TilesetWithExternalResources/tileset.json";
const tilesetUrlWithContentUri =
"Data/Cesium3DTiles/Batched/BatchedWithContentDataUri/tileset.json";
// Tileset where glTF positions are stored as east-north-up instead of
// the glTF y-up convention. This is used for testing modelUpAxis and
// modelForwardAxis.
const tilesetEastNorthUpUrl =
"Data/Cesium3DTiles/EastNorthUpContent/tileset_1.1.json";
const tilesetSubtreeExpirationUrl =
"Data/Cesium3DTiles/Tilesets/TilesetSubtreeExpiration/tileset.json";
const tilesetSubtreeUrl =
"Data/Cesium3DTiles/Tilesets/TilesetSubtreeExpiration/subtree.json";
const batchedExpirationUrl =
"Data/Cesium3DTiles/Batched/BatchedExpiration/tileset.json";
const batchedColorsB3dmUrl =
"Data/Cesium3DTiles/Batched/BatchedColors/batchedColors.b3dm";
const batchedVertexColorsUrl =
"Data/Cesium3DTiles/Batched/BatchedWithVertexColors/tileset.json";
const batchedAnimationUrl =
"Data/Cesium3DTiles/Batched/BatchedAnimated/tileset.json";
const styleUrl = "Data/Cesium3DTiles/Style/style.json";
const pointCloudUrl =
"Data/Cesium3DTiles/PointCloud/PointCloudRGB/tileset.json";
const pointCloudBatchedUrl =
"Data/Cesium3DTiles/PointCloud/PointCloudBatched/tileset.json";
function endsWith(string, suffix) {
const slicePoint = string.length - suffix.length;
return string.slice(slicePoint) === suffix;
}
beforeAll(function () {
scene = createScene();
});
afterAll(function () {
scene.destroyForSpecs();
});
beforeEach(function () {
RequestScheduler.clearForSpecs();
scene.morphTo3D(0.0);
const camera = scene.camera;
camera.frustum = new PerspectiveFrustum();
camera.frustum.aspectRatio =
scene.drawingBufferWidth / scene.drawingBufferHeight;
camera.frustum.fov = CesiumMath.toRadians(60.0);
viewAllTiles();
options = {
cullRequestsWhileMoving: false,
};
});
afterEach(function () {
scene.verticalExaggeration = 1.0;
scene.primitives.removeAll();
ResourceCache.clearForSpecs();
});
function setZoom(distance) {
// Bird's eye view
const center = Cartesian3.fromRadians(centerLongitude, centerLatitude);
scene.camera.lookAt(center, new HeadingPitchRange(0.0, -1.57, distance));
}
function viewAllTiles() {
setZoom(15.0);
}
function viewRootOnly() {
setZoom(100.0);
}
function viewNothing() {
setZoom(200.0);
}
function viewSky() {
const center = Cartesian3.fromRadians(
centerLongitude,
centerLatitude,
100,
);
scene.camera.lookAt(center, new HeadingPitchRange(0.0, 1.57, 10.0));
}
function viewBottomLeft() {
viewAllTiles();
scene.camera.moveLeft(200.0);
scene.camera.moveDown(200.0);
}
function viewInstances() {
setZoom(30.0);
}
function viewPointCloud() {
setZoom(5.0);
}
function viewGltfContent() {
setZoom(100.0);
}
function isSelected(tileset, tile) {
return tileset._selectedTiles.indexOf(tile) > -1;
}
it("loads json with static loadJson method", async function () {
const tilesetJson = {
asset: {
version: 1.1,
},
};
const uri = `data:text/plain;base64,${btoa(JSON.stringify(tilesetJson))}`;
await expectAsync(Cesium3DTileset.loadJson(uri)).toBeResolvedTo(
tilesetJson,
);
});
it("fromUrl throws without url", async function () {
await expectAsync(
Cesium3DTileset.fromUrl(),
).toBeRejectedWithDeveloperError(
"url is required, actual value was undefined",
);
});
it("fromUrl throws with unsupported version", async function () {
const tilesetJson = {
asset: {
version: "2.0",
},
};
const uri = `data:text/plain;base64,${btoa(JSON.stringify(tilesetJson))}`;
await expectAsync(Cesium3DTileset.fromUrl(uri)).toBeRejectedWithError(
RuntimeError,
"The tileset must be 3D Tiles version 0.0, 1.0, or 1.1",
);
});
it("fromUrl throws with unsupported extension", async function () {
const tilesetJson = {
asset: {
version: "1.0",
},
extensionsUsed: ["unsupported_extension"],
extensionsRequired: ["unsupported_extension"],
};
const uri = `data:text/plain;base64,${btoa(JSON.stringify(tilesetJson))}`;
await expectAsync(Cesium3DTileset.fromUrl(uri)).toBeRejectedWithError(
RuntimeError,
"Unsupported 3D Tiles Extension: unsupported_extension",
);
});
it("fromUrl throws with invalid tileset JSON file", async function () {
await expectAsync(Cesium3DTileset.fromUrl("invalid.json")).toBeRejected();
});
it("fromUrl resolves with file resource", async function () {
const resource = new Resource({
url: "Data/Cesium3DTiles/Tilesets/TilesetOfTilesets/tileset.json",
});
const tileset = await Cesium3DTileset.fromUrl(resource);
expect(tileset).toBeInstanceOf(Cesium3DTileset);
});
it("url and tilesetUrl set up correctly given tileset JSON filepath", async function () {
const path = "Data/Cesium3DTiles/Tilesets/TilesetOfTilesets/tileset.json";
const tileset = await Cesium3DTileset.fromUrl(path);
expect(tileset.resource.url).toEqual(path);
});
it("url and tilesetUrl set up correctly given path with query string", async function () {
const path = "Data/Cesium3DTiles/Tilesets/TilesetOfTilesets/tileset.json";
const param = "?param1=1¶m2=2";
const tileset = await Cesium3DTileset.fromUrl(path + param);
expect(tileset.resource.url).toEqual(path + param);
});
it("fromIonAssetId throws without assetId", async function () {
await expectAsync(
Cesium3DTileset.fromIonAssetId(),
).toBeRejectedWithDeveloperError(
"assetId is required, actual value was undefined",
);
});
it("loads tileset JSON file", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
const asset = tileset.asset;
expect(asset).toBeDefined();
expect(asset.version).toEqual("1.0");
expect(asset.tilesetVersion).toEqual("1.2.3");
const properties = tileset.properties;
expect(properties).toBeDefined();
expect(properties.id).toBeDefined();
expect(properties.id.minimum).toEqual(0);
expect(properties.id.maximum).toEqual(9);
expect(tileset._geometricError).toEqual(240.0);
expect(tileset.root).toBeDefined();
expect(tileset.resource.url).toEqual(tilesetUrl);
},
);
});
it("loads tileset with extras", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
expect(tileset.extras).toEqual({ name: "Sample Tileset" });
expect(tileset.root.extras).toBeUndefined();
const length = tileset.root.children.length;
let taggedChildren = 0;
for (let i = 0; i < length; ++i) {
if (defined(tileset.root.children[i].extras)) {
expect(tileset.root.children[i].extras).toEqual({
id: "Special Tile",
});
++taggedChildren;
}
}
expect(taggedChildren).toEqual(1);
},
);
});
it("gets root tile", async function () {
const tileset = await Cesium3DTileset.fromUrl(tilesetUrl, options);
expect(tileset.root).toBeDefined();
});
it("hasExtension returns true if the tileset JSON file uses the specified extension", function () {
return Cesium3DTilesTester.loadTileset(
scene,
withBatchTableHierarchyUrl,
).then(function (tileset) {
expect(tileset.hasExtension("3DTILES_batch_table_hierarchy")).toBe(
true,
);
expect(tileset.hasExtension("3DTILES_nonexistant_extension")).toBe(
false,
);
});
});
it("passes version in query string to tiles", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
expect(tileset.root.content._resource.url).toEqual(
getAbsoluteUri(
tilesetUrl.replace("tileset.json", "parent.b3dm?v=1.2.3"),
),
);
},
);
});
it("passes version in query string to all external resources", function () {
// Spy on loadWithXhr so we can verify requested urls
spyOn(Resource._Implementations, "loadWithXhr").and.callThrough();
const queryParams = "?a=1&b=boy";
const queryParamsWithVersion = "?a=1&b=boy&v=1.2.3";
return Cesium3DTilesTester.loadTileset(
scene,
tilesetWithExternalResourcesUrl + queryParams,
).then(function (tileset) {
const calls = Resource._Implementations.loadWithXhr.calls.all();
const callsLength = calls.length;
for (let i = 0; i < callsLength; ++i) {
const url = calls[0].args[0];
if (url.indexOf(tilesetWithExternalResourcesUrl) >= 0) {
const query = url.slice(url.indexOf("?"));
if (url.indexOf("tileset.json") >= 0) {
// The initial tileset.json does not have a tileset version parameter
expect(query).toBe(queryParams);
} else {
expect(query).toBe(queryParamsWithVersion);
}
}
}
});
});
it("requests tile with invalid magic", async function () {
const invalidMagicBuffer = Cesium3DTilesTester.generateBatchedTileBuffer({
magic: [120, 120, 120, 120],
});
const tileset = await Cesium3DTileset.fromUrl(tilesetUrl, options);
scene.primitives.add(tileset);
const failedSpy = jasmine.createSpy("listenerSpy");
tileset.tileFailed.addEventListener(failedSpy);
// Start spying after the tileset json has been loaded
spyOn(Resource.prototype, "fetchArrayBuffer").and.returnValue(
Promise.resolve(invalidMagicBuffer),
);
scene.renderForSpecs(); // Request root
const root = tileset.root;
await pollToPromise(() => {
scene.renderForSpecs();
return root.contentFailed || root.contentReady;
});
expect(failedSpy).toHaveBeenCalledWith(
jasmine.objectContaining({
message: "Invalid tile content.",
}),
);
expect(root.contentFailed).toBeTrue();
await Cesium3DTilesTester.waitForTilesLoaded(scene, tileset);
});
it("handles failed tile requests", async function () {
viewRootOnly();
const tileset = await Cesium3DTileset.fromUrl(tilesetUrl, options);
scene.primitives.add(tileset);
const failedSpy = jasmine.createSpy("listenerSpy");
tileset.tileFailed.addEventListener(failedSpy);
// Start spying after the tileset json has been loaded
spyOn(Resource.prototype, "fetchArrayBuffer").and.callFake(() => {
return Promise.reject(new Error("404"));
});
scene.renderForSpecs(); // Request root
const root = tileset.root;
await pollToPromise(() => {
scene.renderForSpecs();
return root.contentFailed || root.contentReady;
});
expect(root.contentFailed).toBeTrue();
expect(failedSpy).toHaveBeenCalledWith(
jasmine.objectContaining({
message: "404",
}),
);
const statistics = tileset.statistics;
expect(statistics.numberOfAttemptedRequests).toBe(0);
expect(statistics.numberOfPendingRequests).toBe(0);
expect(statistics.numberOfTilesProcessing).toBe(0);
expect(statistics.numberOfTilesWithContentReady).toBe(0);
await Cesium3DTilesTester.waitForTilesLoaded(scene, tileset);
});
it("handles failed tile processing", async function () {
viewRootOnly();
const tileset = await Cesium3DTileset.fromUrl(tilesetUrl, options);
scene.primitives.add(tileset);
const failedSpy = jasmine.createSpy("listenerSpy");
tileset.tileFailed.addEventListener(failedSpy);
// Start spying after the tileset json has been loaded
spyOn(Resource.prototype, "fetchArrayBuffer").and.returnValue(
Promise.resolve(
Cesium3DTilesTester.generateBatchedTileBuffer({
version: 0, // Invalid version
}),
),
);
scene.renderForSpecs(); // Request root
const root = tileset.root;
await pollToPromise(() => {
scene.renderForSpecs();
return root.contentFailed || root.contentReady;
});
expect(root.contentFailed).toBeTrue();
expect(failedSpy).toHaveBeenCalledWith(
jasmine.objectContaining({
message:
"Only Batched 3D Model version 1 is supported. Version 0 is not.",
}),
);
const statistics = tileset.statistics;
expect(statistics.numberOfAttemptedRequests).toBe(0);
expect(statistics.numberOfPendingRequests).toBe(0);
expect(statistics.numberOfTilesProcessing).toBe(0);
expect(statistics.numberOfTilesWithContentReady).toBe(0);
await Cesium3DTilesTester.waitForTilesLoaded(scene, tileset);
});
it("renders tileset", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(5);
},
);
});
function checkAnimation(url) {
return Cesium3DTilesTester.loadTileset(scene, url).then(
function (tileset) {
const renderOptions = {
scene: scene,
time: new JulianDate(271.828),
};
expect(renderOptions).toRenderAndCall(function (rgba) {
const commandList = scene.frameState.commandList;
const modelMatrix1 = Matrix4.clone(commandList[0].modelMatrix);
// Check that the scene changes after .5 seconds. (it animates)
renderOptions.time.secondsOfDay += 0.5;
expect(renderOptions).toRenderAndCall(function (rgba) {
const modelMatrix2 = Matrix4.clone(commandList[0].modelMatrix);
expect(modelMatrix1).not.toEqual(modelMatrix2);
});
});
},
);
}
it("animates instanced tileset", function () {
return checkAnimation(instancedAnimationUrl);
});
it("animates batched tileset", function () {
return checkAnimation(batchedAnimationUrl);
});
it("renders tileset in CV", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
scene.morphToColumbusView(0.0);
scene.renderForSpecs();
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(5);
},
);
});
it("renders tileset in CV with projectTo2D option", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl, {
projectTo2D: true,
}).then(function (tileset) {
scene.morphToColumbusView(0.0);
scene.renderForSpecs();
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(5);
});
});
it("renders tileset in 2D", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
scene.morphTo2D(0.0);
tileset.maximumScreenSpaceError = 3;
scene.renderForSpecs();
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(5);
},
);
});
it("renders tileset in 2D with projectTo2D option", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl, {
projectTo2D: true,
}).then(function (tileset) {
scene.morphTo2D(0.0);
tileset.maximumScreenSpaceError = 3;
scene.renderForSpecs();
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(5);
});
});
it("does not render during morph", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
const commandList = scene.frameState.commandList;
scene.renderForSpecs();
expect(commandList.length).toBeGreaterThan(0);
scene.morphToColumbusView(1.0);
scene.renderForSpecs();
expect(commandList.length).toBe(0);
},
);
});
it("renders tileset with empty root tile", function () {
return Cesium3DTilesTester.loadTileset(scene, tilesetEmptyRootUrl).then(
function (tileset) {
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(4); // Empty tile doesn't issue a command
},
);
});
it("renders tileset with custom up and forward axes", async function () {
const center = Cartesian3.fromRadians(
centerLongitude,
centerLatitude,
10.0,
);
// 3 different views of the sides of the colored cube.
const viewEast = new HeadingPitchRange(-1.57, 0.0, 3.0);
const viewNorth = new HeadingPitchRange(3.14, 0.0, 3.0);
const viewUp = new HeadingPitchRange(0.0, -1.57, 3.0);
// This tile has data in a local ENU frame, ignoring the glTF +y-up
// convention. Apply a model matrix and configure the tileset to interpret
// the glTF data as +z up.
const tilesetOptions = {
modelMatrix: Transforms.eastNorthUpToFixedFrame(center),
modelUpAxis: Axis.Z,
modelForwardAxis: Axis.X,
};
const renderOptions = {
scene: scene,
time: JulianDate.fromIso8601("2022-06-09T10:30:00Z"),
};
// make sure we can see the cube so it loads
scene.camera.lookAt(center, viewEast);
const tileset = await Cesium3DTilesTester.loadTileset(
scene,
tilesetEastNorthUpUrl,
tilesetOptions,
);
// The east (+x) face of the cube is red
scene.camera.lookAt(center, viewEast);
expect(renderOptions).toRenderAndCall(function (rgba) {
expect(rgba[0]).toBeGreaterThan(190);
expect(rgba[1]).toBeLessThanOrEqual(108);
expect(rgba[2]).toBeLessThanOrEqual(108);
expect(rgba[3]).toEqual(255);
});
// The north (+y) face of the cube is green
scene.camera.lookAt(center, viewNorth);
expect(renderOptions).toRenderAndCall(function (rgba) {
expect(rgba[0]).toBeLessThanOrEqual(108);
expect(rgba[1]).toBeGreaterThan(180);
expect(rgba[2]).toBeLessThanOrEqual(108);
expect(rgba[3]).toEqual(255);
});
// The up (+z) face of the cube is blue
scene.camera.lookAt(center, viewUp);
expect(renderOptions).toRenderAndCall(function (rgba) {
expect(rgba[0]).toBeLessThanOrEqual(108);
expect(rgba[1]).toBeLessThanOrEqual(108);
expect(rgba[2]).toBeGreaterThan(180);
expect(rgba[3]).toEqual(255);
});
await Cesium3DTilesTester.waitForTilesLoaded(scene, tileset);
});
it("verify statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(tilesetUrl, options);
// Verify initial values after root and children are requested
const statistics = tileset._statistics;
expect(statistics.visited).toEqual(0);
expect(statistics.numberOfCommands).toEqual(0);
expect(statistics.numberOfPendingRequests).toEqual(0);
expect(statistics.numberOfTilesProcessing).toEqual(0);
scene.primitives.add(tileset);
// Wait for all tiles to load and check that they are all visited and rendered
await Cesium3DTilesTester.waitForTilesLoaded(scene, tileset);
expect(statistics.visited).toEqual(5);
expect(statistics.numberOfCommands).toEqual(5);
expect(statistics.numberOfPendingRequests).toEqual(0);
expect(statistics.numberOfTilesProcessing).toEqual(0);
});
function checkPointAndFeatureCounts(tileset, features, points, triangles) {
const statistics = tileset._statistics;
expect(statistics.numberOfFeaturesSelected).toEqual(0);
expect(statistics.numberOfFeaturesLoaded).toEqual(0);
expect(statistics.numberOfPointsSelected).toEqual(0);
expect(statistics.numberOfPointsLoaded).toEqual(0);
expect(statistics.numberOfTrianglesSelected).toEqual(0);
return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(
function () {
expect(statistics.numberOfFeaturesSelected).toEqual(features);
expect(statistics.numberOfFeaturesLoaded).toEqual(features);
expect(statistics.numberOfPointsSelected).toEqual(points);
expect(statistics.numberOfPointsLoaded).toEqual(points);
expect(statistics.numberOfTrianglesSelected).toEqual(triangles);
viewNothing();
scene.renderForSpecs();
expect(statistics.numberOfFeaturesSelected).toEqual(0);
expect(statistics.numberOfFeaturesLoaded).toEqual(features);
expect(statistics.numberOfPointsSelected).toEqual(0);
expect(statistics.numberOfPointsLoaded).toEqual(points);
expect(statistics.numberOfTrianglesSelected).toEqual(0);
tileset.trimLoadedTiles();
scene.renderForSpecs();
expect(statistics.numberOfFeaturesSelected).toEqual(0);
expect(statistics.numberOfFeaturesLoaded).toEqual(0);
expect(statistics.numberOfPointsSelected).toEqual(0);
expect(statistics.numberOfPointsLoaded).toEqual(0);
expect(statistics.numberOfTrianglesSelected).toEqual(0);
},
);
}
it("verify batched features statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(withBatchTableUrl, options);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 10, 0, 120);
});
it("verify no batch table features statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(noBatchIdsUrl, options);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 0, 0, 120);
});
it("verify instanced features statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(
instancedRedMaterialUrl,
options,
);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 25, 0, 12);
});
it("verify composite features statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(compositeUrl, options);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 35, 0, 132);
});
it("verify tileset of tilesets features statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(
tilesetOfTilesetsUrl,
options,
);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 50, 0, 600);
});
it("verify points statistics", async function () {
viewPointCloud();
const tileset = await Cesium3DTileset.fromUrl(pointCloudUrl, options);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 0, 1000, 0);
});
it("verify triangle statistics", async function () {
const tileset = await Cesium3DTileset.fromUrl(
tilesetEmptyRootUrl,
options,
);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 40, 0, 480);
});
it("verify batched points statistics", async function () {
viewPointCloud();
const tileset = await Cesium3DTileset.fromUrl(
pointCloudBatchedUrl,
options,
);
scene.primitives.add(tileset);
return checkPointAndFeatureCounts(tileset, 8, 1000, 0);
});
it("verify memory usage statistics", function () {
// 10 buildings, 36 ushort indices and 24 vertices per building, 6 float
// components (position, normal) and 1 uint component (batchId) per vertex
// 10 * [(24 * (6 * 4 + 1 * 4)) + (36 * 2)] = 7440 bytes
const singleTileGeometryMemory = 7440;
const singleTileTextureMemory = 0;
const singleTileBatchTextureMemory = 40;
const singleTilePickTextureMemory = 40;
const tilesLength = 5;
viewNothing();
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(
function (tileset) {
const statistics = tileset._statistics;
// No tiles loaded
expect(statistics.geometryByteLength).toEqual(0);
expect(statistics.texturesByteLength).toEqual(0);
expect(statistics.batchTableByteLength).toEqual(0);
viewRootOnly();
return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(
function () {
// Root tile loaded
expect(statistics.geometryByteLength).toEqual(
singleTileGeometryMemory,
);
expect(statistics.texturesByteLength).toEqual(
singleTileTextureMemory,
);
expect(statistics.batchTableByteLength).toEqual(0);
viewAllTiles();
return Cesium3DTilesTester.waitForTilesLoaded(
scene,
tileset,
).then(function () {
// All tiles loaded
expect(statistics.geometryByteLength).toEqual(
singleTileGeometryMemory * tilesLength,
);
expect(statistics.texturesByteLength).toEqual(
singleTileTextureMemory * tilesLength,
);
expect(statistics.batchTableByteLength).toEqual(0);
// One feature colored, the batch table memory is now higher
tileset.root.content.getFeature(0).color = Color.RED;
scene.renderForSpecs();
expect(statistics.geometryByteLength).toEqual(
singleTileGeometryMemory * tilesLength,
);
expect(statistics.texturesByteLength).toEqual(
singleTileTextureMemory * tilesLength,
);
expect(statistics.batchTableByteLength).toEqual(
singleTileBatchTextureMemory,
);
// All tiles picked, the texture memory is now higher
scene.pickForSpecs();
expect(statistics.geometryByteLength).toEqual(
singleTileGeometryMemory * tilesLength,
);
expect(statistics.texturesByteLength).toEqual(
singleTileTextureMemory * tilesLength,
);
expect(statistics.batchTableByteLength).toEqual(
singleTileBatchTextureMemory +
singleTilePickTextureMemory * tilesLength,
);
// Tiles are still in memory when zoomed out
viewNothing();
scene.renderForSpecs();
expect(statistics.geometryByteLength).toEqual(
singleTileGeometryMemory * tilesLength,
);
expect(statistics.texturesByteLength).toEqual(
singleTileTextureMemory * tilesLength,
);
expect(statistics.batchTableByteLength).toEqual(
singleTileBatchTextureMemory +
singleTilePickTextureMemory * tilesLength,
);
// Trim loaded tiles, expect the memory statistics to be 0
tileset.trimLoadedTiles();
scene.renderForSpecs();
expect(statistics.geometryByteLength).toEqual(0);
expect(statistics.texturesByteLength).toEqual(0);
expect(statistics.batchTableByteLength).toEqual(0);
});
},
);
},
);
});
it("verify memory usage statistics for shared textures", async function () {
// One buffer view with 4 positions, 4 normals, and 4 texture coordinates,
// using a common byte stride of 12 (resulting in 144 bytes)
// and 2*3 unsigned short indices, resulting in a total of 156 bytes
const singleGeometryByteLength = 156;
// One texture with 128x128 * RGBA pixels = 65536 bytes
const singleTexturesByteLength = 65536;
// Basic camera setup
const camera = scene.camera;
// NOTE: This is really, really important. There are some
// random calls in "beforeEach" and other parts of these
// specs that affect the camera transform. And the camera
// transform is NOT maintained to be consistent with the
// other properties in any way. So reset it here...
camera.lookAtTransform(Matrix4.IDENTITY);
camera.position = new Cartesian3(0, -1, 0);
camera.direction = Cartesian3.clone(Cartesian3.UNIT_Y);
camera.up = Cartesian3.clone(Cartesian3.UNIT_Z);
camera.frustum.near = 0.01;
camera.frustum.far = 100.0;
// Move the camera to see no tiles
camera.position = new Cartesian3(100, -1, 100);
const tileset = await Cesium3DTilesTester.loadTileset(