@@ -3529,16 +3529,7 @@ define([
3529
3529
return result ;
3530
3530
} ;
3531
3531
3532
- function isExcluded ( object , objectsToExclude ) {
3533
- if ( ! defined ( objectsToExclude ) || objectsToExclude . length === 0 ) {
3534
- return false ;
3535
- }
3536
- return ( objectsToExclude . indexOf ( object ) > - 1 ) ||
3537
- ( objectsToExclude . indexOf ( object . primitive ) > - 1 ) ||
3538
- ( objectsToExclude . indexOf ( object . id ) > - 1 ) ;
3539
- }
3540
-
3541
- function drillPick ( limit , pickCallback , objectsToExclude ) {
3532
+ function drillPick ( limit , pickCallback ) {
3542
3533
// PERFORMANCE_IDEA: This function calls each primitive's update for each pass. Instead
3543
3534
// we could update the primitive once, and then just execute their commands for each pass,
3544
3535
// and cull commands for picked primitives. e.g., base on the command's owner.
@@ -3556,6 +3547,7 @@ define([
3556
3547
while ( defined ( pickedResult ) ) {
3557
3548
var object = pickedResult . object ;
3558
3549
var position = pickedResult . position ;
3550
+ var exclude = pickedResult . exclude ;
3559
3551
3560
3552
if ( defined ( position ) && ! defined ( object ) ) {
3561
3553
result . push ( pickedResult ) ;
@@ -3566,7 +3558,7 @@ define([
3566
3558
break ;
3567
3559
}
3568
3560
3569
- if ( ! isExcluded ( object , objectsToExclude ) ) {
3561
+ if ( ! exclude ) {
3570
3562
result . push ( pickedResult ) ;
3571
3563
if ( 0 >= -- limit ) {
3572
3564
break ;
@@ -3645,7 +3637,9 @@ define([
3645
3637
var object = that . pick ( windowPosition , width , height ) ;
3646
3638
if ( defined ( object ) ) {
3647
3639
return {
3648
- object : object
3640
+ object : object ,
3641
+ position : undefined ,
3642
+ exclude : false
3649
3643
} ;
3650
3644
}
3651
3645
} ;
@@ -3744,7 +3738,16 @@ define([
3744
3738
} ) ;
3745
3739
}
3746
3740
3747
- function getRayIntersection ( scene , ray , async ) {
3741
+ function isExcluded ( object , objectsToExclude ) {
3742
+ if ( ! defined ( object ) || ! defined ( objectsToExclude ) || objectsToExclude . length === 0 ) {
3743
+ return false ;
3744
+ }
3745
+ return ( objectsToExclude . indexOf ( object ) > - 1 ) ||
3746
+ ( objectsToExclude . indexOf ( object . primitive ) > - 1 ) ||
3747
+ ( objectsToExclude . indexOf ( object . id ) > - 1 ) ;
3748
+ }
3749
+
3750
+ function getRayIntersection ( scene , ray , objectsToExclude , async , requirePosition ) {
3748
3751
var context = scene . _context ;
3749
3752
var uniformState = context . uniformState ;
3750
3753
var frameState = scene . _frameState ;
@@ -3798,40 +3801,45 @@ define([
3798
3801
if ( defined ( object ) || defined ( position ) ) {
3799
3802
return {
3800
3803
object : object ,
3801
- position : position
3804
+ position : position ,
3805
+ exclude : ( ! defined ( position ) && requirePosition ) || isExcluded ( object , objectsToExclude )
3802
3806
} ;
3803
3807
}
3804
3808
}
3805
3809
3806
- function getRayIntersections ( scene , ray , limit , objectsToExclude , async ) {
3810
+ function getRayIntersections ( scene , ray , limit , objectsToExclude , async , requirePosition ) {
3807
3811
//>>includeStart('debug', pragmas.debug);
3808
3812
Check . defined ( 'ray' , ray ) ;
3809
3813
if ( scene . _mode !== SceneMode . SCENE3D ) {
3810
3814
throw new DeveloperError ( 'Ray intersections are only supported in 3D mode.' ) ;
3811
3815
}
3812
3816
//>>includeEnd('debug');
3813
3817
var pickCallback = function ( ) {
3814
- return getRayIntersection ( scene , ray , async ) ;
3818
+ return getRayIntersection ( scene , ray , objectsToExclude , async , requirePosition ) ;
3815
3819
} ;
3816
- return drillPick ( limit , pickCallback , objectsToExclude ) ;
3820
+ return drillPick ( limit , pickCallback ) ;
3817
3821
}
3818
3822
3819
- function pickFromRay ( scene , ray , objectsToExclude , async ) {
3820
- var results = getRayIntersections ( scene , ray , 1 , objectsToExclude , async ) ;
3823
+ function pickFromRay ( scene , ray , objectsToExclude , async , requirePosition ) {
3824
+ var results = getRayIntersections ( scene , ray , 1 , objectsToExclude , async , requirePosition ) ;
3821
3825
if ( results . length > 0 ) {
3822
3826
return results [ 0 ] ;
3823
3827
}
3824
3828
}
3825
3829
3826
- function drillPickFromRay ( scene , ray , limit , objectsToExclude , async ) {
3827
- return getRayIntersections ( scene , ray , limit , objectsToExclude , async ) ;
3830
+ function drillPickFromRay ( scene , ray , limit , objectsToExclude , async , requirePosition ) {
3831
+ return getRayIntersections ( scene , ray , limit , objectsToExclude , async , requirePosition ) ;
3828
3832
}
3829
3833
3830
3834
/**
3831
3835
* Returns an object containing the first object intersected by the ray and the position of intersection,
3832
3836
* or <code>undefined</code> if there were no intersections. The intersected object has a <code>primitive</code>
3833
3837
* property that contains the intersected primitive. Other properties may be set depending on the type of primitive
3834
3838
* and may be used to further identify the picked object. The ray must be given in world coordinates.
3839
+ * <p>
3840
+ * This function only picks globe tiles and 3D Tiles that are rendered in the current view. Picks all other
3841
+ * primitives regardless of their visibility.
3842
+ * </p>
3835
3843
*
3836
3844
* @private
3837
3845
*
@@ -3842,7 +3850,7 @@ define([
3842
3850
* @exception {DeveloperError} Ray intersections are only supported in 3D mode.
3843
3851
*/
3844
3852
Scene . prototype . pickFromRay = function ( ray , objectsToExclude ) {
3845
- return pickFromRay ( this , ray , objectsToExclude , false ) ;
3853
+ return pickFromRay ( this , ray , objectsToExclude , false , false ) ;
3846
3854
} ;
3847
3855
3848
3856
/**
@@ -3851,6 +3859,10 @@ define([
3851
3859
* properties may also be set depending on the type of primitive and may be used to further identify the picked object.
3852
3860
* The primitives in the list are ordered by first intersection to last intersection. The ray must be given in
3853
3861
* world coordinates.
3862
+ * <p>
3863
+ * This function only picks globe tiles and 3D Tiles that are rendered in the current view. Picks all other
3864
+ * primitives regardless of their visibility.
3865
+ * </p>
3854
3866
*
3855
3867
* @private
3856
3868
*
@@ -3862,7 +3874,7 @@ define([
3862
3874
* @exception {DeveloperError} Ray intersections are only supported in 3D mode.
3863
3875
*/
3864
3876
Scene . prototype . drillPickFromRay = function ( ray , limit , objectsToExclude ) {
3865
- return drillPickFromRay ( this , ray , limit , objectsToExclude , false ) ;
3877
+ return drillPickFromRay ( this , ray , limit , objectsToExclude , false , false ) ;
3866
3878
} ;
3867
3879
3868
3880
/**
@@ -3882,7 +3894,7 @@ define([
3882
3894
ray = Ray . clone ( ray ) ;
3883
3895
objectsToExclude = objectsToExclude . slice ( ) ;
3884
3896
return launchAsyncLoader ( this , ray , objectsToExclude , function ( ) {
3885
- return pickFromRay ( that , ray , objectsToExclude , true ) ;
3897
+ return pickFromRay ( that , ray , objectsToExclude , true , false ) ;
3886
3898
} ) ;
3887
3899
} ;
3888
3900
@@ -3904,7 +3916,7 @@ define([
3904
3916
ray = Ray . clone ( ray ) ;
3905
3917
objectsToExclude = objectsToExclude . slice ( ) ;
3906
3918
return launchAsyncLoader ( this , ray , objectsToExclude , function ( ) {
3907
- return drillPickFromRay ( that , ray , limit , objectsToExclude , true ) ;
3919
+ return drillPickFromRay ( that , ray , limit , objectsToExclude , true , false ) ;
3908
3920
} ) ;
3909
3921
} ;
3910
3922
@@ -3945,7 +3957,7 @@ define([
3945
3957
function sampleHeightMostDetailed ( scene , position , objectsToExclude ) {
3946
3958
var ray = getRayForSampleHeight ( scene , position ) ;
3947
3959
return launchAsyncLoader ( scene , ray , objectsToExclude , function ( ) {
3948
- var pickResult = pickFromRay ( scene , ray , objectsToExclude , true ) ;
3960
+ var pickResult = pickFromRay ( scene , ray , objectsToExclude , true , true ) ;
3949
3961
if ( defined ( pickResult ) ) {
3950
3962
return getHeightFromCartesian ( scene , pickResult . position ) ;
3951
3963
}
@@ -3955,7 +3967,7 @@ define([
3955
3967
function clampToHeightMostDetailed ( scene , cartesian , objectsToExclude ) {
3956
3968
var ray = getRayForClampToHeight ( scene , cartesian ) ;
3957
3969
return launchAsyncLoader ( scene , ray , objectsToExclude , function ( ) {
3958
- var pickResult = pickFromRay ( scene , ray , objectsToExclude , true ) ;
3970
+ var pickResult = pickFromRay ( scene , ray , objectsToExclude , true , true ) ;
3959
3971
if ( defined ( pickResult ) ) {
3960
3972
return pickResult . position ;
3961
3973
}
@@ -3989,7 +4001,7 @@ define([
3989
4001
}
3990
4002
//>>includeEnd('debug');
3991
4003
var ray = getRayForSampleHeight ( this , position ) ;
3992
- var pickResult = pickFromRay ( this , ray , objectsToExclude , false ) ;
4004
+ var pickResult = pickFromRay ( this , ray , objectsToExclude , false , true ) ;
3993
4005
if ( defined ( pickResult ) ) {
3994
4006
return getHeightFromCartesian ( this , pickResult . position ) ;
3995
4007
}
@@ -4024,7 +4036,7 @@ define([
4024
4036
}
4025
4037
//>>includeEnd('debug');
4026
4038
var ray = getRayForClampToHeight ( this , cartesian ) ;
4027
- var pickResult = pickFromRay ( this , ray , objectsToExclude , false ) ;
4039
+ var pickResult = pickFromRay ( this , ray , objectsToExclude , false , true ) ;
4028
4040
if ( defined ( pickResult ) ) {
4029
4041
return Cartesian3 . clone ( pickResult . position , result ) ;
4030
4042
}
@@ -4034,9 +4046,9 @@ define([
4034
4046
* Initiates an asynchronous {@link Scene#sampleHeight} request using the maximum level of detail for 3D Tilesets
4035
4047
* regardless of visibility.
4036
4048
*
4037
- * @param {Cartographic|Cartographic [] } positions The cartographic position(s) to sample height from.
4049
+ * @param {Cartographic[] } positions The cartographic positions to sample height from.
4038
4050
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or features to not sample height from.
4039
- * @returns {Promise.<Number|Number []> } A promise that resolves to the height(s) , or <code>undefined</code> if there was no scene geometry to sample height from.
4051
+ * @returns {Promise.<Number[]> } A promise that resolves to the heights , or <code>undefined</code> if there was no scene geometry to sample height from.
4040
4052
*
4041
4053
* @see Scene#sampleHeight
4042
4054
*
@@ -4051,24 +4063,21 @@ define([
4051
4063
}
4052
4064
//>>includeEnd('debug');
4053
4065
objectsToExclude = defined ( objectsToExclude ) ? objectsToExclude . slice ( ) : objectsToExclude ;
4054
- positions = isArray ( positions ) ? positions : [ positions ] ;
4055
4066
var length = positions . length ;
4056
4067
var promises = new Array ( length ) ;
4057
4068
for ( var i = 0 ; i < length ; ++ i ) {
4058
4069
promises [ i ] = sampleHeightMostDetailed ( this , positions [ i ] , objectsToExclude ) ;
4059
4070
}
4060
- return when . all ( promises ) . then ( function ( heights ) {
4061
- return ( length === 1 ) ? heights [ 0 ] : heights ;
4062
- } ) ;
4071
+ return when . all ( promises ) ;
4063
4072
} ;
4064
4073
4065
4074
/**
4066
4075
* Initiates an asynchronous {@link Scene#clampToHeight} request using the maximum level of detail for 3D Tilesets
4067
4076
* regardless of visibility.
4068
4077
*
4069
- * @param {Cartesian3 } cartesians The cartesian positions.
4078
+ * @param {Cartesian3[] } cartesians The cartesian positions.
4070
4079
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or features to not clamp to.
4071
- * @returns {Promise.<Cartesian3|Cartesian3 []> } A promise that resolves to the clamped cartesian position(s) , or <code>undefined</code> if there was no scene geometry to clamp to.
4080
+ * @returns {Promise.<Cartesian3[]> } A promise that resolves to the clamped cartesian positions , or <code>undefined</code> if there was no scene geometry to clamp to.
4072
4081
*
4073
4082
* @see Scene#clampToHeight
4074
4083
*
@@ -4083,15 +4092,12 @@ define([
4083
4092
}
4084
4093
//>>includeEnd('debug');
4085
4094
objectsToExclude = defined ( objectsToExclude ) ? objectsToExclude . slice ( ) : objectsToExclude ;
4086
- cartesians = isArray ( cartesians ) ? cartesians : [ cartesians ] ;
4087
4095
var length = cartesians . length ;
4088
4096
var promises = new Array ( length ) ;
4089
4097
for ( var i = 0 ; i < length ; ++ i ) {
4090
4098
promises [ i ] = clampToHeightMostDetailed ( this , cartesians [ i ] , objectsToExclude ) ;
4091
4099
}
4092
- return when . all ( promises ) . then ( function ( cartesians ) {
4093
- return ( length === 1 ) ? cartesians [ 0 ] : cartesians ;
4094
- } ) ;
4100
+ return when . all ( promises ) ;
4095
4101
} ;
4096
4102
4097
4103
/**
0 commit comments