Skip to content

Commit 11aa2bc

Browse files
authored
Merge pull request #5169 from ateshuseyin/cache-pickposition
Cache pickposition
2 parents 7bff027 + e92cebd commit 11aa2bc

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

.idea/cesium.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Run_tests.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Change Log
77
* Fixed issue with displaying `MapboxImageryProvider` default token error message [#5191](https://github.com/AnalyticalGraphicsInc/cesium/pull/5191)
88
* 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)
99
* Upgrade FXAA to version 3.11. [#5200](https://github.com/AnalyticalGraphicsInc/cesium/pull/5200)
10+
* `Scene.pickPosition` now caches results per frame to increase performance [#5117](https://github.com/AnalyticalGraphicsInc/cesium/issues/5117)
1011
* Fix billboards not initially clustering. [#5208](https://github.com/AnalyticalGraphicsInc/cesium/pull/5208)
1112

1213
### 1.32 - 2017-04-03

Source/Scene/Scene.js

+17
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ define([
321321
this._cameraStartFired = false;
322322
this._cameraMovedTime = undefined;
323323

324+
this._pickPositionCache = {};
325+
this._pickPositionCacheDirty = false;
326+
324327
this._minimumDisableDepthTestDistance = 0.0;
325328

326329
/**
@@ -2548,6 +2551,8 @@ define([
25482551
var scratchEyeTranslation = new Cartesian3();
25492552

25502553
function render(scene, time) {
2554+
scene._pickPositionCacheDirty = true;
2555+
25512556
if (!defined(time)) {
25522557
time = JulianDate.now();
25532558
}
@@ -2979,6 +2984,15 @@ define([
29792984
}
29802985
//>>includeEnd('debug');
29812986

2987+
var cacheKey = windowPosition.toString();
2988+
2989+
if (this._pickPositionCacheDirty){
2990+
this._pickPositionCache = {};
2991+
this._pickPositionCacheDirty = false;
2992+
} else if (this._pickPositionCache.hasOwnProperty(cacheKey)){
2993+
return Cartesian3.clone(this._pickPositionCache[cacheKey], result);
2994+
}
2995+
29822996
var context = this._context;
29832997
var uniformState = context.uniformState;
29842998

@@ -3040,10 +3054,12 @@ define([
30403054
uniformState.update(this.frameState);
30413055
}
30423056

3057+
this._pickPositionCache[cacheKey] = Cartesian3.clone(result);
30433058
return result;
30443059
}
30453060
}
30463061

3062+
this._pickPositionCache[cacheKey] = undefined;
30473063
return undefined;
30483064
};
30493065

@@ -3078,6 +3094,7 @@ define([
30783094
var cart = projection.unproject(result, scratchPickPositionCartographic);
30793095
ellipsoid.cartographicToCartesian(cart, result);
30803096
}
3097+
30813098
return result;
30823099
};
30833100

Specs/Scene/SceneSpec.js

+37
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ defineSuite([
3333
'Scene/Scene',
3434
'Scene/ScreenSpaceCameraController',
3535
'Scene/TweenCollection',
36+
'Scene/SceneTransforms',
3637
'Specs/createCanvas',
3738
'Specs/createScene',
3839
'Specs/equals',
@@ -72,6 +73,7 @@ defineSuite([
7273
Scene,
7374
ScreenSpaceCameraController,
7475
TweenCollection,
76+
SceneTransforms,
7577
createCanvas,
7678
createScene,
7779
equals,
@@ -838,6 +840,41 @@ defineSuite([
838840
});
839841
});
840842

843+
it('pickPosition caches results per frame',function(){
844+
if (!scene.pickPositionSupported) {
845+
return;
846+
}
847+
848+
var rectangle = Rectangle.fromDegrees(-100.0, 30.0, -90.0, 40.0);
849+
scene.camera.setView({ destination : rectangle });
850+
851+
var canvas = scene.canvas;
852+
var windowPosition = new Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2);
853+
spyOn(SceneTransforms, 'transformWindowToDrawingBuffer').and.callThrough();
854+
855+
expect(scene).toRenderAndCall(function() {
856+
scene.pickPosition(windowPosition);
857+
expect(SceneTransforms.transformWindowToDrawingBuffer).toHaveBeenCalled();
858+
859+
scene.pickPosition(windowPosition);
860+
expect(SceneTransforms.transformWindowToDrawingBuffer.calls.count()).toEqual(1);
861+
862+
var rectanglePrimitive = createRectangle(rectangle);
863+
rectanglePrimitive.appearance.material.uniforms.color = new Color(1.0, 0.0, 0.0, 1.0);
864+
865+
var primitives = scene.primitives;
866+
primitives.add(rectanglePrimitive);
867+
});
868+
869+
expect(scene).toRenderAndCall(function() {
870+
scene.pickPosition(windowPosition);
871+
expect(SceneTransforms.transformWindowToDrawingBuffer.calls.count()).toEqual(2);
872+
873+
scene.pickPosition(windowPosition);
874+
expect(SceneTransforms.transformWindowToDrawingBuffer.calls.count()).toEqual(2);
875+
});
876+
});
877+
841878
it('pickPosition throws without windowPosition', function() {
842879
expect(function() {
843880
scene.pickPosition();

0 commit comments

Comments
 (0)