-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Changes from 4 commits
f161322
cdebbd8
153946c
0a7238f
2617c07
368f5dd
fae7cdb
c2c10b1
ea7e20b
bf8386b
1ae9bca
6ce6080
76b6e87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2769,9 +2769,6 @@ define([ | |
} | ||
|
||
// pick rectangle width and height, assumed odd | ||
var rectangleWidth = 3.0; | ||
var rectangleHeight = 3.0; | ||
var scratchRectangle = new BoundingRectangle(0.0, 0.0, rectangleWidth, rectangleHeight); | ||
var scratchColorZero = new Color(0.0, 0.0, 0.0, 0.0); | ||
var scratchPosition = new Cartesian2(); | ||
|
||
|
@@ -2793,16 +2790,22 @@ define([ | |
* }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
* | ||
* @param {Cartesian2} windowPosition Window coordinates to perform picking on. | ||
* @param {Number} [optional] width of the pick rectangle | ||
* @param {Number} [optional] height of the pick rectangle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For optional arguments the name of the argument should be within the brackets, with default values shown, like:
|
||
* @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'); | ||
// override the rectangle dimensions if defined | ||
var rectangleWidth = width || 3.0; | ||
var rectangleHeight = height || width || 3.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Also the comment above can be removed. |
||
var scratchRectangle = new BoundingRectangle(0.0, 0.0, rectangleWidth, rectangleHeight); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still worth storing the scratch rectangle in file scope so that a new rectangle isn't allocated for every pick call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My only thought on using the scratch rectangle is that it will modify the default size for future calls to pick. So if you decided to call pick and change the size to say 10, from there on the pick routine will use 10 instead of 3 until another call to it is made that changes the size. I suppose I could reset it back to the default at the end of the routine... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to how |
||
|
||
var context = this._context; | ||
var us = context.uniformState; | ||
|
@@ -2825,7 +2828,6 @@ define([ | |
|
||
scratchRectangle.x = drawingBufferPosition.x - ((rectangleWidth - 1.0) * 0.5); | ||
scratchRectangle.y = (this.drawingBufferHeight - drawingBufferPosition.y) - ((rectangleHeight - 1.0) * 0.5); | ||
|
||
var passState = this._pickFramebuffer.begin(scratchRectangle); | ||
|
||
updateEnvironment(this, passState); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ defineSuite([ | |
'Scene/PerspectiveFrustum', | ||
'Scene/Primitive', | ||
'Scene/SceneMode', | ||
'Specs/createScene' | ||
'Specs/createCanvas', | ||
'Specs/createScene', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comma. |
||
], 'Scene/Pick', function( | ||
FeatureDetection, | ||
GeometryInstance, | ||
|
@@ -23,6 +24,7 @@ defineSuite([ | |
PerspectiveFrustum, | ||
Primitive, | ||
SceneMode, | ||
createCanvas, | ||
createScene) { | ||
'use strict'; | ||
|
||
|
@@ -58,6 +60,20 @@ defineSuite([ | |
primitives.removeAll(); | ||
}); | ||
|
||
// reset the scene such that the canvas is 10 pixels and the camera is set | ||
// such that the primitive only takes up a small area at the canvas center | ||
function setupPickSizeTestScene() { | ||
scene = createScene({canvas: createCanvas(10,10) }); | ||
primitives = scene.primitives; | ||
camera = scene.camera; | ||
scene.mode = SceneMode.SCENE3D; | ||
scene.morphTime = SceneMode.getMorphTime(scene.mode); | ||
|
||
camera.setView({ | ||
destination : Rectangle.fromDegrees(-10.0, -10.0, 10.0, 10.0) | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just always construct |
||
|
||
function createRectangle() { | ||
var e = new Primitive({ | ||
geometryInstances: new GeometryInstance({ | ||
|
@@ -94,6 +110,35 @@ defineSuite([ | |
expect(scene).toPickPrimitive(rectangle); | ||
}); | ||
|
||
it('picks a primitive at pickSize extent', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (FeatureDetection.isInternetExplorer()) { | ||
// Workaround IE 11.0.9. This test fails when all tests are ran without a breakpoint here. | ||
return; | ||
} | ||
|
||
setupPickSizeTestScene(); | ||
var rectangle = createRectangle(); | ||
// scene is 10px, primitive is at center, pick size convers 5px pixel from corner | ||
var config = { x: 0, y: 0, size: 5 }; | ||
|
||
expect(scene).toPickNearbyPrimitive(rectangle, config); | ||
}); | ||
|
||
it('does not pick a primitive at pickSize extent', function() { | ||
if (FeatureDetection.isInternetExplorer()) { | ||
// Workaround IE 11.0.9. This test fails when all tests are ran without a breakpoint here. | ||
return; | ||
} | ||
|
||
setupPickSizeTestScene(); | ||
createRectangle(); | ||
// scene is 10px, primitive is at center, pick size only convers 3px from corner | ||
var config = { x: 0, y: 0, size: 3 }; | ||
|
||
expect(scene).notToPickNearbyPrimitive(config); | ||
}); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this extra line. |
||
it('does not pick primitives when show is false', function() { | ||
var rectangle = createRectangle(); | ||
rectangle.show = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,22 @@ define([ | |
}; | ||
}, | ||
|
||
toPickNearbyPrimitive : function(util, customEqualityTesters) { | ||
return { | ||
compare : function(actual, expected, config) { | ||
return pickPrimitiveEqualsWrapper(actual, expected, config.x, config.y, config.size); | ||
} | ||
}; | ||
}, | ||
|
||
notToPickNearbyPrimitive : function(util, customEqualityTesters) { | ||
return { | ||
compare : function(actual, config) { | ||
return pickPrimitiveEqualsWrapper(actual, undefined, config.x, config.y, config.size); | ||
} | ||
}; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding these two perhaps just add the functionality to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case it would be fine to send in the values as separate arguments instead of a |
||
|
||
notToPick : function(util, customEqualityTesters) { | ||
return { | ||
compare : function(actual, expected) { | ||
|
@@ -416,6 +432,17 @@ define([ | |
}; | ||
} | ||
|
||
// converts x and y coordinates such that after updating for drawing buffer position, the correct coordinates will be used | ||
function pickPrimitiveEqualsWrapper(actual, expected, x, y, width, height) { | ||
width = width || 3; | ||
height = height || width || 3; | ||
x = x || 0; | ||
y = y || 0; | ||
var adjustedX = x + ((width - 1) * 0.5); | ||
var adjustedY = -1 * (y + ((height - 1) * 0.5) - actual._context.drawingBufferHeight); | ||
return pickPrimitiveEquals(actual, expected, adjustedX, adjustedY, width, height); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not completely following the conversion process here. Can the test be modified instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this conversion is the inverse of
from lines 2829 in Scene.js Honestly, I don't understand what this logic is accomplishing, but for the test I need to set the bounding box for the pick search to be centered at a position exactly far enough from the rectangle for the increase in pick size to affect the outcome. This was just something that would never work right until I implemented this logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I see now. By changing to test to pass in x and y values other than 0 should also work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you saying this conversion is unnecessary when the x and y values aren't 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I tried x = 7 and y = 7 and that seems to work. |
||
} | ||
|
||
function renderAndReadPixels(options) { | ||
var scene; | ||
|
||
|
@@ -465,9 +492,9 @@ define([ | |
}; | ||
} | ||
|
||
function pickPrimitiveEquals(actual, expected) { | ||
function pickPrimitiveEquals(actual, expected, x, y, pickWidth, pickHeight) { | ||
var scene = actual; | ||
var result = scene.pick(new Cartesian2(0, 0)); | ||
var result = scene.pick(new Cartesian2(x || 0, y || 0), pickWidth, pickHeight); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also use |
||
|
||
if (!!window.webglStub) { | ||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a section for
Bentley Systems
at line 84. Add yourself underPaul Connelly
insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, updated