@@ -170,8 +170,9 @@ define([
170
170
} ;
171
171
} ;
172
172
173
- function AsyncRayPick ( ray , primitives ) {
173
+ function AsyncRayPick ( ray , width , primitives ) {
174
174
this . ray = ray ;
175
+ this . width = width ;
175
176
this . primitives = primitives ;
176
177
this . ready = false ;
177
178
this . deferred = when . defer ( ) ;
@@ -775,16 +776,18 @@ define([
775
776
camera . frustum . far = 10000000000.0 ;
776
777
}
777
778
779
+ var pickOffscreenDefaultWidth = 0.1 ;
778
780
var pickOffscreenViewport = new BoundingRectangle ( 0 , 0 , 1 , 1 ) ;
779
781
var pickOffscreenCamera = new Camera ( this ) ;
780
782
pickOffscreenCamera . frustum = new OrthographicFrustum ( {
781
- width : 0.01 ,
783
+ width : pickOffscreenDefaultWidth ,
782
784
aspectRatio : 1.0 ,
783
785
near : 0.1
784
786
} ) ;
785
787
786
788
this . _view = new View ( this , camera , viewport ) ;
787
789
this . _pickOffscreenView = new View ( this , pickOffscreenCamera , pickOffscreenViewport ) ;
790
+ this . _pickOffscreenDefaultWidth = pickOffscreenDefaultWidth ;
788
791
789
792
this . _defaultView = new View ( this , camera , viewport ) ;
790
793
this . _view = this . _defaultView ;
@@ -3758,7 +3761,7 @@ define([
3758
3761
var scratchRight = new Cartesian3 ( ) ;
3759
3762
var scratchUp = new Cartesian3 ( ) ;
3760
3763
3761
- function updateCameraFromRay ( ray , camera ) {
3764
+ function updateCameraFromRay ( ray , width , camera ) {
3762
3765
var direction = ray . direction ;
3763
3766
var orthogonalAxis = Cartesian3 . mostOrthogonalAxis ( direction , scratchRight ) ;
3764
3767
var right = Cartesian3 . cross ( direction , orthogonalAxis , scratchRight ) ;
@@ -3768,6 +3771,10 @@ define([
3768
3771
camera . direction = direction ;
3769
3772
camera . up = up ;
3770
3773
camera . right = right ;
3774
+
3775
+ if ( camera . frustum instanceof OrthographicFrustum ) {
3776
+ camera . frustum . width = width ;
3777
+ }
3771
3778
}
3772
3779
3773
3780
function updateAsyncRayPick ( scene , asyncRayPick ) {
@@ -3779,9 +3786,10 @@ define([
3779
3786
scene . _view = view ;
3780
3787
3781
3788
var ray = asyncRayPick . ray ;
3789
+ var width = defaultValue ( asyncRayPick . width , scene . _pickOffscreenDefaultWidth ) ;
3782
3790
var primitives = asyncRayPick . primitives ;
3783
3791
3784
- updateCameraFromRay ( ray , view . camera ) ;
3792
+ updateCameraFromRay ( ray , width , view . camera ) ;
3785
3793
3786
3794
updateFrameState ( scene ) ;
3787
3795
frameState . passes . offscreen = true ;
@@ -3826,7 +3834,7 @@ define([
3826
3834
}
3827
3835
}
3828
3836
3829
- function launchAsyncRayPick ( scene , ray , objectsToExclude , callback ) {
3837
+ function launchAsyncRayPick ( scene , ray , objectsToExclude , width , callback ) {
3830
3838
var asyncPrimitives = [ ] ;
3831
3839
var primitives = scene . primitives ;
3832
3840
var length = primitives . length ;
@@ -3842,7 +3850,7 @@ define([
3842
3850
return when . resolve ( callback ( ) ) ;
3843
3851
}
3844
3852
3845
- var asyncRayPick = new AsyncRayPick ( ray , asyncPrimitives ) ;
3853
+ var asyncRayPick = new AsyncRayPick ( ray , width , asyncPrimitives ) ;
3846
3854
scene . _asyncRayPicks . push ( asyncRayPick ) ;
3847
3855
return asyncRayPick . promise . then ( function ( ) {
3848
3856
return callback ( ) ;
@@ -3858,15 +3866,16 @@ define([
3858
3866
( objectsToExclude . indexOf ( object . id ) > - 1 ) ;
3859
3867
}
3860
3868
3861
- function getRayIntersection ( scene , ray , objectsToExclude , requirePosition , async ) {
3869
+ function getRayIntersection ( scene , ray , objectsToExclude , width , requirePosition , async ) {
3862
3870
var context = scene . _context ;
3863
3871
var uniformState = context . uniformState ;
3864
3872
var frameState = scene . _frameState ;
3865
3873
3866
3874
var view = scene . _pickOffscreenView ;
3867
3875
scene . _view = view ;
3868
3876
3869
- updateCameraFromRay ( ray , view . camera ) ;
3877
+ width = defaultValue ( width , scene . _pickOffscreenDefaultWidth ) ;
3878
+ updateCameraFromRay ( ray , width , view . camera ) ;
3870
3879
3871
3880
scratchRectangle = BoundingRectangle . clone ( view . viewport , scratchRectangle ) ;
3872
3881
@@ -3917,22 +3926,22 @@ define([
3917
3926
}
3918
3927
}
3919
3928
3920
- function getRayIntersections ( scene , ray , limit , objectsToExclude , requirePosition , async ) {
3929
+ function getRayIntersections ( scene , ray , limit , objectsToExclude , width , requirePosition , async ) {
3921
3930
var pickCallback = function ( ) {
3922
- return getRayIntersection ( scene , ray , objectsToExclude , requirePosition , async ) ;
3931
+ return getRayIntersection ( scene , ray , objectsToExclude , width , requirePosition , async ) ;
3923
3932
} ;
3924
3933
return drillPick ( limit , pickCallback ) ;
3925
3934
}
3926
3935
3927
- function pickFromRay ( scene , ray , objectsToExclude , requirePosition , async ) {
3928
- var results = getRayIntersections ( scene , ray , 1 , objectsToExclude , requirePosition , async ) ;
3936
+ function pickFromRay ( scene , ray , objectsToExclude , width , requirePosition , async ) {
3937
+ var results = getRayIntersections ( scene , ray , 1 , objectsToExclude , width , requirePosition , async ) ;
3929
3938
if ( results . length > 0 ) {
3930
3939
return results [ 0 ] ;
3931
3940
}
3932
3941
}
3933
3942
3934
- function drillPickFromRay ( scene , ray , limit , objectsToExclude , requirePosition , async ) {
3935
- return getRayIntersections ( scene , ray , limit , objectsToExclude , requirePosition , async ) ;
3943
+ function drillPickFromRay ( scene , ray , limit , objectsToExclude , width , requirePosition , async ) {
3944
+ return getRayIntersections ( scene , ray , limit , objectsToExclude , width , requirePosition , async ) ;
3936
3945
}
3937
3946
3938
3947
/**
@@ -3949,18 +3958,19 @@ define([
3949
3958
*
3950
3959
* @param {Ray } ray The ray.
3951
3960
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to exclude from the ray intersection.
3961
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
3952
3962
* @returns {Object } An object containing the object and position of the first intersection.
3953
3963
*
3954
3964
* @exception {DeveloperError} Ray intersections are only supported in 3D mode.
3955
3965
*/
3956
- Scene . prototype . pickFromRay = function ( ray , objectsToExclude ) {
3966
+ Scene . prototype . pickFromRay = function ( ray , objectsToExclude , width ) {
3957
3967
//>>includeStart('debug', pragmas.debug);
3958
3968
Check . defined ( 'ray' , ray ) ;
3959
3969
if ( this . _mode !== SceneMode . SCENE3D ) {
3960
3970
throw new DeveloperError ( 'Ray intersections are only supported in 3D mode.' ) ;
3961
3971
}
3962
3972
//>>includeEnd('debug');
3963
- return pickFromRay ( this , ray , objectsToExclude , false , false ) ;
3973
+ return pickFromRay ( this , ray , objectsToExclude , width , false , false ) ;
3964
3974
} ;
3965
3975
3966
3976
/**
@@ -3979,18 +3989,19 @@ define([
3979
3989
* @param {Ray } ray The ray.
3980
3990
* @param {Number } [limit=Number.MAX_VALUE] If supplied, stop finding intersections after this many intersections.
3981
3991
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to exclude from the ray intersection.
3992
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
3982
3993
* @returns {Object[] } List of objects containing the object and position of each intersection.
3983
3994
*
3984
3995
* @exception {DeveloperError} Ray intersections are only supported in 3D mode.
3985
3996
*/
3986
- Scene . prototype . drillPickFromRay = function ( ray , limit , objectsToExclude ) {
3997
+ Scene . prototype . drillPickFromRay = function ( ray , limit , objectsToExclude , width ) {
3987
3998
//>>includeStart('debug', pragmas.debug);
3988
3999
Check . defined ( 'ray' , ray ) ;
3989
4000
if ( this . _mode !== SceneMode . SCENE3D ) {
3990
4001
throw new DeveloperError ( 'Ray intersections are only supported in 3D mode.' ) ;
3991
4002
}
3992
4003
//>>includeEnd('debug');
3993
- return drillPickFromRay ( this , ray , limit , objectsToExclude , false , false ) ;
4004
+ return drillPickFromRay ( this , ray , limit , objectsToExclude , width , false , false ) ;
3994
4005
} ;
3995
4006
3996
4007
/**
@@ -4001,11 +4012,12 @@ define([
4001
4012
*
4002
4013
* @param {Ray } ray The ray.
4003
4014
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to exclude from the ray intersection.
4015
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
4004
4016
* @returns {Promise.<Object> } A promise that resolves to an object containing the object and position of the first intersection.
4005
4017
*
4006
4018
* @exception {DeveloperError} Ray intersections are only supported in 3D mode.
4007
4019
*/
4008
- Scene . prototype . pickFromRayMostDetailed = function ( ray , objectsToExclude ) {
4020
+ Scene . prototype . pickFromRayMostDetailed = function ( ray , objectsToExclude , width ) {
4009
4021
//>>includeStart('debug', pragmas.debug);
4010
4022
Check . defined ( 'ray' , ray ) ;
4011
4023
if ( this . _mode !== SceneMode . SCENE3D ) {
@@ -4015,8 +4027,8 @@ define([
4015
4027
var that = this ;
4016
4028
ray = Ray . clone ( ray ) ;
4017
4029
objectsToExclude = defined ( objectsToExclude ) ? objectsToExclude . slice ( ) : objectsToExclude ;
4018
- return launchAsyncRayPick ( this , ray , objectsToExclude , function ( ) {
4019
- return pickFromRay ( that , ray , objectsToExclude , false , true ) ;
4030
+ return launchAsyncRayPick ( this , ray , objectsToExclude , width , function ( ) {
4031
+ return pickFromRay ( that , ray , objectsToExclude , width , false , true ) ;
4020
4032
} ) ;
4021
4033
} ;
4022
4034
@@ -4029,11 +4041,12 @@ define([
4029
4041
* @param {Ray } ray The ray.
4030
4042
* @param {Number } [limit=Number.MAX_VALUE] If supplied, stop finding intersections after this many intersections.
4031
4043
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to exclude from the ray intersection.
4044
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
4032
4045
* @returns {Promise.<Object[]> } A promise that resolves to a list of objects containing the object and position of each intersection.
4033
4046
*
4034
4047
* @exception {DeveloperError} Ray intersections are only supported in 3D mode.
4035
4048
*/
4036
- Scene . prototype . drillPickFromRayMostDetailed = function ( ray , limit , objectsToExclude ) {
4049
+ Scene . prototype . drillPickFromRayMostDetailed = function ( ray , limit , objectsToExclude , width ) {
4037
4050
//>>includeStart('debug', pragmas.debug);
4038
4051
Check . defined ( 'ray' , ray ) ;
4039
4052
if ( this . _mode !== SceneMode . SCENE3D ) {
@@ -4043,8 +4056,8 @@ define([
4043
4056
var that = this ;
4044
4057
ray = Ray . clone ( ray ) ;
4045
4058
objectsToExclude = defined ( objectsToExclude ) ? objectsToExclude . slice ( ) : objectsToExclude ;
4046
- return launchAsyncRayPick ( this , ray , objectsToExclude , function ( ) {
4047
- return drillPickFromRay ( that , ray , limit , objectsToExclude , false , true ) ;
4059
+ return launchAsyncRayPick ( this , ray , objectsToExclude , width , function ( ) {
4060
+ return drillPickFromRay ( that , ray , limit , objectsToExclude , width , false , true ) ;
4048
4061
} ) ;
4049
4062
} ;
4050
4063
@@ -4082,20 +4095,20 @@ define([
4082
4095
return cartographic . height ;
4083
4096
}
4084
4097
4085
- function sampleHeightMostDetailed ( scene , cartographic , objectsToExclude ) {
4098
+ function sampleHeightMostDetailed ( scene , cartographic , objectsToExclude , width ) {
4086
4099
var ray = getRayForSampleHeight ( scene , cartographic ) ;
4087
- return launchAsyncRayPick ( scene , ray , objectsToExclude , function ( ) {
4088
- var pickResult = pickFromRay ( scene , ray , objectsToExclude , true , true ) ;
4100
+ return launchAsyncRayPick ( scene , ray , objectsToExclude , width , function ( ) {
4101
+ var pickResult = pickFromRay ( scene , ray , objectsToExclude , width , true , true ) ;
4089
4102
if ( defined ( pickResult ) ) {
4090
4103
return getHeightFromCartesian ( scene , pickResult . position ) ;
4091
4104
}
4092
4105
} ) ;
4093
4106
}
4094
4107
4095
- function clampToHeightMostDetailed ( scene , cartesian , objectsToExclude , result ) {
4108
+ function clampToHeightMostDetailed ( scene , cartesian , objectsToExclude , width , result ) {
4096
4109
var ray = getRayForClampToHeight ( scene , cartesian ) ;
4097
- return launchAsyncRayPick ( scene , ray , objectsToExclude , function ( ) {
4098
- var pickResult = pickFromRay ( scene , ray , objectsToExclude , true , true ) ;
4110
+ return launchAsyncRayPick ( scene , ray , objectsToExclude , width , function ( ) {
4111
+ var pickResult = pickFromRay ( scene , ray , objectsToExclude , width , true , true ) ;
4099
4112
if ( defined ( pickResult ) ) {
4100
4113
return Cartesian3 . clone ( pickResult . position , result ) ;
4101
4114
}
@@ -4113,6 +4126,7 @@ define([
4113
4126
*
4114
4127
* @param {Cartographic } position The cartographic position to sample height from.
4115
4128
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to not sample height from.
4129
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
4116
4130
* @returns {Number } The height. This may be <code>undefined</code> if there was no scene geometry to sample height from.
4117
4131
*
4118
4132
* @example
@@ -4127,7 +4141,7 @@ define([
4127
4141
* @exception {DeveloperError} sampleHeight is only supported in 3D mode.
4128
4142
* @exception {DeveloperError} sampleHeight requires depth texture support. Check sampleHeightSupported.
4129
4143
*/
4130
- Scene . prototype . sampleHeight = function ( position , objectsToExclude ) {
4144
+ Scene . prototype . sampleHeight = function ( position , objectsToExclude , width ) {
4131
4145
//>>includeStart('debug', pragmas.debug);
4132
4146
Check . defined ( 'position' , position ) ;
4133
4147
if ( this . _mode !== SceneMode . SCENE3D ) {
@@ -4138,7 +4152,7 @@ define([
4138
4152
}
4139
4153
//>>includeEnd('debug');
4140
4154
var ray = getRayForSampleHeight ( this , position ) ;
4141
- var pickResult = pickFromRay ( this , ray , objectsToExclude , true , false ) ;
4155
+ var pickResult = pickFromRay ( this , ray , objectsToExclude , width , true , false ) ;
4142
4156
if ( defined ( pickResult ) ) {
4143
4157
return getHeightFromCartesian ( this , pickResult . position ) ;
4144
4158
}
@@ -4155,6 +4169,7 @@ define([
4155
4169
*
4156
4170
* @param {Cartesian3 } cartesian The cartesian position.
4157
4171
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to not clamp to.
4172
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
4158
4173
* @param {Cartesian3 } [result] An optional object to return the clamped position.
4159
4174
* @returns {Cartesian3 } The modified result parameter or a new Cartesian3 instance if one was not provided. This may be <code>undefined</code> if there was no scene geometry to clamp to.
4160
4175
*
@@ -4170,7 +4185,7 @@ define([
4170
4185
* @exception {DeveloperError} clampToHeight is only supported in 3D mode.
4171
4186
* @exception {DeveloperError} clampToHeight requires depth texture support. Check clampToHeightSupported.
4172
4187
*/
4173
- Scene . prototype . clampToHeight = function ( cartesian , objectsToExclude , result ) {
4188
+ Scene . prototype . clampToHeight = function ( cartesian , objectsToExclude , width , result ) {
4174
4189
//>>includeStart('debug', pragmas.debug);
4175
4190
Check . defined ( 'cartesian' , cartesian ) ;
4176
4191
if ( this . _mode !== SceneMode . SCENE3D ) {
@@ -4180,8 +4195,15 @@ define([
4180
4195
throw new DeveloperError ( 'clampToHeight requires depth texture support. Check clampToHeightSupported.' ) ;
4181
4196
}
4182
4197
//>>includeEnd('debug');
4198
+
4199
+ if ( width instanceof Cartesian3 ) {
4200
+ result = width ;
4201
+ width = undefined ;
4202
+ deprecationWarning ( 'clampToHeight-parameter-change' , 'clampToHeight now takes an optional width argument before the result argument in Cesium 1.52. The previous function definition will no longer work in 1.53.' ) ;
4203
+ }
4204
+
4183
4205
var ray = getRayForClampToHeight ( this , cartesian ) ;
4184
- var pickResult = pickFromRay ( this , ray , objectsToExclude , true , false ) ;
4206
+ var pickResult = pickFromRay ( this , ray , objectsToExclude , width , true , false ) ;
4185
4207
if ( defined ( pickResult ) ) {
4186
4208
return Cartesian3 . clone ( pickResult . position , result ) ;
4187
4209
}
@@ -4196,6 +4218,7 @@ define([
4196
4218
*
4197
4219
* @param {Cartographic[] } positions The cartographic positions to update with sampled heights.
4198
4220
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to not sample height from.
4221
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
4199
4222
* @returns {Promise.<Number[]> } A promise that resolves to the provided list of positions when the query has completed.
4200
4223
*
4201
4224
* @example
@@ -4214,7 +4237,7 @@ define([
4214
4237
* @exception {DeveloperError} sampleHeightMostDetailed is only supported in 3D mode.
4215
4238
* @exception {DeveloperError} sampleHeightMostDetailed requires depth texture support. Check sampleHeightSupported.
4216
4239
*/
4217
- Scene . prototype . sampleHeightMostDetailed = function ( positions , objectsToExclude ) {
4240
+ Scene . prototype . sampleHeightMostDetailed = function ( positions , objectsToExclude , width ) {
4218
4241
//>>includeStart('debug', pragmas.debug);
4219
4242
Check . defined ( 'positions' , positions ) ;
4220
4243
if ( this . _mode !== SceneMode . SCENE3D ) {
@@ -4228,7 +4251,7 @@ define([
4228
4251
var length = positions . length ;
4229
4252
var promises = new Array ( length ) ;
4230
4253
for ( var i = 0 ; i < length ; ++ i ) {
4231
- promises [ i ] = sampleHeightMostDetailed ( this , positions [ i ] , objectsToExclude ) ;
4254
+ promises [ i ] = sampleHeightMostDetailed ( this , positions [ i ] , objectsToExclude , width ) ;
4232
4255
}
4233
4256
return when . all ( promises ) . then ( function ( heights ) {
4234
4257
var length = heights . length ;
@@ -4247,6 +4270,7 @@ define([
4247
4270
*
4248
4271
* @param {Cartesian3[] } cartesians The cartesian positions to update with clamped positions.
4249
4272
* @param {Object[] } [objectsToExclude] A list of primitives, entities, or 3D Tiles features to not clamp to.
4273
+ * @param {Number } [width=0.1] Width of the intersection rectangle in meters.
4250
4274
* @returns {Promise.<Cartesian3[]> } A promise that resolves to the provided list of positions when the query has completed.
4251
4275
*
4252
4276
* @example
@@ -4265,7 +4289,7 @@ define([
4265
4289
* @exception {DeveloperError} clampToHeightMostDetailed is only supported in 3D mode.
4266
4290
* @exception {DeveloperError} clampToHeightMostDetailed requires depth texture support. Check clampToHeightSupported.
4267
4291
*/
4268
- Scene . prototype . clampToHeightMostDetailed = function ( cartesians , objectsToExclude ) {
4292
+ Scene . prototype . clampToHeightMostDetailed = function ( cartesians , objectsToExclude , width ) {
4269
4293
//>>includeStart('debug', pragmas.debug);
4270
4294
Check . defined ( 'cartesians' , cartesians ) ;
4271
4295
if ( this . _mode !== SceneMode . SCENE3D ) {
@@ -4279,7 +4303,7 @@ define([
4279
4303
var length = cartesians . length ;
4280
4304
var promises = new Array ( length ) ;
4281
4305
for ( var i = 0 ; i < length ; ++ i ) {
4282
- promises [ i ] = clampToHeightMostDetailed ( this , cartesians [ i ] , objectsToExclude , cartesians [ i ] ) ;
4306
+ promises [ i ] = clampToHeightMostDetailed ( this , cartesians [ i ] , objectsToExclude , width , cartesians [ i ] ) ;
4283
4307
}
4284
4308
return when . all ( promises ) . then ( function ( clampedCartesians ) {
4285
4309
var length = clampedCartesians . length ;
0 commit comments