Picking rect support

I’m trying to modify Cesium to support picking of a rectangular area instead of just a point.
I have the code done but for some reason it gives the incorrect results, and I’m not sure if I’m missing some Cesium detail that might be crucial to solve this.

To do picking, Cesium renders all possible objects into a framebuffer then extracts the color behind the target point.
I did an alternative picking method that takes a rect as input and then looks through all colors in the rect area and generates a list of picked objects (avoid duplicates, of course).

If anyone who knows anything about Cesium internals (Patrick or others) and have some time to look at the code, even if just some tips to find the problem would be good.

There’s two functions added to Cesim for this:

Scene.pickRegion (alternative to scene.pick)

and PickFramebuffer.endWithRect (used by pickRegion, alternative to PickFramebuffer.end)

The code partially works, however the results are incorrect, might be related to the frustum used for picking, I’m not sure why it needs a frustum different from normal rendering, and even I tried with this line (currently commented out in the code), still incorrect result
frameState.cullingVolume = getPickCullingVolume(this, drawingBufferPositionMiddle, rectangleWidth, rectangleHeight);

Hi Sergio,

I suspect you are right: the frustum used for culling or the scissor test is too small. See this article for details on the frustum/scissor test (note that we are not using the depth buffer like we did in that article):


You could try disabling these to help see where the problem is.


Sergio, did you ever get this to work? I am trying to find a way to determine which billboards are currently in view, and I'm wondering if I might be able to take something similar to what you did and modify it to not pick a rectangle, but instead somehow pick the entire viewable area.

Yes, I got it to work, the working code is the one I posted with just one or two changed (which I don’t remember now which ones, though for a full view picking this code might work already).

However I suppose that doing a full picking of the view might be a bit slow, especially if you want to do it often.

Another solution is to just use math, and loop through all billboards, calculate their screen position and check if that position is in or outside the view