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 useDepthPicking flag from 3d-tiles #3390

Merged
merged 3 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

* Reduced the amount of CPU memory used by terrain by ~25% in Chrome.
* Fixed a picking problem ([#3386](https://github.com/AnalyticalGraphicsInc/cesium/issues/3386)) that sometimes prevented objects being selected.
* Added `Scene.useDepthPicking` to enable or disable picking using the depth buffer. [#3390](https://github.com/AnalyticalGraphicsInc/cesium/pull/3390)

### 1.17 - 2016-01-04

Expand Down
14 changes: 13 additions & 1 deletion Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ define([
*/
this.fxaa = true;

/**
* When <code>true</code>, enables picking using the depth buffer.
*
* @type Boolean
* @default true
*/
this.useDepthPicking = true;

/**
* The time in milliseconds to wait before checking if the camera has not moved and fire the cameraMoveEnd event.
* @type {Number}
Expand Down Expand Up @@ -1555,7 +1563,7 @@ define([
commands.length = frustumCommands.indices[Pass.TRANSLUCENT];
executeTranslucentCommands(scene, executeCommand, passState, commands);

if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer) {
if (defined(globeDepth) && environmentState.useGlobeDepthFramebuffer && scene.useDepthPicking) {
// PERFORMANCE_IDEA: Use MRT to avoid the extra copy.
var pickDepth = getPickDepth(scene, index);
pickDepth.update(context, globeDepth.framebuffer.depthStencilTexture);
Expand Down Expand Up @@ -2013,6 +2021,10 @@ define([
* @exception {DeveloperError} 2D is not supported. An orthographic projection matrix is not invertible.
*/
Scene.prototype.pickPosition = function(windowPosition, result) {
if (!this.useDepthPicking) {
return undefined;
}

//>>includeStart('debug', pragmas.debug);
if(!defined(windowPosition)) {
throw new DeveloperError('windowPosition is undefined.');
Expand Down
34 changes: 34 additions & 0 deletions Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,40 @@ defineSuite([
expect(position).toBeDefined();
});

it('pickPosition returns undefined when useDepthPicking is false', function() {
if (!scene.pickPositionSupported) {
return;
}

var rectangle = Rectangle.fromDegrees(-100.0, 30.0, -90.0, 40.0);
scene.camera.setView({
destination : rectangle
});

var canvas = scene.canvas;
var windowPosition = new Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2);

var rectanglePrimitive = createRectangle(rectangle);
rectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 1.0);

var primitives = scene.primitives;
primitives.add(rectanglePrimitive);

scene.useDepthPicking = false;

scene.renderForSpecs();

var position = scene.pickPosition(windowPosition);
expect(position).not.toBeDefined();

scene.useDepthPicking = true;

scene.renderForSpecs();

position = scene.pickPosition(windowPosition);
expect(position).toBeDefined();
});

it('pickPosition throws without windowPosition', function() {
expect(function() {
scene.pickPosition();
Expand Down