@@ -8,17 +8,17 @@ import ShowGeometryInstanceAttribute from '../Core/ShowGeometryInstanceAttribute
8
8
import GroundPrimitive from '../Scene/GroundPrimitive.js' ;
9
9
import BoundingSphereState from './BoundingSphereState.js' ;
10
10
import Property from './Property.js' ;
11
+ import RectangleCollisionChecker from '../Core/RectangleCollisionChecker.js' ;
11
12
12
13
var colorScratch = new Color ( ) ;
13
14
var distanceDisplayConditionScratch = new DistanceDisplayCondition ( ) ;
14
15
var defaultDistanceDisplayCondition = new DistanceDisplayCondition ( ) ;
15
16
16
- function Batch ( primitives , classificationType , color , key , zIndex ) {
17
+ function Batch ( primitives , classificationType , color , zIndex ) {
17
18
this . primitives = primitives ;
18
19
this . zIndex = zIndex ;
19
20
this . classificationType = classificationType ;
20
21
this . color = color ;
21
- this . key = key ;
22
22
this . createPrimitive = false ;
23
23
this . waitingOnCreate = false ;
24
24
this . primitive = undefined ;
@@ -31,13 +31,19 @@ import Property from './Property.js';
31
31
this . showsUpdated = new AssociativeArray ( ) ;
32
32
this . itemsToRemove = [ ] ;
33
33
this . isDirty = false ;
34
+ this . rectangleCollisionCheck = new RectangleCollisionChecker ( ) ;
34
35
}
35
36
37
+ Batch . prototype . overlapping = function ( rectangle ) {
38
+ return this . rectangleCollisionCheck . collides ( rectangle ) ;
39
+ } ;
40
+
36
41
Batch . prototype . add = function ( updater , instance ) {
37
42
var id = updater . id ;
38
43
this . createPrimitive = true ;
39
44
this . geometry . set ( id , instance ) ;
40
45
this . updaters . set ( id , updater ) ;
46
+ this . rectangleCollisionCheck . insert ( id , instance . geometry . rectangle ) ;
41
47
if ( ! updater . hasConstantFill || ! updater . fillMaterialProperty . isConstant || ! Property . isConstant ( updater . distanceDisplayConditionProperty ) ) {
42
48
this . updatersWithAttributes . set ( id , updater ) ;
43
49
} else {
@@ -52,8 +58,10 @@ import Property from './Property.js';
52
58
53
59
Batch . prototype . remove = function ( updater ) {
54
60
var id = updater . id ;
61
+ var geometryInstance = this . geometry . get ( id ) ;
55
62
this . createPrimitive = this . geometry . remove ( id ) || this . createPrimitive ;
56
63
if ( this . updaters . remove ( id ) ) {
64
+ this . rectangleCollisionCheck . remove ( id , geometryInstance . geometry . rectangle ) ;
57
65
this . updatersWithAttributes . remove ( id ) ;
58
66
var unsubscribe = this . subscriptions . get ( id ) ;
59
67
if ( defined ( unsubscribe ) ) {
@@ -227,33 +235,39 @@ import Property from './Property.js';
227
235
* @private
228
236
*/
229
237
function StaticGroundGeometryColorBatch ( primitives , classificationType ) {
230
- this . _batches = new AssociativeArray ( ) ;
238
+ this . _batches = [ ] ;
231
239
this . _primitives = primitives ;
232
240
this . _classificationType = classificationType ;
233
241
}
234
242
235
243
StaticGroundGeometryColorBatch . prototype . add = function ( time , updater ) {
236
244
var instance = updater . createFillGeometryInstance ( time ) ;
237
245
var batches = this . _batches ;
238
- // zIndex is a batch breaker, so we'll use that for the key
239
246
var zIndex = Property . getValueOrDefault ( updater . zIndex , 0 ) ;
240
- var batchKey = zIndex ;
241
247
var batch ;
242
- if ( batches . contains ( batchKey ) ) {
243
- batch = batches . get ( batchKey ) ;
244
- } else {
245
- batch = new Batch ( this . _primitives , this . _classificationType , instance . attributes . color . value , batchKey , zIndex ) ;
246
- batches . set ( batchKey , batch ) ;
248
+ var length = batches . length ;
249
+ for ( var i = 0 ; i < length ; ++ i ) {
250
+ var item = batches [ i ] ;
251
+ if ( item . zIndex === zIndex &&
252
+ ! item . overlapping ( instance . geometry . rectangle ) ) {
253
+ batch = item ;
254
+ break ;
255
+ }
256
+ }
257
+
258
+ if ( ! defined ( batch ) ) {
259
+ batch = new Batch ( this . _primitives , this . _classificationType , instance . attributes . color . value , zIndex ) ;
260
+ batches . push ( batch ) ;
247
261
}
248
262
batch . add ( updater , instance ) ;
249
263
return batch ;
250
264
} ;
251
265
252
266
StaticGroundGeometryColorBatch . prototype . remove = function ( updater ) {
253
- var batchesArray = this . _batches . values ;
254
- var count = batchesArray . length ;
267
+ var batches = this . _batches ;
268
+ var count = batches . length ;
255
269
for ( var i = 0 ; i < count ; ++ i ) {
256
- if ( batchesArray [ i ] . remove ( updater ) ) {
270
+ if ( batches [ i ] . remove ( updater ) ) {
257
271
return ;
258
272
}
259
273
}
@@ -266,15 +280,14 @@ import Property from './Property.js';
266
280
//Perform initial update
267
281
var isUpdated = true ;
268
282
var batches = this . _batches ;
269
- var batchesArray = batches . values ;
270
- var batchCount = batchesArray . length ;
283
+ var batchCount = batches . length ;
271
284
for ( i = 0 ; i < batchCount ; ++ i ) {
272
- isUpdated = batchesArray [ i ] . update ( time ) && isUpdated ;
285
+ isUpdated = batches [ i ] . update ( time ) && isUpdated ;
273
286
}
274
287
275
288
//If any items swapped between batches we need to move them
276
289
for ( i = 0 ; i < batchCount ; ++ i ) {
277
- var oldBatch = batchesArray [ i ] ;
290
+ var oldBatch = batches [ i ] ;
278
291
var itemsToRemove = oldBatch . itemsToRemove ;
279
292
var itemsToMoveLength = itemsToRemove . length ;
280
293
for ( var j = 0 ; j < itemsToMoveLength ; j ++ ) {
@@ -287,27 +300,25 @@ import Property from './Property.js';
287
300
}
288
301
289
302
//If we moved anything around, we need to re-build the primitive and remove empty batches
290
- var batchesArrayCopy = batchesArray . slice ( ) ;
291
- var batchesCopyCount = batchesArrayCopy . length ;
292
- for ( i = 0 ; i < batchesCopyCount ; ++ i ) {
293
- var batch = batchesArrayCopy [ i ] ;
303
+ for ( i = batchCount - 1 ; i >= 0 ; -- i ) {
304
+ var batch = batches [ i ] ;
294
305
if ( batch . isDirty ) {
295
- isUpdated = batchesArrayCopy [ i ] . update ( time ) && isUpdated ;
306
+ isUpdated = batches [ i ] . update ( time ) && isUpdated ;
296
307
batch . isDirty = false ;
297
308
}
298
309
if ( batch . geometry . length === 0 ) {
299
- batches . remove ( batch . key ) ;
310
+ batches . splice ( i , 1 ) ;
300
311
}
301
312
}
302
313
303
314
return isUpdated ;
304
315
} ;
305
316
306
317
StaticGroundGeometryColorBatch . prototype . getBoundingSphere = function ( updater , result ) {
307
- var batchesArray = this . _batches . values ;
308
- var batchCount = batchesArray . length ;
318
+ var batches = this . _batches ;
319
+ var batchCount = batches . length ;
309
320
for ( var i = 0 ; i < batchCount ; ++ i ) {
310
- var batch = batchesArray [ i ] ;
321
+ var batch = batches [ i ] ;
311
322
if ( batch . contains ( updater ) ) {
312
323
return batch . getBoundingSphere ( updater , result ) ;
313
324
}
@@ -317,10 +328,10 @@ import Property from './Property.js';
317
328
} ;
318
329
319
330
StaticGroundGeometryColorBatch . prototype . removeAllPrimitives = function ( ) {
320
- var batchesArray = this . _batches . values ;
321
- var batchCount = batchesArray . length ;
331
+ var batches = this . _batches ;
332
+ var batchCount = batches . length ;
322
333
for ( var i = 0 ; i < batchCount ; ++ i ) {
323
- batchesArray [ i ] . removeAllPrimitives ( ) ;
334
+ batches [ i ] . removeAllPrimitives ( ) ;
324
335
}
325
336
} ;
326
337
export default StaticGroundGeometryColorBatch ;
0 commit comments