@@ -54,7 +54,6 @@ define(['../Core/Cartesian3',
54
54
55
55
var positionScratch ;
56
56
var orientationScratch ;
57
- var radiiScratch ;
58
57
var matrix3Scratch ;
59
58
60
59
var GeometryOptions = function ( dynamicObject ) {
@@ -305,11 +304,12 @@ define(['../Core/Cartesian3',
305
304
306
305
positionScratch = dynamicObject . position . getValue ( Iso8601 . MINIMUM_VALUE , positionScratch ) ;
307
306
orientationScratch = dynamicObject . orientation . getValue ( Iso8601 . MINIMUM_VALUE , orientationScratch ) ;
307
+ matrix3Scratch = Matrix3 . fromQuaternion ( orientationScratch , matrix3Scratch ) ;
308
308
309
309
return new GeometryInstance ( {
310
310
id : dynamicObject ,
311
311
geometry : new EllipsoidGeometry ( this . _options ) ,
312
- modelMatrix : Matrix4 . fromRotationTranslation ( Matrix3 . fromQuaternion ( orientationScratch ) , positionScratch ) ,
312
+ modelMatrix : Matrix4 . fromRotationTranslation ( matrix3Scratch , positionScratch ) ,
313
313
attributes : attributes
314
314
} ) ;
315
315
} ;
@@ -340,11 +340,12 @@ define(['../Core/Cartesian3',
340
340
341
341
positionScratch = dynamicObject . position . getValue ( Iso8601 . MINIMUM_VALUE , positionScratch ) ;
342
342
orientationScratch = dynamicObject . orientation . getValue ( Iso8601 . MINIMUM_VALUE , orientationScratch ) ;
343
+ matrix3Scratch = Matrix3 . fromQuaternion ( orientationScratch , matrix3Scratch ) ;
343
344
344
345
return new GeometryInstance ( {
345
346
id : dynamicObject ,
346
347
geometry : new EllipsoidOutlineGeometry ( this . _options ) ,
347
- modelMatrix : Matrix4 . fromRotationTranslation ( Matrix3 . fromQuaternion ( orientationScratch ) , positionScratch ) ,
348
+ modelMatrix : Matrix4 . fromRotationTranslation ( matrix3Scratch , positionScratch ) ,
348
349
attributes : {
349
350
show : new ShowGeometryInstanceAttribute ( isAvailable && this . _showProperty . getValue ( time ) && this . _showOutlineProperty . getValue ( time ) ) ,
350
351
color : ColorGeometryInstanceAttribute . fromColor ( isAvailable ? this . _outlineColorProperty . getValue ( time ) : Color . BLACK )
@@ -488,17 +489,11 @@ define(['../Core/Cartesian3',
488
489
* @private
489
490
*/
490
491
var DynamicGeometryUpdater = function ( primitives , geometryUpdater ) {
491
- this . _dynamicObject = geometryUpdater . _dynamicObject ;
492
492
this . _primitives = primitives ;
493
493
this . _primitive = undefined ;
494
494
this . _outlinePrimitive = undefined ;
495
495
this . _geometryUpdater = geometryUpdater ;
496
496
this . _options = new GeometryOptions ( geometryUpdater . _dynamicObject ) ;
497
- this . _options . radii = new Cartesian3 ( 1 , 1 , 1 ) ;
498
- this . _modelMatrix = new Matrix4 ( ) ;
499
- this . _material = undefined ;
500
- this . _attributes = undefined ;
501
- this . _outlineAttributes = undefined ;
502
497
} ;
503
498
504
499
DynamicGeometryUpdater . prototype . update = function ( time ) {
@@ -508,50 +503,46 @@ define(['../Core/Cartesian3',
508
503
}
509
504
//>>includeEnd('debug');
510
505
511
- var dynamicObject = this . _dynamicObject ;
506
+ var geometryUpdater = this . _geometryUpdater ;
507
+
508
+ if ( defined ( this . _primitive ) ) {
509
+ this . _primitives . remove ( this . _primitive ) ;
510
+ }
511
+
512
+ if ( defined ( this . _outlinePrimitive ) ) {
513
+ this . _primitives . remove ( this . _outlinePrimitive ) ;
514
+ }
515
+
516
+ var dynamicObject = geometryUpdater . _dynamicObject ;
512
517
var ellipsoid = dynamicObject . ellipsoid ;
513
518
var show = ellipsoid . show ;
514
519
515
520
if ( ! dynamicObject . isAvailable ( time ) || ( defined ( show ) && ! show . getValue ( time ) ) ) {
516
- if ( defined ( this . _primitive ) ) {
517
- this . _primitive . show = false ;
518
- }
519
-
520
- if ( defined ( this . _outlinePrimitive ) ) {
521
- this . _outlinePrimitive . show = false ;
522
- }
523
521
return ;
524
522
}
525
523
526
- //Compute attributes and material.
527
- var appearance ;
528
- var showFill = ! defined ( ellipsoid . fill ) || ellipsoid . fill . getValue ( time ) ;
529
- var showOutline = defined ( ellipsoid . outline ) && ellipsoid . outline . getValue ( time ) ;
530
- var outlineColor = defined ( ellipsoid . outlineColor ) ? ellipsoid . outlineColor . getValue ( time ) : Color . BLACK ;
531
- var material = MaterialProperty . getValue ( time , defaultValue ( ellipsoid . material , defaultMaterial ) , this . _material ) ;
532
- this . _material = material ;
533
-
534
- // Check properties that could trigger a primitive rebuild.
535
- var stackPartitionsProperty = ellipsoid . stackPartitions ;
536
- var slicePartitionsProperty = ellipsoid . slicePartitions ;
537
- var subdivisionsProperty = ellipsoid . subdivisions ;
538
- var stackPartitions = defined ( stackPartitionsProperty ) ? stackPartitionsProperty . getValue ( time ) : undefined ;
539
- var slicePartitions = defined ( slicePartitionsProperty ) ? slicePartitionsProperty . getValue ( time ) : undefined ;
540
- var subdivisions = defined ( subdivisionsProperty ) ? subdivisionsProperty . getValue ( time ) : undefined ;
541
-
542
524
var options = this . _options ;
525
+ var position = dynamicObject . position ;
526
+ var orientation = dynamicObject . orientation ;
527
+ var radii = ellipsoid . radii ;
528
+ var stackPartitions = ellipsoid . stackPartitions ;
529
+ var slicePartitions = ellipsoid . slicePartitions ;
530
+ var subdivisions = ellipsoid . subdivisions ;
531
+
532
+ positionScratch = position . getValue ( time , positionScratch ) ;
533
+ orientationScratch = orientation . getValue ( time , orientationScratch ) ;
534
+ matrix3Scratch = Matrix3 . fromQuaternion ( orientationScratch , matrix3Scratch ) ;
535
+ var modelMatrix = Matrix4 . fromRotationTranslation ( matrix3Scratch , positionScratch ) ;
536
+
537
+ options . radii = radii . getValue ( time , options . radii ) ;
538
+ options . stackPartitions = defined ( stackPartitions ) ? stackPartitions . getValue ( time , options ) : undefined ;
539
+ options . slicePartitions = defined ( slicePartitions ) ? slicePartitions . getValue ( time , options ) : undefined ;
540
+ options . subdivisions = defined ( subdivisions ) ? subdivisions . getValue ( time ) : undefined ;
543
541
544
- //We only rebuild the primitive if something other than the radii has changed
545
- //For the radii, we use unit sphere and then deform it with a scale matrix.
546
- var rebuildPrimitives = ! defined ( this . _primitive ) || options . stackPartitions !== stackPartitions || options . slicePartitions !== slicePartitions || options . subdivisions !== subdivisions ;
547
- if ( rebuildPrimitives ) {
548
- options . stackPartitions = stackPartitions ;
549
- options . slicePartitions = slicePartitions ;
550
- options . subdivisions = subdivisions ;
551
-
552
- this . _material = material ;
553
- material = this . _material ;
554
- appearance = new MaterialAppearance ( {
542
+ if ( ! defined ( ellipsoid . fill ) || ellipsoid . fill . getValue ( time ) ) {
543
+ this . _material = MaterialProperty . getValue ( time , geometryUpdater . fillMaterialProperty , this . _material ) ;
544
+ var material = this . _material ;
545
+ var appearance = new MaterialAppearance ( {
555
546
material : material ,
556
547
faceForward : true ,
557
548
translucent : material . isTranslucent ( ) ,
@@ -562,23 +553,25 @@ define(['../Core/Cartesian3',
562
553
this . _primitive = new Primitive ( {
563
554
geometryInstances : new GeometryInstance ( {
564
555
id : dynamicObject ,
565
- geometry : new EllipsoidGeometry ( options )
556
+ geometry : new EllipsoidGeometry ( options ) ,
557
+ modelMatrix : modelMatrix
566
558
} ) ,
567
559
appearance : appearance ,
568
- asynchronous : false ,
569
- attributes : {
570
- show : new ShowGeometryInstanceAttribute ( showFill )
571
- }
560
+ asynchronous : false
572
561
} ) ;
573
562
this . _primitives . add ( this . _primitive ) ;
563
+ }
574
564
565
+ if ( defined ( ellipsoid . outline ) && ellipsoid . outline . getValue ( time ) ) {
575
566
options . vertexFormat = PerInstanceColorAppearance . VERTEX_FORMAT ;
567
+
568
+ var outlineColor = defined ( ellipsoid . outlineColor ) ? ellipsoid . outlineColor . getValue ( time ) : Color . BLACK ;
576
569
this . _outlinePrimitive = new Primitive ( {
577
570
geometryInstances : new GeometryInstance ( {
578
571
id : dynamicObject ,
579
572
geometry : new EllipsoidOutlineGeometry ( options ) ,
573
+ modelMatrix : modelMatrix ,
580
574
attributes : {
581
- show : new ShowGeometryInstanceAttribute ( showOutline ) ,
582
575
color : ColorGeometryInstanceAttribute . fromColor ( outlineColor )
583
576
}
584
577
} ) ,
@@ -589,46 +582,7 @@ define(['../Core/Cartesian3',
589
582
asynchronous : false
590
583
} ) ;
591
584
this . _primitives . add ( this . _outlinePrimitive ) ;
592
-
593
- } else {
594
- //Update attributes only.
595
- var primitive = this . _primitive ;
596
- appearance = primitive . appearance ;
597
- appearance . material = material ;
598
-
599
- var attributes = this . _attributes ;
600
- if ( ! defined ( attributes ) ) {
601
- attributes = primitive . getGeometryInstanceAttributes ( dynamicObject ) ;
602
- this . _attributes = attributes ;
603
- }
604
- attributes . show = ShowGeometryInstanceAttribute . toValue ( showFill , attributes . show ) ;
605
-
606
- var outlinePrimitive = this . _outlinePrimitive ;
607
-
608
- var outlineAttributes = this . _outlineAttributes ;
609
- if ( ! defined ( outlineAttributes ) ) {
610
- outlineAttributes = outlinePrimitive . getGeometryInstanceAttributes ( dynamicObject ) ;
611
- this . _outlineAttributes = outlineAttributes ;
612
- }
613
- outlineAttributes . show = ShowGeometryInstanceAttribute . toValue ( showOutline , outlineAttributes . show ) ;
614
- outlineAttributes . color = ColorGeometryInstanceAttribute . toValue ( outlineColor , outlineAttributes . color ) ;
615
585
}
616
-
617
- //Finally, compute and set the model matrices
618
- var positionProperty = dynamicObject . position ;
619
- var orientationProperty = dynamicObject . orientation ;
620
- var radiiProperty = ellipsoid . radii ;
621
-
622
- positionScratch = positionProperty . getValue ( time , positionScratch ) ;
623
- orientationScratch = orientationProperty . getValue ( time , orientationScratch ) ;
624
- matrix3Scratch = Matrix3 . fromQuaternion ( orientationScratch , matrix3Scratch ) ;
625
- radiiScratch = radiiProperty . getValue ( time , radiiScratch ) ;
626
-
627
- var modelMatrix = this . _modelMatrix ;
628
- modelMatrix = Matrix4 . fromRotationTranslation ( matrix3Scratch , positionScratch , modelMatrix ) ;
629
- modelMatrix = Matrix4 . multiplyByScale ( modelMatrix , radiiScratch , modelMatrix ) ;
630
- this . _primitive . modelMatrix = modelMatrix ;
631
- this . _outlinePrimitive . modelMatrix = modelMatrix ;
632
586
} ;
633
587
634
588
DynamicGeometryUpdater . prototype . isDestroyed = function ( ) {
0 commit comments