-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Cesium3DTileBatchTableSpec.js
1099 lines (966 loc) · 43.6 KB
/
Cesium3DTileBatchTableSpec.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
/*global defineSuite*/
defineSuite([
'Scene/Cesium3DTileBatchTable',
'Core/Cartesian2',
'Core/Cartesian3',
'Core/Cartesian4',
'Core/Color',
'Core/defined',
'Core/HeadingPitchRange',
'Core/Matrix2',
'Core/Matrix3',
'Core/Matrix4',
'Renderer/ContextLimits',
'Scene/Cesium3DTileStyle',
'Specs/Cesium3DTilesTester',
'Specs/createScene'
], function(
Cesium3DTileBatchTable,
Cartesian2,
Cartesian3,
Cartesian4,
Color,
defined,
HeadingPitchRange,
Matrix2,
Matrix3,
Matrix4,
ContextLimits,
Cesium3DTileStyle,
Cesium3DTilesTester,
createScene) {
'use strict';
var scene;
var centerLongitude = -1.31968;
var centerLatitude = 0.698874;
var withBatchTableUrl = './Data/Cesium3DTiles/Batched/BatchedWithBatchTable/';
var withoutBatchTableUrl = './Data/Cesium3DTiles/Batched/BatchedWithoutBatchTable/';
var noBatchIdsUrl = './Data/Cesium3DTiles/Batched/BatchedNoBatchIds/';
var batchTableHierarchyUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchy/';
var batchTableHierarchyBinaryUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyBinary/';
var batchTableHierarchyMultipleParentsUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyMultipleParents/';
var batchTableHierarchyNoParentsUrl = './Data/Cesium3DTiles/Hierarchy/BatchTableHierarchyNoParents/';
var result = new Color();
var mockContent = {
getFeature : function(batchId) {
return {};
}
};
beforeAll(function() {
scene = createScene();
// One feature is located at the center, point the camera there
var center = Cartesian3.fromRadians(centerLongitude, centerLatitude);
scene.camera.lookAt(center, new HeadingPitchRange(0.0, -1.57, 20.0));
});
afterAll(function() {
scene.destroyForSpecs();
});
afterEach(function() {
scene.primitives.removeAll();
});
it('setShow throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setShow();
}).toThrowDeveloperError();
expect(function() {
batchTable.setShow(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.setShow(2);
}).toThrowDeveloperError();
});
it('setShow throws with undefined value', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setShow(0);
}).toThrowDeveloperError();
});
it('setShow', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
// Batch table resources are undefined by default
expect(batchTable._batchValues).toBeUndefined();
expect(batchTable._batchTexture).toBeUndefined();
// Check that batch table resources are still undefined because value is true by default
batchTable.setShow(0, true);
batchTable.update(mockContent, scene.frameState);
expect(batchTable._batchValues).toBeUndefined();
expect(batchTable._batchTexture).toBeUndefined();
expect(batchTable.getShow(0)).toEqual(true);
// Check that batch values are dirty and resources are created when value changes
batchTable.setShow(0, false);
expect(batchTable._batchValuesDirty).toEqual(true);
batchTable.update(mockContent, scene.frameState);
expect(batchTable._batchValues).toBeDefined();
expect(batchTable._batchTexture).toBeDefined();
expect(batchTable._batchValuesDirty).toEqual(false);
expect(batchTable.getShow(0)).toEqual(false);
// Check that dirty stays false when value is the same
batchTable.setShow(0, false);
expect(batchTable._batchValuesDirty).toEqual(false);
expect(batchTable.getShow(0)).toEqual(false);
});
it('getShow throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getShow();
}).toThrowDeveloperError();
expect(function() {
batchTable.getShow(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.getShow(2);
}).toThrowDeveloperError();
});
it('getShow', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
// Show is true by default
expect(batchTable.getShow(0)).toEqual(true);
batchTable.setShow(0, false);
expect(batchTable.getShow(0)).toEqual(false);
});
it('setColor throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setColor();
}).toThrowDeveloperError();
expect(function() {
batchTable.setColor(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.setColor(2);
}).toThrowDeveloperError();
});
it('setColor throws with undefined value', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setColor(0);
}).toThrowDeveloperError();
});
it('setColor', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
// Batch table resources are undefined by default
expect(batchTable._batchValues).toBeUndefined();
expect(batchTable._batchTexture).toBeUndefined();
// Check that batch table resources are still undefined because value is true by default
batchTable.setColor(0, Color.WHITE);
batchTable.update(mockContent, scene.frameState);
expect(batchTable._batchValues).toBeUndefined();
expect(batchTable._batchTexture).toBeUndefined();
expect(batchTable.getColor(0, result)).toEqual(Color.WHITE);
// Check that batch values are dirty and resources are created when value changes
batchTable.setColor(0, Color.YELLOW);
expect(batchTable._batchValuesDirty).toEqual(true);
batchTable.update(mockContent, scene.frameState);
expect(batchTable._batchValues).toBeDefined();
expect(batchTable._batchTexture).toBeDefined();
expect(batchTable._batchValuesDirty).toEqual(false);
expect(batchTable.getColor(0, result)).toEqual(Color.YELLOW);
// Check that dirty stays false when value is the same
batchTable.setColor(0, Color.YELLOW);
expect(batchTable._batchValuesDirty).toEqual(false);
expect(batchTable.getColor(0, result)).toEqual(Color.YELLOW);
});
it('setAllColor throws with undefined value', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setAllColor();
}).toThrowDeveloperError();
});
it('setAllColor', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 2);
batchTable.setAllColor(Color.YELLOW);
expect(batchTable.getColor(0, result)).toEqual(Color.YELLOW);
expect(batchTable.getColor(1, result)).toEqual(Color.YELLOW);
});
it('getColor throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getColor();
}).toThrowDeveloperError();
expect(function() {
batchTable.getColor(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.getColor(2);
}).toThrowDeveloperError();
});
it('getColor throws with undefined result', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getColor(0);
}).toThrowDeveloperError();
});
it('getColor', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
// Color is true by default
expect(batchTable.getColor(0, result)).toEqual(Color.WHITE);
batchTable.setColor(0, Color.YELLOW);
expect(batchTable.getColor(0, result)).toEqual(Color.YELLOW);
});
it('hasProperty throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.hasProperty();
}).toThrowDeveloperError();
expect(function() {
batchTable.hasProperty(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.hasProperty(2);
}).toThrowDeveloperError();
});
it('hasProperty throws with undefined name', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.hasProperty(0);
}).toThrowDeveloperError();
});
it('hasProperty', function() {
var batchTableJson = {
height: [0.0]
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 1, batchTableJson);
expect(batchTable.hasProperty(0, 'height')).toEqual(true);
expect(batchTable.hasProperty(0, 'id')).toEqual(false);
});
it('getPropertyNames throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getPropertyNames();
}).toThrowDeveloperError();
expect(function() {
batchTable.getPropertyNames(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.getPropertyNames(2);
}).toThrowDeveloperError();
});
it('getPropertyNames', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(batchTable.getPropertyNames(0)).toEqual([]);
var batchTableJson = {
height: [0.0],
id : [0]
};
batchTable = new Cesium3DTileBatchTable(mockContent, 1, batchTableJson);
expect(batchTable.getPropertyNames(0)).toEqual(['height', 'id']);
});
it('getProperty throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getProperty();
}).toThrowDeveloperError();
expect(function() {
batchTable.getProperty(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.getProperty(2);
}).toThrowDeveloperError();
});
it('getProperty throws with undefined name', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getProperty(0);
}).toThrowDeveloperError();
});
it('getProperty', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(batchTable.getProperty(0, 'height')).toBeUndefined();
var batchTableJson = {
height: [1.0]
};
batchTable = new Cesium3DTileBatchTable(mockContent, 1, batchTableJson);
expect(batchTable.getProperty(0, 'height')).toEqual(1.0);
expect(batchTable.getProperty(0, 'id')).toBeUndefined();
});
it('setProperty throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setProperty();
}).toThrowDeveloperError();
expect(function() {
batchTable.setProperty(-1);
}).toThrowDeveloperError();
expect(function() {
batchTable.setProperty(2);
}).toThrowDeveloperError();
});
it('setProperty throws with undefined name', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.setProperty(0);
}).toThrowDeveloperError();
});
it('setProperty without existing batch table', function() {
// Check that a batch table is created with a height of 1.0 for the first resource and undefined for the others
var batchTable = new Cesium3DTileBatchTable(mockContent, 3);
batchTable.setProperty(0, 'height', 1.0);
expect(batchTable.batchTableJson.height.length).toEqual(3);
expect(batchTable.getProperty(0, 'height')).toEqual(1.0);
expect(batchTable.getProperty(1, 'height')).toBeUndefined();
expect(batchTable.getProperty(2, 'height')).toBeUndefined();
});
it('setProperty with existing batch table', function() {
var batchTableJson = {
height : [1.0, 2.0]
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 2, batchTableJson);
batchTable.setProperty(0, 'height', 3.0);
expect(batchTable.getProperty(0, 'height')).toEqual(3.0);
expect(batchTable.getProperty(1, 'height')).toEqual(2.0);
});
it('setProperty with object value', function() {
var batchTableJson = {
info : [{name : 'building0', year : 2000}, {name : 'building1', year : 2001}]
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 2, batchTableJson);
batchTable.setProperty(0, 'info', {name : 'building0_new', year : 2002});
expect(batchTable.getProperty(0, 'info')).toEqual({name : 'building0_new', year : 2002});
expect(batchTable.getProperty(1, 'info')).toEqual({name : 'building1', year : 2001});
});
it('setProperty with array value', function() {
var batchTableJson = {
rooms : [['room1', 'room2'], ['room3', 'room4']]
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 2, batchTableJson);
batchTable.setProperty(0, 'rooms', ['room1_new', 'room2']);
expect(batchTable.getProperty(0, 'rooms')).toEqual(['room1_new', 'room2']);
expect(batchTable.getProperty(1, 'rooms')).toEqual(['room3', 'room4']);
});
it('throws if the binary property does not specify a componentType', function() {
var batchTableJson = {
propertyScalar : {
byteOffset : 0,
type : 'SCALAR'
}
};
var batchTableBinary = new Float64Array([0, 1]);
expect(function() {
return new Cesium3DTileBatchTable(mockContent, 2, batchTableJson, batchTableBinary);
}).toThrowDeveloperError();
});
it('throws if the binary property does not specify a type', function() {
var batchTableJson = {
propertyScalar : {
byteOffset : 0,
componentType : 'DOUBLE'
}
};
var batchTableBinary = new Float64Array([0, 1]);
expect(function() {
return new Cesium3DTileBatchTable(mockContent, 2, batchTableJson, batchTableBinary);
}).toThrowDeveloperError();
});
it('throws if a binary property exists but there is no batchTableBinary', function() {
var batchTableJson = {
propertyScalar : {
byteOffset : 0,
componentType : 'DOUBLE',
type : 'SCALAR'
}
};
expect(function() {
return new Cesium3DTileBatchTable(mockContent, 2, batchTableJson);
}).toThrowDeveloperError();
});
function concatTypedArrays(arrays) {
var i;
var length = arrays.length;
var byteLength = 0;
for (i = 0; i < length; ++i) {
byteLength += arrays[i].byteLength;
}
var buffer = new Uint8Array(byteLength);
var byteOffset = 0;
for (i = 0; i < length; ++i) {
var data = new Uint8Array(arrays[i].buffer);
byteLength = data.length;
for (var j = 0; j < byteLength; ++j) {
buffer[byteOffset++] = data[j];
}
}
return buffer;
}
it('getProperty and setProperty work for binary properties', function() {
var propertyScalarBinary = new Float64Array([0, 1]);
var propertyVec2Binary = new Float32Array([2, 3, 4, 5]);
var propertyVec3Binary = new Int32Array([6, 7, 8, 9, 10, 11]);
var propertyVec4Binary = new Uint32Array([12, 13, 14, 15, 16, 17, 18, 19]);
var propertyMat2Binary = new Int16Array([20, 21, 22, 23, 24, 25, 26, 27]);
var propertyMat3Binary = new Uint16Array([28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45]);
var propertyMat4Binary = new Uint8Array([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]);
var buffers = [propertyScalarBinary, propertyVec2Binary, propertyVec3Binary, propertyVec4Binary, propertyMat2Binary, propertyMat3Binary, propertyMat4Binary];
var batchTableBinary = concatTypedArrays(buffers);
var batchTableJson = {
propertyScalar : {
byteOffset : 0,
componentType : 'DOUBLE',
type : 'SCALAR'
},
propertyVec2 : {
byteOffset : 16,
componentType : 'FLOAT',
type : 'VEC2'
},
propertyVec3 : {
byteOffset : 32,
componentType : 'INT',
type : 'VEC3'
},
propertyVec4 : {
byteOffset : 56,
componentType : 'UNSIGNED_INT',
type : 'VEC4'
},
propertyMat2 : {
byteOffset : 88,
componentType : 'SHORT',
type : 'MAT2'
},
propertyMat3 : {
byteOffset : 104,
componentType : 'UNSIGNED_SHORT',
type : 'MAT3'
},
propertyMat4 : {
byteOffset : 140,
componentType : 'UNSIGNED_BYTE',
type : 'MAT4'
}
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 2, batchTableJson, batchTableBinary);
expect(batchTable.getProperty(1, 'propertyScalar')).toEqual(1);
expect(batchTable.getProperty(1, 'propertyVec2')).toEqual(new Cartesian2(4, 5));
expect(batchTable.getProperty(1, 'propertyVec3')).toEqual(new Cartesian3(9, 10, 11));
expect(batchTable.getProperty(1, 'propertyVec4')).toEqual(new Cartesian4(16, 17, 18, 19));
expect(batchTable.getProperty(1, 'propertyMat2')).toEqual(new Matrix2(24, 26, 25, 27)); // Constructor is row-major, data is column major
expect(batchTable.getProperty(1, 'propertyMat3')).toEqual(new Matrix3(37, 40, 43, 38, 41, 44, 39, 42, 45)); // Constructor is row-major, data is column major
expect(batchTable.getProperty(1, 'propertyMat4')).toEqual(new Matrix4(62, 66, 70, 74, 63, 67, 71, 75, 64, 68, 72, 76, 65, 69, 73, 77)); // Constructor is row-major, data is column major
batchTable.setProperty(1, 'propertyScalar', 2);
batchTable.setProperty(1, 'propertyVec2', new Cartesian2(5, 6));
batchTable.setProperty(1, 'propertyVec3', new Cartesian3(10, 11, 12));
batchTable.setProperty(1, 'propertyVec4', new Cartesian4(17, 18, 19, 20));
batchTable.setProperty(1, 'propertyMat2', new Matrix2(25, 27, 26, 28));
batchTable.setProperty(1, 'propertyMat3', new Matrix3(38, 41, 44, 39, 42, 45, 40, 43, 46));
batchTable.setProperty(1, 'propertyMat4', new Matrix4(63, 67, 71, 75, 64, 68, 72, 76, 65, 69, 73, 77, 66, 70, 74, 78));
expect(batchTable.getProperty(1, 'propertyScalar')).toEqual(2);
expect(batchTable.getProperty(1, 'propertyVec2')).toEqual(new Cartesian2(5, 6));
expect(batchTable.getProperty(1, 'propertyVec3')).toEqual(new Cartesian3(10, 11, 12));
expect(batchTable.getProperty(1, 'propertyVec4')).toEqual(new Cartesian4(17, 18, 19, 20));
expect(batchTable.getProperty(1, 'propertyMat2')).toEqual(new Matrix2(25, 27, 26, 28));
expect(batchTable.getProperty(1, 'propertyMat3')).toEqual(new Matrix3(38, 41, 44, 39, 42, 45, 40, 43, 46));
expect(batchTable.getProperty(1, 'propertyMat4')).toEqual(new Matrix4(63, 67, 71, 75, 64, 68, 72, 76, 65, 69, 73, 77, 66, 70, 74, 78));
});
it('renders tileset with batch table', function() {
return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then(function(tileset) {
var content = tileset._root.content;
// Each feature in the b3dm file has an id property from 0 to 9,
// check that the 2nd resource has an id of 2
expect(content.getFeature(2).getProperty('id')).toEqual(2);
// Check that a property can be an array
expect(content.getFeature(2).getProperty('rooms')).toEqual(['room2_a', 'room2_b', 'room2_c']);
// Check that a property can be an object
expect(content.getFeature(2).getProperty('info')).toEqual({name : 'building2', year : 2});
Cesium3DTilesTester.expectRenderTileset(scene, tileset);
});
});
it('renders tileset without batch table', function() {
return Cesium3DTilesTester.loadTileset(scene, withoutBatchTableUrl).then(function(tileset) {
var content = tileset._root.content;
expect(content.getFeature(2).getProperty('id')).toBeUndefined();
Cesium3DTilesTester.expectRenderTileset(scene, tileset);
});
});
it('renders when vertex texture fetch is not supported', function() {
// Disable VTF
var maximumVertexTextureImageUnits = ContextLimits.maximumVertexTextureImageUnits;
ContextLimits._maximumVertexTextureImageUnits = 0;
return Cesium3DTilesTester.loadTileset(scene, withoutBatchTableUrl).then(function(tileset) {
Cesium3DTilesTester.expectRenderTileset(scene, tileset);
// Re-enable VTF
ContextLimits._maximumVertexTextureImageUnits = maximumVertexTextureImageUnits;
});
});
it('renders with featuresLength greater than maximumTextureSize', function() {
// Set maximum texture size to 4 temporarily. Batch length of b3dm file is 10.
var maximumTextureSize = ContextLimits.maximumTextureSize;
ContextLimits._maximumTextureSize = 4;
return Cesium3DTilesTester.loadTileset(scene, withoutBatchTableUrl).then(function(tileset) {
var content = tileset._root.content;
expect(content.featuresLength).toBeGreaterThan(ContextLimits._maximumTextureSize);
Cesium3DTilesTester.expectRenderTileset(scene, tileset);
// Reset maximum texture size
ContextLimits._maximumTextureSize = maximumTextureSize;
});
});
it('renders with featuresLength of zero', function() {
return Cesium3DTilesTester.loadTileset(scene, noBatchIdsUrl).then(function(tileset) {
Cesium3DTilesTester.expectRender(scene, tileset);
expect(scene).toPickAndCall(function(result) {
expect(result).toBeDefined();
expect(result.primitive).toBe(tileset);
});
});
});
it('renders with debug color', function() {
return Cesium3DTilesTester.loadTileset(scene, withoutBatchTableUrl).then(function(tileset) {
// Get initial color
var color;
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
color = rgba;
});
// Check for debug color
tileset.debugColorizeTiles = true;
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
expect(rgba).not.toEqual(color);
});
// Check for original color
tileset.debugColorizeTiles = false;
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
expect(rgba).toEqual(color);
});
});
});
function expectRenderTranslucent(tileset) {
var batchTable = tileset._root.content.batchTable;
// Get initial color
var opaqueColor;
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
opaqueColor = rgba;
});
// Render translucent
batchTable.setAllColor(new Color(1.0, 1.0, 1.0, 0.5));
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
expect(rgba).not.toEqual(opaqueColor);
});
// Render restored to opaque
batchTable.setAllColor(Color.WHITE);
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
expect(rgba).toEqual(opaqueColor);
});
// Generate both translucent and opaque commands
batchTable.setColor(0, new Color(1.0, 1.0, 1.0, 0.5));
Cesium3DTilesTester.expectRender(scene, tileset);
// Fully transparent
batchTable.setAllColor(new Color(1.0, 1.0, 1.0, 0.0));
Cesium3DTilesTester.expectRenderBlank(scene, tileset);
}
it('renders translucent style', function() {
return Cesium3DTilesTester.loadTileset(scene, withoutBatchTableUrl).then(function(tileset) {
expectRenderTranslucent(tileset);
});
});
it('renders translucent style when vertex texture fetch is not supported', function() {
// Disable VTF
var maximumVertexTextureImageUnits = ContextLimits.maximumVertexTextureImageUnits;
ContextLimits._maximumVertexTextureImageUnits = 0;
return Cesium3DTilesTester.loadTileset(scene, withoutBatchTableUrl).then(function(tileset) {
expectRenderTranslucent(tileset);
// Re-enable VTF
ContextLimits._maximumVertexTextureImageUnits = maximumVertexTextureImageUnits;
});
});
it('isExactClass throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.isExactClass();
}).toThrowDeveloperError();
expect(function() {
batchTable.isExactClass(2, 'door');
}).toThrowDeveloperError();
expect(function() {
batchTable.isExactClass(-1, 'door');
}).toThrowDeveloperError();
});
it('isExactClass throws with undefined className', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.isExactClass(0);
}).toThrowDeveloperError();
});
it('isClass throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.isClass();
}).toThrowDeveloperError();
expect(function() {
batchTable.isClass(2, 'door');
}).toThrowDeveloperError();
expect(function() {
batchTable.isClass(-1, 'door');
}).toThrowDeveloperError();
});
it('isClass throws with undefined className', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.isClass(0);
}).toThrowDeveloperError();
});
it('getExactClassName throws with invalid batchId', function() {
var batchTable = new Cesium3DTileBatchTable(mockContent, 1);
expect(function() {
batchTable.getExactClassName();
}).toThrowDeveloperError();
expect(function() {
batchTable.getExactClassName(1000);
}).toThrowDeveloperError();
expect(function() {
batchTable.getExactClassName(-1);
}).toThrowDeveloperError();
});
function checkHierarchyStyling(tileset) {
// Check that a feature is colored from a generic batch table property.
tileset.style = new Cesium3DTileStyle({color : "${height} === 6.0 ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check that a feature is colored from a class property.
tileset.style = new Cesium3DTileStyle({color : "${roof_name} === 'roof2' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check that a feature is colored from an inherited property.
tileset.style = new Cesium3DTileStyle({color : "${building_name} === 'building2' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check isExactClass
tileset.style = new Cesium3DTileStyle({color : "isExactClass('roof') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
tileset.style = new Cesium3DTileStyle({color : "isExactClass('door') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[1]).toBeGreaterThan(1); // Expect green
});
// Check isClass
tileset.style = new Cesium3DTileStyle({color : "isClass('roof') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
tileset.style = new Cesium3DTileStyle({color : "isClass('zone') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check getExactClassName
tileset.style = new Cesium3DTileStyle({color : "getExactClassName() === 'roof' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
tileset.style = new Cesium3DTileStyle({color : "getExactClassName() === 'zone' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[1]).toBeGreaterThan(0); // Expect green
});
}
function checkHierarchyStylingNoParents(tileset) {
// Check that a feature is colored from a generic batch table property.
tileset.style = new Cesium3DTileStyle({color : "${height} === 6.0 ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check that a feature is colored from a class property.
tileset.style = new Cesium3DTileStyle({color : "${roof_name} === 'roof2' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check isExactClass
tileset.style = new Cesium3DTileStyle({color : "isExactClass('roof') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check isClass
tileset.style = new Cesium3DTileStyle({color : "isClass('roof') ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
// Check getExactClassName
tileset.style = new Cesium3DTileStyle({color : "getExactClassName() === 'roof' ? color('red') : color('green')"});
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba[0]).toBeGreaterThan(0); // Expect red
});
}
function checkHierarchyProperties(tileset, multipleParents) {
// Check isExactClass, isClass, and getExactClassName in Cesium3DTileFeature
var content = tileset._root.content;
var batchTable = content.batchTable;
var hierarchy = batchTable._batchTableHierarchy;
var doorFeature = content.getFeature(4);
var roofFeature = content.getFeature(8);
expect(doorFeature.isExactClass('door')).toBe(true);
expect(doorFeature.isExactClass('building')).toBe(false);
expect(doorFeature.isClass('door')).toBe(true);
expect(doorFeature.isClass('doorknob')).toBe(false);
expect(doorFeature.isClass('building')).toBe(true);
expect(doorFeature.getExactClassName()).toBe('door');
expect(doorFeature.hasProperty('door_name')).toBe(true);
expect(doorFeature.hasProperty('height')).toBe(true);
// Includes batch table properties and hierarchy properties from all inherited classes
var expectedPropertyNames = ['height', 'area', 'door_mass', 'door_width', 'door_name', 'building_area', 'building_name', 'zone_buildings', 'zone_name'];
// door0 has two parents - building0 and classifier_old
// building0 has two parents - zone0 and classifier_new
if (multipleParents) {
expectedPropertyNames.push('year', 'color', 'name', 'architect'); // classier_new
expectedPropertyNames.push('description', 'inspection'); // classifier_old
}
var propertyNames = doorFeature.getPropertyNames();
expect(expectedPropertyNames.sort()).toEqual(propertyNames.sort());
expect(doorFeature.getProperty('height')).toBe(5.0); // Gets generic property
expect(doorFeature.getProperty('door_name')).toBe('door0'); // Gets class property
expect(doorFeature.getProperty('building_name')).toBe('building0'); // Gets inherited property
// Sets generic property
doorFeature.setProperty('height', 10.0);
expect(doorFeature.getProperty('height')).toBe(10.0);
// Sets class property
doorFeature.setProperty('door_name', 'new_door');
expect(doorFeature.getProperty('door_name')).toBe('new_door');
expect(roofFeature.getProperty('door_name')).toBeUndefined();
// Throws error when setting inherited property
expect(function() {
doorFeature.setProperty('building_name', 'new_building');
}).toThrowDeveloperError();
// Check properties when there is no hierarchy
batchTable._batchTableHierarchy = undefined;
expect(doorFeature.isExactClass('door')).toBe(false);
expect(doorFeature.isClass('door')).toBe(false);
expect(doorFeature.getExactClassName()).toBeUndefined();
expect(doorFeature.hasProperty('door_name')).toBe(false);
expect(doorFeature.hasProperty('height')).toBe(true);
expect(doorFeature.getPropertyNames()).toEqual(['height', 'area']);
expect(doorFeature.getProperty('height')).toBe(10.0);
expect(doorFeature.getProperty('door_name')).toBeUndefined();
expect(doorFeature.getProperty('building_name')).toBeUndefined();
batchTable._batchTableHierarchy = hierarchy;
}
function checkHierarchyPropertiesNoParents(tileset) {
// Check isExactClass, isClass, and getExactClassName in Cesium3DTileFeature
var content = tileset._root.content;
var doorFeature = content.getFeature(4);
expect(doorFeature.isExactClass('door')).toBe(true);
expect(doorFeature.isExactClass('doorknob')).toBe(false);
expect(doorFeature.isClass('door')).toBe(true);
expect(doorFeature.isClass('doorknob')).toBe(false);
expect(doorFeature.getExactClassName()).toBe('door');
expect(doorFeature.hasProperty('door_name')).toBe(true);
expect(doorFeature.hasProperty('height')).toBe(true);
// Includes batch table properties and hierarchy properties from all inherited classes
var expectedPropertyNames = ['height', 'area', 'door_mass', 'door_width', 'door_name'];
var propertyNames = doorFeature.getPropertyNames();
expect(expectedPropertyNames.sort()).toEqual(propertyNames.sort());
expect(doorFeature.getProperty('height')).toBe(5.0); // Gets generic property
expect(doorFeature.getProperty('door_name')).toBe('door0'); // Gets class property
// Sets generic property
doorFeature.setProperty('height', 10.0);
expect(doorFeature.getProperty('height')).toBe(10.0);
// Sets class property
doorFeature.setProperty('door_name', 'new_door');
expect(doorFeature.getProperty('door_name')).toBe('new_door');
}
function checkBatchTableHierarchy(url, multipleParents) {
return Cesium3DTilesTester.loadTileset(scene, url).then(function(tileset) {
checkHierarchyStyling(tileset);
checkHierarchyProperties(tileset, multipleParents);
});
}
function checkBatchTableHierarchyNoParents(url) {
return Cesium3DTilesTester.loadTileset(scene, url).then(function(tileset) {
checkHierarchyStylingNoParents(tileset);
checkHierarchyPropertiesNoParents(tileset);
});
}
it('renders tileset with batch table hierarchy', function() {
return checkBatchTableHierarchy(batchTableHierarchyUrl, false);
});
it('renders tileset with batch table hierarchy using binary properties', function() {
return checkBatchTableHierarchy(batchTableHierarchyBinaryUrl, true);
});
it('renders tileset with batch table hierarchy with multiple parent classes', function() {
return checkBatchTableHierarchy(batchTableHierarchyMultipleParentsUrl, true);
});
it('renders tileset with batch table hierarchy with no parents', function() {
return checkBatchTableHierarchyNoParents(batchTableHierarchyNoParentsUrl);
});
it('validates hierarchy with multiple parents', function() {
// building0
// / \
// door0 door1
// \ /
// window0
var batchTableJson = {
HIERARCHY : {
instancesLength : 4,
classIds : [0, 1, 1, 2],
parentCounts : [2, 1, 1, 0],
parentIds : [1, 2, 3, 3],
classes : [{
name : 'window',
length : 1,
instances : {
window_name : ['window0']
}
}, {
name : 'door',
length : 2,
instances : {
door_name : ['door0', 'door1']
}
}, {
name : 'building',
length : 1,
instances : {
building_name : ['building0']
}
}]
}
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 4, batchTableJson);
expect(batchTable.getPropertyNames(0).sort()).toEqual(['building_name', 'door_name', 'window_name']);
});
it('validates hierarchy with multiple parents (2)', function() {
// zone
// / | \
// building0 | \
// / \ | \
// door0 door1 /
// \ | /
// window0
var batchTableJson = {
HIERARCHY : {
instancesLength : 4,
classIds : [0, 1, 1, 2, 3],
parentCounts : [3, 1, 2, 1, 0],
parentIds : [1, 2, 4, 3, 3, 4, 4],
classes : [{
name : 'window',
length : 1,
instances : {
window_name : ['window0']
}
}, {
name : 'door',
length : 2,
instances : {
door_name : ['door0', 'door1']
}
}, {
name : 'building',
length : 1,
instances : {
building_name : ['building0']
}
}, {
name : 'zone',
length : 1,
instances : {
zone_name : ['zone0']
}
}]
}
};
var batchTable = new Cesium3DTileBatchTable(mockContent, 5, batchTableJson);
expect(batchTable.getPropertyNames(0).sort()).toEqual(['building_name', 'door_name', 'window_name', 'zone_name']); // check window
expect(batchTable.hasProperty(1, 'zone_name')).toEqual(true); // check door0
expect(batchTable.hasProperty(2, 'zone_name')).toEqual(true); // check door1
});
//>>includeStart('debug', pragmas.debug);
// Circular dependencies are only caught in debug builds.
it('throws if hierarchy has a circular dependency', function() {
// window0 -> door0 -> building0 -> window0
var batchTableJson = {
HIERARCHY : {
instancesLength : 3,