6
6
'../Core/DistanceDisplayCondition' ,
7
7
'../Core/DistanceDisplayConditionGeometryInstanceAttribute' ,
8
8
'../Core/ShowGeometryInstanceAttribute' ,
9
+ '../Core/RectangleRbush' ,
9
10
'../Scene/GroundPrimitive' ,
10
11
'./BoundingSphereState' ,
11
12
'./ColorMaterialProperty' ,
@@ -19,6 +20,7 @@ define([
19
20
DistanceDisplayCondition ,
20
21
DistanceDisplayConditionGeometryInstanceAttribute ,
21
22
ShowGeometryInstanceAttribute ,
23
+ RectangleRbush ,
22
24
GroundPrimitive ,
23
25
BoundingSphereState ,
24
26
ColorMaterialProperty ,
@@ -29,13 +31,13 @@ define([
29
31
var distanceDisplayConditionScratch = new DistanceDisplayCondition ( ) ;
30
32
31
33
// Encapsulates a Primitive and all the entities that it represents.
32
- function Batch ( primitives , appearanceType , materialProperty , shadows ) {
34
+ function Batch ( primitives , appearanceType , materialProperty , shadows , usingSphericalCoordinates ) {
33
35
this . primitives = primitives ; // scene level primitive collection
34
36
this . appearanceType = appearanceType ;
35
37
this . materialProperty = materialProperty ;
36
38
this . updaters = new AssociativeArray ( ) ;
37
39
this . createPrimitive = true ;
38
- this . primitive = undefined ;
40
+ this . primitive = undefined ; // a GroundPrimitive encapsulating all the entities
39
41
this . oldPrimitive = undefined ;
40
42
this . geometry = new AssociativeArray ( ) ;
41
43
this . material = undefined ;
@@ -46,30 +48,34 @@ define([
46
48
this . subscriptions = new AssociativeArray ( ) ;
47
49
this . showsUpdated = new AssociativeArray ( ) ;
48
50
this . shadows = shadows ;
51
+ this . usingSphericalCoordinates = usingSphericalCoordinates ;
52
+ this . rbush = new RectangleRbush ( ) ;
49
53
}
50
54
51
55
Batch . prototype . onMaterialChanged = function ( ) {
52
56
this . invalidated = true ;
53
57
} ;
54
58
55
- Batch . prototype . nonOverlapping = function ( updater ) {
56
- return false ;
59
+ Batch . prototype . nonOverlapping = function ( rectangle ) {
60
+ return ! this . rbush . collides ( rectangle ) ;
57
61
} ;
58
62
59
63
Batch . prototype . isMaterial = function ( updater ) {
60
64
var material = this . materialProperty ;
61
65
var updaterMaterial = updater . fillMaterialProperty ;
62
66
63
- if ( updaterMaterial === material ) {
67
+ if ( updaterMaterial === material ||
68
+ ( updaterMaterial instanceof ColorMaterialProperty && material instanceof ColorMaterialProperty ) ) {
64
69
return true ;
65
70
}
66
71
return defined ( material ) && material . equals ( updaterMaterial ) ;
67
72
} ;
68
73
69
- Batch . prototype . add = function ( time , updater ) {
74
+ Batch . prototype . add = function ( time , updater , geometryInstance ) {
70
75
var id = updater . id ;
71
76
this . updaters . set ( id , updater ) ;
72
- this . geometry . set ( id , updater . createFillGeometryInstance ( time ) ) ;
77
+ this . geometry . set ( id , geometryInstance ) ;
78
+ this . rbush . insert ( id , geometryInstance . geometry . rectangle ) ;
73
79
if ( ! updater . hasConstantFill || ! updater . fillMaterialProperty . isConstant || ! Property . isConstant ( updater . distanceDisplayConditionProperty ) ) {
74
80
this . updatersWithAttributes . set ( id , updater ) ;
75
81
} else {
@@ -85,8 +91,10 @@ define([
85
91
86
92
Batch . prototype . remove = function ( updater ) {
87
93
var id = updater . id ;
94
+ var geometryInstance = this . geometry . get ( id ) ;
88
95
this . createPrimitive = this . geometry . remove ( id ) || this . createPrimitive ;
89
96
if ( this . updaters . remove ( id ) ) {
97
+ this . rbush . remove ( id , geometryInstance . geometry . rectangle ) ;
90
98
this . updatersWithAttributes . remove ( id ) ;
91
99
var unsubscribe = this . subscriptions . get ( id ) ;
92
100
if ( defined ( unsubscribe ) ) {
@@ -309,15 +317,19 @@ define([
309
317
StaticGroundGeometryPerMaterialBatch . prototype . add = function ( time , updater ) {
310
318
var items = this . _items ;
311
319
var length = items . length ;
312
- for ( var i = 0 ; i < length ; i ++ ) {
320
+ var geometryInstance = updater . createFillGeometryInstance ( time ) ;
321
+ var usingSphericalCoordinates = GroundPrimitive . shouldUseSphericalCoordinates ( geometryInstance . geometry . rectangle ) ;
322
+ for ( var i = 0 ; i < length ; ++ i ) {
313
323
var item = items [ i ] ;
314
- if ( item . isMaterial ( updater ) && item . nonOverlapping ( updater ) ) {
315
- item . add ( time , updater ) ;
324
+ if ( item . isMaterial ( updater ) &&
325
+ item . nonOverlapping ( geometryInstance . geometry . rectangle ) &&
326
+ item . usingSphericalCoordinates === usingSphericalCoordinates ) {
327
+ item . add ( time , updater , geometryInstance ) ;
316
328
return ;
317
329
}
318
330
}
319
- var batch = new Batch ( this . _primitives , this . _appearanceType , updater . fillMaterialProperty , this . _shadows ) ;
320
- batch . add ( time , updater ) ;
331
+ var batch = new Batch ( this . _primitives , this . _appearanceType , updater . fillMaterialProperty , this . _shadows , usingSphericalCoordinates ) ;
332
+ batch . add ( time , updater , geometryInstance ) ;
321
333
items . push ( batch ) ;
322
334
} ;
323
335
0 commit comments