Skip to content

Commit

Permalink
Merge pull request #5169 from ateshuseyin/cache-pickposition
Browse files Browse the repository at this point in the history
Cache pickposition
  • Loading branch information
pjcozzi authored Apr 18, 2017
2 parents 7bff027 + e92cebd commit 11aa2bc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/cesium.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Run_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Change Log
* Fixed issue with displaying `MapboxImageryProvider` default token error message [#5191](https://github.com/AnalyticalGraphicsInc/cesium/pull/5191)
* Added a `depthFailMaterial` property to line entities, which is the material used to render the line when it fails the depth test. [#5160](https://github.com/AnalyticalGraphicsInc/cesium/pull/5160)
* Upgrade FXAA to version 3.11. [#5200](https://github.com/AnalyticalGraphicsInc/cesium/pull/5200)
* `Scene.pickPosition` now caches results per frame to increase performance [#5117](https://github.com/AnalyticalGraphicsInc/cesium/issues/5117)
* Fix billboards not initially clustering. [#5208](https://github.com/AnalyticalGraphicsInc/cesium/pull/5208)

### 1.32 - 2017-04-03
Expand Down
17 changes: 17 additions & 0 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ define([
this._cameraStartFired = false;
this._cameraMovedTime = undefined;

this._pickPositionCache = {};
this._pickPositionCacheDirty = false;

this._minimumDisableDepthTestDistance = 0.0;

/**
Expand Down Expand Up @@ -2548,6 +2551,8 @@ define([
var scratchEyeTranslation = new Cartesian3();

function render(scene, time) {
scene._pickPositionCacheDirty = true;

if (!defined(time)) {
time = JulianDate.now();
}
Expand Down Expand Up @@ -2979,6 +2984,15 @@ define([
}
//>>includeEnd('debug');

var cacheKey = windowPosition.toString();

if (this._pickPositionCacheDirty){
this._pickPositionCache = {};
this._pickPositionCacheDirty = false;
} else if (this._pickPositionCache.hasOwnProperty(cacheKey)){
return Cartesian3.clone(this._pickPositionCache[cacheKey], result);
}

var context = this._context;
var uniformState = context.uniformState;

Expand Down Expand Up @@ -3040,10 +3054,12 @@ define([
uniformState.update(this.frameState);
}

this._pickPositionCache[cacheKey] = Cartesian3.clone(result);
return result;
}
}

this._pickPositionCache[cacheKey] = undefined;
return undefined;
};

Expand Down Expand Up @@ -3078,6 +3094,7 @@ define([
var cart = projection.unproject(result, scratchPickPositionCartographic);
ellipsoid.cartographicToCartesian(cart, result);
}

return result;
};

Expand Down
37 changes: 37 additions & 0 deletions Specs/Scene/SceneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defineSuite([
'Scene/Scene',
'Scene/ScreenSpaceCameraController',
'Scene/TweenCollection',
'Scene/SceneTransforms',
'Specs/createCanvas',
'Specs/createScene',
'Specs/equals',
Expand Down Expand Up @@ -72,6 +73,7 @@ defineSuite([
Scene,
ScreenSpaceCameraController,
TweenCollection,
SceneTransforms,
createCanvas,
createScene,
equals,
Expand Down Expand Up @@ -838,6 +840,41 @@ defineSuite([
});
});

it('pickPosition caches results per frame',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);
spyOn(SceneTransforms, 'transformWindowToDrawingBuffer').and.callThrough();

expect(scene).toRenderAndCall(function() {
scene.pickPosition(windowPosition);
expect(SceneTransforms.transformWindowToDrawingBuffer).toHaveBeenCalled();

scene.pickPosition(windowPosition);
expect(SceneTransforms.transformWindowToDrawingBuffer.calls.count()).toEqual(1);

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);
});

expect(scene).toRenderAndCall(function() {
scene.pickPosition(windowPosition);
expect(SceneTransforms.transformWindowToDrawingBuffer.calls.count()).toEqual(2);

scene.pickPosition(windowPosition);
expect(SceneTransforms.transformWindowToDrawingBuffer.calls.count()).toEqual(2);
});
});

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

0 comments on commit 11aa2bc

Please sign in to comment.