Skip to content

Commit 0935d13

Browse files
committed
Tests TEMP
1 parent e111e3f commit 0935d13

File tree

2 files changed

+136
-25
lines changed

2 files changed

+136
-25
lines changed

Source/Scene/Scene.js

+19-25
Original file line numberDiff line numberDiff line change
@@ -3548,6 +3548,17 @@ define([
35483548
var scratchUp = new Cartesian3();
35493549

35503550
function pickFromRay(scene, ray, pickPosition, pickObject) {
3551+
//>>includeStart('debug', pragmas.debug);
3552+
Check.defined('ray', ray);
3553+
if (pickPosition && !this.pickPositionSupported) {
3554+
throw new DeveloperError('Picking from the depth buffer is not supported. Check pickPositionSupported.');
3555+
}
3556+
if (scene._mode === SceneMode.SCENE2D) {
3557+
throw new DeveloperError('Pick from ray is not supported in 2D.');
3558+
}
3559+
//>>includeEnd('debug');
3560+
3561+
35513562
var context = scene._context;
35523563
var uniformState = context.uniformState;
35533564
var frameState = scene._frameState;
@@ -3635,7 +3646,7 @@ define([
36353646
/**
36363647
* Returns an object with a `primitive` property that contains the first (top) primitive in the scene
36373648
* hit by the ray or undefined if nothing is hit. Other properties may potentially be set depending on the type
3638-
* of primitive and may be used to further identify the picked object.
3649+
* of primitive and may be used to further identify the picked object. The ray must be given in world coordinates.
36393650
* <p>
36403651
* When a feature of a 3D Tiles tileset is picked, <code>pick</code> returns a {@link Cesium3DTileFeature} object.
36413652
* </p>
@@ -3648,17 +3659,15 @@ define([
36483659
* @see Scene#pick
36493660
*/
36503661
Scene.prototype.pickFromRay = function(ray) {
3651-
//>>includeStart('debug', pragmas.debug);
3652-
Check.defined('ray', ray);
3653-
//>>includeEnd('debug');
36543662
var pickResult = pickFromRay(this, ray, false, true);
36553663
if (defined(pickResult)) {
36563664
return pickResult.object;
36573665
}
36583666
};
36593667

36603668
/**
3661-
* Returns the cartesian position of the first intersection of the ray or undefined if nothing is hit.
3669+
* Returns the position, in world coordinates, of the first intersection of the ray or undefined if nothing is hit.
3670+
* The ray must be given in world coordinates.
36623671
*
36633672
* @private
36643673
*
@@ -3669,12 +3678,6 @@ define([
36693678
* @exception {DeveloperError} Picking from the depth buffer is not supported. Check pickPositionSupported.
36703679
*/
36713680
Scene.prototype.pickPositionFromRay = function(ray, result) {
3672-
//>>includeStart('debug', pragmas.debug);
3673-
Check.defined('ray', ray);
3674-
if (!this.pickPositionSupported) {
3675-
throw new DeveloperError('Picking from the depth buffer is not supported. Check pickPositionSupported.');
3676-
}
3677-
//>>includeEnd('debug');
36783681
var pickResult = pickFromRay(this, ray, true, false);
36793682
if (defined(pickResult)) {
36803683
return Cartesian3.clone(pickResult.position, result);
@@ -3684,7 +3687,7 @@ define([
36843687
/**
36853688
* Returns a list of objects, each containing a `primitive` property, for all primitives hit
36863689
* by the ray. Other properties may also be set depending on the type of primitive and may be
3687-
* used to further identify the picked object.
3690+
* used to further identify the picked object. The ray must be given in world coordinates.
36883691
* The primitives in the list are ordered by their visual order in the scene (front to back).
36893692
*
36903693
* @private
@@ -3696,9 +3699,6 @@ define([
36963699
* @see Scene#drillPick
36973700
*/
36983701
Scene.prototype.drillPickFromRay = function(ray, limit) {
3699-
//>>includeStart('debug', pragmas.debug);
3700-
Check.defined('ray', ray);
3701-
//>>includeEnd('debug');
37023702
var that = this;
37033703
var pickCallback = function() {
37043704
return pickFromRay(that, ray, false, true);
@@ -3710,7 +3710,7 @@ define([
37103710
};
37113711

37123712
/**
3713-
* Returns a list of cartesian positions containing intersections of the ray in the scene.
3713+
* Returns a list of cartesian positions, in world coordinates, containing intersections of the ray in the scene.
37143714
*
37153715
* @private
37163716
*
@@ -3721,9 +3721,6 @@ define([
37213721
* @exception {DeveloperError} Picking from the depth buffer is not supported. Check pickPositionSupported.
37223722
*/
37233723
Scene.prototype.drillPickPositionFromRay = function(ray, limit) {
3724-
//>>includeStart('debug', pragmas.debug);
3725-
Check.defined('ray', ray);
3726-
//>>includeEnd('debug');
37273724
if (!this.pickPositionSupported) {
37283725
throw new DeveloperError('Picking from the depth buffer is not supported. Check pickPositionSupported.');
37293726
}
@@ -3758,9 +3755,6 @@ define([
37583755
*
37593756
*/
37603757
Scene.prototype.drillPick = function(windowPosition, limit, width, height) {
3761-
//>>includeStart('debug', pragmas.debug);
3762-
Check.defined('windowPosition', windowPosition);
3763-
//>>includeEnd('debug');
37643758
var that = this;
37653759
var pickCallback = function() {
37663760
var object = that.pick(windowPosition, width, height);
@@ -3804,9 +3798,6 @@ define([
38043798
Scene.prototype.sampleHeight = function(position, objectsToExclude) {
38053799
//>>includeStart('debug', pragmas.debug);
38063800
Check.defined('position', position);
3807-
if (!this.pickPositionSupported) {
3808-
throw new DeveloperError('Picking from the depth buffer is not supported. Check pickPositionSupported.');
3809-
}
38103801
//>>includeEnd('debug');
38113802
var globe = this.globe;
38123803
var ellipsoid = defined(globe) ? globe.ellipsoid : this.mapProjection.ellipsoid;
@@ -3869,6 +3860,9 @@ define([
38693860
* @exception {DeveloperError} Picking from the depth buffer is not supported. Check pickPositionSupported.
38703861
*/
38713862
Scene.prototype.clampToHeight = function(cartesian, objectsToExclude, result) {
3863+
//>>includeStart('debug', pragmas.debug);
3864+
Check.defined('cartesian', cartesian);
3865+
//>>includeEnd('debug');
38723866
var globe = this.globe;
38733867
var ellipsoid = defined(globe) ? globe.ellipsoid : this.mapProjection.ellipsoid;
38743868
var cartographic = Cartographic.fromCartesian(cartesian, ellipsoid, scratchPickCartographic);

Specs/Scene/PickSpec.js

+117
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
defineSuite([
2+
'Core/Cartographic',
23
'Core/FeatureDetection',
34
'Core/GeometryInstance',
45
'Core/Math',
6+
'Core/Matrix4',
57
'Core/OrthographicFrustum',
68
'Core/PerspectiveFrustum',
9+
'Core/Ray',
710
'Core/Rectangle',
811
'Core/RectangleGeometry',
912
'Core/ShowGeometryInstanceAttribute',
13+
'Core/Transforms',
14+
'Scene/Cesium3DTileset',
1015
'Scene/EllipsoidSurfaceAppearance',
1116
'Scene/Primitive',
1217
'Scene/SceneMode',
18+
'Specs/Cesium3DTilesTester',
1319
'Specs/createCanvas',
1420
'Specs/createScene'
1521
], 'Scene/Pick', function(
22+
Cartographic,
1623
FeatureDetection,
1724
GeometryInstance,
1825
CesiumMath,
26+
Matrix4,
1927
OrthographicFrustum,
2028
PerspectiveFrustum,
29+
Ray,
2130
Rectangle,
2231
RectangleGeometry,
2332
ShowGeometryInstanceAttribute,
33+
Transforms,
34+
Cesium3DTileset,
2435
EllipsoidSurfaceAppearance,
2536
Primitive,
2637
SceneMode,
38+
Cesium3DTilesTester,
2739
createCanvas,
2840
createScene) {
2941
'use strict';
@@ -32,13 +44,26 @@ defineSuite([
3244
var primitives;
3345
var camera;
3446
var primitiveRectangle = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0);
47+
var otherRectangle = Rectangle.fromDegrees(-45.0, -1.0, -43.0, 1.0);
48+
var primitiveRay;
49+
var otherRay;
3550

3651
beforeAll(function() {
3752
scene = createScene({
3853
canvas : createCanvas(10, 10)
3954
});
4055
primitives = scene.primitives;
4156
camera = scene.camera;
57+
58+
camera.setView({
59+
destination : primitiveRectangle
60+
});
61+
primitiveRay = new Ray(camera.positionWC, camera.directionWC);
62+
63+
camera.setView({
64+
destination : otherRectangle
65+
});
66+
otherRay = new Ray(camera.positionWC, camera.directionWC);
4267
});
4368

4469
afterAll(function() {
@@ -82,6 +107,20 @@ defineSuite([
82107
return e;
83108
}
84109

110+
function createTileset() {
111+
var url = 'Data/Cesium3DTiles/Batched/BatchedWithTransformBox/tileset.json';
112+
var options = {
113+
maximumScreenSpaceError : 0
114+
};
115+
return Cesium3DTilesTester.loadTileset(scene, url, options).then(function(tileset) {
116+
var cartographic = Rectangle.center(primitiveRectangle);
117+
var cartesian = Cartographic.toCartesian(cartographic);
118+
tileset.root.transform = Matrix4.IDENTITY;
119+
tileset.modelMatrix = Transforms.eastNorthUpToFixedFrame(cartesian);
120+
return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset);
121+
});
122+
}
123+
85124
describe('pick', function() {
86125
it('does not pick undefined window positions', function() {
87126
expect(function() {
@@ -364,4 +403,82 @@ defineSuite([
364403
});
365404
});
366405
});
406+
407+
describe('pickFromRay', function() {
408+
it('picks a tileset', function() {
409+
return createTileset().then(function(tileset) {
410+
scene.renderForSpecs();
411+
var picked = scene.pickFromRay(primitiveRay);
412+
expect(picked.primitive).toBe(tileset);
413+
});
414+
});
415+
416+
it('picks a primitive', function() {
417+
var rectangle = createRectangle();
418+
var picked = scene.pickFromRay(primitiveRay);
419+
expect(picked.primitive).toBe(rectangle);
420+
});
421+
422+
it('does not pick primitive', function() {
423+
createRectangle();
424+
var picked = scene.pickFromRay(otherRay);
425+
expect(picked).toBeUndefined();
426+
});
427+
428+
it('does not pick primitives when show is false', function() {
429+
var rectangle = createRectangle();
430+
rectangle.show = false;
431+
var picked = scene.pickFromRay(primitiveRay);
432+
expect(picked).toBeUndefined();
433+
});
434+
435+
it('does not pick primitives when alpha is zero', function() {
436+
var rectangle = createRectangle();
437+
rectangle.appearance.material.uniforms.color.alpha = 0.0;
438+
var picked = scene.pickFromRay(primitiveRay);
439+
expect(picked).toBeUndefined();
440+
});
441+
442+
it('picks the top primitive', function() {
443+
createRectangle();
444+
var rectangle2 = createRectangle();
445+
rectangle2.height = 0.01;
446+
447+
var picked = scene.pickFromRay(primitiveRay);
448+
expect(picked.primitive).toBe(rectangle2);
449+
});
450+
451+
it('picks when main camera is in 3D with orthographic projection', function() {
452+
var frustum = new OrthographicFrustum();
453+
frustum.aspectRatio = 1.0;
454+
frustum.width = 20.0;
455+
camera.frustum = frustum;
456+
457+
// force off center update
458+
expect(frustum.projectionMatrix).toBeDefined();
459+
460+
camera.setView({ destination : primitiveRectangle });
461+
var rectangle = createRectangle();
462+
scene.initializeFrame();
463+
var picked = scene.pickFromRay(primitiveRay);
464+
expect(picked.primitive).toBe(rectangle);
465+
});
466+
467+
it('picks when main camera is in CV', function() {
468+
// TODO
469+
});
470+
471+
it('throws if ray is undefined', function() {
472+
expect(function() {
473+
scene.pickFromRay(undefined);
474+
}).toThrowDeveloperError();
475+
});
476+
477+
// it('throws if main camera is in 2D', function() {
478+
// scene.morphTo2D(0.0);
479+
// expect(function() {
480+
// scene.pickFromRay(primitiveRay);
481+
// }).toThrowDeveloperError();
482+
// });
483+
});
367484
}, 'WebGL');

0 commit comments

Comments
 (0)