@@ -399,7 +399,7 @@ define([
399
399
cartographicsArray . push ( startCartographic . longitude ) ;
400
400
}
401
401
402
- return generateGeometryAttributes ( projection , bottomPositionsArray , topPositionsArray , normalsArray , cartographicsArray , loop ) ;
402
+ return generateGeometryAttributes ( groundPolylineGeometry , projection , bottomPositionsArray , topPositionsArray , normalsArray , cartographicsArray ) ;
403
403
} ;
404
404
405
405
var positionCartographicScratch = new Cartographic ( ) ;
@@ -417,14 +417,40 @@ define([
417
417
return result ;
418
418
}
419
419
420
- var cartographicScratch = new Cartographic ( ) ;
420
+ var adjustHeightNormalScratch = new Cartesian3 ( ) ;
421
+ var adjustHeightOffsetScratch = new Cartesian3 ( ) ;
422
+ function adjustHeights ( groundPolylineGeometry , bottom , top , minHeight , maxHeight , adjustHeightBottom , adjustHeightTop ) {
423
+ // bottom and top should be at groundPolylineGeometry.minimumTerrainHeight and groundPolylineGeometry.maximumTerrainHeight, respectively
424
+ var adjustHeightNormal = Cartesian3 . subtract ( top , bottom , adjustHeightNormalScratch ) ;
425
+ Cartesian3 . normalize ( adjustHeightNormal , adjustHeightNormal ) ;
426
+
427
+ var distanceForBottom = minHeight - groundPolylineGeometry . minimumTerrainHeight ;
428
+ var adjustHeightOffset = Cartesian3 . multiplyByScalar ( adjustHeightNormal , distanceForBottom , adjustHeightOffsetScratch ) ;
429
+ Cartesian3 . add ( bottom , adjustHeightOffset , adjustHeightBottom ) ;
430
+
431
+ var distanceForTop = maxHeight - groundPolylineGeometry . maximumTerrainHeight ;
432
+ adjustHeightOffset = Cartesian3 . multiplyByScalar ( adjustHeightNormal , distanceForTop , adjustHeightOffsetScratch ) ;
433
+ Cartesian3 . add ( top , adjustHeightOffset , adjustHeightTop ) ;
434
+ }
435
+
436
+ var startCartographicScratch = new Cartographic ( ) ;
437
+ var endCartographicScratch = new Cartographic ( ) ;
438
+
421
439
var segmentStartTopScratch = new Cartesian3 ( ) ;
422
440
var segmentEndTopScratch = new Cartesian3 ( ) ;
423
441
var segmentStartBottomScratch = new Cartesian3 ( ) ;
424
442
var segmentEndBottomScratch = new Cartesian3 ( ) ;
425
443
var segmentStartNormalScratch = new Cartesian3 ( ) ;
426
444
var segmentEndNormalScratch = new Cartesian3 ( ) ;
427
445
446
+ var getHeightCartographics = [ startCartographicScratch , endCartographicScratch ] ;
447
+ var getHeightRectangleScratch = new Rectangle ( ) ;
448
+
449
+ var adjustHeightStartTopScratch = new Cartesian3 ( ) ;
450
+ var adjustHeightEndTopScratch = new Cartesian3 ( ) ;
451
+ var adjustHeightStartBottomScratch = new Cartesian3 ( ) ;
452
+ var adjustHeightEndBottomScratch = new Cartesian3 ( ) ;
453
+
428
454
var segmentStart2DScratch = new Cartesian3 ( ) ;
429
455
var segmentEnd2DScratch = new Cartesian3 ( ) ;
430
456
var segmentStartNormal2DScratch = new Cartesian3 ( ) ;
@@ -452,9 +478,11 @@ define([
452
478
3 , 6 , 2 , 3 , 7 , 6 // top
453
479
] ;
454
480
var REFERENCE_INDICES_LENGTH = REFERENCE_INDICES . length ;
455
- function generateGeometryAttributes ( projection , bottomPositionsArray , topPositionsArray , normalsArray , cartographicsArray , loop ) {
481
+ function generateGeometryAttributes ( groundPolylineGeometry , projection , bottomPositionsArray , topPositionsArray , normalsArray , cartographicsArray ) {
456
482
var i ;
457
483
var index ;
484
+ var loop = groundPolylineGeometry . loop ;
485
+ var ellipsoid = groundPolylineGeometry . ellipsoid ;
458
486
459
487
// Each segment will have 8 vertices
460
488
var segmentCount = ( bottomPositionsArray . length / 3 ) - 1 ;
@@ -482,7 +510,7 @@ define([
482
510
var length2D = 0.0 ;
483
511
var length3D = 0.0 ;
484
512
485
- var cartographic = cartographicScratch ;
513
+ var cartographic = startCartographicScratch ;
486
514
cartographic . latitude = cartographicsArray [ 0 ] ;
487
515
cartographic . longitude = cartographicsArray [ 1 ] ;
488
516
cartographic . height = 0.0 ;
@@ -533,9 +561,11 @@ define([
533
561
endGeometryNormal = Cartesian3 . multiplyByScalar ( endGeometryNormal , - 1.0 , endGeometryNormal ) ;
534
562
}
535
563
}
536
- cartographic . latitude = cartographicsArray [ 0 ] ;
537
- cartographic . longitude = cartographicsArray [ 1 ] ;
538
- var end2D = projection . project ( cartographic , segmentEnd2DScratch ) ;
564
+ var endCartographic = endCartographicScratch ;
565
+ var startCartographic = startCartographicScratch ;
566
+ endCartographic . latitude = cartographicsArray [ 0 ] ;
567
+ endCartographic . longitude = cartographicsArray [ 1 ] ;
568
+ var end2D = projection . project ( endCartographic , segmentEnd2DScratch ) ;
539
569
var endGeometryNormal2D = projectNormal ( projection , endBottom , endGeometryNormal , end2D , segmentEndNormal2DScratch ) ;
540
570
541
571
var lengthSoFar3D = 0.0 ;
@@ -549,10 +579,11 @@ define([
549
579
550
580
var start2D = Cartesian3 . clone ( end2D , segmentStart2DScratch ) ;
551
581
var startGeometryNormal2D = Cartesian3 . clone ( endGeometryNormal2D , segmentStartNormal2DScratch ) ;
582
+ startCartographic = Cartographic . clone ( endCartographic , startCartographic ) ;
552
583
553
584
if ( miterBroken ) {
554
585
// If miter was broken for the previous segment's end vertex, flip for this segment's start vertex
555
- // These " normals" are "right facing."
586
+ // These normals are "right facing."
556
587
startGeometryNormal = Cartesian3 . multiplyByScalar ( startGeometryNormal , - 1.0 , startGeometryNormal ) ;
557
588
startGeometryNormal2D = Cartesian3 . multiplyByScalar ( startGeometryNormal2D , - 1.0 , startGeometryNormal2D ) ;
558
589
}
@@ -566,9 +597,9 @@ define([
566
597
567
598
miterBroken = breakMiter ( endGeometryNormal , startBottom , endBottom , endTop ) ;
568
599
569
- cartographic . latitude = cartographicsArray [ cartographicsIndex ] ;
570
- cartographic . longitude = cartographicsArray [ cartographicsIndex + 1 ] ;
571
- end2D = projection . project ( cartographic , segmentEnd2DScratch ) ;
600
+ endCartographic . latitude = cartographicsArray [ cartographicsIndex ] ;
601
+ endCartographic . longitude = cartographicsArray [ cartographicsIndex + 1 ] ;
602
+ end2D = projection . project ( endCartographic , segmentEnd2DScratch ) ;
572
603
endGeometryNormal2D = projectNormal ( projection , endBottom , endGeometryNormal , end2D , segmentEndNormal2DScratch ) ;
573
604
574
605
/****************************************
@@ -645,7 +676,6 @@ define([
645
676
rightNormal_andTextureCoordinateNormalizationY [ wIndex ] = texcoordNormalization3DY ;
646
677
647
678
// 2D
648
-
649
679
startHiLo2D [ vec4Index ] = encodedStart2D . high . x ;
650
680
startHiLo2D [ vec4Index + 1 ] = encodedStart2D . high . y ;
651
681
startHiLo2D [ vec4Index + 2 ] = encodedStart2D . low . x ;
@@ -671,39 +701,49 @@ define([
671
701
* Encode which side of the line segment each position is on by
672
702
* pushing it "away" by 1 meter along the geometry normal.
673
703
*
674
- * This helps when pushing the vertices out by varying amounts to
704
+ * Needed when pushing the vertices out by varying amounts to
675
705
* help simulate constant screen-space line width.
676
706
****************************************************************/
707
+ // Adjust heights of positions in 3D
708
+ var adjustHeightStartBottom = adjustHeightStartBottomScratch ;
709
+ var adjustHeightEndBottom = adjustHeightEndBottomScratch ;
710
+ var adjustHeightStartTop = adjustHeightStartTopScratch ;
711
+ var adjustHeightEndTop = adjustHeightEndTopScratch ;
712
+
713
+ var getHeightsRectangle = Rectangle . fromCartographicArray ( getHeightCartographics , getHeightRectangleScratch ) ;
714
+ var minMaxHeights = ApproximateTerrainHeights . getApproximateTerrainHeights ( getHeightsRectangle , ellipsoid ) ;
715
+ var minHeight = minMaxHeights . minimumTerrainHeight ;
716
+ var maxHeight = minMaxHeights . maximumTerrainHeight ;
717
+
718
+ adjustHeights ( groundPolylineGeometry , startBottom , startTop , minHeight , maxHeight , adjustHeightStartBottom , adjustHeightStartTop ) ;
719
+ adjustHeights ( groundPolylineGeometry , endBottom , endTop , minHeight , maxHeight , adjustHeightEndBottom , adjustHeightEndTop ) ;
720
+
677
721
// Push out by 1.0 in the "right" direction
678
- var pushedStartBottom = Cartesian3 . add ( startBottom , startGeometryNormal , startBottom ) ;
679
- var pushedEndBottom = Cartesian3 . add ( endBottom , endGeometryNormal , endBottom ) ;
680
- var pushedEndTop = Cartesian3 . add ( endTop , endGeometryNormal , endTop ) ;
681
- var pushedStartTop = Cartesian3 . add ( startTop , startGeometryNormal , startTop ) ;
722
+ var pushedStartBottom = Cartesian3 . add ( adjustHeightStartBottom , startGeometryNormal , adjustHeightStartBottom ) ;
723
+ var pushedEndBottom = Cartesian3 . add ( adjustHeightEndBottom , endGeometryNormal , adjustHeightEndBottom ) ;
724
+ var pushedEndTop = Cartesian3 . add ( adjustHeightEndTop , endGeometryNormal , adjustHeightEndTop ) ;
725
+ var pushedStartTop = Cartesian3 . add ( adjustHeightStartTop , startGeometryNormal , adjustHeightStartTop ) ;
682
726
Cartesian3 . pack ( pushedStartBottom , positionsArray , vec3sWriteIndex ) ;
683
727
Cartesian3 . pack ( pushedEndBottom , positionsArray , vec3sWriteIndex + 3 ) ;
684
728
Cartesian3 . pack ( pushedEndTop , positionsArray , vec3sWriteIndex + 6 ) ;
685
729
Cartesian3 . pack ( pushedStartTop , positionsArray , vec3sWriteIndex + 9 ) ;
686
730
687
731
// Return to center
688
- pushedStartBottom = Cartesian3 . subtract ( startBottom , startGeometryNormal , startBottom ) ;
689
- pushedEndBottom = Cartesian3 . subtract ( endBottom , endGeometryNormal , endBottom ) ;
690
- pushedEndTop = Cartesian3 . subtract ( endTop , endGeometryNormal , endTop ) ;
691
- pushedStartTop = Cartesian3 . subtract ( startTop , startGeometryNormal , startTop ) ;
732
+ pushedStartBottom = Cartesian3 . subtract ( adjustHeightStartBottom , startGeometryNormal , adjustHeightStartBottom ) ;
733
+ pushedEndBottom = Cartesian3 . subtract ( adjustHeightEndBottom , endGeometryNormal , adjustHeightEndBottom ) ;
734
+ pushedEndTop = Cartesian3 . subtract ( adjustHeightEndTop , endGeometryNormal , adjustHeightEndTop ) ;
735
+ pushedStartTop = Cartesian3 . subtract ( adjustHeightStartTop , startGeometryNormal , adjustHeightStartTop ) ;
692
736
693
737
// Push out by 1.0 in the "left" direction
694
- pushedStartBottom = Cartesian3 . subtract ( startBottom , startGeometryNormal , startBottom ) ;
695
- pushedEndBottom = Cartesian3 . subtract ( endBottom , endGeometryNormal , endBottom ) ;
696
- pushedEndTop = Cartesian3 . subtract ( endTop , endGeometryNormal , endTop ) ;
697
- pushedStartTop = Cartesian3 . subtract ( startTop , startGeometryNormal , startTop ) ;
738
+ pushedStartBottom = Cartesian3 . subtract ( adjustHeightStartBottom , startGeometryNormal , adjustHeightStartBottom ) ;
739
+ pushedEndBottom = Cartesian3 . subtract ( adjustHeightEndBottom , endGeometryNormal , adjustHeightEndBottom ) ;
740
+ pushedEndTop = Cartesian3 . subtract ( adjustHeightEndTop , endGeometryNormal , adjustHeightEndTop ) ;
741
+ pushedStartTop = Cartesian3 . subtract ( adjustHeightStartTop , startGeometryNormal , adjustHeightStartTop ) ;
698
742
Cartesian3 . pack ( pushedStartBottom , positionsArray , vec3sWriteIndex + 12 ) ;
699
743
Cartesian3 . pack ( pushedEndBottom , positionsArray , vec3sWriteIndex + 15 ) ;
700
744
Cartesian3 . pack ( pushedEndTop , positionsArray , vec3sWriteIndex + 18 ) ;
701
745
Cartesian3 . pack ( pushedStartTop , positionsArray , vec3sWriteIndex + 21 ) ;
702
746
703
- // Return next segment's start to center
704
- pushedEndBottom = Cartesian3 . add ( endBottom , endGeometryNormal , endBottom ) ;
705
- pushedEndTop = Cartesian3 . add ( endTop , endGeometryNormal , endTop ) ;
706
-
707
747
cartographicsIndex += 2 ;
708
748
index += 3 ;
709
749
0 commit comments