diff --git a/CHANGES.md b/CHANGES.md index 2ef016f2c36f..983146dd573c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ Change Log ========== +### 1.51 - 2018-11-01 + +##### Fixes :wrench: +* Fixed an issue where `pickPosition` would return incorrect results when called after `sampleHeight` or `clampToHeight`. [#7113](https://github.com/AnalyticalGraphicsInc/cesium/pull/7113) + ### 1.50 - 2018-10-01 ##### Breaking Changes :mega: diff --git a/Specs/Scene/PickSpec.js b/Specs/Scene/PickSpec.js index 26812206a792..266497875103 100644 --- a/Specs/Scene/PickSpec.js +++ b/Specs/Scene/PickSpec.js @@ -1,6 +1,8 @@ defineSuite([ + 'Core/Cartesian2', 'Core/Cartesian3', 'Core/Cartographic', + 'Core/Color', 'Core/Ellipsoid', 'Core/FeatureDetection', 'Core/GeometryInstance', @@ -25,8 +27,10 @@ defineSuite([ 'Specs/createScene', 'Specs/pollToPromise' ], 'Scene/Pick', function( + Cartesian2, Cartesian3, Cartographic, + Color, Ellipsoid, FeatureDetection, GeometryInstance, @@ -57,7 +61,7 @@ defineSuite([ var camera; var largeRectangle = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0); var smallRectangle = Rectangle.fromDegrees(-0.0001, -0.0001, 0.0001, 0.0001); - var offscreenRectangle = Rectangle.fromDegrees(-45.0, -1.0, -43.0, 1.0); + var offscreenRectangle = Rectangle.fromDegrees(-45.0002, -1.0002, -45.0001, -1.0001); var primitiveRay; var offscreenRay; @@ -1078,4 +1082,69 @@ defineSuite([ scene.context._depthTexture = depthTexture; }); }); + + it('calls multiple picking functions within the same frame', function() { + if (!scene.clampToHeightSupported || !scene.pickPositionSupported) { + return; + } + + createSmallRectangle(0.0); + var offscreenRectanglePrimitive = createRectangle(0.0, offscreenRectangle); + offscreenRectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 1.0); + + scene.camera.setView({ destination : offscreenRectangle }); + + // Call render. Lays down depth for the pickPosition call + scene.renderForSpecs(); + + // Call clampToHeight + var cartesian = Cartesian3.fromRadians(0.0, 0.0, 100000.0); + expect(scene).toClampToHeightAndCall(function(cartesian) { + var expectedCartesian = Cartesian3.fromRadians(0.0, 0.0); + expect(cartesian).toEqualEpsilon(expectedCartesian, CesiumMath.EPSILON5); + }, cartesian); + + // Call pickPosition + expect(scene).toPickPositionAndCall(function(cartesian) { + var expectedCartesian = Cartographic.toCartesian(Rectangle.center(offscreenRectangle)); + expect(cartesian).toEqualEpsilon(expectedCartesian, CesiumMath.EPSILON5); + }); + + // Call clampToHeight again + expect(scene).toClampToHeightAndCall(function(cartesian) { + var expectedCartesian = Cartesian3.fromRadians(0.0, 0.0); + expect(cartesian).toEqualEpsilon(expectedCartesian, CesiumMath.EPSILON5); + }, cartesian); + + // Call pick + expect(scene).toPickPrimitive(offscreenRectanglePrimitive); + + // Call clampToHeight again + expect(scene).toClampToHeightAndCall(function(cartesian) { + var expectedCartesian = Cartesian3.fromRadians(0.0, 0.0); + expect(cartesian).toEqualEpsilon(expectedCartesian, CesiumMath.EPSILON5); + }, cartesian); + + // Call pickPosition on translucent primitive and returns undefined + offscreenRectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 0.5); + scene.renderForSpecs(); + expect(scene).toPickPositionAndCall(function(cartesian) { + expect(cartesian).toBeUndefined(); + }); + + // Call clampToHeight again + expect(scene).toClampToHeightAndCall(function(cartesian) { + var expectedCartesian = Cartesian3.fromRadians(0.0, 0.0); + expect(cartesian).toEqualEpsilon(expectedCartesian, CesiumMath.EPSILON5); + }, cartesian); + + // Call pickPosition on translucent primitive with pickTranslucentDepth + scene.pickTranslucentDepth = true; + scene.renderForSpecs(); + expect(scene).toPickPositionAndCall(function(cartesian) { + var expectedCartesian = Cartographic.toCartesian(Rectangle.center(offscreenRectangle)); + expect(cartesian).toEqualEpsilon(expectedCartesian, CesiumMath.EPSILON5); + }); + }); + }, 'WebGL'); diff --git a/Specs/addDefaultMatchers.js b/Specs/addDefaultMatchers.js index cc5dd27976f3..a32d118ad25a 100644 --- a/Specs/addDefaultMatchers.js +++ b/Specs/addDefaultMatchers.js @@ -439,6 +439,30 @@ define([ }; }, + toPickPositionAndCall : function(util, customEqualityTesters) { + return { + compare : function(actual, expected, x, y) { + var scene = actual; + var canvas = scene.canvas; + x = defaultValue(x, canvas.clientWidth / 2); + y = defaultValue(y, canvas.clientHeight / 2); + var result = scene.pickPosition(new Cartesian2(x, y)); + + var webglStub = !!window.webglStub; + if (!webglStub) { + // The callback may have expectations that fail, which still makes the + // spec fail, as we desired, even though this matcher sets pass to true. + var callback = expected; + callback(result); + } + + return { + pass : true + }; + } + }; + }, + toReadPixels : function(util, customEqualityTesters) { return { compare : function(actual, expected) {