CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
13.05k stars 3.51k forks source link

Picking clipped entity breaks picking #8824

Open bkuster opened 4 years ago

bkuster commented 4 years ago

Issue

When an entity is clipped and picked in the same animation frame, there is a null pointer in the pick render pass, due to a missing uniforms entry (in other words. The uniforms array has a length of n but only n - 1 entries).

Background

In our application we dynamically place clipping planes. Sometimes the screen space, where the clipping plane is applied is picked within the same animation frame. After this happens, picking is broken.

Reproduction

I made a Sandcastle to programatically recreate the error, see this gist.*

  1. Create a tileset entity
  2. Wait for the entity to be fully rendered
  3. Set the clipping planes and pick the screen space where the entity is visible
  4. See console for error

* this is a modified version of the ClippingPlane Sandcastle with only the entity. The magic happens on lines 43 to 47.

OmarShehata commented 4 years ago

Thanks for the detailed steps to reproduce @bkuster ! I can see this triggers an error in your Sandcastle here.

However, when running it in Sandcastle locally, it doesn't produce an error, but correctly just returns that it picked undefined. Are you seeing this behavior too? You can run Sandcastle locally by cloning here, running npm install and npm run start and then going to http://localhost:8080/Apps/Sandcastle/index.html.

bkuster commented 4 years ago

Thanks for the fast response @OmarShehata . I can also reproduce it in a local Sandcastle (on master). It took me quite some time to find the actual cause of the error and timing is everything. Maybe something loads faster/slower in your local Sandcastle and you would need to tweak the timeout settings or maybe even the picked screen positon.

midnight-dev commented 4 years ago

@bkuster I think you're right about timing being a factor. It could come down to hardware refresh rate or a browser's rAF. Did you notice this on a high refresh rate display or a standard 60Hz panel?

I'll check to see if browser agent matters when I get to my PC.

PolanZ commented 1 year ago

@OmarShehata hi, i created a sample, please see Sandcastle Example

throw error when the mouse pick the 3dtiles.

Recently, I discovered that the texture on the clipping plane was missing during debugging. This occurred because it was executed during the "Cesium3DTileset.prototype.prePassesUpdate" phase, and it may not have been executed when picking.