Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to modify scene pick search size #5602

Merged
merged 13 commits into from
Jul 13, 2017
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log

* Added ability to show tile urls in the 3D Tiles Inspector. [#5592](https://github.com/AnalyticalGraphicsInc/cesium/pull/5592)
* Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139)
* Added ability to provide a `width` and `height` to `scene.pick`. [#5602](https://github.com/AnalyticalGraphicsInc/cesium/pull/5602)

### 1.35.2 - 2017-07-11

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Joel Depooter](https://github.com/JDepooter)
* [Bentley Systems, Inc.](https://www.bentley.com)
* [Paul Connelly](https://github.com/pmconne)
* [Jason Crow](https://github.com/jason-crow)
* [Flightradar24 AB](https://www.flightradar24.com)
* [Aleksei Kalmykov](https://github.com/kalmykov)

Expand Down
10 changes: 8 additions & 2 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -2793,17 +2793,22 @@ define([
* }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
*
* @param {Cartesian2} windowPosition Window coordinates to perform picking on.
* @param {Number} [width=3] Width of the pick rectangle.
* @param {Number} [height=3] Height of the pick rectangle.
* @returns {Object} Object containing the picked primitive.
*
* @exception {DeveloperError} windowPosition is undefined.
*/
Scene.prototype.pick = function(windowPosition) {
Scene.prototype.pick = function(windowPosition, width, height) {
//>>includeStart('debug', pragmas.debug);
if(!defined(windowPosition)) {
throw new DeveloperError('windowPosition is undefined.');
}
//>>includeEnd('debug');

rectangleWidth = defaultValue(width, 3.0);
rectangleHeight = defaultValue(height, rectangleWidth);

var context = this._context;
var us = context.uniformState;
var frameState = this._frameState;
Expand All @@ -2825,7 +2830,8 @@ define([

scratchRectangle.x = drawingBufferPosition.x - ((rectangleWidth - 1.0) * 0.5);
scratchRectangle.y = (this.drawingBufferHeight - drawingBufferPosition.y) - ((rectangleHeight - 1.0) * 0.5);

scratchRectangle.width = rectangleWidth;
scratchRectangle.height = rectangleHeight;
var passState = this._pickFramebuffer.begin(scratchRectangle);

updateEnvironment(this, passState);
Expand Down
26 changes: 23 additions & 3 deletions Specs/Scene/PickSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defineSuite([
'Scene/PerspectiveFrustum',
'Scene/Primitive',
'Scene/SceneMode',
'Specs/createScene'
'Specs/createScene',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comma.

'Specs/createCanvas'
], 'Scene/Pick', function(
FeatureDetection,
GeometryInstance,
Expand All @@ -23,7 +24,8 @@ defineSuite([
PerspectiveFrustum,
Primitive,
SceneMode,
createScene) {
createScene,
createCanvas) {
'use strict';

var scene;
Expand All @@ -32,7 +34,9 @@ defineSuite([
var primitiveRectangle = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0);

beforeAll(function() {
scene = createScene();
scene = createScene({
canvas : createCanvas(10, 10)
});
primitives = scene.primitives;
camera = scene.camera;
});
Expand Down Expand Up @@ -94,6 +98,22 @@ defineSuite([
expect(scene).toPickPrimitive(rectangle);
});

it('picks a primitive with a modified pick search area', function() {
if (FeatureDetection.isInternetExplorer()) {
// Workaround IE 11.0.9. This test fails when all tests are ran without a breakpoint here.
return;
}

camera.setView({
destination : Rectangle.fromDegrees(-10.0, -10.0, 10.0, 10.0)
});

var rectangle = createRectangle();

expect(scene).toPickPrimitive(rectangle, 7, 7, 5);
expect(scene).notToPick(7, 7, 3);
});

it('does not pick primitives when show is false', function() {
var rectangle = createRectangle();
rectangle.show = false;
Expand Down
13 changes: 7 additions & 6 deletions Specs/addDefaultMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,16 @@ define([

toPickPrimitive : function(util, customEqualityTesters) {
return {
compare : function(actual, expected) {
return pickPrimitiveEquals(actual, expected);
compare : function(actual, expected, x, y, width, height) {
return pickPrimitiveEquals(actual, expected, x, y, width, height);
}
};
},

notToPick : function(util, customEqualityTesters) {
return {
compare : function(actual, expected) {
return pickPrimitiveEquals(actual, undefined);
compare : function(actual, expected, x, y, width, height) {
return pickPrimitiveEquals(actual, undefined, x, y, width, height);
}
};
},
Expand Down Expand Up @@ -465,9 +465,10 @@ define([
};
}

function pickPrimitiveEquals(actual, expected) {
function pickPrimitiveEquals(actual, expected, x, y, width, height) {
var scene = actual;
var result = scene.pick(new Cartesian2(0, 0));
var windowPosition = new Cartesian2(x, y);
var result = scene.pick(windowPosition, width, height);

if (!!window.webglStub) {
return {
Expand Down