@@ -13,10 +13,13 @@ defineSuite([
13
13
'Core/RectangleGeometry' ,
14
14
'Core/Transforms' ,
15
15
'Renderer/Pass' ,
16
+ 'Renderer/RenderState' ,
16
17
'Scene/Cesium3DTileBatchTable' ,
18
+ 'Scene/ClassificationType' ,
17
19
'Scene/ColorBlendMode' ,
18
20
'Scene/PerInstanceColorAppearance' ,
19
21
'Scene/Primitive' ,
22
+ 'Scene/StencilConstants' ,
20
23
'Specs/createContext' ,
21
24
'Specs/createScene' ,
22
25
'Specs/pollToPromise'
@@ -35,10 +38,13 @@ defineSuite([
35
38
RectangleGeometry ,
36
39
Transforms ,
37
40
Pass ,
41
+ RenderState ,
38
42
Cesium3DTileBatchTable ,
43
+ ClassificationType ,
39
44
ColorBlendMode ,
40
45
PerInstanceColorAppearance ,
41
46
Primitive ,
47
+ StencilConstants ,
42
48
createContext ,
43
49
createScene ,
44
50
pollToPromise ) {
@@ -57,19 +63,14 @@ defineSuite([
57
63
58
64
var scene ;
59
65
var rectangle ;
60
- var depthPrimitive ;
61
66
var geometry ;
67
+ var globePrimitive ;
68
+ var tilesetPrimitive ;
69
+ var reusableGlobePrimitive ;
70
+ var reusableTilesetPrimitive ;
62
71
63
72
var ellipsoid = Ellipsoid . WGS84 ;
64
73
65
- beforeAll ( function ( ) {
66
- scene = createScene ( { contextOptions : contextOptions } ) ;
67
- } ) ;
68
-
69
- afterAll ( function ( ) {
70
- scene . destroyForSpecs ( ) ;
71
- } ) ;
72
-
73
74
var mockTileset = {
74
75
_statistics : {
75
76
texturesByteLength : 0
@@ -83,61 +84,92 @@ defineSuite([
83
84
getFeature : function ( id ) { return { batchId : id } ; }
84
85
} ;
85
86
86
- function MockGlobePrimitive ( primitive ) {
87
+ function createPrimitive ( rectangle , pass ) {
88
+ var renderState ;
89
+ if ( pass === Pass . CESIUM_3D_TILE ) {
90
+ renderState = RenderState . fromCache ( {
91
+ stencilTest : StencilConstants . setCesium3DTileBit ( ) ,
92
+ stencilMask : StencilConstants . CESIUM_3D_TILE_MASK ,
93
+ depthTest : {
94
+ enabled : true
95
+ }
96
+ } ) ;
97
+ }
98
+ var depthColorAttribute = ColorGeometryInstanceAttribute . fromColor ( new Color ( 1.0 , 0.0 , 0.0 , 1.0 ) ) ;
99
+ return new Primitive ( {
100
+ geometryInstances : new GeometryInstance ( {
101
+ geometry : new RectangleGeometry ( {
102
+ ellipsoid : Ellipsoid . WGS84 ,
103
+ rectangle : rectangle
104
+ } ) ,
105
+ id : 'depth rectangle' ,
106
+ attributes : {
107
+ color : depthColorAttribute
108
+ }
109
+ } ) ,
110
+ appearance : new PerInstanceColorAppearance ( {
111
+ translucent : false ,
112
+ flat : true ,
113
+ renderState : renderState
114
+ } ) ,
115
+ asynchronous : false
116
+ } ) ;
117
+ }
118
+
119
+ function MockPrimitive ( primitive , pass ) {
87
120
this . _primitive = primitive ;
88
- this . pass = Pass . CESIUM_3D_TILE ;
121
+ this . _pass = pass ;
122
+ this . show = true ;
89
123
}
90
124
91
- MockGlobePrimitive . prototype . update = function ( frameState ) {
125
+ MockPrimitive . prototype . update = function ( frameState ) {
126
+ if ( ! this . show ) {
127
+ return ;
128
+ }
129
+
92
130
var commandList = frameState . commandList ;
93
131
var startLength = commandList . length ;
94
132
this . _primitive . update ( frameState ) ;
95
133
96
134
for ( var i = startLength ; i < commandList . length ; ++ i ) {
97
135
var command = commandList [ i ] ;
98
- command . pass = this . pass ;
136
+ command . pass = this . _pass ;
99
137
}
100
138
} ;
101
139
102
- MockGlobePrimitive . prototype . isDestroyed = function ( ) {
140
+ MockPrimitive . prototype . isDestroyed = function ( ) {
103
141
return false ;
104
142
} ;
105
143
106
- MockGlobePrimitive . prototype . destroy = function ( ) {
107
- this . _primitive . destroy ( ) ;
144
+ MockPrimitive . prototype . destroy = function ( ) {
108
145
return destroyObject ( this ) ;
109
146
} ;
110
147
111
- beforeEach ( function ( ) {
148
+ beforeAll ( function ( ) {
149
+ scene = createScene ( { contextOptions : contextOptions } ) ;
150
+
112
151
rectangle = Rectangle . fromDegrees ( - 80.0 , 20.0 , - 70.0 , 30.0 ) ;
152
+ reusableGlobePrimitive = createPrimitive ( rectangle , Pass . GLOBE ) ;
153
+ reusableTilesetPrimitive = createPrimitive ( rectangle , Pass . CESIUM_3D_TILE ) ;
154
+ } ) ;
113
155
114
- var depthColorAttribute = ColorGeometryInstanceAttribute . fromColor ( new Color ( 1.0 , 0.0 , 0.0 , 1.0 ) ) ;
115
- var primitive = new Primitive ( {
116
- geometryInstances : new GeometryInstance ( {
117
- geometry : new RectangleGeometry ( {
118
- ellipsoid : ellipsoid ,
119
- rectangle : rectangle
120
- } ) ,
121
- id : 'depth rectangle' ,
122
- attributes : {
123
- color : depthColorAttribute
124
- }
125
- } ) ,
126
- appearance : new PerInstanceColorAppearance ( {
127
- translucent : false ,
128
- flat : true
129
- } ) ,
130
- asynchronous : false
131
- } ) ;
156
+ afterAll ( function ( ) {
157
+ reusableGlobePrimitive . destroy ( ) ;
158
+ reusableTilesetPrimitive . destroy ( ) ;
159
+ scene . destroyForSpecs ( ) ;
160
+ } ) ;
132
161
133
- // wrap rectangle primitive so it gets executed during the globe pass to lay down depth
134
- depthPrimitive = new MockGlobePrimitive ( primitive ) ;
162
+ beforeEach ( function ( ) {
163
+ // wrap rectangle primitive so it gets executed during the globe pass and 3D Tiles pass to lay down depth
164
+ globePrimitive = new MockPrimitive ( reusableGlobePrimitive , Pass . GLOBE ) ;
165
+ tilesetPrimitive = new MockPrimitive ( reusableTilesetPrimitive , Pass . CESIUM_3D_TILE ) ;
135
166
} ) ;
136
167
137
168
afterEach ( function ( ) {
138
169
scene . primitives . removeAll ( ) ;
170
+ globePrimitive = globePrimitive && ! globePrimitive . isDestroyed ( ) && globePrimitive . destroy ( ) ;
171
+ tilesetPrimitive = tilesetPrimitive && ! tilesetPrimitive . isDestroyed ( ) && tilesetPrimitive . destroy ( ) ;
139
172
geometry = geometry && ! geometry . isDestroyed ( ) && geometry . destroy ( ) ;
140
- depthPrimitive = depthPrimitive && ! depthPrimitive . isDestroyed ( ) && depthPrimitive . destroy ( ) ;
141
173
} ) ;
142
174
143
175
function loadGeometries ( geometries ) {
@@ -217,7 +249,7 @@ defineSuite([
217
249
var batchTable = new Cesium3DTileBatchTable ( mockTileset , 1 ) ;
218
250
batchTable . update ( mockTileset , scene . frameState ) ;
219
251
220
- scene . primitives . add ( depthPrimitive ) ;
252
+ scene . primitives . add ( globePrimitive ) ;
221
253
222
254
geometry = scene . primitives . add ( new Vector3DTileGeometry ( combine ( geometryOptions , {
223
255
center : center ,
@@ -249,7 +281,7 @@ defineSuite([
249
281
var batchTable = new Cesium3DTileBatchTable ( mockTileset , length ) ;
250
282
batchTable . update ( mockTileset , scene . frameState ) ;
251
283
252
- scene . primitives . add ( depthPrimitive ) ;
284
+ scene . primitives . add ( globePrimitive ) ;
253
285
254
286
geometry = scene . primitives . add ( new Vector3DTileGeometry ( combine ( geometryOptions , {
255
287
center : center ,
@@ -533,7 +565,7 @@ defineSuite([
533
565
var batchTable = new Cesium3DTileBatchTable ( mockTileset , length ) ;
534
566
batchTable . update ( mockTileset , scene . frameState ) ;
535
567
536
- scene . primitives . add ( depthPrimitive ) ;
568
+ scene . primitives . add ( globePrimitive ) ;
537
569
538
570
geometry = scene . primitives . add ( new Vector3DTileGeometry ( {
539
571
boxes : boxes ,
@@ -587,7 +619,7 @@ defineSuite([
587
619
var batchTable = new Cesium3DTileBatchTable ( mockTileset , 1 ) ;
588
620
batchTable . update ( mockTileset , scene . frameState ) ;
589
621
590
- scene . primitives . add ( depthPrimitive ) ;
622
+ scene . primitives . add ( tilesetPrimitive ) ;
591
623
592
624
geometry = scene . primitives . add ( new Vector3DTileGeometry ( {
593
625
ellipsoids : ellipsoids ,
@@ -620,7 +652,7 @@ defineSuite([
620
652
var batchTable = new Cesium3DTileBatchTable ( mockTileset , 1 ) ;
621
653
batchTable . update ( mockTileset , scene . frameState ) ;
622
654
623
- scene . primitives . add ( depthPrimitive ) ;
655
+ scene . primitives . add ( globePrimitive ) ;
624
656
625
657
geometry = scene . primitives . add ( new Vector3DTileGeometry ( {
626
658
ellipsoids : packEllipsoids ( [ {
@@ -648,14 +680,71 @@ defineSuite([
648
680
} ) ;
649
681
} ) ;
650
682
683
+ it ( 'renders based on classificationType' + webglMessage , function ( ) {
684
+ var radii = new Cartesian3 ( 100.0 , 100.0 , 1000.0 ) ;
685
+ var ellipsoids = packEllipsoids ( [ {
686
+ modelMatrix : Matrix4 . IDENTITY ,
687
+ radii : radii
688
+ } ] ) ;
689
+ var ellipsoidBatchIds = new Uint16Array ( [ 0 ] ) ;
690
+
691
+ var origin = Rectangle . center ( rectangle ) ;
692
+ var center = ellipsoid . cartographicToCartesian ( origin ) ;
693
+ var modelMatrix = Transforms . eastNorthUpToFixedFrame ( center ) ;
694
+
695
+ var bv = new BoundingSphere ( center , Cartesian3 . maximumComponent ( radii ) ) ;
696
+
697
+ var batchTable = new Cesium3DTileBatchTable ( mockTileset , 1 ) ;
698
+ batchTable . update ( mockTileset , scene . frameState ) ;
699
+
700
+ scene . primitives . add ( globePrimitive ) ;
701
+ scene . primitives . add ( tilesetPrimitive ) ;
702
+
703
+ geometry = scene . primitives . add ( new Vector3DTileGeometry ( {
704
+ ellipsoids : ellipsoids ,
705
+ ellipsoidBatchIds : ellipsoidBatchIds ,
706
+ boundingVolume : bv ,
707
+ center : center ,
708
+ modelMatrix : modelMatrix ,
709
+ batchTable : batchTable
710
+ } ) ) ;
711
+ return loadGeometries ( geometry ) . then ( function ( ) {
712
+ scene . camera . lookAtTransform ( modelMatrix , new Cartesian3 ( 0.0 , 0.0 , 1.0 ) ) ;
713
+
714
+ geometry . classificationType = ClassificationType . CESIUM_3D_TILE ;
715
+ globePrimitive . show = false ;
716
+ tilesetPrimitive . show = true ;
717
+ expect ( scene ) . toRender ( [ 255 , 255 , 255 , 255 ] ) ;
718
+ globePrimitive . show = true ;
719
+ tilesetPrimitive . show = false ;
720
+ expect ( scene ) . toRender ( [ 255 , 0 , 0 , 255 ] ) ;
721
+
722
+ geometry . classificationType = ClassificationType . TERRAIN ;
723
+ globePrimitive . show = false ;
724
+ tilesetPrimitive . show = true ;
725
+ expect ( scene ) . toRender ( [ 255 , 0 , 0 , 255 ] ) ;
726
+ globePrimitive . show = true ;
727
+ tilesetPrimitive . show = false ;
728
+ expect ( scene ) . toRender ( [ 255 , 255 , 255 , 255 ] ) ;
729
+
730
+ geometry . classificationType = ClassificationType . BOTH ;
731
+ globePrimitive . show = false ;
732
+ tilesetPrimitive . show = true ;
733
+ expect ( scene ) . toRender ( [ 255 , 255 , 255 , 255 ] ) ;
734
+ globePrimitive . show = true ;
735
+ tilesetPrimitive . show = false ;
736
+ expect ( scene ) . toRender ( [ 255 , 255 , 255 , 255 ] ) ;
737
+ } ) ;
738
+ } ) ;
739
+
651
740
it ( 'picks geometry' + webglMessage , function ( ) {
652
741
var origin = Rectangle . center ( rectangle ) ;
653
742
var center = ellipsoid . cartographicToCartesian ( origin ) ;
654
743
var modelMatrix = Transforms . eastNorthUpToFixedFrame ( center ) ;
655
744
656
745
var batchTable = new Cesium3DTileBatchTable ( mockTileset , 1 ) ;
657
746
658
- scene . primitives . add ( depthPrimitive ) ;
747
+ scene . primitives . add ( globePrimitive ) ;
659
748
660
749
geometry = scene . primitives . add ( new Vector3DTileGeometry ( {
661
750
ellipsoids : packEllipsoids ( [ {
0 commit comments